]> git.localhorst.tv Git - l2e.git/commitdiff
added inventory menu to EquipMenu
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 27 Nov 2012 12:33:45 +0000 (13:33 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 27 Nov 2012 12:33:45 +0000 (13:33 +0100)
src/common/Item.h
src/menu/EquipMenu.cpp
src/menu/EquipMenu.h

index 06c0f83588d9ca8e9bc4d95dfc29a7a9f8f98a27..df361fe97cdec1a80038bbc1046bc1a74a51aeb4 100644 (file)
@@ -54,12 +54,7 @@ public:
 
        Uint16 Value() const { return value; }
 
-       bool CanEquipWeapon() const { return equipability & EQUIPPABLE_WEAPON; }
-       bool CanEquipArmor() const { return equipability & EQUIPPABLE_ARMOR; }
-       bool CanEquipShield() const { return equipability & EQUIPPABLE_SHIELD; }
-       bool CanEquipHelmet() const { return equipability & EQUIPPABLE_HELMET; }
-       bool CanEquipRing() const { return equipability & EQUIPPABLE_RING; }
-       bool CanEquipJewel() const { return equipability & EQUIPPABLE_JEWEL; }
+       bool EquipableAt(Hero::EquipSlot slot) const { return equipability & (1 << slot); }
 
        int HeroMask() const { return heroMask; }
 
@@ -91,15 +86,6 @@ public:
        static void Construct(void *);
 
 private:
-       enum Equipable {
-               EQUIPPABLE_NONE = 0,
-               EQUIPPABLE_WEAPON = 1 << Hero::EQUIP_WEAPON,
-               EQUIPPABLE_ARMOR = 1 << Hero::EQUIP_ARMOR,
-               EQUIPPABLE_SHIELD = 1 << Hero::EQUIP_SHIELD,
-               EQUIPPABLE_HELMET = 1 << Hero::EQUIP_HELMET,
-               EQUIPPABLE_RING = 1 << Hero::EQUIP_RING,
-               EQUIPPABLE_JEWEL = 1 << Hero::EQUIP_JEWEL,
-       };
        enum Property {
                PROPERTY_HAS_EFFECT_STATUS = 1,
                PROPERTY_HAS_EFFECT_BATTLE = 2,
index df924b18a024ade156e66fdc6784c2184665b9df..c60ea30a92795cb56fc85861b5ca95f03bd7f8ab 100644 (file)
@@ -50,6 +50,7 @@ EquipMenu::EquipMenu(PartyMenu *parent, int cursor)
 
 void EquipMenu::OnEnterState(SDL_Surface *) {
        equipmentMenu.SetInactive();
+       inventoryMenu.SetInactive();
 }
 
 void EquipMenu::OnExitState(SDL_Surface *) {
@@ -81,6 +82,7 @@ void EquipMenu::HandleEvents(const Input &input) {
                if (input.JustPressed(Input::ACTION_A)) {
                        switch (actionMenu.Selected()) {
                                case CHOICE_EQUIP:
+                                       LoadEquipment();
                                        actionMenu.SetSelected();
                                        equipmentMenu.SetActive();
                                        break;
@@ -105,9 +107,15 @@ void EquipMenu::HandleEvents(const Input &input) {
        } else if (equipmentMenu.IsActive()) {
                if (input.JustPressed(Input::PAD_UP)) {
                        equipmentMenu.PreviousRow();
+                       if (InventoryVisible()) {
+                               LoadInventory();
+                       }
                }
                if (input.JustPressed(Input::PAD_DOWN)) {
                        equipmentMenu.NextRow();
+                       if (InventoryVisible()) {
+                               LoadInventory();
+                       }
                }
                if (input.JustPressed(Input::ACTION_B)) {
                        equipmentMenu.SetInactive();
@@ -115,7 +123,8 @@ void EquipMenu::HandleEvents(const Input &input) {
                } else if (input.JustPressed(Input::ACTION_A)) {
                        switch (actionMenu.Selected()) {
                                case CHOICE_EQUIP:
-                                       // TODO
+                                       equipmentMenu.SetSelected();
+                                       inventoryMenu.SetActive();
                                        break;
                                case CHOICE_STRONGEST:
                                case CHOICE_REMOVE_ALL:
@@ -131,6 +140,19 @@ void EquipMenu::HandleEvents(const Input &input) {
                                        break;
                        }
                }
+       } else {
+               if (input.JustPressed(Input::PAD_UP)) {
+                       inventoryMenu.PreviousRow();
+               }
+               if (input.JustPressed(Input::PAD_DOWN)) {
+                       inventoryMenu.NextRow();
+               }
+               if (input.JustPressed(Input::ACTION_A)) {
+                       // TODO: equip selected item
+               } else if (input.JustPressed(Input::ACTION_B)) {
+                       inventoryMenu.SetInactive();
+                       equipmentMenu.SetActive();
+               }
        }
 }
 
@@ -149,16 +171,23 @@ void EquipMenu::Render(SDL_Surface *screen) {
        Vector<int> equipOffset(
                        17 * parent->Res().statusFont->CharWidth(),
                        4 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
-       Vector<int> menuOffset(
-                       15 * parent->Res().statusFont->CharWidth(),
-                       17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
 
        parent->RenderBackground(screen);
        parent->Res().shoulderNav->Draw(screen, offset + shoulderNavOffset);
        RenderStatus(screen, offset + parent->StatusOffset(0));
        RenderStats(screen, offset + statsOffset);
        RenderEquipmentMenu(screen, offset + equipOffset);
-       RenderActionMenu(screen, offset + menuOffset);
+       if (InventoryVisible()) {
+               Vector<int> inventoryOffset(
+                               parent->Res().statusFont->CharWidth(),
+                               17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
+               RenderInventoryMenu(screen, offset + inventoryOffset);
+       } else {
+               Vector<int> menuOffset(
+                               15 * parent->Res().statusFont->CharWidth(),
+                               17 * parent->Res().statusFont->CharHeight() - parent->Res().statusFont->CharHeight() / 8);
+               RenderActionMenu(screen, offset + menuOffset);
+       }
 }
 
 int EquipMenu::Width() const {
@@ -221,7 +250,12 @@ void EquipMenu::RenderActionMenu(SDL_Surface *screen, const Vector<int> &offset)
 }
 
 void EquipMenu::RenderInventoryMenu(SDL_Surface *screen, const Vector<int> &offset) const {
+       const Font &font(*parent->Res().normalFont);
+       const Frame &frame(*parent->Res().statusFrame);
+       const Vector<int> menuOffset(3 * font.CharWidth(), font.CharHeight() + font.CharHeight() / 4);
 
+       frame.Draw(screen, offset, 30 * font.CharWidth(), 11 * font.CharHeight());
+       inventoryMenu.Draw(screen, offset + menuOffset);
 }
 
 
@@ -283,4 +317,24 @@ void EquipMenu::DropItem() {
        LoadEquipment();
 }
 
+
+bool EquipMenu::InventoryVisible() const {
+       return !actionMenu.IsActive() && actionMenu.Selected() == CHOICE_EQUIP;
+}
+
+void EquipMenu::LoadInventory() {
+       const Inventory &inv = parent->Game().state->inventory;
+       const Hero &hero = GetHero();
+       const Hero::EquipSlot slot = Hero::EquipSlot(equipmentMenu.SelectedIndex());
+
+       inventoryMenu.Clear();
+       for (int i = 0; i < inv.MaxItems(); ++i) {
+               const Item *item = inv.ItemAt(i);
+               if (item && item->EquipableAt(slot)) {
+                       inventoryMenu.Add(item->Name(), item, hero.CanEquip(*item),
+                                       item->MenuIcon(), inv.ItemCountAt(i));
+               }
+       }
+}
+
 }
index 2ec66aee992936e4ea87e4ef2303c4e703cc5566..24e9789fef182d35b84f898d055ea82767ec5be6 100644 (file)
@@ -50,6 +50,9 @@ private:
        void RemoveItem();
        void DropItem();
 
+       bool InventoryVisible() const;
+       void LoadInventory();
+
        void RenderStatus(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
        void RenderStats(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
        void RenderStatsLine(const char *label, int number, SDL_Surface *screen, const geometry::Vector<int> &position) const;