diff --git a/engines/stark/ui/gamewindow.cpp b/engines/stark/ui/gamewindow.cpp index a95cbb2cef6..f3da7b16a80 100644 --- a/engines/stark/ui/gamewindow.cpp +++ b/engines/stark/ui/gamewindow.cpp @@ -42,7 +42,8 @@ namespace Stark { GameWindow::GameWindow(Gfx::Driver *gfx, Cursor *cursor, ActionMenu *actionMenu) : Window(gfx, cursor), - _actionMenu(actionMenu) { + _actionMenu(actionMenu), + _objectUnderCursor(nullptr) { _position = Common::Rect(Gfx::Driver::kGameViewportWidth, Gfx::Driver::kGameViewportHeight); _position.translate(0, Gfx::Driver::kTopBorderHeight); _visible = true; @@ -112,4 +113,75 @@ void GameWindow::onClick(const Common::Point &pos) { } } +void GameWindow::updateItems() { + // Check for game world mouse overs + UserInterface *ui = StarkServices::instance().userInterface; + Common::Point pos = getMousePosition(); + + + _objectUnderCursor = nullptr; + + // Render entries are sorted from the farthest to the camera to the nearest + // Loop in reverse order + for (int i = _renderEntries.size() - 1; i >= 0; i--) { + if (_renderEntries[i]->containsPoint(pos, _objectRelativePosition)) { + _objectUnderCursor = _renderEntries[i]->getOwner(); + break; + } + } + + Resources::ActionArray actionsPossible; + if (_objectUnderCursor) { + actionsPossible = ui->getActionsPossibleForObject(_objectUnderCursor, _objectRelativePosition); + } + + if (actionsPossible.empty()) { + // Only consider items with runnable scripts + _objectUnderCursor = nullptr; + } + + Common::String mouseHint; + if (_objectUnderCursor) { + setCursorDependingOnActionsAvailable(actionsPossible); + + mouseHint = ui->getItemTitle(_objectUnderCursor, true, _objectRelativePosition); + } else { + // Not an object + _cursor->setCursorType(Cursor::kPassive); + } + _cursor->setMouseHint(mouseHint); +} + +void GameWindow::setCursorDependingOnActionsAvailable(Resources::ActionArray actionsAvailable) { + if (actionsAvailable.empty()) { + _cursor->setCursorType(Cursor::kPassive); + return; + } + + uint32 count = 0; + Cursor::CursorType cursorType; + for (uint i = 0; i < actionsAvailable.size(); i++) { + switch (actionsAvailable[i]) { + case Resources::PATTable::kActionLook: + cursorType = Cursor::kEye; + count++; + break; + case Resources::PATTable::kActionTalk: + cursorType = Cursor::kMouth; + count++; + break; + case Resources::PATTable::kActionUse: + cursorType = Cursor::kHand; + count++; + break; + } + } + + if (count == 1) { + _cursor->setCursorType(cursorType); + } else { + _cursor->setCursorType(Cursor::kActive); + } +} + } // End of namespace Stark diff --git a/engines/stark/ui/gamewindow.h b/engines/stark/ui/gamewindow.h index bd1c98a3b66..41c22b02e8b 100644 --- a/engines/stark/ui/gamewindow.h +++ b/engines/stark/ui/gamewindow.h @@ -46,6 +46,14 @@ protected: void onRender() override; ActionMenu *_actionMenu; + + // Item handling + void updateItems(); + void setCursorDependingOnActionsAvailable(Resources::ActionArray actionsAvailable); + + Gfx::RenderEntryArray _renderEntries; + Resources::ItemVisual *_objectUnderCursor; + Common::Point _objectRelativePosition; }; } // End of namespace Stark diff --git a/engines/stark/ui/inventoryinterface.h b/engines/stark/ui/inventoryinterface.h index c5a9e9a486a..d63888b9c52 100644 --- a/engines/stark/ui/inventoryinterface.h +++ b/engines/stark/ui/inventoryinterface.h @@ -65,6 +65,7 @@ private: VisualImageXMG *_backgroundTexture; Common::Rect _backgroundRect; + Gfx::RenderEntryArray _renderEntries; int16 _selectedInventoryItem; }; diff --git a/engines/stark/ui/window.cpp b/engines/stark/ui/window.cpp index 5856f1dff95..8e2ac647a35 100644 --- a/engines/stark/ui/window.cpp +++ b/engines/stark/ui/window.cpp @@ -37,8 +37,7 @@ Window::Window(Gfx::Driver *gfx, Cursor *cursor) : _gfx(gfx), _cursor(cursor), _unscaled(false), - _visible(false), - _objectUnderCursor(nullptr) { + _visible(false) { } Window::~Window() { @@ -114,75 +113,4 @@ void Window::handleRightClick() { } } -void Window::updateItems() { - // Check for game world mouse overs - UserInterface *ui = StarkServices::instance().userInterface; - Common::Point pos = getMousePosition(); - - - _objectUnderCursor = nullptr; - - // Render entries are sorted from the farthest to the camera to the nearest - // Loop in reverse order - for (int i = _renderEntries.size() - 1; i >= 0; i--) { - if (_renderEntries[i]->containsPoint(pos, _objectRelativePosition)) { - _objectUnderCursor = _renderEntries[i]->getOwner(); - break; - } - } - - Resources::ActionArray actionsPossible; - if (_objectUnderCursor) { - actionsPossible = ui->getActionsPossibleForObject(_objectUnderCursor, _objectRelativePosition); - } - - if (actionsPossible.empty()) { - // Only consider items with runnable scripts - _objectUnderCursor = nullptr; - } - - Common::String mouseHint; - if (_objectUnderCursor) { - setCursorDependingOnActionsAvailable(actionsPossible); - - mouseHint = ui->getItemTitle(_objectUnderCursor, true, _objectRelativePosition); - } else { - // Not an object - _cursor->setCursorType(Cursor::kPassive); - } - _cursor->setMouseHint(mouseHint); -} - -void Window::setCursorDependingOnActionsAvailable(Resources::ActionArray actionsAvailable) { - if (actionsAvailable.empty()) { - _cursor->setCursorType(Cursor::kPassive); - return; - } - - uint32 count = 0; - Cursor::CursorType cursorType; - for (uint i = 0; i < actionsAvailable.size(); i++) { - switch (actionsAvailable[i]) { - case Resources::PATTable::kActionLook: - cursorType = Cursor::kEye; - count++; - break; - case Resources::PATTable::kActionTalk: - cursorType = Cursor::kMouth; - count++; - break; - case Resources::PATTable::kActionUse: - cursorType = Cursor::kHand; - count++; - break; - } - } - - if (count == 1) { - _cursor->setCursorType(cursorType); - } else { - _cursor->setCursorType(Cursor::kActive); - } -} - } // End of namespace Stark diff --git a/engines/stark/ui/window.h b/engines/stark/ui/window.h index 426a314b08f..ed7ad8595c9 100644 --- a/engines/stark/ui/window.h +++ b/engines/stark/ui/window.h @@ -71,15 +71,6 @@ protected: Common::Rect _position; bool _unscaled; bool _visible; - - - // Item handling - void updateItems(); - void setCursorDependingOnActionsAvailable(Resources::ActionArray actionsAvailable); - - Gfx::RenderEntryArray _renderEntries; - Resources::ItemVisual *_objectUnderCursor; - Common::Point _objectRelativePosition; }; } // End of namespace Stark