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 
28 
31 
32 namespace Engines {
33 
34 namespace KotOR {
35 
36 CharacterGenerationNameMenu::CharacterGenerationNameMenu(CharacterGenerationInfo &info, Console *console) :
37  CharacterGenerationBaseMenu(info, console),
38  _humanFirst(info.getGender() == kGenderMale ? "humanm" : "humanf"), _humanLast("humanl"),
39  _name(_info.getName()) {
40 
41  load("name");
42 
43  addBackground(kBackgroundTypeMenu);
44 
45  _nameLabel = getLabel("NAME_BOX_EDIT");
46  _nameLabel->setText(_info.getName() + "_");
47 
48  EventMan.enableTextInput(true);
49  EventMan.enableKeyRepeat(true);
50 }
51 
53  if (widget.getTag() == "BTN_RANDOM") {
55  _nameLabel->setText(_name + "_");
57  return;
58  }
59 
60  if (widget.getTag() == "BTN_BACK") {
61  _returnCode = 1;
62  EventMan.enableTextInput(false);
63  EventMan.enableKeyRepeat(false);
64  return;
65  }
66 
67  if (widget.getTag() == "END_BTN") {
68  _returnCode = 1;
69  accept();
70  EventMan.enableTextInput(false);
71  EventMan.enableKeyRepeat(false);
72  return;
73  }
74 }
75 
77  if (key == Events::kKeyBackspace && type == Events::kEventKeyDown) {
78  if (!_name.empty()) {
79  _name.erase(--_name.end());
80  _nameLabel->setText(_name + "_");
82  }
83  }
84 }
85 
87  // The name should not be longer than 18 letters (according to the original game).
88  if (_name.size() == 18) {
89  return;
90  }
91 
92  _name += text;
94  _nameLabel->setText(_name + "_");
95 }
96 
97 } // End of namespace KotOR
98 
99 } // End of namespace Engines
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
virtual void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
Definition: chargenname.cpp:47
virtual 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:70
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
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
EventType
Custom event types.
Definition: types.h:45
The menu for modifying the name of the character.
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
void setName(const Common::UString &name)
Set the name of the Character.
CharacterGenerationNameMenu(CharacterGenerationInfo &info, ::Engines::Console *console=0)
iterator end() const
Definition: ustring.cpp:257
virtual void callbackTextInput(const Common::UString &text)
Callback that&#39;s triggered when a text input is received.
Definition: chargenname.cpp:80
The class for storing character information for generation.
static const Common::UString & kBackgroundTypeMenu
Definition: guibackground.h:42