Files
itgmania212121/stepmania/src/ScreenOptionsManageCourses.cpp
T

394 lines
12 KiB
C++
Raw Normal View History

2005-07-29 02:23:02 +00:00
#include "global.h"
#include "ScreenOptionsManageCourses.h"
#include "ScreenManager.h"
#include "RageLog.h"
#include "GameState.h"
#include "SongManager.h"
#include "CommonMetrics.h"
#include "ScreenTextEntry.h"
#include "ScreenPrompt.h"
2005-07-29 23:03:43 +00:00
#include "ScreenMiniMenu.h"
2005-08-01 05:12:06 +00:00
#include "GameManager.h"
#include "Difficulty.h"
2005-08-03 03:28:13 +00:00
#include "CourseUtil.h"
2005-12-22 03:10:04 +00:00
#include "LocalizedString.h"
2006-01-17 20:58:40 +00:00
#include "OptionRowHandler.h"
#include "ProfileManager.h"
#include "Profile.h"
#include "CourseWriterCRS.h"
#include "RageFileManager.h"
2009-04-11 18:45:04 +00:00
#include "PrefsManager.h"
2009-04-11 18:45:04 +00:00
AutoScreenMessage( SM_BackFromRename )
AutoScreenMessage( SM_BackFromDelete )
AutoScreenMessage( SM_BackFromContextMenu )
enum CourseAction
2005-08-01 05:12:06 +00:00
{
2009-04-11 18:45:04 +00:00
CourseAction_Edit,
CourseAction_Rename,
CourseAction_Delete,
NUM_CourseAction
};
static const char *CourseActionNames[] = {
"Edit",
"Rename",
"Delete",
};
XToString( CourseAction );
#define FOREACH_CourseAction( i ) FOREACH_ENUM( CourseAction, i )
static MenuDef g_TempMenu(
"ScreenMiniMenuContext"
);
REGISTER_SCREEN_CLASS( ScreenOptionsManageCourses );
2005-08-01 05:12:06 +00:00
struct StepsTypeAndDifficulty
{
StepsType st;
Difficulty cd;
2005-08-01 05:12:06 +00:00
StepsTypeAndDifficulty( const StepsType &s, const Difficulty &d ) : st( s ), cd( d ) { }
2005-08-01 05:12:06 +00:00
bool operator==( const StepsTypeAndDifficulty &stad ) const { return st == stad.st && cd == stad.cd; }
};
static void SetNextCombination()
{
vector<StepsTypeAndDifficulty> v;
{
FOREACH_CONST( StepsType, CommonMetrics::STEPS_TYPES_TO_SHOW.GetValue(), st )
2005-08-01 05:12:06 +00:00
{
FOREACH_CONST( CourseDifficulty, CommonMetrics::COURSE_DIFFICULTIES_TO_SHOW.GetValue(), cd )
2006-02-19 06:00:35 +00:00
v.push_back( StepsTypeAndDifficulty(*st, *cd) );
2005-08-01 05:12:06 +00:00
}
}
StepsTypeAndDifficulty curVal( GAMESTATE->m_stEdit, GAMESTATE->m_cdEdit );
2005-08-01 05:12:06 +00:00
vector<StepsTypeAndDifficulty>::const_iterator iter = find( v.begin(), v.end(), curVal );
2006-02-19 06:00:35 +00:00
if( iter == v.end() || ++iter == v.end() )
iter = v.begin();
2005-08-01 05:12:06 +00:00
2006-02-19 06:00:35 +00:00
curVal = *iter;
2005-08-01 05:12:06 +00:00
GAMESTATE->m_stEdit.Set( curVal.st );
GAMESTATE->m_cdEdit.Set( curVal.cd );
// XXX Testing.
SCREENMAN->SystemMessage( ssprintf("%s, %s", GAMEMAN->GetStepsTypeInfo(curVal.st).szName, DifficultyToString(curVal.cd).c_str()) );
2005-08-01 05:12:06 +00:00
2009-04-11 18:45:04 +00:00
EditCourseUtil::UpdateAndSetTrail();
2005-08-01 05:12:06 +00:00
}
2005-07-29 02:23:02 +00:00
void ScreenOptionsManageCourses::Init()
{
2009-04-11 18:45:04 +00:00
if( PREFSMAN->m_iArcadeOptionsNavigation )
SetNavigation( NAV_THREE_KEY_MENU );
2005-07-29 02:23:02 +00:00
2009-04-11 18:45:04 +00:00
ScreenOptions::Init();
m_soundDifficultyChanged.Load( THEME->GetPathS("ScreenEditCourseSubmenu", "difficulty changed") );
2006-02-19 06:00:35 +00:00
EDIT_MODE.Load( m_sName,"EditMode" );
CREATE_NEW_SCREEN.Load( m_sName, "CreateNewScreen" );
2005-08-14 01:48:06 +00:00
}
2005-08-01 05:12:06 +00:00
void ScreenOptionsManageCourses::BeginScreen()
{
vector<const Style*> vpStyles;
GAMEMAN->GetStylesForGame( GAMESTATE->m_pCurGame, vpStyles );
const Style *pStyle = vpStyles[0];
GAMESTATE->SetCurrentStyle( pStyle );
2006-09-26 20:28:46 +00:00
if( GAMESTATE->m_stEdit == StepsType_Invalid ||
2006-10-07 04:39:48 +00:00
GAMESTATE->m_cdEdit == Difficulty_Invalid )
{
SetNextCombination();
}
2009-04-11 18:45:04 +00:00
// Remember the current course. All Course pointers will be invalidated when we load the machine profile below.
CourseID cidLast;
cidLast.FromCourse( GAMESTATE->m_pCurCourse );
2005-07-29 02:23:02 +00:00
vector<OptionRowHandler*> vHands;
2005-08-05 10:07:49 +00:00
int iIndex = 0;
2005-07-29 02:23:02 +00:00
2005-08-05 10:07:49 +00:00
{
2006-01-17 20:58:40 +00:00
vHands.push_back( OptionRowHandlerUtil::MakeNull() );
OptionRowDefinition &def = vHands.back()->m_Def;
def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
2006-02-19 06:12:01 +00:00
def.m_bOneChoiceForAllPlayers = true;
def.m_sName = "Create New Course";
def.m_sExplanationName = "Create New Course";
def.m_vsChoices.clear();
def.m_vsChoices.push_back( "" );
2005-08-05 10:07:49 +00:00
iIndex++;
}
m_vpCourses.clear();
2009-04-11 18:45:04 +00:00
FlushDirCache();
PROFILEMAN->LoadMachineProfileEdits();
2005-08-01 05:12:06 +00:00
switch( EDIT_MODE.GetValue() )
{
2009-04-11 18:45:04 +00:00
DEFAULT_FAIL( EDIT_MODE.GetValue() );
case EditMode_Home:
EditCourseUtil::GetAllEditCourses( m_vpCourses );
break;
case EditMode_Practice:
case EditMode_Full:
SONGMAN->GetAllCourses( m_vpCourses, false );
break;
2005-08-01 05:12:06 +00:00
}
2009-04-11 18:45:04 +00:00
FOREACH_CONST( Course*, m_vpCourses, p )
2005-07-29 02:23:02 +00:00
{
2006-01-17 20:58:40 +00:00
vHands.push_back( OptionRowHandlerUtil::MakeNull() );
OptionRowDefinition &def = vHands.back()->m_Def;
2009-04-11 18:45:04 +00:00
def.m_sName = (*p)->GetDisplayFullTitle();
def.m_bAllowThemeTitle = false; // not themable
2009-04-11 19:12:26 +00:00
def.m_sExplanationName = "Select Course";
2009-04-11 18:45:04 +00:00
def.m_vsChoices.clear();
def.m_vsChoices.push_back( "" );
def.m_bAllowThemeItems = false; // already themed
2005-08-05 10:07:49 +00:00
iIndex++;
2005-07-29 02:23:02 +00:00
}
2006-01-17 21:31:50 +00:00
ScreenOptions::InitMenu( vHands );
2005-07-29 02:23:02 +00:00
ScreenOptions::BeginScreen();
2005-07-29 23:03:43 +00:00
2005-08-01 05:12:06 +00:00
// select the last chosen course
2009-04-11 18:45:04 +00:00
GAMESTATE->m_pCurCourse.Set( cidLast.ToCourse() );
2005-08-01 05:12:06 +00:00
if( GAMESTATE->m_pCurCourse )
{
2009-04-11 18:45:04 +00:00
EditCourseUtil::UpdateAndSetTrail();
2005-08-01 05:12:06 +00:00
vector<Course*>::const_iterator iter = find( m_vpCourses.begin(), m_vpCourses.end(), GAMESTATE->m_pCurCourse );
if( iter != m_vpCourses.end() )
{
int iIndex = iter - m_vpCourses.begin();
2006-02-20 06:18:57 +00:00
this->MoveRowAbsolute( GAMESTATE->m_MasterPlayerNumber, 1 + iIndex );
2005-08-01 05:12:06 +00:00
}
}
2006-02-20 06:18:57 +00:00
AfterChangeRow( GAMESTATE->m_MasterPlayerNumber );
2005-07-29 02:23:02 +00:00
}
2009-04-11 18:45:04 +00:00
static LocalizedString ERROR_RENAMING ("ScreenOptionsManageCourses", "Error renaming file.");
2009-04-11 19:12:26 +00:00
static LocalizedString ERROR_DELETING_FILE ("ScreenOptionsManageCourses", "Error deleting the file '%s'.");
static LocalizedString COURSE_WILL_BE_LOST ( "ScreenOptionsManageCourses", "This course will be lost permanently." );
static LocalizedString CONTINUE_WITH_DELETE ( "ScreenOptionsManageCourses", "Continue with delete?" );
static LocalizedString ENTER_COURSE_NAME ( "ScreenOptionsManageCourses", "Enter a name for the course." );
2005-07-29 02:23:02 +00:00
void ScreenOptionsManageCourses::HandleScreenMessage( const ScreenMessage SM )
{
2009-04-11 18:45:04 +00:00
if( SM == SM_GoToNextScreen )
2005-07-29 02:23:02 +00:00
{
int iCurRow = m_iCurrentRow[GAMESTATE->m_MasterPlayerNumber];
2009-04-11 18:45:04 +00:00
if( iCurRow == 0 ) // "create new"
{
/* Allocate the Course now, but don't save the file until the user explicitly chooses Save */
Course *pCourse = new Course;
EditCourseUtil::LoadDefaults( *pCourse );
pCourse->m_LoadedFromProfile = ProfileSlot_Machine;
SONGMAN->AddCourse( pCourse );
GAMESTATE->m_pCurCourse.Set( pCourse );
EditCourseUtil::s_bNewCourseNeedsName = true;
EditCourseUtil::UpdateAndSetTrail();
SCREENMAN->SetNewScreen( CREATE_NEW_SCREEN );
return; // don't call base
}
else if( m_pRows[iCurRow]->GetRowType() == OptionRow::RowType_Exit )
2005-07-29 02:23:02 +00:00
{
this->HandleScreenMessage( SM_GoToPrevScreen );
return; // don't call base
}
2009-04-11 18:45:04 +00:00
else
2005-07-29 02:23:02 +00:00
{
2009-04-11 18:45:04 +00:00
// do base behavior
2005-07-29 02:23:02 +00:00
}
}
2005-08-03 03:28:13 +00:00
else if( SM == SM_BackFromRename )
{
if( !ScreenTextEntry::s_bCancelledLast )
{
ASSERT( ScreenTextEntry::s_sLastAnswer != "" ); // validate should have assured this
2009-04-11 18:45:04 +00:00
if( !EditCourseUtil::RenameAndSave(GAMESTATE->m_pCurCourse, ScreenTextEntry::s_sLastAnswer) )
{
ScreenPrompt::Prompt( SM_None, ERROR_RENAMING );
return;
}
SCREENMAN->SetNewScreen( this->m_sName ); // reload
}
}
else if( SM == SM_BackFromDelete )
{
if( ScreenPrompt::s_LastAnswer == ANSWER_YES )
{
Course *pCourse = GetCourseWithFocus();
if( !EditCourseUtil::RemoveAndDeleteFile( pCourse ) )
{
ScreenPrompt::Prompt( SM_None, ssprintf(ERROR_DELETING_FILE.GetValue(),pCourse->m_sPath.c_str()) );
return;
}
GAMESTATE->m_pCurCourse.Set( NULL );
GAMESTATE->m_pCurTrail[PLAYER_1].Set( NULL );
SCREENMAN->SetNewScreen( this->m_sName ); // reload
2005-08-03 03:28:13 +00:00
}
}
2005-07-29 23:03:43 +00:00
else if( SM == SM_BackFromContextMenu )
{
if( !ScreenMiniMenu::s_bCancelled )
{
switch( ScreenMiniMenu::s_iLastRowCode )
{
case CourseAction_Edit:
2009-04-11 18:45:04 +00:00
{
GAMESTATE->m_pCurCourse.Set( GetCourseWithFocus() );
EditCourseUtil::UpdateAndSetTrail();
EditCourseUtil::s_bNewCourseNeedsName = false;
ScreenOptions::BeginFadingOut();
break;
}
2005-07-29 23:03:43 +00:00
case CourseAction_Rename:
2009-04-11 18:45:04 +00:00
ScreenTextEntry::TextEntry(
SM_BackFromRename,
ENTER_COURSE_NAME,
GAMESTATE->m_pCurCourse->GetDisplayFullTitle(),
EditCourseUtil::MAX_NAME_LENGTH,
EditCourseUtil::ValidateEditCourseName );
2006-02-19 06:00:35 +00:00
break;
2005-07-29 23:03:43 +00:00
case CourseAction_Delete:
2005-12-21 09:56:16 +00:00
ScreenPrompt::Prompt( SM_None, COURSE_WILL_BE_LOST.GetValue()+"\n\n"+CONTINUE_WITH_DELETE.GetValue(), PROMPT_YES_NO, ANSWER_NO );
2005-07-29 23:03:43 +00:00
break;
}
}
}
else if( SM == SM_LoseFocus )
{
this->PlayCommand( "ScreenLoseFocus" );
}
else if( SM == SM_GainFocus )
{
this->PlayCommand( "ScreenGainFocus" );
}
2005-07-29 02:23:02 +00:00
ScreenOptions::HandleScreenMessage( SM );
}
2005-07-29 23:03:43 +00:00
void ScreenOptionsManageCourses::AfterChangeRow( PlayerNumber pn )
2005-07-29 02:23:02 +00:00
{
2005-07-29 23:03:43 +00:00
Course *pCourse = GetCourseWithFocus();
Trail *pTrail = pCourse ? pCourse->GetTrail( GAMESTATE->m_stEdit, GAMESTATE->m_cdEdit ) : NULL;
2005-07-29 23:03:43 +00:00
GAMESTATE->m_pCurCourse.Set( pCourse );
2006-03-04 02:34:01 +00:00
GAMESTATE->m_pCurTrail[PLAYER_1].Set( pTrail );
2005-07-29 23:03:43 +00:00
ScreenOptions::AfterChangeRow( pn );
2005-07-29 02:23:02 +00:00
}
2009-04-11 18:45:04 +00:00
void ScreenOptionsManageCourses::MenuSelect( const InputEventPlus &input )
{
if( input.type != IET_FIRST_PRESS )
return;
SetNextCombination();
m_soundDifficultyChanged.Play();
}
static LocalizedString YOU_HAVE_MAX( "ScreenOptionsManageCourses", "You have %d, the maximum number allowed." );
static LocalizedString YOU_MUST_DELETE( "ScreenOptionsManageCourses", "You must delete an existing before creating a new." );
void ScreenOptionsManageCourses::ProcessMenuStart( const InputEventPlus &input )
2005-07-29 02:23:02 +00:00
{
if( IsTransitioning() )
return;
2005-07-29 02:23:02 +00:00
int iCurRow = m_iCurrentRow[GAMESTATE->m_MasterPlayerNumber];
if( iCurRow == 0 ) // "create new"
{
2009-04-11 18:45:04 +00:00
vector<Course*> vpCourses;
EditCourseUtil::GetAllEditCourses( vpCourses );
if( vpCourses.size() >= (size_t)EditCourseUtil::MAX_PER_PROFILE )
2005-08-05 10:07:49 +00:00
{
2009-04-11 18:45:04 +00:00
RString s = ssprintf( YOU_HAVE_MAX.GetValue()+"\n\n"+YOU_MUST_DELETE.GetValue(), EditCourseUtil::MAX_PER_PROFILE );
ScreenPrompt::Prompt( SM_None, s );
return;
2005-08-03 03:28:13 +00:00
}
2009-04-11 18:45:04 +00:00
SCREENMAN->PlayStartSound();
this->BeginFadingOut();
2005-07-29 02:23:02 +00:00
}
2009-04-11 18:45:04 +00:00
else if( m_pRows[iCurRow]->GetRowType() == OptionRow::RowType_Exit )
2005-07-29 02:23:02 +00:00
{
SCREENMAN->PlayStartSound();
2005-07-30 04:50:17 +00:00
this->BeginFadingOut();
2005-07-29 02:23:02 +00:00
}
else // a course
{
2005-07-29 23:03:43 +00:00
g_TempMenu.rows.clear();
FOREACH_CourseAction( i )
2005-07-29 02:23:02 +00:00
{
2006-02-13 22:45:17 +00:00
MenuRowDef mrd( i, CourseActionToString(i), true, EditMode_Home, true, true, 0, "" );
2005-07-29 23:03:43 +00:00
g_TempMenu.rows.push_back( mrd );
2005-07-29 02:23:02 +00:00
}
2005-07-29 23:03:43 +00:00
int iWidth, iX, iY;
2006-02-20 06:18:57 +00:00
this->GetWidthXY( GAMESTATE->m_MasterPlayerNumber, iCurRow, 0, iWidth, iX, iY );
2005-08-01 05:12:06 +00:00
ScreenMiniMenu::MiniMenu( &g_TempMenu, SM_BackFromContextMenu, SM_BackFromContextMenu, (float)iX, (float)iY );
2005-07-29 02:23:02 +00:00
}
}
void ScreenOptionsManageCourses::ImportOptions( int iRow, const vector<PlayerNumber> &vpns )
{
}
void ScreenOptionsManageCourses::ExportOptions( int iRow, const vector<PlayerNumber> &vpns )
{
}
Course *ScreenOptionsManageCourses::GetCourseWithFocus() const
{
int iCurRow = m_iCurrentRow[GAMESTATE->m_MasterPlayerNumber];
if( iCurRow == 0 )
return NULL;
2009-04-11 18:45:04 +00:00
else if( m_pRows[iCurRow]->GetRowType() == OptionRow::RowType_Exit )
2005-07-29 02:23:02 +00:00
return NULL;
2005-07-29 23:03:43 +00:00
// a course
2009-04-11 18:45:04 +00:00
int index = iCurRow - 1;
return m_vpCourses[index];
2005-07-29 02:23:02 +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.
*/