xoreos  0.0.5
menu.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/graphics/graphics.h"
26 
28 
30 
31 namespace Engines {
32 
33 namespace KotOR {
34 
35 Menu::Menu(Module &module, Console *console) : GUI(console), _module(module), _currentMenu(0) {
36  load("top");
37 
39 
40  static const char * const kButtonTags[kMenuTypeMAX] = {
41  "BTN_EQU" , "BTN_INV" , "BTN_CHAR", "BTN_ABI" , "BTN_MSG" , "BTN_JOU" , "BTN_MAP" , "BTN_OPT"
42  };
43  static const char * const kProtoTags[kMenuTypeMAX] = {
44  "LBLH_EQU", "LBLH_INV", "LBLH_CHA", "LBLH_ABI", "LBLH_MSG", "LBLH_JOU", "LBLH_MAP", "LBLH_OPT"
45  };
46 
47  for (size_t i = 0; i < kMenuTypeMAX; i++) {
48  SubMenu &menu = _menu[i];
49 
50  // Place the widget as the top bar
51  menu.protoItem = getProtoItem(kProtoTags[i]);
52  if (menu.protoItem) {
53  float x, y, z;
54 
55  menu.protoItem->getPosition(x, y, z);
56  menu.protoItem->setPosition(x, y + 197, z);
57  }
58 
59  // Do the same for the button
60  menu.button = getButton(kButtonTags[i]);
61  if (menu.button) {
62  float x, y, z;
63 
64  menu.button->getPosition(x, y, z);
65  menu.button->setPosition(x, y + 197, z);
66  }
67  }
68 
69  _menu[kMenuTypeEquipment].menu.reset(new MenuEquipment(console));
70  _menu[kMenuTypeInventory].menu.reset(new MenuInventory(console));
71  _menu[kMenuTypeCharacter].menu.reset(new MenuCharacter(console));
72  _menu[kMenuTypeAbilities].menu.reset(new MenuAbilities(console));
73  _menu[kMenuTypeMessages].menu.reset(new MenuMessages(console));
74  _menu[kMenuTypeJournal].menu.reset(new MenuJournal(console));
75  _menu[kMenuTypeMap].menu.reset(new MenuMap(console));
76  _menu[kMenuTypeOptions].menu.reset(new MenuOptions(console));
77 
78  _menuLoad.reset(new SaveLoadMenu(module, console, kSaveLoadMenuTypeLoad, true));
79  _menuSave.reset(new SaveLoadMenu(module, console, kSaveLoadMenuTypeSave, true));
80 }
81 
83  dynamic_cast<MenuMap &>(*_menu[kMenuTypeMap].menu.get()).setReturnStrref(id);
84 }
85 
87  dynamic_cast<MenuMap &>(*_menu[kMenuTypeMap].menu.get()).setReturnQueryStrref(id);
88 }
89 
90 void Menu::setReturnEnabled(bool enabled) {
91  dynamic_cast<MenuMap &>(*_menu[kMenuTypeMap].menu.get()).setReturnEnabled(enabled);
92 }
93 
95  assert((type >= 0) && (type < kMenuTypeMAX));
96  if (_currentMenu == &_menu[type])
97  return;
98 
99  if (_currentMenu) {
100  removeChild(_currentMenu->menu.get());
102  }
103 
104  _currentMenu = &_menu[type];
105  addChild(_currentMenu->menu.get());
107 
108  if (type == kMenuTypeEquipment)
109  dynamic_cast<MenuEquipment &>(*_currentMenu->menu.get()).setPC(_module.getPC());
110 }
111 
114  const uint8 selectedItem = dynamic_cast<MenuOptions &>(*_currentMenu->menu.get()).pollSelectedItem();
115 
116  switch (selectedItem) {
118  if (sub(*_menuLoad) == 2) {
119  GfxMan.unlockFrame();
120  _returnCode = 2;
121  }
122  break;
124  if (sub(*_menuSave) == 2)
125  _returnCode = 2;
126  break;
128  _module.leave();
129  _returnCode = 1;
130  break;
131  }
132  }
133 }
134 
135 void Menu::showMenu(const Common::UString &tag) {
136  for (size_t i = 0; i < kMenuTypeMAX; i++) {
137  if (_menu[i].button && _menu[i].button->getTag() == tag) {
138  showMenu(static_cast<MenuType>(i));
139  return;
140  }
141  }
142 }
143 
145  showMenu(widget.getTag());
146 }
147 
148 } // End of namespace KotOR
149 
150 } // End of namespace Engines
void load(const Common::UString &resref)
Definition: gui.cpp:103
static const Common::UString & kBackgroundTypeMenu
Definition: guibackground.h:42
The global graphics manager.
uint32 _returnCode
The GUI&#39;s return code.
Definition: gui.h:75
void showMenu(const Common::UString &tag)
Definition: menu.cpp:135
A class holding an UTF-8 string.
Definition: ustring.h:48
uint8_t uint8
Definition: types.h:200
void callbackRun()
Callback that&#39;s triggered periodically in the run() method.
Definition: menu.cpp:112
A button widget for Star Wars: Knights of the Old Republic and Jade Empire.
void setHighlight(const Common::UString &hilight)
virtual void getPosition(float &x, float &y, float &z) const
Get the widget&#39;s position.
Definition: widget.cpp:140
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
Definition: menu.cpp:144
Common::ScopedPtr< GUI > menu
Definition: menu.h:78
void removeChild(GUI *gui)
Remove a child GUI object from this GUI.
Definition: gui.cpp:245
WidgetButton * getButton(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:228
void setReturnQueryStrref(uint32)
Set the return query string ref.
Definition: menu.cpp:86
const Common::UString & getTag() const
Get the widget&#39;s tag.
Definition: widget.cpp:45
uint32 sub(GUI &gui, uint32 startCode=kStartCodeNone, bool showSelf=true, bool hideSelf=true)
Open up a sub GUI.
Definition: gui.cpp:349
static const char *const kButtonTags[]
Definition: partyleader.cpp:44
WidgetProtoItem * getProtoItem(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:216
WidgetButton * button
Definition: menu.h:76
void setReturnEnabled(bool)
Set the return button enabled/disabled.
Definition: menu.cpp:90
Module & _module
Definition: menu.h:86
void addBackground(const Common::UString &background, bool front=false)
Definition: gui.cpp:300
SubMenu _menu[kMenuTypeMAX]
Definition: menu.h:88
Menu(Module &module, ::Engines::Console *console=0)
Definition: menu.cpp:35
A widget in a GUI.
Definition: widget.h:40
uint32_t uint32
Definition: types.h:204
Common::ScopedPtr< SaveLoadMenu > _menuSave
Definition: menu.h:92
A KotOR GUI.
Definition: gui.h:57
void setReturnStrref(uint32)
Set the return string ref.
Definition: menu.cpp:82
void leave()
Leave the running module, quitting it.
Definition: module.cpp:465
Common::ScopedPtr< SaveLoadMenu > _menuLoad
Definition: menu.h:91
#define GfxMan
Shortcut for accessing the graphics manager.
Definition: graphics.h:299
WidgetProtoItem * protoItem
Definition: menu.h:75
virtual void setPosition(float x, float y, float z)
Set the widget&#39;s position.
SubMenu * _currentMenu
Definition: menu.h:89
void addChild(GUI *gui)
Add a child GUI object to this GUI.
Definition: gui.cpp:240
Creature * getPC()
Return the currently playing PC.
Definition: module.cpp:181