forked from etternagame/etterna
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split ScreenGameplay code into multiple files
PlayerInfo is its own file Practice/Replay specific functions are part of their own class
- Loading branch information
Showing
9 changed files
with
973 additions
and
689 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#include "Etterna/Globals/global.h" | ||
#include "PlayerInfo.h" | ||
#include "GameConstantsAndTypes.h" | ||
#include "PlayerNumber.h" | ||
#include "PlayerState.h" | ||
#include "Etterna/Singletons/Gamestate.h" | ||
#include "Etterna/Singletons/StatsManager.h" | ||
#include "PlayerStageStats.h" | ||
#include "Etterna/Models/ScoreKeepers/ScoreKeeper.h" | ||
#include "Etterna/Actor/Gameplay/Player.h" | ||
#include "Etterna/Actor/Gameplay/LifeMeter.h" | ||
|
||
#include "Etterna/Models/Lua/LuaBinding.h" | ||
#include "Etterna/Singletons/LuaManager.h" | ||
|
||
static ThemeMetric<RString> SCORE_KEEPER_CLASS("ScreenGameplay", | ||
"ScoreKeeperClass"); | ||
|
||
PlayerInfo::PlayerInfo() | ||
: m_pn(PLAYER_INVALID) | ||
, m_SoundEffectControl() | ||
, m_vpStepsQueue() | ||
, m_pLifeMeter(NULL) | ||
, m_ptextStepsDescription(NULL) | ||
, m_pPrimaryScoreKeeper(NULL) | ||
, m_ptextPlayerOptions(NULL) | ||
, m_NoteData() | ||
, m_pPlayer(NULL) | ||
, m_pStepsDisplay(NULL) | ||
{ | ||
} | ||
|
||
void | ||
PlayerInfo::Load(PlayerNumber pn, | ||
MultiPlayer mp, | ||
bool bShowNoteField, | ||
int iAddToDifficulty) | ||
{ | ||
m_pn = pn; | ||
m_mp = mp; | ||
m_bPlayerEnabled = IsEnabled(); | ||
m_bIsDummy = false; | ||
m_iAddToDifficulty = iAddToDifficulty; | ||
m_pLifeMeter = NULL; | ||
m_ptextStepsDescription = NULL; | ||
|
||
if (!IsMultiPlayer()) { | ||
PlayMode mode = GAMESTATE->m_PlayMode; | ||
switch (mode) { | ||
case PLAY_MODE_REGULAR: | ||
break; | ||
default: | ||
FAIL_M(ssprintf("Invalid PlayMode: %i", mode)); | ||
} | ||
} | ||
|
||
PlayerState* const pPlayerState = GetPlayerState(); | ||
PlayerStageStats* const pPlayerStageStats = GetPlayerStageStats(); | ||
m_pPrimaryScoreKeeper = ScoreKeeper::MakeScoreKeeper( | ||
SCORE_KEEPER_CLASS, pPlayerState, pPlayerStageStats); | ||
|
||
m_ptextPlayerOptions = NULL; | ||
m_pPlayer = new Player(m_NoteData, bShowNoteField); | ||
m_pStepsDisplay = NULL; | ||
|
||
if (IsMultiPlayer()) { | ||
pPlayerState->m_PlayerOptions = | ||
GAMESTATE->m_pPlayerState->m_PlayerOptions; | ||
} | ||
} | ||
|
||
PlayerInfo::~PlayerInfo() | ||
{ | ||
SAFE_DELETE(m_pLifeMeter); | ||
SAFE_DELETE(m_ptextStepsDescription); | ||
SAFE_DELETE(m_pPrimaryScoreKeeper); | ||
SAFE_DELETE(m_ptextPlayerOptions); | ||
SAFE_DELETE(m_pPlayer); | ||
SAFE_DELETE(m_pStepsDisplay); | ||
} | ||
|
||
PlayerState* | ||
PlayerInfo::GetPlayerState() | ||
{ | ||
return IsMultiPlayer() | ||
? GAMESTATE | ||
->m_pMultiPlayerState[GetPlayerStateAndStageStatsIndex()] | ||
: GAMESTATE->m_pPlayerState; | ||
} | ||
|
||
PlayerStageStats* | ||
PlayerInfo::GetPlayerStageStats() | ||
{ | ||
return &STATSMAN->m_CurStageStats.m_player; | ||
} | ||
|
||
bool | ||
PlayerInfo::IsEnabled() | ||
{ | ||
if (m_pn != PLAYER_INVALID) | ||
return GAMESTATE->IsPlayerEnabled(m_pn); | ||
if (m_mp != MultiPlayer_Invalid) | ||
return GAMESTATE->IsMultiPlayerEnabled(m_mp); | ||
if (m_bIsDummy) | ||
return true; | ||
FAIL_M("Invalid non-dummy player."); | ||
} | ||
|
||
/** @brief Allow Lua to have access to the PlayerInfo. */ | ||
class LunaPlayerInfo : public Luna<PlayerInfo> | ||
{ | ||
public: | ||
static int GetLifeMeter(T* p, lua_State* L) | ||
{ | ||
if (p->m_pLifeMeter) { | ||
p->m_pLifeMeter->PushSelf(L); | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
static int GetStepsQueueWrapped(T* p, lua_State* L) | ||
{ | ||
int iIndex = IArg(1); | ||
iIndex %= p->m_vpStepsQueue.size(); | ||
Steps* pSteps = p->m_vpStepsQueue[iIndex]; | ||
pSteps->PushSelf(L); | ||
return 1; | ||
} | ||
|
||
LunaPlayerInfo() | ||
{ | ||
ADD_METHOD(GetLifeMeter); | ||
ADD_METHOD(GetStepsQueueWrapped); | ||
} | ||
}; | ||
|
||
LUA_REGISTER_CLASS(PlayerInfo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#ifndef PLAYERINFO_H | ||
#define PLAYERINFO_H | ||
|
||
#include "Etterna/Models/Misc/GameConstantsAndTypes.h" | ||
#include "Etterna/Models/Misc/PlayerNumber.h" | ||
#include "Etterna/Models/StepsAndStyles/Steps.h" | ||
#include "Etterna/Models/Misc/PlayerStageStats.h" | ||
#include "Etterna/Actor/Base/BitmapText.h" | ||
#include "Etterna/Models/Misc/SoundEffectControl.h" | ||
#include "Etterna/Models/NoteData/NoteData.h" | ||
|
||
class Player; | ||
|
||
class LifeMeter; | ||
class StepsDisplay; | ||
class ScoreKeeper; | ||
|
||
class PlayerInfo | ||
{ | ||
public: | ||
PlayerInfo(); | ||
~PlayerInfo(); | ||
|
||
void Load(PlayerNumber pn, | ||
MultiPlayer mp, | ||
bool bShowNoteField, | ||
int iAddToDifficulty); | ||
|
||
/** | ||
* @brief Retrieve the player's state and stage stats index. | ||
* @return the player's state and stage stats index. | ||
*/ | ||
MultiPlayer GetPlayerStateAndStageStatsIndex() | ||
{ | ||
return m_pn == PLAYER_INVALID ? m_mp : static_cast<MultiPlayer>(m_pn); | ||
} | ||
PlayerState* GetPlayerState(); | ||
PlayerStageStats* GetPlayerStageStats(); | ||
PlayerNumber GetStepsAndTrailIndex() | ||
{ | ||
return m_pn == PLAYER_INVALID ? PLAYER_1 : m_pn; | ||
} | ||
/** | ||
* @brief Determine if the player information is enabled. | ||
* @return its success or failure. */ | ||
bool IsEnabled(); | ||
/** | ||
* @brief Determine if we're in MultiPlayer. | ||
* @return true if it is MultiPlayer, false otherwise. */ | ||
bool IsMultiPlayer() const { return m_mp != MultiPlayer_Invalid; } | ||
/** | ||
* @brief Retrieve the name of the Player based on the mode. | ||
* @return the name of the Player. */ | ||
RString GetName() const | ||
{ | ||
if (m_bIsDummy) | ||
return ssprintf("PlayerInfoDummy"); | ||
if (IsMultiPlayer()) | ||
return MultiPlayerToString(m_mp); | ||
else | ||
return PlayerNumberToString(m_pn); | ||
} | ||
|
||
// Lua | ||
void PushSelf(lua_State* L); | ||
|
||
/** @brief The present Player's number. */ | ||
PlayerNumber m_pn; | ||
/** @brief The present Player's multiplayer number. */ | ||
MultiPlayer m_mp{ MultiPlayer_Invalid }; | ||
bool m_bIsDummy{ false }; | ||
int m_iAddToDifficulty{ 0 }; // if > 0, use the Nth harder Steps | ||
bool m_bPlayerEnabled{ false }; // IsEnabled cache for iterators | ||
SoundEffectControl m_SoundEffectControl; | ||
|
||
/** | ||
* @brief The list of Steps a player has to go through in this set. | ||
* | ||
* The size may be greater than 1 if playing a course. */ | ||
vector<Steps*> m_vpStepsQueue; | ||
|
||
/** @brief The LifeMeter showing a Player's health. */ | ||
LifeMeter* m_pLifeMeter; | ||
/** @brief The description of the current Steps. */ | ||
BitmapText* m_ptextStepsDescription; | ||
/** @brief The primary ScoreKeeper for keeping track of the score. */ | ||
ScoreKeeper* m_pPrimaryScoreKeeper; | ||
/** @brief The current PlayerOptions that are activated. */ | ||
BitmapText* m_ptextPlayerOptions; | ||
/** @brief The current attack modifiers that are in play for the moment. */ | ||
|
||
/** @brief The NoteData the Player has to get through. */ | ||
NoteData m_NoteData; | ||
/** @brief The specific Player that is going to play. */ | ||
Player* m_pPlayer; | ||
|
||
StepsDisplay* m_pStepsDisplay; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.