TITANIC: Implement input translator event methods

This commit is contained in:
Paul Gilbert 2016-03-18 21:34:04 -04:00
parent 61947ef56b
commit 9565fbaeac
16 changed files with 360 additions and 18 deletions

View File

@ -856,6 +856,9 @@ DEFFN(CPhonographRecordMsg)
DEFFN(CPhonographStopMsg)
DEFFN(CPlayRangeMsg)
DEFFN(CPlayerTriesRestaurantTableMsg)
DEFFN(CPreEnterNodeMsg);
DEFFN(CPreEnterRoomMsg);
DEFFN(CPreEnterViewMsg);
DEFFN(CPreSaveMsg)
DEFFN(CProdMaitreDMsg)
DEFFN(CPumpingMsg)
@ -1426,6 +1429,9 @@ void CSaveableObject::initClassList() {
ADDFN(CPhonographStopMsg, CMessage);
ADDFN(CPlayRangeMsg, CMessage);
ADDFN(CPlayerTriesRestaurantTableMsg, CMessage);
ADDFN(CEnterNodeMsg, CMessage);
ADDFN(CEnterRoomMsg, CMessage);
ADDFN(CEnterViewMsg, CMessage);
ADDFN(CPreSaveMsg, CMessage);
ADDFN(CProdMaitreDMsg, CMessage);
ADDFN(CPumpingMsg, CMessage);

View File

@ -26,31 +26,46 @@
#include "engines/util.h"
#include "titanic/events.h"
#include "titanic/titanic.h"
#include "titanic/main_game_window.h"
namespace Titanic {
Events::Events(TitanicEngine *vm): _vm(vm),
_frameCounter(1), _priorFrameTime(0) {
Events::Events(TitanicEngine *vm): _vm(vm), _specialButtons(0),
_frameCounter(1), _priorFrameTime(0), _priorLeftDownTime(0),
_priorMiddleDownTime(0), _priorRightDownTime(0) {
}
void Events::pollEvents() {
checkForNextFrameCounter();
Common::Event event;
g_system->getEventManager()->pollEvent(event);
// Give time to the debugger
_vm->_debugger->onFrame();
if (!g_system->getEventManager()->pollEvent(event))
return;
switch (event.type) {
case Common::EVENT_KEYDOWN:
if (event.kbd.keycode == Common::KEYCODE_d && (event.kbd.flags & Common::KBD_CTRL)) {
// Attach to the debugger
_vm->_debugger->attach();
_vm->_debugger->onFrame();
}
case Common::EVENT_MOUSEMOVE:
_mousePos = event.mouse;
mouseMove();
break;
case Common::EVENT_LBUTTONDOWN:
_mousePos = event.mouse;
leftButtonDown();
break;
case Common::EVENT_LBUTTONUP:
_mousePos = event.mouse;
leftButtonUp();
break;
case Common::EVENT_MBUTTONDOWN:
_mousePos = event.mouse;
middleButtonDown();
break;
case Common::EVENT_MBUTTONUP:
_mousePos = event.mouse;
middleButtonUp();
break;
case Common::EVENT_KEYDOWN:
keyDown(event.kbd);
break;
default:
break;
}
@ -84,5 +99,89 @@ uint32 Events::getTicksCount() const {
return g_system->getMillis();
}
#define HANDLE_MESSAGE(method) if (_vm->_window->_inputAllowed) { \
_vm->_window->_gameManager->_inputTranslator.leftButtonDown(_specialButtons, _mousePos); \
_vm->_window->mouseChanged(); \
}
void Events::mouseMove() {
HANDLE_MESSAGE(mouseMove)
}
void Events::leftButtonDown() {
_specialButtons |= MK_LBUTTON;
if ((getTicksCount() - _priorLeftDownTime) < DOUBLE_CLICK_TIME) {
_priorLeftDownTime = 0;
leftButtonDoubleClick();
} else {
_priorLeftDownTime = getTicksCount();
HANDLE_MESSAGE(leftButtonDown)
}
}
void Events::leftButtonUp() {
_specialButtons &= ~MK_LBUTTON;
HANDLE_MESSAGE(leftButtonUp)
}
void Events::leftButtonDoubleClick() {
HANDLE_MESSAGE(leftButtonDoubleClick)
}
void Events::middleButtonDown() {
_specialButtons |= MK_MBUTTON;
if ((getTicksCount() - _priorMiddleDownTime) < DOUBLE_CLICK_TIME) {
_priorMiddleDownTime = 0;
middleButtonDoubleClick();
} else {
_priorMiddleDownTime = getTicksCount();
HANDLE_MESSAGE(middleButtonDown)
}
}
void Events::middleButtonUp() {
_specialButtons &= ~MK_MBUTTON;
HANDLE_MESSAGE(middleButtonUp)
}
void Events::middleButtonDoubleClick() {
HANDLE_MESSAGE(middleButtonDoubleClick)
}
void Events::rightButtonDown() {
_specialButtons |= MK_RBUTTON;
if ((getTicksCount() - _priorRightDownTime) < DOUBLE_CLICK_TIME) {
_priorRightDownTime = 0;
rightButtonDoubleClick();
} else {
_priorRightDownTime = getTicksCount();
HANDLE_MESSAGE(rightButtonDown)
}
}
void Events::rightButtonUp() {
_specialButtons &= ~MK_RBUTTON;
HANDLE_MESSAGE(rightButtonUp)
}
void Events::rightButtonDoubleClick() {
HANDLE_MESSAGE(rightButtonDoubleClick)
}
void Events::charPress(char c) {
}
void Events::keyDown(Common::KeyState keyState) {
if (keyState.keycode == Common::KEYCODE_d && (keyState.flags & Common::KBD_CTRL)) {
// Attach to the debugger
_vm->_debugger->attach();
_vm->_debugger->onFrame();
}
}
} // End of namespace Titanic

View File

@ -30,6 +30,12 @@ namespace Titanic {
#define GAME_FRAME_RATE 30
#define GAME_FRAME_TIME (1000 / GAME_FRAME_RATE)
#define DOUBLE_CLICK_TIME 100
enum SpecialButtons {
MK_LBUTTON = 1, MK_RBUTTON = 2, MK_SHIFT = 4, MK_CONTROL = 8,
MK_MBUTTON = 0x10
};
class TitanicEngine;
@ -38,11 +44,29 @@ private:
TitanicEngine *_vm;
uint32 _frameCounter;
uint32 _priorFrameTime;
uint32 _priorLeftDownTime;
uint32 _priorMiddleDownTime;
uint32 _priorRightDownTime;
Common::Point _mousePos;
int _specialButtons;
/**
* Check whether it's time to display the next screen frame
*/
bool checkForNextFrameCounter();
void mouseMove();
void leftButtonDown();
void leftButtonUp();
void leftButtonDoubleClick();
void middleButtonDown();
void middleButtonUp();
void middleButtonDoubleClick();
void rightButtonDown();
void rightButtonUp();
void rightButtonDoubleClick();
void charPress(char c);
void keyDown(Common::KeyState keyState);
public:
Events(TitanicEngine *vm);
~Events() {}

View File

@ -62,4 +62,8 @@ bool CFilesManager::scanForFile(const CString &name) {
return fileExists(fname);
}
void CFilesManager::fn1() {
warning("TODO: CFilesManager::fn1");
}
} // End of namespace Titanic

View File

@ -63,6 +63,8 @@ public:
* Scans for a file with a matching name
*/
bool scanForFile(const CString &name);
void fn1();
};
} // End of namespace Titanic

