battle_windows.cpp

Go to the documentation of this file.
00001 
00002 //            Copyright (C) 2004-2007 by The Allacrost Project
00003 //                         All Rights Reserved
00004 //
00005 // This code is licensed under the GNU GPL version 2. It is free software and
00006 // you may modify it and/or redistribute it under the terms of this license.
00007 // See http://www.gnu.org/copyleft/gpl.html for details.
00009 
00016 #include "utils.h"
00017 #include "defs.h"
00018 
00019 #include "audio.h"
00020 #include "video.h"
00021 #include "input.h"
00022 #include "system.h"
00023 #include "global.h"
00024 
00025 #include "battle.h"
00026 #include "battle_actors.h"
00027 
00028 using namespace std;
00029 
00030 using namespace hoa_utils;
00031 
00032 using namespace hoa_audio;
00033 using namespace hoa_video;
00034 using namespace hoa_input;
00035 using namespace hoa_system;
00036 using namespace hoa_global;
00037 
00038 namespace hoa_battle {
00039 
00040 namespace private_battle {
00041 
00042 // *****************************************************************************
00043 // ActionWindow class
00044 // *****************************************************************************
00045 
00046 ActionWindow::ActionWindow() {
00047   // TODO: declare the MenuSkin to be used
00048   if (MenuWindow::Create(512.0f, 128.0f) == false) {
00049     cerr << "BATTLE ERROR: In ActionWindow constructor, the call to MenuWindow::Create() failed" << endl;
00050   }
00051   MenuWindow::SetPosition(512.0f, 128.0f);
00052   MenuWindow::SetAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
00053 
00054 
00055   // NOTE: may need to set the dimensions of these images to 45, 45
00056   _action_category_icons.resize(4);
00057   _action_category_icons[0].SetFilename("img/icons/battle/attack.png");
00058   _action_category_icons[1].SetFilename("img/icons/battle/defend.png");
00059   _action_category_icons[2].SetFilename("img/icons/battle/support.png");
00060   _action_category_icons[3].SetFilename("img/icons/battle/item.png");
00061   for (uint32 i = 0; i < 4; i++) {
00062     if (VideoManager->LoadImage(_action_category_icons[i]) == false) {
00063       cerr << "BATTLE ERROR: In ActionWindow constructor, failed to load action category icon: "
00064         << _action_category_icons[i].GetFilename() << endl;
00065       return;
00066     }
00067   }
00068 
00069   // Setup options for VIEW_ACTION_CATEGORY
00070   vector<ustring> category_options;
00071   category_options.push_back(MakeUnicodeString("<img/icons/battle/attack.png><60>Attack"));
00072   category_options.push_back(MakeUnicodeString("<img/icons/battle/defend.png><60>Defend"));
00073   category_options.push_back(MakeUnicodeString("<img/icons/battle/support.png><60>Support"));
00074   category_options.push_back(MakeUnicodeString("<img/icons/battle/item.png><60>Item"));
00075 
00076   _action_category_list.SetOptions(category_options);
00077   _action_category_list.SetPosition(50.0f, 100.0f);
00078   _action_category_list.SetCursorOffset(-20.0f, 25.0f);
00079   _action_category_list.SetCellSize(100.0f, 80.0f);
00080   _action_category_list.SetSize(4, 1);
00081   _action_category_list.SetFont("battle");
00082   _action_category_list.SetAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
00083   _action_category_list.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
00084   _action_category_list.SetSelectMode(VIDEO_SELECT_SINGLE);
00085   _action_category_list.SetHorizontalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
00086   _action_category_list.SetSelection(0);
00087   _action_category_list.SetOwner(this);
00088 
00089   // Setup options for VIEW_ACTION_SELECTION
00090   _action_selection_list.SetPosition(128.0f, 128.0f);
00091   _action_selection_list.SetCursorOffset(-20.0f, 25.0f);
00092   _action_selection_list.SetCellSize(200.0f, 35.0f);
00093   _action_selection_list.SetFont("battle");
00094   _action_selection_list.SetAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
00095   _action_selection_list.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
00096   _action_selection_list.SetSelectMode(VIDEO_SELECT_SINGLE);
00097   _action_selection_list.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
00098   _action_selection_list.SetOwner(this);
00099 
00100   // TODO: add rendered text generation methods for skill and item list headers
00101 
00102   // Setup options for VIEW_TARGET_SELECTION
00103 
00104   // Setup options for VIEW_ACTION_INFORMATION
00105   Reset();
00106 } // ActionWindow::ActionWindow()
00107 
00108 
00109 
00110 ActionWindow::~ActionWindow() {
00111   MenuWindow::Destroy();
00112 
00113   for (uint32 i = 0; i < _action_category_icons.size(); i++) {
00114     VideoManager->DeleteImage(_action_category_icons[i]);
00115   }
00116 }
00117 
00118 
00119 
00120 void ActionWindow::Initialize(BattleCharacterActor* character) {
00121   _character = character;
00122   if (character == NULL) {
00123     if (BATTLE_DEBUG)
00124       cerr << "BATTLE WARNING: In ActionWindow::Initialize(), a NULL character pointer was passed" << endl;
00125     _state = VIEW_INVALID;
00126     return;
00127   }
00128 
00129   MenuWindow::Show();
00130   _state = VIEW_ACTION_CATEGORY;
00131 
00132   // Disable action categories which have no skills, or where the inventory is empty
00133   if (_character->GetActor()->GetAttackSkills()->empty())
00134     _action_category_list.EnableOption(0, false);
00135   if (_character->GetActor()->GetDefenseSkills()->empty())
00136     _action_category_list.EnableOption(1, false);
00137   if (_character->GetActor()->GetSupportSkills()->empty())
00138     _action_category_list.EnableOption(2, false);
00139   // TEMP: inventory not ready yet from GlobalManager
00140   if (GlobalManager->GetInventoryItems()->empty())
00141     _action_category_list.EnableOption(3, false);
00142 
00143   // TODO: clear _action_selection_list of all options
00144 } // void ActionWindow::Initialize(BattleCharacterActor* character)
00145 
00146 
00147 
00148 void ActionWindow::Reset() {
00149   MenuWindow::Hide();
00150   _state = VIEW_INVALID;
00151   _character = NULL;
00152   _selected_action_category = 0;
00153   _selected_action = 0;
00154   _action_target_type = GLOBAL_TARGET_INVALID;
00155   _action_target_ally = false;
00156   _item_list.clear();
00157   _skill_list = NULL;
00158 }
00159 
00160 // ----- UPDATE METHODS
00161 
00162 void ActionWindow::Update() {
00163   MenuWindow::Update(SystemManager->GetUpdateTime());
00164 
00165   switch (_state) {
00166     case VIEW_ACTION_CATEGORY:
00167       _UpdateActionCategory();
00168       break;
00169     case VIEW_ACTION_SELECTION:
00170       _UpdateActionSelection();
00171       break;
00172     case VIEW_TARGET_SELECTION:
00173       _UpdateTargetSelection();
00174       break;
00175     case VIEW_ACTION_INFORMATION:
00176       _UpdateActionInformation();
00177       break;
00178     case VIEW_INVALID:
00179     case VIEW_TOTAL:
00180     default:
00181       if (BATTLE_DEBUG)
00182         cerr << "BATTLE ERROR: In ActionWindow::Update(), the window state was invalid: " << _state << endl;
00183       return;
00184   }
00185 }
00186 
00187 
00188 
00189 void ActionWindow::_UpdateActionCategory() {
00190   if (InputManager->LeftPress()) {
00191     _action_category_list.HandleLeftKey();
00192   }
00193   if (InputManager->RightPress()) {
00194     _action_category_list.HandleRightKey();
00195   }
00196   
00197   if (InputManager->ConfirmPress() ) {
00198     _selected_action_category = static_cast<uint32>(_action_category_list.GetSelection());
00199     _ConstructActionSelectionList();
00200     _state = VIEW_ACTION_SELECTION;
00201   }
00202   // TODO: implement cancel press ... what should it do?
00203   // else if (InputManager->CancelPress()) { ... }
00204 }
00205 
00206 
00207 
00208 void ActionWindow::_UpdateActionSelection() {
00209   if (InputManager->UpPress()) {
00210     _action_selection_list.HandleUpKey();
00211   }
00212   if (InputManager->DownPress()) {
00213     _action_selection_list.HandleDownKey();
00214   }
00215 
00216   // TODO: I want to move most of this code to a new BattleMode function called "SetInitialTarget()" that figures out what the target
00217   if (InputManager->ConfirmPress()) {
00218     // TODO: make a call to battle mode so it can select the appropriate target
00219     _selected_action = _action_selection_list.GetSelection();
00220     _state = VIEW_TARGET_SELECTION;
00221 
00222     // TODO: if the target of the action is an entire party, display a list of all enemies in the window when in the VIEW_TARGET_SELECTION state
00223 
00224     if (_selected_action_category == ACTION_TYPE_ATTACK ||
00225       _selected_action_category == ACTION_TYPE_DEFEND ||
00226       _selected_action_category == ACTION_TYPE_SUPPORT)
00227     {
00228       _action_target_type = _skill_list->at(_selected_action)->GetTargetType();
00229       _action_target_ally = _skill_list->at(_selected_action)->IsTargetAlly();
00230       current_battle->_cursor_state = CURSOR_SELECT_TARGET;
00231       current_battle->_selected_target_index = current_battle->GetIndexOfFirstAliveEnemy();
00232       current_battle->_selected_target = current_battle->GetEnemyActorAt(current_battle->_selected_target_index);
00233     }
00234 
00235     else if (_selected_action_category == ACTION_TYPE_ITEM) {
00236       _action_target_type = _item_list[_selected_action]->GetTargetType();
00237       _action_target_ally = _item_list[_selected_action]->IsTargetAlly();
00238 
00239       // TEMP: Need to re-examine this later... make sure both helpful and hurtful items register properly
00240       current_battle->_cursor_state = CURSOR_SELECT_TARGET;
00241       current_battle->_selected_target_index = 0;
00242 
00243       // TODO: Use target type to select actor or party, and use cursor memory
00244       if (_action_target_ally)
00245         current_battle->_selected_target = current_battle->GetPlayerCharacterAt(0);
00246       else
00247         current_battle->_selected_target = current_battle->GetEnemyActorAt(current_battle->GetIndexOfFirstAliveEnemy());
00248     }
00249 
00250     else {
00251       if (BATTLE_DEBUG)
00252         cerr << "BATTLE WARNING: In ActionWindow::_UpdateActionSelection(), selected action category was invalid" << endl;
00253     }
00254   }
00255   else if (InputManager->MenuPress()) {
00256     _selected_action = _action_selection_list.GetSelection();
00257     _state = VIEW_ACTION_INFORMATION;
00258   }
00259   else if (InputManager->CancelPress()) {
00260     _state = VIEW_ACTION_CATEGORY;
00261     _skill_list = NULL;
00262     _item_list.clear();
00263   }
00264 } // void ActionWindow::_UpdateActionSelection()
00265 
00266 
00267 
00268 void ActionWindow::_UpdateTargetSelection() {
00269   if (InputManager->LeftPress() || InputManager->RightPress() || InputManager->UpPress() || InputManager->DownPress()) {
00270     // TODO: check if selected target has changed and if so, update window content
00271   }
00272 
00273   // TODO: depends
00274   else if (InputManager->CancelPress()) {
00275     _state = VIEW_ACTION_SELECTION;
00276   }
00277 
00278 }
00279 
00280 
00281 
00282 void ActionWindow::_UpdateActionInformation() {
00283   if (InputManager->MenuPress() || InputManager->CancelPress()) {
00284     _state = VIEW_ACTION_SELECTION;
00285   }
00286 }
00287 
00288 // ----- DRAW METHODS
00289 
00290 void ActionWindow::Draw() {
00291   MenuWindow::Draw();
00292 
00293   switch (_state) {
00294     case VIEW_ACTION_CATEGORY:
00295       _DrawActionCategory();
00296       break;
00297     case VIEW_ACTION_SELECTION:
00298       _DrawActionSelection();
00299       break;
00300     case VIEW_TARGET_SELECTION:
00301       _DrawTargetSelection();
00302       break;
00303     case VIEW_ACTION_INFORMATION:
00304       _DrawActionInformation();
00305       break;
00306     case VIEW_INVALID:
00307     case VIEW_TOTAL:
00308     default:
00309       if (BATTLE_DEBUG)
00310         cerr << "BATTLE ERROR: In ActionWindow::Draw(), the window state was invalid: " << _state << endl;
00311       return;
00312   }
00313 }
00314 
00315 
00316 
00317 void ActionWindow::_DrawActionCategory() {
00318   _action_category_list.Draw();
00319 }
00320 
00321 
00322 
00323 void ActionWindow::_DrawActionSelection() {
00324   // Draw the selected action category and name
00325   VideoManager->Move(530.0f, 100.0f);
00326   VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_TOP, 0);
00327   VideoManager->DrawImage(_action_category_icons[_selected_action_category]);
00328   VideoManager->MoveRelative(0.0f, -20.0f);
00329   VideoManager->SetDrawFlags(VIDEO_Y_CENTER, 0);
00330 
00331   switch (_selected_action_category) {
00332     case ACTION_TYPE_ATTACK:
00333       VideoManager->DrawText("Attack");
00334       break;
00335     case ACTION_TYPE_DEFEND:
00336       VideoManager->DrawText("Defend");
00337       break;
00338     case ACTION_TYPE_SUPPORT:
00339       VideoManager->DrawText("Support");
00340       break;
00341     case ACTION_TYPE_ITEM:
00342       VideoManager->DrawText("Item");
00343       break;
00344     default:
00345       if (BATTLE_DEBUG)
00346         cerr << "BATTLE ERROR: In ActionWindow::_DrawActionSelection(), unknown action category was selected: "
00347           << _selected_action_category << endl;
00348       return;
00349   }
00350 
00351   // Draw the action list header text
00352   VideoManager->SetFont("battle");
00353   VideoManager->SetTextColor(Color(1.0f, 1.0f, 0.0f, 0.8f)); // 80% translucent yellow text
00354   VideoManager->Move(650.0f, 125.0f);
00355   if (_selected_action_category != ACTION_TYPE_ITEM) {
00356     VideoManager->DrawText(MakeUnicodeString("Skill                 SP"));
00357   }
00358   else {
00359     VideoManager->DrawText(MakeUnicodeString("Item                 QTY"));
00360   }
00361 
00362   // Draw the list of actions
00363   _action_selection_list.Draw();
00364 }
00365 
00366 
00367 
00368 void ActionWindow::_DrawTargetSelection() {
00369   // TODO: Draw information specific to target (friend vs foe, attack point versus party, etc.)
00370 
00371   // if (current_battle->_selected_target->IsEnemy())
00372   VideoManager->Move(650.0f, 100.0f);
00373   VideoManager->SetTextColor(Color(1.0f, 1.0f, 1.0f, 1.0f)); // white
00374   if (_action_target_type == GLOBAL_TARGET_ATTACK_POINT) {
00375     VideoManager->DrawText(MakeUnicodeString("Attack Point Targeted."));
00376   }
00377   else if (_action_target_type == GLOBAL_TARGET_ACTOR) {
00378     VideoManager->DrawText(MakeUnicodeString("Actor Targeted."));
00379   }
00380   else if (_action_target_type == GLOBAL_TARGET_PARTY) {
00381     VideoManager->DrawText(MakeUnicodeString("Party Targeted."));
00382   }
00383 }
00384 
00385 
00386 
00387 void ActionWindow::_DrawActionInformation() {
00388   // TODO: load action/item info into rendered text objects instead of rendering the textevery frame
00389   VideoManager->Move(650.0f, 100.0f);
00390   if (_selected_action_category == ACTION_TYPE_ITEM) {
00391     VideoManager->SetTextColor(Color(1.0f, 1.0f, 0.0f, 0.8f)); // 80% translucent yellow text
00392     VideoManager->DrawText(MakeUnicodeString("Item"));
00393 
00394     VideoManager->SetTextColor(Color::white);
00395     VideoManager->MoveRelative(0.0f, -25.0f);
00396     // TODO: add item icon and description
00397     VideoManager->DrawText(
00398       MakeUnicodeString("Name: ") + GetSelectedItem()->GetName() +
00399       MakeUnicodeString("\nCurrent Quantity: " + NumberToString(GetSelectedItem()->GetCount())) +
00400       MakeUnicodeString("\nTarget Type: TODO") +
00401       MakeUnicodeString("\nAlignment Type: TODO")
00402     );
00403   }
00404 
00405   else {
00406     VideoManager->SetTextColor(Color(1.0f, 1.0f, 0.0f, 0.8f)); // 80% translucent yellow text
00407     if (_selected_action_category == ACTION_TYPE_ATTACK) {
00408       VideoManager->DrawText(MakeUnicodeString("Attack Skill"));
00409     }
00410     else if (_selected_action_category == ACTION_TYPE_DEFEND) {
00411       VideoManager->DrawText(MakeUnicodeString("Defend Skill"));
00412     }
00413     else if (_selected_action_category == ACTION_TYPE_SUPPORT) {
00414       VideoManager->DrawText(MakeUnicodeString("Support Skill"));
00415     }
00416 
00417     VideoManager->SetTextColor(Color::white);
00418     VideoManager->MoveRelative(0.0f, -25.0f);
00419     // TODO: add warm-up and cool-down times (in seconds), and description
00420     VideoManager->DrawText(
00421       MakeUnicodeString("Name: ") + GetSelectedSkill()->GetName() +
00422       MakeUnicodeString("\nSP Required: " + NumberToString(GetSelectedSkill()->GetSPRequired())) +
00423       MakeUnicodeString("\nTarget Type: TODO") +
00424       MakeUnicodeString("\nAlignment Type: TODO")
00425     );
00426   }
00427 }
00428 
00429 // ----- OTHER METHODS
00430 
00431 void ActionWindow::_ConstructActionSelectionList() {
00432   if (_selected_action_category == ACTION_TYPE_ATTACK ||
00433     _selected_action_category == ACTION_TYPE_DEFEND ||
00434     _selected_action_category == ACTION_TYPE_SUPPORT)
00435   {
00436     // Setup the battle skill list
00437     if (_selected_action_category == ACTION_TYPE_ATTACK) {
00438       _skill_list = _character->GetActor()->GetAttackSkills();
00439     }
00440     else if (_selected_action_category == ACTION_TYPE_DEFEND) {
00441       _skill_list = _character->GetActor()->GetDefenseSkills();
00442     }
00443     else if (_selected_action_category == ACTION_TYPE_SUPPORT) {
00444       _skill_list = _character->GetActor()->GetSupportSkills();
00445     }
00446     
00447     if (_skill_list->empty()) {
00448       if (BATTLE_DEBUG)
00449         cerr << "BATTLE ERROR: In ActionWindow::ConstructActionSelectionList(), the character had no skills to list" << endl;
00450       return;
00451     }
00452 
00453     // Now use the skill_list to construction the text for each skill
00454     vector<ustring> skill_text;
00455     for (uint32 i = 0; i < _skill_list->size(); i++) {
00456       skill_text.push_back(MakeUnicodeString("<L>") + _skill_list->at(i)->GetName() + MakeUnicodeString("<R>") +
00457         MakeUnicodeString(NumberToString(_skill_list->at(i)->GetSPRequired())));
00458     }
00459 
00460     // Add the options to the list
00461     _action_selection_list.SetOptions(skill_text);
00462     _action_selection_list.SetSize(1, skill_text.size());
00463     _action_selection_list.SetSelection(0);
00464 
00465     // Disable any options for which the character does not have a sufficient amount of SP to execute
00466     for (uint32 i = 0; i < _skill_list->size(); i++) {
00467       if (_skill_list->at(i)->GetSPRequired() > _character->GetSkillPoints())
00468         _action_selection_list.EnableOption(i, false);
00469     }
00470     return;
00471   } // if (_action_category_selected == ACTION_TYPE_ATTACK || ...)
00472 
00473   if (_selected_action_category == ACTION_TYPE_ITEM) {
00474     // A temporary pointer to all the items to check
00475     vector<GlobalItem*>* temp_item_list;
00476     
00477     temp_item_list = GlobalManager->GetInventoryItems();
00478     if (temp_item_list->empty()) {
00479       if (BATTLE_DEBUG)
00480         cerr << "BATTLE ERROR: In ActionWindow::ConstructActionSelectionList(), there were no items in the inventory" << endl;
00481       return;
00482     }
00483 
00484     _item_list.clear();
00485     // Contains the text for the items as they will appear on the screen
00486     vector<ustring> items_text;
00487     GlobalItem *item = NULL;
00488 
00489     // Only add items to the list which have a count greater than zero and are usable in battle
00490     // NOTE: We check for GetCount() because if a character is preparing to use an item, we
00491     // we temporarily decrement the count. If the item doesn't get used (e.g. because the character died, etc.),
00492     // then we increment the item count back. So when this point in the code is reached, you could potentially have
00493     // items which are still part of the inventory, but are temporarily unavailable for selection until we
00494     // see if a another character gets to use an item or not.
00495     for (uint32 i = 0; i < temp_item_list->size(); ++i) {
00496       item = temp_item_list->at(i);
00497 
00498       if (item->GetUsage() >= GLOBAL_USE_BATTLE && item->GetCount() > 0) {
00499         _item_list.push_back(item);
00500         items_text.push_back(MakeUnicodeString("<L>") + item->GetName()
00501           + MakeUnicodeString("<R>") + MakeUnicodeString(NumberToString(item->GetCount())));
00502       }
00503     }
00504 
00505     // Calculate the number of rows, this is dividing by 6, and if there is a remainder > 0, add one more row for the remainder
00506     _action_selection_list.SetSize(1, _item_list.size() / 6 + ((_item_list.size() % 6) > 0 ? 1 : 0));
00507 
00508     _action_selection_list.SetOptions(items_text);
00509     _action_selection_list.SetSize(1, items_text.size());
00510     _action_selection_list.SetSelection(0);
00511   } // if (_action_category_selected == ACTION_TYPE_ITEM)
00512 
00513   else {
00514     if (BATTLE_DEBUG)
00515       cerr << "BATTLE ERROR: In ActionWindow::ConstructActionSelectionList(), the action category selected was invalid" << endl;
00516   }
00517 } // void ActionWindow::ConstructActionSelectionList()
00518 
00519 
00520 // *****************************************************************************
00521 // FinishWindow class
00522 // *****************************************************************************
00523 
00524 FinishWindow::FinishWindow() {
00525   // TODO: declare the MenuSkin to be used
00526   if (MenuWindow::Create(512.0f, 256.0f) == false) {
00527     cerr << "BATTLE ERROR: In ActionWindow constructor, the call to MenuWindow::Create() failed" << endl;
00528   }
00529   MenuWindow::SetPosition(512.0f, 384.0f);
00530   MenuWindow::SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
00531   MenuWindow::Hide();
00532 
00533   _state = FINISH_INVALID;
00534 
00535   vector<ustring> lose_text;
00536   lose_text.push_back(MakeUnicodeString("Retry  <R>the battle"));
00537   lose_text.push_back(MakeUnicodeString("Load   <R>from last save point"));
00538   lose_text.push_back(MakeUnicodeString("Return <R>to main menu"));
00539   lose_text.push_back(MakeUnicodeString("Exit   <R>the game"));
00540   _lose_options.SetOptions(lose_text);
00541   _lose_options.SetCellSize(128.0f, 50.0f);
00542   _lose_options.SetPosition(530.0f, 380.0f);
00543   _lose_options.SetSize(1, 4);
00544   _lose_options.SetFont("battle");
00545   _lose_options.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
00546   _lose_options.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
00547   _lose_options.SetSelectMode(VIDEO_SELECT_SINGLE);
00548   _lose_options.SetHorizontalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
00549   _lose_options.SetCursorOffset(-60.0f, 25.0f);
00550   _lose_options.SetSelection(0);
00551   _lose_options.SetOwner(this);
00552 }
00553 
00554 
00555 
00556 FinishWindow::~FinishWindow() {
00557   MenuWindow::Destroy();
00558 }
00559 
00560 
00561 
00562 void FinishWindow::Initialize(bool victory) {
00563   MenuWindow::Show();
00564 
00565   if (victory) {
00566     _state = FINISH_ANNOUNCE_WIN;
00567     current_battle->AddMusic("mus/Allacrost_Fanfare.ogg");
00568     current_battle->_battle_music.back().PlayMusic();
00569   }
00570   else {
00571     _state = FINISH_ANNOUNCE_LOSE;
00572     current_battle->AddMusic("mus/Allacrost_Intermission.ogg");
00573     current_battle->_battle_music.back().PlayMusic();
00574   }
00575 }
00576 
00577 
00578 
00579 void FinishWindow::Update() {
00580   // TODO: This is temporary... need to properly allow player
00581 
00582   if (_state == FINISH_ANNOUNCE_WIN) {
00583     if (InputManager->ConfirmPress()) {
00584       AudioManager->PlaySound("snd/confirm.wav");
00585       current_battle->_ShutDown();
00586     }
00587   }
00588 
00589   else if (_state == FINISH_ANNOUNCE_LOSE) {
00590     if (InputManager->ConfirmPress()) {
00591       current_battle->PlayerDefeat();
00592     }
00593   }
00594 }
00595 
00596 
00597 
00598 void FinishWindow::Draw() {
00599   VideoManager->DisableSceneLighting();
00600   MenuWindow::Draw();
00601 
00602   // TODO: This all needs to be re-written so that it is formatted nicely and fits on the menu window
00603   if (_state == FINISH_ANNOUNCE_WIN) {
00604     VideoManager->Move(520.0f, 384.0f);
00605     VideoManager->SetDrawFlags(VIDEO_X_CENTER, VIDEO_Y_CENTER, 0);
00606     VideoManager->SetTextColor(Color::white);
00607 
00608     ustring text = MakeUnicodeString("Your party is victorious!\n\n");
00609     text += MakeUnicodeString("XP: ") + MakeUnicodeString(NumberToString(current_battle->_victory_xp) + "\n\n");
00610     text += MakeUnicodeString("SP: ") + MakeUnicodeString(NumberToString(current_battle->_victory_sp) + "\n\n");
00611     text += MakeUnicodeString("Drunes: ") + MakeUnicodeString(NumberToString(current_battle->_victory_money) + "\n\n");
00612     if (current_battle->_victory_level) {
00613       text += MakeUnicodeString("Experience Level Gained\n\n");
00614     }
00615     if (current_battle->_victory_skill) {
00616       text += MakeUnicodeString("New Skill Learned\n\n");
00617     }
00618 
00619     if (current_battle->_victory_items.size() > 0) {
00620       text += MakeUnicodeString("Items: ");
00621       std::map<string, uint32>::iterator it;
00622       for (it = current_battle->_victory_items.begin(); it != current_battle->_victory_items.end(); ++it) {
00623         text += MakeUnicodeString(it->first);
00624         text += MakeUnicodeString(" x" + NumberToString(it->second) + "\n\n");
00625       }
00626     }
00627     VideoManager->DrawText(text);
00628   }
00629 
00630   else if (_state == FINISH_ANNOUNCE_LOSE) {
00631     VideoManager->SetDrawFlags(VIDEO_X_CENTER, VIDEO_Y_CENTER, 0);
00632     VideoManager->Move(520.0f, 430.0f);
00633     VideoManager->DrawText("Your party has been defeated!");
00634   }
00635 }
00636 
00637 } // namespace private_battle
00638 
00639 } // namespace hoa_battle

Generated on Fri Jul 6 23:11:10 2007 for Hero of Allacrost by  doxygen 1.5.1