xoreos  0.0.5
chargenname.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/events/events.h"
26 
29 
30 namespace Engines {
31 
32 namespace KotOR2 {
33 
35  CharacterGenerationBaseMenu(info, console),
36  _humanFirst(info.getGender() == kGenderMale ? "humanm" : "humanf"), _humanLast("humanl"),
37  _name(_info.getName()) {
38  load("name_p");
39 
40  _nameLabel = getLabel("NAME_BOX_EDIT");
41  _nameLabel->setText(_info.getName() + "_");
42 
43  EventMan.enableTextInput(true);
44  EventMan.enableKeyRepeat(true);
45 }
46 
48  if (widget.getTag() == "BTN_RANDOM") {
50  _nameLabel->setText(_name + "_");
52  return;
53  }
54 
55  if (widget.getTag() == "BTN_BACK") {
57  EventMan.enableTextInput(false);
58  EventMan.enableKeyRepeat(false);
59  return;
60  }
61  if (widget.getTag() == "END_BTN") {
62  accept();
64  EventMan.enableTextInput(false);
65  EventMan.enableKeyRepeat(false);
66  return;
67  }
68 }
69 
71  if (key == Events::kKeyBackspace && type == Events::kEventKeyDown) {
72  if (!_name.empty()) {
73  _name.erase(--_name.end());
74  _nameLabel->setText(_name + "_");
76  }
77  }
78 }
79 
81  // The name should not be longer than 18 letters (according to the original game).
82  if (_name.size() == 18) {
83  return;
84  }
85 
86  _name += text;
88  _nameLabel->setText(_name + "_");
89 }
90 
91 } // End of namespace KotOR
92 
93 } // End of namespace Engines
void load(const Common::UString &resref)
Definition: gui.cpp:103
static const uint32 kReturnCodeAbort
Definition: gui.h:47
A label widget for Star Wars: Knights of the Old Republic and Jade Empire.
uint32 _returnCode
The GUI&#39;s return code.
Definition: gui.h:75
A class holding an UTF-8 string.
Definition: ustring.h:48
CharacterGenerationNameMenu(CharacterGenerationInfo &info, ::Engines::Console *console=0)
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
Definition: chargenname.cpp:52
void setName(const Common::UString &name)
Set the name of the Character.
Keyboard key was pressed.
Definition: types.h:46
const Common::UString & getTag() const
Get the widget&#39;s tag.
Definition: widget.cpp:45
Common::UString generateRandomName(size_t maxLetters) const
Generate a random name from the ltr file.
Definition: ltrfile.cpp:52
The global events manager.
void info(const char *s,...)
Definition: util.cpp:69
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
#define EventMan
Shortcut for accessing the events manager.
Definition: events.h:210
WidgetLabel * getLabel(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:204
A widget in a GUI.
Definition: widget.h:40
size_t size() const
Return the size of the string, in characters.
Definition: ustring.cpp:241
The KotOR 2 character generation name menu.
EventType
Custom event types.
Definition: types.h:45
Key
Definition: types.h:78
void setText(const Common::UString &text)
void erase(iterator from, iterator to)
Erase the character within this range.
Definition: ustring.cpp:598
iterator end() const
Definition: ustring.cpp:257
void callbackKeyInput(const Events::Key &key, const Events::EventType &type)
Callback that&#39;s triggered when a key is pressed or released.
Definition: chargenname.cpp:76
const Common::UString & getName() const
Get the name of the character.
void callbackTextInput(const Common::UString &text)
Callback that&#39;s triggered when a text input is received.
Definition: chargenname.cpp:86