From: Daniel Karbach Date: Sun, 25 Nov 2012 13:32:16 +0000 (+0100) Subject: implemented "remove all" in equipment menu X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=5ff22859ee5966297862d3384206fa2cf52da7ca;p=l2e.git implemented "remove all" in equipment menu --- diff --git a/src/common/Hero.h b/src/common/Hero.h index 1905c81..70d21f2 100644 --- a/src/common/Hero.h +++ b/src/common/Hero.h @@ -71,6 +71,13 @@ public: bool HasRing() const { return ring; } bool HasJewel() const { return jewel; } + void RemoveWeapon() { weapon = 0; } + void RemoveArmor() { armor = 0; } + void RemoveShield() { shield = 0; } + void RemoveHelmet() { helmet = 0; } + void RemoveRing() { ring = 0; } + void RemoveJewel() { jewel = 0; } + std::vector &Spells() { return spells; } const std::vector &Spells() const { return spells; } diff --git a/src/main.cpp b/src/main.cpp index 44ed13a..f78e7f7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -430,6 +430,8 @@ int main(int argc, char **argv) { equipmentMenuProperties.cursor = &menuCursor; equipmentMenuProperties.selectedCursor = &menuActiveCursor; equipmentMenuProperties.font = menuResources.statusFont; + // TODO: disabled font + equipmentMenuProperties.disabledFont = menuResources.statusFont; equipmentMenuProperties.iconSpace = 16; menuResources.equipmentMenuProperties = &equipmentMenuProperties; diff --git a/src/menu/EquipMenu.cpp b/src/menu/EquipMenu.cpp index c604155..30cc179 100644 --- a/src/menu/EquipMenu.cpp +++ b/src/menu/EquipMenu.cpp @@ -15,6 +15,7 @@ #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" @@ -22,6 +23,7 @@ using app::Input; using common::Hero; +using common::Inventory; using common::Item; using common::Stats; using geometry::Vector; @@ -69,7 +71,37 @@ void EquipMenu::OnResize(int width, int height) { 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) { @@ -173,18 +205,70 @@ void EquipMenu::PreviousHero() { 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(); } } diff --git a/src/menu/EquipMenu.h b/src/menu/EquipMenu.h index 39380dc..dd28344 100644 --- a/src/menu/EquipMenu.h +++ b/src/menu/EquipMenu.h @@ -42,9 +42,11 @@ private: void NextHero(); void PreviousHero(); + common::Hero &GetHero(); const common::Hero &GetHero() const; void LoadEquipment(); + void RemoveAllEquipment(); void RenderStatus(SDL_Surface *screen, const geometry::Vector &offset) const; void RenderStats(SDL_Surface *screen, const geometry::Vector &offset) const;