Merge branch 'inventorysearch' into 'master'

Item search in inventory redux

See merge request OpenMW/openmw!158
pull/558/head
Alexei Dobrohotov 5 years ago
commit 3f64d98305

@ -227,6 +227,7 @@
Feature #4730: Native animated containers support Feature #4730: Native animated containers support
Feature #4784: Launcher: Duplicate Content Lists Feature #4784: Launcher: Duplicate Content Lists
Feature #4812: Support NiSwitchNode Feature #4812: Support NiSwitchNode
Feature #4831: Item search in the player's inventory
Feature #4836: Daytime node switch Feature #4836: Daytime node switch
Feature #4840: Editor: Transient terrain change support Feature #4840: Editor: Transient terrain change support
Feature #4859: Make water reflections more configurable Feature #4859: Make water reflections more configurable

@ -46,9 +46,11 @@ CompanionWindow::CompanionWindow(DragAndDrop *dragAndDrop, MessageBoxManager* ma
getWidget(mCloseButton, "CloseButton"); getWidget(mCloseButton, "CloseButton");
getWidget(mProfitLabel, "ProfitLabel"); getWidget(mProfitLabel, "ProfitLabel");
getWidget(mEncumbranceBar, "EncumbranceBar"); getWidget(mEncumbranceBar, "EncumbranceBar");
getWidget(mFilterEdit, "FilterEdit");
getWidget(mItemView, "ItemView"); getWidget(mItemView, "ItemView");
mItemView->eventBackgroundClicked += MyGUI::newDelegate(this, &CompanionWindow::onBackgroundSelected); mItemView->eventBackgroundClicked += MyGUI::newDelegate(this, &CompanionWindow::onBackgroundSelected);
mItemView->eventItemClicked += MyGUI::newDelegate(this, &CompanionWindow::onItemSelected); mItemView->eventItemClicked += MyGUI::newDelegate(this, &CompanionWindow::onItemSelected);
mFilterEdit->eventEditTextChange += MyGUI::newDelegate(this, &CompanionWindow::onNameFilterChanged);
mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CompanionWindow::onCloseButtonClicked); mCloseButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CompanionWindow::onCloseButtonClicked);
@ -92,6 +94,12 @@ void CompanionWindow::onItemSelected(int index)
dragItem (nullptr, count); dragItem (nullptr, count);
} }
void CompanionWindow::onNameFilterChanged(MyGUI::EditBox* _sender)
{
mSortModel->setNameFilter(_sender->getCaption());
mItemView->update();
}
void CompanionWindow::dragItem(MyGUI::Widget* sender, int count) void CompanionWindow::dragItem(MyGUI::Widget* sender, int count)
{ {
mDragAndDrop->startDrag(mSelectedItem, mSortModel, mModel, mItemView, count); mDragAndDrop->startDrag(mSelectedItem, mSortModel, mModel, mItemView, count);

@ -39,11 +39,13 @@ namespace MWGui
DragAndDrop* mDragAndDrop; DragAndDrop* mDragAndDrop;
MyGUI::Button* mCloseButton; MyGUI::Button* mCloseButton;
MyGUI::EditBox* mFilterEdit;
MyGUI::TextBox* mProfitLabel; MyGUI::TextBox* mProfitLabel;
Widgets::MWDynamicStat* mEncumbranceBar; Widgets::MWDynamicStat* mEncumbranceBar;
MessageBoxManager* mMessageBoxManager; MessageBoxManager* mMessageBoxManager;
void onItemSelected(int index); void onItemSelected(int index);
void onNameFilterChanged(MyGUI::EditBox* _sender);
void onBackgroundSelected(); void onBackgroundSelected();
void dragItem(MyGUI::Widget* sender, int count); void dragItem(MyGUI::Widget* sender, int count);

@ -8,6 +8,7 @@
#include <MyGUI_RenderManager.h> #include <MyGUI_RenderManager.h>
#include <MyGUI_InputManager.h> #include <MyGUI_InputManager.h>
#include <MyGUI_Button.h> #include <MyGUI_Button.h>
#include <MyGUI_EditBox.h>
#include <osg/Texture2D> #include <osg/Texture2D>
@ -88,6 +89,7 @@ namespace MWGui
getWidget(mLeftPane, "LeftPane"); getWidget(mLeftPane, "LeftPane");
getWidget(mRightPane, "RightPane"); getWidget(mRightPane, "RightPane");
getWidget(mArmorRating, "ArmorRating"); getWidget(mArmorRating, "ArmorRating");
getWidget(mFilterEdit, "FilterEdit");
mAvatarImage->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onAvatarClicked); mAvatarImage->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onAvatarClicked);
mAvatarImage->setRenderItemTexture(mPreviewTexture.get()); mAvatarImage->setRenderItemTexture(mPreviewTexture.get());
@ -102,6 +104,7 @@ namespace MWGui
mFilterApparel->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged); mFilterApparel->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged);
mFilterMagic->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged); mFilterMagic->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged);
mFilterMisc->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged); mFilterMisc->eventMouseButtonClick += MyGUI::newDelegate(this, &InventoryWindow::onFilterChanged);
mFilterEdit->eventEditTextChange += MyGUI::newDelegate(this, &InventoryWindow::onNameFilterChanged);
mFilterAll->setStateSelected(true); mFilterAll->setStateSelected(true);
@ -386,6 +389,11 @@ namespace MWGui
void InventoryWindow::onOpen() void InventoryWindow::onOpen()
{ {
// Reset the filter focus when opening the window
MyGUI::Widget* focus = MyGUI::InputManager::getInstance().getKeyFocusWidget();
if (focus == mFilterEdit)
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(nullptr);
if (!mPtr.isEmpty()) if (!mPtr.isEmpty())
{ {
updateEncumbranceBar(); updateEncumbranceBar();
@ -463,6 +471,12 @@ namespace MWGui
width*mScaleFactor/float(mPreview->getTextureWidth()), height*mScaleFactor/float(mPreview->getTextureHeight()))); width*mScaleFactor/float(mPreview->getTextureWidth()), height*mScaleFactor/float(mPreview->getTextureHeight())));
} }
void InventoryWindow::onNameFilterChanged(MyGUI::EditBox* _sender)
{
mSortModel->setNameFilter(_sender->getCaption());
mItemView->update();
}
void InventoryWindow::onFilterChanged(MyGUI::Widget* _sender) void InventoryWindow::onFilterChanged(MyGUI::Widget* _sender)
{ {
if (_sender == mFilterAll) if (_sender == mFilterAll)
@ -475,7 +489,6 @@ namespace MWGui
mSortModel->setCategory(SortFilterItemModel::Category_Magic); mSortModel->setCategory(SortFilterItemModel::Category_Magic);
else if (_sender == mFilterMisc) else if (_sender == mFilterMisc)
mSortModel->setCategory(SortFilterItemModel::Category_Misc); mSortModel->setCategory(SortFilterItemModel::Category_Misc);
mFilterAll->setStateSelected(false); mFilterAll->setStateSelected(false);
mFilterWeapon->setStateSelected(false); mFilterWeapon->setStateSelected(false);
mFilterApparel->setStateSelected(false); mFilterApparel->setStateSelected(false);

@ -92,6 +92,8 @@ namespace MWGui
MyGUI::Button* mFilterApparel; MyGUI::Button* mFilterApparel;
MyGUI::Button* mFilterMagic; MyGUI::Button* mFilterMagic;
MyGUI::Button* mFilterMisc; MyGUI::Button* mFilterMisc;
MyGUI::EditBox* mFilterEdit;
GuiMode mGuiMode; GuiMode mGuiMode;
@ -119,6 +121,7 @@ namespace MWGui
void onWindowResize(MyGUI::Window* _sender); void onWindowResize(MyGUI::Window* _sender);
void onFilterChanged(MyGUI::Widget* _sender); void onFilterChanged(MyGUI::Widget* _sender);
void onNameFilterChanged(MyGUI::EditBox* _sender);
void onAvatarClicked(MyGUI::Widget* _sender); void onAvatarClicked(MyGUI::Widget* _sender);
void onPinToggled(); void onPinToggled();

@ -250,6 +250,10 @@ namespace MWGui
return false; return false;
} }
std::string compare = Misc::StringUtils::lowerCase(item.mBase.getClass().getName(item.mBase));
if(compare.find(mNameFilter) == std::string::npos)
return false;
return true; return true;
} }
@ -277,6 +281,11 @@ namespace MWGui
mFilter = filter; mFilter = filter;
} }
void SortFilterItemModel::setNameFilter (const std::string& filter)
{
mNameFilter = Misc::StringUtils::lowerCase(filter);
}
void SortFilterItemModel::update() void SortFilterItemModel::update()
{ {
mSourceModel->update(); mSourceModel->update();

@ -25,6 +25,7 @@ namespace MWGui
void setCategory (int category); void setCategory (int category);
void setFilter (int filter); void setFilter (int filter);
void setNameFilter (const std::string& filter);
/// Use ItemStack::Type for sorting? /// Use ItemStack::Type for sorting?
void setSortByType(bool sort) { mSortByType = sort; } void setSortByType(bool sort) { mSortByType = sort; }
@ -57,6 +58,8 @@ namespace MWGui
int mCategory; int mCategory;
int mFilter; int mFilter;
bool mSortByType; bool mSortByType;
std::string mNameFilter; // filter by item name
}; };
} }

