Files
itgmania212121/stepmania/src/ScreenOptionsManageEditSteps.cpp
T

328 lines
9.8 KiB
C++
Raw Normal View History

2005-11-30 22:42:28 +00:00
#include "global.h"
#include "ScreenOptionsManageEditSteps.h"
#include "ScreenManager.h"
#include "RageLog.h"
#include "GameState.h"
#include "SongManager.h"
#include "ScreenTextEntry.h"
#include "ScreenPrompt.h"
#include "GameManager.h"
#include "Steps.h"
#include "ScreenMiniMenu.h"
#include "RageUtil.h"
2005-12-06 12:41:33 +00:00
#include "RageFileManager.h"
2005-12-22 03:10:04 +00:00
#include "LocalizedString.h"
2006-01-17 20:58:40 +00:00
#include "OptionRowHandler.h"
2006-03-08 04:03:39 +00:00
#include "SongUtil.h"
#include "song.h"
#include "ProfileManager.h"
#include "Profile.h"
#include "SpecialFiles.h"
#include "NotesWriterSM.h"
2005-11-30 22:42:28 +00:00
AutoScreenMessage( SM_BackFromRename )
2005-12-06 12:41:33 +00:00
AutoScreenMessage( SM_BackFromDelete )
2005-11-30 22:42:28 +00:00
AutoScreenMessage( SM_BackFromContextMenu )
enum StepsEditAction
{
StepsEditAction_Edit,
StepsEditAction_Rename,
StepsEditAction_Delete,
NUM_StepsEditAction
};
static const char *StepsEditActionNames[] = {
2005-11-30 22:42:28 +00:00
"Edit",
"Rename",
"Delete",
};
2006-10-15 00:09:18 +00:00
XToString( StepsEditAction );
2006-10-07 08:56:58 +00:00
#define FOREACH_StepsEditAction( i ) FOREACH_ENUM( StepsEditAction, i )
2005-11-30 22:42:28 +00:00
static MenuDef g_TempMenu(
"ScreenMiniMenuContext"
);
2006-01-15 20:46:15 +00:00
REGISTER_SCREEN_CLASS( ScreenOptionsManageEditSteps );
2005-11-30 22:42:28 +00:00
void ScreenOptionsManageEditSteps::Init()
{
ScreenOptions::Init();
2006-06-18 12:09:28 +00:00
CREATE_NEW_SCREEN.Load( m_sName, "CreateNewScreen" );
2005-11-30 22:42:28 +00:00
}
void ScreenOptionsManageEditSteps::BeginScreen()
{
// Reload so that we're consistent with the disk in case the user has been dinking around with their edits.
SONGMAN->FreeAllLoadedFromProfile( ProfileSlot_Machine );
2007-05-27 17:59:41 +00:00
SONGMAN->LoadStepEditsFromProfileDir( PROFILEMAN->GetProfileDir(ProfileSlot_Machine), ProfileSlot_Machine );
SONGMAN->LoadCourseEditsFromProfileDir( PROFILEMAN->GetProfileDir(ProfileSlot_Machine), ProfileSlot_Machine );
GAMESTATE->m_pCurSong.Set( NULL );
2006-08-21 11:34:59 +00:00
GAMESTATE->m_pCurSteps[PLAYER_1].Set( NULL );
2005-11-30 22:42:28 +00:00
vector<OptionRowHandler*> vHands;
int iIndex = 0;
{
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;
def.m_bOneChoiceForAllPlayers = true;
2005-12-04 09:01:28 +00:00
def.m_sName = "Create New Edit Steps";
def.m_sExplanationName = "Create New Edit Steps";
2005-11-30 22:42:28 +00:00
def.m_vsChoices.clear();
2005-12-04 09:01:28 +00:00
def.m_vsChoices.push_back( "" );
2005-11-30 22:42:28 +00:00
iIndex++;
}
2005-12-01 03:20:25 +00:00
SONGMAN->GetStepsLoadedFromProfile( m_vpSteps, ProfileSlot_Machine );
2005-11-30 22:42:28 +00:00
FOREACH_CONST( Steps*, m_vpSteps, s )
{
2006-01-17 20:58:40 +00:00
vHands.push_back( OptionRowHandlerUtil::MakeNull() );
OptionRowDefinition &def = vHands.back()->m_Def;
Song *pSong = SONGMAN->GetSongFromSteps( *s );
def.m_sName = pSong->GetTranslitFullTitle() + " - " + (*s)->GetDescription();
2005-12-06 12:41:33 +00:00
def.m_bAllowThemeTitle = false; // not themable
2006-03-08 04:03:39 +00:00
def.m_sExplanationName = "Select Edit Steps";
2005-11-30 22:42:28 +00:00
def.m_vsChoices.clear();
2006-01-22 01:00:06 +00:00
RString sType = GAMEMAN->StepsTypeToLocalizedString( (*s)->m_StepsType );
2005-12-04 09:01:28 +00:00
def.m_vsChoices.push_back( sType );
2005-12-06 12:41:33 +00:00
def.m_bAllowThemeItems = false; // already themed
2005-11-30 22:42:28 +00:00
iIndex++;
}
2006-01-17 21:31:50 +00:00
ScreenOptions::InitMenu( vHands );
2005-11-30 22:42:28 +00:00
ScreenOptions::BeginScreen();
// select the last chosen course
if( GAMESTATE->m_pCurSteps[PLAYER_1] )
{
vector<Steps*>::const_iterator iter = find( m_vpSteps.begin(), m_vpSteps.end(), GAMESTATE->m_pCurSteps[PLAYER_1] );
if( iter != m_vpSteps.end() )
{
int iIndex = iter - m_vpSteps.begin();
2006-02-03 08:01:00 +00:00
this->MoveRowAbsolute( PLAYER_1, 1 + iIndex );
2005-11-30 22:42:28 +00:00
}
}
AfterChangeRow( PLAYER_1 );
}
2005-12-21 09:56:16 +00:00
static LocalizedString THESE_STEPS_WILL_BE_LOST ("ScreenOptionsManageEditSteps", "These steps will be lost permanently.");
static LocalizedString CONTINUE_WITH_DELETE ("ScreenOptionsManageEditSteps", "Continue with delete?");
2005-12-21 12:55:20 +00:00
static LocalizedString ENTER_NAME_FOR_STEPS ("ScreenOptionsManageEditSteps", "Enter a name for these steps.");
2005-11-30 22:42:28 +00:00
void ScreenOptionsManageEditSteps::HandleScreenMessage( const ScreenMessage SM )
{
2005-12-06 12:41:33 +00:00
if( SM == SM_GoToNextScreen )
2005-11-30 22:42:28 +00:00
{
2006-02-03 06:21:03 +00:00
int iCurRow = m_iCurrentRow[GAMESTATE->m_MasterPlayerNumber];
2005-12-01 03:20:25 +00:00
if( iCurRow == 0 ) // "create new"
{
2006-06-18 12:09:28 +00:00
SCREENMAN->SetNewScreen( CREATE_NEW_SCREEN );
return; // don't call base
2005-12-01 03:20:25 +00:00
}
2005-12-06 12:41:33 +00:00
else if( m_pRows[iCurRow]->GetRowType() == OptionRow::RowType_Exit )
2005-11-30 22:42:28 +00:00
{
this->HandleScreenMessage( SM_GoToPrevScreen );
return; // don't call base
}
2005-12-01 03:20:25 +00:00
else // a Steps
{
2005-12-06 12:41:33 +00:00
Steps *pSteps = GAMESTATE->m_pCurSteps[PLAYER_1];
ASSERT( pSteps );
const Style *pStyle = GAMEMAN->GetEditorStyleForStepsType( pSteps->m_StepsType );
2006-09-30 22:22:26 +00:00
GAMESTATE->SetCurrentStyle( pStyle );
2006-06-18 12:09:28 +00:00
// do base behavior
2005-12-01 03:20:25 +00:00
}
2005-11-30 22:42:28 +00:00
}
else if( SM == SM_BackFromRename )
{
if( !ScreenTextEntry::s_bCancelledLast )
{
ASSERT( ScreenTextEntry::s_sLastAnswer != "" ); // validate should have assured this
Steps *pSteps = GAMESTATE->m_pCurSteps[PLAYER_1];
Song *pSong = SONGMAN->GetSongFromSteps( pSteps );
RString sOldDescription = pSteps->GetDescription();
pSteps->SetDescription( ScreenTextEntry::s_sLastAnswer );
RString sError;
2006-11-04 23:28:33 +00:00
if( !NotesWriterSM::WriteEditFileToMachine(pSong,pSteps,sError) )
{
ScreenPrompt::Prompt( SM_None, sError );
return;
}
2005-11-30 22:42:28 +00:00
SCREENMAN->SetNewScreen( this->m_sName ); // reload
2005-11-30 22:42:28 +00:00
}
}
2005-12-06 12:41:33 +00:00
else if( SM == SM_BackFromDelete )
{
if( ScreenPrompt::s_LastAnswer == ANSWER_YES )
2005-12-06 12:41:33 +00:00
{
LOG->Trace( "Delete successful; deleting Steps from memory" );
Steps *pSteps = GetStepsWithFocus();
FILEMAN->Remove( pSteps->GetFilename() );
SONGMAN->DeleteSteps( pSteps );
GAMESTATE->m_pCurSteps[PLAYER_1].Set( NULL );
SCREENMAN->SetNewScreen( this->m_sName ); // reload
2005-12-06 12:41:33 +00:00
}
}
2005-11-30 22:42:28 +00:00
else if( SM == SM_BackFromContextMenu )
{
if( !ScreenMiniMenu::s_bCancelled )
{
switch( ScreenMiniMenu::s_iLastRowCode )
{
case StepsEditAction_Edit:
{
Steps *pSteps = GetStepsWithFocus();
Song *pSong = SONGMAN->GetSongFromSteps( pSteps );
GAMESTATE->m_pCurSong.Set( pSong );
GAMESTATE->m_pCurSteps[PLAYER_1].Set( pSteps );
ScreenOptions::BeginFadingOut();
}
break;
case StepsEditAction_Rename:
{
ScreenTextEntry::TextEntry(
SM_BackFromRename,
2005-12-21 12:55:20 +00:00
ENTER_NAME_FOR_STEPS,
2005-11-30 22:42:28 +00:00
GAMESTATE->m_pCurSteps[PLAYER_1]->GetDescription(),
MAX_EDIT_STEPS_DESCRIPTION_LENGTH,
2006-03-08 04:03:39 +00:00
SongUtil::ValidateCurrentEditStepsDescription );
2005-11-30 22:42:28 +00:00
}
break;
case StepsEditAction_Delete:
{
2005-12-21 09:56:16 +00:00
ScreenPrompt::Prompt( SM_BackFromDelete, THESE_STEPS_WILL_BE_LOST.GetValue()+"\n\n"+CONTINUE_WITH_DELETE.GetValue(), PROMPT_YES_NO, ANSWER_NO );
2005-11-30 22:42:28 +00:00
}
break;
}
}
}
else if( SM == SM_LoseFocus )
{
this->PlayCommand( "ScreenLoseFocus" );
}
else if( SM == SM_GainFocus )
{
this->PlayCommand( "ScreenGainFocus" );
}
ScreenOptions::HandleScreenMessage( SM );
}
void ScreenOptionsManageEditSteps::AfterChangeRow( PlayerNumber pn )
{
Steps *pSteps = GetStepsWithFocus();
Song *pSong = pSteps ? SONGMAN->GetSongFromSteps( pSteps ) : NULL;
GAMESTATE->m_pCurSong.Set( pSong );
GAMESTATE->m_pCurSteps[PLAYER_1].Set( pSteps );
ScreenOptions::AfterChangeRow( pn );
}
2005-12-21 09:56:16 +00:00
static LocalizedString YOU_HAVE_MAX_STEP_EDITS( "ScreenOptionsManageEditSteps", "You have %d step edits, the maximum number allowed." );
static LocalizedString YOU_MUST_DELETE( "ScreenOptionsManageEditSteps", "You must delete an existing steps edit before creating a new steps edit." );
2005-11-30 22:42:28 +00:00
void ScreenOptionsManageEditSteps::ProcessMenuStart( const InputEventPlus &input )
{
if( IsTransitioning() )
return;
2005-11-30 22:42:28 +00:00
int iCurRow = m_iCurrentRow[GAMESTATE->m_MasterPlayerNumber];
if( iCurRow == 0 ) // "create new"
{
vector<Steps*> v;
2005-12-01 03:20:25 +00:00
SONGMAN->GetStepsLoadedFromProfile( v, ProfileSlot_Machine );
2005-12-12 09:59:17 +00:00
if( v.size() >= size_t(MAX_EDIT_STEPS_PER_PROFILE) )
2005-11-30 22:42:28 +00:00
{
2006-01-22 01:00:06 +00:00
RString s = ssprintf( YOU_HAVE_MAX_STEP_EDITS.GetValue()+"\n\n"+YOU_MUST_DELETE.GetValue(), MAX_EDIT_STEPS_PER_PROFILE );
2005-11-30 22:42:28 +00:00
ScreenPrompt::Prompt( SM_None, s );
return;
}
SCREENMAN->PlayStartSound();
2005-12-01 03:20:25 +00:00
this->BeginFadingOut();
2005-11-30 22:42:28 +00:00
}
2005-12-06 12:41:33 +00:00
else if( m_pRows[iCurRow]->GetRowType() == OptionRow::RowType_Exit )
2005-11-30 22:42:28 +00:00
{
SCREENMAN->PlayStartSound();
2005-11-30 22:42:28 +00:00
this->BeginFadingOut();
}
else // a Steps
{
g_TempMenu.rows.clear();
FOREACH_StepsEditAction( i )
{
2006-02-13 22:45:17 +00:00
MenuRowDef mrd( i, StepsEditActionToString(i), true, EditMode_Home, true, true, 0, "" );
2005-11-30 22:42:28 +00:00
g_TempMenu.rows.push_back( mrd );
}
int iWidth, iX, iY;
this->GetWidthXY( PLAYER_1, iCurRow, 0, iWidth, iX, iY );
ScreenMiniMenu::MiniMenu( &g_TempMenu, SM_BackFromContextMenu, SM_BackFromContextMenu, (float)iX, (float)iY );
}
}
void ScreenOptionsManageEditSteps::ImportOptions( int iRow, const vector<PlayerNumber> &vpns )
{
}
void ScreenOptionsManageEditSteps::ExportOptions( int iRow, const vector<PlayerNumber> &vpns )
{
}
Steps *ScreenOptionsManageEditSteps::GetStepsWithFocus() const
{
int iCurRow = m_iCurrentRow[GAMESTATE->m_MasterPlayerNumber];
if( iCurRow == 0 )
return NULL;
2005-12-06 12:41:33 +00:00
else if( m_pRows[iCurRow]->GetRowType() == OptionRow::RowType_Exit )
2005-11-30 22:42:28 +00:00
return NULL;
// a Steps
int iStepsIndex = iCurRow - 1;
return m_vpSteps[iStepsIndex];
}
/*
* (c) 2002-2005 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.
*/