GRIM: Make the opcode InputDialog show a dialog instead of using the console.
This commit is contained in:
parent
e89d6195b0
commit
5906b0826d
6 changed files with 189 additions and 12 deletions
|
@ -1753,6 +1753,10 @@ void GrimEngine::clearEventQueue() {
|
|||
Common::Event event;
|
||||
while (g_system->getEventManager()->pollEvent(event)) {
|
||||
}
|
||||
|
||||
for (int i = 0; i < KEYCODE_EXTRA_LAST; ++i) {
|
||||
_controlsState[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
} // end of namespace Grim
|
||||
|
|
|
@ -135,6 +135,7 @@ public:
|
|||
void disableControl(int num) { _controlsEnabled[num] = false; }
|
||||
float getControlAxis(int num);
|
||||
bool getControlState(int num);
|
||||
void clearEventQueue();
|
||||
|
||||
Scene *findScene(const Common::String &name);
|
||||
void setSceneLock(const char *name, bool lockStatus);
|
||||
|
@ -240,8 +241,6 @@ private:
|
|||
void savegameCallback();
|
||||
void storeSaveGameImage(SaveGame *savedState);
|
||||
|
||||
void clearEventQueue();
|
||||
|
||||
bool _savegameLoadRequest;
|
||||
bool _savegameSaveRequest;
|
||||
Common::String _savegameFileName;
|
||||
|
|
113
engines/grim/inputdialog.cpp
Normal file
113
engines/grim/inputdialog.cpp
Normal file
|
@ -0,0 +1,113 @@
|
|||
/* Residual - A 3D game interpreter
|
||||
*
|
||||
* Residual is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "common/system.h"
|
||||
|
||||
#include "gui/gui-manager.h"
|
||||
#include "gui/ThemeEval.h"
|
||||
#include "gui/widget.h"
|
||||
#include "gui/widgets/edittext.h"
|
||||
|
||||
#include "engines/grim/inputdialog.h"
|
||||
|
||||
namespace Grim {
|
||||
|
||||
InputDialog::InputDialog(const Common::String &message, const Common::String &string) :
|
||||
GUI::Dialog(30, 20, 260, 124) {
|
||||
|
||||
const int screenW = g_system->getOverlayWidth();
|
||||
const int screenH = g_system->getOverlayHeight();
|
||||
|
||||
int buttonWidth = g_gui.xmlEval()->getVar("Globals.Button.Width", 0);
|
||||
int buttonHeight = g_gui.xmlEval()->getVar("Globals.Button.Height", 0);
|
||||
|
||||
// First, determine the size the dialog needs. For this we have to break
|
||||
// down the string into lines, and taking the maximum of their widths.
|
||||
// Using this, and accounting for the space the button(s) need, we can set
|
||||
// the real size of the dialog
|
||||
Common::Array<Common::String> lines;
|
||||
int lineCount;
|
||||
int maxlineWidth = g_gui.getFont().wordWrapText(message, screenW - 2 * 20, lines);
|
||||
|
||||
// Calculate the desired dialog size (maxing out at 300*180 for now)
|
||||
_w = MAX(maxlineWidth, (2 * buttonWidth) + 10) + 20;
|
||||
|
||||
lineCount = lines.size();
|
||||
|
||||
_h = 30 + kLineHeight;
|
||||
_h += buttonHeight + 10;
|
||||
|
||||
// Limit the number of lines so that the dialog still fits on the screen.
|
||||
if (lineCount > (screenH - 20 - _h) / kLineHeight) {
|
||||
lineCount = (screenH - 20 - _h) / kLineHeight;
|
||||
}
|
||||
_h += lineCount * kLineHeight;
|
||||
|
||||
// Center the dialog
|
||||
_x = (screenW - _w) / 2;
|
||||
_y = (screenH - _h) / 2;
|
||||
|
||||
// Each line is represented by one static text item.
|
||||
int height = 10;
|
||||
for (int i = 0; i < lineCount; i++) {
|
||||
new GUI::StaticTextWidget(this, 10, height, maxlineWidth, kLineHeight,
|
||||
lines[i], Graphics::kTextAlignCenter);
|
||||
height += kLineHeight;
|
||||
}
|
||||
height += 10;
|
||||
|
||||
m_text = new GUI::EditTextWidget(this, 10, height, _w - 20, kLineHeight, string, "input");
|
||||
height += kLineHeight + 10;
|
||||
|
||||
new GUI::ButtonWidget(this, 10, height, buttonWidth, buttonHeight, "Ok", 0, GUI::kOKCmd, Common::ASCII_RETURN); // Confirm dialog
|
||||
new GUI::ButtonWidget(this, _w - buttonWidth - 10, height, buttonWidth, buttonHeight, "Cancel", 0, GUI::kCloseCmd, Common::ASCII_ESCAPE); // Cancel dialog
|
||||
}
|
||||
|
||||
const Common::String &InputDialog::getString() const {
|
||||
return m_text->getEditString();
|
||||
}
|
||||
|
||||
void InputDialog::handleKeyDown(Common::KeyState state) {
|
||||
if (state.keycode == Common::KEYCODE_RETURN) {
|
||||
setResult(1);
|
||||
close();
|
||||
} else if (state.keycode == Common::KEYCODE_ESCAPE) {
|
||||
setResult(0);
|
||||
close();
|
||||
} else {
|
||||
GUI::Dialog::handleKeyDown(state);
|
||||
}
|
||||
}
|
||||
|
||||
void InputDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data) {
|
||||
if (cmd == GUI::kOKCmd) {
|
||||
setResult(1);
|
||||
close();
|
||||
} else if (cmd == GUI::kCloseCmd) {
|
||||
setResult(0);
|
||||
close();
|
||||
} else {
|
||||
GUI::Dialog::handleCommand(sender, cmd, data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
52
engines/grim/inputdialog.h
Normal file
52
engines/grim/inputdialog.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
/* Residual - A 3D game interpreter
|
||||
*
|
||||
* Residual is the legal property of its developers, whose names
|
||||
* are too numerous to list here. Please refer to the COPYRIGHT
|
||||
* file distributed with this source distribution.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef GRIM_INPUTDIALOG_H
|
||||
#define GRIM_INPUTDIALOG_H
|
||||
|
||||
#include "gui/dialog.h"
|
||||
|
||||
namespace GUI {
|
||||
class CommandSender;
|
||||
class EditTextWidget;
|
||||
}
|
||||
|
||||
namespace Grim {
|
||||
|
||||
class InputDialog : public GUI::Dialog {
|
||||
public:
|
||||
InputDialog(const Common::String &message, const Common::String &string);
|
||||
|
||||
const Common::String &getString() const;
|
||||
|
||||
protected:
|
||||
virtual void handleKeyDown(Common::KeyState state);
|
||||
virtual void handleCommand(GUI::CommandSender *sender, uint32 cmd, uint32 data);
|
||||
|
||||
private:
|
||||
GUI::EditTextWidget *m_text;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -33,6 +33,7 @@
|
|||
#include "engines/grim/savegame.h"
|
||||
#include "engines/grim/colormap.h"
|
||||
#include "engines/grim/resource.h"
|
||||
#include "engines/grim/inputdialog.h"
|
||||
|
||||
#include "engines/grim/imuse/imuse.h"
|
||||
|
||||
|
@ -545,21 +546,28 @@ void L1_PrintLine() {
|
|||
}
|
||||
|
||||
void L1_InputDialog() {
|
||||
lua_Object str1Obj = lua_getparam(1);
|
||||
lua_Object str2Obj = lua_getparam(2);
|
||||
int c, i = 0;
|
||||
char buf[512];
|
||||
lua_Object titleObj = lua_getparam(1);
|
||||
lua_Object messageObj = lua_getparam(2);
|
||||
lua_Object defaultObj = lua_getparam(3);
|
||||
|
||||
if (!lua_isstring(str1Obj) || !lua_isstring(str2Obj)) {
|
||||
if (!lua_isstring(titleObj) || !lua_isstring(messageObj)) {
|
||||
lua_pushnil();
|
||||
return;
|
||||
}
|
||||
fprintf(stderr, "%s %s: ", lua_getstring(str1Obj), lua_getstring(str2Obj));
|
||||
while (i < 512 && (c = fgetc(stdin)) != EOF && c != '\n')
|
||||
buf[i++] = c;
|
||||
buf[i] = '\0';
|
||||
|
||||
lua_pushstring(buf);
|
||||
Common::String str = lua_getstring(titleObj);
|
||||
str += ": ";
|
||||
str += lua_getstring(messageObj);
|
||||
InputDialog d(str, lua_getstring(defaultObj));
|
||||
int res = d.runModal();
|
||||
// The KeyUp event for CTRL has been eat by the gui loop, so we
|
||||
// need to reset it manually.
|
||||
g_grim->clearEventQueue();
|
||||
if (res) {
|
||||
lua_pushstring(d.getString().c_str());
|
||||
} else {
|
||||
lua_pushnil();
|
||||
}
|
||||
}
|
||||
|
||||
void L1_IsMessageGoing() {
|
||||
|
|
|
@ -50,6 +50,7 @@ MODULE_OBJS := \
|
|||
gfx_opengl.o \
|
||||
gfx_tinygl.o \
|
||||
grim.o \
|
||||
inputdialog.o \
|
||||
iris.o \
|
||||
keyframe.o \
|
||||
lab.o \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue