WAGE: Regenerate weapons menu on demand

This commit is contained in:
Eugene Sandulenko 2016-01-15 11:25:50 +01:00
parent 61c4f2091b
commit 5a887808ab
5 changed files with 32 additions and 9 deletions

View File

@ -579,6 +579,10 @@ void Gui::loadFonts() {
delete dat;
}
void Gui::regenWeaponsMenu() {
_menu->regenWeaponsMenu();
}
void Gui::mouseMove(int x, int y) {
if (_menu->_menuActivated) {
if (_menu->mouseMove(x, y))

View File

@ -97,6 +97,7 @@ public:
void drawInput();
void setSceneDirty() { _sceneDirty = true; }
const Graphics::Font *getFont(const char *name, Graphics::FontManager::FontUsage fallback);
void regenWeaponsMenu();
private:
void paintBorder(Graphics::Surface *g, Common::Rect &r, WindowType windowType);

View File

@ -126,6 +126,8 @@ Menu::Menu(Gui *gui) : _gui(gui) {
assert(_gui->_engine);
assert(_gui->_engine->_world);
_font = getMenuFont();
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));
@ -146,12 +148,13 @@ Menu::Menu(Gui *gui) : _gui(gui) {
_items.push_back(commands);
if (!_gui->_engine->_world->_weaponMenuDisabled) {
MenuItem *weapons = createWeaponsMenu();
_items.push_back(weapons);
_weapons = new MenuItem(_gui->_engine->_world->_weaponsMenuName.c_str());
_items.push_back(_weapons);
regenWeaponsMenu();
}
// Calculate menu dimensions
_font = getMenuFont();
int y = 1;
int x = 18;
@ -260,9 +263,21 @@ MenuItem *Menu::createCommandsMenu() {
return menu;
}
MenuItem *Menu::createWeaponsMenu() {
void Menu::regenWeaponsMenu() {
if (_gui->_engine->_world->_weaponMenuDisabled)
return;
for (int 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;
MenuItem *menu = new MenuItem(_gui->_engine->_world->_weaponsMenuName.c_str());
WeaponArray *weapons = player->getWeapons(true);
for (int i = 0; i < weapons->size(); i++) {
@ -275,15 +290,12 @@ MenuItem *Menu::createWeaponsMenu() {
command += obj->_name;
menu->subitems.push_back(new MenuSubItem(command.c_str(), kMenuActionCommand, 0, 0, true));
}
}
delete weapons;
if (menu->subitems.size() == 0)
menu->subitems.push_back(new MenuSubItem("You have no weapons", 0, 0, 0, false));
return menu;
}
const Graphics::Font *Menu::getMenuFont() {

View File

@ -73,6 +73,8 @@ public:
bool mouseRelease(int x, int y);
bool mouseMove(int x, int y);
void regenWeaponsMenu();
bool _menuActivated;
Common::Rect _bbox;
@ -88,10 +90,11 @@ private:
void calcMenuBounds(MenuItem *menu);
void renderSubmenu(MenuItem *menu);
MenuItem *createCommandsMenu();
MenuItem *createWeaponsMenu();
void createWeaponsMenu(MenuItem *menu);
void executeCommand(MenuSubItem *subitem);
Common::Array<MenuItem *> _items;
MenuItem *_weapons;
const Graphics::Font *_font;

View File

@ -305,6 +305,9 @@ void WageEngine::onMove(Designed *what, Designed *from, Designed *to) {
(what->_classType == OBJ && ((Obj *)what)->_currentScene == currentScene))
_gui->setSceneDirty();
if ((from == player || to == player) && !_temporarilyHidden)
_gui->regenWeaponsMenu();
if (what != player && what->_classType == CHR) {
Chr *chr = (Chr *)what;
if (to == _world->_storageScene) {