2011-12-01 12:44:34 +00:00
# include "journalwindow.hpp"
2012-07-03 10:30:50 +00:00
2013-01-13 21:03:11 +00:00
# include <set>
2013-01-27 20:16:46 +00:00
# include <stack>
2013-01-13 21:03:11 +00:00
# include <string>
# include <utility>
2015-01-10 01:50:43 +00:00
# include <MyGUI_TextBox.h>
2015-02-13 15:51:34 +00:00
# include <MyGUI_Button.h>
2017-09-26 22:21:20 +00:00
# include <MyGUI_InputManager.h>
2015-01-10 01:50:43 +00:00
2015-02-09 15:23:41 +00:00
# include <components/misc/stringops.hpp>
2014-09-12 03:14:21 +00:00
# include <components/widgets/imagebutton.hpp>
2014-09-25 14:25:08 +00:00
# include <components/widgets/list.hpp>
2014-09-12 03:14:21 +00:00
2015-01-10 01:50:43 +00:00
# include "../mwbase/environment.hpp"
# include "../mwbase/windowmanager.hpp"
# include "../mwbase/journal.hpp"
2013-01-27 20:16:46 +00:00
# include "bookpage.hpp"
2013-01-13 21:03:11 +00:00
# include "windowbase.hpp"
2013-01-27 20:16:46 +00:00
# include "journalviewmodel.hpp"
# include "journalbooks.hpp"
2013-01-13 21:03:11 +00:00
2012-01-17 12:53:27 +00:00
namespace
2011-12-30 10:39:17 +00:00
{
2013-02-15 05:37:33 +00:00
static char const OptionsOverlay [ ] = " OptionsOverlay " ;
static char const OptionsBTN [ ] = " OptionsBTN " ;
static char const PrevPageBTN [ ] = " PrevPageBTN " ;
static char const NextPageBTN [ ] = " NextPageBTN " ;
static char const CloseBTN [ ] = " CloseBTN " ;
static char const JournalBTN [ ] = " JournalBTN " ;
static char const TopicsBTN [ ] = " TopicsBTN " ;
static char const QuestsBTN [ ] = " QuestsBTN " ;
static char const CancelBTN [ ] = " CancelBTN " ;
static char const ShowAllBTN [ ] = " ShowAllBTN " ;
static char const ShowActiveBTN [ ] = " ShowActiveBTN " ;
static char const PageOneNum [ ] = " PageOneNum " ;
static char const PageTwoNum [ ] = " PageTwoNum " ;
static char const TopicsList [ ] = " TopicsList " ;
static char const QuestsList [ ] = " QuestsList " ;
static char const LeftBookPage [ ] = " LeftBookPage " ;
static char const RightBookPage [ ] = " RightBookPage " ;
static char const LeftTopicIndex [ ] = " LeftTopicIndex " ;
2018-06-18 09:43:39 +00:00
static char const CenterTopicIndex [ ] = " CenterTopicIndex " ;
2013-02-15 05:37:33 +00:00
static char const RightTopicIndex [ ] = " RightTopicIndex " ;
2011-12-01 12:44:34 +00:00
2017-09-22 18:46:08 +00:00
struct JournalWindowImpl : MWGui : : JournalBooks , MWGui : : JournalWindow
2011-12-30 10:39:17 +00:00
{
2013-02-15 05:37:33 +00:00
struct DisplayState
2013-01-27 20:16:46 +00:00
{
2013-05-01 08:28:59 +00:00
unsigned int mPage ;
Book mBook ;
2013-01-27 20:16:46 +00:00
} ;
2011-12-30 10:39:17 +00:00
2013-05-01 08:28:59 +00:00
typedef std : : stack < DisplayState > DisplayStateStack ;
2011-12-01 12:44:34 +00:00
2013-05-01 08:28:59 +00:00
DisplayStateStack mStates ;
Book mTopicIndexBook ;
2013-01-27 20:16:46 +00:00
bool mQuestMode ;
2015-08-15 18:44:15 +00:00
bool mOptionsMode ;
2017-07-30 21:51:32 +00:00
bool mTopicsMode ;
2013-01-27 20:16:46 +00:00
bool mAllQuests ;
2011-12-01 12:44:34 +00:00
2013-05-01 08:28:59 +00:00
template < typename T >
T * getWidget ( char const * name )
2011-12-01 12:44:34 +00:00
{
2013-05-01 08:28:59 +00:00
T * widget ;
2013-01-27 20:16:46 +00:00
WindowBase : : getWidget ( widget , name ) ;
return widget ;
2011-12-01 12:44:34 +00:00
}
2013-01-27 20:16:46 +00:00
template < typename value_type >
void setText ( char const * name , value_type const & value )
2011-12-01 12:44:34 +00:00
{
2013-05-06 14:04:28 +00:00
getWidget < MyGUI : : TextBox > ( name ) - >
2015-01-10 02:01:01 +00:00
setCaption ( MyGUI : : utility : : toString ( value ) ) ;
2011-12-01 12:44:34 +00:00
}
2013-01-27 20:16:46 +00:00
void setVisible ( char const * name , bool visible )
2011-12-01 12:44:34 +00:00
{
2013-05-06 14:04:28 +00:00
getWidget < MyGUI : : Widget > ( name ) - >
2013-01-27 20:16:46 +00:00
setVisible ( visible ) ;
}
2013-05-06 14:04:28 +00:00
void adviseButtonClick ( char const * name , void ( JournalWindowImpl : : * Handler ) ( MyGUI : : Widget * _sender ) )
2013-01-27 20:16:46 +00:00
{
2017-09-26 22:21:20 +00:00
getWidget < MyGUI : : Widget > ( name ) - >
2013-01-27 20:16:46 +00:00
eventMouseButtonClick + = newDelegate ( this , Handler ) ;
}
2017-09-26 22:21:20 +00:00
void adviseKeyPress ( char const * name , void ( JournalWindowImpl : : * Handler ) ( MyGUI : : Widget * _sender , MyGUI : : KeyCode key , MyGUI : : Char character ) )
{
getWidget < MyGUI : : Widget > ( name ) - >
eventKeyButtonPressed + = newDelegate ( this , Handler ) ;
}
2013-03-06 17:25:50 +00:00
MWGui : : BookPage * getPage ( char const * name )
2013-01-27 20:16:46 +00:00
{
2013-03-06 17:25:50 +00:00
return getWidget < MWGui : : BookPage > ( name ) ;
2013-01-27 20:16:46 +00:00
}
2017-11-22 04:32:38 +00:00
JournalWindowImpl ( MWGui : : JournalViewModel : : Ptr Model , bool questList , ToUTF8 : : FromType encoding )
: JournalBooks ( Model , encoding ) , JournalWindow ( )
2013-01-27 20:16:46 +00:00
{
center ( ) ;
2013-03-06 17:25:50 +00:00
adviseButtonClick ( OptionsBTN , & JournalWindowImpl : : notifyOptions ) ;
adviseButtonClick ( PrevPageBTN , & JournalWindowImpl : : notifyPrevPage ) ;
adviseButtonClick ( NextPageBTN , & JournalWindowImpl : : notifyNextPage ) ;
adviseButtonClick ( CloseBTN , & JournalWindowImpl : : notifyClose ) ;
adviseButtonClick ( JournalBTN , & JournalWindowImpl : : notifyJournal ) ;
2013-01-27 20:16:46 +00:00
2013-03-06 17:25:50 +00:00
adviseButtonClick ( TopicsBTN , & JournalWindowImpl : : notifyTopics ) ;
adviseButtonClick ( QuestsBTN , & JournalWindowImpl : : notifyQuests ) ;
adviseButtonClick ( CancelBTN , & JournalWindowImpl : : notifyCancel ) ;
2013-01-27 20:16:46 +00:00
2013-03-06 17:25:50 +00:00
adviseButtonClick ( ShowAllBTN , & JournalWindowImpl : : notifyShowAll ) ;
adviseButtonClick ( ShowActiveBTN , & JournalWindowImpl : : notifyShowActive ) ;
2013-01-27 20:16:46 +00:00
2017-09-26 22:21:20 +00:00
adviseKeyPress ( OptionsBTN , & JournalWindowImpl : : notifyKeyPress ) ;
adviseKeyPress ( PrevPageBTN , & JournalWindowImpl : : notifyKeyPress ) ;
adviseKeyPress ( NextPageBTN , & JournalWindowImpl : : notifyKeyPress ) ;
adviseKeyPress ( CloseBTN , & JournalWindowImpl : : notifyKeyPress ) ;
adviseKeyPress ( JournalBTN , & JournalWindowImpl : : notifyKeyPress ) ;
2014-09-25 14:25:08 +00:00
Gui : : MWList * list = getWidget < Gui : : MWList > ( QuestsList ) ;
2014-06-02 22:16:32 +00:00
list - > eventItemSelected + = MyGUI : : newDelegate ( this , & JournalWindowImpl : : notifyQuestClicked ) ;
2014-09-25 14:25:08 +00:00
Gui : : MWList * topicsList = getWidget < Gui : : MWList > ( TopicsList ) ;
2014-06-03 14:04:18 +00:00
topicsList - > eventItemSelected + = MyGUI : : newDelegate ( this , & JournalWindowImpl : : notifyTopicSelected ) ;
2013-01-27 20:16:46 +00:00
{
2013-05-06 14:04:28 +00:00
MWGui : : BookPage : : ClickCallback callback ;
2013-02-09 18:44:20 +00:00
2017-05-06 13:12:06 +00:00
callback = std : : bind ( & JournalWindowImpl : : notifyTopicClicked , this , std : : placeholders : : _1 ) ;
2013-01-27 20:16:46 +00:00
getPage ( LeftBookPage ) - > adviseLinkClicked ( callback ) ;
getPage ( RightBookPage ) - > adviseLinkClicked ( callback ) ;
2014-08-10 22:51:54 +00:00
getPage ( LeftBookPage ) - > eventMouseWheel + = MyGUI : : newDelegate ( this , & JournalWindowImpl : : notifyMouseWheel ) ;
getPage ( RightBookPage ) - > eventMouseWheel + = MyGUI : : newDelegate ( this , & JournalWindowImpl : : notifyMouseWheel ) ;
2013-01-27 20:16:46 +00:00
}
2011-12-01 12:44:34 +00:00
{
2013-05-06 14:04:28 +00:00
MWGui : : BookPage : : ClickCallback callback ;
2013-02-09 18:44:20 +00:00
2017-05-06 13:12:06 +00:00
callback = std : : bind ( & JournalWindowImpl : : notifyIndexLinkClicked , this , std : : placeholders : : _1 ) ;
2013-01-27 20:16:46 +00:00
getPage ( LeftTopicIndex ) - > adviseLinkClicked ( callback ) ;
2018-06-18 09:43:39 +00:00
getPage ( CenterTopicIndex ) - > adviseLinkClicked ( callback ) ;
2013-01-27 20:16:46 +00:00
getPage ( RightTopicIndex ) - > adviseLinkClicked ( callback ) ;
2011-12-01 12:44:34 +00:00
}
2013-01-27 20:16:46 +00:00
2013-05-08 11:55:15 +00:00
adjustButton ( PrevPageBTN ) ;
2019-04-01 17:47:12 +00:00
float nextButtonScale = adjustButton ( NextPageBTN ) ;
2013-05-08 11:55:15 +00:00
adjustButton ( CloseBTN ) ;
adjustButton ( CancelBTN ) ;
adjustButton ( JournalBTN ) ;
2014-09-12 03:14:21 +00:00
Gui : : ImageButton * optionsButton = getWidget < Gui : : ImageButton > ( OptionsBTN ) ;
2015-12-07 14:32:00 +00:00
Gui : : ImageButton * showActiveButton = getWidget < Gui : : ImageButton > ( ShowActiveBTN ) ;
Gui : : ImageButton * showAllButton = getWidget < Gui : : ImageButton > ( ShowAllBTN ) ;
Gui : : ImageButton * questsButton = getWidget < Gui : : ImageButton > ( QuestsBTN ) ;
2017-11-23 06:14:45 +00:00
Gui : : ImageButton * nextButton = getWidget < Gui : : ImageButton > ( NextPageBTN ) ;
if ( nextButton - > getSize ( ) . width = = 64 )
{
// english button has a 7 pixel wide strip of garbage on its right edge
nextButton - > setSize ( 64 - 7 , nextButton - > getSize ( ) . height ) ;
2019-04-01 17:47:12 +00:00
nextButton - > setImageCoord ( MyGUI : : IntCoord ( 0 , 0 , ( 64 - 7 ) * nextButtonScale , nextButton - > getSize ( ) . height * nextButtonScale ) ) ;
2017-11-23 06:14:45 +00:00
}
2015-12-07 14:32:00 +00:00
if ( ! questList )
2013-11-05 21:50:53 +00:00
{
// If tribunal is not installed (-> no options button), we still want the Topics button available,
// so place it where the options button would have been
2014-09-12 03:14:21 +00:00
Gui : : ImageButton * topicsButton = getWidget < Gui : : ImageButton > ( TopicsBTN ) ;
2013-11-05 21:50:53 +00:00
topicsButton - > detachFromWidget ( ) ;
topicsButton - > attachToWidget ( optionsButton - > getParent ( ) ) ;
topicsButton - > setPosition ( optionsButton - > getPosition ( ) ) ;
topicsButton - > eventMouseButtonClick . clear ( ) ;
topicsButton - > eventMouseButtonClick + = MyGUI : : newDelegate ( this , & JournalWindowImpl : : notifyOptions ) ;
2015-12-07 14:32:00 +00:00
optionsButton - > setVisible ( false ) ;
showActiveButton - > setVisible ( false ) ;
showAllButton - > setVisible ( false ) ;
questsButton - > setVisible ( false ) ;
2017-11-23 06:14:45 +00:00
adjustButton ( TopicsBTN ) ;
2015-12-07 14:32:00 +00:00
}
else
{
optionsButton - > setImage ( " textures/tx_menubook_options.dds " ) ;
showActiveButton - > setImage ( " textures/tx_menubook_quests_active.dds " ) ;
showAllButton - > setImage ( " textures/tx_menubook_quests_all.dds " ) ;
questsButton - > setImage ( " textures/tx_menubook_quests.dds " ) ;
adjustButton ( ShowAllBTN ) ;
adjustButton ( ShowActiveBTN ) ;
adjustButton ( OptionsBTN ) ;
adjustButton ( QuestsBTN ) ;
2017-11-23 06:14:45 +00:00
adjustButton ( TopicsBTN ) ;
int topicsWidth = getWidget < MyGUI : : Widget > ( TopicsBTN ) - > getSize ( ) . width ;
int cancelLeft = getWidget < MyGUI : : Widget > ( CancelBTN ) - > getPosition ( ) . left ;
int cancelRight = getWidget < MyGUI : : Widget > ( CancelBTN ) - > getPosition ( ) . left + getWidget < MyGUI : : Widget > ( CancelBTN ) - > getSize ( ) . width ;
getWidget < MyGUI : : Widget > ( QuestsBTN ) - > setPosition ( cancelRight , getWidget < MyGUI : : Widget > ( QuestsBTN ) - > getPosition ( ) . top ) ;
// Usually Topics, Quests, and Cancel buttons have the 64px width, so we can place the Topics left-up from the Cancel button, and the Quests right-up from the Cancel button.
// But in some installations, e.g. German one, the Topics button has the 128px width, so we should place it exactly left from the Quests button.
if ( topicsWidth = = 64 )
{
getWidget < MyGUI : : Widget > ( TopicsBTN ) - > setPosition ( cancelLeft - topicsWidth , getWidget < MyGUI : : Widget > ( TopicsBTN ) - > getPosition ( ) . top ) ;
}
else
{
int questLeft = getWidget < MyGUI : : Widget > ( QuestsBTN ) - > getPosition ( ) . left ;
getWidget < MyGUI : : Widget > ( TopicsBTN ) - > setPosition ( questLeft - topicsWidth , getWidget < MyGUI : : Widget > ( TopicsBTN ) - > getPosition ( ) . top ) ;
}
2017-11-20 13:39:28 +00:00
}
2013-01-27 20:16:46 +00:00
mQuestMode = false ;
mAllQuests = false ;
2015-08-15 18:44:15 +00:00
mOptionsMode = false ;
2017-07-30 21:51:32 +00:00
mTopicsMode = false ;
2011-12-01 12:44:34 +00:00
}
2017-09-22 15:10:53 +00:00
void onOpen ( )
2013-01-13 21:03:11 +00:00
{
2013-05-16 11:35:28 +00:00
if ( ! MWBase : : Environment : : get ( ) . getWindowManager ( ) - > getJournalAllowed ( ) )
{
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > popGuiMode ( ) ;
2013-06-10 04:27:47 +00:00
}
2013-05-01 08:28:59 +00:00
mModel - > load ( ) ;
2013-01-13 21:03:11 +00:00
2013-01-27 20:16:46 +00:00
setBookMode ( ) ;
2011-12-30 10:39:17 +00:00
2013-05-01 08:28:59 +00:00
Book journalBook ;
if ( mModel - > isEmpty ( ) )
2013-01-27 20:16:46 +00:00
journalBook = createEmptyJournalBook ( ) ;
else
journalBook = createJournalBook ( ) ;
2013-01-13 21:03:11 +00:00
2013-01-27 20:16:46 +00:00
pushBook ( journalBook , 0 ) ;
2013-05-04 14:06:48 +00:00
// fast forward to the last page
if ( ! mStates . empty ( ) )
{
unsigned int & page = mStates . top ( ) . mPage ;
page = mStates . top ( ) . mBook - > pageCount ( ) - 1 ;
if ( page % 2 )
- - page ;
}
updateShowingPages ( ) ;
2017-09-26 22:21:20 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > setKeyFocusWidget ( getWidget < MyGUI : : Widget > ( CloseBTN ) ) ;
2013-01-13 21:03:11 +00:00
}
2017-09-22 15:10:53 +00:00
void onClose ( )
2011-12-30 10:39:17 +00:00
{
2013-05-01 08:28:59 +00:00
mModel - > unload ( ) ;
2013-01-27 20:16:46 +00:00
2013-05-01 08:28:59 +00:00
getPage ( LeftBookPage ) - > showPage ( Book ( ) , 0 ) ;
getPage ( RightBookPage ) - > showPage ( Book ( ) , 0 ) ;
2013-01-27 20:16:46 +00:00
2013-02-09 18:44:20 +00:00
while ( ! mStates . empty ( ) )
mStates . pop ( ) ;
2013-01-27 20:16:46 +00:00
mTopicIndexBook . reset ( ) ;
2011-12-30 10:39:17 +00:00
}
2013-01-13 21:03:11 +00:00
2013-01-27 20:16:46 +00:00
void setVisible ( bool newValue )
2011-12-30 10:39:17 +00:00
{
2013-01-27 20:16:46 +00:00
WindowBase : : setVisible ( newValue ) ;
}
2013-01-13 21:03:11 +00:00
2013-01-27 20:16:46 +00:00
void setBookMode ( )
{
2015-08-15 18:44:15 +00:00
mOptionsMode = false ;
2017-07-30 21:51:32 +00:00
mTopicsMode = false ;
2013-01-27 20:16:46 +00:00
setVisible ( OptionsBTN , true ) ;
setVisible ( OptionsOverlay , false ) ;
updateShowingPages ( ) ;
updateCloseJournalButton ( ) ;
}
void setOptionsMode ( )
{
2015-08-15 18:44:15 +00:00
mOptionsMode = true ;
2017-07-30 21:51:32 +00:00
mTopicsMode = false ;
2015-08-15 18:44:15 +00:00
2013-01-27 20:16:46 +00:00
setVisible ( OptionsBTN , false ) ;
setVisible ( OptionsOverlay , true ) ;
setVisible ( PrevPageBTN , false ) ;
setVisible ( NextPageBTN , false ) ;
setVisible ( CloseBTN , false ) ;
setVisible ( JournalBTN , false ) ;
setVisible ( TopicsList , false ) ;
setVisible ( QuestsList , mQuestMode ) ;
setVisible ( LeftTopicIndex , ! mQuestMode ) ;
2018-06-18 09:43:39 +00:00
setVisible ( CenterTopicIndex , ! mQuestMode ) ;
2013-01-27 20:16:46 +00:00
setVisible ( RightTopicIndex , ! mQuestMode ) ;
setVisible ( ShowAllBTN , mQuestMode & & ! mAllQuests ) ;
setVisible ( ShowActiveBTN , mQuestMode & & mAllQuests ) ;
//TODO: figure out how to make "options" page overlay book page
// correctly, so that text may show underneath
2013-05-01 08:28:59 +00:00
getPage ( RightBookPage ) - > showPage ( Book ( ) , 0 ) ;
2014-06-02 22:16:32 +00:00
// If in quest mode, ensure the quest list is updated
if ( mQuestMode )
notifyQuests ( getWidget < MyGUI : : Widget > ( QuestsList ) ) ;
2017-07-29 15:41:46 +00:00
else
notifyTopics ( getWidget < MyGUI : : Widget > ( TopicsList ) ) ;
2013-01-27 20:16:46 +00:00
}
2013-01-13 21:03:11 +00:00
2013-05-01 08:28:59 +00:00
void pushBook ( Book book , unsigned int page )
2013-01-27 20:16:46 +00:00
{
2013-02-15 05:37:33 +00:00
DisplayState bs ;
2013-05-01 08:28:59 +00:00
bs . mPage = page ;
bs . mBook = book ;
2013-01-27 20:16:46 +00:00
mStates . push ( bs ) ;
updateShowingPages ( ) ;
updateCloseJournalButton ( ) ;
}
2013-05-01 08:28:59 +00:00
void replaceBook ( Book book , unsigned int page )
2013-01-27 20:16:46 +00:00
{
assert ( ! mStates . empty ( ) ) ;
2013-05-01 08:28:59 +00:00
mStates . top ( ) . mBook = book ;
mStates . top ( ) . mPage = page ;
2013-01-27 20:16:46 +00:00
updateShowingPages ( ) ;
}
2013-01-13 21:03:11 +00:00
2013-01-27 20:16:46 +00:00
void popBook ( )
{
mStates . pop ( ) ;
updateShowingPages ( ) ;
updateCloseJournalButton ( ) ;
}
void updateCloseJournalButton ( )
{
setVisible ( CloseBTN , mStates . size ( ) < 2 ) ;
setVisible ( JournalBTN , mStates . size ( ) > = 2 ) ;
}
void updateShowingPages ( )
{
2013-05-01 08:28:59 +00:00
Book book ;
unsigned int page ;
unsigned int relPages ;
2013-01-27 20:16:46 +00:00
if ( ! mStates . empty ( ) )
{
2013-05-01 08:28:59 +00:00
book = mStates . top ( ) . mBook ;
page = mStates . top ( ) . mPage ;
relPages = book - > pageCount ( ) - page ;
2011-12-30 10:39:17 +00:00
}
else
{
2013-05-01 08:28:59 +00:00
page = 0 ;
2013-01-27 20:16:46 +00:00
relPages = 0 ;
2011-12-30 10:39:17 +00:00
}
2013-01-27 20:16:46 +00:00
2017-09-26 22:21:20 +00:00
MyGUI : : Widget * nextPageBtn = getWidget < MyGUI : : Widget > ( NextPageBTN ) ;
MyGUI : : Widget * prevPageBtn = getWidget < MyGUI : : Widget > ( PrevPageBTN ) ;
MyGUI : : Widget * focus = MyGUI : : InputManager : : getInstance ( ) . getKeyFocusWidget ( ) ;
bool nextPageVisible = relPages > 2 ;
nextPageBtn - > setVisible ( nextPageVisible ) ;
bool prevPageVisible = page > 0 ;
prevPageBtn - > setVisible ( prevPageVisible ) ;
if ( focus = = nextPageBtn & & ! nextPageVisible & & prevPageVisible )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > setKeyFocusWidget ( prevPageBtn ) ;
else if ( focus = = prevPageBtn & & ! prevPageVisible & & nextPageVisible )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > setKeyFocusWidget ( nextPageBtn ) ;
2013-01-27 20:16:46 +00:00
setVisible ( PageOneNum , relPages > 0 ) ;
setVisible ( PageTwoNum , relPages > 1 ) ;
2013-05-01 08:28:59 +00:00
getPage ( LeftBookPage ) - > showPage ( ( relPages > 0 ) ? book : Book ( ) , page + 0 ) ;
getPage ( RightBookPage ) - > showPage ( ( relPages > 0 ) ? book : Book ( ) , page + 1 ) ;
2013-01-27 20:16:46 +00:00
2013-05-01 08:28:59 +00:00
setText ( PageOneNum , page + 1 ) ;
setText ( PageTwoNum , page + 2 ) ;
2011-12-30 10:39:17 +00:00
}
2017-09-26 22:21:20 +00:00
void notifyKeyPress ( MyGUI : : Widget * sender , MyGUI : : KeyCode key , MyGUI : : Char character )
{
if ( key = = MyGUI : : KeyCode : : ArrowUp )
notifyPrevPage ( sender ) ;
else if ( key = = MyGUI : : KeyCode : : ArrowDown )
notifyNextPage ( sender ) ;
}
2013-01-27 20:16:46 +00:00
void notifyTopicClicked ( intptr_t linkId )
2013-01-13 21:03:11 +00:00
{
2013-05-01 08:28:59 +00:00
Book topicBook = createTopicBook ( linkId ) ;
2013-01-27 20:16:46 +00:00
if ( mStates . size ( ) > 1 )
replaceBook ( topicBook , 0 ) ;
else
pushBook ( topicBook , 0 ) ;
setVisible ( OptionsOverlay , false ) ;
setVisible ( OptionsBTN , true ) ;
setVisible ( JournalBTN , true ) ;
2015-08-30 15:38:21 +00:00
mOptionsMode = false ;
2017-07-30 21:51:32 +00:00
mTopicsMode = false ;
2017-07-29 15:41:46 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > playSound ( " book page " ) ;
2013-01-13 21:03:11 +00:00
}
2011-12-30 10:39:17 +00:00
2014-06-03 14:04:18 +00:00
void notifyTopicSelected ( const std : : string & topic , int id )
{
const MWBase : : Journal * journal = MWBase : : Environment : : get ( ) . getJournal ( ) ;
intptr_t topicId = 0 ; /// \todo get rid of intptr ids
for ( MWBase : : Journal : : TTopicIter i = journal - > topicBegin ( ) ; i ! = journal - > topicEnd ( ) ; + + i )
{
if ( Misc : : StringUtils : : ciEqual ( i - > first , topic ) )
topicId = intptr_t ( & i - > second ) ;
}
notifyTopicClicked ( topicId ) ;
}
2014-06-02 22:16:32 +00:00
void notifyQuestClicked ( const std : : string & name , int id )
2013-01-27 20:16:46 +00:00
{
2014-06-02 22:16:32 +00:00
Book book = createQuestBook ( name ) ;
2013-01-27 20:16:46 +00:00
if ( mStates . size ( ) > 1 )
2013-05-01 08:28:59 +00:00
replaceBook ( book , 0 ) ;
2013-01-27 20:16:46 +00:00
else
2013-05-01 08:28:59 +00:00
pushBook ( book , 0 ) ;
2013-01-27 20:16:46 +00:00
setVisible ( OptionsOverlay , false ) ;
setVisible ( OptionsBTN , true ) ;
setVisible ( JournalBTN , true ) ;
2015-08-30 15:38:21 +00:00
mOptionsMode = false ;
2017-07-29 15:41:46 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > playSound ( " book page " ) ;
2013-01-27 20:16:46 +00:00
}
2011-12-29 16:58:58 +00:00
2013-05-06 14:04:28 +00:00
void notifyOptions ( MyGUI : : Widget * _sender )
2013-01-13 21:03:11 +00:00
{
2013-01-27 20:16:46 +00:00
setOptionsMode ( ) ;
if ( ! mTopicIndexBook )
2018-09-04 08:19:50 +00:00
mTopicIndexBook = createTopicIndexBook ( ) ;
2013-01-27 20:16:46 +00:00
2018-09-04 08:19:50 +00:00
if ( mIndexPagesCount = = 3 )
2018-06-18 09:43:39 +00:00
{
getPage ( LeftTopicIndex ) - > showPage ( mTopicIndexBook , 0 ) ;
getPage ( CenterTopicIndex ) - > showPage ( mTopicIndexBook , 1 ) ;
getPage ( RightTopicIndex ) - > showPage ( mTopicIndexBook , 2 ) ;
}
else
{
getPage ( LeftTopicIndex ) - > showPage ( mTopicIndexBook , 0 ) ;
getPage ( RightTopicIndex ) - > showPage ( mTopicIndexBook , 1 ) ;
}
2013-01-13 21:03:11 +00:00
}
2011-12-01 12:44:34 +00:00
2013-05-06 14:04:28 +00:00
void notifyJournal ( MyGUI : : Widget * _sender )
2013-01-13 21:03:11 +00:00
{
2013-01-27 20:16:46 +00:00
assert ( mStates . size ( ) > 1 ) ;
popBook ( ) ;
2017-07-29 15:41:46 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > playSound ( " book page " ) ;
2013-01-13 21:03:11 +00:00
}
2012-01-16 16:46:25 +00:00
2017-08-04 16:21:13 +00:00
void notifyIndexLinkClicked ( MWGui : : TypesetBook : : InteractiveId index )
2013-01-13 21:03:11 +00:00
{
2013-01-27 20:16:46 +00:00
setVisible ( LeftTopicIndex , false ) ;
2018-06-18 09:43:39 +00:00
setVisible ( CenterTopicIndex , false ) ;
2013-01-27 20:16:46 +00:00
setVisible ( RightTopicIndex , false ) ;
setVisible ( TopicsList , true ) ;
2017-07-30 21:51:32 +00:00
mTopicsMode = true ;
2014-09-25 14:25:08 +00:00
Gui : : MWList * list = getWidget < Gui : : MWList > ( TopicsList ) ;
2014-06-03 14:04:18 +00:00
list - > clear ( ) ;
AddNamesToList add ( list ) ;
2017-08-04 16:21:13 +00:00
mModel - > visitTopicNamesStartingWith ( index , add ) ;
2014-06-03 14:04:18 +00:00
list - > adjustSize ( ) ;
2017-07-29 15:41:46 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > playSound ( " book page " ) ;
2013-01-27 20:16:46 +00:00
}
2013-05-06 14:04:28 +00:00
void notifyTopics ( MyGUI : : Widget * _sender )
2013-01-27 20:16:46 +00:00
{
mQuestMode = false ;
2017-07-30 21:51:32 +00:00
mTopicsMode = false ;
2013-01-27 20:16:46 +00:00
setVisible ( LeftTopicIndex , true ) ;
2018-06-18 09:43:39 +00:00
setVisible ( CenterTopicIndex , true ) ;
2013-01-27 20:16:46 +00:00
setVisible ( RightTopicIndex , true ) ;
setVisible ( TopicsList , false ) ;
setVisible ( QuestsList , false ) ;
setVisible ( ShowAllBTN , false ) ;
setVisible ( ShowActiveBTN , false ) ;
2017-07-29 15:41:46 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > playSound ( " book page " ) ;
2013-01-27 20:16:46 +00:00
}
2014-06-03 14:04:18 +00:00
struct AddNamesToList
2014-06-02 22:16:32 +00:00
{
2014-09-25 14:25:08 +00:00
AddNamesToList ( Gui : : MWList * list ) : mList ( list ) { }
2014-06-02 22:16:32 +00:00
2014-09-25 14:25:08 +00:00
Gui : : MWList * mList ;
2015-02-13 15:51:34 +00:00
void operator ( ) ( const std : : string & name , bool finished = false )
2014-06-02 22:16:32 +00:00
{
mList - > addItem ( name ) ;
}
} ;
2015-02-13 15:51:34 +00:00
struct SetNamesInactive
{
SetNamesInactive ( Gui : : MWList * list ) : mList ( list ) { }
Gui : : MWList * mList ;
void operator ( ) ( const std : : string & name , bool finished )
{
if ( finished )
{
mList - > getItemWidget ( name ) - > setStateSelected ( true ) ;
}
}
} ;
2014-06-02 22:16:32 +00:00
2013-05-06 14:04:28 +00:00
void notifyQuests ( MyGUI : : Widget * _sender )
2013-01-27 20:16:46 +00:00
{
mQuestMode = true ;
2014-06-02 22:16:32 +00:00
2013-01-27 20:16:46 +00:00
setVisible ( LeftTopicIndex , false ) ;
2019-02-08 07:52:17 +00:00
setVisible ( CenterTopicIndex , false ) ;
2013-01-27 20:16:46 +00:00
setVisible ( RightTopicIndex , false ) ;
setVisible ( TopicsList , false ) ;
setVisible ( QuestsList , true ) ;
setVisible ( ShowAllBTN , ! mAllQuests ) ;
setVisible ( ShowActiveBTN , mAllQuests ) ;
2014-09-25 14:25:08 +00:00
Gui : : MWList * list = getWidget < Gui : : MWList > ( QuestsList ) ;
2014-06-02 22:16:32 +00:00
list - > clear ( ) ;
2014-06-03 14:04:18 +00:00
AddNamesToList add ( list ) ;
2014-06-02 22:16:32 +00:00
mModel - > visitQuestNames ( ! mAllQuests , add ) ;
list - > adjustSize ( ) ;
2015-02-13 15:51:34 +00:00
if ( mAllQuests )
{
SetNamesInactive setInactive ( list ) ;
2018-04-17 09:11:05 +00:00
mModel - > visitQuestNames ( ! mAllQuests , setInactive ) ;
2015-02-13 15:51:34 +00:00
}
2017-07-29 15:41:46 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > playSound ( " book page " ) ;
2013-01-27 20:16:46 +00:00
}
2013-05-06 14:04:28 +00:00
void notifyShowAll ( MyGUI : : Widget * _sender )
2013-01-27 20:16:46 +00:00
{
mAllQuests = true ;
2014-06-02 22:16:32 +00:00
notifyQuests ( _sender ) ;
2013-01-27 20:16:46 +00:00
}
2013-05-06 14:04:28 +00:00
void notifyShowActive ( MyGUI : : Widget * _sender )
2013-01-27 20:16:46 +00:00
{
mAllQuests = false ;
2014-06-02 22:16:32 +00:00
notifyQuests ( _sender ) ;
2013-01-27 20:16:46 +00:00
}
2013-05-06 14:04:28 +00:00
void notifyCancel ( MyGUI : : Widget * _sender )
2013-01-27 20:16:46 +00:00
{
2017-07-30 21:51:32 +00:00
if ( mTopicsMode )
{
notifyTopics ( _sender ) ;
}
else
{
setBookMode ( ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > playSound ( " book page " ) ;
}
2017-07-29 15:41:46 +00:00
2013-01-27 20:16:46 +00:00
}
2013-05-06 14:04:28 +00:00
void notifyClose ( MyGUI : : Widget * _sender )
2013-01-27 20:16:46 +00:00
{
2017-07-10 11:48:00 +00:00
MWBase : : WindowManager * winMgr = MWBase : : Environment : : get ( ) . getWindowManager ( ) ;
winMgr - > playSound ( " book close " ) ;
winMgr - > popGuiMode ( ) ;
2013-01-27 20:16:46 +00:00
}
2014-08-10 22:51:54 +00:00
void notifyMouseWheel ( MyGUI : : Widget * sender , int rel )
{
if ( rel < 0 )
notifyNextPage ( sender ) ;
else
notifyPrevPage ( sender ) ;
}
2013-05-06 14:04:28 +00:00
void notifyNextPage ( MyGUI : : Widget * _sender )
2013-01-27 20:16:46 +00:00
{
2015-08-15 18:44:15 +00:00
if ( mOptionsMode )
return ;
2013-01-27 20:16:46 +00:00
if ( ! mStates . empty ( ) )
2013-01-13 21:03:11 +00:00
{
2013-05-01 08:28:59 +00:00
unsigned int & page = mStates . top ( ) . mPage ;
Book book = mStates . top ( ) . mBook ;
2013-01-27 20:16:46 +00:00
2014-09-30 16:14:25 +00:00
if ( page + 2 < book - > pageCount ( ) )
2013-01-27 20:16:46 +00:00
{
2019-02-17 07:57:18 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > playSound ( " book page " ) ;
2017-07-29 15:41:46 +00:00
2013-05-01 08:28:59 +00:00
page + = 2 ;
2013-01-27 20:16:46 +00:00
updateShowingPages ( ) ;
}
2013-01-13 21:03:11 +00:00
}
}
2013-05-06 14:04:28 +00:00
void notifyPrevPage ( MyGUI : : Widget * _sender )
2013-01-13 21:03:11 +00:00
{
2015-08-15 18:44:15 +00:00
if ( mOptionsMode )
return ;
2013-01-27 20:16:46 +00:00
if ( ! mStates . empty ( ) )
2013-01-13 21:03:11 +00:00
{
2013-05-01 08:28:59 +00:00
unsigned int & page = mStates . top ( ) . mPage ;
2013-01-27 20:16:46 +00:00
2014-08-10 22:51:54 +00:00
if ( page > = 2 )
2013-01-27 20:16:46 +00:00
{
2019-02-17 07:57:18 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > playSound ( " book page " ) ;
2017-07-29 15:41:46 +00:00
2013-05-01 08:28:59 +00:00
page - = 2 ;
2013-01-27 20:16:46 +00:00
updateShowingPages ( ) ;
}
2013-01-13 21:03:11 +00:00
}
}
} ;
2012-01-17 12:53:27 +00:00
}
2013-01-13 21:03:11 +00:00
// glue the implementation to the interface
2017-11-22 04:32:38 +00:00
MWGui : : JournalWindow * MWGui : : JournalWindow : : create ( JournalViewModel : : Ptr Model , bool questList , ToUTF8 : : FromType encoding )
2013-01-27 20:16:46 +00:00
{
2017-11-22 04:32:38 +00:00
return new JournalWindowImpl ( Model , questList , encoding ) ;
2013-06-13 16:17:34 +00:00
}
2017-09-22 18:46:08 +00:00
MWGui : : JournalWindow : : JournalWindow ( )
2019-04-01 17:47:12 +00:00
: BookWindowBase ( " openmw_journal.layout " )
2017-09-22 18:46:08 +00:00
{
}