From: Daniel Karbach Date: Sat, 17 Nov 2012 13:19:03 +0000 (+0100) Subject: implemented inventory item swapping X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=9c03a930498206bfa05de06ed838a74c8dd84a24;p=l2e.git implemented inventory item swapping --- diff --git a/src/common/Inventory.cpp b/src/common/Inventory.cpp index 6a6af81..e7dbe72 100644 --- a/src/common/Inventory.cpp +++ b/src/common/Inventory.cpp @@ -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]); +} + } diff --git a/src/common/Inventory.h b/src/common/Inventory.h index f80368c..db6c705 100644 --- a/src/common/Inventory.h +++ b/src/common/Inventory.h @@ -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 { diff --git a/src/main.cpp b/src/main.cpp index 1fc702b..b47a473 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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; diff --git a/src/menu/InventoryMenu.cpp b/src/menu/InventoryMenu.cpp index 429fefe..bdd94ce 100644 --- a/src/menu/InventoryMenu.cpp +++ b/src/menu/InventoryMenu.cpp @@ -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(); } } }