1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 04:49:54 +00:00
openmw-tes3mp/apps/openmw/mwgui/enchantingdialog.cpp

308 lines
11 KiB
C++
Raw Normal View History

#include "enchantingdialog.hpp"
2013-03-16 18:00:14 +00:00
#include <boost/lexical_cast.hpp>
#include "../mwbase/environment.hpp"
#include "../mwbase/world.hpp"
#include "../mwworld/player.hpp"
2013-03-28 16:41:00 +00:00
#include "../mwworld/manualref.hpp"
2013-05-11 16:38:27 +00:00
#include "../mwworld/class.hpp"
2013-03-16 18:00:14 +00:00
#include "itemselection.hpp"
#include "container.hpp"
2013-03-28 16:41:00 +00:00
#include "inventorywindow.hpp"
2013-05-11 16:38:27 +00:00
#include "sortfilteritemmodel.hpp"
namespace MWGui
{
EnchantingDialog::EnchantingDialog()
: WindowBase("openmw_enchanting_dialog.layout")
, EffectEditorBase()
2013-03-16 18:00:14 +00:00
, mItemSelectionDialog(NULL)
{
2013-03-28 16:41:00 +00:00
getWidget(mName, "NameEdit");
2012-10-03 13:06:54 +00:00
getWidget(mCancelButton, "CancelButton");
getWidget(mAvailableEffectsList, "AvailableEffects");
getWidget(mUsedEffectsView, "UsedEffects");
2013-03-16 18:00:14 +00:00
getWidget(mItemBox, "ItemBox");
getWidget(mSoulBox, "SoulBox");
getWidget(mEnchantmentPoints, "Enchantment");
getWidget(mCastCost, "CastCost");
getWidget(mCharge, "Charge");
getWidget(mTypeButton, "TypeButton");
getWidget(mBuyButton, "BuyButton");
getWidget(mPrice, "PriceLabel");
2013-04-03 16:02:30 +00:00
getWidget(mPriceText, "PriceTextLabel");
setWidgets(mAvailableEffectsList, mUsedEffectsView);
2012-10-03 13:06:54 +00:00
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &EnchantingDialog::onCancelButtonClicked);
2013-03-16 18:00:14 +00:00
mItemBox->eventMouseButtonClick += MyGUI::newDelegate(this, &EnchantingDialog::onSelectItem);
mSoulBox->eventMouseButtonClick += MyGUI::newDelegate(this, &EnchantingDialog::onSelectSoul);
2013-03-28 16:41:00 +00:00
mBuyButton->eventMouseButtonClick += MyGUI::newDelegate(this, &EnchantingDialog::onBuyButtonClicked);
mTypeButton->eventMouseButtonClick += MyGUI::newDelegate(this, &EnchantingDialog::onTypeButtonClicked);
2013-03-16 18:00:14 +00:00
}
EnchantingDialog::~EnchantingDialog()
{
delete mItemSelectionDialog;
}
void EnchantingDialog::open()
{
center();
2013-03-16 18:00:14 +00:00
onRemoveItem(NULL);
onRemoveSoul(NULL);
}
void EnchantingDialog::updateLabels()
{
2013-04-29 08:19:09 +00:00
std::stringstream enchantCost;
2013-05-27 18:23:04 +00:00
enchantCost << std::setprecision(1) << std::fixed << mEnchanting.getEnchantPoints();
2013-04-29 08:19:09 +00:00
mEnchantmentPoints->setCaption(enchantCost.str() + " / " + boost::lexical_cast<std::string>(mEnchanting.getMaxEnchantValue()));
2013-03-28 16:41:00 +00:00
mCharge->setCaption(boost::lexical_cast<std::string>(mEnchanting.getGemCharge()));
std::stringstream castCost;
castCost << std::setprecision(1) << std::fixed << mEnchanting.getCastCost();
mCastCost->setCaption(boost::lexical_cast<std::string>(castCost.str()));
2013-03-28 16:41:00 +00:00
2013-04-02 18:46:48 +00:00
mPrice->setCaption(boost::lexical_cast<std::string>(mEnchanting.getEnchantPrice()));
switch(mEnchanting.getCastStyle())
2013-03-28 16:41:00 +00:00
{
case ESM::Enchantment::CastOnce:
mTypeButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastOnce","Cast Once"));
2013-03-28 16:41:00 +00:00
mAddEffectDialog.constantEffect=false;
break;
case ESM::Enchantment::WhenStrikes:
mTypeButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastWhenStrikes", "When Strikes"));
2013-03-28 16:41:00 +00:00
mAddEffectDialog.constantEffect=false;
break;
case ESM::Enchantment::WhenUsed:
mTypeButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastWhenUsed", "When Used"));
2013-03-28 16:41:00 +00:00
mAddEffectDialog.constantEffect=false;
break;
case ESM::Enchantment::ConstantEffect:
mTypeButton->setCaption(MWBase::Environment::get().getWindowManager()->getGameSettingString("sItemCastConstant", "Cast Constant"));
2013-03-28 16:41:00 +00:00
mAddEffectDialog.constantEffect=true;
break;
}
}
void EnchantingDialog::startEnchanting (MWWorld::Ptr actor)
{
2013-03-30 18:08:42 +00:00
mEnchanting.setSelfEnchanting(false);
2013-04-02 18:46:48 +00:00
mEnchanting.setEnchanter(actor);
2013-03-30 18:08:42 +00:00
2013-04-02 18:46:48 +00:00
mPtr = actor;
startEditing ();
}
void EnchantingDialog::startSelfEnchanting(MWWorld::Ptr soulgem)
{
2013-03-30 18:08:42 +00:00
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
mEnchanting.setSelfEnchanting(true);
mEnchanting.setEnchanter(player);
mPtr = player;
startEditing();
2013-04-03 16:02:30 +00:00
mEnchanting.setSoulGem(soulgem);
MyGUI::ImageBox* image = mSoulBox->createWidget<MyGUI::ImageBox>("ImageBox", MyGUI::IntCoord(0, 0, 32, 32), MyGUI::Align::Default);
std::string path = std::string("icons\\");
path += MWWorld::Class::get(soulgem).getInventoryIcon(soulgem);
int pos = path.rfind(".");
path.erase(pos);
path.append(".dds");
image->setImageTexture (path);
image->setUserString ("ToolTipType", "ItemPtr");
image->setUserData(soulgem);
image->eventMouseButtonClick += MyGUI::newDelegate(this, &EnchantingDialog::onRemoveSoul);
mPrice->setVisible(false);
mPriceText->setVisible(false);
2013-04-03 16:06:11 +00:00
updateLabels();
}
void EnchantingDialog::onReferenceUnavailable ()
{
MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_Dialogue);
MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_Enchanting);
}
2012-10-03 13:06:54 +00:00
void EnchantingDialog::onCancelButtonClicked(MyGUI::Widget* sender)
{
MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_Enchanting);
2012-10-03 13:06:54 +00:00
}
2013-03-16 18:00:14 +00:00
void EnchantingDialog::onSelectItem(MyGUI::Widget *sender)
{
delete mItemSelectionDialog;
2013-05-11 16:38:27 +00:00
mItemSelectionDialog = new ItemSelectionDialog("#{sEnchantItems}");
2013-03-16 18:00:14 +00:00
mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &EnchantingDialog::onItemSelected);
mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &EnchantingDialog::onItemCancel);
mItemSelectionDialog->setVisible(true);
mItemSelectionDialog->openContainer(MWBase::Environment::get().getWorld()->getPlayer().getPlayer());
2013-05-11 16:38:27 +00:00
mItemSelectionDialog->setFilter(SortFilterItemModel::Filter_OnlyEnchantable);
2013-03-16 18:00:14 +00:00
}
void EnchantingDialog::onItemSelected(MWWorld::Ptr item)
{
mItemSelectionDialog->setVisible(false);
while (mItemBox->getChildCount ())
MyGUI::Gui::getInstance ().destroyWidget (mItemBox->getChildAt(0));
MyGUI::ImageBox* image = mItemBox->createWidget<MyGUI::ImageBox>("ImageBox", MyGUI::IntCoord(0, 0, 32, 32), MyGUI::Align::Default);
std::string path = std::string("icons\\");
path += MWWorld::Class::get(item).getInventoryIcon(item);
int pos = path.rfind(".");
path.erase(pos);
path.append(".dds");
image->setImageTexture (path);
image->setUserString ("ToolTipType", "ItemPtr");
image->setUserData(item);
image->eventMouseButtonClick += MyGUI::newDelegate(this, &EnchantingDialog::onRemoveItem);
2013-03-28 16:41:00 +00:00
mEnchanting.setOldItem(item);
mEnchanting.nextCastStyle();
2013-03-16 18:00:14 +00:00
updateLabels();
}
void EnchantingDialog::onRemoveItem(MyGUI::Widget *sender)
{
while (mItemBox->getChildCount ())
MyGUI::Gui::getInstance ().destroyWidget (mItemBox->getChildAt(0));
2013-03-28 16:41:00 +00:00
mEnchanting.setOldItem(MWWorld::Ptr());
2013-03-16 18:00:14 +00:00
updateLabels();
}
void EnchantingDialog::onItemCancel()
{
mItemSelectionDialog->setVisible(false);
}
void EnchantingDialog::onSoulSelected(MWWorld::Ptr item)
{
mItemSelectionDialog->setVisible(false);
2013-03-28 16:41:00 +00:00
mEnchanting.setSoulGem(item);
if(mEnchanting.getGemCharge()==0)
{
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage32}");
2013-03-28 16:41:00 +00:00
return;
}
2013-03-16 18:00:14 +00:00
while (mSoulBox->getChildCount ())
MyGUI::Gui::getInstance ().destroyWidget (mSoulBox->getChildAt(0));
MyGUI::ImageBox* image = mSoulBox->createWidget<MyGUI::ImageBox>("ImageBox", MyGUI::IntCoord(0, 0, 32, 32), MyGUI::Align::Default);
std::string path = std::string("icons\\");
path += MWWorld::Class::get(item).getInventoryIcon(item);
int pos = path.rfind(".");
path.erase(pos);
path.append(".dds");
image->setImageTexture (path);
image->setUserString ("ToolTipType", "ItemPtr");
image->setUserData(item);
image->eventMouseButtonClick += MyGUI::newDelegate(this, &EnchantingDialog::onRemoveSoul);
updateLabels();
}
void EnchantingDialog::onRemoveSoul(MyGUI::Widget *sender)
{
while (mSoulBox->getChildCount ())
MyGUI::Gui::getInstance ().destroyWidget (mSoulBox->getChildAt(0));
2013-03-28 16:41:00 +00:00
mEnchanting.setSoulGem(MWWorld::Ptr());
2013-03-16 18:00:14 +00:00
updateLabels();
}
void EnchantingDialog::onSoulCancel()
{
mItemSelectionDialog->setVisible(false);
}
void EnchantingDialog::onSelectSoul(MyGUI::Widget *sender)
{
delete mItemSelectionDialog;
2013-05-11 16:38:27 +00:00
mItemSelectionDialog = new ItemSelectionDialog("#{sSoulGemsWithSouls}");
2013-03-16 18:00:14 +00:00
mItemSelectionDialog->eventItemSelected += MyGUI::newDelegate(this, &EnchantingDialog::onSoulSelected);
mItemSelectionDialog->eventDialogCanceled += MyGUI::newDelegate(this, &EnchantingDialog::onSoulCancel);
mItemSelectionDialog->setVisible(true);
mItemSelectionDialog->openContainer(MWBase::Environment::get().getWorld()->getPlayer().getPlayer());
2013-05-11 16:38:27 +00:00
mItemSelectionDialog->setFilter(SortFilterItemModel::Filter_OnlyChargedSoulstones);
2013-03-16 18:00:14 +00:00
//MWBase::Environment::get().getWindowManager()->messageBox("#{sInventorySelectNoSoul}");
2013-03-16 18:00:14 +00:00
}
2013-03-28 16:41:00 +00:00
void EnchantingDialog::notifyEffectsChanged ()
{
mEffectList.mList = mEffects;
mEnchanting.setEffect(mEffectList);
updateLabels();
}
void EnchantingDialog::onTypeButtonClicked(MyGUI::Widget* sender)
{
mEnchanting.nextCastStyle();
2013-03-28 16:41:00 +00:00
updateLabels();
}
void EnchantingDialog::onBuyButtonClicked(MyGUI::Widget* sender)
{
if (mEffects.size() <= 0)
{
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage30}");
2013-03-28 16:41:00 +00:00
return;
}
if (mName->getCaption ().empty())
{
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage10}");
2013-03-28 16:41:00 +00:00
return;
}
if (mEnchanting.soulEmpty())
{
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage52}");
2013-03-28 16:41:00 +00:00
return;
}
if (mEnchanting.itemEmpty())
{
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage11}");
return;
}
2013-05-27 18:23:04 +00:00
if (mEnchanting.getEnchantPoints() > mEnchanting.getMaxEnchantValue())
{
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage29}");
2013-03-28 16:41:00 +00:00
return;
}
mEnchanting.setNewItemName(mName->getCaption());
mEnchanting.setEffect(mEffectList);
if (mEnchanting.getEnchantPrice() > MWBase::Environment::get().getWindowManager()->getInventoryWindow()->getPlayerGold())
2013-04-02 18:46:48 +00:00
{
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage18}");
2013-04-02 18:46:48 +00:00
return;
}
2013-03-30 18:08:42 +00:00
int result = mEnchanting.create();
if(result==1)
MWBase::Environment::get().getWindowManager()->messageBox ("#{sEnchantmentMenu12}");
2013-03-30 18:08:42 +00:00
else
MWBase::Environment::get().getWindowManager()->messageBox ("#{sNotifyMessage34}");
2013-03-30 18:08:42 +00:00
MWBase::Environment::get().getWindowManager()->removeGuiMode (GM_Enchanting);
2013-03-28 16:41:00 +00:00
}
}