From 025e820703344ea3cd7a57cc278d4fc2e42f1586 Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 3 Oct 2012 15:36:10 +0200 Subject: [PATCH] abstracted code and use it in enchanting window as well --- apps/openmw/mwgui/enchantingdialog.cpp | 7 ++ apps/openmw/mwgui/enchantingdialog.hpp | 3 +- apps/openmw/mwgui/spellcreationdialog.cpp | 86 +++++++++++++-------- apps/openmw/mwgui/spellcreationdialog.hpp | 61 +++++++++------ files/mygui/openmw_enchanting_dialog.layout | 3 +- 5 files changed, 101 insertions(+), 59 deletions(-) diff --git a/apps/openmw/mwgui/enchantingdialog.cpp b/apps/openmw/mwgui/enchantingdialog.cpp index b3e785fd9..3bd67ade6 100644 --- a/apps/openmw/mwgui/enchantingdialog.cpp +++ b/apps/openmw/mwgui/enchantingdialog.cpp @@ -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 () diff --git a/apps/openmw/mwgui/enchantingdialog.hpp b/apps/openmw/mwgui/enchantingdialog.hpp index 663758b02..0415c9d8d 100644 --- a/apps/openmw/mwgui/enchantingdialog.hpp +++ b/apps/openmw/mwgui/enchantingdialog.hpp @@ -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); diff --git a/apps/openmw/mwgui/spellcreationdialog.cpp b/apps/openmw/mwgui/spellcreationdialog.cpp index c10295ad1..4e1c334db 100644 --- a/apps/openmw/mwgui/spellcreationdialog.cpp +++ b/apps/openmw/mwgui/spellcreationdialog.cpp @@ -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(); @@ -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("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(); diff --git a/apps/openmw/mwgui/spellcreationdialog.hpp b/apps/openmw/mwgui/spellcreationdialog.hpp index 73c940412..c5fffeb63 100644 --- a/apps/openmw/mwgui/spellcreationdialog.hpp +++ b/apps/openmw/mwgui/spellcreationdialog.hpp @@ -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 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 mEffects; - }; } diff --git a/files/mygui/openmw_enchanting_dialog.layout b/files/mygui/openmw_enchanting_dialog.layout index e3c8a8b18..a19c56925 100644 --- a/files/mygui/openmw_enchanting_dialog.layout +++ b/files/mygui/openmw_enchanting_dialog.layout @@ -77,7 +77,8 @@ - + +