View File

@ -96,4 +96,8 @@ void CGameManager::fn2() {
warning("TODO");
}
void CGameManager::update() {
warning("TODO: CGameManager::update");
}
} // End of namespace Titanic

View File

@ -54,8 +54,6 @@ class CGameManager {
private:
CGameView *_gameView;
CSound _sound;
CInputHandler _inputHandler;
CInputTranslator _inputTranslator;
CMusicRoom _musicRoom;
CTrueTalkManager _trueTalkManager;
CGameManagerList _list;
@ -72,6 +70,8 @@ public:
CProjectItem *_project;
CGameState _gameState;
Common::Rect _bounds;
CInputHandler _inputHandler;
CInputTranslator _inputTranslator;
public:
CGameManager(CProjectItem *project, CGameView *gameView);
~CGameManager();
@ -104,6 +104,11 @@ public:
void initBounds();
void fn2();
/**
* Updates the state of the manager
*/
void update();
};
} // End of namespace Titanic

View File

@ -21,7 +21,9 @@
*/
#include "titanic/input_handler.h"
#include "titanic/game_manager.h"
#include "titanic/screen_manager.h"
#include "titanic/titanic.h"
namespace Titanic {
@ -46,4 +48,18 @@ void CInputHandler::decLockCount() {
}
}
void CInputHandler::handleMessage(const CMessage &msg, bool respectLock) {
if (!respectLock || _lockCount <= 0) {
if (_gameManager->_gameState._mode == GSMODE_1) {
processMessage(msg);
} else if (!msg.isMouseMsg()) {
g_vm->_filesManager.fn1();
}
}
}
void CInputHandler::processMessage(const CMessage &msg) {
warning("TODO: CInputHandler::processMessage");
}
} // End of namespace Titanic z

