00001
00002
00003
00004
00005
00006
00007
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "utils.h"
00018 #include <iostream>
00019 #include <sstream>
00020 #include "boot.h"
00021 #include "boot_menu.h"
00022 #include "boot_credits.h"
00023 #include "audio.h"
00024 #include "video.h"
00025 #include "script.h"
00026 #include "global.h"
00027 #include "mode_manager.h"
00028 #include "input.h"
00029 #include "system.h"
00030 #include "map.h"
00031 #include "battle.h"
00032 #include "menu.h"
00033 #include "shop.h"
00034 #include <fstream>
00035
00036 using namespace std;
00037 using namespace hoa_boot::private_boot;
00038 using namespace hoa_utils;
00039 using namespace hoa_audio;
00040 using namespace hoa_video;
00041 using namespace hoa_mode_manager;
00042 using namespace hoa_input;
00043 using namespace hoa_system;
00044 using namespace hoa_global;
00045 using namespace hoa_script;
00046 using namespace hoa_map;
00047 using namespace hoa_battle;
00048
00049 namespace hoa_boot {
00050
00051 bool BOOT_DEBUG = false;
00052
00053
00054
00055 bool BootMode::_logo_animating = true;
00056 uint32 welcome = 0;
00057
00058
00059
00060
00061
00062
00063
00064 BootMode::BootMode() :
00065 _fade_out(false),
00066 _main_menu(0, false, this),
00067 _latest_version(true),
00068 _has_modified_settings(false)
00069 {
00070 if (BOOT_DEBUG) cout << "BOOT: BootMode constructor invoked." << endl;
00071 mode_type = MODE_MANAGER_BOOT_MODE;
00072
00073 ReadScriptDescriptor read_data;
00074 if (!read_data.OpenFile("dat/config/boot.lua")) {
00075 cout << "BOOT ERROR: failed to load data file" << endl;
00076 }
00077
00078
00079 StillImage im;
00080
00081
00082 im.SetFilename(read_data.ReadString("background_image"));
00083 im.SetDimensions(read_data.ReadFloat("background_image_width"),
00084 read_data.ReadFloat("background_image_height"));
00085 _boot_images.push_back(im);
00086
00087
00088 im.SetFilename(read_data.ReadString("logo_background"));
00089 im.SetDimensions(read_data.ReadFloat("logo_background_width"),
00090 read_data.ReadFloat("logo_background_height"));
00091 _boot_images.push_back(im);
00092
00093
00094 im.SetFilename(read_data.ReadString("logo_sword"));
00095 im.SetDimensions(read_data.ReadFloat("logo_sword_width"),
00096 read_data.ReadFloat("logo_sword_height"));
00097 _boot_images.push_back(im);
00098
00099
00100 im.SetFilename(read_data.ReadString("logo_text"));
00101 im.SetDimensions(read_data.ReadFloat("logo_text_width"),
00102 read_data.ReadFloat("logo_text_height"));
00103 _boot_images.push_back(im);
00104
00105
00106 VideoManager->SetCoordSys(read_data.ReadFloat("coord_sys_x_left"),
00107 read_data.ReadFloat("coord_sys_x_right"),
00108 read_data.ReadFloat("coord_sys_y_bottom"),
00109 read_data.ReadFloat("coord_sys_y_top"));
00110
00111
00112
00113 vector<string> new_music_files;
00114 read_data.ReadStringVector("music_files", new_music_files);
00115
00116 vector<string> new_sound_files;
00117 read_data.ReadStringVector("sound_files", new_sound_files);
00118
00119 if (read_data.IsErrorDetected()) {
00120 cerr << "BOOT ERROR: some error occured during reading of boot data file" << endl;
00121 cerr << read_data.GetErrorMessages() << endl;
00122 }
00123
00124 read_data.CloseFile();
00125
00126
00127 _boot_music.resize(new_music_files.size(), MusicDescriptor());
00128 for (uint32 i = 0; i < new_music_files.size(); i++) {
00129 if (_boot_music[i].LoadMusic(new_music_files[i]) == false) {
00130 cout << "BOOT: failed to load music file " << new_music_files[i] << endl;
00131 SystemManager->ExitGame();
00132 return;
00133 }
00134 }
00135
00136 SoundDescriptor new_sound;
00137 _boot_sounds.push_back(new_sound);
00138 _boot_sounds.push_back(new_sound);
00139 _boot_sounds.push_back(new_sound);
00140 _boot_sounds.push_back(new_sound);
00141 _boot_sounds.push_back(new_sound);
00142 _boot_sounds[0].LoadSound(new_sound_files[0]);
00143 _boot_sounds[1].LoadSound(new_sound_files[1]);
00144 _boot_sounds[2].LoadSound(new_sound_files[2]);
00145 _boot_sounds[3].LoadSound(new_sound_files[3]);
00146 _boot_sounds[4].LoadSound(new_sound_files[4]);
00147
00148
00149 _latest_version = true;
00150 if (!_latest_version)
00151 _latest_version_number = GetLatestVersion();
00152 else
00153 _latest_version_number = "";
00154
00155
00156
00157
00158
00159
00160
00161
00162 for (uint32 i = 0; i < _boot_images.size(); i++) {
00163 VideoManager->LoadImage(_boot_images[i]);
00164 }
00165
00166
00167 _SetupMainMenu();
00168 _SetupOptionsMenu();
00169 _SetupVideoOptionsMenu();
00170 _SetupAudioOptionsMenu();
00171 _SetupKeySetttingsMenu();
00172 _SetupJoySetttingsMenu();
00173 _SetupResolutionMenu();
00174
00175
00176 _current_menu = &_main_menu;
00177 }
00178
00179
00180
00181 BootMode::~BootMode() {
00182 if (BOOT_DEBUG) cout << "BOOT: BootMode destructor invoked." << endl;
00183
00184 for (uint32 i = 0; i < _boot_music.size(); i++)
00185 _boot_music[i].FreeMusic();
00186
00187 for (uint32 i = 0; i < _boot_sounds.size(); i++)
00188 _boot_sounds[i].FreeSound();
00189
00190 for (uint32 i = 0; i < _boot_images.size(); i++)
00191 VideoManager->DeleteImage(_boot_images[i]);
00192 }
00193
00194
00195
00196 void BootMode::Reset() {
00197
00198 VideoManager->SetCoordSys(0.0f, 1024.0f, 0.0f, 768.0f);
00199 VideoManager->SetDrawFlags(VIDEO_X_CENTER, VIDEO_Y_CENTER, 0);
00200 VideoManager->DisableFog();
00201 VideoManager->SetTextColor(Color::white);
00202
00203
00204 GlobalManager->ClearAllData();
00205
00206
00207 if (_logo_animating)
00208 _boot_music.at(1).PlayMusic();
00209 else
00210 _boot_music.at(0).PlayMusic();
00211 }
00212
00213
00214
00215 void BootMode::_AnimateLogo() {
00216
00217
00218 static const float SEQUENCE_ONE = 0.0f;
00219 static const float SEQUENCE_TWO = SEQUENCE_ONE + 1000.0f;
00220 static const float SEQUENCE_THREE = SEQUENCE_TWO + 2000.0f;
00221 static const float SEQUENCE_FOUR = SEQUENCE_THREE + 575.0f;
00222 static const float SEQUENCE_FIVE = SEQUENCE_FOUR + 1900.0f;
00223 static const float SEQUENCE_SIX = SEQUENCE_FIVE + 1400.0f;
00224 static const float SEQUENCE_SEVEN = SEQUENCE_SIX + 3500.0f;
00225
00226
00227 static float sword_x = 670.0f;
00228 static float sword_y = 360.0f;
00229 static float rotation = -90.0f;
00230
00231
00232 static float total_time = 0.0f;
00233
00234
00235 float time_elapsed = static_cast<float>(SystemManager->GetUpdateTime());
00236 total_time += time_elapsed;
00237
00238
00239 if (total_time >= SEQUENCE_ONE && total_time < SEQUENCE_TWO)
00240 {
00241 }
00242
00243 else if (total_time >= SEQUENCE_TWO && total_time < SEQUENCE_THREE)
00244 {
00245 float alpha = (total_time - SEQUENCE_TWO) / (SEQUENCE_THREE - SEQUENCE_TWO);
00246
00247 VideoManager->Move(512.0f, 385.0f);
00248 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
00249 VideoManager->DrawImage(_boot_images[1], Color(alpha, alpha, alpha, 1.0f));
00250 VideoManager->Move(sword_x, sword_y);
00251 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
00252 VideoManager->Rotate(-90.0f);
00253 VideoManager->DrawImage(_boot_images[2], Color(alpha, alpha, alpha, 1.0f));
00254 VideoManager->Move(512.0f, 385.0f);
00255 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
00256 VideoManager->DrawImage(_boot_images[3], Color(alpha, alpha, alpha, 1.0f));
00257 }
00258
00259 else if (total_time >= SEQUENCE_THREE && total_time < SEQUENCE_FOUR)
00260 {
00261 float dt = (total_time - SEQUENCE_THREE) * 0.001f;
00262 sword_x = 670.0f + (dt * dt) * 660.0f;
00263 VideoManager->Move(512.0f, 385.0f);
00264 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
00265 VideoManager->DrawImage(_boot_images[1]);
00266 VideoManager->Move(sword_x, sword_y);
00267 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
00268 VideoManager->Rotate(-90.0f);
00269 VideoManager->DrawImage(_boot_images[2]);
00270 VideoManager->Move(512.0f, 385.0f);
00271 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
00272 VideoManager->DrawImage(_boot_images[3]);
00273 }
00274
00275 else if (total_time >= SEQUENCE_FOUR && total_time < SEQUENCE_FIVE)
00276 {
00277 const float ROTATIONS = 720.0f + 90.0f;
00278 const float SPEED_LEFT = 35.0f;
00279 const float SPEED_UP = 750.0f;
00280 const float GRAVITY = 120.0f;
00281
00282
00283 float delta = ((total_time - SEQUENCE_FOUR) / (SEQUENCE_FIVE - SEQUENCE_FOUR));
00284 float dt = (total_time - SEQUENCE_FOUR) * 0.001f;
00285 sword_x = 885.941f - dt*dt * SPEED_LEFT;
00286 sword_y = 360.0f - dt*dt * GRAVITY + SPEED_UP * delta;
00287 rotation = -90.0f + delta * ROTATIONS;
00288
00289 VideoManager->Move(512.0f, 385.0f);
00290 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
00291 VideoManager->DrawImage(_boot_images[1]);
00292 VideoManager->Move(512.0f, 385.0f);
00293 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
00294 VideoManager->DrawImage(_boot_images[3]);
00295 VideoManager->Move(sword_x, sword_y);
00296 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
00297 VideoManager->Rotate(rotation);
00298 VideoManager->DrawImage(_boot_images[2]);
00299 }
00300
00301 else if (total_time >= SEQUENCE_FIVE && total_time < SEQUENCE_SIX)
00302 {
00303
00304 float delta_root = (total_time - SEQUENCE_FIVE) / (SEQUENCE_SIX - SEQUENCE_FIVE);
00305 float delta = delta_root * delta_root * delta_root * delta_root;
00306 float newX = (1.0f - delta) * sword_x + 762.0f * delta;
00307 float newY = (1.0f - delta) * sword_y + 310.0f * delta;
00308
00309 VideoManager->Move(512.0f, 385.0f);
00310 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
00311 VideoManager->DrawImage(_boot_images[1]);
00312 VideoManager->Move(512.0f, 385.0f);
00313 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
00314 VideoManager->DrawImage(_boot_images[3]);
00315 VideoManager->Move(newX, newY);
00316 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
00317 VideoManager->DrawImage(_boot_images[2]);
00318 }
00319
00320 else if (total_time >= SEQUENCE_SIX && total_time < SEQUENCE_SEVEN)
00321 {
00322
00323 float delta = (total_time - SEQUENCE_SIX) / (SEQUENCE_SEVEN - SEQUENCE_SIX);
00324 delta = 1.0f - delta * delta;
00325 VideoManager->EnableFog(Color::white, delta);
00326 _DrawBackgroundItems();
00327 }
00328 else if (total_time >= SEQUENCE_SEVEN)
00329 {
00330 _EndOpeningAnimation();
00331 _DrawBackgroundItems();
00332 }
00333 }
00334
00335
00336
00337 void BootMode::_DrawBackgroundItems() {
00338 VideoManager->Move(512.0f, 384.0f);
00339 VideoManager->SetDrawFlags(VIDEO_NO_BLEND, 0);
00340 VideoManager->DrawImage(_boot_images[0]);
00341
00342 VideoManager->Move(512.0f, 648.0f);
00343 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
00344 VideoManager->DrawImage(_boot_images[1]);
00345
00346 VideoManager->Move(762.0f, 578.0f);
00347 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
00348 VideoManager->DrawImage(_boot_images[2]);
00349
00350 VideoManager->Move(512, 648);
00351 VideoManager->SetDrawFlags(VIDEO_BLEND, 0);
00352 VideoManager->DrawImage(_boot_images[3]);
00353 }
00354
00355
00356
00357 void BootMode::_EndOpeningAnimation() {
00358 VideoManager->DisableFog();
00359
00360
00361 _boot_music.at(1).SetFadeOutTime(1000);
00362 _boot_music.at(1).StopMusic();
00363 _boot_music.at(0).SetFadeInTime(5000);
00364 _boot_music.at(0).PlayMusic();
00365
00366
00367 ReadScriptDescriptor settings_lua;
00368 if (!settings_lua.OpenFile("dat/config/settings.lua")) {
00369 cout << "BOOT ERROR: failed to load the settings file!" << endl;
00370 }
00371 welcome = settings_lua.ReadInt("welcome");
00372 settings_lua.CloseFile();
00373 if (welcome) {
00374 _welcome_screen.Show();
00375 }
00376
00377 _logo_animating = false;
00378 }
00379
00380
00381
00382 SDLKey BootMode::_WaitKeyPress() {
00383 SDL_Event event;
00384 while (SDL_WaitEvent(&event)) {
00385 if (event.type == SDL_KEYDOWN)
00386 return event.key.keysym.sym;
00387 }
00388
00389 return event.key.keysym.sym;
00390 }
00391
00392
00393
00394 uint8 BootMode::_WaitJoyPress() {
00395 SDL_Event event;
00396 while (SDL_WaitEvent(&event)) {
00397 if (event.type == SDL_JOYBUTTONDOWN)
00398 return event.jbutton.button;
00399 }
00400
00401 return event.jbutton.button;
00402 }
00403
00404
00405
00406 void BootMode::_RedefineUpKey() {
00407 InputManager->SetUpKey(_WaitKeyPress());
00408 _UpdateKeySettings();
00409 }
00410
00411 void BootMode::_RedefineDownKey() {
00412 InputManager->SetDownKey(_WaitKeyPress());
00413 _UpdateKeySettings();
00414 }
00415
00416 void BootMode::_RedefineLeftKey() {
00417 InputManager->SetLeftKey(_WaitKeyPress());
00418 _UpdateKeySettings();
00419 }
00420
00421 void BootMode::_RedefineRightKey() {
00422 InputManager->SetRightKey(_WaitKeyPress());
00423 _UpdateKeySettings();
00424 }
00425
00426 void BootMode::_RedefineConfirmKey() {
00427 InputManager->SetConfirmKey(_WaitKeyPress());
00428 _UpdateKeySettings();
00429 }
00430
00431 void BootMode::_RedefineCancelKey() {
00432 InputManager->SetCancelKey(_WaitKeyPress());
00433 _UpdateKeySettings();
00434 }
00435
00436 void BootMode::_RedefineMenuKey() {
00437 InputManager->SetMenuKey(_WaitKeyPress());
00438 _UpdateKeySettings();
00439 }
00440
00441 void BootMode::_RedefineSwapKey() {
00442 InputManager->SetSwapKey(_WaitKeyPress());
00443 _UpdateKeySettings();
00444 }
00445
00446 void BootMode::_RedefineLeftSelectKey() {
00447 InputManager->SetLeftSelectKey(_WaitKeyPress());
00448 _UpdateKeySettings();
00449 }
00450
00451 void BootMode::_RedefineRightSelectKey() {
00452 InputManager->SetRightSelectKey(_WaitKeyPress());
00453 _UpdateKeySettings();
00454 }
00455
00456 void BootMode::_RedefinePauseKey() {
00457 InputManager->SetPauseKey(_WaitKeyPress());
00458 _UpdateKeySettings();
00459 }
00460
00461
00462
00463 void BootMode::_RedefineConfirmJoy() {
00464 InputManager->SetConfirmJoy(_WaitJoyPress());
00465 _UpdateJoySettings();
00466 }
00467 void BootMode::_RedefineCancelJoy() {
00468 InputManager->SetCancelJoy(_WaitJoyPress());
00469 _UpdateJoySettings();
00470 }
00471 void BootMode::_RedefineMenuJoy() {
00472 InputManager->SetMenuJoy(_WaitJoyPress());
00473 _UpdateJoySettings();
00474 }
00475 void BootMode::_RedefineSwapJoy() {
00476 InputManager->SetSwapJoy(_WaitJoyPress());
00477 _UpdateJoySettings();
00478 }
00479 void BootMode::_RedefineLeftSelectJoy() {
00480 InputManager->SetLeftSelectJoy(_WaitJoyPress());
00481 _UpdateJoySettings();
00482 }
00483 void BootMode::_RedefineRightSelectJoy() {
00484 InputManager->SetRightSelectJoy(_WaitJoyPress());
00485 _UpdateJoySettings();
00486 }
00487 void BootMode::_RedefinePauseJoy() {
00488 InputManager->SetPauseJoy(_WaitJoyPress());
00489 _UpdateJoySettings();
00490 }
00491
00492
00493
00494 void BootMode::_SetupMainMenu() {
00495
00496
00497 _main_menu.AddOption(MakeUnicodeString("New Game"), &BootMode::_OnNewGame);
00498 _main_menu.AddOption(MakeUnicodeString("Load Game"), &BootMode::_OnLoadGame);
00499 _main_menu.AddOption(MakeUnicodeString("Options"), &BootMode::_OnOptions);
00500 _main_menu.AddOption(MakeUnicodeString("Credits"), &BootMode::_OnCredits);
00501 _main_menu.AddOption(MakeUnicodeString("Quit"), &BootMode::_OnQuit);
00502
00503 _main_menu.AddOption(MakeUnicodeString("Battle"), &BootMode::_OnBattleDebug);
00504 _main_menu.AddOption(MakeUnicodeString("Menu"), &BootMode::_OnMenuDebug);
00505 _main_menu.AddOption(MakeUnicodeString("Shop"), &BootMode::_OnShopDebug);
00506 }
00507
00508
00509
00510 void BootMode::_SetupOptionsMenu() {
00511 _options_menu.AddOption(MakeUnicodeString("Video"), &BootMode::_OnVideoOptions);
00512 _options_menu.AddOption(MakeUnicodeString("Audio"), &BootMode::_OnAudioOptions);
00513 _options_menu.AddOption(MakeUnicodeString("Language"));
00514 _options_menu.AddOption(MakeUnicodeString("Key Settings"), &BootMode::_OnKeySettings);
00515 _options_menu.AddOption(MakeUnicodeString("Joystick Settings"), &BootMode::_OnJoySettings);
00516
00517
00518 _options_menu.EnableOption(2, false);
00519
00520 _options_menu.SetWindowed(true);
00521 _options_menu.SetParent(&_main_menu);
00522 }
00523
00524
00525
00526 void BootMode::_SetupVideoOptionsMenu()
00527 {
00528 _video_options_menu.AddOption(MakeUnicodeString("Resolution:"), &BootMode::_OnResolution);
00529 _video_options_menu.AddOption(MakeUnicodeString("Window mode:"), &BootMode::_OnVideoMode, &BootMode::_OnVideoMode, &BootMode::_OnVideoMode);
00530 _video_options_menu.AddOption(MakeUnicodeString("Brightness:"), 0, &BootMode::_OnBrightnessLeft, &BootMode::_OnBrightnessRight);
00531 _video_options_menu.AddOption(MakeUnicodeString("Image quality:"));
00532
00533 _video_options_menu.EnableOption(3, false);
00534 _video_options_menu.SetWindowed(true);
00535 _video_options_menu.SetParent(&_options_menu);
00536 }
00537
00538
00539
00540 void BootMode::_SetupAudioOptionsMenu()
00541 {
00542 _audio_options_menu.AddOption(MakeUnicodeString("Sound Volume: "), 0, &BootMode::_OnSoundLeft, &BootMode::_OnSoundRight);
00543 _audio_options_menu.AddOption(MakeUnicodeString("Music Volume: "), 0, &BootMode::_OnMusicLeft, &BootMode::_OnMusicRight);
00544 _audio_options_menu.SetWindowed(true);
00545 _audio_options_menu.SetParent(&_options_menu);
00546 }
00547
00548
00549
00550 void BootMode::_SetupKeySetttingsMenu() {
00551 _key_settings_menu.AddOption(MakeUnicodeString("Up: "), &BootMode::_RedefineUpKey);
00552 _key_settings_menu.AddOption(MakeUnicodeString("Down: "), &BootMode::_RedefineDownKey);
00553 _key_settings_menu.AddOption(MakeUnicodeString("Left: "), &BootMode::_RedefineLeftKey);
00554 _key_settings_menu.AddOption(MakeUnicodeString("Right: "), &BootMode::_RedefineRightKey);
00555 _key_settings_menu.AddOption(MakeUnicodeString("Confirm: "), &BootMode::_RedefineConfirmKey);
00556 _key_settings_menu.AddOption(MakeUnicodeString("Cancel: "), &BootMode::_RedefineCancelKey);
00557 _key_settings_menu.AddOption(MakeUnicodeString("Menu: "), &BootMode::_RedefineMenuKey);
00558 _key_settings_menu.AddOption(MakeUnicodeString("Swap: "), &BootMode::_RedefineSwapKey);
00559 _key_settings_menu.AddOption(MakeUnicodeString("Left Select: "), &BootMode::_RedefineLeftSelectKey);
00560 _key_settings_menu.AddOption(MakeUnicodeString("Right Select: "), &BootMode::_RedefineRightSelectKey);
00561 _key_settings_menu.AddOption(MakeUnicodeString("Pause: "), &BootMode::_RedefinePauseKey);
00562
00563 _key_settings_menu.AddOption(MakeUnicodeString("Restore defaults"), &BootMode::_OnRestoreDefaultKeys);
00564 _key_settings_menu.SetWindowed(true);
00565 _key_settings_menu.SetParent(&_options_menu);
00566 _key_settings_menu.SetTextDensity(30.0f);
00567 }
00568
00569
00570 void BootMode::_SetupJoySetttingsMenu() {
00571 _joy_settings_menu.AddOption(MakeUnicodeString("Confirm: "), &BootMode::_RedefineConfirmJoy);
00572 _joy_settings_menu.AddOption(MakeUnicodeString("Cancel: "), &BootMode::_RedefineCancelJoy);
00573 _joy_settings_menu.AddOption(MakeUnicodeString("Menu: "), &BootMode::_RedefineMenuJoy);
00574 _joy_settings_menu.AddOption(MakeUnicodeString("Swap: "), &BootMode::_RedefineSwapJoy);
00575 _joy_settings_menu.AddOption(MakeUnicodeString("Left Select: "), &BootMode::_RedefineLeftSelectJoy);
00576 _joy_settings_menu.AddOption(MakeUnicodeString("Right Select: "), &BootMode::_RedefineRightSelectJoy);
00577 _joy_settings_menu.AddOption(MakeUnicodeString("Pause: "), &BootMode::_RedefinePauseJoy);
00578
00579 _joy_settings_menu.AddOption(MakeUnicodeString("Restore defaults"), &BootMode::_OnRestoreDefaultJoyButtons);
00580 _joy_settings_menu.SetWindowed(true);
00581 _joy_settings_menu.SetParent(&_options_menu);
00582 _joy_settings_menu.SetTextDensity(40.0f);
00583 }
00584
00585
00586 void BootMode::_SetupResolutionMenu() {
00587 _resolution_menu.AddOption(MakeUnicodeString("640 x 480"), &BootMode::_OnResolution640x480);
00588 _resolution_menu.AddOption(MakeUnicodeString("800 x 600"), &BootMode::_OnResolution800x600);
00589 _resolution_menu.AddOption(MakeUnicodeString("1024 x 768"), &BootMode::_OnResolution1024x768);
00590 _resolution_menu.SetParent(&_video_options_menu);
00591 _resolution_menu.SetWindowed(true);
00592 }
00593
00594
00595
00596
00597 void BootMode::_OnNewGame() {
00598 if (BOOT_DEBUG) cout << "BOOT: Starting new game." << endl;
00599
00600 _SaveSettingsFile();
00601
00602 GlobalManager->AddCharacter(GLOBAL_CHARACTER_CLAUDIUS);
00603 GlobalManager->AddCharacter(GLOBAL_CHARACTER_LAILA);
00604 GlobalManager->AddToInventory(1, 2);
00605 GlobalManager->SetDrunes(250);
00606
00607 _fade_out = true;
00608 VideoManager->FadeScreen(Color::black, 1.0f);
00609 _boot_music.at(0).SetFadeOutTime(500);
00610 _boot_music.at(0).StopMusic();
00611 }
00612
00613
00614
00615 void BootMode::_OnLoadGame() {
00616 if (BOOT_DEBUG) cout << "BOOT: Loading game." << endl;
00617
00618 if (DoesFileExist("dat/saved_game.lua")) {
00619 _SaveSettingsFile();
00620
00621 GlobalManager->LoadGame("dat/saved_game.lua");
00622 _fade_out = true;
00623 VideoManager->FadeScreen(Color::black, 1.0f);
00624 _boot_music.at(0).SetFadeOutTime(500);
00625 _boot_music.at(0).StopMusic();
00626 }
00627 else {
00628 cout << "BOOT: No saved game file exists, can not load game" << endl;
00629 }
00630 }
00631
00632
00633
00634 void BootMode::_OnOptions() {
00635 _current_menu = &_options_menu;
00636 _has_modified_settings = true;
00637 }
00638
00639
00640
00641 void BootMode::_OnCredits() {
00642 _credits_screen.Show();
00643 }
00644
00645
00646
00647 void BootMode::_OnQuit() {
00648
00649 _SaveSettingsFile();
00650 SystemManager->ExitGame();
00651 }
00652
00653
00654 void BootMode::_OnBattleDebug() {
00655 ModeManager->Pop();
00656 GlobalManager->AddCharacter(GLOBAL_CHARACTER_CLAUDIUS);
00657 BattleMode *BM = new BattleMode();
00658 BM->AddEnemy(101);
00659 BM->AddEnemy(102);
00660 ModeManager->Push(BM);
00661 }
00662
00663
00664 void BootMode::_OnMenuDebug() {
00665 ModeManager->Pop();
00666 GlobalManager->AddCharacter(GLOBAL_CHARACTER_CLAUDIUS);
00667 hoa_menu::MenuMode *MM = new hoa_menu::MenuMode(MakeUnicodeString("The Boot Screen"), "img/menus/locations/desert_cave.png");
00668 ModeManager->Push(MM);
00669 }
00670
00671
00672 void BootMode::_OnShopDebug() {
00673 GlobalManager->AddDrunes(500);
00674 hoa_shop::ShopMode *SM = new hoa_shop::ShopMode();
00675 ModeManager->Push(SM);
00676 }
00677
00678
00679
00680 void BootMode::_OnResolution() {
00681 _current_menu = &_resolution_menu;
00682 }
00683
00684
00685
00686 void BootMode::_OnVideoOptions()
00687 {
00688 _current_menu = &_video_options_menu;
00689 _UpdateVideoOptions();
00690 }
00691
00692
00693
00694 void BootMode::_OnAudioOptions()
00695 {
00696
00697 _current_menu = &_audio_options_menu;
00698 _UpdateAudioOptions();
00699 }
00700
00701
00702
00703 void BootMode::_OnKeySettings() {
00704 _current_menu = &_key_settings_menu;
00705 _UpdateKeySettings();
00706 }
00707
00708
00709
00710 void BootMode::_OnJoySettings() {
00711 _current_menu = &_joy_settings_menu;
00712 _UpdateJoySettings();
00713 }
00714
00715
00716
00717 void BootMode::_OnVideoMode() {
00718
00719 VideoManager->ToggleFullscreen();
00720 VideoManager->ApplySettings();
00721
00722 _UpdateVideoOptions();
00723 }
00724
00725
00726
00727 void BootMode::_OnSoundLeft() {
00728 AudioManager->SetSoundVolume(AudioManager->GetSoundVolume() - 0.1f);
00729 _UpdateAudioOptions();
00730 _boot_sounds.at(4).PlaySound();
00731 }
00732
00733
00734
00735 void BootMode::_OnSoundRight() {
00736 AudioManager->SetSoundVolume(AudioManager->GetSoundVolume() + 0.1f);
00737 _UpdateAudioOptions();
00738 _boot_sounds.at(4).PlaySound();
00739 }
00740
00741
00742
00743 void BootMode::_OnMusicLeft() {
00744 AudioManager->SetMusicVolume(AudioManager->GetMusicVolume() - 0.1f);
00745 _UpdateAudioOptions();
00746 }
00747
00748
00749
00750 void BootMode::_OnMusicRight() {
00751 AudioManager->SetMusicVolume(AudioManager->GetMusicVolume() + 0.1f);
00752 _UpdateAudioOptions();
00753 }
00754
00755
00756 void BootMode::_SetResolution(int32 width, int32 height) {
00757 VideoManager->SetResolution(width, height);
00758 VideoManager->ApplySettings();
00759 _current_menu = &_video_options_menu;
00760 _UpdateVideoOptions();
00761 }
00762
00763 void BootMode::_OnResolution640x480() {
00764 if (VideoManager->GetWidth() != 640 && VideoManager->GetHeight() != 480)
00765 _SetResolution(640, 480);
00766 }
00767
00768 void BootMode::_OnResolution800x600() {
00769 if (VideoManager->GetWidth() != 800 && VideoManager->GetHeight() != 600)
00770 _SetResolution(800, 600);
00771 }
00772
00773 void BootMode::_OnResolution1024x768() {
00774 if (VideoManager->GetWidth() != 1024 && VideoManager->GetHeight() != 768)
00775 _SetResolution(1024, 768);
00776 }
00777
00778
00779 void BootMode::_OnBrightnessLeft() {
00780 VideoManager->SetGamma(VideoManager->GetGamma() - 0.1f);
00781 _UpdateVideoOptions();
00782 }
00783
00784
00785 void BootMode::_OnBrightnessRight() {
00786 VideoManager->SetGamma(VideoManager->GetGamma() + 0.1f);
00787 _UpdateVideoOptions();
00788 }
00789
00790
00791
00792 void BootMode::_OnRestoreDefaultKeys() {
00793 InputManager->RestoreDefaultKeys();
00794 _UpdateKeySettings();
00795 }
00796
00797
00798
00799 void BootMode::_OnRestoreDefaultJoyButtons() {
00800 InputManager->RestoreDefaultJoyButtons();
00801 _UpdateJoySettings();
00802 }
00803
00804
00805
00806 void BootMode::_UpdateVideoOptions() {
00807
00808 std::ostringstream resolution("");
00809 resolution << "Resolution: " << VideoManager->GetWidth() << " x " << VideoManager->GetHeight();
00810 _video_options_menu.SetOptionText(0, MakeUnicodeString(resolution.str()));
00811
00812
00813 if (VideoManager->IsFullscreen())
00814 _video_options_menu.SetOptionText(1, MakeUnicodeString("Window mode: fullscreen"));
00815 else
00816 _video_options_menu.SetOptionText(1, MakeUnicodeString("Window mode: windowed"));
00817
00818
00819 _video_options_menu.SetOptionText(2, MakeUnicodeString("Brightness: " + NumberToString(VideoManager->GetGamma() * 50.0f + 0.5f) + " %"));
00820 }
00821
00822
00823
00824 void BootMode::_UpdateAudioOptions() {
00825 std::ostringstream sound_volume("");
00826 sound_volume << "Sound Volume: " << static_cast<int32>(AudioManager->GetSoundVolume() * 100.0f + 0.5f) << " %";
00827
00828 std::ostringstream music_volume("");
00829 music_volume << "Music Volume: " << static_cast<int32>(AudioManager->GetMusicVolume() * 100.0f + 0.5f) << " %";
00830
00831 _audio_options_menu.SetOptionText(0, MakeUnicodeString(sound_volume.str()));
00832 _audio_options_menu.SetOptionText(1, MakeUnicodeString(music_volume.str()));
00833 }
00834
00835
00836
00837 void BootMode::_UpdateKeySettings() {
00838
00839 _key_settings_menu.SetOptionText(0, MakeUnicodeString("Move Up: " + InputManager->GetUpKeyName()));
00840 _key_settings_menu.SetOptionText(1, MakeUnicodeString("Move Down: " + InputManager->GetDownKeyName()));
00841 _key_settings_menu.SetOptionText(2, MakeUnicodeString("Move Left: " + InputManager->GetLeftKeyName()));
00842 _key_settings_menu.SetOptionText(3, MakeUnicodeString("Move Right: " + InputManager->GetRightKeyName()));
00843 _key_settings_menu.SetOptionText(4, MakeUnicodeString("Confirm: " + InputManager->GetConfirmKeyName()));
00844 _key_settings_menu.SetOptionText(5, MakeUnicodeString("Cancel: " + InputManager->GetCancelKeyName()));
00845 _key_settings_menu.SetOptionText(6, MakeUnicodeString("Menu: " + InputManager->GetMenuKeyName()));
00846 _key_settings_menu.SetOptionText(7, MakeUnicodeString("Swap: " + InputManager->GetSwapKeyName()));
00847 _key_settings_menu.SetOptionText(8, MakeUnicodeString("Left Select: " + InputManager->GetLeftSelectKeyName()));
00848 _key_settings_menu.SetOptionText(9, MakeUnicodeString("Right Select: " + InputManager->GetRightSelectKeyName()));
00849 _key_settings_menu.SetOptionText(10, MakeUnicodeString("Pause: " + InputManager->GetPauseKeyName()));
00850 }
00851
00852
00853 void BootMode::_UpdateJoySettings() {
00854 _joy_settings_menu.SetOptionText(0, MakeUnicodeString("Confirm: Button " + NumberToString(InputManager->GetConfirmJoy())));
00855 _joy_settings_menu.SetOptionText(1, MakeUnicodeString("Cancel: Button " + NumberToString(InputManager->GetCancelJoy())));
00856 _joy_settings_menu.SetOptionText(2, MakeUnicodeString("Menu: Button " + NumberToString(InputManager->GetMenuJoy())));
00857 _joy_settings_menu.SetOptionText(3, MakeUnicodeString("Swap: Button " + NumberToString(InputManager->GetSwapJoy())));
00858 _joy_settings_menu.SetOptionText(4, MakeUnicodeString("Left Select : Button " + NumberToString(InputManager->GetLeftSelectJoy())));
00859 _joy_settings_menu.SetOptionText(5, MakeUnicodeString("Right Select: Button " + NumberToString(InputManager->GetRightSelectJoy())));
00860 _joy_settings_menu.SetOptionText(6, MakeUnicodeString("Pause: Button " + NumberToString(InputManager->GetPauseJoy())));
00861 }
00862
00863
00864
00865 void BootMode::_SaveSettingsFile() {
00866
00867
00868
00869
00870 return;
00871
00872
00873 ModifyScriptDescriptor settings_lua;
00874 if (!settings_lua.OpenFile("dat/config/settings.lua")) {
00875 cout << "BOOT ERROR: failed to load the settings file!" << endl;
00876 }
00877
00878
00879
00880 settings_lua.ModifyInt("video_settings.screen_resx", VideoManager->GetWidth());
00881 settings_lua.ModifyInt("video_settings.screen_resy", VideoManager->GetHeight());
00882 settings_lua.ModifyString("video_settings.full_screen", VideoManager->IsFullscreen() ? "true" : "false");
00883 settings_lua.ModifyFloat("video_settings.brightness", VideoManager->GetGamma());
00884
00885
00886 settings_lua.ModifyFloat("audio_settings.music_vol", AudioManager->GetMusicVolume());
00887 settings_lua.ModifyFloat("audio_settings.sound_vol", AudioManager->GetSoundVolume());
00888
00889
00890 settings_lua.ModifyInt("key_settings.up", InputManager->GetUpKey());
00891 settings_lua.ModifyInt("key_settings.down", InputManager->GetDownKey());
00892 settings_lua.ModifyInt("key_settings.left", InputManager->GetLeftKey());
00893 settings_lua.ModifyInt("key_settings.right", InputManager->GetRightKey());
00894 settings_lua.ModifyInt("key_settings.confirm", InputManager->GetConfirmKey());
00895 settings_lua.ModifyInt("key_settings.cancel", InputManager->GetCancelKey());
00896 settings_lua.ModifyInt("key_settings.menu", InputManager->GetMenuKey());
00897 settings_lua.ModifyInt("key_settings.swap", InputManager->GetSwapKey());
00898 settings_lua.ModifyInt("key_settings.left_select", InputManager->GetLeftSelectKey());
00899 settings_lua.ModifyInt("key_settings.right_select", InputManager->GetRightSelectKey());
00900 settings_lua.ModifyInt("key_settings.pause", InputManager->GetPauseKey());
00901 settings_lua.ModifyInt("joystick_settings.confirm", InputManager->GetConfirmJoy());
00902 settings_lua.ModifyInt("joystick_settings.cancel", InputManager->GetCancelJoy());
00903 settings_lua.ModifyInt("joystick_settings.menu", InputManager->GetMenuJoy());
00904 settings_lua.ModifyInt("joystick_settings.swap", InputManager->GetSwapJoy());
00905 settings_lua.ModifyInt("joystick_settings.left_select", InputManager->GetLeftSelectJoy());
00906 settings_lua.ModifyInt("joystick_settings.right_select", InputManager->GetRightSelectJoy());
00907 settings_lua.ModifyInt("joystick_settings.pause", InputManager->GetPauseJoy());
00908
00909
00910 settings_lua.CommitChanges();
00911 }
00912
00913
00914
00915 void BootMode::Update() {
00916 uint32 time_elapsed = SystemManager->GetUpdateTime();
00917
00918
00919 if (_fade_out)
00920 {
00921
00922 if (!VideoManager->IsFading()) {
00923 ModeManager->Pop();
00924 MapMode *MM = new MapMode("dat/maps/demo_town.lua");
00925 ModeManager->Push(MM);
00926 VideoManager->FadeScreen(Color::clear, 1.0f);
00927 }
00928 return;
00929 }
00930 else if (_logo_animating)
00931 {
00932 if (InputManager->AnyKeyPress())
00933 {
00934 _EndOpeningAnimation();
00935 return;
00936 }
00937 else
00938 {
00939 return;
00940 }
00941 }
00942
00943
00944 BootMenu::UpdateWindow(time_elapsed);
00945
00946
00947 _credits_screen.UpdateWindow(time_elapsed);
00948
00949
00950 if (_welcome_screen.IsVisible())
00951 {
00952 if (InputManager->AnyKeyPress())
00953 {
00954 _boot_sounds.at(0).PlaySound();
00955 welcome = 0;
00956 _welcome_screen.Hide();
00957
00958
00959 string line = "";
00960 fstream settings_file("dat/config/settings.lua");
00961 if (settings_file.is_open()) {
00962 while (!settings_file.eof() && line != "welcome = 1;")
00963 getline(settings_file, line);
00964 settings_file.seekp(-3, ios::cur);
00965 settings_file.put('0');
00966 settings_file.close();
00967 }
00968 else
00969 cout << "BOOT ERROR: failed to load the settings file!" << endl;
00970 }
00971
00972 return;
00973 }
00974
00975
00976 if (InputManager->ConfirmPress() && !_credits_screen.IsVisible())
00977 {
00978
00979 if (_current_menu->IsSelectionEnabled())
00980 _boot_sounds.at(0).PlaySound();
00981 else
00982 _boot_sounds.at(3).PlaySound();
00983
00984 _current_menu->ConfirmPressed();
00985
00986
00987 if (_current_menu->IsWindowed())
00988 {
00989 BootMenu::ShowWindow(true);
00990 }
00991 else
00992 {
00993 BootMenu::ShowWindow(false);
00994 }
00995 }
00996 else if (InputManager->LeftPress() && !_credits_screen.IsVisible())
00997 {
00998 _current_menu->LeftPressed();
00999 }
01000 else if(InputManager->RightPress() && !_credits_screen.IsVisible())
01001 {
01002 _current_menu->RightPressed();
01003 }
01004 else if(InputManager->UpPress() && !_credits_screen.IsVisible())
01005 {
01006 _current_menu->UpPressed();
01007 }
01008 else if(InputManager->DownPress() && !_credits_screen.IsVisible())
01009 {
01010 _current_menu->DownPressed();
01011 }
01012 else if(InputManager->CancelPress())
01013 {
01014
01015 if (_credits_screen.IsVisible())
01016 {
01017 _credits_screen.Hide();
01018 _boot_sounds.at(1).PlaySound();
01019 }
01020
01021
01022 _current_menu->CancelPressed();
01023
01024
01025 if (_current_menu->GetParent() != 0)
01026 {
01027
01028 _boot_sounds.at(1).PlaySound();
01029
01030
01031 _current_menu = _current_menu->GetParent();
01032
01033
01034 if (_current_menu->IsWindowed())
01035 BootMenu::ShowWindow(true);
01036 else
01037 BootMenu::ShowWindow(false);
01038 }
01039 }
01040
01041
01042 _current_menu->GetEvent();
01043 }
01044
01045
01046
01047 void BootMode::Draw() {
01048
01049
01050 if (_logo_animating)
01051 {
01052 _AnimateLogo();
01053 return;
01054 }
01055
01056 _DrawBackgroundItems();
01057
01058
01059 if (_credits_screen.IsVisible())
01060 _credits_screen.Draw();
01061 else if (_welcome_screen.IsVisible())
01062 _welcome_screen.Draw();
01063 else
01064 _current_menu->Draw();
01065
01066 if (!_latest_version)
01067 {
01068 VideoManager->SetTextColor(Color::green);
01069 VideoManager->Move(482.0f, 553.0f);
01070 VideoManager->DrawText("New version available from allacrost.org: " + _latest_version_number);
01071 }
01072
01073 VideoManager->Move(65.0f, 10.0f);
01074 VideoManager->SetFont("default");
01075 VideoManager->SetTextColor(Color::gray);
01076 VideoManager->DrawText("Tech Demo");
01077 VideoManager->MoveRelative(730.0f, 0.0f);
01078 VideoManager->DrawText("Copyright (C) 2004 - 2007 The Allacrost Project");
01079 }
01080
01081
01082 }