1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-27 03:35:27 +00:00

choices works. The only thing remaining is the script arguments problems.

Need a lot of clean up too.
This commit is contained in:
gugus 2012-03-16 17:30:59 +01:00
parent 07d8d654cd
commit 56a84b6a1a
4 changed files with 115 additions and 25 deletions

View File

@ -142,8 +142,10 @@ namespace MWDialogue
return toLower(str).find(toLower(substr),pos); return toLower(str).find(toLower(substr),pos);
} }
bool DialogueManager::functionFilter(const MWWorld::Ptr& actor, const ESM::DialInfo& info) bool DialogueManager::functionFilter(const MWWorld::Ptr& actor, const ESM::DialInfo& info,bool choice)
{ {
bool isAChoice = false;//is there any choice in the filters?
bool isFunction = false;
for (std::vector<ESM::DialInfo::SelectStruct>::const_iterator iter (info.selects.begin()); for (std::vector<ESM::DialInfo::SelectStruct>::const_iterator iter (info.selects.begin());
iter != info.selects.end(); ++iter) iter != info.selects.end(); ++iter)
{ {
@ -151,19 +153,24 @@ namespace MWDialogue
char type = select.selectRule[1]; char type = select.selectRule[1];
if(type == '1') if(type == '1')
{ {
isFunction = true;
char comp = select.selectRule[4]; char comp = select.selectRule[4];
std::string name = select.selectRule.substr (5); std::string name = select.selectRule.substr (5);
std::string function = select.selectRule.substr(1,2); std::string function = select.selectRule.substr(2,2);
std::cout << function; std::cout << "f " <<select.selectRule <<" ";
int ifunction; int ifunction;
std::istringstream iss(function); std::istringstream iss(function);
iss >> ifunction; iss >> ifunction;
switch(ifunction) switch(ifunction)
{ {
case 4://choice case 50://choice
if(!selectCompare(comp,mChoice,select.i)) return false; std::cout << "choice";
isAChoice = true;
if(choice)
{
if(!selectCompare(comp,mChoice,select.i)){std::cout << "pbhere"; return false;}
}
break; break;
default: default:
@ -172,6 +179,19 @@ namespace MWDialogue
} }
} }
} }
if(isAChoice)
{
std::cout << "CHOICEEE!";
return true;
}
/*if(!choice && !isAChoice)
{
return false;
}*/
if(isFunction)
{
return false;
}
return true; return true;
} }
@ -185,7 +205,7 @@ namespace MWDialogue
char comp = select.selectRule[4]; char comp = select.selectRule[4];
std::string name = select.selectRule.substr (5); std::string name = select.selectRule.substr (5);
std::string function = select.selectRule.substr(1,2); std::string function = select.selectRule.substr(1,2);
std::cout << function; //std::cout << function;
// TODO types 4, 5, 6, 7, 8, 9, A, B, C // TODO types 4, 5, 6, 7, 8, 9, A, B, C
//new TOTO: 5,6,9 //new TOTO: 5,6,9
@ -193,7 +213,7 @@ namespace MWDialogue
{ {
case '1': // function case '1': // function
return false; // TODO implement functions return true; // TODO implement functions
case '2': // global case '2': // global
@ -450,6 +470,7 @@ namespace MWDialogue
mErrorStream(std::cout.rdbuf()),mErrorHandler(mErrorStream) mErrorStream(std::cout.rdbuf()),mErrorHandler(mErrorStream)
{ {
mChoice = -1; mChoice = -1;
mIsInChoice = false;
mCompilerContext.setExtensions (&extensions); mCompilerContext.setExtensions (&extensions);
} }
@ -508,8 +529,15 @@ namespace MWDialogue
for (std::vector<ESM::DialInfo>::const_iterator iter (it->second.mInfo.begin()); for (std::vector<ESM::DialInfo>::const_iterator iter (it->second.mInfo.begin());
iter!=it->second.mInfo.end(); ++iter) iter!=it->second.mInfo.end(); ++iter)
{ {
if (isMatching (actor, *iter)) if(it->first == "anneau")
{ {
std::cout << iter->response << std::endl;
}
//std::cout << "a";
if (isMatching (actor, *iter) && functionFilter(mActor,*iter,false))
{
std::cout << "OK";
//std::cout << it->first;
actorKnownTopics[it->first].push_back(*iter); actorKnownTopics[it->first].push_back(*iter);
if(knownTopics.find(toLower(it->first)) != knownTopics.end()) if(knownTopics.find(toLower(it->first)) != knownTopics.end())
{ {
@ -521,10 +549,12 @@ namespace MWDialogue
} }
} }
} }
//std::cout << "b";
} }
} }
//ESMS::RecListT<ESM::Dialogue>::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list; //ESMS::RecListT<ESM::Dialogue>::MapType dialogueList = mEnvironment.mWorld->getStore().dialogs.list;
//greeting
bool greetingFound = false; bool greetingFound = false;
for(ESMS::RecListT<ESM::Dialogue>::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++) for(ESMS::RecListT<ESM::Dialogue>::MapType::iterator it = dialogueList.begin(); it!=dialogueList.end();it++)
{ {
@ -535,7 +565,7 @@ namespace MWDialogue
for (std::vector<ESM::DialInfo>::const_iterator iter (it->second.mInfo.begin()); for (std::vector<ESM::DialInfo>::const_iterator iter (it->second.mInfo.begin());
iter!=it->second.mInfo.end(); ++iter) iter!=it->second.mInfo.end(); ++iter)
{ {
if (isMatching (actor, *iter)) if (isMatching (actor, *iter) && functionFilter(mActor,*iter,false))
{ {
if (!iter->sound.empty()) if (!iter->sound.empty())
{ {
@ -552,6 +582,8 @@ namespace MWDialogue
win->addText(iter->response); win->addText(iter->response);
executeScript(iter->resultScript); executeScript(iter->resultScript);
greetingFound = true; greetingFound = true;
mLastTopic = it->first;
mLastDialogue = *iter;
break; break;
} }
} }
@ -622,23 +654,35 @@ namespace MWDialogue
} }
void DialogueManager::keywordSelected(std::string keyword) void DialogueManager::keywordSelected(std::string keyword)
{
if(!mIsInChoice)
{ {
if(!actorKnownTopics[keyword].empty()) if(!actorKnownTopics[keyword].empty())
{ {
for(std::list<ESM::DialInfo>::iterator it = actorKnownTopics[keyword].begin(); it != actorKnownTopics[keyword].end();it++) for(std::list<ESM::DialInfo>::iterator it = actorKnownTopics[keyword].begin(); it != actorKnownTopics[keyword].end();it++)
{ {
ESM::DialInfo dial = *it; ESM::DialInfo dial = *it;
if(functionFilter(mActor,dial)) if(functionFilter(mActor,dial,true))
{ {
std::string text = actorKnownTopics[keyword].front().response; std::string text = it->response;
std::string script = actorKnownTopics[keyword].front().resultScript; std::string script = it->resultScript;
parseText(text); parseText(text);
MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow();
win->addTitle(keyword);
win->addText(it->response);
executeScript(script); executeScript(script);
mLastTopic = keyword;
mLastDialogue = dial;
break; break;
} }
} }
} }
} }
}
void DialogueManager::goodbyeSelected() void DialogueManager::goodbyeSelected()
{ {
@ -647,6 +691,40 @@ namespace MWDialogue
void DialogueManager::questionAnswered(std::string answere) void DialogueManager::questionAnswered(std::string answere)
{ {
if(mChoiceMap.find(answere) != mChoiceMap.end())
{
mChoice = mChoiceMap[answere];
std::cout << "found1";
std::list<ESM::DialInfo> dials = actorKnownTopics[mLastTopic];
//bool passedLastDialogue = false;
std::cout << actorKnownTopics[mLastTopic].size() << mLastTopic;
std::list<ESM::DialInfo>::iterator iter;
for(iter = actorKnownTopics[mLastTopic].begin(); iter->id != mLastDialogue.id;iter++)
{
}
//iter--;
for(std::list<ESM::DialInfo>::iterator it = iter; it!=actorKnownTopics[mLastTopic].begin();)
{
it--;
std::cout << "parsing\n";
if(functionFilter(mActor,*it,true))
{
mChoiceMap.clear();
mChoice = -1;
mIsInChoice = false;
std::cout << "2";
MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow();
std::string text = it->response;
parseText(text);
win->addText(text);
executeScript(it->resultScript);
mLastTopic = mLastTopic;
mLastDialogue = *it;
break;
}
}
}
std::cout << "and the ansere is..."<< answere; std::cout << "and the ansere is..."<< answere;
} }
@ -659,7 +737,9 @@ namespace MWDialogue
void DialogueManager::askQuestion(std::string question, int choice) void DialogueManager::askQuestion(std::string question, int choice)
{ {
MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow(); MWGui::DialogueWindow* win = mEnvironment.mWindowManager->getDialogueWindow();
win->askQuestion(question,choice); win->askQuestion(question);
mChoiceMap[question] = choice;
mIsInChoice = true;
std::cout << "choice"; std::cout << "choice";
} }
} }

View File

@ -26,7 +26,7 @@ namespace MWDialogue
bool isMatching (const MWWorld::Ptr& actor, const ESM::DialInfo& info) const; bool isMatching (const MWWorld::Ptr& actor, const ESM::DialInfo& info) const;
bool functionFilter(const MWWorld::Ptr& actor, const ESM::DialInfo& info); bool functionFilter(const MWWorld::Ptr& actor, const ESM::DialInfo& info,bool choice);
void parseText(std::string text); void parseText(std::string text);
@ -45,6 +45,10 @@ namespace MWDialogue
void printError(std::string error); void printError(std::string error);
int mChoice; int mChoice;
std::map<std::string,int> mChoiceMap;
std::string mLastTopic;
ESM::DialInfo mLastDialogue;
bool mIsInChoice;
public: public:

View File

@ -84,7 +84,7 @@ void DialogueWindow::onHistoryClicked(MyGUI::Widget* _sender)
//std::cout << "Clicked on key: " << key << std::endl; //std::cout << "Clicked on key: " << key << std::endl;
if(color == "#686EBA") if(color == "#686EBA")
{ {
displayTopicText(lower_string(key)); //displayTopicText(lower_string(key));
mEnvironment.mDialogueManager->keywordSelected(lower_string(key)); mEnvironment.mDialogueManager->keywordSelected(lower_string(key));
} }
if(color == "#572D21") if(color == "#572D21")
@ -117,7 +117,7 @@ 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); std::string topic = _sender->getItem(_index);
displayTopicText(topic); //displayTopicText(topic);
mEnvironment.mDialogueManager->keywordSelected(lower_string(topic)); mEnvironment.mDialogueManager->keywordSelected(lower_string(topic));
//const std::string* theTopic = topicsList->getItemDataAt<std::string>(_index); //const std::string* theTopic = topicsList->getItemDataAt<std::string>(_index);
@ -204,7 +204,12 @@ void DialogueWindow::addText(std::string text)
history->addDialogText("#B29154"+parseText(text)+"#B29154"); history->addDialogText("#B29154"+parseText(text)+"#B29154");
} }
void DialogueWindow::askQuestion(std::string question,int choice) void DialogueWindow::addTitle(std::string text)
{
history->addDialogHeading(text);
}
void DialogueWindow::askQuestion(std::string question)
{ {
history->addDialogText("#572D21"+question+"#B29154"+" "); history->addDialogText("#572D21"+question+"#B29154"+" ");
/*for(std::list<std::string>::iterator it = answers.begin();it!=answers.end();it++) /*for(std::list<std::string>::iterator it = answers.begin();it!=answers.end();it++)

View File

@ -45,7 +45,8 @@ namespace MWGui
void addKeyword(std::string keyWord,std::string topicText); void addKeyword(std::string keyWord,std::string topicText);
void removeKeyword(std::string keyWord); void removeKeyword(std::string keyWord);
void addText(std::string text); void addText(std::string text);
void askQuestion(std::string question,int choice); void addTitle(std::string text);
void askQuestion(std::string question);
protected: protected:
void onSelectTopic(MyGUI::List* _sender, size_t _index); void onSelectTopic(MyGUI::List* _sender, size_t _index);