Skip to content
This repository
tree: 83e04df52b
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 373 lines (317 sloc) 13.386 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
///////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2004-2010 by The Allacrost Project
// All Rights Reserved
//
// This code is licensed under the GNU GPL version 2. It is free software
// and you may modify it and/or redistribute it under the terms of this license.
// See http://www.gnu.org/copyleft/gpl.html for details.
///////////////////////////////////////////////////////////////////////////////

/** ****************************************************************************
*** \file map_treasure.cpp
*** \author Tyler Olsen, roots@allacrost.org
*** \brief Source file for map mode treasures.
*** ***************************************************************************/

#include "modes/map/map_treasure.h"

#include "modes/map/map.h"
#include "modes/map/map_objects.h"

#include "modes/menu/menu.h"

#include "engine/input.h"
#include "engine/video/video.h"

#include "common/global/global.h"

using namespace hoa_utils;
using namespace hoa_input;
using namespace hoa_mode_manager;
using namespace hoa_system;
using namespace hoa_video;
using namespace hoa_gui;
using namespace hoa_global;
using namespace hoa_menu;

namespace hoa_map {

namespace private_map {

// -----------------------------------------------------------------------------
// ---------- MapTreasure Class Functions
// -----------------------------------------------------------------------------

MapTreasure::MapTreasure() :
_taken(false),
_drunes(0)
{}

MapTreasure::~MapTreasure() {
for (uint32 i = 0; i < _objects_list.size(); i++) {
delete _objects_list[i];
}
}

bool MapTreasure::AddObject(uint32 id, uint32 quantity) {
hoa_global::GlobalObject* obj = GlobalCreateNewObject(id, quantity);

if (obj == NULL) {
IF_PRINT_WARNING(MAP_DEBUG) << "invalid object id argument passed to function: " << id << std::endl;
return false;
}

_objects_list.push_back(obj);
return true;
}

// -----------------------------------------------------------------------------
// ---------- TreasureSupervisor class methods
// -----------------------------------------------------------------------------

TreasureSupervisor::TreasureSupervisor() :
_treasure(NULL),
_selection(ACTION_SELECTED),
_window_title(UTranslate("You obtain"), TextStyle("title24", Color::white, VIDEO_TEXT_SHADOW_DARK, 1, -2)),
_selection_name(),
_selection_icon(NULL)
{
// Create the menu windows and option boxes used for the treasure menu and
// align them at the appropriate locations on the screen
_action_window.Create(768.0f, 64.0f, ~VIDEO_MENU_EDGE_BOTTOM);
_action_window.SetPosition(512.0f, 460.0f);
_action_window.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_TOP);
_action_window.SetDisplayMode(VIDEO_MENU_INSTANT);

_list_window.Create(768.0f, 236.0f);
_list_window.SetPosition(512.0f, 516.0f);
_list_window.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_TOP);
_list_window.SetDisplayMode(VIDEO_MENU_INSTANT);

_action_options.SetPosition(30.0f, 18.0f);
_action_options.SetDimensions(726.0f, 32.0f, 1, 1, 1, 1);
_action_options.SetAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
_action_options.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
_action_options.SetHorizontalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
_action_options.SetSelectMode(VIDEO_SELECT_SINGLE);
_action_options.SetCursorOffset(-50.0f, -25.0f);
_action_options.SetTextStyle(TextStyle("title22", Color::white, VIDEO_TEXT_SHADOW_DARK, 1, -2));
_action_options.AddOption(UTranslate("Ok"));
_action_options.SetSelection(0);
_action_options.SetOwner(&_action_window);

_list_options.SetPosition(20.0f, 20.0f);
_list_options.SetDimensions(726.0f, 200.0f, 1, 255, 1, 5);
_list_options.SetAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
_list_options.SetOptionAlignment(VIDEO_X_LEFT, VIDEO_Y_CENTER);
_list_options.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
_list_options.SetSelectMode(VIDEO_SELECT_SINGLE);
_list_options.SetCursorOffset(-50.0f, -25.0f);
_list_options.SetTextStyle(TextStyle("text22", Color::white, VIDEO_TEXT_SHADOW_DARK, 1, -2));
_list_options.SetOwner(&_list_window);
// TODO: this currently does not work (text will be blank). Re-enable it once the scissoring bug is fixed in the video engine
// _list_options.Scissoring(true, true);

_detail_textbox.SetPosition(20.0f, 90.0f);
_detail_textbox.SetDimensions(726.0f, 128.0f);
_detail_textbox.SetDisplaySpeed(50);
_detail_textbox.SetTextStyle(TextStyle("text22", Color::white, VIDEO_TEXT_SHADOW_DARK, 1, -2));
_detail_textbox.SetDisplayMode(VIDEO_TEXT_REVEAL);
_detail_textbox.SetTextAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
_detail_textbox.SetOwner(&_list_window);

_selection_name.SetStyle(TextStyle("text22", Color::white, VIDEO_TEXT_SHADOW_DARK, 1, -2));

if (!_drunes_icon.Load("img/icons/drunes.png"))
IF_PRINT_WARNING(MAP_DEBUG) << "failed to load drunes icon for treasure menu" << std::endl;

if (!_coins_snd.LoadAudio("snd/coins.wav"))
IF_PRINT_WARNING(MAP_DEBUG) << "failed to load the obtain sound for Drunes treasures" << std::endl;
_coins_snd.AddOwner(MapMode::CurrentInstance());

if (!_items_snd.LoadAudio("snd/itempick2_michel_baradari_oga.wav"))
IF_PRINT_WARNING(MAP_DEBUG) << "failed to load the obtain sound for Items treasures" << std::endl;
_items_snd.AddOwner(MapMode::CurrentInstance());
} // TreasureSupervisor::TreasureSupervisor()

