xoreos  0.0.5
chardomain.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/common/strutil.h"
26 
27 #include "src/aurora/talkman.h"
28 #include "src/aurora/2dareg.h"
29 #include "src/aurora/2dafile.h"
30 
32 
37 
39 
40 namespace Engines {
41 
42 namespace NWN {
43 
45  const Common::UString &icon, const Common::UString &desc,
46  uint8 domainId)
47  : WidgetListItemButton(gui, "ctl_cg_btn_dom", name, icon, kMoveButton)
48  , _name(name), _description(desc), _domainId(domainId) {
49 
50  setTag("Item#" + name);
51 }
52 
54 }
55 
56 void WidgetListItemDomain::mouseUp(uint8 state, float x, float y) {
57  WidgetListItemButton::mouseUp(state, x, y);
58 
59  // Show description text
60  CharDomain &gui = dynamic_cast<CharDomain &>(*_gui);
61 
62  gui.getEditBox("DomainDesc", true)->setText("fnt_galahad14", _description);
63  gui.getLabel("DomainName", true)->setText(_name);
64 }
65 
66 void WidgetListItemDomain::mouseDblClick(uint8 UNUSED(state), float UNUSED(x), float UNUSED(y)) {
67  // Remove double click behaviour.
68 }
69 
71  if ((widget.getTag().endsWith("#MoveButtonLeft") || widget.getTag().endsWith("#MoveButtonRight")))
72  dynamic_cast<CharDomain &>(*_gui).moveDomain(this);
73 }
74 
75 CharDomain::CharDomain(CharGenChoices &choices, Console *console) : CharGenBase(console) {
76  _choices = &choices;
77  load("cg_domain");
78 
79  _chosenDomains.clear();
80 
81  getButton("OkButton")->setDisabled(true);
82  _domainListBox = getListBox("DomainListBox", true);
83 
85 }
86 
88  for (size_t d = 0; d < _chosenDomains.size(); ++d) {
89  _chosenDomains[d]->remove();
90  }
91 
95 }
96 
99 
100  for (size_t d = _chosenDomains.size(); d > 0; --d)
102 }
103 
105  if (tag == "DomainListBox")
107 }
108 
110  if (widget.getTag() == "OkButton") {
111  assert(_chosenDomains.size() == 2);
112  _choices->setDomains(_chosenDomains.front()->_domainId, _chosenDomains.back()->_domainId);
113  _returnCode = 2;
114  return;
115  }
116 
117  if (widget.getTag() == "CancelButton") {
118  _returnCode = 1;
119  return;
120  }
121 
122  if (widget.getTag() == "RecommendButton") {
124  return;
125  }
126 }
127 
129  _domainListBox->lock();
132 
133  const Aurora::TwoDAFile &twodaDomains = TwoDAReg.get2DA("domains");
134  for (size_t d = 0; d < twodaDomains.getRowCount(); ++d) {
135  const Aurora::TwoDARow &domainRow = twodaDomains.getRow(d);
136  // Some rows are unused.
137  if (domainRow.empty("Label"))
138  continue;
139 
140  const Common::UString name = TalkMan.getString(domainRow.getInt("Name"));
141  const Common::UString desc = TalkMan.getString(domainRow.getInt("Description"));
142  const Common::UString icon = domainRow.getString("Icon");
143 
144  _domainListBox->add(new WidgetListItemDomain(*this, name, icon, desc, static_cast<uint8>(d)), true);
145  }
147 
149 }
150 
152  getEditBox("DomainDesc", true)->setText("fnt_galahad14", item->_description);
153  getLabel("DomainName", true)->setText(item->_name);
154  // Check if the item belongs to the listbox or not and moves it.
155  if (item->_isRight) {
156  if (_chosenDomains.size() > 1)
157  return;
158 
159  _domainListBox->lock();
160  _domainListBox->remove(item);
161  item->changeArrowDirection();
163 
164  _chosenDomains.push_back(item);
165  _domainListBox->addSub(*item);
166  for (std::vector<WidgetListItem *>::iterator it = _domainListBox->begin(); it != _domainListBox->end(); ++it) {
167  (*it)->addGroupMember(*item);
168  item->addGroupMember(**it);
169  }
170 
171  if (_chosenDomains.size() == 2)
172  getButton("OkButton")->setDisabled(false);
173 
174  } else {
175  _domainListBox->lock();
176  _domainListBox->add(item, true);
177  item->changeArrowDirection();
180 
181  std::vector<WidgetListItemDomain *>::iterator itItem;
182  for (std::vector<WidgetListItemDomain *>::iterator i = _chosenDomains.begin(); i != _chosenDomains.end(); ++i) {
183  if (*i == item)
184  itItem = i;
185  }
186 
187  _chosenDomains.erase(itItem);
188 
189  if (_chosenDomains.size() < 2)
190  getButton("OkButton")->setDisabled(true);
191  }
192 
194 
195  item->activate();
196 }
197 
199  float pX, pY, pZ;
200  getEditBox("DomainDesc")->getPosition(pX, pY, pZ);
201  float nX, nY, nZ;
202  for (size_t dom = 0; dom < _chosenDomains.size(); ++dom) {
203  getEditBox("DomainDesc")->getNode("domain" + Common::composeString<size_t>(dom + 1))->getPosition(nX, nY, nZ);
204  _chosenDomains[dom]->setPosition(nX + pX,nY + pY,nZ + pZ - 100.f);
205  _chosenDomains[dom]->show();
206  }
207 }
208 
210  reset();
211 
212  uint8 domain1, domain2;
213  _choices->getPrefDomains(domain1, domain2);
214  while (_chosenDomains.size() < 2) {
215  for (std::vector<WidgetListItem *>::iterator d = _domainListBox->begin(); d != _domainListBox->end(); ++d) {
216  WidgetListItemDomain &item = dynamic_cast<WidgetListItemDomain &>(**d);
217 
218  if (domain1 == item._domainId) {
219  moveDomain(&item);
220  break;
221  }
222 
223  if (domain2 == item._domainId) {
224  moveDomain(&item);
225  break;
226  }
227  }
228  }
229  // FIXME: It seems that when we try to move back a preferred item, it doesn't hide itself
230  // necessarily.
231 }
232 
233 } // End of namespace NWN
234 
235 } // End of namespace Engines
Class to hold the two-dimensional array of a 2DA file.
Definition: 2dafile.h:124
A NWN editbox widget.
#define TalkMan
Shortcut for accessing the talk manager.
Definition: talkman.h:111
A NWN button widget.
CharDomain(CharGenChoices &choices, ::Engines::Console *console=0)
Definition: chardomain.cpp:75
const Common::UString & getString(size_t column) const
Return the contents of a cell as a string.
Definition: 2dafile.cpp:59
void getPrefDomains(uint8 &domain1, uint8 &domain2)
uint32 _returnCode
The GUI&#39;s return code.
Definition: gui.h:75
A class holding an UTF-8 string.
Definition: ustring.h:48
WidgetListItemDomain(::Engines::GUI &gui, const Common::UString &title, const Common::UString &icon, const Common::UString &desc, uint8 domainId)
Definition: chardomain.cpp:44
WidgetListBox * getListBox(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:318
void remove(WidgetListItem *item)
Definition: listbox.cpp:438
void add(WidgetListItem *item, bool noTag=false)
Definition: listbox.cpp:411
uint8_t uint8
Definition: types.h:200
void setTag(const Common::UString &tag)
Set the widget&#39;s tag.
void setDisabled(bool disabled)
Disable/Enable the widget.
Definition: button.cpp:107
virtual void addGroupMember(Widget &widget)
Add a fellow group member to the widget.
Definition: widget.cpp:222
virtual void getPosition(float &x, float &y, float &z) const
Get the widget&#39;s position.
Definition: widget.cpp:140
bool endsWith(const UString &with) const
Definition: ustring.cpp:315
std::vector< WidgetListItem * >::iterator begin()
Get begin iterator from all the items in WidgetListBox.
Definition: listbox.cpp:654
void getPosition(float &x, float &y, float &z) const
Get the position of the node.
Definition: modelnode.cpp:181
void mouseUp(uint8 state, float x, float y)
A mouse button was released on the widget.
size_t getRowCount() const
Return the number of rows in the array.
Definition: 2dafile.cpp:400
std::vector< WidgetListItemDomain * > _chosenDomains
Definition: chardomain.h:74
Utility templates and functions for working with strings and streams.
A NWN listbox widget.
WidgetListBox * _domainListBox
Definition: chardomain.h:73
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
Definition: chardomain.cpp:109
WidgetButton * getButton(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:306
A GUI.
Definition: gui.h:43
void setText(const Common::UString &font, const Common::UString &text, float spacing=0.0f)
Definition: listbox.cpp:523
void subActive(Engines::Widget &widget)
A sub-widget was activated.
Definition: chardomain.cpp:70
The domain chooser for clerc in CharGen.
WidgetLabel * getLabel(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:270
#define UNUSED(x)
Definition: system.h:170
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
A node within a 3D model.
void load(const Common::UString &resref)
Definition: gui.cpp:77
std::vector< WidgetListItem * >::iterator end()
Get end iterator from all the items in WidgetListBox.
Definition: listbox.cpp:658
#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
void moveDomain(WidgetListItemDomain *item)
Definition: chardomain.cpp:151
bool empty(size_t column) const
Check if the cell is empty.
Definition: 2dafile.cpp:107
const TwoDARow & getRow(size_t row) const
Get a row.
Definition: 2dafile.cpp:421
A widget in a GUI.
Definition: widget.h:40
Graphics::Aurora::ModelNode * getNode(const Common::UString &nodeName) const
Definition: modelwidget.cpp:92
void mouseDblClick(uint8 state, float x, float y)
A mouse button was double-clicked on the widget.
Definition: chardomain.cpp:66
The global talk manager for Aurora strings.
void setDomains(uint8 domain1, uint8 domain2)
void fixWidgetType(const Common::UString &tag, NWN::GUI::WidgetType &type)
Definition: chardomain.cpp:104
A row within a 2DA file.
Definition: 2dafile.h:61
virtual void addSub(Widget &widget)
Add a sub-widget to the widget.
Definition: widget.cpp:206
A NWN label widget.
void setText(const Common::UString &text)
Definition: label.cpp:67
friend class WidgetListItemDomain
Definition: chardomain.h:76
void mouseUp(uint8 state, float x, float y)
A mouse button was released on the widget.
Definition: chardomain.cpp:56