]> git.localhorst.tv Git - l2e.git/commitdiff
implemented "remove all" in equipment menu
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 25 Nov 2012 13:32:16 +0000 (14:32 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 25 Nov 2012 13:32:16 +0000 (14:32 +0100)
src/common/Hero.h
src/main.cpp
src/menu/EquipMenu.cpp
src/menu/EquipMenu.h

index 1905c815e9cac9cbb7549c0f276b8054a6c9a035..70d21f202b7551dd11a45642a949871286036ba7 100644 (file)
@@ -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<const Spell *> &Spells() { return spells; }
        const std::vector<const Spell *> &Spells() const { return spells; }
 
index 44ed13a39e7c81b07cf021c2f638c7913a9d1fef..f78e7f7d74373f5fb3a812c6a3fbfca5255cccf1 100644 (file)
@@ -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;
 
index c604155861cc778196bbbf2752930574150fa46a..30cc1798a70c9b55dca4f20ea3fa1ba1a74c24b4 100644 (file)
@@ -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();
 }
 
 }
index 39380dcccd2d597ad2699754a069d86d4d9bd0cf..dd28344b612ff3530a989f025f21e361178dc152 100644 (file)
@@ -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<int> &offset) const;
        void RenderStats(SDL_Surface *screen, const geometry::Vector<int> &offset) const;