From a51b73b6091c3dadd6ab791161ddb09bc87410c4 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 9 Mar 2013 21:50:01 +0100 Subject: [PATCH] Fix topics that have the same name as a service opening that service when clicked --- apps/openmw/mwgui/dialogue.cpp | 88 +++++++++++++++++++--------------- apps/openmw/mwgui/dialogue.hpp | 2 +- apps/openmw/mwgui/list.cpp | 7 ++- apps/openmw/mwgui/list.hpp | 4 +- 4 files changed, 57 insertions(+), 44 deletions(-) diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 859e3008cc..cdcbfc4d18 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -223,50 +223,60 @@ void DialogueWindow::onByeClicked(MyGUI::Widget* _sender) MWBase::Environment::get().getDialogueManager()->goodbyeSelected(); } -void DialogueWindow::onSelectTopic(std::string topic) +void DialogueWindow::onSelectTopic(const std::string& topic, int id) { if (!mEnabled) return; - const MWWorld::Store &gmst = - MWBase::Environment::get().getWorld()->getStore().get(); + int separatorPos = mTopicsList->getItemCount(); + for (unsigned int i=0; igetItemCount(); ++i) + { + if (mTopicsList->getItemNameAt(i) == "") + separatorPos = i; + } - if (topic == gmst.find("sBarter")->getString()) - { - /// \todo check if the player is allowed to trade with this actor (e.g. faction rank high enough)? - mWindowManager.pushGuiMode(GM_Barter); - mWindowManager.getTradeWindow()->startTrade(mPtr); - } - if (topic == gmst.find("sPersuasion")->getString()) - { - mPersuasionDialog.setVisible(true); - } - else if (topic == gmst.find("sSpells")->getString()) - { - mWindowManager.pushGuiMode(GM_SpellBuying); - mWindowManager.getSpellBuyingWindow()->startSpellBuying(mPtr); - } - else if (topic == gmst.find("sTravel")->getString()) - { - mWindowManager.pushGuiMode(GM_Travel); - mWindowManager.getTravelWindow()->startTravel(mPtr); - } - else if (topic == gmst.find("sSpellMakingMenuTitle")->getString()) - { - mWindowManager.pushGuiMode(GM_SpellCreation); - mWindowManager.startSpellMaking (mPtr); - } - else if (topic == gmst.find("sEnchanting")->getString()) - { - mWindowManager.pushGuiMode(GM_Enchanting); - mWindowManager.startEnchanting (mPtr); - } - else if (topic == gmst.find("sServiceTrainingTitle")->getString()) - { - mWindowManager.pushGuiMode(GM_Training); - mWindowManager.startTraining (mPtr); - } - else + if (id > separatorPos) MWBase::Environment::get().getDialogueManager()->keywordSelected(lower_string(topic)); + else + { + const MWWorld::Store &gmst = + MWBase::Environment::get().getWorld()->getStore().get(); + + if (topic == gmst.find("sBarter")->getString()) + { + /// \todo check if the player is allowed to trade with this actor (e.g. faction rank high enough)? + mWindowManager.pushGuiMode(GM_Barter); + mWindowManager.getTradeWindow()->startTrade(mPtr); + } + if (topic == gmst.find("sPersuasion")->getString()) + { + mPersuasionDialog.setVisible(true); + } + else if (topic == gmst.find("sSpells")->getString()) + { + mWindowManager.pushGuiMode(GM_SpellBuying); + mWindowManager.getSpellBuyingWindow()->startSpellBuying(mPtr); + } + else if (topic == gmst.find("sTravel")->getString()) + { + mWindowManager.pushGuiMode(GM_Travel); + mWindowManager.getTravelWindow()->startTravel(mPtr); + } + else if (topic == gmst.find("sSpellMakingMenuTitle")->getString()) + { + mWindowManager.pushGuiMode(GM_SpellCreation); + mWindowManager.startSpellMaking (mPtr); + } + else if (topic == gmst.find("sEnchanting")->getString()) + { + mWindowManager.pushGuiMode(GM_Enchanting); + mWindowManager.startEnchanting (mPtr); + } + else if (topic == gmst.find("sServiceTrainingTitle")->getString()) + { + mWindowManager.pushGuiMode(GM_Training); + mWindowManager.startTraining (mPtr); + } + } } void DialogueWindow::startDialogue(MWWorld::Ptr actor, std::string npcName) diff --git a/apps/openmw/mwgui/dialogue.hpp b/apps/openmw/mwgui/dialogue.hpp index e39cecc3cf..a8e0a6d174 100644 --- a/apps/openmw/mwgui/dialogue.hpp +++ b/apps/openmw/mwgui/dialogue.hpp @@ -85,7 +85,7 @@ namespace MWGui }; protected: - void onSelectTopic(std::string topic); + void onSelectTopic(const std::string& topic, int id); void onByeClicked(MyGUI::Widget* _sender); void onHistoryClicked(MyGUI::Widget* _sender); void onMouseWheel(MyGUI::Widget* _sender, int _rel); diff --git a/apps/openmw/mwgui/list.cpp b/apps/openmw/mwgui/list.cpp index 8343c302a5..c7b7207305 100644 --- a/apps/openmw/mwgui/list.cpp +++ b/apps/openmw/mwgui/list.cpp @@ -56,6 +56,7 @@ void MWList::redraw(bool scrollbarShown) } mItemHeight = 0; + int i=0; for (std::vector::const_iterator it=mItems.begin(); it!=mItems.end(); ++it) { @@ -72,6 +73,7 @@ void MWList::redraw(bool scrollbarShown) int height = button->getTextSize().height; button->setSize(MyGUI::IntSize(button->getSize().width, height)); + button->setUserData(i); mItemHeight += height + spacing; } @@ -84,6 +86,7 @@ void MWList::redraw(bool scrollbarShown) mItemHeight += 18 + spacing; } + ++i; } mScrollView->setCanvasSize(mClient->getSize().width + (_scrollBarWidth-scrollBarWidth), std::max(mItemHeight, mClient->getSize().height)); @@ -135,8 +138,8 @@ void MWList::onMouseWheel(MyGUI::Widget* _sender, int _rel) void MWList::onItemSelected(MyGUI::Widget* _sender) { std::string name = static_cast(_sender)->getCaption(); - - eventItemSelected(name); + int id = *_sender->getUserData(); + eventItemSelected(name, id); eventWidgetSelected(_sender); } diff --git a/apps/openmw/mwgui/list.hpp b/apps/openmw/mwgui/list.hpp index 40e997459d..09e42e865e 100644 --- a/apps/openmw/mwgui/list.hpp +++ b/apps/openmw/mwgui/list.hpp @@ -30,14 +30,14 @@ namespace MWGui public: MWList(); - typedef MyGUI::delegates::CMultiDelegate1 EventHandle_String; + typedef MyGUI::delegates::CMultiDelegate2 EventHandle_StringInt; typedef MyGUI::delegates::CMultiDelegate1 EventHandle_Widget; /** * Event: Item selected with the mouse. * signature: void method(std::string itemName) */ - EventHandle_String eventItemSelected; + EventHandle_StringInt eventItemSelected; /** * Event: Item selected with the mouse.