change the select attribute/skill dialogs to be reusable

actorid
scrawl 12 years ago
parent d393f551ed
commit b63d205c6e

@ -565,7 +565,7 @@ void CreateClassDialog::onAttributeClicked(Widgets::MWAttributePtr _sender)
{
delete mAttribDialog;
mAttribDialog = new SelectAttributeDialog(mWindowManager);
mAttribDialog->setAffectedWidget(_sender);
mAffectedAttribute = _sender;
mAttribDialog->eventCancel += MyGUI::newDelegate(this, &CreateClassDialog::onDialogCancel);
mAttribDialog->eventItemSelected += MyGUI::newDelegate(this, &CreateClassDialog::onAttributeSelected);
mAttribDialog->setVisible(true);
@ -574,18 +574,17 @@ void CreateClassDialog::onAttributeClicked(Widgets::MWAttributePtr _sender)
void CreateClassDialog::onAttributeSelected()
{
ESM::Attribute::AttributeID id = mAttribDialog->getAttributeId();
Widgets::MWAttributePtr attribute = mAttribDialog->getAffectedWidget();
if (attribute == mFavoriteAttribute0)
if (mAffectedAttribute == mFavoriteAttribute0)
{
if (mFavoriteAttribute1->getAttributeId() == id)
mFavoriteAttribute1->setAttributeId(mFavoriteAttribute0->getAttributeId());
}
else if (attribute == mFavoriteAttribute1)
else if (mAffectedAttribute == mFavoriteAttribute1)
{
if (mFavoriteAttribute0->getAttributeId() == id)
mFavoriteAttribute0->setAttributeId(mFavoriteAttribute1->getAttributeId());
}
attribute->setAttributeId(id);
mAffectedAttribute->setAttributeId(id);
mWindowManager.removeDialog(mAttribDialog);
mAttribDialog = 0;
@ -596,7 +595,7 @@ void CreateClassDialog::onSkillClicked(Widgets::MWSkillPtr _sender)
{
delete mSkillDialog;
mSkillDialog = new SelectSkillDialog(mWindowManager);
mSkillDialog->setAffectedWidget(_sender);
mAffectedSkill = _sender;
mSkillDialog->eventCancel += MyGUI::newDelegate(this, &CreateClassDialog::onDialogCancel);
mSkillDialog->eventItemSelected += MyGUI::newDelegate(this, &CreateClassDialog::onSkillSelected);
mSkillDialog->setVisible(true);
@ -605,22 +604,21 @@ void CreateClassDialog::onSkillClicked(Widgets::MWSkillPtr _sender)
void CreateClassDialog::onSkillSelected()
{
ESM::Skill::SkillEnum id = mSkillDialog->getSkillId();
Widgets::MWSkillPtr skill = mSkillDialog->getAffectedWidget();
// Avoid duplicate skills by swapping any skill field that matches the selected one
std::vector<Widgets::MWSkillPtr>::const_iterator end = mSkills.end();
for (std::vector<Widgets::MWSkillPtr>::const_iterator it = mSkills.begin(); it != end; ++it)
{
if (*it == skill)
if (*it == mAffectedSkill)
continue;
if ((*it)->getSkillId() == id)
{
(*it)->setSkillId(skill->getSkillId());
(*it)->setSkillId(mAffectedSkill->getSkillId());
break;
}
}
skill->setSkillId(mSkillDialog->getSkillId());
mAffectedSkill->setSkillId(mSkillDialog->getSkillId());
mWindowManager.removeDialog(mSkillDialog);
mSkillDialog = 0;
update();

@ -167,8 +167,6 @@ namespace MWGui
~SelectAttributeDialog();
ESM::Attribute::AttributeID getAttributeId() const { return mAttributeId; }
Widgets::MWAttributePtr getAffectedWidget() const { return mAffectedWidget; }
void setAffectedWidget(Widgets::MWAttributePtr widget) { mAffectedWidget = widget; }
// Events
typedef MyGUI::delegates::CMultiDelegate0 EventHandle_Void;
@ -188,8 +186,6 @@ namespace MWGui
void onCancelClicked(MyGUI::Widget* _sender);
private:
Widgets::MWAttributePtr mAffectedWidget;
ESM::Attribute::AttributeID mAttributeId;
};
@ -200,8 +196,6 @@ namespace MWGui
~SelectSkillDialog();
ESM::Skill::SkillEnum getSkillId() const { return mSkillId; }
Widgets::MWSkillPtr getAffectedWidget() const { return mAffectedWidget; }
void setAffectedWidget(Widgets::MWSkillPtr widget) { mAffectedWidget = widget; }
// Events
typedef MyGUI::delegates::CMultiDelegate0 EventHandle_Void;
@ -224,7 +218,6 @@ namespace MWGui
Widgets::MWSkillPtr mCombatSkill[9];
Widgets::MWSkillPtr mMagicSkill[9];
Widgets::MWSkillPtr mStealthSkill[9];
Widgets::MWSkillPtr mAffectedWidget;
ESM::Skill::SkillEnum mSkillId;
};
@ -301,6 +294,9 @@ namespace MWGui
DescriptionDialog *mDescDialog;
ESM::Class::Specialization mSpecializationId;
Widgets::MWAttributePtr mAffectedAttribute;
Widgets::MWSkillPtr mAffectedSkill;
};
}
#endif

