Files
itgmania212121/stepmania/src/ScreenOptionsEditCourseEntry.cpp
T

453 lines
13 KiB
C++
Raw Normal View History

2005-06-26 21:31:07 +00:00
#include "global.h"
2005-07-29 02:23:02 +00:00
#include "ScreenOptionsEditCourseEntry.h"
2005-07-20 09:48:19 +00:00
#include "ScreenManager.h"
2005-06-26 21:31:07 +00:00
#include "RageLog.h"
#include "GameState.h"
#include "SongManager.h"
#include "CommonMetrics.h"
#include "GameManager.h"
#include "song.h"
2005-07-30 19:34:23 +00:00
#include "Steps.h"
2006-01-17 21:23:26 +00:00
#include "OptionRowHandler.h"
2005-06-26 21:31:07 +00:00
2005-06-26 23:31:36 +00:00
enum EditCourseEntryRow
2005-06-26 21:31:07 +00:00
{
ROW_SONG_GROUP,
ROW_SONG,
2005-06-26 23:31:36 +00:00
ROW_BASE_DIFFICULTY,
2005-06-26 21:31:07 +00:00
ROW_LOW_METER,
ROW_HIGH_METER,
2005-06-28 08:11:30 +00:00
ROW_SORT,
ROW_CHOOSE_INDEX,
2005-06-26 21:31:07 +00:00
ROW_SET_MODS,
ROW_DONE,
2005-06-26 23:31:36 +00:00
NUM_EditCourseEntryRow
};
#define FOREACH_EditCourseEntryRow( i ) FOREACH_ENUM( EditCourseEntryRow, NUM_EditCourseEntryRow, i )
2005-07-30 19:34:23 +00:00
static void FillSongsAndChoices( const CString &sSongGroup, vector<Song*> &vpSongsOut, vector<CString> &vsChoicesOut )
{
vpSongsOut.clear();
vsChoicesOut.clear();
if( sSongGroup.empty() )
SONGMAN->GetSongs( vpSongsOut );
else
SONGMAN->GetSongs( vpSongsOut, sSongGroup );
vpSongsOut.insert( vpSongsOut.begin(), NULL );
FOREACH_CONST( Song*, vpSongsOut, s )
{
if( *s == NULL )
vsChoicesOut.push_back( "(any)" );
else
vsChoicesOut.push_back( (*s)->GetTranslitFullTitle() );
}
}
2005-06-28 08:11:30 +00:00
2006-01-15 20:46:15 +00:00
REGISTER_SCREEN_CLASS( ScreenOptionsEditCourseEntry );
2005-06-26 21:31:07 +00:00
2005-07-29 02:23:02 +00:00
void ScreenOptionsEditCourseEntry::Init()
2005-06-26 21:31:07 +00:00
{
ScreenOptions::Init();
2005-08-15 02:32:36 +00:00
}
2005-06-26 21:31:07 +00:00
2005-08-15 02:32:36 +00:00
void ScreenOptionsEditCourseEntry::BeginScreen()
{
2005-06-28 08:11:30 +00:00
// save a backup that we'll use if we revert.
Course *pCourse = GAMESTATE->m_pCurCourse;
2005-07-30 19:34:23 +00:00
const CourseEntry &ce = pCourse->m_vEntries[ GAMESTATE->m_iEditCourseEntryIndex ];
m_Original = ce;
2005-06-28 08:11:30 +00:00
2005-06-26 21:31:07 +00:00
vector<OptionRowDefinition> vDefs;
vector<OptionRowHandler*> vHands;
2006-01-17 21:23:26 +00:00
OptionRowHandler *pHand = OptionRowHandlerUtil::MakeNull();
vHands.push_back( OptionRowHandlerUtil::MakeNull() );
pHand->m_Def.m_sName = "Song Group";
pHand->m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
pHand->m_Def.m_bExportOnChange = true;
pHand->m_Def.m_vsChoices.clear();
2005-06-26 21:31:07 +00:00
vector<CString> vsSongGroups;
SONGMAN->GetSongGroupNames( vsSongGroups );
2006-01-17 21:23:26 +00:00
pHand->m_Def.m_vsChoices.push_back( "(any)" );
FOREACH_CONST( CString, vsSongGroups, song )
2006-01-17 21:23:26 +00:00
pHand->m_Def.m_vsChoices.push_back( *song );
vDefs.push_back( pHand->m_Def );
vHands.push_back( pHand );
pHand = OptionRowHandlerUtil::MakeNull();
pHand->m_Def.m_sName = "Song";
pHand->m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
pHand->m_Def.m_bExportOnChange = true;
pHand->m_Def.m_vsChoices.clear();
FillSongsAndChoices( ce.sSongGroup, m_vpDisplayedSongs, pHand->m_Def.m_vsChoices );
vDefs.push_back( pHand->m_Def );
vHands.push_back( pHand );
pHand = OptionRowHandlerUtil::MakeNull();
pHand->m_Def.m_sName = "Base Difficulty";
pHand->m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
pHand->m_Def.m_bExportOnChange = true;
pHand->m_Def.m_vsChoices.clear();
pHand->m_Def.m_vsChoices.push_back( "(any)" );
FOREACH_CONST( Difficulty, CommonMetrics::DIFFICULTIES_TO_SHOW.GetValue(), dc )
2006-01-17 21:23:26 +00:00
pHand->m_Def.m_vsChoices.push_back( DifficultyToLocalizedString(*dc) );
vDefs.push_back( pHand->m_Def );
vHands.push_back( pHand );
pHand = OptionRowHandlerUtil::MakeNull();
pHand->m_Def.m_sName = "Low Meter";
pHand->m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
pHand->m_Def.m_bExportOnChange = true;
pHand->m_Def.m_vsChoices.clear();
pHand->m_Def.m_vsChoices.push_back( "(any)" );
2005-06-26 21:31:07 +00:00
for( int i=MIN_METER; i<=MAX_METER; i++ )
2006-01-17 21:23:26 +00:00
pHand->m_Def.m_vsChoices.push_back( ssprintf("%i",i) );
vDefs.push_back( pHand->m_Def );
vHands.push_back( pHand );
pHand = OptionRowHandlerUtil::MakeNull();
pHand->m_Def.m_sName = "High Meter";
pHand->m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
pHand->m_Def.m_bExportOnChange = true;
pHand->m_Def.m_vsChoices.clear();
pHand->m_Def.m_vsChoices.push_back( "(any)" );
2005-06-26 21:31:07 +00:00
for( int i=MIN_METER; i<=MAX_METER; i++ )
2006-01-17 21:23:26 +00:00
pHand->m_Def.m_vsChoices.push_back( ssprintf("%i",i) );
vDefs.push_back( pHand->m_Def );
vHands.push_back( pHand );
pHand = OptionRowHandlerUtil::MakeNull();
pHand->m_Def.m_sName = "Sort";
pHand->m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
pHand->m_Def.m_bExportOnChange = true;
pHand->m_Def.m_vsChoices.clear();
2005-06-28 08:11:30 +00:00
FOREACH_SongSort( i )
2006-01-17 21:23:26 +00:00
pHand->m_Def.m_vsChoices.push_back( SongSortToLocalizedString(i) );
vDefs.push_back( pHand->m_Def );
vHands.push_back( pHand );
pHand = OptionRowHandlerUtil::MakeNull();
pHand->m_Def.m_sName = "Choose";
pHand->m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
pHand->m_Def.m_bExportOnChange = true;
pHand->m_Def.m_vsChoices.clear();
2005-06-28 08:11:30 +00:00
for( int i=0; i<20; i++ )
2006-01-17 21:23:26 +00:00
pHand->m_Def.m_vsChoices.push_back( FormatNumberAndSuffix(i+1) );
vDefs.push_back( pHand->m_Def );
vHands.push_back( pHand );
pHand = OptionRowHandlerUtil::MakeNull();
pHand->m_Def.m_sName = "Set Mods";
pHand->m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
pHand->m_Def.m_bExportOnChange = true;
pHand->m_Def.m_vsChoices.clear();
2005-07-30 19:34:23 +00:00
CString s = ssprintf( "%d mod changes", ce.GetNumModChanges() );
2006-01-17 21:23:26 +00:00
pHand->m_Def.m_vsChoices.push_back( s );
vDefs.push_back( pHand->m_Def );
vHands.push_back( pHand );
2005-06-26 21:31:07 +00:00
ScreenOptions::InitMenu( vDefs, vHands );
2005-06-26 21:31:07 +00:00
2005-07-30 04:50:17 +00:00
ScreenOptions::BeginScreen();
2005-06-26 21:31:07 +00:00
}
2005-07-29 02:23:02 +00:00
void ScreenOptionsEditCourseEntry::HandleScreenMessage( const ScreenMessage SM )
2005-06-26 21:31:07 +00:00
{
2005-07-30 19:34:23 +00:00
Course *pCourse = GAMESTATE->m_pCurCourse;
if( SM == SM_GoToNextScreen )
{
switch( m_iCurrentRow[GAMESTATE->m_MasterPlayerNumber] )
{
case ROW_SONG_GROUP:
case ROW_SONG:
case ROW_BASE_DIFFICULTY:
case ROW_LOW_METER:
case ROW_HIGH_METER:
case ROW_CHOOSE_INDEX:
break;
case ROW_SET_MODS:
2005-07-30 19:34:23 +00:00
{
2005-08-01 05:12:06 +00:00
Trail *pTrail = GAMESTATE->m_pCurTrail[PLAYER_1];
2005-07-30 19:34:23 +00:00
TrailEntry *pTrailEntry = &pTrail->m_vEntries[GAMESTATE->m_iEditCourseEntryIndex];
Song *pSong = pTrailEntry->pSong;
Steps *pSteps = pTrailEntry->pSteps;
// Set up for ScreenEdit
const Style *pStyle = GAMEMAN->GetEditorStyleForStepsType(pSteps->m_StepsType);
GAMESTATE->m_pCurStyle.Set( pStyle );
GAMESTATE->m_pCurSong.Set( pSong );
GAMESTATE->m_pCurSteps[PLAYER_1].Set( pSteps );
SCREENMAN->SetNewScreen( "ScreenEditCourseMods" );
}
break;
case ROW_DONE:
2005-07-30 04:50:17 +00:00
SCREENMAN->SetNewScreen( "ScreenOptionsEditCourse" );
break;
}
return;
}
else if( SM == SM_GoToPrevScreen )
{
// revert
pCourse->m_vEntries[ GAMESTATE->m_iEditCourseEntryIndex ] = m_Original;
2005-07-30 04:50:17 +00:00
SCREENMAN->SetNewScreen( "ScreenOptionsEditCourse" );
return;
}
2005-06-26 21:31:07 +00:00
ScreenOptions::HandleScreenMessage( SM );
}
2005-07-30 19:34:23 +00:00
void ScreenOptionsEditCourseEntry::AfterChangeValueInRow( int iRow, PlayerNumber pn )
2005-06-26 21:31:07 +00:00
{
2005-07-30 19:34:23 +00:00
ScreenOptions::AfterChangeValueInRow( iRow, pn );
2005-06-26 21:31:07 +00:00
Course *pCourse = GAMESTATE->m_pCurCourse;
2005-08-01 05:12:06 +00:00
GAMESTATE->m_pCurTrail[PLAYER_1].Set( NULL );
Trail *pTrail = pCourse->GetTrailForceRegenCache( GAMESTATE->m_stEdit, GAMESTATE->m_PreferredCourseDifficulty[PLAYER_1] );
2005-07-30 19:34:23 +00:00
int iEntryIndex = GAMESTATE->m_iEditCourseEntryIndex;
2005-08-05 16:18:07 +00:00
ASSERT( iEntryIndex >= 0 && iEntryIndex < (int) pCourse->m_vEntries.size() );
2005-07-30 19:34:23 +00:00
CourseEntry &ce = pCourse->m_vEntries[ iEntryIndex ];
2005-06-26 21:31:07 +00:00
2005-07-30 19:34:23 +00:00
switch( iRow )
2005-06-26 21:31:07 +00:00
{
case ROW_SONG_GROUP:
// refresh songs
{
2005-07-30 19:34:23 +00:00
vector<PlayerNumber> vpns;
vpns.push_back( PLAYER_1 );
ExportOptions( ROW_SONG_GROUP, vpns );
2005-06-26 21:31:07 +00:00
OptionRow &row = *m_pRows[ROW_SONG];
OptionRowDefinition def = row.GetRowDef();
2005-07-30 19:34:23 +00:00
FillSongsAndChoices( ce.sSongGroup, m_vpDisplayedSongs, def.m_vsChoices );
row.Reload( def );
vector<Song*>::const_iterator iter = find( m_vpDisplayedSongs.begin(), m_vpDisplayedSongs.end(), ce.pSong );
if( iter == m_vpDisplayedSongs.end() )
2005-06-26 21:31:07 +00:00
{
2005-07-30 19:34:23 +00:00
this->ChangeValueInRowAbsolute( ROW_SONG, PLAYER_1, 0, false );
2005-06-26 21:31:07 +00:00
}
else
{
2005-07-30 19:34:23 +00:00
int iSongIndex = iter - m_vpDisplayedSongs.begin();
this->ChangeValueInRowAbsolute( ROW_SONG, PLAYER_1, iSongIndex, false );
}
}
break;
}
2005-08-01 05:12:06 +00:00
// cause overlay elements to refresh by changing the course
GAMESTATE->m_pCurCourse.Set( pCourse );
GAMESTATE->m_pCurTrail[PLAYER_1].Set( pTrail );
2005-07-30 19:34:23 +00:00
}
void ScreenOptionsEditCourseEntry::ImportOptions( int iRow, const vector<PlayerNumber> &vpns )
{
Course *pCourse = GAMESTATE->m_pCurCourse;
int iEntryIndex = GAMESTATE->m_iEditCourseEntryIndex;
2005-08-05 16:18:07 +00:00
ASSERT( iEntryIndex >= 0 && iEntryIndex < (int) pCourse->m_vEntries.size() );
2005-07-30 19:34:23 +00:00
CourseEntry &ce = pCourse->m_vEntries[ iEntryIndex ];
OptionRow &row = *m_pRows[iRow];
switch( iRow )
{
case ROW_SONG_GROUP:
FOREACH_CONST( CString, row.GetRowDef().m_vsChoices, s )
{
if( *s == ce.sSongGroup )
{
int iChoice = s - row.GetRowDef().m_vsChoices.begin();
row.SetOneSharedSelection( iChoice );
AfterChangeValueInRow( iRow, GAMESTATE->m_MasterPlayerNumber );
break;
2005-06-26 21:31:07 +00:00
}
}
2005-07-30 19:34:23 +00:00
break;
case ROW_SONG:
{
vector<Song*>::const_iterator iter = find( m_vpDisplayedSongs.begin(), m_vpDisplayedSongs.end(), ce.pSong );
int iChoice = 0;
if( iter != m_vpDisplayedSongs.end() )
iChoice = iter - m_vpDisplayedSongs.begin();
OptionRow &row = *m_pRows[ROW_SONG];
row.SetOneSharedSelection( iChoice );
}
break;
case ROW_BASE_DIFFICULTY:
{
vector<Difficulty>::const_iterator iter = find( CommonMetrics::DIFFICULTIES_TO_SHOW.GetValue().begin(), CommonMetrics::DIFFICULTIES_TO_SHOW.GetValue().end(), ce.baseDifficulty );
2005-07-30 19:34:23 +00:00
int iChoice = 0;
if( iter != CommonMetrics::DIFFICULTIES_TO_SHOW.GetValue().end() )
iChoice = iter - CommonMetrics::DIFFICULTIES_TO_SHOW.GetValue().begin() + 1;
2005-07-30 19:34:23 +00:00
OptionRow &row = *m_pRows[ROW_BASE_DIFFICULTY];
row.SetOneSharedSelection( iChoice );
}
break;
case ROW_LOW_METER:
{
int iChoice = 0;
if( ce.iLowMeter != -1 )
iChoice = ce.iLowMeter;
OptionRow &row = *m_pRows[ROW_LOW_METER];
row.SetOneSharedSelection( iChoice );
}
break;
case ROW_HIGH_METER:
{
int iChoice = 0;
if( ce.iHighMeter != -1 )
iChoice = ce.iHighMeter;
OptionRow &row = *m_pRows[ROW_HIGH_METER];
row.SetOneSharedSelection( iChoice );
}
break;
case ROW_SORT:
{
int iChoice = ce.songSort;
OptionRow &row = *m_pRows[ROW_SORT];
row.SetOneSharedSelection( iChoice );
}
break;
case ROW_CHOOSE_INDEX:
{
int iChoice = ce.iChooseIndex;
OptionRow &row = *m_pRows[ROW_CHOOSE_INDEX];
row.SetOneSharedSelection( iChoice );
}
}
}
void ScreenOptionsEditCourseEntry::ExportOptions( int iRow, const vector<PlayerNumber> &vpns )
{
Course *pCourse = GAMESTATE->m_pCurCourse;
int iEntryIndex = GAMESTATE->m_iEditCourseEntryIndex;
2005-08-05 16:18:07 +00:00
ASSERT( iEntryIndex >= 0 && iEntryIndex < (int) pCourse->m_vEntries.size() );
2005-07-30 19:34:23 +00:00
CourseEntry &ce = pCourse->m_vEntries[ iEntryIndex ];
switch( iRow )
{
case ROW_SONG_GROUP:
{
OptionRow &row = *m_pRows[ROW_SONG_GROUP];
int iChoice = row.GetChoiceInRowWithFocus( GAMESTATE->m_MasterPlayerNumber );
if( iChoice == 0 )
ce.sSongGroup = "";
else
ce.sSongGroup = row.GetRowDef().m_vsChoices[ iChoice ];
}
break;
2005-06-26 21:31:07 +00:00
case ROW_SONG:
{
OptionRow &row = *m_pRows[ROW_SONG];
int iChoice = row.GetChoiceInRowWithFocus( GAMESTATE->m_MasterPlayerNumber );
2005-08-01 05:12:06 +00:00
ce.pSong = m_vpDisplayedSongs[iChoice];
2005-06-26 21:31:07 +00:00
}
2005-07-30 19:34:23 +00:00
break;
2005-06-26 23:31:36 +00:00
case ROW_BASE_DIFFICULTY:
2005-06-26 21:31:07 +00:00
{
2005-06-26 23:31:36 +00:00
OptionRow &row = *m_pRows[ROW_BASE_DIFFICULTY];
2005-06-26 21:31:07 +00:00
int iChoice = row.GetChoiceInRowWithFocus( GAMESTATE->m_MasterPlayerNumber );
2005-08-01 05:12:06 +00:00
if( iChoice == 0 )
{
ce.baseDifficulty = DIFFICULTY_INVALID;
}
else
{
Difficulty d = CommonMetrics::DIFFICULTIES_TO_SHOW.GetValue()[iChoice-1];
2005-08-01 05:12:06 +00:00
ce.baseDifficulty = d;
}
2005-06-26 21:31:07 +00:00
}
2005-07-30 19:34:23 +00:00
break;
2005-06-26 21:31:07 +00:00
case ROW_LOW_METER:
{
2005-06-28 08:11:30 +00:00
OptionRow &row = *m_pRows[ROW_LOW_METER];
int iChoice = row.GetChoiceInRowWithFocus( GAMESTATE->m_MasterPlayerNumber );
if( iChoice == 0 )
ce.iLowMeter = -1;
else
ce.iLowMeter = iChoice;
2005-06-26 21:31:07 +00:00
}
2005-07-30 19:34:23 +00:00
break;
2005-06-26 21:31:07 +00:00
case ROW_HIGH_METER:
{
2005-06-28 08:11:30 +00:00
OptionRow &row = *m_pRows[ROW_HIGH_METER];
int iChoice = row.GetChoiceInRowWithFocus( GAMESTATE->m_MasterPlayerNumber );
if( iChoice == 0 )
ce.iHighMeter = -1;
else
ce.iHighMeter = iChoice;
}
2005-07-30 19:34:23 +00:00
break;
2005-06-28 08:11:30 +00:00
case ROW_SORT:
{
OptionRow &row = *m_pRows[ROW_SORT];
int iChoice = row.GetChoiceInRowWithFocus( GAMESTATE->m_MasterPlayerNumber );
ce.songSort = (SongSort)iChoice;
2005-06-26 21:31:07 +00:00
}
2005-07-30 19:34:23 +00:00
break;
2005-06-28 08:11:30 +00:00
case ROW_CHOOSE_INDEX:
2005-06-26 21:31:07 +00:00
{
2005-06-28 08:11:30 +00:00
OptionRow &row = *m_pRows[ROW_CHOOSE_INDEX];
int iChoice = row.GetChoiceInRowWithFocus( GAMESTATE->m_MasterPlayerNumber );
ce.iChooseIndex = iChoice;
2005-06-26 21:31:07 +00:00
}
2005-07-30 19:34:23 +00:00
break;
2005-06-26 21:31:07 +00:00
}
}
void ScreenOptionsEditCourseEntry::ProcessMenuStart( const InputEventPlus &input )
2005-06-26 21:31:07 +00:00
{
switch( m_iCurrentRow[GAMESTATE->m_MasterPlayerNumber] )
{
case ROW_SONG_GROUP:
case ROW_SONG:
2005-06-26 23:31:36 +00:00
case ROW_BASE_DIFFICULTY:
2005-06-26 21:31:07 +00:00
case ROW_LOW_METER:
case ROW_HIGH_METER:
2005-06-28 08:11:30 +00:00
case ROW_SORT:
case ROW_CHOOSE_INDEX:
2005-06-26 21:31:07 +00:00
break;
case ROW_SET_MODS:
case ROW_DONE:
2005-06-29 09:20:49 +00:00
ScreenOptions::BeginFadingOut();
2005-06-26 21:31:07 +00:00
break;
}
}
2005-07-30 19:34:23 +00:00
2005-06-26 21:31:07 +00:00
/*
* (c) 2002-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.
*/