Repository navigation
Expand file tree
/
Copy pathscreen.cpp
More file actions
254 lines (215 loc) · 8.1 KB
/
Copy pathscreen.cpp
File metadata and controls
254 lines (215 loc) · 8.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2010-2015 Marianne Gagnon
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "guiengine/screen.hpp"
#include "io/file_manager.hpp"
#include "graphics/irr_driver.hpp"
#include "guiengine/engine.hpp"
#include "guiengine/layout_manager.hpp"
#include "guiengine/modaldialog.hpp"
#include "guiengine/widget.hpp"
#include "modes/world.hpp"
#include "network/network_config.hpp"
#include "states_screens/state_manager.hpp"
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
using namespace GUIEngine;
#include <assert.h>
// -----------------------------------------------------------------------------
/**
* \brief Creates a screen populated by the widgets described
* in a STK GUI file.
* \param filename Name of the XML file describing the screen.
* This is NOT a path.
* The passed file name will be searched for in the
* STK data/gui directory.
*/
Screen::Screen(const char* file, bool pause_race)
{
m_magic_number = 0xCAFEC001;
m_filename = file;
m_throttle_FPS = true;
m_render_3d = false;
m_loaded = false;
m_pause_race = pause_race;
m_update_in_background = false;
} // Screen
// -----------------------------------------------------------------------------
/** \brief Creates a dummy incomplete object; only use to override behaviour
* in sub-class.
*/
Screen::Screen(bool pause_race)
{
m_magic_number = 0xCAFEC001;
m_loaded = false;
m_render_3d = false;
m_pause_race = pause_race;
m_update_in_background = false;
} // Screen
// -----------------------------------------------------------------------------
Screen::~Screen()
{
assert(m_magic_number == 0xCAFEC001);
m_magic_number = 0xDEADBEEF;
}
// -----------------------------------------------------------------------------
/** Initialisation before the object is displayed. If necessary this function
* will pause the race if it is running (i.e. world exists). While only some
* of the screen can be shown during the race (via the in-game menu you
* can get the options screen and the help screens only). This is used by
* the RaceResultGUI to leave the race running (for the end animation) while
* the results are being shown.
*/
void Screen::init()
{
if (m_pause_race && World::getWorld() &&
!NetworkConfig::get()->isNetworking())
World::getWorld()->schedulePause(World::IN_GAME_MENU_PHASE);
} // init
// -----------------------------------------------------------------------------
/** Displays this screen bu pushing it onto the stack of screen
* in the state manager.
*/
void Screen::push()
{
StateManager::get()->pushScreen(this);
} // push
// -----------------------------------------------------------------------------
/** Prepares removal of this screen. If necessary this will unpause the
* race (so this means that if you have several consecutive screens while
* the race is running the race will be unpaused and paused when switching
* from one screen to the next.
*/
void Screen::tearDown()
{
if (m_pause_race && World::getWorld() &&
!NetworkConfig::get()->isNetworking())
World::getWorld()->scheduleUnpause();
} // tearDown
// -----------------------------------------------------------------------------
#if 0
#pragma mark -
#pragma mark Load/Init
#endif
/** \brief loads this Screen from the file passed to the constructor */
void Screen::loadFromFile()
{
assert(m_magic_number == 0xCAFEC001);
std::string path = file_manager->getAssetChecked(FileManager::GUI_SCREEN, m_filename, true);
IXMLReader* xml = file_manager->createXMLReader( path );
parseScreenFileDiv(xml, m_widgets);
m_loaded = true;
calculateLayout();
// invoke callback so that the class deriving from Screen is aware of this event
loadedFromFile();
delete xml;
} // loadFromFile
// -----------------------------------------------------------------------------
/** Next time this menu needs to be shown, don't use cached values,
* re-calculate everything. (useful e.g. on reschange, when sizes have changed
* and must be re-calculated)
*/
void Screen::unload()
{
assert(m_magic_number == 0xCAFEC001);
Widget* w;
for_in (w, m_widgets)
{
assert(w->m_magic_number == 0xCAFEC001);
}
m_loaded = false;
m_widgets.clearAndDeleteAll();
// invoke callback so that the class deriving from Screen is aware of this event
unloaded();
} // unload
// -----------------------------------------------------------------------------
/** \brief Called after all widgets have been added. namely expands layouts
* into absolute positions.
*/
void Screen::calculateLayout()
{
assert(m_magic_number == 0xCAFEC001);
// build layout
LayoutManager::calculateLayout( m_widgets, this );
} // calculateLayout
// -----------------------------------------------------------------------------
#if 0
#pragma mark -
#pragma mark Adding/Removing widgets
#endif
/** \brief Adds the IrrLicht widgets corresponding to this screen to the
* IGUIEnvironment.
*/
void Screen::addWidgets()
{
assert(m_magic_number == 0xCAFEC001);
if (!m_loaded) loadFromFile();
addWidgetsRecursively( m_widgets );
//Log::info("Screen::AddWidgets", "%s: focusing the first widget", m_filename.c_str());
// select the first widget (for first players only; if other players need some focus the Screen must provide it).
Widget* w = getFirstWidget();
//Log::info("Screen::AddWidgets", "First widget is %s", (w == NULL ? "null" : w->m_properties[PROP_ID].c_str()));
if (w != NULL) w->setFocusForPlayer( PLAYER_ID_GAME_MASTER );
else Log::warn("Screen::AddWidgets", "Couldn't select first widget, NULL was returned");
} // addWidgets
// -----------------------------------------------------------------------------
/** \brief Can be used for custom purposes for which the load-screen-from-XML
* code won't make it.
*/
void Screen::manualAddWidget(Widget* w)
{
assert(m_magic_number == 0xCAFEC001);
m_widgets.push_back(w);
} // manualAddWidget
// -----------------------------------------------------------------------------
/** \brief Can be used for custom purposes for which the load-screen-from-XML
* code won't make it. */
void Screen::manualRemoveWidget(Widget* w)
{
assert(m_magic_number == 0xCAFEC001);
#ifdef DEBUG
if(!m_widgets.contains(w))
{
Log::info("Screen", "Widget '%d' not found in screen when removing.",
w->m_id);
Log::info("Screen", "This can be ignored, but is probably wrong.");
}
#endif
m_widgets.remove(w);
} // manualRemoveWidget
// -----------------------------------------------------------------------------
#if 0
#pragma mark -
#pragma mark Getters
#endif
// -----------------------------------------------------------------------------
/** \brief Implementing method from AbstractTopLevelContainer */
int Screen::getWidth()
{
return irr_driver->getActualScreenSize().Width;
}
// -----------------------------------------------------------------------------
/** \brief Implementing method from AbstractTopLevelContainer */
int Screen::getHeight()
{
return irr_driver->getActualScreenSize().Height;
}
// -----------------------------------------------------------------------------