From ebf80943a974c393f321ad1701d0996d3a18fd53 Mon Sep 17 00:00:00 2001 From: Adam Hogan Date: Sat, 8 Sep 2012 18:17:03 -0400 Subject: [PATCH 1/9] Added spell buying window --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwbase/windowmanager.hpp | 2 + apps/openmw/mwdialogue/dialoguemanagerimp.cpp | 5 + apps/openmw/mwgui/dialogue.cpp | 12 +- apps/openmw/mwgui/dialogue.hpp | 2 + apps/openmw/mwgui/mode.hpp | 1 + apps/openmw/mwgui/spellswindow.cpp | 269 ++++++++++++++++++ apps/openmw/mwgui/spellswindow.hpp | 70 +++++ apps/openmw/mwgui/tradewindow.cpp | 51 ++-- apps/openmw/mwgui/tradewindow.hpp | 2 + apps/openmw/mwgui/windowmanagerimp.cpp | 10 + apps/openmw/mwgui/windowmanagerimp.hpp | 4 +- extern/shiny | 2 +- files/mygui/CMakeLists.txt | 1 + files/mygui/openmw_spells_window.layout | 33 +++ 15 files changed, 439 insertions(+), 27 deletions(-) create mode 100644 apps/openmw/mwgui/spellswindow.cpp create mode 100644 apps/openmw/mwgui/spellswindow.hpp create mode 100644 files/mygui/openmw_spells_window.layout diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index a64ab1ed4..77b25e0c1 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -29,7 +29,7 @@ add_openmw_dir (mwgui map_window window_pinnable_base cursorreplace tooltips scrollwindow bookwindow list formatting inventorywindow container hud countdialog tradewindow settingswindow confirmationdialog alchemywindow referenceinterface spellwindow mainmenu quickkeysmenu - itemselection + itemselection spellswindow ) add_openmw_dir (mwdialogue diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index 389f816dc..99f1e46d2 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -42,6 +42,7 @@ namespace MWGui class Console; class SpellWindow; class TradeWindow; + class SpellsWindow; class ConfirmationDialog; class CountDialog; class ScrollWindow; @@ -106,6 +107,7 @@ namespace MWBase virtual MWGui::CountDialog* getCountDialog() = 0; virtual MWGui::ConfirmationDialog* getConfirmationDialog() = 0; virtual MWGui::TradeWindow* getTradeWindow() = 0; + virtual MWGui::SpellsWindow* getSpellsWindow() = 0; virtual MWGui::SpellWindow* getSpellWindow() = 0; virtual MWGui::Console* getConsole() = 0; diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index 841e36bf4..1b7532d0a 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -794,6 +794,11 @@ namespace MWDialogue else win->setShowTrade(false); + if (services & ESM::NPC::Spells) + win->setShowSpells(true); + else + win->setShowSpells(false); + // sort again, because the previous sort was case-sensitive keywordList.sort(stringCompareNoCase); win->setKeywords(keywordList); diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 4342b1130..949e745f2 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -17,6 +17,7 @@ #include "widgets.hpp" #include "list.hpp" #include "tradewindow.hpp" +#include "spellswindow.hpp" #include "inventorywindow.hpp" using namespace MWGui; @@ -46,6 +47,7 @@ DialogueWindow::DialogueWindow(MWBase::WindowManager& parWindowManager) : WindowBase("openmw_dialogue_window.layout", parWindowManager) , mEnabled(true) , mShowTrade(false) + , mShowSpells(false) { // Centre dialog center(); @@ -127,6 +129,11 @@ void DialogueWindow::onSelectTopic(std::string topic) mWindowManager.pushGuiMode(GM_Barter); mWindowManager.getTradeWindow()->startTrade(mPtr); } + else if (topic == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sSpells")->str) + { + mWindowManager.pushGuiMode(GM_Spells); + mWindowManager.getSpellsWindow()->startSpells(mPtr); + } else MWBase::Environment::get().getDialogueManager()->keywordSelected(lower_string(topic)); @@ -148,11 +155,14 @@ void DialogueWindow::setKeywords(std::list keyWords) { mTopicsList->clear(); - bool anyService = mShowTrade; + bool anyService = mShowTrade||mShowSpells; if (mShowTrade) mTopicsList->addItem(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sBarter")->str); + if (mShowSpells) + mTopicsList->addItem(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sSpells")->str); + if (anyService) mTopicsList->addSeparator(); diff --git a/apps/openmw/mwgui/dialogue.hpp b/apps/openmw/mwgui/dialogue.hpp index e7f2b076c..a43b0d5a7 100644 --- a/apps/openmw/mwgui/dialogue.hpp +++ b/apps/openmw/mwgui/dialogue.hpp @@ -51,6 +51,7 @@ namespace MWGui // various service button visibilities, depending if the npc/creature talked to has these services // make sure to call these before setKeywords() void setShowTrade(bool show) { mShowTrade = show; } + void setShowSpells(bool show) { mShowSpells = show; } protected: void onSelectTopic(std::string topic); @@ -70,6 +71,7 @@ namespace MWGui // various service button visibilities, depending if the npc/creature talked to has these services bool mShowTrade; + bool mShowSpells; bool mEnabled; diff --git a/apps/openmw/mwgui/mode.hpp b/apps/openmw/mwgui/mode.hpp index 2d6f69871..8c0a2fc5f 100644 --- a/apps/openmw/mwgui/mode.hpp +++ b/apps/openmw/mwgui/mode.hpp @@ -20,6 +20,7 @@ namespace MWGui GM_Dialogue, // NPC interaction GM_Barter, GM_Rest, + GM_Spells, // Startup character creation dialogs GM_Name, diff --git a/apps/openmw/mwgui/spellswindow.cpp b/apps/openmw/mwgui/spellswindow.cpp new file mode 100644 index 000000000..5e1797823 --- /dev/null +++ b/apps/openmw/mwgui/spellswindow.cpp @@ -0,0 +1,269 @@ +#include "spellswindow.hpp" + +#include + +#include "../mwbase/environment.hpp" +#include "../mwbase/world.hpp" +#include "../mwbase/soundmanager.hpp" +#include "../mwbase/windowmanager.hpp" + +#include "../mwworld/player.hpp" +#include "../mwworld/manualref.hpp" + +#include "../mwmechanics/spells.hpp" +#include "../mwmechanics/creaturestats.hpp" + +#include "inventorywindow.hpp" +#include "tradewindow.hpp" + +namespace MWGui +{ + const int SpellsWindow::sLineHeight = 18; + + SpellsWindow::SpellsWindow(MWBase::WindowManager& parWindowManager) : + WindowBase("openmw_spells_window.layout", parWindowManager) + , ContainerBase(NULL) // no drag&drop + , mSpellsWidgetMap() + , mCurrentY(0) + , mLastPos(0) + , mSpellsWidgets() + , mSpellsPriceMap() + { + setCoord(0, 0, 450, 300); + center(); + + getWidget(mCancelButton, "CancelButton"); + getWidget(mPlayerGold, "PlayerGold"); + getWidget(mSelect, "Select"); + getWidget(mSpells, "Spells"); + getWidget(mSpellsBoxWidget, "SpellsBox"); + getWidget(mSpellsClientWidget, "SpellsClient"); + getWidget(mSpellsScrollerWidget, "SpellsScroller"); + + mSpellsClientWidget->eventMouseWheel += MyGUI::newDelegate(this, &SpellsWindow::onMouseWheel); + + mSpellsScrollerWidget->eventScrollChangePosition += MyGUI::newDelegate(this, &SpellsWindow::onScrollChangePosition); + + mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellsWindow::onCancelButtonClicked); + + int cancelButtonWidth = mCancelButton->getTextSize().width + 24; + mCancelButton->setCoord(430-cancelButtonWidth, + mCancelButton->getTop(), + cancelButtonWidth, + mCancelButton->getHeight()); + mSpells->setCoord(450/2-mSpells->getTextSize().width/2, + mSpells->getTop(), + mSpells->getTextSize().width, + mSpells->getHeight()); + mSelect->setCoord(8, + mSelect->getTop(), + mSelect->getTextSize().width, + mSelect->getHeight()); + + static_cast(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &SpellsWindow::onWindowResize); + } + + void SpellsWindow::addSpell(std::string spellID) + { + MyGUI::Button* toAdd; + + toAdd = mSpellsClientWidget->createWidget("SandText", 0, mCurrentY, 200, sLineHeight, MyGUI::Align::Default); + mCurrentY += sLineHeight; + const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().spells.find(spellID); + /// \todo price adjustment depending on merchantile skill + int price = spell->data.cost*MWBase::Environment::get().getWorld()->getStore().gameSettings.search("fSpellValueMult")->f; + mSpellsPriceMap.insert(std::pair(spell,price)); + if (price>mWindowManager.getInventoryWindow()->getPlayerGold()) + toAdd->setCaption("#A3997B" + spell->name+" - "+boost::lexical_cast(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str); + else + toAdd->setCaption(spell->name+" - "+boost::lexical_cast(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str); + toAdd->setSize(toAdd->getTextSize().width,sLineHeight); + toAdd->eventMouseWheel += MyGUI::newDelegate(this, &SpellsWindow::onMouseWheel); + toAdd->setUserString("ToolTipType", "Spell"); + toAdd->setUserString("Spell", spellID); + toAdd->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellsWindow::onSpellButtonClick); + toAdd->eventMouseSetFocus += MyGUI::newDelegate(this, &SpellsWindow::onFocus); + toAdd->eventMouseLostFocus += MyGUI::newDelegate(this, &SpellsWindow::onFocusLost); + mSpellsWidgets.push_back(toAdd); + mSpellsWidgetMap.insert(std::pair(toAdd,spell)); + } + + void SpellsWindow::onFocusLost(MyGUI::Widget* _sender, MyGUI::Widget* _old) + { + updateLabels(); + } + + void SpellsWindow::onFocus(MyGUI::Widget* _sender, MyGUI::Widget* _old) + { + updateLabels(); + MyGUI::Button* toUpdate; + toUpdate = (MyGUI::Button*) _sender; + const ESM::Spell* spell = mSpellsWidgetMap.find(toUpdate)->second; + int price = mSpellsPriceMap.find(spell)->second; + if (price>mWindowManager.getInventoryWindow()->getPlayerGold()) + toUpdate->setCaption("#A3997B" + spell->name+" - "+boost::lexical_cast(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str); + else + toUpdate->setCaption("#D8C09A" + spell->name+" - "+boost::lexical_cast(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str); + } + + void SpellsWindow::clearSpells() + { + mSpellsScrollerWidget->setScrollPosition(0); + onScrollChangePosition(mSpellsScrollerWidget, mSpellsScrollerWidget->getScrollPosition()); + mCurrentY = 0; + mSpellsWidgets.clear(); + while (mSpellsClientWidget->getChildCount()!=0) + { + MyGUI::Widget* toRemove; + toRemove = mSpellsClientWidget->getChildAt(0); + mSpellsClientWidget->_destroyChildWidget(toRemove); + } + mSpellsWidgetMap.clear(); + mSpellsPriceMap.clear(); + } + + void SpellsWindow::startSpells(MWWorld::Ptr actor) + { + clearSpells(); + + if (actor.getTypeName() == typeid(ESM::NPC).name()) + { + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); + MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); + MWMechanics::Spells& playerSpells = stats.getSpells(); + std::vector spellList = actor.get()->base->spells.list; + for (std::vector::const_iterator it = spellList.begin(); it != spellList.end(); ++it) + { + bool alreadyHave = false; + for (std::vector::const_iterator it2 = playerSpells.begin(); it2 != playerSpells.end(); ++it2) + { + std::string spellname1 = MWBase::Environment::get().getWorld()->getStore().spells.find(*it)->name; + std::string spellname2 = MWBase::Environment::get().getWorld()->getStore().spells.find(*it2)->name; + if (spellname1.compare(spellname2)==0) + alreadyHave = true; + } + if (alreadyHave==false) + addSpell(*it); + } + } + updateLabels(); + updateScroller(); + } + + void SpellsWindow::onSpellButtonClick(MyGUI::Widget* _sender) + { + const ESM::Spell* spell = mSpellsWidgetMap.find(_sender)->second; + int price = mSpellsPriceMap.find(spell)->second; + + if (mWindowManager.getInventoryWindow()->getPlayerGold()>=price) + { + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); + MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); + MWMechanics::Spells& spells = stats.getSpells(); + spells.add(spell->name); + mWindowManager.getTradeWindow()->addOrRemoveGold(-price); + mSpellsWidgetMap.erase(_sender); + mSpellsPriceMap.erase(spell); + for (std::vector::iterator it = mSpellsWidgets.begin(); it != mSpellsWidgets.end(); ++it) + { + if (*it==_sender) + { + mSpellsWidgets.erase(it); + break; + } + } + mSpellsClientWidget->_destroyChildWidget(_sender); + unsigned int i; + mSpellsScrollerWidget->setScrollPosition(0); + onScrollChangePosition(mSpellsScrollerWidget, mSpellsScrollerWidget->getScrollPosition()); + mCurrentY = 0; + for (i=0;igetChildCount();i++) + { + MyGUI::Widget* toMove; + toMove = mSpellsClientWidget->getChildAt(i); + toMove->setPosition(0,mCurrentY); + mCurrentY+=sLineHeight; + } + } + else + { + + } + updateLabels(); + updateScroller(); + } + + void SpellsWindow::onWindowResize(MyGUI::Window* _sender) + { + + } + + void SpellsWindow::onCancelButtonClicked(MyGUI::Widget* _sender) + { + mWindowManager.removeGuiMode(GM_Spells); + } + + void SpellsWindow::updateLabels() + { + mPlayerGold->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str + + ": " + boost::lexical_cast(mWindowManager.getInventoryWindow()->getPlayerGold())); + mPlayerGold->setCoord(8, + mPlayerGold->getTop(), + mPlayerGold->getTextSize().width, + mPlayerGold->getHeight()); + unsigned int i; + for (i=0;igetChildCount();i++) + { + MyGUI::Button* toUpdate; + toUpdate = (MyGUI::Button*) mSpellsClientWidget->getChildAt(i); + const ESM::Spell* spell = mSpellsWidgetMap.find(toUpdate)->second; + int price = mSpellsPriceMap.find(spell)->second; + if (price>mWindowManager.getInventoryWindow()->getPlayerGold()) + toUpdate->setCaption("#A3997B" + spell->name+" - "+boost::lexical_cast(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str); + else + toUpdate->setCaption(spell->name+" - "+boost::lexical_cast(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str); + } + } + + void SpellsWindow::onReferenceUnavailable() + { + // remove both Spells and Dialogue (since you always trade with the NPC/creature that you have previously talked to) + mWindowManager.removeGuiMode(GM_Spells); + mWindowManager.removeGuiMode(GM_Dialogue); + } + + void SpellsWindow::updateScroller() + { + mSpellsScrollerWidget->setScrollRange(std::max(mCurrentY - mSpellsClientWidget->getHeight(), 0)); + mSpellsScrollerWidget->setScrollPage(std::max(mSpellsClientWidget->getHeight() - sLineHeight, 0)); + if (mCurrentY != 0) + mSpellsScrollerWidget->setTrackSize( (mSpellsBoxWidget->getHeight() / float(mCurrentY)) * mSpellsScrollerWidget->getLineSize() ); + } + + void SpellsWindow::onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos) + { + int diff = mLastPos - pos; + // Adjust position of all widget according to difference + if (diff == 0) + return; + mLastPos = pos; + + std::vector::const_iterator end = mSpellsWidgets.end(); + for (std::vector::const_iterator it = mSpellsWidgets.begin(); it != end; ++it) + { + (*it)->setCoord((*it)->getCoord() + MyGUI::IntPoint(0, diff)); + } + } + + void SpellsWindow::onMouseWheel(MyGUI::Widget* _sender, int _rel) + { + if (mSpellsScrollerWidget->getScrollPosition() - _rel*0.3 < 0) + mSpellsScrollerWidget->setScrollPosition(0); + else if (mSpellsScrollerWidget->getScrollPosition() - _rel*0.3 > mSpellsScrollerWidget->getScrollRange()-1) + mSpellsScrollerWidget->setScrollPosition(mSpellsScrollerWidget->getScrollRange()-1); + else + mSpellsScrollerWidget->setScrollPosition(mSpellsScrollerWidget->getScrollPosition() - _rel*0.3); + + onScrollChangePosition(mSpellsScrollerWidget, mSpellsScrollerWidget->getScrollPosition()); + } +} diff --git a/apps/openmw/mwgui/spellswindow.hpp b/apps/openmw/mwgui/spellswindow.hpp new file mode 100644 index 000000000..4bc073d14 --- /dev/null +++ b/apps/openmw/mwgui/spellswindow.hpp @@ -0,0 +1,70 @@ +#ifndef MWGUI_SPELLSWINDOW_H +#define MWGUI_SPELLSWINDOW_H + +#include "container.hpp" +#include "window_base.hpp" + +#include "../mwworld/ptr.hpp" + +namespace MyGUI +{ + class Gui; + class Widget; +} + +namespace MWGui +{ + class WindowManager; +} + + +namespace MWGui +{ + class SpellsWindow : public ContainerBase, public WindowBase + { + public: + SpellsWindow(MWBase::WindowManager& parWindowManager); + + void startSpells(MWWorld::Ptr actor); + + protected: + MyGUI::Button* mCancelButton; + MyGUI::TextBox* mPlayerGold; + MyGUI::TextBox* mSpells; + MyGUI::TextBox* mSelect; + + MyGUI::WidgetPtr mSpellsBoxWidget, mSpellsClientWidget; + MyGUI::ScrollBar* mSpellsScrollerWidget; + + std::map mSpellsWidgetMap; + std::map mSpellsPriceMap; + std::vector mSpellsWidgets; + + void onWindowResize(MyGUI::Window* _sender); + void onFilterChanged(MyGUI::Widget* _sender); + void onCancelButtonClicked(MyGUI::Widget* _sender); + void onFocus(MyGUI::Widget* _sender, MyGUI::Widget* _old); + void onFocusLost(MyGUI::Widget* _sender, MyGUI::Widget* _old); + void onSpellButtonClick(MyGUI::Widget* _sender); + void addSpell(std::string spellID); + void clearSpells(); + void updateScroller(); + void onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos); + void onMouseWheel(MyGUI::Widget* _sender, int _rel); + int mLastPos,mCurrentY; + + static const int sLineHeight; + + // don't show items that the NPC has equipped in his trade-window. + virtual bool ignoreEquippedItems() { return true; } + + virtual bool isTrading() { return true; } + virtual bool isTradeWindow() { return true; } + + void updateLabels(); + + virtual void onReferenceUnavailable(); + }; +} + +#endif diff --git a/apps/openmw/mwgui/tradewindow.cpp b/apps/openmw/mwgui/tradewindow.cpp index 9abd97bb7..dc6c650ac 100644 --- a/apps/openmw/mwgui/tradewindow.cpp +++ b/apps/openmw/mwgui/tradewindow.cpp @@ -136,6 +136,33 @@ namespace MWGui drawItems(); } + void TradeWindow::addOrRemoveGold(int amount) + { + bool goldFound = false; + MWWorld::Ptr gold; + MWWorld::ContainerStore& playerStore = mWindowManager.getInventoryWindow()->getContainerStore(); + for (MWWorld::ContainerStoreIterator it = playerStore.begin(); + it != playerStore.end(); ++it) + { + if (MWWorld::Class::get(*it).getName(*it) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str) + { + goldFound = true; + gold = *it; + } + } + if (goldFound) + { + gold.getRefData().setCount(gold.getRefData().getCount() + amount); + } + else + { + assert(amount > 0); + MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), "Gold_001"); + ref.getPtr().getRefData().setCount(amount); + playerStore.add(ref.getPtr()); + } + } + void TradeWindow::onOfferButtonClicked(MyGUI::Widget* _sender) { // were there any items traded at all? @@ -186,29 +213,7 @@ namespace MWGui mWindowManager.getInventoryWindow()->transferBoughtItems(); // add or remove gold from the player. - bool goldFound = false; - MWWorld::Ptr gold; - MWWorld::ContainerStore& playerStore = mWindowManager.getInventoryWindow()->getContainerStore(); - for (MWWorld::ContainerStoreIterator it = playerStore.begin(); - it != playerStore.end(); ++it) - { - if (MWWorld::Class::get(*it).getName(*it) == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str) - { - goldFound = true; - gold = *it; - } - } - if (goldFound) - { - gold.getRefData().setCount(gold.getRefData().getCount() + mCurrentBalance); - } - else - { - assert(mCurrentBalance > 0); - MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), "Gold_001"); - ref.getPtr().getRefData().setCount(mCurrentBalance); - playerStore.add(ref.getPtr()); - } + addOrRemoveGold(mCurrentBalance); std::string sound = "Item Gold Up"; MWBase::Environment::get().getSoundManager()->playSound (sound, 1.0, 1.0); diff --git a/apps/openmw/mwgui/tradewindow.hpp b/apps/openmw/mwgui/tradewindow.hpp index 1daeefa96..4ec55045c 100644 --- a/apps/openmw/mwgui/tradewindow.hpp +++ b/apps/openmw/mwgui/tradewindow.hpp @@ -32,6 +32,8 @@ namespace MWGui bool npcAcceptsItem(MWWorld::Ptr item); + void addOrRemoveGold(int gold); + protected: MyGUI::Button* mFilterAll; MyGUI::Button* mFilterWeapon; diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index faaa41783..012a0e127 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -37,6 +37,7 @@ #include "mainmenu.hpp" #include "countdialog.hpp" #include "tradewindow.hpp" +#include "spellswindow.hpp" #include "settingswindow.hpp" #include "confirmationdialog.hpp" #include "alchemywindow.hpp" @@ -61,6 +62,7 @@ WindowManager::WindowManager( , mScrollWindow(NULL) , mCountDialog(NULL) , mTradeWindow(NULL) + , mSpellsWindow(NULL) , mSettingsWindow(NULL) , mConfirmationDialog(NULL) , mAlchemyWindow(NULL) @@ -126,6 +128,7 @@ WindowManager::WindowManager( mMessageBoxManager = new MessageBoxManager(this); mInventoryWindow = new InventoryWindow(*this,mDragAndDrop); mTradeWindow = new TradeWindow(*this); + mSpellsWindow = new SpellsWindow(*this); mDialogueWindow = new DialogueWindow(*this); mContainerWindow = new ContainerWindow(*this,mDragAndDrop); mHud = new HUD(w,h, mShowFPSLevel, mDragAndDrop); @@ -182,6 +185,7 @@ WindowManager::~WindowManager() delete mBookWindow; delete mScrollWindow; delete mTradeWindow; + delete mSpellsWindow; delete mSettingsWindow; delete mConfirmationDialog; delete mAlchemyWindow; @@ -228,6 +232,7 @@ void WindowManager::updateVisible() mScrollWindow->setVisible(false); mBookWindow->setVisible(false); mTradeWindow->setVisible(false); + mSpellsWindow->setVisible(false); mSettingsWindow->setVisible(false); mAlchemyWindow->setVisible(false); mSpellWindow->setVisible(false); @@ -317,6 +322,9 @@ void WindowManager::updateVisible() mInventoryWindow->setVisible(true); mTradeWindow->setVisible(true); break; + case GM_Spells: + mSpellsWindow->setVisible(true); + break; case GM_InterMessageBox: break; case GM_Journal: @@ -509,6 +517,7 @@ void WindowManager::onFrame (float frameDuration) mDialogueWindow->checkReferenceAvailable(); mTradeWindow->checkReferenceAvailable(); + mSpellsWindow->checkReferenceAvailable(); mContainerWindow->checkReferenceAvailable(); mConsole->checkReferenceAvailable(); } @@ -786,6 +795,7 @@ MWGui::ScrollWindow* WindowManager::getScrollWindow() { return mScrollWindow; } MWGui::CountDialog* WindowManager::getCountDialog() { return mCountDialog; } MWGui::ConfirmationDialog* WindowManager::getConfirmationDialog() { return mConfirmationDialog; } MWGui::TradeWindow* WindowManager::getTradeWindow() { return mTradeWindow; } +MWGui::SpellsWindow* WindowManager::getSpellsWindow() { return mSpellsWindow; } MWGui::SpellWindow* WindowManager::getSpellWindow() { return mSpellWindow; } MWGui::Console* WindowManager::getConsole() { return mConsole; } diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index 38411bb18..805107478 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -105,6 +105,7 @@ namespace MWGui virtual MWGui::CountDialog* getCountDialog(); virtual MWGui::ConfirmationDialog* getConfirmationDialog(); virtual MWGui::TradeWindow* getTradeWindow(); + virtual MWGui::SpellsWindow* getSpellsWindow(); virtual MWGui::SpellWindow* getSpellWindow(); virtual MWGui::Console* getConsole(); @@ -212,10 +213,11 @@ namespace MWGui BookWindow* mBookWindow; CountDialog* mCountDialog; TradeWindow* mTradeWindow; + SpellsWindow* mSpellsWindow; // Npc selling spells window SettingsWindow* mSettingsWindow; ConfirmationDialog* mConfirmationDialog; AlchemyWindow* mAlchemyWindow; - SpellWindow* mSpellWindow; + SpellWindow* mSpellWindow; // Player owned spells window QuickKeysMenu* mQuickKeysMenu; CharacterCreation* mCharGen; diff --git a/extern/shiny b/extern/shiny index 278c6952b..164bc8d3b 160000 --- a/extern/shiny +++ b/extern/shiny @@ -1 +1 @@ -Subproject commit 278c6952b5c38e4b2a10205953e379598fad71a0 +Subproject commit 164bc8d3bfe860bd16ad89c0bd1b59f465c9bb24 diff --git a/files/mygui/CMakeLists.txt b/files/mygui/CMakeLists.txt index 70f7282e5..05713c5d1 100644 --- a/files/mygui/CMakeLists.txt +++ b/files/mygui/CMakeLists.txt @@ -64,6 +64,7 @@ set(MYGUI_FILES openmw_text.skin.xml openmw_tooltips.layout openmw_trade_window.layout + openmw_spells_window.layout openmw_windows.skin.xml openmw_quickkeys_menu.layout openmw_quickkeys_menu_assign.layout diff --git a/files/mygui/openmw_spells_window.layout b/files/mygui/openmw_spells_window.layout new file mode 100644 index 000000000..6b45b231c --- /dev/null +++ b/files/mygui/openmw_spells_window.layout @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From fc10649bb517fcc48af111857c54f11026262104 Mon Sep 17 00:00:00 2001 From: Adam Hogan Date: Sat, 8 Sep 2012 18:32:43 -0400 Subject: [PATCH 2/9] Updated shiny --- extern/shiny | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extern/shiny b/extern/shiny index 164bc8d3b..278c6952b 160000 --- a/extern/shiny +++ b/extern/shiny @@ -1 +1 @@ -Subproject commit 164bc8d3bfe860bd16ad89c0bd1b59f465c9bb24 +Subproject commit 278c6952b5c38e4b2a10205953e379598fad71a0 From 08410b9062b54ece3b8bb96c902291de1aa81e40 Mon Sep 17 00:00:00 2001 From: Adam Hogan Date: Sun, 9 Sep 2012 14:10:07 -0400 Subject: [PATCH 3/9] Renamed SpellBuyingWindow, took some suggestions from scrawl --- apps/openmw/CMakeLists.txt | 2 +- apps/openmw/mwbase/windowmanager.hpp | 4 +- apps/openmw/mwgui/dialogue.cpp | 6 +- apps/openmw/mwgui/mode.hpp | 2 +- ...spellswindow.cpp => spellbuyingwindow.cpp} | 148 +++++------------- ...spellswindow.hpp => spellbuyingwindow.hpp} | 30 ++-- apps/openmw/mwgui/windowmanagerimp.cpp | 18 +-- apps/openmw/mwgui/windowmanagerimp.hpp | 6 +- files/mygui/CMakeLists.txt | 2 +- ...yout => openmw_spell_buying_window.layout} | 0 files/mygui/openmw_text.skin.xml | 8 + 11 files changed, 76 insertions(+), 150 deletions(-) rename apps/openmw/mwgui/{spellswindow.cpp => spellbuyingwindow.cpp} (56%) rename apps/openmw/mwgui/{spellswindow.hpp => spellbuyingwindow.hpp} (57%) rename files/mygui/{openmw_spells_window.layout => openmw_spell_buying_window.layout} (100%) diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index aa66ba791..4cf3bd7fd 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -29,7 +29,7 @@ add_openmw_dir (mwgui map_window window_pinnable_base cursorreplace tooltips scrollwindow bookwindow list formatting inventorywindow container hud countdialog tradewindow settingswindow confirmationdialog alchemywindow referenceinterface spellwindow mainmenu quickkeysmenu - itemselection spellswindow + itemselection spellbuyingwindow ) add_openmw_dir (mwdialogue diff --git a/apps/openmw/mwbase/windowmanager.hpp b/apps/openmw/mwbase/windowmanager.hpp index 99f1e46d2..14b1051e8 100644 --- a/apps/openmw/mwbase/windowmanager.hpp +++ b/apps/openmw/mwbase/windowmanager.hpp @@ -42,7 +42,7 @@ namespace MWGui class Console; class SpellWindow; class TradeWindow; - class SpellsWindow; + class SpellBuyingWindow; class ConfirmationDialog; class CountDialog; class ScrollWindow; @@ -107,7 +107,7 @@ namespace MWBase virtual MWGui::CountDialog* getCountDialog() = 0; virtual MWGui::ConfirmationDialog* getConfirmationDialog() = 0; virtual MWGui::TradeWindow* getTradeWindow() = 0; - virtual MWGui::SpellsWindow* getSpellsWindow() = 0; + virtual MWGui::SpellBuyingWindow* getSpellBuyingWindow() = 0; virtual MWGui::SpellWindow* getSpellWindow() = 0; virtual MWGui::Console* getConsole() = 0; diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 949e745f2..20ae1fd65 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -17,7 +17,7 @@ #include "widgets.hpp" #include "list.hpp" #include "tradewindow.hpp" -#include "spellswindow.hpp" +#include "spellbuyingwindow.hpp" #include "inventorywindow.hpp" using namespace MWGui; @@ -131,8 +131,8 @@ void DialogueWindow::onSelectTopic(std::string topic) } else if (topic == MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sSpells")->str) { - mWindowManager.pushGuiMode(GM_Spells); - mWindowManager.getSpellsWindow()->startSpells(mPtr); + mWindowManager.pushGuiMode(GM_SpellBuying); + mWindowManager.getSpellBuyingWindow()->startSpellBuying(mPtr); } else diff --git a/apps/openmw/mwgui/mode.hpp b/apps/openmw/mwgui/mode.hpp index 8c0a2fc5f..4417f7b9c 100644 --- a/apps/openmw/mwgui/mode.hpp +++ b/apps/openmw/mwgui/mode.hpp @@ -20,7 +20,7 @@ namespace MWGui GM_Dialogue, // NPC interaction GM_Barter, GM_Rest, - GM_Spells, + GM_SpellBuying, // Startup character creation dialogs GM_Name, diff --git a/apps/openmw/mwgui/spellswindow.cpp b/apps/openmw/mwgui/spellbuyingwindow.cpp similarity index 56% rename from apps/openmw/mwgui/spellswindow.cpp rename to apps/openmw/mwgui/spellbuyingwindow.cpp index 5e1797823..af6bb182d 100644 --- a/apps/openmw/mwgui/spellswindow.cpp +++ b/apps/openmw/mwgui/spellbuyingwindow.cpp @@ -1,4 +1,4 @@ -#include "spellswindow.hpp" +#include "spellbuyingwindow.hpp" #include @@ -18,19 +18,16 @@ namespace MWGui { - const int SpellsWindow::sLineHeight = 18; + const int SpellBuyingWindow::sLineHeight = 18; - SpellsWindow::SpellsWindow(MWBase::WindowManager& parWindowManager) : + SpellBuyingWindow::SpellBuyingWindow(MWBase::WindowManager& parWindowManager) : WindowBase("openmw_spells_window.layout", parWindowManager) , ContainerBase(NULL) // no drag&drop , mSpellsWidgetMap() , mCurrentY(0) , mLastPos(0) - , mSpellsWidgets() - , mSpellsPriceMap() { setCoord(0, 0, 450, 300); - center(); getWidget(mCancelButton, "CancelButton"); getWidget(mPlayerGold, "PlayerGold"); @@ -40,11 +37,11 @@ namespace MWGui getWidget(mSpellsClientWidget, "SpellsClient"); getWidget(mSpellsScrollerWidget, "SpellsScroller"); - mSpellsClientWidget->eventMouseWheel += MyGUI::newDelegate(this, &SpellsWindow::onMouseWheel); + mSpellsClientWidget->eventMouseWheel += MyGUI::newDelegate(this, &SpellBuyingWindow::onMouseWheel); - mSpellsScrollerWidget->eventScrollChangePosition += MyGUI::newDelegate(this, &SpellsWindow::onScrollChangePosition); + mSpellsScrollerWidget->eventScrollChangePosition += MyGUI::newDelegate(this, &SpellBuyingWindow::onScrollChangePosition); - mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellsWindow::onCancelButtonClicked); + mCancelButton->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellBuyingWindow::onCancelButtonClicked); int cancelButtonWidth = mCancelButton->getTextSize().width + 24; mCancelButton->setCoord(430-cancelButtonWidth, @@ -59,71 +56,40 @@ namespace MWGui mSelect->getTop(), mSelect->getTextSize().width, mSelect->getHeight()); - - static_cast(mMainWidget)->eventWindowChangeCoord += MyGUI::newDelegate(this, &SpellsWindow::onWindowResize); } - void SpellsWindow::addSpell(std::string spellID) + void SpellBuyingWindow::addSpell(std::string spellID) { MyGUI::Button* toAdd; - - toAdd = mSpellsClientWidget->createWidget("SandText", 0, mCurrentY, 200, sLineHeight, MyGUI::Align::Default); - mCurrentY += sLineHeight; const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().spells.find(spellID); - /// \todo price adjustment depending on merchantile skill int price = spell->data.cost*MWBase::Environment::get().getWorld()->getStore().gameSettings.search("fSpellValueMult")->f; - mSpellsPriceMap.insert(std::pair(spell,price)); - if (price>mWindowManager.getInventoryWindow()->getPlayerGold()) - toAdd->setCaption("#A3997B" + spell->name+" - "+boost::lexical_cast(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str); - else - toAdd->setCaption(spell->name+" - "+boost::lexical_cast(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str); + toAdd = mSpellsClientWidget->createWidget((price>mWindowManager.getInventoryWindow()->getPlayerGold()) ? "SandTextGreyedOut" : "SpellText", 0, mCurrentY, 200, sLineHeight, MyGUI::Align::Default); + mCurrentY += sLineHeight; + /// \todo price adjustment depending on merchantile skill + toAdd->setUserData(price); + toAdd->setCaption(spell->name+" - "+boost::lexical_cast(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str); toAdd->setSize(toAdd->getTextSize().width,sLineHeight); - toAdd->eventMouseWheel += MyGUI::newDelegate(this, &SpellsWindow::onMouseWheel); + toAdd->eventMouseWheel += MyGUI::newDelegate(this, &SpellBuyingWindow::onMouseWheel); toAdd->setUserString("ToolTipType", "Spell"); toAdd->setUserString("Spell", spellID); - toAdd->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellsWindow::onSpellButtonClick); - toAdd->eventMouseSetFocus += MyGUI::newDelegate(this, &SpellsWindow::onFocus); - toAdd->eventMouseLostFocus += MyGUI::newDelegate(this, &SpellsWindow::onFocusLost); - mSpellsWidgets.push_back(toAdd); + toAdd->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellBuyingWindow::onSpellButtonClick); mSpellsWidgetMap.insert(std::pair(toAdd,spell)); } - void SpellsWindow::onFocusLost(MyGUI::Widget* _sender, MyGUI::Widget* _old) - { - updateLabels(); - } - - void SpellsWindow::onFocus(MyGUI::Widget* _sender, MyGUI::Widget* _old) - { - updateLabels(); - MyGUI::Button* toUpdate; - toUpdate = (MyGUI::Button*) _sender; - const ESM::Spell* spell = mSpellsWidgetMap.find(toUpdate)->second; - int price = mSpellsPriceMap.find(spell)->second; - if (price>mWindowManager.getInventoryWindow()->getPlayerGold()) - toUpdate->setCaption("#A3997B" + spell->name+" - "+boost::lexical_cast(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str); - else - toUpdate->setCaption("#D8C09A" + spell->name+" - "+boost::lexical_cast(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str); - } - - void SpellsWindow::clearSpells() + void SpellBuyingWindow::clearSpells() { mSpellsScrollerWidget->setScrollPosition(0); onScrollChangePosition(mSpellsScrollerWidget, mSpellsScrollerWidget->getScrollPosition()); mCurrentY = 0; - mSpellsWidgets.clear(); - while (mSpellsClientWidget->getChildCount()!=0) - { - MyGUI::Widget* toRemove; - toRemove = mSpellsClientWidget->getChildAt(0); - mSpellsClientWidget->_destroyChildWidget(toRemove); - } + while (mSpellsClientWidget->getChildCount()) + MyGUI::Gui::getInstance().destroyWidget(mSpellsClientWidget->getChildAt(0)); mSpellsWidgetMap.clear(); - mSpellsPriceMap.clear(); } - void SpellsWindow::startSpells(MWWorld::Ptr actor) + void SpellBuyingWindow::startSpellBuying(MWWorld::Ptr actor) { + center(); + mActor = actor; clearSpells(); if (actor.getTypeName() == typeid(ESM::NPC).name()) @@ -150,10 +116,10 @@ namespace MWGui updateScroller(); } - void SpellsWindow::onSpellButtonClick(MyGUI::Widget* _sender) + void SpellBuyingWindow::onSpellButtonClick(MyGUI::Widget* _sender) { const ESM::Spell* spell = mSpellsWidgetMap.find(_sender)->second; - int price = mSpellsPriceMap.find(spell)->second; + int price = *_sender->getUserData(); if (mWindowManager.getInventoryWindow()->getPlayerGold()>=price) { @@ -162,48 +128,19 @@ namespace MWGui MWMechanics::Spells& spells = stats.getSpells(); spells.add(spell->name); mWindowManager.getTradeWindow()->addOrRemoveGold(-price); - mSpellsWidgetMap.erase(_sender); - mSpellsPriceMap.erase(spell); - for (std::vector::iterator it = mSpellsWidgets.begin(); it != mSpellsWidgets.end(); ++it) - { - if (*it==_sender) - { - mSpellsWidgets.erase(it); - break; - } - } - mSpellsClientWidget->_destroyChildWidget(_sender); - unsigned int i; mSpellsScrollerWidget->setScrollPosition(0); onScrollChangePosition(mSpellsScrollerWidget, mSpellsScrollerWidget->getScrollPosition()); - mCurrentY = 0; - for (i=0;igetChildCount();i++) - { - MyGUI::Widget* toMove; - toMove = mSpellsClientWidget->getChildAt(i); - toMove->setPosition(0,mCurrentY); - mCurrentY+=sLineHeight; - } + updateScroller(); + startSpellBuying(mActor); } - else - { - - } - updateLabels(); - updateScroller(); } - void SpellsWindow::onWindowResize(MyGUI::Window* _sender) + void SpellBuyingWindow::onCancelButtonClicked(MyGUI::Widget* _sender) { - + mWindowManager.removeGuiMode(GM_SpellBuying); } - void SpellsWindow::onCancelButtonClicked(MyGUI::Widget* _sender) - { - mWindowManager.removeGuiMode(GM_Spells); - } - - void SpellsWindow::updateLabels() + void SpellBuyingWindow::updateLabels() { mPlayerGold->setCaption(MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sGold")->str + ": " + boost::lexical_cast(mWindowManager.getInventoryWindow()->getPlayerGold())); @@ -211,28 +148,16 @@ namespace MWGui mPlayerGold->getTop(), mPlayerGold->getTextSize().width, mPlayerGold->getHeight()); - unsigned int i; - for (i=0;igetChildCount();i++) - { - MyGUI::Button* toUpdate; - toUpdate = (MyGUI::Button*) mSpellsClientWidget->getChildAt(i); - const ESM::Spell* spell = mSpellsWidgetMap.find(toUpdate)->second; - int price = mSpellsPriceMap.find(spell)->second; - if (price>mWindowManager.getInventoryWindow()->getPlayerGold()) - toUpdate->setCaption("#A3997B" + spell->name+" - "+boost::lexical_cast(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str); - else - toUpdate->setCaption(spell->name+" - "+boost::lexical_cast(price)+MWBase::Environment::get().getWorld()->getStore().gameSettings.search("sgp")->str); - } } - void SpellsWindow::onReferenceUnavailable() + void SpellBuyingWindow::onReferenceUnavailable() { // remove both Spells and Dialogue (since you always trade with the NPC/creature that you have previously talked to) - mWindowManager.removeGuiMode(GM_Spells); + mWindowManager.removeGuiMode(GM_SpellBuying); mWindowManager.removeGuiMode(GM_Dialogue); } - void SpellsWindow::updateScroller() + void SpellBuyingWindow::updateScroller() { mSpellsScrollerWidget->setScrollRange(std::max(mCurrentY - mSpellsClientWidget->getHeight(), 0)); mSpellsScrollerWidget->setScrollPage(std::max(mSpellsClientWidget->getHeight() - sLineHeight, 0)); @@ -240,7 +165,7 @@ namespace MWGui mSpellsScrollerWidget->setTrackSize( (mSpellsBoxWidget->getHeight() / float(mCurrentY)) * mSpellsScrollerWidget->getLineSize() ); } - void SpellsWindow::onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos) + void SpellBuyingWindow::onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos) { int diff = mLastPos - pos; // Adjust position of all widget according to difference @@ -248,14 +173,16 @@ namespace MWGui return; mLastPos = pos; - std::vector::const_iterator end = mSpellsWidgets.end(); - for (std::vector::const_iterator it = mSpellsWidgets.begin(); it != end; ++it) + unsigned int i; + for (i=0;igetChildCount();i++) { - (*it)->setCoord((*it)->getCoord() + MyGUI::IntPoint(0, diff)); + MyGUI::Widget* toMove; + toMove = mSpellsClientWidget->getChildAt(i); + toMove->setCoord(toMove->getCoord() + MyGUI::IntPoint(0, diff)); } } - void SpellsWindow::onMouseWheel(MyGUI::Widget* _sender, int _rel) + void SpellBuyingWindow::onMouseWheel(MyGUI::Widget* _sender, int _rel) { if (mSpellsScrollerWidget->getScrollPosition() - _rel*0.3 < 0) mSpellsScrollerWidget->setScrollPosition(0); @@ -267,3 +194,4 @@ namespace MWGui onScrollChangePosition(mSpellsScrollerWidget, mSpellsScrollerWidget->getScrollPosition()); } } + diff --git a/apps/openmw/mwgui/spellswindow.hpp b/apps/openmw/mwgui/spellbuyingwindow.hpp similarity index 57% rename from apps/openmw/mwgui/spellswindow.hpp rename to apps/openmw/mwgui/spellbuyingwindow.hpp index 4bc073d14..7c16b116a 100644 --- a/apps/openmw/mwgui/spellswindow.hpp +++ b/apps/openmw/mwgui/spellbuyingwindow.hpp @@ -1,5 +1,5 @@ -#ifndef MWGUI_SPELLSWINDOW_H -#define MWGUI_SPELLSWINDOW_H +#ifndef MWGUI_SpellBuyingWINDOW_H +#define MWGUI_SpellBuyingWINDOW_H #include "container.hpp" #include "window_base.hpp" @@ -20,12 +20,12 @@ namespace MWGui namespace MWGui { - class SpellsWindow : public ContainerBase, public WindowBase + class SpellBuyingWindow : public ContainerBase, public WindowBase { public: - SpellsWindow(MWBase::WindowManager& parWindowManager); + SpellBuyingWindow(MWBase::WindowManager& parWindowManager); - void startSpells(MWWorld::Ptr actor); + void startSpellBuying(MWWorld::Ptr actor); protected: MyGUI::Button* mCancelButton; @@ -36,31 +36,21 @@ namespace MWGui MyGUI::WidgetPtr mSpellsBoxWidget, mSpellsClientWidget; MyGUI::ScrollBar* mSpellsScrollerWidget; - std::map mSpellsWidgetMap; - std::map mSpellsPriceMap; - std::vector mSpellsWidgets; + MWWorld::Ptr mActor; + + std::map mSpellsWidgetMap; - void onWindowResize(MyGUI::Window* _sender); - void onFilterChanged(MyGUI::Widget* _sender); void onCancelButtonClicked(MyGUI::Widget* _sender); - void onFocus(MyGUI::Widget* _sender, MyGUI::Widget* _old); - void onFocusLost(MyGUI::Widget* _sender, MyGUI::Widget* _old); void onSpellButtonClick(MyGUI::Widget* _sender); - void addSpell(std::string spellID); - void clearSpells(); void updateScroller(); void onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos); void onMouseWheel(MyGUI::Widget* _sender, int _rel); + void addSpell(std::string spellID); + void clearSpells(); int mLastPos,mCurrentY; static const int sLineHeight; - // don't show items that the NPC has equipped in his trade-window. - virtual bool ignoreEquippedItems() { return true; } - - virtual bool isTrading() { return true; } - virtual bool isTradeWindow() { return true; } - void updateLabels(); virtual void onReferenceUnavailable(); diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index 012a0e127..dcefd1e71 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -37,7 +37,7 @@ #include "mainmenu.hpp" #include "countdialog.hpp" #include "tradewindow.hpp" -#include "spellswindow.hpp" +#include "spellbuyingwindow.hpp" #include "settingswindow.hpp" #include "confirmationdialog.hpp" #include "alchemywindow.hpp" @@ -62,7 +62,7 @@ WindowManager::WindowManager( , mScrollWindow(NULL) , mCountDialog(NULL) , mTradeWindow(NULL) - , mSpellsWindow(NULL) + , mSpellBuyingWindow(NULL) , mSettingsWindow(NULL) , mConfirmationDialog(NULL) , mAlchemyWindow(NULL) @@ -128,7 +128,7 @@ WindowManager::WindowManager( mMessageBoxManager = new MessageBoxManager(this); mInventoryWindow = new InventoryWindow(*this,mDragAndDrop); mTradeWindow = new TradeWindow(*this); - mSpellsWindow = new SpellsWindow(*this); + mSpellBuyingWindow = new SpellBuyingWindow(*this); mDialogueWindow = new DialogueWindow(*this); mContainerWindow = new ContainerWindow(*this,mDragAndDrop); mHud = new HUD(w,h, mShowFPSLevel, mDragAndDrop); @@ -185,7 +185,7 @@ WindowManager::~WindowManager() delete mBookWindow; delete mScrollWindow; delete mTradeWindow; - delete mSpellsWindow; + delete mSpellBuyingWindow; delete mSettingsWindow; delete mConfirmationDialog; delete mAlchemyWindow; @@ -232,7 +232,7 @@ void WindowManager::updateVisible() mScrollWindow->setVisible(false); mBookWindow->setVisible(false); mTradeWindow->setVisible(false); - mSpellsWindow->setVisible(false); + mSpellBuyingWindow->setVisible(false); mSettingsWindow->setVisible(false); mAlchemyWindow->setVisible(false); mSpellWindow->setVisible(false); @@ -322,8 +322,8 @@ void WindowManager::updateVisible() mInventoryWindow->setVisible(true); mTradeWindow->setVisible(true); break; - case GM_Spells: - mSpellsWindow->setVisible(true); + case GM_SpellBuying: + mSpellBuyingWindow->setVisible(true); break; case GM_InterMessageBox: break; @@ -517,7 +517,7 @@ void WindowManager::onFrame (float frameDuration) mDialogueWindow->checkReferenceAvailable(); mTradeWindow->checkReferenceAvailable(); - mSpellsWindow->checkReferenceAvailable(); + mSpellBuyingWindow->checkReferenceAvailable(); mContainerWindow->checkReferenceAvailable(); mConsole->checkReferenceAvailable(); } @@ -795,7 +795,7 @@ MWGui::ScrollWindow* WindowManager::getScrollWindow() { return mScrollWindow; } MWGui::CountDialog* WindowManager::getCountDialog() { return mCountDialog; } MWGui::ConfirmationDialog* WindowManager::getConfirmationDialog() { return mConfirmationDialog; } MWGui::TradeWindow* WindowManager::getTradeWindow() { return mTradeWindow; } -MWGui::SpellsWindow* WindowManager::getSpellsWindow() { return mSpellsWindow; } +MWGui::SpellBuyingWindow* WindowManager::getSpellBuyingWindow() { return mSpellBuyingWindow; } MWGui::SpellWindow* WindowManager::getSpellWindow() { return mSpellWindow; } MWGui::Console* WindowManager::getConsole() { return mConsole; } diff --git a/apps/openmw/mwgui/windowmanagerimp.hpp b/apps/openmw/mwgui/windowmanagerimp.hpp index 805107478..a91478bbc 100644 --- a/apps/openmw/mwgui/windowmanagerimp.hpp +++ b/apps/openmw/mwgui/windowmanagerimp.hpp @@ -105,7 +105,7 @@ namespace MWGui virtual MWGui::CountDialog* getCountDialog(); virtual MWGui::ConfirmationDialog* getConfirmationDialog(); virtual MWGui::TradeWindow* getTradeWindow(); - virtual MWGui::SpellsWindow* getSpellsWindow(); + virtual MWGui::SpellBuyingWindow* getSpellBuyingWindow(); virtual MWGui::SpellWindow* getSpellWindow(); virtual MWGui::Console* getConsole(); @@ -213,11 +213,11 @@ namespace MWGui BookWindow* mBookWindow; CountDialog* mCountDialog; TradeWindow* mTradeWindow; - SpellsWindow* mSpellsWindow; // Npc selling spells window + SpellBuyingWindow* mSpellBuyingWindow; SettingsWindow* mSettingsWindow; ConfirmationDialog* mConfirmationDialog; AlchemyWindow* mAlchemyWindow; - SpellWindow* mSpellWindow; // Player owned spells window + SpellWindow* mSpellWindow; QuickKeysMenu* mQuickKeysMenu; CharacterCreation* mCharGen; diff --git a/files/mygui/CMakeLists.txt b/files/mygui/CMakeLists.txt index 05713c5d1..4a215c50f 100644 --- a/files/mygui/CMakeLists.txt +++ b/files/mygui/CMakeLists.txt @@ -64,7 +64,7 @@ set(MYGUI_FILES openmw_text.skin.xml openmw_tooltips.layout openmw_trade_window.layout - openmw_spells_window.layout + openmw_spell_buying_window.layout openmw_windows.skin.xml openmw_quickkeys_menu.layout openmw_quickkeys_menu_assign.layout diff --git a/files/mygui/openmw_spells_window.layout b/files/mygui/openmw_spell_buying_window.layout similarity index 100% rename from files/mygui/openmw_spells_window.layout rename to files/mygui/openmw_spell_buying_window.layout diff --git a/files/mygui/openmw_text.skin.xml b/files/mygui/openmw_text.skin.xml index e29483e35..3e1a977e5 100644 --- a/files/mygui/openmw_text.skin.xml +++ b/files/mygui/openmw_text.skin.xml @@ -17,6 +17,14 @@ + + + + + + + + From 3fad1c07868a769931492f253450793386767d75 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 9 Sep 2012 20:43:21 +0200 Subject: [PATCH 4/9] fixed a crash --- apps/openmw/mwgui/spellbuyingwindow.cpp | 2 +- files/mygui/CMakeLists.txt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/spellbuyingwindow.cpp b/apps/openmw/mwgui/spellbuyingwindow.cpp index af6bb182d..5750bb869 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.cpp +++ b/apps/openmw/mwgui/spellbuyingwindow.cpp @@ -21,7 +21,7 @@ namespace MWGui const int SpellBuyingWindow::sLineHeight = 18; SpellBuyingWindow::SpellBuyingWindow(MWBase::WindowManager& parWindowManager) : - WindowBase("openmw_spells_window.layout", parWindowManager) + WindowBase("openmw_spell_buying_window.layout", parWindowManager) , ContainerBase(NULL) // no drag&drop , mSpellsWidgetMap() , mCurrentY(0) diff --git a/files/mygui/CMakeLists.txt b/files/mygui/CMakeLists.txt index 4a215c50f..82fb64c76 100644 --- a/files/mygui/CMakeLists.txt +++ b/files/mygui/CMakeLists.txt @@ -70,6 +70,7 @@ set(MYGUI_FILES openmw_quickkeys_menu_assign.layout openmw_itemselection_dialog.layout openmw_magicselection_dialog.layout + openmw_spell_buying_window.layout smallbars.png VeraMono.ttf markers.png From 06677a0fc8220c21ce30cc3b79a3918a598a5d61 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 9 Sep 2012 21:03:39 +0200 Subject: [PATCH 5/9] fixed ID handling and some misc cleanup --- apps/openmw/mwgui/spellbuyingwindow.cpp | 43 ++++++++++++------------- apps/openmw/mwgui/spellbuyingwindow.hpp | 2 +- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/apps/openmw/mwgui/spellbuyingwindow.cpp b/apps/openmw/mwgui/spellbuyingwindow.cpp index 5750bb869..970651372 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.cpp +++ b/apps/openmw/mwgui/spellbuyingwindow.cpp @@ -58,12 +58,11 @@ namespace MWGui mSelect->getHeight()); } - void SpellBuyingWindow::addSpell(std::string spellID) + void SpellBuyingWindow::addSpell(std::string spellId) { - MyGUI::Button* toAdd; - const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().spells.find(spellID); + const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().spells.find(spellId); int price = spell->data.cost*MWBase::Environment::get().getWorld()->getStore().gameSettings.search("fSpellValueMult")->f; - toAdd = mSpellsClientWidget->createWidget((price>mWindowManager.getInventoryWindow()->getPlayerGold()) ? "SandTextGreyedOut" : "SpellText", 0, mCurrentY, 200, sLineHeight, MyGUI::Align::Default); + MyGUI::Button* toAdd = mSpellsClientWidget->createWidget((price>mWindowManager.getInventoryWindow()->getPlayerGold()) ? "SandTextGreyedOut" : "SpellText", 0, mCurrentY, 200, sLineHeight, MyGUI::Align::Default); mCurrentY += sLineHeight; /// \todo price adjustment depending on merchantile skill toAdd->setUserData(price); @@ -71,9 +70,9 @@ namespace MWGui toAdd->setSize(toAdd->getTextSize().width,sLineHeight); toAdd->eventMouseWheel += MyGUI::newDelegate(this, &SpellBuyingWindow::onMouseWheel); toAdd->setUserString("ToolTipType", "Spell"); - toAdd->setUserString("Spell", spellID); + toAdd->setUserString("Spell", spellId); toAdd->eventMouseButtonClick += MyGUI::newDelegate(this, &SpellBuyingWindow::onSpellButtonClick); - mSpellsWidgetMap.insert(std::pair(toAdd,spell)); + mSpellsWidgetMap.insert(std::make_pair (toAdd, spellId)); } void SpellBuyingWindow::clearSpells() @@ -92,33 +91,33 @@ namespace MWGui mActor = actor; clearSpells(); - if (actor.getTypeName() == typeid(ESM::NPC).name()) + MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); + MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); + MWMechanics::Spells& playerSpells = stats.getSpells(); + /// \todo get spell list via class interface + std::vector spellList = actor.get()->base->spells.list; + for (std::vector::const_iterator it = spellList.begin(); it != spellList.end(); ++it) { - MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); - MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); - MWMechanics::Spells& playerSpells = stats.getSpells(); - std::vector spellList = actor.get()->base->spells.list; - for (std::vector::const_iterator it = spellList.begin(); it != spellList.end(); ++it) + bool alreadyHave = false; + for (std::vector::const_iterator it2 = playerSpells.begin(); it2 != playerSpells.end(); ++it2) { - bool alreadyHave = false; - for (std::vector::const_iterator it2 = playerSpells.begin(); it2 != playerSpells.end(); ++it2) + if (*it==*it2) { - std::string spellname1 = MWBase::Environment::get().getWorld()->getStore().spells.find(*it)->name; - std::string spellname2 = MWBase::Environment::get().getWorld()->getStore().spells.find(*it2)->name; - if (spellname1.compare(spellname2)==0) - alreadyHave = true; + alreadyHave = true; + break; } - if (alreadyHave==false) - addSpell(*it); } + + if (alreadyHave==false) + addSpell(*it); } + updateLabels(); updateScroller(); } void SpellBuyingWindow::onSpellButtonClick(MyGUI::Widget* _sender) { - const ESM::Spell* spell = mSpellsWidgetMap.find(_sender)->second; int price = *_sender->getUserData(); if (mWindowManager.getInventoryWindow()->getPlayerGold()>=price) @@ -126,7 +125,7 @@ namespace MWGui MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); MWMechanics::Spells& spells = stats.getSpells(); - spells.add(spell->name); + spells.add (mSpellsWidgetMap.find(_sender)->second); mWindowManager.getTradeWindow()->addOrRemoveGold(-price); mSpellsScrollerWidget->setScrollPosition(0); onScrollChangePosition(mSpellsScrollerWidget, mSpellsScrollerWidget->getScrollPosition()); diff --git a/apps/openmw/mwgui/spellbuyingwindow.hpp b/apps/openmw/mwgui/spellbuyingwindow.hpp index 7c16b116a..66cec2f2a 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.hpp +++ b/apps/openmw/mwgui/spellbuyingwindow.hpp @@ -38,7 +38,7 @@ namespace MWGui MWWorld::Ptr mActor; - std::map mSpellsWidgetMap; + std::map mSpellsWidgetMap; void onCancelButtonClicked(MyGUI::Widget* _sender); void onSpellButtonClick(MyGUI::Widget* _sender); From 9c49ca1468a03c4e80e724f35c1949ed3ec10482 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 9 Sep 2012 21:08:57 +0200 Subject: [PATCH 6/9] a bit more random cleanup --- apps/openmw/mwgui/spellbuyingwindow.cpp | 10 ++++------ apps/openmw/mwgui/spellbuyingwindow.hpp | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwgui/spellbuyingwindow.cpp b/apps/openmw/mwgui/spellbuyingwindow.cpp index 970651372..4d89ee8c2 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.cpp +++ b/apps/openmw/mwgui/spellbuyingwindow.cpp @@ -23,7 +23,6 @@ namespace MWGui SpellBuyingWindow::SpellBuyingWindow(MWBase::WindowManager& parWindowManager) : WindowBase("openmw_spell_buying_window.layout", parWindowManager) , ContainerBase(NULL) // no drag&drop - , mSpellsWidgetMap() , mCurrentY(0) , mLastPos(0) { @@ -58,7 +57,7 @@ namespace MWGui mSelect->getHeight()); } - void SpellBuyingWindow::addSpell(std::string spellId) + void SpellBuyingWindow::addSpell(const std::string& spellId) { const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().spells.find(spellId); int price = spell->data.cost*MWBase::Environment::get().getWorld()->getStore().gameSettings.search("fSpellValueMult")->f; @@ -85,7 +84,7 @@ namespace MWGui mSpellsWidgetMap.clear(); } - void SpellBuyingWindow::startSpellBuying(MWWorld::Ptr actor) + void SpellBuyingWindow::startSpellBuying(const MWWorld::Ptr& actor) { center(); mActor = actor; @@ -94,7 +93,7 @@ namespace MWGui MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); MWMechanics::Spells& playerSpells = stats.getSpells(); - /// \todo get spell list via class interface + /// \todo get spell list via MWWorld::Class interface std::vector spellList = actor.get()->base->spells.list; for (std::vector::const_iterator it = spellList.begin(); it != spellList.end(); ++it) { @@ -172,8 +171,7 @@ namespace MWGui return; mLastPos = pos; - unsigned int i; - for (i=0;igetChildCount();i++) + for (unsigned int i=0;igetChildCount();i++) { MyGUI::Widget* toMove; toMove = mSpellsClientWidget->getChildAt(i); diff --git a/apps/openmw/mwgui/spellbuyingwindow.hpp b/apps/openmw/mwgui/spellbuyingwindow.hpp index 66cec2f2a..6f94e91b2 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.hpp +++ b/apps/openmw/mwgui/spellbuyingwindow.hpp @@ -25,7 +25,7 @@ namespace MWGui public: SpellBuyingWindow(MWBase::WindowManager& parWindowManager); - void startSpellBuying(MWWorld::Ptr actor); + void startSpellBuying(const MWWorld::Ptr& actor); protected: MyGUI::Button* mCancelButton; @@ -45,7 +45,7 @@ namespace MWGui void updateScroller(); void onScrollChangePosition(MyGUI::ScrollBar* scroller, size_t pos); void onMouseWheel(MyGUI::Widget* _sender, int _rel); - void addSpell(std::string spellID); + void addSpell(const std::string& spellID); void clearSpells(); int mLastPos,mCurrentY; From bcf3a81a6ce98f4e3939c1bb074d407fdcfd7631 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Sun, 9 Sep 2012 21:18:47 +0200 Subject: [PATCH 7/9] and a tiny bit more of cleanup --- apps/openmw/mwgui/spellbuyingwindow.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/openmw/mwgui/spellbuyingwindow.cpp b/apps/openmw/mwgui/spellbuyingwindow.cpp index 4d89ee8c2..481dd5dd8 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.cpp +++ b/apps/openmw/mwgui/spellbuyingwindow.cpp @@ -173,8 +173,7 @@ namespace MWGui for (unsigned int i=0;igetChildCount();i++) { - MyGUI::Widget* toMove; - toMove = mSpellsClientWidget->getChildAt(i); + MyGUI::Widget* toMove = mSpellsClientWidget->getChildAt(i); toMove->setCoord(toMove->getCoord() + MyGUI::IntPoint(0, diff)); } } From 6c928e93d38dbe8073505fd9ec841bd6a8495842 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 10 Sep 2012 13:04:00 +0200 Subject: [PATCH 8/9] added missing initialisation of NPC/creature spell lists from ESX records --- apps/openmw/mwclass/creature.cpp | 5 +++++ apps/openmw/mwclass/npc.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 7c6021652..d80a5c788 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -66,6 +66,11 @@ namespace MWClass data->mCreatureStats.setFlee(ref->base->mAiData.mFlee); data->mCreatureStats.setAlarm(ref->base->mAiData.mAlarm); + // spells + for (std::vector::const_iterator iter (ref->base->mSpells.list.begin()); + iter!=ref->base->mSpells.list.end(); ++iter) + data->mCreatureStats.getSpells().add (*iter); + // store ptr.getRefData().setCustomData (data.release()); } diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 909c681a5..8aab9da56 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -105,6 +105,11 @@ namespace MWClass data->mCreatureStats.setFlee(ref->base->mAiData.mFlee); data->mCreatureStats.setAlarm(ref->base->mAiData.mAlarm); + // spells + for (std::vector::const_iterator iter (ref->base->spells.list.begin()); + iter!=ref->base->spells.list.end(); ++iter) + data->mCreatureStats.getSpells().add (*iter); + // store ptr.getRefData().setCustomData (data.release()); } From f17756712a9c1c5b8da37052e1daa7d122933f11 Mon Sep 17 00:00:00 2001 From: Marc Zinnschlag Date: Mon, 10 Sep 2012 13:15:55 +0200 Subject: [PATCH 9/9] fixed spell list handling --- apps/openmw/mwgui/spellbuyingwindow.cpp | 29 +++++++++++-------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/apps/openmw/mwgui/spellbuyingwindow.cpp b/apps/openmw/mwgui/spellbuyingwindow.cpp index 481dd5dd8..48e181545 100644 --- a/apps/openmw/mwgui/spellbuyingwindow.cpp +++ b/apps/openmw/mwgui/spellbuyingwindow.cpp @@ -91,24 +91,21 @@ namespace MWGui clearSpells(); MWWorld::Ptr player = MWBase::Environment::get().getWorld()->getPlayer().getPlayer(); - MWMechanics::CreatureStats& stats = MWWorld::Class::get(player).getCreatureStats(player); - MWMechanics::Spells& playerSpells = stats.getSpells(); - /// \todo get spell list via MWWorld::Class interface - std::vector spellList = actor.get()->base->spells.list; - for (std::vector::const_iterator it = spellList.begin(); it != spellList.end(); ++it) + + MWMechanics::Spells& playerSpells = MWWorld::Class::get (player).getCreatureStats (player).getSpells(); + MWMechanics::Spells& merchantSpells = MWWorld::Class::get (actor).getCreatureStats (actor).getSpells(); + + for (MWMechanics::Spells::TIterator iter = merchantSpells.begin(); iter!=merchantSpells.end(); ++iter) { - bool alreadyHave = false; - for (std::vector::const_iterator it2 = playerSpells.begin(); it2 != playerSpells.end(); ++it2) - { - if (*it==*it2) - { - alreadyHave = true; - break; - } - } + const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().spells.find (*iter); - if (alreadyHave==false) - addSpell(*it); + if (spell->data.type!=ESM::Spell::ST_Spell) + continue; // don't try to sell diseases, curses or powers + + if (std::find (playerSpells.begin(), playerSpells.end(), *iter)!=playerSpells.end()) + continue; // we have that spell already + + addSpell (*iter); } updateLabels();