View File

@ -31,6 +31,11 @@ namespace Titanic {
class CGameManager;
class CInputHandler {
private:
/**
* Process and dispatch a passed message
*/
void processMessage(const CMessage &msg);
public:
CGameManager *_gameManager;
CInputTranslator *_inputTranslator;
@ -56,6 +61,11 @@ public:
* Decrement the lock count on the input handler
*/
void decLockCount();
/**
* Handles a genereated mouse message
*/
void handleMessage(const CMessage &msg, bool respectLock = true);
};
} // End of namespace Titanic

View File

@ -22,6 +22,8 @@
#include "titanic/input_handler.h"
#include "titanic/input_translator.h"
#include "titanic/events.h"
#include "titanic/messages/mouse_messages.h"
namespace Titanic {
@ -30,4 +32,57 @@ CInputTranslator::CInputTranslator(CInputHandler *inputHandler) :
inputHandler->setTranslator(this);
}
} // End of namespace Titanic z
int CInputTranslator::getButtons(int special) const {
int buttons = 0;
if (special & MK_LBUTTON)
buttons |= MB_LEFT;
if (special & MK_MBUTTON)
buttons |= MB_MIDDLE;
if (special & MK_RBUTTON)
buttons |= MB_RIGHT;
return buttons;
}
void CInputTranslator::mouseMove(int special, const Common::Point &pt) {
CMouseMoveMsg msg(pt, getButtons(special));
_inputHandler->handleMessage(msg);
}
void CInputTranslator::leftButtonDown(int special, const Common::Point &pt) {
}
void CInputTranslator::leftButtonUp(int special, const Common::Point &pt) {
}
void CInputTranslator::leftButtonDoubleClick(int special, const Common::Point &pt) {
}
void CInputTranslator::middleButtonDown(int special, const Common::Point &pt) {
}
void CInputTranslator::middleButtonUp(int special, const Common::Point &pt) {
}
void CInputTranslator::middleButtonDoubleClick(int special, const Common::Point &pt) {
}
void CInputTranslator::rightButtonDown(int special, const Common::Point &pt) {
}
void CInputTranslator::rightButtonUp(int special, const Common::Point &pt) {
}
void CInputTranslator::rightButtonDoubleClick(int special, const Common::Point &pt) {
}
} // End of namespace Titanic

View File

@ -23,15 +23,33 @@
#ifndef TITANIC_INPUT_TRANSLATOR_H
#define TITANIC_INPUT_TRANSLATOR_H
#include "titanic/messages/mouse_messages.h"
namespace Titanic {
class CInputHandler;
class CInputTranslator {
private:
/**
* Converts the special buttons bitset into a buttons bitset
*/
int getButtons(int special) const;
public:
CInputHandler *_inputHandler;
public:
CInputTranslator(CInputHandler *inputHandler);
void mouseMove(int special, const Common::Point &pt);
void leftButtonDown(int special, const Common::Point &pt);
void leftButtonUp(int special, const Common::Point &pt);
void leftButtonDoubleClick(int special, const Common::Point &pt);
void middleButtonDown(int special, const Common::Point &pt);
void middleButtonUp(int special, const Common::Point &pt);
void middleButtonDoubleClick(int special, const Common::Point &pt);
void rightButtonDown(int special, const Common::Point &pt);
void rightButtonUp(int special, const Common::Point &pt);
void rightButtonDoubleClick(int special, const Common::Point &pt);
};
} // End of namespace Titanic

