TITANIC: More view event handling, beginnings of mouse cursor loading

This commit is contained in:
Paul Gilbert 2016-03-23 20:51:42 -04:00
parent 42208769f7
commit 7d2d624908
19 changed files with 301 additions and 37 deletions

View File

@ -46,7 +46,7 @@ CGameObject::CGameObject(): CNamedItem() {
_field58 = 0;
_field5C = 1;
_field60 = 0;
_cursorId = 1;
_cursorId = CURSOR_1;
_field78 = 0;
_frameNumber = -1;
_field90 = 0;
@ -77,7 +77,7 @@ void CGameObject::load(SimpleFile *file) {
// Deliberate fall-through
case 6:
val = _cursorId = file->readNumber();
_cursorId = (CursorId)file->readNumber();
// Deliberate fall-through
case 5:

View File

@ -23,6 +23,7 @@
#ifndef TITANIC_GAME_OBJECT_H
#define TITANIC_GAME_OBJECT_H
#include "titanic/mouse_cursor.h"
#include "titanic/rect.h"
#include "titanic/core/movie_clip.h"
#include "titanic/core/named_item.h"
@ -94,7 +95,7 @@ protected:
int _fieldB8;
public:
int _field60;
int _cursorId;
CursorId _cursorId;
public:
CLASSDEF
CGameObject();

View File

@ -32,7 +32,7 @@ CLinkItem::CLinkItem() : CNamedItem() {
_nodeNumber = -1;
_viewNumber = -1;
_field30 = 0;
_field34 = 1;
_cursorId = CURSOR_1;
_name = "Link";
}
@ -44,7 +44,7 @@ CString CLinkItem::formName() {
void CLinkItem::save(SimpleFile *file, int indent) const {
file->writeNumberLine(2, indent);
file->writeQuotedLine("L", indent);
file->writeNumberLine(_field34, indent + 1);
file->writeNumberLine(_cursorId, indent + 1);
file->writeNumberLine(_field30, indent + 1);
file->writeNumberLine(_roomNumber, indent + 1);
file->writeNumberLine(_nodeNumber, indent + 1);
@ -65,7 +65,7 @@ void CLinkItem::load(SimpleFile *file) {
switch (val) {
case 2:
_field34 = file->readNumber();
_cursorId = (CursorId)file->readNumber();
// Deliberate fall-through
case 1:
@ -93,16 +93,16 @@ void CLinkItem::load(SimpleFile *file) {
if (val < 2) {
switch (_field30) {
case 2:
_field34 = 2;
_cursorId = CURSOR_2;
break;
case 3:
_field34 = 3;
_cursorId = CURSOR_3;
break;
case 5:
_field34 = 7;
_cursorId = CURSOR_7;
break;
default:
_field34 = 4;
_cursorId = CURSOR_4;
break;
}
}

View File

@ -23,6 +23,7 @@
#ifndef TITANIC_LINK_ITEM_H
#define TITANIC_LINK_ITEM_H
#include "titanic/mouse_cursor.h"
#include "titanic/core/named_item.h"
#include "titanic/core/movie_clip.h"
@ -44,9 +45,9 @@ protected:
int _nodeNumber;
int _viewNumber;
int _field30;
int _field34;
public:
Rect _bounds;
CursorId _cursorId;
public:
CLASSDEF
CLinkItem();

View File

@ -818,7 +818,7 @@ DEFFN(CMouseMoveMsg)
DEFFN(CMouseButtonMsg)
DEFFN(CMouseButtonDownMsg)
DEFFN(CMouseButtonUpMsg)
DEFFN(CMouseButtonDoubleClickMsg)
DEFFN(CMouseDoubleClickMsg)
DEFFN(CMouseDragMsg)
DEFFN(CMouseDragStartMsg)
DEFFN(CMouseDragMoveMsg)
@ -1395,7 +1395,7 @@ void CSaveableObject::initClassList() {
ADDFN(CMouseButtonMsg, CMouseMsg);
ADDFN(CMouseButtonDownMsg, CMouseButtonMsg);
ADDFN(CMouseButtonUpMsg, CMouseButtonMsg);
ADDFN(CMouseButtonDoubleClickMsg, CMouseButtonMsg);
ADDFN(CMouseDoubleClickMsg, CMouseButtonMsg);
ADDFN(CMouseDragMsg, CMouseMsg);
ADDFN(CMouseDragStartMsg, CMouseDragMsg);
ADDFN(CMouseDragMoveMsg, CMouseDragMsg);

View File

@ -180,7 +180,45 @@ bool CViewItem::handleEvent(CMouseButtonDownMsg &msg) {
}
}
}
// TODO
}
return true;
}
bool CViewItem::handleEvent(CMouseButtonUpMsg &msg) {
if (msg._buttons & MB_LEFT)
handleMouseMsg(&msg, false);
return true;
}
bool CViewItem::handleEvent(CMouseDoubleClickMsg &msg) {
if (msg._buttons & MB_LEFT)
handleMouseMsg(&msg, false);
return true;
}
bool CViewItem::handleEvent(CMouseMoveMsg &msg) {
CScreenManager *screenManager = CScreenManager::_screenManagerPtr;
if (handleMouseMsg(&msg, true)) {
screenManager->_mouseCursor->setCursor(CURSOR_1);
} else {
// Iterate through each link item, and if any is highlighted,
// change the mouse cursor to the designated cursor for the item
CLinkItem *linkItem = dynamic_cast<CLinkItem *>(getFirstChild());
while (linkItem) {
if (linkItem->_bounds.contains(msg._mousePos)) {
screenManager->_mouseCursor->setCursor(linkItem->_cursorId);
return true;
}
linkItem = dynamic_cast<CLinkItem *>(linkItem->getNextSibling());
}
if (!handleMouseMsg(&msg, false))
screenManager->_mouseCursor->setCursor(CURSOR_1);
}
return true;
@ -212,8 +250,8 @@ bool CViewItem::handleMouseMsg(const CMouseMsg *msg, bool flag) {
return false;
for (int idx = (int)gameObjects.size() - 1; idx >= 0; ++idx) {
if (gameObjects[idx]->_cursorId != 12) {
CScreenManager::_screenManagerPtr->_mouseCursor->setCursorId(gameObjects[idx]->_cursorId);
if (gameObjects[idx]->_cursorId != CURSOR_12) {
CScreenManager::_screenManagerPtr->_mouseCursor->setCursor(gameObjects[idx]->_cursorId);
break;
}
}

View File

@ -29,7 +29,8 @@
namespace Titanic {
class CViewItem : public CNamedItem { //, CMouseButtonDownMsgTarget {
class CViewItem : public CNamedItem, CMouseButtonDownMsgTarget,
CMouseButtonUpMsgTarget, CMouseMoveMsgTarget, CMouseDoubleClickMsgTarget {
private:
CTreeItem *_buttonUpTargets[4];
private:
@ -52,6 +53,9 @@ protected:
int _field54;
protected:
virtual bool handleEvent(CMouseButtonDownMsg &msg);
virtual bool handleEvent(CMouseButtonUpMsg &msg);
virtual bool handleEvent(CMouseMoveMsg &msg);
virtual bool handleEvent(CMouseDoubleClickMsg &msg);
public:
int _viewNumber;
public:

View File

@ -81,6 +81,10 @@ void CFilesManager::resetView() {
}
}
void CFilesManager::fn4(const CString &name) {
warning("TODO: CFilesManager::fn4");
}
void CFilesManager::fn5(const CString &name) {
warning("TODO: CFilesManager::fn5");
}

View File

@ -77,6 +77,8 @@ public:
*/
void resetView();
void fn4(const CString &name);
void fn5(const CString &name);
};

View File

@ -60,7 +60,7 @@ void CInputTranslator::leftButtonUp(int special, const Point &pt) {
}
void CInputTranslator::leftButtonDoubleClick(int special, const Point &pt) {
CMouseButtonDoubleClickMsg msg(pt, getButtons(special));
CMouseDoubleClickMsg msg(pt, getButtons(special));
_inputHandler->handleMessage(msg);
}
@ -75,7 +75,7 @@ void CInputTranslator::middleButtonUp(int special, const Point &pt) {
}
void CInputTranslator::middleButtonDoubleClick(int special, const Point &pt) {
CMouseButtonDoubleClickMsg msg(pt, getButtons(special));
CMouseDoubleClickMsg msg(pt, getButtons(special));
_inputHandler->handleMessage(msg);
}
@ -90,7 +90,7 @@ void CInputTranslator::rightButtonUp(int special, const Point &pt) {
}
void CInputTranslator::rightButtonDoubleClick(int special, const Point &pt) {
CMouseButtonDoubleClickMsg msg(pt, getButtons(special));
CMouseDoubleClickMsg msg(pt, getButtons(special));
_inputHandler->handleMessage(msg);
}

View File

@ -84,7 +84,7 @@ bool CMessage::isMouseMoveMsg() const {
}
bool CMessage::isDoubleClickMsg() const {
return dynamic_cast<const CMouseButtonDoubleClickMsg *>(this) != nullptr;
return dynamic_cast<const CMouseDoubleClickMsg *>(this) != nullptr;
}
bool CMessage::isEnterRoomMsg() const {

View File

@ -108,19 +108,19 @@ public:
}
};
MSGTARGET(CMouseButtonDoubleClickMsg);
class CMouseButtonDoubleClickMsg : public CMouseButtonMsg {
MSGTARGET(CMouseDoubleClickMsg);
class CMouseDoubleClickMsg : public CMouseButtonMsg {
public:
CLASSDEF
CMouseButtonDoubleClickMsg() : CMouseButtonMsg() {}
CMouseButtonDoubleClickMsg(const Point &pt, int buttons) : CMouseButtonMsg(pt, buttons) {}
CMouseDoubleClickMsg() : CMouseButtonMsg() {}
CMouseDoubleClickMsg(const Point &pt, int buttons) : CMouseButtonMsg(pt, buttons) {}
static bool isSupportedBy(const CTreeItem *item) {
return dynamic_cast<const CMouseButtonDoubleClickMsg *>(item) != nullptr;
return dynamic_cast<const CMouseDoubleClickMsg *>(item) != nullptr;
}
virtual bool handleMessage(const CMouseButtonDoubleClickMsg &msg) { return false; }
virtual bool handleMessage(const CMouseDoubleClickMsg &msg) { return false; }
virtual bool perform(CTreeItem *treeItem) {
CMouseButtonDoubleClickMsg *dest = dynamic_cast<CMouseButtonDoubleClickMsg *>(treeItem);
CMouseDoubleClickMsg *dest = dynamic_cast<CMouseDoubleClickMsg *>(treeItem);
return dest != nullptr && dest->handleMessage(*this);
}
};

View File

@ -20,25 +20,80 @@
*
*/
#include "graphics/cursorman.h"
#include "common/textconsole.h"
#include "titanic/mouse_cursor.h"
#include "titanic/movie.h"
#include "titanic/screen_manager.h"
#include "titanic/titanic.h"
#include "titanic/video_surface.h"
#include "titanic/core/resource_key.h"
namespace Titanic {
static const int CURSOR_DATA[NUM_CURSORS][4] = {
{ 1, 136, 19, 18 },
{ 2, 139, 1, 1 },
{ 3, 140, 32, 1 },
{ 4, 137, 13, 0 },
{ 5, 145, 13, 0 },
{ 6, 144, 13, 22 },
{ 7, 137, 14, 0 },
{ 8, 148, 22, 40 },
{ 9, 136, 19, 18 },
{ 10, 143, 11, 11 },
{ 11, 146, 11, 11 },
{ 12, 136, 19, 18 },
{ 13, 136, 19, 25 },
{ 14, 136, 13, 22 },
{ 15, 138, 20, 28 }
};
CMouseCursor::CMouseCursor(CScreenManager *screenManager) :
_screenManager(screenManager), _cursorId(CURSOR_1) {
loadCursorImages();
}
CMouseCursor::~CMouseCursor() {
for (int idx = 0; idx < NUM_CURSORS; ++idx)
delete _cursors[idx]._videoSurface;
}
void CMouseCursor::loadCursorImages() {
const CString name("ycursors.avi");
const CResourceKey key(name);
g_vm->_filesManager.fn4(name);
// Iterate through each cursor
for (int idx = 0; idx < NUM_CURSORS; ++idx) {
assert(CURSOR_DATA[idx][0] == (idx + 1));
_cursors[idx]._centroid = Common::Point(CURSOR_DATA[idx][2],
CURSOR_DATA[idx][3]);
CVideoSurface *surface = _screenManager->createSurface(64, 64);
_cursors[idx]._videoSurface = surface;
OSMovie movie(key, surface);
movie.setFrame(idx);
_cursors[idx]._ptrUnknown = movie.proc21();
surface->set40(_cursors[idx]._ptrUnknown);
}
}
void CMouseCursor::show() {
warning("CMouseCursor::show");
CursorMan.showMouse(true);
}
void CMouseCursor::hide() {
warning("CMouseCursor::hide");
CursorMan.showMouse(false);
}
void CMouseCursor::setCursorId(int id) {
warning("CMouseCursor::setCursorId");
void CMouseCursor::setCursor(CursorId cursorId) {
warning("CMouseCursor::setCursor");
}
void CMouseCursor::update() {
warning("CMouseCursor::update");
// No implementation needed
}
} // End of namespace Titanic

View File

@ -24,14 +24,66 @@
#define TITANIC_MOUSE_CURSOR_H
#include "common/scummsys.h"
#include "common/rect.h"
namespace Titanic {
#define NUM_CURSORS 15
enum CursorId {
CURSOR_1 = 1,
CURSOR_2 = 3,
CURSOR_3 = 3,
CURSOR_4 = 4,
CURSOR_5 = 5,
CURSOR_6 = 6,
CURSOR_7 = 7,
CURSOR_8 = 8,
CURSOR_9 = 9,
CURSOR_10 = 10,
CURSOR_11 = 11,
CURSOR_12 = 12,
CURSOR_13 = 13,
CURSOR_14 = 14,
CURSOR_15 = 15
};
class CScreenManager;
class CVideoSurface;
class CMouseCursor {
struct CursorEntry {
CVideoSurface *_videoSurface;
void *_ptrUnknown;
Common::Point _centroid;
};
private:
CScreenManager *_screenManager;
CursorId _cursorId;
CursorEntry _cursors[NUM_CURSORS];
/**
* Load the images for each cursor
*/
void loadCursorImages();
public:
CMouseCursor(CScreenManager *screenManager);
~CMouseCursor();
/**
* Make the mouse cursor visible
*/
void show();
/**
* Hide the mouse cursor
*/
void hide();
void setCursorId(int id);
/**
* Set the cursor
*/
void setCursor(CursorId cursorId);
/**
* Updates the mouse cursor

View File

@ -24,5 +24,69 @@
namespace Titanic {
OSMovie::OSMovie(const CResourceKey &name, CVideoSurface *surface) {
}
void OSMovie::proc8() {
warning("TODO: OSMovie::proc8");
}
void OSMovie::proc9() {
warning("TODO: OSMovie::proc9");
}
void OSMovie::proc10() {
warning("TODO: OSMovie::proc10");
}
void OSMovie::proc11() {
warning("TODO: OSMovie::proc11");
}
void OSMovie::proc12() {
warning("TODO: OSMovie::proc12");
}
void OSMovie::proc13() {
warning("TODO: OSMovie::proc13");
}
void OSMovie::proc14() {
warning("TODO: OSMovie::proc14");
}
void OSMovie::proc15() {
warning("TODO: OSMovie::proc15");
}
void OSMovie::proc16() {
warning("TODO: OSMovie::proc16");
}
void OSMovie::proc17() {
warning("TODO: OSMovie::proc17");
}
void OSMovie::proc18() {
warning("TODO: OSMovie::proc18");
}
void OSMovie::proc19() {
warning("TODO: OSMovie::proc19");
}
void OSMovie::proc20() {
warning("TODO: OSMovie::proc20");
}
void *OSMovie::proc21() {
warning("TODO: OSMovie::proc21");
return nullptr;
}
void OSMovie::setFrame(uint frameNumber) {
}
} // End of namespace Titanic

View File

@ -24,11 +24,52 @@
#define TITANIC_MOVIE_H
#include "titanic/core/list.h"
#include "titanic/core/resource_key.h"
#include "titanic/video_surface.h"
namespace Titanic {
class CMovie : public ListItem {
public:
virtual void proc8() = 0;
virtual void proc9() = 0;
virtual void proc10() = 0;
virtual void proc11() = 0;
virtual void proc12() = 0;
virtual void proc13() = 0;
virtual void proc14() = 0;
virtual void proc15() = 0;
virtual void proc16() = 0;
virtual void proc17() = 0;
virtual void proc18() = 0;
virtual void proc19() = 0;
virtual void proc20() = 0;
virtual void *proc21() = 0;
};
class OSMovie : public CMovie {
public:
OSMovie(const CResourceKey &name, CVideoSurface *surface);
virtual void proc8();
virtual void proc9();
virtual void proc10();
virtual void proc11();
virtual void proc12();
virtual void proc13();
virtual void proc14();
virtual void proc15();
virtual void proc16();
virtual void proc17();
virtual void proc18();
virtual void proc19();
virtual void proc20();
virtual void *proc21();
/**
* Set the current frame number
*/
void setFrame(uint frameNumber);
};
} // End of namespace Titanic

View File

@ -222,7 +222,7 @@ void OSScreenManager::loadCursors() {
hideCursor();
delete _mouseCursor;
}
_mouseCursor = new CMouseCursor();
_mouseCursor = new CMouseCursor(this);
showCursor();
if (!_textCursor) {

View File

@ -31,7 +31,7 @@ int CVideoSurface::_videoSurfaceCounter = 0;
CVideoSurface::CVideoSurface(CScreenManager *screenManager) :
_screenManager(screenManager), _rawSurface(nullptr), _field34(nullptr),
_pendingLoad(false), _blitStyleFlag(false), _blitFlag(false),
_field40(0), _field44(4), _field48(0), _field50(1) {
_field40(nullptr), _field44(4), _field48(0), _field50(1) {
_videoSurfaceNum = _videoSurfaceCounter++;
}

View File

@ -58,7 +58,7 @@ protected:
Graphics::ManagedSurface *_rawSurface;
void *_field34;
bool _pendingLoad;
int _field40;
void *_field40;
int _field44;
int _field48;
int _videoSurfaceNum;
@ -157,6 +157,8 @@ public:
* Blit from another surface
*/
void blitFrom(const Point &destPos, CVideoSurface *src, const Rect *srcRect = nullptr);
void set40(void *v) { _field40 = v; }
};
class OSVideoSurface : public CVideoSurface {