aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic
diff options
context:
space:
mode:
Diffstat (limited to 'engines/titanic')
-rw-r--r--engines/titanic/core/game_object.cpp21
-rw-r--r--engines/titanic/core/game_object.h7
-rw-r--r--engines/titanic/core/view_item.cpp65
-rw-r--r--engines/titanic/core/view_item.h6
4 files changed, 56 insertions, 43 deletions
diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp
index ea3cb4ddac..27af509618 100644
--- a/engines/titanic/core/game_object.cpp
+++ b/engines/titanic/core/game_object.cpp
@@ -289,6 +289,27 @@ bool CGameObject::checkPoint(const Point &pt, bool ignoreSurface, bool visibleOn
return pixel != transColor;
}
+bool CGameObject::findPoint(Point &pt) {
+ // Start by checking a centroid point in the bounds
+ if (!_bounds.isEmpty()) {
+ pt = Point((_bounds.left + _bounds.right) / 2,
+ (_bounds.top + _bounds.bottom) / 2);
+ if (checkPoint(pt, false, true))
+ return true;
+ }
+
+ // Scan through all the area of the bounds to find a valid point
+ for (pt.y = _bounds.top; pt.y < _bounds.bottom; ++pt.y) {
+ for (pt.x = _bounds.left; pt.x < _bounds.right; ++pt.x) {
+ if (checkPoint(pt, false, true))
+ return true;
+ }
+ }
+
+ pt = Point(0, 0);
+ return false;
+}
+
bool CGameObject::clipRect(const Rect &rect1, Rect &rect2) const {
if (!rect2.intersects(rect1))
return false;
diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h
index d08ef4cf76..1c3cbf386c 100644
--- a/engines/titanic/core/game_object.h
+++ b/engines/titanic/core/game_object.h
@@ -609,6 +609,13 @@ public:
bool checkPoint(const Point &pt, bool ignoreSurface = false, bool visibleOnly = false);
/**
+ * Returns a point that falls within the object
+ * @param pt Return point
+ * @returns True if a point was found
+ */
+ bool findPoint(Point &pt);
+
+ /**
* Set the position of the object
*/
void setPosition(const Point &newPos);
diff --git a/engines/titanic/core/view_item.cpp b/engines/titanic/core/view_item.cpp
index 979fea81fe..19e1a1136b 100644
--- a/engines/titanic/core/view_item.cpp
+++ b/engines/titanic/core/view_item.cpp
@@ -339,52 +339,43 @@ CString CViewItem::getNodeViewName() const {
}
bool CViewItem::MovementMsg(CMovementMsg *msg) {
- Movement move = msg->_movement;
-
+ Point pt;
+
// Iterate through the links to find an appropriate link
for (CTreeItem *treeItem = getFirstChild(); treeItem;
treeItem = treeItem->scan(this)) {
CLinkItem *link = dynamic_cast<CLinkItem *>(treeItem);
- if (!link)
+ CGameObject *gameObj = dynamic_cast<CGameObject *>(treeItem);
+
+ if (link) {
+ // Skip links that aren't for the desired direction
+ if (link->getMovement() != msg->_movement)
+ continue;
+
+ pt = Point((link->_bounds.left + link->_bounds.right) / 2,
+ (link->_bounds.top + link->_bounds.bottom) / 2);
+ } else if (gameObj) {
+ if (!gameObj->_visible || gameObj->getMovement() != msg->_movement)
+ continue;
+
+ if (!gameObj->findPoint(pt))
+ continue;
+ } else {
+ // Not a link or object, so ignore
continue;
-
- Movement m = link->getMovement();
- if (move == m) {
- // Found a matching link
- CGameManager *gm = getGameManager();
- gm->_gameState.triggerLink(link);
- return true;
- }
- }
-
- return false;
-}
-
-CursorId CViewItem::getLinkCursor(CLinkItem *link) {
- // Pick the center of the link's region as a check point
- Common::Point pt((link->_bounds.left + link->_bounds.right) / 2,
- (link->_bounds.top + link->_bounds.bottom) / 2);
- if (link->_bounds.isEmpty())
- // Bridge doorway link has an empty bounds, so workaround it
- pt = Common::Point(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2);
-
- // Scan for a restricted object covering the link
- Common::Array<CGameObject *> gameObjects;
- for (CTreeItem *treeItem = scan(this); treeItem; treeItem = treeItem->scan(this)) {
- CGameObject *gameObject = dynamic_cast<CGameObject *>(treeItem);
- if (gameObject) {
- if (gameObject->checkPoint(pt, false, true))
- gameObjects.push_back(gameObject);
}
- }
- for (int idx = (int)gameObjects.size() - 1; idx >= 0; --idx) {
- if (gameObjects[idx]->_cursorId == CURSOR_INVALID)
- return CURSOR_INVALID;
+ // We've found a point on the object or link that has a
+ // cursor for the given direction. So simulate a mouse
+ // press and release on the desired point
+ CMouseButtonDownMsg downMsg(pt, MB_LEFT);
+ CMouseButtonUpMsg upMsg(pt, MB_LEFT);
+ MouseButtonDownMsg(&downMsg);
+ MouseButtonUpMsg(&upMsg);
+ return true;
}
- // No obscuring objects, so we're free to return the link's cursor
- return link->_cursorId;
+ return false;
}
} // End of namespace Titanic
diff --git a/engines/titanic/core/view_item.h b/engines/titanic/core/view_item.h
index c32a7b4b90..253294d9a1 100644
--- a/engines/titanic/core/view_item.h
+++ b/engines/titanic/core/view_item.h
@@ -54,12 +54,6 @@ private:
* Handles mouse button up messages
*/
void handleButtonUpMsg(CMouseButtonUpMsg *msg);
-
- /**
- * Gets the cursor for a link, taking into account any
- * "restricted" surface that may be covering it
- */
- CursorId getLinkCursor(CLinkItem *link);
protected:
int _field24;
CResourceKey _resourceKey;