View File

@ -32,7 +32,7 @@ CMainGameWindow::CMainGameWindow(TitanicEngine *vm): _vm(vm) {
_gameView = nullptr;
_gameManager = nullptr;
_project = nullptr;
_field50 = 0;
_inputAllowed = false;
_image = nullptr;
_cursor = nullptr;
}
@ -134,4 +134,9 @@ void CMainGameWindow::fn2() {
}
}
void CMainGameWindow::mouseChanged() {
if (_gameManager->_gameState._mode != GSMODE_5)
_gameManager->update();
}
} // End of namespace Titanic

View File

@ -53,7 +53,7 @@ public:
CGameView *_gameView;
CGameManager *_gameManager;
CProjectItem *_project;
int _field50;
bool _inputAllowed;
Image *_image;
void *_cursor;
public:
@ -75,6 +75,11 @@ public:
void setActiveView(CViewItem *viewItem);
void fn2();
/**
* Called by the event handler when a mouse event has been generated
*/
void mouseChanged();
};
} // End of namespace Titanic

View File

@ -21,6 +21,7 @@
*/
#include "titanic/messages/messages.h"
#include "titanic/messages/mouse_messages.h"
#include "titanic/core/game_object.h"
#include "titanic/core/tree_item.h"
@ -66,4 +67,60 @@ bool CMessage::execute(CTreeItem *target, const ClassDef *classDef, int flags) c
return result;
}
bool CMessage::isMouseMsg() const {
return dynamic_cast<const CMouseMsg *>(this) != nullptr;
}
bool CMessage::isButtonDownMsg() const {
return dynamic_cast<const CMouseButtonDownMsg *>(this) != nullptr;
}
bool CMessage::isButtonUpMsg() const {
return dynamic_cast<const CMouseButtonUpMsg *>(this) != nullptr;
}
bool CMessage::isMouseMoveMsg() const {
return dynamic_cast<const CMouseMoveMsg *>(this) != nullptr;
}
bool CMessage::isDoubleClickMsg() const {
return dynamic_cast<const CMouseButtonDoubleClickMsg *>(this) != nullptr;
}
bool CMessage::isEnterRoomMsg() const {
return dynamic_cast<const CEnterRoomMsg *>(this) != nullptr;
}
bool CMessage::isPreEnterRoomMsg() const {
return dynamic_cast<const CPreEnterRoomMsg *>(this) != nullptr;
}
bool CMessage::isleaveRoomMsg() const {
return dynamic_cast<const CLeaveRoomMsg *>(this) != nullptr;
}
bool CMessage::isEnterNodeMsg() const {
return dynamic_cast<const CEnterNodeMsg *>(this) != nullptr;
}
bool CMessage::isPreEnterNodeMsg() const {
return dynamic_cast<const CPreEnterNodeMsg *>(this) != nullptr;
}
bool CMessage::isLeaveNodeMsg() const {
return dynamic_cast<const CLeaveNodeMsg *>(this) != nullptr;
}
bool CMessage::isEnterViewMsg() const {
return dynamic_cast<const CEnterViewMsg *>(this) != nullptr;
}
bool CMessage::isPreEnterViewMsg() const {
return dynamic_cast<const CPreEnterViewMsg *>(this) != nullptr;
}
bool CMessage::isLeaveViewMsg() const {
return dynamic_cast<const CLeaveViewMsg *>(this) != nullptr;
}
} // End of namespace Titanic

View File

