xoreos  0.0.5
menu_equ.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/aurora/talkman.h"
26 
27 #include "src/graphics/graphics.h"
28 
32 
33 #include "src/engines/kotor/item.h"
35 
37 
38 namespace Engines {
39 
40 namespace KotOR {
41 
43  : GUI(console),
44  _pc(0),
45  _selectedSlot(kEquipmentSlotBody),
46  _slotFixated(false) {
47  load("equip");
48 
49  WidgetListBox *desc = getListBox("LB_DESC");
50  if (!desc)
51  throw Common::Exception("MenuEquipment: No desription listbox");
52 
53  desc->setInvisible(true);
54 
55  WidgetLabel *cantEquip = getLabel("LBL_CANTEQUIP");
56  if (cantEquip)
57  cantEquip->setInvisible(true);
58 
59  WidgetLabel *slotName = getLabel("LBL_SLOTNAME");
60  if (slotName)
62 
63  WidgetListBox *lbItems = getListBox("LB_ITEMS");
64  if (lbItems) {
66  lbItems->setHideScrollbar(false);
67  lbItems->setPadding(6);
68  lbItems->setItemBorderColor(0.0f, 0.0f, 0.0f, 0.0f);
69  lbItems->setSoundSelectItem("gui_actuse");
70  lbItems->createItemWidgets(5);
71  }
72 }
73 
75  _pc = pc;
76 
79 }
80 
82  GUI::show();
83 
86 }
87 
91 
92  GUI::hide();
93 }
94 
96  EquipmentSlot newSlot;
97 
98  if (getLabel("LBL_INV_IMPLANT")->isHovered())
99  newSlot = kEquipmentSlotImplant;
100  else if (getLabel("LBL_INV_HEAD")->isHovered())
101  newSlot = kEquipmentSlotHead;
102  else if (getLabel("LBL_INV_HANDS")->isHovered())
103  newSlot = kEquipmentSlotHands;
104  else if (getLabel("LBL_INV_ARM_L")->isHovered())
105  newSlot = kEquipmentSlotArmL;
106  else if (getLabel("LBL_INV_BODY")->isHovered())
107  newSlot = kEquipmentSlotBody;
108  else if (getLabel("LBL_INV_ARM_R")->isHovered())
109  newSlot = kEquipmentSlotArmR;
110  else if (getLabel("LBL_INV_WEAP_L")->isHovered())
111  newSlot = kEquipmentSlotWeaponL;
112  else if (getLabel("LBL_INV_BELT")->isHovered())
113  newSlot = kEquipmentSlotBelt;
114  else if (getLabel("LBL_INV_WEAP_R")->isHovered())
115  newSlot = kEquipmentSlotWeaponR;
116  else
117  return;
118 
119  if (newSlot != _selectedSlot) {
122 
123  _selectedSlot = newSlot;
125  getLabel("LBL_SLOTNAME")->setText(getSlotName(_selectedSlot));
127  }
128 }
129 
131  const Common::UString &tag = widget.getTag();
132  if (_slotFixated) {
133  if (tag == "BTN_EQUIP") {
134  int selectedIndex = getListBox("LB_ITEMS")->getSelectedIndex();
135  Common::UString itemTag = selectedIndex > 0 ? _visibleItems[selectedIndex - 1] : "";
136  _pc->equipItem(itemTag, _selectedSlot);
137 
140 
141  fixateOnSlot(false);
142  return;
143  }
144  if (tag == "BTN_BACK") {
145  fixateOnSlot(false);
146  return;
147  }
148  } else {
149  if (tag == "BTN_BACK") {
150  _returnCode = 1;
151  return;
152  }
153  if (tag.beginsWith("LBL_INV_")) {
154  fixateOnSlot(true);
155  return;
156  }
157  }
158 }
159 
161  if (type == Events::kEventKeyDown) {
162  switch (key) {
163  case Events::kKeyUp:
164  getListBox("LB_ITEMS")->selectPreviousItem();
165  break;
166  case Events::kKeyDown:
167  getListBox("LB_ITEMS")->selectNextItem();
168  break;
169  default:
170  break;
171  }
172  }
173 }
174 
185 
186  getLabel("LBL_INV_IMPLANT")->setFill(implant.empty() ? "iimplant" : implant);
187  getLabel("LBL_INV_HEAD")->setFill(head.empty() ? "ihead" : head);
188  getLabel("LBL_INV_HANDS")->setFill(hands.empty() ? "ihands" : hands);
189  getLabel("LBL_INV_ARM_L")->setFill(armL.empty() ? "iforearm_l" : armL);
190  getLabel("LBL_INV_BODY")->setFill(body.empty() ? "iarmor" : body);
191  getLabel("LBL_INV_ARM_R")->setFill(armR.empty() ? "iforearm_r" : armR);
192  getLabel("LBL_INV_WEAP_L")->setFill(weapL.empty() ? "iweap_l" : weapL);
193  getLabel("LBL_INV_BELT")->setFill(belt.empty() ? "ibelt" : belt);
194  getLabel("LBL_INV_WEAP_R")->setFill(weapR.empty() ? "iweap_r" : weapR);
195 }
196 
198  Item *item = _pc->getEquipedItem(slot);
199  return item ? item->getIcon() : "";
200 }
201 
203  Inventory &inv = _pc->getInventory();
204 
205  WidgetListBox *lbItems = getListBox("LB_ITEMS");
206  lbItems->removeAllItems();
207  lbItems->addItem("None|inone|1");
208 
209  _visibleItems.clear();
210 
211  const std::map<Common::UString, InventoryItem> &invItems = inv.getItems();
212  for (std::map<Common::UString, InventoryItem>::const_iterator i = invItems.begin();
213  i != invItems.end(); ++i) {
214  try {
215  Item item(i->second.tag);
216  if ((item.getEquipableSlots() & _selectedSlot) == 0)
217  continue;
218 
219  lbItems->addItem(Common::UString::format("%s|%s|%u",
220  item.getName().c_str(),
221  item.getIcon().c_str(),
222  i->second.count));
223 
224  _visibleItems.push_back(i->second.tag);
225  } catch (Common::Exception &e) {
226  e.add("Failed to load item %s", i->second.tag.c_str());
227  Common::printException(e, "WARNING: ");
228  }
229  }
230 
231  GfxMan.lockFrame();
232  lbItems->refreshItemWidgets();
233  GfxMan.unlockFrame();
234 }
235 
237  if (tag == "LBL_INV_IMPLANT")
238  return kEquipmentSlotImplant;
239  if (tag == "LBL_INV_BODY")
240  return kEquipmentSlotBody;
241  if (tag == "LBL_INV_HANDS")
242  return kEquipmentSlotHands;
243  if (tag == "LBL_INV_ARM_R")
244  return kEquipmentSlotArmR;
245  if (tag == "LBL_INV_BODY")
246  return kEquipmentSlotBody;
247  if (tag == "LBL_INV_ARM_L")
248  return kEquipmentSlotArmL;
249  if (tag == "LBL_INV_WEAP_R")
250  return kEquipmentSlotWeaponR;
251  if (tag == "LBL_INV_BELT")
252  return kEquipmentSlotBelt;
253  if (tag == "LBL_INV_WEAP_L")
254  return kEquipmentSlotWeaponL;
255 
256  return kEquipmentSlotNone;
257 }
258 
260  switch (slot) {
262  return getButton("BTN_INV_IMPLANT");
263  case kEquipmentSlotHead:
264  return getButton("BTN_INV_HEAD");
265  case kEquipmentSlotHands:
266  return getButton("BTN_INV_HANDS");
267  case kEquipmentSlotArmR:
268  return getButton("BTN_INV_ARM_R");
269  case kEquipmentSlotBody:
270  return getButton("BTN_INV_BODY");
271  case kEquipmentSlotArmL:
272  return getButton("BTN_INV_ARM_L");
274  return getButton("BTN_INV_WEAP_R");
275  case kEquipmentSlotBelt:
276  return getButton("BTN_INV_BELT");
278  return getButton("BTN_INV_WEAP_L");
279  default:
280  return 0;
281  }
282 }
283 
285  switch (slot) {
287  return TalkMan.getString(31388); // Implant
288  case kEquipmentSlotHead:
289  return TalkMan.getString(31375); // Head
290  case kEquipmentSlotHands:
291  return TalkMan.getString(31383); // Hands
292  case kEquipmentSlotArmR:
293  return TalkMan.getString(31377); // Right Arm
294  case kEquipmentSlotBody:
295  return TalkMan.getString(31380); // Body
296  case kEquipmentSlotArmL:
297  return TalkMan.getString(31376); // Left Arm
299  return TalkMan.getString(31379); // Right Weapon
300  case kEquipmentSlotBelt:
301  return TalkMan.getString(31382); // Belt
303  return TalkMan.getString(31378); // Left Weapon
304  default:
305  return "";
306  }
307 }
308 
309 void MenuEquipment::fixateOnSlot(bool fixate) {
310  _slotFixated = fixate;
311 
312  WidgetListBox *lbDesc = getListBox("LB_DESC");
313 
314  WidgetButton *btnInvImplant = getButton("BTN_INV_IMPLANT");
315  WidgetButton *btnInvHead = getButton("BTN_INV_HEAD");
316  WidgetButton *btnInvHands = getButton("BTN_INV_HANDS");
317  WidgetButton *btnInvArmL = getButton("BTN_INV_ARM_L");
318  WidgetButton *btnInvBody = getButton("BTN_INV_BODY");
319  WidgetButton *btnInvArmR = getButton("BTN_INV_ARM_R");
320  WidgetButton *btnInvWeapL = getButton("BTN_INV_WEAP_L");
321  WidgetButton *btnInvBelt = getButton("BTN_INV_BELT");
322  WidgetButton *btnInvWeapR = getButton("BTN_INV_WEAP_R");
323 
324  WidgetLabel *lblInvImplant = getLabel("LBL_INV_IMPLANT");
325  WidgetLabel *lblInvHead = getLabel("LBL_INV_HEAD");
326  WidgetLabel *lblInvHands = getLabel("LBL_INV_HANDS");
327  WidgetLabel *lblInvArmL = getLabel("LBL_INV_ARM_L");
328  WidgetLabel *lblInvBody = getLabel("LBL_INV_BODY");
329  WidgetLabel *lblInvArmR = getLabel("LBL_INV_ARM_R");
330  WidgetLabel *lblInvWeapL = getLabel("LBL_INV_WEAP_L");
331  WidgetLabel *lblInvBelt = getLabel("LBL_INV_BELT");
332  WidgetLabel *lblInvWeapR = getLabel("LBL_INV_WEAP_R");
333 
334  WidgetLabel *lblTxtBar = getLabel("LBL_TXTBAR");
335  WidgetLabel *lblSlotName = getLabel("LBL_SLOTNAME");
336  WidgetLabel *lblPortBord = getLabel("LBL_PORT_BORD");
337  WidgetLabel *lblPortrait = getLabel("LBL_PORTRAIT");
338 
339  WidgetListBox *lbItems = getListBox("LB_ITEMS");
340  WidgetButton *btnBack = getButton("BTN_BACK");
341 
342  lbDesc->setInvisible(!_slotFixated);
343 
344  btnInvImplant->setInvisible(_slotFixated);
345  btnInvHead->setInvisible(_slotFixated);
346  btnInvHands->setInvisible(_slotFixated);
347  btnInvArmL->setInvisible(_slotFixated);
348  btnInvBody->setInvisible(_slotFixated);
349  btnInvArmR->setInvisible(_slotFixated);
350  btnInvWeapL->setInvisible(_slotFixated);
351  btnInvBelt->setInvisible(_slotFixated);
352  btnInvWeapR->setInvisible(_slotFixated);
353 
354  lblInvImplant->setInvisible(_slotFixated);
355  lblInvHead->setInvisible(_slotFixated);
356  lblInvHands->setInvisible(_slotFixated);
357  lblInvArmL->setInvisible(_slotFixated);
358  lblInvBody->setInvisible(_slotFixated);
359  lblInvArmR->setInvisible(_slotFixated);
360  lblInvWeapL->setInvisible(_slotFixated);
361  lblInvBelt->setInvisible(_slotFixated);
362  lblInvWeapR->setInvisible(_slotFixated);
363 
364  lblTxtBar->setInvisible(_slotFixated);
365  lblSlotName->setInvisible(_slotFixated);
366  lblPortBord->setInvisible(_slotFixated);
367  lblPortrait->setInvisible(_slotFixated);
368 
369  if (_slotFixated) {
370  lbDesc->show();
371 
373 
374  btnInvImplant->hide();
375  btnInvHead->hide();
376  btnInvHands->hide();
377  btnInvArmL->hide();
378  btnInvBody->hide();
379  btnInvArmR->hide();
380  btnInvWeapL->hide();
381  btnInvBelt->hide();
382  btnInvWeapR->hide();
383 
384  lblInvImplant->hide();
385  lblInvHead->hide();
386  lblInvHands->hide();
387  lblInvArmL->hide();
388  lblInvBody->hide();
389  lblInvArmR->hide();
390  lblInvWeapL->hide();
391  lblInvBelt->hide();
392  lblInvWeapR->hide();
393 
394  lblTxtBar->hide();
395  lblSlotName->hide();
396  lblPortBord->hide();
397  lblPortrait->hide();
398 
399  lbItems->setItemSelectionEnabled(true);
400  lbItems->setItemBorderColor(0.0f, 0.648438f, 0.968750f, 1.0f);
401  lbItems->selectItemByWidgetTag("LB_ITEMS_ITEM_0");
402 
403  btnBack->setText(TalkMan.getString(1581));
404  } else {
405  lbDesc->hide();
406 
407  btnInvImplant->show();
408  btnInvHead->show();
409  btnInvHands->show();
410  btnInvArmL->show();
411  btnInvBody->show();
412  btnInvArmR->show();
413  btnInvWeapL->show();
414  btnInvBelt->show();
415  btnInvWeapR->show();
416 
418 
419  lblInvImplant->show();
420  lblInvHead->show();
421  lblInvHands->show();
422  lblInvArmL->show();
423  lblInvBody->show();
424  lblInvArmR->show();
425  lblInvWeapL->show();
426  lblInvBelt->show();
427  lblInvWeapR->show();
428 
429  lblTxtBar->show();
430  lblSlotName->show();
431  lblPortBord->show();
432  lblPortrait->show();
433 
434  lbItems->setItemSelectionEnabled(false);
435  lbItems->setItemBorderColor(0.0f, 0.0f, 0.0f, 0.0f);
436 
437  btnBack->setText(TalkMan.getString(1582));
438  }
439 
440  lbItems->refreshItemWidgets();
441 }
442 
443 } // End of namespace KotOR
444 
445 } // End of namespace Engines
A creature in a Star Wars: Knights of the Old Republic area.
void load(const Common::UString &resref)
Definition: gui.cpp:103
Common::UString getEquipedItemIcon(EquipmentSlot slot) const
Definition: menu_equ.cpp:197
EquipmentSlot _selectedSlot
Definition: menu_equ.h:55
void setFill(const Common::UString &fill)
void add(const char *s,...) GCC_PRINTF(2
Definition: error.cpp:58
The global graphics manager.
A label widget for Star Wars: Knights of the Old Republic and Jade Empire.
#define TalkMan
Shortcut for accessing the talk manager.
Definition: talkman.h:111
uint32 _returnCode
The GUI&#39;s return code.
Definition: gui.h:75
virtual void hide()
Hide the widget.
A class holding an UTF-8 string.
Definition: ustring.h:48
void createItemWidgets(uint32 count)
Definition: listbox.cpp:131
void equipItem(Common::UString tag, EquipmentSlot slot)
Definition: creature.cpp:614
bool beginsWith(const UString &with) const
Definition: ustring.cpp:295
A button widget for Star Wars: Knights of the Old Republic and Jade Empire.
void setHighlight(const Common::UString &hilight)
virtual void hide()
Hide the GUI.
Definition: gui.cpp:75
Inventory & getInventory()
Definition: creature.cpp:643
void setPadding(uint32 padding)
Definition: listbox.cpp:98
void hide()
Hide the GUI.
Definition: menu_equ.cpp:88
Exception that provides a stack of explanations.
Definition: error.h:36
Keyboard key was pressed.
Definition: types.h:46
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
Definition: menu_equ.cpp:130
MenuEquipment(::Engines::Console *console=0)
Definition: menu_equ.cpp:42
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
WidgetButton * getSlotButton(EquipmentSlot slot)
Definition: menu_equ.cpp:259
static UString format(const char *s,...) GCC_PRINTF(1
Print formatted data into an UString object, similar to sprintf().
Definition: ustring.cpp:718
WidgetButton * getButton(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:228
virtual void show()
Show the widget.
const Common::UString & getTag() const
Get the widget&#39;s tag.
Definition: widget.cpp:45
A list box widget for Star Wars: Knights of the Old Republic and Jade Empire.
void setItemSelectionEnabled(bool itemSelectionEnabled)
Toggle item selection mode.
Definition: listbox.cpp:82
void addItem(const Common::UString &contents)
Definition: listbox.cpp:122
void selectItemByWidgetTag(const Common::UString &tag)
Definition: listbox.cpp:234
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
std::vector< Common::UString > _visibleItems
Definition: menu_equ.h:57
StackException Exception
Definition: error.h:59
void setPC(Creature *pc)
Definition: menu_equ.cpp:74
virtual void show()
Show the GUI.
Definition: gui.cpp:69
EquipmentSlot getSlotByWidgetTag(const Common::UString &tag) const
Definition: menu_equ.cpp:236
void setHideScrollbar(bool hideScrollbar)
Toggle scroll bar visibility mode.
Definition: listbox.cpp:94
void setItemBorderColor(float r, float g, float b, float a)
Definition: listbox.cpp:112
void fixateOnSlot(bool fixate)
Definition: menu_equ.cpp:309
WidgetLabel * getLabel(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:204
A widget in a GUI.
Definition: widget.h:40
const Common::UString getIcon() const
Definition: item.cpp:80
void callbackRun()
Callback that&#39;s triggered periodically in the run() method.
Definition: menu_equ.cpp:95
The global talk manager for Aurora strings.
EventType
Custom event types.
Definition: types.h:45
virtual void setInvisible(bool invisible)
Make the widget invisible.
Item * getEquipedItem(EquipmentSlot slot) const
Definition: creature.cpp:647
Key
Definition: types.h:78
void setText(const Common::UString &text)
EquipmentSlot getEquipableSlots() const
Definition: item.cpp:68
WidgetListBox * getListBox(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:288
An item in a Star Wars: Knights of the Old Republic area.
const Common::UString & getName() const
Definition: item.cpp:64
void setItemType(ListBoxItemType itemType)
Definition: listbox.cpp:78
A KotOR GUI.
Definition: gui.h:57
void callbackKeyInput(const Events::Key &key, const Events::EventType &type)
Callback that&#39;s triggered when a key is pressed or released.
Definition: menu_equ.cpp:160
void show()
Show the GUI.
Definition: menu_equ.cpp:81
void printException(Exception &e, const UString &prefix)
Print a whole exception stack to stderr and the log.
Definition: error.cpp:95
#define GfxMan
Shortcut for accessing the graphics manager.
Definition: graphics.h:299
Common::UString getSlotName(EquipmentSlot slot) const
Definition: menu_equ.cpp:284
int getSelectedIndex() const
Definition: listbox.cpp:306
const std::map< Common::UString, InventoryItem > & getItems() const
Definition: inventory.cpp:67
void setSoundSelectItem(const Common::UString &resRef)
Definition: listbox.cpp:328