From f7cf5f9bef4746efaddf7b2ed8ea81c8d6c83cfa Mon Sep 17 00:00:00 2001 From: gugus Date: Fri, 27 Jan 2012 14:50:13 +0100 Subject: [PATCH 01/14] improved the dialogue GUI. Questions are still missing. --- apps/openmw/mwgui/dialogue.cpp | 105 ++++++++++++++++++++++++++++----- apps/openmw/mwgui/dialogue.hpp | 13 ++++ 2 files changed, 102 insertions(+), 16 deletions(-) diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index e48c142aa..39d541915 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -15,31 +15,31 @@ using namespace MWGui; using namespace Widgets; DialogueWindow::DialogueWindow(WindowManager& parWindowManager) - : WindowBase("openmw_dialogue_window_layout.xml", parWindowManager) + : WindowBase("openmw_dialogue_window_layout.xml", parWindowManager) { // Centre dialog center(); //WindowManager *wm = environment.mWindowManager; setText("NpcName", "Name of character"); - + //History view getWidget(history, "History"); history->setOverflowToTheLeft(true); history->getClient()->eventMouseButtonClick = MyGUI::newDelegate(this, &DialogueWindow::onHistoryClicked); - + //Topics list getWidget(topicsList, "TopicsList"); topicsList->setScrollVisible(true); - topicsList->eventListSelectAccept = MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic); + //topicsList->eventListSelectAccept = MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic); topicsList->eventListMouseItemActivate = MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic); - topicsList->eventListChangePosition = MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic); + //topicsList->eventListChangePosition = MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic); MyGUI::ButtonPtr byeButton; getWidget(byeButton, "ByeButton"); byeButton->eventMouseButtonClick = MyGUI::newDelegate(this, &DialogueWindow::onByeClicked); - updateOptions(); + //updateOptions(); } void DialogueWindow::onHistoryClicked(MyGUI::Widget* _sender) @@ -54,14 +54,18 @@ void DialogueWindow::onHistoryClicked(MyGUI::Widget* _sender) if(history->getColorAtPos(cursorPosition) != "#FFFFFF") { UString key = history->getColorTextAt(cursorPosition); - std::cout << "Clicked on key: " << key << std::endl; - //eventTopicSelected(key); + //std::cout << "Clicked on key: " << key << std::endl; + displayTopicText(key); } } void DialogueWindow::open() { - updateOptions(); + //updateOptions(); + topicsList->removeAllItems(); + pTopicsText.clear(); + history->eraseText(0,history->getTextLength()); + setVisible(true); } @@ -74,27 +78,96 @@ void DialogueWindow::onSelectTopic(MyGUI::List* _sender, size_t _index) { if (_index == MyGUI::ITEM_NONE) return; + std::string topic = _sender->getItem(_index); + displayTopicText(topic); //const std::string* theTopic = topicsList->getItemDataAt(_index); //std::cout << "Selected: "<< theTopic << std::endl; //eventTopicSelected(key); } +void DialogueWindow::startDialogue(std::string npcName) +{ + setText("NpcName", npcName); +} + +void DialogueWindow::addKeyword(std::string keyWord,std::string topicText) +{ + if(topicsList->findItemIndexWith(keyWord) == MyGUI::ITEM_NONE) + { + topicsList->addItem(keyWord); + pTopicsText[keyWord] = topicText; + } +} + +void DialogueWindow::removeKeyword(std::string keyWord) +{ + if(topicsList->findItemIndexWith(keyWord) != MyGUI::ITEM_NONE) + { + std::cout << topicsList->findItem(keyWord); + topicsList->removeItemAt(topicsList->findItem(keyWord)); + pTopicsText.erase(keyWord); + } +} + + +/** +*Copied from the internet. +*/ +void replaceInString(std::string& str, const std::string& oldStr, const std::string& newStr) +{ + size_t pos = 0; + while((pos = str.find(oldStr, pos)) != std::string::npos) + { + str.replace(pos, oldStr.length(), newStr); + pos += newStr.length(); + } +} + +std::string DialogueWindow::parseText(std::string text) +{ + //topicsList->geti + for(int i = 0;igetItemCount();i++) + { + std::string keyWord = topicsList->getItem(i); + std::string newKeyWord = "#FF0000"+keyWord+"#FFFFFF"; + replaceInString(text,keyWord,newKeyWord); + } + return text; +} + +void DialogueWindow::displayTopicText(std::string topic) +{ + if(topicsList->findItemIndexWith(topic) != MyGUI::ITEM_NONE) + { + history->addDialogHeading(topic); + history->addDialogText(parseText(pTopicsText[topic])); + } + else + { + std::cout << "topic not found!"; + } +} void DialogueWindow::updateOptions() { //FIXME Add this properly - history->addDialogText("Through the translucent surface of the orb, you see shifting images of distant locations..."); + /*history->addDialogText("Through the translucent surface of the orb, you see shifting images of distant locations..."); for(int z = 0; z < 10; z++) { - history->addDialogHeading("Fort Frostmoth"); - history->addDialogText("The image in the orb flickers, and you see.... The cold courtyard of #FF0000Fort Frostmoth#FFFFFF, battered bu werewolf attack, but still standing, still projecting Imperial might even to this distant and cold corner of the world."); - } + history->addDialogHeading("Fort Frostmoth"); + history->addDialogText("The image in the orb flickers, and you see.... The cold courtyard of #FF0000Fort Frostmoth#FFFFFF, battered bu werewolf attack, but still standing, still projecting Imperial might even to this distant and cold corner of the world."); + }*/ //Clear the list of topics topicsList->removeAllItems(); - int i = 0; - topicsList->addItem("Ald'ruhn", i++); + pTopicsText.clear(); + history->eraseText(0,history->getTextLength()); + + addKeyword("gus","gus is working on the dialogue system"); + + displayTopicText("gus"); + /*topicsList->addItem("Ald'ruhn", i++); topicsList->addItem("Balmora", i++); topicsList->addItem("Sadrith Mora", i++); topicsList->addItem("Vivec", i++); @@ -115,6 +188,6 @@ void DialogueWindow::updateOptions() topicsList->addItem("Tel Fyr", i++); topicsList->addItem("Tel Mora", i++); topicsList->addItem("Tel Vos", i++); - topicsList->addItem("Vos", i++); + topicsList->addItem("Vos", i++);*/ } diff --git a/apps/openmw/mwgui/dialogue.hpp b/apps/openmw/mwgui/dialogue.hpp index ddb6f8a4c..efedf0748 100644 --- a/apps/openmw/mwgui/dialogue.hpp +++ b/apps/openmw/mwgui/dialogue.hpp @@ -35,6 +35,13 @@ namespace MWGui */ EventHandle_Void eventBye; + void startDialogue(std::string npcName); + void stopDialogue(); + void addKeyword(std::string keyWord,std::string topicText); + void removeKeyword(std::string keyWord); + void addText(std::string text); + void askQuestion(); + protected: void onSelectTopic(MyGUI::List* _sender, size_t _index); void onByeClicked(MyGUI::Widget* _sender); @@ -42,9 +49,15 @@ namespace MWGui private: void updateOptions(); + /** + *Helper function that add topic keyword in blue in a text. + */ + std::string parseText(std::string text); + void displayTopicText(std::string topic); DialogeHistory* history; MyGUI::ListPtr topicsList; + std::map pTopicsText;// this map links keyword and "real" text. }; } #endif From debec44b511f7143542504761c1d5083f8aecbcf Mon Sep 17 00:00:00 2001 From: gugus Date: Sat, 28 Jan 2012 16:08:22 +0100 Subject: [PATCH 02/14] better colors (not perfect yet), and some basic question support (not finished yet). --- apps/openmw/mwgui/dialogue.cpp | 21 +++++++++++++++++---- apps/openmw/mwgui/dialogue.hpp | 2 +- apps/openmw/mwgui/dialogue_history.cpp | 4 ++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 39d541915..b94858a7b 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -51,7 +51,7 @@ void DialogueWindow::onHistoryClicked(MyGUI::Widget* _sender) const IntPoint& lastPressed = InputManager::getInstance().getLastLeftPressed(); size_t cursorPosition = t->getCursorPosition(lastPressed); - if(history->getColorAtPos(cursorPosition) != "#FFFFFF") + if(history->getColorAtPos(cursorPosition) != "#B29154") { UString key = history->getColorTextAt(cursorPosition); //std::cout << "Clicked on key: " << key << std::endl; @@ -65,7 +65,7 @@ void DialogueWindow::open() topicsList->removeAllItems(); pTopicsText.clear(); history->eraseText(0,history->getTextLength()); - + updateOptions(); setVisible(true); } @@ -130,7 +130,7 @@ std::string DialogueWindow::parseText(std::string text) for(int i = 0;igetItemCount();i++) { std::string keyWord = topicsList->getItem(i); - std::string newKeyWord = "#FF0000"+keyWord+"#FFFFFF"; + std::string newKeyWord = "#686EBA"+keyWord+"#B29154"; replaceInString(text,keyWord,newKeyWord); } return text; @@ -149,6 +149,15 @@ void DialogueWindow::displayTopicText(std::string topic) } } +void DialogueWindow::askQuestion(std::string question,std::list answers) +{ + history->addDialogText(parseText(question)); + for(std::list::iterator it = answers.begin();it!=answers.end();it++) + { + history->addDialogText("#572D21"+(*it)+"#B29154"); + } +} + void DialogueWindow::updateOptions() { //FIXME Add this properly @@ -165,8 +174,12 @@ void DialogueWindow::updateOptions() history->eraseText(0,history->getTextLength()); addKeyword("gus","gus is working on the dialogue system"); - displayTopicText("gus"); + + std::list test; + test.push_back("option 1"); + test.push_back("option 2"); + askQuestion("is gus cooking?",test); /*topicsList->addItem("Ald'ruhn", i++); topicsList->addItem("Balmora", i++); topicsList->addItem("Sadrith Mora", i++); diff --git a/apps/openmw/mwgui/dialogue.hpp b/apps/openmw/mwgui/dialogue.hpp index efedf0748..a83334e39 100644 --- a/apps/openmw/mwgui/dialogue.hpp +++ b/apps/openmw/mwgui/dialogue.hpp @@ -40,7 +40,7 @@ namespace MWGui void addKeyword(std::string keyWord,std::string topicText); void removeKeyword(std::string keyWord); void addText(std::string text); - void askQuestion(); + void askQuestion(std::string question,std::list answers); protected: void onSelectTopic(MyGUI::List* _sender, size_t _index); diff --git a/apps/openmw/mwgui/dialogue_history.cpp b/apps/openmw/mwgui/dialogue_history.cpp index aaa559d24..ceb904528 100644 --- a/apps/openmw/mwgui/dialogue_history.cpp +++ b/apps/openmw/mwgui/dialogue_history.cpp @@ -61,9 +61,9 @@ UString DialogeHistory::getColorTextAt(size_t _pos) void DialogeHistory::addDialogHeading(const UString& parText) { - UString head("\n#00FF00"); + UString head("\n#D8C09A"); head.append(parText); - head.append("#FFFFFF\n"); + head.append("#B29154\n"); addText(head); } From 5cbd256e1c9633bee716c7b03156f446e5240110 Mon Sep 17 00:00:00 2001 From: gugus Date: Sat, 28 Jan 2012 16:16:49 +0100 Subject: [PATCH 03/14] "full" question support. Now needs to be linked with the dialogue Manager. --- apps/openmw/mwgui/dialogue.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index b94858a7b..87eb3e9cf 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -51,11 +51,18 @@ void DialogueWindow::onHistoryClicked(MyGUI::Widget* _sender) const IntPoint& lastPressed = InputManager::getInstance().getLastLeftPressed(); size_t cursorPosition = t->getCursorPosition(lastPressed); - if(history->getColorAtPos(cursorPosition) != "#B29154") + MyGUI::UString color = history->getColorAtPos(cursorPosition); + if(color != "#B29154") { UString key = history->getColorTextAt(cursorPosition); + //std::cout << "Clicked on key: " << key << std::endl; - displayTopicText(key); + if(color == "#686EBA") displayTopicText(key); + if(color == "#572D21") + { + //TODO: send back the answere to the question! + std::cout << "and the ansere is..."<< key; + } } } @@ -154,7 +161,7 @@ void DialogueWindow::askQuestion(std::string question,std::list ans history->addDialogText(parseText(question)); for(std::list::iterator it = answers.begin();it!=answers.end();it++) { - history->addDialogText("#572D21"+(*it)+"#B29154"); + history->addDialogText("#572D21"+(*it)+"#B29154"+" "); } } From abe38e5f879e22e9bd451d2da50a51fba6cdf8ae Mon Sep 17 00:00:00 2001 From: gugus Date: Sun, 5 Feb 2012 10:54:56 +0100 Subject: [PATCH 04/14] Started to weire the dialogue manager and the dialogue GUI --- apps/openmw/mwdialogue/dialoguemanager.cpp | 31 +++++++++- apps/openmw/mwgui/dialogue.cpp | 61 ++++++++++++++----- apps/openmw/mwgui/dialogue.hpp | 2 + apps/openmw/mwgui/window_manager.cpp | 4 +- apps/openmw/mwgui/window_manager.hpp | 2 + extern/mygui_3.0.1/CMakeLists.txt | 1 + extern/mygui_3.0.1/openmw_resources/core.xml | 1 + .../openmw_dialogue_window_layout.xml | 7 ++- .../openmw_dialogue_window_skin.xml | 18 ++++++ 9 files changed, 106 insertions(+), 21 deletions(-) create mode 100644 extern/mygui_3.0.1/openmw_resources/openmw_dialogue_window_skin.xml diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index f78160cd7..6665c30aa 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -16,6 +16,8 @@ #include "../mwworld/player.hpp" #include "../mwinput/inputmanager.hpp" +#include "../mwgui/dialogue.hpp" +#include "../mwgui/window_manager.hpp" #include @@ -236,13 +238,13 @@ namespace MWDialogue if (!isMatching (actor, *iter)) return false; - std::cout + /*std::cout << "unchecked entries:" << std::endl << " player faction: " << info.pcFaction << std::endl << " disposition: " << info.data.disposition << std::endl << " NPC rank: " << static_cast (info.data.rank) << std::endl << " gender: " << static_cast (info.data.gender) << std::endl - << " PC rank: " << static_cast (info.data.PCrank) << std::endl; + << " PC rank: " << static_cast (info.data.PCrank) << std::endl;*/ return true; } @@ -254,7 +256,7 @@ namespace MWDialogue std::cout << "talking with " << MWWorld::Class::get (actor).getName (actor) << std::endl; const ESM::Dialogue *dialogue = mEnvironment.mWorld->getStore().dialogs.find ("hello"); - + for (std::vector::const_iterator iter (dialogue->mInfo.begin()); iter!=dialogue->mInfo.end(); ++iter) { @@ -277,9 +279,32 @@ namespace MWDialogue } mEnvironment.mInputManager->setGuiMode(MWGui::GM_Dialogue); + MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); + win->startDialogue(MWWorld::Class::get (actor).getName (actor)); + win->addText(iter->response); break; } } + + ESMS::RecListT::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list; + for(ESMS::RecListT::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++) + { + ESM::Dialogue ndialogue = it->second; + if(ndialogue.type == ESM::Dialogue::Type::Topic) + { + for (std::vector::const_iterator iter (it->second.mInfo.begin()); + iter!=it->second.mInfo.end(); ++iter) + { + if (isMatching (actor, *iter)) + { + MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); + win->addKeyword(it->first,iter->response); + //std::cout << "match found!!"; + break; + } + } + } + } } } diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index 87eb3e9cf..acb04e53c 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -14,6 +14,23 @@ using namespace MWGui; using namespace Widgets; +/** +*Copied from the internet. +*/ + +std::string lower_string(const std::string& str) +{ + std::string lower; + std::transform(str.begin(), str.end(), std::back_inserter(lower), std::tolower); + return lower; +} + +std::string::size_type find_str_ci(const std::string& str, const std::string& substr,size_t pos) +{ + return lower_string(str).find(lower_string(substr),pos); +} + + DialogueWindow::DialogueWindow(WindowManager& parWindowManager) : WindowBase("openmw_dialogue_window_layout.xml", parWindowManager) { @@ -39,7 +56,9 @@ DialogueWindow::DialogueWindow(WindowManager& parWindowManager) getWidget(byeButton, "ByeButton"); byeButton->eventMouseButtonClick = MyGUI::newDelegate(this, &DialogueWindow::onByeClicked); - //updateOptions(); + getWidget(pDispositionBar, "Disposition"); + getWidget(pDispositionText,"DispositionText"); + std::cout << "creation dialogue"; } void DialogueWindow::onHistoryClicked(MyGUI::Widget* _sender) @@ -57,7 +76,7 @@ void DialogueWindow::onHistoryClicked(MyGUI::Widget* _sender) UString key = history->getColorTextAt(cursorPosition); //std::cout << "Clicked on key: " << key << std::endl; - if(color == "#686EBA") displayTopicText(key); + if(color == "#686EBA") displayTopicText(lower_string(key)); if(color == "#572D21") { //TODO: send back the answere to the question! @@ -117,17 +136,17 @@ void DialogueWindow::removeKeyword(std::string keyWord) } } - -/** -*Copied from the internet. -*/ -void replaceInString(std::string& str, const std::string& oldStr, const std::string& newStr) +void addColorInString(std::string& str, const std::string& keyword,std::string color1, std::string color2) { size_t pos = 0; - while((pos = str.find(oldStr, pos)) != std::string::npos) + while((pos = find_str_ci(str,keyword, pos)) != std::string::npos) { - str.replace(pos, oldStr.length(), newStr); - pos += newStr.length(); + //str.replace(pos, oldStr.length(), "#686EBA"+str.get); + str.insert(pos,color1); + pos += color1.length(); + pos += keyword.length(); + str.insert(pos,color2); + pos+= color2.length(); } } @@ -137,8 +156,8 @@ std::string DialogueWindow::parseText(std::string text) for(int i = 0;igetItemCount();i++) { std::string keyWord = topicsList->getItem(i); - std::string newKeyWord = "#686EBA"+keyWord+"#B29154"; - replaceInString(text,keyWord,newKeyWord); + //std::string newKeyWord = "#686EBA"+keyWord+"#B29154"; + addColorInString(text,keyWord,"#686EBA","#B29154"); } return text; } @@ -156,6 +175,11 @@ void DialogueWindow::displayTopicText(std::string topic) } } +void DialogueWindow::addText(std::string text) +{ + history->addDialogText(parseText(text)); +} + void DialogueWindow::askQuestion(std::string question,std::list answers) { history->addDialogText(parseText(question)); @@ -180,13 +204,18 @@ void DialogueWindow::updateOptions() pTopicsText.clear(); history->eraseText(0,history->getTextLength()); - addKeyword("gus","gus is working on the dialogue system"); - displayTopicText("gus"); + /*addKeyword("gus","gus is working on the dialogue system"); + displayTopicText("gus");*/ + + pDispositionBar->setProgressRange(100); + pDispositionBar->setProgressPosition(40); + pDispositionText->eraseText(0,pDispositionText->getTextLength()); + pDispositionText->addText("#B29154"+std::string("40/100")+"#B29154"); - std::list test; + /*std::list test; test.push_back("option 1"); test.push_back("option 2"); - askQuestion("is gus cooking?",test); + askQuestion("is gus cooking?",test);*/ /*topicsList->addItem("Ald'ruhn", i++); topicsList->addItem("Balmora", i++); topicsList->addItem("Sadrith Mora", i++); diff --git a/apps/openmw/mwgui/dialogue.hpp b/apps/openmw/mwgui/dialogue.hpp index a83334e39..9518edcde 100644 --- a/apps/openmw/mwgui/dialogue.hpp +++ b/apps/openmw/mwgui/dialogue.hpp @@ -57,6 +57,8 @@ namespace MWGui DialogeHistory* history; MyGUI::ListPtr topicsList; + MyGUI::ProgressPtr pDispositionBar; + MyGUI::EditPtr pDispositionText; std::map pTopicsText;// this map links keyword and "real" text. }; } diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index d16611794..f1db1654e 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -472,6 +472,7 @@ void WindowManager::updateSkillArea() void WindowManager::removeDialog(OEngine::GUI::Layout*dialog) { + std::cout << "dialogue a la poubelle"; assert(dialog); if (!dialog) return; @@ -553,7 +554,8 @@ void WindowManager::onDialogueWindowBye() if (dialogueWindow) { //FIXME set some state and stuff? - removeDialog(dialogueWindow); + //removeDialog(dialogueWindow); + dialogueWindow->setVisible(false); } setGuiMode(GM_Game); } diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index a47e53fed..9dbe72eab 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -207,6 +207,8 @@ namespace MWGui updateVisible(); } + MWGui::DialogueWindow* getDialogueWindow() {return dialogueWindow;} + MyGUI::Gui* getGui() const { return gui; } void wmUpdateFps(float fps, size_t triangleCount, size_t batchCount) diff --git a/extern/mygui_3.0.1/CMakeLists.txt b/extern/mygui_3.0.1/CMakeLists.txt index 2cbe8aabe..6a96bd367 100644 --- a/extern/mygui_3.0.1/CMakeLists.txt +++ b/extern/mygui_3.0.1/CMakeLists.txt @@ -54,6 +54,7 @@ configure_file("${SDIR}/openmw_chargen_class_description_layout.xml" "${DDIR}/op configure_file("${SDIR}/openmw_chargen_birth_layout.xml" "${DDIR}/openmw_chargen_birth_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_chargen_review_layout.xml" "${DDIR}/openmw_chargen_review_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_dialogue_window_layout.xml" "${DDIR}/openmw_dialogue_window_layout.xml" COPYONLY) +configure_file("${SDIR}/openmw_dialogue_window_skin.xml" "${DDIR}/openmw_dialogue_window_skin.xml" COPYONLY) configure_file("${SDIR}/openmw_inventory_window_layout.xml" "${DDIR}/openmw_inventory_window_layout.xml" COPYONLY) configure_file("${SDIR}/openmw_layers.xml" "${DDIR}/openmw_layers.xml" COPYONLY) configure_file("${SDIR}/openmw_mainmenu_layout.xml" "${DDIR}/openmw_mainmenu_layout.xml" COPYONLY) diff --git a/extern/mygui_3.0.1/openmw_resources/core.xml b/extern/mygui_3.0.1/openmw_resources/core.xml index 31d409a35..e98b20d3a 100644 --- a/extern/mygui_3.0.1/openmw_resources/core.xml +++ b/extern/mygui_3.0.1/openmw_resources/core.xml @@ -20,6 +20,7 @@ + diff --git a/extern/mygui_3.0.1/openmw_resources/openmw_dialogue_window_layout.xml b/extern/mygui_3.0.1/openmw_resources/openmw_dialogue_window_layout.xml index 2987e82be..44642167b 100644 --- a/extern/mygui_3.0.1/openmw_resources/openmw_dialogue_window_layout.xml +++ b/extern/mygui_3.0.1/openmw_resources/openmw_dialogue_window_layout.xml @@ -17,8 +17,13 @@ + + + + - + diff --git a/extern/mygui_3.0.1/openmw_resources/openmw_dialogue_window_skin.xml b/extern/mygui_3.0.1/openmw_resources/openmw_dialogue_window_skin.xml new file mode 100644 index 000000000..25e0b8659 --- /dev/null +++ b/extern/mygui_3.0.1/openmw_resources/openmw_dialogue_window_skin.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file From c65c160e7b2eebed85a45bb5732f4b2c1aca60ab Mon Sep 17 00:00:00 2001 From: gugus Date: Sun, 5 Feb 2012 12:25:23 +0100 Subject: [PATCH 05/14] finished connecting the dialogue GUI and the dialogue manager --- apps/openmw/mwdialogue/dialoguemanager.cpp | 15 +++++++++++++++ apps/openmw/mwdialogue/dialoguemanager.hpp | 5 +++++ apps/openmw/mwgui/dialogue.cpp | 20 +++++++++++++++----- apps/openmw/mwgui/dialogue.hpp | 9 ++++++++- apps/openmw/mwgui/window_manager.cpp | 7 ++----- 5 files changed, 45 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index 6665c30aa..7ffb7f29b 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -307,4 +307,19 @@ namespace MWDialogue } } + void DialogueManager::keywordSelected(std::string keyword) + { + std::cout << "keyword" << keyword; + } + + void DialogueManager::goodbyeSelected() + { + mEnvironment.mInputManager->setGuiMode(MWGui::GM_Game); + } + + void DialogueManager::questionAnswered(std::string answere) + { + std::cout << "and the ansere is..."<< answere; + } + } diff --git a/apps/openmw/mwdialogue/dialoguemanager.hpp b/apps/openmw/mwdialogue/dialoguemanager.hpp index 5b6b26240..0e06838e6 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.hpp +++ b/apps/openmw/mwdialogue/dialoguemanager.hpp @@ -26,6 +26,11 @@ namespace MWDialogue void startDialogue (const MWWorld::Ptr& actor); + //calbacks for the GUI + void keywordSelected(std::string keyword); + void goodbyeSelected(); + void questionAnswered(std::string answere); + }; } diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index acb04e53c..c4cebaa67 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -3,6 +3,8 @@ #include "window_manager.hpp" #include "widgets.hpp" #include "components/esm_store/store.hpp" +#include "../mwworld/environment.hpp" +#include "../mwdialogue/dialoguemanager.hpp" #include #include @@ -31,8 +33,9 @@ std::string::size_type find_str_ci(const std::string& str, const std::string& su } -DialogueWindow::DialogueWindow(WindowManager& parWindowManager) - : WindowBase("openmw_dialogue_window_layout.xml", parWindowManager) +DialogueWindow::DialogueWindow(WindowManager& parWindowManager,MWWorld::Environment& environment) + : WindowBase("openmw_dialogue_window_layout.xml", parWindowManager), + mEnvironment(environment) { // Centre dialog center(); @@ -76,11 +79,16 @@ void DialogueWindow::onHistoryClicked(MyGUI::Widget* _sender) UString key = history->getColorTextAt(cursorPosition); //std::cout << "Clicked on key: " << key << std::endl; - if(color == "#686EBA") displayTopicText(lower_string(key)); + if(color == "#686EBA") + { + mEnvironment.mDialogueManager->keywordSelected(lower_string(key)); + displayTopicText(lower_string(key)); + } if(color == "#572D21") { //TODO: send back the answere to the question! - std::cout << "and the ansere is..."<< key; + mEnvironment.mDialogueManager->questionAnswered(key); + //std::cout << "and the ansere is..."<< key; } } } @@ -97,7 +105,8 @@ void DialogueWindow::open() void DialogueWindow::onByeClicked(MyGUI::Widget* _sender) { - eventBye(); + //eventBye(); + mEnvironment.mDialogueManager->goodbyeSelected(); } void DialogueWindow::onSelectTopic(MyGUI::List* _sender, size_t _index) @@ -105,6 +114,7 @@ void DialogueWindow::onSelectTopic(MyGUI::List* _sender, size_t _index) if (_index == MyGUI::ITEM_NONE) return; std::string topic = _sender->getItem(_index); + mEnvironment.mDialogueManager->keywordSelected(lower_string(topic)); displayTopicText(topic); //const std::string* theTopic = topicsList->getItemDataAt(_index); diff --git a/apps/openmw/mwgui/dialogue.hpp b/apps/openmw/mwgui/dialogue.hpp index 9518edcde..232721f0a 100644 --- a/apps/openmw/mwgui/dialogue.hpp +++ b/apps/openmw/mwgui/dialogue.hpp @@ -9,6 +9,11 @@ namespace MWGui class WindowManager; } +namespace MWWorld +{ + class Environment; +} + /* This file contains the dialouge window Layout is defined by resources/mygui/openmw_dialogue_window_layout.xml. @@ -23,7 +28,7 @@ namespace MWGui class DialogueWindow: public WindowBase { public: - DialogueWindow(WindowManager& parWindowManager); + DialogueWindow(WindowManager& parWindowManager,MWWorld::Environment& environment); void open(); @@ -60,6 +65,8 @@ namespace MWGui MyGUI::ProgressPtr pDispositionBar; MyGUI::EditPtr pDispositionText; std::map pTopicsText;// this map links keyword and "real" text. + + MWWorld::Environment& mEnvironment; }; } #endif diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index f1db1654e..5302489f1 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -64,6 +64,7 @@ WindowManager::WindowManager(MyGUI::Gui *_gui, MWWorld::Environment& environment console = new Console(w,h, environment, extensions); mJournal = new JournalWindow(*this); mMessageBoxManager = new MessageBoxManager(this); + dialogueWindow = new DialogueWindow(*this,environment); // The HUD is always on hud->setVisible(true); @@ -173,6 +174,7 @@ void WindowManager::updateVisible() #endif console->disable(); mJournal->setVisible(false); + dialogueWindow->setVisible(false); // Mouse is visible whenever we're not in game mode gui->setVisiblePointer(isGuiMode()); @@ -338,11 +340,6 @@ void WindowManager::updateVisible() if (mode == GM_Dialogue) { - if (!dialogueWindow) - { - dialogueWindow = new DialogueWindow(*this); - dialogueWindow->eventBye = MyGUI::newDelegate(this, &WindowManager::onDialogueWindowBye); - } dialogueWindow->open(); return; } From f76e0e19411be73ea12df2c0c8f652729bdb04ef Mon Sep 17 00:00:00 2001 From: gugus Date: Wed, 8 Feb 2012 00:32:22 +0100 Subject: [PATCH 06/14] corrected the light problem --- apps/openmw/mwrender/renderingmanager.cpp | 13 +++++++++---- apps/openmw/mwrender/renderingmanager.hpp | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index 6215c1913..adc0b23f9 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -54,10 +54,12 @@ RenderingManager::RenderingManager (OEngine::Render::OgreRenderer& _rend, const cameraPitchNode->attachObject(mRendering.getCamera()); mPlayer = new MWRender::Player (mRendering.getCamera(), playerNode); + mSun = 0; } RenderingManager::~RenderingManager () { + //TODO: destroy mSun? delete mPlayer; delete mSkyManager; } @@ -204,12 +206,15 @@ void RenderingManager::configureAmbient(ESMS::CellStore &mCell // Create a "sun" that shines light downwards. It doesn't look // completely right, but leave it for now. - Ogre::Light *light = mRendering.getScene()->createLight(); + if(!mSun) + { + mSun = mRendering.getScene()->createLight(); + } Ogre::ColourValue colour; colour.setAsABGR (mCell.cell->ambi.sunlight); - light->setDiffuseColour (colour); - light->setType(Ogre::Light::LT_DIRECTIONAL); - light->setDirection(0,-1,0); + mSun->setDiffuseColour (colour); + mSun->setType(Ogre::Light::LT_DIRECTIONAL); + mSun->setDirection(0,-1,0); } // Switch through lighting modes. diff --git a/apps/openmw/mwrender/renderingmanager.hpp b/apps/openmw/mwrender/renderingmanager.hpp index 747a3e0ee..f25dbfb54 100644 --- a/apps/openmw/mwrender/renderingmanager.hpp +++ b/apps/openmw/mwrender/renderingmanager.hpp @@ -120,6 +120,7 @@ class RenderingManager: private RenderingInterface { int mAmbientMode; Ogre::ColourValue mAmbientColor; + Ogre::Light* mSun; /// Root node for all objects added to the scene. This is rotated so /// that the OGRE coordinate system matches that used internally in From e7ef39cabc08a2b573687e3bab4df69062e6e43d Mon Sep 17 00:00:00 2001 From: gugus Date: Thu, 9 Feb 2012 19:27:15 +0100 Subject: [PATCH 07/14] more improvements to dialogue filters. Some of them are still missing. --- apps/openmw/mwdialogue/dialoguemanager.cpp | 153 ++++++++++++++++++++- apps/openmw/mwdialogue/dialoguemanager.hpp | 3 + 2 files changed, 151 insertions(+), 5 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index 7ffb7f29b..d98b295f3 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -9,6 +9,7 @@ #include + #include "../mwworld/class.hpp" #include "../mwworld/environment.hpp" #include "../mwworld/world.hpp" @@ -19,6 +20,8 @@ #include "../mwgui/dialogue.hpp" #include "../mwgui/window_manager.hpp" +#include "journal.hpp" + #include namespace @@ -128,7 +131,7 @@ namespace MWDialogue std::string name = select.selectRule.substr (5); // TODO types 4, 5, 6, 7, 8, 9, A, B, C - + //new TOTO: 5,6,9 switch (type) { case '1': // function @@ -169,12 +172,122 @@ namespace MWDialogue mEnvironment.mWorld->getStore())) return false; } + else + throw std::runtime_error ( + "unsupported variable type in dialogue info select"); + + return true; + + case '4'://journal + if(select.type==ESM::VT_Int) + { + //std::cout << "vtint: " << select.i << std::endl; + bool isInJournal; + if(mEnvironment.mJournal->begin()!=mEnvironment.mJournal->end()) + { + for(std::deque::const_iterator it = mEnvironment.mJournal->begin();it!=mEnvironment.mJournal->end();it++) + { + + if(it->mTopic == name) isInJournal = true; + } + } + else + isInJournal = false; + if(!selectCompare(comp,int(isInJournal),select.i)) return false; + } + else + throw std::runtime_error ( + "unsupported variable type in dialogue info select"); + + return true; + + case '7':// not ID + if(select.type==ESM::VT_String ||select.type==ESM::VT_Int)//bug in morrowind here? it's not a short, it's a string + { + int isID = int(toLower(name)==toLower(MWWorld::Class::get (actor).getId (actor))); + if (selectCompare(comp,!isID,select.i)) return false; + } + else + throw std::runtime_error ( + "unsupported variable type in dialogue info select"); + + return true; + + case '8':// not faction + if(select.type==ESM::VT_Int) + { + ESMS::LiveCellRef* npc = actor.get(); + int isFaction = int(toLower(npc->base->faction) == toLower(name)); + if(selectCompare(comp,!isFaction,select.i)) + return false; + } + else + throw std::runtime_error ( + "unsupported variable type in dialogue info select"); + + return true; + + case '9':// not class + if(select.type==ESM::VT_Int) + { + ESMS::LiveCellRef* npc = actor.get(); + int isClass = int(toLower(npc->base->cls) == toLower(name)); + if(selectCompare(comp,!isClass,select.i)) + return false; + } + else + throw std::runtime_error ( + "unsupported variable type in dialogue info select"); + + return true; + + case 'A'://not Race + if(select.type==ESM::VT_Int) + { + ESMS::LiveCellRef* npc = actor.get(); + int isRace = int(toLower(npc->base->race) == toLower(name)); + //std::cout << "isRace"<(comp,!isRace,select.i)) + return false; + } else throw std::runtime_error ( "unsupported variable type in dialogue info select"); return true; + case 'B'://not Cell + if(select.type==ESM::VT_Int) + { + int isCell = int(toLower(actor.getCell()->cell->name) == toLower(name)); + if(selectCompare(comp,!isCell,select.i)) + return false; + } + else + throw std::runtime_error ( + "unsupported variable type in dialogue info select"); + return true; + + case 'C'://not local + if (select.type==ESM::VT_Short || select.type==ESM::VT_Int || + select.type==ESM::VT_Long) + { + if (checkLocal (comp, toLower (name), select.i, actor, + mEnvironment.mWorld->getStore())) + return false; + } + else if (select.type==ESM::VT_Float) + { + if (checkLocal (comp, toLower (name), select.f, actor, + mEnvironment.mWorld->getStore())) + return false; + } + else + throw std::runtime_error ( + "unsupported variable type in dialogue info select"); + return true; + + default: std::cout << "unchecked select: " << type << " " << comp << " " << name << std::endl; @@ -186,11 +299,13 @@ namespace MWDialogue bool DialogueManager::isMatching (const MWWorld::Ptr& actor, const ESM::DialInfo& info) const { + //bool return true;//does the actor knows the topic? // actor id if (!info.actor.empty()) if (toLower (info.actor)!=MWWorld::Class::get (actor).getId (actor)) return false; + //NPC race if (!info.race.empty()) { ESMS::LiveCellRef *cellRef = actor.get(); @@ -202,6 +317,7 @@ namespace MWDialogue return false; } + //NPC class if (!info.clas.empty()) { ESMS::LiveCellRef *cellRef = actor.get(); @@ -213,6 +329,7 @@ namespace MWDialogue return false; } + //NPC faction if (!info.npcFaction.empty()) { ESMS::LiveCellRef *cellRef = actor.get(); @@ -222,10 +339,32 @@ namespace MWDialogue if (toLower (info.npcFaction)!=toLower (cellRef->base->faction)) return false; + + //check NPC rank + if(cellRef->base->npdt52.gold != -10) + { + if(cellRef->base->npdt52.rank < info.data.rank) return false; + } + else + { + if(cellRef->base->npdt12.rank < info.data.rank) return false; + } } // TODO check player faction + //check gender + ESMS::LiveCellRef* npc = actor.get(); + if(npc->base->flags&npc->base->Female) + { + if(static_cast (info.data.gender)==0) return false; + } + else + { + if(static_cast (info.data.gender)==1) return false; + } + + // check cell if (!info.cell.empty()) if (mEnvironment.mWorld->getPlayer().getPlayer().getCell()->cell->name != info.cell) @@ -297,10 +436,14 @@ namespace MWDialogue { if (isMatching (actor, *iter)) { - MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); - win->addKeyword(it->first,iter->response); - //std::cout << "match found!!"; - break; + if(knownTopics.find(toLower(it->first)) != knownTopics.end()) + { + MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); + win->addKeyword(it->first,iter->response); + //std::cout << it->first; + //std::cout << "match found!!"; + break; + } } } } diff --git a/apps/openmw/mwdialogue/dialoguemanager.hpp b/apps/openmw/mwdialogue/dialoguemanager.hpp index 0e06838e6..7579ce7e4 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.hpp +++ b/apps/openmw/mwdialogue/dialoguemanager.hpp @@ -4,6 +4,7 @@ #include #include "../mwworld/ptr.hpp" +#include namespace MWWorld { @@ -20,6 +21,8 @@ namespace MWDialogue bool isMatching (const MWWorld::Ptr& actor, const ESM::DialInfo& info) const; + std::map knownTopics;// Those are the topics the player knows. + public: DialogueManager (MWWorld::Environment& environment); From ea8335a393c4fb1223d25fae1dec5b8f3e4b4b61 Mon Sep 17 00:00:00 2001 From: gugus Date: Fri, 10 Feb 2012 16:09:43 +0100 Subject: [PATCH 08/14] addTopic function --- apps/openmw/mwdialogue/dialoguemanager.cpp | 5 +++++ apps/openmw/mwdialogue/dialoguemanager.hpp | 2 ++ 2 files changed, 7 insertions(+) diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index d98b295f3..053e3987b 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -390,6 +390,11 @@ namespace MWDialogue DialogueManager::DialogueManager (MWWorld::Environment& environment) : mEnvironment (environment) {} + void DialogueManager::addTopic(std::string topic) + { + knownTopics[toLower(topic)] = true; + } + void DialogueManager::startDialogue (const MWWorld::Ptr& actor) { std::cout << "talking with " << MWWorld::Class::get (actor).getName (actor) << std::endl; diff --git a/apps/openmw/mwdialogue/dialoguemanager.hpp b/apps/openmw/mwdialogue/dialoguemanager.hpp index 7579ce7e4..cafad7c6e 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.hpp +++ b/apps/openmw/mwdialogue/dialoguemanager.hpp @@ -29,6 +29,8 @@ namespace MWDialogue void startDialogue (const MWWorld::Ptr& actor); + void addTopic(std::string topic); + //calbacks for the GUI void keywordSelected(std::string keyword); void goodbyeSelected(); From 94ab65f8bb7d4bd00e7a9919cedb77feb6cc6be9 Mon Sep 17 00:00:00 2001 From: gugus Date: Fri, 10 Feb 2012 16:21:04 +0100 Subject: [PATCH 09/14] fixe a compiling error? --- apps/openmw/mwgui/dialogue.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index c4cebaa67..ddd76bbee 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -22,9 +22,12 @@ using namespace Widgets; std::string lower_string(const std::string& str) { - std::string lower; - std::transform(str.begin(), str.end(), std::back_inserter(lower), std::tolower); - return lower; + std::string lowerCase; + + std::transform (str.begin(), str.end(), std::back_inserter (lowerCase), + (int(*)(int)) std::tolower); + + return lowerCase; } std::string::size_type find_str_ci(const std::string& str, const std::string& substr,size_t pos) From 554bf8e58601483b3fc4b520972e4b2137cc6fda Mon Sep 17 00:00:00 2001 From: gugus Date: Fri, 10 Feb 2012 22:01:31 +0100 Subject: [PATCH 10/14] Improvement in the dialogue manager --- apps/openmw/mwdialogue/dialoguemanager.cpp | 78 ++++++++++++++-------- apps/openmw/mwdialogue/dialoguemanager.hpp | 1 + 2 files changed, 50 insertions(+), 29 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index 053e3987b..8e7077870 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -36,6 +36,7 @@ namespace return lowerCase; } + template bool selectCompare (char comp, T1 value1, T2 value2) { @@ -399,8 +400,39 @@ namespace MWDialogue { std::cout << "talking with " << MWWorld::Class::get (actor).getName (actor) << std::endl; + //initialise the GUI + mEnvironment.mInputManager->setGuiMode(MWGui::GM_Dialogue); + MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); + win->startDialogue(MWWorld::Class::get (actor).getName (actor)); + + actorKnownTopics.clear(); + ESMS::RecListT::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list; + for(ESMS::RecListT::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++) + { + ESM::Dialogue ndialogue = it->second; + if(ndialogue.type == ESM::Dialogue::Type::Topic) + { + for (std::vector::const_iterator iter (it->second.mInfo.begin()); + iter!=it->second.mInfo.end(); ++iter) + { + if (isMatching (actor, *iter)) + { + actorKnownTopics[it->first] = iter->response; + if(knownTopics.find(toLower(it->first)) != knownTopics.end()) + { + MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); + win->addKeyword(it->first,iter->response); + //std::cout << it->first; + //std::cout << "match found!!"; + break; + } + } + } + } + } + const ESM::Dialogue *dialogue = mEnvironment.mWorld->getStore().dialogs.find ("hello"); - + for (std::vector::const_iterator iter (dialogue->mInfo.begin()); iter!=dialogue->mInfo.end(); ++iter) { @@ -421,43 +453,31 @@ namespace MWDialogue std::cout << "script: " << iter->resultScript << std::endl; // TODO execute script } - - mEnvironment.mInputManager->setGuiMode(MWGui::GM_Dialogue); - MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); - win->startDialogue(MWWorld::Class::get (actor).getName (actor)); win->addText(iter->response); break; } } + } - ESMS::RecListT::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list; - for(ESMS::RecListT::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++) - { - ESM::Dialogue ndialogue = it->second; - if(ndialogue.type == ESM::Dialogue::Type::Topic) - { - for (std::vector::const_iterator iter (it->second.mInfo.begin()); - iter!=it->second.mInfo.end(); ++iter) - { - if (isMatching (actor, *iter)) - { - if(knownTopics.find(toLower(it->first)) != knownTopics.end()) - { - MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); - win->addKeyword(it->first,iter->response); - //std::cout << it->first; - //std::cout << "match found!!"; - break; - } - } - } - } - } + //helper function + std::string::size_type find_str_ci(const std::string& str, const std::string& substr,size_t pos) + { + return toLower(str).find(toLower(substr),pos); } void DialogueManager::keywordSelected(std::string keyword) { - std::cout << "keyword" << keyword; + std::string text = actorKnownTopics[keyword]; + std::map::iterator it; + for(it = actorKnownTopics.begin();it != actorKnownTopics.end();it++) + { + if(find_str_ci(text,it->second,0) !=std::string::npos) + { + knownTopics[it->first] = true; + MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); + win->addKeyword(it->first,it->second); + } + } } void DialogueManager::goodbyeSelected() diff --git a/apps/openmw/mwdialogue/dialoguemanager.hpp b/apps/openmw/mwdialogue/dialoguemanager.hpp index cafad7c6e..88ae9e35c 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.hpp +++ b/apps/openmw/mwdialogue/dialoguemanager.hpp @@ -22,6 +22,7 @@ namespace MWDialogue bool isMatching (const MWWorld::Ptr& actor, const ESM::DialInfo& info) const; std::map knownTopics;// Those are the topics the player knows. + std::map actorKnownTopics; public: From f1dc36072026e9943c5a858b9e0a6688fdaa02bc Mon Sep 17 00:00:00 2001 From: gugus Date: Fri, 10 Feb 2012 22:02:24 +0100 Subject: [PATCH 11/14] added the script instruction addTopic --- apps/openmw/mwscript/dialogueextensions.cpp | 20 ++++++++++++++++++++ apps/openmw/mwscript/docs/vmformat.txt | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwscript/dialogueextensions.cpp b/apps/openmw/mwscript/dialogueextensions.cpp index c2ff9ed8b..26fb6d9be 100644 --- a/apps/openmw/mwscript/dialogueextensions.cpp +++ b/apps/openmw/mwscript/dialogueextensions.cpp @@ -8,6 +8,7 @@ #include #include "../mwdialogue/journal.hpp" +#include "../mwdialogue/dialoguemanager.hpp" #include "interpretercontext.hpp" @@ -72,15 +73,33 @@ namespace MWScript } }; + class OpAddTopic : public Interpreter::Opcode0 + { + public: + + virtual void execute (Interpreter::Runtime& runtime) + { + MWScript::InterpreterContext& context + = static_cast (runtime.getContext()); + + std::string topic = runtime.getStringLiteral (runtime[0].mInteger); + runtime.pop(); + + context.getEnvironment().mDialogueManager->addTopic(topic); + } + }; + const int opcodeJournal = 0x2000133; const int opcodeSetJournalIndex = 0x2000134; const int opcodeGetJournalIndex = 0x2000135; + const int opcodeAddTopic = 0x200013a; void registerExtensions (Compiler::Extensions& extensions) { extensions.registerInstruction ("journal", "cl", opcodeJournal); extensions.registerInstruction ("setjournalindex", "cl", opcodeSetJournalIndex); extensions.registerFunction ("getjournalindex", 'l', "c", opcodeGetJournalIndex); + extensions.registerInstruction ("addtopic", "S" , opcodeAddTopic); } void installOpcodes (Interpreter::Interpreter& interpreter) @@ -88,6 +107,7 @@ namespace MWScript interpreter.installSegment5 (opcodeJournal, new OpJournal); interpreter.installSegment5 (opcodeSetJournalIndex, new OpSetJournalIndex); interpreter.installSegment5 (opcodeGetJournalIndex, new OpGetJournalIndex); + interpreter.installSegment5 (opcodeAddTopic, new OpAddTopic); } } diff --git a/apps/openmw/mwscript/docs/vmformat.txt b/apps/openmw/mwscript/docs/vmformat.txt index 183605328..1f033c8db 100644 --- a/apps/openmw/mwscript/docs/vmformat.txt +++ b/apps/openmw/mwscript/docs/vmformat.txt @@ -115,4 +115,5 @@ op 0x2000136: GetPCCell op 0x2000137: GetButtonPressed op 0x2000138: SkipAnim op 0x2000139: SkipAnim, expplicit reference -opcodes 0x200013a-0x3ffffff unused +op 0x200013a: AddTopic +opcodes 0x200013b-0x3ffffff unused From eee5d20809a3d538c5f03d6650dfbd6f7d28dd3f Mon Sep 17 00:00:00 2001 From: gugus Date: Fri, 10 Feb 2012 22:54:17 +0100 Subject: [PATCH 12/14] a little fix --- apps/openmw/mwdialogue/dialoguemanager.cpp | 36 +++++++++++++++------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index 8e7077870..df8543032 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -121,6 +121,14 @@ namespace namespace MWDialogue { + + //helper function + std::string::size_type find_str_ci(const std::string& str, const std::string& substr,size_t pos) + { + return toLower(str).find(toLower(substr),pos); + } + + bool DialogueManager::isMatching (const MWWorld::Ptr& actor, const ESM::DialInfo::SelectStruct& select) const { @@ -439,9 +447,9 @@ namespace MWDialogue if (isMatching (actor, *iter)) { // start dialogue - std::cout << "found matching info record" << std::endl; + //std::cout << "found matching info record" << std::endl; - std::cout << "response: " << iter->response << std::endl; + //std::cout << "response: " << iter->response << std::endl; if (!iter->sound.empty()) { @@ -450,28 +458,34 @@ namespace MWDialogue if (!iter->resultScript.empty()) { - std::cout << "script: " << iter->resultScript << std::endl; + //std::cout << "script: " << iter->resultScript << std::endl; // TODO execute script } + std::string text = iter->response; + std::map::iterator it; + for(it = actorKnownTopics.begin();it != actorKnownTopics.end();it++) + { + if(find_str_ci(text,it->first,0) !=std::string::npos) + { + std::cout << "fouuuuuuuuuuund"; + knownTopics[it->first] = true; + MWGui::DialogueWindow* win2 = mEnvironment.mWindowManager->getDialogueWindow(); + win2->addKeyword(it->first,it->second); + } + } win->addText(iter->response); - break; + //break; } } } - //helper function - std::string::size_type find_str_ci(const std::string& str, const std::string& substr,size_t pos) - { - return toLower(str).find(toLower(substr),pos); - } - void DialogueManager::keywordSelected(std::string keyword) { std::string text = actorKnownTopics[keyword]; std::map::iterator it; for(it = actorKnownTopics.begin();it != actorKnownTopics.end();it++) { - if(find_str_ci(text,it->second,0) !=std::string::npos) + if(find_str_ci(text,it->first,0) !=std::string::npos) { knownTopics[it->first] = true; MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); From 4658ec276f87f63024daace58759b98821bcc622 Mon Sep 17 00:00:00 2001 From: gugus Date: Sat, 11 Feb 2012 12:18:47 +0100 Subject: [PATCH 13/14] increased the max size of the text of the dialogue --- apps/openmw/mwgui/dialogue.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/openmw/mwgui/dialogue.cpp b/apps/openmw/mwgui/dialogue.cpp index ddd76bbee..5754d1d7e 100644 --- a/apps/openmw/mwgui/dialogue.cpp +++ b/apps/openmw/mwgui/dialogue.cpp @@ -50,7 +50,7 @@ DialogueWindow::DialogueWindow(WindowManager& parWindowManager,MWWorld::Environm getWidget(history, "History"); history->setOverflowToTheLeft(true); history->getClient()->eventMouseButtonClick = MyGUI::newDelegate(this, &DialogueWindow::onHistoryClicked); - + history->setMaxTextLength(1000000); //Topics list getWidget(topicsList, "TopicsList"); topicsList->setScrollVisible(true); From 4d4ae41a4a2a2af504e1e69e6dd8b933d3ce9b41 Mon Sep 17 00:00:00 2001 From: gugus Date: Sat, 11 Feb 2012 12:19:02 +0100 Subject: [PATCH 14/14] greetings are working now --- apps/openmw/mwdialogue/dialoguemanager.cpp | 64 ++++++++++++---------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanager.cpp b/apps/openmw/mwdialogue/dialoguemanager.cpp index df8543032..d4b2234d6 100644 --- a/apps/openmw/mwdialogue/dialoguemanager.cpp +++ b/apps/openmw/mwdialogue/dialoguemanager.cpp @@ -438,43 +438,47 @@ namespace MWDialogue } } } + //ESMS::RecListT::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list; - const ESM::Dialogue *dialogue = mEnvironment.mWorld->getStore().dialogs.find ("hello"); - - for (std::vector::const_iterator iter (dialogue->mInfo.begin()); - iter!=dialogue->mInfo.end(); ++iter) + bool greetingFound = false; + for(ESMS::RecListT::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++) { - if (isMatching (actor, *iter)) + ESM::Dialogue ndialogue = it->second; + if(ndialogue.type == ESM::Dialogue::Type::Greeting) { - // start dialogue - //std::cout << "found matching info record" << std::endl; - - //std::cout << "response: " << iter->response << std::endl; - - if (!iter->sound.empty()) - { - // TODO play sound - } - - if (!iter->resultScript.empty()) - { - //std::cout << "script: " << iter->resultScript << std::endl; - // TODO execute script - } - std::string text = iter->response; - std::map::iterator it; - for(it = actorKnownTopics.begin();it != actorKnownTopics.end();it++) + if (greetingFound) break; + for (std::vector::const_iterator iter (it->second.mInfo.begin()); + iter!=it->second.mInfo.end(); ++iter) { - if(find_str_ci(text,it->first,0) !=std::string::npos) + if (isMatching (actor, *iter)) { - std::cout << "fouuuuuuuuuuund"; - knownTopics[it->first] = true; - MWGui::DialogueWindow* win2 = mEnvironment.mWindowManager->getDialogueWindow(); - win2->addKeyword(it->first,it->second); + if (!iter->sound.empty()) + { + // TODO play sound + } + + if (!iter->resultScript.empty()) + { + //std::cout << "script: " << iter->resultScript << std::endl; + // TODO execute script + } + std::string text = iter->response; + std::map::iterator it; + for(it = actorKnownTopics.begin();it != actorKnownTopics.end();it++) + { + if(find_str_ci(text,it->first,0) !=std::string::npos) + { + //std::cout << "fouuuuuuuuuuund"; + knownTopics[it->first] = true; + MWGui::DialogueWindow* win2 = mEnvironment.mWindowManager->getDialogueWindow(); + win2->addKeyword(it->first,it->second); + } + } + win->addText(iter->response); + greetingFound = true; + break; } } - win->addText(iter->response); - //break; } } }