]> git.localhorst.tv Git - l2e.git/commitdiff
implemented inventory item swapping
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 17 Nov 2012 13:19:03 +0000 (14:19 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Sat, 17 Nov 2012 13:19:03 +0000 (14:19 +0100)
src/common/Inventory.cpp
src/common/Inventory.h
src/main.cpp
src/menu/InventoryMenu.cpp

index 6a6af81f3b52fe3dd0f94875cde38f00689f016b..e7dbe726e356ca2408669d2e88e8e42cec5213ea 100644 (file)
@@ -83,4 +83,8 @@ bool Inventory::Entry::Less(const Entry &lhs, const Entry &rhs) {
        }
 }
 
+void Inventory::SwapEntriesAt(int lhs, int rhs) {
+       std::swap(entries[lhs], entries[rhs]);
+}
+
 }
index f80368c5ca6c1666b8ba2c9f9405ec17117d585c..db6c7052e7d908c6b38339efd6d0b3c8a6d9330b 100644 (file)
@@ -29,6 +29,7 @@ public:
        int ItemCountAt(int offset) const { return entries[offset].count; }
 
        void Sort();
+       void SwapEntriesAt(int lhs, int rhs);
 
 private:
        struct Entry {
index 1fc702b819f314c1fbd2255284cef9da6e66831f..b47a473d50d3f395d92eaad5507127982a774092 100644 (file)
@@ -386,7 +386,7 @@ int main(int argc, char **argv) {
                inventoryMenuProperties.charsPerEntry = 13;
                inventoryMenuProperties.rowGap = 8;
                inventoryMenuProperties.cursor = &menuCursor;
-               itemMenuProperties.selectedCursor = &menuActiveCursor;
+               inventoryMenuProperties.selectedCursor = &menuActiveCursor;
                inventoryMenuProperties.font = &menuFont;
                // TODO: disabled font
                inventoryMenuProperties.disabledFont = &menuFont;
index 429fefe59da30888f73b0037c6ae493ec8495daf..bdd94cebf5937f1b439e340f9cef7b2b365d6976 100644 (file)
@@ -23,6 +23,7 @@ using common::Item;
 using geometry::Vector;
 using graphics::Font;
 using graphics::Frame;
+using std::swap;
 
 namespace menu {
 
@@ -99,14 +100,38 @@ void InventoryMenu::HandleEvents(const Input &input) {
                                menu.SetSelected();
                                itemMenu.SetActive();
                        }
+               } else if (itemMenu.IsActive()) {
+                       itemMenu.SetDualSelection();
+               } else if (itemMenu.SelectedIndex() == itemMenu.SecondaryIndex()) {
+                       switch (menu.Selected()) {
+                               case CHOICE_USE:
+                                       // TODO: implement item use
+                                       break;
+                               case CHOICE_SORT:
+                                       // invalid state, recover
+                                       menu.SetActive();
+                                       itemMenu.SetInactive();
+                                       break;
+                               case CHOICE_DROP:
+                                       // TODO: implement item drop
+                                       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();
                }
        }
 }