2010-07-17 12:01:47 +00:00
# include "window_manager.hpp"
2010-09-14 20:10:15 +00:00
# include "layouts.hpp"
2010-09-14 21:17:08 +00:00
# include "text_input.hpp"
2010-09-14 20:01:45 +00:00
# include "race.hpp"
2010-09-19 02:29:22 +00:00
# include "class.hpp"
2010-09-21 10:34:47 +00:00
# include "birth.hpp"
2010-10-20 19:40:32 +00:00
# include "review.hpp"
2010-07-17 12:01:47 +00:00
2010-09-14 19:27:40 +00:00
# include "../mwmechanics/mechanicsmanager.hpp"
2010-09-15 12:48:19 +00:00
# include "../mwinput/inputmanager.hpp"
2010-09-14 19:27:40 +00:00
2010-07-20 19:10:51 +00:00
# include "console.hpp"
2010-07-17 12:01:47 +00:00
# include <assert.h>
2010-08-22 09:22:10 +00:00
# include <iostream>
2010-08-22 10:56:35 +00:00
# include <iterator>
2010-07-17 12:01:47 +00:00
using namespace MWGui ;
2010-07-20 21:21:48 +00:00
WindowManager : : WindowManager ( MyGUI : : Gui * _gui , MWWorld : : Environment & environment ,
2010-07-21 08:28:58 +00:00
const Compiler : : Extensions & extensions , bool newGame )
2010-09-14 19:27:40 +00:00
: environment ( environment )
2010-09-14 21:17:08 +00:00
, nameDialog ( nullptr )
2010-09-14 19:27:40 +00:00
, raceDialog ( nullptr )
2010-10-09 22:42:56 +00:00
, classChoiceDialog ( nullptr )
, generateClassQuestionDialog ( nullptr )
2010-10-09 23:52:08 +00:00
, generateClassResultDialog ( nullptr )
2010-09-19 02:29:22 +00:00
, pickClassDialog ( nullptr )
2010-10-10 00:43:44 +00:00
, createClassDialog ( nullptr )
2010-09-21 10:34:47 +00:00
, birthSignDialog ( nullptr )
2010-10-20 19:40:32 +00:00
, reviewDialog ( nullptr )
2010-09-14 19:27:40 +00:00
, nameChosen ( false )
, raceChosen ( false )
, classChosen ( false )
2010-09-21 10:34:47 +00:00
, birthSignChosen ( false )
2010-09-14 19:27:40 +00:00
, reviewNext ( false )
, gui ( _gui )
, mode ( GM_Game )
2010-10-22 20:53:34 +00:00
, nextMode ( GM_Game )
, needModeChange ( false )
2010-09-14 19:27:40 +00:00
, shown ( GW_ALL )
, allowed ( newGame ? GW_None : GW_ALL )
2010-07-17 12:01:47 +00:00
{
// Get size info from the Gui object
assert ( gui ) ;
2010-08-30 10:19:45 +00:00
int w = gui - > getViewSize ( ) . width ;
int h = gui - > getViewSize ( ) . height ;
2010-07-17 12:01:47 +00:00
hud = new HUD ( w , h ) ;
menu = new MainMenu ( w , h ) ;
map = new MapWindow ( ) ;
2010-09-17 23:30:23 +00:00
stats = new StatsWindow ( environment ) ;
2010-09-15 11:15:58 +00:00
#if 0
2010-09-10 01:29:29 +00:00
inventory = new InventoryWindow ( ) ;
2010-09-15 11:15:58 +00:00
# endif
2010-07-20 21:21:48 +00:00
console = new Console ( w , h , environment , extensions ) ;
2010-07-17 12:01:47 +00:00
// The HUD is always on
hud - > setVisible ( true ) ;
2010-10-21 07:28:09 +00:00
// Setup player stats
for ( int i = 0 ; i < ESM : : Attribute : : Length ; + + i )
{
playerAttributes . insert ( std : : make_pair ( ESM : : Attribute : : attributeIds [ i ] , MWMechanics : : Stat < int > ( ) ) ) ;
}
for ( int i = 0 ; i < ESM : : Skill : : Length ; + + i )
{
playerSkillValues . insert ( std : : make_pair ( ESM : : Skill : : skillIds [ i ] , MWMechanics : : Stat < float > ( ) ) ) ;
}
2010-07-17 12:01:47 +00:00
// Set up visibility
updateVisible ( ) ;
}
WindowManager : : ~ WindowManager ( )
{
2010-07-20 19:10:51 +00:00
delete console ;
2010-07-17 12:01:47 +00:00
delete hud ;
delete map ;
delete menu ;
delete stats ;
2010-09-15 11:15:58 +00:00
#if 0
2010-09-10 01:29:29 +00:00
delete inventory ;
2010-09-15 11:15:58 +00:00
# endif
2010-09-12 12:06:10 +00:00
2010-09-14 21:17:08 +00:00
delete nameDialog ;
2010-09-12 12:06:10 +00:00
delete raceDialog ;
2010-10-09 22:42:56 +00:00
delete classChoiceDialog ;
delete generateClassQuestionDialog ;
2010-10-09 23:52:08 +00:00
delete generateClassResultDialog ;
2010-09-19 02:29:22 +00:00
delete pickClassDialog ;
2010-10-10 00:43:44 +00:00
delete createClassDialog ;
2010-09-21 10:34:47 +00:00
delete birthSignDialog ;
2010-10-20 19:40:32 +00:00
delete reviewDialog ;
2010-10-22 21:21:15 +00:00
cleanupGarbage ( ) ;
2010-07-17 12:01:47 +00:00
}
2010-10-22 21:21:15 +00:00
void WindowManager : : cleanupGarbage ( )
2010-10-22 20:53:34 +00:00
{
2010-10-22 21:21:15 +00:00
// Delete any dialogs which are no longer in use
2010-10-22 20:53:34 +00:00
if ( ! garbageDialogs . empty ( ) )
{
for ( std : : vector < OEngine : : GUI : : Layout * > : : iterator it = garbageDialogs . begin ( ) ; it ! = garbageDialogs . end ( ) ; + + it )
{
delete * it ;
}
garbageDialogs . clear ( ) ;
}
2010-10-22 21:21:15 +00:00
}
2010-10-22 20:53:34 +00:00
2010-10-22 21:21:15 +00:00
void WindowManager : : update ( )
{
cleanupGarbage ( ) ;
2010-10-22 20:53:34 +00:00
if ( needModeChange )
{
needModeChange = false ;
environment . mInputManager - > setGuiMode ( nextMode ) ;
nextMode = GM_Game ;
}
}
void WindowManager : : setNextMode ( GuiMode newMode )
{
nextMode = newMode ;
needModeChange = true ;
}
void WindowManager : : setGuiMode ( GuiMode newMode )
{
environment . mInputManager - > setGuiMode ( newMode ) ;
}
2010-07-17 12:01:47 +00:00
void WindowManager : : updateVisible ( )
{
// Start out by hiding everything except the HUD
map - > setVisible ( false ) ;
menu - > setVisible ( false ) ;
stats - > setVisible ( false ) ;
2010-09-15 11:15:58 +00:00
#if 0
2010-09-10 01:29:29 +00:00
inventory - > setVisible ( false ) ;
2010-09-15 11:15:58 +00:00
# endif
2010-07-20 19:10:51 +00:00
console - > disable ( ) ;
2010-07-17 12:01:47 +00:00
// Mouse is visible whenever we're not in game mode
gui - > setVisiblePointer ( isGuiMode ( ) ) ;
// If in game mode, don't show anything.
if ( mode = = GM_Game )
{
return ;
}
if ( mode = = GM_MainMenu )
{
// Enable the main menu
menu - > setVisible ( true ) ;
return ;
}
2010-07-20 19:10:51 +00:00
if ( mode = = GM_Console )
{
console - > enable ( ) ;
return ;
}
2010-09-14 21:17:08 +00:00
if ( mode = = GM_Name )
{
2010-10-22 20:53:34 +00:00
if ( nameDialog )
2010-10-22 21:34:41 +00:00
removeDialog ( nameDialog ) ;
2010-10-22 20:53:34 +00:00
nameDialog = new TextInputDialog ( environment , gui - > getViewSize ( ) ) ;
2010-09-15 17:37:06 +00:00
std : : string sName = getGameSettingString ( " sName " , " Name " ) ;
nameDialog - > setTextLabel ( sName ) ;
2010-10-22 22:00:09 +00:00
nameDialog - > setTextInput ( playerName ) ;
2010-09-15 17:37:06 +00:00
nameDialog - > setNextButtonShow ( nameChosen ) ;
2010-09-14 21:17:08 +00:00
nameDialog - > eventDone = MyGUI : : newDelegate ( this , & WindowManager : : onNameDialogDone ) ;
2010-09-15 17:48:37 +00:00
nameDialog - > open ( ) ;
2010-09-14 21:17:08 +00:00
return ;
}
2010-09-14 19:27:40 +00:00
if ( mode = = GM_Race )
{
2010-10-22 20:53:34 +00:00
if ( raceDialog )
2010-10-22 21:34:41 +00:00
removeDialog ( raceDialog ) ;
2010-10-22 20:53:34 +00:00
raceDialog = new RaceDialog ( environment , gui - > getViewSize ( ) ) ;
2010-09-15 17:44:53 +00:00
raceDialog - > setNextButtonShow ( raceChosen ) ;
2010-10-22 21:51:53 +00:00
raceDialog - > setRaceId ( playerRaceId ) ;
2010-09-14 19:27:40 +00:00
raceDialog - > eventDone = MyGUI : : newDelegate ( this , & WindowManager : : onRaceDialogDone ) ;
raceDialog - > eventBack = MyGUI : : newDelegate ( this , & WindowManager : : onRaceDialogBack ) ;
2010-09-15 19:36:32 +00:00
raceDialog - > open ( ) ;
2010-09-14 19:27:40 +00:00
return ;
}
2010-09-19 02:29:22 +00:00
if ( mode = = GM_Class )
2010-10-09 22:42:56 +00:00
{
if ( classChoiceDialog )
2010-10-22 21:34:41 +00:00
removeDialog ( classChoiceDialog ) ;
2010-10-09 22:42:56 +00:00
classChoiceDialog = new ClassChoiceDialog ( environment ) ;
classChoiceDialog - > eventButtonSelected = MyGUI : : newDelegate ( this , & WindowManager : : onClassChoice ) ;
2010-10-22 22:11:54 +00:00
classChoiceDialog - > open ( ) ;
2010-10-09 22:42:56 +00:00
return ;
}
if ( mode = = GM_ClassGenerate )
{
generateClassStep = 0 ;
showClassQuestionDialog ( ) ;
return ;
}
if ( mode = = GM_ClassPick )
2010-09-19 02:29:22 +00:00
{
2010-10-22 20:53:34 +00:00
if ( pickClassDialog )
2010-10-22 21:34:41 +00:00
removeDialog ( pickClassDialog ) ;
2010-10-22 20:53:34 +00:00
pickClassDialog = new PickClassDialog ( environment , gui - > getViewSize ( ) ) ;
2010-09-19 02:29:22 +00:00
pickClassDialog - > setNextButtonShow ( classChosen ) ;
2010-10-22 21:51:53 +00:00
pickClassDialog - > setClassId ( playerClass . name ) ;
2010-09-19 02:29:22 +00:00
pickClassDialog - > eventDone = MyGUI : : newDelegate ( this , & WindowManager : : onPickClassDialogDone ) ;
pickClassDialog - > eventBack = MyGUI : : newDelegate ( this , & WindowManager : : onPickClassDialogBack ) ;
pickClassDialog - > open ( ) ;
return ;
}
2010-10-09 22:42:56 +00:00
if ( mode = = GM_ClassCreate )
{
2010-10-10 00:43:44 +00:00
if ( createClassDialog )
2010-10-22 21:34:41 +00:00
removeDialog ( createClassDialog ) ;
2010-10-10 00:43:44 +00:00
createClassDialog = new CreateClassDialog ( environment , gui - > getViewSize ( ) ) ;
createClassDialog - > eventDone = MyGUI : : newDelegate ( this , & WindowManager : : onCreateClassDialogDone ) ;
createClassDialog - > eventBack = MyGUI : : newDelegate ( this , & WindowManager : : onCreateClassDialogBack ) ;
createClassDialog - > open ( ) ;
2010-10-09 22:42:56 +00:00
return ;
}
2010-09-21 10:34:47 +00:00
if ( mode = = GM_Birth )
{
2010-10-22 20:53:34 +00:00
if ( birthSignDialog )
2010-10-22 21:34:41 +00:00
removeDialog ( birthSignDialog ) ;
2010-10-22 20:53:34 +00:00
birthSignDialog = new BirthDialog ( environment , gui - > getViewSize ( ) ) ;
2010-09-21 10:34:47 +00:00
birthSignDialog - > setNextButtonShow ( birthSignChosen ) ;
2010-10-22 20:53:34 +00:00
birthSignDialog - > setBirthId ( playerBirthSignId ) ;
2010-09-21 10:34:47 +00:00
birthSignDialog - > eventDone = MyGUI : : newDelegate ( this , & WindowManager : : onBirthSignDialogDone ) ;
birthSignDialog - > eventBack = MyGUI : : newDelegate ( this , & WindowManager : : onBirthSignDialogBack ) ;
birthSignDialog - > open ( ) ;
return ;
}
2010-10-20 19:40:32 +00:00
if ( mode = = GM_Review )
{
reviewNext = false ;
2010-10-22 20:53:34 +00:00
if ( reviewDialog )
2010-10-22 21:34:41 +00:00
removeDialog ( reviewDialog ) ;
2010-10-22 20:53:34 +00:00
reviewDialog = new ReviewDialog ( environment , gui - > getViewSize ( ) ) ;
2010-10-21 07:28:09 +00:00
reviewDialog - > setPlayerName ( playerName ) ;
reviewDialog - > setRace ( playerRaceId ) ;
reviewDialog - > setClass ( playerClass ) ;
reviewDialog - > setBirthSign ( playerBirthSignId ) ;
reviewDialog - > setHealth ( playerHealth ) ;
reviewDialog - > setMagicka ( playerMagicka ) ;
reviewDialog - > setFatigue ( playerFatigue ) ;
{
std : : map < ESM : : Attribute : : AttributeID , MWMechanics : : Stat < int > > : : iterator end = playerAttributes . end ( ) ;
for ( std : : map < ESM : : Attribute : : AttributeID , MWMechanics : : Stat < int > > : : iterator it = playerAttributes . begin ( ) ; it ! = end ; + + it )
{
reviewDialog - > setAttribute ( it - > first , it - > second ) ;
}
}
{
std : : map < ESM : : Skill : : SkillEnum , MWMechanics : : Stat < float > > : : iterator end = playerSkillValues . end ( ) ;
for ( std : : map < ESM : : Skill : : SkillEnum , MWMechanics : : Stat < float > > : : iterator it = playerSkillValues . begin ( ) ; it ! = end ; + + it )
{
reviewDialog - > setSkillValue ( it - > first , it - > second ) ;
}
reviewDialog - > configureSkills ( playerMajorSkills , playerMinorSkills ) ;
}
2010-10-20 19:40:32 +00:00
reviewDialog - > eventDone = MyGUI : : newDelegate ( this , & WindowManager : : onReviewDialogDone ) ;
reviewDialog - > eventBack = MyGUI : : newDelegate ( this , & WindowManager : : onReviewDialogBack ) ;
2010-10-22 22:11:54 +00:00
reviewDialog - > open ( ) ;
2010-10-20 19:40:32 +00:00
return ;
}
2010-07-17 12:01:47 +00:00
if ( mode = = GM_Inventory )
{
// Ah, inventory mode. First, compute the effective set of
// windows to show. This is controlled both by what windows the
// user has opened/closed (the 'shown' variable) and by what
// windows we are allowed to show (the 'allowed' var.)
int eff = shown & allowed ;
// Show the windows we want
2010-09-15 11:16:54 +00:00
map - > setVisible ( ( eff & GW_Map ) ! = 0 ) ;
stats - > setVisible ( ( eff & GW_Stats ) ! = 0 ) ;
2010-09-15 11:15:58 +00:00
#if 0
2010-09-12 12:06:10 +00:00
// inventory -> setVisible( eff & GW_Inventory );
2010-09-15 11:15:58 +00:00
# endif
2010-09-14 19:55:41 +00:00
return ;
2010-07-17 12:01:47 +00:00
}
2010-09-15 12:48:19 +00:00
// Unsupported mode, switch back to game
// Note: The call will eventually end up this method again but
// will stop at the check if(mode == GM_Game) above.
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Game ) ;
2010-07-17 12:01:47 +00:00
}
2010-07-26 09:15:38 +00:00
2010-07-27 13:59:41 +00:00
void WindowManager : : setValue ( const std : : string & id , const MWMechanics : : Stat < int > & value )
{
stats - > setValue ( id , value ) ;
2010-10-21 07:28:09 +00:00
static const char * ids [ ] =
{
" AttribVal1 " , " AttribVal2 " , " AttribVal3 " , " AttribVal4 " , " AttribVal5 " ,
" AttribVal6 " , " AttribVal7 " , " AttribVal8 "
} ;
static ESM : : Attribute : : AttributeID attributes [ ] =
{
ESM : : Attribute : : Strength ,
ESM : : Attribute : : Intelligence ,
ESM : : Attribute : : Willpower ,
ESM : : Attribute : : Agility ,
ESM : : Attribute : : Speed ,
ESM : : Attribute : : Endurance ,
ESM : : Attribute : : Personality ,
ESM : : Attribute : : Luck
} ;
for ( int i = 0 ; i < sizeof ( ids ) / sizeof ( ids [ 0 ] ) ; + + i )
{
if ( id ! = ids [ i ] )
continue ;
playerAttributes [ attributes [ i ] ] = value ;
break ;
}
2010-07-27 13:59:41 +00:00
}
2010-09-18 16:04:53 +00:00
void WindowManager : : setValue ( const std : : string & id , const MWMechanics : : Stat < float > & value )
{
stats - > setValue ( id , value ) ;
2010-10-21 07:28:09 +00:00
static struct { const char * id ; ESM : : Skill : : SkillEnum skillId ; } skillMap [ ] =
{
{ " SkillBlock " , ESM : : Skill : : Block } ,
{ " SkillArmorer " , ESM : : Skill : : Armorer } ,
{ " SkillMediumArmor " , ESM : : Skill : : MediumArmor } ,
{ " SkillHeavyArmor " , ESM : : Skill : : HeavyArmor } ,
{ " SkillBluntWeapon " , ESM : : Skill : : BluntWeapon } ,
{ " SkillLongBlade " , ESM : : Skill : : LongBlade } ,
{ " SkillAxe " , ESM : : Skill : : Axe } ,
{ " SkillSpear " , ESM : : Skill : : Spear } ,
{ " SkillAthletics " , ESM : : Skill : : Athletics } ,
{ " SkillEnchant " , ESM : : Skill : : Armorer } ,
{ " SkillDestruction " , ESM : : Skill : : Destruction } ,
{ " SkillAlteration " , ESM : : Skill : : Alteration } ,
{ " SkillIllusion " , ESM : : Skill : : Illusion } ,
{ " SkillConjuration " , ESM : : Skill : : Conjuration } ,
{ " SkillMysticism " , ESM : : Skill : : Mysticism } ,
{ " SkillRestoration " , ESM : : Skill : : Restoration } ,
{ " SkillAlchemy " , ESM : : Skill : : Alchemy } ,
{ " SkillUnarmored " , ESM : : Skill : : Unarmored } ,
{ " SkillSecurity " , ESM : : Skill : : Security } ,
{ " SkillSneak " , ESM : : Skill : : Sneak } ,
{ " SkillAcrobatics " , ESM : : Skill : : Acrobatics } ,
{ " SkillLightArmor " , ESM : : Skill : : LightArmor } ,
{ " SkillShortBlade " , ESM : : Skill : : ShortBlade } ,
{ " SkillMarksman " , ESM : : Skill : : Marksman } ,
{ " SkillMercantile " , ESM : : Skill : : Mercantile } ,
{ " SkillSpeechcraft " , ESM : : Skill : : Speechcraft } ,
{ " SkillHandToHand " , ESM : : Skill : : HandToHand } ,
} ;
for ( int i = 0 ; i < sizeof ( skillMap ) / sizeof ( skillMap [ 0 ] ) ; + + i )
{
if ( skillMap [ i ] . id = = id )
{
ESM : : Skill : : SkillEnum skillId = skillMap [ i ] . skillId ;
playerSkillValues [ skillId ] = value ;
break ;
}
}
2010-09-18 16:04:53 +00:00
}
2010-07-28 16:48:01 +00:00
void WindowManager : : setValue ( const std : : string & id , const MWMechanics : : DynamicStat < int > & value )
{
stats - > setValue ( id , value ) ;
hud - > setValue ( id , value ) ;
2010-10-21 07:28:09 +00:00
if ( id = = " HBar " )
playerHealth = value ;
else if ( id = = " MBar " )
playerMagicka = value ;
else if ( id = = " FBar " )
playerFatigue = value ;
2010-07-28 16:48:01 +00:00
}
2010-08-22 09:22:10 +00:00
2010-09-15 10:22:06 +00:00
void WindowManager : : setValue ( const std : : string & id , const std : : string & value )
{
stats - > setValue ( id , value ) ;
2010-10-21 07:28:09 +00:00
if ( id = = " name " )
playerName = value ;
else if ( id = = " race " )
playerRaceId = value ;
2010-09-15 10:22:06 +00:00
}
2010-09-15 13:32:35 +00:00
void WindowManager : : setValue ( const std : : string & id , int value )
{
stats - > setValue ( id , value ) ;
}
2010-10-21 07:28:09 +00:00
void WindowManager : : setPlayerClass ( const ESM : : Class & class_ )
{
playerClass = class_ ;
stats - > setValue ( " class " , playerClass . name ) ;
}
2010-09-18 17:26:45 +00:00
void WindowManager : : configureSkills ( const SkillList & major , const SkillList & minor )
2010-09-17 23:30:23 +00:00
{
2010-09-18 17:26:45 +00:00
stats - > configureSkills ( major , minor ) ;
2010-10-21 07:28:09 +00:00
playerMajorSkills = major ;
playerMinorSkills = minor ;
2010-09-17 23:30:23 +00:00
}
2010-09-18 16:21:37 +00:00
void WindowManager : : setFactions ( const FactionList & factions )
2010-09-18 00:24:42 +00:00
{
2010-09-18 16:21:37 +00:00
stats - > setFactions ( factions ) ;
2010-09-18 00:24:42 +00:00
}
2010-09-18 16:44:20 +00:00
void WindowManager : : setBirthSign ( const std : : string & signId )
2010-09-18 00:24:42 +00:00
{
2010-09-18 16:44:20 +00:00
stats - > setBirthSign ( signId ) ;
2010-10-21 07:47:34 +00:00
playerBirthSignId = signId ;
2010-09-18 00:24:42 +00:00
}
void WindowManager : : setReputation ( int reputation )
{
stats - > setReputation ( reputation ) ;
}
void WindowManager : : setBounty ( int bounty )
{
stats - > setBounty ( bounty ) ;
}
void WindowManager : : updateSkillArea ( )
{
stats - > updateSkillArea ( ) ;
}
2010-10-22 21:14:21 +00:00
void WindowManager : : removeDialog ( OEngine : : GUI : : Layout * dialog )
{
assert ( dialog ) ;
if ( ! dialog )
return ;
dialog - > setVisible ( false ) ;
garbageDialogs . push_back ( dialog ) ;
}
2010-08-22 09:22:10 +00:00
void WindowManager : : messageBox ( const std : : string & message , const std : : vector < std : : string > & buttons )
{
std : : cout < < " message box: " < < message < < std : : endl ;
if ( ! buttons . empty ( ) )
2010-08-22 10:56:35 +00:00
{
std : : cout < < " buttons: " ;
std : : copy ( buttons . begin ( ) , buttons . end ( ) , std : : ostream_iterator < std : : string > ( std : : cout , " , " ) ) ;
std : : cout < < std : : endl ;
}
2010-08-22 09:22:10 +00:00
}
2010-09-14 17:33:40 +00:00
2010-09-15 20:22:27 +00:00
const std : : string & WindowManager : : getGameSettingString ( const std : : string & id , const std : : string & default_ )
2010-09-15 10:41:53 +00:00
{
const ESM : : GameSetting * setting = environment . mWorld - > getStore ( ) . gameSettings . search ( id ) ;
if ( setting & & setting - > type = = ESM : : VT_String )
return setting - > str ;
2010-09-15 20:22:27 +00:00
return default_ ;
2010-09-15 10:41:53 +00:00
}
2010-09-14 21:17:08 +00:00
void WindowManager : : onNameDialogDone ( )
{
if ( nameDialog )
{
environment . mMechanicsManager - > setPlayerName ( nameDialog - > getTextInput ( ) ) ;
2010-10-22 21:34:41 +00:00
removeDialog ( nameDialog ) ;
2010-09-14 21:17:08 +00:00
}
2010-10-22 20:53:34 +00:00
bool goNext = nameChosen ; // Go to next dialog if name was previously chosen
nameChosen = true ;
2010-09-14 21:17:08 +00:00
if ( reviewNext )
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Review ) ;
2010-09-15 10:44:43 +00:00
else if ( goNext )
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Race ) ;
2010-09-15 11:10:47 +00:00
else
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Game ) ;
2010-09-14 21:17:08 +00:00
}
2010-09-14 17:33:40 +00:00
void WindowManager : : onRaceDialogDone ( )
{
2010-09-14 19:27:40 +00:00
if ( raceDialog )
{
2010-10-22 21:18:57 +00:00
const std : : string & raceId = raceDialog - > getRaceId ( ) ;
if ( ! raceId . empty ( ) )
environment . mMechanicsManager - > setPlayerRace ( raceId , raceDialog - > getGender ( ) = = RaceDialog : : GM_Male ) ;
2010-10-22 21:34:41 +00:00
removeDialog ( raceDialog ) ;
2010-09-14 19:27:40 +00:00
}
2010-10-22 20:53:34 +00:00
bool goNext = raceChosen ; // Go to next dialog if race was previously chosen
raceChosen = true ;
2010-09-14 19:27:40 +00:00
if ( reviewNext )
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Review ) ;
2010-09-15 10:44:43 +00:00
else if ( goNext )
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Class ) ;
2010-09-15 11:10:47 +00:00
else
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Game ) ;
2010-09-14 17:33:40 +00:00
}
void WindowManager : : onRaceDialogBack ( )
{
2010-09-14 19:27:40 +00:00
if ( raceDialog )
{
2010-10-22 21:18:57 +00:00
const std : : string & raceId = raceDialog - > getRaceId ( ) ;
if ( ! raceId . empty ( ) )
environment . mMechanicsManager - > setPlayerRace ( raceId , raceDialog - > getGender ( ) = = RaceDialog : : GM_Male ) ;
2010-10-22 21:34:41 +00:00
removeDialog ( raceDialog ) ;
2010-09-14 19:27:40 +00:00
}
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Name ) ;
2010-09-14 17:33:40 +00:00
}
2010-09-19 02:29:22 +00:00
2010-10-09 22:42:56 +00:00
void WindowManager : : onClassChoice ( MyGUI : : WidgetPtr , int _index )
{
2010-10-22 20:53:34 +00:00
if ( classChoiceDialog )
{
2010-10-22 21:34:41 +00:00
removeDialog ( classChoiceDialog ) ;
2010-10-22 20:53:34 +00:00
}
2010-10-09 22:42:56 +00:00
if ( _index = = ClassChoiceDialog : : Class_Generate )
{
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_ClassGenerate ) ;
2010-10-09 22:42:56 +00:00
}
else if ( _index = = ClassChoiceDialog : : Class_Pick )
{
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_ClassPick ) ;
2010-10-09 22:42:56 +00:00
}
else if ( _index = = ClassChoiceDialog : : Class_Create )
{
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_ClassCreate ) ;
2010-10-09 22:42:56 +00:00
}
else if ( _index = = ClassChoiceDialog : : Class_Back )
{
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Race ) ;
2010-10-09 22:42:56 +00:00
}
}
void WindowManager : : showClassQuestionDialog ( )
{
struct Step
{
const char * text ;
const char * buttons [ 3 ] ;
} ;
static boost : : array < Step , 2 > steps = { {
{ " On a clear day you chance upon a strange animal, its legs trapped in a hunter's clawsnare. Judging from the bleeding, it will not survive long. " ,
{ " Use herbs from your pack to put it to sleep? " ,
" Do not interfere in the natural evolution of events, but rather take the opportunity to learn more about a strange animal that you have never seen before? " ,
" Draw your dagger, mercifully endings its life with a single thrust? " }
} ,
{ " Your mother sends you to the market with a list of goods to buy. After you finish you find that by mistake a shopkeeper has given you too much money back in exchange for one of the items. " ,
{ " Return to the store and give the shopkeeper his hard-earned money, explaining to him the mistake? " ,
" Pocket the extra money, knowing that shopkeepers in general tend to overcharge customers anyway? " ,
" Decide to put the extra money to good use and purchase items that would help your family? " }
} ,
} } ;
2010-10-09 23:52:08 +00:00
if ( generateClassStep = = steps . size ( ) )
2010-10-09 22:42:56 +00:00
{
2010-10-09 23:52:08 +00:00
// TODO: Calculate this in mechanics manager
generateClass = " acrobat " ;
if ( generateClassResultDialog )
2010-10-22 21:34:41 +00:00
removeDialog ( generateClassResultDialog ) ;
2010-10-09 23:52:08 +00:00
generateClassResultDialog = new GenerateClassResultDialog ( environment ) ;
generateClassResultDialog - > setClassId ( generateClass ) ;
generateClassResultDialog - > eventBack = MyGUI : : newDelegate ( this , & WindowManager : : onGenerateClassBack ) ;
generateClassResultDialog - > eventDone = MyGUI : : newDelegate ( this , & WindowManager : : onGenerateClassDone ) ;
2010-10-22 22:11:54 +00:00
generateClassResultDialog - > open ( ) ;
2010-10-09 22:42:56 +00:00
return ;
}
2010-10-09 23:52:08 +00:00
if ( generateClassStep > steps . size ( ) )
2010-10-09 22:42:56 +00:00
{
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Class ) ;
2010-10-09 22:42:56 +00:00
return ;
}
2010-10-22 20:53:34 +00:00
if ( generateClassQuestionDialog )
2010-10-22 21:34:41 +00:00
removeDialog ( generateClassQuestionDialog ) ;
2010-10-22 20:53:34 +00:00
generateClassQuestionDialog = new InfoBoxDialog ( environment ) ;
2010-10-09 23:52:08 +00:00
2010-10-09 22:42:56 +00:00
InfoBoxDialog : : ButtonList buttons ;
generateClassQuestionDialog - > setText ( steps [ generateClassStep ] . text ) ;
buttons . push_back ( steps [ generateClassStep ] . buttons [ 0 ] ) ;
buttons . push_back ( steps [ generateClassStep ] . buttons [ 1 ] ) ;
buttons . push_back ( steps [ generateClassStep ] . buttons [ 2 ] ) ;
generateClassQuestionDialog - > setButtons ( buttons ) ;
generateClassQuestionDialog - > eventButtonSelected = MyGUI : : newDelegate ( this , & WindowManager : : onClassQuestionChosen ) ;
2010-10-22 22:11:54 +00:00
generateClassQuestionDialog - > open ( ) ;
2010-10-09 22:42:56 +00:00
}
void WindowManager : : onClassQuestionChosen ( MyGUI : : Widget * _sender , int _index )
{
2010-10-22 20:53:34 +00:00
if ( generateClassQuestionDialog )
2010-10-22 21:34:41 +00:00
removeDialog ( generateClassQuestionDialog ) ;
2010-10-09 22:42:56 +00:00
if ( _index < 0 | | _index > = 3 )
{
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Class ) ;
2010-10-09 22:42:56 +00:00
return ;
}
+ + generateClassStep ;
showClassQuestionDialog ( ) ;
}
2010-10-09 23:52:08 +00:00
void WindowManager : : onGenerateClassBack ( )
{
2010-10-10 00:43:44 +00:00
bool goNext = classChosen ; // Go to next dialog if class was previously chosen
classChosen = true ;
2010-10-09 23:52:08 +00:00
if ( generateClassResultDialog )
2010-10-22 21:34:41 +00:00
removeDialog ( generateClassResultDialog ) ;
2010-10-09 23:52:08 +00:00
environment . mMechanicsManager - > setPlayerClass ( generateClass ) ;
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Class ) ;
2010-10-09 23:52:08 +00:00
}
void WindowManager : : onGenerateClassDone ( )
{
2010-10-10 00:43:44 +00:00
bool goNext = classChosen ; // Go to next dialog if class was previously chosen
classChosen = true ;
2010-10-09 23:52:08 +00:00
if ( generateClassResultDialog )
2010-10-22 21:34:41 +00:00
removeDialog ( generateClassResultDialog ) ;
2010-10-09 23:52:08 +00:00
environment . mMechanicsManager - > setPlayerClass ( generateClass ) ;
2010-10-10 00:43:44 +00:00
if ( reviewNext )
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Review ) ;
2010-10-10 00:43:44 +00:00
else if ( goNext )
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Birth ) ;
2010-10-10 00:43:44 +00:00
else
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Game ) ;
2010-10-09 23:52:08 +00:00
}
2010-09-19 02:29:22 +00:00
void WindowManager : : onPickClassDialogDone ( )
{
if ( pickClassDialog )
{
2010-10-22 21:18:57 +00:00
const std : : string & classId = pickClassDialog - > getClassId ( ) ;
if ( ! classId . empty ( ) )
environment . mMechanicsManager - > setPlayerClass ( classId ) ;
2010-10-22 21:34:41 +00:00
removeDialog ( pickClassDialog ) ;
2010-09-19 02:29:22 +00:00
}
2010-10-22 20:53:34 +00:00
bool goNext = classChosen ; // Go to next dialog if class was previously chosen
classChosen = true ;
2010-09-19 02:29:22 +00:00
if ( reviewNext )
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Review ) ;
2010-09-19 02:29:22 +00:00
else if ( goNext )
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Birth ) ;
2010-09-19 02:29:22 +00:00
else
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Game ) ;
2010-09-19 02:29:22 +00:00
}
void WindowManager : : onPickClassDialogBack ( )
2010-10-10 00:43:44 +00:00
{
if ( pickClassDialog )
{
2010-10-22 21:18:57 +00:00
const std : : string classId = pickClassDialog - > getClassId ( ) ;
if ( ! classId . empty ( ) )
environment . mMechanicsManager - > setPlayerClass ( classId ) ;
2010-10-22 21:34:41 +00:00
removeDialog ( pickClassDialog ) ;
2010-10-10 00:43:44 +00:00
}
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Class ) ;
2010-10-10 00:43:44 +00:00
}
void WindowManager : : onCreateClassDialogDone ( )
{
if ( createClassDialog )
{
// TODO: The ESM::Class should have methods to set these values to ensure correct data is assigned
ESM : : Class klass ;
klass . name = createClassDialog - > getName ( ) ;
klass . description = createClassDialog - > getDescription ( ) ;
klass . data . specialization = createClassDialog - > getSpecializationId ( ) ;
klass . data . isPlayable = 0x1 ;
std : : vector < int > attributes = createClassDialog - > getFavoriteAttributes ( ) ;
assert ( attributes . size ( ) = = 2 ) ;
klass . data . attribute [ 0 ] = attributes [ 0 ] ;
klass . data . attribute [ 1 ] = attributes [ 1 ] ;
std : : vector < ESM : : Skill : : SkillEnum > majorSkills = createClassDialog - > getMajorSkills ( ) ;
std : : vector < ESM : : Skill : : SkillEnum > minorSkills = createClassDialog - > getMinorSkills ( ) ;
assert ( majorSkills . size ( ) > = sizeof ( klass . data . skills ) / sizeof ( klass . data . skills [ 0 ] ) ) ;
assert ( minorSkills . size ( ) > = sizeof ( klass . data . skills ) / sizeof ( klass . data . skills [ 0 ] ) ) ;
for ( size_t i = 0 ; i < sizeof ( klass . data . skills ) / sizeof ( klass . data . skills [ 0 ] ) ; + + i )
{
klass . data . skills [ i ] [ 1 ] = majorSkills [ i ] ;
klass . data . skills [ i ] [ 0 ] = minorSkills [ i ] ;
}
environment . mMechanicsManager - > setPlayerClass ( klass ) ;
2010-10-22 20:53:34 +00:00
2010-10-22 21:34:41 +00:00
removeDialog ( createClassDialog ) ;
2010-10-10 00:43:44 +00:00
}
2010-10-22 20:53:34 +00:00
bool goNext = classChosen ; // Go to next dialog if class was previously chosen
classChosen = true ;
2010-10-10 00:43:44 +00:00
if ( reviewNext )
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Review ) ;
2010-10-10 00:43:44 +00:00
else if ( goNext )
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Birth ) ;
2010-10-10 00:43:44 +00:00
else
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Game ) ;
2010-10-10 00:43:44 +00:00
}
void WindowManager : : onCreateClassDialogBack ( )
2010-09-19 02:29:22 +00:00
{
2010-10-22 20:53:34 +00:00
if ( createClassDialog )
2010-10-22 21:34:41 +00:00
removeDialog ( createClassDialog ) ;
2010-09-19 02:29:22 +00:00
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Class ) ;
2010-09-19 02:29:22 +00:00
}
2010-09-21 10:34:47 +00:00
void WindowManager : : onBirthSignDialogDone ( )
{
if ( birthSignDialog )
{
environment . mMechanicsManager - > setPlayerBirthsign ( birthSignDialog - > getBirthId ( ) ) ;
2010-10-22 21:34:41 +00:00
removeDialog ( birthSignDialog ) ;
2010-09-21 10:34:47 +00:00
}
2010-10-22 20:53:34 +00:00
bool goNext = birthSignChosen ; // Go to next dialog if birth sign was previously chosen
birthSignChosen = true ;
2010-09-21 10:34:47 +00:00
if ( reviewNext | | goNext )
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Review ) ;
2010-09-21 10:34:47 +00:00
else
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Game ) ;
2010-09-21 10:34:47 +00:00
}
void WindowManager : : onBirthSignDialogBack ( )
{
if ( birthSignDialog )
{
environment . mMechanicsManager - > setPlayerBirthsign ( birthSignDialog - > getBirthId ( ) ) ;
2010-10-22 21:34:41 +00:00
removeDialog ( birthSignDialog ) ;
2010-09-21 10:34:47 +00:00
}
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Class ) ;
2010-09-21 10:34:47 +00:00
}
2010-10-20 19:40:32 +00:00
void WindowManager : : onReviewDialogDone ( )
{
if ( reviewDialog )
2010-10-22 21:34:41 +00:00
removeDialog ( reviewDialog ) ;
2010-10-20 19:40:32 +00:00
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Game ) ;
2010-10-20 19:40:32 +00:00
}
void WindowManager : : onReviewDialogBack ( )
{
if ( reviewDialog )
2010-10-22 21:34:41 +00:00
removeDialog ( reviewDialog ) ;
2010-10-20 19:40:32 +00:00
2010-10-22 20:53:34 +00:00
setGuiMode ( GM_Birth ) ;
2010-10-20 19:40:32 +00:00
}