Skip to content

Commit

Permalink
WAGE: Generate Commands menu
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Jan 14, 2016
1 parent 3dc9223 commit 0c6b063
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 18 deletions.
83 changes: 77 additions & 6 deletions engines/wage/menu.cpp
Expand Up @@ -92,7 +92,9 @@ enum {
kMenuActionCut,
kMenuActionCopy,
kMenuActionPaste,
kMenuActionClear
kMenuActionClear,

kMenuActionCommand
};

struct MenuData {
Expand Down Expand Up @@ -121,6 +123,9 @@ struct MenuData {
};

Menu::Menu(Gui *gui) : _gui(gui) {
assert(_gui->_engine);
assert(_gui->_engine->_world);

MenuItem *about = new MenuItem(_gui->_builtInFonts ? "\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));
Expand All @@ -137,14 +142,11 @@ Menu::Menu(Gui *gui) : _gui(gui) {
_items[m->menunum]->subitems.push_back(new MenuSubItem(m->title, m->action, 0, m->shortcut, m->enabled));
}

MenuItem *commands = new MenuItem("Commands");
MenuItem *commands = createCommandsMenu();
_items.push_back(commands);

assert(_gui->_engine);
assert(_gui->_engine->_world);

if (!_gui->_engine->_world->_weaponMenuDisabled) {
MenuItem *weapons = new MenuItem("Weapons");
MenuItem *weapons = new MenuItem(_gui->_engine->_world->_weaponsMenuName.c_str());
_items.push_back(weapons);
}

Expand Down Expand Up @@ -189,6 +191,75 @@ Menu::~Menu() {
}
}

MenuItem *Menu::createCommandsMenu() {
MenuItem *menu = new MenuItem(_gui->_engine->_world->_commandsMenuName.c_str());
Common::String string(_gui->_engine->_world->_commandsMenu);

Common::String item;

for (int i = 0; i < string.size(); i++) {
while(i < string.size() && string[i] != ';') // Read token
item += string[i++];

if (item == "(-") {
menu->subitems.push_back(new MenuSubItem(NULL, 0));
} else {
bool enabled = true;
int style = 0;
char shortcut = 0;
char *shortptr = strrchr(item.c_str(), '/');
if (shortptr != NULL) {
if (strlen(shortptr) == 2) {
shortcut = shortptr[1];
item.deleteLastChar();
item.deleteLastChar();
} else {
error("Unexpected shortcut: '%s', item '%s' in menu '%s'", shortptr, item.c_str(), string.c_str());
}
}

while (item.size() >= 2 && item[item.size() - 2] == '<') {
char c = item.lastChar();
if (c == 'B') {
style |= kFontStyleBold;
} else if (c == 'I') {
style |= kFontStyleItalic;
} else if (c == 'U') {
style |= kFontStyleUnderline;
} else if (c == 'O') {
style |= kFontStyleOutline;
} else if (c == 'S') {
style |= kFontStyleShadow;
} else if (c == 'C') {
style |= kFontStyleCondensed;
} else if (c == 'E') {
style |= kFontStyleExtended;
}
item.deleteLastChar();
item.deleteLastChar();
}

Common::String tmpitem(item);
tmpitem.trim();
if (tmpitem[0] == '(') {
enabled = false;

for (int j = 0; j < item.size(); j++)
if (item[j] == '(') {
item.deleteChar(j);
break;
}
}

menu->subitems.push_back(new MenuSubItem(item.c_str(), kMenuActionCommand, style, shortcut, enabled));
}

item = "";
}

return menu;
}

const Graphics::Font *Menu::getMenuFont() {
return _gui->getFont("Chicago-12", Graphics::FontManager::kBigGUIFont);
}
Expand Down
11 changes: 11 additions & 0 deletions engines/wage/menu.h
Expand Up @@ -53,6 +53,16 @@ namespace Wage {
struct MenuItem;
struct MenuSubItem;

enum {
kFontStyleBold = 1,
kFontStyleItalic = 2,
kFontStyleUnderline = 4,
kFontStyleOutline = 8,
kFontStyleShadow = 16,
kFontStyleCondensed = 32,
kFontStyleExtended = 64
};

class Menu {
public:
Menu(Gui *gui);
Expand All @@ -77,6 +87,7 @@ class Menu {
int calculateMenuWidth(MenuItem *menu);
void calcMenuBounds(MenuItem *menu);
void renderSubmenu(MenuItem *menu);
MenuItem *createCommandsMenu();

Common::Array<MenuItem *> _items;

Expand Down
22 changes: 11 additions & 11 deletions engines/wage/world.cpp
Expand Up @@ -273,17 +273,17 @@ bool World::loadWorld(Common::MacResManager *resMan) {
}
res = resMan->getResource(MKTAG('M','E','N','U'), 2004);
if (res != NULL) {
readMenu(res);
warning("STUB: commandsMenu");
//world.setCommandsMenuName(commandsMenu[0]);
//world.setDefaultCommandsMenu(commandsMenu[1]);
Common::StringArray *menu = readMenu(res);
_commandsMenuName = menu->operator[](0);
_commandsMenu = menu->operator[](1);
delete menu;
delete res;
}
res = resMan->getResource(MKTAG('M','E','N','U'), 2005);
if (res != NULL) {
readMenu(res);
warning("STUB: weaponsMenu");
//world.setWeaponsMenuName(weaponsMenu[0]);
Common::StringArray *menu = readMenu(res);
_weaponsMenuName = menu->operator[](0);
delete menu;
delete res;
}
// TODO: Read Apple menu and get the name of that menu item..
Expand All @@ -294,7 +294,7 @@ bool World::loadWorld(Common::MacResManager *resMan) {
return true;
}

Common::StringArray World::readMenu(Common::SeekableReadStream *res) {
Common::StringArray *World::readMenu(Common::SeekableReadStream *res) {
res->skip(10);
int enableFlags = res->readUint32BE();
String menuName = readPascalString(res);
Expand Down Expand Up @@ -327,9 +327,9 @@ Common::StringArray World::readMenu(Common::SeekableReadStream *res) {
menuItemNumber++;
}

Common::StringArray result;
result.push_back(menuName);
result.push_back(sb);
Common::StringArray *result = new Common::StringArray;
result->push_back(menuName);
result->push_back(sb);

warning("menuName: %s", menuName.c_str());
warning("sb: %s", sb.c_str());
Expand Down
6 changes: 5 additions & 1 deletion engines/wage/world.h
Expand Up @@ -95,6 +95,10 @@ class World {
Common::String *_saveBeforeCloseMessage;
Common::String *_revertMessage;

Common::String _commandsMenuName;
Common::String _commandsMenu;
Common::String _weaponsMenuName;

void addScene(Scene *room) {
if (room->_name.size() != 0) {
String s = room->_name;
Expand Down Expand Up @@ -128,7 +132,7 @@ class World {
}

private:
Common::StringArray readMenu(Common::SeekableReadStream *res);
Common::StringArray *readMenu(Common::SeekableReadStream *res);
};

} // End of namespace Wage
Expand Down

0 comments on commit 0c6b063

Please sign in to comment.