X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmenu%2FInventoryMenu.cpp;h=c980f9719a3c120e0097f5a8c19bcb63cbdced90;hb=2255d436a0c2acc10b015827366a72b2ece86094;hp=82a615b103a465c0e77ef41f78090ce0dc79f6aa;hpb=cc3905e6ddd9536139cb5d613c3e2d90c83b60fc;p=l2e.git diff --git a/src/menu/InventoryMenu.cpp b/src/menu/InventoryMenu.cpp index 82a615b..c980f97 100644 --- a/src/menu/InventoryMenu.cpp +++ b/src/menu/InventoryMenu.cpp @@ -1,14 +1,8 @@ -/* - * InventoryMenu.cpp - * - * Created on: Nov 4, 2012 - * Author: holy - */ - #include "InventoryMenu.h" #include "PartyMenu.h" #include "Resources.h" +#include "../app/Application.h" #include "../app/Input.h" #include "../common/GameConfig.h" #include "../common/GameState.h" @@ -23,6 +17,7 @@ using common::Item; using geometry::Vector; using graphics::Font; using graphics::Frame; +using std::swap; namespace menu { @@ -30,14 +25,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,16 +87,52 @@ void InventoryMenu::HandleEvents(const Input &input) { if (input.JustPressed(Input::ACTION_A)) { if (menu.IsActive()) { - menu.SetSelected(); + if (menu.Selected() == CHOICE_SORT) { + parent->Game().state->inventory.Sort(); + LoadInventory(); + } else { + menu.SetSelected(); + itemMenu.SetActive(); + } + } else if (itemMenu.IsActive()) { + itemMenu.SetDualSelection(); + } else if (itemMenu.SelectedIndex() == itemMenu.SecondaryIndex()) { + switch (menu.Selected()) { + case CHOICE_USE: + if (itemMenu.Selected()->CanUseOnStatusScreen()) { + // TODO: implement item use + } + itemMenu.SetActive(); + break; + case CHOICE_SORT: + // invalid state, recover + menu.SetActive(); + itemMenu.SetInactive(); + break; + case CHOICE_DROP: + if (itemMenu.Selected()->CanDrop()) { + parent->Game().state->inventory.RemoveAll(itemMenu.Selected()); + itemMenu.ClearEntry(itemMenu.SelectedIndex()); + } + itemMenu.SetActive(); + break; + } + } else { + parent->Game().state->inventory.SwapEntriesAt( + itemMenu.SelectedIndex(), + itemMenu.SecondaryIndex()); + itemMenu.SwapSelected(); itemMenu.SetActive(); } } if (input.JustPressed(Input::ACTION_B)) { if (menu.IsActive()) { Ctrl().PopState(); - } else { + } else if (itemMenu.IsActive()) { menu.SetActive(); itemMenu.SetInactive(); + } else { + itemMenu.SetActive(); } } }