TITANIC: Implemented drag/drop handling
This commit is contained in:
parent
9565fbaeac
commit
7a38b51357
7 changed files with 123 additions and 21 deletions
|
@ -48,7 +48,7 @@ CGameManager::CGameManager(CProjectItem *project, CGameView *gameView):
|
|||
_inputHandler(this), _inputTranslator(&_inputHandler),
|
||||
_gameState(this), _sound(this), _musicRoom(this),
|
||||
_field30(0), _field34(0), _field4C(0),
|
||||
_field50(0), _field54(0), _tickCount1(0), _tickCount2(0) {
|
||||
_dragItem(nullptr), _field54(0), _tickCount1(0), _tickCount2(0) {
|
||||
|
||||
_videoSurface1 = nullptr;
|
||||
_videoSurface2 = CScreenManager::_screenManagerPtr->createSurface(600, 340);
|
||||
|
|
|
@ -61,7 +61,6 @@ private:
|
|||
int _field34;
|
||||
CVideoSurface *_videoSurface1;
|
||||
int _field4C;
|
||||
int _field50;
|
||||
int _field54;
|
||||
CVideoSurface *_videoSurface2;
|
||||
uint _tickCount1;
|
||||
|
@ -72,6 +71,7 @@ public:
|
|||
Common::Rect _bounds;
|
||||
CInputHandler _inputHandler;
|
||||
CInputTranslator _inputTranslator;
|
||||
CTreeItem *_dragItem;
|
||||
public:
|
||||
CGameManager(CProjectItem *project, CGameView *gameView);
|
||||
~CGameManager();
|
||||
|
|
|
@ -30,7 +30,7 @@ CGameState::CGameState(CGameManager *gameManager) :
|
|||
_gameManager(gameManager), _gameLocation(this),
|
||||
_field8(0), _fieldC(0), _mode(GSMODE_0), _field14(0), _field18(0),
|
||||
_field1C(0), _field20(0), _field24(0), _field28(0), _field2C(0),
|
||||
_field30(0), _field34(0), _field38(0) {
|
||||
_field38(0) {
|
||||
}
|
||||
|
||||
void CGameState::save(SimpleFile *file) const {
|
||||
|
@ -78,4 +78,8 @@ void CGameState::setMode(GameStateMode newMode) {
|
|||
_mode = newMode;
|
||||
}
|
||||
|
||||
void CGameState::setMousePos(const Common::Point &pt) {
|
||||
_mousePos = pt;
|
||||
}
|
||||
|
||||
} // End of namespace Titanic z
|
||||
|
|
|
@ -56,8 +56,7 @@ public:
|
|||
int _field24;
|
||||
int _field28;
|
||||
int _field2C;
|
||||
int _field30;
|
||||
int _field34;
|
||||
Common::Point _mousePos;
|
||||
int _field38;
|
||||
public:
|
||||
CGameState(CGameManager *gameManager);
|
||||
|
@ -76,6 +75,11 @@ public:
|
|||
* Sets a new mode
|
||||
*/
|
||||
void setMode(GameStateMode newMode);
|
||||
|
||||
/**
|
||||
* Sets the current mouse position
|
||||
*/
|
||||
void setMousePos(const Common::Point &pt);
|
||||
};
|
||||
|
||||
} // End of namespace Titanic
|
||||
|
|
|
@ -24,13 +24,13 @@
|
|||
#include "titanic/game_manager.h"
|
||||
#include "titanic/screen_manager.h"
|
||||
#include "titanic/titanic.h"
|
||||
#include "titanic/pet_control/pet_control.h"
|
||||
|
||||
namespace Titanic {
|
||||
|
||||
CInputHandler::CInputHandler(CGameManager *owner) :
|
||||
_gameManager(owner), _inputTranslator(nullptr),
|
||||
_field4(0), _field8(0), _fieldC(0), _field10(0), _field14(0),
|
||||
_lockCount(0), _field24(0) {
|
||||
_gameManager(owner), _inputTranslator(nullptr), _dragging(false),
|
||||
_buttonDown(false), _dragItem(nullptr), _lockCount(0), _field24(0) {
|
||||
CScreenManager::_screenManagerPtr->_inputHandler = this;
|
||||
}
|
||||
|
||||
|
@ -51,15 +51,91 @@ void CInputHandler::decLockCount() {
|
|||
void CInputHandler::handleMessage(const CMessage &msg, bool respectLock) {
|
||||
if (!respectLock || _lockCount <= 0) {
|
||||
if (_gameManager->_gameState._mode == GSMODE_1) {
|
||||
processMessage(msg);
|
||||
processMessage(&msg);
|
||||
} else if (!msg.isMouseMsg()) {
|
||||
g_vm->_filesManager.fn1();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CInputHandler::processMessage(const CMessage &msg) {
|
||||
warning("TODO: CInputHandler::processMessage");
|
||||
void CInputHandler::processMessage(const CMessage *msg) {
|
||||
const CMouseMsg *mouseMsg = dynamic_cast<const CMouseMsg *>(msg);
|
||||
_field24 = 0;
|
||||
dispatchMessage(msg);
|
||||
|
||||
if (_field24) {
|
||||
_field24 = 0;
|
||||
} else if (mouseMsg) {
|
||||
// Keep the game state mouse position up to date
|
||||
if (_mousePos != mouseMsg->_mousePos) {
|
||||
_mousePos = mouseMsg->_mousePos;
|
||||
_gameManager->_gameState.setMousePos(mouseMsg->_mousePos);
|
||||
}
|
||||
|
||||
// Set flag for whether a mouse button is currently being pressed
|
||||
if (mouseMsg->isButtonDownMsg())
|
||||
_buttonDown = true;
|
||||
else if (mouseMsg->isButtonUpMsg())
|
||||
_buttonDown = false;
|
||||
|
||||
// Drag events generation
|
||||
if (_dragging) {
|
||||
if (mouseMsg->isMouseMoveMsg()) {
|
||||
if (_dragItem) {
|
||||
CMouseDragMoveMsg moveMsg(_mousePos);
|
||||
moveMsg.execute(_dragItem);
|
||||
}
|
||||
} else {
|
||||
if (mouseMsg->isButtonUpMsg() && _dragItem) {
|
||||
// Mouse drag ended
|
||||
dragEnd(_mousePos, _dragItem);
|
||||
CMouseDragEndMsg endMsg(_mousePos, _dragItem);
|
||||
endMsg.execute(_dragItem);
|
||||
}
|
||||
|
||||
_dragging = false;
|
||||
_dragItem = nullptr;
|
||||
}
|
||||
} else if (_buttonDown) {
|
||||
if (!mouseMsg->isMouseMoveMsg()) {
|
||||
// Save where the drag movement started from
|
||||
_dragStartPos = _mousePos;
|
||||
} else {
|
||||
Common::Point delta = mouseMsg->_mousePos - _dragStartPos;
|
||||
int distance = (int)sqrt(double(delta.x * delta.x + delta.y * delta.y));
|
||||
|
||||
if (distance > 4) {
|
||||
// We've moved far enough with the mouse button held down
|
||||
// to trigger an official dragging operation
|
||||
CMouseDragStartMsg startMsg(_dragStartPos);
|
||||
dispatchMessage(&startMsg);
|
||||
|
||||
// Set the drag item, if any, that a handler will have set on the message
|
||||
_dragItem = startMsg._dragItem;
|
||||
_gameManager->_dragItem = startMsg._dragItem;
|
||||
|
||||
if (_dragItem) {
|
||||
CMouseDragMoveMsg moveMsg(_dragStartPos);
|
||||
dispatchMessage(&moveMsg);
|
||||
}
|
||||
|
||||
_dragging = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CInputHandler::dispatchMessage(const CMessage *msg) {
|
||||
CPetControl *pet = _gameManager->_project->getPetControl();
|
||||
if (!pet || !msg->execute(pet, nullptr, MSGFLAG_BREAK_IF_HANDLED)) {
|
||||
CViewItem *view = _gameManager->getView();
|
||||
msg->execute(view);
|
||||
}
|
||||
}
|
||||
|
||||
void CInputHandler::dragEnd(const Common::Point &mousePos, CTreeItem *dragItem) {
|
||||
warning("TODO CInputHandler::dragEnd");
|
||||
}
|
||||
|
||||
} // End of namespace Titanic z
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include "common/rect.h"
|
||||
#include "titanic/input_translator.h"
|
||||
#include "titanic/core/tree_item.h"
|
||||
|
||||
namespace Titanic {
|
||||
|
||||
|
@ -35,15 +36,24 @@ private:
|
|||
/**
|
||||
* Process and dispatch a passed message
|
||||
*/
|
||||
void processMessage(const CMessage &msg);
|
||||
void processMessage(const CMessage *msg);
|
||||
|
||||
/**
|
||||
* Dispatches a message to the project
|
||||
*/
|
||||
void dispatchMessage(const CMessage *msg);
|
||||
|
||||
/**
|
||||
* Called when a drag operation has ended
|
||||
*/
|
||||
void dragEnd(const Common::Point &mousePos, CTreeItem *dragItem);
|
||||
public:
|
||||
CGameManager *_gameManager;
|
||||
CInputTranslator *_inputTranslator;
|
||||
int _field4;
|
||||
int _field8;
|
||||
int _fieldC;
|
||||
int _field10;
|
||||
int _field14;
|
||||
bool _dragging;
|
||||
bool _buttonDown;
|
||||
CTreeItem *_dragItem;
|
||||
Common::Point _dragStartPos;
|
||||
Common::Point _mousePos;
|
||||
int _lockCount;
|
||||
int _field24;
|
||||
|
|
|
@ -109,11 +109,15 @@ public:
|
|||
class CMouseDragMsg : public CMouseMsg {
|
||||
public:
|
||||
CLASSDEF
|
||||
CMouseDragMsg() : CMouseMsg() {}
|
||||
CMouseDragMsg(const Common::Point &pt) : CMouseMsg(pt, 0) {}
|
||||
};
|
||||
|
||||
class CMouseDragMoveMsg : public CMouseDragMsg {
|
||||
public:
|
||||
CLASSDEF
|
||||
CMouseDragMoveMsg() : CMouseDragMsg() {}
|
||||
CMouseDragMoveMsg(const Common::Point &pt) : CMouseDragMsg(pt) {}
|
||||
|
||||
virtual bool handleMessage(const CMouseDragMoveMsg &msg) { return false; }
|
||||
virtual bool perform(CTreeItem *treeItem) {
|
||||
|
@ -125,11 +129,13 @@ public:
|
|||
MSGTARGET(CMouseDragStartMsg);
|
||||
class CMouseDragStartMsg : public CMouseDragMsg {
|
||||
public:
|
||||
int _field10;
|
||||
CTreeItem *_dragItem;
|
||||
int _field14;
|
||||
public:
|
||||
CLASSDEF
|
||||
CMouseDragStartMsg() : CMouseDragMsg(), _field10(0), _field14(0) {}
|
||||
CMouseDragStartMsg() : CMouseDragMsg(), _dragItem(nullptr), _field14(0) {}
|
||||
CMouseDragStartMsg(const Common::Point &pt) : CMouseDragMsg(pt),
|
||||
_dragItem(nullptr), _field14(0) {}
|
||||
|
||||
virtual bool handleMessage(const CMouseDragStartMsg &msg) { return false; }
|
||||
virtual bool perform(CTreeItem *treeItem) {
|
||||
|
@ -141,10 +147,12 @@ public:
|
|||
MSGTARGET(CMouseDragEndMsg);
|
||||
class CMouseDragEndMsg : public CMouseDragMsg {
|
||||
public:
|
||||
int _field10;
|
||||
CTreeItem *_dragItem;
|
||||
public:
|
||||
CLASSDEF
|
||||
CMouseDragEndMsg() : CMouseDragMsg(), _field10(0) {}
|
||||
CMouseDragEndMsg() : CMouseDragMsg(), _dragItem(nullptr) {}
|
||||
CMouseDragEndMsg(const Common::Point &pt, CTreeItem *dragItem = nullptr) :
|
||||
CMouseDragMsg(pt), _dragItem(dragItem) {}
|
||||
|
||||
virtual bool handleMessage(const CMouseDragEndMsg &msg) { return false; }
|
||||
virtual bool perform(CTreeItem *treeItem) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue