Skip to content
This repository
tree: 0fddae0bfd
Fetching contributors…

Cannot retrieve contributors at this time

file 1351 lines (1085 sloc) 45.519 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 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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351
////////////////////////////////////////////////////////////////////////////////
// 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 battle_command.cpp
*** \author Tyler Olsen, roots@allacrost.org
*** \brief Source file for battle menu windows
*** ***************************************************************************/

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

#include "modes/battle/battle.h"
#include "modes/battle/battle_actions.h"
#include "modes/battle/battle_actors.h"
#include "modes/battle/battle_command.h"
#include "modes/battle/battle_utils.h"

using namespace hoa_utils;

using namespace hoa_audio;
using namespace hoa_video;
using namespace hoa_gui;
using namespace hoa_input;
using namespace hoa_system;
using namespace hoa_global;

namespace hoa_battle {

namespace private_battle {

const float HEADER_POSITION_X = 140.0f;
const float HEADER_POSITION_Y = 140.0f;
const float HEADER_SIZE_X = 350.0f;
const float HEADER_SIZE_Y = 30.0f;

const float LIST_POSITION_X = 140.0f;
const float LIST_POSITION_Y = 115.0f;
const float LIST_SIZE_X = 350.0f;
const float LIST_SIZE_Y = 100.0f;

const float TARGET_POSITION_X = 40.0f;
const float TARGET_POSITION_Y = 115.0f;
const float TARGET_SIZE_X = 450.0f;
const float TARGET_SIZE_Y = 100.0f;

// Offset used to properly align the target icons in the skill and item selection lists
const uint32 TARGET_ICON_OFFSET = 288;

////////////////////////////////////////////////////////////////////////////////
// CharacterCommandSettings class
////////////////////////////////////////////////////////////////////////////////

CharacterCommandSettings::CharacterCommandSettings(BattleCharacter* character, MenuWindow& window) :
_character(character),
_last_category(CATEGORY_ATTACK),
_last_item(0),
_last_self_target(BattleTarget()),
_last_character_target(BattleTarget()),
_last_enemy_target(BattleTarget())
{
_attack_list.SetOwner(&window);
_attack_list.SetPosition(LIST_POSITION_X, LIST_POSITION_Y);
_attack_list.SetDimensions(LIST_SIZE_X, LIST_SIZE_Y, 1, 255, 1, 4);
_attack_list.SetAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
_attack_list.SetOptionAlignment(VIDEO_X_LEFT, VIDEO_Y_CENTER);
_attack_list.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
_attack_list.SetTextStyle(TextStyle("text20"));
_attack_list.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
_attack_list.SetCursorOffset(-50.0f, 25.0f);

_defend_list.SetOwner(&window);
_defend_list.SetPosition(LIST_POSITION_X, LIST_POSITION_Y);
_defend_list.SetDimensions(LIST_SIZE_X, LIST_SIZE_Y, 1, 255, 1, 4);
_defend_list.SetAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
_defend_list.SetOptionAlignment(VIDEO_X_LEFT, VIDEO_Y_CENTER);
_defend_list.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
_defend_list.SetTextStyle(TextStyle("text20"));
_defend_list.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
_defend_list.SetCursorOffset(-50.0f, 25.0f);

_support_list.SetOwner(&window);
_support_list.SetPosition(LIST_POSITION_X, LIST_POSITION_Y);
_support_list.SetDimensions(LIST_SIZE_X, LIST_SIZE_Y, 1, 255, 1, 4);
_support_list.SetAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
_support_list.SetOptionAlignment(VIDEO_X_LEFT, VIDEO_Y_CENTER);
_support_list.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
_support_list.SetTextStyle(TextStyle("text20"));
_support_list.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
_support_list.SetCursorOffset(-50.0f, 25.0f);

if (_character == NULL) {
IF_PRINT_WARNING(BATTLE_DEBUG) << "constructor received NULL character pointer" << std::endl;
return;
}

// Construct the attack, defend, and support skill lists for the character
std::vector<GlobalSkill*>* skill_list = NULL;

skill_list = _character->GetGlobalCharacter()->GetAttackSkills();
for (uint32 i = 0; i < skill_list->size(); i++) {
_attack_list.AddOption(ustring());
_attack_list.AddOptionElementText(i, skill_list->at(i)->GetName());
_attack_list.AddOptionElementPosition(i, TARGET_ICON_OFFSET);
_attack_list.AddOptionElementImage(i, BattleMode::CurrentInstance()->GetMedia().GetTargetTypeIcon(skill_list->at(i)->GetTargetType()));
_attack_list.AddOptionElementAlignment(i, VIDEO_OPTION_ELEMENT_RIGHT_ALIGN);
_attack_list.AddOptionElementText(i, MakeUnicodeString(NumberToString(skill_list->at(i)->GetSPRequired())));
if (skill_list->at(i)->GetSPRequired() > _character->GetGlobalCharacter()->GetSkillPoints()) {
_attack_list.EnableOption(i, false);
}
}
if (skill_list->empty() == false)
_attack_list.SetSelection(0);

skill_list = _character->GetGlobalCharacter()->GetDefenseSkills();
for (uint32 i = 0; i < skill_list->size(); i++) {
_defend_list.AddOption(ustring());
_defend_list.AddOptionElementText(i, skill_list->at(i)->GetName());
_defend_list.AddOptionElementPosition(i, TARGET_ICON_OFFSET);
_defend_list.AddOptionElementImage(i, BattleMode::CurrentInstance()->GetMedia().GetTargetTypeIcon(skill_list->at(i)->GetTargetType()));
_defend_list.AddOptionElementAlignment(i, VIDEO_OPTION_ELEMENT_RIGHT_ALIGN);
_defend_list.AddOptionElementText(i, MakeUnicodeString(NumberToString(skill_list->at(i)->GetSPRequired())));
if (skill_list->at(i)->GetSPRequired() > _character->GetGlobalCharacter()->GetSkillPoints()) {
_defend_list.EnableOption(i, false);
}
}
if (skill_list->empty() == false)
_defend_list.SetSelection(0);

skill_list = _character->GetGlobalCharacter()->GetSupportSkills();
for (uint32 i = 0; i < skill_list->size(); i++) {
_support_list.AddOption(ustring());
_support_list.AddOptionElementText(i, skill_list->at(i)->GetName());
_support_list.AddOptionElementPosition(i, TARGET_ICON_OFFSET);
_support_list.AddOptionElementImage(i, BattleMode::CurrentInstance()->GetMedia().GetTargetTypeIcon(skill_list->at(i)->GetTargetType()));
_support_list.AddOptionElementAlignment(i, VIDEO_OPTION_ELEMENT_RIGHT_ALIGN);
_support_list.AddOptionElementText(i, MakeUnicodeString(NumberToString(skill_list->at(i)->GetSPRequired())));
if (skill_list->at(i)->GetSPRequired() > _character->GetGlobalCharacter()->GetSkillPoints()) {
_support_list.EnableOption(i, false);
}
}
if (skill_list->empty() == false)
_support_list.SetSelection(0);
} // CharacterCommandSettings::CharacterCommandSettings(BattleCharacter* character, MenuWindow& window)



void CharacterCommandSettings::RefreshLists() {
uint32 require_sp = 0xFFFFFFFF;
uint32 current_sp = _character->GetSkillPoints();
std::vector<GlobalSkill*>* skill_list = NULL;

skill_list = _character->GetGlobalCharacter()->GetAttackSkills();
for (uint32 i = 0; i < skill_list->size(); i++) {
require_sp = skill_list->at(i)->GetSPRequired();
if (require_sp > current_sp)
_attack_list.EnableOption(i, false);
else
_attack_list.EnableOption(i, true);
}

skill_list = _character->GetGlobalCharacter()->GetDefenseSkills();
for (uint32 i = 0; i < skill_list->size(); i++) {
require_sp = skill_list->at(i)->GetSPRequired();
if (require_sp > current_sp)
_defend_list.EnableOption(i, false);
else
_defend_list.EnableOption(i, true);
}

skill_list = _character->GetGlobalCharacter()->GetSupportSkills();
for (uint32 i = 0; i < skill_list->size(); i++) {
require_sp = skill_list->at(i)->GetSPRequired();
if (require_sp > current_sp)
_support_list.EnableOption(i, false);
else
_support_list.EnableOption(i, true);
}
}



void CharacterCommandSettings::SaveLastTarget(BattleTarget& target) {
switch (target.GetType()) {
case GLOBAL_TARGET_SELF_POINT:
case GLOBAL_TARGET_SELF:
_last_self_target = target;
break;
case GLOBAL_TARGET_ALLY_POINT:
case GLOBAL_TARGET_ALLY:
case GLOBAL_TARGET_ALLY_EVEN_DEAD:
_last_character_target = target;
break;
case GLOBAL_TARGET_FOE_POINT:
case GLOBAL_TARGET_FOE:
_last_enemy_target = target;
break;
case GLOBAL_TARGET_ALL_ALLIES:
case GLOBAL_TARGET_ALL_FOES:
break; // Party type targets are not retained
default:
IF_PRINT_WARNING(BATTLE_DEBUG) << "target argument was an invalid type: " << target.GetType() << std::endl;
break;
}
}



void CharacterCommandSettings::SetLastSelfTarget(BattleTarget& target) {
if ((target.GetType() != GLOBAL_TARGET_SELF_POINT) && (target.GetType() != GLOBAL_TARGET_SELF)) {
IF_PRINT_WARNING(BATTLE_DEBUG) << "target argument was an invalid type: " << target.GetType() << std::endl;
return;
}

_last_self_target = target;
}



void CharacterCommandSettings::SetLastCharacterTarget(BattleTarget& target) {
if ((target.GetType() != GLOBAL_TARGET_ALLY_POINT) && (target.GetType() != GLOBAL_TARGET_ALLY)
&& (target.GetType() != GLOBAL_TARGET_ALLY_EVEN_DEAD)) {
IF_PRINT_WARNING(BATTLE_DEBUG) << "target argument was an invalid type: " << target.GetType() << std::endl;
return;
}

_last_character_target = target;
}



void CharacterCommandSettings::SetLastEnemyTarget(BattleTarget& target) {
if ((target.GetType() != GLOBAL_TARGET_FOE_POINT) && (target.GetType() != GLOBAL_TARGET_FOE)) {
IF_PRINT_WARNING(BATTLE_DEBUG) << "target argument was an invalid type: " << target.GetType() << std::endl;
return;
}

_last_enemy_target = target;
}

////////////////////////////////////////////////////////////////////////////////
// ItemCommand class
////////////////////////////////////////////////////////////////////////////////

ItemCommand::ItemCommand(MenuWindow& window) {
_item_header.SetOwner(&window);
_item_header.SetPosition(HEADER_POSITION_X, HEADER_POSITION_Y);
_item_header.SetDimensions(HEADER_SIZE_X, HEADER_SIZE_Y, 1, 1, 1, 1);
_item_header.SetAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
_item_header.SetOptionAlignment(VIDEO_X_LEFT, VIDEO_Y_CENTER);
_item_header.SetTextStyle(TextStyle("title22"));
_item_header.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
_item_header.AddOption(UTranslate("Item<R>Type ×"));

_item_list.SetOwner(&window);
_item_list.SetPosition(LIST_POSITION_X, LIST_POSITION_Y);
_item_list.SetDimensions(LIST_SIZE_X, LIST_SIZE_Y, 1, 255, 1, 4);
_item_list.SetAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
_item_list.SetOptionAlignment(VIDEO_X_LEFT, VIDEO_Y_CENTER);
_item_list.SetVerticalWrapMode(VIDEO_WRAP_MODE_STRAIGHT);
_item_list.SetTextStyle(TextStyle("text20"));
_item_list.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
_item_list.SetCursorOffset(-50.0f, 25.0f);

std::vector<GlobalItem*>* all_items = GlobalManager->GetInventoryItems();
for (uint32 i = 0; i < all_items->size(); i++) {
if (all_items->at(i)->IsUsableInBattle() == true) {
if (all_items->at(i)->GetCount() == 0) {
IF_PRINT_WARNING(BATTLE_DEBUG) << "discovered item in inventory with a zero count" << std::endl;
}

_items.push_back(BattleItem(GlobalItem(*all_items->at(i))));
}
}
_item_mappings.resize(_items.size(), -1);
}



void ItemCommand::ConstructList() {
_item_list.ClearOptions();

uint32 option_index = 0;
for (uint32 i = 0; i < _items.size(); i++) {
// Don't add any items with a non-zero count
if (_items[i].GetBattleCount() == 0) {
_item_mappings[i] = -1;
continue;
}

_item_list.AddOption();
_item_list.AddOptionElementText(option_index, _items[i].GetItem().GetName());
_item_list.AddOptionElementPosition(option_index, TARGET_ICON_OFFSET);
_item_list.AddOptionElementImage(option_index, BattleMode::CurrentInstance()->GetMedia().GetTargetTypeIcon(_items[i].GetTargetType()));
_item_list.AddOptionElementAlignment(option_index, VIDEO_OPTION_ELEMENT_RIGHT_ALIGN);
_item_list.AddOptionElementText(option_index, MakeUnicodeString(NumberToString(_items[i].GetBattleCount())));

_item_mappings[i] = option_index;
option_index++;
}

if (_item_list.GetNumberOptions() == 0)
_item_list.SetSelection(-1);
else
_item_list.SetSelection(0);
}



void ItemCommand::Initialize(uint32 item_index) {
if (item_index >= _items.size()) {
IF_PRINT_WARNING(BATTLE_DEBUG) << "item_index argument was out-of-range: " << item_index << std::endl;
return;
}

// If the item is in the list, set the list selection to that item
if (_item_mappings[item_index] >= 0) {
_item_list.SetSelection(_item_mappings[item_index]);
return;
}

// Otherwise find the nearest item to the desired item that is in the list
uint32 next_item_index = 0xFFFFFFFF;
uint32 prev_item_index = 0xFFFFFFFF;

for (uint32 i = item_index + 1; i < _items.size(); i++) {
if (_item_mappings[i] >= 0) {
next_item_index = i;
break;
}
}
if (item_index != 0) {
uint32 i = item_index - 1;

do {
if (_item_mappings[i] >= 0) {
prev_item_index = i;
break;
}

i--;
} while (i != 0);
}

// If this case is true there are no items in the list. This should not happen because the item
// command should not be used if no items exist
if ((next_item_index == 0xFFFFFFFF) && (prev_item_index == 0xFFFFFFFF)) {
IF_PRINT_WARNING(BATTLE_DEBUG) << "no items were in the list" << std::endl;
return;
}
else if ((next_item_index - item_index) <= (item_index - prev_item_index)) {
_item_list.SetSelection(_item_mappings[next_item_index]);
}
else {
_item_list.SetSelection(_item_mappings[prev_item_index]);
}
}



BattleItem* ItemCommand::GetSelectedItem() {
uint32 index = GetItemIndex();
if (index == 0xFFFFFFFF)
return NULL;
else
return &(_items[index]);
}



uint32 ItemCommand::GetItemIndex() const {
if (_item_list.GetSelection() < 0) {
IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid selection in item list" << std::endl;
return 0xFFFFFFFF;
}

int32 selection = _item_list.GetSelection();
for (uint32 i = 0; i < _items.size(); i++) {
if (_item_mappings[i] == selection) {
return static_cast<uint32>(selection);
}
}

// Execution should never reach this line
IF_PRINT_WARNING(BATTLE_DEBUG) << "could not find index for item list selection: " << _item_list.GetSelection() << std::endl;
return 0xFFFFFFFF;
}


bool ItemCommand::IsSelectedItemAvailable() const {
uint32 index = GetItemIndex();

if (index == 0xFFFFFFFF)
return false;
else
return (_items[index].GetBattleCount() > 0);
}


void ItemCommand::UpdateList() {
_item_list.Update();

if (InputManager->UpPress()) {
_item_list.InputUp();
BattleMode::CurrentInstance()->GetMedia().cursor_sound.Play();
}
else if (InputManager->DownPress()) {
_item_list.InputDown();
BattleMode::CurrentInstance()->GetMedia().cursor_sound.Play();
}
}



void ItemCommand::UpdateInformation() {
// TODO
}



void ItemCommand::DrawList() {
_item_header.Draw();
_item_list.Draw();
}



void ItemCommand::DrawInformation() {
// TODO
}



void ItemCommand::CommitChangesToInventory() {
for (uint32 i = 0; i < _items.size(); ++i) {
// Get the global item id
uint32 id = _items[i].GetItem().GetID();

// Remove slots totally used
if (_items[i].GetBattleCount() == 0) {
GlobalManager->RemoveFromInventory(id);
}
else {
int32 diff = _items[i].GetBattleCount() - _items[i].GetInventoryCount();
if (diff > 0) {
// Somehow the character have more than before the battle.
GlobalManager->IncrementObjectCount(id, diff);
}
else if (diff < 0) {
// Remove the used items.
GlobalManager->DecrementObjectCount(id, -diff);
}
}
}
}


void ItemCommand::RefreshEntry(uint32 entry) {
if (entry >= _item_list.GetNumberOptions()) {
IF_PRINT_WARNING(BATTLE_DEBUG) << "entry argument was out-of-range: " << entry << std::endl;
return;
}

// Determine which item corresponds to the list entry
int32 item_index = 0;
for (uint32 i = 0; i < _item_mappings.size(); i++) {
if (_item_mappings[i] == static_cast<int32>(entry)) {
item_index = _item_mappings[i];
break;
}
}

// Clear the option and repopulate its elements
_item_list.SetOptionText(entry, ustring());
_item_list.AddOptionElementText(entry, _items[item_index].GetItem().GetName());
_item_list.AddOptionElementPosition(entry, TARGET_ICON_OFFSET);
_item_list.AddOptionElementImage(entry, BattleMode::CurrentInstance()->GetMedia().GetTargetTypeIcon(_items[item_index].GetTargetType()));
_item_list.AddOptionElementAlignment(entry, VIDEO_OPTION_ELEMENT_RIGHT_ALIGN);
_item_list.AddOptionElementText(entry, MakeUnicodeString(NumberToString(_items[item_index].GetBattleCount())));

// Gray out the option when there are no items available.
if (_items[item_index].GetBattleCount() == 0) {
_item_list.EnableOption(entry, false);
}
else {
// Re-enable it if we come to get an item back for any reasons
_item_list.EnableOption(entry, true);
}
}

////////////////////////////////////////////////////////////////////////////////
// SkillCommand class
////////////////////////////////////////////////////////////////////////////////

SkillCommand::SkillCommand(MenuWindow& window) :
_skills(NULL),
_skill_list(NULL)
{
_skill_header.SetOwner(&window);
_skill_header.SetPosition(HEADER_POSITION_X, HEADER_POSITION_Y);
_skill_header.SetDimensions(HEADER_SIZE_X, HEADER_SIZE_Y, 1, 1, 1, 1);
_skill_header.SetAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
_skill_header.SetOptionAlignment(VIDEO_X_LEFT, VIDEO_Y_CENTER);
_skill_header.SetTextStyle(TextStyle("title22"));
_skill_header.SetCursorState(VIDEO_CURSOR_STATE_HIDDEN);
_skill_header.AddOption(UTranslate("Skill<R>Type SP"));
}



void SkillCommand::Initialize(std::vector<GlobalSkill*>* skills, OptionBox* skill_list) {
if (skills == NULL) {
IF_PRINT_WARNING(BATTLE_DEBUG) << "function received NULL skills argument" << std::endl;
return;
}
if (skill_list == NULL) {
IF_PRINT_WARNING(BATTLE_DEBUG) << "function received NULL skill_list argument" << std::endl;
return;
}

_skills = skills;
_skill_list = skill_list;
}



GlobalSkill* SkillCommand::GetSelectedSkill() const {
if ((_skills == NULL) || (_skill_list == NULL))
return NULL;

uint32 selection = _skill_list->GetSelection();
    // _skills needs to be returned even if not enabled due to low SP in order to print information
    // of both, enabled and disabled skills.
// if (_skill_list->IsOptionEnabled(selection) == false)
// return NULL;
// else
    return _skills->at(selection);
}



bool SkillCommand::GetSelectedSkillEnabled() {
if ((_skills == NULL) || (_skill_list == NULL))
return false;

uint32 selection = _skill_list->GetSelection();
    return _skill_list->IsOptionEnabled(selection);
}



void SkillCommand::UpdateList() {
if (_skill_list == NULL)
return;

_skill_list->Update();

if (InputManager->UpPress()) {
_skill_list->InputUp();
BattleMode::CurrentInstance()->GetMedia().cursor_sound.Play();
}
else if (InputManager->DownPress()) {
_skill_list->InputDown();
BattleMode::CurrentInstance()->GetMedia().cursor_sound.Play();
}
}



void SkillCommand::UpdateInformation() {

}



void SkillCommand::DrawList() {
if (_skill_list == NULL)
return;

_skill_header.Draw();
_skill_list->Draw();
}

////////////////////////////////////////////////////////////////////////////////
// CommandSupervisor class
////////////////////////////////////////////////////////////////////////////////

CommandSupervisor::CommandSupervisor() :
_state(COMMAND_STATE_INVALID),
_active_settings(NULL),
_selected_skill(NULL),
_selected_item(NULL),
_item_command(_command_window),
_skill_command(_command_window)
{
if (_command_window.Create(512.0f, 128.0f) == false) {
IF_PRINT_WARNING(BATTLE_DEBUG) << "failed to create menu window" << std::endl;
}
_command_window.SetPosition(512.0f, 128.0f);
_command_window.SetAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
_command_window.Show();

_category_icons.resize(4, StillImage());
if (_category_icons[0].Load("img/icons/battle/attack.png") == false)
PRINT_ERROR << "failed to load category icon" << std::endl;
if (_category_icons[1].Load("img/icons/battle/defend.png") == false)
PRINT_ERROR << "failed to load category icon" << std::endl;
if (_category_icons[2].Load("img/icons/battle/support.png") == false)
PRINT_ERROR << "failed to load category icon" << std::endl;
if (_category_icons[3].Load("img/icons/battle/item.png") == false)
PRINT_ERROR << "failed to load category icon" << std::endl;

_category_text.resize(4, TextImage("", TextStyle("title22")));
_category_text[0].SetText(Translate("Attack"));
_category_text[1].SetText(Translate("Defend"));
_category_text[2].SetText(Translate("Support"));
_category_text[3].SetText(Translate("Item"));

std::vector<ustring> option_text;
option_text.push_back(MakeUnicodeString("<img/icons/battle/attack.png>\n") + UTranslate("Attack"));
option_text.push_back(MakeUnicodeString("<img/icons/battle/defend.png>\n") + UTranslate("Defend"));
option_text.push_back(MakeUnicodeString("<img/icons/battle/support.png>\n") + UTranslate("Support"));
option_text.push_back(MakeUnicodeString("<img/icons/battle/item.png>\n") + UTranslate("Item"));

_window_header.SetStyle(TextStyle("title22"));
_window_text.SetStyle(TextStyle("text20"));

_category_options.SetOwner(&_command_window);
_category_options.SetPosition(256.0f, 75.0f);
_category_options.SetDimensions(400.0f, 80.0f, 4, 1, 4, 1);
_category_options.SetCursorOffset(-20.0f, 25.0f);
_category_options.SetAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
_category_options.SetOptionAlignment(VIDEO_X_CENTER, VIDEO_Y_CENTER);
_category_options.SetTextStyle(TextStyle("title22"));
_category_options.SetSelectMode(VIDEO_SELECT_SINGLE);
_category_options.SetOptions(option_text);
_category_options.SetSelection(0);

    // Skip disabled category items
_category_options.SetSkipDisabled(true);

_target_options.SetOwner(&_command_window);
_target_options.SetPosition(TARGET_POSITION_X, TARGET_POSITION_Y);
_target_options.SetDimensions(TARGET_SIZE_X, TARGET_SIZE_Y, 1, 255, 1, 4);
_target_options.SetAlignment(VIDEO_X_LEFT, VIDEO_Y_TOP);
_target_options.SetOptionAlignment(VIDEO_X_LEFT, VIDEO_Y_CENTER);
_target_options.SetVerticalWrapMode(VIDEO_WRAP_MODE_NONE);
_target_options.SetTextStyle(TextStyle("text20"));
_target_options.SetCursorState(VIDEO_CURSOR_STATE_VISIBLE);
_target_options.SetCursorOffset(-50.0f, 25.0f);
}



CommandSupervisor::~CommandSupervisor() {
_command_window.Destroy();
}



void CommandSupervisor::ConstructMenus() {
_item_command.ConstructList();

std::deque<BattleCharacter*>& characters = BattleMode::CurrentInstance()->GetCharacterActors();
for (uint32 i = 0; i < characters.size(); i++)
_CreateCharacterSettings(characters[i]);
}



void CommandSupervisor::Initialize(BattleCharacter* character) {
if (character == NULL) {
IF_PRINT_WARNING(BATTLE_DEBUG) << "function recieved NULL pointer argument" << std::endl;
_state = COMMAND_STATE_INVALID;
return;
}

if (_HasCharacterSettings(character) == false)
_CreateCharacterSettings(character);

_ChangeState(COMMAND_STATE_CATEGORY);
_active_settings = &(_character_settings.find(character)->second);
    // Update _skill_list to check, if some skills need to be deactivated due to low amount of SP
    _active_settings->RefreshLists();
_category_options.SetSelection(_active_settings->GetLastCategory());

// Determine which categories should be enabled or disabled
if (_active_settings->GetAttackList()->GetNumberOptions() == 0)
_category_options.EnableOption(0, false);
else
_category_options.EnableOption(0, true);
if (_active_settings->GetDefendList()->GetNumberOptions() == 0)
_category_options.EnableOption(1, false);
else
_category_options.EnableOption(1, true);
if (_active_settings->GetSupportList()->GetNumberOptions() == 0)
_category_options.EnableOption(2, false);
else
_category_options.EnableOption(2, true);
if (_item_command.GetNumberListOptions() == 0)
_category_options.EnableOption(3, false);
else
_category_options.EnableOption(3, true);

// Warn if there are no enabled options in the category list
for (uint32 i = 0; i < _category_options.GetNumberOptions(); i++) {
if (_category_options.IsOptionEnabled(i) == true)
return;
}

IF_PRINT_WARNING(BATTLE_DEBUG) << "no options in category list were enabled" << std::endl;
}



void CommandSupervisor::Update() {
switch (_state) {
case COMMAND_STATE_CATEGORY:
_UpdateCategory();
break;
case COMMAND_STATE_ACTION:
_UpdateAction();
break;
case COMMAND_STATE_ACTOR:
_UpdateActorTarget();
break;
case COMMAND_STATE_POINT:
_UpdateAttackPointTarget();
break;
case COMMAND_STATE_INFORMATION:
_UpdateInformation();
break;
default:
IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid/unknown command state: " << _state << std::endl;
_ChangeState(COMMAND_STATE_CATEGORY);
return;
}
}



void CommandSupervisor::Draw() {
_command_window.Draw();

switch (_state) {
case COMMAND_STATE_CATEGORY:
_DrawCategory();
break;
case COMMAND_STATE_ACTION:
_DrawAction();
break;
case COMMAND_STATE_ACTOR:
_DrawActorTarget();
break;
case COMMAND_STATE_POINT:
_DrawAttackPointTarget();
break;
case COMMAND_STATE_INFORMATION:
_DrawInformation();
break;
default:
IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid/unknown command state: " << _state << std::endl;
_ChangeState(COMMAND_STATE_CATEGORY);
return;
}
}



void CommandSupervisor::NotifyActorDeath(BattleActor* actor) {
if (_state == COMMAND_STATE_INVALID) {
IF_PRINT_WARNING(BATTLE_DEBUG)
<< "function called when class was in invalid state" << std::endl;
return;
}

BattleCharacter *character = GetCommandCharacter();

// If the character currently selecting a command dies, we get out.
if (character == actor) {
_ChangeState(COMMAND_STATE_INVALID);
BattleMode::CurrentInstance()->GetMedia().cancel_sound.Play();
return;
}

// Update the selected target if the target is the actor who just deceased
if (_selected_target.GetActor() == actor) {
BattleMode::CurrentInstance()->GetMedia().cancel_sound.Play();

// Try selecting the next actor and fall back to the previous command menu
// if not possible.
if (!_selected_target.SelectNextActor(actor)) {
if (character && (_state == COMMAND_STATE_ACTOR || _state == COMMAND_STATE_POINT))
_ChangeState(COMMAND_STATE_ACTION);
return;
}
}
}



bool CommandSupervisor::_IsSkillCategorySelected() const {
uint32 category = _category_options.GetSelection();
if ((category == CATEGORY_ATTACK) || (category == CATEGORY_DEFEND) || (category == CATEGORY_SUPPORT))
return true;
else
return false;
}



bool CommandSupervisor::_IsItemCategorySelected() const {
uint32 category = _category_options.GetSelection();
if (category == CATEGORY_ITEM)
return true;
else
return false;
}



GLOBAL_TARGET CommandSupervisor::_ActionTargetType() {
if (_IsSkillCategorySelected() == true)
return _skill_command.GetSelectedSkill()->GetTargetType();
else if (_IsItemCategorySelected() == true)
return _item_command.GetSelectedItem()->GetTargetType();
else
return GLOBAL_TARGET_INVALID;
}



bool CommandSupervisor::_SetInitialTarget() {
BattleActor* user = GetCommandCharacter();
GLOBAL_TARGET target_type = _ActionTargetType();

// Party targets are simple because we don't have to restore the last save target, since there is either the
// ally party or foe party, and both parties are always valid targets (because otherwise the battle would have
// already ended).
if (IsTargetParty(target_type) == true) {
// Party-type targets are always the same, so we don't need to recall the last target in this case
return _selected_target.SetInitialTarget(user, target_type);
}

// Retrieved the last saved target depending on the type (self/ally/foe)
if (IsTargetSelf(target_type)) {
_selected_target = _active_settings->GetLastSelfTarget();
}
else if (IsTargetAlly(target_type)) {
_selected_target = _active_settings->GetLastCharacterTarget();
}
else if (IsTargetFoe(target_type)) {
_selected_target = _active_settings->GetLastEnemyTarget();
}
else {
IF_PRINT_WARNING(BATTLE_DEBUG) << "no conditions met for invalid target type: " << target_type << std::endl;
}

bool permit_dead_targets = (_selected_target.GetType() == GLOBAL_TARGET_ALLY_EVEN_DEAD);

// If the target type is invalid that means that there is no previous target so grab the initial target
if (_selected_target.GetType() == GLOBAL_TARGET_INVALID) {
if (!_selected_target.SetInitialTarget(user, target_type)) {
// No more target of that type, let's go back to the command state
_selected_target.InvalidateTarget();
BattleMode::CurrentInstance()->GetMedia().cancel_sound.Play();
return false;
}
}
// Otherwise if the last target is no longer valid, select the next valid target
else if (!_selected_target.IsValid(permit_dead_targets)) {
// Party targets should always be valid and attack points on actors do not disappear, so only the actor
// must be invalid
if (!_selected_target.SelectNextActor(user, permit_dead_targets)) {
// No more target of that type, let's go back to the command state
_selected_target.InvalidateTarget();
BattleMode::CurrentInstance()->GetMedia().cancel_sound.Play();
return false;
}
}

// This case occurs when our last target was an actor type and we're now using an action with a point target,
// or vice versa. We need to modify the target type while still retaining the original target actor.
if (_selected_target.GetType() != target_type) {
if (IsTargetPoint(target_type) == true) {
_selected_target.SetPointTarget(target_type, 0);
}
else { // then IsTargetActor(target_type) == true
_selected_target.SetActorTarget(target_type, _selected_target.GetActor());
}
}
return true;
}

void CommandSupervisor::_ChangeState(COMMAND_STATE new_state) {
if (_state == new_state) {
IF_PRINT_WARNING(BATTLE_DEBUG) << "class was already in state to change to: " << new_state << std::endl;
return;
}

if (new_state == COMMAND_STATE_INVALID) {
_active_settings = NULL;
_selected_skill = NULL;
_selected_item = NULL;
}
else if (new_state == COMMAND_STATE_CATEGORY) {
// Nothing to do here. The Initialize() function performs all necessary actions when entering this state.
}
else if (new_state == COMMAND_STATE_ACTION) {
// Construct the appropriate skill or item selection list if we're coming from the category state
if (_state == COMMAND_STATE_CATEGORY) {
switch (_category_options.GetSelection()) {
case CATEGORY_ATTACK:
_skill_command.Initialize(GetCommandCharacter()->GetGlobalCharacter()->GetAttackSkills(), _active_settings->GetAttackList());
break;
case CATEGORY_DEFEND:
_skill_command.Initialize(GetCommandCharacter()->GetGlobalCharacter()->GetDefenseSkills(), _active_settings->GetDefendList());
break;
case CATEGORY_SUPPORT:
_skill_command.Initialize(GetCommandCharacter()->GetGlobalCharacter()->GetSupportSkills(), _active_settings->GetSupportList());
break;
case CATEGORY_ITEM:
_item_command.Initialize(_active_settings->GetLastItem());
break;
default:
IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid category selection: " << _category_options.GetSelection() << std::endl;
_category_options.SetSelection(0);
return;
}
}
}
else if (new_state == COMMAND_STATE_ACTOR) {
// Set the initial target if we're coming from the action selection state
if (_state == COMMAND_STATE_ACTION) {
if (!_SetInitialTarget()) {
BattleMode::CurrentInstance()->GetMedia().cancel_sound.Play();
return;
}
}

_CreateActorTargetText();
}
else if (new_state == COMMAND_STATE_POINT) {
_CreateAttackPointTargetText();
}
else if (new_state == COMMAND_STATE_INFORMATION) {
_CreateInformationText();
}

_state = new_state;
}



void CommandSupervisor::_UpdateCategory() {
_category_options.Update();

// Event priority is given to the player requesting to abort the command selection process
if (InputManager->CancelPress()) {
BattleMode *BM = BattleMode::CurrentInstance();
// The only time we do not allow the player to abort the command menu is if they are running the battle with the "wait" setting active and the
// current character is in the command state. Under these circumstances, the player has to enter a command for this character before the battle
// is allowed to continue.
if ((BM->GetBattleType() == BATTLE_TYPE_WAIT || BM->GetBattleType() == BATTLE_TYPE_SEMI_ACTIVE)
&& (GetCommandCharacter()->GetState() == ACTOR_STATE_COMMAND)) {
BM->GetMedia().cancel_sound.Play();
}
else {
_ChangeState(COMMAND_STATE_INVALID);
BM->NotifyCommandCancel();
BM->GetMedia().cancel_sound.Play();
}
}

else if (InputManager->ConfirmPress()) {
if (_category_options.IsOptionEnabled(_category_options.GetSelection()) == true) {
_active_settings->SetLastCategory(_category_options.GetSelection());
_ChangeState(COMMAND_STATE_ACTION);
BattleMode::CurrentInstance()->GetMedia().confirm_sound.Play();
}
else {
BattleMode::CurrentInstance()->GetMedia().invalid_sound.Play();
}
}

else if (InputManager->LeftPress()) {
_category_options.InputLeft();
BattleMode::CurrentInstance()->GetMedia().cursor_sound.Play();
}

else if (InputManager->RightPress()) {
_category_options.InputRight();
BattleMode::CurrentInstance()->GetMedia().cursor_sound.Play();
}
}



void CommandSupervisor::_UpdateAction() {
if (InputManager->CancelPress()) {
_ChangeState(COMMAND_STATE_CATEGORY);
BattleMode::CurrentInstance()->GetMedia().cancel_sound.Play();
return;
}

if (_IsSkillCategorySelected() == true) {
_selected_skill = _skill_command.GetSelectedSkill();

if (InputManager->ConfirmPress()) {
            bool is_skill_enabled = _skill_command.GetSelectedSkillEnabled();
if (is_skill_enabled == true) {
_ChangeState(COMMAND_STATE_ACTOR);
BattleMode::CurrentInstance()->GetMedia().confirm_sound.Play();
}
else {
BattleMode::CurrentInstance()->GetMedia().invalid_sound.Play();
}
}

else if (InputManager->MenuPress()) {
_ChangeState(COMMAND_STATE_INFORMATION);
BattleMode::CurrentInstance()->GetMedia().confirm_sound.Play();
}

else {
_skill_command.UpdateList();
}
}
else if (_IsItemCategorySelected() == true) {
_selected_item = _item_command.GetSelectedItem();

if (InputManager->ConfirmPress()) {
// Permit the selection only where are items left.
if (_selected_item != NULL && _item_command.IsSelectedItemAvailable()) {
_ChangeState(COMMAND_STATE_ACTOR);
BattleMode::CurrentInstance()->GetMedia().confirm_sound.Play();
}
else {
BattleMode::CurrentInstance()->GetMedia().invalid_sound.Play();
}
}

else if (InputManager->MenuPress()) {
_ChangeState(COMMAND_STATE_INFORMATION);
BattleMode::CurrentInstance()->GetMedia().confirm_sound.Play();
}

else {
_item_command.UpdateList();
}
}
else {
IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid category selection: " << _category_options.GetSelection() << std::endl;
_state = COMMAND_STATE_CATEGORY;
_category_options.SetSelection(0);
}
}



void CommandSupervisor::_UpdateActorTarget() {
if (InputManager->CancelPress()) {
_ChangeState(COMMAND_STATE_ACTION);
BattleMode::CurrentInstance()->GetMedia().cancel_sound.Play();
}

else if (InputManager->ConfirmPress()) {
if (IsTargetPoint(_selected_target.GetType()) == true) {
_ChangeState(COMMAND_STATE_POINT);
}
else {
_FinalizeCommand();
}
}

else if (InputManager->UpPress() || InputManager->DownPress()) {
if (InputManager->DownPress())
_target_options.InputDown();
else
_target_options.InputUp();

bool direction = InputManager->DownPress();
bool permit_dead_targets = (_selected_target.GetType() == GLOBAL_TARGET_ALLY_EVEN_DEAD);

if ((IsTargetActor(_selected_target.GetType()) == true) || (IsTargetPoint(_selected_target.GetType()) == true)) {
_selected_target.SelectNextActor(GetCommandCharacter(), direction, true, permit_dead_targets);
_CreateActorTargetText();
BattleMode::CurrentInstance()->GetMedia().cursor_sound.Play();
}
}
}



void CommandSupervisor::_UpdateAttackPointTarget() {
if (InputManager->CancelPress()) {
_ChangeState(COMMAND_STATE_ACTOR);
BattleMode::CurrentInstance()->GetMedia().cancel_sound.Play();
}

else if (InputManager->ConfirmPress()
|| _selected_target.GetActor()->GetAttackPoints().size() == 1) {
_FinalizeCommand();
}

else if (InputManager->UpPress() || InputManager->DownPress()) {
if (InputManager->DownPress())
_target_options.InputDown();
else
_target_options.InputUp();

_selected_target.SelectNextPoint(GetCommandCharacter(), InputManager->DownPress());
_CreateAttackPointTargetText();
BattleMode::CurrentInstance()->GetMedia().cursor_sound.Play();
}
}



void CommandSupervisor::_UpdateInformation() {
if (InputManager->CancelPress() || InputManager->MenuPress()) {
_state = COMMAND_STATE_ACTION;
BattleMode::CurrentInstance()->GetMedia().cancel_sound.Play();
}

else if (InputManager->ConfirmPress()) {
_ChangeState(COMMAND_STATE_ACTOR);
BattleMode::CurrentInstance()->GetMedia().cancel_sound.Play();
}

// Change selected skill/item and update the information text
else if (InputManager->UpPress() || InputManager->DownPress()) {

if (_IsSkillCategorySelected() == true) {
_skill_command.UpdateList();
_selected_skill = _skill_command.GetSelectedSkill();
BattleMode::CurrentInstance()->GetMedia().cursor_sound.Play();
}
else if (_IsItemCategorySelected() == true) {
_item_command.UpdateList();
_selected_item = _item_command.GetSelectedItem();
BattleMode::CurrentInstance()->GetMedia().cursor_sound.Play();
}

_CreateInformationText();
}

else if (InputManager->RightPress() || InputManager->LeftPress()) {
// TODO: toggle between description text and detailed stats
}
}



void CommandSupervisor::_DrawCategory() {
_category_options.Draw();
}



void CommandSupervisor::_DrawAction() {
uint32 category_index = _category_options.GetSelection();

// Draw the corresponding category icon and text to the left side of the window
VideoManager->SetDrawFlags(VIDEO_X_CENTER, VIDEO_Y_CENTER, 0);
VideoManager->Move(570.0f, 75.0);
_category_icons[category_index].Draw();
VideoManager->MoveRelative(0.0f, -35.0f);
_category_text[category_index].Draw();

// Draw the header and list for either the skills or items to the right side of the window
if (_IsSkillCategorySelected() == true) {
_skill_command.DrawList();
}
else if (_IsItemCategorySelected() == true) {
_item_command.DrawList();
}
}



void CommandSupervisor::_DrawActorTarget() {
VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_BOTTOM, VIDEO_BLEND, 0);
VideoManager->Move(560.0f, 110.0f);
_window_header.Draw();
VideoManager->Move(560.0f, 85.0f);
_window_text.Draw();

// _target_options.Draw();
// TODO: draw relevant status/elemental icons
}



void CommandSupervisor::_DrawAttackPointTarget() {
VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_BOTTOM, VIDEO_BLEND, 0);
VideoManager->Move(560.0f, 110.0f);
_window_header.Draw();
VideoManager->Move(560.0f, 85.0f);
// _window_text.Draw();

_target_options.Draw();
// TODO: draw relevant status/elemental icons
}



