xoreos  0.0.5
newpremium.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 <cassert>
26 
27 #include "src/common/util.h"
28 
29 #include "src/aurora/talkman.h"
30 
31 #include "src/graphics/font.h"
32 
36 
38 
39 #include "src/engines/nwn/game.h"
40 #include "src/engines/nwn/module.h"
41 
43 
45 
46 namespace Engines {
47 
48 namespace NWN {
49 
51  const Common::UString &font, const Common::UString &text, float spacing) :
52  WidgetListItem(gui), _spacing(spacing) {
53 
54  _button.reset(loadModelGUI("ctl_btn_txt407"));
55  assert(_button);
56 
57  _button->setClickable(true);
58 
59  Common::UString splitText;
61  f.getFont().split(text, splitText, _button->getWidth() - 8.0f);
62 
63  _text.reset(new Graphics::Aurora::Text(f, splitText, 1.0f, 1.0f, 1.0f, 1.0f, Graphics::Aurora::kHAlignCenter));
64 }
65 
67 }
68 
70  _button->show();
71  _text->show();
72 }
73 
75  _text->hide();
76  _button->hide();
77 }
78 
79 void WidgetListItemPremium::setPosition(float x, float y, float z) {
80  NWNWidget::setPosition(x, y, z);
81 
82  getPosition(x, y, z);
83  _button->setPosition(x, y, z);
84 
85  x = x + (_button->getWidth () - _text->getWidth ()) / 2.0f;
86  y = y + (_button->getHeight() - _text->getHeight()) / 2.0f;
87 
88  _text->setPosition(x, y, z - 1.0f);
89 }
90 
92  return _button->getWidth();
93 }
94 
96  return _button->getHeight() + _spacing;
97 }
98 
101 
102  _button->setTag(tag);
103 }
104 
107  return false;
108 
109  _button->setState("down");
110 
111  return true;
112 }
113 
116  return false;
117 
118  _button->setState("");
119 
120  return true;
121 }
122 
123 
124 NewPremiumMenu::NewPremiumMenu(Module &module, GUI &charType, ::Engines::Console *console) : GUI(console),
125  _module(&module), _charType(&charType) {
126 
127  load("pre_loadmod");
128 }
129 
131 }
132 
134  if (_modules.empty())
135  initModuleList();
136 
137  GUI::show();
138 }
139 
141  if (tag == "ModuleListBox")
142  type = kWidgetTypeListBox;
143  else if (tag == "ModDescEditBox")
144  type = kWidgetTypeListBox;
145 }
146 
148  if (widget.getTag() == "TitleBar") {
149  dynamic_cast<WidgetLabel &>(widget).setText(TalkMan.getString(110806));
150  return;
151  }
152 }
153 
155  status("Creating module list");
156 
158 
159  WidgetListBox &moduleList = *getListBox("ModuleListBox", true);
160 
161  moduleList.lock();
162 
163  moduleList.clear();
165 
166  moduleList.reserve(_modules.size());
167  for (std::vector<Common::UString>::iterator m = _modules.begin(); m != _modules.end(); ++m)
168  moduleList.add(new WidgetListItemPremium(*this, "fnt_galahad14", *m, 2.0f));
169 
170  moduleList.unlock();
171 
172  moduleList.select(0);
173  selectedModule();
174 }
175 
177  if (widget.getTag() == "CancelButton") {
178  _returnCode = 1;
179  return;
180  }
181 
182  if (widget.getTag() == "LoadButton") {
183  loadModule();
184  return;
185  }
186 
187  if (widget.getTag() == "ModuleListBox") {
188  selectedModule();
189 
190  if (dynamic_cast<WidgetListBox &>(widget).wasDblClicked())
191  loadModule();
192 
193  return;
194  }
195 }
196 
198  size_t n = getListBox("ModuleListBox", true)->getSelected();
199  if (n >= _modules.size())
200  return "";
201 
202  return _modules[n];
203 }
204 
206  Common::UString description = Module::getDescription(getSelectedModule() + ".nwm");
207  if (description.empty())
208  description = TalkMan.getString(67741);
209 
210  getListBox("ModDescEditBox", true)->setText("fnt_galahad14", description, 1.0f);
211 }
212 
215 
216  try {
217  _module->load(module + ".nwm");
218  } catch (...) {
220  return;
221  }
222 
223  if (sub(*_charType, 0, false) == 2) {
224  _returnCode = 2;
225  return;
226  }
227 
228  show();
229 }
230 
231 } // End of namespace NWN
232 
233 } // End of namespace Engines
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: newpremium.cpp:79
#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 setTag(const Common::UString &tag)
Set the widget&#39;s tag.
Definition: widget.cpp:49
A class holding an UTF-8 string.
Definition: ustring.h:48
WidgetListBox * getListBox(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:318
void reset(PointerType o=0)
Resets the pointer with the new value.
Definition: scopedptr.h:87
void add(WidgetListItem *item, bool noTag=false)
Definition: listbox.cpp:411
float getWidth() const
Get the widget&#39;s width.
Definition: newpremium.cpp:91
void show()
Show the widget.
Definition: newpremium.cpp:69
A handle to a font.
Definition: fonthandle.h:52
A text object.
void fixWidgetType(const Common::UString &tag, WidgetType &type)
Definition: newpremium.cpp:140
virtual void getPosition(float &x, float &y, float &z) const
Get the widget&#39;s position.
Definition: widget.cpp:140
float split(const Common::UString &line, std::vector< Common::UString > &lines, float maxWidth=0.0f, float maxHeight=0.0f, bool trim=true) const
Definition: font.cpp:69
void initWidget(Widget &widget)
Definition: newpremium.cpp:147
const Common::UString & getDescription() const
Return the object&#39;s description.
Definition: object.cpp:94
The Aurora font manager.
An item widget within a NWN listbox widget.
Definition: listbox.h:51
The new premium module menu.
void exceptionDispatcherWarning(const char *s,...)
Exception dispatcher that prints the exception as a warning, and adds another reason on top...
Definition: error.cpp:158
Common::UString getSelectedModule()
Definition: newpremium.cpp:197
The context needed to run a Neverwinter Nights module.
static void getPremiumModules(std::vector< Common::UString > &modules)
Return a list of all premium modules.
Definition: game.cpp:230
A GUI.
Definition: gui.h:43
size_t getSelected() const
Definition: listbox.cpp:626
void setText(const Common::UString &font, const Common::UString &text, float spacing=0.0f)
Definition: listbox.cpp:523
void load(const Common::UString &module)
Load a module.
Definition: module.cpp:127
A text object.
Definition: text.h:42
void show()
Show the GUI.
Definition: newpremium.cpp:133
virtual void show()
Show the GUI.
Definition: gui.cpp:62
A NWN GUI.
Definition: gui.h:54
Utility templates and functions.
const Common::UString & getTag() const
Get the widget&#39;s tag.
Definition: widget.cpp:45
void setMode(Mode mode)
Definition: listbox.cpp:313
A 3D model of an object.
uint32 sub(GUI &gui, uint32 startCode=kStartCodeNone, bool showSelf=true, bool hideSelf=true)
Open up a sub GUI.
Definition: gui.cpp:349
void load(const Common::UString &resref)
Definition: gui.cpp:77
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
A NWN listbox widget.
Definition: listbox.h:116
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: nwnwidget.cpp:60
virtual bool deactivate()
Definition: listbox.cpp:124
void reserve(size_t n)
Definition: listbox.cpp:405
const float kHAlignCenter
Definition: types.h:43
Common::ScopedPtr< Graphics::Aurora::Model > _button
Definition: newpremium.h:66
NewPremiumMenu(Module &module, GUI &charType, ::Engines::Console *console=0)
Definition: newpremium.cpp:124
Common::ScopedPtr< Graphics::Aurora::Text > _text
Definition: newpremium.h:67
A NWN label widget.
Definition: label.h:41
std::vector< Common::UString > _modules
Definition: newpremium.h:89
float getHeight() const
Get the widget&#39;s height.
Definition: newpremium.cpp:95
A widget in a GUI.
Definition: widget.h:40
void select(size_t item)
Definition: listbox.cpp:618
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
Definition: newpremium.cpp:176
The global talk manager for Aurora strings.
void status(const char *s,...)
Definition: util.cpp:52
void setTag(const Common::UString &tag)
Set the widget&#39;s tag.
Definition: newpremium.cpp:99
Graphics::Aurora::Model * loadModelGUI(const Common::UString &resref)
Definition: model.cpp:65
void hide()
Hide the widget.
Definition: newpremium.cpp:74
The context handling the gameplay in Neverwinter Nights.
WidgetListItemPremium(::Engines::GUI &gui, const Common::UString &font, const Common::UString &text, float spacing=0.0f)
Definition: newpremium.cpp:50
A font.
A NWN label widget.
#define FontMan
Shortcut for accessing the font manager.
Definition: fontman.h:105
Generic Aurora engines model functions.