]> git.localhorst.tv Git - l2e.git/commitdiff
hooked Inventory::Sort into InventoryMenu
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 12 Nov 2012 20:44:17 +0000 (21:44 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 12 Nov 2012 20:44:17 +0000 (21:44 +0100)
src/main.cpp
src/menu/InventoryMenu.cpp
src/menu/InventoryMenu.h

index 9ed4af396efa07c7094eddb9db08a6546da40c78..1fc702b819f314c1fbd2255284cef9da6e66831f 100644 (file)
@@ -222,12 +222,19 @@ int main(int argc, char **argv) {
                gameState.heroes[0].AddSpell(valorSpell);
                gameState.heroes[1].AddSpell(valorSpell);
 
+               gameState.inventory.Add(caster.GetItem("zirconPlateItem"));
                gameState.inventory.Add(caster.GetItem("antidoteItem"), 9);
+               gameState.inventory.Add(caster.GetItem("powerRingItem"));
                gameState.inventory.Add(caster.GetItem("magicJarItem"), 4);
+               gameState.inventory.Add(caster.GetItem("sProRingItem"));
                gameState.inventory.Add(caster.GetItem("hiPotionItem"), 4);
+               gameState.inventory.Add(caster.GetItem("powerRingItem"));
                gameState.inventory.Add(caster.GetItem("powerPotionItem"), 4);
+               gameState.inventory.Add(caster.GetItem("zircoSwordItem"));
                gameState.inventory.Add(caster.GetItem("escapeItem"), 2);
+               gameState.inventory.Add(caster.GetItem("zircoHelmetItem"));
                gameState.inventory.Add(caster.GetItem("sleepBallItem"), 1);
+               gameState.inventory.Add(caster.GetItem("zirconPlateItem"));
 
                gameState.heroes[0].SetWeapon(caster.GetItem("zircoSwordItem"));
                gameState.heroes[0].SetArmor(caster.GetItem("zirconArmorItem"));
index 82a615b103a465c0e77ef41f78090ce0dc79f6aa..429fefe59da30888f73b0037c6ae493ec8495daf 100644 (file)
@@ -30,14 +30,18 @@ InventoryMenu::InventoryMenu(PartyMenu *parent)
 : parent(parent)
 , menu(*parent->Res().itemMenuProperties)
 , itemMenu(*parent->Res().inventoryMenuProperties) {
-       menu.Add(parent->Res().itemMenuUseText, 0);
-       menu.Add(parent->Res().itemMenuSortText, 1);
-       menu.Add(parent->Res().itemMenuDropText, 2);
+       menu.Add(parent->Res().itemMenuUseText, CHOICE_USE);
+       menu.Add(parent->Res().itemMenuSortText, CHOICE_SORT);
+       menu.Add(parent->Res().itemMenuDropText, CHOICE_DROP);
 }
 
 
 void InventoryMenu::OnEnterState(SDL_Surface *) {
        menu.SetSelected();
+       LoadInventory();
+}
+
+void InventoryMenu::LoadInventory() {
        const Inventory &inv(parent->Game().state->inventory);
        itemMenu.Clear();
        itemMenu.Reserve(inv.MaxItems());
@@ -88,8 +92,13 @@ void InventoryMenu::HandleEvents(const Input &input) {
 
        if (input.JustPressed(Input::ACTION_A)) {
                if (menu.IsActive()) {
-                       menu.SetSelected();
-                       itemMenu.SetActive();
+                       if (menu.Selected() == CHOICE_SORT) {
+                               parent->Game().state->inventory.Sort();
+                               LoadInventory();
+                       } else {
+                               menu.SetSelected();
+                               itemMenu.SetActive();
+                       }
                }
        }
        if (input.JustPressed(Input::ACTION_B)) {
index 20cbe17f54ef388786488f9d98941f9b46e3c01c..c1d458b18cdaf906370e7f24797567cd75069552 100644 (file)
@@ -38,12 +38,19 @@ private:
 
        virtual void OnResize(int width, int height);
 
+       void LoadInventory();
+
        void RenderMenu(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
        void RenderInventory(SDL_Surface *screen, const geometry::Vector<int> &offset) const;
 
 private:
        PartyMenu *parent;
-       graphics::Menu<int> menu;
+       enum Choice {
+               CHOICE_USE,
+               CHOICE_SORT,
+               CHOICE_DROP,
+       };
+       graphics::Menu<Choice> menu;
        graphics::Menu<const common::Item *> itemMenu;
 
 };