Change SAGA engine to properly use KeyState structs for handling keyboard input
svn-id: r28889
This commit is contained in:
parent
669309776a
commit
4a4fc235f2
4 changed files with 43 additions and 45 deletions
|
@ -2014,6 +2014,8 @@ bool Actor::followProtagonist(ActorData *actor) {
|
||||||
newLocation.y += _vm->_rnd.getRandomNumber(prefer1.y - 1) - prefer1.y / 2;
|
newLocation.y += _vm->_rnd.getRandomNumber(prefer1.y - 1) - prefer1.y / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Fingolfin asks: why is there a FIXME here? Please either clarify what
|
||||||
|
// needs fixing, or remove it!
|
||||||
newLocation.x = clamp(-31*4, newLocation.x, (_vm->getDisplayWidth() + 31) * 4); //fixme
|
newLocation.x = clamp(-31*4, newLocation.x, (_vm->getDisplayWidth() + 31) * 4); //fixme
|
||||||
|
|
||||||
return actorWalkTo(actor->_id, newLocation);
|
return actorWalkTo(actor->_id, newLocation);
|
||||||
|
|
|
@ -49,7 +49,7 @@ int SagaEngine::processInput() {
|
||||||
_console->attach();
|
_console->attach();
|
||||||
}
|
}
|
||||||
if (_interface->_textInput || _interface->_statusTextInput) {
|
if (_interface->_textInput || _interface->_statusTextInput) {
|
||||||
_interface->processAscii(event.kbd.ascii);
|
_interface->processAscii(event.kbd);
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ int SagaEngine::processInput() {
|
||||||
_render->toggleFlag(RF_RENDERPAUSE);
|
_render->toggleFlag(RF_RENDERPAUSE);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
_interface->processAscii(event.kbd.ascii);
|
_interface->processAscii(event.kbd);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -476,22 +476,22 @@ void Interface::setMode(int mode) {
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Interface::processAscii(uint16 ascii) {
|
bool Interface::processAscii(Common::KeyState keystate) {
|
||||||
// TODO: Checking for Esc and Enter below is a bit hackish, and
|
// TODO: Checking for Esc and Enter below is a bit hackish, and
|
||||||
// and probably only works with the English version. Maybe we should
|
// and probably only works with the English version. Maybe we should
|
||||||
// add a flag to the button so it can indicate if it's the default or
|
// add a flag to the button so it can indicate if it's the default or
|
||||||
// cancel button?
|
// cancel button?
|
||||||
|
uint16 ascii = keystate.ascii;
|
||||||
int i;
|
int i;
|
||||||
PanelButton *panelButton;
|
PanelButton *panelButton;
|
||||||
if (_statusTextInput) {
|
if (_statusTextInput) {
|
||||||
processStatusTextInput(ascii);
|
processStatusTextInput(keystate);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (_panelMode) {
|
switch (_panelMode) {
|
||||||
case kPanelNull:
|
case kPanelNull:
|
||||||
if (ascii == 27) { // Esc
|
if (keystate.keycode == Common::KEYCODE_ESCAPE) {
|
||||||
if (_vm->_scene->isInIntro()) {
|
if (_vm->_scene->isInIntro()) {
|
||||||
_vm->_scene->skipScene();
|
_vm->_scene->skipScene();
|
||||||
} else {
|
} else {
|
||||||
|
@ -505,7 +505,7 @@ bool Interface::processAscii(uint16 ascii) {
|
||||||
_vm->_scene->showIHNMDemoSpecialScreen();
|
_vm->_scene->showIHNMDemoSpecialScreen();
|
||||||
break;
|
break;
|
||||||
case kPanelCutaway:
|
case kPanelCutaway:
|
||||||
if (ascii == 27) { // Esc
|
if (keystate.keycode == Common::KEYCODE_ESCAPE) {
|
||||||
if (!_disableAbortSpeeches)
|
if (!_disableAbortSpeeches)
|
||||||
_vm->_actor->abortAllSpeeches();
|
_vm->_actor->abortAllSpeeches();
|
||||||
_vm->_scene->cutawaySkip();
|
_vm->_scene->cutawaySkip();
|
||||||
|
@ -516,7 +516,7 @@ bool Interface::processAscii(uint16 ascii) {
|
||||||
_vm->_scene->showIHNMDemoSpecialScreen();
|
_vm->_scene->showIHNMDemoSpecialScreen();
|
||||||
break;
|
break;
|
||||||
case kPanelVideo:
|
case kPanelVideo:
|
||||||
if (ascii == 27) { // Esc
|
if (keystate.keycode == Common::KEYCODE_ESCAPE) {
|
||||||
if (_vm->_scene->isInIntro()) {
|
if (_vm->_scene->isInIntro()) {
|
||||||
_vm->_scene->skipScene();
|
_vm->_scene->skipScene();
|
||||||
} else {
|
} else {
|
||||||
|
@ -532,7 +532,7 @@ bool Interface::processAscii(uint16 ascii) {
|
||||||
break;
|
break;
|
||||||
case kPanelOption:
|
case kPanelOption:
|
||||||
// TODO: check input dialog keys
|
// TODO: check input dialog keys
|
||||||
if (ascii == 27 || ascii == 13) { // Esc or Enter
|
if (keystate.keycode == Common::KEYCODE_ESCAPE || keystate.keycode == Common::KEYCODE_RETURN) { // Esc or Enter
|
||||||
ascii = 'c'; //continue
|
ascii = 'c'; //continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -547,13 +547,13 @@ bool Interface::processAscii(uint16 ascii) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kPanelSave:
|
case kPanelSave:
|
||||||
if (_textInput && processTextInput(ascii)) {
|
if (_textInput && processTextInput(keystate)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ascii == 27) { // Esc
|
if (keystate.keycode == Common::KEYCODE_ESCAPE) {
|
||||||
ascii = 'c'; // cancel
|
ascii = 'c'; // cancel
|
||||||
} else if (ascii == 13) { // Enter
|
} else if (keystate.keycode == Common::KEYCODE_RETURN) { // Enter
|
||||||
ascii = 's'; // save
|
ascii = 's'; // save
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -568,9 +568,9 @@ bool Interface::processAscii(uint16 ascii) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kPanelQuit:
|
case kPanelQuit:
|
||||||
if (ascii == 27) { // Esc
|
if (keystate.keycode == Common::KEYCODE_ESCAPE) {
|
||||||
ascii = 'c'; // cancel
|
ascii = 'c'; // cancel
|
||||||
} else if (ascii == 13) { // Enter
|
} else if (keystate.keycode == Common::KEYCODE_RETURN) { // Enter
|
||||||
ascii = 'q'; // quit
|
ascii = 'q'; // quit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -608,7 +608,7 @@ bool Interface::processAscii(uint16 ascii) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ascii == 15) { // ctrl-o
|
if (keystate.keycode == Common::KEYCODE_o && keystate.flags == Common::KBD_CTRL) { // ctrl-o
|
||||||
if (_saveReminderState > 0) {
|
if (_saveReminderState > 0) {
|
||||||
setMode(kPanelOption);
|
setMode(kPanelOption);
|
||||||
return true;
|
return true;
|
||||||
|
@ -651,7 +651,7 @@ bool Interface::processAscii(uint16 ascii) {
|
||||||
mapPanelClean();
|
mapPanelClean();
|
||||||
break;
|
break;
|
||||||
case kPanelSceneSubstitute:
|
case kPanelSceneSubstitute:
|
||||||
if (ascii == 13) {
|
if (keystate.keycode == Common::KEYCODE_RETURN) {
|
||||||
_vm->_render->clearFlag(RF_DEMO_SUBST);
|
_vm->_render->clearFlag(RF_DEMO_SUBST);
|
||||||
_vm->_gfx->setPalette(_mapSavedPal);
|
_vm->_gfx->setPalette(_mapSavedPal);
|
||||||
setMode(kPanelMain);
|
setMode(kPanelMain);
|
||||||
|
@ -666,11 +666,11 @@ bool Interface::processAscii(uint16 ascii) {
|
||||||
break;
|
break;
|
||||||
case kPanelProtect:
|
case kPanelProtect:
|
||||||
if (_vm->getGameType() == GType_ITE) {
|
if (_vm->getGameType() == GType_ITE) {
|
||||||
if (_textInput && processTextInput(ascii)) {
|
if (_textInput && processTextInput(keystate)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ascii == 27 || ascii == 13) { // Esc or Enter
|
if (keystate.keycode == Common::KEYCODE_ESCAPE || keystate.keycode == Common::KEYCODE_RETURN) {
|
||||||
_vm->_script->wakeUpThreads(kWaitTypeRequest);
|
_vm->_script->wakeUpThreads(kWaitTypeRequest);
|
||||||
_vm->_interface->setMode(kPanelMain);
|
_vm->_interface->setMode(kPanelMain);
|
||||||
|
|
||||||
|
@ -1113,20 +1113,20 @@ void Interface::setLoad(PanelButton *panelButton) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Interface::processStatusTextInput(uint16 ascii) {
|
void Interface::processStatusTextInput(Common::KeyState keystate) {
|
||||||
|
|
||||||
switch (ascii) {
|
switch (keystate.keycode) {
|
||||||
case 27: // esc
|
case Common::KEYCODE_ESCAPE:
|
||||||
_statusTextInputState = kStatusTextInputAborted;
|
_statusTextInputState = kStatusTextInputAborted;
|
||||||
_statusTextInput = false;
|
_statusTextInput = false;
|
||||||
_vm->_script->wakeUpThreads(kWaitTypeStatusTextInput);
|
_vm->_script->wakeUpThreads(kWaitTypeStatusTextInput);
|
||||||
break;
|
break;
|
||||||
case 13: // return
|
case Common::KEYCODE_RETURN:
|
||||||
_statusTextInputState = kStatusTextInputEntered;
|
_statusTextInputState = kStatusTextInputEntered;
|
||||||
_statusTextInput = false;
|
_statusTextInput = false;
|
||||||
_vm->_script->wakeUpThreads(kWaitTypeStatusTextInput);
|
_vm->_script->wakeUpThreads(kWaitTypeStatusTextInput);
|
||||||
break;
|
break;
|
||||||
case 8: // backspace
|
case Common::KEYCODE_BACKSPACE:
|
||||||
if (_statusTextInputPos == 0) {
|
if (_statusTextInputPos == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1136,18 +1136,15 @@ void Interface::processStatusTextInput(uint16 ascii) {
|
||||||
if (_statusTextInputPos >= STATUS_TEXT_INPUT_MAX) {
|
if (_statusTextInputPos >= STATUS_TEXT_INPUT_MAX) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (((ascii >= 'a') && (ascii <='z')) ||
|
if (isalnum(keystate.ascii) || (keystate.ascii == ' ')) {
|
||||||
((ascii >= '0') && (ascii <='9')) ||
|
_statusTextInputString[_statusTextInputPos++] = keystate.ascii;
|
||||||
((ascii >= 'A') && (ascii <='Z')) ||
|
|
||||||
(ascii == ' ')) {
|
|
||||||
_statusTextInputString[_statusTextInputPos++] = ascii;
|
|
||||||
_statusTextInputString[_statusTextInputPos] = 0;
|
_statusTextInputString[_statusTextInputPos] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setStatusText(_statusTextInputString);
|
setStatusText(_statusTextInputString);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Interface::processTextInput(uint16 ascii) {
|
bool Interface::processTextInput(Common::KeyState keystate) {
|
||||||
char ch[2];
|
char ch[2];
|
||||||
char tempString[SAVE_TITLE_SIZE];
|
char tempString[SAVE_TITLE_SIZE];
|
||||||
uint tempWidth;
|
uint tempWidth;
|
||||||
|
@ -1157,18 +1154,18 @@ bool Interface::processTextInput(uint16 ascii) {
|
||||||
// in IHNM, to preserve backwards compatibility with older save games
|
// in IHNM, to preserve backwards compatibility with older save games
|
||||||
uint save_title_size = _vm->getGameType() == GType_ITE ? SAVE_TITLE_SIZE : IHNM_SAVE_TITLE_SIZE;
|
uint save_title_size = _vm->getGameType() == GType_ITE ? SAVE_TITLE_SIZE : IHNM_SAVE_TITLE_SIZE;
|
||||||
|
|
||||||
switch (ascii) {
|
switch (keystate.keycode) {
|
||||||
case 13:
|
case Common::KEYCODE_RETURN:
|
||||||
return false;
|
return false;
|
||||||
case 27: // esc
|
case Common::KEYCODE_ESCAPE:
|
||||||
_textInput = false;
|
_textInput = false;
|
||||||
break;
|
break;
|
||||||
case 8: // backspace
|
case Common::KEYCODE_BACKSPACE:
|
||||||
if (_textInputPos <= 1) {
|
if (_textInputPos <= 1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_textInputPos--;
|
_textInputPos--;
|
||||||
case 127: // del
|
case Common::KEYCODE_DELETE:
|
||||||
if (_textInputPos <= _textInputStringLength) {
|
if (_textInputPos <= _textInputStringLength) {
|
||||||
if (_textInputPos != 1) {
|
if (_textInputPos != 1) {
|
||||||
strncpy(tempString, _textInputString, _textInputPos - 1);
|
strncpy(tempString, _textInputString, _textInputPos - 1);
|
||||||
|
@ -1180,23 +1177,21 @@ bool Interface::processTextInput(uint16 ascii) {
|
||||||
_textInputStringLength = strlen(_textInputString);
|
_textInputStringLength = strlen(_textInputString);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 276: // left
|
case Common::KEYCODE_LEFT:
|
||||||
if (_textInputPos > 1) {
|
if (_textInputPos > 1) {
|
||||||
_textInputPos--;
|
_textInputPos--;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 275: // right
|
case Common::KEYCODE_RIGHT:
|
||||||
if (_textInputPos <= _textInputStringLength) {
|
if (_textInputPos <= _textInputStringLength) {
|
||||||
_textInputPos++;
|
_textInputPos++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (((ascii >= 'a') && (ascii <='z')) ||
|
if (isalnum(keystate.ascii) || (keystate.ascii == ' ') ||
|
||||||
((ascii >= '0') && (ascii <='9')) ||
|
(keystate.ascii == '-') || (keystate.ascii == '_')) {
|
||||||
((ascii >= 'A') && (ascii <='Z')) ||
|
|
||||||
(ascii == ' ') || (ascii == '-') || (ascii == '_')) {
|
|
||||||
if (_textInputStringLength < save_title_size - 1) {
|
if (_textInputStringLength < save_title_size - 1) {
|
||||||
ch[0] = ascii;
|
ch[0] = keystate.ascii;
|
||||||
tempWidth = _vm->_font->getStringWidth(kKnownFontSmall, ch, 0, kFontNormal);
|
tempWidth = _vm->_font->getStringWidth(kKnownFontSmall, ch, 0, kFontNormal);
|
||||||
tempWidth += _vm->_font->getStringWidth(kKnownFontSmall, _textInputString, 0, kFontNormal);
|
tempWidth += _vm->_font->getStringWidth(kKnownFontSmall, _textInputString, 0, kFontNormal);
|
||||||
if (tempWidth > _textInputMaxWidth) {
|
if (tempWidth > _textInputMaxWidth) {
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#ifndef SAGA_INTERFACE_H
|
#ifndef SAGA_INTERFACE_H
|
||||||
#define SAGA_INTERFACE_H
|
#define SAGA_INTERFACE_H
|
||||||
|
|
||||||
|
#include "common/keyboard.h"
|
||||||
#include "common/savefile.h"
|
#include "common/savefile.h"
|
||||||
|
|
||||||
#include "saga/displayinfo.h"
|
#include "saga/displayinfo.h"
|
||||||
|
@ -225,7 +226,7 @@ public:
|
||||||
void drawStatusBar();
|
void drawStatusBar();
|
||||||
void setVerbState(int verb, int state);
|
void setVerbState(int verb, int state);
|
||||||
|
|
||||||
bool processAscii(uint16 ascii);
|
bool processAscii(Common::KeyState keystate);
|
||||||
|
|
||||||
void keyBoss();
|
void keyBoss();
|
||||||
void keyBossExit();
|
void keyBossExit();
|
||||||
|
@ -341,8 +342,8 @@ private:
|
||||||
void drawVerbPanelText(Surface *ds, PanelButton *panelButton, KnownColor textKnownColor, KnownColor textShadowKnownColor);
|
void drawVerbPanelText(Surface *ds, PanelButton *panelButton, KnownColor textKnownColor, KnownColor textShadowKnownColor);
|
||||||
void drawVerbPanel(Surface *backBuffer, PanelButton* panelButton);
|
void drawVerbPanel(Surface *backBuffer, PanelButton* panelButton);
|
||||||
void calcOptionSaveSlider();
|
void calcOptionSaveSlider();
|
||||||
bool processTextInput(uint16 ascii);
|
bool processTextInput(Common::KeyState keystate);
|
||||||
void processStatusTextInput(uint16 ascii);
|
void processStatusTextInput(Common::KeyState keystate);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void converseInit(void);
|
void converseInit(void);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue