xoreos  0.0.5
classselection.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/gtc/type_ptr.hpp"
26 #include "glm/gtc/matrix_transform.hpp"
27 
28 #include "src/aurora/talkman.h"
29 
31 
34 
35 namespace Engines {
36 
37 namespace KotOR {
38 
40  _hoveredButton(0), _module(module) {
41 
42  load("classsel");
43 
45 
46  // Get the six class buttons
47  _maleScoundrelButton = getButton("BTN_SEL1");
48  _maleScoutButton = getButton("BTN_SEL2");
49  _maleSoldierButton = getButton("BTN_SEL3");
50  _femaleSoldierButton = getButton("BTN_SEL4");
51  _femaleScoutButton = getButton("BTN_SEL5");
52  _femaleScoundrelButton = getButton("BTN_SEL6");
53 
54  // Get the description label
55  _labelDesc = getLabel("LBL_DESC");
56  _labelDesc->setWrapped(true);
57  _labelDesc->setText(TalkMan.getString(32111));
58 
59  // Get the title label
60  _labelTitle = getLabel("LBL_CLASS");
61  _labelTitle->setText("");
62 
63  // Get the class descriptions
64  _soldierDesc = TalkMan.getString(32111);
65  _scoutDesc = TalkMan.getString(32110);
66  _scoundrelDesc = TalkMan.getString(32109);
67 
68  // Combine the titles with gender prefix and class name
69  Common::UString malePrefix = TalkMan.getString(358);
70  Common::UString femalePrefix = TalkMan.getString(359);
71  _soldierMaleTitle = malePrefix + " " + TalkMan.getString(134);
72  _soldierFemaleTitle = femalePrefix + " " + TalkMan.getString(134);
73  _scoutMaleTitle = malePrefix + " " + TalkMan.getString(133);
74  _scoutFemaleTitle = femalePrefix + " " + TalkMan.getString(133);
75  _scoundrelMaleTitle = malePrefix + " " + TalkMan.getString(135);
76  _scoundrelFemaleTitle = femalePrefix + " " + TalkMan.getString(135);
77 
78  // Create the random characters
85 
86  float subSceneWidth = getLabel("3D_MODEL2")->getWidth();
87  float subSceneHeight = getLabel("3D_MODEL2")->getHeight();
88 
89  glm::mat4 projection(glm::perspective(Common::deg2rad(22.72f), subSceneWidth/subSceneHeight, 0.1f, 10.0f));
90 
91  /*
92  * TODO: These values are extracted using apitrace from the original game.
93  * They should be replaced with a more straight forward matrix transformation expression.
94  */
95 
96  float modelView[] = {
97  0.00979373, -0.040304, 0.999139, 0,
98  0.999952, 0.000393929, -0.00978577, 0,
99  8.34465e-7, 0.999187, 0.0403059, 0,
100  0, 0, 0, 1
101  };
102 
103  glm::mat4 transformation(glm::make_mat4(modelView));
104 
105  transformation = glm::translate(transformation, glm::vec3(-4.87294f, 0.0880559f, -1.06834f));
106 
107  transformation = glm::rotate(transformation,
108  Common::deg2rad(-90.0f),
109  glm::vec3(0.0f, 0.0f, 1.0f));
110 
112  projection, transformation);
114  projection, transformation);
116  projection, transformation);
118  projection, transformation);
120  projection, transformation);
122  projection, transformation);
123 }
124 
126  delete _maleSoldier;
127  delete _maleScout;
128  delete _maleScoundrel;
129  delete _femaleSoldier;
130  delete _femaleScout;
131  delete _femaleScoundrel;
132 }
133 
136 }
137 
139  // Check if a specific button is hovered and set title and description
144  return;
145  }
150  return;
151  }
156  return;
157  }
162  return;
163  }
168  return;
169  }
174  return;
175  }
176 }
177 
179  // Return to the main menu
180  if (widget.getTag() == "BTN_BACK") {
181  _returnCode = 1;
182  return;
183  }
184 
185  // Start the character generation with
186  if (widget.getTag() == "BTN_SEL1") {
188  if (sub(*_charGen) == 2) {
189  _returnCode = 2;
190  }
191  }
192  if (widget.getTag() == "BTN_SEL2") {
194  if (sub(*_charGen) == 2) {
195  _returnCode = 2;
196  }
197  }
198  if (widget.getTag() == "BTN_SEL3") {
200  if (sub(*_charGen) == 2) {
201  _returnCode = 2;
202  }
203  }
204  if (widget.getTag() == "BTN_SEL4") {
206  if (sub(*_charGen) == 2) {
207  _returnCode = 2;
208  }
209  }
210  if (widget.getTag() == "BTN_SEL5") {
212  if (sub(*_charGen) == 2) {
213  _returnCode = 2;
214  }
215  }
216  if (widget.getTag() == "BTN_SEL6") {
218  if (sub(*_charGen) == 2) {
219  _returnCode = 2;
220  }
221  }
222 }
223 
225  if (getWidget("BTN_BACK") || !_hoveredButton)
226  return;
227 
228  if (key != Events::kKeyReturn || type != Events::kEventKeyUp)
229  return;
230 
233  if (sub(*_charGen) == 2) {
234  _returnCode = 2;
235  }
236  }
239  if (sub(*_charGen) == 2) {
240  _returnCode = 2;
241  }
242  }
245  if (sub(*_charGen) == 2) {
246  _returnCode = 2;
247  }
248  }
251  if (sub(*_charGen) == 2) {
252  _returnCode = 2;
253  }
254  }
257  if (sub(*_charGen) == 2) {
258  _returnCode = 2;
259  }
260  }
263  if (sub(*_charGen) == 2) {
264  _returnCode = 2;
265  }
266  }
267 }
268 
271  glm::mat4 &projection, glm::mat4 &transformation) {
272 
273  getLabel(widgetName)->setSubScene(&subScene);
274 
275  if (model) {
276  // TODO: Should randomly switch between pause1, pause2 and pause3
277  model->playAnimation("pause1", true, -1);
278  subScene.add(model);
279  }
280 
281  subScene.setProjectionMatrix(projection);
282  subScene.setGlobalTransformationMatrix(transformation);
283 }
284 
285 } // End of namespace KotOR
286 
287 } // End of namespace Engines
A creature in a Star Wars: Knights of the Old Republic area.
static CharacterGenerationInfo * createRandomMaleScout()
Definition: chargeninfo.cpp:53
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
static const Common::UString & kBackgroundTypeMenu
Definition: guibackground.h:42
static CharacterGenerationInfo * createRandomMaleScoundrel()
Definition: chargeninfo.cpp:68
#define TalkMan
Shortcut for accessing the talk manager.
Definition: talkman.h:111
uint32 _returnCode
The GUI&#39;s return code.
Definition: gui.h:75
A class holding an UTF-8 string.
Definition: ustring.h:48
Graphics::Aurora::SubSceneQuad _femaleScoundrelSubScene
Graphics::Aurora::SubSceneQuad _maleScoutSubScene
void add(Renderable *renderable)
Add a renderable to the sub scene.
bool isHovered() const
Definition: button.cpp:90
void setProjectionMatrix(const glm::mat4 &projection)
CharacterGenerationInfo * _femaleScoundrel
The class selection menu.
void setSubScene(Graphics::Aurora::SubSceneQuad *subscene)
Graphics::Aurora::SubSceneQuad _femaleSoldierSubScene
Common::ScopedPtr< GUI > _charGen
Graphics::Aurora::Model * getModel()
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
void callbackRun()
Callback that&#39;s triggered periodically in the run() method.
Graphics::Aurora::SubSceneQuad _maleScoundrelSubScene
WidgetButton * getButton(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:228
ClassSelectionMenu(Module *module, ::Engines::Console *console=0)
static CharacterGenerationInfo * createRandomMaleSoldier()
Definition: chargeninfo.cpp:38
const Common::UString & getTag() const
Get the widget&#39;s tag.
Definition: widget.cpp:45
Graphics::Aurora::SubSceneQuad _maleSoldierSubScene
void createCharacterGeneration(CharacterGenerationInfo *)
void info(const char *s,...)
Definition: util.cpp:69
Graphics::Aurora::SubSceneQuad _femaleScoutSubScene
uint32 sub(GUI &gui, uint32 startCode=kStartCodeNone, bool showSelf=true, bool hideSelf=true)
Open up a sub GUI.
Definition: gui.cpp:349
CharacterGenerationInfo * _maleScout
CharacterGenerationInfo * _maleScoundrel
void addBackground(const Common::UString &background, bool front=false)
Definition: gui.cpp:300
WidgetLabel * getLabel(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:204
static CharacterGenerationInfo * createRandomFemaleScoundrel()
static CharacterGenerationInfo * createRandomFemaleScout()
Definition: chargeninfo.cpp:98
A widget in a GUI.
Definition: widget.h:40
void setGlobalTransformationMatrix(const glm::mat4 &transformation)
void playAnimation(const Common::UString &anim, bool restart=true, float length=0.0f, float speed=1.0f)
Definition: model.cpp:560
void setupClassSubScene(const Common::UString &widgetName, Graphics::Aurora::SubSceneQuad &subScene, Graphics::Aurora::Model *model, glm::mat4 &projection, glm::mat4 &transformation)
The global talk manager for Aurora strings.
EventType
Custom event types.
Definition: types.h:45
CharacterGenerationInfo * _femaleScout
The primary character generation menu.
Key
Definition: types.h:78
void setText(const Common::UString &text)
void setWrapped(bool wrapped)
void callbackKeyInput(const Events::Key &key, const Events::EventType &type)
Callback that&#39;s triggered when a key is pressed or released.
A KotOR GUI.
Definition: gui.h:57
Keyboard key was released.
Definition: types.h:47
CharacterGenerationInfo * _femaleSoldier
static float deg2rad(float deg)
Definition: maths.h:97
static CharacterGenerationInfo * createRandomFemaleSoldier()
Definition: chargeninfo.cpp:83
float getWidth() const
Get the widget&#39;s width.
CharacterGenerationInfo * _maleSoldier
float getHeight() const
Get the widget&#39;s height.