00001
00002
00003
00004
00005
00006
00007
00009
00016 #include <iostream>
00017
00018 #include "utils.h"
00019 #include "audio.h"
00020 #include "video.h"
00021 #include "input.h"
00022 #include "system.h"
00023
00024 #include "quit.h"
00025 #include "boot.h"
00026
00027 using namespace std;
00028 using namespace hoa_quit::private_quit;
00029 using namespace hoa_audio;
00030 using namespace hoa_video;
00031 using namespace hoa_mode_manager;
00032 using namespace hoa_input;
00033 using namespace hoa_system;
00034 using namespace hoa_boot;
00035 using namespace hoa_utils;
00036
00037 namespace hoa_quit {
00038
00039 bool QUIT_DEBUG = false;
00040
00041 QuitMode::QuitMode() {
00042 if (QUIT_DEBUG) cout << "QUIT: QuitMode constructor invoked" << endl;
00043 mode_type = MODE_MANAGER_QUIT_MODE;
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 if (!VideoManager->CaptureScreen(_saved_screen))
00063 if (QUIT_DEBUG) cerr << "PAUSE: ERROR: Couldn't save the screen!" << endl;
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 _option_box.SetFont("default");
00074 _option_box.SetCellSize(250.0f, 50.0f);
00075 _option_box.SetSize(3, 1);
00076 _option_box.SetPosition(512.0f, 384.0f);
00077 _option_box.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
00078 _option_box.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
00079 _option_box.SetSelectMode(VIDEO_SELECT_SINGLE);
00080 _option_box.SetCursorOffset(-58.0f, 18.0f);
00081
00082 vector<ustring> options;
00083 options.push_back(MakeUnicodeString("Quit Game"));
00084 options.push_back(MakeUnicodeString("Quit to Main Menu"));
00085 options.push_back(MakeUnicodeString("Cancel"));
00086
00087 _option_box.SetOptions(options);
00088 _option_box.SetSelection(QUIT_CANCEL);
00089 }
00090
00091
00092
00093
00094 QuitMode::~QuitMode() {
00095 if (QUIT_DEBUG) cout << "QUIT: QuitMode destructor invoked" << endl;
00096
00097
00098 VideoManager->DeleteImage(_saved_screen);
00099 }
00100
00101
00102
00103 void QuitMode::Reset() {
00104 _quit_type = QUIT_CANCEL;
00105
00106
00107 VideoManager->SetCoordSys(0, 1024, 0, 768);
00108 if(!VideoManager->SetFont("default"))
00109 cerr << "MAP: ERROR > Couldn't set map font!" << endl;
00110 VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_BOTTOM, VIDEO_BLEND, 0);
00111
00112 }
00113
00114
00115
00116 void QuitMode::Update() {
00117 uint32 time_elapsed = SystemManager->GetUpdateTime();
00118
00119
00120
00121 if (InputManager->LeftPress())
00122 _option_box.HandleLeftKey();
00123 else if(InputManager->RightPress())
00124 _option_box.HandleRightKey();
00125 else if(InputManager->CancelPress())
00126 _option_box.HandleCancelKey();
00127 else if(InputManager->ConfirmPress())
00128 _option_box.HandleConfirmKey();
00129
00130
00131
00132 int32 event = _option_box.GetEvent();
00133 int32 selection = _option_box.GetSelection();
00134
00135 if(event == VIDEO_OPTION_CONFIRM)
00136 {
00137 switch(selection)
00138 {
00139 case QUIT_GAME:
00140 _QuitGame();
00141 break;
00142 case QUIT_TO_BOOTMENU:
00143 _QuitToBootMenu();
00144 break;
00145 case QUIT_CANCEL:
00146 _Cancel();
00147 break;
00148 default:
00149 {
00150 if(QUIT_DEBUG)
00151 cerr << "QUIT ERROR: received confirm event, but option box selection was invalid" << endl;
00152 break;
00153 }
00154 };
00155 }
00156 else if(event == VIDEO_OPTION_CANCEL)
00157 {
00158 _Cancel();
00159 }
00160
00161
00162 _option_box.Update(time_elapsed);
00163
00164
00165
00166 SDL_Delay(50);
00167 }
00168
00169
00170
00171
00172 void QuitMode::Draw() {
00173
00174
00175 int32 width = VideoManager->GetWidth();
00176 int32 height = VideoManager->GetHeight();
00177 VideoManager->SetCoordSys (0.0f, static_cast<float>(width), 0.0f, static_cast<float>(height));
00178
00179 VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_BOTTOM, 0);
00180 Color grayed(0.35f, 0.35f, 0.35f, 1.0f);
00181 VideoManager->Move(0, 0);
00182 VideoManager->DrawImage(_saved_screen, grayed);
00183
00184
00185
00186 VideoManager->SetCoordSys (0.0f, 1024.0f, 0.0f, 768.0f);
00187
00188 VideoManager->Move(512, 384);
00189 VideoManager->SetDrawFlags(VIDEO_X_CENTER, VIDEO_Y_CENTER, 0);
00190 VideoManager->DrawImage(_quit_menu);
00191
00192 _option_box.Draw();
00193 }
00194
00195
00196
00197 void QuitMode::_QuitGame() {
00198
00199 SystemManager->ExitGame();
00200 }
00201
00202
00203
00204 void QuitMode::_QuitToBootMenu() {
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218 ModeManager->PopAll();
00219 BootMode *BM = new BootMode();
00220 ModeManager->Push(BM);
00221 }
00222
00223
00224
00225 void QuitMode::_Cancel() {
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238 TEMP_HandlePause();
00239 ModeManager->Pop();
00240 }
00241
00242 }