TreasureSupervisor::~TreasureSupervisor() {
_action_window.Destroy();
_list_window.Destroy();
}

void TreasureSupervisor::Initialize(TreasureObject* map_object) {
if (map_object == NULL) {
IF_PRINT_WARNING(MAP_DEBUG) << "function argument was NULL" << std::endl;
return;
}

Initialize(map_object->GetTreasure());
}

void TreasureSupervisor::Initialize(MapTreasure* treasure) {
if (!treasure) {
IF_PRINT_WARNING(MAP_DEBUG) << "function argument was NULL" << std::endl;
return;
}
_treasure = treasure;
MapMode::CurrentInstance()->PushState(STATE_TREASURE);

// Construct the object list, including any drunes that were contained within the treasure
if (_treasure->_drunes != 0) {
_list_options.AddOption(MakeUnicodeString("<img/icons/drunes.png> Drunes<R>" + NumberToString(_treasure->_drunes)));
_coins_snd.Play();
}
else {
_items_snd.Play();
}

for (uint32 i = 0; i < _treasure->_objects_list.size(); i++) {
if (_treasure->_objects_list[i]->GetCount() > 1) {
_list_options.AddOption(MakeUnicodeString("<" + _treasure->_objects_list[i]->GetIconImage().GetFilename() + "> ") +
_treasure->_objects_list[i]->GetName() +
MakeUnicodeString("<R>x" + NumberToString(_treasure->_objects_list[i]->GetCount())));
}
else {
_list_options.AddOption(MakeUnicodeString("<" + _treasure->_objects_list[i]->GetIconImage().GetFilename() + "> ") +
_treasure->_objects_list[i]->GetName());
}
}

for (uint32 i = 0; i < _list_options.GetNumberOptions(); i++) {
_list_options.GetEmbeddedImage(i)->SetDimensions(30.0f, 30.0f);
}

_action_options.SetSelection(0);
_action_options.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
_list_options.SetSelection(0);
_list_options.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);

_selection = ACTION_SELECTED;
_action_window.Show();
_list_window.Show();

// Immediately add the drunes and objects to the player's inventory
GlobalManager->AddDrunes(_treasure->_drunes);

for (uint32 i = 0; i < _treasure->_objects_list.size(); ++i) {
GlobalObject* obj = _treasure->_objects_list[i];
if (!obj)
continue;
if (!GlobalManager->IsObjectInInventory(obj->GetID())) {
// Pass a copy to the inventory, the treasure object will delete its content on destruction.
hoa_global::GlobalObject* obj_copy = GlobalCreateNewObject(obj->GetID(), obj->GetCount());
GlobalManager->AddToInventory(obj_copy);
}
else {
GlobalManager->IncrementObjectCount(obj->GetID(), obj->GetCount());
}
}
} // void TreasureSupervisor::Initialize(MapTreasure* treasure)

void TreasureSupervisor::Update() {
_action_window.Update();
_list_window.Update();
_action_options.Update();
_list_options.Update();
_detail_textbox.Update();

// Allow the user to go to menu mode at any time when the treasure menu is open
if (InputManager->MenuPress()) {
MenuMode *MM = new MenuMode(MapMode::CurrentInstance()->GetMapHudName(),
                                    MapMode::CurrentInstance()->GetMapImage().GetFilename());
ModeManager->Push(MM);
return;
}

// Update the menu according to which sub-window is currently selected
if (_selection == ACTION_SELECTED)
_UpdateAction();
else if (_selection == LIST_SELECTED)
_UpdateList();
else if (_selection == DETAIL_SELECTED)
_UpdateDetail();
else
IF_PRINT_WARNING(MAP_DEBUG) << "unknown selection state: " << _selection << std::endl;
}