@ -31,7 +31,6 @@ namespace MWGui
EditEffectDialog::EditEffectDialog(MWBase::WindowManager &parWindowManager)
: WindowModal("openmw_edit_effect.layout", parWindowManager)
, mRange(ESM::RT_Touch)
{
getWidget(mCancelButton, "CancelButton");
getWidget(mOkButton, "OkButton");
@ -59,6 +58,10 @@ namespace MWGui
{
WindowModal::open();
center();
mEffect.range = ESM::RT_Self;
onRangeButtonClicked(mRangeButton);
}
void EditEffectDialog::setEffect (const ESM::MagicEffect *effect)
@ -76,17 +79,17 @@ namespace MWGui
void EditEffectDialog::onRangeButtonClicked (MyGUI::Widget* sender)
{
mRange = (mRange+1)%3;
mEffect.range = (mEffect.range+1)%3;
if (mRange == ESM::RT_Self)
if (mEffect.range == ESM::RT_Self)
mRangeButton->setCaptionWithReplacing ("#{sRangeSelf}");
else if (mRange == ESM::RT_Target)
else if (mEffect.range == ESM::RT_Target)
mRangeButton->setCaptionWithReplacing ("#{sRangeTarget}");
else if (mRange == ESM::RT_Touch)
else if (mEffect.range == ESM::RT_Touch)
mRangeButton->setCaptionWithReplacing ("#{sRangeTouch}");
mAreaSlider->setVisible (mRange != ESM::RT_Self);
mAreaText->setVisible (mRange != ESM::RT_Self);
mAreaSlider->setVisible (mEffect.range != ESM::RT_Self);
mAreaText->setVisible (mEffect.range != ESM::RT_Self);
}
void EditEffectDialog::onDeleteButtonClicked (MyGUI::Widget* sender)
@ -109,6 +112,8 @@ namespace MWGui
SpellCreationDialog::SpellCreationDialog(MWBase::WindowManager &parWindowManager)
: WindowBase("openmw_spellcreation_dialog.layout", parWindowManager)
, mAddEffectDialog(parWindowManager)
, mSelectAttributeDialog(NULL)
, mSelectSkillDialog(NULL)
{
getWidget(mNameEdit, "NameEdit");
getWidget(mMagickaCost, "MagickaCost");
@ -202,10 +207,12 @@ namespace MWGui
void SpellCreationDialog::onAvailableEffectClicked (MyGUI::Widget* sender)
{
mAddEffectDialog.setVisible(true);
short effectId = *sender->getUserData<short>();
const ESM::MagicEffect* effect = MWBase::Environment::get().getWorld()->getStore().magicEffects.find(effectId);
mAddEffectDialog.setVisible(true);
mAddEffectDialog.setEffect (effect);
}

@ -8,6 +8,9 @@
namespace MWGui
{
class SelectSkillDialog;
class SelectAttributeDialog;
class EditEffectDialog : public WindowModal
{
public:
@ -34,7 +37,7 @@ namespace MWGui
MyGUI::ScrollBar* mDurationSlider;
MyGUI::ScrollBar* mAreaSlider;
MyGUI::ScrollBar* mAreaText;
MyGUI::TextBox* mAreaText;
MyGUI::ImageBox* mEffectImage;
MyGUI::TextBox* mEffectName;
@ -46,7 +49,7 @@ namespace MWGui
void onCancelButtonClicked (MyGUI::Widget* sender);
protected:
int mRange;
ESM::ENAMstruct mEffect;
};
class SpellCreationDialog : public WindowBase, public ReferenceInterface
@ -77,6 +80,9 @@ namespace MWGui
EditEffectDialog mAddEffectDialog;
SelectAttributeDialog* mSelectAttributeDialog;
SelectSkillDialog* mSelectSkillDialog;
};
}

@ -250,10 +250,12 @@ namespace MWGui
void setSpellEffect(const SpellEffectParams& params);
static std::string effectIDToString(const short effectID);
bool effectHasMagnitude (const std::string& effect);
bool effectHasDuration (const std::string& effect);
bool effectInvolvesAttribute (const std::string& effect);
bool effectInvolvesSkill (const std::string& effect);
/// \todo Remove all of these! The information can be obtained via the ESM::MagicEffect's flags!
static bool effectHasMagnitude (const std::string& effect);
static bool effectHasDuration (const std::string& effect);
static bool effectInvolvesAttribute (const std::string& effect);
static bool effectInvolvesSkill (const std::string& effect);
int getRequestedWidth() const { return mRequestedWidth; }

Loading…
Cancel
Save