STRAK: Move item handling to the game window
This commit is contained in:
parent
17eec33272
commit
21ecb3e798
5 changed files with 83 additions and 83 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -65,6 +65,7 @@ private:
|
|||
VisualImageXMG *_backgroundTexture;
|
||||
Common::Rect _backgroundRect;
|
||||
|
||||
Gfx::RenderEntryArray _renderEntries;
|
||||
int16 _selectedInventoryItem;
|
||||
};
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue