]> git.localhorst.tv Git - l2e.git/blobdiff - src/menu/InventoryMenu.cpp
hooked Inventory::Sort into InventoryMenu
[l2e.git] / src / menu / InventoryMenu.cpp
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)) {