xoreos  0.0.5
charinfovoice.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/util.h"
26 
27 #include "src/aurora/talkman.h"
28 #include "src/aurora/2dareg.h"
29 #include "src/aurora/2dafile.h"
30 #include "src/aurora/ssffile.h"
31 
34 
37 
38 namespace Engines {
39 
40 namespace NWN {
41 
43  WidgetListItemButton(gui, "ctl_cg_btn_snds", title, "", kNoButton), _soundSetID(soundSetID) {
44 
45  _soundSet.reset(new Aurora::SSFFile(soundSet));
47 }
48 
50 }
51 
52 void WidgetListItemVoice::mouseDown(uint8 state, float x, float y) {
53  if (_currentSound < _soundSet->getSoundCount()) {
54  ++_currentSound;
55  } else {
56  _currentSound = 0;
57  }
58 
59  setSound(_soundSet->getSoundFile(_currentSound));
60 
62 }
63 
66 
68 }
69 
71  _choices = &choices;
72 
73  load("cg_char_info");
74 
76 
77  // TODO: Random button.
78  getWidget("RandomButton", true)->setDisabled(true);
79  // TODO: Deity button.
80  getWidget("DeityButton", true)->setDisabled(true);
81  // TODO: Enable name and description.
82 }
83 
85 }
86 
88 }
89 
92 
93  WidgetListItemVoice *firstItem =
94  dynamic_cast<WidgetListItemVoice *>(getListBox("SoundSetEdit", true)->getSelectedItem());
95 
96  if (firstItem)
97  playSound(firstItem->_soundSet->getSoundFile(0), Sound::kSoundTypeSFX);
98 }
99 
101  if (widget.getTag() == "OkButton") {
102  WidgetListItemVoice *item =
103  dynamic_cast<WidgetListItemVoice *>(getListBox("SoundSetEdit", true)->getSelectedItem());
104 
105  if (!item)
106  return;
107 
109  _returnCode = 2;
110  return;
111  }
112 
113  if (widget.getTag() == "CancelButton") {
114  _returnCode = 1;
115  return;
116  }
117 }
118 
120  WidgetListBox *voicesListBox = getListBox("SoundSetEdit", true);
121  voicesListBox->lock();
122 
123  voicesListBox->clear();
124  voicesListBox->setMode(WidgetListBox::kModeSelectable);
125 
126  const Aurora::TwoDAFile &twodaSoundSet = TwoDAReg.get2DA("soundset");
127  for (size_t it = 0; it < twodaSoundSet.getRowCount(); ++it) {
128  const Aurora::TwoDARow &row = twodaSoundSet.getRow(it);
129  // Take only sound set for players.
130  if (row.getInt("TYPE") != 0)
131  continue;
132 
133  // Filter by gender.
134  if (static_cast<Gender>(row.getInt("GENDER")) != _choices->getCharacter().getGender())
135  continue;
136 
137  const Common::UString voiceName = TalkMan.getString(row.getInt("STRREF"));
138  const Common::UString resRef = row.getString("RESREF");
139 
140  WidgetListItemVoice *item = new WidgetListItemVoice(*this, voiceName, resRef, (uint16) it);
141  voicesListBox->add(item);
142  }
143  voicesListBox->unlock();
144 
145  voicesListBox->select(0);
146 }
147 
148 } // End of namespace NWN
149 
150 } // End of namespace Engines
Class to hold the two-dimensional array of a 2DA file.
Definition: 2dafile.h:124
Widget * getWidget(const Common::UString &tag, bool vital=false)
Return a widget in the GUI.
Definition: gui.cpp:314
Handling BioWare&#39;s SSFs (sound set file).
#define TalkMan
Shortcut for accessing the talk manager.
Definition: talkman.h:111
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
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 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
Common::ScopedPtr< Aurora::SSFFile > _soundSet
Definition: charinfovoice.h:52
uint8_t uint8
Definition: types.h:200
Class to hold a sound set.
Definition: ssffile.h:55
const Creature & getCharacter()
virtual void setDisabled(bool disabled)
Disable/Enable the widget.
Definition: widget.cpp:154
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
WidgetListItem * getSelectedItem() const
Definition: listbox.cpp:630
size_t getRowCount() const
Return the number of rows in the array.
Definition: 2dafile.cpp:400
void setSoundSet(uint32 soundSetID)
A NWN listbox widget.
A GUI.
Definition: gui.h:43
void mouseDown(uint8 state, float x, float y)
A mouse button was pressed on the widget.
virtual void show()
Show the GUI.
Definition: gui.cpp:62
void setSound(const Common::UString &sound)
uint16_t uint16
Definition: types.h:202
Utility templates and functions.
void mouseDown(uint8 state, float x, float y)
A mouse button was pressed on the widget.
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).
void load(const Common::UString &resref)
Definition: gui.cpp:77
#define TwoDAReg
Shortcut for accessing the 2da registry.
Definition: 2dareg.h:101
A NWN listbox widget.
Definition: listbox.h:116
void show()
Show the GUI.
The global 2DA registry.
int32 getInt(size_t column) const
Return the contents of a cell as an int.
Definition: 2dafile.cpp:75
Sound::ChannelHandle playSound(const Common::UString &sound, Sound::SoundType soundType, bool loop, float volume, bool pitchVariance)
Play this sound resource.
Definition: util.cpp:81
CharInfoVoice(CharGenChoices &choices, ::Engines::Console *console=0)
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
Gender getGender() const
Get the creature&#39;s gender.
Definition: creature.cpp:190
The global talk manager for Aurora strings.
A creature in a Neverwinter Nights area.
WidgetListItemVoice(::Engines::GUI &gui, const Common::UString &title, const Common::UString &soundSet, uint16 soundSetID)
#define SIZE_MAX
Definition: types.h:172
Sound effect.
Definition: types.h:45
Generic Aurora engines utility functions.
A row within a 2DA file.
Definition: 2dafile.h:61
The character information GUI in CharGen.