give new edits unique names

This commit is contained in:
Chris Danford
2005-03-07 05:23:18 +00:00
parent a07f0822d1
commit e65362e3f5
6 changed files with 79 additions and 34 deletions
+15 -24
View File
@@ -149,27 +149,6 @@ void ScreenEditMenu::MenuStart( PlayerNumber pn )
m_Selector.RefreshAll();
return;
case EditMenu::ACTION_COPY:
ASSERT( !pSteps );
ASSERT( pSourceSteps );
{
// Yuck. Doing the memory allocation doesn't seem right since
// Song allocates all of the other Steps.
Steps* pNewSteps = new Steps;
pNewSteps->CopyFrom( pSourceSteps, st );
pNewSteps->SetDifficulty( dc );
pNewSteps->SetDescription( GetCopyDescription(pSourceSteps) );
pSong->AddSteps( pNewSteps );
SCREENMAN->SystemMessage( "Steps created from copy." );
SOUND->PlayOnce( THEME->GetPathS(m_sName,"create") );
pSong->Save();
GAMESTATE->m_pCurSong.Set( pSong );
GAMESTATE->m_pCurSteps[0].Set( pNewSteps );
m_Selector.RefreshAll();
}
return;
case EditMenu::ACTION_AUTOGEN:
ASSERT( !pSteps );
ASSERT( pSourceSteps );
@@ -177,10 +156,22 @@ void ScreenEditMenu::MenuStart( PlayerNumber pn )
// Yuck. Doing the memory allocation doesn't seem right since
// Song allocates all of the other Steps.
Steps* pNewSteps = new Steps;
pNewSteps->AutogenFrom( pSourceSteps, st );
pNewSteps->DeAutogen();
switch( action )
{
case EditMenu::ACTION_COPY:
pNewSteps->CopyFrom( pSourceSteps, st );
break;
case EditMenu::ACTION_AUTOGEN:
pNewSteps->AutogenFrom( pSourceSteps, st );
pNewSteps->DeAutogen();
break;
default:
ASSERT(0);
}
pNewSteps->SetDifficulty( dc ); // override difficulty with the user's choice
pNewSteps->SetDescription( GetCopyDescription(pSourceSteps) );
CString sPreferredEditName = GetCopyDescription(pSourceSteps);
pSong->MakeUniqueEditDescription( st, sPreferredEditName );
pNewSteps->SetDescription( sPreferredEditName );
pSong->AddSteps( pNewSteps );
SCREENMAN->SystemMessage( "Steps created from AutoGen." );
+44 -3
View File
@@ -855,7 +855,7 @@ void Song::GetSteps(
}
}
Steps* Song::GetSteps(
Steps* Song::GetOneSteps(
StepsType st,
Difficulty dc,
int iMeterLow,
@@ -952,12 +952,12 @@ bool Song::SongCompleteForStyle( const Style *st ) const
bool Song::HasStepsType( StepsType st ) const
{
return GetSteps( st ) != NULL;
return GetOneSteps( st ) != NULL;
}
bool Song::HasStepsTypeAndDifficulty( StepsType st, Difficulty dc ) const
{
return GetSteps( st, dc ) != NULL;
return GetOneSteps( st, dc ) != NULL;
}
void Song::Save()
@@ -1404,6 +1404,47 @@ bool Song::HasSignificantBpmChangesOrStops() const
return m_Timing.HasBpmChangesOrStops();
}
bool IsEditDescriptionUnique( vector<Steps*> vSteps, StepsType st, CString sPreferredDescription )
{
FOREACH( Steps*, vSteps, s )
{
if( (*s)->GetDifficulty() != DIFFICULTY_EDIT )
continue;
if( (*s)->m_StepsType != st )
continue;
if( (*s)->GetDescription() == sPreferredDescription )
return false;
}
return true;
}
void Song::MakeUniqueEditDescription( StepsType st, CString &sPreferredDescriptionInOut )
{
if( IsEditDescriptionUnique( m_vpSteps, st, sPreferredDescriptionInOut ) )
return;
int i=0;
CString sTemp;
for( int i=0; i<1000; i++ )
{
// make name "My Edit" -> "My Edit"
CString sNum = ssprintf("%d", i+1);
sTemp = sPreferredDescriptionInOut.Left( MAX_DESCRIPTION_LENGTH - sNum.size() ) + sNum;
if( IsEditDescriptionUnique(m_vpSteps, st, sTemp) )
{
sPreferredDescriptionInOut = sTemp;
return;
}
}
// Edit limit guards should keep us from ever having more than 1000 edits per song.
return;
}
// lua start
#include "LuaBinding.h"
+11 -4
View File
@@ -31,8 +31,6 @@
#include "PrefsManager.h"
#include "NotesLoaderSM.h"
const int MAX_DESCRIPTION_LENGTH = 12;
Steps::Steps()
{
m_StepsType = STEPS_TYPE_INVALID;
@@ -303,8 +301,17 @@ void Steps::SetDescription(CString desc)
{
DeAutogen();
m_sDescription = desc;
if( int(m_sDescription.size()) > MAX_DESCRIPTION_LENGTH )
m_sDescription = m_sDescription.Left( MAX_DESCRIPTION_LENGTH );
MakeValidDescription( m_sDescription );
}
bool Steps::MakeValidDescription( CString &sPreferredDescription )
{
if( int(sPreferredDescription.size()) > MAX_DESCRIPTION_LENGTH )
{
sPreferredDescription = sPreferredDescription.Left( MAX_DESCRIPTION_LENGTH );
return true;
}
return false;
}
void Steps::SetDifficulty(Difficulty d)
+4
View File
@@ -12,6 +12,8 @@ class NoteData;
class Profile;
struct lua_State;
const int MAX_DESCRIPTION_LENGTH = 12;
class Steps
{
public:
@@ -40,6 +42,8 @@ public:
void SetFile( CString fn );
void SetDescription(CString desc);
static bool MakeValidDescription( CString &sPreferredDescription ); // return true if was modified
void SetDifficulty(Difficulty d);
void SetLoadedFromProfile( ProfileSlot slot ) { m_LoadedFromProfile = slot; }
void SetMeter(int meter);
+2 -2
View File
@@ -176,11 +176,11 @@ Steps *StepsID::ToSteps( const Song *p, bool bAllowNull, bool bUseCache ) const
Steps *ret = NULL;
if( dc == DIFFICULTY_EDIT )
{
ret = p->GetSteps( st, dc, -1, -1, sDescription, uHash, true );
ret = p->GetOneSteps( st, dc, -1, -1, sDescription, uHash, true );
}
else
{
ret = p->GetSteps( st, dc, -1, -1, "", 0, true );
ret = p->GetOneSteps( st, dc, -1, -1, "", 0, true );
}
if( !bAllowNull && ret == NULL )
+3 -1
View File
@@ -189,7 +189,7 @@ public:
unsigned uHash = 0,
int iMaxToGet = -1
) const;
Steps* GetSteps(
Steps* GetOneSteps(
StepsType st = STEPS_TYPE_INVALID,
Difficulty dc = DIFFICULTY_INVALID,
int iMeterLow = -1,
@@ -219,6 +219,8 @@ public:
int GetNumStepsLoadedFromProfile( ProfileSlot slot ) const;
bool IsEditAlreadyLoaded( Steps* pSteps ) const;
void MakeUniqueEditDescription( StepsType st, CString &sPreferredDescriptionInOut );
// An array of keysound file names (e.g. "beep.wav").
// The index in this array corresponds to the index in TapNote. If you
// change the index in here, you must change all NoteData too.