aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Sandulenko2016-04-28 13:43:06 +0200
committerEugene Sandulenko2016-04-28 13:43:29 +0200
commit3027433b669d00a5b16689a4de518639d7dff746 (patch)
tree83e1841bda357c4e632bf7679ced8ab9561287f0
parent6c610e7a1882144283b1de0347ea91f4bb4f41ea (diff)
downloadscummvm-rg350-3027433b669d00a5b16689a4de518639d7dff746.tar.gz
scummvm-rg350-3027433b669d00a5b16689a4de518639d7dff746.tar.bz2
scummvm-rg350-3027433b669d00a5b16689a4de518639d7dff746.zip
WAGE: Moved game-specific menu creation to gui.cpp
-rw-r--r--engines/wage/gui.cpp68
-rw-r--r--engines/wage/gui.h3
-rw-r--r--engines/wage/macmenu.cpp154
-rw-r--r--engines/wage/macmenu.h23
4 files changed, 136 insertions, 112 deletions
diff --git a/engines/wage/gui.cpp b/engines/wage/gui.cpp
index 2809656bec..9eca3a8fea 100644
--- a/engines/wage/gui.cpp
+++ b/engines/wage/gui.cpp
@@ -61,6 +61,27 @@
namespace Wage {
+static const MenuData menuSubItems[] = {
+ { kMenuHighLevel, "File", 0, 0, false },
+ { kMenuHighLevel, "Edit", 0, 0, false },
+ { kMenuFile, "New", kMenuActionNew, 0, false },
+ { kMenuFile, "Open...", kMenuActionOpen, 0, false },
+ { kMenuFile, "Close", kMenuActionClose, 0, true },
+ { kMenuFile, "Save", kMenuActionSave, 0, false },
+ { kMenuFile, "Save as...", kMenuActionSaveAs, 0, true },
+ { kMenuFile, "Revert", kMenuActionRevert, 0, false },
+ { kMenuFile, "Quit", kMenuActionQuit, 0, true },
+
+ { kMenuEdit, "Undo", kMenuActionUndo, 'Z', false },
+ { kMenuEdit, NULL, 0, 0, false },
+ { kMenuEdit, "Cut", kMenuActionCut, 'K', false },
+ { kMenuEdit, "Copy", kMenuActionCopy, 'C', false },
+ { kMenuEdit, "Paste", kMenuActionPaste, 'V', false },
+ { kMenuEdit, "Clear", kMenuActionClear, 'B', false },
+
+ { 0, NULL, 0, 0, false }
+};
+
static void cursorTimerHandler(void *refCon) {
Gui *gui = (Gui *)refCon;
@@ -122,6 +143,22 @@ Gui::Gui(WageEngine *engine) {
_menu = _wm.addMenu(this);
+ _menu->addStaticMenus(menuSubItems);
+ _menu->addMenuSubItem(kMenuAbout, _engine->_world->getAboutMenuItemName(), kMenuActionAbout);
+
+ _commandsMenuId = _menu->addMenuItem(_engine->_world->_commandsMenuName.c_str());
+ regenCommandsMenu();
+
+ if (!_engine->_world->_weaponMenuDisabled) {
+ _weaponsMenuId = _menu->addMenuItem(_engine->_world->_weaponsMenuName.c_str());
+
+ regenWeaponsMenu();
+ } else {
+ _weaponsMenuId = -1;
+ }
+
+ _menu->calcDimensions();
+
_sceneWindow = _wm.addWindow(false, false, false);
_sceneWindow->setCallback(sceneWindowCallback, this);
@@ -231,11 +268,38 @@ static bool consoleWindowCallback(WindowClick click, Common::Event &event, void
}
void Gui::regenCommandsMenu() {
- _menu->regenCommandsMenu();
+ _menu->createSubMenuFromString(_commandsMenuId, _engine->_world->_commandsMenu.c_str());
}
void Gui::regenWeaponsMenu() {
- _menu->regenWeaponsMenu();
+ if (_engine->_world->_weaponMenuDisabled)
+ return;
+
+ _menu->clearSubMenu(_weaponsMenuId);
+
+ Chr *player = _engine->_world->_player;
+ ObjArray *weapons = player->getWeapons(true);
+
+ bool empty = true;
+
+ for (uint i = 0; i < weapons->size(); i++) {
+ Obj *obj = (*weapons)[i];
+ if (obj->_type == Obj::REGULAR_WEAPON ||
+ obj->_type == Obj::THROW_WEAPON ||
+ obj->_type == Obj::MAGICAL_OBJECT) {
+ Common::String command(obj->_operativeVerb);
+ command += " ";
+ command += obj->_name;
+
+ _menu->addMenuSubItem(_weaponsMenuId, command.c_str(), kMenuActionCommand, 0, 0, true);
+
+ empty = false;
+ }
+ }
+ delete weapons;
+
+ if (empty)
+ _menu->addMenuSubItem(_weaponsMenuId, "You have no weapons", 0, 0, 0, false);
}
bool Gui::processEvent(Common::Event &event) {
diff --git a/engines/wage/gui.h b/engines/wage/gui.h
index cba02bb32b..c3612db6b5 100644
--- a/engines/wage/gui.h
+++ b/engines/wage/gui.h
@@ -145,6 +145,9 @@ private:
Common::String _undobuffer;
int _inputTextLineNum;
+
+ int _commandsMenuId;
+ int _weaponsMenuId;
};
} // End of namespace Wage
diff --git a/engines/wage/macmenu.cpp b/engines/wage/macmenu.cpp
index 5aecfb6a11..0b3b76c7bb 100644
--- a/engines/wage/macmenu.cpp
+++ b/engines/wage/macmenu.cpp
@@ -90,66 +90,63 @@ struct MenuItem {
MenuItem(const char *n) : name(n) {}
};
-struct MenuData {
- int menunum;
- const char *title;
- int action;
- byte shortcut;
- bool enabled;
-} static const menuSubItems[] = {
- { kMenuFile, "New", kMenuActionNew, 0, false },
- { kMenuFile, "Open...", kMenuActionOpen, 0, false },
- { kMenuFile, "Close", kMenuActionClose, 0, true },
- { kMenuFile, "Save", kMenuActionSave, 0, false },
- { kMenuFile, "Save as...", kMenuActionSaveAs, 0, true },
- { kMenuFile, "Revert", kMenuActionRevert, 0, false },
- { kMenuFile, "Quit", kMenuActionQuit, 0, true },
-
- { kMenuEdit, "Undo", kMenuActionUndo, 'Z', false },
- { kMenuEdit, NULL, 0, 0, false },
- { kMenuEdit, "Cut", kMenuActionCut, 'K', false },
- { kMenuEdit, "Copy", kMenuActionCopy, 'C', false },
- { kMenuEdit, "Paste", kMenuActionPaste, 'V', false },
- { kMenuEdit, "Clear", kMenuActionClear, 'B', false },
-
- { 0, NULL, 0, 0, false }
-};
-
Menu::Menu(int id, const Common::Rect &bounds, MacWindowManager *wm, Gui *gui)
: BaseMacWindow(id, false, wm), _gui(gui) {
_font = getMenuFont();
_screen.create(bounds.width(), bounds.height(), Graphics::PixelFormat::createFormatCLUT8());
+ _bbox.left = 0;
+ _bbox.top = 0;
+ _bbox.right = _screen.w - 1;
+ _bbox.bottom = kMenuHeight - 1;
+
+ _menuActivated = false;
+ _activeItem = -1;
+ _activeSubItem = -1;
+
+ _screenCopy.create(_screen.w, _screen.h, Graphics::PixelFormat::createFormatCLUT8());
+ _tempSurface.create(_screen.w, _font->getFontHeight(), Graphics::PixelFormat::createFormatCLUT8());
+}
+
+Menu::~Menu() {
+ for (uint i = 0; i < _items.size(); i++) {
+ for (uint j = 0; j < _items[i]->subitems.size(); j++)
+ delete _items[i]->subitems[j];
+ delete _items[i];
+ }
+}
+
+void Menu::addStaticMenus(const MenuData *data) {
MenuItem *about = new MenuItem(_wm->hasBuiltInFonts() ? "\xa9" : "\xf0"); // (c) Symbol as the most resembling apple
_items.push_back(about);
- _items[0]->subitems.push_back(new MenuSubItem(_gui->_engine->_world->getAboutMenuItemName(), kMenuActionAbout));
- MenuItem *file = new MenuItem("File");
- _items.push_back(file);
+ for (int i = 0; data[i].menunum; i++) {
+ const MenuData *m = &data[i];
- MenuItem *edit = new MenuItem("Edit");
- _items.push_back(edit);
+ if (m->menunum == kMenuHighLevel) {
+ MenuItem *item = new MenuItem(m->title);
+ _items.push_back(item);
- for (int i = 0; menuSubItems[i].menunum; i++) {
- const MenuData *m = &menuSubItems[i];
+ continue;
+ }
_items[m->menunum]->subitems.push_back(new MenuSubItem(m->title, m->action, 0, m->shortcut, m->enabled));
}
+}
- _commands = new MenuItem(_gui->_engine->_world->_commandsMenuName.c_str());
- _items.push_back(_commands);
- regenCommandsMenu();
-
- _weapons = NULL;
+int Menu::addMenuItem(const char *name) {
+ MenuItem *i = new MenuItem(name);
+ _items.push_back(i);
- if (!_gui->_engine->_world->_weaponMenuDisabled) {
- _weapons = new MenuItem(_gui->_engine->_world->_weaponsMenuName.c_str());
- _items.push_back(_weapons);
+ return _items.size() - 1;
+}
- regenWeaponsMenu();
- }
+void Menu::addMenuSubItem(int id, const char *text, int action, int style, char shortcut, bool enabled) {
+ _items[id]->subitems.push_back(new MenuSubItem(text, action, style, shortcut, enabled));
+}
+void Menu::calcDimensions() {
// Calculate menu dimensions
int y = 1;
int x = 18;
@@ -168,40 +165,22 @@ Menu::Menu(int id, const Common::Rect &bounds, MacWindowManager *wm, Gui *gui)
x += w + kMenuSpacing;
}
-
- _bbox.left = 0;
- _bbox.top = 0;
- _bbox.right = _screen.w - 1;
- _bbox.bottom = kMenuHeight - 1;
-
- _menuActivated = false;
- _activeItem = -1;
- _activeSubItem = -1;
-
- _screenCopy.create(_screen.w, _screen.h, Graphics::PixelFormat::createFormatCLUT8());
- _tempSurface.create(_screen.w, _font->getFontHeight(), Graphics::PixelFormat::createFormatCLUT8());
-}
-
-Menu::~Menu() {
- for (uint i = 0; i < _items.size(); i++) {
- for (uint j = 0; j < _items[i]->subitems.size(); j++)
- delete _items[i]->subitems[j];
- delete _items[i];
- }
}
-void Menu::regenCommandsMenu() {
- for (uint j = 0; j < _commands->subitems.size(); j++)
- delete _commands->subitems[j];
+void Menu::clearSubMenu(int id) {
+ MenuItem *menu = _items[id];
- _commands->subitems.clear();
+ for (uint j = 0; j < menu->subitems.size(); j++)
+ delete menu->subitems[j];
- createCommandsMenu(_commands);
- calcMenuBounds(_commands);
+ menu->subitems.clear();
}
-void Menu::createCommandsMenu(MenuItem *menu) {
- Common::String string(_gui->_engine->_world->_commandsMenu);
+void Menu::createSubMenuFromString(int id, const char *str) {
+ clearSubMenu(id);
+
+ MenuItem *menu = _items[id];
+ Common::String string(str);
Common::String item;
@@ -264,41 +243,8 @@ void Menu::createCommandsMenu(MenuItem *menu) {
item.clear();
}
-}
-
-void Menu::regenWeaponsMenu() {
- if (_gui->_engine->_world->_weaponMenuDisabled)
- return;
-
- for (uint j = 0; j < _weapons->subitems.size(); j++)
- delete _weapons->subitems[j];
-
- _weapons->subitems.clear();
-
- createWeaponsMenu(_weapons);
- calcMenuBounds(_weapons);
-}
-
-void Menu::createWeaponsMenu(MenuItem *menu) {
- Chr *player = _gui->_engine->_world->_player;
- ObjArray *weapons = player->getWeapons(true);
-
- for (uint i = 0; i < weapons->size(); i++) {
- Obj *obj = (*weapons)[i];
- if (obj->_type == Obj::REGULAR_WEAPON ||
- obj->_type == Obj::THROW_WEAPON ||
- obj->_type == Obj::MAGICAL_OBJECT) {
- Common::String command(obj->_operativeVerb);
- command += " ";
- command += obj->_name;
-
- menu->subitems.push_back(new MenuSubItem(command.c_str(), kMenuActionCommand, 0, 0, true));
- }
- }
- delete weapons;
- if (menu->subitems.empty())
- menu->subitems.push_back(new MenuSubItem("You have no weapons", 0, 0, 0, false));
+ calcMenuBounds(menu);
}
const Graphics::Font *Menu::getMenuFont() {
diff --git a/engines/wage/macmenu.h b/engines/wage/macmenu.h
index 0ad99a458c..c80de9d683 100644
--- a/engines/wage/macmenu.h
+++ b/engines/wage/macmenu.h
@@ -64,6 +64,7 @@ enum {
};
enum {
+ kMenuHighLevel = -1,
kMenuAbout = 0,
kMenuFile = 1,
kMenuEdit = 2,
@@ -90,16 +91,30 @@ enum {
kMenuActionCommand
};
+struct MenuData {
+ int menunum;
+ const char *title;
+ int action;
+ byte shortcut;
+ bool enabled;
+};
+
class Menu : public BaseMacWindow {
public:
Menu(int id, const Common::Rect &bounds, MacWindowManager *wm, Gui *gui);
~Menu();
+ void addStaticMenus(const MenuData *data);
+ void calcDimensions();
+
+ int addMenuItem(const char *name);
+ void addMenuSubItem(int id, const char *text, int action, int style = 0, char shortcut = 0, bool enabled = true);
+ void createSubMenuFromString(int id, const char *string);
+ void clearSubMenu(int id);
+
bool draw(Graphics::ManagedSurface *g, bool forceRedraw = false);
bool processEvent(Common::Event &event);
- void regenCommandsMenu();
- void regenWeaponsMenu();
void enableCommand(int menunum, int action, bool state);
void disableAllMenus();
@@ -120,8 +135,6 @@ private:
int calculateMenuWidth(MenuItem *menu);
void calcMenuBounds(MenuItem *menu);
void renderSubmenu(MenuItem *menu);
- void createCommandsMenu(MenuItem *menu);
- void createWeaponsMenu(MenuItem *menu);
void executeCommand(MenuSubItem *subitem);
bool keyEvent(Common::Event &event);
@@ -132,8 +145,6 @@ private:
bool processMenuShortCut(byte flags, uint16 ascii);
Common::Array<MenuItem *> _items;
- MenuItem *_weapons;
- MenuItem *_commands;
const Graphics::Font *_font;