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