xoreos  0.0.5
charactergeneration.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 "glm/mat4x4.hpp"
26 #include "glm/gtc/type_ptr.hpp"
27 #include "glm/gtc/matrix_transform.hpp"
28 
29 #include "src/common/util.h"
30 
31 #include "src/aurora/talkman.h"
32 
34 
41 
42 namespace Engines {
43 
44 namespace KotOR {
45 
47  GUI(console), _module(module), _pc(pc), _step(0), _charSubScene(new Graphics::Aurora::SubSceneQuad) {
48 
49  load("maincg");
50 
52 
53  static const char * const kEmptyLabels[] = {
54  "VIT_ARROW_LBL", "DEF_ARROW_LBL", "LBL_NAME",
55  "WILL_ARROW_LBL", "REFL_ARROW_LBL", "FORT_ARROW_LBL",
56  "VIT_ARROW_LBL", "DEF_ARROW_LBL", "LBL_NAME"
57  };
58 
59  for (size_t i = 0; i < ARRAYSIZE(kEmptyLabels); i++) {
60  WidgetLabel *label = getLabel(kEmptyLabels[i]);
61  if (label)
62  label->setText("");
63  }
64 
65  static const char * const kInvisibleWidgets[] = {
66  "NEW_LBL", "OLD_LBL", "LBL_LEVEL", "LBL_LEVEL_VAL"
67  };
68 
69  for (size_t i = 0; i < ARRAYSIZE(kInvisibleWidgets); i++) {
70  Widget *widget = getWidget(kInvisibleWidgets[i]);
71  if (widget)
72  widget->setInvisible(true);
73  }
74 
75  WidgetLabel *lblClass = getLabel("LBL_CLASS");
76  if (lblClass) {
77  // Set the class title according to the class of the character
78  switch (pc->getClass()) {
79  case kClassSoldier:
80  lblClass->setText(TalkMan.getString(134));
81  break;
82  case kClassScout:
83  lblClass->setText(TalkMan.getString(133));
84  break;
85  case kClassScoundrel:
86  lblClass->setText(TalkMan.getString(135));
87  break;
88  default:
89  lblClass->setText("");
90  }
91  }
92 
93  WidgetLabel *lblPortrait = getLabel("PORTRAIT_LBL");
94  if (lblPortrait)
95  lblPortrait->setFill(_pc->getPortrait());
96 
97  WidgetLabel *lblModel = getLabel("MODEL_LBL");
98 
99  float subSceneWidth = lblModel ? lblModel->getWidth() : 1.0f;
100  float subSceneHeight = lblModel ? lblModel->getHeight() : 1.0f;
101 
102  glm::mat4 projection(glm::perspective(Common::deg2rad(22.72f), subSceneWidth/subSceneHeight, 0.1f, 10.0f));
103 
104  /*
105  * TODO: These values are extracted using apitrace from the original game.
106  * They should be replaced with a more straight forward matrix transformation expression.
107  */
108  float modelView[] = {
109  0.000900542, 0.0176735, 0.999843, 0,
110  0.999999, 0.000900542, -0.00091657, 0,
111  -0.00091657, 0.999843, -0.0176727, 0,
112  0, 0, 0, 1
113  };
114 
115  glm::mat4 transformation(glm::make_mat4(modelView));
116 
117  transformation = glm::translate(transformation, glm::vec3(-4.87251f, 0.0f, -0.776371f));
118 
119  transformation = glm::rotate(transformation,
120  Common::deg2rad(-90.0f),
121  glm::vec3(0.0f, 0.0f, 1.0f));
122 
123  if (lblModel) {
124  lblModel->setSubScene(_charSubScene.get());
125 
126  if (_pc->getModel())
127  _charSubScene->add(_pc->getModel());
128 
129  _charSubScene->setProjectionMatrix(projection);
130  _charSubScene->setGlobalTransformationMatrix(transformation);
131  }
132 
134 }
135 
137 }
138 
140  if (_quickChar)
141  removeChild(_quickChar.get());
142  if (_customChar)
143  removeChild(_customChar.get());
144 
145  _step = 0;
146 
147  _quickOrCustom.reset(new QuickOrCustomPanel(this));
148  addChild(_quickOrCustom.get());
149 }
150 
152  if (_quickOrCustom)
154  if (_customChar)
155  removeChild(_customChar.get());
156 
157  _quickChar.reset(new QuickCharPanel(this));
158  addChild(_quickChar.get());
159 }
160 
162  if (_quickOrCustom)
164  if (_quickChar)
165  removeChild(_quickChar.get());
166 
167  _customChar.reset(new CustomCharPanel(this));
168  addChild(_customChar.get());
169 }
170 
172  // Operate on a copy of the character object
174 
176 
177  sub(*_charGenMenu);
178  if (_charGenMenu->isAccepted()) {
179  *_pc = info;
180 
181  WidgetLabel *lblPortrait = getLabel("PORTRAIT_LBL");
182  if (lblPortrait)
183  lblPortrait->setFill(_pc->getPortrait());
184 
185  _pc->recreateHead();
186 
187  _step += 1;
188  }
189 }
190 
192  // Operate on a copy of the character object
194 
196 
197  sub(*_charGenMenu);
198  if (_charGenMenu->isAccepted()) {
199  *_pc = info;
200 
201  WidgetLabel *lblName = getLabel("LBL_NAME");
202  if (lblName)
203  lblName->setText(info.getName());
204 
205  _step += 1;
206  }
207 }
208 
210  return _step;
211 }
212 
214  _step = MIN(0, _step - 1);
215 }
216 
218  hide();
219 
220  try {
222  _module->load("end_m01aa");
223  } catch (...) {
225  return;
226  }
227 
228  show();
229 }
230 
232  if (getWidget("DEF_ARROW_LBL"))
233  return;
234 
235  if (key != Events::kKeyReturn || type != Events::kEventKeyUp)
236  return;
237 
238  start();
239  GfxMan.lockFrame();
240  _returnCode = 2;
241 }
242 
243 } // End of namespace KotOR
244 
245 } // End of namespace Engines
void load(const Common::UString &resref)
Definition: gui.cpp:103
Widget * getWidget(const Common::UString &tag, bool vital=false)
Return a widget in the GUI.
Definition: gui.cpp:314
void setFill(const Common::UString &fill)
static const Common::UString & kBackgroundTypeMenu
Definition: guibackground.h:42
The menu for modifying the portrait of the.
virtual void setInvisible(bool invisible)
Make the widget invisible.
Definition: widget.cpp:168
A label widget for Star Wars: Knights of the Old Republic and Jade Empire.
#define TalkMan
Shortcut for accessing the talk manager.
Definition: talkman.h:111
uint32 _returnCode
The GUI&#39;s return code.
Definition: gui.h:75
The panel to customize a quick character.
The panel to choose between quick or custom characters.
void setSubScene(Graphics::Aurora::SubSceneQuad *subscene)
#define ARRAYSIZE(x)
Macro which determines the number of entries in a fixed size array.
Definition: util.h:131
void load(const Common::UString &module, const Common::UString &entryLocation="", ObjectType entryLocationType=kObjectTypeAll)
Load a module.
Definition: module.cpp:110
virtual void hide()
Hide the GUI.
Definition: gui.cpp:75
Graphics::Aurora::Model * getModel()
void exceptionDispatcherWarning(const char *s,...)
Exception dispatcher that prints the exception as a warning, and adds another reason on top...
Definition: error.cpp:158
void removeChild(GUI *gui)
Remove a child GUI object from this GUI.
Definition: gui.cpp:245
Utility templates and functions.
void info(const char *s,...)
Definition: util.cpp:69
T MIN(T a, T b)
Definition: util.h:70
uint32 sub(GUI &gui, uint32 startCode=kStartCodeNone, bool showSelf=true, bool hideSelf=true)
Open up a sub GUI.
Definition: gui.cpp:349
The panel to customize a custom character.
void addBackground(const Common::UString &background, bool front=false)
Definition: gui.cpp:300
Common::ScopedPtr< Graphics::Aurora::SubSceneQuad > _charSubScene
CharacterGenerationMenu(Module *module, CharacterGenerationInfo *pc, ::Engines::Console *console=0)
virtual void show()
Show the GUI.
Definition: gui.cpp:69
WidgetLabel * getLabel(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:204
PointerType get() const
Returns the plain pointer value.
Definition: scopedptr.h:96
A widget in a GUI.
Definition: widget.h:40
void callbackKeyInput(const Events::Key &key, const Events::EventType &type)
Callback that&#39;s triggered when a key is pressed or released.
The global talk manager for Aurora strings.
EventType
Custom event types.
Definition: types.h:45
The menu for modifying the name of the character.
The primary character generation menu.
Key
Definition: types.h:78
void setText(const Common::UString &text)
Common::ScopedPtr< CharacterGenerationBaseMenu > _charGenMenu
Class getClass() const
Get the class of the character, defined in types.h.
void usePC(Creature *pc)
Use this character as the player character.
Definition: module.cpp:177
A KotOR GUI.
Definition: gui.h:57
Keyboard key was released.
Definition: types.h:47
static float deg2rad(float deg)
Definition: maths.h:97
float getWidth() const
Get the widget&#39;s width.
#define GfxMan
Shortcut for accessing the graphics manager.
Definition: graphics.h:299
float getHeight() const
Get the widget&#39;s height.
Common::UString getPortrait() const
Get the name of the portrait of this character.
void addChild(GUI *gui)
Add a child GUI object to this GUI.
Definition: gui.cpp:240