@ -69,6 +69,7 @@ namespace MWGui
getWidget(mTotalBalance, "TotalBalance"); getWidget(mTotalBalance, "TotalBalance");
getWidget(mTotalBalanceLabel, "TotalBalanceLabel"); getWidget(mTotalBalanceLabel, "TotalBalanceLabel");
getWidget(mBottomPane, "BottomPane"); getWidget(mBottomPane, "BottomPane");
getWidget(mFilterEdit, "FilterEdit");
getWidget(mItemView, "ItemView"); getWidget(mItemView, "ItemView");
mItemView->eventItemClicked += MyGUI::newDelegate(this, &TradeWindow::onItemSelected); mItemView->eventItemClicked += MyGUI::newDelegate(this, &TradeWindow::onItemSelected);
@ -80,6 +81,7 @@ namespace MWGui
mFilterApparel->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged); mFilterApparel->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged);
mFilterMagic->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged); mFilterMagic->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged);
mFilterMisc->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged); mFilterMisc->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onFilterChanged);
mFilterEdit->eventEditTextChange += MyGUI::newDelegate(this, &TradeWindow::onNameFilterChanged);
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onCancelButtonClicked); mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onCancelButtonClicked);
mOfferButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onOfferButtonClicked); mOfferButton->eventMouseButtonClick += MyGUI::newDelegate(this, &TradeWindow::onOfferButtonClicked);
@ -135,8 +137,7 @@ namespace MWGui
setTitle(actor.getClass().getName(actor)); setTitle(actor.getClass().getName(actor));
onFilterChanged(mFilterAll); onFilterChanged(mFilterAll);
mFilterEdit->setCaption("");
MWBase::Environment::get().getWindowManager()->setKeyFocusWidget(mTotalBalance);
} }
void TradeWindow::onFrame(float dt) void TradeWindow::onFrame(float dt)
@ -144,6 +145,12 @@ namespace MWGui
checkReferenceAvailable(); checkReferenceAvailable();
} }
void TradeWindow::onNameFilterChanged(MyGUI::EditBox* _sender)
{
mSortModel->setNameFilter(_sender->getCaption());
mItemView->update();
}
void TradeWindow::onFilterChanged(MyGUI::Widget* _sender) void TradeWindow::onFilterChanged(MyGUI::Widget* _sender)
{ {
if (_sender == mFilterAll) if (_sender == mFilterAll)

@ -59,6 +59,8 @@ namespace MWGui
MyGUI::Button* mFilterMagic; MyGUI::Button* mFilterMagic;
MyGUI::Button* mFilterMisc; MyGUI::Button* mFilterMisc;
MyGUI::EditBox* mFilterEdit;
MyGUI::Button* mIncreaseButton; MyGUI::Button* mIncreaseButton;
MyGUI::Button* mDecreaseButton; MyGUI::Button* mDecreaseButton;
MyGUI::TextBox* mTotalBalanceLabel; MyGUI::TextBox* mTotalBalanceLabel;
@ -86,6 +88,7 @@ namespace MWGui
void sellItem (MyGUI::Widget* sender, int count); void sellItem (MyGUI::Widget* sender, int count);
void onFilterChanged(MyGUI::Widget* _sender); void onFilterChanged(MyGUI::Widget* _sender);
void onNameFilterChanged(MyGUI::EditBox* _sender);
void onOfferButtonClicked(MyGUI::Widget* _sender); void onOfferButtonClicked(MyGUI::Widget* _sender);
void onAccept(MyGUI::EditBox* sender); void onAccept(MyGUI::EditBox* sender);
void onCancelButtonClicked(MyGUI::Widget* _sender); void onCancelButtonClicked(MyGUI::Widget* _sender);

@ -4,8 +4,14 @@
<Widget type="Window" skin="MW_Window" layer="Windows" position="0 0 600 300" name="_Main"> <Widget type="Window" skin="MW_Window" layer="Windows" position="0 0 600 300" name="_Main">
<Property key="MinSize" value="245 145"/> <Property key="MinSize" value="245 145"/>
<!-- Search box-->
<Widget type="HBox" position="5 5 575 23" align="Left Top HStretch" name="_Filter">
<Widget type="EditBox" skin="MW_TextBoxEditWithBorder" position="0 0 0 23" name="FilterEdit">
<UserString key="HStretch" value="true"/>
</Widget>
</Widget>
<!-- Items --> <!-- Items -->
<Widget type="ItemView" skin="MW_ItemView" position="5 5 575 225" name="ItemView" align="Left Top Stretch"> <Widget type="ItemView" skin="MW_ItemView" position="5 33 575 197" name="ItemView" align="Left Top Stretch">
</Widget> </Widget>
<Widget type="HBox" position="5 235 575 24" align="Bottom HStretch"> <Widget type="HBox" position="5 235 575 24" align="Bottom HStretch">

@ -50,6 +50,10 @@
<Property key="Caption" value="#{sMiscTab}"/> <Property key="Caption" value="#{sMiscTab}"/>
<Property key="NeedKey" value="false"/> <Property key="NeedKey" value="false"/>
</Widget> </Widget>
<!-- Search box-->
<Widget type="EditBox" skin="MW_TextBoxEditWithBorder" position="0 0 0 23" name="FilterEdit">
<UserString key="HStretch" value="true"/>
</Widget>
</Widget> </Widget>
</Widget> </Widget>

@ -27,6 +27,10 @@
<Property key="Caption" value="#{sMiscTab}"/> <Property key="Caption" value="#{sMiscTab}"/>
<Property key="NeedKey" value="false"/> <Property key="NeedKey" value="false"/>
</Widget> </Widget>
<!-- Search box-->
<Widget type="EditBox" skin="MW_TextBoxEditWithBorder" position="0 0 0 23" name="FilterEdit">
<UserString key="HStretch" value="true"/>
</Widget>
</Widget> </Widget>
<!-- Items --> <!-- Items -->

Loading…
Cancel
Save