@ -36,28 +36,41 @@ All rights reserved.
*/
# pragma endregion
# pragma once
# include <unordered_map>
# include <memory>
# include "AdventuresInLestoria.h"
# include "MenuComponent.h"
# include "LoadingScreen.h"
# include "Key.h"
using A = Attribute ;
INCLUDE_game
# undef BLACKSMITH
enum class TutorialTaskName {
SET_LOADOUT_ITEM ,
MOVE_AROUND ,
USE_ATTACK ,
USE_ABILITIES ,
USE_DEFENSIVE ,
USE_RECOVERY_ITEMS ,
BLACKSMITH ,
NONE ,
} ;
class TutorialTask {
class TutorialTask : public IAttributable {
friend class Tutorial ;
public :
TutorialTask ( ) ;
protected :
bool completed = false ;
bool systemInitializeCalled = false ;
TutorialTask ( ) ;
virtual void Initialize ( ) ;
private :
void _Initialize ( ) ;
//Actions that occur when this task is reset/locked. DO NOT CALL DIRECTLY, USE _Initialize()!
virtual void Initialize ( ) ;
virtual void Update ( ) ;
virtual void OnActivate ( ) ;
virtual void Draw ( ) const ;
//Returns true when the task has detected it is completed.
virtual bool CompleteCondition ( ) = 0 ;
@ -67,19 +80,25 @@ class TutorialTask{
} ;
class Tutorial {
friend class SaveFile ;
public :
static void Initialize ( ) ;
static void ResetTasks ( ) ;
static void Update ( ) ;
static void Draw ( ) ;
static const bool TaskIsComplete ( TutorialTaskName task ) ;
static void SetNextTask ( TutorialTaskName task ) ;
static TutorialTask & GetTask ( TutorialTaskName task ) ;
static void CompleteTask ( TutorialTaskName task ) ;
private :
static TutorialTaskName currentTaskState ;
static std : : unordered_map < TutorialTaskName , std : : unique_ptr < TutorialTask > > taskList ;
static std : : map < TutorialTaskName , std : : unique_ptr < TutorialTask > > taskList ;
} ;
class SetLoadoutItemTask : protected TutorialTask {
class SetLoadoutItemTask : public TutorialTask {
public :
inline SetLoadoutItemTask ( ) : TutorialTask ( ) { } ;
private :
virtual inline void Initialize ( ) override final {
Component < MenuComponent > ( ITEM_LOADOUT , " Start Level Button " ) - > SetGrayedOut ( true ) ;
}
@ -96,11 +115,23 @@ class SetLoadoutItemTask:protected TutorialTask{
}
} ;
class MoveAroundTask : protected TutorialTask {
vf2d initialPlayerPos = vf2d { } ;
class MoveAroundTask : public TutorialTask {
public :
inline MoveAroundTask ( ) : TutorialTask ( ) { } ;
private :
InputGroup moveGroup ;
vf2d initialPlayerPos = vf2d { } ;
virtual inline void Initialize ( ) override final {
initialPlayerPos = vf2d { } ;
moveGroup . ClearAllKeybinds ( ) ;
moveGroup . AddKeybind ( game - > KEY_LEFT . GetPrimaryKey ( InputType : : CONTROLLER ) . value ( ) ) ;
moveGroup . AddKeybind ( game - > KEY_DOWN . GetPrimaryKey ( InputType : : CONTROLLER ) . value ( ) ) ;
moveGroup . AddKeybind ( game - > KEY_UP . GetPrimaryKey ( InputType : : CONTROLLER ) . value ( ) ) ;
moveGroup . AddKeybind ( game - > KEY_RIGHT . GetPrimaryKey ( InputType : : CONTROLLER ) . value ( ) ) ;
moveGroup . AddKeybind ( game - > KEY_LEFT . GetPrimaryKey ( InputType : : KEY ) . value ( ) ) ;
moveGroup . AddKeybind ( game - > KEY_DOWN . GetPrimaryKey ( InputType : : KEY ) . value ( ) ) ;
moveGroup . AddKeybind ( game - > KEY_UP . GetPrimaryKey ( InputType : : KEY ) . value ( ) ) ;
moveGroup . AddKeybind ( game - > KEY_RIGHT . GetPrimaryKey ( InputType : : KEY ) . value ( ) ) ;
}
virtual inline void Update ( ) override final {
if ( ! LoadingScreen : : loading & & initialPlayerPos = = vf2d { } ) {
@ -108,9 +139,148 @@ class MoveAroundTask:protected TutorialTask{
}
}
virtual inline bool CompleteCondition ( ) override final {
return initialPlayerPos ! = { } & & geom2d : : line < float > ( initialPlayerPos , game - > GetPlayer ( ) ) . length ( ) > 60 ;
return initialPlayerPos ! = vf2d { } & & geom2d : : line < float > ( initialPlayerPos , game - > GetPlayer ( ) - > GetPos ( ) ) . length ( ) > 60 ;
}
virtual inline void OnComplete ( ) override final {
initialPlayerPos = { } ;
initialPlayerPos = vf2d { } ;
}
virtual inline void Draw ( ) const override final {
if ( Input : : UsingGamepad ( ) ) {
moveGroup . DrawInput ( game , { game - > ScreenWidth ( ) / 2.f , 48.f } , " Move " , 180 , InputType : : CONTROLLER ) ;
} else {
moveGroup . DrawInput ( game , { game - > ScreenWidth ( ) / 2.f , 48.f } , " Move " , 180 , InputType : : KEY ) ;
}
}
} ;
# define ADDKEYBIND(group,key,type) \
group . AddKeybind ( key . GetPrimaryKey ( InputType : : type ) . value ( ) ) ; \
if ( type = = InputType : : KEY & & key . GetPrimaryKey ( InputType : : MOUSE ) . has_value ( ) ) { \
group . AddKeybind ( key . GetPrimaryKey ( InputType : : MOUSE ) . value ( ) ) ; \
}
class UseAttackTask : public TutorialTask {
public :
inline UseAttackTask ( ) : TutorialTask ( ) { } ;
private :
InputGroup attackGroup ;
virtual inline void OnActivate ( ) override final {
attackGroup . ClearAllKeybinds ( ) ;
ADDKEYBIND ( attackGroup , game - > KEY_ATTACK , CONTROLLER ) ;
ADDKEYBIND ( attackGroup , game - > KEY_ATTACK , KEY ) ;
}
virtual inline bool CompleteCondition ( ) override final {
return I ( A : : ATTACK_COUNT ) > = 10 ;
}
virtual inline void OnComplete ( ) override final { }
virtual inline void Draw ( ) const override final {
if ( Input : : UsingGamepad ( ) ) {
attackGroup . DrawInput ( game , { game - > ScreenWidth ( ) / 2.f , 48.f } , " Attack " , 180 , InputType : : CONTROLLER ) ;
} else {
attackGroup . DrawInput ( game , { game - > ScreenWidth ( ) / 2.f , 48.f } , " Attack " , 180 , InputType : : KEY ) ;
}
}
} ;
class UseAbilitiesTask : public TutorialTask {
public :
inline UseAbilitiesTask ( ) : TutorialTask ( ) { } ;
private :
InputGroup abilityGroup ;
virtual inline void OnActivate ( ) override final {
abilityGroup . ClearAllKeybinds ( ) ;
ADDKEYBIND ( abilityGroup , game - > GetPlayer ( ) - > KEY_ABILITY1 , CONTROLLER ) ;
ADDKEYBIND ( abilityGroup , game - > GetPlayer ( ) - > KEY_ABILITY1 , KEY ) ;
ADDKEYBIND ( abilityGroup , game - > GetPlayer ( ) - > KEY_ABILITY2 , CONTROLLER ) ;
ADDKEYBIND ( abilityGroup , game - > GetPlayer ( ) - > KEY_ABILITY2 , KEY ) ;
ADDKEYBIND ( abilityGroup , game - > GetPlayer ( ) - > KEY_ABILITY3 , CONTROLLER ) ;
ADDKEYBIND ( abilityGroup , game - > GetPlayer ( ) - > KEY_ABILITY3 , KEY ) ;
}
virtual inline bool CompleteCondition ( ) override final {
return I ( A : : ABILITY_COUNT ) > = 5 ;
}
virtual inline void OnComplete ( ) override final { }
virtual inline void Draw ( ) const override final {
if ( Input : : UsingGamepad ( ) ) {
abilityGroup . DrawInput ( game , { game - > ScreenWidth ( ) / 2.f , 48.f } , " Use Abilities " , 180 , InputType : : CONTROLLER ) ;
} else {
abilityGroup . DrawInput ( game , { game - > ScreenWidth ( ) / 2.f , 48.f } , " Use Abilities " , 180 , InputType : : KEY ) ;
}
}
} ;
class UseDefensiveTask : public TutorialTask {
public :
inline UseDefensiveTask ( ) : TutorialTask ( ) { } ;
private :
InputGroup defensiveGroup ;
virtual inline void OnActivate ( ) override final {
defensiveGroup . ClearAllKeybinds ( ) ;
ADDKEYBIND ( defensiveGroup , game - > GetPlayer ( ) - > KEY_DEFENSIVE , CONTROLLER ) ;
ADDKEYBIND ( defensiveGroup , game - > GetPlayer ( ) - > KEY_DEFENSIVE , KEY ) ;
}
virtual inline bool CompleteCondition ( ) override final {
return I ( A : : DEFENSIVE_COUNT ) > = 2 ;
}
virtual inline void OnComplete ( ) override final { }
virtual inline void Draw ( ) const override final {
if ( Input : : UsingGamepad ( ) ) {
defensiveGroup . DrawInput ( game , { game - > ScreenWidth ( ) / 2.f , 48.f } , " Defensive Ability " , 180 , InputType : : CONTROLLER ) ;
} else {
defensiveGroup . DrawInput ( game , { game - > ScreenWidth ( ) / 2.f , 48.f } , " Defensive Ability " , 180 , InputType : : KEY ) ;
}
}
} ;
class UseRecoveryItemsTask : public TutorialTask {
public :
inline UseRecoveryItemsTask ( ) : TutorialTask ( ) { } ;
private :
InputGroup itemsGroup ;
virtual inline void OnActivate ( ) override final {
itemsGroup . ClearAllKeybinds ( ) ;
if ( ! ISBLANK ( game - > GetLoadoutItem ( 0 ) ) ) {
ADDKEYBIND ( itemsGroup , game - > GetPlayer ( ) - > KEY_ITEM1 , CONTROLLER ) ;
ADDKEYBIND ( itemsGroup , game - > GetPlayer ( ) - > KEY_ITEM1 , KEY ) ;
}
if ( ! ISBLANK ( game - > GetLoadoutItem ( 1 ) ) ) {
ADDKEYBIND ( itemsGroup , game - > GetPlayer ( ) - > KEY_ITEM2 , CONTROLLER ) ;
ADDKEYBIND ( itemsGroup , game - > GetPlayer ( ) - > KEY_ITEM2 , KEY ) ;
}
if ( ! ISBLANK ( game - > GetLoadoutItem ( 2 ) ) ) {
ADDKEYBIND ( itemsGroup , game - > GetPlayer ( ) - > KEY_ITEM3 , CONTROLLER ) ;
ADDKEYBIND ( itemsGroup , game - > GetPlayer ( ) - > KEY_ITEM3 , KEY ) ;
}
}
virtual inline bool CompleteCondition ( ) override final {
return I ( A : : ITEM_USE_COUNT ) > = 1 ;
}
virtual inline void OnComplete ( ) override final { }
virtual inline void Draw ( ) const override final {
if ( Input : : UsingGamepad ( ) ) {
itemsGroup . DrawInput ( game , { game - > ScreenWidth ( ) / 2.f , 48.f } , " Use Consumables " , 180 , InputType : : CONTROLLER ) ;
} else {
itemsGroup . DrawInput ( game , { game - > ScreenWidth ( ) / 2.f , 48.f } , " Use Consumables " , 180 , InputType : : KEY ) ;
}
}
} ;
class BlacksmithTask : public TutorialTask {
public :
inline BlacksmithTask ( ) : TutorialTask ( ) { } ;
private :
virtual inline void OnActivate ( ) override final {
Component < MenuComponent > ( SHERMAN , " Leave Button " ) - > SetGrayedOut ( true ) ;
}
virtual inline bool CompleteCondition ( ) override final {
return I ( A : : ITEM_USE_COUNT ) > = 1 ;
}
virtual inline void OnComplete ( ) override final {
Component < MenuComponent > ( SHERMAN , " Leave Button " ) - > SetGrayedOut ( false ) ;
}
virtual inline void Draw ( ) const override final {
std : : string helpText = " Visit #00FFD0 \" Greg \" the Blacksmith#FFFFFF to browse craftable gear. " ;
float textWidth = game - > GetTextSizeProp ( helpText ) . x ;
game - > DrawShadowStringPropDecal ( { game - > ScreenWidth ( ) / 2.f - textWidth / 2.f , 48.f } , helpText ) ;
}
} ;