1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-03 16:19:41 +00:00

Topic passed to keywordSelected() no longer has to be lower case

Remove redundant mDialogueMap
This commit is contained in:
scrawl 2017-09-25 18:50:24 +02:00
parent b7752ec52d
commit f8ffd85146
3 changed files with 23 additions and 45 deletions

View file

@ -60,15 +60,6 @@ namespace MWDialogue
mChoice = -1; mChoice = -1;
mIsInChoice = false; mIsInChoice = false;
mCompilerContext.setExtensions (&extensions); mCompilerContext.setExtensions (&extensions);
const MWWorld::Store<ESM::Dialogue> &dialogs =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>();
MWWorld::Store<ESM::Dialogue>::iterator it = dialogs.begin();
for (; it != dialogs.end(); ++it)
{
mDialogueMap[Misc::StringUtils::lowerCase(it->mId)] = *it;
}
} }
void DialogueManager::clear() void DialogueManager::clear()
@ -171,7 +162,7 @@ namespace MWDialogue
MWScript::InterpreterContext interpreterContext(&mActor.getRefData().getLocals(),mActor); MWScript::InterpreterContext interpreterContext(&mActor.getRefData().getLocals(),mActor);
win->addResponse (Interpreter::fixDefinesDialog(info->mResponse, interpreterContext), "", false); win->addResponse (Interpreter::fixDefinesDialog(info->mResponse, interpreterContext), "", false);
executeScript (info->mResultScript, mActor); executeScript (info->mResultScript, mActor);
mLastTopic = Misc::StringUtils::lowerCase(it->mId); mLastTopic = it->mId;
// update topics again to accommodate changes resulting from executeScript // update topics again to accommodate changes resulting from executeScript
updateTopics(); updateTopics();
@ -310,7 +301,7 @@ namespace MWDialogue
{ {
if (iter->mId == info->mId) if (iter->mId == info->mId)
{ {
MWBase::Environment::get().getJournal()->addTopic (topic, info->mId, mActor); MWBase::Environment::get().getJournal()->addTopic (Misc::StringUtils::lowerCase(topic), info->mId, mActor);
break; break;
} }
} }
@ -327,6 +318,11 @@ namespace MWDialogue
} }
} }
const ESM::Dialogue *DialogueManager::searchDialogue(const std::string& id)
{
return MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>().search(id);
}
void DialogueManager::updateGlobals() void DialogueManager::updateGlobals()
{ {
MWBase::Environment::get().getWorld()->updateDialogueGlobals(); MWBase::Environment::get().getWorld()->updateDialogueGlobals();
@ -416,12 +412,10 @@ namespace MWDialogue
{ {
if(!mIsInChoice) if(!mIsInChoice)
{ {
if(mDialogueMap.find(keyword) != mDialogueMap.end()) const ESM::Dialogue* dialogue = searchDialogue(keyword);
if (dialogue && dialogue->mType == ESM::Dialogue::Topic)
{ {
if (mDialogueMap[keyword].mType == ESM::Dialogue::Topic) executeTopic (keyword);
{
executeTopic (keyword);
}
} }
} }
@ -456,14 +450,14 @@ namespace MWDialogue
{ {
mChoice = answer; mChoice = answer;
if (mDialogueMap.find(mLastTopic) != mDialogueMap.end()) const ESM::Dialogue* dialogue = searchDialogue(mLastTopic);
if (dialogue)
{ {
Filter filter (mActor, mChoice, mTalkedTo); Filter filter (mActor, mChoice, mTalkedTo);
if (mDialogueMap[mLastTopic].mType == ESM::Dialogue::Topic if (dialogue->mType == ESM::Dialogue::Topic || dialogue->mType == ESM::Dialogue::Greeting)
|| mDialogueMap[mLastTopic].mType == ESM::Dialogue::Greeting)
{ {
if (const ESM::DialInfo *info = filter.search (mDialogueMap[mLastTopic], true)) if (const ESM::DialInfo *info = filter.search (*dialogue, true))
{ {
std::string text = info->mResponse; std::string text = info->mResponse;
parseText (text); parseText (text);
@ -477,12 +471,12 @@ namespace MWDialogue
// Make sure the returned DialInfo is from the Dialogue we supplied. If could also be from the Info refusal group, // Make sure the returned DialInfo is from the Dialogue we supplied. If could also be from the Info refusal group,
// in which case it should not be added to the journal. // in which case it should not be added to the journal.
for (ESM::Dialogue::InfoContainer::const_iterator iter = mDialogueMap[mLastTopic].mInfo.begin(); for (ESM::Dialogue::InfoContainer::const_iterator iter = dialogue->mInfo.begin();
iter!=mDialogueMap[mLastTopic].mInfo.end(); ++iter) iter!=dialogue->mInfo.end(); ++iter)
{ {
if (iter->mId == info->mId) if (iter->mId == info->mId)
{ {
MWBase::Environment::get().getJournal()->addTopic (mLastTopic, info->mId, mActor); MWBase::Environment::get().getJournal()->addTopic (Misc::StringUtils::lowerCase(mLastTopic), info->mId, mActor);
break; break;
} }
} }
@ -737,7 +731,7 @@ namespace MWDialogue
if (actor == mActor && !mLastTopic.empty()) if (actor == mActor && !mLastTopic.empty())
{ {
MWBase::Environment::get().getJournal()->removeLastAddedTopicResponse( MWBase::Environment::get().getJournal()->removeLastAddedTopicResponse(
mLastTopic, actor.getClass().getName(actor)); Misc::StringUtils::lowerCase(mLastTopic), actor.getClass().getName(actor));
} }
} }
} }

View file

@ -22,7 +22,6 @@ namespace MWDialogue
{ {
class DialogueManager : public MWBase::DialogueManager class DialogueManager : public MWBase::DialogueManager
{ {
std::map<std::string, ESM::Dialogue> mDialogueMap;
std::set<std::string> mKnownTopics;// Those are the topics the player knows. std::set<std::string> mKnownTopics;// Those are the topics the player knows.
// Modified faction reactions. <Faction1, <Faction2, Difference> > // Modified faction reactions. <Faction1, <Faction2, Difference> >
@ -56,6 +55,8 @@ namespace MWDialogue
void executeTopic (const std::string& topic); void executeTopic (const std::string& topic);
const ESM::Dialogue* searchDialogue(const std::string& id);
public: public:
DialogueManager (const Compiler::Extensions& extensions, Translation::Storage& translationDataStorage); DialogueManager (const Compiler::Extensions& extensions, Translation::Storage& translationDataStorage);

View file

@ -223,7 +223,7 @@ namespace MWGui
{ {
MWBase::Environment::get().getWindowManager()->playSound("Menu Click"); MWBase::Environment::get().getWindowManager()->playSound("Menu Click");
MWBase::Environment::get().getDialogueManager()->keywordSelected(Misc::StringUtils::lowerCase(mTopicId)); MWBase::Environment::get().getDialogueManager()->keywordSelected(mTopicId);
} }
void Goodbye::activated() void Goodbye::activated()
@ -328,7 +328,7 @@ namespace MWGui
} }
if (id >= separatorPos) if (id >= separatorPos)
MWBase::Environment::get().getDialogueManager()->keywordSelected(Misc::StringUtils::lowerCase(topic)); MWBase::Environment::get().getDialogueManager()->keywordSelected(topic);
else else
{ {
const MWWorld::Store<ESM::GameSetting> &gmst = const MWWorld::Store<ESM::GameSetting> &gmst =
@ -552,24 +552,7 @@ namespace MWGui
void DialogueWindow::addResponse(const std::string &text, const std::string &title, bool needMargin) void DialogueWindow::addResponse(const std::string &text, const std::string &title, bool needMargin)
{ {
// This is called from the dialogue manager, so text is mHistoryContents.push_back(new Response(text, title, needMargin));
// case-smashed - thus we have to retrieve the correct case
// of the title through the topic list.
std::string realTitle = title;
if (realTitle != "")
{
for (size_t i=0; i<mTopicsList->getItemCount(); ++i)
{
std::string item = mTopicsList->getItemNameAt(i);
if (Misc::StringUtils::ciEqual(item, title))
{
realTitle = item;
break;
}
}
}
mHistoryContents.push_back(new Response(text, realTitle, needMargin));
updateHistory(); updateHistory();
} }