void CommandSupervisor::_DrawInformation() {
VideoManager->SetDrawFlags(VIDEO_X_LEFT, VIDEO_Y_BOTTOM, VIDEO_BLEND, 0);
VideoManager->Move(560.0f, 110.0f);
_window_header.Draw();
VideoManager->Move(560.0f, 85.0f);
_window_text.Draw();

// TODO: draw relevant status/elemental icons
}



void CommandSupervisor::_CreateActorTargetText() {
_window_header.SetText(UTranslate("Select Target"));

_target_options.ClearOptions();
if (IsTargetParty(_selected_target.GetType()) == true) {
if (_selected_target.GetType() == GLOBAL_TARGET_ALL_ALLIES) {
_target_options.AddOption(UTranslate("All Allies"));
}
else {
_target_options.AddOption(UTranslate("All Enemies"));
}
}
else if (IsTargetSelf(_selected_target.GetType()) == true) {
_target_options.AddOption(_selected_target.GetActor()->GetName());
}
else if (IsTargetAlly(_selected_target.GetType()) == true) {
for (uint32 i = 0; i < BattleMode::CurrentInstance()->GetCharacterActors().size(); i++) {
_target_options.AddOption(BattleMode::CurrentInstance()->GetCharacterActors().at(i)->GetName());
if (_selected_target.GetType() != GLOBAL_TARGET_ALLY_EVEN_DEAD
&& !BattleMode::CurrentInstance()->GetCharacterActors().at(i)->IsAlive()) {
_target_options.EnableOption(i, false);
}
}
}
else if (IsTargetFoe(_selected_target.GetType()) == true) {
for (uint32 i = 0; i < BattleMode::CurrentInstance()->GetEnemyActors().size(); i++) {
_target_options.AddOption(BattleMode::CurrentInstance()->GetEnemyActors().at(i)->GetName());
if (BattleMode::CurrentInstance()->GetEnemyActors().at(i)->IsAlive() == false) {
_target_options.EnableOption(i, false);
}
}
}
else {
IF_PRINT_WARNING(BATTLE_DEBUG) << "invalid target type: " << _selected_target.GetType() << std::endl;
}

// TEMP: remove once _target_options box works properly
if (IsTargetParty(_selected_target.GetType()) == true) {
if (_selected_target.GetType() == GLOBAL_TARGET_ALL_ALLIES) {
_window_text.SetText(UTranslate("All Allies"));
}
else {
_window_text.SetText(UTranslate("All Enemies"));
}
}
else {
_window_text.SetText(_selected_target.GetActor()->GetName());
}

}



