2015-04-06 12:23:12 +02:00
|
|
|
/* ResidualVM - A 3D game interpreter
|
|
|
|
*
|
|
|
|
* ResidualVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the AUTHORS
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "engines/stark/ui/gamewindow.h"
|
|
|
|
|
|
|
|
#include "engines/stark/gfx/driver.h"
|
|
|
|
|
|
|
|
#include "engines/stark/resources/anim.h"
|
|
|
|
#include "engines/stark/resources/knowledgeset.h"
|
|
|
|
#include "engines/stark/resources/item.h"
|
|
|
|
#include "engines/stark/resources/location.h"
|
|
|
|
|
|
|
|
#include "engines/stark/services/global.h"
|
|
|
|
#include "engines/stark/services/services.h"
|
|
|
|
#include "engines/stark/services/staticprovider.h"
|
2015-07-13 09:26:57 +02:00
|
|
|
#include "engines/stark/services/gameinterface.h"
|
2015-04-06 12:23:12 +02:00
|
|
|
|
2015-07-13 09:14:45 +02:00
|
|
|
#include "engines/stark/ui/actionmenu.h"
|
2015-07-13 09:36:09 +02:00
|
|
|
#include "engines/stark/ui/inventorywindow.h"
|
2015-04-06 12:23:12 +02:00
|
|
|
|
|
|
|
namespace Stark {
|
|
|
|
|
2015-07-13 09:36:09 +02:00
|
|
|
GameWindow::GameWindow(Gfx::Driver *gfx, Cursor *cursor, ActionMenu *actionMenu, InventoryWindow *inventory) :
|
2015-04-06 12:23:12 +02:00
|
|
|
Window(gfx, cursor),
|
2015-07-11 18:50:28 +02:00
|
|
|
_actionMenu(actionMenu),
|
2015-07-12 17:09:14 +02:00
|
|
|
_inventory(inventory),
|
2015-07-11 18:50:28 +02:00
|
|
|
_objectUnderCursor(nullptr) {
|
2015-04-06 12:23:12 +02:00
|
|
|
_position = Common::Rect(Gfx::Driver::kGameViewportWidth, Gfx::Driver::kGameViewportHeight);
|
|
|
|
_position.translate(0, Gfx::Driver::kTopBorderHeight);
|
|
|
|
_visible = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameWindow::onRender() {
|
2015-04-15 08:16:23 +02:00
|
|
|
// List the items to render
|
2015-07-16 20:04:00 +02:00
|
|
|
_renderEntries = StarkGlobal->getCurrent()->getLocation()->listRenderEntries();
|
2015-04-06 12:23:12 +02:00
|
|
|
|
2015-04-15 08:16:23 +02:00
|
|
|
// Render all the scene items
|
2015-04-06 12:23:12 +02:00
|
|
|
Gfx::RenderEntryArray::iterator element = _renderEntries.begin();
|
|
|
|
while (element != _renderEntries.end()) {
|
|
|
|
// Draw the current element
|
|
|
|
(*element)->render(_gfx);
|
|
|
|
|
|
|
|
// Go for the next one
|
|
|
|
element++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameWindow::onMouseMove(const Common::Point &pos) {
|
2015-07-16 20:04:00 +02:00
|
|
|
_renderEntries = StarkGlobal->getCurrent()->getLocation()->listRenderEntries();
|
2015-04-06 12:23:12 +02:00
|
|
|
|
2015-07-12 22:16:30 +02:00
|
|
|
int16 selectedInventoryItem = _inventory->getSelectedInventoryItem();
|
|
|
|
int16 singlePossibleAction = -1;
|
|
|
|
|
|
|
|
checkObjectAtPos(pos, selectedInventoryItem, singlePossibleAction);
|
|
|
|
|
|
|
|
Common::String mouseHint;
|
|
|
|
|
|
|
|
if (selectedInventoryItem != -1) {
|
2015-07-16 20:04:00 +02:00
|
|
|
VisualImageXMG *cursorImage = StarkGameInterface->getCursorImage(selectedInventoryItem);
|
2015-07-12 22:16:30 +02:00
|
|
|
_cursor->setCursorImage(cursorImage);
|
|
|
|
} else if (_objectUnderCursor) {
|
|
|
|
switch (singlePossibleAction) {
|
|
|
|
case -1:
|
|
|
|
_cursor->setCursorType(Cursor::kActive);
|
|
|
|
break;
|
|
|
|
case Resources::PATTable::kActionLook:
|
|
|
|
_cursor->setCursorType(Cursor::kEye);
|
|
|
|
break;
|
|
|
|
case Resources::PATTable::kActionTalk:
|
|
|
|
_cursor->setCursorType(Cursor::kMouth);
|
|
|
|
break;
|
|
|
|
case Resources::PATTable::kActionUse:
|
|
|
|
_cursor->setCursorType(Cursor::kHand);
|
|
|
|
break;
|
|
|
|
default:
|
2015-07-16 20:04:00 +02:00
|
|
|
VisualImageXMG *cursorImage = StarkGameInterface->getCursorImage(singlePossibleAction);
|
2015-07-12 22:16:30 +02:00
|
|
|
_cursor->setCursorImage(cursorImage);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-07-17 20:16:03 +02:00
|
|
|
mouseHint = StarkGameInterface->getItemTitleAt(_objectUnderCursor, _objectRelativePosition);
|
2015-07-12 22:16:30 +02:00
|
|
|
} else {
|
|
|
|
// Not an object
|
|
|
|
_cursor->setCursorType(Cursor::kDefault);
|
|
|
|
}
|
|
|
|
_cursor->setMouseHint(mouseHint);
|
2015-04-06 12:23:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameWindow::onClick(const Common::Point &pos) {
|
2015-07-11 16:21:33 +02:00
|
|
|
_actionMenu->close();
|
|
|
|
|
2015-07-12 22:16:30 +02:00
|
|
|
int16 selectedInventoryItem = _inventory->getSelectedInventoryItem();
|
|
|
|
int16 singlePossibleAction = -1;
|
|
|
|
|
|
|
|
checkObjectAtPos(pos, selectedInventoryItem, singlePossibleAction);
|
|
|
|
|
2015-04-06 12:23:12 +02:00
|
|
|
if (_objectUnderCursor) {
|
2015-07-12 22:16:30 +02:00
|
|
|
if (singlePossibleAction != -1) {
|
2015-07-16 20:04:00 +02:00
|
|
|
StarkGameInterface->itemDoActionAt(_objectUnderCursor, singlePossibleAction, _objectRelativePosition);
|
2015-07-12 22:16:30 +02:00
|
|
|
} else if (selectedInventoryItem == -1) {
|
|
|
|
_actionMenu->open(_objectUnderCursor, _objectRelativePosition);
|
2015-04-06 12:23:12 +02:00
|
|
|
}
|
|
|
|
} else {
|
2015-07-13 16:49:12 +02:00
|
|
|
// The walk code expects unscaled absolute mouse coordinates
|
2015-07-16 20:04:00 +02:00
|
|
|
StarkGameInterface->walkTo(_cursor->getMousePosition(true));
|
2015-04-06 12:23:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 07:35:09 +02:00
|
|
|
void GameWindow::onRightClick(const Common::Point &pos) {
|
|
|
|
int16 selectedInventoryItem = _inventory->getSelectedInventoryItem();
|
|
|
|
|
|
|
|
if (selectedInventoryItem == -1) {
|
|
|
|
_inventory->open();
|
|
|
|
} else {
|
|
|
|
_inventory->setSelectedInventoryItem(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-13 09:19:30 +02:00
|
|
|
void GameWindow::checkObjectAtPos(Common::Point pos, int16 selectedInventoryItem, int16 &singlePossibleAction) {
|
2015-07-11 18:50:28 +02:00
|
|
|
_objectUnderCursor = nullptr;
|
2015-07-13 09:19:30 +02:00
|
|
|
singlePossibleAction = -1;
|
2015-07-11 18:50:28 +02:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-16 20:04:00 +02:00
|
|
|
if (!_objectUnderCursor || !StarkGameInterface->itemHasActionAt(_objectUnderCursor, _objectRelativePosition, -1)) {
|
2015-07-11 18:50:28 +02:00
|
|
|
// Only consider items with runnable scripts
|
|
|
|
_objectUnderCursor = nullptr;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-07-16 20:04:00 +02:00
|
|
|
int32 defaultAction = StarkGameInterface->itemGetDefaultActionAt(_objectUnderCursor, _objectRelativePosition);
|
2015-07-12 22:16:30 +02:00
|
|
|
if (defaultAction != -1) {
|
|
|
|
// Use the default action if there is one
|
2015-07-13 09:19:30 +02:00
|
|
|
singlePossibleAction = defaultAction;
|
|
|
|
} else if (selectedInventoryItem != -1) {
|
2015-07-12 22:16:30 +02:00
|
|
|
// Use the selected inventory item if there is one
|
2015-07-16 20:04:00 +02:00
|
|
|
if (StarkGameInterface->itemHasActionAt(_objectUnderCursor, _objectRelativePosition, selectedInventoryItem)) {
|
2015-07-13 09:19:30 +02:00
|
|
|
singlePossibleAction = selectedInventoryItem;
|
2015-07-11 18:50:28 +02:00
|
|
|
}
|
|
|
|
} else {
|
2015-07-12 22:16:30 +02:00
|
|
|
// Otherwise, use stock actions
|
2015-07-17 20:16:03 +02:00
|
|
|
Resources::ActionArray actionsPossible = StarkGameInterface->listStockActionsPossibleForObjectAt(
|
|
|
|
_objectUnderCursor, _objectRelativePosition);
|
2015-07-12 22:16:30 +02:00
|
|
|
|
|
|
|
if (actionsPossible.size() == 1) {
|
2015-07-13 09:19:30 +02:00
|
|
|
singlePossibleAction = actionsPossible[0];
|
2015-07-12 22:16:30 +02:00
|
|
|
}
|
2015-07-11 18:50:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-06 12:23:12 +02:00
|
|
|
} // End of namespace Stark
|