#include "../common/GameConfig.h"
#include "../common/GameState.h"
#include "../common/Hero.h"
+#include "../common/Inventory.h"
#include "../common/Item.h"
#include "../common/Stats.h"
#include "../graphics/Font.h"
using app::Input;
using common::Hero;
+using common::Inventory;
using common::Item;
using common::Stats;
using geometry::Vector;
void EquipMenu::HandleEvents(const Input &input) {
-
+ if (actionMenu.IsActive()) {
+ if (input.JustPressed(Input::PAD_UP)) {
+ actionMenu.PreviousRow();
+ }
+ if (input.JustPressed(Input::PAD_DOWN)) {
+ actionMenu.NextRow();
+ }
+ if (input.JustPressed(Input::ACTION_A)) {
+ switch (actionMenu.Selected()) {
+ case CHOICE_EQUIP:
+ actionMenu.SetSelected();
+ equipmentMenu.SetActive();
+ break;
+ case CHOICE_STRONGEST:
+ break;
+ case CHOICE_REMOVE:
+ actionMenu.SetSelected();
+ equipmentMenu.SetActive();
+ break;
+ case CHOICE_REMOVE_ALL:
+ RemoveAllEquipment();
+ break;
+ case CHOICE_DROP:
+ actionMenu.SetSelected();
+ equipmentMenu.SetActive();
+ break;
+ }
+ } else if (input.JustPressed(Input::ACTION_B)) {
+ Ctrl().PopState();
+ }
+ }
}
void EquipMenu::UpdateWorld(float deltaT) {
LoadEquipment();
}
+Hero &EquipMenu::GetHero() {
+ return *parent->Game().state->party[cursor];
+}
+
const Hero &EquipMenu::GetHero() const {
return *parent->Game().state->party[cursor];
}
+
void EquipMenu::LoadEquipment() {
equipmentMenu.Clear();
- equipmentMenu.Add(GetHero().Weapon()->Name(), GetHero().Weapon(), true, GetHero().Weapon()->MenuIcon());
- equipmentMenu.Add(GetHero().Armor()->Name(), GetHero().Armor(), true, GetHero().Armor()->MenuIcon());
- equipmentMenu.Add(GetHero().Shield()->Name(), GetHero().Shield(), true, GetHero().Shield()->MenuIcon());
- equipmentMenu.Add(GetHero().Helmet()->Name(), GetHero().Helmet(), true, GetHero().Helmet()->MenuIcon());
- equipmentMenu.Add(GetHero().Ring()->Name(), GetHero().Ring(), true, GetHero().Ring()->MenuIcon());
- equipmentMenu.Add(GetHero().Jewel()->Name(), GetHero().Jewel(), true, GetHero().Jewel()->MenuIcon());
+ if (GetHero().HasWeapon()) {
+ equipmentMenu.Add(GetHero().Weapon()->Name(), GetHero().Weapon(), true, GetHero().Weapon()->MenuIcon());
+ } else {
+ equipmentMenu.Add(parent->Res().noEquipmentText, 0, false);
+ }
+ if (GetHero().HasArmor()) {
+ equipmentMenu.Add(GetHero().Armor()->Name(), GetHero().Armor(), true, GetHero().Armor()->MenuIcon());
+ } else {
+ equipmentMenu.Add(parent->Res().noEquipmentText, 0, false);
+ }
+ if (GetHero().HasShield()) {
+ equipmentMenu.Add(GetHero().Shield()->Name(), GetHero().Shield(), true, GetHero().Shield()->MenuIcon());
+ } else {
+ equipmentMenu.Add(parent->Res().noEquipmentText, 0, false);
+ }
+ if (GetHero().HasHelmet()) {
+ equipmentMenu.Add(GetHero().Helmet()->Name(), GetHero().Helmet(), true, GetHero().Helmet()->MenuIcon());
+ } else {
+ equipmentMenu.Add(parent->Res().noEquipmentText, 0, false);
+ }
+ if (GetHero().HasRing()) {
+ equipmentMenu.Add(GetHero().Ring()->Name(), GetHero().Ring(), true, GetHero().Ring()->MenuIcon());
+ } else {
+ equipmentMenu.Add(parent->Res().noEquipmentText, 0, false);
+ }
+ if (GetHero().HasJewel()) {
+ equipmentMenu.Add(GetHero().Jewel()->Name(), GetHero().Jewel(), true, GetHero().Jewel()->MenuIcon());
+ } else {
+ equipmentMenu.Add(parent->Res().noEquipmentText, 0, false);
+ }
+}
+
+void EquipMenu::RemoveAllEquipment() {
+ Inventory &inv(parent->Game().state->inventory);
+ if (GetHero().HasWeapon() && inv.Add(GetHero().Weapon(), 1)) {
+ GetHero().RemoveWeapon();
+ }
+ if (GetHero().HasArmor() && inv.Add(GetHero().Armor(), 1)) {
+ GetHero().RemoveArmor();
+ }
+ if (GetHero().HasShield() && inv.Add(GetHero().Shield(), 1)) {
+ GetHero().RemoveShield();
+ }
+ if (GetHero().HasHelmet() && inv.Add(GetHero().Helmet(), 1)) {
+ GetHero().RemoveHelmet();
+ }
+ if (GetHero().HasRing() && inv.Add(GetHero().Ring(), 1)) {
+ GetHero().RemoveRing();
+ }
+ if (GetHero().HasJewel() && inv.Add(GetHero().Jewel(), 1)) {
+ GetHero().RemoveJewel();
+ }
+ LoadEquipment();
}
}