]> git.localhorst.tv Git - l2e.git/commitdiff
implemented equipment removing and dropping
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 25 Nov 2012 13:45:01 +0000 (14:45 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sun, 25 Nov 2012 13:47:49 +0000 (14:47 +0100)
src/menu/EquipMenu.cpp
src/menu/EquipMenu.h

index 30cc1798a70c9b55dca4f20ea3fa1ba1a74c24b4..bfc262430023643d5051c97a974103a2b799680f 100644 (file)
@@ -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();
+}
+
 }
index dd28344b612ff3530a989f025f21e361178dc152..2ec66aee992936e4ea87e4ef2303c4e703cc5566 100644 (file)
@@ -47,6 +47,8 @@ private:
 
        void LoadEquipment();
        void RemoveAllEquipment();
+       void RemoveItem();
+       void DropItem();
 
        void RenderStatus(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
        void RenderStats(SDL_Surface *screen, const geometry::Vector<int> &offset) const;