void TreasureSupervisor::Draw() {
// We wait until the treasure is fully open before displaying any portions of the menu
VideoManager->PushState();
VideoManager->SetStandardCoordSys();
_action_window.Draw();
if (_selection != DETAIL_SELECTED) {
_action_options.Draw();
}
_list_window.Draw();
VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_CENTER, 0);
VideoManager->Move(152.0f, 495.0f);
_window_title.Draw();

if (_selection == DETAIL_SELECTED) {
VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_TOP, 0);
// Move to the upper left corner and draw the object icon
if (_selection_icon != NULL) {
VideoManager->Move(150.0f, 535.0f);
_selection_icon->Draw();
}

// Draw the name of the selected object to the right of the icon
VideoManager->MoveRelative(80.0f, 20.0f);
_selection_name.Draw();

_detail_textbox.Draw();
}
else {
_list_options.Draw();
}

VideoManager->PopState();
} // void TreasureSupervisor::Draw()

void TreasureSupervisor::Finish() {
_treasure->SetTaken(true);
_treasure = 0; // Forget about it once finished

_action_window.Hide();
_list_window.Hide();
_list_options.ClearOptions();

if (MapMode::CurrentInstance()->CurrentState() == hoa_map::private_map::STATE_TREASURE)
MapMode::CurrentInstance()->PopState();
}

void TreasureSupervisor::_UpdateAction() {
if (InputManager->ConfirmPress()) {
if (_action_options.GetSelection() == 0) // "Finish" lone action
Finish();
else
IF_PRINT_WARNING(MAP_DEBUG) << "unhandled action selection in OptionBox: " << _action_options.GetSelection() << std::endl;
}

// when there is no item, no need to update anything
if (_list_options.GetNumberOptions() == 0)
return;

if (InputManager->UpPress()) {
_selection = LIST_SELECTED;
_list_options.SetSelection(_list_options.GetNumberOptions() - 1);
_action_options.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
_list_options.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
}
else if (InputManager->DownPress()) {
_selection = LIST_SELECTED;
_list_options.SetSelection(0);
_action_options.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
_list_options.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
}
}

void TreasureSupervisor::_UpdateList() {
if (InputManager->CancelPress() || _list_options.GetNumberOptions() == 0) {
_selection = ACTION_SELECTED;
_action_options.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
_list_options.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
}
else if (InputManager->ConfirmPress()) {
_selection = DETAIL_SELECTED;
_list_options.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);

uint32 list_selection = _list_options.GetSelection();
if (list_selection == 0 && _treasure->_drunes != 0) { // If true, the drunes have been selected
_selection_name.SetText(UTranslate("Drunes"));
_selection_icon = &_drunes_icon;
_detail_textbox.SetDisplayText(UTranslate("With the additional ") + MakeUnicodeString(NumberToString(_treasure->_drunes)) +
UTranslate(" drunes found in this treasure added, the party now holds a total of ") + MakeUnicodeString(NumberToString(GlobalManager->GetDrunes()))
+ MakeUnicodeString(" drunes."));
}
else { // Otherwise, a GlobalObject is selected
if (_treasure->_drunes != 0)
list_selection--;
_selection_name.SetText(_treasure->_objects_list[list_selection]->GetName());
// TODO: this is not good practice. We should probably either remove the const status from the GetIconImage() call
_selection_icon = const_cast<StillImage*>(&_treasure->_objects_list[list_selection]->GetIconImage());
_detail_textbox.SetDisplayText(_treasure->_objects_list[list_selection]->GetDescription());
}
}
else if (InputManager->UpPress()) {
if (_list_options.GetSelection() == 0) {
_selection = ACTION_SELECTED;
_action_options.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
_list_options.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
}
else {
_list_options.InputUp();
}
}
else if (InputManager->DownPress()) {
if (static_cast<uint32>(_list_options.GetSelection()) == (_list_options.GetNumberOptions() - 1)) {
_selection = ACTION_SELECTED;
_action_options.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
_list_options.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
}
else {
_list_options.InputDown();
}
}
}

void TreasureSupervisor::_UpdateDetail() {
if (InputManager->ConfirmPress() || InputManager->CancelPress()) {
if (_detail_textbox.IsFinished() == false) {
_detail_textbox.ForceFinish();
}
else {
_selection = LIST_SELECTED;
_list_options.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
}
}
}

} // namespace private_map

} // namespace hoa_map
Something went wrong with that request. Please try again.