From c5570839d913f6b0843a21733155e1bc16400e06 Mon Sep 17 00:00:00 2001 From: "Peter S. May" Date: Tue, 16 Jul 2002 18:38:12 +0000 Subject: [PATCH] The changes I have made have mostly to do with the Edit mode, but do pay attention, because one of my code additions might save you some work in the future. * NotesTypeToStyle(nt) and StyleToNotesType(s) Look in GameConstantsAndTypes.h for these two new functions. Essentially, they provide a centralized automation for the NotesType/Style switch() tables in several functions. On top of that, I've even included a Perl script which will actually rewrite the two functions for you - all you have to do is keep the array at the beginning of the script updated, then run the script and paste the results. See the notes in GameConstantsAndTypes.h for details. * Changes in ScreenEditMenu and ScreenEdit I changed ScreenEditMenu and ScreenEdit in order to correct a bug that made it so that in Edit mode, when working with a (NEW) sequence (previously created sequences were not affected), no matter which style was selected, it was only possible to edit the leftmost four arrows of the style. This made creating ez2-single, pump-single, and dance-solo (among others) impractical (one would have to manually add a new section to the .sm file with the correct number of columns; then it would be editable). The change made to ScreenEditMenu is only to update the NotesType to Style conversion; the former switch() table in HandleScreenMessage() was already out of date and unable to support EZ2 styles/types. The change made to ScreenEdit changes the m_NotesType of the freshly initialized Notes object. In Notes::Notes(), m_NotesType is initialized to NOTES_TYPE_DANCE_SINGLE (hence the locking to four arrows). My addition changes m_NotesType to reflect the selection made in ScreenEditMenu. Word up. - Dro - --- stepmania/src/GameConstantsAndTypes.h | 194 ++++++++++++++++++++++++++ stepmania/src/ScreenEdit.cpp | 16 +++ stepmania/src/ScreenEditMenu.cpp | 24 ++-- 3 files changed, 225 insertions(+), 9 deletions(-) diff --git a/stepmania/src/GameConstantsAndTypes.h b/stepmania/src/GameConstantsAndTypes.h index 2411c95b1e..5c4c6f155d 100644 --- a/stepmania/src/GameConstantsAndTypes.h +++ b/stepmania/src/GameConstantsAndTypes.h @@ -343,6 +343,200 @@ inline Game StyleToGame( Style s ) } } +//////////////////////////////// +// NotesType/Style conversions +//////////////////////////////// + +// Dro Kulix: This part really is necessary. +// Several subroutines call for conversions between +// NotesType and Style, both ways. It would make +// things a bit easier to keep them central. + +// The next two functions have self-explanatory +// names, NotesTypeToStyle(nt) and +// StyleToNotesType(s). + +// Both of these functions involve a tedious +// switch-based one-to-one mapping between +// NotesTypes and Styles. I have written a +// Perl script which will actually write both +// of the functions for you. All you need to do +// is keep updated the list of Styles and +// NotesTypes near the beginning of the script. + +// If you need a copy of Perl for Win32, +// http://www.activeperl.com/Products/ActivePerl/ +// will suit nicely. + +/* + +Begin Perl file -> + +# StyleNotesType.pl + +# Perl script to write StyleToNotesType and +# NotesTypeToStyle functions for StepMania. + +# Usage: perl StyleNotesType.pl > code.txt +# (outputs C++ functions to file code.txt) + +# Keep the following list updated to produce +# correct code. + +# First column is Styles, second is NotesTypes. + +# These mapping sequences only make the first possible +# mapping. That is, STYLE_DANCE_SINGLE will map to +# NOTES_TYPE_DANCE_SINGLE, and STYLE_DANCE_VERSUS will +# map to NOTES_TYPE_DANCE_SINGLE, but +# NOTES_TYPE_DANCE_SINGLE will only map to +# STYLE_DANCE_SINGLE. + +my @Types = qw[ + DANCE_SINGLE DANCE_SINGLE + DANCE_VERSUS DANCE_SINGLE + DANCE_DOUBLE DANCE_DOUBLE + DANCE_COUPLE DANCE_COUPLE + DANCE_SOLO DANCE_SOLO + PUMP_SINGLE PUMP_SINGLE + PUMP_VERSUS PUMP_SINGLE + PUMP_DOUBLE PUMP_DOUBLE + EZ2_SINGLE EZ2_SINGLE + EZ2_DOUBLE EZ2_DOUBLE + EZ2_REAL EZ2_REAL + EZ2_SINGLE_VERSUS EZ2_SINGLE_VERSUS + EZ2_REAL_VERSUS EZ2_REAL_VERSUS + NONE INVALID +]; + + + +my %StyleToNotesType = (); +{ + my @tmpTypes = @Types; + # Map Style to NotesType + while (@tmpTypes) { + my $key = shift(@tmpTypes); + my $value = shift(@tmpTypes); + if (!exists($StyleToNotesType{$key})) { + $StyleToNotesType{$key} = $value; + } + } +} + +my %NotesTypeToStyle = (); +{ + my @tmpTypes = @Types; + # Map NotesType to Style + while (@tmpTypes) { + my $value = shift(@tmpTypes); + my $key = shift(@tmpTypes); + if (!exists($NotesTypeToStyle{$key})) { + $NotesTypeToStyle{$key} = $value; + } + } +} + +# Produce NotesTypeToStyle +print " +// +// NotesTypeToStyle(nt): Converts nt to a Style +// +inline Style NotesTypeToStyle ( NotesType nt ) +{ + switch ( nt ) + { +"; + +foreach (sort keys %NotesTypeToStyle) { + my $key = "NOTES_TYPE_$_"; + my $value = 'STYLE_' . $NotesTypeToStyle{$_}; + print "\t\tcase $key:\treturn $value;\n"; +} + +print "\t\tdefault:\treturn STYLE_NONE; + } +} +"; + +# Produce StyleToNotesType +print " +// +// StyleToNotesType(s): Converts s to a NotesType +// +inline NotesType StyleToNotesType ( Style s ) +{ + switch ( s ) + { +"; + +foreach (sort keys %StyleToNotesType) { + my $key = "STYLE_$_"; + my $value = 'NOTES_TYPE_' . $StyleToNotesType{$_}; + print "\t\tcase $key:\treturn $value;\n"; +} + +print "\t\tdefault:\treturn NOTES_TYPE_INVALID; + } +} +"; + +# Finished. + +<- End of Perl file +*/ + + +// +// NotesTypeToStyle(nt): Converts nt to a Style +// +inline Style NotesTypeToStyle ( NotesType nt ) +{ + switch ( nt ) + { + case NOTES_TYPE_DANCE_COUPLE: return STYLE_DANCE_COUPLE; + case NOTES_TYPE_DANCE_DOUBLE: return STYLE_DANCE_DOUBLE; + case NOTES_TYPE_DANCE_SINGLE: return STYLE_DANCE_SINGLE; + case NOTES_TYPE_DANCE_SOLO: return STYLE_DANCE_SOLO; + case NOTES_TYPE_EZ2_DOUBLE: return STYLE_EZ2_DOUBLE; + case NOTES_TYPE_EZ2_REAL: return STYLE_EZ2_REAL; + case NOTES_TYPE_EZ2_REAL_VERSUS: return STYLE_EZ2_REAL_VERSUS; + case NOTES_TYPE_EZ2_SINGLE: return STYLE_EZ2_SINGLE; + case NOTES_TYPE_EZ2_SINGLE_VERSUS: return STYLE_EZ2_SINGLE_VERSUS; + case NOTES_TYPE_INVALID: return STYLE_NONE; + case NOTES_TYPE_PUMP_DOUBLE: return STYLE_PUMP_DOUBLE; + case NOTES_TYPE_PUMP_SINGLE: return STYLE_PUMP_SINGLE; + default: return STYLE_NONE; + } +} + +// +// StyleToNotesType(s): Converts s to a NotesType +// +inline NotesType StyleToNotesType ( Style s ) +{ + switch ( s ) + { + case STYLE_DANCE_COUPLE: return NOTES_TYPE_DANCE_COUPLE; + case STYLE_DANCE_DOUBLE: return NOTES_TYPE_DANCE_DOUBLE; + case STYLE_DANCE_SINGLE: return NOTES_TYPE_DANCE_SINGLE; + case STYLE_DANCE_SOLO: return NOTES_TYPE_DANCE_SOLO; + case STYLE_DANCE_VERSUS: return NOTES_TYPE_DANCE_SINGLE; + case STYLE_EZ2_DOUBLE: return NOTES_TYPE_EZ2_DOUBLE; + case STYLE_EZ2_REAL: return NOTES_TYPE_EZ2_REAL; + case STYLE_EZ2_REAL_VERSUS: return NOTES_TYPE_EZ2_REAL_VERSUS; + case STYLE_EZ2_SINGLE: return NOTES_TYPE_EZ2_SINGLE; + case STYLE_EZ2_SINGLE_VERSUS: return NOTES_TYPE_EZ2_SINGLE_VERSUS; + case STYLE_NONE: return NOTES_TYPE_INVALID; + case STYLE_PUMP_DOUBLE: return NOTES_TYPE_PUMP_DOUBLE; + case STYLE_PUMP_SINGLE: return NOTES_TYPE_PUMP_SINGLE; + case STYLE_PUMP_VERSUS: return NOTES_TYPE_PUMP_SINGLE; + default: return NOTES_TYPE_INVALID; + } +} + + + /////////////////////////// // Options stuff /////////////////////////// diff --git a/stepmania/src/ScreenEdit.cpp b/stepmania/src/ScreenEdit.cpp index 3026725d5b..448193dd66 100644 --- a/stepmania/src/ScreenEdit.cpp +++ b/stepmania/src/ScreenEdit.cpp @@ -93,6 +93,22 @@ ScreenEdit::ScreenEdit() if( m_pNotes == NULL ) { m_pNotes = new Notes; + // Dro Kulix: If m_pNotes->m_NotesType is not changed here, + // the edit mode is somehow stuck only being able to edit + // the first four columns of a (NEW) sequence. + // I've determined that this is because m_NotesType is + // initialized in the constructor as + // NOTES_TYPE_DANCE_SINGLE. For minimal impact, I am + // changing m_NotesType here, but at some point we + // may want to consider changing it in the Notes + // constructor, if another reason to do so pops up... + + // In ScreenEditMenu, the screen preceding this one, + // GAMEMAN->m_CurStyle is set to the target game style + // of the current edit. Naturally, this is where we'll + // want to extract the NotesType for a (NEW) sequence. + m_pNotes->m_NotesType = StyleToNotesType( GAMEMAN->m_CurStyle ); + m_pSong->m_apNotes.Add( m_pNotes ); } diff --git a/stepmania/src/ScreenEditMenu.cpp b/stepmania/src/ScreenEditMenu.cpp index 2bd7621ee0..f462a902f9 100644 --- a/stepmania/src/ScreenEditMenu.cpp +++ b/stepmania/src/ScreenEditMenu.cpp @@ -162,15 +162,21 @@ void ScreenEditMenu::HandleScreenMessage( const ScreenMessage SM ) break; case SM_GoToNextState: // set the current style based on the notes type - switch( GetSelectedNotesType() ) - { - case NOTES_TYPE_DANCE_SINGLE: GAMEMAN->m_CurStyle = STYLE_DANCE_SINGLE; break; - case NOTES_TYPE_DANCE_DOUBLE: GAMEMAN->m_CurStyle = STYLE_DANCE_DOUBLE; break; - case NOTES_TYPE_DANCE_COUPLE: GAMEMAN->m_CurStyle = STYLE_DANCE_COUPLE; break; - case NOTES_TYPE_DANCE_SOLO: GAMEMAN->m_CurStyle = STYLE_DANCE_SOLO; break; - case NOTES_TYPE_PUMP_SINGLE: GAMEMAN->m_CurStyle = STYLE_PUMP_SINGLE; break; - case NOTES_TYPE_PUMP_DOUBLE: GAMEMAN->m_CurStyle = STYLE_PUMP_DOUBLE; break; - } + + //switch( GetSelectedNotesType() ) + //{ + //case NOTES_TYPE_DANCE_SINGLE: GAMEMAN->m_CurStyle = STYLE_DANCE_SINGLE; break; + //case NOTES_TYPE_DANCE_DOUBLE: GAMEMAN->m_CurStyle = STYLE_DANCE_DOUBLE; break; + //case NOTES_TYPE_DANCE_COUPLE: GAMEMAN->m_CurStyle = STYLE_DANCE_COUPLE; break; + //case NOTES_TYPE_DANCE_SOLO: GAMEMAN->m_CurStyle = STYLE_DANCE_SOLO; break; + //case NOTES_TYPE_PUMP_SINGLE: GAMEMAN->m_CurStyle = STYLE_PUMP_SINGLE; break; + //case NOTES_TYPE_PUMP_DOUBLE: GAMEMAN->m_CurStyle = STYLE_PUMP_DOUBLE; break; + //} + + // Dro Kulix: + // A centralized solution for this switching mess... + // (See GameConstantsAndTypes.h) + GAMEMAN->m_CurStyle = NotesTypeToStyle( GetSelectedNotesType() ); SCREENMAN->SetNewScreen( new ScreenEdit ); break;