xoreos  0.0.5
newmodule.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 
44 namespace Engines {
45 
46 namespace NWN {
47 
49  const Common::UString &font, const Common::UString &text, float spacing) :
50  WidgetListItem(gui), _spacing(spacing) {
51 
52  _button.reset(loadModelGUI("ctl_btn_txt407"));
53  assert(_button);
54 
55  _button->setClickable(true);
56 
57  Common::UString splitText;
59  f.getFont().split(text, splitText, _button->getWidth() - 8.0f);
60 
61  _text.reset(new Graphics::Aurora::Text(f, splitText, 1.0f, 1.0f, 1.0f, 1.0f, Graphics::Aurora::kHAlignCenter));
62 }
63 
65 }
66 
68  _button->show();
69  _text->show();
70 }
71 
73  _text->hide();
74  _button->hide();
75 }
76 
77 void WidgetListItemModule::setPosition(float x, float y, float z) {
78  NWNWidget::setPosition(x, y, z);
79 
80  getPosition(x, y, z);
81  _button->setPosition(x, y, z);
82 
83  x = x + (_button->getWidth () - _text->getWidth ()) / 2.0f;
84  y = y + (_button->getHeight() - _text->getHeight()) / 2.0f;
85 
86  _text->setPosition(x, y, z - 1.0f);
87 }
88 
90  return _button->getWidth();
91 }
92 
94  return _button->getHeight() + _spacing;
95 }
96 
99 
100  _button->setTag(tag);
101 }
102 
105  return false;
106 
107  _button->setState("down");
108 
109  return true;
110 }
111 
114  return false;
115 
116  _button->setState("");
117 
118  return true;
119 }
120 
121 
122 NewModuleMenu::NewModuleMenu(Module &module, GUI &charType, ::Engines::Console *console) : GUI(console),
123  _module(&module), _charType(&charType) {
124 
125  load("pre_loadmod");
126 }
127 
129 }
130 
132  if (_modules.empty())
133  initModuleList();
134 
135  GUI::show();
136 }
137 
139  if (tag == "ModuleListBox")
140  type = kWidgetTypeListBox;
141  else if (tag == "ModDescEditBox")
142  type = kWidgetTypeListBox;
143 }
144 
146  status("Creating module list");
147 
149 
150  WidgetListBox &moduleList = *getListBox("ModuleListBox", true);
151 
152  moduleList.lock();
153 
154  moduleList.clear();
156 
157  moduleList.reserve(_modules.size());
158  for (std::vector<Common::UString>::iterator m = _modules.begin(); m != _modules.end(); ++m)
159  moduleList.add(new WidgetListItemModule(*this, "fnt_galahad14", *m, 2.0f));
160 
161  moduleList.unlock();
162 
163  moduleList.select(0);
164  selectedModule();
165 }
166 
168  if (widget.getTag() == "CancelButton") {
169  _returnCode = 1;
170  return;
171  }
172 
173  if (widget.getTag() == "LoadButton") {
174  loadModule();
175  return;
176  }
177 
178  if (widget.getTag() == "ModuleListBox") {
179  selectedModule();
180 
181  if (dynamic_cast<WidgetListBox &>(widget).wasDblClicked())
182  loadModule();
183 
184  return;
185  }
186 }
187 
189  size_t n = getListBox("ModuleListBox", true)->getSelected();
190  if (n >= _modules.size())
191  return "";
192 
193  return _modules[n];
194 }
195 
197  Common::UString description = Module::getDescription(getSelectedModule() + ".mod");
198  if (description.empty())
199  description = TalkMan.getString(67741);
200 
201  getListBox("ModDescEditBox", true)->setText("fnt_galahad14", description, 1.0f);
202 }
203 
206 
207  try {
208  _module->load(module + ".mod");
209  } catch (...) {
211  return;
212  }
213 
214  if (sub(*_charType, 0, false) == 2) {
215  _returnCode = 2;
216  return;
217  }
218 
219  show();
220 }
221 
222 } // End of namespace NWN
223 
224 } // End of namespace Engines
WidgetListItemModule(::Engines::GUI &gui, const Common::UString &font, const Common::UString &text, float spacing=0.0f)
Definition: newmodule.cpp:48
#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
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
Definition: newmodule.cpp:167
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
static void getModules(std::vector< Common::UString > &modules)
Return a list of all modules.
Definition: game.cpp:210
A handle to a font.
Definition: fonthandle.h:52
A text object.
float getWidth() const
Get the widget&#39;s width.
Definition: newmodule.cpp:89
void fixWidgetType(const Common::UString &tag, WidgetType &type)
Definition: newmodule.cpp:138
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
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
void exceptionDispatcherWarning(const char *s,...)
Exception dispatcher that prints the exception as a warning, and adds another reason on top...
Definition: error.cpp:158
The context needed to run a Neverwinter Nights module.
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
The new module menu.
A text object.
Definition: text.h:42
virtual void show()
Show the GUI.
Definition: gui.cpp:62
A NWN GUI.
Definition: gui.h:54
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: newmodule.cpp:77
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
Common::ScopedPtr< Graphics::Aurora::Model > _button
Definition: newmodule.h:66
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
void setTag(const Common::UString &tag)
Set the widget&#39;s tag.
Definition: newmodule.cpp:97
virtual bool deactivate()
Definition: listbox.cpp:124
Common::UString getSelectedModule()
Definition: newmodule.cpp:188
void hide()
Hide the widget.
Definition: newmodule.cpp:72
void reserve(size_t n)
Definition: listbox.cpp:405
const float kHAlignCenter
Definition: types.h:43
float getHeight() const
Get the widget&#39;s height.
Definition: newmodule.cpp:93
A widget in a GUI.
Definition: widget.h:40
void select(size_t item)
Definition: listbox.cpp:618
The global talk manager for Aurora strings.
void status(const char *s,...)
Definition: util.cpp:52
Graphics::Aurora::Model * loadModelGUI(const Common::UString &resref)
Definition: model.cpp:65
void show()
Show the GUI.
Definition: newmodule.cpp:131
The context handling the gameplay in Neverwinter Nights.
void show()
Show the widget.
Definition: newmodule.cpp:67
A font.
Common::ScopedPtr< Graphics::Aurora::Text > _text
Definition: newmodule.h:67
#define FontMan
Shortcut for accessing the font manager.
Definition: fontman.h:105
NewModuleMenu(Module &module, GUI &charType, ::Engines::Console *console=0)
Definition: newmodule.cpp:122
std::vector< Common::UString > _modules
Definition: newmodule.h:88
Generic Aurora engines model functions.