forked from EasyRPG/Player
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscene_title.cpp
More file actions
347 lines (292 loc) · 10 KB
/
scene_title.cpp
File metadata and controls
347 lines (292 loc) · 10 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
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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
/*
* This file is part of EasyRPG Player.
*
* EasyRPG Player 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.
*
* EasyRPG Player 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 EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/
// Headers
#include <fstream>
#include <sstream>
#include <vector>
#include "scene_title.h"
#include "audio.h"
#include "audio_secache.h"
#include "cache.h"
#include "game_battle.h"
#include "game_screen.h"
#include "game_system.h"
#include "transition.h"
#include "input.h"
#include "main_data.h"
#include "meta.h"
#include "output.h"
#include "player.h"
#include "translation.h"
#include "scene_battle.h"
#include "scene_import.h"
#include "scene_load.h"
#include "window_command.h"
#include "baseui.h"
#include <lcf/reader_util.h>
Scene_Title::Scene_Title() {
type = Scene::Title;
}
void Scene_Title::Start() {
Main_Data::game_system->ResetSystemGraphic();
// Skip background image and music if not used
if (CheckEnableTitleGraphicAndMusic()) {
CreateTitleGraphic();
PlayTitleMusic();
}
CreateCommandWindow();
CreateTranslationWindow();
CreateHelpWindow();
}
void Scene_Title::CreateHelpWindow() {
help_window.reset(new Window_Help(0, 0, SCREEN_TARGET_WIDTH, 32));
help_window->SetVisible(false);
translate_window->SetHelpWindow(help_window.get());
}
void Scene_Title::Continue(SceneType prev_scene) {
Main_Data::game_system->ResetSystemGraphic();
if (restart_title_cache) {
// Clear the cache when the game returns to the title screen
// e.g. by pressing F12, except the Title Load menu
Cache::Clear();
AudioSeCache::Clear();
Player::ResetGameObjects();
Start();
} else if (CheckEnableTitleGraphicAndMusic()) {
CreateTitleGraphic();
}
if (prev_scene != Scene::Load && !Player::hide_title_flag) {
command_window->SetOpenAnimation(8);
}
}
void Scene_Title::TransitionIn(SceneType prev_scene) {
if (Game_Battle::battle_test.enabled || !lcf::Data::system.show_title || Player::new_game_flag)
return;
if (prev_scene == Scene::Load || Player::hide_title_flag) {
Scene::TransitionIn(prev_scene);
return;
}
Transition::instance().InitShow(Transition::TransitionFadeIn, this);
}
void Scene_Title::TransitionOut(Scene::SceneType next_scene) {
Scene::TransitionOut(next_scene);
// Unload title graphic to save memory
title.reset();
}
void Scene_Title::Update() {
if (Game_Battle::battle_test.enabled) {
Player::SetupBattleTest();
return;
}
if (!lcf::Data::system.show_title || Player::new_game_flag) {
Player::SetupNewGame();
if (Player::debug_flag && Player::hide_title_flag) {
Scene::Push(std::make_shared<Scene_Load>());
}
return;
}
if (active_window == 0) {
command_window->Update();
} else {
translate_window->Update();
}
if (Input::IsTriggered(Input::DECISION)) {
if (active_window == 0) {
int index = command_window->GetIndex();
if (index == indices.new_game) { // New Game
CommandNewGame();
} else if (index == indices.continue_game) { // Load Game
CommandContinue();
} else if (index == indices.import) { // Import (multi-part games)
CommandImport();
} else if (index == indices.translate) { // Choose a Translation (Language)
CommandTranslation();
} else if (index == indices.exit) { // Exit Game
CommandShutdown();
}
} else if (active_window == 1) {
int index = translate_window->GetIndex();
ChangeLanguage(lang_dirs.at(index));
}
} else if (Input::IsTriggered(Input::CANCEL)) {
if (active_window == 1) {
// Switch back
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Cancel));
HideTranslationWindow();
}
}
}
void Scene_Title::CreateTitleGraphic() {
// Load Title Graphic
if (!lcf::Data::system.title_name.empty()) {
title.reset(new Sprite());
FileRequestAsync* request = AsyncHandler::RequestFile("Title", lcf::Data::system.title_name);
request->SetGraphicFile(true);
request_id = request->Bind(&Scene_Title::OnTitleSpriteReady, this);
request->Start();
} else {
title.reset(new Sprite());
title->SetBitmap(Bitmap::Create(DisplayUi->GetWidth(), DisplayUi->GetHeight(), Color(0, 0, 0, 255)));
}
}
void Scene_Title::RepositionWindow(Window_Command& window, bool center_vertical) {
if (!center_vertical) {
window.SetX(SCREEN_TARGET_WIDTH / 2 - window.GetWidth() / 2);
window.SetY(SCREEN_TARGET_HEIGHT * 53 / 60 - window.GetHeight());
} else {
window.SetX(SCREEN_TARGET_WIDTH / 2 - window.GetWidth() / 2);
window.SetY(SCREEN_TARGET_HEIGHT / 2 - window.GetHeight() / 2);
}
}
void Scene_Title::CreateCommandWindow() {
// Create Options Window
std::vector<std::string> options;
options.push_back(ToString(lcf::Data::terms.new_game));
options.push_back(ToString(lcf::Data::terms.load_game));
// Reset index to fix issues on reuse.
indices = CommandIndices();
// Set "Import" based on metadata
if (Player::meta->IsImportEnabled()) {
options.push_back(Player::meta->GetExVocabImportSaveTitleText());
indices.import = indices.exit;
indices.exit++;
}
// Set "Translate" based on metadata
if (Player::translation.HasTranslations()) {
options.push_back(Player::meta->GetExVocabTranslateTitleText());
indices.translate = indices.exit;
indices.exit++;
}
options.push_back(ToString(lcf::Data::terms.exit_game));
command_window.reset(new Window_Command(options));
RepositionWindow(*command_window, Player::hide_title_flag);
// Enable load game if available
continue_enabled = FileFinder::HasSavegame();
if (continue_enabled) {
command_window->SetIndex(1);
} else {
command_window->DisableItem(1);
}
// Set the number of frames for the opening animation to last
if (!Player::hide_title_flag) {
command_window->SetOpenAnimation(8);
}
if (Player::IsRPG2k3E() && lcf::Data::battlecommands.transparency == lcf::rpg::BattleCommands::Transparency_transparent) {
command_window->SetBackOpacity(128);
}
command_window->SetVisible(true);
}
void Scene_Title::CreateTranslationWindow() {
// Build a list of 'Default' and all known languages.
std::vector<std::string> lang_names;
lang_names.push_back("Default Language");
lang_dirs.push_back("");
lang_helps.push_back("Play the game in its original language.");
// Push menu entries with the display name, but also save the directory location and help text.
for (const Language& lg : Player::translation.GetLanguages()) {
lang_names.push_back(lg.lang_name);
lang_dirs.push_back(lg.lang_dir);
lang_helps.push_back(lg.lang_desc);
}
translate_window.reset(new Window_Command(lang_names));
translate_window->UpdateHelpFn = [this](Window_Help& win, int index) {
if (index>=0 && index<lang_helps.size()) {
win.SetText(lang_helps[index]);
} else {
win.SetText("");
}
};
RepositionWindow(*translate_window, Player::hide_title_flag);
if (Player::IsRPG2k3E() && lcf::Data::battlecommands.transparency == lcf::rpg::BattleCommands::Transparency_transparent) {
translate_window->SetBackOpacity(128);
}
translate_window->SetVisible(false);
}
void Scene_Title::PlayTitleMusic() {
// Workaround Android problem: BGM doesn't start when game is started again
Main_Data::game_system->BgmStop();
// Play BGM
Main_Data::game_system->BgmPlay(lcf::Data::system.title_music);
}
bool Scene_Title::CheckEnableTitleGraphicAndMusic() {
return lcf::Data::system.show_title &&
!Player::new_game_flag &&
!Game_Battle::battle_test.enabled &&
!Player::hide_title_flag;
}
bool Scene_Title::CheckValidPlayerLocation() {
return (lcf::Data::treemap.start.party_map_id > 0);
}
void Scene_Title::CommandNewGame() {
if (!CheckValidPlayerLocation()) {
Output::Warning("The game has no start location set.");
} else {
Output::Debug("Starting new game");
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Decision));
Player::SetupNewGame();
}
}
void Scene_Title::CommandContinue() {
if (continue_enabled) {
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Decision));
} else {
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Buzzer));
return;
}
Scene::Push(std::make_shared<Scene_Load>());
}
void Scene_Title::CommandImport() {
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Decision));
Scene::Push(std::make_shared<Scene_Import>());
}
void Scene_Title::CommandTranslation() {
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Decision));
// Switch windows
active_window = 1;
command_window->SetVisible(false);
translate_window->SetVisible(true);
help_window->SetVisible(true);
}
void Scene_Title::ChangeLanguage(const std::string& lang_str) {
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Decision));
// No-op?
if (lang_str == Player::translation.GetCurrentLanguageId()) {
HideTranslationWindow();
return;
}
// First change the language
Player::translation.SelectLanguage(lang_str);
// Now reset the scene (force asset reload)
Scene::Push(std::make_shared<Scene_Title>(), true);
}
void Scene_Title::HideTranslationWindow() {
active_window = 0;
command_window->SetVisible(true);
translate_window->SetVisible(false);
help_window->SetVisible(false);
}
void Scene_Title::CommandShutdown() {
Main_Data::game_system->SePlay(Main_Data::game_system->GetSystemSE(Main_Data::game_system->SFX_Decision));
Transition::instance().InitErase(Transition::TransitionFadeOut, this);
Scene::Pop();
}
void Scene_Title::OnTitleSpriteReady(FileRequestResult* result) {
title->SetBitmap(Cache::Title(result->file));
}
void Scene_Title::OnGameStart() {
restart_title_cache = true;
}