diff options
Diffstat (limited to 'src/gui/inventorywindow.cpp')
-rw-r--r-- | src/gui/inventorywindow.cpp | 84 |
1 files changed, 60 insertions, 24 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 31743c57..4ebcce8b 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -58,9 +58,10 @@ InventoryWindow::WindowList InventoryWindow::instances; InventoryWindow::InventoryWindow(Inventory *inventory): Window(inventory->isMainInventory() ? _("Inventory") : _("Storage")), mInventory(inventory), + mFilterText(new TextField), mSplit(false) { - listen(CHANNEL_ATTRIBUTES); + listen(Event::AttributesChannel); setWindowName(isMainInventory() ? "Inventory" : "Storage"); setupWindow->registerWindowForReset(this); @@ -73,6 +74,9 @@ InventoryWindow::InventoryWindow(Inventory *inventory): setMinHeight(179); addKeyListener(this); + mFilterText->setWidth(150); + mFilterText->addKeyListener(this); + mItems = new ItemContainer(mInventory); mItems->addSelectionListener(this); @@ -80,6 +84,7 @@ InventoryWindow::InventoryWindow(Inventory *inventory): invenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mSlotsLabel = new Label(_("Slots:")); + mFilterLabel = new Label(_("Search:")); mSlotsBar = new ProgressBar(0.0f, 100, 20, Theme::PROG_INVY_SLOTS); if (isMainInventory()) @@ -109,13 +114,15 @@ InventoryWindow::InventoryWindow(Inventory *inventory): place(0, 0, mWeightLabel).setPadding(3); place(1, 0, mWeightBar, 3); place(4, 0, mSlotsLabel).setPadding(3); - place(5, 0, mSlotsBar, 2); - place(0, 1, invenScroll, 7).setPadding(3); - place(0, 2, mUseButton); - place(1, 2, mEquipButton); - place(2, 2, mDropButton); - place(3, 2, mSplitButton); - place(6, 2, mOutfitButton); + place(5, 0, mSlotsBar, 3); + place(0, 1, mFilterLabel, 4); + place(1, 1, mFilterText, 4); + place(0, 2, invenScroll, 8).setPadding(3); + place(0, 3, mUseButton); + place(1, 3, mEquipButton); + place(2, 3, mDropButton); + place(3, 3, mSplitButton); + place(7, 3, mOutfitButton); updateWeight(); } @@ -126,13 +133,15 @@ InventoryWindow::InventoryWindow(Inventory *inventory): place(0, 0, mSlotsLabel).setPadding(3); place(1, 0, mSlotsBar, 3); - place(0, 1, invenScroll, 4, 4); - place(0, 5, mStoreButton); - place(1, 5, mRetrieveButton); + place(0, 1, mFilterLabel).setPadding(3); + place(1, 1, mFilterText, 3); + place(0, 2, invenScroll, 4, 4); + place(0, 6, mStoreButton); + place(1, 6, mRetrieveButton); } Layout &layout = getLayout(); - layout.setRowHeight(1, Layout::AUTO_SET); + layout.setRowHeight(2, Layout::AUTO_SET); mInventory->addInventoyListener(this); @@ -186,19 +195,19 @@ void InventoryWindow::action(const gcn::ActionEvent &event) return; if (event.getId() == "activate") - item->doEvent(EVENT_DOUSE); + item->doEvent(Event::DoUse); else if (event.getId() == "equip") { if (item->isEquippable()) { if (item->isEquipped()) - item->doEvent(EVENT_DOUNEQUIP); + item->doEvent(Event::DoUnequip); else - item->doEvent(EVENT_DOEQUIP); + item->doEvent(Event::DoEquip); } else { - item->doEvent(EVENT_DOUSE); + item->doEvent(Event::DoUse); } } else if (event.getId() == "drop") @@ -256,21 +265,21 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) return; if (mInventory->isMainInventory()) { - Mana::Event event(EVENT_DOMOVE); + Event event(Event::DoMove); event.setItem("item", item); event.setInt("amount", item->getQuantity()); event.setInt("source", Inventory::INVENTORY); event.setInt("destination", Inventory::STORAGE); - event.trigger(CHANNEL_ITEM); + event.trigger(Event::ItemChannel); } else { - Mana::Event event(EVENT_DOMOVE); + Event event(Event::DoMove); event.setItem("item", item); event.setInt("amount", item->getQuantity()); event.setInt("source", Inventory::STORAGE); event.setInt("destination", Inventory::INVENTORY); - event.trigger(CHANNEL_ITEM); + event.trigger(Event::ItemChannel); } } } @@ -289,6 +298,12 @@ void InventoryWindow::keyPressed(gcn::KeyEvent &event) void InventoryWindow::keyReleased(gcn::KeyEvent &event) { + if (isInputFocused()) + { + mItems->setFilter(mFilterText->getText()); + return; + } + switch (event.getKey().getValue()) { case Key::LEFT_SHIFT: @@ -368,16 +383,16 @@ void InventoryWindow::close() } else { - Mana::Event event(EVENT_DOCLOSEINVENTORY); + Event event(Event::DoCloseInventory); event.setInt("type", mInventory->getType()); - event.trigger(CHANNEL_ITEM); + event.trigger(Event::ItemChannel); scheduleDelete(); } } -void InventoryWindow::event(Channels channel, const Mana::Event &event) +void InventoryWindow::event(Event::Channel channel, const Event &event) { - if (event.getName() == EVENT_UPDATEATTRIBUTE) + if (event.getType() == Event::UpdateAttribute) { int id = event.getInt("id"); if (id == TOTAL_WEIGHT || @@ -405,6 +420,27 @@ void InventoryWindow::updateWeight() Units::formatWeight(max).c_str())); } +bool InventoryWindow::isInputFocused() const +{ + return mFilterText->isFocused(); +} + +bool InventoryWindow::isAnyInputFocused() +{ + WindowList::iterator it = instances.begin(); + WindowList::iterator it_end = instances.end(); + + for (; it != it_end; it++) + { + if ((*it)->isInputFocused()) + { + return true; + } + } + + return false; +} + void InventoryWindow::slotsChanged(Inventory* inventory) { if (inventory == mInventory) |