From 10d4cb15ad609389080d77e4dea47cd43e454579 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sat, 15 Apr 2017 23:06:13 +0400 Subject: [PATCH] Improved repair widget --- apps/openmw/mwgui/repair.cpp | 43 ++++++++++++++- apps/openmw/mwgui/repair.hpp | 10 ++++ apps/openmw/mwgui/sortfilteritemmodel.cpp | 2 + apps/openmw/mwgui/sortfilteritemmodel.hpp | 1 + .../mygui/openmw_itemselection_dialog.layout | 2 +- files/mygui/openmw_repair.layout | 54 ++++++++++--------- 6 files changed, 85 insertions(+), 27 deletions(-) diff --git a/apps/openmw/mwgui/repair.cpp b/apps/openmw/mwgui/repair.cpp index 3acea985b..156f4412b 100644 --- a/apps/openmw/mwgui/repair.cpp +++ b/apps/openmw/mwgui/repair.cpp @@ -30,6 +30,7 @@ namespace MWGui Repair::Repair() : WindowBase("openmw_repair.layout") + , mItemSelectionDialog(NULL) { getWidget(mRepairBox, "RepairBox"); getWidget(mToolBox, "ToolBox"); @@ -39,9 +40,11 @@ Repair::Repair() getWidget(mCancelButton, "CancelButton"); mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &Repair::onCancel); - mRepairBox->eventItemClicked += MyGUI::newDelegate(this, &Repair::onRepairItem); + mRepairBox->eventItemClicked += MyGUI::newDelegate(this, &Repair::onRepairItem); mRepairBox->setDisplayMode(ItemChargeView::DisplayMode_Health); + + mToolIcon->eventMouseButtonClick += MyGUI::newDelegate(this, &Repair::onSelectItem); } void Repair::open() @@ -83,6 +86,8 @@ void Repair::updateRepairView() float quality = ref->mBase->mData.mQuality; + mToolIcon->setUserData(mRepair.getTool()); + std::stringstream qualityStr; qualityStr << std::setprecision(3) << quality; @@ -93,6 +98,12 @@ void Repair::updateRepairView() mToolBox->setVisible(toolBoxVisible); mToolBox->setUserString("Hidden", toolBoxVisible ? "false" : "true"); + if (!toolBoxVisible) + { + mToolIcon->setItem(MWWorld::Ptr()); + mToolIcon->clearUserStrings(); + } + mRepairBox->update(); Gui::Box* box = dynamic_cast(mMainWidget); @@ -103,6 +114,36 @@ void Repair::updateRepairView() center(); } +void Repair::onSelectItem(MyGUI::Widget *sender) +{ + delete mItemSelectionDialog; + mItemSelectionDialog = new ItemSelectionDialog("#{sRepair}"); + mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &Repair::onItemSelected); + mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &Repair::onItemCancel); + mItemSelectionDialog->setVisible(true); + mItemSelectionDialog->openContainer(MWMechanics::getPlayer()); + mItemSelectionDialog->setFilter(SortFilterItemModel::Filter_OnlyRepairTools); +} + +void Repair::onItemSelected(MWWorld::Ptr item) +{ + mItemSelectionDialog->setVisible(false); + + mToolIcon->setItem(item); + mToolIcon->setUserString ("ToolTipType", "ItemPtr"); + mToolIcon->setUserData(item); + + mRepair.setTool(item); + + MWBase::Environment::get().getSoundManager()->playSound(item.getClass().getDownSoundId(item), 1, 1); + updateRepairView(); +} + +void Repair::onItemCancel() +{ + mItemSelectionDialog->setVisible(false); +} + void Repair::onCancel(MyGUI::Widget* /*sender*/) { exit(); diff --git a/apps/openmw/mwgui/repair.hpp b/apps/openmw/mwgui/repair.hpp index 8746f7dc4..c50ba861a 100644 --- a/apps/openmw/mwgui/repair.hpp +++ b/apps/openmw/mwgui/repair.hpp @@ -3,11 +3,14 @@ #include "windowbase.hpp" +#include "itemselection.hpp" + #include "../mwmechanics/repair.hpp" namespace MWGui { +class ItemSelectionDialog; class ItemWidget; class ItemChargeView; @@ -29,6 +32,8 @@ protected: ItemWidget* mToolIcon; + ItemSelectionDialog* mItemSelectionDialog; + MyGUI::TextBox* mUsesLabel; MyGUI::TextBox* mQualityLabel; @@ -38,6 +43,11 @@ protected: void updateRepairView(); + void onSelectItem(MyGUI::Widget* sender); + + void onItemSelected(MWWorld::Ptr item); + void onItemCancel(); + void onRepairItem(MyGUI::Widget* sender, const MWWorld::Ptr& ptr); void onCancel(MyGUI::Widget* sender); diff --git a/apps/openmw/mwgui/sortfilteritemmodel.cpp b/apps/openmw/mwgui/sortfilteritemmodel.cpp index 09438b950..60111fb79 100644 --- a/apps/openmw/mwgui/sortfilteritemmodel.cpp +++ b/apps/openmw/mwgui/sortfilteritemmodel.cpp @@ -129,6 +129,8 @@ namespace MWGui if ((mFilter & Filter_OnlyChargedSoulstones) && (base.getTypeName() != typeid(ESM::Miscellaneous).name() || base.getCellRef().getSoul() == "")) return false; + if ((mFilter & Filter_OnlyRepairTools) && (base.getTypeName() != typeid(ESM::Repair).name())) + return false; if ((mFilter & Filter_OnlyEnchantable) && (item.mFlags & ItemStack::Flag_Enchanted || (base.getTypeName() != typeid(ESM::Armor).name() && base.getTypeName() != typeid(ESM::Clothing).name() diff --git a/apps/openmw/mwgui/sortfilteritemmodel.hpp b/apps/openmw/mwgui/sortfilteritemmodel.hpp index 3d5396e2a..4731cbb8a 100644 --- a/apps/openmw/mwgui/sortfilteritemmodel.hpp +++ b/apps/openmw/mwgui/sortfilteritemmodel.hpp @@ -41,6 +41,7 @@ namespace MWGui static const int Filter_OnlyUsableItems = (1<<4); // Only items with a Use action static const int Filter_OnlyRepairable = (1<<5); static const int Filter_OnlyRechargable = (1<<6); + static const int Filter_OnlyRepairTools = (1<<7); private: diff --git a/files/mygui/openmw_itemselection_dialog.layout b/files/mygui/openmw_itemselection_dialog.layout index 5ae30563a..b2337b669 100644 --- a/files/mygui/openmw_itemselection_dialog.layout +++ b/files/mygui/openmw_itemselection_dialog.layout @@ -1,6 +1,6 @@ - + diff --git a/files/mygui/openmw_repair.layout b/files/mygui/openmw_repair.layout index 9a349c56b..340711bb1 100644 --- a/files/mygui/openmw_repair.layout +++ b/files/mygui/openmw_repair.layout @@ -1,26 +1,13 @@ - + - - - - - - - - - - - - - - - - + + + @@ -29,14 +16,31 @@ - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - -