Skip to content

Commit

Permalink
TITANIC: Cleanup and fixes for clicking on Starfield marker LEDs
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Sep 9, 2017
1 parent 1e0a22d commit 74c401c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
6 changes: 6 additions & 0 deletions engines/titanic/pet_control/pet_gfx_element.h
Expand Up @@ -67,6 +67,12 @@ class CPetGfxElement: public CPetElement {
* Get the game object associated with this item
*/
virtual CGameObject *getObject() const;

/**
* Gets the explicit bounds set for the graphic element,
* ignoring any associated sub-object bounds
*/
const Rect &getRawBounds() const { return _bounds; }
};

} // End of namespace Titanic
Expand Down
23 changes: 13 additions & 10 deletions engines/titanic/pet_control/pet_starfield.cpp
Expand Up @@ -94,7 +94,7 @@ bool CPetStarfield::MouseButtonDownMsg(CMouseButtonDownMsg *msg) {
_petControl->displayMessage(SUPPLY_GALACTIC_REFERENCE);
}
} else if (!_btnSetDest.MouseButtonDownMsg(msg->_mousePos)) {
return elementsMouseDown(msg);
return markersMouseDown(msg);
}

return true;
Expand Down Expand Up @@ -216,33 +216,36 @@ void CPetStarfield::makePetDirty() {
_petControl->makeDirty();
}

bool CPetStarfield::elementsMouseDown(CMouseButtonDownMsg *msg) {
if (elementMouseButton(0, msg, _leds[0].getBounds()))
bool CPetStarfield::markersMouseDown(CMouseButtonDownMsg *msg) {
if (markerMouseDown(0, msg, _leds[0].getRawBounds()))
return true;
if (elementMouseButton(1, msg, _leds[2].getBounds()))
if (markerMouseDown(1, msg, _leds[2].getRawBounds()))
return true;
if (elementMouseButton(2, msg, _leds[4].getBounds()))
if (markerMouseDown(2, msg, _leds[4].getRawBounds()))
return true;

return false;
}

bool CPetStarfield::elementMouseButton(int index, CMouseButtonDownMsg *msg, const Rect &rect) {
bool CPetStarfield::markerMouseDown(int index, CMouseButtonDownMsg *msg, const Rect &rect) {
if (!rect.contains(msg->_mousePos))
return false;

switch (_markerStates[index]) {
case 1:
case MS_FLICKERING:
// Marker is flickering, so lock it in
if (_petControl->_remoteTarget) {
CPETStarFieldLockMsg lockMsg(1);
lockMsg.execute(_petControl->_remoteTarget);
}
break;

case 2:
if (index < 2 && _markerStates[index] >= 2) {
case MS_HIGHLIGHTED:
// Marker is locked in. If the most recently locked marker
// is clicked on, allow it to be unlocked
if (index == 2 || _markerStates[index + 1] != MS_HIGHLIGHTED) {
if (_petControl->_remoteTarget) {
CPETStarFieldLockMsg lockMsg(1);
CPETStarFieldLockMsg lockMsg(0);
lockMsg.execute(_petControl->_remoteTarget);
}
}
Expand Down
9 changes: 6 additions & 3 deletions engines/titanic/pet_control/pet_starfield.h
Expand Up @@ -56,11 +56,14 @@ class CPetStarfield : public CPetSection {
void drawButton(MarkerState state, int index, CScreenManager *screenManager);

/**
* Mouse down handling for Nav elements
* Handles clicking on any of the three locked star LED markers
*/
bool elementsMouseDown(CMouseButtonDownMsg *msg);
bool markersMouseDown(CMouseButtonDownMsg *msg);

bool elementMouseButton(int index, CMouseButtonDownMsg *msg, const Rect &rect);
/**
* Handles clicking on a specific locked star LED marker
*/
bool markerMouseDown(int index, CMouseButtonDownMsg *msg, const Rect &rect);
public:
CPetStarfield();

Expand Down

0 comments on commit 74c401c

Please sign in to comment.