diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-09-09 00:47:31 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-09-09 00:47:57 +0300 |
commit | e72f26151bca6c5a73d0377e385c0f7dd7cab3aa (patch) | |
tree | 6960f1846e0258a5f3658cae6e2f40f643074e3f /src/gui | |
parent | f1c17766c66394ce875854430f8f028c0fa5b3a5 (diff) | |
download | ManaVerse-e72f26151bca6c5a73d0377e385c0f7dd7cab3aa.tar.gz ManaVerse-e72f26151bca6c5a73d0377e385c0f7dd7cab3aa.tar.bz2 ManaVerse-e72f26151bca6c5a73d0377e385c0f7dd7cab3aa.tar.xz ManaVerse-e72f26151bca6c5a73d0377e385c0f7dd7cab3aa.zip |
Add to inventory filter by letters from item names.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/inventorywindow.cpp | 49 | ||||
-rw-r--r-- | src/gui/inventorywindow.h | 8 | ||||
-rw-r--r-- | src/gui/widgets/itemcontainer.cpp | 13 | ||||
-rw-r--r-- | src/gui/widgets/itemcontainer.h | 4 | ||||
-rw-r--r-- | src/gui/widgets/textfield.cpp | 13 | ||||
-rw-r--r-- | src/gui/widgets/textfield.h | 3 |
6 files changed, 69 insertions, 21 deletions
diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index a8c003019..7a70135fd 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -22,6 +22,7 @@ #include "gui/inventorywindow.h" +#include "configuration.h" #include "inventory.h" #include "item.h" #include "units.h" @@ -46,6 +47,7 @@ #include "gui/widgets/progressbar.h" #include "gui/widgets/radiobutton.h" #include "gui/widgets/scrollarea.h" +#include "gui/widgets/textfield.h" #include "net/inventoryhandler.h" #include "net/net.h" @@ -134,7 +136,8 @@ InventoryWindow::InventoryWindow(Inventory *inventory): mSlotsLabel = new Label(_("Slots:")); mSlotsBar = new ProgressBar(0.0f, 100, 20, Theme::PROG_INVY_SLOTS); - mFilter = new InventoryFilter("filter_" + getWindowName(), 20, 5); + int size = config.getIntValue("fontSize"); + mFilter = new InventoryFilter("filter_" + getWindowName(), size, 0); mFilter->addActionListener(this); mFilter->setActionEventId("tag_"); @@ -144,6 +147,7 @@ InventoryWindow::InventoryWindow(Inventory *inventory): mFilterLabel = new Label(_("Filter:")); mSorterLabel = new Label(_("Sort:")); + mNameFilter = new TextField("", true, this, "namefilter", true); std::vector<std::string> tags = ItemDB::getTags(); for (unsigned f = 0; f < tags.size(); f ++) @@ -182,7 +186,8 @@ InventoryWindow::InventoryWindow(Inventory *inventory): place(8, 0, mSortDropDown, 3); place(0, 1, mFilterLabel, 1).setPadding(3); - place(1, 1, mFilter, 10).setPadding(3); + place(1, 1, mFilter, 7).setPadding(3); + place(8, 1, mNameFilter, 3); place(0, 2, invenScroll, 11).setPadding(3); place(0, 3, mUseButton); @@ -206,7 +211,8 @@ InventoryWindow::InventoryWindow(Inventory *inventory): place(6, 0, mSortDropDown, 1); place(0, 1, mFilterLabel, 1).setPadding(3); - place(1, 1, mFilter, 6).setPadding(3); + place(1, 1, mFilter, 5).setPadding(3); + place(6, 1, mNameFilter, 1); place(0, 2, invenScroll, 7, 4); place(0, 6, mStoreButton); @@ -288,23 +294,18 @@ void InventoryWindow::action(const gcn::ActionEvent &event) else if (event.getId() == "sort") { mItems->setSortType(mSortDropDown->getSelected()); + return; + } + else if (event.getId() == "namefilter") + { + mItems->setName(mNameFilter->getText()); + mItems->updateMatrix(); } else if (!event.getId().find("tag_") && mItems) { std::string tagName = event.getId().substr(4); mItems->setFilter(ItemDB::getTagId(tagName)); - } - else if (!event.getId().find("sort_") && mItems) - { - int sortType = 0; - std::string str = event.getId().substr(5).c_str(); - if (str == "na") - sortType = 0; - else if (str == "az") - sortType = 1; - else if (str == "id") - sortType = 2; - mItems->setSortType(sortType); + return; } Item *item = mItems->getSelectedItem(); @@ -653,3 +654,21 @@ void InventoryWindow::updateDropButton() mDropButton->setCaption(_("Drop")); } } + +bool InventoryWindow::isInputFocused() const +{ + return mNameFilter && mNameFilter->isFocused(); +} + +bool InventoryWindow::isAnyInputFocused() +{ + WindowList::const_iterator it = instances.begin(); + WindowList::const_iterator it_end = instances.end(); + + for (; it != it_end; ++it) + { + if ((*it) && (*it)->isInputFocused()) + return true; + } + return false; +} diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h index c07b5b0e1..14a53a179 100644 --- a/src/gui/inventorywindow.h +++ b/src/gui/inventorywindow.h @@ -47,7 +47,8 @@ class ItemContainer; class InventoryFilter; class ProgressBar; class SortListModel; -class TextBox; +//class TextBox; +class TextField; /** * Inventory dialog. @@ -130,6 +131,10 @@ class InventoryWindow : public Window, void updateButtons(Item *item = 0); + bool isInputFocused() const; + + static bool isAnyInputFocused(); + private: /** * Updates the weight bar. @@ -155,6 +160,7 @@ class InventoryWindow : public Window, InventoryFilter *mFilter; DropDown *mSortDropDown; SortListModel *mSortModel; + TextField *mNameFilter; bool mSplit; }; diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 75968d668..84313d64f 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -513,6 +513,9 @@ void ItemContainer::updateMatrix() int i = 0; int j = 0; + std::string temp = mName; + toLower(temp); + for (unsigned idx = 0; idx < mInventory->getSize(); idx ++) { Item *item = mInventory->getItem(idx); @@ -520,7 +523,15 @@ void ItemContainer::updateMatrix() if (!item || item->getId() == 0 || !item->isHaveTag(mTag)) continue; - sortedItems.push_back(new ItemIdPair(idx, item)); + if (mName.empty()) + { + sortedItems.push_back(new ItemIdPair(idx, item)); + continue; + } + std::string name = item->getInfo().getName(); + toLower(name); + if (name.find(temp) != std::string::npos) + sortedItems.push_back(new ItemIdPair(idx, item)); } switch (mSortType) diff --git a/src/gui/widgets/itemcontainer.h b/src/gui/widgets/itemcontainer.h index df7de63ee..845bfb3a9 100644 --- a/src/gui/widgets/itemcontainer.h +++ b/src/gui/widgets/itemcontainer.h @@ -125,6 +125,9 @@ class ItemContainer : public gcn::Widget, void setSortType (int sortType); + void setName(std::string str) + { mName = str; } + void updateMatrix(); private: @@ -194,6 +197,7 @@ class ItemContainer : public gcn::Widget, int mDragPosX, mDragPosY; int mTag; int mSortType; + std::string mName; ItemPopup *mItemPopup; int *mShowMatrix; diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index d9f5bed9a..5d4fbc0b4 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -48,12 +48,14 @@ float TextField::mAlpha = 1.0; ImageRect TextField::skin; TextField::TextField(const std::string &text, bool loseFocusOnTab, - gcn::ActionListener* listener, std::string eventId): + gcn::ActionListener* listener, std::string eventId, + bool sendAlwaysEvents): gcn::TextField(text), mNumeric(false), mMinimum(0), mMaximum(0), - mLastEventPaste(false) + mLastEventPaste(false), + mSendAlwaysEvents(sendAlwaysEvents) { setFrameSize(2); @@ -276,7 +278,9 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) case Key::ENTER: distributeActionEvent(); - break; + keyEvent.consume(); + fixScroll(); + return; case Key::HOME: mCaretPosition = 0; @@ -337,6 +341,9 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) break; } + if (mSendAlwaysEvents) + distributeActionEvent(); + keyEvent.consume(); fixScroll(); } diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h index 79790d83a..7e19099e8 100644 --- a/src/gui/widgets/textfield.h +++ b/src/gui/widgets/textfield.h @@ -41,7 +41,7 @@ class TextField : public gcn::TextField */ TextField(const std::string &text = "", bool loseFocusOnTab = true, gcn::ActionListener* listener = NULL, - std::string eventId = ""); + std::string eventId = "", bool sendAlwaysEvents = false); ~TextField(); @@ -109,6 +109,7 @@ class TextField : public gcn::TextField int mMaximum; bool mLoseFocusOnTab; int mLastEventPaste; + bool mSendAlwaysEvents; }; #endif |