xoreos  0.0.5
main.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/configman.h"
26 #include "src/common/error.h"
27 #include "src/common/ustring.h"
28 
29 #include "src/events/events.h"
30 
31 #include "src/aurora/2dareg.h"
32 #include "src/aurora/2dafile.h"
33 #include "src/aurora/talkman.h"
34 
36 
39 
42 
46 
47 namespace Engines {
48 
49 namespace Jade {
50 
51 MainMenu::MainMenu(Module &module, ::Engines::Console *console) : ::Engines::Jade::GUI(console),
52  _module(&module), _background(0) {
53 
54  load("maingame");
55 
56  /*
57  * The list box is initially empty, so we need to create the buttons
58  * for the main menu
59  */
60  WidgetListBox *listBoxButtons = getListBox("ListBoxButtons");
61  listBoxButtons->setFill("");
62  listBoxButtons->createItemWidgets(6);
63 
64  listBoxButtons->addItem(TalkMan.getString(111)); // New Game
65  listBoxButtons->addItem(TalkMan.getString(112)); // Load Game
66  listBoxButtons->addItem(TalkMan.getString(114)); // Minigames
67  listBoxButtons->addItem(TalkMan.getString(116)); // Options
68  listBoxButtons->addItem(TalkMan.getString(15709)); // Credits
69  listBoxButtons->addItem(TalkMan.getString(112745)); // Exit
70 
71  listBoxButtons->refreshItemWidgets();
72 
73  /*
74  * The Jade Empire Logo is placed in the middle of the screen
75  * and needs to be moved above the menu buttons
76  */
77  getLabel("TitleLabel")->setWidth(256);
78  getLabel("TitleLabel")->setHeight(65);
79 
80  float tX, tY, tZ;
81  getLabel("TitleLabel")->getPosition(tX, tY, tZ);
82  getLabel("TitleLabel")->setPosition(tX-80, tY+52, tZ);
83 
84  addBackground();
85 }
86 
88  delete _background;
89  _background = NULL;
90 }
91 
93  if (_background)
94  _background->show();
96 }
97 
99  if (_background)
100  _background->hide();
102 }
103 
105  if (widget.getTag() == "ListBoxButtons_ITEM_3") {
106  if (!_options)
107  createOptions();
108 
109  sub(*_options);
110  }
111 
112  if (widget.getTag() == "ListBoxButtons_ITEM_0") {
113  try {
114  _module->load("j01_town");
115  _returnCode = 1;
116  } catch (...) {
118  return;
119  }
120  return;
121  }
122 
123  if (widget.getTag() == "ListBoxButtons_ITEM_4") {
124  playVideo("creditmovie");
125  return;
126  }
127 
128  if (widget.getTag() == "ListBoxButtons_ITEM_5")
129  EventMan.requestQuit();
130 }
131 
133  const Aurora::TwoDAFile &startrooms = TwoDAReg.get2DA("startrooms");
134 
135  Common::UString currentChapter = ConfigMan.getString("chapter", "1");
136  if (startrooms.getRow("chapter", currentChapter).empty("room"))
137  currentChapter = "1";
138 
139  const Common::UString &room = startrooms.getRow("chapter", currentChapter).getString("room");
140 
141  _background = new AreaLayout(room);
142 }
143 
145  _options.reset(new OptionsMenu());
146 }
147 
148 } // End of namespace Jade
149 
150 } // End of namespace Engines
Class to hold the two-dimensional array of a 2DA file.
Definition: 2dafile.h:124
virtual void setHeight(float height)
Set the height of the widget.
void playVideo(const Common::UString &video)
Play this video resource.
Definition: util.cpp:54
void setFill(const Common::UString &fill)
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
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
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
Definition: main.cpp:104
void createItemWidgets(uint32 count)
Definition: listbox.cpp:131
The global config manager.
Module * _module
Definition: main.h:50
A button widget for Star Wars: Knights of the Old Republic and Jade Empire.
virtual void getPosition(float &x, float &y, float &z) const
Get the widget&#39;s position.
Definition: widget.cpp:140
virtual void hide()
Hide the GUI.
Definition: gui.cpp:75
A layout for an area.
void show()
Show the GUI.
Definition: main.cpp:92
void hide()
Hide the GUI.
Definition: main.cpp:98
void exceptionDispatcherWarning(const char *s,...)
Exception dispatcher that prints the exception as a warning, and adds another reason on top...
Definition: error.cpp:158
Basic exceptions to throw.
#define ConfigMan
Shortcut for accessing the config manager.
Definition: configman.h:176
The Jade Empire main options menu.
A Jade Empire GUI.
Definition: gui.h:57
const Common::UString & getTag() const
Get the widget&#39;s tag.
Definition: widget.cpp:45
A list box widget for Star Wars: Knights of the Old Republic and Jade Empire.
A Jade area layout.
Definition: arealayout.h:46
Handling BioWare&#39;s 2DAs (two-dimensional array).
The global events manager.
void addItem(const Common::UString &contents)
Definition: listbox.cpp:122
uint32 sub(GUI &gui, uint32 startCode=kStartCodeNone, bool showSelf=true, bool hideSelf=true)
Open up a sub GUI.
Definition: gui.cpp:349
AreaLayout * _background
Definition: main.h:52
The Jade Empire main menu.
#define TwoDAReg
Shortcut for accessing the 2da registry.
Definition: 2dareg.h:101
The global 2DA registry.
MainMenu(Module &module, ::Engines::Console *console=0)
Definition: main.cpp:51
#define EventMan
Shortcut for accessing the events manager.
Definition: events.h:210
A Jade module.
Definition: module.h:53
Unicode string handling.
bool empty(size_t column) const
Check if the cell is empty.
Definition: 2dafile.cpp:107
void load(const Common::UString &resref)
Definition: gui.cpp:103
const TwoDARow & getRow(size_t row) const
Get a row.
Definition: 2dafile.cpp:421
virtual void show()
Show the GUI.
Definition: gui.cpp:69
A widget in a GUI.
Definition: widget.h:40
void load(const Common::UString &module)
Load a module.
Definition: module.cpp:66
The global talk manager for Aurora strings.
WidgetListBox * getListBox(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:278
A module.
Generic Aurora engines utility functions.
Common::ScopedPtr< GUI > _options
Definition: main.h:54
virtual void setWidth(float width)
Set the width of the widget.
virtual void setPosition(float x, float y, float z)
Set the widget&#39;s position.
WidgetLabel * getLabel(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:194