2013-03-23 07:16:46 +00:00
|
|
|
#include "repair.hpp"
|
|
|
|
|
2014-02-19 17:40:29 +00:00
|
|
|
#include <iomanip>
|
|
|
|
|
2015-01-10 01:50:43 +00:00
|
|
|
#include <MyGUI_ScrollView.h>
|
2016-11-06 10:01:46 +00:00
|
|
|
|
|
|
|
#include <components/widgets/box.hpp>
|
2015-01-10 01:50:43 +00:00
|
|
|
|
2013-03-23 07:16:46 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/windowmanager.hpp"
|
|
|
|
|
2015-08-21 09:12:39 +00:00
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
|
|
|
|
2013-03-23 07:16:46 +00:00
|
|
|
#include "../mwworld/containerstore.hpp"
|
|
|
|
#include "../mwworld/class.hpp"
|
|
|
|
|
2021-05-15 20:15:46 +00:00
|
|
|
#include "itemselection.hpp"
|
2014-06-05 20:13:18 +00:00
|
|
|
#include "itemwidget.hpp"
|
2016-11-06 10:01:46 +00:00
|
|
|
#include "itemchargeview.hpp"
|
|
|
|
#include "sortfilteritemmodel.hpp"
|
|
|
|
#include "inventoryitemmodel.hpp"
|
2014-06-05 20:13:18 +00:00
|
|
|
|
2013-03-23 07:16:46 +00:00
|
|
|
namespace MWGui
|
|
|
|
{
|
|
|
|
|
2013-04-10 18:46:21 +00:00
|
|
|
Repair::Repair()
|
|
|
|
: WindowBase("openmw_repair.layout")
|
2018-10-09 06:21:12 +00:00
|
|
|
, mItemSelectionDialog(nullptr)
|
2013-03-23 07:16:46 +00:00
|
|
|
{
|
|
|
|
getWidget(mRepairBox, "RepairBox");
|
|
|
|
getWidget(mToolBox, "ToolBox");
|
|
|
|
getWidget(mToolIcon, "ToolIcon");
|
|
|
|
getWidget(mUsesLabel, "UsesLabel");
|
|
|
|
getWidget(mQualityLabel, "QualityLabel");
|
|
|
|
getWidget(mCancelButton, "CancelButton");
|
|
|
|
|
|
|
|
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &Repair::onCancel);
|
2016-11-06 10:01:46 +00:00
|
|
|
|
2017-04-15 19:06:13 +00:00
|
|
|
mRepairBox->eventItemClicked += MyGUI::newDelegate(this, &Repair::onRepairItem);
|
2016-11-06 10:01:46 +00:00
|
|
|
mRepairBox->setDisplayMode(ItemChargeView::DisplayMode_Health);
|
2017-04-15 19:06:13 +00:00
|
|
|
|
|
|
|
mToolIcon->eventMouseButtonClick += MyGUI::newDelegate(this, &Repair::onSelectItem);
|
2013-03-23 07:16:46 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 15:10:53 +00:00
|
|
|
void Repair::onOpen()
|
2013-03-23 07:16:46 +00:00
|
|
|
{
|
|
|
|
center();
|
2016-11-06 10:01:46 +00:00
|
|
|
|
|
|
|
SortFilterItemModel * model = new SortFilterItemModel(new InventoryItemModel(MWMechanics::getPlayer()));
|
|
|
|
model->setFilter(SortFilterItemModel::Filter_OnlyRepairable);
|
|
|
|
mRepairBox->setModel(model);
|
|
|
|
|
2015-06-04 20:09:40 +00:00
|
|
|
// Reset scrollbars
|
2016-11-06 10:01:46 +00:00
|
|
|
mRepairBox->resetScrollbars();
|
2013-03-23 07:16:46 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 19:26:41 +00:00
|
|
|
void Repair::setPtr(const MWWorld::Ptr &item)
|
2013-03-23 07:16:46 +00:00
|
|
|
{
|
2017-07-10 11:48:00 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->playSound("Item Repair Up");
|
2017-04-02 19:19:43 +00:00
|
|
|
|
2013-03-23 07:16:46 +00:00
|
|
|
mRepair.setTool(item);
|
|
|
|
|
2014-06-05 20:13:18 +00:00
|
|
|
mToolIcon->setItem(item);
|
2013-03-23 07:16:46 +00:00
|
|
|
mToolIcon->setUserString("ToolTipType", "ItemPtr");
|
2017-03-13 01:47:52 +00:00
|
|
|
mToolIcon->setUserData(MWWorld::Ptr(item));
|
2013-03-23 07:16:46 +00:00
|
|
|
|
|
|
|
updateRepairView();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Repair::updateRepairView()
|
|
|
|
{
|
|
|
|
MWWorld::LiveCellRef<ESM::Repair> *ref =
|
|
|
|
mRepair.getTool().get<ESM::Repair>();
|
|
|
|
|
2014-05-25 12:13:07 +00:00
|
|
|
int uses = mRepair.getTool().getClass().getItemHealth(mRepair.getTool());
|
2013-03-23 07:16:46 +00:00
|
|
|
|
|
|
|
float quality = ref->mBase->mData.mQuality;
|
|
|
|
|
2017-04-15 19:06:13 +00:00
|
|
|
mToolIcon->setUserData(mRepair.getTool());
|
|
|
|
|
2013-03-23 07:16:46 +00:00
|
|
|
std::stringstream qualityStr;
|
|
|
|
qualityStr << std::setprecision(3) << quality;
|
|
|
|
|
2015-01-10 02:01:01 +00:00
|
|
|
mUsesLabel->setCaptionWithReplacing("#{sUses} " + MyGUI::utility::toString(uses));
|
2013-03-23 07:16:46 +00:00
|
|
|
mQualityLabel->setCaptionWithReplacing("#{sQuality} " + qualityStr.str());
|
|
|
|
|
|
|
|
bool toolBoxVisible = (mRepair.getTool().getRefData().getCount() != 0);
|
|
|
|
mToolBox->setVisible(toolBoxVisible);
|
2016-11-06 10:01:46 +00:00
|
|
|
mToolBox->setUserString("Hidden", toolBoxVisible ? "false" : "true");
|
|
|
|
|
2017-04-15 19:06:13 +00:00
|
|
|
if (!toolBoxVisible)
|
|
|
|
{
|
|
|
|
mToolIcon->setItem(MWWorld::Ptr());
|
|
|
|
mToolIcon->clearUserStrings();
|
|
|
|
}
|
|
|
|
|
2016-11-06 10:01:46 +00:00
|
|
|
mRepairBox->update();
|
2013-03-23 07:16:46 +00:00
|
|
|
|
2016-11-06 10:01:46 +00:00
|
|
|
Gui::Box* box = dynamic_cast<Gui::Box*>(mMainWidget);
|
2018-10-09 06:21:12 +00:00
|
|
|
if (box == nullptr)
|
2016-11-06 10:01:46 +00:00
|
|
|
throw std::runtime_error("main widget must be a box");
|
|
|
|
|
|
|
|
box->notifyChildrenSizeChanged();
|
|
|
|
center();
|
2013-03-23 07:16:46 +00:00
|
|
|
}
|
|
|
|
|
2017-04-15 19:06:13 +00:00
|
|
|
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);
|
|
|
|
|
2017-07-10 11:48:00 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->playSound(item.getClass().getDownSoundId(item));
|
2017-04-15 19:06:13 +00:00
|
|
|
updateRepairView();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Repair::onItemCancel()
|
|
|
|
{
|
|
|
|
mItemSelectionDialog->setVisible(false);
|
|
|
|
}
|
|
|
|
|
2016-11-06 10:01:46 +00:00
|
|
|
void Repair::onCancel(MyGUI::Widget* /*sender*/)
|
2013-03-23 07:16:46 +00:00
|
|
|
{
|
2017-09-23 10:18:39 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Repair);
|
2013-03-23 07:16:46 +00:00
|
|
|
}
|
|
|
|
|
2016-11-06 10:01:46 +00:00
|
|
|
void Repair::onRepairItem(MyGUI::Widget* /*sender*/, const MWWorld::Ptr& ptr)
|
2013-03-23 07:16:46 +00:00
|
|
|
{
|
|
|
|
if (!mRepair.getTool().getRefData().getCount())
|
|
|
|
return;
|
|
|
|
|
2016-11-06 10:01:46 +00:00
|
|
|
mRepair.repair(ptr);
|
2013-03-23 07:16:46 +00:00
|
|
|
|
|
|
|
updateRepairView();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|