xoreos  0.0.5
charclass.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 #include "src/aurora/2dareg.h"
27 #include "src/aurora/2dafile.h"
28 
32 
34 
35 namespace Engines {
36 
37 namespace NWN {
38 
40  CharGenBase(console) {
41 
42  _choices = &choices;
43  load("cg_class");
44 
45  getEditBox("HelpBox", true)->setText("fnt_galahad14", TalkMan.getString(484), 1.0f);
46  _classesListBox = getListBox("ClassListBox", true);
47 
50 }
51 
53 }
54 
56  if (tag == "ClassListBox")
58 }
59 
61  getEditBox("HelpBox", true)->setTitle("fnt_galahad14", "");
62  getEditBox("HelpBox", true)->setText("fnt_galahad14", TalkMan.getString(484), 1.0f);
63 
65 }
66 
69 
70  if (_returnCode == 1) {
71  // Set previous choice if any.
72 
73  // Get previous choice.
74  size_t previousChoice = 0;
75  for (size_t it = 0; it < _classesId.size(); ++it) {
76  if (_classesId[it] == _choices->getClass()) {
77  previousChoice = it;
78  break;
79  }
80  }
81 
82  // Setting previous choice.
83  _classesListBox->select(previousChoice);
84  getEditBox("HelpBox", true)->setText("fnt_galahad14", _helpTexts[previousChoice]);
85  getEditBox("HelpBox", true)->setTitle("fnt_galahad14", _classNames[previousChoice]);
86  }
87 }
88 
91 
94 
95  _classNames.clear();
96  _helpTexts.clear();
97 
98  const Aurora::TwoDAFile &twoda = TwoDAReg.get2DA("classes");
99  for (size_t it = 0; it < twoda.getRowCount(); ++it) {
100  const Aurora::TwoDARow &row = twoda.getRow(it);
101  if (row.getInt("PlayerClass") == 0)
102  continue;
103 
104  _classNames.push_back(TalkMan.getString(row.getInt("Name")));
105  _helpTexts.push_back(TalkMan.getString(row.getInt("Description")));
106  WidgetListItemButton *itemClass = new WidgetListItemButton(*this, "ctl_cg_btn_class",
107  _classNames.back(), row.getString("Icon"));
108  _classesListBox->add(itemClass);
109  _classesId.push_back(it);
110 
111  //TODO Implement a real check.
112  if (!row.empty("PreReqTable")) {
113  itemClass->setTextColor(0.5f, 0.5f, 0.5f, 1.0f);
114  } else {
116  }
117  }
118 
121 }
122 
124  if (widget.getTag() == "OkButton") {
126  _returnCode = 2;
127  return;
128  }
129 
130  if (widget.getTag() == "CancelButton") {
131  _returnCode = 1;
132  return;
133  }
134 
135  if (widget.getTag() == "RecommendButton") {
136  // Recommend fighter.
138  getEditBox("HelpBox", true)->setText("fnt_galahad14", _helpTexts[4]);
139  getEditBox("HelpBox", true)->setTitle("fnt_galahad14", _classNames[4]);
140  return;
141  }
142 
143  if (widget.getTag() == "ClassListBox") {
144  getEditBox("HelpBox", true)->setText("fnt_galahad14", _helpTexts[_classesListBox->getSelected()]);
145  getEditBox("HelpBox", true)->setTitle("fnt_galahad14", _classNames[_classesListBox->getSelected()]);
146 
148  getButton("OkButton", true)->setDisabled(true);
149  else
150  getButton("OkButton", true)->setDisabled(false);
151  }
152 }
153 
154 } // End of namespace NWN
155 
156 } // End of namespace Engines
Class to hold the two-dimensional array of a 2DA file.
Definition: 2dafile.h:124
A NWN editbox widget.
The class chooser in CharGen.
#define TalkMan
Shortcut for accessing the talk manager.
Definition: talkman.h:111
A NWN button widget.
const Common::UString & getString(size_t column) const
Return the contents of a cell as a string.
Definition: 2dafile.cpp:59
uint32 _returnCode
The GUI&#39;s return code.
Definition: gui.h:75
std::vector< Common::UString > _classNames
Definition: charclass.h:52
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 add(WidgetListItem *item, bool noTag=false)
Definition: listbox.cpp:411
void setDisabled(bool disabled)
Disable/Enable the widget.
Definition: button.cpp:107
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
Definition: charclass.cpp:123
void fixWidgetType(const Common::UString &tag, WidgetType &type)
Definition: charclass.cpp:55
size_t getRowCount() const
Return the number of rows in the array.
Definition: 2dafile.cpp:400
WidgetButton * getButton(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:306
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 setClass(uint32 classId)
void setTextColor(float r, float g, float b, float a)
const Common::UString & getTag() const
Get the widget&#39;s tag.
Definition: widget.cpp:45
void setMode(Mode mode)
Definition: listbox.cpp:313
CharGenChoices * _choices
Definition: chargenbase.h:45
Handling BioWare&#39;s 2DAs (two-dimensional array).
std::vector< uint32 > _classesId
Definition: charclass.h:54
void load(const Common::UString &resref)
Definition: gui.cpp:77
#define TwoDAReg
Shortcut for accessing the 2da registry.
Definition: 2dareg.h:101
The global 2DA registry.
int32 getInt(size_t column) const
Return the contents of a cell as an int.
Definition: 2dafile.cpp:75
WidgetEditBox * getEditBox(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:294
bool empty(size_t column) const
Check if the cell is empty.
Definition: 2dafile.cpp:107
Button items used in WidgetListBox.
const TwoDARow & getRow(size_t row) const
Get a row.
Definition: 2dafile.cpp:421
A widget in a GUI.
Definition: widget.h:40
void select(size_t item)
Definition: listbox.cpp:618
void setTitle(const Common::UString &font, const Common::UString &title)
Set title text if available.
Definition: editbox.cpp:59
std::vector< Common::UString > _helpTexts
Definition: charclass.h:53
The global talk manager for Aurora strings.
WidgetListBox * _classesListBox
Definition: charclass.h:51
void hide()
Hide the GUI.
Definition: charclass.cpp:67
A row within a 2DA file.
Definition: 2dafile.h:61
virtual void hide()
Hide the GUI.
Definition: gui.cpp:80
CharClass(CharGenChoices &choices, ::Engines::Console *console=0)
Definition: charclass.cpp:39