void CommandSupervisor::_CreateAttackPointTargetText() {
_window_header.SetText(UTranslate("Select Attack Point"));

BattleActor* actor = _selected_target.GetActor();
uint32 selected_point = _selected_target.GetPoint();

_target_options.ClearOptions();
for (uint32 i = 0; i < actor->GetAttackPoints().size(); i++) {
_target_options.AddOption(actor->GetAttackPoints().at(i)->GetName());
}

_target_options.SetSelection(selected_point);
}



void CommandSupervisor::_CreateInformationText() {
ustring info_text;

if (_IsSkillCategorySelected() == true) {
_window_header.SetText(_selected_skill->GetName());

info_text = UTranslate("Skill Points: " + NumberToString(_selected_skill->GetSPRequired())) + MakeUnicodeString("\n");
info_text += UTranslate("Target Type: ") + MakeUnicodeString(GetTargetText(_selected_skill->GetTargetType())) + MakeUnicodeString("\n");
info_text += UTranslate("Prep Time: ") + MakeUnicodeString(NumberToString(_selected_skill->GetWarmupTime())) + MakeUnicodeString("\n");
info_text += UTranslate("Cool Time: ") + MakeUnicodeString(NumberToString(_selected_skill->GetCooldownTime())) + MakeUnicodeString("\n");
}
else if (_IsItemCategorySelected() == true) {
_window_header.SetText(_selected_item->GetItem().GetName());

info_text = UTranslate("Quantity: " + NumberToString(_selected_item->GetBattleCount())) + MakeUnicodeString("\n");
info_text += UTranslate("Target Type: ") + MakeUnicodeString(GetTargetText(_selected_item->GetItem().GetTargetType())) + MakeUnicodeString("\n");
}
else {
IF_PRINT_WARNING(BATTLE_DEBUG) << "unknown category selected: " << _category_options.GetSelection() << std::endl;
}

_window_text.SetText(info_text);
}



void CommandSupervisor::_FinalizeCommand() {
BattleAction* new_action = NULL;
BattleCharacter* character = GetCommandCharacter();

_active_settings->SaveLastTarget(_selected_target);

if (_IsSkillCategorySelected() == true) {
new_action = new SkillAction(character, _selected_target, _selected_skill);
}
else if (_IsItemCategorySelected() == true) {
new_action = new ItemAction(character, _selected_target, _selected_item);

// Reserve the item for use by the character.
_selected_item->DecrementBattleCount();
_item_command.RefreshEntry(_item_command.GetItemIndex());
}
else {
IF_PRINT_WARNING(BATTLE_DEBUG) << "did not create action for character, unknown category selected: " << _category_options.GetSelection() << std::endl;
}
character->SetAction(new_action);

_ChangeState(COMMAND_STATE_INVALID);
BattleMode::CurrentInstance()->NotifyCharacterCommandComplete(character);
BattleMode::CurrentInstance()->GetMedia().finish_sound.Play();
}

} // namespace private_battle

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