@ -3,6 +3,8 @@
# include <MyGUI_LanguageManager.h>
# include <MyGUI_LanguageManager.h>
# include <MyGUI_Window.h>
# include <MyGUI_Window.h>
# include <MyGUI_ProgressBar.h>
# include <MyGUI_ProgressBar.h>
# include <MyGUI_ScrollBar.h>
# include <MyGUI_Button.h>
# include <components/widgets/list.hpp>
# include <components/widgets/list.hpp>
# include <components/translation/translation.hpp>
# include <components/translation/translation.hpp>
@ -20,7 +22,6 @@
# include "../mwmechanics/creaturestats.hpp"
# include "../mwmechanics/creaturestats.hpp"
# include "../mwmechanics/actorutil.hpp"
# include "../mwmechanics/actorutil.hpp"
# include "widgets.hpp"
# include "bookpage.hpp"
# include "bookpage.hpp"
# include "textcolours.hpp"
# include "textcolours.hpp"
@ -52,7 +53,7 @@ namespace MWGui
void PersuasionDialog : : onCancel ( MyGUI : : Widget * sender )
void PersuasionDialog : : onCancel ( MyGUI : : Widget * sender )
{
{
exit( ) ;
setVisible( false ) ;
}
}
void PersuasionDialog : : onPersuade ( MyGUI : : Widget * sender )
void PersuasionDialog : : onPersuade ( MyGUI : : Widget * sender )
@ -68,14 +69,15 @@ namespace MWGui
else /*if (sender == mBribe1000Button)*/
else /*if (sender == mBribe1000Button)*/
type = MWBase : : MechanicsManager : : PT_Bribe1000 ;
type = MWBase : : MechanicsManager : : PT_Bribe1000 ;
MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > persuade ( type ) ;
MWBase : : DialogueManager : : Response response = MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > persuade ( type ) ;
eventPersuadeMsg ( response . first , response . second ) ;
setVisible ( false ) ;
setVisible ( false ) ;
}
}
void PersuasionDialog : : o pen( )
void PersuasionDialog : : o nO pen( )
{
{
WindowModal : : open ( ) ;
center ( ) ;
center ( ) ;
MWWorld : : Ptr player = MWMechanics : : getPlayer ( ) ;
MWWorld : : Ptr player = MWMechanics : : getPlayer ( ) ;
@ -86,11 +88,12 @@ namespace MWGui
mBribe1000Button - > setEnabled ( playerGold > = 1000 ) ;
mBribe1000Button - > setEnabled ( playerGold > = 1000 ) ;
mGoldLabel - > setCaptionWithReplacing ( " #{sGold}: " + MyGUI : : utility : : toString ( playerGold ) ) ;
mGoldLabel - > setCaptionWithReplacing ( " #{sGold}: " + MyGUI : : utility : : toString ( playerGold ) ) ;
WindowModal : : onOpen ( ) ;
}
}
void PersuasionDialog : : exi t( )
MyGUI : : Widget * PersuasionDialog : : g etDefaultKeyFocus ( )
{
{
setVisible ( false ) ;
return mAdmireButton ;
}
}
// --------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------
@ -219,31 +222,27 @@ namespace MWGui
void Choice : : activated ( )
void Choice : : activated ( )
{
{
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > playSound ( " Menu Click " ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > playSound ( " Menu Click " ) ;
MWBase: : Environment : : get ( ) . getDialogueManager ( ) - > questionAnswer ed( mChoiceId ) ;
eventChoiceActivat ed( mChoiceId ) ;
}
}
void Topic : : activated ( )
void Topic : : activated ( )
{
{
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > playSound ( " Menu Click " ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > playSound ( " Menu Click " ) ;
MWBase: : Environment : : get ( ) . getDialogueManager ( ) - > keywordSelected ( Misc : : StringUtils : : lowerCase ( mTopicId ) ) ;
eventTopicActivated( mTopicId ) ;
}
}
void Goodbye : : activated ( )
void Goodbye : : activated ( )
{
{
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > playSound ( " Menu Click " ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > playSound ( " Menu Click " ) ;
MWBase: : Environment : : get ( ) . getDialogueManager ( ) - > goodbyeSelec ted( ) ;
eventActiva ted( ) ;
}
}
// --------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------
DialogueWindow : : DialogueWindow ( )
DialogueWindow : : DialogueWindow ( )
: WindowBase ( " openmw_dialogue_window.layout " )
: WindowBase ( " openmw_dialogue_window.layout " )
, mServices ( 0 )
, mIsCompanion ( false )
, mEnabled ( false )
, mGoodbye ( false )
, mGoodbye ( false )
, mPersuasionDialog ( )
, mPersuasionDialog ( )
{
{
@ -251,17 +250,17 @@ namespace MWGui
center ( ) ;
center ( ) ;
mPersuasionDialog . setVisible ( false ) ;
mPersuasionDialog . setVisible ( false ) ;
mPersuasionDialog . eventPersuadeMsg + = MyGUI : : newDelegate ( this , & DialogueWindow : : onPersuadeResult ) ;
//History view
//History view
getWidget ( mHistory , " History " ) ;
getWidget ( mHistory , " History " ) ;
//Topics list
//Topics list
getWidget ( mTopicsList , " TopicsList " ) ;
getWidget ( mTopicsList , " TopicsList " ) ;
mTopicsList - > eventItemSelected + = MyGUI : : newDelegate ( this , & DialogueWindow : : onSelect Topic ) ;
mTopicsList - > eventItemSelected + = MyGUI : : newDelegate ( this , & DialogueWindow : : onSelect ListItem ) ;
MyGUI : : Button * byeButton ;
getWidget ( mGoodbyeButton , " ByeButton " ) ;
getWidget ( byeButton , " ByeButton " ) ;
mGoodbyeButton - > eventMouseButtonClick + = MyGUI : : newDelegate ( this , & DialogueWindow : : onByeClicked ) ;
byeButton - > eventMouseButtonClick + = MyGUI : : newDelegate ( this , & DialogueWindow : : onByeClicked ) ;
getWidget ( mDispositionBar , " Disposition " ) ;
getWidget ( mDispositionBar , " Disposition " ) ;
getWidget ( mDispositionText , " DispositionText " ) ;
getWidget ( mDispositionText , " DispositionText " ) ;
@ -276,18 +275,36 @@ namespace MWGui
mMainWidget - > castType < MyGUI : : Window > ( ) - > eventWindowChangeCoord + = MyGUI : : newDelegate ( this , & DialogueWindow : : onWindowResize ) ;
mMainWidget - > castType < MyGUI : : Window > ( ) - > eventWindowChangeCoord + = MyGUI : : newDelegate ( this , & DialogueWindow : : onWindowResize ) ;
}
}
void DialogueWindow : : exit ( )
DialogueWindow : : ~ DialogueWindow ( )
{
{
if ( ( ! mEnabled | | MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > isInChoice ( ) )
mPersuasionDialog . eventPersuadeMsg . clear ( ) ;
& & ! mGoodbye )
deleteLater ( ) ;
for ( Link * link : mLinks )
delete link ;
for ( auto link : mTopicLinks )
delete link . second ;
for ( auto history : mHistoryContents )
delete history ;
}
void DialogueWindow : : onTradeComplete ( )
{
{
// in choice, not allowed to escape, but give access to main menu to allow loading other saves
addResponse ( " " , MyGUI : : LanguageManager : : getInstance ( ) . replaceTags ( " #{sBarterDialog5} " ) ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > pushGuiMode ( MWGui : : GM_MainMenu ) ;
}
bool DialogueWindow : : exit ( )
{
if ( ( MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > isInChoice ( ) ) )
{
return false ;
}
}
else
else
{
{
resetReference ( ) ;
MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > goodbyeSelected ( ) ;
MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > goodbyeSelected ( ) ;
mTopicsList - > scrollToTop ( ) ;
mTopicsList - > scrollToTop ( ) ;
return true ;
}
}
}
}
@ -312,12 +329,13 @@ namespace MWGui
void DialogueWindow : : onByeClicked ( MyGUI : : Widget * _sender )
void DialogueWindow : : onByeClicked ( MyGUI : : Widget * _sender )
{
{
exit ( ) ;
if ( exit ( ) )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > removeGuiMode ( GM_Dialogue ) ;
}
}
void DialogueWindow : : onSelect Topic ( const std : : string & topic , int id )
void DialogueWindow : : onSelect ListItem ( const std : : string & topic , int id )
{
{
if ( ! mEnabled | | MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > isInChoice ( ) )
if ( mGoodbye | | MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > isInChoice ( ) )
return ;
return ;
int separatorPos = 0 ;
int separatorPos = 0 ;
@ -328,63 +346,84 @@ namespace MWGui
}
}
if ( id > = separatorPos )
if ( id > = separatorPos )
MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > keywordSelected ( Misc : : StringUtils : : lowerCase ( topic ) ) ;
{
onTopicActivated ( topic ) ;
if ( mGoodbyeButton - > getEnabled ( ) )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > setKeyFocusWidget ( mGoodbyeButton ) ;
}
else
else
{
{
const MWWorld : : Store < ESM : : GameSetting > & gmst =
const MWWorld : : Store < ESM : : GameSetting > & gmst =
MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) . get < ESM : : GameSetting > ( ) ;
MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) . get < ESM : : GameSetting > ( ) ;
MWBase : : DialogueManager : : Response response ;
if ( topic = = gmst . find ( " sPersuasion " ) - > getString ( ) )
if ( topic = = gmst . find ( " sPersuasion " ) - > getString ( ) )
mPersuasionDialog . setVisible ( true ) ;
mPersuasionDialog . setVisible ( true ) ;
else if ( topic = = gmst . find ( " sCompanionShare " ) - > getString ( ) )
else if ( topic = = gmst . find ( " sCompanionShare " ) - > getString ( ) )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > showCompanionWindow( mPtr ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > pushGuiMode( GM_Companion , mPtr ) ;
else if ( ! MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > checkServiceRefused ( ) )
else if ( ! MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > checkServiceRefused ( response ) )
{
{
if ( topic = = gmst . find ( " sBarter " ) - > getString ( ) )
if ( topic = = gmst . find ( " sBarter " ) - > getString ( ) )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > startTrade( mPtr ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > pushGuiMode( GM_Barter , mPtr ) ;
else if ( topic = = gmst . find ( " sSpells " ) - > getString ( ) )
else if ( topic = = gmst . find ( " sSpells " ) - > getString ( ) )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > startSpellBuying( mPtr ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > pushGuiMode( GM_SpellBuying , mPtr ) ;
else if ( topic = = gmst . find ( " sTravel " ) - > getString ( ) )
else if ( topic = = gmst . find ( " sTravel " ) - > getString ( ) )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > startTravel( mPtr ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > pushGuiMode( GM_Travel , mPtr ) ;
else if ( topic = = gmst . find ( " sSpellMakingMenuTitle " ) - > getString ( ) )
else if ( topic = = gmst . find ( " sSpellMakingMenuTitle " ) - > getString ( ) )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > startSpellMaking ( mPtr ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > pushGuiMode( GM_SpellCreation , mPtr ) ;
else if ( topic = = gmst . find ( " sEnchanting " ) - > getString ( ) )
else if ( topic = = gmst . find ( " sEnchanting " ) - > getString ( ) )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > startEnchanting ( mPtr ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > pushGuiMode( GM_Enchanting , mPtr ) ;
else if ( topic = = gmst . find ( " sServiceTrainingTitle " ) - > getString ( ) )
else if ( topic = = gmst . find ( " sServiceTrainingTitle " ) - > getString ( ) )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > startTraining ( mPtr ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > pushGuiMode( GM_Training , mPtr ) ;
else if ( topic = = gmst . find ( " sRepair " ) - > getString ( ) )
else if ( topic = = gmst . find ( " sRepair " ) - > getString ( ) )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > startRepair ( mPtr ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > pushGuiMode( GM_MerchantRepair , mPtr ) ;
}
}
else
addResponse ( response . first , response . second ) ;
}
}
}
}
void DialogueWindow : : startDialogue ( MWWorld : : Ptr actor , std : : string npcName , bool resetHistory )
void DialogueWindow : : setPtr ( const MWWorld : : Ptr & actor )
{
MWBase : : DialogueManager : : Response response ;
if ( ! MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > startDialogue ( actor , response ) )
{
{
// No greetings found. The dialogue window should not be shown.
// If this is a companion, we must show the companion window directly (used by BM_bear_be_unique).
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > removeGuiMode ( MWGui : : GM_Dialogue ) ;
if ( isCompanion ( ) )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > pushGuiMode ( MWGui : : GM_Companion , mPtr ) ;
return ;
}
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > setKeyFocusWidget ( mGoodbyeButton ) ;
mGoodbye = false ;
mGoodbye = false ;
mEnabled = true ;
bool sameActor = ( mPtr = = actor ) ;
bool sameActor = ( mPtr = = actor ) ;
mPtr = actor ;
mPtr = actor ;
mTopicsList - > setEnabled ( true ) ;
mTopicsList - > setEnabled ( true ) ;
setTitle ( npcName ) ;
setTitle ( mPtr . getClass ( ) . getName ( mPtr ) ) ;
clearChoices ( ) ;
mTopicsList - > clear ( ) ;
mTopicsList - > clear ( ) ;
if ( resetHistory | | ! sameActor )
if ( ! sameActor )
{
{
for ( std : : vector < DialogueText * > : : iterator it = mHistoryContents . begin ( ) ; it ! = mHistoryContents . end ( ) ; + + it )
for ( std : : vector < DialogueText * > : : iterator it = mHistoryContents . begin ( ) ; it ! = mHistoryContents . end ( ) ; + + it )
delete ( * it ) ;
delete ( * it ) ;
mHistoryContents . clear ( ) ;
mHistoryContents . clear ( ) ;
mKeywords . clear ( ) ;
updateTopicsPane ( ) ;
}
}
for ( std : : vector < Link * > : : iterator it = mLinks . begin ( ) ; it ! = mLinks . end ( ) ; + + it )
for ( std : : vector < Link * > : : iterator it = mLinks . begin ( ) ; it ! = mLinks . end ( ) ; + + it )
delete ( * it ) ;
mDeleteLater . push_back ( * it ) ; // Links are not deleted right away to prevent issues with event handlers
mLinks . clear ( ) ;
mLinks . clear ( ) ;
updateOptions ( ) ;
updateDisposition ( ) ;
restock ( ) ;
restock ( ) ;
addResponse ( response . first , response . second , false ) ;
}
}
void DialogueWindow : : restock ( )
void DialogueWindow : : restock ( )
@ -401,16 +440,35 @@ namespace MWGui
}
}
}
}
void DialogueWindow : : deleteLater ( )
{
for ( Link * link : mDeleteLater )
delete link ;
mDeleteLater . clear ( ) ;
}
void DialogueWindow : : setKeywords ( std : : list < std : : string > keyWords )
void DialogueWindow : : setKeywords ( std : : list < std : : string > keyWords )
{
if ( mKeywords = = keyWords & & isCompanion ( ) = = mIsCompanion )
return ;
mIsCompanion = isCompanion ( ) ;
mKeywords = keyWords ;
updateTopicsPane ( ) ;
}
void DialogueWindow : : updateTopicsPane ( )
{
{
mTopicsList - > clear ( ) ;
mTopicsList - > clear ( ) ;
for ( std : : map < std : : string , Link * > : : iterator it = mTopicLinks . begin ( ) ; it ! = mTopicLinks . end ( ) ; + + it )
for ( std : : map < std : : string , Link * > : : iterator it = mTopicLinks . begin ( ) ; it ! = mTopicLinks . end ( ) ; + + it )
delete it - > second ;
mDeleteLater . push_back ( it - > second ) ;
mTopicLinks . clear ( ) ;
mTopicLinks . clear ( ) ;
mKeywordSearch . clear ( ) ;
mKeywordSearch . clear ( ) ;
bool isCompanion = ! mPtr . getClass ( ) . getScript ( mPtr ) . empty ( )
int services = mPtr . getClass ( ) . getServices ( mPtr ) ;
& & mPtr . getRefData ( ) . getLocals ( ) . getIntVar ( mPtr . getClass ( ) . getScript ( mPtr ) , " companion " ) ;
bool travel = ( mPtr . getTypeName ( ) = = typeid ( ESM : : NPC ) . name ( ) & & ! mPtr . get < ESM : : NPC > ( ) - > mBase - > getTransport ( ) . empty ( ) )
| | ( mPtr . getTypeName ( ) = = typeid ( ESM : : Creature ) . name ( ) & & ! mPtr . get < ESM : : Creature > ( ) - > mBase - > getTransport ( ) . empty ( ) ) ;
const MWWorld : : Store < ESM : : GameSetting > & gmst =
const MWWorld : : Store < ESM : : GameSetting > & gmst =
MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) . get < ESM : : GameSetting > ( ) ;
MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) . get < ESM : : GameSetting > ( ) ;
@ -418,39 +476,40 @@ namespace MWGui
if ( mPtr . getTypeName ( ) = = typeid ( ESM : : NPC ) . name ( ) )
if ( mPtr . getTypeName ( ) = = typeid ( ESM : : NPC ) . name ( ) )
mTopicsList - > addItem ( gmst . find ( " sPersuasion " ) - > getString ( ) ) ;
mTopicsList - > addItem ( gmst . find ( " sPersuasion " ) - > getString ( ) ) ;
if ( mServices & Service_Trade )
if ( services & ESM : : NPC : : AllItems )
mTopicsList - > addItem ( gmst . find ( " sBarter " ) - > getString ( ) ) ;
mTopicsList - > addItem ( gmst . find ( " sBarter " ) - > getString ( ) ) ;
if ( mServices & Service_Buy Spells)
if ( services & ESM : : NPC : : Spells)
mTopicsList - > addItem ( gmst . find ( " sSpells " ) - > getString ( ) ) ;
mTopicsList - > addItem ( gmst . find ( " sSpells " ) - > getString ( ) ) ;
if ( mServices & Service_T ravel)
if ( t ravel)
mTopicsList - > addItem ( gmst . find ( " sTravel " ) - > getString ( ) ) ;
mTopicsList - > addItem ( gmst . find ( " sTravel " ) - > getString ( ) ) ;
if ( mServices & Service_CreateSpells )
if ( services & ESM : : NPC : : Spellmaking )
mTopicsList - > addItem ( gmst . find ( " sSpellmakingMenuTitle " ) - > getString ( ) ) ;
mTopicsList - > addItem ( gmst . find ( " sSpellmakingMenuTitle " ) - > getString ( ) ) ;
if ( mServices & Service_Enchant )
if ( services & ESM : : NPC : : Enchanting )
mTopicsList - > addItem ( gmst . find ( " sEnchanting " ) - > getString ( ) ) ;
mTopicsList - > addItem ( gmst . find ( " sEnchanting " ) - > getString ( ) ) ;
if ( mServices & Service_ Training)
if ( services & ESM : : NPC : : Training)
mTopicsList - > addItem ( gmst . find ( " sServiceTrainingTitle " ) - > getString ( ) ) ;
mTopicsList - > addItem ( gmst . find ( " sServiceTrainingTitle " ) - > getString ( ) ) ;
if ( mServices & Service_ Repair)
if ( services & ESM : : NPC : : Repair)
mTopicsList - > addItem ( gmst . find ( " sRepair " ) - > getString ( ) ) ;
mTopicsList - > addItem ( gmst . find ( " sRepair " ) - > getString ( ) ) ;
if ( isCompanion )
if ( isCompanion () )
mTopicsList - > addItem ( gmst . find ( " sCompanionShare " ) - > getString ( ) ) ;
mTopicsList - > addItem ( gmst . find ( " sCompanionShare " ) - > getString ( ) ) ;
if ( mTopicsList - > getItemCount ( ) > 0 )
if ( mTopicsList - > getItemCount ( ) > 0 )
mTopicsList - > addSeparator ( ) ;
mTopicsList - > addSeparator ( ) ;
for ( std : : list < std : : string > : : iterator it = keyWords. begin ( ) ; it ! = keyW ords. end ( ) ; + + it )
for ( std : : list < std : : string > : : iterator it = mKeywords. begin ( ) ; it ! = mKeyw ords. end ( ) ; + + it )
{
{
mTopicsList - > addItem ( * it ) ;
mTopicsList - > addItem ( * it ) ;
Topic * t = new Topic ( * it ) ;
Topic * t = new Topic ( * it ) ;
t - > eventTopicActivated + = MyGUI : : newDelegate ( this , & DialogueWindow : : onTopicActivated ) ;
mTopicLinks [ Misc : : StringUtils : : lowerCase ( * it ) ] = t ;
mTopicLinks [ Misc : : StringUtils : : lowerCase ( * it ) ] = t ;
mKeywordSearch . seed ( Misc : : StringUtils : : lowerCase ( * it ) , intptr_t ( t ) ) ;
mKeywordSearch . seed ( Misc : : StringUtils : : lowerCase ( * it ) , intptr_t ( t ) ) ;
@ -484,9 +543,11 @@ namespace MWGui
typesetter - > sectionBreak ( 9 ) ;
typesetter - > sectionBreak ( 9 ) ;
// choices
// choices
const TextColours & textColours = MWBase : : Environment : : get ( ) . getWindowManager ( ) - > getTextColours ( ) ;
const TextColours & textColours = MWBase : : Environment : : get ( ) . getWindowManager ( ) - > getTextColours ( ) ;
for ( std : : vector < std : : pair < std : : string , int > > : : iterator it = mChoices . begin ( ) ; it ! = mChoices . end ( ) ; + + it )
mChoices = MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > getChoices ( ) ;
for ( std : : vector < std : : pair < std : : string , int > > : : const_iterator it = mChoices . begin ( ) ; it ! = mChoices . end ( ) ; + + it )
{
{
Choice * link = new Choice ( it - > second ) ;
Choice * link = new Choice ( it - > second ) ;
link - > eventChoiceActivated + = MyGUI : : newDelegate ( this , & DialogueWindow : : onChoiceActivated ) ;
mLinks . push_back ( link ) ;
mLinks . push_back ( link ) ;
typesetter - > lineBreak ( ) ;
typesetter - > lineBreak ( ) ;
@ -496,9 +557,11 @@ namespace MWGui
typesetter - > write ( questionStyle , to_utf8_span ( it - > first . c_str ( ) ) ) ;
typesetter - > write ( questionStyle , to_utf8_span ( it - > first . c_str ( ) ) ) ;
}
}
mGoodbye = MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > isGoodbye ( ) ;
if ( mGoodbye )
if ( mGoodbye )
{
{
Goodbye * link = new Goodbye ( ) ;
Goodbye * link = new Goodbye ( ) ;
link - > eventActivated + = MyGUI : : newDelegate ( this , & DialogueWindow : : onGoodbyeActivated ) ;
mLinks . push_back ( link ) ;
mLinks . push_back ( link ) ;
std : : string goodbye = MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) . get < ESM : : GameSetting > ( ) . find ( " sGoodbye " ) - > getString ( ) ;
std : : string goodbye = MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) . get < ESM : : GameSetting > ( ) . find ( " sGoodbye " ) - > getString ( ) ;
BookTypesetter : : Style * questionStyle = typesetter - > createHotStyle ( body , textColours . answer , textColours . answerOver ,
BookTypesetter : : Style * questionStyle = typesetter - > createHotStyle ( body , textColours . answer , textColours . answerOver ,
@ -528,10 +591,11 @@ namespace MWGui
onScrollbarMoved ( mScrollBar , 0 ) ;
onScrollbarMoved ( mScrollBar , 0 ) ;
}
}
MyGUI : : Button * byeButton ;
getWidget ( byeButton , " ByeButton " ) ;
bool goodbyeEnabled = ! MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > isInChoice ( ) | | mGoodbye ;
bool goodbyeEnabled = ! MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > isInChoice ( ) | | mGoodbye ;
byeButton - > setEnabled ( goodbyeEnabled ) ;
bool goodbyeWasEnabled = mGoodbyeButton - > getEnabled ( ) ;
mGoodbyeButton - > setEnabled ( goodbyeEnabled ) ;
if ( goodbyeEnabled & & ! goodbyeWasEnabled )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > setKeyFocusWidget ( mGoodbyeButton ) ;
bool topicsEnabled = ! MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > isInChoice ( ) & & ! mGoodbye ;
bool topicsEnabled = ! MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > isInChoice ( ) & & ! mGoodbye ;
mTopicsList - > setEnabled ( topicsEnabled ) ;
mTopicsList - > setEnabled ( topicsEnabled ) ;
@ -542,59 +606,47 @@ namespace MWGui
reinterpret_cast < Link * > ( link ) - > activated ( ) ;
reinterpret_cast < Link * > ( link ) - > activated ( ) ;
}
}
void DialogueWindow : : on ScrollbarMoved( MyGUI : : ScrollBar * sender , size_t pos )
void DialogueWindow : : on TopicActivated( const std : : string & topicId )
{
{
mHistory - > setPosition ( 0 , static_cast < int > ( pos ) * - 1 ) ;
MWBase : : DialogueManager : : Response response = MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > keywordSelected ( topicId ) ;
addResponse ( response . first , response . second ) ;
}
}
void DialogueWindow : : addResponse ( const std : : string & text , const std : : string & title , bool needMargin )
void DialogueWindow : : onChoiceActivated ( int id )
{
// This is called from the dialogue manager, so text is
// 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 ) ;
MWBase : : DialogueManager : : Response response = MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > questionAnswered ( id ) ;
if ( Misc : : StringUtils : : ciEqual ( item , title ) )
addResponse ( response . first , response . second ) ;
{
realTitle = item ;
break ;
}
}
}
}
mHistoryContents . push_back ( new Response ( text , realTitle , needMargin ) ) ;
void DialogueWindow : : onGoodbyeActivated ( )
updateHistory ( ) ;
{
MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > goodbyeSelected ( ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > removeGuiMode ( MWGui : : GM_Dialogue ) ;
resetReference ( ) ;
}
}
void DialogueWindow : : addMessageBox ( const std : : string & text )
void DialogueWindow : : onScrollbarMoved( MyGUI : : ScrollBar * sender , size_t pos )
{
{
mHistoryContents . push_back ( new Message ( text ) ) ;
mHistory - > setPosition ( 0 , static_cast < int > ( pos ) * - 1 ) ;
updateHistory ( ) ;
}
}
void DialogueWindow : : add Choice( const std : : string & choice , int id )
void DialogueWindow : : add Response( const std : : string & title , const std : : string & text , bool needMargin )
{
{
m Choices. push_back ( std : : make_pair ( choice , id ) ) ;
m HistoryContents. push_back ( new Response ( text , title , needMargin ) ) ;
updateHistory ( ) ;
updateHistory ( ) ;
updateTopics ( ) ;
}
}
void DialogueWindow : : clearChoices( )
void DialogueWindow : : addMessageBox( const std : : string & text )
{
{
m Choices. clear ( ) ;
m HistoryContents. push_back ( new Message ( text ) ) ;
updateHistory ( ) ;
updateHistory ( ) ;
}
}
void DialogueWindow : : update Options ( )
void DialogueWindow : : update Disposition ( )
{
{
//Clear the list of topics
mTopicsList - > clear ( ) ;
bool dispositionVisible = false ;
bool dispositionVisible = false ;
if ( mPtr . getClass ( ) . isNpc ( ) )
if ( ! mPtr . isEmpty ( ) & & mPtr . getClass ( ) . isNpc ( ) )
{
{
dispositionVisible = true ;
dispositionVisible = true ;
mDispositionBar - > setProgressRange ( 100 ) ;
mDispositionBar - > setProgressRange ( 100 ) ;
@ -620,26 +672,38 @@ namespace MWGui
}
}
}
}
void DialogueWindow : : goodby e( )
void DialogueWindow : : onReferenceUnavailabl e( )
{
{
mGoodbye = true ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > removeGuiMode ( GM_Dialogue ) ;
mEnabled = false ;
updateHistory ( ) ;
}
}
void DialogueWindow : : on ReferenceUnavailable( )
void DialogueWindow : : on Frame( float dt )
{
{
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > removeGuiMode ( GM_Dialogue ) ;
checkReferenceAvailable ( ) ;
if ( mPtr . isEmpty ( ) )
return ;
updateDisposition ( ) ;
deleteLater ( ) ;
if ( mChoices ! = MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > getChoices ( )
| | mGoodbye ! = MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > isGoodbye ( ) )
updateHistory ( ) ;
}
}
void DialogueWindow : : onFrame ( )
void DialogueWindow : : updateTopics ( )
{
{
if ( mMainWidget - > getVisible ( ) & & mPtr . getTypeName ( ) = = typeid ( ESM : : NPC ) . name ( ) )
setKeywords ( MWBase : : Environment : : get ( ) . getDialogueManager ( ) - > getAvailableTopics ( ) ) ;
}
bool DialogueWindow : : isCompanion ( )
{
{
int disp = MWBase : : Environment : : get ( ) . getMechanicsManager ( ) - > getDerivedDisposition ( mPtr ) ;
return ! mPtr . getClass ( ) . getScript ( mPtr ) . empty ( )
mDispositionBar - > setProgressRange ( 100 ) ;
& & mPtr . getRefData ( ) . getLocals ( ) . getIntVar ( mPtr . getClass ( ) . getScript ( mPtr ) , " companion " ) ;
mDispositionBar - > setProgressPosition ( disp ) ;
mDispositionText - > setCaption ( MyGUI : : utility : : toString ( disp ) + std : : string ( " /100 " ) ) ;
}
}
void DialogueWindow : : onPersuadeResult ( const std : : string & title , const std : : string & text )
{
addResponse ( title , text ) ;
}
}
}
}