xoreos  0.0.5
charalignment.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  _lawfulness = 101;
44  _goodness = 101;
45 
46  load("cg_alignment");
47 
48  getEditBox("HelpEdit", true)->setTitle("fnt_galahad14", TalkMan.getString(111));
49  getEditBox("HelpEdit", true)->setText("fnt_galahad14", TalkMan.getString(458));
50 
51  _buttons.reset(new ButtonsGroup(getEditBox("HelpEdit", true)));
52 
53  uint textID = 448;
54 
55  _buttons->addButton(getButton("CEButton"), TalkMan.getString(120), TalkMan.getString(textID));
56  _buttons->addButton(getButton("CGButton"), TalkMan.getString(118), TalkMan.getString(++textID));
57  _buttons->addButton(getButton("CNButton"), TalkMan.getString(119), TalkMan.getString(++textID));
58  _buttons->addButton(getButton("LEButton"), TalkMan.getString(114), TalkMan.getString(++textID));
59  _buttons->addButton(getButton("LGButton"), TalkMan.getString(112), TalkMan.getString(++textID));
60  _buttons->addButton(getButton("LNButton"), TalkMan.getString(113), TalkMan.getString(++textID));
61  _buttons->addButton(getButton("NEButton"), TalkMan.getString(117), TalkMan.getString(++textID));
62  _buttons->addButton(getButton("NGButton"), TalkMan.getString(115), TalkMan.getString(++textID));
63  _buttons->addButton(getButton("TNButton"), TalkMan.getString(116), TalkMan.getString(++textID));
64 }
65 
67 }
68 
70  getEditBox("HelpEdit", true)->setTitle("fnt_galahad14", TalkMan.getString(111));
71  getEditBox("HelpEdit", true)->setText("fnt_galahad14", TalkMan.getString(458));
72 
73  _buttons->setAllInactive();
74  _lawfulness = 101;
75  _goodness = 101;
77 }
78 
81 
82  setRestrict();
83  setRecommend();
84 
85  getEditBox("HelpEdit", true)->setTitle("fnt_galahad14", TalkMan.getString(111));
86  getEditBox("HelpEdit", true)->setText("fnt_galahad14", TalkMan.getString(458));
87 }
88 
91 
92  if (_returnCode == 1) {
93  // If alignment has been previously select, set it back.
95  uint8 point[3] = { 0, 100, 50 };
96 
97  uint lawfulnessButton = 0;
98  uint goodnessButton = 0;
99  for (uint a = 0; a < 3; ++a) {
100  if (point[a] == _lawfulness)
101  lawfulnessButton = 3 * a;
102 
103  if (point[a] == _goodness)
104  goodnessButton = a;
105  }
106  _buttons->setActive(lawfulnessButton + goodnessButton);
107  } else {
108  reset();
109  }
110  }
111 }
112 
114  if (widget.getTag() == "OkButton") {
116  _returnCode = 2;
117  return;
118  }
119 
120  if (widget.getTag() == "CancelButton") {
121  _returnCode = 1;
122  return;
123  }
124 
125  if (widget.getTag() == "RecommendButton") {
126  setRecommend();
127  return;
128  }
129 
130  _buttons->setActive(dynamic_cast<WidgetButton *>(&widget));
131  getAlignment();
132 }
133 
135  // { Barbarian, Bard, Cleric, Druid, Fighter, Monk, Paladin, Ranger, Rogue, Sorcerer, Wizard }
136  uint8 recommendedAlign[] = {2, 1, 5, 8, 1, 5, 4, 1, 8, 2, 5};
137  _buttons->setActive(recommendedAlign[_choices->getClass()]);
138 }
139 
141  // If restriction has already been set, directly return.
142  if (_goodness < 101)
143  return;
144 
145  const Aurora::TwoDAFile &twodaClasses = TwoDAReg.get2DA("classes");
146  const Aurora::TwoDARow &row = twodaClasses.getRow(_choices->getClass());
147 
148  uint alignRestrict = row.getInt("AlignRestrict");
149  bool invertRestrict = row.getInt("InvertRestrict") != 0;
150 
151  // Build restriction axis.
152  uint axisRestrict[5] = { 0x01, 0x02, 0x04, 0x08, 0x10 };
153  uint good[] = { 1, 4, 7 };
154  uint evil[] = { 0, 3, 6 };
155  uint lawful[] = { 3, 4, 5 };
156  uint chaos[] = { 0, 1, 2 };
157 
158  std::vector<uint> goodAxis(good, good + sizeof(good) / sizeof(uint));
159  std::vector<uint> evilAxis(evil, evil + sizeof(evil) / sizeof(uint));
160  std::vector<uint> lawfulAxis(lawful, lawful + sizeof(lawful) / sizeof(uint));
161  std::vector<uint> chaosAxis(chaos, chaos + sizeof(chaos) / sizeof(uint));
162  std::vector<uint> neutralAxis;
163 
164  neutralAxis.push_back(8);
165 
166  uint alignRstrctType = row.getInt("AlignRstrctType");
167 
168  if (alignRstrctType == 0x1) {
169  neutralAxis.push_back(6);
170  neutralAxis.push_back(7);
171  } else if (alignRstrctType == 0x2) {
172  neutralAxis.push_back(2);
173  neutralAxis.push_back(5);
174  } else if (alignRstrctType == 0x3) {
175  neutralAxis.push_back(6);
176  neutralAxis.push_back(7);
177  neutralAxis.push_back(2);
178  neutralAxis.push_back(5);
179  }
180 
181  std::vector<std::vector<uint> > axis;
182  axis.push_back(neutralAxis);
183  axis.push_back(lawfulAxis);
184  axis.push_back(chaosAxis);
185  axis.push_back(goodAxis);
186  axis.push_back(evilAxis);
187 
188  const std::vector<WidgetButton *> bList = _buttons->getButtonsList();
189 
190  for (std::vector<WidgetButton *>::const_iterator it = bList.begin(); it != bList.end(); ++it)
191  (*it)->setDisabled(invertRestrict);
192 
193  for (uint it = 0; it < 5; ++it) {
194  if (axisRestrict[it] & alignRestrict) {
195  for (std::vector<uint>::iterator ax = axis[it].begin(); ax != axis[it].end(); ++ax)
196  bList[*ax]->setDisabled(!invertRestrict);
197  }
198  }
199 }
200 
202  size_t button = _buttons->getChoice();
203 
204  uint8 point[3] = { 0, 100, 50 };
205  size_t rest = button % 3;
206  _goodness = point[rest];
207  _lawfulness = point[(button - rest) / 3];
208 }
209 
210 } // End of namespace NWN
211 
212 } // End of namespace Engines
Class to hold the two-dimensional array of a 2DA file.
Definition: 2dafile.h:124
Common::ScopedPtr< ButtonsGroup > _buttons
Definition: charalignment.h:55
A NWN editbox widget.
#define TalkMan
Shortcut for accessing the talk manager.
Definition: talkman.h:111
A NWN button widget.
uint32 _returnCode
The GUI&#39;s return code.
Definition: gui.h:75
CharAlignment(CharGenChoices &choices, ::Engines::Console *console=0)
bool getAlign(uint8 &goodness, uint8 &lawfulness) const
void setAlign(uint8 goodness, uint8 lawfulness)
uint8_t uint8
Definition: types.h:200
Utility class that handles group of WidgetButton where only one button can be toggled.
The alignment chooser in CharGen.
WidgetButton * getButton(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:306
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
const Common::UString & getTag() const
Get the widget&#39;s tag.
Definition: widget.cpp:45
CharGenChoices * _choices
Definition: chargenbase.h:45
Handling BioWare&#39;s 2DAs (two-dimensional array).
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
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
WidgetEditBox * getEditBox(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:294
void hide()
Hide the GUI.
const TwoDARow & getRow(size_t row) const
Get a row.
Definition: 2dafile.cpp:421
A widget in a GUI.
Definition: widget.h:40
void setTitle(const Common::UString &font, const Common::UString &title)
Set title text if available.
Definition: editbox.cpp:59
The global talk manager for Aurora strings.
void show()
Show the GUI.
A row within a 2DA file.
Definition: 2dafile.h:61
virtual void hide()
Hide the GUI.
Definition: gui.cpp:80
unsigned int uint
Definition: types.h:211