/
menu_views.cpp
2618 lines (2234 loc) · 97 KB
/
menu_views.cpp
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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
///////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2004-2011 by The Allacrost Project
// Copyright (C) 2012-2014 by Bertram (Valyria Tear)
// 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 menu_views.cpp
*** \author Daniel Steuernol steu@allacrost.org
*** \author Andy Gardner chopperdave@allacrost.org
*** \author Nik Nadig (IkarusDowned) nihonnik@gmail.com
*** \author Yohann Ferreira, yohann ferreira orange fr
*** \brief Source file for various menu views.
*** ***************************************************************************/
#include "utils/utils_pch.h"
#include "modes/menu/menu_views.h"
#include "modes/menu/menu.h"
#include "engine/audio/audio.h"
#include "engine/input.h"
#include "engine/system.h"
using namespace vt_menu::private_menu;
using namespace vt_utils;
using namespace vt_audio;
using namespace vt_video;
using namespace vt_gui;
using namespace vt_global;
using namespace vt_input;
using namespace vt_system;
namespace vt_menu
{
namespace private_menu
{
////////////////////////////////////////////////////////////////////////////////
// CharacterWindow Class
////////////////////////////////////////////////////////////////////////////////
CharacterWindow::CharacterWindow() : _char_id(GLOBAL_CHARACTER_INVALID)
{
}
void CharacterWindow::SetCharacter(GlobalCharacter* character)
{
if(!character || character->GetID() == vt_global::GLOBAL_CHARACTER_INVALID) {
_character_name.Clear();
_character_data.Clear();
_portrait = StillImage();
_UpdateActiveStatusEffects(NULL);
return;
}
_char_id = character->GetID();
_portrait = character->GetPortrait();
// Only size up valid portraits
if(!_portrait.GetFilename().empty())
_portrait.SetDimensions(100.0f, 100.0f);
// the characters' name is already translated.
_character_name.SetText(character->GetName(), TextStyle("title22"));
// And the rest of the data
ustring char_data = UTranslate("Lv: ") + MakeUnicodeString(NumberToString(character->GetExperienceLevel()) + "\n");
char_data += UTranslate("HP: ") + MakeUnicodeString(NumberToString(character->GetHitPoints()) +
" / " + NumberToString(character->GetMaxHitPoints()) + "\n");
char_data += UTranslate("SP: ") + MakeUnicodeString(NumberToString(character->GetSkillPoints()) +
" / " + NumberToString(character->GetMaxSkillPoints()) + "\n");
char_data += UTranslate("XP to Next: ") + MakeUnicodeString(NumberToString(character->GetExperienceForNextLevel()));
_character_data.SetText(char_data, TextStyle("text20"));
_UpdateActiveStatusEffects(character);
} // void CharacterWindow::SetCharacter(GlobalCharacter *character)
// Draw the window to the screen
void CharacterWindow::Draw()
{
// Call parent Draw method, if failed pass on fail result
MenuWindow::Draw();
VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_TOP, 0);
// Get the window metrics
float x, y;
GetPosition(x, y);
// Adjust the current position to make it look better
y += 5;
//Draw character portrait
VideoManager->Move(x + 12, y + 8);
_portrait.Draw();
// Write character name
VideoManager->MoveRelative(150, -5);
_character_name.Draw();
// Level, HP, SP, XP to Next Lvl
VideoManager->MoveRelative(0, 19);
_character_data.Draw();
// Active status effects
VideoManager->MoveRelative(-30, -17);
uint32 nb_effects = _active_status_effects.size();
for (uint32 i = 0; i < nb_effects && i < 6; ++i) {
if (_active_status_effects[i])
_active_status_effects[i]->Draw();
VideoManager->MoveRelative(0, 15);
}
if (nb_effects < 6)
return;
// Show a second column when there are more than 6 active status effects
VideoManager->MoveRelative(-15, -6 * 15);
for (uint32 i = 6; i < nb_effects && i < 12; ++i) {
if (_active_status_effects[i])
_active_status_effects[i]->Draw();
VideoManager->MoveRelative(0, 15);
}
if (nb_effects < 12)
return;
// Show a third column when there are more than 12 active status effects (max 15)
VideoManager->MoveRelative(-15, -6 * 15);
for (uint32 i = 12; i < nb_effects; ++i) {
if (_active_status_effects[i])
_active_status_effects[i]->Draw();
VideoManager->MoveRelative(0, 15);
}
}
void CharacterWindow::_UpdateActiveStatusEffects(vt_global::GlobalCharacter* character)
{
_active_status_effects.clear();
if (!character)
return;
GlobalMedia& media = GlobalManager->Media();
const std::vector<ActiveStatusEffect> effects = character->GetActiveStatusEffects();
for (uint32 i = 0; i < effects.size(); ++i) {
GLOBAL_STATUS status = effects[i].GetEffect();
GLOBAL_INTENSITY intensity = effects[i].GetIntensity();
if (status != GLOBAL_STATUS_INVALID && intensity != GLOBAL_INTENSITY_NEUTRAL) {
StillImage* image = media.GetStatusIcon(status, intensity);
if (image)
_active_status_effects.push_back(image);
}
}
}
////////////////////////////////////////////////////////////////////////////////
// InventoryWindow Class
////////////////////////////////////////////////////////////////////////////////
//! help message
static ustring inventory_help_message;
static ustring cannot_equip;
static ustring item_use;
InventoryWindow::InventoryWindow() :
_active_box(ITEM_ACTIVE_NONE),
_previous_category(ITEM_ALL),
_object(NULL),
_object_type(vt_global::GLOBAL_OBJECT_INVALID),
_character(NULL),
_is_equipment(false),
_can_equip(false)
{
_InitCategory();
_UpdateItemText();
_InitInventoryItems();
_InitCharSelect();
//Initializes the description textbox for the bottom window
_description.SetOwner(this);
_description.SetPosition(30.0f, 525.0f);
_description.SetDimensions(800.0f, 80.0f);
_description.SetDisplaySpeed(SystemManager->GetMessageSpeed());
_description.SetTextStyle(TextStyle("text20"));
_description.SetDisplayMode(VIDEO_TEXT_INSTANT);
_description.SetTextAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
// We update it here to permit reloading it in case the language has changed
// since the game start.
inventory_help_message = UTranslate("Select an item to Equip or Use.");
cannot_equip = UTranslate("This character cannot equip this item.");
item_use = UTranslate("Select a character to use the item on.");
} // void InventoryWindow::InventoryWindow
//Initializes the list of items
void InventoryWindow::_InitInventoryItems()
{
// Set up the inventory option box
_inventory_items.SetPosition(500.0f, 170.0f);
_inventory_items.SetDimensions(400.0f, 360.0f, 1, 255, 1, 10);
_inventory_items.SetTextStyle(TextStyle("text20"));
_inventory_items.SetCursorOffset(-52.0f, -20.0f);
_inventory_items.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
_inventory_items.SetOptionAlignment(VIDEO_X_LEFT, VIDEO_Y_CENTER);
// Update the item text
_UpdateItemText();
if(_inventory_items.GetNumberOptions() > 0) {
_inventory_items.SetSelection(0);
_object = _item_objects[ _inventory_items.GetSelection() ];
_object_type = _object->GetObjectType();
}
VideoManager->MoveRelative(-65, 20);
// Initially hide the cursor
_inventory_items.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
}
//Initalizes character select
void InventoryWindow::_InitCharSelect()
{
//character selection set up
std::vector<ustring> options;
uint32 size = GlobalManager->GetActiveParty()->GetPartySize();
_char_select.SetPosition(72.0f, 109.0f);
_char_select.SetDimensions(360.0f, 432.0f, 1, 4, 1, 4);
_char_select.SetCursorOffset(-50.0f, -6.0f);
_char_select.SetTextStyle(TextStyle("text20"));
_char_select.SetHorizontalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
_char_select.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
_char_select.SetOptionAlignment(VIDEO_X_LEFT, VIDEO_Y_CENTER);
//Use a blank string so the cursor has somewhere to point
//String is overdrawn by char portraits, so no matter
for(uint32 i = 0; i < size; i++) {
options.push_back(MakeUnicodeString(" "));
}
_char_select.SetOptions(options);
_char_select.SetSelection(0);
_char_select.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
_character = GlobalManager->GetActiveParty()->GetCharacterAtIndex(_char_select.GetSelection());
}
//Initalizes the available item categories
void InventoryWindow::_InitCategory()
{
_item_categories.SetPosition(458.0f, 120.0f);
_item_categories.SetDimensions(448.0f, 30.0f, ITEM_CATEGORY_SIZE, 1, ITEM_CATEGORY_SIZE, 1);
_item_categories.SetTextStyle(TextStyle("text20"));
_item_categories.SetCursorOffset(-52.0f, -20.0f);
_item_categories.SetHorizontalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
_item_categories.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
_item_categories.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
std::vector<ustring> options;
options.push_back(UTranslate("All"));
options.push_back(UTranslate("Itm"));
options.push_back(UTranslate("Wpn"));
options.push_back(UTranslate("Hlm"));
options.push_back(UTranslate("Tor"));
options.push_back(CUTranslate("Menu|Arm"));
options.push_back(UTranslate("Leg"));
options.push_back(UTranslate("Key"));
_item_categories.SetOptions(options);
_item_categories.SetSelection(ITEM_ALL);
_item_categories.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
}
// Activates/deactivates inventory window
void InventoryWindow::Activate(bool new_status)
{
// Set new status
if(new_status) {
_active_box = ITEM_ACTIVE_CATEGORY;
MenuMode::CurrentInstance()->_help_information.SetDisplayText(inventory_help_message);
// Update cursor state
_item_categories.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
} else {
GlobalManager->Media().PlaySound("bump");
_active_box = ITEM_ACTIVE_NONE;
_item_categories.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
_char_select.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
}
}
// Updates the window
void InventoryWindow::Update()
{
GlobalMedia& media = GlobalManager->Media();
if(GlobalManager->GetInventory()->empty()) {
// no more items in inventory, exit inventory window
Activate(false);
return;
}
// Points to the active option box
OptionBox *active_option = NULL;
_inventory_items.Update(); //For scrolling
switch(_active_box) {
case ITEM_ACTIVE_CATEGORY:
active_option = &_item_categories;
break;
case ITEM_ACTIVE_CHAR:
active_option = &_char_select;
break;
case ITEM_ACTIVE_LIST:
active_option = &_inventory_items;
break;
}
// Handle the appropriate input events
if(InputManager->ConfirmPress()) {
active_option->InputConfirm();
} else if(InputManager->CancelPress()) {
active_option->InputCancel();
} else if(InputManager->LeftPress()) {
active_option->InputLeft();
} else if(InputManager->RightPress()) {
active_option->InputRight();
} else if(InputManager->UpPress()) {
active_option->InputUp();
} else if(InputManager->DownPress()) {
active_option->InputDown();
}
// Update object and character data when necessary
if (InputManager->AnyKeyPress())
_UpdateSelection();
uint32 event = active_option->GetEvent();
active_option->Update();
// Handle confirm/cancel presses differently for each window
switch(_active_box) {
case ITEM_ACTIVE_NONE:
break;
case ITEM_ACTIVE_CATEGORY: {
// Activate the item list for this category
if(event == VIDEO_OPTION_CONFIRM) {
if(_inventory_items.GetNumberOptions() > 0) {
_inventory_items.SetSelection(0);
_item_categories.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
_inventory_items.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
_description.SetDisplayText(_item_objects[ 0 ]->GetDescription());
_active_box = ITEM_ACTIVE_LIST;
media.PlaySound("confirm");
} // if _inventory_items.GetNumberOptions() > 0
} // if VIDEO_OPTION_CONFIRM
// Deactivate inventory
else if(event == VIDEO_OPTION_CANCEL) {
media.PlaySound("cancel");
_item_categories.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
Activate(false);
} // if VIDEO_OPTION_CANCEL
break;
} // case ITEM_ACTIVE_CATEGORY
case ITEM_ACTIVE_LIST: {
//check if the items list is empty. if so, we exit up to the categories level
if( _inventory_items.GetNumberOptions() <= 0)
{
_active_box = ITEM_ACTIVE_CATEGORY;
MenuMode::CurrentInstance()->_help_information.SetDisplayText(inventory_help_message);
_inventory_items.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
_item_categories.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
break;
}
// Test whether the inventory cursor is out of bound after using
// the item. Can happen when using/equipping the last item of the list.
else if(_inventory_items.GetSelection() >= (int32)_inventory_items.GetNumberOptions()) {
_inventory_items.SetSelection((uint32)_inventory_items.GetNumberOptions() - 1);
}
// Activate the character select for application
if(event == VIDEO_OPTION_CONFIRM) {
// Don't accept selecting spirit items for now
if(_object_type == GLOBAL_OBJECT_SPIRIT) {
media.PlaySound("cancel");
break;
}
// Check first whether the item is usable from the menu
GlobalItem *item = (GlobalItem *)GlobalManager->RetrieveFromInventory(_object->GetID());
if (!item->IsUsableInField()) {
media.PlaySound("cancel");
GlobalManager->AddToInventory(item);
break;
}
GlobalManager->AddToInventory(item);
_active_box = ITEM_ACTIVE_CHAR;
_inventory_items.SetCursorState(VIDEO_CURSOR_STATE_DARKEN);
_char_select.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
switch (_object_type) {
case GLOBAL_OBJECT_WEAPON:
case GLOBAL_OBJECT_ARM_ARMOR:
case GLOBAL_OBJECT_HEAD_ARMOR:
case GLOBAL_OBJECT_TORSO_ARMOR:
case GLOBAL_OBJECT_LEG_ARMOR:
MenuMode::CurrentInstance()->UpdateEquipmentInfo(_character, _object, EQUIP_VIEW_EQUIPPING);
break;
default: // other objects
break;
}
media.PlaySound("confirm");
} // if VIDEO_OPTION_CONFIRM
// Return to category selection
else if(event == VIDEO_OPTION_CANCEL) {
_active_box = ITEM_ACTIVE_CATEGORY;
MenuMode::CurrentInstance()->_help_information.SetDisplayText(inventory_help_message);
_inventory_items.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
_item_categories.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
media.PlaySound("cancel");
} // else if VIDEO_OPTION_CANCEL
else if(event == VIDEO_OPTION_BOUNDS_UP || VIDEO_OPTION_BOUNDS_DOWN) {
_description.SetDisplayText(_object->GetDescription());
} // else if VIDEO_OPTION_BOUNDS_UP
break;
} // case ITEM_ACTIVE_LIST
case ITEM_ACTIVE_CHAR: {
// Use the item on the chosen character
if(event == VIDEO_OPTION_CONFIRM) {
//values used for equipment selection
GlobalArmor *selected_armor = NULL;
GlobalWeapon *selected_weapon = NULL;
switch(_object_type)
{
case GLOBAL_OBJECT_ITEM:
{
// Returns an item object, already removed from inventory.
// Don't forget to readd the item if not used, or to delete the pointer.
GlobalItem *item = (GlobalItem *)GlobalManager->RetrieveFromInventory(_object->GetID());
const ScriptObject &script_function = item->GetFieldUseFunction();
if(!script_function.is_valid()) {
IF_PRINT_WARNING(MENU_DEBUG) << "item did not have a menu use function" << std::endl;
} else {
if(IsTargetParty(item->GetTargetType())) {
GlobalParty *ch_party = GlobalManager->GetActiveParty();
bool success = false;
try {
success = ScriptCallFunction<bool>(script_function, ch_party);
} catch(const luabind::error& e) {
PRINT_ERROR << "Error while loading FieldUse() function" << std::endl;
vt_script::ScriptManager->HandleLuaError(e);
success = false;
} catch(const luabind::cast_failed& e) {
PRINT_ERROR << "Error while loading FieldUse() function" << std::endl;
vt_script::ScriptManager->HandleCastError(e);
success = false;
}
// If the item use failed, we readd it to inventory.
if(!success)
GlobalManager->AddToInventory(item);
else // delete the item instance when succeeded. Also, return back a level to the item selection list
{
_active_box = ITEM_ACTIVE_LIST;
_char_select.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
_char_select.ResetViewableOption();
// Show the selected item
_inventory_items.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
// We also update the Characters stats as the item might have some effects there.
MenuMode::CurrentInstance()->ReloadCharacterWindows();
delete item;
}
} // if GLOBAL_TARGET_PARTY
else { // Use on a single character only
bool success = false;
try {
success = ScriptCallFunction<bool>(script_function, _character);
} catch(const luabind::error& e) {
PRINT_ERROR << "Error while loading FieldUse() function" << std::endl;
vt_script::ScriptManager->HandleLuaError(e);
success = false;
} catch(const luabind::cast_failed& e) {
PRINT_ERROR << "Error while loading FieldUse() function" << std::endl;
vt_script::ScriptManager->HandleCastError(e);
success = false;
}
// If the item use failed, we readd it to inventory.
if(!success)
GlobalManager->AddToInventory(item);
else // delete the item instance when succeeded. Also, return back a level to the item selection list
{
_active_box = ITEM_ACTIVE_LIST;
_char_select.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
_char_select.ResetViewableOption();
// Show the selected item
_inventory_items.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
// We also update the Characters stats as the item might have some effects there.
MenuMode::CurrentInstance()->ReloadCharacterWindows();
delete item;
}
}
}
break;
} // if GLOBAL_OBJECT_ITEM
case GLOBAL_OBJECT_WEAPON:
{
//get the item from the inventory list. this also removes the item from the list
selected_weapon = dynamic_cast<GlobalWeapon *>(GlobalManager->RetrieveFromInventory(_object->GetID()));
break;
}
case GLOBAL_OBJECT_HEAD_ARMOR:
case GLOBAL_OBJECT_TORSO_ARMOR:
case GLOBAL_OBJECT_ARM_ARMOR:
case GLOBAL_OBJECT_LEG_ARMOR:
{
//get the item from the inventory list. this also removes the item from the list
selected_armor = dynamic_cast<GlobalArmor *>(GlobalManager->RetrieveFromInventory(_object->GetID()));
break;
}
default:
break;
}
//if we can equip this and it is armor
if(_can_equip && selected_armor)
{
//do swap of armor based on object type (aka armor type)
switch(_object_type)
{
case GLOBAL_OBJECT_HEAD_ARMOR:
selected_armor = _character->EquipHeadArmor(selected_armor);
break;
case GLOBAL_OBJECT_TORSO_ARMOR:
selected_armor = _character->EquipTorsoArmor(selected_armor);
break;
case GLOBAL_OBJECT_ARM_ARMOR:
selected_armor = _character->EquipArmArmor(selected_armor);
break;
case GLOBAL_OBJECT_LEG_ARMOR:
selected_armor = _character->EquipLegArmor(selected_armor);
default:
break;
}
//add the old armor back to the inventory
GlobalManager->AddToInventory(selected_armor);
//return back a level
_active_box = ITEM_ACTIVE_LIST;
_char_select.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
_char_select.ResetViewableOption();
//set the item select to by lightened
_inventory_items.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
}
//if we can equuip and it is a weapon
else if(_can_equip && selected_weapon)
{
//get the old weapon by swapping the selected_weapon for the current one
selected_weapon = _character->EquipWeapon(selected_weapon);
//add the old weapon back into the inventory
GlobalManager->AddToInventory(selected_weapon);
//return back a level
_active_box = ITEM_ACTIVE_LIST;
_char_select.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
_char_select.ResetViewableOption();
//set the item select to by lightened
_inventory_items.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
}
//if we cannot equip
else
{
//return the weapon to inventory
if(selected_weapon)
GlobalManager->AddToInventory(selected_weapon);
if(selected_armor)
GlobalManager->AddToInventory(selected_armor);
media.PlaySound("cancel");
}
_UpdateSelection();
} // if VIDEO_OPTION_CONFIRM
// Return to item selection
else if(event == VIDEO_OPTION_CANCEL) {
_active_box = ITEM_ACTIVE_LIST;
_inventory_items.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
_char_select.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
media.PlaySound("cancel");
} // if VIDEO_OPTION_CANCEL
break;
} // case ITEM_ACTIVE_CHAR
} // switch (_active_box)
} // void InventoryWindow::Update()
void InventoryWindow::_UpdateSelection()
{
// Update the item list
_UpdateItemText();
_object = _item_objects[ _inventory_items.GetSelection() ];
_object_type = _object->GetObjectType();
_object_name.SetText(_object->GetName(), TextStyle("title22"));
if (_active_box == ITEM_ACTIVE_CHAR)
_character = GlobalManager->GetActiveParty()->GetCharacterAtIndex(_char_select.GetSelection());
//check the obj_type again to see if its a weapon or armor
switch(_object_type) {
case GLOBAL_OBJECT_WEAPON:
{
GlobalWeapon* selected_weapon = dynamic_cast<GlobalWeapon *>(_object);
uint32 usability_bitmask = selected_weapon->GetUsableBy();
_is_equipment = true;
_can_equip = usability_bitmask & _character->GetID();
MenuMode::CurrentInstance()->UpdateEquipmentInfo(_character, _object, EQUIP_VIEW_EQUIPPING);
break;
}
case GLOBAL_OBJECT_HEAD_ARMOR:
case GLOBAL_OBJECT_TORSO_ARMOR:
case GLOBAL_OBJECT_ARM_ARMOR:
case GLOBAL_OBJECT_LEG_ARMOR:
{
GlobalArmor* selected_armor = dynamic_cast<GlobalArmor *>(_object);
uint32 usability_bitmask = selected_armor->GetUsableBy();
_is_equipment = true;
_can_equip = usability_bitmask & _character->GetID();
MenuMode::CurrentInstance()->UpdateEquipmentInfo(_character, _object, EQUIP_VIEW_EQUIPPING);
break;
}
default:
_is_equipment = false;
_can_equip = false;
break;
}
if (_is_equipment && !_can_equip)
MenuMode::CurrentInstance()->_help_information.SetDisplayText(cannot_equip);
else // standard items
MenuMode::CurrentInstance()->_help_information.SetDisplayText(item_use);
}
// Updates the item list
void InventoryWindow::_UpdateItemText()
{
// This is a case only for equipment.
// before we update the current inventory_items option box
// if the actual available items WAS zero on the last frame, then we make sure
// that the cursor is reset to hidden.
// if you don't do this, then the previous ITEM_CATEGORY cursor state remains, and will
// cause the darkened pointer to show
if(_item_objects.empty())
_inventory_items.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
_item_objects.clear();
_inventory_items.ClearOptions();
ITEM_CATEGORY current_selected_category = static_cast<ITEM_CATEGORY>(_item_categories.GetSelection());
switch(current_selected_category) {
case ITEM_ALL: {
std::map<uint32, GlobalObject *>* inv = GlobalManager->GetInventory();
for(std::map<uint32, GlobalObject *>::iterator it = inv->begin(); it != inv->end(); ++it) {
_item_objects.push_back(it->second);
}
break;
}
case ITEM_ITEM:
_item_objects = _GetItemVector(GlobalManager->GetInventoryItems());
break;
case ITEM_WEAPON:
_item_objects = _GetItemVector(GlobalManager->GetInventoryWeapons());
break;
case ITEM_HEAD_ARMOR:
_item_objects = _GetItemVector(GlobalManager->GetInventoryHeadArmor());
break;
case ITEM_TORSO_ARMOR:
_item_objects = _GetItemVector(GlobalManager->GetInventoryTorsoArmor());
break;
case ITEM_ARMS_ARMOR:
_item_objects = _GetItemVector(GlobalManager->GetInventoryArmArmor());
break;
case ITEM_LEGS_ARMOR:
_item_objects = _GetItemVector(GlobalManager->GetInventoryLegArmor());
break;
case ITEM_KEY: {
std::map<uint32, GlobalObject *>* inv = GlobalManager->GetInventory();
for(std::map<uint32, GlobalObject *>::iterator it = inv->begin(); it != inv->end(); ++it) {
if (it->second->IsKeyItem())
_item_objects.push_back(it->second);
}
break;
}
default:
break;
}
ustring text;
std::vector<ustring> inv_names;
for(size_t ctr = 0; ctr < _item_objects.size(); ctr++) {
text = MakeUnicodeString("<" + _item_objects[ctr]->GetIconImage().GetFilename() + "><20> ") +
_item_objects[ctr]->GetName() + MakeUnicodeString("<R><350>" + NumberToString(_item_objects[ctr]->GetCount()) + " ");
inv_names.push_back(text);
}
_inventory_items.SetOptions(inv_names);
for (uint32 i = 0; i < _inventory_items.GetNumberOptions(); ++i) {
StillImage *image = _inventory_items.GetEmbeddedImage(i);
if (image)
image->SetWidthKeepRatio(32);
}
if(current_selected_category != _previous_category )
{
//swap to the new category
_previous_category = current_selected_category ;
//reset the top viewing inventory item
_inventory_items.ResetViewableOption();
}
} // void InventoryWindow::UpdateItemText()
void InventoryWindow::Draw()
{
_DrawBottomInfo();
MenuWindow::Draw();
// Draw char select option box
_char_select.Draw();
// Draw item categories option box
_item_categories.Draw();
// Draw item list
_inventory_items.Draw();
} // bool InventoryWindow::Draw()
void InventoryWindow::_DrawSpecialItemDescription(vt_video::StillImage* special_image,
vt_gui::TextBox& description)
{
int32 key_pos_x = 100 + _object->GetIconImage().GetWidth() - special_image->GetWidth() - 3;
int32 key_pos_y = 600 + _object->GetIconImage().GetHeight() - special_image->GetHeight() - 3;
VideoManager->Move(key_pos_x, key_pos_y);
special_image->Draw();
VideoManager->Move(185, 600);
description.Draw();
}
void InventoryWindow::_DrawBottomInfo()
{
//if we are out of items, the bottom view should do no work
if(GlobalManager->GetInventory()->empty() || _item_objects.empty())
return;
MenuMode* menu = MenuMode::CurrentInstance();
VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_BOTTOM, 0);
VideoManager->Move(150, 580);
if(_active_box == ITEM_ACTIVE_CATEGORY) {
menu->_bottom_window.Draw();
menu->_help_information.Draw();
}
else if(_active_box == ITEM_ACTIVE_LIST) {
menu->_bottom_window.Draw();
VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_CENTER, 0);
VideoManager->Move(100, 600);
_object->GetIconImage().Draw();
VideoManager->MoveRelative(65, -15);
_object_name.Draw();
VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_BOTTOM, 0);
_description.Draw();
if (_object->IsKeyItem())
_DrawSpecialItemDescription(menu->_key_item_icon, menu->_key_item_description);
else if (_object_type == GLOBAL_OBJECT_SPIRIT)
_DrawSpecialItemDescription(menu->_spirit_icon, menu->_spirit_description);
}
else if(_active_box == ITEM_ACTIVE_CHAR) {
menu->_bottom_window.Draw();
if (_is_equipment && _can_equip)
menu->DrawEquipmentInfo();
else
menu->_help_information.Draw();
}
}
////////////////////////////////////////////////////////////////////////////////
// PartyWindow Class
////////////////////////////////////////////////////////////////////////////////
static ustring change_position_message;
static ustring change_formation_message;
PartyWindow::PartyWindow() :
_char_select_active(FORM_ACTIVE_NONE),
_focused_def_icon(NULL),
_focused_mdef_icon(NULL)
{
// Get party size for iteration
uint32 partysize = GlobalManager->GetActiveParty()->GetPartySize();
StillImage portrait;
// Set up the full body portrait
for(uint32 i = 0; i < partysize; i++) {
GlobalCharacter* ch = GlobalManager->GetActiveParty()->GetCharacterAtIndex(i);
_full_portraits.push_back(ch->GetFullPortrait());
}
// We set them here in case the language has changed since the game start
change_position_message = UTranslate("Select a character to change position with.");
change_formation_message = UTranslate("Select a character to change formation.");
// Init char select option box
_InitCharSelect();
} // PartyWindow::PartyWindow()
// Activate/deactivate window
void PartyWindow::Activate(bool new_value)
{
if(new_value) {
_char_select_active = FORM_ACTIVE_CHAR;
_char_select.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
} else {
_char_select_active = FORM_ACTIVE_NONE;
_char_select.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
_second_char_select.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
}
}
void PartyWindow::_InitCharSelect()
{
//character selection set up
std::vector<ustring> options;
uint32 size = GlobalManager->GetActiveParty()->GetPartySize();
_char_select.SetPosition(72.0f, 109.0f);
_char_select.SetDimensions(360.0f, 432.0f, 1, 4, 1, 4);
_char_select.SetCursorOffset(-50.0f, -6.0f);
_char_select.SetTextStyle(TextStyle("text20"));
_char_select.SetHorizontalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
_char_select.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
_char_select.SetOptionAlignment(VIDEO_X_LEFT, VIDEO_Y_CENTER);
_second_char_select.SetPosition(72.0f, 109.0f);
_second_char_select.SetDimensions(360.0f, 432.0f, 1, 4, 1, 4);
_second_char_select.SetCursorOffset(-50.0f, -6.0f);
_second_char_select.SetTextStyle(TextStyle("text20"));
_second_char_select.SetHorizontalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
_second_char_select.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
_second_char_select.SetOptionAlignment(VIDEO_X_LEFT, VIDEO_Y_CENTER);
// Use blank string so cursor can point somewhere
for(uint32 i = 0; i < size; i++) {
options.push_back(MakeUnicodeString(" "));
}
_char_select.SetOptions(options);
_char_select.SetSelection(0);
_char_select.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
_second_char_select.SetOptions(options);
_second_char_select.SetSelection(0);
_second_char_select.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
_help_text.SetStyle(TextStyle("text18"));
_character_status_text.SetStyle(TextStyle("text20"));
_character_status_numbers.SetStyle(TextStyle("text20"));
_character_status_icons.Load("img/menus/status/menu_stats_icons.png");
_average_text.SetStyle(TextStyle("text20"));
_average_text.SetText(Translate("Attack / Defense:"));
_focused_text.SetStyle(TextStyle("text20"));
_focused_text.SetText(Translate("Detailed defense:"));
_average_atk_def_text.SetStyle(TextStyle("text18"));
vt_utils::ustring text = UTranslate("Attack (ATK): ") + MakeUnicodeString("\n")
+ UTranslate("Magical Attack (M.ATK): ") + MakeUnicodeString("\n\n")
+ UTranslate("Defense (DEF): ") + MakeUnicodeString("\n")
+ UTranslate("Magical Defense (M.DEF): ");
_average_atk_def_text.SetText(text);
_average_atk_def_numbers.SetStyle(TextStyle("text18"));
_average_atk_def_icons.Load("img/menus/status/menu_avg_atk_def.png");
_focused_def_text.SetStyle(TextStyle("text18"));
text = MakeUnicodeString("\n") // Skip title
+ UTranslate("Head: ") + MakeUnicodeString("\n")
+ UTranslate("Torso: ") + MakeUnicodeString("\n")
+ UTranslate("Arm: ") + MakeUnicodeString("\n")
+ UTranslate("Leg: ");
_focused_def_text.SetText(text);
_focused_def_numbers.SetStyle(TextStyle("text18"));
_focused_mdef_numbers.SetStyle(TextStyle("text18"));
_focused_def_category_icons.Load("img/menus/status/menu_point_atk_def.png");
_focused_def_icon = GlobalManager->Media().GetStatusIcon(GLOBAL_STATUS_FORTITUDE, GLOBAL_INTENSITY_NEUTRAL);
_focused_mdef_icon = GlobalManager->Media().GetStatusIcon(GLOBAL_STATUS_PROTECTION, GLOBAL_INTENSITY_NEUTRAL);
UpdateStatus();
}
// Updates the status window
void PartyWindow::Update()
{
GlobalMedia& media = GlobalManager->Media();
// Points to the active option box
OptionBox *active_option = NULL;
//choose correct menu
switch(_char_select_active) {
case FORM_ACTIVE_CHAR:
active_option = &_char_select;
_help_text.SetText(change_formation_message);
break;
case FORM_ACTIVE_SECOND:
active_option = &_second_char_select;
_help_text.SetText(change_position_message);
break;
}
// Handle the appropriate input events
if(InputManager->ConfirmPress()) {
active_option->InputConfirm();
} else if(InputManager->CancelPress()) {
active_option->InputCancel();
} else if(InputManager->LeftPress()) {
active_option->InputLeft();
} else if(InputManager->RightPress()) {
active_option->InputRight();
} else if(InputManager->UpPress()) {
active_option->InputUp();
} else if(InputManager->DownPress()) {
active_option->InputDown();
}
uint32 event = active_option->GetEvent();
active_option->Update();
switch(_char_select_active) {
case FORM_ACTIVE_CHAR:
if(event == VIDEO_OPTION_CONFIRM) {
_char_select_active = FORM_ACTIVE_SECOND;
_char_select.SetCursorState(VIDEO_CURSOR_STATE_DARKEN);
_second_char_select.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
media.PlaySound("confirm");
} else if(event == VIDEO_OPTION_CANCEL) {
Activate(false);
media.PlaySound("cancel");
}
break;
case FORM_ACTIVE_SECOND:
if(event == VIDEO_OPTION_CONFIRM) {
// Switch Characters
GlobalManager->SwapCharactersByIndex(_char_select.GetSelection(), _second_char_select.GetSelection());
std::swap(_full_portraits[_char_select.GetSelection()],_full_portraits[_second_char_select.GetSelection()]);
// Update the character's view
MenuMode::CurrentInstance()->ReloadCharacterWindows();
_char_select_active = FORM_ACTIVE_CHAR;
_char_select.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
_second_char_select.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
} else if(event == VIDEO_OPTION_CANCEL) {
_char_select_active = FORM_ACTIVE_CHAR;
_char_select.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
_second_char_select.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
media.PlaySound("cancel");
}
break;
} // switch
_char_select.Update();
// update the status text
if (InputManager->AnyKeyPress())
UpdateStatus();