Files
itgmania212121/stepmania/src/PaneDisplay.cpp
T

359 lines
10 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"
#include "PercentageDisplay.h"
2005-09-09 08:11:31 +00:00
#include "LuaManager.h"
2005-12-05 19:09:22 +00:00
#include "XmlFile.h"
2003-11-17 06:08:30 +00:00
2006-03-21 03:55:10 +00:00
#define SHIFT_X(p) THEME->GetMetricF(sMetricsGroup, ssprintf("ShiftP%iX", p+1))
#define SHIFT_Y(p) THEME->GetMetricF(sMetricsGroup, ssprintf("ShiftP%iY", p+1))
2003-11-17 06:08:30 +00:00
enum { NEED_NOTES=1, NEED_COURSE=2, NEED_PROFILE=4 };
struct Content_t
{
const char *name;
PaneTypes type;
int req;
};
static const Content_t g_Contents[NUM_PANE_CONTENTS] =
{
2006-03-21 03:55:10 +00:00
{ "SongNumSteps", PANE_SONG_DIFFICULTY, NEED_NOTES },
{ "SongJumps", PANE_SONG_DIFFICULTY, NEED_NOTES },
{ "SongHolds", PANE_SONG_DIFFICULTY, NEED_NOTES },
{ "SongRolls", PANE_SONG_DIFFICULTY, NEED_NOTES },
{ "SongMines", PANE_SONG_DIFFICULTY, NEED_NOTES },
{ "SongHands", PANE_SONG_DIFFICULTY, NEED_NOTES },
2003-11-26 05:20:59 +00:00
{ "MachineHighScore", PANE_SONG_DIFFICULTY, NEED_NOTES },
{ "MachineHighName", PANE_SONG_DIFFICULTY, NEED_NOTES },
{ "ProfileHighScore", PANE_SONG_DIFFICULTY, NEED_NOTES|NEED_PROFILE },
2003-11-17 06:08:30 +00:00
{ "CourseMachineHighScore", PANE_COURSE_MACHINE_SCORES, NEED_COURSE },
2003-12-10 22:11:07 +00:00
{ "CourseMachineHighName", PANE_COURSE_MACHINE_SCORES, NEED_COURSE },
{ "CourseProfileHighScore", PANE_COURSE_MACHINE_SCORES, NEED_COURSE|NEED_PROFILE },
2006-03-21 03:55:10 +00:00
{ "CourseNumSteps", PANE_COURSE_MACHINE_SCORES, NEED_COURSE },
{ "CourseJumps", PANE_COURSE_MACHINE_SCORES, NEED_COURSE },
{ "CourseHolds", PANE_COURSE_MACHINE_SCORES, NEED_COURSE },
{ "CourseMines", PANE_COURSE_MACHINE_SCORES, NEED_COURSE },
{ "CourseHands", PANE_COURSE_MACHINE_SCORES, NEED_COURSE },
{ "CourseRolls", PANE_COURSE_MACHINE_SCORES, NEED_COURSE }
2003-11-17 06:08:30 +00:00
};
2005-07-29 22:59:11 +00:00
REGISTER_ACTOR_CLASS( PaneDisplay )
2003-11-17 06:08:30 +00:00
PaneDisplay::PaneDisplay()
{
m_CurPane = PANE_INVALID;
}
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
m_sprPaneUnder.Load( THEME->GetPathG(sMetricsGroup,ssprintf("under p%i",pn+1)) );
2003-11-17 06:08:30 +00:00
m_sprPaneUnder->SetName( "Under" );
2007-02-19 09:30:07 +00:00
ActorUtil::LoadAllCommandsAndOnCommand( m_sprPaneUnder, sMetricsGroup );
2003-11-17 06:08:30 +00:00
this->AddChild( m_sprPaneUnder );
2005-12-05 19:09:22 +00:00
EMPTY_MACHINE_HIGH_SCORE_NAME.Load( sMetricsGroup, "EmptyMachineHighScoreName" );
NOT_AVAILABLE.Load( sMetricsGroup, "NotAvailable" );
2005-06-12 00:44:59 +00:00
2005-01-29 23:05:21 +00:00
for( int p = 0; p < NUM_PANE_CONTENTS; ++p )
2003-11-17 06:08:30 +00:00
{
2003-12-10 22:11:07 +00:00
if( g_Contents[p].type == NUM_PANES )
continue; /* skip, disabled */
2005-12-05 19:09:22 +00:00
m_textContents[p].LoadFromFont( THEME->GetPathF(sMetricsGroup,"text") );
2003-11-17 06:08:30 +00:00
m_textContents[p].SetName( ssprintf("%sText", g_Contents[p].name) );
ActorUtil::LoadAllCommands( m_textContents[p], sMetricsGroup );
ActorUtil::SetXY( m_textContents[p], sMetricsGroup );
2006-08-16 06:44:24 +00:00
m_ContentsFrame.AddChild( &m_textContents[p] );
2003-11-17 06:08:30 +00:00
2006-01-22 01:00:06 +00:00
m_Labels[p].Load( THEME->GetPathG(sMetricsGroup,RString(g_Contents[p].name)+" label") );
2003-11-17 06:08:30 +00:00
m_Labels[p]->SetName( ssprintf("%sLabel", g_Contents[p].name) );
ActorUtil::LoadAllCommands( *m_Labels[p], sMetricsGroup );
ActorUtil::SetXY( m_Labels[p], sMetricsGroup );
2006-08-16 06:44:24 +00:00
m_ContentsFrame.AddChild( m_Labels[p] );
2005-09-09 08:11:31 +00:00
2005-12-05 19:09:22 +00:00
ActorUtil::LoadAllCommandsFromName( m_textContents[p], sMetricsGroup, g_Contents[p].name );
2003-11-17 06:08:30 +00:00
}
m_ContentsFrame.SetXY( SHIFT_X(m_PlayerNumber), SHIFT_Y(m_PlayerNumber) );
this->AddChild( &m_ContentsFrame );
for( unsigned i = 0; i < NUM_PANE_CONTENTS; ++i )
{
m_textContents[i].PlayCommand( "LoseFocus" );
m_Labels[i]->PlayCommand( "LoseFocus" );
2003-11-17 06:08:30 +00:00
m_textContents[i].FinishTweening();
m_Labels[i]->FinishTweening();
}
2005-01-29 23:05:21 +00:00
m_CurPane = PANE_INVALID;
2003-11-17 06:08:30 +00:00
}
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
}
2003-11-17 06:08:30 +00:00
void PaneDisplay::SetContent( PaneContents c )
{
2006-01-22 01:00:06 +00:00
RString str = "?"; // fill this in
float val = 0; // fill this in
2003-11-17 06:08:30 +00:00
2004-05-24 06:07:59 +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-05-24 06:07:59 +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-05-24 06:07:59 +00:00
if( (g_Contents[c].req&NEED_NOTES) && !pSteps )
goto done;
if( (g_Contents[c].req&NEED_COURSE) && !pTrail )
goto done;
if( (g_Contents[c].req&NEED_PROFILE) && !pProfile )
{
2005-10-30 20:58:08 +00:00
str = NOT_AVAILABLE;
goto done;
}
2003-11-17 06:08:30 +00:00
{
RadarValues rv;
2003-11-17 06:08:30 +00:00
if( g_Contents[c].req&NEED_NOTES )
rv = pSteps->GetRadarValues( m_PlayerNumber );
else if( g_Contents[c].req&NEED_COURSE )
rv = pTrail->GetRadarValues();
2003-11-17 06:08:30 +00:00
switch( c )
2003-11-17 06:08:31 +00:00
{
case COURSE_NUM_STEPS:
2006-03-21 03:55:10 +00:00
case SONG_NUM_STEPS: val = rv[RadarCategory_TapsAndHolds]; break;
case COURSE_JUMPS:
2006-03-21 03:55:10 +00:00
case SONG_JUMPS: val = rv[RadarCategory_Jumps]; break;
case COURSE_HOLDS:
2006-03-21 03:55:10 +00:00
case SONG_HOLDS: val = rv[RadarCategory_Holds]; break;
2005-04-25 11:24:27 +00:00
case COURSE_ROLLS:
2006-03-21 03:55:10 +00:00
case SONG_ROLLS: val = rv[RadarCategory_Rolls]; break;
case COURSE_MINES:
2006-03-21 03:55:10 +00:00
case SONG_MINES: val = rv[RadarCategory_Mines]; break;
case COURSE_HANDS:
2006-03-21 03:55:10 +00:00
case SONG_HANDS: val = rv[RadarCategory_Hands]; break;
case SONG_PROFILE_HIGH_SCORE:
2005-08-12 02:46:58 +00:00
val = PROFILEMAN->GetProfile(m_PlayerNumber)->GetStepsHighScoreList(pSong,pSteps).GetTopScore().GetPercentDP();
break;
case SONG_MACHINE_HIGH_NAME: /* set val for color */
case SONG_MACHINE_HIGH_SCORE:
CHECKPOINT;
2005-08-12 02:46:58 +00:00
val = PROFILEMAN->GetMachineProfile()->GetStepsHighScoreList(pSong,pSteps).GetTopScore().GetPercentDP();
break;
case COURSE_MACHINE_HIGH_NAME: /* set val for color */
case COURSE_MACHINE_HIGH_SCORE:
2005-08-12 02:46:58 +00:00
val = PROFILEMAN->GetMachineProfile()->GetCourseHighScoreList(pCourse,pTrail).GetTopScore().GetPercentDP();
break;
case COURSE_PROFILE_HIGH_SCORE:
2005-08-12 02:46:58 +00:00
val = PROFILEMAN->GetProfile(m_PlayerNumber)->GetCourseHighScoreList(pCourse,pTrail).GetTopScore().GetPercentDP();
break;
};
if( val == RADAR_VAL_UNKNOWN )
goto done;
switch( c )
2003-11-17 06:08:30 +00:00
{
case SONG_MACHINE_HIGH_NAME:
2005-04-29 21:06:13 +00:00
if( PROFILEMAN->GetMachineProfile()->GetStepsHighScoreList(pSong,pSteps).vHighScores.empty() )
{
2005-06-12 00:44:59 +00:00
str = EMPTY_MACHINE_HIGH_SCORE_NAME;
2005-04-29 21:06:13 +00:00
}
else
{
2005-08-12 01:52:01 +00:00
str = PROFILEMAN->GetMachineProfile()->GetStepsHighScoreList(pSong,pSteps).GetTopScore().GetName();
2005-04-29 21:06:13 +00:00
if( str.empty() )
str = "????";
}
break;
case COURSE_MACHINE_HIGH_NAME:
2005-04-29 21:06:13 +00:00
if( PROFILEMAN->GetMachineProfile()->GetCourseHighScoreList(pCourse,pTrail).vHighScores.empty() )
{
2005-06-12 00:44:59 +00:00
str = EMPTY_MACHINE_HIGH_SCORE_NAME;
2005-04-29 21:06:13 +00:00
}
else
{
2005-08-12 01:52:01 +00:00
str = PROFILEMAN->GetMachineProfile()->GetCourseHighScoreList(pCourse,pTrail).GetTopScore().GetName();
2005-04-29 21:06:13 +00:00
if( str.empty() )
str = "????";
}
break;
case SONG_MACHINE_HIGH_SCORE:
// 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 = PercentageDisplay::FormatPercentScore( val );
break;
case COURSE_MACHINE_HIGH_SCORE:
case SONG_PROFILE_HIGH_SCORE:
case COURSE_PROFILE_HIGH_SCORE:
str = PercentageDisplay::FormatPercentScore( val );
break;
case SONG_NUM_STEPS:
case SONG_JUMPS:
case SONG_HOLDS:
2005-04-25 11:24:27 +00:00
case SONG_ROLLS:
case SONG_MINES:
case SONG_HANDS:
case COURSE_NUM_STEPS:
case COURSE_JUMPS:
case COURSE_HOLDS:
2005-04-25 11:24:27 +00:00
case COURSE_ROLLS:
case COURSE_MINES:
case COURSE_HANDS:
str = ssprintf( "%.0f", val );
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();
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" );
2003-11-17 06:08:30 +00:00
2005-09-09 08:11:31 +00:00
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
{
2006-08-10 20:43:49 +00:00
m_SortOrder = GAMESTATE->m_SortOrder;
2005-01-29 23:05:21 +00:00
SetFocus( GetPane() );
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. */
for( unsigned i = 0; i < NUM_PANE_CONTENTS; ++i )
{
if( g_Contents[i].type != m_CurPane )
continue;
SetContent( (PaneContents) i );
}
}
2005-01-29 23:05:21 +00:00
PaneTypes PaneDisplay::GetPane() const
2003-11-17 06:08:30 +00:00
{
switch( m_SortOrder )
2003-11-17 06:08:30 +00:00
{
case SORT_ALL_COURSES:
case SORT_NONSTOP_COURSES:
case SORT_ONI_COURSES:
case SORT_ENDLESS_COURSES:
2005-01-29 23:05:21 +00:00
return PANE_COURSE_MACHINE_SCORES;
case SORT_MODE_MENU:
2005-01-29 23:05:21 +00:00
return m_CurPane; // leave it
2003-11-17 06:08:30 +00:00
default:
2005-01-29 23:05:21 +00:00
return PANE_SONG_DIFFICULTY;
2003-11-17 06:08:30 +00:00
}
}
void PaneDisplay::SetFocus( PaneTypes NewPane )
{
if( m_CurPane == NewPane )
return;
for( unsigned i = 0; i < NUM_PANE_CONTENTS; ++i )
{
if( g_Contents[i].type == m_CurPane )
{
m_textContents[i].PlayCommand( "LoseFocus" );
m_Labels[i]->PlayCommand( "LoseFocus" );
2003-11-17 06:08:30 +00:00
}
else if( g_Contents[i].type == NewPane )
{
m_textContents[i].PlayCommand( "GainFocus" );
m_Labels[i]->PlayCommand( "GainFocus" );
2003-11-17 06:08:30 +00:00
}
}
m_CurPane = NewPane;
}
2005-07-29 22:59:11 +00:00
// lua start
#include "LuaBinding.h"
class LunaPaneDisplay: public Luna<PaneDisplay>
{
public:
2006-08-10 20:43:49 +00:00
static int SetFromGameState( T* p, lua_State *L ) { p->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.
*/