From c5ee1039b4cc41615c2402ecd7a73f62f9a7d2f5 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Sun, 25 Nov 2012 14:45:01 +0100 Subject: [PATCH] implemented equipment removing and dropping --- src/menu/EquipMenu.cpp | 91 ++++++++++++++++++++++++++++++++++++++++++ src/menu/EquipMenu.h | 2 + 2 files changed, 93 insertions(+) diff --git a/src/menu/EquipMenu.cpp b/src/menu/EquipMenu.cpp index 30cc179..bfc2624 100644 --- a/src/menu/EquipMenu.cpp +++ b/src/menu/EquipMenu.cpp @@ -85,6 +85,7 @@ void EquipMenu::HandleEvents(const Input &input) { equipmentMenu.SetActive(); break; case CHOICE_STRONGEST: + // TODO break; case CHOICE_REMOVE: actionMenu.SetSelected(); @@ -101,6 +102,35 @@ void EquipMenu::HandleEvents(const Input &input) { } else if (input.JustPressed(Input::ACTION_B)) { Ctrl().PopState(); } + } else if (equipmentMenu.IsActive()) { + if (input.JustPressed(Input::PAD_UP)) { + equipmentMenu.PreviousRow(); + } + if (input.JustPressed(Input::PAD_DOWN)) { + equipmentMenu.NextRow(); + } + if (input.JustPressed(Input::ACTION_B)) { + equipmentMenu.SetInactive(); + actionMenu.SetActive(); + } else if (input.JustPressed(Input::ACTION_A)) { + switch (actionMenu.Selected()) { + case CHOICE_EQUIP: + // TODO + break; + case CHOICE_STRONGEST: + case CHOICE_REMOVE_ALL: + // invalid state, recover + equipmentMenu.SetInactive(); + actionMenu.SetActive(); + break; + case CHOICE_REMOVE: + RemoveItem(); + break; + case CHOICE_DROP: + DropItem(); + break; + } + } } } @@ -271,4 +301,65 @@ void EquipMenu::RemoveAllEquipment() { LoadEquipment(); } +void EquipMenu::RemoveItem() { + Inventory &inv(parent->Game().state->inventory); + switch (equipmentMenu.SelectedIndex()) { + case 0: + if (GetHero().HasWeapon() && inv.Add(GetHero().Weapon(), 1)) { + GetHero().RemoveWeapon(); + } + break; + case 1: + if (GetHero().HasArmor() && inv.Add(GetHero().Armor(), 1)) { + GetHero().RemoveArmor(); + } + break; + case 2: + if (GetHero().HasShield() && inv.Add(GetHero().Shield(), 1)) { + GetHero().RemoveShield(); + } + break; + case 3: + if (GetHero().HasHelmet() && inv.Add(GetHero().Helmet(), 1)) { + GetHero().RemoveHelmet(); + } + break; + case 4: + if (GetHero().HasRing() && inv.Add(GetHero().Ring(), 1)) { + GetHero().RemoveRing(); + } + break; + case 5: + if (GetHero().HasJewel() && inv.Add(GetHero().Jewel(), 1)) { + GetHero().RemoveJewel(); + } + break; + } + LoadEquipment(); +} + +void EquipMenu::DropItem() { + switch (equipmentMenu.SelectedIndex()) { + case 0: + GetHero().RemoveWeapon(); + break; + case 1: + GetHero().RemoveArmor(); + break; + case 2: + GetHero().RemoveShield(); + break; + case 3: + GetHero().RemoveHelmet(); + break; + case 4: + GetHero().RemoveRing(); + break; + case 5: + GetHero().RemoveJewel(); + break; + } + LoadEquipment(); +} + } diff --git a/src/menu/EquipMenu.h b/src/menu/EquipMenu.h index dd28344..2ec66ae 100644 --- a/src/menu/EquipMenu.h +++ b/src/menu/EquipMenu.h @@ -47,6 +47,8 @@ private: void LoadEquipment(); void RemoveAllEquipment(); + void RemoveItem(); + void DropItem(); void RenderStatus(SDL_Surface *screen, const geometry::Vector &offset) const; void RenderStats(SDL_Surface *screen, const geometry::Vector &offset) const; -- 2.39.2