/
MenuWidgets.cpp
316 lines (241 loc) · 7.83 KB
/
MenuWidgets.cpp
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*
* Copyright 2011-2021 Arx Libertatis Team (see the AUTHORS file)
*
* This file is part of Arx Libertatis.
*
* Arx Libertatis 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.
*
* Arx Libertatis 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 Arx Libertatis. If not, see <http://www.gnu.org/licenses/>.
*/
/* Based on:
===========================================================================
ARX FATALIS GPL Source Code
Copyright (C) 1999-2010 Arkane Studios SA, a ZeniMax Media company.
This file is part of the Arx Fatalis GPL Source Code ('Arx Fatalis Source Code').
Arx Fatalis Source Code 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.
Arx Fatalis Source Code 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 Arx Fatalis Source Code. If not, see
<http://www.gnu.org/licenses/>.
In addition, the Arx Fatalis Source Code is also subject to certain additional terms. You should have received a copy of these
additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Arx
Fatalis Source Code. If not, please request a copy in writing from Arkane Studios at the address below.
If you have questions concerning this license or the applicable additional terms, you may contact in writing Arkane Studios, c/o
ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
===========================================================================
*/
#include "gui/MenuWidgets.h"
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iosfwd>
#include <limits>
#include <algorithm>
#include <sstream>
#include <boost/foreach.hpp>
#include "core/Application.h"
#include "core/ArxGame.h"
#include "core/Benchmark.h"
#include "core/Config.h"
#include "core/Core.h"
#include "core/GameTime.h"
#include "core/Localisation.h"
#include "core/SaveGame.h"
#include "core/Version.h"
#include "gui/Hud.h"
#include "gui/LoadLevelScreen.h"
#include "gui/MainMenu.h"
#include "gui/Menu.h"
#include "gui/MenuPublic.h"
#include "gui/Text.h"
#include "gui/Interface.h"
#include "gui/Credits.h"
#include "gui/TextManager.h"
#include "gui/menu/MenuCursor.h"
#include "gui/menu/MenuFader.h"
#include "gui/widget/CycleTextWidget.h"
#include "gui/widget/KeybindWidget.h"
#include "gui/widget/PanelWidget.h"
#include "gui/widget/TextInputWidget.h"
#include "gui/widget/TextWidget.h"
#include "graphics/Draw.h"
#include "graphics/DrawLine.h"
#include "graphics/Math.h"
#include "graphics/Renderer.h"
#include "graphics/data/TextureContainer.h"
#include "graphics/font/Font.h"
#include "graphics/texture/TextureStage.h"
#include "input/Input.h"
#include "scene/ChangeLevel.h"
#include "scene/GameSound.h"
#include "scene/LoadLevel.h"
#include "window/RenderWindow.h"
void ARX_QuickSave() {
if(!g_canResumeGame) {
return;
}
ARX_SOUND_MixerPause(ARX_SOUND_MixerGame);
savegames.quicksave(savegame_thumbnail);
ARX_SOUND_MixerResume(ARX_SOUND_MixerGame);
}
void ARX_LoadGame(const SaveGame & save) {
ARXmenu.requestMode(Mode_InGame);
ARX_SOUND_MixerPause(ARX_SOUND_MixerMenu);
ARX_SOUND_MixerPause(ARX_SOUND_MixerGame);
benchmark::begin(benchmark::LoadLevel);
LoadLevelScreen();
progressBarSetTotal(238);
progressBarReset();
progressBarAdvance();
LoadLevelScreen(save.level);
ARX_CHANGELEVEL_Load(save.savefile);
g_canResumeGame = true;
}
void ARX_QuickLoad() {
SavegameHandle save = savegames.quickload();
if(save == SavegameHandle()) {
// No saves found!
return;
}
ARX_LoadGame(savegames[save]);
}
bool MENU_NoActiveWindow() {
return (!g_mainMenu || !g_mainMenu->m_window || g_mainMenu->m_window->currentPageId() == Page_None);
}
void MainMenuDoFrame() {
UseRenderState state(render2D());
UseTextureState textureState(TextureStage::FilterLinear, TextureStage::WrapClamp);
if(!g_mainMenu || g_mainMenu->bReInitAll) {
MENUSTATE page = Page_None;
float scroll = 0.f;
if(g_mainMenu) {
page = g_mainMenu->requestedPage();
if(g_mainMenu->m_window) {
scroll = g_mainMenu->m_window->scroll();
}
delete g_mainMenu, g_mainMenu = NULL;
}
g_mainMenu = new MainMenu();
g_mainMenu->init();
g_mainMenu->requestPage(page);
if(page != Page_None) {
g_mainMenu->initWindowPages();
g_mainMenu->m_window->setScroll(scroll);
}
}
if(pMenuCursor == NULL) {
pMenuCursor = new MenuCursor();
}
pMenuCursor->update();
g_mainMenu->update();
if(g_mainMenu->bReInitAll) {
return;
}
g_mainMenu->render();
pMenuCursor->DrawCursor();
g_thumbnailCursor.render();
if(MenuFader_process()) {
switch(iFadeAction) {
case Mode_Credits:
ARX_MENU_Clicked_CREDITS();
MenuFader_start(Fade_Out, -1);
break;
case Mode_CharacterCreation:
ARX_MENU_Clicked_NEWQUEST();
MenuFader_start(Fade_Out, -1);
cinematicBorder.reset();
break;
case Mode_InGame:
mainApp->quit();
MenuFader_start(Fade_Out, -1);
break;
default: break;
}
}
}
MenuWindow::MenuWindow()
: m_pos(RATIO_2(Vec2f(20, 25)))
, m_size(RATIO_2(Vec2f(321, 430)))
, m_initalOffsetX(-m_size.x)
, m_fadeDistance(m_size.x + m_pos.x)
, fAngle(0.f)
, m_currentPage(NULL)
, m_background(TextureContainer::LoadUI("graph/interface/menus/menu_console_background"))
, m_border(TextureContainer::LoadUI("graph/interface/menus/menu_console_background_border"))
{ }
MenuWindow::~MenuWindow() {
for(std::vector<MenuPage *>::iterator it = m_pages.begin(), it_end = m_pages.end(); it < it_end; ++it) {
delete *it;
}
}
void MenuWindow::add(MenuPage * page) {
page->setSize(RATIO_2(Vec2f(292, 395)));
m_pages.push_back(page);
}
void MenuWindow::update() {
m_pos.x = m_initalOffsetX + (m_fadeDistance * glm::sin(glm::radians(fAngle)));
fAngle = std::min(fAngle + g_platformTime.lastFrameDuration() / PlatformDurationMsf(12.5f), 90.f);
if(m_currentPage) {
m_currentPage->update(m_pos + Vec2f(RATIO_X(14.5f), RATIO_Y(12.f)));
}
}
void MenuWindow::render() {
if(!m_currentPage) {
return;
}
// Draw background and border
{
UseRenderState state(render2D().blend(BlendZero, BlendInvSrcColor));
EERIEDrawBitmap(Rectf(m_pos, RATIO_X(m_background->m_size.x), RATIO_Y(m_background->m_size.y)),
0, m_background, Color::white);
}
EERIEDrawBitmap(Rectf(m_pos, RATIO_X(m_border->m_size.x), RATIO_Y(m_border->m_size.y)),
0, m_border, Color::white);
m_currentPage->render();
if(g_debugInfo == InfoPanelGuiDebug) {
m_currentPage->drawDebug();
}
}
void MenuWindow::setCurrentPage(MENUSTATE id) {
if(currentPageId() == id) {
return;
}
if(m_currentPage) {
m_currentPage->unfocus();
}
m_currentPage = getPage(id);
if(m_currentPage) {
m_currentPage->focus();
}
}
MenuPage * MenuWindow::getPage(MENUSTATE id) const {
BOOST_FOREACH(MenuPage * page, m_pages) {
if(page->id() == id) {
return page;
}
}
return NULL;
}
void Menu2_Close() {
delete g_mainMenu, g_mainMenu = NULL;
delete pMenuCursor, pMenuCursor = NULL;
}
void MenuReInitAll() {
if(!g_mainMenu) {
return;
}
g_mainMenu->bReInitAll = true;
}