aboutsummaryrefslogtreecommitdiff
path: root/engines/mutationofjb/widgets
diff options
context:
space:
mode:
authorĽubomír Remák2018-10-28 13:08:41 +0100
committerĽubomír Remák2018-10-28 13:08:41 +0100
commitd5568906739da23154cacd17aca93802901a9baf (patch)
tree56e9a8060f2c513aade94d18078c1d572c25a31b /engines/mutationofjb/widgets
parent0cf567de28fbdc0ee3c4aedf2c6da94c5b8ca129 (diff)
downloadscummvm-rg350-d5568906739da23154cacd17aca93802901a9baf.tar.gz
scummvm-rg350-d5568906739da23154cacd17aca93802901a9baf.tar.bz2
scummvm-rg350-d5568906739da23154cacd17aca93802901a9baf.zip
MUTATIONOFJB: Add support for combining items.
Introduce game screen and game widget. Add status bar to show currently hovered and picked items. Load hardcoded strings from game executable.
Diffstat (limited to 'engines/mutationofjb/widgets')
-rw-r--r--engines/mutationofjb/widgets/gamewidget.cpp179
-rw-r--r--engines/mutationofjb/widgets/gamewidget.h96
-rw-r--r--engines/mutationofjb/widgets/labelwidget.cpp64
-rw-r--r--engines/mutationofjb/widgets/labelwidget.h50
-rw-r--r--engines/mutationofjb/widgets/widget.cpp26
-rw-r--r--engines/mutationofjb/widgets/widget.h18
6 files changed, 425 insertions, 8 deletions
diff --git a/engines/mutationofjb/widgets/gamewidget.cpp b/engines/mutationofjb/widgets/gamewidget.cpp
new file mode 100644
index 0000000000..c481869ff3
--- /dev/null
+++ b/engines/mutationofjb/widgets/gamewidget.cpp
@@ -0,0 +1,179 @@
+/* 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();
+
+ // 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;
+ }
+ }
+
+ // Full redraw.
+ if (_dirtyBits == DIRTY_ALL) {
+ room.redraw();
+ return;
+ }
+}
+
+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 (door->_destSceneId != 0) {
+ 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 (Bitmap *const bitmap = 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 (Bitmap *const bitmap = 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;
+ }
+}
+
+}
diff --git a/engines/mutationofjb/widgets/gamewidget.h b/engines/mutationofjb/widgets/gamewidget.h
new file mode 100644
index 0000000000..e3fe08a818
--- /dev/null
+++ b/engines/mutationofjb/widgets/gamewidget.h
@@ -0,0 +1,96 @@
+/* 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.
+ *
+ */
+
+#ifndef MUTATIONOFJB_GAMEWIDGET_H
+#define MUTATIONOFJB_GAMEWIDGET_H
+
+#include "mutationofjb/widgets/widget.h"
+
+namespace MutationOfJB {
+
+class GameWidget;
+struct Door;
+struct Static;
+
+class GameWidgetCallback {
+public:
+ virtual ~GameWidgetCallback() {}
+ virtual void onGameDoorClicked(GameWidget *, const Door *door) = 0;
+ virtual void onGameStaticClicked(GameWidget *, const Static *stat) = 0;
+ virtual void onGameEntityHovered(GameWidget *, const Common::String &entity) = 0;
+};
+
+class GameWidget : public Widget {
+public:
+ enum {
+ GAME_NORMAL_AREA_WIDTH = 320,
+ GAME_NORMAL_AREA_HEIGHT = 139,
+ GAME_FULL_AREA_WIDTH = 320,
+ GAME_FULL_AREA_HEIGHT = 200
+ };
+
+ GameWidget(GuiScreen &gui);
+ void setCallback(GameWidgetCallback *callback) {
+ _callback = callback;
+ }
+
+ virtual void handleEvent(const Common::Event &);
+
+ void clearState();
+protected:
+ virtual void draw(Graphics::ManagedSurface &);
+
+private:
+ enum {
+ DIRTY_MAP_SELECTION = 1 << 1
+ };
+
+ /**
+ * Handling for normal (non-map) scenes.
+ *
+ * Statics and doors define mouse clickable areas.
+ * Statics are used to start actions.
+ * Doors are used to transition between scenes.
+ *
+ * @param event ScummVM event.
+ */
+ void handleNormalScene(const Common::Event &event);
+
+ /**
+ * Special handling for map scenes.
+ *
+ * Bitmaps define mouse clickable areas.
+ * Statics are used to start actions.
+ * Objects are used for showing labels.
+ *
+ * @param event ScummVM event.
+ */
+ void handleMapScene(const Common::Event &event);
+
+ uint8 _currentMapObjectId;
+ uint8 _nextMapObjectId;
+ GameWidgetCallback *_callback;
+};
+
+}
+
+#endif
diff --git a/engines/mutationofjb/widgets/labelwidget.cpp b/engines/mutationofjb/widgets/labelwidget.cpp
new file mode 100644
index 0000000000..0279cb27e1
--- /dev/null
+++ b/engines/mutationofjb/widgets/labelwidget.cpp
@@ -0,0 +1,64 @@
+/* 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/labelwidget.h"
+
+#include "mutationofjb/assets.h"
+#include "mutationofjb/game.h"
+#include "mutationofjb/gamedata.h"
+
+namespace MutationOfJB {
+
+LabelWidget::LabelWidget(GuiScreen &gui, const Common::Rect &area) :
+ Widget(gui, area),
+ _backgroundColor(0x00) {}
+
+uint8 LabelWidget::getBackgroundColor() const {
+ return _backgroundColor;
+}
+
+void LabelWidget::setBackgroundColor(uint8 color) {
+ if (_backgroundColor == color)
+ return;
+
+ _backgroundColor = color;
+ markDirty();
+}
+
+const Common::String &LabelWidget::getText() const {
+ return _text;
+}
+
+void LabelWidget::setText(const Common::String &text) {
+ if (_text == text)
+ return;
+
+ _text = text;
+ markDirty();
+}
+
+void LabelWidget::draw(Graphics::ManagedSurface &surface) {
+ surface.fillRect(_area, _backgroundColor);
+ _gui.getGame().getAssets().getSystemFont().drawString(&surface, _text, _area.left, _area.top, _area.width(), LIGHTGRAY, Graphics::kTextAlignCenter);
+}
+
+}
diff --git a/engines/mutationofjb/widgets/labelwidget.h b/engines/mutationofjb/widgets/labelwidget.h
new file mode 100644
index 0000000000..c87099671b
--- /dev/null
+++ b/engines/mutationofjb/widgets/labelwidget.h
@@ -0,0 +1,50 @@
+/* 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.
+ *
+ */
+
+#ifndef MUTATIONOJFB_LABELWIDGET_H
+#define MUTATIONOJFB_LABELWIDGET_H
+
+#include "mutationofjb/widgets/widget.h"
+
+namespace MutationOfJB {
+
+class LabelWidget : public Widget {
+public:
+ LabelWidget(GuiScreen &gui, const Common::Rect &area);
+
+ uint8 getBackgroundColor() const;
+ void setBackgroundColor(uint8 color);
+
+ const Common::String &getText() const;
+ void setText(const Common::String &text);
+
+protected:
+ virtual void draw(Graphics::ManagedSurface &) override;
+
+private:
+ uint8 _backgroundColor;
+ Common::String _text;
+};
+
+}
+
+#endif
diff --git a/engines/mutationofjb/widgets/widget.cpp b/engines/mutationofjb/widgets/widget.cpp
index b0302110ea..1b09fe08c3 100644
--- a/engines/mutationofjb/widgets/widget.cpp
+++ b/engines/mutationofjb/widgets/widget.cpp
@@ -43,20 +43,36 @@ void Widget::setVisible(bool visible) {
_visible = visible;
}
-void Widget::markDirty() {
- _dirty = true;
+bool Widget::isEnabled() const {
+ return _enabled;
+}
+
+void Widget::setEnabled(bool enabled) {
+ _enabled = enabled;
+}
+
+Common::Rect Widget::getArea() const {
+ return _area;
+}
+
+void Widget::setArea(const Common::Rect &area) {
+ _area = area;
+}
+
+void Widget::markDirty(uint32 dirtyBits) {
+ _dirtyBits = dirtyBits;
}
bool Widget::isDirty() const {
- return _dirty;
+ return _dirtyBits != DIRTY_NONE;
}
void Widget::update(Graphics::ManagedSurface &surface) {
- if (_dirty) {
+ if (isDirty()) {
if (_visible) {
draw(surface);
}
- _dirty = false;
+ _dirtyBits = DIRTY_NONE;
}
}
diff --git a/engines/mutationofjb/widgets/widget.h b/engines/mutationofjb/widgets/widget.h
index 86c912a555..108d86c92f 100644
--- a/engines/mutationofjb/widgets/widget.h
+++ b/engines/mutationofjb/widgets/widget.h
@@ -40,7 +40,12 @@ class GuiScreen;
class Widget {
public:
- Widget(GuiScreen &gui, const Common::Rect &area) : _gui(gui), _area(area), _id(0), _visible(true), _dirty(true) {}
+ enum {
+ DIRTY_NONE = 0,
+ DIRTY_ALL = 0xFFFFFFFF
+ };
+
+ Widget(GuiScreen &gui, const Common::Rect &area) : _gui(gui), _area(area), _id(0), _visible(true), _enabled(true), _dirtyBits(DIRTY_NONE) {}
virtual ~Widget() {}
int getId() const;
@@ -49,8 +54,14 @@ public:
bool isVisible() const;
void setVisible(bool visible);
+ bool isEnabled() const;
+ void setEnabled(bool enabled);
+
+ Common::Rect getArea() const;
+ void setArea(const Common::Rect &area);
+
bool isDirty() const;
- void markDirty();
+ void markDirty(uint32 dirtyBits = DIRTY_ALL);
void update(Graphics::ManagedSurface &);
virtual void handleEvent(const Common::Event &) {}
@@ -61,7 +72,8 @@ protected:
Common::Rect _area;
int _id;
bool _visible;
- bool _dirty;
+ bool _enabled;
+ uint32 _dirtyBits;
};
}