From 24a1c72ef826bac796575dd259d43db55054482e Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Mon, 12 Nov 2012 21:44:17 +0100 Subject: [PATCH] hooked Inventory::Sort into InventoryMenu --- src/main.cpp | 7 +++++++ src/menu/InventoryMenu.cpp | 19 ++++++++++++++----- src/menu/InventoryMenu.h | 9 ++++++++- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 9ed4af3..1fc702b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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")); diff --git a/src/menu/InventoryMenu.cpp b/src/menu/InventoryMenu.cpp index 82a615b..429fefe 100644 --- a/src/menu/InventoryMenu.cpp +++ b/src/menu/InventoryMenu.cpp @@ -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)) { diff --git a/src/menu/InventoryMenu.h b/src/menu/InventoryMenu.h index 20cbe17..c1d458b 100644 --- a/src/menu/InventoryMenu.h +++ b/src/menu/InventoryMenu.h @@ -38,12 +38,19 @@ private: virtual void OnResize(int width, int height); + void LoadInventory(); + void RenderMenu(SDL_Surface *screen, const geometry::Vector &offset) const; void RenderInventory(SDL_Surface *screen, const geometry::Vector &offset) const; private: PartyMenu *parent; - graphics::Menu menu; + enum Choice { + CHOICE_USE, + CHOICE_SORT, + CHOICE_DROP, + }; + graphics::Menu menu; graphics::Menu itemMenu; }; -- 2.39.2