Files
itgmania212121/stepmania/src/ScreenEditMenu.cpp
T

364 lines
9.7 KiB
C++
Raw Normal View History

2003-02-16 04:01:45 +00:00
#include "global.h"
2002-05-20 08:59:37 +00:00
#include "ScreenEditMenu.h"
#include "SongManager.h"
#include "ScreenManager.h"
#include "GameConstantsAndTypes.h"
#include "RageUtil.h"
#include "GameManager.h"
#include "RageLog.h"
2002-07-23 01:41:40 +00:00
#include "GameState.h"
2004-07-08 00:10:34 +00:00
#include "GameSoundManager.h"
#include "ThemeManager.h"
2003-08-03 00:13:55 +00:00
#include "Steps.h"
2003-11-07 20:24:44 +00:00
#include "song.h"
2005-03-08 01:46:57 +00:00
#include "CommonMetrics.h"
2005-03-22 23:59:17 +00:00
#include "ScreenTextEntry.h"
2005-07-03 04:34:53 +00:00
#include "ScreenPrompt.h"
2005-12-22 03:10:04 +00:00
#include "LocalizedString.h"
2006-03-08 04:03:39 +00:00
#include "SongUtil.h"
#include "RageFile.h"
#include "RageFileManager.h"
static const RString TEMP_FILE_NAME = "--temp--";
2002-05-20 08:59:37 +00:00
2006-01-08 18:40:20 +00:00
#define EXPLANATION_TEXT( row ) THEME->GetString(m_sName,"Explanation"+EditMenuRowToString(row))
2005-07-14 05:53:46 +00:00
#define EDIT_MENU_TYPE THEME->GetMetric(m_sName,"EditMenuType")
2002-05-20 08:59:37 +00:00
AutoScreenMessage( SM_RefreshSelector )
AutoScreenMessage( SM_BackFromEditDescription )
2002-05-20 08:59:37 +00:00
2006-01-15 20:46:15 +00:00
REGISTER_SCREEN_CLASS( ScreenEditMenu );
2006-01-15 18:54:03 +00:00
void ScreenEditMenu::Init()
2002-05-20 08:59:37 +00:00
{
2004-05-22 00:12:57 +00:00
/* Enable all players. */
FOREACH_PlayerNumber( pn )
GAMESTATE->m_bSideIsJoined[pn] = true;
2005-02-23 18:56:50 +00:00
ScreenWithMenuElements::Init();
2005-07-14 07:11:44 +00:00
m_Selector.SetName( "EditMenu" );
m_Selector.Load( EDIT_MENU_TYPE );
2003-01-30 07:18:33 +00:00
m_Selector.SetXY( 0, 0 );
this->AddChild( &m_Selector );
2002-05-20 08:59:37 +00:00
2002-08-27 16:53:25 +00:00
2004-05-22 00:12:57 +00:00
m_textExplanation.SetName( "Explanation" );
2005-03-05 09:11:56 +00:00
m_textExplanation.LoadFromFont( THEME->GetPathF(m_sName,"explanation") );
2005-03-08 00:32:49 +00:00
SET_XY( m_textExplanation );
RefreshExplanationText();
this->AddChild( &m_textExplanation );
2002-05-20 08:59:37 +00:00
2005-03-08 01:46:57 +00:00
m_textNumStepsLoadedFromProfile.SetName( "NumStepsLoadedFromProfile" );
m_textNumStepsLoadedFromProfile.LoadFromFont( THEME->GetPathF(m_sName,"NumStepsLoadedFromProfile") );
SET_XY_AND_ON_COMMAND( m_textNumStepsLoadedFromProfile );
RefreshNumStepsLoadedFromProfile();
this->AddChild( &m_textNumStepsLoadedFromProfile );
2004-05-03 00:08:56 +00:00
this->SortByDrawOrder();
2002-05-20 08:59:37 +00:00
}
2005-03-14 02:48:48 +00:00
2002-05-20 08:59:37 +00:00
void ScreenEditMenu::HandleScreenMessage( const ScreenMessage SM )
{
if( SM == SM_RefreshSelector )
2002-05-20 08:59:37 +00:00
{
2005-03-06 00:08:48 +00:00
m_Selector.RefreshAll();
2005-03-21 03:47:30 +00:00
RefreshNumStepsLoadedFromProfile();
}
else if( SM == SM_Success && m_Selector.GetSelectedAction() == EditMenuAction_Delete )
{
2005-03-14 02:56:01 +00:00
LOG->Trace( "Delete successful; deleting steps from memory" );
2005-07-14 04:15:57 +00:00
Song* pSong = GAMESTATE->m_pCurSong;
Steps* pStepsToDelete = GAMESTATE->m_pCurSteps[PLAYER_1];
bool bSaveSong = !pStepsToDelete->WasLoadedFromProfile();
2005-07-29 02:23:02 +00:00
pSong->DeleteSteps( pStepsToDelete );
2005-07-14 04:15:57 +00:00
/* Only save to the main .SM file if the steps we're deleting were loaded
* from it. */
if( bSaveSong )
{
pSong->Save();
SCREENMAN->ZeroNextUpdate();
}
SCREENMAN->SendMessageToTopScreen( SM_RefreshSelector );
}
else if( SM == SM_Failure && m_Selector.GetSelectedAction() == EditMenuAction_Delete )
{
2005-03-14 02:56:01 +00:00
LOG->Trace( "Delete failed; not deleting steps" );
}
else if( SM == SM_BackFromEditDescription )
{
2005-03-22 23:59:17 +00:00
if( !ScreenTextEntry::s_bCancelledLast )
{
SOUND->StopMusic();
StartTransitioningScreen( SM_GoToNextScreen );
2005-03-22 23:59:17 +00:00
}
2002-05-20 08:59:37 +00:00
}
2005-07-12 02:21:28 +00:00
ScreenWithMenuElements::HandleScreenMessage( SM );
2002-05-20 08:59:37 +00:00
}
void ScreenEditMenu::MenuUp( PlayerNumber pn )
2002-05-20 08:59:37 +00:00
{
2005-03-08 00:32:49 +00:00
if( m_Selector.CanGoUp() )
{
m_Selector.Up();
RefreshExplanationText();
}
2002-05-20 08:59:37 +00:00
}
void ScreenEditMenu::MenuDown( PlayerNumber pn )
2002-05-20 08:59:37 +00:00
{
2005-03-08 00:32:49 +00:00
if( m_Selector.CanGoDown() )
{
m_Selector.Down();
RefreshExplanationText();
}
2002-05-20 08:59:37 +00:00
}
void ScreenEditMenu::MenuLeft( const InputEventPlus &input )
2002-05-20 08:59:37 +00:00
{
2005-03-08 00:32:49 +00:00
if( m_Selector.CanGoLeft() )
{
m_Selector.Left();
}
2002-05-20 08:59:37 +00:00
}
void ScreenEditMenu::MenuRight( const InputEventPlus &input )
2002-05-20 08:59:37 +00:00
{
2005-03-08 00:32:49 +00:00
if( m_Selector.CanGoRight() )
{
m_Selector.Right();
}
2003-01-30 07:18:33 +00:00
}
2006-01-22 01:00:06 +00:00
static RString GetCopyDescription( const Steps *pSourceSteps )
{
2006-01-22 01:00:06 +00:00
RString s;
if( pSourceSteps->GetDifficulty() == DIFFICULTY_EDIT )
s = pSourceSteps->GetDescription();
else
2006-01-07 04:11:29 +00:00
s = DifficultyToLocalizedString( pSourceSteps->GetDifficulty() );
2005-03-06 00:08:48 +00:00
return s;
}
2005-03-23 05:12:31 +00:00
2006-01-22 01:00:06 +00:00
static void SetCurrentStepsDescription( const RString &s )
2005-03-22 23:59:17 +00:00
{
GAMESTATE->m_pCurSteps[0]->SetDescription( s );
}
static void DeleteCurrentSteps()
{
2005-07-29 02:23:02 +00:00
GAMESTATE->m_pCurSong->DeleteSteps( GAMESTATE->m_pCurSteps[0] );
2005-03-22 23:59:17 +00:00
GAMESTATE->m_pCurSteps[0].Set( NULL );
}
2006-01-18 10:03:45 +00:00
static LocalizedString MISSING_MUSIC_FILE ( "ScreenEditMenu", "This song is missing a music file and cannot be edited." );
static LocalizedString SONG_DIR_READ_ONLY ( "ScreenEditMenu", "The song directory is read-only and cannot be edited." );
2006-01-18 10:03:45 +00:00
static LocalizedString STEPS_WILL_BE_LOST ( "ScreenEditMenu", "These steps will be lost permanently." );
static LocalizedString CONTINUE_WITH_DELETE ( "ScreenEditMenu", "Continue with delete?" );
static LocalizedString BLANK ( "ScreenEditMenu", "Blank" );
2005-12-21 12:55:20 +00:00
static LocalizedString ENTER_EDIT_DESCRIPTION ( "ScreenEditMenu", "Enter a description for this edit.");
void ScreenEditMenu::MenuStart( PlayerNumber pn )
2002-05-20 08:59:37 +00:00
{
if( IsTransitioning() )
2002-10-18 02:42:52 +00:00
return;
if( m_Selector.CanGoDown() )
{
m_Selector.Down();
RefreshExplanationText();
return;
}
2006-03-09 22:16:20 +00:00
Song* pSong = m_Selector.GetSelectedSong();
StepsType st = m_Selector.GetSelectedStepsType();
Difficulty dc = m_Selector.GetSelectedDifficulty();
Steps* pSteps = m_Selector.GetSelectedSteps();
// StepsType soureNT = m_Selector.GetSelectedSourceStepsType();
2005-03-07 23:55:18 +00:00
// Difficulty sourceDiff = m_Selector.GetSelectedSourceDifficulty();
2006-03-09 22:16:20 +00:00
Steps* pSourceSteps = m_Selector.GetSelectedSourceSteps();
2005-03-07 23:55:18 +00:00
EditMenuAction action = m_Selector.GetSelectedAction();
2003-01-30 07:18:33 +00:00
GAMESTATE->m_pCurSong.Set( pSong );
2006-08-18 07:11:51 +00:00
GAMESTATE->m_pCurCourse.Set( NULL );
2005-05-07 08:34:20 +00:00
GAMESTATE->m_pCurStyle.Set( GAMEMAN->GetEditorStyleForStepsType(st) );
GAMESTATE->m_pCurSteps[PLAYER_1].Set( pSteps );
2003-01-30 07:18:33 +00:00
//
// handle error cases
//
2003-01-30 07:18:33 +00:00
if( !pSong->HasMusic() )
{
2005-12-20 21:32:26 +00:00
ScreenPrompt::Prompt( SM_None, MISSING_MUSIC_FILE );
return;
}
switch( m_Selector.EDIT_MODE )
{
2006-06-24 05:52:25 +00:00
case EditMode_Full:
{
RString sDir = pSong->GetSongDir();
RString sTempFile = sDir + TEMP_FILE_NAME;
RageFile file;
if( !file.Open( sTempFile, RageFile::WRITE ) )
{
2006-06-24 05:52:25 +00:00
ScreenPrompt::Prompt( SM_None, SONG_DIR_READ_ONLY );
return;
}
2006-06-24 05:52:25 +00:00
file.Close();
FILEMAN->Remove( sTempFile );
break;
}
2006-06-24 05:52:25 +00:00
}
2005-03-21 03:45:14 +00:00
//
// Do work
//
2003-01-30 07:18:33 +00:00
switch( action )
{
2005-12-01 03:20:25 +00:00
case EditMenuAction_Edit:
case EditMenuAction_Practice:
2003-01-30 07:18:33 +00:00
break;
2005-12-01 03:20:25 +00:00
case EditMenuAction_Delete:
2004-05-24 03:41:39 +00:00
ASSERT( pSteps );
2005-12-21 09:56:16 +00:00
ScreenPrompt::Prompt( SM_None, STEPS_WILL_BE_LOST.GetValue() + "\n\n" + CONTINUE_WITH_DELETE.GetValue(), PROMPT_YES_NO, ANSWER_NO );
break;
2005-12-01 03:20:25 +00:00
case EditMenuAction_Create:
2004-05-24 03:41:39 +00:00
ASSERT( !pSteps );
2003-01-30 07:18:33 +00:00
{
// Yuck. Doing the memory allocation doesn't seem right since
2003-08-03 00:13:55 +00:00
// Song allocates all of the other Steps.
pSteps = new Steps;
switch( m_Selector.EDIT_MODE )
{
default:
ASSERT(0);
case EditMode_Full:
break;
case EditMode_Home:
pSteps->SetLoadedFromProfile( ProfileSlot_Machine );
break;
case EditMode_Practice:
ASSERT(0);
break;
}
2006-01-22 01:00:06 +00:00
RString sEditName;
if( pSourceSteps )
2005-03-07 05:23:18 +00:00
{
2005-04-03 21:23:38 +00:00
pSteps->CopyFrom( pSourceSteps, st, pSong->m_fMusicLengthSeconds );
sEditName = GetCopyDescription(pSourceSteps);
2005-03-07 05:23:18 +00:00
}
else
{
pSteps->CreateBlank( st );
pSteps->SetMeter( 1 );
2006-01-18 10:03:45 +00:00
sEditName = BLANK;
}
pSteps->SetDifficulty( dc ); // override difficulty with the user's choice
2006-03-08 04:03:39 +00:00
SongUtil::MakeUniqueEditDescription( pSong, st, sEditName );
pSteps->SetDescription( sEditName );
pSong->AddSteps( pSteps );
SCREENMAN->PlayStartSound();
2005-03-06 00:08:48 +00:00
GAMESTATE->m_pCurSong.Set( pSong );
GAMESTATE->m_pCurSteps[0].Set( pSteps );
2006-08-18 07:11:51 +00:00
GAMESTATE->m_pCurCourse.Set( NULL );
2003-01-30 07:18:33 +00:00
}
break;
default:
ASSERT(0);
}
2005-03-21 03:45:14 +00:00
//
// Go to the next screen.
//
switch( action )
{
2005-12-01 03:20:25 +00:00
case EditMenuAction_Edit:
case EditMenuAction_Create:
case EditMenuAction_Practice:
2005-03-22 23:59:17 +00:00
{
// Prepare prepare for ScreenEdit
ASSERT( pSteps );
2005-12-01 03:20:25 +00:00
bool bPromptToNameSteps = (action == EditMenuAction_Create && dc == DIFFICULTY_EDIT);
2005-03-22 23:59:17 +00:00
if( bPromptToNameSteps )
{
ScreenTextEntry::TextEntry(
2005-03-23 04:08:27 +00:00
SM_BackFromEditDescription,
2005-12-21 12:55:20 +00:00
ENTER_EDIT_DESCRIPTION,
2005-03-23 04:08:27 +00:00
GAMESTATE->m_pCurSteps[0]->GetDescription(),
2005-07-29 02:23:02 +00:00
MAX_EDIT_STEPS_DESCRIPTION_LENGTH,
2006-03-08 04:03:39 +00:00
SongUtil::ValidateCurrentStepsDescription,
2005-03-23 04:08:27 +00:00
SetCurrentStepsDescription,
DeleteCurrentSteps );
2005-03-22 23:59:17 +00:00
}
else
{
SOUND->StopMusic();
SCREENMAN->PlayStartSound();
StartTransitioningScreen( SM_GoToNextScreen );
2005-03-22 23:59:17 +00:00
}
}
break;
2005-12-01 03:20:25 +00:00
case EditMenuAction_Delete:
break;
2003-01-30 07:18:33 +00:00
default:
ASSERT(0);
}
2002-05-20 08:59:37 +00:00
}
void ScreenEditMenu::MenuBack( PlayerNumber pn )
2002-05-20 08:59:37 +00:00
{
Cancel( SM_GoToPrevScreen );
2002-05-20 08:59:37 +00:00
2003-07-26 22:53:22 +00:00
SOUND->StopMusic();
2002-05-20 08:59:37 +00:00
}
2004-01-01 01:21:59 +00:00
2005-03-08 00:32:49 +00:00
void ScreenEditMenu::RefreshExplanationText()
{
m_textExplanation.SetText( EXPLANATION_TEXT(m_Selector.GetSelectedRow()) );
m_textExplanation.StopTweening();
ON_COMMAND( m_textExplanation );
}
2005-03-08 01:46:57 +00:00
void ScreenEditMenu::RefreshNumStepsLoadedFromProfile()
{
2006-01-22 01:00:06 +00:00
RString s = ssprintf( "edits used: %d", SONGMAN->GetNumStepsLoadedFromProfile() );
2005-03-08 01:46:57 +00:00
m_textNumStepsLoadedFromProfile.SetText( s );
}
2005-03-08 00:32:49 +00:00
2004-05-22 00:12:57 +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.
*/