Files
itgmania212121/stepmania/src/PaneDisplay.cpp
T

269 lines
7.4 KiB
C++
Raw Normal View History

2003-11-17 06:08:30 +00:00
#include "global.h"
#include "PaneDisplay.h"
#include "ThemeManager.h"
#include "GameState.h"
#include "Song.h"
2003-12-18 03:40:57 +00:00
#include "Steps.h"
2003-11-17 06:08:30 +00:00
#include "RageLog.h"
#include "ProfileManager.h"
2005-07-01 05:07:22 +00:00
#include "Profile.h"
2003-11-17 06:08:30 +00:00
#include "Course.h"
2004-06-28 07:26:00 +00:00
#include "Style.h"
2005-02-09 05:27:51 +00:00
#include "ActorUtil.h"
#include "Foreach.h"
2005-09-09 08:11:31 +00:00
#include "LuaManager.h"
2005-12-05 19:09:22 +00:00
#include "XmlFile.h"
#include "PlayerStageStats.h"
2003-11-17 06:08:30 +00:00
2008-02-15 09:57:24 +00:00
#define SHIFT_X(pc) THEME->GetMetricF(sMetricsGroup, ssprintf("ShiftP%iX", pc+1))
#define SHIFT_Y(pc) THEME->GetMetricF(sMetricsGroup, ssprintf("ShiftP%iY", pc+1))
static const char *PaneCategoryNames[] = {
"NumSteps",
"Jumps",
"Holds",
"Rolls",
"Mines",
"Hands",
"MachineHighScore",
"MachineHighName",
"ProfileHighScore",
};
XToString( PaneCategory );
LuaXType( PaneCategory );
2003-11-17 06:08:30 +00:00
2007-06-09 16:59:19 +00:00
enum { NEED_NOTES=1, NEED_PROFILE=2 };
2003-11-17 06:08:30 +00:00
struct Content_t
{
int req;
2008-02-15 09:57:24 +00:00
RString sFontType;
2003-11-17 06:08:30 +00:00
};
2008-02-15 09:57:24 +00:00
static const Content_t g_Contents[NUM_PaneCategory] =
2003-11-17 06:08:30 +00:00
{
2008-02-15 09:57:24 +00:00
{ NEED_NOTES, "count" },
{ NEED_NOTES, "count" },
{ NEED_NOTES, "count" },
{ NEED_NOTES, "count" },
{ NEED_NOTES, "count" },
{ NEED_NOTES, "count" },
{ NEED_NOTES, "score" },
{ NEED_NOTES, "name" },
{ NEED_NOTES|NEED_PROFILE, "score" },
2003-11-17 06:08:30 +00:00
};
2005-07-29 22:59:11 +00:00
REGISTER_ACTOR_CLASS( PaneDisplay )
2006-01-22 01:00:06 +00:00
void PaneDisplay::Load( const RString &sMetricsGroup, PlayerNumber pn )
2003-11-17 06:08:30 +00:00
{
m_PlayerNumber = pn;
2005-12-05 19:09:22 +00:00
EMPTY_MACHINE_HIGH_SCORE_NAME.Load( sMetricsGroup, "EmptyMachineHighScoreName" );
NOT_AVAILABLE.Load( sMetricsGroup, "NotAvailable" );
2008-02-15 09:57:24 +00:00
COUNT_FORMAT.Load( sMetricsGroup, "CountFormat" );
2005-06-12 00:44:59 +00:00
2005-01-29 23:05:21 +00:00
2008-02-15 09:57:24 +00:00
FOREACH_ENUM( PaneCategory, pc )
2003-11-17 06:08:30 +00:00
{
2008-02-15 09:57:24 +00:00
LuaThreadVariable var( "PaneCategory", LuaReference::Create(pc) );
2003-11-17 06:08:30 +00:00
2008-02-15 09:57:24 +00:00
RString sFontType = g_Contents[pc].sFontType;
2005-09-09 08:11:31 +00:00
2008-02-15 09:57:24 +00:00
m_textContents[pc].LoadFromFont( THEME->GetPathF(sMetricsGroup,sFontType) );
m_textContents[pc].SetName( PaneCategoryToString(pc) + "Text" );
ActorUtil::LoadAllCommands( m_textContents[pc], sMetricsGroup );
ActorUtil::SetXY( m_textContents[pc], sMetricsGroup );
m_ContentsFrame.AddChild( &m_textContents[pc] );
m_Labels[pc].Load( THEME->GetPathG(sMetricsGroup,"label " + PaneCategoryToString(pc)) );
m_Labels[pc]->SetName( PaneCategoryToString(pc) + "Label" );
ActorUtil::LoadAllCommands( *m_Labels[pc], sMetricsGroup );
ActorUtil::SetXY( m_Labels[pc], sMetricsGroup );
m_ContentsFrame.AddChild( m_Labels[pc] );
ActorUtil::LoadAllCommandsFromName( m_textContents[pc], sMetricsGroup, PaneCategoryToString(pc) );
2003-11-17 06:08:30 +00:00
}
m_ContentsFrame.SetXY( SHIFT_X(m_PlayerNumber), SHIFT_Y(m_PlayerNumber) );
this->AddChild( &m_ContentsFrame );
}
void PaneDisplay::LoadFromNode( const XNode *pNode )
2005-12-05 19:09:22 +00:00
{
bool b;
2006-01-22 01:00:06 +00:00
RString sMetricsGroup;
2005-12-05 19:09:22 +00:00
b = pNode->GetAttrValue( "MetricsGroup", sMetricsGroup );
ASSERT( b );
2006-10-09 01:34:16 +00:00
Lua *L = LUA->Get();
b = pNode->PushAttrValue( L, "PlayerNumber" );
2005-12-05 19:09:22 +00:00
ASSERT( b );
2006-10-09 01:34:16 +00:00
PlayerNumber pn;
LuaHelpers::Pop( L, pn );
LUA->Release( L );
2005-12-05 19:09:22 +00:00
Load( sMetricsGroup, pn );
2006-08-10 21:26:57 +00:00
ActorFrame::LoadFromNode( pNode );
2005-12-05 19:09:22 +00:00
}
2008-02-15 09:57:24 +00:00
void PaneDisplay::SetContent( PaneCategory c )
2003-11-17 06:08:30 +00:00
{
2007-04-07 23:43:10 +00:00
RString str = ""; // fill this in
float val = 0; // fill this in
2003-11-17 06:08:30 +00:00
2004-02-09 06:26:13 +00:00
const Song *pSong = GAMESTATE->m_pCurSong;
2004-05-24 06:12:17 +00:00
const Steps *pSteps = GAMESTATE->m_pCurSteps[m_PlayerNumber];
2004-02-09 06:26:13 +00:00
const Course *pCourse = GAMESTATE->m_pCurCourse;
2004-06-03 08:22:02 +00:00
const Trail *pTrail = GAMESTATE->m_pCurTrail[m_PlayerNumber];
const Profile *pProfile = PROFILEMAN->IsPersistentProfile(m_PlayerNumber) ? PROFILEMAN->GetProfile(m_PlayerNumber) : NULL;
bool bIsPlayerEdit = pSteps && pSteps->IsAPlayerEdit();
2004-02-09 06:26:13 +00:00
2007-06-09 16:59:19 +00:00
if( (g_Contents[c].req&NEED_NOTES) && !pSteps && !pTrail )
goto done;
if( (g_Contents[c].req&NEED_PROFILE) && !pProfile )
{
2005-10-30 20:58:08 +00:00
str = NOT_AVAILABLE;
goto done;
}
2004-05-24 06:07:59 +00:00
2003-11-17 06:08:30 +00:00
{
RadarValues rv;
2007-06-09 16:59:19 +00:00
HighScoreList *pHSL = NULL;
ProfileSlot slot = ProfileSlot_Machine;
switch( c )
{
2008-02-15 09:57:24 +00:00
case PaneCategory_ProfileHighScore:
2007-06-09 16:59:19 +00:00
slot = (ProfileSlot) m_PlayerNumber;
}
2003-11-17 06:08:30 +00:00
2007-06-09 16:59:19 +00:00
if( pSteps )
{
rv = pSteps->GetRadarValues( m_PlayerNumber );
2007-06-09 16:59:19 +00:00
pHSL = &PROFILEMAN->GetProfile(slot)->GetStepsHighScoreList(pSong, pSteps);
}
else if( pTrail )
{
rv = pTrail->GetRadarValues();
2007-06-09 16:59:19 +00:00
pHSL = &PROFILEMAN->GetProfile(slot)->GetCourseHighScoreList(pCourse, pTrail);
}
2003-11-17 06:08:30 +00:00
switch( c )
2003-11-17 06:08:31 +00:00
{
2008-02-15 09:57:24 +00:00
case PaneCategory_NumSteps: val = rv[RadarCategory_TapsAndHolds]; break;
case PaneCategory_Jumps: val = rv[RadarCategory_Jumps]; break;
case PaneCategory_Holds: val = rv[RadarCategory_Holds]; break;
case PaneCategory_Rolls: val = rv[RadarCategory_Rolls]; break;
case PaneCategory_Mines: val = rv[RadarCategory_Mines]; break;
case PaneCategory_Hands: val = rv[RadarCategory_Hands]; break;
case PaneCategory_ProfileHighScore:
case PaneCategory_MachineHighName: /* set val for color */
case PaneCategory_MachineHighScore:
CHECKPOINT;
2007-06-09 16:59:19 +00:00
val = pHSL->GetTopScore().GetPercentDP();
break;
};
if( val == RADAR_VAL_UNKNOWN )
goto done;
switch( c )
2003-11-17 06:08:31 +00:00
{
2008-02-15 09:57:24 +00:00
case PaneCategory_MachineHighName:
2007-06-09 16:59:19 +00:00
if( pHSL->vHighScores.empty() )
2005-04-29 21:06:13 +00:00
{
2005-06-12 00:44:59 +00:00
str = EMPTY_MACHINE_HIGH_SCORE_NAME;
2005-04-29 21:06:13 +00:00
}
else
{
2007-06-09 16:59:19 +00:00
str = pHSL->GetTopScore().GetName();
2005-04-29 21:06:13 +00:00
if( str.empty() )
str = "????";
}
break;
2008-02-15 09:57:24 +00:00
case PaneCategory_MachineHighScore:
case PaneCategory_ProfileHighScore:
// Don't show or save machine high scores for edits loaded from a player profile.
if( bIsPlayerEdit )
2005-10-30 20:58:08 +00:00
str = NOT_AVAILABLE;
else
str = PlayerStageStats::FormatPercentScore( val );
break;
2008-02-15 09:57:24 +00:00
case PaneCategory_NumSteps:
case PaneCategory_Jumps:
case PaneCategory_Holds:
case PaneCategory_Rolls:
case PaneCategory_Mines:
case PaneCategory_Hands:
str = ssprintf( COUNT_FORMAT.GetValue(), val );
2003-11-17 06:08:31 +00:00
}
2003-11-17 06:08:30 +00:00
}
done:
2003-11-17 06:08:30 +00:00
m_textContents[c].SetText( str );
2005-09-09 08:11:31 +00:00
Lua *L = LUA->Get();
2003-12-10 22:11:07 +00:00
2005-09-09 08:11:31 +00:00
m_textContents[c].PushSelf( L );
lua_pushstring( L, "PaneLevel" );
lua_pushnumber( L, val );
lua_settable( L, -3 );
lua_pop( L, 1 );
m_textContents[c].PlayCommand( "Level" );
LUA->Release(L);
2003-11-17 06:08:30 +00:00
}
2006-08-10 20:43:49 +00:00
void PaneDisplay::SetFromGameState()
2003-11-17 06:08:30 +00:00
{
/* Don't update text that doesn't apply to the current mode. It's still tweening off. */
2008-02-15 09:57:24 +00:00
FOREACH_ENUM( PaneCategory, i )
2007-06-09 16:59:19 +00:00
SetContent( i );
2003-11-17 06:08:30 +00:00
}
2005-07-29 22:59:11 +00:00
// lua start
#include "LuaBinding.h"
class LunaPaneDisplay: public Luna<PaneDisplay>
{
public:
2008-02-15 09:57:24 +00:00
static int SetFromGameState( T* pc, lua_State *L ) { pc->SetFromGameState(); return 0; }
2005-07-29 22:59:11 +00:00
2006-09-27 20:10:14 +00:00
LunaPaneDisplay()
2005-07-29 22:59:11 +00:00
{
2006-09-27 20:10:14 +00:00
ADD_METHOD( SetFromGameState );
2005-07-29 22:59:11 +00:00
}
};
LUA_REGISTER_DERIVED_CLASS( PaneDisplay, ActorFrame )
// lua end
2004-06-07 21:14:03 +00:00
/*
* (c) 2003 Glenn Maynard
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/