xoreos  0.0.5
container.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/engines/kotor/item.h"
28 
33 
35 
36 namespace Engines {
37 
38 namespace KotOR {
39 
41  load("container");
42 
43  WidgetPanel *guiPanel = getPanel("TGuiPanel");
44  guiPanel->setPosition(-guiPanel->getWidth()/2, -guiPanel->getHeight()/2, 0);
45 
46  WidgetListBox *lbItems = getListBox("LB_ITEMS");
48  lbItems->setPadding(18);
49  lbItems->createItemWidgets(3);
50 }
51 
53  if (inv.getItems().empty())
54  getLabel("LBL_MESSAGE")->setText(TalkMan.getString(394));
55 
56  WidgetListBox *lbItems = getListBox("LB_ITEMS");
57  lbItems->removeAllItems();
58 
59  const std::map<Common::UString, InventoryItem> &invItems = inv.getItems();
60  for (std::map<Common::UString, InventoryItem>::const_iterator i = invItems.begin();
61  i != invItems.end(); ++i) {
62  try {
63  Item item(i->second.tag);
64  lbItems->addItem(Common::UString::format("%s|%s|%u",
65  item.getName().c_str(),
66  item.getIcon().c_str(),
67  i->second.count));
68  } catch (Common::Exception &e) {
69  e.add("Failed to load item %s", i->second.tag.c_str());
70  Common::printException(e, "WARNING: ");
71  }
72  }
73 
74  lbItems->refreshItemWidgets();
75 }
76 
78  const Common::UString &tag = widget.getTag();
79 
80  if (tag == "BTN_OK") {
81  _returnCode = 1;
82  return;
83  }
84 
85  if (tag == "BTN_CANCEL") {
87  return;
88  }
89 }
90 
92  if (type == Events::kEventKeyDown) {
93  switch (key) {
94  case Events::kKeyUp:
95  getListBox("LB_ITEMS")->selectPreviousItem();
96  break;
97  case Events::kKeyDown:
98  getListBox("LB_ITEMS")->selectNextItem();
99  break;
100  default:
101  break;
102  }
103  }
104 }
105 
106 
107 } // End of namespace KotOR
108 
109 } // End of namespace Engines
void load(const Common::UString &resref)
Definition: gui.cpp:103
void add(const char *s,...) GCC_PRINTF(2
Definition: error.cpp:58
static const uint32 kReturnCodeAbort
Definition: gui.h:47
A label widget for Star Wars: Knights of the Old Republic and Jade Empire.
void fillFromInventory(const Inventory &inv)
Definition: container.cpp:52
#define TalkMan
Shortcut for accessing the talk manager.
Definition: talkman.h:111
uint32 _returnCode
The GUI&#39;s return code.
Definition: gui.h:75
A class holding an UTF-8 string.
Definition: ustring.h:48
void createItemWidgets(uint32 count)
Definition: listbox.cpp:131
void setPadding(uint32 padding)
Definition: listbox.cpp:98
A panel widget for Star Wars: Knights of the Old Republic and Jade Empire.
Exception that provides a stack of explanations.
Definition: error.h:36
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
Definition: container.cpp:77
A scrollbar widget for Star Wars: Knights of the Old Republic and Jade Empire.
The ingame container inventory menu.
Keyboard key was pressed.
Definition: types.h:46
const char * c_str() const
Return the (utf8 encoded) string data.
Definition: ustring.cpp:249
static UString format(const char *s,...) GCC_PRINTF(1
Print formatted data into an UString object, similar to sprintf().
Definition: ustring.cpp:718
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 addItem(const Common::UString &contents)
Definition: listbox.cpp:122
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
The global talk manager for Aurora strings.
EventType
Custom event types.
Definition: types.h:45
Key
Definition: types.h:78
ContainerMenu(Engines::Console *console=0)
Definition: container.cpp:40
void setText(const Common::UString &text)
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
WidgetPanel * getPanel(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:192
void printException(Exception &e, const UString &prefix)
Print a whole exception stack to stderr and the log.
Definition: error.cpp:95
float getWidth() const
Get the widget&#39;s width.
void callbackKeyInput(const Events::Key &key, const Events::EventType &type)
Callback that&#39;s triggered when a key is pressed or released.
Definition: container.cpp:91
virtual void setPosition(float x, float y, float z)
Set the widget&#39;s position.
float getHeight() const
Get the widget&#39;s height.
const std::map< Common::UString, InventoryItem > & getItems() const
Definition: inventory.cpp:67