Files
itgmania212121/src/ScreenOptionsEditCourse.cpp
T

520 lines
13 KiB
C++
Raw Normal View History

2006-09-22 11:36:12 +00:00
#include "global.h"
#include "ScreenOptionsEditCourse.h"
2006-09-22 11:36:12 +00:00
#include "ScreenMiniMenu.h"
#include "SongUtil.h"
#include "SongManager.h"
#include "OptionRowHandler.h"
#include "Song.h"
2006-09-22 11:36:12 +00:00
#include "GameState.h"
#include "ScreenPrompt.h"
#include "LocalizedString.h"
#include "CourseUtil.h"
2009-08-09 23:02:39 +00:00
#include "Song.h"
2009-03-22 08:42:27 +00:00
#include "Style.h"
#include "Steps.h"
2006-09-22 11:36:12 +00:00
2009-03-22 08:42:27 +00:00
static void GetStepsForSong( Song *pSong, vector<Steps*> &vpStepsOut )
{
SongUtil::GetSteps( pSong, vpStepsOut, GAMESTATE->GetCurrentStyle()->m_StepsType );
StepsUtil::RemoveLockedSteps( pSong, vpStepsOut );
StepsUtil::SortNotesArrayByDifficulty( vpStepsOut );
}
// XXX: very similar to OptionRowHandlerSteps
class OptionRowHandlerSteps : public OptionRowHandler
{
public:
void Load( int iEntryIndex )
{
m_iEntryIndex = iEntryIndex;
}
virtual ReloadChanged Reload()
{
m_Def.m_vsChoices.clear();
m_vpSteps.clear();
Song *pSong = GAMESTATE->m_pCurSong;
if( pSong ) // playing a song
{
GetStepsForSong( pSong, m_vpSteps );
FOREACH_CONST( Steps*, m_vpSteps, steps )
{
RString s;
if( (*steps)->GetDifficulty() == Difficulty_Edit )
s = (*steps)->GetDescription();
else
s = CustomDifficultyToLocalizedString( StepsToCustomDifficulty(*steps) );
2009-03-22 08:42:27 +00:00
s += ssprintf( " %d", (*steps)->GetMeter() );
m_Def.m_vsChoices.push_back( s );
}
m_Def.m_vEnabledForPlayers.clear();
m_Def.m_vEnabledForPlayers.insert( PLAYER_1 );
}
else
{
m_Def.m_vsChoices.push_back( "n/a" );
m_vpSteps.push_back( NULL );
m_Def.m_vEnabledForPlayers.clear();
}
return RELOAD_CHANGED_ALL;
}
virtual void ImportOption( OptionRow *pRow, const vector<PlayerNumber> &vpns, vector<bool> vbSelectedOut[NUM_PLAYERS] ) const
{
Trail *pTrail = GAMESTATE->m_pCurTrail[PLAYER_1];
Steps *pSteps;
if( pTrail )
{
if( m_iEntryIndex < (int)pTrail->m_vEntries.size() )
pSteps = pTrail->m_vEntries[ m_iEntryIndex ].pSteps;
}
2009-03-22 08:42:27 +00:00
vector<Steps*>::const_iterator iter = find( m_vpSteps.begin(), m_vpSteps.end(), pSteps );
if( iter == m_vpSteps.end() )
{
pRow->SetOneSharedSelection( 0 );
}
else
{
int index = iter - m_vpSteps.begin();
pRow->SetOneSharedSelection( index );
}
}
virtual int ExportOption( const vector<PlayerNumber> &vpns, const vector<bool> vbSelected[NUM_PLAYERS] ) const
{
return 0;
}
Steps *GetSteps( int iStepsIndex ) const
{
return m_vpSteps[iStepsIndex];
}
protected:
int m_iEntryIndex;
vector<Steps*> m_vpSteps;
};
const int NUM_SONG_ROWS = 20;
2006-09-22 11:36:12 +00:00
REGISTER_SCREEN_CLASS( ScreenOptionsEditCourse );
2006-09-22 11:36:12 +00:00
enum EditCourseRow
2009-03-22 08:42:27 +00:00
{
EditCourseRow_Minutes,
NUM_EditCourseRow
2009-03-22 08:42:27 +00:00
};
enum RowType
{
RowType_Song,
RowType_Steps,
NUM_RowType,
RowType_Invalid,
};
static int RowToEntryIndex( int iRow )
{
if( iRow < NUM_EditCourseRow )
2009-03-22 08:42:27 +00:00
return -1;
return (iRow-NUM_EditCourseRow)/NUM_RowType;
2009-03-22 08:42:27 +00:00
}
static RowType RowToRowType( int iRow )
{
if( iRow < NUM_EditCourseRow )
2009-03-22 08:42:27 +00:00
return RowType_Invalid;
return (RowType)((iRow-NUM_EditCourseRow) % NUM_RowType);
2009-03-22 08:42:27 +00:00
}
static int EntryIndexAndRowTypeToRow( int iEntryIndex, RowType rowType )
{
return NUM_EditCourseRow + iEntryIndex*NUM_RowType + rowType;
2009-03-22 08:42:27 +00:00
}
void ScreenOptionsEditCourse::Init()
2006-09-22 11:36:12 +00:00
{
ScreenOptions::Init();
SongCriteria sc;
sc.m_Selectable = SongCriteria::Selectable_Yes;
sc.m_Tutorial = SongCriteria::Tutorial_No;
sc.m_Locked = SongCriteria::Locked_Unlocked;
SongUtil::FilterSongs( sc, SONGMAN->GetAllSongs(), m_vpSongs );
2009-03-22 08:42:27 +00:00
SongUtil::SortSongPointerArrayByTitle( m_vpSongs );
}
const MenuRowDef g_MenuRows[] =
{
MenuRowDef( -1, "Max Minutes", true, EditMode_Practice, true, false, 0, NULL ),
2009-03-22 08:42:27 +00:00
};
static LocalizedString EMPTY ("ScreenOptionsEditCourse","-Empty-");
static LocalizedString SONG ("ScreenOptionsEditCourse","Song");
static LocalizedString STEPS ("ScreenOptionsEditCourse","Steps");
static LocalizedString MINUTES ("ScreenOptionsEditCourse","minutes");
2009-03-22 08:42:27 +00:00
static RString MakeMinutesString( int mins )
{
if( mins == 0 )
return "No Cut-off";
return ssprintf( "%d", mins ) + " " + MINUTES.GetValue();
2006-09-22 11:36:12 +00:00
}
void ScreenOptionsEditCourse::BeginScreen()
2006-09-22 11:36:12 +00:00
{
vector<OptionRowHandler*> vHands;
FOREACH_ENUM( EditCourseRow, rowIndex )
2006-09-22 11:36:12 +00:00
{
2009-03-22 08:42:27 +00:00
const MenuRowDef &mr = g_MenuRows[rowIndex];
OptionRowHandler *pHand = OptionRowHandlerUtil::MakeSimple( mr );
pHand->m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
pHand->m_Def.m_vsChoices.clear();
switch( rowIndex )
{
DEFAULT_FAIL(rowIndex);
case EditCourseRow_Minutes:
2009-03-22 08:42:27 +00:00
pHand->m_Def.m_vsChoices.push_back( MakeMinutesString(0) );
for( int i=EditCourseUtil::MIN_WORKOUT_MINUTES; i<=20; i+=2 )
2009-03-22 08:42:27 +00:00
pHand->m_Def.m_vsChoices.push_back( MakeMinutesString(i) );
for( int i=20; i<=EditCourseUtil::MAX_WORKOUT_MINUTES; i+=5 )
2009-03-22 08:42:27 +00:00
pHand->m_Def.m_vsChoices.push_back( MakeMinutesString(i) );
break;
}
2006-09-22 11:36:12 +00:00
pHand->m_Def.m_bExportOnChange = true;
2009-03-22 08:42:27 +00:00
vHands.push_back( pHand );
}
for( int i=0; i<NUM_SONG_ROWS; i++ )
{
{
MenuRowDef mrd = MenuRowDef( -1, "---", true, EditMode_Practice, true, false, 0, EMPTY.GetValue() );
FOREACH_CONST( Song*, m_vpSongs, s )
mrd.choices.push_back( (*s)->GetDisplayFullTitle() );
mrd.sName = ssprintf(SONG.GetValue() + " %d",i+1);
OptionRowHandler *pHand = OptionRowHandlerUtil::MakeSimple( mrd );
pHand->m_Def.m_bAllowThemeTitle = false; // already themed
pHand->m_Def.m_sExplanationName = "Choose Song";
pHand->m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
pHand->m_Def.m_bExportOnChange = true;
vHands.push_back( pHand );
}
{
OptionRowHandlerSteps *pHand = new OptionRowHandlerSteps;
pHand->Load( i );
pHand->m_Def.m_vsChoices.push_back( "n/a" );
pHand->m_Def.m_sName = ssprintf(STEPS.GetValue() + " %d",i+1);
pHand->m_Def.m_bAllowThemeTitle = false; // already themed
pHand->m_Def.m_bAllowThemeItems = false; // already themed
pHand->m_Def.m_sExplanationName = "Choose Steps";
pHand->m_Def.m_bOneChoiceForAllPlayers = true;
pHand->m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
pHand->m_Def.m_bExportOnChange = true;
vHands.push_back( pHand );
}
2006-09-22 11:36:12 +00:00
}
ScreenOptions::InitMenu( vHands );
ScreenOptions::BeginScreen();
2009-03-22 08:42:27 +00:00
for( int i=0; i<(int)m_pRows.size(); i++ )
{
OptionRow *pRow = m_pRows[i];
m_iCurrentRow[PLAYER_1] = i;
this->SetCurrentSong();
pRow->Reload();
}
m_iCurrentRow[PLAYER_1] = 0;
this->SetCurrentSong();
//this->AfterChangeRow( PLAYER_1 );
2006-09-22 11:36:12 +00:00
}
ScreenOptionsEditCourse::~ScreenOptionsEditCourse()
2006-09-22 11:36:12 +00:00
{
}
void ScreenOptionsEditCourse::ImportOptions( int iRow, const vector<PlayerNumber> &vpns )
2006-09-22 11:36:12 +00:00
{
OptionRow &row = *m_pRows[iRow];
if( row.GetRowType() == OptionRow::RowType_Exit )
return;
2009-03-22 08:42:27 +00:00
switch( iRow )
2006-09-22 11:36:12 +00:00
{
case EditCourseRow_Minutes:
2009-03-22 08:42:27 +00:00
row.SetOneSharedSelection( 0 );
row.SetOneSharedSelectionIfPresent( MakeMinutesString(GAMESTATE->m_pCurCourse->m_fGoalSeconds/60) );
break;
default:
2006-09-22 11:36:12 +00:00
{
2009-03-22 08:42:27 +00:00
int iEntryIndex = RowToEntryIndex( iRow );
RowType rowType = RowToRowType( iRow );
switch( rowType )
{
DEFAULT_FAIL( rowType );
case RowType_Song:
{
Song *pSong = NULL;
if( iEntryIndex < (int)GAMESTATE->m_pCurCourse->m_vEntries.size() )
pSong = GAMESTATE->m_pCurCourse->m_vEntries[iEntryIndex].songID.ToSong();
vector<Song*>::iterator iter = find( m_vpSongs.begin(), m_vpSongs.end(), pSong );
if( iter == m_vpSongs.end() )
row.SetOneSharedSelection( 0 );
else
row.SetOneSharedSelection( 1 + iter - m_vpSongs.begin() );
}
break;
case RowType_Steps:
// the OptionRowHandler does its own importing
break;
}
2006-09-22 11:36:12 +00:00
}
2009-03-22 08:42:27 +00:00
break;
2006-09-22 11:36:12 +00:00
}
}
void ScreenOptionsEditCourse::ExportOptions( int iRow, const vector<PlayerNumber> &vpns )
2006-09-22 11:36:12 +00:00
{
FOREACH_ENUM( EditCourseRow, i )
2006-09-22 11:36:12 +00:00
{
2009-03-22 08:42:27 +00:00
OptionRow &row = *m_pRows[i];
int iIndex = row.GetOneSharedSelection( true );
RString sValue;
if( iIndex >= 0 )
sValue = row.GetRowDef().m_vsChoices[ iIndex ];
switch( i )
{
DEFAULT_FAIL(i);
case EditCourseRow_Minutes:
2009-03-22 08:42:27 +00:00
GAMESTATE->m_pCurCourse->m_fGoalSeconds = 0;
int mins;
if( sscanf( sValue, "%d", &mins ) == 1 )
GAMESTATE->m_pCurCourse->m_fGoalSeconds = mins * 60;
break;
}
2006-09-22 11:36:12 +00:00
}
2009-03-22 08:42:27 +00:00
GAMESTATE->m_pCurCourse->m_vEntries.clear();
for( int i=NUM_EditCourseRow; i<(int)m_pRows.size(); i++ )
2006-09-22 11:36:12 +00:00
{
2009-03-22 08:42:27 +00:00
OptionRow &row = *m_pRows[i];
if( row.GetRowType() == OptionRow::RowType_Exit )
continue;
RowType rowType = RowToRowType( i );
int iEntryIndex = RowToEntryIndex( i );
switch( rowType )
{
case RowType_Song:
{
Song *pSong = this->GetSongForEntry( iEntryIndex );
if( pSong )
{
Steps *pSteps = this->GetStepsForEntry( iEntryIndex );
ASSERT( pSteps );
CourseEntry ce;
ce.songID.FromSong( pSong );
ce.stepsCriteria.m_difficulty = pSteps->GetDifficulty();
GAMESTATE->m_pCurCourse->m_vEntries.push_back( ce );
}
}
break;
case RowType_Steps:
// push each CourseEntry when we handle each RowType_Song above
break;
default:
break;
}
2006-09-22 11:36:12 +00:00
}
2009-03-22 08:42:27 +00:00
EditCourseUtil::UpdateAndSetTrail();
2006-09-22 11:36:12 +00:00
}
void ScreenOptionsEditCourse::GoToNextScreen()
2006-09-22 11:36:12 +00:00
{
}
void ScreenOptionsEditCourse::GoToPrevScreen()
2006-09-22 11:36:12 +00:00
{
}
void ScreenOptionsEditCourse::HandleScreenMessage( const ScreenMessage SM )
2006-09-22 11:36:12 +00:00
{
if( SM == SM_ExportOptions )
{
//g_Workout.m_vpSongs.clear();
}
ScreenOptions::HandleScreenMessage( SM );
}
void ScreenOptionsEditCourse::SetCurrentSong()
2006-09-22 11:36:12 +00:00
{
2009-03-22 08:42:27 +00:00
int iRow = m_iCurrentRow[PLAYER_1];
2006-09-22 11:36:12 +00:00
OptionRow &row = *m_pRows[iRow];
2009-03-22 08:42:27 +00:00
2006-09-22 11:36:12 +00:00
if( row.GetRowType() == OptionRow::RowType_Exit )
2009-03-22 08:42:27 +00:00
{
GAMESTATE->m_pCurSong.Set( NULL );
GAMESTATE->m_pCurSteps[PLAYER_1].Set( NULL );
}
else
{
int iRow = m_iCurrentRow[PLAYER_1];
int iEntryIndex = RowToEntryIndex( iRow );
Song *pSong = NULL;
if( iEntryIndex != -1 )
{
int iCurrentSongRow = EntryIndexAndRowTypeToRow(iEntryIndex,RowType_Song);
OptionRow &row = *m_pRows[ iCurrentSongRow ];
int index = row.GetOneSelection(PLAYER_1);
if( index != 0 )
pSong = m_vpSongs[ index - 1 ];
}
GAMESTATE->m_pCurSong.Set( pSong );
}
}
void ScreenOptionsEditCourse::SetCurrentSteps()
2009-03-22 08:42:27 +00:00
{
Song *pSong = GAMESTATE->m_pCurSong;
if( pSong )
{
int iRow = m_iCurrentRow[PLAYER_1];
int iEntryIndex = RowToEntryIndex( iRow );
OptionRow &row = *m_pRows[ EntryIndexAndRowTypeToRow(iEntryIndex, RowType_Steps) ];
int iStepsIndex = row.GetOneSharedSelection();
const OptionRowHandlerSteps *pHand = dynamic_cast<const OptionRowHandlerSteps *>( row.GetHandler() );
ASSERT( pHand );
Steps *pSteps = pHand->GetSteps( iStepsIndex );
GAMESTATE->m_pCurSteps[PLAYER_1].Set( pSteps );
}
2006-09-22 11:36:12 +00:00
else
2009-03-22 08:42:27 +00:00
{
GAMESTATE->m_pCurSteps[PLAYER_1].Set( NULL );
}
}
Song *ScreenOptionsEditCourse::GetSongForEntry( int iEntryIndex )
2009-03-22 08:42:27 +00:00
{
int iRow = EntryIndexAndRowTypeToRow( iEntryIndex, RowType_Song );
OptionRow &row = *m_pRows[iRow];
int index = row.GetOneSharedSelection();
if( index == 0 )
return NULL;
return m_vpSongs[ index - 1 ];
}
Steps *ScreenOptionsEditCourse::GetStepsForEntry( int iEntryIndex )
2009-03-22 08:42:27 +00:00
{
int iRow = EntryIndexAndRowTypeToRow( iEntryIndex, RowType_Steps );
OptionRow &row = *m_pRows[iRow];
int index = row.GetOneSharedSelection();
Song *pSong = GetSongForEntry( iEntryIndex );
vector<Steps*> vpSteps;
GetStepsForSong( pSong, vpSteps );
return vpSteps[index];
}
void ScreenOptionsEditCourse::AfterChangeRow( PlayerNumber pn )
2009-03-22 08:42:27 +00:00
{
ScreenOptions::AfterChangeRow( pn );
2006-09-22 11:36:12 +00:00
2009-03-22 08:42:27 +00:00
SetCurrentSong();
2009-08-10 16:32:46 +00:00
SetCurrentSteps();
2006-09-22 11:36:12 +00:00
}
void ScreenOptionsEditCourse::AfterChangeValueInRow( int iRow, PlayerNumber pn )
2006-09-22 11:36:12 +00:00
{
ScreenOptions::AfterChangeValueInRow( iRow, pn );
2009-03-22 08:42:27 +00:00
int iEntryIndex = RowToEntryIndex( iRow );
RowType rowType = RowToRowType( iRow );
switch( rowType )
{
case RowType_Song:
{
SetCurrentSong();
OptionRow &row = *m_pRows[ EntryIndexAndRowTypeToRow(iEntryIndex, RowType_Steps) ];
row.Reload();
}
break;
case RowType_Steps:
SetCurrentSteps();
break;
default:
break;
}
2006-09-22 11:36:12 +00:00
}
2009-03-22 08:42:27 +00:00
const int MIN_ENABLED_SONGS = 2;
2006-09-22 11:36:12 +00:00
static LocalizedString MUST_ENABLE_AT_LEAST("ScreenOptionsEditCourse","You must enable at least %d songs.");
void ScreenOptionsEditCourse::ProcessMenuStart( const InputEventPlus &input )
2006-09-22 11:36:12 +00:00
{
if( IsTransitioning() )
return;
int iRow = m_iCurrentRow[GAMESTATE->m_MasterPlayerNumber];
2009-03-22 14:30:04 +00:00
unsigned iSongCount = GAMESTATE->m_pCurCourse->m_vEntries.size();
2006-09-22 11:36:12 +00:00
2009-03-22 08:42:27 +00:00
if( m_pRows[iRow]->GetRowType() == OptionRow::RowType_Exit && iSongCount < unsigned(MIN_ENABLED_SONGS) )
2006-09-22 11:36:12 +00:00
{
ScreenPrompt::Prompt( SM_None, ssprintf(MUST_ENABLE_AT_LEAST.GetValue(),MIN_ENABLED_SONGS) );
return;
}
ScreenOptions::ProcessMenuStart( input );
}
/*
* (c) 2003-2004 Chris Danford
* 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.
*/