1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* 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 "mutationofjb/widgets/gamewidget.h"
#include "mutationofjb/game.h"
#include "mutationofjb/gamedata.h"
#include "mutationofjb/guiscreen.h"
#include "mutationofjb/mutationofjb.h"
#include "mutationofjb/room.h"
#include "common/events.h"
#include "graphics/screen.h"
namespace MutationOfJB {
GameWidget::GameWidget(GuiScreen &gui) :
Widget(gui, Common::Rect(GAME_NORMAL_AREA_WIDTH, GAME_NORMAL_AREA_HEIGHT)),
_currentMapObjectId(0),
_nextMapObjectId(0),
_callback(nullptr) {}
void GameWidget::handleEvent(const Common::Event &event) {
if (!_enabled)
return;
if (!_gui.getGame().isCurrentSceneMap()) {
handleNormalScene(event);
} else {
handleMapScene(event);
}
}
void GameWidget::clearState() {
_currentMapObjectId = _nextMapObjectId = 0;
}
void GameWidget::draw(Graphics::ManagedSurface &) {
Room &room = _gui.getGame().getRoom();
// Full redraw using background buffer.
if (_dirtyBits == DIRTY_ALL) {
room.redraw();
return;
}
// Full redraw without background buffer.
if (_dirtyBits & DIRTY_AFTER_SCENE_CHANGE) {
room.redraw(false); // Don't use background buffer.
return;
}
// Only selection changed.
if (_dirtyBits & DIRTY_MAP_SELECTION) {
if (_currentMapObjectId != _nextMapObjectId) {
if (_currentMapObjectId) {
room.drawObjectAnimation(_currentMapObjectId, 1);
}
if (_nextMapObjectId) {
room.drawObjectAnimation(_nextMapObjectId, 0);
}
_currentMapObjectId = _nextMapObjectId;
}
}
}
void GameWidget::handleNormalScene(const Common::Event &event) {
Game &game = _gui.getGame();
Scene *const scene = game.getGameData().getCurrentScene();
switch (event.type) {
case Common::EVENT_LBUTTONDOWN: {
const int16 x = event.mouse.x;
const int16 y = event.mouse.y;
if (!_area.contains(x, y))
break;
if (Door *const door = scene->findDoor(x, y)) {
if (_callback)
_callback->onGameDoorClicked(this, door);
} else if (Static *const stat = scene->findStatic(x, y)) {
if (_callback)
_callback->onGameStaticClicked(this, stat);
}
break;
}
case Common::EVENT_MOUSEMOVE: {
const int16 x = event.mouse.x;
const int16 y = event.mouse.y;
if (!_area.contains(x, y))
break;
bool entityHit = false;
if (Door *const door = scene->findDoor(x, y)) {
if (_callback)
_callback->onGameEntityHovered(this, door->_name);
entityHit = true;
} else if (Static *const stat = scene->findStatic(x, y)) {
if (_callback)
_callback->onGameEntityHovered(this, stat->_name);
entityHit = true;
}
if (_callback && !entityHit)
_callback->onGameEntityHovered(this, Common::String());
_gui.getGame().getEngine().setCursorState(entityHit ? MutationOfJBEngine::CURSOR_ACTIVE : MutationOfJBEngine::CURSOR_IDLE);
break;
}
default:
break;
}
}
void GameWidget::handleMapScene(const Common::Event &event) {
Game &game = _gui.getGame();
Scene *const scene = game.getGameData().getCurrentScene();
switch (event.type) {
case Common::EVENT_LBUTTONDOWN: {
const int16 x = event.mouse.x;
const int16 y = event.mouse.y;
int index = 0;
if (scene->findBitmap(x, y, &index)) {
Static *const stat = scene->getStatic(index);
if (stat && stat->_active == 1) {
game.startActionSection(ActionInfo::Walk, stat->_name);
}
}
break;
}
case Common::EVENT_MOUSEMOVE: {
const int16 x = event.mouse.x;
const int16 y = event.mouse.y;
_nextMapObjectId = 0;
int index = 0;
//bool found = false;
if (scene->findBitmap(x, y, &index)) {
Static *const stat = scene->getStatic(index);
if (stat && stat->_active == 1) {
Object *const object = scene->getObject(index);
if (object) {
_nextMapObjectId = index;
}
}
}
if (_currentMapObjectId != _nextMapObjectId)
markDirty(DIRTY_MAP_SELECTION);
_gui.getGame().getEngine().setCursorState(_nextMapObjectId ? MutationOfJBEngine::CURSOR_ACTIVE : MutationOfJBEngine::CURSOR_IDLE);
break;
}
default:
break;
}
}
}
|