LILLIPUT: Start implementing keyboard handling

This commit is contained in:
Strangerke 2012-05-31 08:29:02 +02:00 committed by Eugene Sandulenko
parent 8ce9bac02a
commit f625b60117
3 changed files with 29 additions and 9 deletions

View file

@ -2332,7 +2332,18 @@ void LilliputEngine::pollEvent() {
case Common::EVENT_QUIT:
_shouldQuit = true;
break;
// TODO: handle keyboard
case Common::EVENT_KEYDOWN: {
if (event.kbd == _lastKeyPressed)
break;
_lastKeyPressed = event.kbd;
int nextIndex = (_keyboard_nextIndex + 1) % 8;
if (_keyboard_oldIndex != nextIndex) {
_keyboard_buffer[_keyboard_nextIndex] = event.kbd;
_keyboard_nextIndex = nextIndex;
}
}
break;
default:
break;
}
@ -2808,9 +2819,15 @@ Common::String LilliputEngine::getSavegameFilename(int slot) {
return _targetName + Common::String::format("-%02d.SAV", slot);
}
byte LilliputEngine::_keyboard_getch() {
Common::KeyState LilliputEngine::_keyboard_getch() {
warning("getch()");
return ' ';
while(_keyboard_nextIndex == _keyboard_oldIndex)
pollEvent();
Common::KeyState tmpEvent = _keyboard_buffer[_keyboard_oldIndex];
_keyboard_oldIndex = (_keyboard_oldIndex + 1) % 8;
return tmpEvent;
}
} // End of namespace Lilliput

View file

@ -30,6 +30,7 @@
#include "common/file.h"
#include "common/rect.h"
#include "common/events.h"
#include "engines/engine.h"
#include "graphics/palette.h"
@ -104,9 +105,10 @@ public:
byte _animationTick;
Common::Point _nextDisplayCharacterPos;
byte _sound_byte16F06;
byte _lastKeyPressed;
Common::KeyState _lastKeyPressed;
byte _keyboard_nextIndex;
byte _keyboard_oldIndex;
Common::KeyState _keyboard_buffer[8];
byte _byte12A05;
byte _byte12A06;
byte _byte12A07;
@ -359,7 +361,7 @@ public:
byte *getCharacterVariablesPtr(int16 index);
// Temporary stubs
byte _keyboard_getch();
Common::KeyState _keyboard_getch();
protected:
Common::EventManager *_eventMan;

View file

@ -2059,7 +2059,7 @@ byte LilliputScript::OC_checkKeyPressed() {
int8 index = (_currScript->readUint16LE() & 0xFF) - 0x30;
if (specialKeys[index] == _vm->_lastKeyPressed)
if (specialKeys[index] == _vm->_lastKeyPressed.keycode)
return 1;
return 0;
@ -3156,11 +3156,12 @@ void LilliputScript::OC_displayTitleScreen() {
_vm->_keyboard_oldIndex = 0;
//
_vm->_mouseButton = 0;
_vm->_lastKeyPressed = 0;
// _vm->_lastKeyPressed = 0;
while (!_vm->_shouldQuit) {
_vm->displaySmallAnims();
_vm->update();
_vm->pollEvent();
if (_vm->_keyboard_nextIndex != _vm->_keyboard_oldIndex) {
_vm->_lastKeyPressed = _vm->_keyboard_getch();
_vm->_keyboard_getch();