TITANIC: Implemented CBarMenu and CBarMenuButton classes

This commit is contained in:
Paul Gilbert 2016-08-14 15:52:03 -04:00
parent b670c02835
commit 8ea436686d
4 changed files with 98 additions and 10 deletions

View File

@ -24,25 +24,81 @@
namespace Titanic {
CBarMenu::CBarMenu() : CGameObject(), _fieldBC(0), _fieldC0(0), _fieldC4(6) {
BEGIN_MESSAGE_MAP(CBarMenu, CGameObject)
ON_MESSAGE(PETActivateMsg)
ON_MESSAGE(PETDownMsg)
ON_MESSAGE(PETUpMsg)
ON_MESSAGE(EnterViewMsg)
ON_MESSAGE(LeaveViewMsg)
END_MESSAGE_MAP()
CBarMenu::CBarMenu() : CGameObject(), _barFrameNumber(0), _visibleFlag(false), _numFrames(6) {
}
void CBarMenu::save(SimpleFile *file, int indent) {
file->writeNumberLine(1, indent);
file->writeNumberLine(_fieldBC, indent);
file->writeNumberLine(_fieldC0, indent);
file->writeNumberLine(_fieldC4, indent);
file->writeNumberLine(_barFrameNumber, indent);
file->writeNumberLine(_visibleFlag, indent);
file->writeNumberLine(_numFrames, indent);
CGameObject::save(file, indent);
}
void CBarMenu::load(SimpleFile *file) {
file->readNumber();
_fieldBC = file->readNumber();
_fieldC0 = file->readNumber();
_fieldC4 = file->readNumber();
_barFrameNumber = file->readNumber();
_visibleFlag = file->readNumber();
_numFrames = file->readNumber();
CGameObject::load(file);
}
bool CBarMenu::PETActivateMsg(CPETActivateMsg *msg) {
if (msg->_name == "Television") {
_visibleFlag = !_visibleFlag;
setVisible(_visibleFlag);
loadFrame(_barFrameNumber);
}
return true;
}
bool CBarMenu::PETDownMsg(CPETDownMsg *msg) {
if (_visibleFlag) {
if (--_barFrameNumber < 0)
_barFrameNumber = _numFrames - 1;
loadFrame(_barFrameNumber);
}
return true;
}
bool CBarMenu::PETUpMsg(CPETUpMsg *msg) {
if (_visibleFlag) {
_barFrameNumber = (_barFrameNumber + 1) % _numFrames;
loadFrame(_barFrameNumber);
}
return true;
}
bool CBarMenu::EnterViewMsg(CEnterViewMsg *msg) {
petSetArea(PET_REMOTE);
petHighlightGlyph(2);
petSetRemoteTarget();
setVisible(_visibleFlag);
loadFrame(_barFrameNumber);
return true;
}
bool CBarMenu::LeaveViewMsg(CLeaveViewMsg *msg) {
petClear();
_visibleFlag = false;
setVisible(false);
return true;
}
} // End of namespace Titanic

View File

@ -24,14 +24,21 @@
#define TITANIC_BAR_MENU_H
#include "titanic/core/game_object.h"
#include "titanic/messages/pet_messages.h"
namespace Titanic {
class CBarMenu : public CGameObject {
DECLARE_MESSAGE_MAP;
bool PETActivateMsg(CPETActivateMsg *msg);
bool PETDownMsg(CPETDownMsg *msg);
bool PETUpMsg(CPETUpMsg *msg);
bool EnterViewMsg(CEnterViewMsg *msg);
bool LeaveViewMsg(CLeaveViewMsg *msg);
public:
int _fieldBC;
int _fieldC0;
int _fieldC4;
int _barFrameNumber;
bool _visibleFlag;
int _numFrames;
public:
CLASSDEF;
CBarMenu();

View File

@ -21,9 +21,15 @@
*/
#include "titanic/game/bar_menu_button.h"
#include "titanic/messages/pet_messages.h"
namespace Titanic {
BEGIN_MESSAGE_MAP(CBarMenuButton, CGameObject)
ON_MESSAGE(MouseButtonDownMsg)
ON_MESSAGE(MouseButtonUpMsg)
END_MESSAGE_MAP()
void CBarMenuButton::save(SimpleFile *file, int indent) {
file->writeNumberLine(1, indent);
file->writeNumberLine(_value, indent);
@ -36,4 +42,20 @@ void CBarMenuButton::load(SimpleFile *file) {
CGameObject::load(file);
}
bool CBarMenuButton::MouseButtonDownMsg(CMouseButtonDownMsg *msg) {
return true;
}
bool CBarMenuButton::MouseButtonUpMsg(CMouseButtonUpMsg *msg) {
if (_value) {
CPETUpMsg upMsg("", -1);
upMsg.execute("BarTelevision");
} else {
CPETDownMsg downMsg("", -1);
downMsg.execute("BarTelevision");
}
return true;
}
} // End of namespace Titanic

View File

@ -28,6 +28,9 @@
namespace Titanic {
class CBarMenuButton : public CGameObject {
DECLARE_MESSAGE_MAP;
bool MouseButtonDownMsg(CMouseButtonDownMsg *msg);
bool MouseButtonUpMsg(CMouseButtonUpMsg *msg);
public:
int _value;
public: