Files
itgmania212121/stepmania/src/OptionRowHandler.cpp
T

1289 lines
36 KiB
C++
Raw Normal View History

#include "global.h"
#include "OptionRowHandler.h"
#include "LuaManager.h"
#include "ScreenOptionsMasterPrefs.h"
#include "NoteSkinManager.h"
#include "RageUtil.h"
#include "RageLog.h"
#include "GameState.h"
#include "Course.h"
#include "Steps.h"
#include "Style.h"
#include "song.h"
#include "SongManager.h"
#include "Character.h"
#include "PrefsManager.h"
#include "StepsUtil.h"
#include "GameManager.h"
#include "Foreach.h"
2005-02-26 11:21:50 +00:00
#include "ScreenManager.h"
#include "GameSoundManager.h"
#define ENTRY(s) THEME->GetMetric ("ScreenOptionsMaster",s)
#define ENTRY_MODE(s,i) THEME->GetMetric ("ScreenOptionsMaster",ssprintf("%s,%i",(s).c_str(),(i+1)))
#define ENTRY_DEFAULT(s) THEME->GetMetric ("ScreenOptionsMaster",(s) + "Default")
2005-02-24 11:36:19 +00:00
#define STEPS_TYPES_TO_HIDE THEME->GetMetric ("OptionRowHandler","StepsTypesToHide")
static void SelectExactlyOne( int iSelection, vector<bool> &vbSelectedOut )
{
for( int i=0; i<(int)vbSelectedOut.size(); i++ )
vbSelectedOut[i] = i==iSelection;
}
static int GetOneSelection( const vector<bool> &vbSelected )
{
2005-03-05 08:33:59 +00:00
int iRet = -1;
for( unsigned i=0; i<vbSelected.size(); i++ )
2005-03-05 08:33:59 +00:00
{
if( vbSelected[i] )
2005-03-05 08:33:59 +00:00
{
ASSERT( iRet == -1 ); // only one should be selected
iRet = i;
}
}
ASSERT( iRet != -1 ); // shouldn't call this if not expecting one to be selected
return iRet;
}
class OptionRowHandlerList : public OptionRowHandler
{
public:
vector<GameCommand> ListEntries;
GameCommand Default;
bool m_bUseModNameForIcon;
2005-03-01 01:15:22 +00:00
vector<CString> m_vsBroadcastOnExport;
OptionRowHandlerList::OptionRowHandlerList() { Init(); }
virtual void Init()
{
OptionRowHandler::Init();
ListEntries.clear();
Default.Init();
m_bUseModNameForIcon = false;
2005-03-01 01:15:22 +00:00
m_vsBroadcastOnExport.clear();
}
2005-02-25 05:44:56 +00:00
virtual void Load( OptionRowDefinition &defOut, CString sParam )
{
ASSERT( sParam.size() );
if( sParam.CompareNoCase("NoteSkins")==0 ) { FillNoteSkins( defOut, sParam ); return; }
else if( sParam.CompareNoCase("Steps")==0 ) { FillSteps( defOut, sParam ); return; }
else if( sParam.CompareNoCase("EditsAndNull")==0 ) { FillEditsAndNull( defOut, sParam ); return; }
else if( sParam.CompareNoCase("Characters")==0 ) { FillCharacters( defOut, sParam ); return; }
else if( sParam.CompareNoCase("Styles")==0 ) { FillStyles( defOut, sParam ); return; }
else if( sParam.CompareNoCase("Groups")==0 ) { FillGroups( defOut, sParam ); return; }
else if( sParam.CompareNoCase("Difficulties")==0 ) { FillDifficulties( defOut, sParam ); return; }
else if( sParam.CompareNoCase("SongsInCurrentSongGroup")==0 ) { FillSongsInCurrentSongGroup( defOut, sParam ); return; }
Init();
defOut.Init();
m_bUseModNameForIcon = true;
defOut.name = sParam;
Default.Load( -1, ParseCommands(ENTRY_DEFAULT(sParam)) );
/* Parse the basic configuration metric. */
Commands cmds = ParseCommands( ENTRY(sParam) );
if( cmds.v.size() < 1 )
RageException::Throw( "Parse error in OptionRowHandlerUtilEntries::ListName%s", sParam.c_str() );
defOut.bOneChoiceForAllPlayers = false;
const int NumCols = atoi( cmds.v[0].m_vsArgs[0] );
for( unsigned i=1; i<cmds.v.size(); i++ )
{
const Command &cmd = cmds.v[i];
CString sName = cmd.GetName();
if( sName == "together" ) defOut.bOneChoiceForAllPlayers = true;
else if( sName == "selectmultiple" ) defOut.selectType = SELECT_MULTIPLE;
else if( sName == "selectnone" ) defOut.selectType = SELECT_NONE;
else if( sName == "showoneinrow" ) defOut.layoutType = LAYOUT_SHOW_ONE_IN_ROW;
else if( sName == "reloadrowmessages" )
{
for( unsigned a=1; a<cmd.m_vsArgs.size(); a++ )
m_vsReloadRowMessages.push_back( cmd.m_vsArgs[a] );
}
else if( sName == "enabledforplayers" )
{
defOut.m_vEnabledForPlayers.clear();
for( unsigned a=1; a<cmd.m_vsArgs.size(); a++ )
{
CString sArg = cmd.m_vsArgs[a];
PlayerNumber pn = (PlayerNumber)(atoi(sArg)-1);
ASSERT( pn >= 0 && pn < NUM_PLAYERS );
defOut.m_vEnabledForPlayers.insert( pn );
}
}
else if( sName == "exportonchange" ) defOut.m_bExportOnChange = true;
2005-03-01 01:15:22 +00:00
else if( sName == "broadcastonexport" )
{
for( unsigned i=1; i<cmd.m_vsArgs.size(); i++ )
m_vsBroadcastOnExport.push_back( cmd.m_vsArgs[i] );
}
2005-02-25 05:44:56 +00:00
else RageException::Throw( "Unkown row flag \"%s\"", sName.c_str() );
}
for( int col = 0; col < NumCols; ++col )
{
GameCommand mc;
mc.Load( 0, ParseCommands(ENTRY_MODE(sParam, col)) );
if( mc.m_sName == "" )
RageException::Throw( "List \"%s\", col %i has no name", sParam.c_str(), col );
if( !mc.IsPlayable() )
continue;
ListEntries.push_back( mc );
CString sName = mc.m_sName;
CString sChoice = ENTRY_NAME(mc.m_sName);
defOut.choices.push_back( sChoice );
}
}
void ImportOption( const OptionRowDefinition &def, PlayerNumber pn, vector<bool> &vbSelectedOut ) const
{
int FallbackOption = -1;
bool UseFallbackOption = true;
for( unsigned e = 0; e < ListEntries.size(); ++e )
{
const GameCommand &mc = ListEntries[e];
vbSelectedOut[e] = false;
if( mc.IsZero() )
{
/* The entry has no effect. This is usually a default "none of the
* above" entry. It will always return true for DescribesCurrentMode().
* It's only the selected choice if nothing else matches. */
if( def.selectType != SELECT_MULTIPLE )
FallbackOption = e;
continue;
}
if( def.bOneChoiceForAllPlayers )
{
if( mc.DescribesCurrentModeForAllPlayers() )
{
UseFallbackOption = false;
if( def.selectType != SELECT_MULTIPLE )
SelectExactlyOne( e, vbSelectedOut );
else
vbSelectedOut[e] = true;
}
}
else
{
if( mc.DescribesCurrentMode( pn) )
{
UseFallbackOption = false;
if( def.selectType != SELECT_MULTIPLE )
SelectExactlyOne( e, vbSelectedOut );
else
vbSelectedOut[e] = true;
}
}
}
if( def.selectType == SELECT_ONE &&
UseFallbackOption &&
FallbackOption != -1 )
{
SelectExactlyOne( FallbackOption, vbSelectedOut );
}
}
int ExportOption( const OptionRowDefinition &def, PlayerNumber pn, const vector<bool> &vbSelected ) const
{
Default.Apply( pn );
for( unsigned i=0; i<vbSelected.size(); i++ )
2005-03-01 01:15:22 +00:00
{
2005-02-25 05:44:56 +00:00
if( vbSelected[i] )
ListEntries[i].Apply( pn );
2005-03-01 01:15:22 +00:00
}
FOREACH_CONST( CString, m_vsBroadcastOnExport, s )
MESSAGEMAN->Broadcast( *s );
2005-02-25 05:44:56 +00:00
return 0;
}
virtual CString GetIconText( const OptionRowDefinition &def, int iFirstSelection ) const
{
return m_bUseModNameForIcon ?
ListEntries[iFirstSelection].m_sModifiers :
def.choices[iFirstSelection];
}
virtual CString GetAndEraseScreen( int iChoice )
{
GameCommand &mc = ListEntries[iChoice];
if( mc.m_sScreen != "" )
{
/* Hack: instead of applying screen commands here, store them in
* m_sNextScreen and apply them after we tween out. If we don't set
* m_sScreen to "", we'll load it twice (once for each player) and
* then again for m_sNextScreen. */
CString sNextScreen = mc.m_sScreen;
mc.m_sScreen = "";
return sNextScreen;
}
return "";
}
2005-02-24 06:33:50 +00:00
2005-02-25 05:44:56 +00:00
void FillNoteSkins( OptionRowDefinition &defOut, CString sParam )
{
2005-02-25 05:44:56 +00:00
Init();
defOut.Init();
2005-02-25 05:44:56 +00:00
ASSERT( sParam.size() );
m_sName = sParam;
2005-02-25 05:44:56 +00:00
defOut.name = "NoteSkins";
defOut.bOneChoiceForAllPlayers = false;
2005-02-25 05:44:56 +00:00
CStringArray arraySkinNames;
NOTESKIN->GetNoteSkinNames( arraySkinNames );
for( unsigned skin=0; skin<arraySkinNames.size(); skin++ )
{
arraySkinNames[skin].MakeUpper();
2005-02-24 11:36:19 +00:00
2005-02-25 05:44:56 +00:00
GameCommand mc;
mc.m_sModifiers = arraySkinNames[skin];
ListEntries.push_back( mc );
defOut.choices.push_back( arraySkinNames[skin] );
}
2005-02-24 11:36:19 +00:00
}
2005-02-25 05:44:56 +00:00
void FillSteps( OptionRowDefinition &defOut, CString sParam )
2005-02-24 11:36:19 +00:00
{
Init();
defOut.Init();
2005-02-25 05:44:56 +00:00
ASSERT( sParam.size() );
2005-02-24 11:36:19 +00:00
m_sName = sParam;
2005-02-25 05:44:56 +00:00
defOut.name = "Steps";
defOut.bOneChoiceForAllPlayers = false;
2005-02-24 11:36:19 +00:00
2005-02-25 05:44:56 +00:00
// fill in difficulty names
if( GAMESTATE->m_bEditing )
2005-02-24 11:36:19 +00:00
{
2005-02-25 05:44:56 +00:00
defOut.choices.push_back( "" );
ListEntries.push_back( GameCommand() );
2005-02-24 11:36:19 +00:00
}
2005-02-25 05:44:56 +00:00
else if( GAMESTATE->IsCourseMode() ) // playing a course
2005-02-24 11:36:19 +00:00
{
2005-02-25 05:44:56 +00:00
defOut.bOneChoiceForAllPlayers = PREFSMAN->m_bLockCourseDifficulties;
2005-02-24 11:36:19 +00:00
2005-02-25 05:44:56 +00:00
vector<Trail*> vTrails;
GAMESTATE->m_pCurCourse->GetTrails( vTrails, GAMESTATE->GetCurrentStyle()->m_StepsType );
for( unsigned i=0; i<vTrails.size(); i++ )
{
2005-02-25 05:44:56 +00:00
Trail* pTrail = vTrails[i];
CString s = CourseDifficultyToThemedString( pTrail->m_CourseDifficulty );
defOut.choices.push_back( s );
GameCommand mc;
mc.m_pTrail = pTrail;
ListEntries.push_back( mc );
}
}
2005-02-25 05:44:56 +00:00
else // !GAMESTATE->IsCourseMode(), playing a song
{
vector<Steps*> vSteps;
GAMESTATE->m_pCurSong->GetSteps( vSteps, GAMESTATE->GetCurrentStyle()->m_StepsType );
StepsUtil::SortNotesArrayByDifficulty( vSteps );
for( unsigned i=0; i<vSteps.size(); i++ )
{
Steps* pSteps = vSteps[i];
2005-02-24 11:36:19 +00:00
2005-02-25 05:44:56 +00:00
CString s;
if( pSteps->GetDifficulty() == DIFFICULTY_EDIT )
s = pSteps->GetDescription();
else
s = DifficultyToThemedString( pSteps->GetDifficulty() );
defOut.choices.push_back( s );
GameCommand mc;
mc.m_pSteps = pSteps;
mc.m_dc = pSteps->GetDifficulty();
ListEntries.push_back( mc );
}
}
2005-02-24 11:36:19 +00:00
}
2005-02-25 05:44:56 +00:00
void FillEditsAndNull( OptionRowDefinition &defOut, CString sParam )
2005-02-24 11:36:19 +00:00
{
Init();
defOut.Init();
2005-02-25 05:44:56 +00:00
ASSERT( sParam.size() );
2005-02-24 11:36:19 +00:00
m_sName = sParam;
2005-02-25 05:44:56 +00:00
defOut.name = "EditsAndNull";
2005-02-24 11:36:19 +00:00
defOut.bOneChoiceForAllPlayers = true;
defOut.layoutType = LAYOUT_SHOW_ONE_IN_ROW;
defOut.m_bExportOnChange = true;
m_vsReloadRowMessages.push_back( MessageToString(MESSAGE_CURRENT_SONG_CHANGED) );
2005-02-25 19:38:53 +00:00
m_vsReloadRowMessages.push_back( MessageToString(MESSAGE_EDIT_STEPS_TYPE_CHANGED) );
2005-02-24 11:36:19 +00:00
2005-02-25 05:44:56 +00:00
if( GAMESTATE->m_pCurSong != NULL )
2005-02-24 11:36:19 +00:00
{
2005-02-25 05:44:56 +00:00
vector<Steps*> vSteps;
GAMESTATE->m_pCurSong->GetSteps( vSteps, GAMESTATE->m_stEdit, DIFFICULTY_EDIT );
StepsUtil::SortNotesArrayByDifficulty( vSteps );
FOREACH_CONST( Steps*, vSteps, p )
{
CString s = (*p)->GetDescription();
defOut.choices.push_back( s );
GameCommand mc;
mc.m_pSteps = *p;
ListEntries.push_back( mc );
}
2005-02-24 11:36:19 +00:00
}
2005-02-25 05:44:56 +00:00
// Add NULL entry for a new edit
{
2005-02-25 05:44:56 +00:00
defOut.choices.push_back( ENTRY_NAME("NewEdit") );
GameCommand mc;
ListEntries.push_back( mc );
}
}
2005-02-24 11:36:19 +00:00
2005-02-25 05:44:56 +00:00
void FillCharacters( OptionRowDefinition &defOut, CString sParam )
{
2005-02-25 05:44:56 +00:00
Init();
defOut.Init();
2005-02-25 05:44:56 +00:00
ASSERT( sParam.size() );
m_sName = sParam;
2005-02-25 05:44:56 +00:00
defOut.bOneChoiceForAllPlayers = false;
defOut.name = "Characters";
Default.m_pCharacter = GAMESTATE->GetDefaultCharacter();
{
2005-02-25 05:44:56 +00:00
defOut.choices.push_back( ENTRY_NAME("Off") );
GameCommand mc;
mc.m_pCharacter = NULL;
ListEntries.push_back( mc );
}
2005-02-25 05:44:56 +00:00
vector<Character*> apCharacters;
GAMESTATE->GetCharacters( apCharacters );
for( unsigned i=0; i<apCharacters.size(); i++ )
{
2005-02-25 05:44:56 +00:00
Character* pCharacter = apCharacters[i];
CString s = pCharacter->m_sName;
s.MakeUpper();
defOut.choices.push_back( s );
GameCommand mc;
mc.m_pCharacter = pCharacter;
ListEntries.push_back( mc );
}
}
2005-02-25 05:44:56 +00:00
void FillStyles( OptionRowDefinition &defOut, CString sParam )
{
2005-02-25 05:44:56 +00:00
Init();
defOut.Init();
2005-02-25 05:44:56 +00:00
ASSERT( sParam.size() );
m_sName = sParam;
2005-02-25 05:44:56 +00:00
defOut.bOneChoiceForAllPlayers = true;
defOut.name = "Style";
defOut.bOneChoiceForAllPlayers = true;
2005-02-25 05:44:56 +00:00
vector<const Style*> vStyles;
GAMEMAN->GetStylesForGame( GAMESTATE->m_pCurGame, vStyles );
ASSERT( vStyles.size() );
FOREACH_CONST( const Style*, vStyles, s )
{
defOut.choices.push_back( GAMEMAN->StyleToThemedString(*s) );
GameCommand mc;
mc.m_pStyle = *s;
ListEntries.push_back( mc );
}
2005-02-25 05:44:56 +00:00
Default.m_pStyle = vStyles[0];
}
2005-02-25 05:44:56 +00:00
void FillGroups( OptionRowDefinition &defOut, CString sParam )
{
Init();
defOut.Init();
2005-02-25 05:44:56 +00:00
ASSERT( sParam.size() );
m_sName = sParam;
2005-02-25 05:44:56 +00:00
defOut.bOneChoiceForAllPlayers = true;
defOut.name = "Group";
Default.m_sSongGroup = GROUP_ALL_MUSIC;
2005-02-25 05:44:56 +00:00
vector<CString> vGroups;
SONGMAN->GetGroupNames( vGroups );
ASSERT( vGroups.size() );
2005-02-25 05:44:56 +00:00
{
defOut.choices.push_back( ENTRY_NAME("AllGroups") );
GameCommand mc;
mc.m_sSongGroup = GROUP_ALL_MUSIC;
ListEntries.push_back( mc );
}
2005-02-25 05:44:56 +00:00
FOREACH_CONST( CString, vGroups, g )
{
defOut.choices.push_back( *g );
GameCommand mc;
mc.m_sSongGroup = *g;
ListEntries.push_back( mc );
}
}
2005-02-25 05:44:56 +00:00
void FillDifficulties( OptionRowDefinition &defOut, CString sParam )
{
Init();
defOut.Init();
2005-02-25 05:44:56 +00:00
ASSERT( sParam.size() );
m_sName = sParam;
2005-02-25 05:44:56 +00:00
set<Difficulty> vDifficulties;
GAMESTATE->GetDifficultiesToShow( vDifficulties );
2005-02-25 05:44:56 +00:00
defOut.bOneChoiceForAllPlayers = true;
defOut.name = "Difficulty";
Default.m_dc = DIFFICULTY_INVALID;
2005-02-25 05:44:56 +00:00
{
defOut.choices.push_back( ENTRY_NAME("AllDifficulties") );
GameCommand mc;
mc.m_dc = DIFFICULTY_INVALID;
ListEntries.push_back( mc );
}
2005-02-25 05:44:56 +00:00
FOREACHS_CONST( Difficulty, vDifficulties, d )
{
CString s = DifficultyToThemedString( *d );
2005-02-25 05:44:56 +00:00
defOut.choices.push_back( s );
GameCommand mc;
mc.m_dc = *d;
ListEntries.push_back( mc );
}
}
2005-02-25 05:44:56 +00:00
void FillSongsInCurrentSongGroup( OptionRowDefinition &defOut, CString sParam )
{
Init();
defOut.Init();
2005-02-25 05:44:56 +00:00
ASSERT( sParam.size() );
m_sName = sParam;
2005-02-25 05:44:56 +00:00
vector<Song*> vpSongs;
SONGMAN->GetSongs( vpSongs, GAMESTATE->m_sPreferredSongGroup );
2005-02-25 05:44:56 +00:00
if( GAMESTATE->m_pCurSong == NULL )
GAMESTATE->m_pCurSong.Set( vpSongs[0] );
2005-02-25 05:44:56 +00:00
defOut.name = "SongsInCurrentSongGroup";
defOut.bOneChoiceForAllPlayers = true;
defOut.layoutType = LAYOUT_SHOW_ONE_IN_ROW;
defOut.m_bExportOnChange = true;
2005-02-25 05:44:56 +00:00
FOREACH_CONST( Song*, vpSongs, p )
{
defOut.choices.push_back( (*p)->GetFullTranslitTitle() );
GameCommand mc;
mc.m_pSong = *p;
ListEntries.push_back( mc );
}
}
};
2005-02-25 05:44:56 +00:00
class OptionRowHandlerLua : public OptionRowHandler
{
2005-02-25 05:44:56 +00:00
public:
LuaExpression *m_pLuaTable;
2005-03-07 22:23:14 +00:00
OptionRowHandlerLua() { m_pLuaTable = new LuaExpression; Init(); }
virtual ~OptionRowHandlerLua() { delete m_pLuaTable; }
2005-02-25 05:44:56 +00:00
void Init()
{
OptionRowHandler::Init();
2005-03-07 22:23:14 +00:00
m_pLuaTable->Unset();
2005-02-25 05:44:56 +00:00
}
virtual void Load( OptionRowDefinition &defOut, CString sLuaFunction )
{
ASSERT( sLuaFunction.size() );
2005-02-25 05:44:56 +00:00
Init();
defOut.Init();
2005-02-25 05:44:56 +00:00
m_sName = sLuaFunction;
// m_bUseModNameForIcon = true;
2005-02-25 05:44:56 +00:00
/* Run the Lua expression. It should return a table. */
m_pLuaTable->SetFromExpression( sLuaFunction );
2005-02-25 05:44:56 +00:00
if( m_pLuaTable->GetLuaType() != LUA_TTABLE )
RageException::Throw( "Result of \"%s\" is not a table", sLuaFunction.c_str() );
2005-02-25 05:44:56 +00:00
{
m_pLuaTable->PushSelf( LUA->L );
lua_pushstring( LUA->L, "Name" );
lua_gettable( LUA->L, -2 );
const char *pStr = lua_tostring( LUA->L, -1 );
if( pStr == NULL )
RageException::Throw( "\"%s\" \"Name\" entry is not a string", sLuaFunction.c_str() );
defOut.name = pStr;
lua_pop( LUA->L, 1 );
lua_pushstring( LUA->L, "OneChoiceForAllPlayers" );
lua_gettable( LUA->L, -2 );
defOut.bOneChoiceForAllPlayers = !!lua_toboolean( LUA->L, -1 );
lua_pop( LUA->L, 1 );
2005-03-08 17:54:12 +00:00
lua_pushstring( LUA->L, "ExportOnChange" );
lua_gettable( LUA->L, -2 );
defOut.m_bExportOnChange = !!lua_toboolean( LUA->L, -1 );
lua_pop( LUA->L, 1 );
2005-02-25 05:44:56 +00:00
lua_pushstring( LUA->L, "LayoutType" );
lua_gettable( LUA->L, -2 );
pStr = lua_tostring( LUA->L, -1 );
if( pStr == NULL )
RageException::Throw( "\"%s\" \"LayoutType\" entry is not a string", sLuaFunction.c_str() );
defOut.layoutType = StringToLayoutType( pStr );
ASSERT( defOut.layoutType != LAYOUT_INVALID );
lua_pop( LUA->L, 1 );
lua_pushstring( LUA->L, "SelectType" );
lua_gettable( LUA->L, -2 );
pStr = lua_tostring( LUA->L, -1 );
if( pStr == NULL )
RageException::Throw( "\"%s\" \"SelectType\" entry is not a string", sLuaFunction.c_str() );
defOut.selectType = StringToSelectType( pStr );
ASSERT( defOut.selectType != SELECT_INVALID );
lua_pop( LUA->L, 1 );
/* Iterate over the "Choices" table. */
lua_pushstring( LUA->L, "Choices" );
lua_gettable( LUA->L, -2 );
if( !lua_istable( LUA->L, -1 ) )
RageException::Throw( "\"%s\" \"Choices\" is not a table", sLuaFunction.c_str() );
2005-02-25 05:44:56 +00:00
lua_pushnil( LUA->L );
while( lua_next(LUA->L, -2) != 0 )
{
/* `key' is at index -2 and `value' at index -1 */
const char *pValue = lua_tostring( LUA->L, -1 );
if( pValue == NULL )
RageException::Throw( "\"%s\" Column entry is not a string", sLuaFunction.c_str() );
LOG->Trace( "'%s'", pValue);
2005-02-25 05:44:56 +00:00
defOut.choices.push_back( pValue );
2005-02-25 05:44:56 +00:00
lua_pop( LUA->L, 1 ); /* removes `value'; keeps `key' for next iteration */
}
2005-02-24 11:36:19 +00:00
2005-02-25 05:44:56 +00:00
lua_pop( LUA->L, 1 ); /* pop choices table */
2005-02-24 07:58:03 +00:00
2005-02-25 05:44:56 +00:00
/* Iterate over the "EnabledForPlayers" table. */
lua_pushstring( LUA->L, "EnabledForPlayers" );
lua_gettable( LUA->L, -2 );
if( !lua_isnil( LUA->L, -1 ) )
{
if( !lua_istable( LUA->L, -1 ) )
RageException::Throw( "\"%s\" \"EnabledForPlayers\" is not a table", sLuaFunction.c_str() );
2005-02-25 05:44:56 +00:00
defOut.m_vEnabledForPlayers.clear(); // and fill in with supplied PlayerNumbers below
2005-02-25 05:44:56 +00:00
lua_pushnil( LUA->L );
while( lua_next(LUA->L, -2) != 0 )
{
/* `key' is at index -2 and `value' at index -1 */
PlayerNumber pn = (PlayerNumber)luaL_checkint( LUA->L, -1 );
2005-02-25 05:44:56 +00:00
defOut.m_vEnabledForPlayers.insert( pn );
2005-02-25 05:44:56 +00:00
lua_pop( LUA->L, 1 ); /* removes `value'; keeps `key' for next iteration */
}
}
2005-02-25 05:44:56 +00:00
lua_pop( LUA->L, 1 ); /* pop EnabledForPlayers table */
2005-02-25 05:44:56 +00:00
2005-03-01 01:15:22 +00:00
/* Iterate over the "ReloadRowMessages" table. */
lua_pushstring( LUA->L, "ReloadRowMessages" );
lua_gettable( LUA->L, -2 );
if( !lua_isnil( LUA->L, -1 ) )
{
if( !lua_istable( LUA->L, -1 ) )
RageException::Throw( "\"%s\" \"ReloadRowMessages\" is not a table", sLuaFunction.c_str() );
lua_pushnil( LUA->L );
while( lua_next(LUA->L, -2) != 0 )
{
/* `key' is at index -2 and `value' at index -1 */
const char *pValue = lua_tostring( LUA->L, -1 );
if( pValue == NULL )
RageException::Throw( "\"%s\" Column entry is not a string", sLuaFunction.c_str() );
LOG->Trace( "'%s'", pValue);
m_vsReloadRowMessages.push_back( pValue );
lua_pop( LUA->L, 1 ); /* removes `value'; keeps `key' for next iteration */
}
}
lua_pop( LUA->L, 1 ); /* pop ReloadRowMessages table */
2005-02-25 05:44:56 +00:00
/* Look for "ExportOnChange" value. */
lua_pushstring( LUA->L, "ExportOnChange" );
lua_gettable( LUA->L, -2 );
if( !lua_isnil( LUA->L, -1 ) )
{
defOut.m_bExportOnChange = !!MyLua_checkboolean( LUA->L, -1 );
}
lua_pop( LUA->L, 1 ); /* pop ExportOnChange value */
2005-02-25 05:44:56 +00:00
/* Iterate over the "ReloadRowMessages" table. */
lua_pushstring( LUA->L, "ReloadRowMessages" );
lua_gettable( LUA->L, -2 );
if( !lua_isnil( LUA->L, -1 ) )
{
if( !lua_istable( LUA->L, -1 ) )
RageException::Throw( "\"%s\" \"ReloadRowMessages\" is not a table", sLuaFunction.c_str() );
2005-02-25 05:44:56 +00:00
m_vsReloadRowMessages.clear(); // and fill in with supplied PlayerNumbers below
2005-02-25 05:44:56 +00:00
lua_pushnil( LUA->L );
while( lua_next(LUA->L, -2) != 0 )
{
/* `key' is at index -2 and `value' at index -1 */
const char *pValue = lua_tostring( LUA->L, -1 );
if( pValue == NULL )
RageException::Throw( "\"%s\" Column entry is not a string", sLuaFunction.c_str() );
LOG->Trace( "'%s'", pValue);
2005-02-25 05:44:56 +00:00
m_vsReloadRowMessages.push_back( pValue );
2005-02-25 05:44:56 +00:00
lua_pop( LUA->L, 1 ); /* removes `value'; keeps `key' for next iteration */
}
}
lua_pop( LUA->L, 1 ); /* pop ReloadRowMessages table */
2005-02-25 05:44:56 +00:00
lua_pop( LUA->L, 1 ); /* pop main table */
ASSERT( lua_gettop(LUA->L) == 0 );
}
}
virtual void ImportOption( const OptionRowDefinition &def, PlayerNumber pn, vector<bool> &vbSelectedOut ) const
{
2005-02-25 05:44:56 +00:00
ASSERT( lua_gettop(LUA->L) == 0 );
2005-02-25 05:44:56 +00:00
/* Evaluate the LoadSelections(self,array,pn) function, where array is a table
* representing vbSelectedOut. */
2005-02-25 05:44:56 +00:00
/* All selections default to false. */
for( unsigned i = 0; i < vbSelectedOut.size(); ++i )
vbSelectedOut[i] = false;
2005-02-25 05:44:56 +00:00
/* Create the vbSelectedOut table. */
LUA->CreateTableFromArrayB( vbSelectedOut );
ASSERT( lua_gettop(LUA->L) == 1 ); /* vbSelectedOut table */
2005-02-25 05:44:56 +00:00
/* Get the function to call from m_LuaTable. */
m_pLuaTable->PushSelf( LUA->L );
ASSERT( lua_istable( LUA->L, -1 ) );
2005-02-25 05:44:56 +00:00
lua_pushstring( LUA->L, "LoadSelections" );
lua_gettable( LUA->L, -2 );
2005-02-25 05:44:56 +00:00
if( !lua_isfunction( LUA->L, -1 ) )
RageException::Throw( "\"%s\" \"LoadSelections\" entry is not a function", def.name.c_str() );
2005-02-25 05:44:56 +00:00
/* Argument 1 (self): */
m_pLuaTable->PushSelf( LUA->L );
2005-02-25 05:44:56 +00:00
/* Argument 2 (vbSelectedOut): */
lua_pushvalue( LUA->L, 1 );
2005-02-25 05:44:56 +00:00
/* Argument 3 (pn): */
LUA->PushStack( (int) pn );
2005-02-25 05:44:56 +00:00
ASSERT( lua_gettop(LUA->L) == 6 ); /* vbSelectedOut, m_iLuaTable, function, self, arg, arg */
2005-02-25 05:44:56 +00:00
lua_call( LUA->L, 3, 0 ); // call function with 3 arguments and 0 results
ASSERT( lua_gettop(LUA->L) == 2 );
2005-02-25 05:44:56 +00:00
lua_pop( LUA->L, 1 ); /* pop option table */
2005-02-25 05:44:56 +00:00
LUA->ReadArrayFromTableB( vbSelectedOut );
lua_pop( LUA->L, 1 ); /* pop vbSelectedOut table */
2005-02-25 05:44:56 +00:00
ASSERT( lua_gettop(LUA->L) == 0 );
}
virtual int ExportOption( const OptionRowDefinition &def, PlayerNumber pn, const vector<bool> &vbSelected ) const
{
ASSERT( lua_gettop(LUA->L) == 0 );
2005-02-25 05:44:56 +00:00
/* Evaluate SaveSelections(self,array,pn) function, where array is a table
* representing vbSelectedOut. */
2005-02-25 05:44:56 +00:00
vector<bool> vbSelectedCopy = vbSelected;
2005-02-25 05:44:56 +00:00
/* Create the vbSelectedOut table. */
LUA->CreateTableFromArrayB( vbSelectedCopy );
ASSERT( lua_gettop(LUA->L) == 1 ); /* vbSelectedOut table */
2005-02-25 05:44:56 +00:00
/* Get the function to call. */
m_pLuaTable->PushSelf( LUA->L );
ASSERT( lua_istable( LUA->L, -1 ) );
2005-02-25 05:44:56 +00:00
lua_pushstring( LUA->L, "SaveSelections" );
lua_gettable( LUA->L, -2 );
2005-02-25 05:44:56 +00:00
if( !lua_isfunction( LUA->L, -1 ) )
RageException::Throw( "\"%s\" \"SaveSelections\" entry is not a function", def.name.c_str() );
2005-02-25 05:44:56 +00:00
/* Argument 1 (self): */
m_pLuaTable->PushSelf( LUA->L );
2005-02-25 05:44:56 +00:00
/* Argument 2 (vbSelectedOut): */
lua_pushvalue( LUA->L, 1 );
2005-02-25 05:44:56 +00:00
/* Argument 3 (pn): */
LUA->PushStack( (int) pn );
2005-02-25 05:44:56 +00:00
ASSERT( lua_gettop(LUA->L) == 6 ); /* vbSelectedOut, m_iLuaTable, function, self, arg, arg */
2005-02-25 05:44:56 +00:00
lua_call( LUA->L, 3, 0 ); // call function with 3 arguments and 0 results
ASSERT( lua_gettop(LUA->L) == 2 );
2005-02-25 05:44:56 +00:00
lua_pop( LUA->L, 1 ); /* pop option table */
lua_pop( LUA->L, 1 ); /* pop vbSelected table */
ASSERT( lua_gettop(LUA->L) == 0 );
2005-02-25 05:44:56 +00:00
// XXX: allow specifying the mask
return 0;
}
2005-02-25 05:44:56 +00:00
};
2005-02-25 05:44:56 +00:00
class OptionRowHandlerConfig : public OptionRowHandler
2005-02-24 07:58:03 +00:00
{
2005-02-25 05:44:56 +00:00
public:
const ConfOption *opt;
2005-02-24 07:58:03 +00:00
2005-02-25 05:44:56 +00:00
OptionRowHandlerConfig::OptionRowHandlerConfig() { Init(); }
void Init()
2005-02-24 07:58:03 +00:00
{
2005-02-25 05:44:56 +00:00
OptionRowHandler::Init();
opt = NULL;
2005-02-24 07:58:03 +00:00
}
2005-02-25 05:44:56 +00:00
virtual void Load( OptionRowDefinition &defOut, CString sParam )
{
ASSERT( sParam.size() );
2005-02-25 05:44:56 +00:00
Init();
defOut.Init();
2005-02-25 05:44:56 +00:00
/* Configuration values are never per-player. */
defOut.bOneChoiceForAllPlayers = true;
2005-02-25 05:44:56 +00:00
ConfOption *pConfOption = ConfOption::Find( sParam );
if( pConfOption == NULL )
RageException::Throw( "Invalid Conf type \"%s\"", sParam.c_str() );
2005-02-25 05:44:56 +00:00
pConfOption->UpdateAvailableOptions();
2005-02-25 05:44:56 +00:00
opt = pConfOption;
opt->MakeOptionsList( defOut.choices );
defOut.name = opt->name;
}
2005-02-25 19:38:53 +00:00
virtual void ImportOption( const OptionRowDefinition &def, PlayerNumber pn, vector<bool> &vbSelectedOut ) const
{
2005-02-25 05:44:56 +00:00
int iSelection = opt->Get();
SelectExactlyOne( iSelection, vbSelectedOut );
}
2005-02-25 05:44:56 +00:00
virtual int ExportOption( const OptionRowDefinition &def, PlayerNumber pn, const vector<bool> &vbSelected ) const
{
int sel = GetOneSelection(vbSelected);
2005-02-25 05:44:56 +00:00
/* Get the original choice. */
int Original = opt->Get();
2005-02-24 11:36:19 +00:00
2005-02-25 05:44:56 +00:00
/* Apply. */
opt->Put( sel );
2005-02-24 11:36:19 +00:00
2005-02-25 05:44:56 +00:00
/* Get the new choice. */
int New = opt->Get();
2005-02-24 11:36:19 +00:00
2005-02-25 05:44:56 +00:00
/* If it didn't change, don't return any side-effects. */
if( Original == New )
return 0;
2005-02-24 11:36:19 +00:00
2005-02-25 05:44:56 +00:00
return opt->GetEffects();
2005-02-24 11:36:19 +00:00
}
2005-02-25 05:44:56 +00:00
};
2005-02-25 05:44:56 +00:00
class OptionRowHandlerStepsType : public OptionRowHandler
{
2005-02-25 05:44:56 +00:00
public:
BroadcastOnChange<StepsType> *m_pstToFill;
vector<StepsType> m_vStepsTypesToShow;
2005-02-25 05:44:56 +00:00
OptionRowHandlerStepsType::OptionRowHandlerStepsType() { Init(); }
void Init()
{
OptionRowHandler::Init();
m_pstToFill = NULL;
m_vStepsTypesToShow.clear();
}
2005-02-25 05:44:56 +00:00
virtual void Load( OptionRowDefinition &defOut, CString sParam )
{
ASSERT( sParam.size() );
2005-02-25 05:44:56 +00:00
Init();
defOut.Init();
2005-02-25 05:44:56 +00:00
if( sParam == "EditStepsType" )
2005-02-26 11:21:50 +00:00
{
2005-02-25 05:44:56 +00:00
m_pstToFill = &GAMESTATE->m_stEdit;
2005-02-26 11:21:50 +00:00
}
2005-02-25 05:44:56 +00:00
else if( sParam == "EditSourceStepsType" )
2005-02-26 11:21:50 +00:00
{
2005-02-25 05:44:56 +00:00
m_pstToFill = &GAMESTATE->m_stEditSource;
2005-02-26 11:21:50 +00:00
m_vsReloadRowMessages.push_back( MessageToString(MESSAGE_CURRENT_STEPS_P1_CHANGED) );
m_vsReloadRowMessages.push_back( MessageToString(MESSAGE_EDIT_STEPS_TYPE_CHANGED) );
if( GAMESTATE->m_pCurSteps[0].Get() != NULL )
defOut.m_vEnabledForPlayers.clear(); // hide row
}
2005-02-25 05:44:56 +00:00
else
2005-02-26 11:21:50 +00:00
{
2005-02-25 05:44:56 +00:00
RageException::Throw( "invalid StepsType param \"%s\"", sParam.c_str() );
2005-02-26 11:21:50 +00:00
}
2005-02-25 05:44:56 +00:00
m_sName = sParam;
defOut.name = sParam;
defOut.bOneChoiceForAllPlayers = true;
defOut.layoutType = LAYOUT_SHOW_ONE_IN_ROW;
defOut.m_bExportOnChange = true;
2005-02-25 05:44:56 +00:00
// calculate which StepsTypes to show
GAMEMAN->GetStepsTypesForGame( GAMESTATE->m_pCurGame, m_vStepsTypesToShow );
2005-02-25 05:44:56 +00:00
// subtract hidden StepsTypes
vector<CString> vsStepsTypesToHide;
split( STEPS_TYPES_TO_HIDE, ",", vsStepsTypesToHide, true );
for( unsigned i=0; i<vsStepsTypesToHide.size(); i++ )
{
StepsType st = GameManager::StringToStepsType(vsStepsTypesToHide[i]);
if( st != STEPS_TYPE_INVALID )
{
const vector<StepsType>::iterator iter = find( m_vStepsTypesToShow.begin(), m_vStepsTypesToShow.end(), st );
if( iter != m_vStepsTypesToShow.end() )
m_vStepsTypesToShow.erase( iter );
}
}
2005-02-25 05:44:56 +00:00
FOREACH_CONST( StepsType, m_vStepsTypesToShow, st )
{
CString s = GAMEMAN->StepsTypeToThemedString( *st );
defOut.choices.push_back( s );
}
2005-02-25 05:44:56 +00:00
if( *m_pstToFill == STEPS_TYPE_INVALID )
m_pstToFill->Set( m_vStepsTypesToShow[0] );
}
2005-02-25 19:38:53 +00:00
virtual void ImportOption( const OptionRowDefinition &def, PlayerNumber pn, vector<bool> &vbSelectedOut ) const
{
2005-02-25 05:44:56 +00:00
if( GAMESTATE->m_pCurSteps[0] )
{
StepsType st = GAMESTATE->m_pCurSteps[0]->m_StepsType;
vector<StepsType>::const_iterator iter = find( m_vStepsTypesToShow.begin(), m_vStepsTypesToShow.end(), st );
if( iter != m_vStepsTypesToShow.end() )
{
unsigned i = iter - m_vStepsTypesToShow.begin();
vbSelectedOut[i] = true;
return;
}
}
vbSelectedOut[0] = true;
}
2005-02-25 05:44:56 +00:00
virtual int ExportOption( const OptionRowDefinition &def, PlayerNumber pn, const vector<bool> &vbSelected ) const
{
2005-02-25 05:44:56 +00:00
int index = GetOneSelection( vbSelected );
m_pstToFill->Set( m_vStepsTypesToShow[index] );
return 0;
}
2005-02-25 05:44:56 +00:00
};
2005-02-25 05:44:56 +00:00
class OptionRowHandlerSteps : public OptionRowHandler
{
public:
BroadcastOnChangePtr<Steps> *m_ppStepsToFill;
2005-02-26 11:21:50 +00:00
BroadcastOnChange<Difficulty> *m_pDifficultyToFill;
2005-02-25 19:38:53 +00:00
const BroadcastOnChange<StepsType> *m_pst;
2005-02-25 05:44:56 +00:00
vector<Steps*> m_vSteps;
2005-02-26 11:21:50 +00:00
vector<Difficulty> m_vDifficulties;
2005-02-25 05:44:56 +00:00
OptionRowHandlerSteps::OptionRowHandlerSteps() { Init(); }
void Init()
{
2005-02-25 05:44:56 +00:00
OptionRowHandler::Init();
m_ppStepsToFill = NULL;
2005-02-26 11:21:50 +00:00
m_pDifficultyToFill = NULL;
2005-02-25 05:44:56 +00:00
m_vSteps.clear();
2005-02-26 11:21:50 +00:00
m_vDifficulties.clear();
}
2005-02-25 05:44:56 +00:00
virtual void Load( OptionRowDefinition &defOut, CString sParam )
{
ASSERT( sParam.size() );
2005-02-25 05:44:56 +00:00
Init();
defOut.Init();
2005-02-25 19:38:53 +00:00
if( sParam == "EditSteps" )
{
m_ppStepsToFill = &GAMESTATE->m_pCurSteps[0];
2005-02-26 11:21:50 +00:00
m_pDifficultyToFill = &GAMESTATE->m_PreferredDifficulty[0];
2005-02-25 19:38:53 +00:00
m_pst = &GAMESTATE->m_stEdit;
m_vsReloadRowMessages.push_back( MessageToString(MESSAGE_EDIT_STEPS_TYPE_CHANGED) );
}
else if( sParam == "EditSourceSteps" )
{
2005-02-25 05:44:56 +00:00
m_ppStepsToFill = &GAMESTATE->m_pEditSourceSteps;
2005-02-25 19:38:53 +00:00
m_pst = &GAMESTATE->m_stEditSource;
m_vsReloadRowMessages.push_back( MessageToString(MESSAGE_EDIT_SOURCE_STEPS_TYPE_CHANGED) );
2005-02-26 11:21:50 +00:00
if( GAMESTATE->m_pCurSteps[0].Get() != NULL )
defOut.m_vEnabledForPlayers.clear(); // hide row
2005-02-25 19:38:53 +00:00
}
2005-02-25 05:44:56 +00:00
else
2005-02-25 19:38:53 +00:00
{
2005-02-25 05:44:56 +00:00
RageException::Throw( "invalid StepsType param \"%s\"", sParam.c_str() );
2005-02-25 19:38:53 +00:00
}
2005-02-25 05:44:56 +00:00
m_sName = sParam;
defOut.name = sParam;
defOut.bOneChoiceForAllPlayers = true;
defOut.layoutType = LAYOUT_SHOW_ONE_IN_ROW;
defOut.m_bExportOnChange = true;
2005-02-25 19:38:53 +00:00
m_vsReloadRowMessages.push_back( MessageToString(MESSAGE_CURRENT_SONG_CHANGED) );
2005-02-25 05:44:56 +00:00
if( GAMESTATE->m_pCurSong )
{
FOREACH_Difficulty( dc )
2005-02-26 11:21:50 +00:00
{
if( dc == DIFFICULTY_EDIT )
continue;
m_vDifficulties.push_back( dc );
Steps* pSteps = GAMESTATE->m_pCurSong->GetStepsByDifficulty( *m_pst, dc );
m_vSteps.push_back( pSteps );
2005-02-26 11:21:50 +00:00
}
GAMESTATE->m_pCurSong->GetSteps( m_vSteps, *m_pst, DIFFICULTY_EDIT );
m_vDifficulties.resize( m_vSteps.size(), DIFFICULTY_EDIT );
2005-02-26 22:19:29 +00:00
if( m_sName == "EditSteps" )
{
m_vSteps.push_back( NULL );
m_vDifficulties.push_back( DIFFICULTY_EDIT );
}
2005-02-26 11:21:50 +00:00
2005-02-25 05:44:56 +00:00
for( unsigned i=0; i<m_vSteps.size(); i++ )
{
Steps* pSteps = m_vSteps[i];
2005-02-26 11:21:50 +00:00
Difficulty dc = m_vDifficulties[i];
2005-02-25 05:44:56 +00:00
CString s;
2005-02-26 11:21:50 +00:00
if( dc == DIFFICULTY_EDIT )
{
if( pSteps )
s = pSteps->GetDescription();
else
s = ENTRY_NAME("NewEdit");
}
2005-02-25 05:44:56 +00:00
else
2005-02-26 11:21:50 +00:00
{
s = DifficultyToThemedString( dc );
}
2005-02-25 05:44:56 +00:00
defOut.choices.push_back( s );
}
}
2005-02-26 11:21:50 +00:00
else
{
m_vDifficulties.push_back( DIFFICULTY_EDIT );
m_vSteps.push_back( NULL );
defOut.choices.push_back( "none" );
}
2005-02-26 21:35:27 +00:00
if( m_pDifficultyToFill )
m_pDifficultyToFill->Set( m_vDifficulties[0] );
m_ppStepsToFill->Set( m_vSteps[0] );
2005-02-25 05:44:56 +00:00
}
2005-02-25 19:38:53 +00:00
virtual void ImportOption( const OptionRowDefinition &def, PlayerNumber pn, vector<bool> &vbSelectedOut ) const
{
2005-02-25 19:38:53 +00:00
ASSERT( m_vSteps.size() == vbSelectedOut.size() );
// look for matching steps
2005-02-25 05:44:56 +00:00
vector<Steps*>::const_iterator iter = find( m_vSteps.begin(), m_vSteps.end(), m_ppStepsToFill->Get() );
if( iter != m_vSteps.end() )
{
unsigned i = iter - m_vSteps.begin();
vbSelectedOut[i] = true;
return;
}
2005-02-25 19:38:53 +00:00
// look for matching difficulty
2005-02-26 11:21:50 +00:00
if( m_pDifficultyToFill )
2005-02-25 19:38:53 +00:00
{
2005-02-26 11:21:50 +00:00
FOREACH_CONST( Difficulty, m_vDifficulties, d )
{
unsigned i = d - m_vDifficulties.begin();
if( *d == GAMESTATE->m_PreferredDifficulty[0] )
{
vbSelectedOut[i] = true;
ExportOption( def, pn, vbSelectedOut ); // current steps changed
return;
}
}
2005-02-25 19:38:53 +00:00
}
// default to 1st
2005-02-25 05:44:56 +00:00
vbSelectedOut[0] = true;
}
2005-02-25 05:44:56 +00:00
virtual int ExportOption( const OptionRowDefinition &def, PlayerNumber pn, const vector<bool> &vbSelected ) const
{
2005-02-25 05:44:56 +00:00
int index = GetOneSelection( vbSelected );
2005-02-26 11:21:50 +00:00
Difficulty dc = m_vDifficulties[index];
Steps *pSteps = m_vSteps[index];
if( m_pDifficultyToFill )
m_pDifficultyToFill->Set( dc );
m_ppStepsToFill->Set( pSteps );
2005-02-25 05:44:56 +00:00
return 0;
}
2005-02-25 05:44:56 +00:00
};
2005-02-26 11:21:50 +00:00
// helpers for MenuStart() below
static void DeleteCurNotes( void* pThrowAway )
{
Song* pSong = GAMESTATE->m_pCurSong;
Steps* pStepsToDelete = GAMESTATE->m_pCurSteps[PLAYER_1];
pSong->RemoveSteps( pStepsToDelete );
pSong->Save();
// refresh the list
MESSAGEMAN->Broadcast( MESSAGE_CURRENT_SONG_CHANGED );
}
2005-02-25 05:44:56 +00:00
class OptionRowHandlerEditMenuAction : public OptionRowHandler
{
2005-02-25 05:44:56 +00:00
public:
vector<EditMenuAction> m_vEditMenuActions;
2005-02-25 05:44:56 +00:00
OptionRowHandlerEditMenuAction::OptionRowHandlerEditMenuAction() { Init(); }
void Init()
{
2005-02-25 05:44:56 +00:00
OptionRowHandler::Init();
m_vEditMenuActions.clear();
}
2005-02-25 05:44:56 +00:00
virtual void Load( OptionRowDefinition &defOut, CString sParam )
{
2005-02-25 05:44:56 +00:00
ASSERT( sParam.size() );
2005-02-25 05:44:56 +00:00
Init();
defOut.Init();
2005-02-24 11:36:19 +00:00
2005-02-25 05:44:56 +00:00
m_sName = sParam;
defOut.name = sParam;
defOut.bOneChoiceForAllPlayers = true;
defOut.layoutType = LAYOUT_SHOW_ONE_IN_ROW;
m_vsReloadRowMessages.push_back( MessageToString(MESSAGE_CURRENT_STEPS_P1_CHANGED) );
m_vsReloadRowMessages.push_back( MessageToString(MESSAGE_EDIT_SOURCE_STEPS_CHANGED) );
2005-02-24 11:36:19 +00:00
2005-02-25 05:44:56 +00:00
bool bHasSteps = GAMESTATE->m_pCurSteps[0] != NULL;
bool bHasSourceSteps = GAMESTATE->m_pEditSourceSteps != NULL;
2005-02-25 05:44:56 +00:00
FOREACH_EditMenuAction( ema )
{
switch( ema )
{
case EDIT_MENU_ACTION_EDIT:
case EDIT_MENU_ACTION_DELETE:
if( !bHasSteps )
continue; // skip
break;
case EDIT_MENU_ACTION_COPY:
case EDIT_MENU_ACTION_AUTOGEN:
if( bHasSteps || !bHasSourceSteps )
continue; // skip
break;
2005-02-25 05:44:56 +00:00
case EDIT_MENU_ACTION_BLANK:
if( bHasSteps )
continue; // skip
break;
default:
ASSERT(0);
}
2005-02-24 11:36:19 +00:00
2005-02-25 05:44:56 +00:00
m_vEditMenuActions.push_back( ema );
CString s = EditMenuActionToThemedString( ema );
defOut.choices.push_back( s );
}
}
2005-02-25 19:38:53 +00:00
virtual void ImportOption( const OptionRowDefinition &def, PlayerNumber pn, vector<bool> &vbSelectedOut ) const
2005-02-24 11:36:19 +00:00
{
2005-02-25 05:44:56 +00:00
vbSelectedOut[0] = true;
2005-02-24 11:36:19 +00:00
}
2005-02-25 05:44:56 +00:00
virtual int ExportOption( const OptionRowDefinition &def, PlayerNumber pn, const vector<bool> &vbSelected ) const
2005-02-26 22:19:29 +00:00
{
return 0;
}
virtual CString GetAndEraseScreen( int iChoice )
2005-02-25 05:44:56 +00:00
{
2005-02-26 11:21:50 +00:00
Song* pSong = GAMESTATE->m_pCurSong;
Steps *pSteps = GAMESTATE->m_pCurSteps[0];
Difficulty dc = GAMESTATE->m_PreferredDifficulty[0];
StepsType st = GAMESTATE->m_stEdit;
Steps *pSourceNotes = GAMESTATE->m_pEditSourceSteps;
2005-02-26 22:19:29 +00:00
EditMenuAction ema = m_vEditMenuActions[iChoice];
2005-02-26 11:21:50 +00:00
switch( ema )
{
case EDIT_MENU_ACTION_EDIT:
// Prepare prepare for ScreenEdit
2005-02-28 20:15:31 +00:00
ASSERT( pSong );
2005-02-26 11:21:50 +00:00
ASSERT( pSteps );
2005-02-28 20:15:31 +00:00
GAMESTATE->m_pCurStyle = GAMEMAN->GetEditorStyleForStepsType( st );
2005-02-26 22:19:29 +00:00
return "ScreenEdit";
2005-02-26 11:21:50 +00:00
break;
case EDIT_MENU_ACTION_DELETE:
ASSERT( pSteps );
SCREENMAN->Prompt( SM_None, "These notes will be lost permanently.\n\nContinue with delete?", PROMPT_YES_NO, ANSWER_NO, DeleteCurNotes );
2005-02-26 11:21:50 +00:00
break;
case EDIT_MENU_ACTION_COPY:
ASSERT( !pSteps );
ASSERT( pSourceNotes );
{
// Yuck. Doing the memory allocation doesn't seem right since
// Song allocates all of the other Steps.
Steps* pNewSteps = new Steps;
pNewSteps->CopyFrom( pSourceNotes, st );
pNewSteps->SetDifficulty( dc );
pSong->AddSteps( pNewSteps );
SCREENMAN->SystemMessage( "Steps created from copy." );
SOUND->PlayOnce( THEME->GetPathS("ScreenEditMenu","create") );
pSong->Save();
}
break;
case EDIT_MENU_ACTION_AUTOGEN:
ASSERT( !pSteps );
ASSERT( pSourceNotes );
{
// Yuck. Doing the memory allocation doesn't seem right since
// Song allocates all of the other Steps.
Steps* pNewNotes = new Steps;
pNewNotes->AutogenFrom( pSourceNotes, st );
pNewNotes->DeAutogen();
pNewNotes->SetDifficulty( dc ); // override difficulty with the user's choice
pSong->AddSteps( pNewNotes );
SCREENMAN->SystemMessage( "Steps created from AutoGen." );
SOUND->PlayOnce( THEME->GetPathS("ScreenEditMenu","create") );
pSong->Save();
}
break;
case EDIT_MENU_ACTION_BLANK:
ASSERT( !pSteps );
{
// Yuck. Doing the memory allocation doesn't seem right since
// Song allocates all of the other Steps.
Steps* pNewNotes = new Steps;
pNewNotes->CreateBlank( st );
pNewNotes->SetDifficulty( dc );
pNewNotes->SetMeter( 1 );
pSong->AddSteps( pNewNotes );
SCREENMAN->SystemMessage( "Blank Steps created." );
SOUND->PlayOnce( THEME->GetPathS("ScreenEditMenu","create") );
pSong->Save();
}
break;
default:
ASSERT(0);
}
2005-02-26 22:19:29 +00:00
// refresh the screen since we deleted or added steps
2005-02-26 11:21:50 +00:00
MESSAGEMAN->Broadcast( MESSAGE_CURRENT_SONG_CHANGED );
2005-02-26 22:19:29 +00:00
return "";
2005-02-25 05:44:56 +00:00
}
};
///////////////////////////////////////////////////////////////////////////////////
2005-02-24 11:36:19 +00:00
OptionRowHandler* OptionRowHandlerUtil::Make( const Command &command, OptionRowDefinition &defOut )
{
OptionRowHandler* pHand = NULL;
BeginHandleArgs;
const CString &name = command.GetName();
#define MAKE( type ) { type *p = new type; p->Load( defOut, sArg(1) ); pHand = p; }
if( name == "list" ) MAKE( OptionRowHandlerList )
else if( name == "lua" ) MAKE( OptionRowHandlerLua )
else if( name == "conf" ) MAKE( OptionRowHandlerConfig )
else if( name == "stepstype" ) MAKE( OptionRowHandlerStepsType )
else if( name == "steps" ) MAKE( OptionRowHandlerSteps )
2005-02-25 05:44:56 +00:00
else if( name == "editmenuaction" ) MAKE( OptionRowHandlerEditMenuAction )
EndHandleArgs;
return pHand;
}
/*
* (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.
*/