diff options
author | Borja Lorente | 2016-06-08 17:13:02 +0200 |
---|---|---|
committer | Borja Lorente | 2016-08-14 18:11:38 +0200 |
commit | 4611429959b2fdc8608b6c972997b4e0b5ca05e7 (patch) | |
tree | 52b95c29c4bcba4b2741db987701ebcb1478d72e /engines/macventure | |
parent | dd072a39de77f410c41604bcbcc1581606422f67 (diff) | |
download | scummvm-rg350-4611429959b2fdc8608b6c972997b4e0b5ca05e7.tar.gz scummvm-rg350-4611429959b2fdc8608b6c972997b4e0b5ca05e7.tar.bz2 scummvm-rg350-4611429959b2fdc8608b6c972997b4e0b5ca05e7.zip |
MACVENTURE: Add submenu loading
Diffstat (limited to 'engines/macventure')
-rw-r--r-- | engines/macventure/gui.cpp | 80 | ||||
-rw-r--r-- | engines/macventure/gui.h | 6 | ||||
-rw-r--r-- | engines/macventure/macventure.cpp | 60 | ||||
-rw-r--r-- | engines/macventure/macventure.h | 8 | ||||
-rw-r--r-- | engines/macventure/menu.cpp | 53 | ||||
-rw-r--r-- | engines/macventure/menu.h | 56 |
6 files changed, 197 insertions, 66 deletions
diff --git a/engines/macventure/gui.cpp b/engines/macventure/gui.cpp index 38a633673c..10901e952e 100644 --- a/engines/macventure/gui.cpp +++ b/engines/macventure/gui.cpp @@ -1,3 +1,25 @@ +/* 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 "common/file.h" #include "image/bmp.h" @@ -16,8 +38,9 @@ static const Graphics::MenuData menuSubItems[] = { { 0, "How yo duin", 0, 0, false }, }; -Gui::Gui(MacVentureEngine *engine) { +Gui::Gui(MacVentureEngine *engine, Common::MacResManager *resman) { _engine = engine; + _resourceManager = resman; initGUI(); } @@ -29,6 +52,10 @@ void Gui::draw() { _wm.draw(); } +bool Gui::processEvent(Common::Event &event) { + return _wm.processEvent(event); +} + void Gui::initGUI() { _screen.create(kScreenWidth, kScreenHeight, Graphics::PixelFormat::createFormatCLUT8()); _wm.setScreen(&_screen); @@ -38,7 +65,8 @@ void Gui::initGUI() { _menu = _wm.addMenu(); - loadMenus(); + if (!loadMenus()) + error("Could not load menus"); _menu->calcDimensions(); @@ -76,10 +104,50 @@ void Gui::loadBorder(Graphics::MacWindow * target, Common::String filename, bool } } -void Gui::loadMenus() { - Graphics::MenuData data; - Common::Array<Graphics::MenuData>::const_iterator iter; - _menu->addStaticMenus(_engine->getMenuData()); +bool Gui::loadMenus() { + Common::MacResIDArray resArray; + Common::SeekableReadStream *res; + Common::MacResIDArray::const_iterator iter; + + if ((resArray = _resourceManager->getResIDArray(MKTAG('M', 'E', 'N', 'U'))).size() == 0) + return false; + + _menu->addMenuItem("(c)"); + _menu->addMenuSubItem(0, "Hello", 0, 0, 'K', true); + + int i = 1; + for (iter = resArray.begin(); iter != resArray.end(); ++iter) { + res = _resourceManager->getResource(MKTAG('M', 'E', 'N', 'U'), *iter); + + Graphics::MenuData data; + int menunum = -1; // High level menus have level -1 + /* Skip menuID, width, height, resourceID, placeholder */ + for (int skip = 0; skip < 5; skip++) { res->readUint16BE(); } + bool enabled = res->readUint32BE(); + uint8 titleLength = res->readByte(); + char* title = new char[titleLength + 1]; + res->read(title, titleLength); + title[titleLength] = '\0'; + + if (titleLength > 2) { + _menu->addMenuItem(title); + + // Read submenu items + while (titleLength = res->readByte()) { + title = new char[titleLength + 1]; + res->read(title, titleLength); + title[titleLength] = '\0'; + // Skip icon, key, mark, style + for (int skip = 0; skip < 4; skip++) { res->readUint16BE(); } + _menu->addMenuSubItem(i, title, 0); + } + } + + i++; + } + + return true; + } } // End of namespace MacVenture diff --git a/engines/macventure/gui.h b/engines/macventure/gui.h index c6aae15303..96f2380ca0 100644 --- a/engines/macventure/gui.h +++ b/engines/macventure/gui.h @@ -35,14 +35,16 @@ class MacVentureEngine; class Gui { public: - Gui(MacVentureEngine *engine); + Gui(MacVentureEngine *engine, Common::MacResManager *resman); ~Gui(); void draw(); + bool processEvent(Common::Event &event); private: // Attributes MacVentureEngine *_engine; + Common::MacResManager *_resourceManager; Graphics::ManagedSurface _screen; Graphics::MacWindowManager _wm; @@ -52,7 +54,7 @@ private: // Attributes private: // Methods void initGUI(); - void loadMenus(); + bool loadMenus(); void loadBorder(Graphics::MacWindow * target, Common::String filename, bool active); }; diff --git a/engines/macventure/macventure.cpp b/engines/macventure/macventure.cpp index 5eefde51f3..5660fde16c 100644 --- a/engines/macventure/macventure.cpp +++ b/engines/macventure/macventure.cpp @@ -63,7 +63,7 @@ Common::Error MacVentureEngine::run() { _debugger = new Console(this); // Additional setup. - debug("MacVentureEngine::init"); + debug("MacVentureEngine::init"); // Your main even loop should be (invoked from) here. debug("MacVentureEngine::go: Hello, World!"); @@ -72,10 +72,7 @@ Common::Error MacVentureEngine::run() { if (!_resourceManager->open(getGameFileName())) error("Could not open %s as a resource fork", getGameFileName()); - if (!loadMenuData()) - error("Could not load menu data from %s", getGameFileName()); - - _gui = new Gui(this); + _gui = new Gui(this, _resourceManager); _shouldQuit = false; while (!_shouldQuit) { @@ -94,55 +91,18 @@ void MacVentureEngine::processEvents() { Common::Event event; while (_eventMan->pollEvent(event)) { + if (_gui->processEvent(event)) + continue; + switch (event.type) { - case Common::EVENT_QUIT: - _shouldQuit = true; - break; - default: - break; + case Common::EVENT_QUIT: + _shouldQuit = true; + break; + default: + break; } } } -bool MacVentureEngine::loadMenuData() { - Common::MacResIDArray resArray; - Common::SeekableReadStream *res; - Common::MacResIDArray::const_iterator iter; - - if ((resArray = _resourceManager->getResIDArray(MKTAG('M', 'E', 'N', 'U'))).size() == 0) - return false; - - _menuData = new Graphics::MenuData[resArray.size()]; - int i = 0; - - for (iter = resArray.begin(); iter != resArray.end(); ++iter) { - res = _resourceManager->getResource(MKTAG('M', 'E', 'N', 'U'), *iter); - - Graphics::MenuData data; - int menunum = -1; - for (int i = 0; i < 5; i++) { - res->readUint16BE(); - // Skip menuID, width, height, resourceID, placeholder - } - bool enabled = res->readUint32BE(); - uint8 titleLength = res->readByte(); - char* title = new char[titleLength+1]; - res->read(title, titleLength); - title[titleLength] = '\0'; - - _menuData[i] = { menunum, title, 0, 0, enabled}; - i++; - } - - // Override last value (end-of-menu) with our end-of-menu - _menuData[resArray.size() - 1] = { 0, 0, 0, 0, false }; - - return true; -} - -Graphics::MenuData* MacVentureEngine::getMenuData() { - return _menuData; -} - } // End of namespace MacVenture diff --git a/engines/macventure/macventure.h b/engines/macventure/macventure.h index 254f162d54..771588fde1 100644 --- a/engines/macventure/macventure.h +++ b/engines/macventure/macventure.h @@ -58,12 +58,8 @@ public: virtual Common::Error run(); - Graphics::MenuData *getMenuData(); - private: void processEvents(); - - bool loadMenuData(); private: // Attributes @@ -82,10 +78,6 @@ private: // Methods const char* getGameFileName() const; -private: //To move - - Graphics::MenuData *_menuData; - }; diff --git a/engines/macventure/menu.cpp b/engines/macventure/menu.cpp new file mode 100644 index 0000000000..dd3c495e10 --- /dev/null +++ b/engines/macventure/menu.cpp @@ -0,0 +1,53 @@ +/* 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 "macventure/menu.h" +#include "macventure/macventure.h" + +#include "common/file.h" +#include "graphics/macgui/macwindowmanager.h" + +namespace MacVenture { + +Menu::Menu(MacVentureEngine *engine, Graphics::MacWindowManager *wm) { + + _engine = engine; + _wm = wm; + + _menu = _wm->addMenu(); + + if (!loadMenuData()) + error("Could not load menu data from %s", _engine->getGameFileName()); +} + +Menu::~Menu() { + delete _ +} + +void Menu::draw() { + +} + +bool Menu::loadMenuData() { + +} + +} // End of namespace MacVenture
\ No newline at end of file diff --git a/engines/macventure/menu.h b/engines/macventure/menu.h new file mode 100644 index 0000000000..dab6369e15 --- /dev/null +++ b/engines/macventure/menu.h @@ -0,0 +1,56 @@ +/* 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 MACVENTURE_MENU_H +#define MACVENTURE_MENU_H + +namespace MacVenture { + +class MacVentureEngine; + +class Graphics::MacWindowManager; + +class Menu { + +public: + Menu(MacVentureEngine *engine, Graphics::MacWindowManager *wm); + ~Menu(); + + void draw(); + +private: // Attributes + + MacVentureEngine *_engine; + Graphics::MacWindowManager *_wm; + Graphics::Menu *_menu; + +private: // Methods + + void init(); + bool loadMenuData(); + +}; + +} // End of namespace MacVenture + +#endif + |