From a14b7e4a0fe80f07949b5fc7e019f4c5827b1baa Mon Sep 17 00:00:00 2001 From: Tom Mason Date: Wed, 26 Dec 2012 18:07:56 +0000 Subject: [PATCH] small fixes on text defines --- apps/openmw/mwgui/formatting.cpp | 4 ++-- components/interpreter/defines.cpp | 22 +++++++++++++++------- components/interpreter/defines.hpp | 1 + 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwgui/formatting.cpp b/apps/openmw/mwgui/formatting.cpp index 273034edd..4090b592d 100644 --- a/apps/openmw/mwgui/formatting.cpp +++ b/apps/openmw/mwgui/formatting.cpp @@ -74,7 +74,7 @@ std::vector BookTextParser::split(std::string text, const int width std::vector result; MWScript::InterpreterContext interpreterContext(NULL, MWWorld::Ptr()); // empty arguments, because there is no locals or actor - text = Interpreter::fixDefinesDialog(text, interpreterContext); + text = Interpreter::fixDefinesBook(text, interpreterContext); boost::algorithm::replace_all(text, "
", "\n"); boost::algorithm::replace_all(text, "

", "\n\n"); @@ -176,7 +176,7 @@ std::vector BookTextParser::split(std::string text, const int width MyGUI::IntSize BookTextParser::parse(std::string text, MyGUI::Widget* parent, const int width) { MWScript::InterpreterContext interpreterContext(NULL, MWWorld::Ptr()); // empty arguments, because there is no locals or actor - text = Interpreter::fixDefinesDialog(text, interpreterContext); + text = Interpreter::fixDefinesBook(text, interpreterContext); mParent = parent; diff --git a/components/interpreter/defines.cpp b/components/interpreter/defines.cpp index bd355fd7c..29c78200d 100644 --- a/components/interpreter/defines.cpp +++ b/components/interpreter/defines.cpp @@ -1,6 +1,5 @@ #include "defines.hpp" -#include #include #include #include @@ -22,7 +21,7 @@ namespace Interpreter{ return a.length() > b.length(); } - std::string fixDefinesReal(std::string text, char eschar, Context& context){ + std::string fixDefinesReal(std::string text, char eschar, bool isBook, Context& context){ unsigned int start = 0; std::string retval = ""; @@ -107,7 +106,7 @@ namespace Interpreter{ retval += context.getCurrentCellName(); } - else if(eschar == '%'){ // In Dialogue, not messagebox + else if(eschar == '%' && !isBook) { // In Dialogue, not messagebox if( (found = Check(temp, "faction", &i, &start))){ retval += context.getNPCFaction(); } @@ -134,9 +133,9 @@ namespace Interpreter{ retval += context.getNPCName(); } } - else if(eschar == '^') { // In messagebox, not dialogue + else { // In messagebox or book, not dialogue - /* empty in messageboxes */ + /* empty outside dialogue */ if( (found = Check(temp, "faction", &i, &start))); else if((found = Check(temp, "nextpcrank", &i, &start))); else if((found = Check(temp, "pcnextrank", &i, &start))); @@ -164,6 +163,11 @@ namespace Interpreter{ } for(unsigned int j = 0; j < globals.size(); j++){ + if(globals[j].length() > temp.length()){ // Just in case there's a global with a huuuge name + std::string temp = text.substr(i+1, globals[j].length()); + transform(temp.begin(), temp.end(), temp.begin(), ::tolower); + } + if((found = Check(temp, globals[j], &i, &start))){ char type = context.getGlobalType(globals[j]); @@ -191,10 +195,14 @@ namespace Interpreter{ } std::string fixDefinesDialog(std::string text, Context& context){ - return fixDefinesReal(text, '%', context); + return fixDefinesReal(text, '%', false, context); } std::string fixDefinesMsgBox(std::string text, Context& context){ - return fixDefinesReal(text, '^', context); + return fixDefinesReal(text, '^', false, context); + } + + std::string fixDefinesBook(std::string text, Context& context){ + return fixDefinesReal(text, '%', true, context); } } diff --git a/components/interpreter/defines.hpp b/components/interpreter/defines.hpp index 4cfba21ea..00c4386b8 100644 --- a/components/interpreter/defines.hpp +++ b/components/interpreter/defines.hpp @@ -7,6 +7,7 @@ namespace Interpreter{ std::string fixDefinesDialog(std::string text, Context& context); std::string fixDefinesMsgBox(std::string text, Context& context); + std::string fixDefinesBook(std::string text, Context& context); } #endif