1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (C) 2004-2010 by The Allacrost Project
3 // All Rights Reserved
4 //
5 // This code is licensed under the GNU GPL version 2. It is free software
6 // and you may modify it and/or redistribute it under the terms of this license.
7 // See http://www.gnu.org/copyleft/gpl.html for details.
8 ///////////////////////////////////////////////////////////////////////////////
9
10 /** ****************************************************************************
11 *** \file boot.cpp
12 *** \author Viljami Korhonen, mindflayer@allacrost.org
13 *** \brief Source file for boot mode interface.
14 *** ***************************************************************************/
15
16 #include <iostream>
17 #include <sstream>
18
19 #include "audio.h"
20 #include "script.h"
21 #include "input.h"
22 #include "system.h"
23
24 #include "global.h"
25
26 #include "boot.h"
27 #include "boot_credits.h"
28 #include "boot_welcome.h"
29
30 #include "map.h"
31 #include "save_mode.h"
32 // Files below are included temporarily, used for boot mode to do a test launch of other modes
33 #include "battle.h"
34 #include "menu.h"
35 #include "shop.h"
36
37 using namespace std;
38 using namespace hoa_utils;
39
40 using namespace hoa_audio;
41 using namespace hoa_video;
42 using namespace hoa_gui;
43 using namespace hoa_input;
44 using namespace hoa_mode_manager;
45 using namespace hoa_script;
46 using namespace hoa_system;
47
48 using namespace hoa_global;
49
50 using namespace hoa_boot::private_boot;
51
52 namespace hoa_boot {
53
54 bool BOOT_DEBUG = false;
55
56 // A temporary hack to boot mode used to make it possible to enter battle mode, menu mode, and
57 // shop mode from the main boot menu. Set this member to true to enable those options or false
58 // to disable them. Make sure to set this boolean to false for release builds!
59 bool TEMP_BOOT_TEST = false;
60
61 // Initialize static members here
62 bool BootMode::_initial_entry = true;
63 BootMode* BootMode::_current_instance = NULL;
64
65 // ****************************************************************************
66 // ***** BootMode public methods
67 // ****************************************************************************
68
BootMode()69 BootMode::BootMode() :
70 _fade_out(false),
71 _has_modified_settings(false),
72 _key_setting_function(NULL),
73 _joy_setting_function(NULL),
74 _joy_axis_setting_function(NULL),
75 _overwrite_function(NULL),
76 _message_window(ustring(), 210.0f, 35.0f),
77 _file_name_alert(ustring(),300.0f,35.0f),
78 _file_name_window(ustring(),150.0f,35.0f)
79 {
80 IF_PRINT_DEBUG(BOOT_DEBUG) << "BootMode constructor invoked" << endl;
81 mode_type = MODE_MANAGER_BOOT_MODE;
82
83 _credits_window = new CreditsWindow();
84 _welcome_window = new WelcomeWindow();
85
86 _version_text.SetStyle(TextStyle("text20"));
87 _version_text.SetText(UTranslate("Demo 1.0.0"));
88 _copyright_text.SetStyle(TextStyle("text20"));
89 _copyright_text.SetText(UTranslate("© 2004 — 2010 The Allacrost Project"));
90
91 ReadScriptDescriptor read_data;
92 if (!read_data.OpenFile("dat/config/boot.lua")) {
93 PRINT_ERROR << "failed to load boot data file" << endl;
94 }
95
96 // Load all bitmaps using this StillImage
97 StillImage im;
98 bool success = true;
99
100 success &= im.Load(read_data.ReadString("background_image"), read_data.ReadFloat("background_image_width"), read_data.ReadFloat("background_image_height"));
101 _boot_images.push_back(im);
102
103 success &= im.Load(read_data.ReadString("logo_background"), read_data.ReadFloat("logo_background_width"), read_data.ReadFloat("logo_background_height"));
104 _boot_images.push_back(im);
105
106 success &= im.Load(read_data.ReadString("logo_sword"), read_data.ReadFloat("logo_sword_width"), read_data.ReadFloat("logo_sword_height"));
107 _boot_images.push_back(im);
108
109 success &= im.Load(read_data.ReadString("logo_text"), read_data.ReadFloat("logo_text_width"), read_data.ReadFloat("logo_text_height"));
110 _boot_images.push_back(im);
111
112 if (success == false) {
113 PRINT_ERROR << "failed to load one or more boot images" << endl;
114 }
115
116 // Load audio data
117 vector<string> new_music_files;
118 vector<string> new_sound_files;
119 read_data.ReadStringVector("music_files", new_music_files);
120 read_data.ReadStringVector("sound_files", new_sound_files);
121 if (read_data.IsErrorDetected()) {
122 PRINT_ERROR << "an error occured during reading of the boot data file" << endl;
123 PRINT_ERROR << read_data.GetErrorMessages() << endl;
124 }
125 read_data.CloseFile();
126
127 _boot_music.resize(new_music_files.size(), MusicDescriptor());
128 for (uint32 i = 0; i < new_music_files.size(); i++) {
129 if (_boot_music[i].LoadAudio(new_music_files[i]) == false) {
130 PRINT_ERROR << "failed to load music file: " << new_music_files[i] << endl;
131 SystemManager->ExitGame();
132 return;
133 }
134 }
135
136 _boot_sounds.resize(new_sound_files.size(), SoundDescriptor());
137 for (uint32 i = 0; i < new_sound_files.size(); i++) {
138 if (_boot_sounds[i].LoadAudio(new_sound_files[i]) == false) {
139 PRINT_ERROR << "failed to load sound file: " << new_sound_files[i] << endl;
140 SystemManager->ExitGame();
141 return;
142 }
143 }
144
145 _options_window.Create(300.0f, 550.0f);
146 _options_window.SetPosition(360.0f, 580.0f);
147 _options_window.SetDisplayMode(VIDEO_MENU_INSTANT);
148 _options_window.Hide();
149
150 /*
151 if (!_is_windowed) // without a window
152 {
153 _active_menu.SetTextStyle(TextStyle("title22"));
154 // _active_menu.SetCellSize(150.0f, 70.0f);
155 _active_menu.SetPosition(552.0f, 50.0f);
156 _active_menu.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
157 _active_menu.SetOptionAlignment(VIDEO_X_LEFT, VIDEO_Y_CENTER);
158 _active_menu.SetSelectMode(VIDEO_SELECT_SINGLE);
159 _active_menu.SetHorizontalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
160 _active_menu.SetCursorOffset(-50.0f, 28.0f);
161 // _active_menu.SetSize(_active_menu.GetNumberOptions(), 1);
162 }
163 else // windowed
164 {
165 _active_menu.SetTextStyle(TextStyle("title22"));
166 // _active_menu.SetCellSize(210.0f, 50.0f);
167 _active_menu.SetPosition(150.0f, 200.0f);
168 _active_menu.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
169 _active_menu.SetOptionAlignment(VIDEO_X_LEFT, VIDEO_Y_CENTER);
170 _active_menu.SetSelectMode(VIDEO_SELECT_SINGLE);
171 _active_menu.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
172 _active_menu.SetCursorOffset(-50.0f, 28.0f);
173 // _active_menu.SetSize(1, _active_menu.GetNumberOptions());
174 _active_menu.SetOwner(_options_window);
175 }
176 */
177
178 // Setup all boot menu options and properties
179 _SetupMainMenu();
180 _SetupOptionsMenu();
181 _SetupVideoOptionsMenu();
182 _SetupAudioOptionsMenu();
183 _SetupLanguageOptionsMenu();
184 _SetupKeySetttingsMenu();
185 _SetupJoySetttingsMenu();
186 _SetupResolutionMenu();
187 _SetupProfileMenu();
188 _SetupLoadProfileMenu();
189 _SetupSaveProfileMenu();
190 _SetupDeleteProfileMenu();
191 _SetupUserInputMenu();
192 _active_menu = &_main_menu;
193
194 // make sure message window is not visible
195 _message_window.Hide();
196 _file_name_alert.Hide();
197 _file_name_window.Hide();
198 } // BootMode::BootMode()
199
200
201
~BootMode()202 BootMode::~BootMode() {
203 delete _credits_window;
204 delete _welcome_window;
205
206 _options_window.Destroy();
207 _SaveSettingsFile("");
208
209 if (BOOT_DEBUG) cout << "BOOT: BootMode destructor invoked." << endl;
210
211 for (uint32 i = 0; i < _boot_music.size(); i++)
212 _boot_music[i].FreeAudio();
213
214 for (uint32 i = 0; i < _boot_sounds.size(); i++)
215 _boot_sounds[i].FreeAudio();
216
217 _key_setting_function = NULL;
218 _joy_setting_function = NULL;
219 _joy_axis_setting_function = NULL;
220 _overwrite_function = NULL;
221 }
222
223
224
Reset()225 void BootMode::Reset() {
226 // Set the coordinate system that BootMode uses
227 VideoManager->SetCoordSys(0.0f, 1023.0f, 0.0f, 767.0f);
228 VideoManager->SetDrawFlags(VIDEO_X_CENTER, VIDEO_Y_CENTER, 0);
229
230 GlobalManager->ClearAllData(); // Resets the game universe to a NULL state
231 _current_instance = this;
232
233 // Decide which music track to play
234 if (_initial_entry == true)
235 _boot_music.at(1).Play(); // Opening Effect
236 else
237 _boot_music.at(0).Play(); // Main theme
238 }
239
240
241
Update()242 void BootMode::Update() {
243 _options_window.Update(SystemManager->GetUpdateTime());
244 if (InputManager->QuitPress() == true) {
245 SystemManager->ExitGame();
246 return;
247 }
248
249 // Screen is in the process of fading out
250 if (_fade_out)
251 {
252 // When the screen is finished fading to black, create a new map mode and fade back in
253 if (!VideoManager->IsFading()) {
254 ModeManager->Pop();
255 try {
256 hoa_map::MapMode *MM = new hoa_map::MapMode(MakeStandardString(GlobalManager->GetLocationName()));
257 ModeManager->Push(MM);
258 } catch (luabind::error e) {
259 PRINT_ERROR << "Map::_Load -- Error loading map " << MakeStandardString(GlobalManager->GetLocationName()) << ", returning to BootMode." << endl;
260 cerr << "Exception message:" << endl;
261 ScriptManager->HandleLuaError(e);
262 }
263 VideoManager->FadeScreen(Color::clear, 1000);
264 }
265 return;
266 }
267 else if (_initial_entry) // We're animating the opening logo
268 {
269 if (InputManager->AnyKeyPress()) // Check if we want to skip the demo
270 {
271 _EndLogoAnimation();
272 return;
273 }
274 else
275 {
276 return; // Otherwise skip rest of the event handling for now
277 }
278 }
279
280 // Update the credits window (because it may be hiding/showing!)
281 _credits_window->Update();
282
283 //CD: Handle key press here, just like any other time
284 if (_welcome_window->IsActive())
285 {
286 if (InputManager->AnyKeyPress())
287 {
288 _boot_sounds.at(0).Play();
289 _welcome_window->Hide();
290
291 // save the settings (automatically changes the welcome variable to 0
292 _has_modified_settings = true;
293 _SaveSettingsFile("");
294 }
295
296 return;
297 }
298
299 // Check for waiting keypresses or joystick button presses
300 SDL_Event ev = InputManager->GetMostRecentEvent();
301 if (_joy_setting_function != NULL)
302 {
303 if (InputManager->AnyKeyPress() && ev.type == SDL_JOYBUTTONDOWN)
304 {
305 (this->*_joy_setting_function)(InputManager->GetMostRecentEvent().jbutton.button);
306 _joy_setting_function = NULL;
307 _has_modified_settings = true;
308 _RefreshJoySettings();
309 _message_window.Hide();
310 }
311 if (InputManager->CancelPress())
312 {
313 _joy_setting_function = NULL;
314 _message_window.Hide();
315 }
316 return;
317 }
318
319 if (_joy_axis_setting_function != NULL)
320 {
321 int8 x = InputManager->GetLastAxisMoved();
322 if (x != -1)
323 {
324 (this->*_joy_axis_setting_function)(x);
325 _joy_axis_setting_function = NULL;
326 _has_modified_settings = true;
327 _RefreshJoySettings();
328 _message_window.Hide();
329 }
330 if (InputManager->CancelPress())
331 {
332 _joy_axis_setting_function = NULL;
333 _message_window.Hide();
334 }
335 return;
336 }
337
338 if (_key_setting_function != NULL)
339 {
340 if (InputManager->AnyKeyPress() && ev.type == SDL_KEYDOWN)
341 {
342 (this->*_key_setting_function)(InputManager->GetMostRecentEvent().key.keysym.sym);
343 _key_setting_function = NULL;
344 _has_modified_settings = true;
345 _RefreshKeySettings();
346 _message_window.Hide();
347 }
348 if (InputManager->CancelPress())
349 {
350 _key_setting_function = NULL;
351 _message_window.Hide();
352 }
353 return;
354 }
355
356 if(_overwrite_function != NULL)
357 {
358 if(InputManager->ConfirmPress())
359 {
360 (this->*_overwrite_function)();
361 _overwrite_function = NULL;
362 _file_name_alert.Hide();
363 }
364 else if(InputManager->CancelPress())
365 {
366 _overwrite_function = NULL;
367 _file_name_alert.Hide();
368 }
369 //dont want to execute the confirm command on my menu selection for a second time!
370 return;
371 }
372
373 _active_menu->Update();
374
375 // A confirm-key was pressed -> handle it (but ONLY if the credits screen isn't visible)
376 if (InputManager->ConfirmPress() && !_credits_window->IsActive())
377 {
378 // Play 'confirm sound' if the selection isn't grayed out and it has a confirm handler
379 if (_active_menu->IsEnabled(_active_menu->GetSelection()))
380 _boot_sounds.at(0).Play();
381 else
382 _boot_sounds.at(3).Play(); // Otherwise play a different sound
383
384 _active_menu->InputConfirm();
385
386 }
387 else if (InputManager->LeftPress() && !_credits_window->IsActive())
388 {
389 _active_menu->InputLeft();
390 }
391 else if(InputManager->RightPress() && !_credits_window->IsActive())
392 {
393 _active_menu->InputRight();
394 }
395 else if(InputManager->UpPress() && !_credits_window->IsActive())
396 {
397 _active_menu->InputUp();
398 }
399 else if(InputManager->DownPress() && !_credits_window->IsActive())
400 {
401 _active_menu->InputDown();
402 }
403 else if(InputManager->CancelPress())
404 {
405 // Close the credits-screen if it was visible
406 if (_credits_window->IsActive())
407 {
408 _credits_window->Hide();
409 _boot_sounds.at(1).Play(); // Play cancel sound here as well
410 }
411 else if (_active_menu == &_main_menu) {
412
413 }
414 else if (_active_menu == &_options_menu) {
415 _options_window.Hide();
416 _active_menu = &_main_menu;
417 }
418 else if (_active_menu == &_video_options_menu) {
419 _active_menu = &_options_menu;
420 }
421 else if (_active_menu == &_audio_options_menu) {
422 _active_menu = &_options_menu;
423 }
424 else if (_active_menu == &_language_options_menu) {
425 _active_menu = &_options_menu;
426 }
427 else if (_active_menu == &_key_settings_menu) {
428 _active_menu = &_options_menu;
429 }
430 else if (_active_menu == &_joy_settings_menu) {
431 _active_menu = &_options_menu;
432 }
433 else if (_active_menu == &_resolution_menu) {
434 _active_menu = &_video_options_menu;
435 }
436 else if (_active_menu == &_profiles_menu) {
437 _active_menu = &_options_menu;
438 }
439 else if (_active_menu == &_load_profile_menu){
440 _active_menu = &_profiles_menu;
441 }
442 else if (_active_menu == &_save_profile_menu){
443 _active_menu = &_profiles_menu;
444 }
445 else if (_active_menu == &_delete_profile_menu){
446 _active_menu = &_profiles_menu;
447 }
448 else if(_active_menu == &_user_input_menu) {
449 _file_name_window.Hide();
450 _file_name_alert.Hide();
451 _active_menu = &_save_profile_menu;
452 }
453 // Play cancel sound
454 _boot_sounds.at(1).Play();
455 }
456
457 // Update menu events
458 // _active_menu->GetEvent();
459 } // void BootMode::Update()
460
461
462
Draw()463 void BootMode::Draw() {
464 VideoManager->SetDrawFlags(VIDEO_X_CENTER, VIDEO_Y_CENTER, 0);
465
466 // If we're animating logo at the moment, handle all drawing in there and simply return
467 if (_initial_entry) {
468 _AnimateLogo();
469 return;
470 }
471
472 _DrawBackgroundItems();
473
474 _options_window.Draw();
475
476 // Decide whether to draw the credits window, welcome window or the main menu
477 if (_credits_window->IsActive())
478 _credits_window->Draw();
479 else if (_welcome_window->IsActive())
480 _welcome_window->Draw();
481 else if (_active_menu != NULL)
482 _active_menu->Draw();
483
484 VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_BOTTOM, 0);
485 VideoManager->Move(10.0f, 10.0f);
486 _version_text.Draw();
487 VideoManager->SetDrawFlags(VIDEO_X_RIGHT, VIDEO_Y_BOTTOM, 0);
488 VideoManager->Move(1013.0f, 10.0f);
489 _copyright_text.Draw();
490
491 // VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_TOP, 0);
492 VideoManager->Move(0.0f, 0.0f);
493 _message_window.Draw();
494 _file_name_alert.Draw();
495 _file_name_window.Draw();
496 }
497
498 // ****************************************************************************
499 // ***** BootMode menu setup and refresh methods
500 // ****************************************************************************
501
_SetupMainMenu()502 void BootMode::_SetupMainMenu() {
503 if (TEMP_BOOT_TEST == true) {
504 _main_menu.SetPosition(512.0f, 80.0f);
505 _main_menu.SetDimensions(1000.0f, 50.0f, 8, 1, 8, 1);
506 _main_menu.SetTextStyle(TextStyle("title24"));
507 _main_menu.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
508 _main_menu.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
509 _main_menu.SetSelectMode(VIDEO_SELECT_SINGLE);
510 _main_menu.SetHorizontalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
511 _main_menu.SetCursorOffset(-50.0f, 28.0f);
512
513 // Add all the needed menu options to the main menu
514 _main_menu.AddOption(UTranslate("New Game"), &BootMode::_OnNewGame);
515 _main_menu.AddOption(UTranslate("Load Game"), &BootMode::_OnLoadGame);
516 _main_menu.AddOption(UTranslate("Options"), &BootMode::_OnOptions);
517 _main_menu.AddOption(UTranslate("Credits"), &BootMode::_OnCredits);
518 _main_menu.AddOption(UTranslate("Battle"), &BootMode::_TEMP_OnBattle);
519 _main_menu.AddOption(UTranslate("Menu"), &BootMode::_TEMP_OnMenu);
520 _main_menu.AddOption(UTranslate("Shop"), &BootMode::_TEMP_OnShop);
521 _main_menu.AddOption(UTranslate("Quit"), &BootMode::_OnQuit);
522 }
523 else {
524 _main_menu.SetPosition(512.0f, 80.0f);
525 _main_menu.SetDimensions(800.0f, 50.0f, 5, 1, 5, 1);
526 _main_menu.SetTextStyle(TextStyle("title24"));
527 _main_menu.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
528 _main_menu.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
529 _main_menu.SetSelectMode(VIDEO_SELECT_SINGLE);
530 _main_menu.SetHorizontalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
531 _main_menu.SetCursorOffset(-50.0f, 28.0f);
532
533 // Add all the needed menu options to the main menu
534 _main_menu.AddOption(UTranslate("New Game"), &BootMode::_OnNewGame);
535 _main_menu.AddOption(UTranslate("Load Game"), &BootMode::_OnLoadGame);
536 _main_menu.AddOption(UTranslate("Options"), &BootMode::_OnOptions);
537 _main_menu.AddOption(UTranslate("Credits"), &BootMode::_OnCredits);
538 _main_menu.AddOption(UTranslate("Quit"), &BootMode::_OnQuit);
539 }
540
541 string path = GetUserDataPath(true) + "saved_game_1.lua";
542 if (DoesFileExist(path) == false) {
543 _main_menu.EnableOption(1, false);
544 _main_menu.SetSelection(0);
545 }
546 else {
547 _main_menu.SetSelection(1);
548 }
549 }
550
551
552
_SetupOptionsMenu()553 void BootMode::_SetupOptionsMenu() {
554 _options_menu.SetPosition(512.0f, 300.0f);
555 _options_menu.SetDimensions(300.0f, 600.0f, 1, 6, 1, 6);
556 _options_menu.SetTextStyle(TextStyle("title22"));
557 _options_menu.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
558 _options_menu.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
559 _options_menu.SetSelectMode(VIDEO_SELECT_SINGLE);
560 _options_menu.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
561 _options_menu.SetCursorOffset(-50.0f, 28.0f);
562
563 _options_menu.AddOption(UTranslate("Video"), &BootMode::_OnVideoOptions);
564 _options_menu.AddOption(UTranslate("Audio"), &BootMode::_OnAudioOptions);
565 _options_menu.AddOption(UTranslate("Language"), &BootMode::_OnLanguageOptions);
566 _options_menu.AddOption(UTranslate("Key Settings"), &BootMode::_OnKeySettings);
567 _options_menu.AddOption(UTranslate("Joystick Settings"), &BootMode::_OnJoySettings);
568 _options_menu.AddOption(UTranslate("Profiles"), &BootMode::_OnProfiles);
569
570 _options_menu.SetSelection(0);
571 }
572
573
574
_SetupVideoOptionsMenu()575 void BootMode::_SetupVideoOptionsMenu() {
576 _video_options_menu.SetPosition(512.0f, 300.0f);
577 _video_options_menu.SetDimensions(300.0f, 400.0f, 1, 4, 1, 4);
578 _video_options_menu.SetTextStyle(TextStyle("title22"));
579 _video_options_menu.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
580 _video_options_menu.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
581 _video_options_menu.SetSelectMode(VIDEO_SELECT_SINGLE);
582 _video_options_menu.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
583 _video_options_menu.SetCursorOffset(-50.0f, 28.0f);
584
585 _video_options_menu.AddOption(UTranslate("Resolution:"), &BootMode::_OnResolution);
586 // Left & right will change window mode as well as confirm
587 _video_options_menu.AddOption(UTranslate("Window mode:"), &BootMode::_OnToggleFullscreen, NULL, NULL, &BootMode::_OnToggleFullscreen, &BootMode::_OnToggleFullscreen);
588 _video_options_menu.AddOption(UTranslate("Brightness:"), NULL, NULL, NULL, &BootMode::_OnBrightnessLeft, &BootMode::_OnBrightnessRight);
589 _video_options_menu.AddOption(UTranslate("Image quality:"));
590
591 _video_options_menu.EnableOption(3, false); // Disable image quality
592
593 _video_options_menu.SetSelection(0);
594 }
595
596
597
_SetupAudioOptionsMenu()598 void BootMode::_SetupAudioOptionsMenu() {
599 _audio_options_menu.SetPosition(512.0f, 300.0f);
600 _audio_options_menu.SetDimensions(300.0f, 200.0f, 1, 2, 1, 2);
601 _audio_options_menu.SetTextStyle(TextStyle("title22"));
602 _audio_options_menu.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
603 _audio_options_menu.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
604 _audio_options_menu.SetSelectMode(VIDEO_SELECT_SINGLE);
605 _audio_options_menu.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
606 _audio_options_menu.SetCursorOffset(-50.0f, 28.0f);
607
608 _audio_options_menu.AddOption(UTranslate("Sound Volume: "), NULL, NULL, NULL, &BootMode::_OnSoundLeft, &BootMode::_OnSoundRight);
609 _audio_options_menu.AddOption(UTranslate("Music Volume: "), NULL, NULL, NULL, &BootMode::_OnMusicLeft, &BootMode::_OnMusicRight);
610
611 _audio_options_menu.SetSelection(0);
612 }
613
614
615
_SetupLanguageOptionsMenu()616 void BootMode::_SetupLanguageOptionsMenu() {
617 _language_options_menu.SetPosition(512.0f, 300.0f);
618 _language_options_menu.SetTextStyle(TextStyle("title22"));
619 _language_options_menu.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
620 _language_options_menu.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
621 _language_options_menu.SetSelectMode(VIDEO_SELECT_SINGLE);
622 _language_options_menu.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
623 _language_options_menu.SetCursorOffset(-50.0f, 28.0f);
624
625
626 // Get the list of languages from the Lua file.
627 ReadScriptDescriptor read_data;
628 if (!read_data.OpenFile(_LANGUAGE_FILE)) {
629 PRINT_ERROR << "Failed to load language file: " << _LANGUAGE_FILE << endl;
630 PRINT_ERROR << "The language list will be empty." << endl;
631 return;
632 }
633
634 read_data.OpenTable("languages");
635 uint32 table_size = read_data.GetTableSize();
636
637 // Set up the dimensions of the window according to how many languages are available.
638 _language_options_menu.SetDimensions(300.0f, 200.0f, 1, table_size, 1, table_size);
639
640 _po_files.clear();
641 for (uint32 i = 1; i <= table_size; i++) {
642 read_data.OpenTable(i);
643 _po_files.push_back(read_data.ReadString(2));
644 _language_options_menu.AddOption(MakeUnicodeString(read_data.ReadString(1)),
645 &BootMode::_OnLanguageSelect);
646 read_data.CloseTable();
647 }
648
649 read_data.CloseTable();
650 if (read_data.IsErrorDetected())
651 PRINT_ERROR << "Error occurred while loading language list: " << read_data.GetErrorMessages() << endl;
652 read_data.CloseFile();
653 }
654
655
656
_SetupKeySetttingsMenu()657 void BootMode::_SetupKeySetttingsMenu() {
658 _key_settings_menu.SetPosition(512.0f, 300.0f);
659 _key_settings_menu.SetDimensions(300.0f, 500.0f, 1, 11, 1, 11);
660 _key_settings_menu.SetTextStyle(TextStyle("title22"));
661 _key_settings_menu.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
662 _key_settings_menu.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
663 _key_settings_menu.SetSelectMode(VIDEO_SELECT_SINGLE);
664 _key_settings_menu.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
665 _key_settings_menu.SetCursorOffset(-50.0f, 28.0f);
666
667 _key_settings_menu.AddOption(UTranslate("Up: "), &BootMode::_RedefineUpKey);
668 _key_settings_menu.AddOption(UTranslate("Down: "), &BootMode::_RedefineDownKey);
669 _key_settings_menu.AddOption(UTranslate("Left: "), &BootMode::_RedefineLeftKey);
670 _key_settings_menu.AddOption(UTranslate("Right: "), &BootMode::_RedefineRightKey);
671 _key_settings_menu.AddOption(UTranslate("Confirm: "), &BootMode::_RedefineConfirmKey);
672 _key_settings_menu.AddOption(UTranslate("Cancel: "), &BootMode::_RedefineCancelKey);
673 _key_settings_menu.AddOption(UTranslate("Menu: "), &BootMode::_RedefineMenuKey);
674 _key_settings_menu.AddOption(UTranslate("Swap: "), &BootMode::_RedefineSwapKey);
675 _key_settings_menu.AddOption(UTranslate("Left Select: "), &BootMode::_RedefineLeftSelectKey);
676 _key_settings_menu.AddOption(UTranslate("Right Select: "), &BootMode::_RedefineRightSelectKey);
677 _key_settings_menu.AddOption(UTranslate("Pause: "), &BootMode::_RedefinePauseKey);
678 _key_settings_menu.AddOption(UTranslate("Restore defaults"), &BootMode::_OnRestoreDefaultKeys);
679 }
680
681
682
_SetupJoySetttingsMenu()683 void BootMode::_SetupJoySetttingsMenu() {
684 _joy_settings_menu.SetPosition(512.0f, 300.0f);
685 _joy_settings_menu.SetDimensions(300.0f, 500.0f, 1, 10, 1, 10);
686 _joy_settings_menu.SetTextStyle(TextStyle("title22"));
687 _joy_settings_menu.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
688 _joy_settings_menu.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
689 _joy_settings_menu.SetSelectMode(VIDEO_SELECT_SINGLE);
690 _joy_settings_menu.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
691 _joy_settings_menu.SetCursorOffset(-50.0f, 28.0f);
692
693 ustring dummy;
694 _joy_settings_menu.AddOption(dummy, &BootMode::_RedefineXAxisJoy);
695 _joy_settings_menu.AddOption(dummy, &BootMode::_RedefineYAxisJoy);
696 // _joy_settings_menu.AddOption(dummy, &BootMode::_RedefineThresholdJoy);
697
698 _joy_settings_menu.AddOption(dummy, &BootMode::_RedefineConfirmJoy);
699 _joy_settings_menu.AddOption(dummy, &BootMode::_RedefineCancelJoy);
700 _joy_settings_menu.AddOption(dummy, &BootMode::_RedefineMenuJoy);
701 _joy_settings_menu.AddOption(dummy, &BootMode::_RedefineSwapJoy);
702 _joy_settings_menu.AddOption(dummy, &BootMode::_RedefineLeftSelectJoy);
703 _joy_settings_menu.AddOption(dummy, &BootMode::_RedefineRightSelectJoy);
704 _joy_settings_menu.AddOption(dummy, &BootMode::_RedefinePauseJoy);
705 // _joy_settings_menu.AddOption(dummy, &BootMode::_RedefineQuitJoy);
706
707 _joy_settings_menu.AddOption(UTranslate("Restore defaults"), &BootMode::_OnRestoreDefaultJoyButtons);
708 }
709
710
711
_SetupResolutionMenu()712 void BootMode::_SetupResolutionMenu() {
713 _resolution_menu.SetPosition(512.0f, 300.0f);
714 _resolution_menu.SetDimensions(300.0f, 200.0f, 1, 4, 1, 4);
715 _resolution_menu.SetTextStyle(TextStyle("title22"));
716 _resolution_menu.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
717 _resolution_menu.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
718 _resolution_menu.SetSelectMode(VIDEO_SELECT_SINGLE);
719 _resolution_menu.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
720 _resolution_menu.SetCursorOffset(-50.0f, 28.0f);
721
722 _resolution_menu.AddOption(MakeUnicodeString("640 x 480"), &BootMode::_OnResolution640x480);
723 _resolution_menu.AddOption(MakeUnicodeString("800 x 600"), &BootMode::_OnResolution800x600);
724 _resolution_menu.AddOption(MakeUnicodeString("1024 x 768"), &BootMode::_OnResolution1024x768);
725 _resolution_menu.AddOption(MakeUnicodeString("1280 x 1024"), &BootMode::_OnResolution1280x1024);
726
727 if (VideoManager->GetScreenWidth() == 640)
728 _resolution_menu.SetSelection(0);
729 else if (VideoManager->GetScreenWidth() == 800)
730 _resolution_menu.SetSelection(1);
731 else if (VideoManager->GetScreenWidth() == 1024)
732 _resolution_menu.SetSelection(2);
733 else if(VideoManager->GetScreenWidth() == 1280)
734 _resolution_menu.SetSelection(3);
735 }
736
737
738
_SetupProfileMenu()739 void BootMode::_SetupProfileMenu() {
740 _profiles_menu.SetPosition(512.0f, 300.0f);
741 _profiles_menu.SetDimensions(300.0f, 300.0f, 1, 3, 1, 3);
742 _profiles_menu.SetTextStyle(TextStyle("title22"));
743 _profiles_menu.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
744 _profiles_menu.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
745 _profiles_menu.SetSelectMode(VIDEO_SELECT_SINGLE);
746 _profiles_menu.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
747 _profiles_menu.SetCursorOffset(-50.0f, 28.0f);
748
749 _profiles_menu.AddOption(UTranslate("Save"), &BootMode::_OnSaveProfile);
750 _profiles_menu.AddOption(UTranslate("Load"), &BootMode::_OnLoadProfile);
751 _profiles_menu.AddOption(UTranslate("Delete"), &BootMode::_OnDeleteProfile);
752 }
753
754
755
_SetupLoadProfileMenu()756 void BootMode::_SetupLoadProfileMenu() {
757 _load_profile_menu.SetPosition(512.0f, 300.0f);
758 _load_profile_menu.SetTextStyle(TextStyle("title22"));
759 _load_profile_menu.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
760 _load_profile_menu.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
761 _load_profile_menu.SetSelectMode(VIDEO_SELECT_SINGLE);
762 _load_profile_menu.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
763 _load_profile_menu.SetCursorOffset(-50.0f, 28.0f);
764
765 _AddProfileOptions(&_load_profile_menu);
766 }
767
768
769
_SetupSaveProfileMenu()770 void BootMode::_SetupSaveProfileMenu() {
771 _save_profile_menu.SetPosition(512.0f, 300.0f);
772 _save_profile_menu.SetTextStyle(TextStyle("title22"));
773 _save_profile_menu.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
774 _save_profile_menu.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
775 _save_profile_menu.SetSelectMode(VIDEO_SELECT_SINGLE);
776 _save_profile_menu.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
777 _save_profile_menu.SetCursorOffset(-50.0f, 28.0f);
778
779 //this option is selected when user wants to create a new file
780 _save_profile_menu.AddOption(UTranslate("New Profile"), &BootMode::_OnSaveFile);
781
782 _AddProfileOptions(&_save_profile_menu);
783 }
784
785
786
_SetupDeleteProfileMenu()787 void BootMode::_SetupDeleteProfileMenu() {
788 _delete_profile_menu.SetPosition(512.0f, 300.0f);
789 _delete_profile_menu.SetTextStyle(TextStyle("title22"));
790 _delete_profile_menu.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
791 _delete_profile_menu.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
792 _delete_profile_menu.SetSelectMode(VIDEO_SELECT_SINGLE);
793 _delete_profile_menu.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
794 _delete_profile_menu.SetCursorOffset(-50.0f, 28.0f);
795
796 _AddProfileOptions(&_delete_profile_menu);
797 }
798
799
800
_SetupUserInputMenu()801 void BootMode::_SetupUserInputMenu() {
802 _user_input_menu.SetPosition(275.0f, 475.0f);
803 _user_input_menu.SetDimensions(400.0f, 300.0f, 7, 4, 7, 4);
804 _user_input_menu.SetTextStyle(TextStyle("title22"));
805 _user_input_menu.SetAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
806 _user_input_menu.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
807 _user_input_menu.SetSelectMode(VIDEO_SELECT_SINGLE);
808 _user_input_menu.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
809 _user_input_menu.SetHorizontalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
810 _user_input_menu.SetCursorOffset(-50.0f, 28.0f);
811
812
813 //add in the letters :)
814 _user_input_menu.AddOption(MakeUnicodeString("a"), &BootMode::_OnPickLetter);
815 _user_input_menu.AddOption(MakeUnicodeString("b"), &BootMode::_OnPickLetter);
816 _user_input_menu.AddOption(MakeUnicodeString("c"), &BootMode::_OnPickLetter);
817 _user_input_menu.AddOption(MakeUnicodeString("d"), &BootMode::_OnPickLetter);
818 _user_input_menu.AddOption(MakeUnicodeString("e"), &BootMode::_OnPickLetter);
819 _user_input_menu.AddOption(MakeUnicodeString("f"), &BootMode::_OnPickLetter);
820 _user_input_menu.AddOption(MakeUnicodeString("g"), &BootMode::_OnPickLetter);
821 _user_input_menu.AddOption(MakeUnicodeString("h"), &BootMode::_OnPickLetter);
822 _user_input_menu.AddOption(MakeUnicodeString("i"), &BootMode::_OnPickLetter);
823 _user_input_menu.AddOption(MakeUnicodeString("j"), &BootMode::_OnPickLetter);
824 _user_input_menu.AddOption(MakeUnicodeString("k"), &BootMode::_OnPickLetter);
825 _user_input_menu.AddOption(MakeUnicodeString("l"), &BootMode::_OnPickLetter);
826 _user_input_menu.AddOption(MakeUnicodeString("m"), &BootMode::_OnPickLetter);
827 _user_input_menu.AddOption(MakeUnicodeString("n"), &BootMode::_OnPickLetter);
828 _user_input_menu.AddOption(MakeUnicodeString("o"), &BootMode::_OnPickLetter);
829 _user_input_menu.AddOption(MakeUnicodeString("p"), &BootMode::_OnPickLetter);
830 _user_input_menu.AddOption(MakeUnicodeString("q"), &BootMode::_OnPickLetter);
831 _user_input_menu.AddOption(MakeUnicodeString("r"), &BootMode::_OnPickLetter);
832 _user_input_menu.AddOption(MakeUnicodeString("s"), &BootMode::_OnPickLetter);
833 _user_input_menu.AddOption(MakeUnicodeString("t"), &BootMode::_OnPickLetter);
834 _user_input_menu.AddOption(MakeUnicodeString("u"), &BootMode::_OnPickLetter);
835 _user_input_menu.AddOption(MakeUnicodeString("v"), &BootMode::_OnPickLetter);
836 _user_input_menu.AddOption(MakeUnicodeString("w"), &BootMode::_OnPickLetter);
837 _user_input_menu.AddOption(MakeUnicodeString("x"), &BootMode::_OnPickLetter);
838 _user_input_menu.AddOption(MakeUnicodeString("y"), &BootMode::_OnPickLetter);
839 _user_input_menu.AddOption(MakeUnicodeString("z"), &BootMode::_OnPickLetter);
840
841 //backspace to delete characters
842 _user_input_menu.AddOption(UTranslate("back"), &BootMode::_OnPickLetter);
843
844 //end to confirm the name
845 _user_input_menu.AddOption(UTranslate("end"), &BootMode::_OnPickLetter);
846 }
847
848
849
_RefreshVideoOptions()850 void BootMode::_RefreshVideoOptions() {
851 // Update resolution text
852 std::ostringstream resolution("");
853 resolution << "Resolution: " << VideoManager->GetScreenWidth() << " x " << VideoManager->GetScreenHeight();
854 _video_options_menu.SetOptionText(0, MakeUnicodeString(resolution.str()));
855
856 // Update text on current video mode
857 if (VideoManager->IsFullscreen())
858 _video_options_menu.SetOptionText(1, UTranslate("Window mode: fullscreen"));
859 else
860 _video_options_menu.SetOptionText(1, UTranslate("Window mode: windowed"));
861
862 // Update brightness
863 _video_options_menu.SetOptionText(2, UTranslate("Brightness: ") + MakeUnicodeString(NumberToString(VideoManager->GetGamma() * 50.0f + 0.5f) + " %"));
864 }
865
866
867
_RefreshAudioOptions()868 void BootMode::_RefreshAudioOptions() {
869 _audio_options_menu.SetOptionText(0, UTranslate("Sound Volume: ") + MakeUnicodeString(NumberToString(static_cast<int32>(AudioManager->GetSoundVolume() * 100.0f + 0.5f)) + " %"));
870 _audio_options_menu.SetOptionText(1, UTranslate("Music Volume: ") + MakeUnicodeString(NumberToString(static_cast<int32>(AudioManager->GetMusicVolume() * 100.0f + 0.5f)) + " %"));
871 }
872
873
874
_RefreshKeySettings()875 void BootMode::_RefreshKeySettings() {
876 // Update key names
877 _key_settings_menu.SetOptionText(0, UTranslate("Move Up") + MakeUnicodeString("<r>" + InputManager->GetUpKeyName()));
878 _key_settings_menu.SetOptionText(1, UTranslate("Move Down") + MakeUnicodeString("<r>" + InputManager->GetDownKeyName()));
879 _key_settings_menu.SetOptionText(2, UTranslate("Move Left") + MakeUnicodeString("<r>" + InputManager->GetLeftKeyName()));
880 _key_settings_menu.SetOptionText(3, UTranslate("Move Right") + MakeUnicodeString("<r>" + InputManager->GetRightKeyName()));
881 _key_settings_menu.SetOptionText(4, UTranslate("Confirm") + MakeUnicodeString("<r>" + InputManager->GetConfirmKeyName()));
882 _key_settings_menu.SetOptionText(5, UTranslate("Cancel") + MakeUnicodeString("<r>" + InputManager->GetCancelKeyName()));
883 _key_settings_menu.SetOptionText(6, UTranslate("Menu") + MakeUnicodeString("<r>" + InputManager->GetMenuKeyName()));
884 _key_settings_menu.SetOptionText(7, UTranslate("Swap") + MakeUnicodeString("<r>" + InputManager->GetSwapKeyName()));
885 _key_settings_menu.SetOptionText(8, UTranslate("Left Select") + MakeUnicodeString("<r>" + InputManager->GetLeftSelectKeyName()));
886 _key_settings_menu.SetOptionText(9, UTranslate("Right Select") + MakeUnicodeString("<r>" + InputManager->GetRightSelectKeyName()));
887 _key_settings_menu.SetOptionText(10, UTranslate("Pause") + MakeUnicodeString("<r>" + InputManager->GetPauseKeyName()));
888 }
889
890
891
_RefreshJoySettings()892 void BootMode::_RefreshJoySettings() {
893 int32 i = 0;
894 _joy_settings_menu.SetOptionText(i++, UTranslate("X Axis") + MakeUnicodeString("<r>" + NumberToString(InputManager->GetXAxisJoy())));
895 _joy_settings_menu.SetOptionText(i++, UTranslate("Y Axis") + MakeUnicodeString("<r>" + NumberToString(InputManager->GetYAxisJoy())));
896 _joy_settings_menu.SetOptionText(i++, UTranslate("Confirm: Button") + MakeUnicodeString("<r>" + NumberToString(InputManager->GetConfirmJoy())));
897 _joy_settings_menu.SetOptionText(i++, UTranslate("Cancel: Button") + MakeUnicodeString("<r>" + NumberToString(InputManager->GetCancelJoy())));
898 _joy_settings_menu.SetOptionText(i++, UTranslate("Menu: Button") + MakeUnicodeString("<r>" + NumberToString(InputManager->GetMenuJoy())));
899 _joy_settings_menu.SetOptionText(i++, UTranslate("Swap: Button") + MakeUnicodeString("<r>" + NumberToString(InputManager->GetSwapJoy())));
900 _joy_settings_menu.SetOptionText(i++, UTranslate("Left Select: Button") + MakeUnicodeString("<r>" + NumberToString(InputManager->GetLeftSelectJoy())));
901 _joy_settings_menu.SetOptionText(i++, UTranslate("Right Select: Button") + MakeUnicodeString("<r>" + NumberToString(InputManager->GetRightSelectJoy())));
902 _joy_settings_menu.SetOptionText(i++, UTranslate("Pause: Button") + MakeUnicodeString("<r>" + NumberToString(InputManager->GetPauseJoy())));
903 }
904
905
906
_RefreshSaveAndLoadProfiles()907 void BootMode::_RefreshSaveAndLoadProfiles() {
908 //match the text with the directory listing :0
909 for (uint32 i = 0; i < _GetDirectoryListingUserProfilePath().size(); i++) {
910 _load_profile_menu.SetOptionText(i,MakeUnicodeString(_GetDirectoryListingUserProfilePath().at(i)));
911 _delete_profile_menu.SetOptionText(i,MakeUnicodeString(_GetDirectoryListingUserProfilePath().at(i)));
912 }
913 }
914
915 // ****************************************************************************
916 // ***** BootMode menu handler methods
917 // ****************************************************************************
918
_OnNewGame()919 void BootMode::_OnNewGame() {
920 GlobalManager->NewGame();
921
922 _fade_out = true;
923 VideoManager->FadeScreen(Color::black, 1000); // Fade to black over the course of one second
924 // _boot_music.at(0).SetFadeOutTime(500); // Fade out the music
925 _boot_music.at(0).Stop();
926 }
927
928
929
_OnLoadGame()930 void BootMode::_OnLoadGame() {
931 _boot_music.at(0).Stop();
932 // TODO: SaveMode music should take over when this is used for loading games...
933 hoa_save::SaveMode *SVM = new hoa_save::SaveMode(false);
934 ModeManager->Push(SVM);
935 }
936
937
938
_OnOptions()939 void BootMode::_OnOptions() {
940 _active_menu = &_options_menu;
941 _options_window.Show();
942 }
943
944
945
_OnCredits()946 void BootMode::_OnCredits() {
947 _credits_window->Show();
948 }
949
950
951
_OnQuit()952 void BootMode::_OnQuit() {
953 SystemManager->ExitGame();
954 }
955
956
957
_TEMP_OnBattle()958 void BootMode::_TEMP_OnBattle() {
959 ReadScriptDescriptor read_data;
960 if (!read_data.OpenFile("dat/config/boot.lua")) {
961 PRINT_ERROR << "failed to load boot data file" << endl;
962 }
963
964 ScriptCallFunction<void>(read_data.GetLuaState(), "BootBattleTest");
965
966 if (read_data.IsErrorDetected()) {
967 PRINT_ERROR << "an error occured during reading of the boot data file" << endl;
968 PRINT_ERROR << read_data.GetErrorMessages() << endl;
969 }
970 read_data.CloseFile();
971 }
972
973
974
_TEMP_OnMenu()975 void BootMode::_TEMP_OnMenu() {
976 ReadScriptDescriptor read_data;
977 if (!read_data.OpenFile("dat/config/boot.lua")) {
978 PRINT_ERROR << "failed to load boot data file" << endl;
979 }
980
981 ScriptCallFunction<void>(read_data.GetLuaState(), "BootMenuTest");
982
983 if (read_data.IsErrorDetected()) {
984 PRINT_ERROR << "an error occured during reading of the boot data file" << endl;
985 PRINT_ERROR << read_data.GetErrorMessages() << endl;
986 }
987 read_data.CloseFile();
988
989 // TEMP: remove this once menu mode can be created in Lua and then add to boot.lua
990 GlobalManager->AddToInventory(1, 5);
991 GlobalManager->AddCharacter(1);
992 GlobalManager->AddCharacter(2);
993 GlobalManager->AddCharacter(4);
994 GlobalManager->AddCharacter(8);
995 hoa_menu::MenuMode *MM = new hoa_menu::MenuMode(MakeUnicodeString("The Boot Screen"), "img/menus/locations/desert_cave.png");
996 ModeManager->Push(MM);
997 }
998
999
1000
_TEMP_OnShop()1001 void BootMode::_TEMP_OnShop() {
1002 ReadScriptDescriptor read_data;
1003 if (!read_data.OpenFile("dat/config/boot.lua")) {
1004 PRINT_ERROR << "failed to load boot data file" << endl;
1005 }
1006
1007 ScriptCallFunction<void>(read_data.GetLuaState(), "BootShopTest");
1008
1009 if (read_data.IsErrorDetected()) {
1010 PRINT_ERROR << "an error occured during reading of the boot data file" << endl;
1011 PRINT_ERROR << read_data.GetErrorMessages() << endl;
1012 }
1013 read_data.CloseFile();
1014 }
1015
1016
1017
_OnVideoOptions()1018 void BootMode::_OnVideoOptions() {
1019 _active_menu = &_video_options_menu;
1020 _RefreshVideoOptions();
1021 }
1022
1023
1024
_OnAudioOptions()1025 void BootMode::_OnAudioOptions() {
1026 // Switch the current menu
1027 _active_menu = &_audio_options_menu;
1028 _RefreshAudioOptions();
1029 }
1030
1031
1032
_OnLanguageOptions()1033 void BootMode::_OnLanguageOptions()
1034 {
1035 // Switch the current menu
1036 _active_menu = &_language_options_menu;
1037 //_UpdateLanguageOptions();
1038 }
1039
1040
1041
_OnKeySettings()1042 void BootMode::_OnKeySettings() {
1043 _active_menu = &_key_settings_menu;
1044 _RefreshKeySettings();
1045 }
1046
1047
1048
_OnJoySettings()1049 void BootMode::_OnJoySettings() {
1050 _active_menu = &_joy_settings_menu;
1051 _RefreshJoySettings();
1052 }
1053
1054
1055
_OnProfiles()1056 void BootMode::_OnProfiles() {
1057 _active_menu = &_profiles_menu;
1058 }
1059
1060
1061
_OnToggleFullscreen()1062 void BootMode::_OnToggleFullscreen() {
1063 // Toggle fullscreen / windowed
1064 VideoManager->ToggleFullscreen();
1065 VideoManager->ApplySettings();
1066 _RefreshVideoOptions();
1067 _has_modified_settings = true;
1068 }
1069
1070
1071
_OnResolution()1072 void BootMode::_OnResolution() {
1073 _active_menu = &_resolution_menu;
1074 }
1075
1076
1077
_OnResolution640x480()1078 void BootMode::_OnResolution640x480() {
1079 if (VideoManager->GetScreenWidth() != 640 && VideoManager->GetScreenHeight() != 480)
1080 _ChangeResolution(640, 480);
1081 }
1082
1083
1084
_OnResolution800x600()1085 void BootMode::_OnResolution800x600() {
1086 if (VideoManager->GetScreenWidth() != 800 && VideoManager->GetScreenHeight() != 600)
1087 _ChangeResolution(800, 600);
1088 }
1089
1090
1091
_OnResolution1024x768()1092 void BootMode::_OnResolution1024x768() {
1093 if (VideoManager->GetScreenWidth() != 1024 && VideoManager->GetScreenHeight() != 768)
1094 _ChangeResolution(1024, 768);
1095 }
1096
1097
1098
_OnResolution1280x1024()1099 void BootMode::_OnResolution1280x1024() {
1100 if(VideoManager->GetScreenWidth() != 1280 && VideoManager->GetScreenHeight() != 1024)
1101 _ChangeResolution(1280,1024);
1102 }
1103
1104
1105
_OnBrightnessLeft()1106 void BootMode::_OnBrightnessLeft() {
1107 VideoManager->SetGamma(VideoManager->GetGamma() - 0.1f);
1108 _RefreshVideoOptions();
1109 }
1110
1111
1112
_OnBrightnessRight()1113 void BootMode::_OnBrightnessRight() {
1114 VideoManager->SetGamma(VideoManager->GetGamma() + 0.1f);
1115 _RefreshVideoOptions();
1116 }
1117
1118
1119
_OnSoundLeft()1120 void BootMode::_OnSoundLeft() {
1121 AudioManager->SetSoundVolume(AudioManager->GetSoundVolume() - 0.1f);
1122 _RefreshAudioOptions();
1123 _boot_sounds.at(4).Play(); // Play a sound for user to hear new volume level.
1124 _has_modified_settings = true;
1125 }
1126
1127
1128
_OnSoundRight()1129 void BootMode::_OnSoundRight() {
1130 AudioManager->SetSoundVolume(AudioManager->GetSoundVolume() + 0.1f);
1131 _RefreshAudioOptions();
1132 _boot_sounds.at(4).Play(); // Play a sound for user to hear new volume level
1133 _has_modified_settings = true;
1134 }
1135
1136
1137
_OnMusicLeft()1138 void BootMode::_OnMusicLeft() {
1139 AudioManager->SetMusicVolume(AudioManager->GetMusicVolume() - 0.1f);
1140 _RefreshAudioOptions();
1141 _has_modified_settings = true;
1142 }
1143
1144
1145
_OnMusicRight()1146 void BootMode::_OnMusicRight() {
1147 AudioManager->SetMusicVolume(AudioManager->GetMusicVolume() + 0.1f);
1148 _RefreshAudioOptions();
1149 _has_modified_settings = true;
1150 }
1151
1152
1153
_OnLanguageSelect()1154 void BootMode::_OnLanguageSelect() {
1155 SystemManager->SetLanguage(_po_files[_language_options_menu.GetSelection()]);
1156 _has_modified_settings = true;
1157
1158 // TODO: when the new language is set by the above call, we need to reload/refresh all text,
1159 // otherwise the new language will not take effect.
1160 }
1161
1162
1163
_OnRestoreDefaultKeys()1164 void BootMode::_OnRestoreDefaultKeys() {
1165 InputManager->RestoreDefaultKeys();
1166 _RefreshKeySettings();
1167 _has_modified_settings = true;
1168 }
1169
1170
1171
_OnRestoreDefaultJoyButtons()1172 void BootMode::_OnRestoreDefaultJoyButtons() {
1173 InputManager->RestoreDefaultJoyButtons();
1174 _RefreshJoySettings();
1175 _has_modified_settings = true;
1176 }
1177
1178
1179
_OnLoadProfile()1180 void BootMode::_OnLoadProfile() {
1181 _active_menu = &_load_profile_menu;
1182 }
1183
1184
1185
_OnSaveProfile()1186 void BootMode::_OnSaveProfile() {
1187 _active_menu = &_save_profile_menu;
1188
1189 }
1190
1191
1192
_OnDeleteProfile()1193 void BootMode::_OnDeleteProfile() {
1194 _active_menu = &_delete_profile_menu;
1195 }
1196
1197
1198
_OnLoadFile()1199 void BootMode::_OnLoadFile() {
1200 //get the file path
1201 if (_load_profile_menu.GetSelection() < 0 || _load_profile_menu.GetSelection() >= (int32)_GetDirectoryListingUserProfilePath().size())
1202 cerr << "selection was out of range: " << _load_profile_menu.GetSelection() << " try another one " << endl;
1203 else {
1204 //we took off the .lua extension so that end users wouldn't see it but we need to add it back now
1205 const string& filename = GetUserProfilePath() + _GetDirectoryListingUserProfilePath().at(_load_profile_menu.GetSelection()) + ".lua";
1206 bool success = _LoadSettingsFile(filename);
1207
1208 //load the file
1209 if (BOOT_DEBUG) {
1210 if (success)
1211 cout << "BOOT: profile was successfully loaded " << filename << endl;
1212 else
1213 cout << "BOOT ERROR: profile failed to load " << filename << endl;
1214 }
1215
1216 //update all of the settings when loaded
1217 _RefreshKeySettings();
1218 _RefreshJoySettings();
1219 _RefreshVideoOptions();
1220 _RefreshAudioOptions();
1221 }
1222 }
1223
1224
1225
_OnSaveFile()1226 void BootMode::_OnSaveFile() {
1227 //if new profile was selected go to the user input menu
1228 if (_save_profile_menu.GetSelection() == 0) {
1229 _active_menu = &_user_input_menu;
1230
1231 //show the alert windows before we switch
1232 _file_name_alert.SetPosition(275.0f, 575.0f);
1233 _file_name_alert.SetText(UTranslate("Please enter a name for your new profile"));
1234 _file_name_alert.Show();
1235
1236 _file_name_window.SetPosition(275.0f, 150.0f);
1237 _file_name_window.Show();
1238 }
1239 else {
1240 _file_name_alert.SetPosition(360.0f, 115.0f);
1241 _file_name_alert.SetText(UTranslate("Overwrite? Confirm/Cancel"));
1242 _file_name_alert.Show();
1243 _overwrite_function = &BootMode::_OverwriteProfile;
1244 }
1245 }
1246
1247
1248
_OnDeleteFile()1249 void BootMode::_OnDeleteFile() {
1250 if (_load_profile_menu.GetSelection() < 0 || _load_profile_menu.GetSelection() >= (int32)_GetDirectoryListingUserProfilePath().size())
1251 cerr << "selection was out of range: " << _load_profile_menu.GetSelection() << " try another one " << endl;
1252 else {
1253 //get the file path
1254 //we took off the .lua extension so that end users wouldn't see it but we need to add it back now
1255 const string& filename = GetUserProfilePath() + _GetDirectoryListingUserProfilePath().at(_load_profile_menu.GetSelection()) + ".lua";
1256
1257 bool success = DeleteFile(filename);
1258
1259 if (BOOT_DEBUG) {
1260 if (success)
1261 cout << "BOOT: profile was successfully deleted " << filename << endl;
1262 else
1263 cout << "BOOT ERROR: failed to delete profile " << filename << endl;
1264 }
1265
1266 //Clear the option boxes on all the menus and reload them so we can get rid of the deleted profile
1267 _save_profile_menu.ClearOptions();
1268 _delete_profile_menu.ClearOptions();
1269 _load_profile_menu.ClearOptions();
1270
1271 //reload the menus
1272 _SetupSaveProfileMenu();
1273 _SetupDeleteProfileMenu();
1274 _SetupLoadProfileMenu();
1275 }
1276 }
1277
1278
1279
_OnPickLetter()1280 void BootMode::_OnPickLetter() {
1281 //the letters from the table
1282 char letters[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
1283
1284 if(_user_input_menu.GetSelection() == END) {
1285 //end, so save the file
1286
1287 //add the .lua extension
1288 _current_filename += ".lua";
1289
1290 //lets save this mofo :) and then add the option to save_profile menu and the load-profile menu
1291 _has_modified_settings = true;
1292
1293 if(_SaveSettingsFile(_current_filename))
1294 {
1295 if(BOOT_DEBUG)
1296 cout << "BOOT: profile successfully saved.";
1297 }
1298 else
1299 cout << "BOOT ERROR: profile could not be saved.";
1300
1301
1302 //take off the .lua extension so the end user doesnt see it
1303 _current_filename.erase(_current_filename.size() - 4);
1304 _save_profile_menu.AddOption(MakeUnicodeString(_current_filename), &BootMode::_OnSaveFile);
1305 _load_profile_menu.AddOption(MakeUnicodeString(_current_filename), &BootMode::_OnLoadFile);
1306 _delete_profile_menu.AddOption(MakeUnicodeString(_current_filename), &BootMode::_OnDeleteFile);
1307
1308 //make sure we reset the current _current_filename string
1309 _current_filename = "";
1310
1311 //also make sure we hide the alert windows if they havent selected new profile
1312 _file_name_alert.Hide();
1313 _file_name_window.Hide();
1314
1315 //update the profile menus
1316 _RefreshSaveAndLoadProfiles();
1317
1318 //since we ended we have to go back to the save profile menu
1319 _active_menu = &_save_profile_menu;
1320
1321 }
1322 else if(_user_input_menu.GetSelection() == BACK) {
1323 //take off the last letter
1324 //we subtract 1 because char arrays AKA strings start at position 0
1325
1326 //make sure we dont try to erase letters that are not there
1327 if(_current_filename != "")
1328 _current_filename.erase(_current_filename.length()-1);
1329 }
1330 else {
1331 //add letter to the _current_filename the _current_filename can be no longer than 19 characters
1332 if(_current_filename.length() != MAX_NAME)
1333 _current_filename += letters[_user_input_menu.GetSelection()];
1334 else if(BOOT_DEBUG)
1335 cout << "BOOT ERROR: _current_filename cannot be longer than 19 characters";
1336 }
1337
1338 _file_name_window.SetText(MakeUnicodeString(_current_filename));
1339 } // void BootMode::_OnPickLetter()
1340
1341 // ****************************************************************************
1342 // ***** BootMode helper methods
1343 // ****************************************************************************
1344
_DrawBackgroundItems()1345 void BootMode::_DrawBackgroundItems() {
1346 VideoManager->Move(512.0f, 384.0f);
1347 VideoManager->SetDrawFlags(VIDEO_NO_BLEND, 0);
1348 _boot_images[0].Draw(); // Draw background
1349
1350 VideoManager->Move(512.0f, 648.0f);
1351 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
1352 _boot_images[1].Draw(); // Draw the logo background
1353
1354 VideoManager->Move(762.0f, 578.0f);
1355 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
1356 _boot_images[2].Draw(); // Draw the sword
1357
1358 VideoManager->Move(512.0f, 648.0f);
1359 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
1360 _boot_images[3].Draw(); // Draw the logo text
1361 }
1362
1363
1364
_AnimateLogo()1365 void BootMode::_AnimateLogo() {
1366 // Sequence starting times. Note: I've changed _every_ variable here into floats
1367 // to avoid unneccessary type casts that would kill performance! -Viljami
1368 static const float SEQUENCE_ONE = 0.0f;
1369 static const float SEQUENCE_TWO = SEQUENCE_ONE + 1000.0f;
1370 static const float SEQUENCE_THREE = SEQUENCE_TWO + 2000.0f;
1371 static const float SEQUENCE_FOUR = SEQUENCE_THREE + 575.0f;
1372 static const float SEQUENCE_FIVE = SEQUENCE_FOUR + 1900.0f;
1373 static const float SEQUENCE_SIX = SEQUENCE_FIVE + 1400.0f;
1374 static const float SEQUENCE_SEVEN = SEQUENCE_SIX + 3500.0f;
1375
1376 // Sword image position and rotation
1377 static float sword_x = 670.0f;
1378 static float sword_y = 360.0f;
1379 static float rotation = -90.0f;
1380
1381 // Total time in ms
1382 static float total_time = 0.0f;
1383
1384 // Get the frametime and update total time
1385 float time_elapsed = static_cast<float>(SystemManager->GetUpdateTime());
1386 total_time += time_elapsed;
1387
1388 // Sequence one: black
1389 if (total_time >= SEQUENCE_ONE && total_time < SEQUENCE_TWO) {
1390 // Nothing drawn during this sequence
1391 }
1392 // Sequence two: fade in logo+sword
1393 else if (total_time >= SEQUENCE_TWO && total_time < SEQUENCE_THREE) {
1394 float alpha = (total_time - SEQUENCE_TWO) / (SEQUENCE_THREE - SEQUENCE_TWO);
1395
1396 VideoManager->Move(512.0f, 385.0f); // logo bg
1397 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
1398 _boot_images[1].Draw(Color(alpha, alpha, alpha, 1.0f));
1399 VideoManager->Move(sword_x, sword_y); // sword
1400 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
1401 VideoManager->Rotate(-90.0f);
1402 _boot_images[2].Draw(Color(alpha, alpha, alpha, 1.0f));
1403 VideoManager->Move(512.0f, 385.0f); // text
1404 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
1405 _boot_images[3].Draw(Color(alpha, alpha, alpha, 1.0f));
1406 }
1407 // Sequence three: Sword unsheathe & slide
1408 else if (total_time >= SEQUENCE_THREE && total_time < SEQUENCE_FOUR) {
1409 float dt = (total_time - SEQUENCE_THREE) * 0.001f;
1410 sword_x = 670.0f + (dt * dt) * 660.0f; // s = s0 + 0.5 * a * t^2
1411 VideoManager->Move(512.0f, 385.0f); // logo bg
1412 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
1413 _boot_images[1].Draw();
1414 VideoManager->Move(sword_x, sword_y); // sword
1415 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
1416 VideoManager->Rotate(-90.0f);
1417 _boot_images[2].Draw();
1418 VideoManager->Move(512.0f, 385.0f); // text
1419 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
1420 _boot_images[3].Draw();
1421 }
1422 // Sequence four: Spin around the sword
1423 else if (total_time >= SEQUENCE_FOUR && total_time < SEQUENCE_FIVE) {
1424 const float ROTATIONS = 720.0f + 90.0f;
1425 const float SPEED_LEFT = 35.0f;
1426 const float SPEED_UP = 750.0f;
1427 const float GRAVITY = 120.0f;
1428
1429 // Delta goes from 0.0f to 1.0f
1430 float delta = ((total_time - SEQUENCE_FOUR) / (SEQUENCE_FIVE - SEQUENCE_FOUR));
1431 float dt = (total_time - SEQUENCE_FOUR) * 0.001f;
1432 sword_x = 885.941f - dt * dt * SPEED_LEFT; // Small accelerated movement to left
1433 sword_y = 360.0f - dt * dt * GRAVITY + SPEED_UP * delta;
1434 rotation = -90.0f + delta * ROTATIONS;
1435
1436 VideoManager->Move(512.0f, 385.0f); // logo bg
1437 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
1438 _boot_images[1].Draw();
1439 VideoManager->Move(512.0f, 385.0f); // text
1440 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
1441 _boot_images[3].Draw();
1442 VideoManager->Move(sword_x, sword_y); // sword
1443 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
1444 VideoManager->Rotate(rotation);
1445 _boot_images[2].Draw();
1446 }
1447 // Sequence five: Sword comes back
1448 else if (total_time >= SEQUENCE_FIVE && total_time < SEQUENCE_SIX) {
1449 // Delta goes from 0.0f to 1.0f
1450 float delta_root = (total_time - SEQUENCE_FIVE) / (SEQUENCE_SIX - SEQUENCE_FIVE);
1451 float delta = delta_root * delta_root * delta_root * delta_root;
1452 float newX = (1.0f - delta) * sword_x + 762.0f * delta;
1453 float newY = (1.0f - delta) * sword_y + 310.0f * delta;
1454
1455 VideoManager->Move(512.0f, 385.0f); // logo bg
1456 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
1457 _boot_images[1].Draw();
1458 VideoManager->Move(512.0f, 385.0f); // text
1459 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
1460 _boot_images[3].Draw();
1461 VideoManager->Move(newX, newY); // sword
1462 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
1463 _boot_images[2].Draw();
1464 }
1465 // Sequence six: flash of light
1466 else if (total_time >= SEQUENCE_SIX && total_time < SEQUENCE_SEVEN) {
1467 // Delta goes from 1.0f to 0.0f
1468 float delta = (total_time - SEQUENCE_SIX) / (SEQUENCE_SEVEN - SEQUENCE_SIX);
1469 delta = 1.0f - delta * delta;
1470 _DrawBackgroundItems();
1471 Color targetColor(Color::white);
1472 targetColor.SetAlpha(delta);
1473 VideoManager->DrawFullscreenOverlay(targetColor);
1474 }
1475 else if (total_time >= SEQUENCE_SEVEN) {
1476 _EndLogoAnimation();
1477 _DrawBackgroundItems();
1478 }
1479 } // void BootMode::_AnimateLogo()
1480
1481
1482
_EndLogoAnimation()1483 void BootMode::_EndLogoAnimation() {
1484 // Stop playing SFX and start playing the main theme
1485 // _boot_music.at(1).SetFadeOutTime(1000);
1486 _boot_music.at(1).Stop();
1487 // _boot_music.at(0).SetFadeInTime(5000);
1488 _boot_music.at(0).Play();
1489
1490 // Effects::FadeOut(_boot_music.at(1), 10.0f);
1491 // Effects::FadeIn(_boot_music.at(0), 50.0f);
1492
1493 // Load the settings file for reading in the welcome variable
1494 ReadScriptDescriptor settings_lua;
1495 string file = GetSettingsFilename();
1496 if (!settings_lua.OpenFile(file)) {
1497 PRINT_WARNING << "failed to load the boot settings file" << endl;
1498 }
1499
1500 settings_lua.OpenTable("settings");
1501 if (settings_lua.ReadInt("welcome") == 1) {
1502 _welcome_window->Show();
1503 }
1504 settings_lua.CloseTable();
1505 settings_lua.CloseFile();
1506 _initial_entry = false;
1507 }
1508
1509
1510
_ShowMessageWindow(bool joystick)1511 void BootMode::_ShowMessageWindow(bool joystick) {
1512 if (joystick)
1513 _ShowMessageWindow(WAIT_JOY_BUTTON);
1514 else
1515 _ShowMessageWindow(WAIT_KEY);
1516 }
1517
1518
1519
_ShowMessageWindow(WAIT_FOR wait)1520 void BootMode::_ShowMessageWindow(WAIT_FOR wait) {
1521 string message = "";
1522 if (wait == WAIT_JOY_BUTTON)
1523 _message_window.SetText(UTranslate("Please press a new joystick button."));
1524 else if (wait == WAIT_KEY)
1525 _message_window.SetText(UTranslate("Please press a new key."));
1526 else if (wait == WAIT_JOY_AXIS)
1527 _message_window.SetText(UTranslate("Please move an axis."));
1528 else {
1529 PRINT_WARNING << "Undefined wait value." << std::endl;
1530 return;
1531 }
1532
1533 _message_window.Show();
1534 }
1535
1536
1537
_ChangeResolution(int32 width,int32 height)1538 void BootMode::_ChangeResolution(int32 width, int32 height) {
1539 VideoManager->SetResolution(width, height);
1540 VideoManager->ApplySettings();
1541 // _active_menu = &_video_options_menu; // return back to video options
1542 _RefreshVideoOptions();
1543 _has_modified_settings = true;
1544 }
1545
1546
1547
_LoadSettingsFile(const std::string & filename)1548 bool BootMode::_LoadSettingsFile(const std::string& filename) {
1549
1550 ReadScriptDescriptor settings;
1551
1552 if (settings.OpenFile(filename) == false)
1553 return false;
1554
1555 if(BOOT_DEBUG)
1556 cout << "BOOT: Opened file to load settings " << settings.GetFilename() << endl;
1557
1558 settings.OpenTable("settings");
1559
1560 // Load language settings
1561 // uint32 lang_code = static_cast<uint32>(settings.ReadInt("lang_code"));
1562
1563 // if (lang_code == 1) SystemManager->SetLanguage("en@quot");
1564 // else if (lang_code == 2) SystemManager->SetLanguage("fr");
1565 // else if (lang_code == 3) SystemManager->SetLanguage("pt_BR");
1566 // else if (lang_code == 4) SystemManager->SetLanguage("es");
1567 // else if (lang_code == 5) SystemManager->SetLanguage("de");
1568 // else SystemManager->SetLanguage("en@quot");
1569
1570 SystemManager->SetLanguage(static_cast<std::string>(settings.ReadString("language")));
1571
1572 settings.OpenTable("key_settings");
1573 InputManager->SetUpKey(static_cast<SDLKey>(settings.ReadInt("up")));
1574 InputManager->SetDownKey(static_cast<SDLKey>(settings.ReadInt("down")));
1575 InputManager->SetLeftKey(static_cast<SDLKey>(settings.ReadInt("left")));
1576 InputManager->SetRightKey(static_cast<SDLKey>(settings.ReadInt("right")));
1577 InputManager->SetConfirmKey(static_cast<SDLKey>(settings.ReadInt("confirm")));
1578 InputManager->SetCancelKey(static_cast<SDLKey>(settings.ReadInt("cancel")));
1579 InputManager->SetMenuKey(static_cast<SDLKey>(settings.ReadInt("menu")));
1580 InputManager->SetSwapKey(static_cast<SDLKey>(settings.ReadInt("swap")));
1581 InputManager->SetLeftSelectKey(static_cast<SDLKey>(settings.ReadInt("left_select")));
1582 InputManager->SetRightSelectKey(static_cast<SDLKey>(settings.ReadInt("right_select")));
1583 InputManager->SetPauseKey(static_cast<SDLKey>(settings.ReadInt("pause")));
1584 settings.CloseTable();
1585
1586 if (settings.IsErrorDetected()) {
1587 cerr << "SETTINGS LOAD ERROR: failure while trying to retrieve key map "
1588 << "information from file: " << settings.GetFilename() << endl;
1589 cerr << settings.GetErrorMessages() << endl;
1590 return false;
1591 }
1592
1593 settings.OpenTable("joystick_settings");
1594 InputManager->SetJoyIndex(static_cast<int32>(settings.ReadInt("index")));
1595 InputManager->SetConfirmJoy(static_cast<uint8>(settings.ReadInt("confirm")));
1596 InputManager->SetCancelJoy(static_cast<uint8>(settings.ReadInt("cancel")));
1597 InputManager->SetMenuJoy(static_cast<uint8>(settings.ReadInt("menu")));
1598 InputManager->SetSwapJoy(static_cast<uint8>(settings.ReadInt("swap")));
1599 InputManager->SetLeftSelectJoy(static_cast<uint8>(settings.ReadInt("left_select")));
1600 InputManager->SetRightSelectJoy(static_cast<uint8>(settings.ReadInt("right_select")));
1601 InputManager->SetPauseJoy(static_cast<uint8>(settings.ReadInt("pause")));
1602
1603 // WinterKnight: These are hidden settings. You can change them by editing settings.lua,
1604 // but they are not available in the options menu at this time.
1605 InputManager->SetQuitJoy(static_cast<uint8>(settings.ReadInt("quit")));
1606 if (settings.DoesIntExist("x_axis"))
1607 InputManager->SetXAxisJoy(static_cast<int8>(settings.ReadInt("x_axis")));
1608 if (settings.DoesIntExist("y_axis"))
1609 InputManager->SetYAxisJoy(static_cast<int8>(settings.ReadInt("y_axis")));
1610 if (settings.DoesIntExist("threshold"))
1611 InputManager->SetThresholdJoy(static_cast<uint16>(settings.ReadInt("threshold")));
1612 settings.CloseTable();
1613
1614 if (settings.IsErrorDetected()) {
1615 cerr << "SETTINGS LOAD ERROR: an error occured while trying to retrieve joystick mapping information "
1616 << "from file: " << settings.GetFilename() << endl;
1617 cerr << settings.GetErrorMessages() << endl;
1618 return false;
1619 }
1620
1621 // Load video settings
1622 settings.OpenTable("video_settings");
1623 bool fullscreen = static_cast<bool>(settings.ReadBool("full_screen"));
1624 int32 resx = static_cast<int32>(settings.ReadInt("screen_resx"));
1625
1626
1627 //Set Resolution according to width if no width matches our predefined resoultion set to lowest resolution
1628 if(resx == 800) {
1629 _OnResolution800x600();
1630 _resolution_menu.SetSelection(1);
1631 }
1632 else if(resx == 1024) {
1633 _OnResolution1024x768();
1634 _resolution_menu.SetSelection(2);
1635 }
1636 else if(resx == 1280) {
1637 _OnResolution1280x1024();
1638 _resolution_menu.SetSelection(3);
1639 }
1640 else {
1641 _OnResolution640x480();
1642 _resolution_menu.SetSelection(0);
1643 }
1644
1645 //set the fullscreen and update video options
1646 if(VideoManager->IsFullscreen() && fullscreen == false)
1647 _OnToggleFullscreen();
1648 else if(VideoManager->IsFullscreen() == false && fullscreen)
1649 _OnToggleFullscreen();
1650
1651 settings.CloseTable();
1652
1653 if (settings.IsErrorDetected()) {
1654 cerr << "SETTINGS LOAD ERROR: failure while trying to retrieve video settings "
1655 << "information from file: " << settings.GetFilename() << endl;
1656 cerr << settings.GetErrorMessages() << endl;
1657 return false;
1658 }
1659
1660 // Load Audio settings
1661 if (AUDIO_ENABLE) {
1662 settings.OpenTable("audio_settings");
1663 AudioManager->SetMusicVolume(static_cast<float>(settings.ReadFloat("music_vol")));
1664 AudioManager->SetSoundVolume(static_cast<float>(settings.ReadFloat("sound_vol")));
1665 }
1666 settings.CloseAllTables();
1667
1668 if (settings.IsErrorDetected()) {
1669 cerr << "SETTINGS LOAD ERROR: failure while trying to retrieve audio settings "
1670 << "information from file: " << settings.GetFilename() << endl;
1671 cerr << settings.GetErrorMessages() << endl;
1672 return false;
1673 }
1674
1675 settings.CloseFile();
1676
1677 if(BOOT_DEBUG)
1678 cout << "Profile closed " << settings.GetFilename() << endl;
1679
1680
1681 return true;
1682 } // bool BootMode::_LoadSettingsFile(const std::string& filename)
1683
1684
1685
_SaveSettingsFile(const std::string & filename)1686 bool BootMode::_SaveSettingsFile(const std::string& filename) {
1687
1688 // No need to save the settings if we haven't edited anything!
1689 if (!_has_modified_settings)
1690 return false;
1691
1692 string file = "";
1693 string fileTemp = "";
1694
1695 // Load the settings file for reading in the original data
1696 fileTemp = GetUserProfilePath() + "settings.lua";
1697
1698
1699 if(filename == "")
1700 file = fileTemp;
1701 else
1702 file = GetUserProfilePath() + filename;
1703
1704 //copy the default file so we have an already set up lua file and then we can modify its settings
1705 if (!DoesFileExist(file))
1706 CopyFile(string("dat/config/settings.lua"), file);
1707
1708 ModifyScriptDescriptor settings_lua;
1709 if (!settings_lua.OpenFile(file)) {
1710 cerr << "BOOT ERROR: failed to load the settings file!" << endl;
1711 return false;
1712 }
1713
1714 // Write the current settings into the .lua file
1715 settings_lua.ModifyInt("settings.welcome", 0);
1716
1717 //Save language settings
1718 settings_lua.ModifyString("settings.language", SystemManager->GetLanguage());
1719 // std::string lang_name = SystemManager->GetLanguage();
1720
1721 // if (lang_name == "en@quot") settings_lua.ModifyInt("settings.lang_code", 1);
1722 // else if (lang_name == "fr") settings_lua.ModifyInt("settings.lang_code", 2);
1723 // else if (lang_name == "pt_br") settings_lua.ModifyInt("settings.lang_code", 3);
1724 // else if (lang_name == "es") settings_lua.ModifyInt("settings.lang_code", 4);
1725 // else if (lang_name == "de") settings_lua.ModifyInt("settings.lang_code", 5);
1726 // else settings_lua.ModifyInt("settings.lang_code", 1);
1727
1728 // video
1729 settings_lua.OpenTable("settings");
1730 settings_lua.ModifyInt("video_settings.screen_resx", VideoManager->GetScreenWidth());
1731 settings_lua.ModifyInt("video_settings.screen_resy", VideoManager->GetScreenHeight());
1732 settings_lua.ModifyBool("video_settings.full_screen", VideoManager->IsFullscreen());
1733 //settings_lua.ModifyFloat("video_settings.brightness", VideoManager->GetGamma());
1734
1735 // audio
1736 settings_lua.ModifyFloat("audio_settings.music_vol", AudioManager->GetMusicVolume());
1737 settings_lua.ModifyFloat("audio_settings.sound_vol", AudioManager->GetSoundVolume());
1738
1739 // input
1740 settings_lua.ModifyInt("key_settings.up", InputManager->GetUpKey());
1741 settings_lua.ModifyInt("key_settings.down", InputManager->GetDownKey());
1742 settings_lua.ModifyInt("key_settings.left", InputManager->GetLeftKey());
1743 settings_lua.ModifyInt("key_settings.right", InputManager->GetRightKey());
1744 settings_lua.ModifyInt("key_settings.confirm", InputManager->GetConfirmKey());
1745 settings_lua.ModifyInt("key_settings.cancel", InputManager->GetCancelKey());
1746 settings_lua.ModifyInt("key_settings.menu", InputManager->GetMenuKey());
1747 settings_lua.ModifyInt("key_settings.swap", InputManager->GetSwapKey());
1748 settings_lua.ModifyInt("key_settings.left_select", InputManager->GetLeftSelectKey());
1749 settings_lua.ModifyInt("key_settings.right_select", InputManager->GetRightSelectKey());
1750 settings_lua.ModifyInt("key_settings.pause", InputManager->GetPauseKey());
1751 settings_lua.ModifyInt("joystick_settings.x_axis", InputManager->GetXAxisJoy());
1752 settings_lua.ModifyInt("joystick_settings.y_axis", InputManager->GetYAxisJoy());
1753 settings_lua.ModifyInt("joystick_settings.confirm", InputManager->GetConfirmJoy());
1754 settings_lua.ModifyInt("joystick_settings.cancel", InputManager->GetCancelJoy());
1755 settings_lua.ModifyInt("joystick_settings.menu", InputManager->GetMenuJoy());
1756 settings_lua.ModifyInt("joystick_settings.swap", InputManager->GetSwapJoy());
1757 settings_lua.ModifyInt("joystick_settings.left_select", InputManager->GetLeftSelectJoy());
1758 settings_lua.ModifyInt("joystick_settings.right_select", InputManager->GetRightSelectJoy());
1759 settings_lua.ModifyInt("joystick_settings.pause", InputManager->GetPauseJoy());
1760
1761 // and save it!
1762 settings_lua.CommitChanges();
1763 settings_lua.CloseFile();
1764
1765 _has_modified_settings = false;
1766
1767 return true;
1768 } // bool BootMode::_SaveSettingsFile(const std::string& filename)
1769
1770
1771
_GetDirectoryListingUserProfilePath()1772 vector<string> BootMode::_GetDirectoryListingUserProfilePath() {
1773
1774 //get the entire directory listing for user data path
1775 vector<string> directory_listing = ListDirectory(GetUserProfilePath(), ".lua");
1776
1777 if (directory_listing.empty()) {
1778 return directory_listing;
1779 }
1780 else {
1781 //as stated earlier this is for personalized profiles only
1782 directory_listing.erase(find(directory_listing.begin(), directory_listing.end(), "settings.lua"));
1783
1784 //we also need to take off the .lua extension so end users do not see it
1785 for(uint32 i = 0; i < directory_listing.size(); i++)
1786 directory_listing.at(i).erase(directory_listing.at(i).size() - 4);
1787
1788 return directory_listing;
1789 }
1790 }
_AddProfileOptions(private_boot::BootMenu * menu)1791 void BootMode::_AddProfileOptions(private_boot::BootMenu* menu)
1792 {
1793 //setup the dimensions according to how many profiles we have available
1794 vector<std::string> profile_vector = _GetDirectoryListingUserProfilePath();
1795 menu->SetDimensions(300.0f, 200.0f, 1,profile_vector.size()+1, 1, profile_vector.size()+1);
1796
1797 //add the options in for each file
1798 for (uint32 i = 0; i < profile_vector.size(); i++) {
1799 //this menu is for personalized profiles only do not include the default profile "restore defaults" already exists
1800 string filename = profile_vector.at(i);
1801 menu->AddOption(MakeUnicodeString(filename.c_str()), &BootMode::_OnLoadFile);
1802 }
1803 }
1804
1805
1806
_OverwriteProfile()1807 void BootMode::_OverwriteProfile() {
1808 _has_modified_settings = true;
1809
1810 //we subtract 1 to take into account the "new profile" option
1811 _SaveSettingsFile(_GetDirectoryListingUserProfilePath().at(_save_profile_menu.GetSelection() - 1) + ".lua");
1812
1813 //if we got past the save settings without throwing an exception then we succeeded
1814 if (BOOT_DEBUG)
1815 cout << "BOOT: profile successfully overwritten " << _GetDirectoryListingUserProfilePath().at(_save_profile_menu.GetSelection() - 1) << endl;
1816 }
1817
1818 // ****************************************************************************
1819 // ***** BootMode input configuration methods
1820 // ****************************************************************************
1821
_WaitKeyPress()1822 SDLKey BootMode::_WaitKeyPress() {
1823 SDL_Event event;
1824 while (SDL_WaitEvent(&event)) {
1825 if (event.type == SDL_KEYDOWN)
1826 break;
1827 }
1828
1829 return event.key.keysym.sym;
1830 }
1831
1832
1833
_WaitJoyPress()1834 uint8 BootMode::_WaitJoyPress() {
1835 SDL_Event event;
1836 while (SDL_WaitEvent(&event)) {
1837 if (event.type == SDL_JOYBUTTONDOWN)
1838 break;
1839 }
1840
1841 return event.jbutton.button;
1842 }
1843
1844
1845
_RedefineUpKey()1846 void BootMode::_RedefineUpKey() {
1847 _key_setting_function = &BootMode::_SetUpKey;
1848 _ShowMessageWindow(false);
1849 }
1850
1851
1852
_RedefineDownKey()1853 void BootMode::_RedefineDownKey() {
1854 _key_setting_function = &BootMode::_SetDownKey;
1855 _ShowMessageWindow(false);
1856 }
1857
1858
1859
_RedefineLeftKey()1860 void BootMode::_RedefineLeftKey() {
1861 _key_setting_function = &BootMode::_SetLeftKey;
1862 _ShowMessageWindow(false);
1863 }
1864
1865
1866
_RedefineRightKey()1867 void BootMode::_RedefineRightKey() {
1868 _key_setting_function = &BootMode::_SetRightKey;
1869 _ShowMessageWindow(false);
1870 }
1871
1872
1873
_RedefineConfirmKey()1874 void BootMode::_RedefineConfirmKey() {
1875 _key_setting_function = &BootMode::_SetConfirmKey;
1876 _ShowMessageWindow(false);
1877 }
1878
1879
1880
_RedefineCancelKey()1881 void BootMode::_RedefineCancelKey() {
1882 _key_setting_function = &BootMode::_SetCancelKey;
1883 _ShowMessageWindow(false);
1884 }
1885
1886
1887
_RedefineMenuKey()1888 void BootMode::_RedefineMenuKey() {
1889 _key_setting_function = &BootMode::_SetMenuKey;
1890 _ShowMessageWindow(false);
1891 }
1892
1893
1894
_RedefineSwapKey()1895 void BootMode::_RedefineSwapKey() {
1896 _key_setting_function = &BootMode::_SetSwapKey;
1897 _ShowMessageWindow(false);
1898 }
1899
1900
1901
_RedefineLeftSelectKey()1902 void BootMode::_RedefineLeftSelectKey() {
1903 _key_setting_function = &BootMode::_SetLeftSelectKey;
1904 _ShowMessageWindow(false);
1905 }
1906
1907
1908
_RedefineRightSelectKey()1909 void BootMode::_RedefineRightSelectKey() {
1910 _key_setting_function = &BootMode::_SetRightSelectKey;
1911 _ShowMessageWindow(false);
1912 }
1913
1914
1915
_RedefinePauseKey()1916 void BootMode::_RedefinePauseKey() {
1917 _key_setting_function = &BootMode::_SetPauseKey;
1918 _ShowMessageWindow(false);
1919 }
1920
1921
1922
_SetUpKey(const SDLKey & key)1923 void BootMode::_SetUpKey(const SDLKey &key) {
1924 InputManager->SetUpKey(key);
1925 }
1926
1927
1928
_SetDownKey(const SDLKey & key)1929 void BootMode::_SetDownKey(const SDLKey &key) {
1930 InputManager->SetDownKey(key);
1931 }
1932
1933
_SetLeftKey(const SDLKey & key)1934 void BootMode::_SetLeftKey(const SDLKey &key) {
1935 InputManager->SetLeftKey(key);
1936 }
1937
1938
1939
_SetRightKey(const SDLKey & key)1940 void BootMode::_SetRightKey(const SDLKey &key) {
1941 InputManager->SetRightKey(key);
1942 }
1943
1944
1945
_SetConfirmKey(const SDLKey & key)1946 void BootMode::_SetConfirmKey(const SDLKey &key) {
1947 InputManager->SetConfirmKey(key);
1948 }
1949
1950
1951
_SetCancelKey(const SDLKey & key)1952 void BootMode::_SetCancelKey(const SDLKey &key) {
1953 InputManager->SetCancelKey(key);
1954 }
1955
1956
1957
_SetMenuKey(const SDLKey & key)1958 void BootMode::_SetMenuKey(const SDLKey &key) {
1959 InputManager->SetMenuKey(key);
1960 }
1961
1962
1963
_SetSwapKey(const SDLKey & key)1964 void BootMode::_SetSwapKey(const SDLKey &key) {
1965 InputManager->SetSwapKey(key);
1966 }
1967
1968
1969
_SetLeftSelectKey(const SDLKey & key)1970 void BootMode::_SetLeftSelectKey(const SDLKey &key) {
1971 InputManager->SetLeftSelectKey(key);
1972 }
1973
1974
1975
_SetRightSelectKey(const SDLKey & key)1976 void BootMode::_SetRightSelectKey(const SDLKey &key) {
1977 InputManager->SetRightSelectKey(key);
1978 }
1979
1980
1981
_SetPauseKey(const SDLKey & key)1982 void BootMode::_SetPauseKey(const SDLKey &key) {
1983 InputManager->SetPauseKey(key);
1984 }
1985
1986
1987
_RedefineXAxisJoy()1988 void BootMode::_RedefineXAxisJoy() {
1989 _joy_axis_setting_function = &BootMode::_SetXAxisJoy;
1990 _ShowMessageWindow(WAIT_JOY_AXIS);
1991 InputManager->ResetLastAxisMoved();
1992 }
1993
1994
1995
_RedefineYAxisJoy()1996 void BootMode::_RedefineYAxisJoy() {
1997 _joy_axis_setting_function = &BootMode::_SetYAxisJoy;
1998 _ShowMessageWindow(WAIT_JOY_AXIS);
1999 InputManager->ResetLastAxisMoved();
2000 }
2001
2002
2003
_RedefineThresholdJoy()2004 void BootMode::_RedefineThresholdJoy() {
2005 // TODO
2006 }
2007
2008
2009
_RedefineConfirmJoy()2010 void BootMode::_RedefineConfirmJoy() {
2011 _joy_setting_function = &BootMode::_SetConfirmJoy;
2012 _ShowMessageWindow(true);
2013 }
2014
2015
2016
_RedefineCancelJoy()2017 void BootMode::_RedefineCancelJoy() {
2018 _joy_setting_function = &BootMode::_SetCancelJoy;
2019 _ShowMessageWindow(true);
2020 }
2021
2022
2023
_RedefineMenuJoy()2024 void BootMode::_RedefineMenuJoy() {
2025 _joy_setting_function = &BootMode::_SetMenuJoy;
2026 _ShowMessageWindow(true);
2027 }
2028
2029
2030
_RedefineSwapJoy()2031 void BootMode::_RedefineSwapJoy() {
2032 _joy_setting_function = &BootMode::_SetSwapJoy;
2033 _ShowMessageWindow(true);
2034 }
2035
2036
2037
_RedefineLeftSelectJoy()2038 void BootMode::_RedefineLeftSelectJoy() {
2039 _joy_setting_function = &BootMode::_SetLeftSelectJoy;
2040 _ShowMessageWindow(true);
2041 }
2042
2043
2044
_RedefineRightSelectJoy()2045 void BootMode::_RedefineRightSelectJoy() {
2046 _joy_setting_function = &BootMode::_SetRightSelectJoy;
2047 _ShowMessageWindow(true);
2048 }
2049
2050
2051
_RedefinePauseJoy()2052 void BootMode::_RedefinePauseJoy() {
2053 _joy_setting_function = &BootMode::_SetPauseJoy;
2054 _ShowMessageWindow(true);
2055 }
2056
2057
2058
_RedefineQuitJoy()2059 void BootMode::_RedefineQuitJoy() {
2060 // TODO
2061 }
2062
2063
2064
_SetXAxisJoy(int8 axis)2065 void BootMode::_SetXAxisJoy(int8 axis) {
2066 InputManager->SetXAxisJoy(axis);
2067 }
2068
2069
2070
_SetYAxisJoy(int8 axis)2071 void BootMode::_SetYAxisJoy(int8 axis) {
2072 InputManager->SetYAxisJoy(axis);
2073 }
2074
2075
2076
_SetConfirmJoy(uint8 button)2077 void BootMode::_SetConfirmJoy(uint8 button) {
2078 InputManager->SetConfirmJoy(button);
2079 }
2080
2081
2082
_SetCancelJoy(uint8 button)2083 void BootMode::_SetCancelJoy(uint8 button) {
2084 InputManager->SetCancelJoy(button);
2085 }
2086
2087
2088
_SetMenuJoy(uint8 button)2089 void BootMode::_SetMenuJoy(uint8 button) {
2090 InputManager->SetMenuJoy(button);
2091 }
2092
2093
2094
_SetSwapJoy(uint8 button)2095 void BootMode::_SetSwapJoy(uint8 button) {
2096 InputManager->SetSwapJoy(button);
2097 }
2098
2099
2100
_SetLeftSelectJoy(uint8 button)2101 void BootMode::_SetLeftSelectJoy(uint8 button) {
2102 InputManager->SetLeftSelectJoy(button);
2103 }
2104
2105
2106
_SetRightSelectJoy(uint8 button)2107 void BootMode::_SetRightSelectJoy(uint8 button) {
2108 InputManager->SetRightSelectJoy(button);
2109 }
2110
2111
2112
_SetPauseJoy(uint8 button)2113 void BootMode::_SetPauseJoy(uint8 button) {
2114 InputManager->SetPauseJoy(button);
2115 }
2116
2117 } // namespace hoa_boot
2118