@ -16,6 +16,8 @@
# include "../mwmechanics/npcstats.hpp"
# include "../mwdialogue/dialoguemanagerimp.hpp"
# include "dialogue_history.hpp"
# include "widgets.hpp"
# include "list.hpp"
@ -52,7 +54,6 @@ bool sortByLength (const std::string& left, const std::string& right)
{
return left . size ( ) > right . size ( ) ;
}
}
@ -131,6 +132,7 @@ DialogueWindow::DialogueWindow(MWBase::WindowManager& parWindowManager)
, mPersuasionDialog ( parWindowManager )
, mEnabled ( false )
, mServices ( 0 )
, mWindowManager ( parWindowManager )
{
// Centre dialog
center ( ) ;
@ -180,9 +182,30 @@ void DialogueWindow::onHistoryClicked(MyGUI::Widget* _sender)
if ( color ! = " #B29154 " )
{
MyGUI : : UString key = mHistory - > getColorTextAt ( cursorPosition ) ;
if ( color = = " #686EBA " ) MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > keywordSelected ( lower_string ( key ) ) ;
if ( color = = " #572D21 " ) MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > questionAnswered ( lower_string ( key ) ) ;
if ( color = = " #686EBA " )
{
std : : map < size_t , HyperLink > : : iterator i = mHyperLinks . upper_bound ( cursorPosition ) ;
if ( ! mHyperLinks . empty ( ) )
{
- - i ;
if ( i - > first + i - > second . mLength > cursorPosition )
{
MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > keywordSelected ( i - > second . mTrueValue ) ;
}
}
else
{
// the link was colored, but it is not in mHyperLinks.
// It means that those liunks are not marked with @# and found
// by topic name search
MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > keywordSelected ( lower_string ( key ) ) ;
}
}
if ( color = = " #572D21 " )
MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > questionAnswered ( lower_string ( key ) ) ;
}
}
@ -258,6 +281,7 @@ void DialogueWindow::startDialogue(MWWorld::Ptr actor, std::string npcName)
setTitle ( npcName ) ;
mTopicsList - > clear ( ) ;
mHyperLinks . clear ( ) ;
mHistory - > setCaption ( " " ) ;
updateOptions ( ) ;
}
@ -340,7 +364,7 @@ void addColorInString(std::string& str, const std::string& keyword,std::string c
}
}
std : : string DialogueWindow : : parseText ( std : : string text )
std : : string DialogueWindow : : parseText ( const std : : string & text )
{
bool separatorReached = false ; // only parse topics that are below the separator (this prevents actions like "Barter" that are not topics from getting blue-colored)
@ -358,11 +382,55 @@ std::string DialogueWindow::parseText(std::string text)
// sort by length to make sure longer topics are replaced first
std : : sort ( topics . begin ( ) , topics . end ( ) , sortByLength ) ;
std : : vector < MWDialogue : : HyperTextToken > hypertext = MWDialogue : : ParseHyperText ( text ) ;
size_t historySize = 0 ;
if ( mHistory - > getClient ( ) - > getSubWidgetText ( ) ! = nullptr )
{
historySize = mHistory - > getOnlyText ( ) . size ( ) ;
}
std : : string result ;
size_t hypertextPos = 0 ;
for ( size_t i = 0 ; i < hypertext . size ( ) ; + + i )
{
if ( hypertext [ i ] . mLink )
{
size_t asterisk_count = MWDialogue : : RemovePseudoAsterisks ( hypertext [ i ] . mText ) ;
std : : string standardForm = hypertext [ i ] . mText ;
for ( ; asterisk_count > 0 ; - - asterisk_count )
standardForm . append ( " * " ) ;
standardForm =
mWindowManager . getTranslationDataStorage ( ) . topicStandardForm ( standardForm ) ;
if ( std : : find ( topics . begin ( ) , topics . end ( ) , std : : string ( standardForm ) ) ! = topics . end ( ) )
{
result . append ( " #686EBA " ) . append ( hypertext [ i ] . mText ) . append ( " #B29154 " ) ;
mHyperLinks [ historySize + hypertextPos ] . mLength = MyGUI : : UString ( hypertext [ i ] . mText ) . length ( ) ;
mHyperLinks [ historySize + hypertextPos ] . mTrueValue = lower_string ( standardForm ) ;
}
else
result + = hypertext [ i ] . mText ;
}
else
{
if ( ! mWindowManager . getTranslationDataStorage ( ) . hasTranslation ( ) )
{
for ( std : : vector < std : : string > : : const_iterator it = topics . begin ( ) ; it ! = topics . end ( ) ; + + it )
{
addColorInString ( text , * it , " #686EBA " , " #B29154 " ) ;
addColorInString ( hypertext [ i ] . mText , * it , " #686EBA " , " #B29154 " ) ;
}
}
result + = hypertext [ i ] . mText ;
}
hypertextPos + = MyGUI : : UString ( hypertext [ i ] . mText ) . length ( ) ;
}
return text ;
return result ;
}
void DialogueWindow : : addText ( std : : string text )
@ -394,6 +462,7 @@ void DialogueWindow::updateOptions()
{
//Clear the list of topics
mTopicsList - > clear ( ) ;
mHyperLinks . clear ( ) ;
mHistory - > eraseText ( 0 , mHistory - > getTextLength ( ) ) ;
if ( mPtr . getTypeName ( ) = = typeid ( ESM : : NPC ) . name ( ) )