abstracted code and use it in enchanting window as well

actorid
scrawl 12 years ago
parent 1c0dd3ccc5
commit 025e820703

@ -7,8 +7,13 @@ namespace MWGui
EnchantingDialog::EnchantingDialog(MWBase::WindowManager &parWindowManager)
: WindowBase("openmw_enchanting_dialog.layout", parWindowManager)
, EffectEditorBase(parWindowManager)
{
getWidget(mCancelButton, "CancelButton");
getWidget(mAvailableEffectsList, "AvailableEffects");
getWidget(mUsedEffectsView, "UsedEffects");
setWidgets(mAvailableEffectsList, mUsedEffectsView);
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &EnchantingDialog::onCancelButtonClicked);
}
@ -21,6 +26,8 @@ namespace MWGui
void EnchantingDialog::startEnchanting (MWWorld::Ptr actor)
{
mPtr = actor;
startEditing ();
}
void EnchantingDialog::onReferenceUnavailable ()

@ -3,13 +3,14 @@
#include "window_base.hpp"
#include "referenceinterface.hpp"
#include "spellcreationdialog.hpp"
#include "../mwbase/windowmanager.hpp"
namespace MWGui
{
class EnchantingDialog : public WindowBase, public ReferenceInterface
class EnchantingDialog : public WindowBase, public ReferenceInterface, public EffectEditorBase
{
public:
EnchantingDialog(MWBase::WindowManager& parWindowManager);

@ -152,9 +152,7 @@ namespace MWGui
SpellCreationDialog::SpellCreationDialog(MWBase::WindowManager &parWindowManager)
: WindowBase("openmw_spellcreation_dialog.layout", parWindowManager)
, mAddEffectDialog(parWindowManager)
, mSelectAttributeDialog(NULL)
, mSelectSkillDialog(NULL)
, EffectEditorBase(parWindowManager)
{
getWidget(mNameEdit, "NameEdit");
getWidget(mMagickaCost, "MagickaCost");
@ -165,18 +163,28 @@ namespace MWGui
getWidget(mBuyButton, "BuyButton");
getWidget(mCancelButton, "CancelButton");
mAddEffectDialog.setVisible(false);
mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellCreationDialog::onCancelButtonClicked);
mBuyButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellCreationDialog::onBuyButtonClicked);
mAvailableEffectsList->eventWidgetSelected += MyGUI::newDelegate(this, &SpellCreationDialog::onAvailableEffectClicked);
setWidgets(mAvailableEffectsList, mUsedEffectsView);
}
mAddEffectDialog.eventEffectAdded += MyGUI::newDelegate(this, &SpellCreationDialog::onEffectAdded);
mAddEffectDialog.eventEffectModified += MyGUI::newDelegate(this, &SpellCreationDialog::onEffectModified);
mAddEffectDialog.eventEffectRemoved += MyGUI::newDelegate(this, &SpellCreationDialog::onEffectRemoved);
void SpellCreationDialog::startSpellMaking (MWWorld::Ptr actor)
{
mPtr = actor;
startEditing();
}
void SpellCreationDialog::onCancelButtonClicked (MyGUI::Widget* sender)
{
mWindowManager.removeGuiMode (MWGui::GM_SpellCreation);
}
void SpellCreationDialog::onBuyButtonClicked (MyGUI::Widget* sender)
{
}
void SpellCreationDialog::open()
{
@ -189,10 +197,23 @@ namespace MWGui
mWindowManager.removeGuiMode (GM_SpellCreation);
}
void SpellCreationDialog::startSpellMaking (MWWorld::Ptr actor)
// ------------------------------------------------------------------------------------------------
EffectEditorBase::EffectEditorBase(MWBase::WindowManager& parWindowManager)
: mAddEffectDialog(parWindowManager)
, mSelectAttributeDialog(NULL)
, mSelectSkillDialog(NULL)
{
mPtr = actor;
mAddEffectDialog.eventEffectAdded += MyGUI::newDelegate(this, &EffectEditorBase::onEffectAdded);
mAddEffectDialog.eventEffectModified += MyGUI::newDelegate(this, &EffectEditorBase::onEffectModified);
mAddEffectDialog.eventEffectRemoved += MyGUI::newDelegate(this, &EffectEditorBase::onEffectRemoved);
mAddEffectDialog.setVisible (false);
}
void EffectEditorBase::startEditing ()
{
// get the list of magic effects that are known to the player
MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer();
@ -237,47 +258,44 @@ namespace MWGui
ToolTips::createMagicEffectToolTip (w, *it);
}
}
void SpellCreationDialog::onCancelButtonClicked (MyGUI::Widget* sender)
{
mWindowManager.removeGuiMode (MWGui::GM_SpellCreation);
}
void SpellCreationDialog::onBuyButtonClicked (MyGUI::Widget* sender)
void EffectEditorBase::setWidgets (Widgets::MWList *availableEffectsList, MyGUI::ScrollView *usedEffectsView)
{
mAvailableEffectsList = availableEffectsList;
mUsedEffectsView = usedEffectsView;
mAvailableEffectsList->eventWidgetSelected += MyGUI::newDelegate(this, &EffectEditorBase::onAvailableEffectClicked);
}
void SpellCreationDialog::onSelectAttribute ()
void EffectEditorBase::onSelectAttribute ()
{
mAddEffectDialog.setVisible(true);
mAddEffectDialog.setAttribute (mSelectAttributeDialog->getAttributeId());
mWindowManager.removeDialog (mSelectAttributeDialog);
MWBase::Environment::get().getWindowManager ()->removeDialog (mSelectAttributeDialog);
mSelectAttributeDialog = 0;
}
void SpellCreationDialog::onSelectSkill ()
void EffectEditorBase::onSelectSkill ()
{
mAddEffectDialog.setVisible(true);
mAddEffectDialog.setSkill (mSelectSkillDialog->getSkillId ());
mWindowManager.removeDialog (mSelectSkillDialog);
MWBase::Environment::get().getWindowManager ()->removeDialog (mSelectSkillDialog);
mSelectSkillDialog = 0;
}
void SpellCreationDialog::onAttributeOrSkillCancel ()
void EffectEditorBase::onAttributeOrSkillCancel ()
{
if (mSelectSkillDialog)
mWindowManager.removeDialog (mSelectSkillDialog);
MWBase::Environment::get().getWindowManager ()->removeDialog (mSelectSkillDialog);
if (mSelectAttributeDialog)
mWindowManager.removeDialog (mSelectAttributeDialog);
MWBase::Environment::get().getWindowManager ()->removeDialog (mSelectAttributeDialog);
mSelectSkillDialog = 0;
mSelectAttributeDialog = 0;
}
void SpellCreationDialog::onAvailableEffectClicked (MyGUI::Widget* sender)
void EffectEditorBase::onAvailableEffectClicked (MyGUI::Widget* sender)
{
short effectId = *sender->getUserData<short>();
@ -288,7 +306,7 @@ namespace MWGui
if (effect->mData.mFlags & ESM::MagicEffect::TargetSkill)
{
delete mSelectSkillDialog;
mSelectSkillDialog = new SelectSkillDialog(mWindowManager);
mSelectSkillDialog = new SelectSkillDialog(*MWBase::Environment::get().getWindowManager ());
mSelectSkillDialog->eventCancel += MyGUI::newDelegate(this, &SpellCreationDialog::onAttributeOrSkillCancel);
mSelectSkillDialog->eventItemSelected += MyGUI::newDelegate(this, &SpellCreationDialog::onSelectSkill);
mSelectSkillDialog->setVisible (true);
@ -296,7 +314,7 @@ namespace MWGui
else if (effect->mData.mFlags & ESM::MagicEffect::TargetAttribute)
{
delete mSelectAttributeDialog;
mSelectAttributeDialog = new SelectAttributeDialog(mWindowManager);
mSelectAttributeDialog = new SelectAttributeDialog(*MWBase::Environment::get().getWindowManager ());
mSelectAttributeDialog->eventCancel += MyGUI::newDelegate(this, &SpellCreationDialog::onAttributeOrSkillCancel);
mSelectAttributeDialog->eventItemSelected += MyGUI::newDelegate(this, &SpellCreationDialog::onSelectAttribute);
mSelectAttributeDialog->setVisible (true);
@ -307,20 +325,20 @@ namespace MWGui
}
}
void SpellCreationDialog::onEffectModified (ESM::ENAMstruct effect)
void EffectEditorBase::onEffectModified (ESM::ENAMstruct effect)
{
mEffects[mSelectedEffect] = effect;
updateEffectsView();
}
void SpellCreationDialog::onEffectRemoved (ESM::ENAMstruct effect)
void EffectEditorBase::onEffectRemoved (ESM::ENAMstruct effect)
{
mEffects.erase(mEffects.begin() + mSelectedEffect);
updateEffectsView();
}
void SpellCreationDialog::updateEffectsView ()
void EffectEditorBase::updateEffectsView ()
{
MyGUI::EnumeratorWidgetPtr oldWidgets = mUsedEffectsView->getEnumerator ();
MyGUI::Gui::getInstance ().destroyWidgets (oldWidgets);
@ -347,7 +365,7 @@ namespace MWGui
Widgets::MWSpellEffectPtr effect = button->createWidget<Widgets::MWSpellEffect>("MW_EffectImage", MyGUI::IntCoord(0,0,0,24), MyGUI::Align::Default);
effect->setNeedMouseFocus (false);
effect->setWindowManager (&mWindowManager);
effect->setWindowManager (MWBase::Environment::get().getWindowManager ());
effect->setSpellEffect (params);
effect->setSize(effect->getRequestedWidth (), 24);
@ -361,14 +379,14 @@ namespace MWGui
mUsedEffectsView->setCanvasSize(size);
}
void SpellCreationDialog::onEffectAdded (ESM::ENAMstruct effect)
void EffectEditorBase::onEffectAdded (ESM::ENAMstruct effect)
{
mEffects.push_back(effect);
updateEffectsView();
}
void SpellCreationDialog::onEditEffect (MyGUI::Widget *sender)
void EffectEditorBase::onEditEffect (MyGUI::Widget *sender)
{
int id = *sender->getUserData<int>();

@ -67,54 +67,69 @@ namespace MWGui
ESM::ENAMstruct mEffect;
};
class SpellCreationDialog : public WindowBase, public ReferenceInterface
class EffectEditorBase
{
public:
SpellCreationDialog(MWBase::WindowManager& parWindowManager);
EffectEditorBase(MWBase::WindowManager& parWindowManager);
virtual void open();
void startSpellMaking(MWWorld::Ptr actor);
protected:
virtual void onReferenceUnavailable ();
Widgets::MWList* mAvailableEffectsList;
MyGUI::ScrollView* mUsedEffectsView;
EditEffectDialog mAddEffectDialog;
SelectAttributeDialog* mSelectAttributeDialog;
SelectSkillDialog* mSelectSkillDialog;
int mSelectedEffect;
std::vector<ESM::ENAMstruct> mEffects;
void onEffectAdded(ESM::ENAMstruct effect);
void onEffectModified(ESM::ENAMstruct effect);
void onEffectRemoved(ESM::ENAMstruct effect);
void onCancelButtonClicked (MyGUI::Widget* sender);
void onBuyButtonClicked (MyGUI::Widget* sender);
void onAvailableEffectClicked (MyGUI::Widget* sender);
void onAttributeOrSkillCancel();
void onSelectAttribute();
void onSelectSkill();
void onEffectAdded(ESM::ENAMstruct effect);
void onEffectModified(ESM::ENAMstruct effect);
void onEffectRemoved(ESM::ENAMstruct effect);
void onEditEffect(MyGUI::Widget* sender);
void updateEffectsView();
void onEditEffect(MyGUI::Widget* sender);
void startEditing();
void setWidgets (Widgets::MWList* availableEffectsList, MyGUI::ScrollView* usedEffectsView);
};
class SpellCreationDialog : public WindowBase, public ReferenceInterface, public EffectEditorBase
{
public:
SpellCreationDialog(MWBase::WindowManager& parWindowManager);
virtual void open();
void startSpellMaking(MWWorld::Ptr actor);
protected:
virtual void onReferenceUnavailable ();
void onCancelButtonClicked (MyGUI::Widget* sender);
void onBuyButtonClicked (MyGUI::Widget* sender);
MyGUI::EditBox* mNameEdit;
MyGUI::TextBox* mMagickaCost;
MyGUI::TextBox* mSuccessChance;
Widgets::MWList* mAvailableEffectsList;
MyGUI::ScrollView* mUsedEffectsView;
MyGUI::Button* mBuyButton;
MyGUI::Button* mCancelButton;
MyGUI::TextBox* mPriceLabel;
int mSelectedEffect;
EditEffectDialog mAddEffectDialog;
SelectAttributeDialog* mSelectAttributeDialog;
SelectSkillDialog* mSelectSkillDialog;
Widgets::MWEffectList* mUsedEffectsList;
std::vector<ESM::ENAMstruct> mEffects;
};
}

@ -77,7 +77,8 @@
<Property key="Caption" value="#{sEffects}"/>
</Widget>
<Widget type="Widget" skin="MW_Box" position="226 176 316 169">
<Widget type="ScrollView" skin="MW_ScrollView" position="4 4 308 161" name="UsedEffects">
<Widget type="ScrollView" skin="MW_ScrollViewH" position="4 4 308 161" name="UsedEffects">
<Property key="CanvasAlign" value="Left Top"/>
</Widget>
</Widget>

Loading…
Cancel
Save