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