diff options
| -rw-r--r-- | engines/mutationofjb/commands/endblockcommand.cpp | 5 | ||||
| -rw-r--r-- | engines/mutationofjb/game.cpp | 17 | ||||
| -rw-r--r-- | engines/mutationofjb/game.h | 4 | ||||
| -rw-r--r-- | engines/mutationofjb/gui.cpp | 144 | ||||
| -rw-r--r-- | engines/mutationofjb/gui.h | 29 | ||||
| -rw-r--r-- | engines/mutationofjb/module.mk | 3 | ||||
| -rw-r--r-- | engines/mutationofjb/mutationofjb.cpp | 16 | ||||
| -rw-r--r-- | engines/mutationofjb/room.h | 1 | ||||
| -rw-r--r-- | engines/mutationofjb/widgets/buttonwidget.cpp | 70 | ||||
| -rw-r--r-- | engines/mutationofjb/widgets/buttonwidget.h | 58 | ||||
| -rw-r--r-- | engines/mutationofjb/widgets/inventorywidget.cpp | 75 | ||||
| -rw-r--r-- | engines/mutationofjb/widgets/inventorywidget.h | 48 | ||||
| -rw-r--r-- | engines/mutationofjb/widgets/widget.cpp | 50 | ||||
| -rw-r--r-- | engines/mutationofjb/widgets/widget.h | 66 | 
14 files changed, 523 insertions, 63 deletions
diff --git a/engines/mutationofjb/commands/endblockcommand.cpp b/engines/mutationofjb/commands/endblockcommand.cpp index 492a4244b3..cc6a4559b4 100644 --- a/engines/mutationofjb/commands/endblockcommand.cpp +++ b/engines/mutationofjb/commands/endblockcommand.cpp @@ -31,6 +31,7 @@  	("#L " | "-L ") <object>  	("#W " | "-W ") <object>  	("#T " | "-T ") <object> +	("#P " | "-P ") <object1>  	("#U " | "-U ") <object1> [<object2>]  	("#ELSE" | "-ELSE") [<tag>]  	"#MACRO " <name> @@ -73,6 +74,10 @@ bool EndBlockCommandParser::parse(const Common::String &line, ScriptParseContext  		ActionInfo ai = {ActionInfo::Talk, line.c_str() + 3, "", firstChar == '#', nullptr};  		parseCtx._actionInfos.push_back(ai);  		_pendingActionInfos.push_back(parseCtx._actionInfos.size() - 1); +	} else if (line.size() >= 4 && (line.hasPrefix("#P ") || line.hasPrefix("-P "))) { +		ActionInfo ai = {ActionInfo::PickUp, line.c_str() + 3, "", firstChar == '#', nullptr}; +		parseCtx._actionInfos.push_back(ai); +		_pendingActionInfos.push_back(parseCtx._actionInfos.size() - 1);  	} else if (line.size() >= 4 && (line.hasPrefix("#U ") || line.hasPrefix("-U "))) {  		int secondObjPos = -1;  		for (uint i = 3; i < line.size(); ++i) { diff --git a/engines/mutationofjb/game.cpp b/engines/mutationofjb/game.cpp index b7f1893198..af0b76bb7e 100644 --- a/engines/mutationofjb/game.cpp +++ b/engines/mutationofjb/game.cpp @@ -35,7 +35,12 @@  namespace MutationOfJB {  Game::Game(MutationOfJBEngine *vm) -: _vm(vm), _delayedLocalScript(nullptr), _gui(*this, _vm->getScreen()), _scriptExecCtx(*this) { +	: _vm(vm), +	_delayedLocalScript(nullptr), +	_gui(*this, _vm->getScreen()), +	_scriptExecCtx(*this), +	_currentAction(ActionInfo::Walk) { +  	_gameData = new GameData;  	loadGameData(false); @@ -87,7 +92,7 @@ bool Game::loadGameData(bool partB) {  Script *Game::changeSceneLoadScript(uint8 sceneId, bool partB) {  	if (isCurrentSceneMap()) { -		_gui.markInventoryDirty(); +		_gui.markDirty();  	}  	_gameData->_lastScene = _gameData->_currentScene; @@ -179,4 +184,12 @@ Gui &Game::getGui() {  	return _gui;  } +ActionInfo::Action Game::getCurrentAction() const { +	return _currentAction; +} + +void Game::setCurrentAction(ActionInfo::Action action) { +	_currentAction = action; +} +  } diff --git a/engines/mutationofjb/game.h b/engines/mutationofjb/game.h index 71dadf2cd7..19cf406168 100644 --- a/engines/mutationofjb/game.h +++ b/engines/mutationofjb/game.h @@ -61,6 +61,9 @@ public:  	Gui &getGui(); +	ActionInfo::Action getCurrentAction() const; +	void setCurrentAction(ActionInfo::Action); +  private:  	bool loadGameData(bool partB);  	void runActiveCommand(); @@ -75,6 +78,7 @@ private:  	Script *_delayedLocalScript;  	Room *_room;  	Gui _gui; +	ActionInfo::Action _currentAction;  	ScriptExecutionContext _scriptExecCtx;  }; diff --git a/engines/mutationofjb/gui.cpp b/engines/mutationofjb/gui.cpp index 5ceed67b88..76e93056d0 100644 --- a/engines/mutationofjb/gui.cpp +++ b/engines/mutationofjb/gui.cpp @@ -27,20 +27,23 @@  #include "mutationofjb/gamedata.h"  #include "mutationofjb/inventory.h"  #include "mutationofjb/util.h" +#include "mutationofjb/widgets/widget.h" +#include "mutationofjb/widgets/inventorywidget.h"  #include "common/rect.h"  #include "graphics/screen.h"  namespace MutationOfJB {  enum ButtonType { -	BUTTON_WALK, +	BUTTON_WALK = 0,  	BUTTON_TALK,  	BUTTON_LOOK,  	BUTTON_USE,  	BUTTON_PICKUP,  	BUTTON_SCROLL_LEFT,  	BUTTON_SCROLL_RIGHT, -	BUTTON_SETTINGS +	BUTTON_SETTINGS, +	NUM_BUTTONS  };  enum { @@ -52,40 +55,78 @@ enum {  	INVENTORY_ITEMS_LINES = 5  }; -static Common::Rect ButtonRects[] = { -	Common::Rect(0, 148, 67, 158), // Walk -	Common::Rect(0, 158, 67, 168), // Talk -	Common::Rect(0, 168, 67, 178), // Look -	Common::Rect(0, 178, 67, 188), // Use -	Common::Rect(0, 188, 67, 198), // PickUp -	Common::Rect(67, 149, 88, 174), // ScrollLeft -	Common::Rect(67, 174, 88, 199), // ScrollRight -	Common::Rect(301, 148, 320, 200) // Settings -};  Gui::Gui(Game &game, Graphics::Screen *screen)  	: _game(game), -	_screen(screen), -	_inventoryDirty(false) { +	_screen(screen) {} + +Gui::~Gui() { +	for (Common::Array<Widget *>::iterator it = _widgets.begin(); it != _widgets.end(); ++it) { +		delete *it; +	} +} + +Game &Gui::getGame() { +	return _game;  }  bool Gui::init() { -	const bool result1 = loadInventoryList(); -	const bool result2 = loadInventoryGfx(); +	if (!loadInventoryList()) { +		return false; +	} + +	if (!loadInventoryGfx()) { +		return false; +	} + +	if (!loadHudGfx()) { +		return false; +	}  	_game.getGameData().getInventory().setObserver(this); -	return result1 && result2; +	// Init widgets. +	_inventoryWidget = new InventoryWidget(*this, _inventoryItems, _inventorySurfaces); +	_widgets.push_back(_inventoryWidget); + +	const Common::Rect ButtonRects[] = { +		Common::Rect(0, 148, 67, 158), // Walk +		Common::Rect(0, 158, 67, 168), // Talk +		Common::Rect(0, 168, 67, 178), // Look +		Common::Rect(0, 178, 67, 188), // Use +		Common::Rect(0, 188, 67, 198), // PickUp +		Common::Rect(67, 149, 88, 174), // ScrollLeft +		Common::Rect(67, 174, 88, 199), // ScrollRight +		Common::Rect(301, 148, 320, 200) // Settings +	}; + +	for (int i = 0; i < NUM_BUTTONS; ++i) { +		const Graphics::Surface normalSurface = _hudSurfaces[0].getSubArea(ButtonRects[i]); +		const Graphics::Surface pressedSurface = _hudSurfaces[1].getSubArea(ButtonRects[i]); +		ButtonWidget *button = new ButtonWidget(*this, ButtonRects[i], normalSurface, pressedSurface); +		button->setId(i); +		button->setCallback(this); +		_widgets.push_back(button); +	} + +	return true;  } -void Gui::markInventoryDirty() { -	_inventoryDirty = true; +void Gui::markDirty() { +	for (Common::Array<Widget *>::iterator it = _widgets.begin(); it != _widgets.end(); ++it) { +		(*it)->markDirty(); +	} +} + +void Gui::handleEvent(const Common::Event &event) { +	for (Common::Array<Widget *>::iterator it = _widgets.begin(); it != _widgets.end(); ++it) { +		(*it)->handleEvent(event); +	}  }  void Gui::update() { -	if (_inventoryDirty) { -		drawInventory(); -		_inventoryDirty = false; +	for (Common::Array<Widget *>::iterator it = _widgets.begin(); it != _widgets.end(); ++it) { +		(*it)->update(*_screen);  	}  } @@ -116,6 +157,32 @@ bool Gui::loadInventoryGfx() {  	return decoder.decode(&callback);  } +class HudAnimationDecoderCallback : public AnimationDecoderCallback { +public: +	HudAnimationDecoderCallback(Gui &gui) : _gui(gui) {} +	virtual void onFrame(int frameNo, Graphics::Surface &surface) override; +	virtual void onPaletteUpdated(byte palette[PALETTE_SIZE]) override; +private: +	Gui &_gui; +}; + +void HudAnimationDecoderCallback::onPaletteUpdated(byte [PALETTE_SIZE]) { +} + +void HudAnimationDecoderCallback::onFrame(int frameNo, Graphics::Surface &surface) { +	if (frameNo == 0 || frameNo == 1 || frameNo == 3) { +		Graphics::Surface outSurface; +		outSurface.copyFrom(surface); +		_gui._hudSurfaces.push_back(outSurface); +	} +} + +bool Gui::loadHudGfx() { +	AnimationDecoder decoder("room0.dat"); +	HudAnimationDecoderCallback callback(*this); +	return decoder.decode(&callback); +} +  bool Gui::loadInventoryList() {  	EncryptedFile file;  	const char *fileName = "fixitems.dat"; @@ -147,35 +214,16 @@ bool Gui::loadInventoryList() {  	return true;  } -void Gui::drawInventoryItem(const Common::String &item, int pos) { -	InventoryMap::iterator it = _inventoryItems.find(item); -	if (it == _inventoryItems.end()) { -		return; -	} - -	const int index = it->_value; -	const int surfaceNo = index / (INVENTORY_ITEMS_LINES * INVENTORY_ITEMS_PER_LINE); -	const int indexInSurface = index % (INVENTORY_ITEMS_LINES * INVENTORY_ITEMS_PER_LINE); -	const int itemX = indexInSurface % INVENTORY_ITEMS_PER_LINE; -	const int itemY = indexInSurface / INVENTORY_ITEMS_PER_LINE; - -	Common::Point destStartPos(INVENTORY_START_X + pos * INVENTORY_ITEM_WIDTH, INVENTORY_START_Y); -	Common::Rect sourceRect(itemX * INVENTORY_ITEM_WIDTH, itemY * INVENTORY_ITEM_HEIGHT, (itemX + 1) * INVENTORY_ITEM_WIDTH, (itemY + 1) * INVENTORY_ITEM_HEIGHT); -	_screen->blitFrom(_inventorySurfaces[surfaceNo], sourceRect, destStartPos); +void Gui::onInventoryChanged() { +	_inventoryWidget->markDirty();  } -void Gui::drawInventory() { -	Inventory &inventory = _game.getGameData().getInventory(); -	const Inventory::Items &items = inventory.getItems(); -	Common::Rect fullRect(INVENTORY_START_X, INVENTORY_START_Y, INVENTORY_START_X + Inventory::VISIBLE_ITEMS * INVENTORY_ITEM_WIDTH, INVENTORY_START_Y + INVENTORY_ITEM_HEIGHT); -	_screen->fillRect(fullRect, 0x00); -	for (int i = 0; i < MIN((int) items.size(), (int) Inventory::VISIBLE_ITEMS); ++i) { -		drawInventoryItem(items[i], i); +void Gui::onButtonClicked(ButtonWidget *button) { +	const int buttonId = button->getId(); +	if (buttonId <= BUTTON_PICKUP) { +		const ActionInfo::Action actions[] = {ActionInfo::Walk, ActionInfo::Talk, ActionInfo::Look, ActionInfo::Use, ActionInfo::PickUp}; +		_game.setCurrentAction(actions[buttonId]);  	}  } -void Gui::onInventoryChanged() { -	markInventoryDirty(); -} -  } diff --git a/engines/mutationofjb/gui.h b/engines/mutationofjb/gui.h index 27e0b0c2b3..5d8358b47f 100644 --- a/engines/mutationofjb/gui.h +++ b/engines/mutationofjb/gui.h @@ -23,10 +23,16 @@  #ifndef MUTATIONOFJB_GUI_H  #define MUTATIONOFJB_GUI_H +#include "common/array.h"  #include "common/hashmap.h"  #include "common/hash-str.h"  #include "graphics/surface.h"  #include "mutationofjb/inventory.h" +#include "mutationofjb/widgets/buttonwidget.h" + +namespace Common { +class Event; +}  namespace Graphics {  class Screen; @@ -35,31 +41,44 @@ class Screen;  namespace MutationOfJB {  class Game; +class Widget; +class InventoryWidget; -class Gui : public InventoryObserver { +class Gui : public InventoryObserver, public ButtonWidgetCallback {  public: +	typedef Common::HashMap<Common::String, int> InventoryMap; +  	friend class InventoryAnimationDecoderCallback; +	friend class HudAnimationDecoderCallback; +  	Gui(Game &game, Graphics::Screen *screen); +	~Gui(); +	Game &getGame(); +  	bool init();  	void update(); -	void markInventoryDirty(); +	void markDirty(); +	void handleEvent(const Common::Event &event);  	virtual void onInventoryChanged() override; +	virtual void onButtonClicked(ButtonWidget *) override;  private:  	bool loadInventoryGfx(); +	bool loadHudGfx();  	bool loadInventoryList();  	void drawInventoryItem(const Common::String &item, int pos);  	void drawInventory(); -	typedef Common::HashMap<Common::String, int> InventoryMap; -  	Game &_game;  	Graphics::Screen *_screen;  	InventoryMap _inventoryItems;  	Common::Array<Graphics::Surface> _inventorySurfaces; -	bool _inventoryDirty; +	Common::Array<Graphics::Surface> _hudSurfaces; + +	InventoryWidget *_inventoryWidget; +	Common::Array<Widget *> _widgets;  };  } diff --git a/engines/mutationofjb/module.mk b/engines/mutationofjb/module.mk index 729ea4409e..2352ae9613 100644 --- a/engines/mutationofjb/module.mk +++ b/engines/mutationofjb/module.mk @@ -18,6 +18,9 @@ MODULE_OBJS := \  	commands/removeitemcommand.o \  	commands/saycommand.o \  	commands/seqcommand.o \ +	widgets/buttonwidget.o \ +	widgets/inventorywidget.o \ +	widgets/widget.o \  	animationdecoder.o \  	debug.o \  	detection.o \ diff --git a/engines/mutationofjb/mutationofjb.cpp b/engines/mutationofjb/mutationofjb.cpp index df8ad113a6..e7f534edb0 100644 --- a/engines/mutationofjb/mutationofjb.cpp +++ b/engines/mutationofjb/mutationofjb.cpp @@ -43,7 +43,6 @@ MutationOfJBEngine::MutationOfJBEngine(OSystem *syst)  : Engine(syst),   _console(nullptr),   _screen(nullptr), - _currentAction(ActionInfo::Walk),   _mapObjectId(0) {  	debug("MutationOfJBEngine::MutationOfJBEngine");  } @@ -82,12 +81,12 @@ void MutationOfJBEngine::handleNormalScene(const Common::Event &event) {  		const int16 y = event.mouse.y;  		if (Door *const door = scene->findDoor(x, y)) { -			if (!_game->startActionSection(_currentAction, door->_name) && _currentAction == ActionInfo::Walk && door->_destSceneId != 0) { +			if (!_game->startActionSection(_game->getCurrentAction(), door->_name) && _game->getCurrentAction() == ActionInfo::Walk && door->_destSceneId != 0) {  				_game->changeScene(door->_destSceneId, _game->getGameData()._partB);  			}  		} else if (Static *const stat = scene->findStatic(x, y)) {  			if (stat->_active == 1) { -				_game->startActionSection(_currentAction, stat->_name); +				_game->startActionSection(_game->getCurrentAction(), stat->_name);  			}  		}  		break; @@ -95,6 +94,7 @@ void MutationOfJBEngine::handleNormalScene(const Common::Event &event) {  	default:  		break;  	} +	_game->getGui().handleEvent(event);  }  /* @@ -187,19 +187,19 @@ Common::Error MutationOfJBEngine::run() {  			{  				switch (event.kbd.ascii) {  				case 'g': -					_currentAction = ActionInfo::Walk; +					_game->setCurrentAction(ActionInfo::Walk);  					break;  				case 'r': -					_currentAction = ActionInfo::Talk; +					_game->setCurrentAction(ActionInfo::Talk);  					break;  				case 's': -					_currentAction = ActionInfo::Look; +					_game->setCurrentAction(ActionInfo::Look);  					break;  				case 'b': -					_currentAction = ActionInfo::Use; +					_game->setCurrentAction(ActionInfo::Use);  					break;  				case 'n': -					_currentAction = ActionInfo::PickUp; +					_game->setCurrentAction(ActionInfo::PickUp);  					break;  				}  			} diff --git a/engines/mutationofjb/room.h b/engines/mutationofjb/room.h index a2be2fc3be..e57d2ebb61 100644 --- a/engines/mutationofjb/room.h +++ b/engines/mutationofjb/room.h @@ -39,6 +39,7 @@ class Game;  class Room {  public:  	friend class RoomAnimationDecoderCallback; +	friend class GuiAnimationDecoderCallback;  	Room(Game *game, Graphics::Screen *screen);  	bool load(uint8 roomNumber, bool roomB); diff --git a/engines/mutationofjb/widgets/buttonwidget.cpp b/engines/mutationofjb/widgets/buttonwidget.cpp new file mode 100644 index 0000000000..9f9a401eb6 --- /dev/null +++ b/engines/mutationofjb/widgets/buttonwidget.cpp @@ -0,0 +1,70 @@ +/* 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/buttonwidget.h" +#include "common/events.h" +#include "graphics/managed_surface.h" + +namespace MutationOfJB { + +ButtonWidget::ButtonWidget(Gui &gui, const Common::Rect &area, const Graphics::Surface &normalSurface, const Graphics::Surface &pressedSurface) : +	Widget(gui, area), +	_normalSurface(normalSurface), +	_pressedSurface(pressedSurface), +	_callback(nullptr), +	_pressed(false) {} + +void ButtonWidget::setCallback(ButtonWidgetCallback *callback) { +	_callback = callback; +} + +void ButtonWidget::handleEvent(const Common::Event &event) { +	switch(event.type) { +	case Common::EVENT_LBUTTONDOWN: +	{ +		const int16 x = event.mouse.x; +		const int16 y = event.mouse.y; +		if (_area.contains(x, y)) { +			_pressed = true; +			markDirty(); +		} +		break; +	} +	case Common::EVENT_LBUTTONUP: +	{ +		if (_pressed) { +			_pressed = false; +			markDirty(); +			if (_callback) { +				_callback->onButtonClicked(this); +			} +		} +		break; +	} +	default: +		break; +	} +} +void ButtonWidget::_draw(Graphics::ManagedSurface &surface) { +	surface.blitFrom(_pressed ? _pressedSurface : _normalSurface, Common::Point(_area.left, _area.top)); +} +} diff --git a/engines/mutationofjb/widgets/buttonwidget.h b/engines/mutationofjb/widgets/buttonwidget.h new file mode 100644 index 0000000000..de8cb631f5 --- /dev/null +++ b/engines/mutationofjb/widgets/buttonwidget.h @@ -0,0 +1,58 @@ +/* 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_BUTTONWIDGET_H +#define MUTATIONOFJB_BUTTONWIDGET_H + +#include "mutationofjb/widgets/widget.h" +#include "graphics/surface.h" + +namespace MutationOfJB { + +class ButtonWidget; + +class ButtonWidgetCallback { +public: +	virtual ~ButtonWidgetCallback() {} +	virtual void onButtonClicked(ButtonWidget *) = 0; +}; + +class ButtonWidget : public Widget { +public: +	ButtonWidget(Gui &gui, const Common::Rect &area, const Graphics::Surface &normalSurface, const Graphics::Surface &pressedSurface); +	void setCallback(ButtonWidgetCallback *callback); + +	virtual void handleEvent(const Common::Event &event) override; + +protected: +	virtual void _draw(Graphics::ManagedSurface &) override; + +private: +	Graphics::Surface _normalSurface; +	Graphics::Surface _pressedSurface; +	ButtonWidgetCallback *_callback; +	bool _pressed; +}; + +} + +#endif diff --git a/engines/mutationofjb/widgets/inventorywidget.cpp b/engines/mutationofjb/widgets/inventorywidget.cpp new file mode 100644 index 0000000000..d78ef10adc --- /dev/null +++ b/engines/mutationofjb/widgets/inventorywidget.cpp @@ -0,0 +1,75 @@ +/* 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/inventorywidget.h" +#include "mutationofjb/game.h" +#include "mutationofjb/gamedata.h" +#include "mutationofjb/gui.h" +#include "mutationofjb/inventory.h" +#include "common/str.h" +#include "common/rect.h" +#include "common/util.h" +#include "graphics/managed_surface.h" + +namespace MutationOfJB { + +enum { +	INVENTORY_START_X = 88, +	INVENTORY_START_Y = 149, +	INVENTORY_ITEM_WIDTH = 34, +	INVENTORY_ITEM_HEIGHT = 33, +	INVENTORY_ITEMS_PER_LINE = 8, +	INVENTORY_ITEMS_LINES = 5 +}; + +InventoryWidget::InventoryWidget(Gui &gui, Gui::InventoryMap &inventoryMap, const Common::Array<Graphics::Surface>& inventorySurfaces) : +	Widget(gui, Common::Rect(INVENTORY_START_X, INVENTORY_START_Y, INVENTORY_START_X + Inventory::VISIBLE_ITEMS * INVENTORY_ITEM_WIDTH, INVENTORY_START_Y + INVENTORY_ITEM_HEIGHT)), +	_inventoryMap(inventoryMap), +	_surfaces(inventorySurfaces) {} + +void InventoryWidget::drawInventoryItem(Graphics::ManagedSurface &surface, const Common::String &item, int pos) { +	Gui::InventoryMap::iterator it = _inventoryMap.find(item); +	if (it == _inventoryMap.end()) { +		return; +	} + +	const int index = it->_value; +	const int surfaceNo = index / (INVENTORY_ITEMS_LINES * INVENTORY_ITEMS_PER_LINE); +	const int indexInSurface = index % (INVENTORY_ITEMS_LINES * INVENTORY_ITEMS_PER_LINE); +	const int itemX = indexInSurface % INVENTORY_ITEMS_PER_LINE; +	const int itemY = indexInSurface / INVENTORY_ITEMS_PER_LINE; + +	Common::Point destStartPos(INVENTORY_START_X + pos * INVENTORY_ITEM_WIDTH, INVENTORY_START_Y); +	Common::Rect sourceRect(itemX * INVENTORY_ITEM_WIDTH, itemY * INVENTORY_ITEM_HEIGHT, (itemX + 1) * INVENTORY_ITEM_WIDTH, (itemY + 1) * INVENTORY_ITEM_HEIGHT); +	surface.blitFrom(_surfaces[surfaceNo], sourceRect, destStartPos); +} + +void InventoryWidget::_draw(Graphics::ManagedSurface &surface) { +	Inventory &inventory = _gui.getGame().getGameData().getInventory(); +	const Inventory::Items &items = inventory.getItems(); +	surface.fillRect(_area, 0x00); +	for (int i = 0; i < MIN((int) items.size(), (int) Inventory::VISIBLE_ITEMS); ++i) { +		drawInventoryItem(surface, items[i], i); +	} +} + +} diff --git a/engines/mutationofjb/widgets/inventorywidget.h b/engines/mutationofjb/widgets/inventorywidget.h new file mode 100644 index 0000000000..f0bc4baeee --- /dev/null +++ b/engines/mutationofjb/widgets/inventorywidget.h @@ -0,0 +1,48 @@ +/* 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_INVENTORYWIDGET_H +#define MUTATIONOFJB_INVENTORYWIDGET_H + +#include "mutationofjb/widgets/widget.h" +#include "mutationofjb/gui.h" + +namespace Common { +class String; +} + +namespace MutationOfJB { + +class InventoryWidget : public Widget { +public: +	InventoryWidget(Gui &gui, Gui::InventoryMap &inventoryMap, const Common::Array<Graphics::Surface>& inventorySurfaces); +	virtual void _draw(Graphics::ManagedSurface &) override; + +private: +	void drawInventoryItem(Graphics::ManagedSurface &surface, const Common::String &item, int pos); +	Gui::InventoryMap &_inventoryMap; +	const Common::Array<Graphics::Surface>& _surfaces; +}; + +} + +#endif diff --git a/engines/mutationofjb/widgets/widget.cpp b/engines/mutationofjb/widgets/widget.cpp new file mode 100644 index 0000000000..fea7f6fbe0 --- /dev/null +++ b/engines/mutationofjb/widgets/widget.cpp @@ -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. + * + */ + +#include "mutationofjb/widgets/widget.h" + +namespace MutationOfJB { + +int Widget::getId() const { +	return _id; +} + +void Widget::setId(int id) { +	_id = id; +} + +void Widget::markDirty() { +	_dirty = true; +} + +bool Widget::isDirty() const { +	return _dirty; +} + +void Widget::update(Graphics::ManagedSurface &surface) { +	if (_dirty) { +		_draw(surface); +		_dirty = false; +	} +} + +} diff --git a/engines/mutationofjb/widgets/widget.h b/engines/mutationofjb/widgets/widget.h new file mode 100644 index 0000000000..f81d466c1c --- /dev/null +++ b/engines/mutationofjb/widgets/widget.h @@ -0,0 +1,66 @@ +/* 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_WIDGET_H +#define MUTATIONOFJB_WIDGET_H + +#include <common/scummsys.h> +#include <common/rect.h> + +namespace Common { +class Event; +} + +namespace Graphics { +class ManagedSurface; +} + +namespace MutationOfJB { + +class Gui; + +class Widget { +public: +	Widget(Gui &gui, const Common::Rect &area) : _gui(gui), _area(area), _id(0), _dirty(true) {} +	virtual ~Widget() {} + +	int getId() const; +	void setId(int id); + +	bool isDirty() const; +	void markDirty(); +	void update(Graphics::ManagedSurface &); + +	virtual void handleEvent(const Common::Event &) {} +protected: +	virtual void _draw(Graphics::ManagedSurface &) = 0; + +	Gui &_gui; +	Common::Rect _area; +	int _id; +	bool _dirty; +}; + +} + +#endif +  | 