@ -59,6 +59,21 @@ public:
* Load the data for the class from file
*/
virtual void load(SimpleFile *file);
virtual bool isMouseMsg() const;
virtual bool isButtonDownMsg() const;
virtual bool isButtonUpMsg() const;
virtual bool isMouseMoveMsg() const;
virtual bool isDoubleClickMsg() const;
virtual bool isEnterRoomMsg() const;
virtual bool isPreEnterRoomMsg() const;
virtual bool isleaveRoomMsg() const;
virtual bool isEnterNodeMsg() const;
virtual bool isPreEnterNodeMsg() const;
virtual bool isLeaveNodeMsg() const;
virtual bool isEnterViewMsg() const;
virtual bool isPreEnterViewMsg() const;
virtual bool isLeaveViewMsg() const;
};
MSGTARGET(CEditControlMsg);
@ -244,6 +259,9 @@ MESSAGE1(CDropobjectMsg, int, value, 0);
MESSAGE1(CDropZoneGotObjectMsg, int, value, 0);
MESSAGE1(CDropZoneLostObjectMsg, int, value, 0);
MESSAGE1(CEjectCylinderMsg, int, value, 0);
MESSAGE1(CPreEnterNodeMsg, CNodeItem *, node, nullptr);
MESSAGE1(CPreEnterRoomMsg, CRoomItem *, room, nullptr);
MESSAGE1(CPreEnterViewMsg, CViewItem *, view, nullptr);
MESSAGE1(CEnterNodeMsg, CNodeItem *, node, nullptr);
MESSAGE1(CEnterRoomMsg, CRoomItem *, room, nullptr);
MESSAGE1(CEnterViewMsg, CViewItem *, view, nullptr);

View File

@ -23,10 +23,13 @@
#ifndef TITANIC_MOUSE_MESSAGES_H
#define TITANIC_MOUSE_MESSAGES_H
#include "common/rect.h"
#include "titanic/messages/messages.h"
namespace Titanic {
enum MouseButton { MB_LEFT = 1, MB_MIDDLE = 2, MB_RIGHT = 4 };
class CMouseMsg : public CMessage {
public:
int _buttons;
@ -34,12 +37,16 @@ public:
public:
CLASSDEF
CMouseMsg() : _buttons(0) {}
CMouseMsg(const Common::Point &pt, int buttons) :
_mousePos(pt), _buttons(buttons) {}
};
MSGTARGET(CMouseMoveMsg);
class CMouseMoveMsg : public CMouseMsg {
public:
CLASSDEF
CMouseMoveMsg() : CMouseMsg() {}
CMouseMoveMsg(const Common::Point &pt, int buttons) : CMouseMsg(pt, buttons) {}
virtual bool handleMessage(const CMouseMoveMsg &msg) { return false; }
virtual bool perform(CTreeItem *treeItem) {
@ -54,12 +61,15 @@ public:
public:
CLASSDEF
CMouseButtonMsg() : CMouseMsg(), _field10(0) {}
CMouseButtonMsg(const Common::Point &pt, int buttons) : CMouseMsg(pt, buttons) {}
};
MSGTARGET(CMouseButtonDownMsg);
class CMouseButtonDownMsg : public CMouseButtonMsg {
public:
CLASSDEF
CMouseButtonDownMsg() : CMouseButtonMsg() {}
CMouseButtonDownMsg(const Common::Point &pt, int buttons) : CMouseButtonMsg(pt, buttons) {}
virtual bool handleMessage(const CMouseButtonDownMsg &msg) { return false; }
virtual bool perform(CTreeItem *treeItem) {
@ -72,6 +82,8 @@ MSGTARGET(CMouseButtonUpMsg);
class CMouseButtonUpMsg : public CMouseButtonMsg {
public:
CLASSDEF
CMouseButtonUpMsg() : CMouseButtonMsg() {}
CMouseButtonUpMsg(const Common::Point &pt, int buttons) : CMouseButtonMsg(pt, buttons) {}
virtual bool handleMessage(const CMouseButtonUpMsg &msg) { return false; }
virtual bool perform(CTreeItem *treeItem) {
@ -84,6 +96,8 @@ MSGTARGET(CMouseButtonDoubleClickMsg);
class CMouseButtonDoubleClickMsg : public CMouseButtonMsg {
public:
CLASSDEF
CMouseButtonDoubleClickMsg() : CMouseButtonMsg() {}
CMouseButtonDoubleClickMsg(const Common::Point &pt, int buttons) : CMouseButtonMsg(pt, buttons) {}
virtual bool handleMessage(const CMouseButtonDoubleClickMsg &msg) { return false; }
virtual bool perform(CTreeItem *treeItem) {