block changes that insert a beat past the end

This commit is contained in:
Chris Danford
2005-04-02 21:59:27 +00:00
parent dc0f7d909a
commit 350ebdaeec
2 changed files with 37 additions and 14 deletions
+35 -13
View File
@@ -969,7 +969,7 @@ void ScreenEdit::InputEdit( const DeviceInput& DeviceI, const InputEventType typ
const float fOriginalBeat = GAMESTATE->m_fSongBeat;
float fDestinationBeat = GAMESTATE->m_fSongBeat + fBeatsToMove;
fDestinationBeat = Quantize( fDestinationBeat, NoteTypeToBeat(m_SnapDisplay.GetNoteType()) );
CLAMP( fDestinationBeat, 0, GetMaximumBeat() );
CLAMP( fDestinationBeat, 0, GetMaximumBeatForMoving() );
GAMESTATE->m_fSongBeat = fDestinationBeat;
@@ -2093,12 +2093,8 @@ void ScreenEdit::HandleAreaMenuChoice( AreaMenuChoice c, const vector<int> &iAns
default:
ASSERT(0);
}
int iRowsToCopy = m_Clipboard.GetLastRow()+1;
// Don't allow pasting past the maximum row
int iMaxRow = (GetMaximumBeat() == FLT_MAX) ? INT_MAX : BeatToNoteRow(GetMaximumBeat());
CLAMP( iRowsToCopy, 0, iMaxRow - iDestFirstRow + 1 );
int iRowsToCopy = m_Clipboard.GetLastRow()+1;
m_NoteDataEdit.CopyRange( m_Clipboard, 0, iRowsToCopy, iDestFirstRow );
}
break;
@@ -2621,9 +2617,28 @@ void ScreenEdit::CheckNumberOfNotesAndUndo()
return;
}
}
if( GAMESTATE->m_pCurSteps[0]->IsAnEdit() )
{
// Check that the action didn't push notes any farther past the last measure.
// This blocks Insert Beat from pushing past the end, but allows Delete Beat
// to pull back the notes that are already past the end.
float fNewLastBeat = m_NoteDataEdit.GetLastBeat();
bool bLastBeatIncreased = fNewLastBeat > m_Undo.GetLastBeat();
bool bPassedTheEnd = fNewLastBeat > GetMaximumBeatForNewNote();
if( bLastBeatIncreased && bPassedTheEnd )
{
Undo();
CString sError = ssprintf(
"This change creates notes past the end of the music and is not allowed.\n\nThe change has been reverted.",
MAX_NOTES_PER_MEASURE, MAX_NOTES_PER_MEASURE );
SCREENMAN->Prompt( SM_None, sError );
return;
}
}
}
float ScreenEdit::GetMaximumBeat() const
float ScreenEdit::GetMaximumBeatForNewNote() const
{
if( GAMESTATE->m_pCurSteps[0]->IsAnEdit() )
{
@@ -2635,12 +2650,6 @@ float ScreenEdit::GetMaximumBeat() const
fEndBeat += BEATS_PER_MEASURE;
fEndBeat = ftruncf( fEndBeat, (float)BEATS_PER_MEASURE );
// Jump to GetLastBeat even if it's past m_pCurSong->m_fLastBeat
// so that users can delete garbage steps past then end that they have
// have inserted in a text editor. Once they delete all steps on
// GetLastBeat() and move off of that beat, they won't be able to return.
fEndBeat = max( fEndBeat, GAMESTATE->m_pCurSong->m_fLastBeat );
return fEndBeat;
}
else
@@ -2649,6 +2658,19 @@ float ScreenEdit::GetMaximumBeat() const
}
}
float ScreenEdit::GetMaximumBeatForMoving() const
{
float fEndBeat = GetMaximumBeatForNewNote();
// Jump to GetLastBeat even if it's past m_pCurSong->m_fLastBeat
// so that users can delete garbage steps past then end that they have
// have inserted in a text editor. Once they delete all steps on
// GetLastBeat() and move off of that beat, they won't be able to return.
fEndBeat = max( fEndBeat, m_NoteDataEdit.GetLastBeat() );
return fEndBeat;
}
/*
* (c) 2001-2004 Chris Danford
* All rights reserved.
+2 -1
View File
@@ -155,7 +155,8 @@ protected:
void MenuItemGainFocus( BitmapText* menuitem );
void MenuItemLoseFocus( BitmapText* menuitem );
float GetMaximumBeat() const; // don't allow Down key to go past this beat.
float GetMaximumBeatForNewNote() const; // don't allow Down key to go past this beat.
float GetMaximumBeatForMoving() const; // don't allow Down key to go past this beat.
EditMode m_EditMode;