2010-11-03 20:21:08 +00:00
# include "dialogue.hpp"
# include <iostream>
# include <iterator>
# include <boost/algorithm/string.hpp>
# include <boost/lexical_cast.hpp>
2012-10-01 15:17:04 +00:00
# include "../mwworld/esmstore.hpp"
2012-05-17 15:15:44 +00:00
# include "../mwbase/environment.hpp"
2012-08-09 08:35:53 +00:00
# include "../mwbase/dialoguemanager.hpp"
# include "../mwbase/world.hpp"
2012-08-12 16:11:09 +00:00
# include "../mwbase/windowmanager.hpp"
2012-11-05 18:55:06 +00:00
# include "../mwbase/mechanicsmanager.hpp"
2012-05-17 15:15:44 +00:00
2012-11-09 23:29:36 +00:00
# include "../mwmechanics/npcstats.hpp"
2012-12-31 00:15:47 +00:00
# include "../mwdialogue/dialoguemanagerimp.hpp"
2012-05-17 15:15:44 +00:00
# include "dialogue_history.hpp"
# include "widgets.hpp"
# include "list.hpp"
# include "tradewindow.hpp"
2012-09-09 18:10:07 +00:00
# include "spellbuyingwindow.hpp"
2012-05-17 19:15:48 +00:00
# include "inventorywindow.hpp"
2012-09-26 16:30:47 +00:00
# include "travelwindow.hpp"
2012-05-17 15:15:44 +00:00
2010-11-03 20:21:08 +00:00
using namespace MWGui ;
using namespace Widgets ;
2012-02-05 09:54:56 +00:00
/**
* Copied from the internet .
*/
2012-09-22 22:36:20 +00:00
namespace {
2012-02-05 09:54:56 +00:00
std : : string lower_string ( const std : : string & str )
{
2013-01-09 19:51:52 +00:00
std : : string lowerCase = Misc : : StringUtils : : lowerCase ( str ) ;
2012-02-10 15:21:04 +00:00
return lowerCase ;
2012-02-05 09:54:56 +00:00
}
std : : string : : size_type find_str_ci ( const std : : string & str , const std : : string & substr , size_t pos )
{
return lower_string ( str ) . find ( lower_string ( substr ) , pos ) ;
}
2012-11-23 18:05:40 +00:00
bool sortByLength ( const std : : string & left , const std : : string & right )
{
return left . size ( ) > right . size ( ) ;
}
2012-09-22 22:36:20 +00:00
}
2012-02-05 09:54:56 +00:00
2012-11-09 19:18:38 +00:00
PersuasionDialog : : PersuasionDialog ( MWBase : : WindowManager & parWindowManager )
: WindowModal ( " openmw_persuasion_dialog.layout " , parWindowManager )
{
getWidget ( mCancelButton , " CancelButton " ) ;
getWidget ( mAdmireButton , " AdmireButton " ) ;
getWidget ( mIntimidateButton , " IntimidateButton " ) ;
getWidget ( mTauntButton , " TauntButton " ) ;
getWidget ( mBribe10Button , " Bribe10Button " ) ;
getWidget ( mBribe100Button , " Bribe100Button " ) ;
getWidget ( mBribe1000Button , " Bribe1000Button " ) ;
getWidget ( mGoldLabel , " GoldLabel " ) ;
mCancelButton - > eventMouseButtonClick + = MyGUI : : newDelegate ( this , & PersuasionDialog : : onCancel ) ;
mAdmireButton - > eventMouseButtonClick + = MyGUI : : newDelegate ( this , & PersuasionDialog : : onPersuade ) ;
mIntimidateButton - > eventMouseButtonClick + = MyGUI : : newDelegate ( this , & PersuasionDialog : : onPersuade ) ;
mTauntButton - > eventMouseButtonClick + = MyGUI : : newDelegate ( this , & PersuasionDialog : : onPersuade ) ;
mBribe10Button - > eventMouseButtonClick + = MyGUI : : newDelegate ( this , & PersuasionDialog : : onPersuade ) ;
mBribe100Button - > eventMouseButtonClick + = MyGUI : : newDelegate ( this , & PersuasionDialog : : onPersuade ) ;
mBribe1000Button - > eventMouseButtonClick + = MyGUI : : newDelegate ( this , & PersuasionDialog : : onPersuade ) ;
}
void PersuasionDialog : : onCancel ( MyGUI : : Widget * sender )
{
setVisible ( false ) ;
}
void PersuasionDialog : : onPersuade ( MyGUI : : Widget * sender )
{
MWBase : : MechanicsManager : : PersuasionType type ;
if ( sender = = mAdmireButton ) type = MWBase : : MechanicsManager : : PT_Admire ;
else if ( sender = = mIntimidateButton ) type = MWBase : : MechanicsManager : : PT_Intimidate ;
else if ( sender = = mTauntButton ) type = MWBase : : MechanicsManager : : PT_Taunt ;
else if ( sender = = mBribe10Button )
{
mWindowManager . getTradeWindow ( ) - > addOrRemoveGold ( - 10 ) ;
type = MWBase : : MechanicsManager : : PT_Bribe10 ;
}
else if ( sender = = mBribe100Button )
{
mWindowManager . getTradeWindow ( ) - > addOrRemoveGold ( - 100 ) ;
type = MWBase : : MechanicsManager : : PT_Bribe100 ;
}
else /*if (sender == mBribe1000Button)*/
{
mWindowManager . getTradeWindow ( ) - > addOrRemoveGold ( - 1000 ) ;
type = MWBase : : MechanicsManager : : PT_Bribe1000 ;
}
2012-11-09 23:29:36 +00:00
MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > persuade ( type ) ;
2012-11-09 19:18:38 +00:00
setVisible ( false ) ;
}
void PersuasionDialog : : open ( )
{
WindowModal : : open ( ) ;
center ( ) ;
int playerGold = mWindowManager . getInventoryWindow ( ) - > getPlayerGold ( ) ;
mBribe10Button - > setEnabled ( playerGold > = 10 ) ;
mBribe100Button - > setEnabled ( playerGold > = 100 ) ;
mBribe1000Button - > setEnabled ( playerGold > = 1000 ) ;
mGoldLabel - > setCaptionWithReplacing ( " #{sGold}: " + boost : : lexical_cast < std : : string > ( playerGold ) ) ;
}
// --------------------------------------------------------------------------------------------------
2012-08-12 16:11:09 +00:00
DialogueWindow : : DialogueWindow ( MWBase : : WindowManager & parWindowManager )
2012-07-03 09:34:20 +00:00
: WindowBase ( " openmw_dialogue_window.layout " , parWindowManager )
2012-11-09 19:18:38 +00:00
, mPersuasionDialog ( parWindowManager )
2012-11-05 22:16:37 +00:00
, mEnabled ( false )
2012-09-22 22:36:20 +00:00
, mServices ( 0 )
2010-11-03 20:21:08 +00:00
{
// Centre dialog
2010-11-06 10:47:46 +00:00
center ( ) ;
2010-11-03 20:21:08 +00:00
2012-11-09 19:18:38 +00:00
mPersuasionDialog . setVisible ( false ) ;
2010-11-03 20:21:08 +00:00
//History view
2012-07-13 10:51:58 +00:00
getWidget ( mHistory , " History " ) ;
mHistory - > setOverflowToTheLeft ( true ) ;
mHistory - > setMaxTextLength ( 1000000 ) ;
2012-09-10 07:10:50 +00:00
MyGUI : : Widget * eventbox ;
2012-03-22 14:01:37 +00:00
//An EditBox cannot receive mouse click events, so we use an
//invisible widget on top of the editbox to receive them
getWidget ( eventbox , " EventBox " ) ;
eventbox - > eventMouseButtonClick + = MyGUI : : newDelegate ( this , & DialogueWindow : : onHistoryClicked ) ;
2012-04-29 22:57:41 +00:00
eventbox - > eventMouseWheel + = MyGUI : : newDelegate ( this , & DialogueWindow : : onMouseWheel ) ;
2012-04-23 13:27:03 +00:00
2012-03-19 18:21:08 +00:00
//Topics list
2012-07-13 10:51:58 +00:00
getWidget ( mTopicsList , " TopicsList " ) ;
mTopicsList - > eventItemSelected + = MyGUI : : newDelegate ( this , & DialogueWindow : : onSelectTopic ) ;
2010-11-03 20:21:08 +00:00
MyGUI : : ButtonPtr byeButton ;
getWidget ( byeButton , " ByeButton " ) ;
2012-03-21 12:27:08 +00:00
byeButton - > eventMouseButtonClick + = MyGUI : : newDelegate ( this , & DialogueWindow : : onByeClicked ) ;
2010-11-03 20:21:08 +00:00
2012-07-13 10:51:58 +00:00
getWidget ( mDispositionBar , " Disposition " ) ;
getWidget ( mDispositionText , " DispositionText " ) ;
2012-05-10 09:19:22 +00:00
static_cast < MyGUI : : Window * > ( mMainWidget ) - > eventWindowChangeCoord + = MyGUI : : newDelegate ( this , & DialogueWindow : : onWindowResize ) ;
2010-11-03 20:21:08 +00:00
}
void DialogueWindow : : onHistoryClicked ( MyGUI : : Widget * _sender )
{
2012-09-10 07:10:50 +00:00
MyGUI : : ISubWidgetText * t = mHistory - > getClient ( ) - > getSubWidgetText ( ) ;
2010-11-03 20:21:08 +00:00
if ( t = = nullptr )
return ;
2012-09-10 07:10:50 +00:00
const MyGUI : : IntPoint & lastPressed = MyGUI : : InputManager : : getInstance ( ) . getLastPressedPosition ( MyGUI : : MouseButton : : Left ) ;
2010-11-03 20:21:08 +00:00
size_t cursorPosition = t - > getCursorPosition ( lastPressed ) ;
2012-07-13 10:51:58 +00:00
MyGUI : : UString color = mHistory - > getColorAtPos ( cursorPosition ) ;
2012-05-11 05:18:41 +00:00
if ( ! mEnabled & & color = = " #572D21 " )
MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > goodbyeSelected ( ) ;
2012-01-28 15:16:49 +00:00
if ( color ! = " #B29154 " )
2010-11-03 20:21:08 +00:00
{
2012-09-10 07:10:50 +00:00
MyGUI : : UString key = mHistory - > getColorTextAt ( cursorPosition ) ;
2012-01-28 15:16:49 +00:00
2012-12-31 00:15:47 +00:00
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 ) ) ;
2010-11-03 20:21:08 +00:00
}
}
2012-05-10 09:19:22 +00:00
void DialogueWindow : : onWindowResize ( MyGUI : : Window * _sender )
{
2012-07-13 10:51:58 +00:00
mTopicsList - > adjustSize ( ) ;
2012-05-10 09:19:22 +00:00
}
2012-04-29 22:57:41 +00:00
void DialogueWindow : : onMouseWheel ( MyGUI : : Widget * _sender , int _rel )
{
2012-07-13 10:51:58 +00:00
if ( mHistory - > getVScrollPosition ( ) - _rel * 0.3 < 0 )
mHistory - > setVScrollPosition ( 0 ) ;
2012-04-29 22:57:41 +00:00
else
2012-07-13 10:51:58 +00:00
mHistory - > setVScrollPosition ( mHistory - > getVScrollPosition ( ) - _rel * 0.3 ) ;
2012-04-29 22:57:41 +00:00
}
2010-11-03 20:21:08 +00:00
void DialogueWindow : : onByeClicked ( MyGUI : : Widget * _sender )
{
2012-04-23 13:27:03 +00:00
MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > goodbyeSelected ( ) ;
2010-11-03 20:21:08 +00:00
}
2012-05-04 21:53:50 +00:00
void DialogueWindow : : onSelectTopic ( std : : string topic )
2010-11-03 20:21:08 +00:00
{
2012-05-11 05:18:41 +00:00
if ( ! mEnabled ) return ;
2012-11-05 20:34:11 +00:00
const MWWorld : : Store < ESM : : GameSetting > & gmst =
MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) . get < ESM : : GameSetting > ( ) ;
if ( topic = = gmst . find ( " sBarter " ) - > getString ( ) )
2012-05-17 15:15:44 +00:00
{
/// \todo check if the player is allowed to trade with this actor (e.g. faction rank high enough)?
2012-05-23 10:23:35 +00:00
mWindowManager . pushGuiMode ( GM_Barter ) ;
2012-05-26 23:14:33 +00:00
mWindowManager . getTradeWindow ( ) - > startTrade ( mPtr ) ;
2012-05-17 15:15:44 +00:00
}
2012-11-09 19:18:38 +00:00
if ( topic = = gmst . find ( " sPersuasion " ) - > getString ( ) )
{
mPersuasionDialog . setVisible ( true ) ;
}
2012-11-05 20:34:11 +00:00
else if ( topic = = gmst . find ( " sSpells " ) - > getString ( ) )
2012-09-08 22:17:03 +00:00
{
2012-09-09 18:10:07 +00:00
mWindowManager . pushGuiMode ( GM_SpellBuying ) ;
mWindowManager . getSpellBuyingWindow ( ) - > startSpellBuying ( mPtr ) ;
2012-09-08 22:17:03 +00:00
}
2012-11-05 20:34:11 +00:00
else if ( topic = = gmst . find ( " sTravel " ) - > getString ( ) )
2012-09-26 16:30:47 +00:00
{
mWindowManager . pushGuiMode ( GM_Travel ) ;
mWindowManager . getTravelWindow ( ) - > startTravel ( mPtr ) ;
}
2012-11-05 20:34:11 +00:00
else if ( topic = = gmst . find ( " sSpellMakingMenuTitle " ) - > getString ( ) )
2012-09-22 22:36:20 +00:00
{
mWindowManager . pushGuiMode ( GM_SpellCreation ) ;
mWindowManager . startSpellMaking ( mPtr ) ;
}
2012-11-05 20:34:11 +00:00
else if ( topic = = gmst . find ( " sEnchanting " ) - > getString ( ) )
2012-09-27 06:47:47 +00:00
{
mWindowManager . pushGuiMode ( GM_Enchanting ) ;
mWindowManager . startEnchanting ( mPtr ) ;
}
2012-11-05 20:34:11 +00:00
else if ( topic = = gmst . find ( " sServiceTrainingTitle " ) - > getString ( ) )
2012-10-17 16:03:02 +00:00
{
mWindowManager . pushGuiMode ( GM_Training ) ;
mWindowManager . startTraining ( mPtr ) ;
}
2012-05-17 15:15:44 +00:00
else
MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > keywordSelected ( lower_string ( topic ) ) ;
2010-11-03 20:21:08 +00:00
}
2012-05-17 15:15:44 +00:00
void DialogueWindow : : startDialogue ( MWWorld : : Ptr actor , std : : string npcName )
2012-01-27 13:50:13 +00:00
{
2012-05-11 05:18:41 +00:00
mEnabled = true ;
2012-05-26 23:14:33 +00:00
mPtr = actor ;
2012-07-13 10:51:58 +00:00
mTopicsList - > setEnabled ( true ) ;
2012-05-18 15:27:55 +00:00
setTitle ( npcName ) ;
2012-05-23 10:23:35 +00:00
2012-07-13 10:51:58 +00:00
mTopicsList - > clear ( ) ;
2012-12-31 00:15:47 +00:00
mHyperLinks . clear ( ) ;
2012-11-05 19:47:28 +00:00
mHistory - > setCaption ( " " ) ;
2012-05-23 10:23:35 +00:00
updateOptions ( ) ;
2012-01-27 13:50:13 +00:00
}
2012-03-19 17:30:52 +00:00
void DialogueWindow : : setKeywords ( std : : list < std : : string > keyWords )
2012-01-27 13:50:13 +00:00
{
2012-07-13 10:51:58 +00:00
mTopicsList - > clear ( ) ;
2012-05-17 12:54:03 +00:00
2012-09-22 22:36:20 +00:00
bool anyService = mServices > 0 ;
2012-05-17 12:54:03 +00:00
2012-11-05 20:34:11 +00:00
const MWWorld : : Store < ESM : : GameSetting > & gmst =
MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) . get < ESM : : GameSetting > ( ) ;
2012-11-09 19:18:38 +00:00
if ( mPtr . getTypeName ( ) = = typeid ( ESM : : NPC ) . name ( ) )
mTopicsList - > addItem ( gmst . find ( " sPersuasion " ) - > getString ( ) ) ;
2012-09-22 22:36:20 +00:00
if ( mServices & Service_Trade )
2012-11-05 20:34:11 +00:00
mTopicsList - > addItem ( gmst . find ( " sBarter " ) - > getString ( ) ) ;
2012-05-17 12:54:03 +00:00
2012-09-22 22:36:20 +00:00
if ( mServices & Service_BuySpells )
2012-11-05 20:34:11 +00:00
mTopicsList - > addItem ( gmst . find ( " sSpells " ) - > getString ( ) ) ;
2012-09-08 22:17:03 +00:00
2012-10-17 16:17:53 +00:00
if ( mServices & Service_Travel )
2012-11-05 20:34:11 +00:00
mTopicsList - > addItem ( gmst . find ( " sTravel " ) - > getString ( ) ) ;
2012-09-26 16:30:47 +00:00
2012-09-22 22:36:20 +00:00
if ( mServices & Service_CreateSpells )
2012-11-05 20:34:11 +00:00
mTopicsList - > addItem ( gmst . find ( " sSpellmakingMenuTitle " ) - > getString ( ) ) ;
2012-09-27 06:47:47 +00:00
2012-11-04 22:15:20 +00:00
// if (mServices & Service_Enchant)
2012-11-05 20:34:11 +00:00
// mTopicsList->addItem(gmst.find("sEnchanting")->getString());
2012-09-22 22:36:20 +00:00
2012-10-17 16:03:02 +00:00
if ( mServices & Service_Training )
2012-11-05 20:34:11 +00:00
mTopicsList - > addItem ( gmst . find ( " sServiceTrainingTitle " ) - > getString ( ) ) ;
2012-10-17 16:03:02 +00:00
2012-11-23 18:05:40 +00:00
if ( anyService | | mPtr . getTypeName ( ) = = typeid ( ESM : : NPC ) . name ( ) )
2012-07-13 10:51:58 +00:00
mTopicsList - > addSeparator ( ) ;
2012-05-17 12:54:03 +00:00
2012-06-06 18:29:30 +00:00
for ( std : : list < std : : string > : : iterator it = keyWords . begin ( ) ; it ! = keyWords . end ( ) ; + + it )
2012-01-27 13:50:13 +00:00
{
2012-07-13 10:51:58 +00:00
mTopicsList - > addItem ( * it ) ;
2012-01-27 13:50:13 +00:00
}
2012-07-13 10:51:58 +00:00
mTopicsList - > adjustSize ( ) ;
2012-01-27 13:50:13 +00:00
}
void DialogueWindow : : removeKeyword ( std : : string keyWord )
{
2012-07-13 10:51:58 +00:00
if ( mTopicsList - > hasItem ( keyWord ) )
2012-01-27 13:50:13 +00:00
{
2012-07-13 10:51:58 +00:00
mTopicsList - > removeItem ( keyWord ) ;
2012-01-27 13:50:13 +00:00
}
2012-07-13 10:51:58 +00:00
mTopicsList - > adjustSize ( ) ;
2012-01-27 13:50:13 +00:00
}
2012-02-05 09:54:56 +00:00
void addColorInString ( std : : string & str , const std : : string & keyword , std : : string color1 , std : : string color2 )
2012-01-27 13:50:13 +00:00
{
size_t pos = 0 ;
2012-02-05 09:54:56 +00:00
while ( ( pos = find_str_ci ( str , keyword , pos ) ) ! = std : : string : : npos )
2012-01-27 13:50:13 +00:00
{
2012-11-28 01:36:33 +00:00
// do not add color if this portion of text is already colored.
{
MyGUI : : TextIterator iterator ( str ) ;
MyGUI : : UString colour ;
while ( iterator . moveNext ( ) )
{
size_t iteratorPos = iterator . getPosition ( ) ;
iterator . getTagColour ( colour ) ;
if ( iteratorPos = = pos )
break ;
}
if ( colour = = color1 )
return ;
}
2012-11-23 18:05:40 +00:00
str . insert ( pos , color1 ) ;
pos + = color1 . length ( ) ;
pos + = keyword . length ( ) ;
str . insert ( pos , color2 ) ;
pos + = color2 . length ( ) ;
2012-01-27 13:50:13 +00:00
}
}
2012-12-31 00:15:47 +00:00
std : : string DialogueWindow : : parseText ( const std : : string & text )
2012-01-27 13:50:13 +00:00
{
2012-06-19 13:24:52 +00:00
bool separatorReached = false ; // only parse topics that are below the separator (this prevents actions like "Barter" that are not topics from getting blue-colored)
2012-11-23 18:05:40 +00:00
std : : vector < std : : string > topics ;
2012-07-13 10:51:58 +00:00
for ( unsigned int i = 0 ; i < mTopicsList - > getItemCount ( ) ; i + + )
2012-01-27 13:50:13 +00:00
{
2012-07-13 10:51:58 +00:00
std : : string keyWord = mTopicsList - > getItemNameAt ( i ) ;
2012-11-23 18:21:13 +00:00
if ( separatorReached )
2012-11-23 18:05:40 +00:00
topics . push_back ( keyWord ) ;
2012-11-23 18:21:13 +00:00
else if ( keyWord = = " " )
2012-06-19 13:24:52 +00:00
separatorReached = true ;
2012-01-27 13:50:13 +00:00
}
2012-11-23 18:05:40 +00:00
// sort by length to make sure longer topics are replaced first
std : : sort ( topics . begin ( ) , topics . end ( ) , sortByLength ) ;
2012-12-31 00:15:47 +00:00
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 )
2012-11-23 18:05:40 +00:00
{
2012-12-31 00:15:47 +00:00
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 =
2013-01-01 18:18:21 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - >
getTranslationDataStorage ( ) . topicStandardForm ( standardForm ) ;
2012-12-31 00:15:47 +00:00
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 ( hypertext [ i ] . mText , * it , " #686EBA " , " #B29154 " ) ;
}
}
result + = hypertext [ i ] . mText ;
}
hypertextPos + = MyGUI : : UString ( hypertext [ i ] . mText ) . length ( ) ;
2012-11-23 18:05:40 +00:00
}
2012-12-31 00:15:47 +00:00
return result ;
2012-01-27 13:50:13 +00:00
}
2012-02-05 09:54:56 +00:00
void DialogueWindow : : addText ( std : : string text )
{
2012-07-13 10:51:58 +00:00
mHistory - > addDialogText ( " #B29154 " + parseText ( text ) + " #B29154 " ) ;
2012-02-05 09:54:56 +00:00
}
2012-12-27 15:28:13 +00:00
void DialogueWindow : : addMessageBox ( const std : : string & text )
2012-12-26 22:57:53 +00:00
{
mHistory - > addDialogText ( " \n #FFFFFF " + text + " #B29154 " ) ;
}
2012-03-16 16:30:59 +00:00
void DialogueWindow : : addTitle ( std : : string text )
{
2012-04-17 21:47:50 +00:00
// This is called from the dialogue manager, so text is
// case-smashed - thus we have to retrieve the correct case
// of the text through the topic list.
2012-07-13 10:51:58 +00:00
for ( size_t i = 0 ; i < mTopicsList - > getItemCount ( ) ; + + i )
2012-04-17 21:47:50 +00:00
{
2012-07-13 10:51:58 +00:00
std : : string item = mTopicsList - > getItemNameAt ( i ) ;
2012-04-17 21:47:50 +00:00
if ( lower_string ( item ) = = text )
text = item ;
}
2012-07-13 10:51:58 +00:00
mHistory - > addDialogHeading ( text ) ;
2012-03-16 16:30:59 +00:00
}
void DialogueWindow : : askQuestion ( std : : string question )
2012-01-28 15:08:22 +00:00
{
2012-07-13 10:51:58 +00:00
mHistory - > addDialogText ( " #572D21 " + question + " #B29154 " + " " ) ;
2012-01-28 15:08:22 +00:00
}
2010-11-03 20:21:08 +00:00
void DialogueWindow : : updateOptions ( )
{
//Clear the list of topics
2012-07-13 10:51:58 +00:00
mTopicsList - > clear ( ) ;
2012-12-31 00:15:47 +00:00
mHyperLinks . clear ( ) ;
2012-07-13 10:51:58 +00:00
mHistory - > eraseText ( 0 , mHistory - > getTextLength ( ) ) ;
2012-01-27 13:50:13 +00:00
2012-11-08 21:31:08 +00:00
if ( mPtr . getTypeName ( ) = = typeid ( ESM : : NPC ) . name ( ) )
{
mDispositionBar - > setProgressRange ( 100 ) ;
2012-11-09 13:42:09 +00:00
mDispositionBar - > setProgressPosition ( MWBase : : Environment : : get ( ) . getMechanicsManager ( ) - > getDerivedDisposition ( mPtr ) ) ;
2012-11-08 21:31:08 +00:00
mDispositionText - > eraseText ( 0 , mDispositionText - > getTextLength ( ) ) ;
2012-11-09 13:42:09 +00:00
mDispositionText - > addText ( " #B29154 " + boost : : lexical_cast < std : : string > ( MWBase : : Environment : : get ( ) . getMechanicsManager ( ) - > getDerivedDisposition ( mPtr ) ) + std : : string ( " /100 " ) + " #B29154 " ) ;
2012-11-08 21:31:08 +00:00
}
2010-11-03 20:21:08 +00:00
}
2012-05-11 05:18:41 +00:00
void DialogueWindow : : goodbye ( )
{
2012-11-05 20:34:11 +00:00
mHistory - > addDialogText ( " \n #572D21 " + MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) . get < ESM : : GameSetting > ( ) . find ( " sGoodbye " ) - > getString ( ) ) ;
2012-07-13 10:51:58 +00:00
mTopicsList - > setEnabled ( false ) ;
2012-05-11 05:18:41 +00:00
mEnabled = false ;
}
2012-05-26 23:14:33 +00:00
void DialogueWindow : : onReferenceUnavailable ( )
{
mWindowManager . removeGuiMode ( GM_Dialogue ) ;
}
2012-11-05 22:16:37 +00:00
void DialogueWindow : : onFrame ( )
{
2013-01-14 23:59:48 +00:00
if ( mMainWidget - > getVisible ( ) & & mEnabled & & mPtr . getTypeName ( ) = = typeid ( ESM : : NPC ) . name ( ) )
2012-11-05 22:16:37 +00:00
{
2012-11-09 23:29:36 +00:00
int disp = std : : max ( 0 , std : : min ( 100 ,
MWBase : : Environment : : get ( ) . getMechanicsManager ( ) - > getDerivedDisposition ( mPtr )
+ MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > getTemporaryDispositionChange ( ) ) ) ;
2012-11-05 22:16:37 +00:00
mDispositionBar - > setProgressRange ( 100 ) ;
2012-11-09 23:29:36 +00:00
mDispositionBar - > setProgressPosition ( disp ) ;
2012-11-05 22:16:37 +00:00
mDispositionText - > eraseText ( 0 , mDispositionText - > getTextLength ( ) ) ;
2012-11-09 23:29:36 +00:00
mDispositionText - > addText ( " #B29154 " + boost : : lexical_cast < std : : string > ( disp ) + std : : string ( " /100 " ) + " #B29154 " ) ;
2012-11-05 22:16:37 +00:00
}
}