mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 12:53:51 +00:00
improved the dialogue GUI. Questions are still missing.
This commit is contained in:
parent
0c2de2c00c
commit
f7cf5f9bef
2 changed files with 102 additions and 16 deletions
|
@ -15,7 +15,7 @@ using namespace MWGui;
|
||||||
using namespace Widgets;
|
using namespace Widgets;
|
||||||
|
|
||||||
DialogueWindow::DialogueWindow(WindowManager& parWindowManager)
|
DialogueWindow::DialogueWindow(WindowManager& parWindowManager)
|
||||||
: WindowBase("openmw_dialogue_window_layout.xml", parWindowManager)
|
: WindowBase("openmw_dialogue_window_layout.xml", parWindowManager)
|
||||||
{
|
{
|
||||||
// Centre dialog
|
// Centre dialog
|
||||||
center();
|
center();
|
||||||
|
@ -31,15 +31,15 @@ DialogueWindow::DialogueWindow(WindowManager& parWindowManager)
|
||||||
//Topics list
|
//Topics list
|
||||||
getWidget(topicsList, "TopicsList");
|
getWidget(topicsList, "TopicsList");
|
||||||
topicsList->setScrollVisible(true);
|
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->eventListMouseItemActivate = MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic);
|
||||||
topicsList->eventListChangePosition = MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic);
|
//topicsList->eventListChangePosition = MyGUI::newDelegate(this, &DialogueWindow::onSelectTopic);
|
||||||
|
|
||||||
MyGUI::ButtonPtr byeButton;
|
MyGUI::ButtonPtr byeButton;
|
||||||
getWidget(byeButton, "ByeButton");
|
getWidget(byeButton, "ByeButton");
|
||||||
byeButton->eventMouseButtonClick = MyGUI::newDelegate(this, &DialogueWindow::onByeClicked);
|
byeButton->eventMouseButtonClick = MyGUI::newDelegate(this, &DialogueWindow::onByeClicked);
|
||||||
|
|
||||||
updateOptions();
|
//updateOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogueWindow::onHistoryClicked(MyGUI::Widget* _sender)
|
void DialogueWindow::onHistoryClicked(MyGUI::Widget* _sender)
|
||||||
|
@ -54,14 +54,18 @@ void DialogueWindow::onHistoryClicked(MyGUI::Widget* _sender)
|
||||||
if(history->getColorAtPos(cursorPosition) != "#FFFFFF")
|
if(history->getColorAtPos(cursorPosition) != "#FFFFFF")
|
||||||
{
|
{
|
||||||
UString key = history->getColorTextAt(cursorPosition);
|
UString key = history->getColorTextAt(cursorPosition);
|
||||||
std::cout << "Clicked on key: " << key << std::endl;
|
//std::cout << "Clicked on key: " << key << std::endl;
|
||||||
//eventTopicSelected(key);
|
displayTopicText(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DialogueWindow::open()
|
void DialogueWindow::open()
|
||||||
{
|
{
|
||||||
updateOptions();
|
//updateOptions();
|
||||||
|
topicsList->removeAllItems();
|
||||||
|
pTopicsText.clear();
|
||||||
|
history->eraseText(0,history->getTextLength());
|
||||||
|
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,27 +78,96 @@ void DialogueWindow::onSelectTopic(MyGUI::List* _sender, size_t _index)
|
||||||
{
|
{
|
||||||
if (_index == MyGUI::ITEM_NONE)
|
if (_index == MyGUI::ITEM_NONE)
|
||||||
return;
|
return;
|
||||||
|
std::string topic = _sender->getItem(_index);
|
||||||
|
displayTopicText(topic);
|
||||||
|
|
||||||
//const std::string* theTopic = topicsList->getItemDataAt<std::string>(_index);
|
//const std::string* theTopic = topicsList->getItemDataAt<std::string>(_index);
|
||||||
//std::cout << "Selected: "<< theTopic << std::endl;
|
//std::cout << "Selected: "<< theTopic << std::endl;
|
||||||
//eventTopicSelected(key);
|
//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;i<topicsList->getItemCount();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()
|
void DialogueWindow::updateOptions()
|
||||||
{
|
{
|
||||||
//FIXME Add this properly
|
//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++)
|
for(int z = 0; z < 10; z++)
|
||||||
{
|
{
|
||||||
history->addDialogHeading("Fort Frostmoth");
|
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->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
|
//Clear the list of topics
|
||||||
topicsList->removeAllItems();
|
topicsList->removeAllItems();
|
||||||
int i = 0;
|
pTopicsText.clear();
|
||||||
topicsList->addItem("Ald'ruhn", i++);
|
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("Balmora", i++);
|
||||||
topicsList->addItem("Sadrith Mora", i++);
|
topicsList->addItem("Sadrith Mora", i++);
|
||||||
topicsList->addItem("Vivec", i++);
|
topicsList->addItem("Vivec", i++);
|
||||||
|
@ -115,6 +188,6 @@ void DialogueWindow::updateOptions()
|
||||||
topicsList->addItem("Tel Fyr", i++);
|
topicsList->addItem("Tel Fyr", i++);
|
||||||
topicsList->addItem("Tel Mora", i++);
|
topicsList->addItem("Tel Mora", i++);
|
||||||
topicsList->addItem("Tel Vos", i++);
|
topicsList->addItem("Tel Vos", i++);
|
||||||
topicsList->addItem("Vos", i++);
|
topicsList->addItem("Vos", i++);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,13 @@ namespace MWGui
|
||||||
*/
|
*/
|
||||||
EventHandle_Void eventBye;
|
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:
|
protected:
|
||||||
void onSelectTopic(MyGUI::List* _sender, size_t _index);
|
void onSelectTopic(MyGUI::List* _sender, size_t _index);
|
||||||
void onByeClicked(MyGUI::Widget* _sender);
|
void onByeClicked(MyGUI::Widget* _sender);
|
||||||
|
@ -42,9 +49,15 @@ namespace MWGui
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateOptions();
|
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;
|
DialogeHistory* history;
|
||||||
MyGUI::ListPtr topicsList;
|
MyGUI::ListPtr topicsList;
|
||||||
|
std::map<std::string,std::string> pTopicsText;// this map links keyword and "real" text.
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue