Permalink
Browse files

Improved a bit the equipment handling in the menu mode.

First of all, I turned PHYS ATK/DEF into ATK/DEF alone,
META ATK/DEF into M.ATK/M.DEF, as this is shorter
and many people are used to those names out there.

As for the menu actually, I made only the equipable items
appear when trying to equip, and made the stats diff appear
bottom right. I.e.: If you try to equip a stronger armor,
it will show a +X in green bottom right, and a -X in red
if it is weaker.

The menu drawing logic is still very unoptimized, but this kind
of fix belongs to another commit.
  • Loading branch information...
1 parent 5e6afc3 commit 11f20813e402f97d347a76870318698ba4ea2f93 Yohann Ferreira committed Sep 20, 2012
Showing with 166 additions and 82 deletions.
  1. +118 −70 src/modes/menu/menu.cpp
  2. +44 −12 src/modes/menu/menu_views.cpp
  3. +4 −0 src/modes/menu/menu_views.h
View
@@ -844,146 +844,194 @@ void MenuMode::_DrawBottomMenu() {
VideoManager->MoveRelative(0, 20);
GlobalWeapon *wpn = ch->GetWeaponEquipped();
- VideoManager->Text()->Draw(UTranslate("PHYS ATK: ") + MakeUnicodeString(NumberToString(wpn ? wpn->GetPhysicalAttack() : 0)));
+ VideoManager->Text()->Draw(UTranslate("ATK: ") + MakeUnicodeString(NumberToString(wpn ? wpn->GetPhysicalAttack() : 0)));
VideoManager->MoveRelative(0, 20);
GlobalArmor *head_armor = ch->GetHeadArmorEquipped();
- VideoManager->Text()->Draw(UTranslate("PHYS DEF: ") + MakeUnicodeString(NumberToString(head_armor ? head_armor->GetPhysicalDefense() : 0)));
+ VideoManager->Text()->Draw(UTranslate("DEF: ") + MakeUnicodeString(NumberToString(head_armor ? head_armor->GetPhysicalDefense() : 0)));
VideoManager->MoveRelative(0, 20);
GlobalArmor *torso_armor = ch->GetTorsoArmorEquipped();
- VideoManager->Text()->Draw(UTranslate("PHYS DEF: ") + MakeUnicodeString(NumberToString(torso_armor ? torso_armor->GetPhysicalDefense() : 0)));
+ VideoManager->Text()->Draw(UTranslate("DEF: ") + MakeUnicodeString(NumberToString(torso_armor ? torso_armor->GetPhysicalDefense() : 0)));
VideoManager->MoveRelative(0, 20);
GlobalArmor *arm_armor = ch->GetArmArmorEquipped();
- VideoManager->Text()->Draw(UTranslate("PHYS DEF: ") + MakeUnicodeString(NumberToString(arm_armor ? arm_armor->GetPhysicalDefense() : 0)));
+ VideoManager->Text()->Draw(UTranslate("DEF: ") + MakeUnicodeString(NumberToString(arm_armor ? arm_armor->GetPhysicalDefense() : 0)));
VideoManager->MoveRelative(0, 20);
GlobalArmor *leg_armor = ch->GetLegArmorEquipped();
- VideoManager->Text()->Draw(UTranslate("PHYS DEF: ") + MakeUnicodeString(NumberToString(leg_armor ? leg_armor->GetPhysicalDefense() : 0)));
+ VideoManager->Text()->Draw(UTranslate("DEF: ") + MakeUnicodeString(NumberToString(leg_armor ? leg_armor->GetPhysicalDefense() : 0)));
VideoManager->Move(550, 577);
VideoManager->MoveRelative(0, 20);
- VideoManager->Text()->Draw(UTranslate("META ATK: ") + MakeUnicodeString(NumberToString(wpn ? wpn->GetMetaphysicalAttack() : 0)));
+ VideoManager->Text()->Draw(UTranslate("M.ATK: ") + MakeUnicodeString(NumberToString(wpn ? wpn->GetMetaphysicalAttack() : 0)));
VideoManager->MoveRelative(0, 20);
- VideoManager->Text()->Draw(UTranslate("META DEF: ") + MakeUnicodeString(NumberToString(head_armor ? head_armor->GetMetaphysicalDefense() : 0)));
+ VideoManager->Text()->Draw(UTranslate("M.DEF: ") + MakeUnicodeString(NumberToString(head_armor ? head_armor->GetMetaphysicalDefense() : 0)));
VideoManager->MoveRelative(0, 20);
- VideoManager->Text()->Draw(UTranslate("META DEF: ") + MakeUnicodeString(NumberToString(torso_armor ? torso_armor->GetMetaphysicalDefense() : 0)));
+ VideoManager->Text()->Draw(UTranslate("M.DEF: ") + MakeUnicodeString(NumberToString(torso_armor ? torso_armor->GetMetaphysicalDefense() : 0)));
VideoManager->MoveRelative(0, 20);
- VideoManager->Text()->Draw(UTranslate("META DEF: ") + MakeUnicodeString(NumberToString(arm_armor ? arm_armor->GetMetaphysicalDefense() : 0)));
+ VideoManager->Text()->Draw(UTranslate("M.DEF: ") + MakeUnicodeString(NumberToString(arm_armor ? arm_armor->GetMetaphysicalDefense() : 0)));
VideoManager->MoveRelative(0, 20);
- VideoManager->Text()->Draw(UTranslate("META DEF: ") + MakeUnicodeString(NumberToString(leg_armor ? leg_armor->GetMetaphysicalDefense() : 0)));
+ VideoManager->Text()->Draw(UTranslate("M.DEF: ") + MakeUnicodeString(NumberToString(leg_armor ? leg_armor->GetMetaphysicalDefense() : 0)));
VideoManager->SetDrawFlags(VIDEO_X_CENTER,VIDEO_Y_BOTTOM,0);
-
+ // Show the selected equipment stats (and diff with the current one.)
if (_equip_window._active_box == EQUIP_ACTIVE_LIST) {
- VideoManager->Move(755, 577);
+ ustring equipment_name;
+ uint32 physical_attribute = 0;
+ uint32 magical_attribute = 0;
+
+ uint32 current_phys_attribute = 0;
+ uint32 current_mag_attribute = 0;
switch (_equip_window._equip_select.GetSelection()) {
case EQUIP_WEAPON:
{
GlobalWeapon* weapon = GlobalManager->GetInventoryWeapons()->at(_equip_window._equip_list.GetSelection());
- VideoManager->Text()->Draw(weapon->GetName());
- VideoManager->MoveRelative(0, 20);
+ equipment_name = weapon->GetName();
+ physical_attribute = weapon->GetPhysicalAttack();
+ magical_attribute = weapon->GetMetaphysicalAttack();
- VideoManager->Text()->Draw(UTranslate("PHYS ATK:"));
- VideoManager->MoveRelative(0, 20);
- VideoManager->Text()->Draw(MakeUnicodeString(NumberToString(weapon->GetPhysicalAttack())));
- VideoManager->MoveRelative(0, 20);
-
- VideoManager->Text()->Draw(UTranslate("META ATK:"));
- VideoManager->MoveRelative(0, 20);
- VideoManager->Text()->Draw(MakeUnicodeString(NumberToString(weapon->GetMetaphysicalAttack())));
- VideoManager->MoveRelative(0, 20);
+ GlobalWeapon *current_wpn = ch->GetWeaponEquipped();
+ if (current_wpn) {
+ current_phys_attribute = current_wpn->GetPhysicalAttack();
+ current_mag_attribute = current_wpn->GetMetaphysicalAttack();
+ }
break;
} // case EQUIP_WEAPON
case EQUIP_HEADGEAR:
{
GlobalArmor* armor = GlobalManager->GetInventoryHeadArmor()->at(_equip_window._equip_list.GetSelection());
- VideoManager->Text()->Draw(armor->GetName());
- VideoManager->MoveRelative(0, 20);
-
- VideoManager->Text()->Draw(UTranslate("PHYS DEF:"));
- VideoManager->MoveRelative(0, 20);
- VideoManager->Text()->Draw(MakeUnicodeString(NumberToString(armor->GetPhysicalDefense())));
- VideoManager->MoveRelative(0, 20);
+ equipment_name = armor->GetName();
+ physical_attribute = armor->GetPhysicalDefense();
+ magical_attribute = armor->GetMetaphysicalDefense();
- VideoManager->Text()->Draw(UTranslate("META DEF:"));
- VideoManager->MoveRelative(0, 20);
- VideoManager->Text()->Draw(MakeUnicodeString(NumberToString(armor->GetMetaphysicalDefense())));
- VideoManager->MoveRelative(0, 20);
+ GlobalArmor *current_armor = ch->GetHeadArmorEquipped();
+ if (current_armor) {
+ current_phys_attribute = current_armor->GetPhysicalDefense();
+ current_mag_attribute = current_armor->GetMetaphysicalDefense();
+ }
break;
} // case EQUIP_HEADGEAR
case EQUIP_BODYARMOR:
{
GlobalArmor* armor = GlobalManager->GetInventoryTorsoArmor()->at(_equip_window._equip_list.GetSelection());
- VideoManager->Text()->Draw(armor->GetName());
- VideoManager->MoveRelative(0, 20);
-
- VideoManager->Text()->Draw(UTranslate("PHYS DEF:"));
- VideoManager->MoveRelative(0, 20);
- VideoManager->Text()->Draw(MakeUnicodeString(NumberToString(armor->GetPhysicalDefense())));
- VideoManager->MoveRelative(0, 20);
-
- VideoManager->Text()->Draw(UTranslate("META DEF:"));
- VideoManager->MoveRelative(0, 20);
- VideoManager->Text()->Draw(MakeUnicodeString(NumberToString(armor->GetMetaphysicalDefense())));
- VideoManager->MoveRelative(0, 20);
+ equipment_name = armor->GetName();
+ physical_attribute = armor->GetPhysicalDefense();
+ magical_attribute = armor->GetMetaphysicalDefense();
+ GlobalArmor *current_armor = ch->GetTorsoArmorEquipped();
+ if (current_armor) {
+ current_phys_attribute = current_armor->GetPhysicalDefense();
+ current_mag_attribute = current_armor->GetMetaphysicalDefense();
+ }
break;
} // case EQUIP_BODYARMOR
case EQUIP_OFFHAND:
{
GlobalArmor* armor = GlobalManager->GetInventoryArmArmor()->at(_equip_window._equip_list.GetSelection());
- VideoManager->Text()->Draw(armor->GetName());
- VideoManager->MoveRelative(0, 20);
-
- VideoManager->Text()->Draw(UTranslate("PHYS DEF:"));
- VideoManager->MoveRelative(0, 20);
- VideoManager->Text()->Draw(MakeUnicodeString(NumberToString(armor->GetPhysicalDefense())));
- VideoManager->MoveRelative(0, 20);
-
- VideoManager->Text()->Draw(UTranslate("META DEF:"));
- VideoManager->MoveRelative(0, 20);
- VideoManager->Text()->Draw(MakeUnicodeString(NumberToString(armor->GetMetaphysicalDefense())));
- VideoManager->MoveRelative(0, 20);
+ equipment_name = armor->GetName();
+ physical_attribute = armor->GetPhysicalDefense();
+ magical_attribute = armor->GetMetaphysicalDefense();
+ GlobalArmor *current_armor = ch->GetArmArmorEquipped();
+ if (current_armor) {
+ current_phys_attribute = current_armor->GetPhysicalDefense();
+ current_mag_attribute = current_armor->GetMetaphysicalDefense();
+ }
break;
} // case EQUIP_OFFHAND
case EQUIP_LEGGINGS:
{
GlobalArmor* armor = GlobalManager->GetInventoryLegArmor()->at(_equip_window._equip_list.GetSelection());
- VideoManager->Text()->Draw(armor->GetName());
- VideoManager->MoveRelative(0, 20);
-
- VideoManager->Text()->Draw(UTranslate("PHYS DEF:"));
- VideoManager->MoveRelative(0, 20);
- VideoManager->Text()->Draw(MakeUnicodeString(NumberToString(armor->GetPhysicalDefense())));
- VideoManager->MoveRelative(0, 20);
-
- VideoManager->Text()->Draw(UTranslate("META DEF:"));
- VideoManager->MoveRelative(0, 20);
- VideoManager->Text()->Draw(MakeUnicodeString(NumberToString(armor->GetMetaphysicalDefense())));
- VideoManager->MoveRelative(0, 20);
+ equipment_name = armor->GetName();
+ physical_attribute = armor->GetPhysicalDefense();
+ magical_attribute = armor->GetMetaphysicalDefense();
+ GlobalArmor *current_armor = ch->GetLegArmorEquipped();
+ if (current_armor) {
+ current_phys_attribute = current_armor->GetPhysicalDefense();
+ current_mag_attribute = current_armor->GetMetaphysicalDefense();
+ }
break;
} // case EQUIP_LEGGINGS
default:
break;
} // switch
+
+ // Display the info
+ VideoManager->Move(755, 577);
+ VideoManager->Text()->Draw(equipment_name);
+ VideoManager->MoveRelative(0, 20);
+
+ if (_equip_window._equip_select.GetSelection() == EQUIP_WEAPON)
+ VideoManager->Text()->Draw(UTranslate("ATK:"));
+ else
+ VideoManager->Text()->Draw(UTranslate("DEF:"));
+ VideoManager->MoveRelative(0, 20);
+ VideoManager->Text()->Draw(MakeUnicodeString(NumberToString(physical_attribute)));
+
+ if (current_phys_attribute > 0 && physical_attribute - current_phys_attribute != 0) {
+ std::string sign_start;
+ Color text_color;
+ if ((int32)(physical_attribute - current_phys_attribute) > 0) {
+ sign_start = "+";
+ text_color = Color::green;
+ }
+ else {
+ sign_start = "";
+ text_color = Color::red;
+ }
+
+ ustring diff_stat = MakeUnicodeString(sign_start)
+ + MakeUnicodeString(NumberToString(physical_attribute - current_phys_attribute));
+ VideoManager->MoveRelative(60, 0);
+ VideoManager->Text()->Draw(diff_stat, TextStyle("text22", text_color));
+ VideoManager->MoveRelative(-60, 0);
+ }
+ VideoManager->MoveRelative(0, 20);
+
+ if (_equip_window._equip_select.GetSelection() == EQUIP_WEAPON)
+ VideoManager->Text()->Draw(UTranslate("M.ATK:"));
+ else
+ VideoManager->Text()->Draw(UTranslate("M.DEF:"));
+ VideoManager->MoveRelative(0, 20);
+ VideoManager->Text()->Draw(MakeUnicodeString(NumberToString(magical_attribute)));
+
+ if (current_mag_attribute > 0 && magical_attribute - current_mag_attribute != 0) {
+ std::string sign_start;
+ Color text_color;
+ if ((int32)(magical_attribute - current_mag_attribute) > 0) {
+ sign_start = "+";
+ text_color = Color::green;
+ }
+ else {
+ sign_start = "";
+ text_color = Color::red;
+ }
+
+ ustring diff_stat = MakeUnicodeString(sign_start)
+ + MakeUnicodeString(NumberToString(magical_attribute - current_mag_attribute));
+ VideoManager->MoveRelative(60, 0);
+ VideoManager->Text()->Draw(diff_stat, TextStyle("text22", text_color));
+ VideoManager->MoveRelative(-60, 0);
+ }
+
+ VideoManager->MoveRelative(0, 20);
+
} // if EQUIP_ACTIVE_LIST
} // if SHOW_EQUIP
else {
@@ -1220,37 +1220,45 @@ void EquipWindow::Update() {
}
break;
- //Choose replacement
+ // Choose replacement when equipping
case EQUIP_ACTIVE_LIST:
if (event == VIDEO_OPTION_CONFIRM) {
GlobalCharacter* ch = dynamic_cast<GlobalCharacter*>(GlobalManager->GetActiveParty()->GetActorAtIndex(_char_select.GetSelection()));
- uint32 id_num;
+ // Equipment global Id.
+ uint32 id_num = 0;
+ // Get the actual inventory index.
+ uint32 inventory_id = _equip_list_inv_index[_equip_list.GetSelection()];
switch ( _equip_select.GetSelection() ) {
case EQUIP_WEAPON:
- { GlobalWeapon* wpn = GlobalManager->GetInventoryWeapons()->at(_equip_list.GetSelection());
+ {
+ GlobalWeapon* wpn = GlobalManager->GetInventoryWeapons()->at(inventory_id);
if (wpn->GetUsableBy() & ch->GetID()) {
id_num = wpn->GetID();
GlobalManager->AddToInventory(ch->EquipWeapon((GlobalWeapon*)GlobalManager->RetrieveFromInventory(id_num)));
}
else {
MenuMode::CurrentInstance()->_menu_sounds["cancel"].Play();
}
- break;}
+ break;
+ }
case EQUIP_HEADGEAR:
- { GlobalArmor* hlm = GlobalManager->GetInventoryHeadArmor()->at(_equip_list.GetSelection());
+ {
+ GlobalArmor* hlm = GlobalManager->GetInventoryHeadArmor()->at(inventory_id);
if (hlm->GetUsableBy() & ch->GetID()) {
id_num = hlm->GetID();
GlobalManager->AddToInventory(ch->EquipHeadArmor((GlobalArmor*)GlobalManager->RetrieveFromInventory(id_num)));
}
else {
MenuMode::CurrentInstance()->_menu_sounds["cancel"].Play();
}
- break;}
+ break;
+ }
case EQUIP_BODYARMOR:
- { GlobalArmor* arm = GlobalManager->GetInventoryTorsoArmor()->at(_equip_list.GetSelection());
+ {
+ GlobalArmor* arm = GlobalManager->GetInventoryTorsoArmor()->at(inventory_id);
if (arm->GetUsableBy() & ch->GetID()) {
id_num = arm->GetID();
GlobalManager->AddToInventory(ch->EquipTorsoArmor((GlobalArmor*)GlobalManager->RetrieveFromInventory(id_num)));
@@ -1261,29 +1269,34 @@ void EquipWindow::Update() {
break;}
case EQUIP_OFFHAND:
- { GlobalArmor* shld = GlobalManager->GetInventoryArmArmor()->at(_equip_list.GetSelection());
+ {
+ GlobalArmor* shld = GlobalManager->GetInventoryArmArmor()->at(inventory_id);
if (shld->GetUsableBy() & ch->GetID()) {
id_num = shld->GetID();
GlobalManager->AddToInventory(ch->EquipArmArmor((GlobalArmor*)GlobalManager->RetrieveFromInventory(id_num)));
}
else {
MenuMode::CurrentInstance()->_menu_sounds["cancel"].Play();
}
- break;}
+ break;
+ }
case EQUIP_LEGGINGS:
- { GlobalArmor* lgs = GlobalManager->GetInventoryLegArmor()->at(_equip_list.GetSelection());
+ {
+ GlobalArmor* lgs = GlobalManager->GetInventoryLegArmor()->at(inventory_id);
if (lgs->GetUsableBy() & ch->GetID()) {
id_num = lgs->GetID();
GlobalManager->AddToInventory(ch->EquipLegArmor((GlobalArmor*)GlobalManager->RetrieveFromInventory(id_num)));
}
else {
MenuMode::CurrentInstance()->_menu_sounds["cancel"].Play();
}
- break;}
+ break;
+ }
default:
- PRINT_WARNING << "Equip slot value is invalid: " << _equip_select.GetSelection() << std::endl;
+ PRINT_WARNING << "Equip slot value is invalid: "
+ << inventory_id << std::endl;
break;
} // switch _equip_select.GetSelection()
@@ -1335,12 +1348,31 @@ void EquipWindow::_UpdateEquipList() {
if (equipment_list != NULL)
gearsize = equipment_list->size();
+ // Clear the replacer ids
+ _equip_list_inv_index.clear();
// Add the options
for (uint32 j = 0; j < gearsize; j++) {
+ uint32 usability_bitmask = 0;
+ if (_equip_select.GetSelection() == EQUIP_WEAPON) {
+ GlobalWeapon *selected_weapon = dynamic_cast<GlobalWeapon*>(equipment_list->at(j));
+ usability_bitmask = selected_weapon->GetUsableBy();
+ }
+ else {
+ GlobalArmor *selected_armor = dynamic_cast<GlobalArmor*>(equipment_list->at(j));
+ usability_bitmask = selected_armor->GetUsableBy();
+ }
+
+ // If the character can't equip the item, don't show it.
+ if (_equip && !(usability_bitmask & ch->GetID()))
+ continue;
+
options.push_back(MakeUnicodeString("<") +
MakeUnicodeString(equipment_list->at(j)->GetIconImage().GetFilename()) +
MakeUnicodeString("><70>") +
equipment_list->at(j)->GetName());
+
+ // Add the actual inventory index
+ _equip_list_inv_index.push_back(j);
}
_equip_list.SetOptions(options);
Oops, something went wrong.

0 comments on commit 11f2081

Please sign in to comment.