2013-11-19 05:48:47 +00:00
|
|
|
#include "recharge.hpp"
|
|
|
|
|
2015-01-10 01:50:43 +00:00
|
|
|
#include <MyGUI_ScrollView.h>
|
|
|
|
#include <MyGUI_Gui.h>
|
|
|
|
|
2016-11-06 10:01:46 +00:00
|
|
|
#include <components/widgets/box.hpp>
|
|
|
|
|
2015-04-22 15:58:55 +00:00
|
|
|
#include <components/misc/rng.hpp>
|
2015-03-15 01:07:47 +00:00
|
|
|
|
2013-11-19 05:48:47 +00:00
|
|
|
#include "../mwbase/world.hpp"
|
|
|
|
#include "../mwbase/environment.hpp"
|
|
|
|
#include "../mwbase/windowmanager.hpp"
|
|
|
|
|
|
|
|
#include "../mwworld/containerstore.hpp"
|
|
|
|
#include "../mwworld/class.hpp"
|
2014-12-19 10:26:54 +00:00
|
|
|
#include "../mwworld/esmstore.hpp"
|
2013-11-19 05:48:47 +00:00
|
|
|
|
|
|
|
#include "../mwmechanics/creaturestats.hpp"
|
2015-08-21 09:12:39 +00:00
|
|
|
#include "../mwmechanics/actorutil.hpp"
|
2018-12-15 06:23:50 +00:00
|
|
|
#include "../mwmechanics/recharge.hpp"
|
2013-11-19 05:48:47 +00:00
|
|
|
|
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"
|
2013-11-19 05:48:47 +00:00
|
|
|
|
|
|
|
namespace MWGui
|
|
|
|
{
|
|
|
|
|
|
|
|
Recharge::Recharge()
|
|
|
|
: WindowBase("openmw_recharge_dialog.layout")
|
2018-10-09 06:21:12 +00:00
|
|
|
, mItemSelectionDialog(nullptr)
|
2013-11-19 05:48:47 +00:00
|
|
|
{
|
|
|
|
getWidget(mBox, "Box");
|
|
|
|
getWidget(mGemBox, "GemBox");
|
|
|
|
getWidget(mGemIcon, "GemIcon");
|
|
|
|
getWidget(mChargeLabel, "ChargeLabel");
|
|
|
|
getWidget(mCancelButton, "CancelButton");
|
|
|
|
|
|
|
|
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &Recharge::onCancel);
|
2016-11-06 10:01:46 +00:00
|
|
|
mBox->eventItemClicked += MyGUI::newDelegate(this, &Recharge::onItemClicked);
|
|
|
|
|
|
|
|
mBox->setDisplayMode(ItemChargeView::DisplayMode_EnchantmentCharge);
|
2013-11-19 05:48:47 +00:00
|
|
|
|
2017-04-16 12:52:56 +00:00
|
|
|
mGemIcon->eventMouseButtonClick += MyGUI::newDelegate(this, &Recharge::onSelectItem);
|
2013-11-19 05:48:47 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 15:10:53 +00:00
|
|
|
void Recharge::onOpen()
|
2013-11-19 05:48:47 +00:00
|
|
|
{
|
|
|
|
center();
|
2016-11-06 10:01:46 +00:00
|
|
|
|
|
|
|
SortFilterItemModel * model = new SortFilterItemModel(new InventoryItemModel(MWMechanics::getPlayer()));
|
|
|
|
model->setFilter(SortFilterItemModel::Filter_OnlyRechargable);
|
|
|
|
mBox->setModel(model);
|
|
|
|
|
2015-06-04 20:09:40 +00:00
|
|
|
// Reset scrollbars
|
2016-11-06 10:01:46 +00:00
|
|
|
mBox->resetScrollbars();
|
2013-11-19 05:48:47 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 19:26:41 +00:00
|
|
|
void Recharge::setPtr (const MWWorld::Ptr &item)
|
2013-11-19 05:48:47 +00:00
|
|
|
{
|
2014-06-05 20:13:18 +00:00
|
|
|
mGemIcon->setItem(item);
|
2013-11-19 05:48:47 +00:00
|
|
|
mGemIcon->setUserString("ToolTipType", "ItemPtr");
|
2017-03-13 01:47:52 +00:00
|
|
|
mGemIcon->setUserData(MWWorld::Ptr(item));
|
2013-11-19 05:48:47 +00:00
|
|
|
|
|
|
|
updateView();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Recharge::updateView()
|
|
|
|
{
|
|
|
|
MWWorld::Ptr gem = *mGemIcon->getUserData<MWWorld::Ptr>();
|
|
|
|
|
2014-05-25 12:13:07 +00:00
|
|
|
std::string soul = gem.getCellRef().getSoul();
|
2013-11-19 05:48:47 +00:00
|
|
|
const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get<ESM::Creature>().find(soul);
|
|
|
|
|
2015-01-10 02:01:01 +00:00
|
|
|
mChargeLabel->setCaptionWithReplacing("#{sCharges} " + MyGUI::utility::toString(creature->mData.mSoul));
|
2013-11-19 05:48:47 +00:00
|
|
|
|
|
|
|
bool toolBoxVisible = (gem.getRefData().getCount() != 0);
|
|
|
|
mGemBox->setVisible(toolBoxVisible);
|
2016-11-06 10:01:46 +00:00
|
|
|
mGemBox->setUserString("Hidden", toolBoxVisible ? "false" : "true");
|
2013-11-19 05:48:47 +00:00
|
|
|
|
2017-04-16 12:52:56 +00:00
|
|
|
if (!toolBoxVisible)
|
|
|
|
{
|
|
|
|
mGemIcon->setItem(MWWorld::Ptr());
|
|
|
|
mGemIcon->clearUserStrings();
|
|
|
|
}
|
|
|
|
|
2016-11-06 10:01:46 +00:00
|
|
|
mBox->update();
|
2013-11-19 05:48:47 +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");
|
2013-11-19 05:48:47 +00:00
|
|
|
|
2016-11-06 10:01:46 +00:00
|
|
|
box->notifyChildrenSizeChanged();
|
|
|
|
center();
|
2013-11-19 05:48:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Recharge::onCancel(MyGUI::Widget *sender)
|
|
|
|
{
|
2017-09-23 10:18:39 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->removeGuiMode(GM_Recharge);
|
2013-11-19 05:48:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-16 12:52:56 +00:00
|
|
|
void Recharge::onSelectItem(MyGUI::Widget *sender)
|
|
|
|
{
|
|
|
|
delete mItemSelectionDialog;
|
|
|
|
mItemSelectionDialog = new ItemSelectionDialog("#{sSoulGemsWithSouls}");
|
|
|
|
mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &Recharge::onItemSelected);
|
|
|
|
mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &Recharge::onItemCancel);
|
|
|
|
mItemSelectionDialog->setVisible(true);
|
|
|
|
mItemSelectionDialog->openContainer(MWMechanics::getPlayer());
|
|
|
|
mItemSelectionDialog->setFilter(SortFilterItemModel::Filter_OnlyChargedSoulstones);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Recharge::onItemSelected(MWWorld::Ptr item)
|
|
|
|
{
|
|
|
|
mItemSelectionDialog->setVisible(false);
|
|
|
|
|
|
|
|
mGemIcon->setItem(item);
|
|
|
|
mGemIcon->setUserString ("ToolTipType", "ItemPtr");
|
|
|
|
mGemIcon->setUserData(item);
|
|
|
|
|
2017-07-10 11:48:00 +00:00
|
|
|
MWBase::Environment::get().getWindowManager()->playSound(item.getClass().getDownSoundId(item));
|
2017-04-16 12:52:56 +00:00
|
|
|
updateView();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Recharge::onItemCancel()
|
|
|
|
{
|
|
|
|
mItemSelectionDialog->setVisible(false);
|
|
|
|
}
|
|
|
|
|
2016-11-06 10:01:46 +00:00
|
|
|
void Recharge::onItemClicked(MyGUI::Widget *sender, const MWWorld::Ptr& item)
|
2013-11-19 05:48:47 +00:00
|
|
|
{
|
|
|
|
MWWorld::Ptr gem = *mGemIcon->getUserData<MWWorld::Ptr>();
|
2018-12-15 06:23:50 +00:00
|
|
|
if (!MWMechanics::rechargeItem(item, gem))
|
2013-11-19 05:48:47 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
updateView();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|