xoreos  0.0.5
charpackage.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/2dareg.h"
26 #include "src/aurora/2dafile.h"
27 #include "src/aurora/talkman.h"
28 
30 
34 
41 
42 namespace Engines {
43 
44 namespace NWN {
45 
47  _choices = &choices;
48  load("cg_package");
49 
50  _packageListBox = getListBox("ClassListBox", true);
51 }
52 
54 }
55 
57  getEditBox("HelpBox", true)->setTitle("fnt_galahad14", TalkMan.getString(483));
58  getEditBox("HelpBox", true)->setText("fnt_galahad14", TalkMan.getString(487));
59 
61 
62  _subGUIs.clear();
63 }
64 
67 
69 }
70 
72  if (widget.getTag() == "OkButton") {
74 
75  _returnCode = 2;
76  return;
77  }
78 
79  if (widget.getTag() == "CancelButton") {
80  _returnCode = 1;
81  return;
82  }
83 
84  if (widget.getTag() == "ClassListBox") {
85  size_t choice = _packageListBox->getSelected();
86  getEditBox("HelpBox", true)->setText("fnt_galahad14", _helpTexts[choice]);
87  getEditBox("HelpBox", true)->setTitle("fnt_galahad14", _packageNames[choice]);
88  return;
89  }
90 
91  if (widget.getTag() == "RecommendButton") {
92  // Recommend first package.
94  }
95 
96  if (widget.getTag() == "ConfigurePckg") {
97  if (_subGUIs.size() == 0) {
98  CharSkills *charSkills = new CharSkills(*_choices, _console);
99  _subGUIs.push_back(charSkills);
100  // TODO Check if new feats are needed.
101  CharFeats *charFeats = new CharFeats(*_choices, _console);
102  _subGUIs.push_back(charFeats);
103 
104  // Add spell GUI if needed
105  const Aurora::TwoDAFile &twodaClasses = TwoDAReg.get2DA("classes");
106  const Aurora::TwoDARow &rowClass = twodaClasses.getRow(_choices->getClass());
107  if (rowClass.getInt("SpellCaster") > 0) {
108  if (rowClass.getString("SpellGainTable") == "CLS_SPGN_WIZ" &&
109  _choices->getCharacter().getHitDice() == 0) {
110  CharSchool *charSchool = new CharSchool(*_choices, _console);
111  _subGUIs.push_back(charSchool);
112  CharSpells *charSpells = new CharSpells(*_choices, _console);
113  _subGUIs.push_back(charSpells);
114  } else if (rowClass.getString("SpellGainTable") == "CLS_SPGN_CLER" &&
115  _choices->getCharacter().getHitDice() == 0) {
116  CharDomain *charDomain = new CharDomain(*_choices, _console);
117  _subGUIs.push_back(charDomain);
118  } else if (!rowClass.empty("SpellKnownTable")) {
119  CharSpells *charSpells = new CharSpells(*_choices, _console);
120  _subGUIs.push_back(charSpells);
121  }
122  }
123  //TODO: Add animal companion/familiar GUI.
124  }
125 
126  uint32 subReturnCode;
127  for (Common::PtrVector<CharGenBase>::iterator g = _subGUIs.begin(); g != _subGUIs.end(); ++g) {
128  subReturnCode = sub(**g, 0, false);
129  if (subReturnCode == 1) {
130  reset();
131  _returnCode = 1;
132  return;
133  }
134  }
135 
136  _returnCode = 2;
137  }
138 }
139 
144 
145  _helpTexts.clear();
146  _packageID.clear();
147  _packageNames.clear();
148 
149  const Aurora::TwoDAFile &twoda = TwoDAReg.get2DA("packages");
150  for (size_t it = 0; it < twoda.getRowCount(); ++it) {
151  const Aurora::TwoDARow &row = twoda.getRow(it);
152  if (row.getInt("PlayerClass") == 0 ||
153  row.getInt("ClassID") != (int) _choices->getClass() ||
154  row.getInt("Name") == 0)
155  continue;
156 
157  _helpTexts.push_back(TalkMan.getString(row.getInt("Description")));
158  _packageNames.push_back(TalkMan.getString(row.getInt("Name")));
159  WidgetListItemButton *packagetItem = new WidgetListItemButton(*this, "ctl_cg_btn_class", TalkMan.getString(row.getInt("Name")), "");
160  _packageListBox->add(packagetItem);
161 
162  _packageID.push_back((uint8) it);
163  }
165 
166  // Set previous choice if any.
167  uint8 package = _choices->getPackage();
168  if (package == UINT8_MAX) {
169  getEditBox("HelpBox", true)->setTitle("fnt_galahad14", TalkMan.getString(483));
170  getEditBox("HelpBox", true)->setText("fnt_galahad14", TalkMan.getString(487));
171 
173  return;
174  }
175 
176  size_t p = 0;
177  for (; p < _packageID.size(); ++p) {
178  if (_packageID[p] == package)
179  break;
180  }
181 
183 }
184 
185 } // End of namespace NWN
186 
187 } // End of namespace Engines
Class to hold the two-dimensional array of a 2DA file.
Definition: 2dafile.h:124
uint8 getHitDice() const
Returns the number of hit dice, which is effectively the total number of levels.
Definition: creature.cpp:1031
A NWN editbox widget.
#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
WidgetListBox * getListBox(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:318
void add(WidgetListItem *item, bool noTag=false)
Definition: listbox.cpp:411
uint8_t uint8
Definition: types.h:200
const Creature & getCharacter()
Console * _console
Definition: gui.h:70
void setPackage(uint8 package)
size_t getRowCount() const
Return the number of rows in the array.
Definition: 2dafile.cpp:400
WidgetListBox * _packageListBox
Definition: charpackage.h:54
std::vector< Common::UString > _packageNames
Definition: charpackage.h:58
A vector of pointer to objects, with automatic deletion.
Definition: ptrvector.h:44
Common::PtrVector< CharGenBase > _subGUIs
Definition: charpackage.h:56
std::vector< Common::UString > _helpTexts
Definition: charpackage.h:60
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
virtual void show()
Show the GUI.
Definition: gui.cpp:62
The domain chooser for clerc in CharGen.
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).
#define UINT8_MAX
Definition: types.h:225
The feats selection GUI.
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
#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
std::vector< uint8 > _packageID
Definition: charpackage.h:59
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
The spells selection GUI in CharGen.
void select(size_t item)
Definition: listbox.cpp:618
The spell school chooser in CharGen.
void setTitle(const Common::UString &font, const Common::UString &title)
Set title text if available.
Definition: editbox.cpp:59
uint32_t uint32
Definition: types.h:204
The global talk manager for Aurora strings.
A creature in a Neverwinter Nights area.
The package selection GUI.
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
Definition: charpackage.cpp:71
The skills selection GUI.
A row within a 2DA file.
Definition: 2dafile.h:61
void show()
Show the GUI.
Definition: charpackage.cpp:65
CharPackage(CharGenChoices &choices, ::Engines::Console *console)
Definition: charpackage.cpp:46