Files
itgmania212121/stepmania/src/OptionRowHandler.cpp
T

1416 lines
39 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 "SongUtil.h"
#include "StepsUtil.h"
#include "GameManager.h"
#include "Foreach.h"
2005-02-26 11:21:50 +00:00
#include "GameSoundManager.h"
2005-03-10 19:57:43 +00:00
#include "CommonMetrics.h"
#include "CharacterManager.h"
#include "ScreenManager.h"
#include "ScreenMiniMenu.h" // for MenuRowDef
#include "FontCharAliases.h"
2006-05-20 05:40:09 +00:00
#define ENTRY(s) THEME->GetMetric ("ScreenOptionsMaster",s)
2006-01-09 01:07:02 +00:00
#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")
2007-06-08 01:35:29 +00:00
#define NOTE_SKIN_SORT_ORDER THEME->GetMetric ("ScreenOptionsMaster","NoteSkinSortOrder")
static const char *SelectTypeNames[] = {
"SelectOne",
"SelectMultiple",
"SelectNone",
};
2006-10-15 00:09:18 +00:00
XToString( SelectType );
StringToX( SelectType );
static const char *LayoutTypeNames[] = {
"ShowAllInRow",
"ShowOneInRow",
};
2006-10-15 00:09:18 +00:00
XToString( LayoutType );
StringToX( LayoutType );
2006-09-01 04:29:24 +00:00
RString OptionRowHandler::OptionTitle() const
{
bool bTheme = false;
// HACK: Always theme the NEXT_ROW and EXIT items, even if metrics says not to theme.
if( m_Def.m_bAllowThemeTitle )
bTheme = true;
RString s = m_Def.m_sName;
if( s.empty() )
return s;
return bTheme ? THEME->GetString("OptionTitles",s) : s;
}
RString OptionRowHandler::GetThemedItemText( int iChoice ) const
{
RString s = m_Def.m_vsChoices[iChoice];
if( s == "" )
return "";
bool bTheme = false;
if( m_Def.m_bAllowThemeItems ) bTheme = true;
// Items beginning with a pipe mean "don't theme".
// This allows us to disable theming on a per-choice basis for choice names that are just a number
// and don't need to be localized.
if( s[0] == '|' )
{
s.erase( s.begin() );
bTheme = false;
}
2008-10-06 07:27:58 +00:00
if( bTheme )
s = CommonMetrics::LocalizeOptionItem( s, false );
return s;
}
2006-01-22 01:00:06 +00:00
void OptionRowHandler::GetIconTextAndGameCommand( int iFirstSelection, RString &sIconTextOut, GameCommand &gcOut ) const
2005-07-16 07:01:48 +00:00
{
sIconTextOut = "";
gcOut.Init();
}
void OptionRowHandlerUtil::SelectExactlyOne( int iSelection, vector<bool> &vbSelectedOut )
{
2005-04-28 17:16:49 +00:00
ASSERT_M( iSelection >= 0 && iSelection < (int) vbSelectedOut.size(),
ssprintf("%d/%u",iSelection, unsigned(vbSelectedOut.size())) );
for( int i=0; i<int(vbSelectedOut.size()); i++ )
vbSelectedOut[i] = i==iSelection;
}
int OptionRowHandlerUtil::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;
}
2006-01-08 18:40:20 +00:00
static LocalizedString OFF ( "OptionRowHandler", "Off" );
class OptionRowHandlerList : public OptionRowHandler
{
public:
2006-01-17 06:51:22 +00:00
vector<GameCommand> m_aListEntries;
GameCommand m_Default;
bool m_bUseModNameForIcon;
2006-01-22 01:00:06 +00:00
vector<RString> m_vsBroadcastOnExport;
2006-01-16 22:38:53 +00:00
OptionRowHandlerList() { Init(); }
virtual void Init()
{
OptionRowHandler::Init();
2006-01-17 06:51:22 +00:00
m_aListEntries.clear();
m_Default.Init();
m_bUseModNameForIcon = false;
2005-03-01 01:15:22 +00:00
m_vsBroadcastOnExport.clear();
}
2006-01-18 00:06:25 +00:00
virtual void LoadInternal( const Commands &cmds )
2005-02-25 05:44:56 +00:00
{
ASSERT( cmds.v.size() == 1 );
const Command &command = cmds.v[0];
2006-10-11 02:41:24 +00:00
RString sParam = command.GetArg(1).s;
ASSERT( command.m_vsArgs.size() == 2 );
2005-02-25 05:44:56 +00:00
ASSERT( sParam.size() );
m_bUseModNameForIcon = true;
2006-01-18 00:06:25 +00:00
m_Def.m_sName = sParam;
2005-02-25 05:44:56 +00:00
2006-01-17 06:51:22 +00:00
m_Default.Load( -1, ParseCommands(ENTRY_DEFAULT(sParam)) );
2005-02-25 05:44:56 +00:00
{
/* Parse the basic configuration metric. */
Commands cmds = ParseCommands( ENTRY(sParam) );
if( cmds.v.size() < 1 )
RageException::Throw( "Parse error in \"ScreenOptionsMaster::%s\".", sParam.c_str() );
2006-01-18 00:06:25 +00:00
m_Def.m_bOneChoiceForAllPlayers = false;
const int NumCols = atoi( cmds.v[0].m_vsArgs[0] );
for( unsigned i=1; i<cmds.v.size(); i++ )
2005-02-25 05:44:56 +00:00
{
const Command &cmd = cmds.v[i];
2006-01-22 01:00:06 +00:00
RString sName = cmd.GetName();
2006-05-20 05:40:09 +00:00
if( sName == "together" ) m_Def.m_bOneChoiceForAllPlayers = true;
2006-01-18 00:06:25 +00:00
else if( sName == "selectmultiple" ) m_Def.m_selectType = SELECT_MULTIPLE;
else if( sName == "selectone" ) m_Def.m_selectType = SELECT_ONE;
else if( sName == "selectnone" ) m_Def.m_selectType = SELECT_NONE;
else if( sName == "showoneinrow" ) m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
2007-03-18 09:51:44 +00:00
else if( sName == "default" ) m_Def.m_iDefault = atoi( cmd.GetArg(1).s ) - 1; // match ENTRY_MODE
else if( sName == "reloadrowmessages" )
2005-02-25 05:44:56 +00:00
{
for( unsigned a=1; a<cmd.m_vsArgs.size(); a++ )
m_vsReloadRowMessages.push_back( cmd.m_vsArgs[a] );
2005-02-25 05:44:56 +00:00
}
else if( sName == "enabledforplayers" )
{
2006-01-18 00:06:25 +00:00
m_Def.m_vEnabledForPlayers.clear();
for( unsigned a=1; a<cmd.m_vsArgs.size(); a++ )
{
2006-01-22 01:00:06 +00:00
RString sArg = cmd.m_vsArgs[a];
PlayerNumber pn = (PlayerNumber)(atoi(sArg)-1);
ASSERT( pn >= 0 && pn < NUM_PLAYERS );
2006-01-18 00:06:25 +00:00
m_Def.m_vEnabledForPlayers.insert( pn );
}
}
2006-01-18 00:06:25 +00:00
else if( sName == "exportonchange" ) m_Def.m_bExportOnChange = true;
else if( sName == "broadcastonexport" )
{
for( unsigned i=1; i<cmd.m_vsArgs.size(); i++ )
m_vsBroadcastOnExport.push_back( cmd.m_vsArgs[i] );
}
else RageException::Throw( "Unkown row flag \"%s\".", sName.c_str() );
2005-02-25 05:44:56 +00:00
}
for( int col = 0; col < NumCols; ++col )
2005-03-29 01:46:00 +00:00
{
GameCommand mc;
mc.ApplyCommitsScreens( false );
mc.Load( 0, ParseCommands(ENTRY_MODE(sParam, col)) );
/* If the row has just one entry, use the name of the row as the name of the
* entry. If it has more than one, each one must be specified explicitly. */
if( mc.m_sName == "" && NumCols == 1 )
mc.m_sName = sParam;
if( mc.m_sName == "" )
RageException::Throw( "List \"%s\", col %i has no name.", sParam.c_str(), col );
if( !mc.IsPlayable() )
{
LOG->Trace( "\"%s\" is not playable.", sParam.c_str() );
continue;
}
2005-02-25 05:44:56 +00:00
2006-01-17 06:51:22 +00:00
m_aListEntries.push_back( mc );
2005-02-25 05:44:56 +00:00
2006-01-22 01:00:06 +00:00
RString sName = mc.m_sName;
RString sChoice = mc.m_sName;
2006-01-18 00:06:25 +00:00
m_Def.m_vsChoices.push_back( sChoice );
}
2005-02-25 05:44:56 +00:00
}
2007-03-18 09:51:44 +00:00
2007-03-22 07:06:08 +00:00
if( m_Def.m_selectType != SELECT_MULTIPLE && m_Def.m_iDefault == -1 )
2007-03-18 09:51:44 +00:00
{
for( unsigned e = 0; e < m_aListEntries.size(); ++e )
{
const GameCommand &mc = m_aListEntries[e];
if( mc.IsZero() )
m_Def.m_iDefault = e;
}
}
2005-02-25 05:44:56 +00:00
}
2009-03-22 08:42:27 +00:00
void ImportOption( OptionRow *pRow, const vector<PlayerNumber> &vpns, vector<bool> vbSelectedOut[NUM_PLAYERS] ) const
2005-02-25 05:44:56 +00:00
{
2005-04-03 06:21:02 +00:00
FOREACH_CONST( PlayerNumber, vpns, pn )
2005-02-25 05:44:56 +00:00
{
2005-04-03 06:21:02 +00:00
PlayerNumber p = *pn;
vector<bool> &vbSelOut = vbSelectedOut[p];
2005-02-25 05:44:56 +00:00
bool bUseFallbackOption = true;
2006-01-17 06:51:22 +00:00
for( unsigned e = 0; e < m_aListEntries.size(); ++e )
2005-02-25 05:44:56 +00:00
{
2006-01-17 06:51:22 +00:00
const GameCommand &mc = m_aListEntries[e];
2005-02-25 05:44:56 +00:00
2005-04-03 06:21:02 +00:00
vbSelOut[e] = false;
if( mc.IsZero() )
2005-02-25 05:44:56 +00:00
{
2005-04-03 06:21:02 +00:00
/* The entry has no effect. This is usually a default "none of the
2005-04-25 07:02:33 +00:00
* above" entry. It will always return true for DescribesCurrentMode().
* It's only the selected choice if nothing else matches. */
2005-04-03 06:21:02 +00:00
continue;
2005-02-25 05:44:56 +00:00
}
2005-04-03 06:21:02 +00:00
2006-01-19 03:36:06 +00:00
if( m_Def.m_bOneChoiceForAllPlayers )
2005-02-25 05:44:56 +00:00
{
2005-04-03 06:21:02 +00:00
if( mc.DescribesCurrentModeForAllPlayers() )
{
2005-04-25 07:02:33 +00:00
bUseFallbackOption = false;
2006-01-19 03:36:06 +00:00
if( m_Def.m_selectType != SELECT_MULTIPLE )
OptionRowHandlerUtil::SelectExactlyOne( e, vbSelOut );
2005-04-03 06:21:02 +00:00
else
vbSelOut[e] = true;
}
}
else
{
2007-04-27 19:53:33 +00:00
if( mc.DescribesCurrentMode(p) )
2005-04-03 06:21:02 +00:00
{
2005-04-25 07:02:33 +00:00
bUseFallbackOption = false;
2006-01-19 03:36:06 +00:00
if( m_Def.m_selectType != SELECT_MULTIPLE )
OptionRowHandlerUtil::SelectExactlyOne( e, vbSelOut );
2005-04-03 06:21:02 +00:00
else
vbSelOut[e] = true;
}
2005-02-25 05:44:56 +00:00
}
}
2006-01-19 03:36:06 +00:00
if( m_Def.m_selectType == SELECT_ONE && bUseFallbackOption )
2005-04-03 06:21:02 +00:00
{
2007-03-18 09:51:44 +00:00
int iFallbackOption = m_Def.m_iDefault;
2005-04-25 07:02:33 +00:00
if( iFallbackOption == -1 )
2005-04-19 03:31:06 +00:00
{
2006-02-28 21:45:46 +00:00
RString s = ssprintf("No options in row \"list,%s\" were selected, and no fallback row found; selected entry 0", m_Def.m_sName.c_str());
2008-12-26 23:23:18 +00:00
LOG->Warn( "%s", s.c_str() );
2005-04-25 07:02:33 +00:00
CHECKPOINT_M( s );
iFallbackOption = 0;
2005-04-19 03:31:06 +00:00
}
2005-03-11 02:01:55 +00:00
OptionRowHandlerUtil::SelectExactlyOne( iFallbackOption, vbSelOut );
2005-04-03 06:21:02 +00:00
}
2005-04-25 07:02:33 +00:00
2006-01-19 03:36:06 +00:00
VerifySelected( m_Def.m_selectType, vbSelOut, m_Def.m_sName );
2005-02-25 05:44:56 +00:00
}
}
2006-01-19 03:43:29 +00:00
int ExportOption( const vector<PlayerNumber> &vpns, const vector<bool> vbSelected[NUM_PLAYERS] ) const
2005-02-25 05:44:56 +00:00
{
2005-04-03 06:21:02 +00:00
FOREACH_CONST( PlayerNumber, vpns, pn )
2005-03-01 01:15:22 +00:00
{
2005-04-03 06:21:02 +00:00
PlayerNumber p = *pn;
const vector<bool> &vbSel = vbSelected[p];
2006-01-17 06:51:22 +00:00
m_Default.Apply( p );
2005-04-03 06:21:02 +00:00
for( unsigned i=0; i<vbSel.size(); i++ )
{
if( vbSel[i] )
2006-01-17 06:51:22 +00:00
m_aListEntries[i].Apply( p );
2005-04-03 06:21:02 +00:00
}
2005-03-01 01:15:22 +00:00
}
2006-01-22 01:00:06 +00:00
FOREACH_CONST( RString, m_vsBroadcastOnExport, s )
MESSAGEMAN->Broadcast( *s );
2005-02-25 05:44:56 +00:00
return 0;
}
2007-03-18 09:51:44 +00:00
virtual int GetDefaultOption() const
{
return m_Def.m_iDefault;
}
2006-01-22 01:00:06 +00:00
virtual void GetIconTextAndGameCommand( int iFirstSelection, RString &sIconTextOut, GameCommand &gcOut ) const
{
2005-07-16 07:01:48 +00:00
sIconTextOut = m_bUseModNameForIcon ?
m_aListEntries[iFirstSelection].m_sPreferredModifiers :
2006-01-19 03:36:06 +00:00
m_Def.m_vsChoices[iFirstSelection];
2005-07-16 07:01:48 +00:00
2006-01-17 06:51:22 +00:00
gcOut = m_aListEntries[iFirstSelection];
}
virtual RString GetScreen( int iChoice ) const
{
2006-01-17 06:51:22 +00:00
const GameCommand &gc = m_aListEntries[iChoice];
return gc.m_sScreen;
}
2006-02-18 03:18:58 +00:00
virtual ReloadChanged Reload()
2006-02-18 03:18:58 +00:00
{
// HACK: always reload "speed", to update the BPM text in the name of the speed line
if( !m_Def.m_sName.CompareNoCase("speed") )
return RELOAD_CHANGED_ALL;
2006-02-18 03:18:58 +00:00
return OptionRowHandler::Reload();
}
};
2005-02-24 06:33:50 +00:00
2007-06-08 01:35:29 +00:00
static void SortNoteSkins( vector<RString> &asSkinNames )
{
set<RString> setSkinNames;
setSkinNames.insert( asSkinNames.begin(), asSkinNames.end() );
vector<RString> asSorted;
split( NOTE_SKIN_SORT_ORDER, ",", asSorted );
set<RString> setUnusedSkinNames( setSkinNames );
asSkinNames.clear();
FOREACH( RString, asSorted, sSkin )
{
if( setSkinNames.find(*sSkin) == setSkinNames.end() )
continue;
asSkinNames.push_back( *sSkin );
setUnusedSkinNames.erase( *sSkin );
}
asSkinNames.insert( asSkinNames.end(), setUnusedSkinNames.begin(), setUnusedSkinNames.end() );
}
class OptionRowHandlerListNoteSkins : public OptionRowHandlerList
{
virtual void LoadInternal( const Commands &cmds )
{
2006-01-18 00:06:25 +00:00
m_Def.m_sName = "NoteSkins";
m_Def.m_bOneChoiceForAllPlayers = false;
m_Def.m_bAllowThemeItems = false; // we theme the text ourself
2006-01-22 01:00:06 +00:00
vector<RString> arraySkinNames;
2005-02-25 05:44:56 +00:00
NOTESKIN->GetNoteSkinNames( arraySkinNames );
2007-06-08 01:35:29 +00:00
SortNoteSkins( arraySkinNames );
2005-02-25 05:44:56 +00:00
for( unsigned skin=0; skin<arraySkinNames.size(); skin++ )
{
2007-03-18 09:51:44 +00:00
if( arraySkinNames[skin] == CommonMetrics::DEFAULT_NOTESKIN_NAME.GetValue() )
m_Def.m_iDefault = skin;
2005-02-25 05:44:56 +00:00
GameCommand mc;
mc.m_sPreferredModifiers = arraySkinNames[skin];
2006-01-17 06:51:22 +00:00
m_aListEntries.push_back( mc );
2006-01-18 00:06:25 +00:00
m_Def.m_vsChoices.push_back( arraySkinNames[skin] );
2005-02-25 05:44:56 +00:00
}
2005-02-24 11:36:19 +00:00
}
};
2005-02-24 11:36:19 +00:00
// XXX: very similar to OptionRowHandlerSteps
class OptionRowHandlerListSteps : public OptionRowHandlerList
{
virtual void LoadInternal( const Commands &cmds )
2005-02-24 11:36:19 +00:00
{
2006-01-18 00:06:25 +00:00
m_Def.m_sName = "Steps";
m_Def.m_bAllowThemeItems = false; // we theme the text ourself
2005-02-24 11:36:19 +00:00
2006-01-18 06:44:13 +00:00
Reload();
// don't call default
// OptionRowHandlerList::LoadInternal( cmds );
}
virtual ReloadChanged Reload()
2006-01-18 06:44:13 +00:00
{
m_Def.m_vsChoices.clear();
m_aListEntries.clear();
2005-02-25 05:44:56 +00:00
// fill in difficulty names
if( GAMESTATE->IsEditing() )
2005-02-24 11:36:19 +00:00
{
2006-01-18 00:06:25 +00:00
m_Def.m_vsChoices.push_back( "" );
2006-01-17 06:51:22 +00:00
m_aListEntries.push_back( GameCommand() );
2005-02-24 11:36:19 +00:00
}
else if( GAMESTATE->IsCourseMode() && GAMESTATE->m_pCurCourse ) // playing a course
2005-02-24 11:36:19 +00:00
{
2006-01-18 00:06:25 +00:00
m_Def.m_bOneChoiceForAllPlayers = (bool)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];
2006-01-22 01:00:06 +00:00
RString s = CourseDifficultyToLocalizedString( pTrail->m_CourseDifficulty );
2005-03-17 06:23:16 +00:00
s += ssprintf( " %d", pTrail->GetMeter() );
2006-01-18 00:06:25 +00:00
m_Def.m_vsChoices.push_back( s );
2005-02-25 05:44:56 +00:00
GameCommand mc;
mc.m_pTrail = pTrail;
2006-01-17 06:51:22 +00:00
m_aListEntries.push_back( mc );
}
}
2006-01-18 06:44:13 +00:00
else if( GAMESTATE->m_pCurSong ) // playing a song
2005-02-25 05:44:56 +00:00
{
2005-04-24 20:32:03 +00:00
vector<Steps*> vpSteps;
Song *pSong = GAMESTATE->m_pCurSong;
SongUtil::GetSteps( pSong, vpSteps, GAMESTATE->GetCurrentStyle()->m_StepsType );
2005-04-24 20:32:03 +00:00
StepsUtil::RemoveLockedSteps( pSong, vpSteps );
StepsUtil::SortNotesArrayByDifficulty( vpSteps );
for( unsigned i=0; i<vpSteps.size(); i++ )
2005-02-25 05:44:56 +00:00
{
2005-04-24 20:32:03 +00:00
Steps* pSteps = vpSteps[i];
2005-02-24 11:36:19 +00:00
2006-01-22 01:00:06 +00:00
RString s;
if( pSteps->GetDifficulty() == Difficulty_Edit )
{
2005-02-25 05:44:56 +00:00
s = pSteps->GetDescription();
}
2005-02-25 05:44:56 +00:00
else
{
2008-11-28 22:26:06 +00:00
if( pSteps->IsAnEdit() )
s = pSteps->GetDescription();
else
2008-12-21 01:27:33 +00:00
s = GetLocalizedCustomDifficulty( pSteps->m_StepsType, pSteps->GetDifficulty() );
}
2005-03-17 06:23:16 +00:00
s += ssprintf( " %d", pSteps->GetMeter() );
2006-01-18 00:06:25 +00:00
m_Def.m_vsChoices.push_back( s );
2005-02-25 05:44:56 +00:00
GameCommand mc;
mc.m_pSteps = pSteps;
mc.m_dc = pSteps->GetDifficulty();
2006-01-17 06:51:22 +00:00
m_aListEntries.push_back( mc );
2005-02-25 05:44:56 +00:00
}
}
2006-01-18 06:44:13 +00:00
else
{
/* We have neither a song nor a course. We may be preloading the screen
* for future use. */
m_Def.m_vsChoices.push_back( "n/a" );
m_aListEntries.push_back( GameCommand() );
}
return RELOAD_CHANGED_ALL;
2005-02-24 11:36:19 +00:00
}
};
2005-02-24 11:36:19 +00:00
class OptionRowHandlerSteps : public OptionRowHandler
{
public:
BroadcastOnChangePtr<Steps> *m_ppStepsToFill;
BroadcastOnChange<Difficulty> *m_pDifficultyToFill;
const BroadcastOnChange<StepsType> *m_pst;
vector<Steps*> m_vSteps;
vector<Difficulty> m_vDifficulties;
OptionRowHandlerSteps() { Init(); }
void Init()
{
OptionRowHandler::Init();
m_ppStepsToFill = NULL;
m_pDifficultyToFill = NULL;
m_vSteps.clear();
m_vDifficulties.clear();
}
virtual void LoadInternal( const Commands &cmds )
{
ASSERT( cmds.v.size() == 1 );
const Command &command = cmds.v[0];
2006-10-11 02:41:24 +00:00
RString sParam = command.GetArg(1).s;
ASSERT( command.m_vsArgs.size() == 2 );
ASSERT( sParam.size() );
if( sParam == "EditSteps" )
{
m_ppStepsToFill = &GAMESTATE->m_pCurSteps[0];
m_pDifficultyToFill = &GAMESTATE->m_PreferredDifficulty[0];
m_pst = &GAMESTATE->m_stEdit;
2006-11-14 04:26:38 +00:00
m_vsReloadRowMessages.push_back( MessageIDToString(Message_EditStepsTypeChanged) );
}
else if( sParam == "EditSourceSteps" )
{
m_ppStepsToFill = &GAMESTATE->m_pEditSourceSteps;
m_pst = &GAMESTATE->m_stEditSource;
2006-11-14 04:26:38 +00:00
m_vsReloadRowMessages.push_back( MessageIDToString(Message_EditSourceStepsTypeChanged) );
if( GAMESTATE->m_pCurSteps[0].Get() != NULL )
m_Def.m_vEnabledForPlayers.clear(); // hide row
}
else
{
RageException::Throw( "Invalid StepsType param \"%s\".", sParam.c_str() );
}
m_Def.m_sName = sParam;
m_Def.m_bOneChoiceForAllPlayers = true;
m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
m_Def.m_bExportOnChange = true;
m_Def.m_bAllowThemeItems = false; // we theme the text ourself
2006-11-14 04:26:38 +00:00
m_vsReloadRowMessages.push_back( MessageIDToString(Message_CurrentSongChanged) );
m_vDifficulties.clear();
m_vSteps.clear();
if( GAMESTATE->m_pCurSong )
{
FOREACH_ENUM( Difficulty, dc )
{
if( dc == Difficulty_Edit )
continue;
m_vDifficulties.push_back( dc );
Steps* pSteps = SongUtil::GetStepsByDifficulty( GAMESTATE->m_pCurSong, *m_pst, dc );
m_vSteps.push_back( pSteps );
}
SongUtil::GetSteps( GAMESTATE->m_pCurSong, m_vSteps, *m_pst, Difficulty_Edit );
m_vDifficulties.resize( m_vSteps.size(), Difficulty_Edit );
if( sParam == "EditSteps" )
{
m_vSteps.push_back( NULL );
m_vDifficulties.push_back( Difficulty_Edit );
}
for( unsigned i=0; i<m_vSteps.size(); i++ )
{
Steps* pSteps = m_vSteps[i];
Difficulty dc = m_vDifficulties[i];
2006-01-22 01:00:06 +00:00
RString s;
if( dc == Difficulty_Edit )
{
if( pSteps )
s = pSteps->GetDescription();
else
s = "NewEdit";
}
else
{
2008-12-21 01:27:33 +00:00
s = GetLocalizedCustomDifficulty( GAMESTATE->m_stEdit, dc );
}
m_Def.m_vsChoices.push_back( s );
}
}
else
{
m_vDifficulties.push_back( Difficulty_Edit );
m_vSteps.push_back( NULL );
m_Def.m_vsChoices.push_back( "none" );
}
if( m_pDifficultyToFill )
m_pDifficultyToFill->Set( m_vDifficulties[0] );
m_ppStepsToFill->Set( m_vSteps[0] );
}
2009-03-22 08:42:27 +00:00
virtual void ImportOption( OptionRow *pRow, const vector<PlayerNumber> &vpns, vector<bool> vbSelectedOut[NUM_PLAYERS] ) const
{
FOREACH_CONST( PlayerNumber, vpns, pn )
{
PlayerNumber p = *pn;
vector<bool> &vbSelOut = vbSelectedOut[p];
ASSERT( m_vSteps.size() == vbSelOut.size() );
// look for matching steps
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();
vbSelOut[i] = true;
return;
}
// look for matching difficulty
if( m_pDifficultyToFill )
{
FOREACH_CONST( Difficulty, m_vDifficulties, d )
{
unsigned i = d - m_vDifficulties.begin();
if( *d == GAMESTATE->m_PreferredDifficulty[0] )
{
vbSelOut[i] = true;
vector<PlayerNumber> v;
v.push_back( p );
2006-01-19 03:43:29 +00:00
ExportOption( v, vbSelectedOut ); // current steps changed
continue;
}
}
}
// default to 1st
vbSelOut[0] = true;
}
}
2006-01-19 03:43:29 +00:00
virtual int ExportOption( const vector<PlayerNumber> &vpns, const vector<bool> vbSelected[NUM_PLAYERS] ) const
{
FOREACH_CONST( PlayerNumber, vpns, pn )
{
PlayerNumber p = *pn;
const vector<bool> &vbSel = vbSelected[p];
int index = OptionRowHandlerUtil::GetOneSelection( vbSel );
Difficulty dc = m_vDifficulties[index];
Steps *pSteps = m_vSteps[index];
if( m_pDifficultyToFill )
m_pDifficultyToFill->Set( dc );
m_ppStepsToFill->Set( pSteps );
}
return 0;
}
};
class OptionRowHandlerListCharacters: public OptionRowHandlerList
{
virtual void LoadInternal( const Commands &cmds )
{
2006-01-18 00:06:25 +00:00
m_Def.m_bOneChoiceForAllPlayers = false;
m_Def.m_bAllowThemeItems = false;
m_Def.m_sName = "Characters";
m_Def.m_iDefault = 0;
2006-01-17 06:51:22 +00:00
m_Default.m_pCharacter = CHARMAN->GetDefaultCharacter();
{
2006-01-18 00:06:25 +00:00
m_Def.m_vsChoices.push_back( OFF );
2005-02-25 05:44:56 +00:00
GameCommand mc;
mc.m_pCharacter = NULL;
2006-01-17 06:51:22 +00:00
m_aListEntries.push_back( mc );
}
2005-02-25 05:44:56 +00:00
vector<Character*> vpCharacters;
CHARMAN->GetCharacters( vpCharacters );
for( unsigned i=0; i<vpCharacters.size(); i++ )
{
Character* pCharacter = vpCharacters[i];
2006-01-22 01:00:06 +00:00
RString s = pCharacter->GetDisplayName();
2005-02-25 05:44:56 +00:00
s.MakeUpper();
2006-01-18 00:06:25 +00:00
m_Def.m_vsChoices.push_back( s );
2005-02-25 05:44:56 +00:00
GameCommand mc;
mc.m_pCharacter = pCharacter;
2006-01-17 06:51:22 +00:00
m_aListEntries.push_back( mc );
}
}
};
class OptionRowHandlerListStyles: public OptionRowHandlerList
{
virtual void LoadInternal( const Commands &cmds )
{
2006-01-18 00:06:25 +00:00
m_Def.m_bOneChoiceForAllPlayers = true;
m_Def.m_sName = "Style";
m_Def.m_bAllowThemeItems = false; // we theme the text ourself
2005-02-25 05:44:56 +00:00
vector<const Style*> vStyles;
2008-03-24 12:50:16 +00:00
GameManager::GetStylesForGame( GAMESTATE->m_pCurGame, vStyles );
2005-02-25 05:44:56 +00:00
ASSERT( vStyles.size() );
FOREACH_CONST( const Style*, vStyles, s )
{
2008-03-24 12:50:16 +00:00
m_Def.m_vsChoices.push_back( GameManager::StyleToLocalizedString(*s) );
2005-02-25 05:44:56 +00:00
GameCommand mc;
mc.m_pStyle = *s;
2006-01-17 06:51:22 +00:00
m_aListEntries.push_back( mc );
2005-02-25 05:44:56 +00:00
}
2006-01-17 06:51:22 +00:00
m_Default.m_pStyle = vStyles[0];
2005-02-25 05:44:56 +00:00
}
};
class OptionRowHandlerListGroups: public OptionRowHandlerList
{
virtual void LoadInternal( const Commands &cmds )
2005-02-25 05:44:56 +00:00
{
2006-01-18 00:06:25 +00:00
m_Def.m_bOneChoiceForAllPlayers = true;
m_Def.m_bAllowThemeItems = false; // we theme the text ourself
m_Def.m_sName = "Group";
2006-01-17 06:51:22 +00:00
m_Default.m_sSongGroup = GROUP_ALL;
2006-01-22 01:00:06 +00:00
vector<RString> vSongGroups;
2005-06-23 08:05:09 +00:00
SONGMAN->GetSongGroupNames( vSongGroups );
ASSERT( vSongGroups.size() );
2005-02-25 05:44:56 +00:00
{
2006-01-18 00:06:25 +00:00
m_Def.m_vsChoices.push_back( "AllGroups" );
2005-02-25 05:44:56 +00:00
GameCommand mc;
2005-06-24 06:06:16 +00:00
mc.m_sSongGroup = GROUP_ALL;
2006-01-17 06:51:22 +00:00
m_aListEntries.push_back( mc );
2005-02-25 05:44:56 +00:00
}
2006-01-22 01:00:06 +00:00
FOREACH_CONST( RString, vSongGroups, g )
2005-02-25 05:44:56 +00:00
{
2006-01-18 00:06:25 +00:00
m_Def.m_vsChoices.push_back( *g );
2005-02-25 05:44:56 +00:00
GameCommand mc;
mc.m_sSongGroup = *g;
2006-01-17 06:51:22 +00:00
m_aListEntries.push_back( mc );
2005-02-25 05:44:56 +00:00
}
}
};
class OptionRowHandlerListDifficulties: public OptionRowHandlerList
{
virtual void LoadInternal( const Commands &cmds )
2005-02-25 05:44:56 +00:00
{
2006-01-18 00:06:25 +00:00
m_Def.m_bOneChoiceForAllPlayers = true;
m_Def.m_sName = "Difficulty";
2006-10-07 04:39:48 +00:00
m_Default.m_dc = Difficulty_Invalid;
2006-01-18 00:06:25 +00:00
m_Def.m_bAllowThemeItems = false; // we theme the text ourself
2005-02-25 05:44:56 +00:00
{
2006-01-18 00:06:25 +00:00
m_Def.m_vsChoices.push_back( "AllDifficulties" );
2005-02-25 05:44:56 +00:00
GameCommand mc;
2006-10-07 04:39:48 +00:00
mc.m_dc = Difficulty_Invalid;
2006-01-17 06:51:22 +00:00
m_aListEntries.push_back( mc );
2005-02-25 05:44:56 +00:00
}
FOREACH_CONST( Difficulty, CommonMetrics::DIFFICULTIES_TO_SHOW.GetValue(), d )
2005-02-25 05:44:56 +00:00
{
2008-12-21 01:27:33 +00:00
StepsType st = GameManager::GetHowToPlayStyleForGame( GAMESTATE->m_pCurGame )->m_StepsType; // TODO: Is this the best thing we can do here?
RString s = GetLocalizedCustomDifficulty( st, *d );
2006-01-18 00:06:25 +00:00
m_Def.m_vsChoices.push_back( s );
2005-02-25 05:44:56 +00:00
GameCommand mc;
mc.m_dc = *d;
2006-01-17 06:51:22 +00:00
m_aListEntries.push_back( mc );
2005-02-25 05:44:56 +00:00
}
}
};
// XXX: very similar to OptionRowHandlerSongChoices
class OptionRowHandlerListSongsInCurrentSongGroup: public OptionRowHandlerList
{
virtual void LoadInternal( const Commands &cmds )
2005-02-25 05:44:56 +00:00
{
2007-04-07 05:11:47 +00:00
const vector<Song*> &vpSongs = SONGMAN->GetSongs( GAMESTATE->m_sPreferredSongGroup );
2005-02-25 05:44:56 +00:00
if( GAMESTATE->m_pCurSong == NULL )
GAMESTATE->m_pCurSong.Set( vpSongs[0] );
2006-01-18 00:06:25 +00:00
m_Def.m_sName = "SongsInCurrentSongGroup";
m_Def.m_bOneChoiceForAllPlayers = true;
m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
m_Def.m_bExportOnChange = true;
2005-02-25 05:44:56 +00:00
FOREACH_CONST( Song*, vpSongs, p )
{
2006-01-18 00:06:25 +00:00
m_Def.m_vsChoices.push_back( (*p)->GetTranslitFullTitle() );
2005-02-25 05:44:56 +00:00
GameCommand mc;
mc.m_pSong = *p;
2006-01-17 06:51:22 +00:00
m_aListEntries.push_back( mc );
2005-02-25 05:44:56 +00:00
}
}
};
2005-02-25 05:44:56 +00:00
class OptionRowHandlerLua : public OptionRowHandler
{
2005-02-25 05:44:56 +00:00
public:
2006-09-21 02:09:44 +00:00
LuaReference *m_pLuaTable;
LuaReference m_EnabledForPlayersFunc;
2006-09-21 02:09:44 +00:00
OptionRowHandlerLua() { m_pLuaTable = new LuaReference; Init(); }
2005-03-07 22:23:14 +00:00
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
}
void SetEnabledForPlayers()
{
Lua *L = LUA->Get();
if( m_EnabledForPlayersFunc.IsNil() )
{
LUA->Release(L);
return;
}
m_EnabledForPlayersFunc.PushSelf( L );
/* Argument 1 (self): */
m_pLuaTable->PushSelf( L );
lua_call( L, 1, 1 ); // call function with 1 argument and 1 result
if( !lua_istable(L, -1) )
RageException::Throw( "\"EnabledForPlayers\" did not return a table." );
m_Def.m_vEnabledForPlayers.clear(); // and fill in with supplied PlayerNumbers below
lua_pushnil( L );
while( lua_next(L, -2) != 0 )
{
/* `key' is at index -2 and `value' at index -1 */
PlayerNumber pn = (PlayerNumber)luaL_checkint( L, -1 );
m_Def.m_vEnabledForPlayers.insert( pn );
lua_pop( L, 1 ); /* removes `value'; keeps `key' for next iteration */
}
lua_pop( L, 1 );
LUA->Release(L);
}
2006-01-18 00:06:25 +00:00
virtual void LoadInternal( const Commands &cmds )
2005-02-25 05:44:56 +00:00
{
ASSERT( cmds.v.size() == 1 );
const Command &command = cmds.v[0];
ASSERT( command.m_vsArgs.size() == 2 );
2006-01-22 01:00:06 +00:00
RString sLuaFunction = command.m_vsArgs[1];
2005-02-25 05:44:56 +00:00
ASSERT( sLuaFunction.size() );
2006-01-18 00:06:25 +00:00
m_Def.m_bAllowThemeItems = false; // Lua options are always dynamic and can theme themselves.
2005-06-16 06:55:34 +00:00
Lua *L = LUA->Get();
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-06-16 06:55:34 +00:00
m_pLuaTable->PushSelf( L );
2005-02-25 05:44:56 +00:00
2005-06-16 06:55:34 +00:00
lua_pushstring( L, "Name" );
lua_gettable( L, -2 );
const char *pStr = lua_tostring( L, -1 );
2005-04-03 06:21:02 +00:00
if( pStr == NULL )
RageException::Throw( "\"%s\" \"Name\" entry is not a string.", sLuaFunction.c_str() );
2006-01-18 00:06:25 +00:00
m_Def.m_sName = pStr;
2005-06-16 06:55:34 +00:00
lua_pop( L, 1 );
2005-02-25 05:44:56 +00:00
2005-06-16 06:55:34 +00:00
lua_pushstring( L, "OneChoiceForAllPlayers" );
lua_gettable( L, -2 );
2006-01-18 00:06:25 +00:00
m_Def.m_bOneChoiceForAllPlayers = !!lua_toboolean( L, -1 );
2005-06-16 06:55:34 +00:00
lua_pop( L, 1 );
2005-02-25 05:44:56 +00:00
2005-06-16 06:55:34 +00:00
lua_pushstring( L, "ExportOnChange" );
lua_gettable( L, -2 );
2006-01-18 00:06:25 +00:00
m_Def.m_bExportOnChange = !!lua_toboolean( L, -1 );
2005-06-16 06:55:34 +00:00
lua_pop( L, 1 );
2005-03-08 17:54:12 +00:00
2005-06-16 06:55:34 +00:00
lua_pushstring( L, "LayoutType" );
lua_gettable( L, -2 );
pStr = lua_tostring( L, -1 );
2005-04-03 06:21:02 +00:00
if( pStr == NULL )
RageException::Throw( "\"%s\" \"LayoutType\" entry is not a string.", sLuaFunction.c_str() );
2006-01-18 00:06:25 +00:00
m_Def.m_layoutType = StringToLayoutType( pStr );
2006-09-26 20:49:10 +00:00
ASSERT( m_Def.m_layoutType != LayoutType_Invalid );
2005-06-16 06:55:34 +00:00
lua_pop( L, 1 );
2005-02-25 05:44:56 +00:00
2005-06-16 06:55:34 +00:00
lua_pushstring( L, "SelectType" );
lua_gettable( L, -2 );
pStr = lua_tostring( L, -1 );
2005-04-03 06:21:02 +00:00
if( pStr == NULL )
RageException::Throw( "\"%s\" \"SelectType\" entry is not a string.", sLuaFunction.c_str() );
2006-01-18 00:06:25 +00:00
m_Def.m_selectType = StringToSelectType( pStr );
2006-09-26 20:49:10 +00:00
ASSERT( m_Def.m_selectType != SelectType_Invalid );
2005-06-16 06:55:34 +00:00
lua_pop( L, 1 );
2005-02-25 05:44:56 +00:00
2005-04-03 06:21:02 +00:00
/* Iterate over the "Choices" table. */
2005-06-16 06:55:34 +00:00
lua_pushstring( L, "Choices" );
lua_gettable( L, -2 );
if( !lua_istable( L, -1 ) )
RageException::Throw( "\"%s\" \"Choices\" is not a table.", sLuaFunction.c_str() );
2005-04-03 06:21:02 +00:00
2005-06-16 06:55:34 +00:00
lua_pushnil( L );
while( lua_next(L, -2) != 0 )
2005-04-03 06:21:02 +00:00
{
/* `key' is at index -2 and `value' at index -1 */
2005-06-16 06:55:34 +00:00
const char *pValue = lua_tostring( L, -1 );
2005-04-03 06:21:02 +00:00
if( pValue == NULL )
RageException::Throw( "\"%s\" Column entry is not a string.", sLuaFunction.c_str() );
2005-04-03 06:21:02 +00:00
// LOG->Trace( "'%s'", pValue);
2006-01-18 00:06:25 +00:00
m_Def.m_vsChoices.push_back( pValue );
2005-04-03 06:21:02 +00:00
2005-06-16 06:55:34 +00:00
lua_pop( L, 1 ); /* removes `value'; keeps `key' for next iteration */
2005-04-03 06:21:02 +00:00
}
2005-06-16 06:55:34 +00:00
lua_pop( L, 1 ); /* pop choices table */
2005-04-03 06:21:02 +00:00
/* Set the EnabledForPlayers function. */
2005-06-16 06:55:34 +00:00
lua_pushstring( L, "EnabledForPlayers" );
lua_gettable( L, -2 );
if( !lua_isfunction( L, -1 ) && !lua_isnil( L, -1 ) )
RageException::Throw( "\"%s\" \"EnabledForPlayers\" is not a table.", sLuaFunction.c_str() );
m_EnabledForPlayersFunc.SetFromStack( L );
SetEnabledForPlayers();
2005-04-03 06:21:02 +00:00
/* Iterate over the "ReloadRowMessages" table. */
2005-06-16 06:55:34 +00:00
lua_pushstring( L, "ReloadRowMessages" );
lua_gettable( L, -2 );
if( !lua_isnil( L, -1 ) )
2005-04-03 06:21:02 +00:00
{
2005-06-16 06:55:34 +00:00
if( !lua_istable( L, -1 ) )
RageException::Throw( "\"%s\" \"ReloadRowMessages\" is not a table.", sLuaFunction.c_str() );
2005-06-16 06:55:34 +00:00
lua_pushnil( L );
while( lua_next(L, -2) != 0 )
2005-02-25 05:44:56 +00:00
{
2005-04-03 06:21:02 +00:00
/* `key' is at index -2 and `value' at index -1 */
2005-06-16 06:55:34 +00:00
const char *pValue = lua_tostring( L, -1 );
2005-04-03 06:21:02 +00:00
if( pValue == NULL )
RageException::Throw( "\"%s\" Column entry is not a string.", sLuaFunction.c_str() );
2005-04-03 06:21:02 +00:00
LOG->Trace( "Found ReloadRowMessage '%s'", pValue);
2005-04-03 06:21:02 +00:00
m_vsReloadRowMessages.push_back( pValue );
2005-06-16 06:55:34 +00:00
lua_pop( L, 1 ); /* removes `value'; keeps `key' for next iteration */
}
2005-04-03 06:21:02 +00:00
}
2005-06-16 06:55:34 +00:00
lua_pop( L, 1 ); /* pop ReloadRowMessages table */
2005-04-03 06:21:02 +00:00
/* Look for "ExportOnChange" value. */
2005-06-16 06:55:34 +00:00
lua_pushstring( L, "ExportOnChange" );
lua_gettable( L, -2 );
if( !lua_isnil( L, -1 ) )
2005-04-03 06:21:02 +00:00
{
2006-01-18 00:06:25 +00:00
m_Def.m_bExportOnChange = !!MyLua_checkboolean( L, -1 );
2005-04-03 06:21:02 +00:00
}
2005-06-16 06:55:34 +00:00
lua_pop( L, 1 ); /* pop ExportOnChange value */
2005-03-01 01:15:22 +00:00
2005-06-16 06:55:34 +00:00
lua_pop( L, 1 ); /* pop main table */
ASSERT( lua_gettop(L) == 0 );
2005-03-01 01:15:22 +00:00
2005-06-16 06:55:34 +00:00
LUA->Release(L);
2005-04-03 06:21:02 +00:00
}
virtual ReloadChanged Reload()
{
SetEnabledForPlayers();
return RELOAD_CHANGED_ENABLED;
2005-02-25 05:44:56 +00:00
}
2009-03-22 08:42:27 +00:00
virtual void ImportOption( OptionRow *pRow, const vector<PlayerNumber> &vpns, vector<bool> vbSelectedOut[NUM_PLAYERS] ) const
{
2005-06-16 06:55:34 +00:00
Lua *L = LUA->Get();
ASSERT( lua_gettop(L) == 0 );
2005-04-03 06:21:02 +00:00
FOREACH_CONST( PlayerNumber, vpns, pn )
{
PlayerNumber p = *pn;
vector<bool> &vbSelOut = vbSelectedOut[p];
2005-04-03 06:21:02 +00:00
/* Evaluate the LoadSelections(self,array,pn) function, where array is a table
* representing vbSelectedOut. */
2005-04-03 06:21:02 +00:00
/* All selections default to false. */
for( unsigned i = 0; i < vbSelOut.size(); ++i )
vbSelOut[i] = false;
2005-04-03 06:21:02 +00:00
/* Create the vbSelectedOut table. */
2005-06-16 06:55:34 +00:00
LuaHelpers::CreateTableFromArrayB( L, vbSelOut );
ASSERT( lua_gettop(L) == 1 ); /* vbSelectedOut table */
2005-04-03 06:21:02 +00:00
/* Get the function to call from m_LuaTable. */
2005-06-16 06:55:34 +00:00
m_pLuaTable->PushSelf( L );
ASSERT( lua_istable( L, -1 ) );
2005-06-16 06:55:34 +00:00
lua_pushstring( L, "LoadSelections" );
lua_gettable( L, -2 );
if( !lua_isfunction( L, -1 ) )
RageException::Throw( "\"%s\" \"LoadSelections\" entry is not a function.", m_Def.m_sName.c_str() );
2005-04-03 06:21:02 +00:00
/* Argument 1 (self): */
2005-06-16 06:55:34 +00:00
m_pLuaTable->PushSelf( L );
2005-04-03 06:21:02 +00:00
/* Argument 2 (vbSelectedOut): */
2005-06-16 06:55:34 +00:00
lua_pushvalue( L, 1 );
2005-04-03 06:21:02 +00:00
/* Argument 3 (pn): */
2006-09-26 08:54:54 +00:00
LuaHelpers::Push( L, p );
2005-06-16 06:55:34 +00:00
ASSERT( lua_gettop(L) == 6 ); /* vbSelectedOut, m_iLuaTable, function, self, arg, arg */
2005-06-16 06:55:34 +00:00
lua_call( L, 3, 0 ); // call function with 3 arguments and 0 results
ASSERT( lua_gettop(L) == 2 );
2005-06-16 06:55:34 +00:00
lua_pop( L, 1 ); /* pop option table */
2005-06-16 06:55:34 +00:00
LuaHelpers::ReadArrayFromTableB( L, vbSelOut );
2005-04-03 06:21:02 +00:00
2005-06-16 06:55:34 +00:00
lua_pop( L, 1 ); /* pop vbSelectedOut table */
2005-04-03 06:21:02 +00:00
2005-06-16 06:55:34 +00:00
ASSERT( lua_gettop(L) == 0 );
2005-04-03 06:21:02 +00:00
}
2005-06-16 06:55:34 +00:00
LUA->Release(L);
2005-02-25 05:44:56 +00:00
}
2006-01-19 03:43:29 +00:00
virtual int ExportOption( const vector<PlayerNumber> &vpns, const vector<bool> vbSelected[NUM_PLAYERS] ) const
2005-02-25 05:44:56 +00:00
{
2005-06-16 06:55:34 +00:00
Lua *L = LUA->Get();
ASSERT( lua_gettop(L) == 0 );
2005-04-03 06:21:02 +00:00
FOREACH_CONST( PlayerNumber, vpns, pn )
{
PlayerNumber p = *pn;
const vector<bool> &vbSel = vbSelected[p];
2005-04-03 06:21:02 +00:00
/* Evaluate SaveSelections(self,array,pn) function, where array is a table
* representing vbSelectedOut. */
2005-04-03 06:21:02 +00:00
vector<bool> vbSelectedCopy = vbSel;
2005-04-03 06:21:02 +00:00
/* Create the vbSelectedOut table. */
2005-06-16 06:55:34 +00:00
LuaHelpers::CreateTableFromArrayB( L, vbSelectedCopy );
ASSERT( lua_gettop(L) == 1 ); /* vbSelectedOut table */
2005-04-03 06:21:02 +00:00
/* Get the function to call. */
2005-06-16 06:55:34 +00:00
m_pLuaTable->PushSelf( L );
ASSERT( lua_istable( L, -1 ) );
2005-06-16 06:55:34 +00:00
lua_pushstring( L, "SaveSelections" );
lua_gettable( L, -2 );
if( !lua_isfunction( L, -1 ) )
RageException::Throw( "\"%s\" \"SaveSelections\" entry is not a function.", m_Def.m_sName.c_str() );
2005-04-03 06:21:02 +00:00
/* Argument 1 (self): */
2005-06-16 06:55:34 +00:00
m_pLuaTable->PushSelf( L );
2005-04-03 06:21:02 +00:00
/* Argument 2 (vbSelectedOut): */
2005-06-16 06:55:34 +00:00
lua_pushvalue( L, 1 );
2005-04-03 06:21:02 +00:00
/* Argument 3 (pn): */
2006-09-26 08:54:54 +00:00
LuaHelpers::Push( L, p );
2005-06-16 06:55:34 +00:00
ASSERT( lua_gettop(L) == 6 ); /* vbSelectedOut, m_iLuaTable, function, self, arg, arg */
2005-06-16 06:55:34 +00:00
lua_call( L, 3, 0 ); // call function with 3 arguments and 0 results
ASSERT( lua_gettop(L) == 2 );
2005-06-16 06:55:34 +00:00
lua_pop( L, 1 ); /* pop option table */
lua_pop( L, 1 ); /* pop vbSelected table */
2005-04-03 06:21:02 +00:00
2005-06-16 06:55:34 +00:00
ASSERT( lua_gettop(L) == 0 );
2005-04-03 06:21:02 +00:00
}
2005-02-25 05:44:56 +00:00
2005-06-16 06:55:34 +00:00
LUA->Release(L);
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:
2006-11-21 03:48:12 +00:00
const ConfOption *m_pOpt;
2005-02-24 07:58:03 +00:00
2006-01-16 22:38:53 +00:00
OptionRowHandlerConfig() { Init(); }
2005-02-25 05:44:56 +00:00
void Init()
2005-02-24 07:58:03 +00:00
{
2005-02-25 05:44:56 +00:00
OptionRowHandler::Init();
2006-11-21 03:48:12 +00:00
m_pOpt = NULL;
2005-02-24 07:58:03 +00:00
}
2006-01-18 00:06:25 +00:00
virtual void LoadInternal( const Commands &cmds )
2005-02-25 05:44:56 +00:00
{
ASSERT( cmds.v.size() == 1 );
const Command &command = cmds.v[0];
2006-10-11 02:41:24 +00:00
RString sParam = command.GetArg(1).s;
ASSERT( command.m_vsArgs.size() == 2 );
2005-02-25 05:44:56 +00:00
ASSERT( sParam.size() );
2005-02-25 05:44:56 +00:00
Init();
2005-02-25 05:44:56 +00:00
/* Configuration values are never per-player. */
2006-01-18 00:06:25 +00:00
m_Def.m_bOneChoiceForAllPlayers = true;
2005-02-25 05:44:56 +00:00
ConfOption *pConfOption = ConfOption::Find( sParam );
if( pConfOption == NULL )
2006-07-05 02:39:47 +00:00
{
LOG->Warn( "Invalid Conf type \"%s\"", sParam.c_str() );
pConfOption = ConfOption::Find( "Invalid" );
ASSERT_M( pConfOption != NULL, "ConfOption::Find(Invalid)" );
}
2005-02-25 05:44:56 +00:00
pConfOption->UpdateAvailableOptions();
2006-11-21 03:48:12 +00:00
m_pOpt = pConfOption;
m_pOpt->MakeOptionsList( m_Def.m_vsChoices );
2005-02-25 05:44:56 +00:00
2006-11-21 03:48:12 +00:00
m_Def.m_bAllowThemeItems = m_pOpt->m_bAllowThemeItems;
2005-12-01 19:27:33 +00:00
2006-11-21 03:48:12 +00:00
m_Def.m_sName = m_pOpt->name;
}
2009-03-22 08:42:27 +00:00
virtual void ImportOption( OptionRow *pRow, const vector<PlayerNumber> &vpns, vector<bool> vbSelectedOut[NUM_PLAYERS] ) const
{
2005-04-03 06:21:02 +00:00
FOREACH_CONST( PlayerNumber, vpns, pn )
{
PlayerNumber p = *pn;
vector<bool> &vbSelOut = vbSelectedOut[p];
2006-11-21 03:48:12 +00:00
int iSelection = m_pOpt->Get();
OptionRowHandlerUtil::SelectExactlyOne( iSelection, vbSelOut );
2005-04-03 06:21:02 +00:00
}
}
2006-01-19 03:43:29 +00:00
virtual int ExportOption( const vector<PlayerNumber> &vpns, const vector<bool> vbSelected[NUM_PLAYERS] ) const
2005-02-25 05:44:56 +00:00
{
2005-04-03 06:21:02 +00:00
bool bChanged = false;
FOREACH_CONST( PlayerNumber, vpns, pn )
{
PlayerNumber p = *pn;
const vector<bool> &vbSel = vbSelected[p];
2006-11-21 03:48:12 +00:00
int iSel = OptionRowHandlerUtil::GetOneSelection(vbSel);
2005-02-24 11:36:19 +00:00
2005-04-03 06:21:02 +00:00
/* Get the original choice. */
2006-11-21 03:48:12 +00:00
int iOriginal = m_pOpt->Get();
2005-02-24 11:36:19 +00:00
2005-04-03 06:21:02 +00:00
/* Apply. */
2006-11-21 03:48:12 +00:00
m_pOpt->Put( iSel );
2005-02-24 11:36:19 +00:00
2005-04-03 06:21:02 +00:00
/* Get the new choice. */
2006-11-21 03:48:12 +00:00
int iNew = m_pOpt->Get();
2005-04-03 06:21:02 +00:00
/* If it didn't change, don't return any side-effects. */
2006-11-21 03:48:12 +00:00
if( iOriginal != iNew )
2005-04-03 06:21:02 +00:00
bChanged = true;
}
2005-02-24 11:36:19 +00:00
2006-11-21 03:48:12 +00:00
return bChanged ? m_pOpt->GetEffects() : 0;
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;
2006-01-16 22:38:53 +00:00
OptionRowHandlerStepsType() { Init(); }
2005-02-25 05:44:56 +00:00
void Init()
{
OptionRowHandler::Init();
m_pstToFill = NULL;
m_vStepsTypesToShow.clear();
}
2006-01-18 00:06:25 +00:00
virtual void LoadInternal( const Commands &cmds )
2005-02-25 05:44:56 +00:00
{
ASSERT( cmds.v.size() == 1 );
const Command &command = cmds.v[0];
2006-10-11 02:41:24 +00:00
RString sParam = command.GetArg(1).s;
ASSERT( command.m_vsArgs.size() == 2 );
2005-02-25 05:44:56 +00:00
ASSERT( sParam.size() );
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;
2006-11-14 04:26:38 +00:00
m_vsReloadRowMessages.push_back( MessageIDToString(Message_CurrentStepsP1Changed) );
m_vsReloadRowMessages.push_back( MessageIDToString(Message_EditStepsTypeChanged) );
2005-02-26 11:21:50 +00:00
if( GAMESTATE->m_pCurSteps[0].Get() != NULL )
2006-01-18 00:06:25 +00:00
m_Def.m_vEnabledForPlayers.clear(); // hide row
2005-02-26 11:21:50 +00:00
}
2005-02-25 05:44:56 +00:00
else
2005-02-26 11:21:50 +00:00
{
RageException::Throw( "Invalid StepsType param \"%s\".", sParam.c_str() );
2005-02-26 11:21:50 +00:00
}
2006-01-18 00:06:25 +00:00
m_Def.m_sName = sParam;
m_Def.m_bOneChoiceForAllPlayers = true;
m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
m_Def.m_bExportOnChange = true;
m_Def.m_bAllowThemeItems = false; // we theme the text ourself
2005-02-25 05:44:56 +00:00
// calculate which StepsTypes to show
m_vStepsTypesToShow = CommonMetrics::STEPS_TYPES_TO_SHOW.GetValue();
m_Def.m_vsChoices.clear();
2005-02-25 05:44:56 +00:00
FOREACH_CONST( StepsType, m_vStepsTypesToShow, st )
{
RString s = GameManager::GetStepsTypeInfo( *st ).GetLocalizedString();
2006-01-18 00:06:25 +00:00
m_Def.m_vsChoices.push_back( s );
2005-02-25 05:44:56 +00:00
}
2006-09-26 20:28:46 +00:00
if( *m_pstToFill == StepsType_Invalid )
2005-02-25 05:44:56 +00:00
m_pstToFill->Set( m_vStepsTypesToShow[0] );
}
2009-03-22 08:42:27 +00:00
virtual void ImportOption( OptionRow *pRow, const vector<PlayerNumber> &vpns, vector<bool> vbSelectedOut[NUM_PLAYERS] ) const
{
2005-04-03 06:21:02 +00:00
FOREACH_CONST( PlayerNumber, vpns, pn )
2005-02-25 05:44:56 +00:00
{
2005-04-03 06:21:02 +00:00
PlayerNumber p = *pn;
vector<bool> &vbSelOut = vbSelectedOut[p];
if( GAMESTATE->m_pCurSteps[0] )
2005-02-25 05:44:56 +00:00
{
2005-04-03 06:21:02 +00:00
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();
vbSelOut[i] = true;
continue; // done with this player
}
2005-02-25 05:44:56 +00:00
}
2005-04-03 06:21:02 +00:00
vbSelOut[0] = true;
2005-02-25 05:44:56 +00:00
}
}
2006-01-19 03:43:29 +00:00
virtual int ExportOption( const vector<PlayerNumber> &vpns, const vector<bool> vbSelected[NUM_PLAYERS] ) const
{
2005-04-03 06:21:02 +00:00
FOREACH_CONST( PlayerNumber, vpns, pn )
{
PlayerNumber p = *pn;
const vector<bool> &vbSel = vbSelected[p];
int index = OptionRowHandlerUtil::GetOneSelection( vbSel );
2005-04-03 06:21:02 +00:00
m_pstToFill->Set( m_vStepsTypesToShow[index] );
}
2005-02-25 05:44:56 +00:00
return 0;
}
2005-02-25 05:44:56 +00:00
};
class OptionRowHandlerGameCommand : public OptionRowHandler
{
public:
GameCommand m_gc;
2006-01-16 22:38:53 +00:00
OptionRowHandlerGameCommand() { Init(); }
void Init()
{
2006-01-17 20:19:04 +00:00
OptionRowHandler::Init();
m_gc.Init();
m_gc.ApplyCommitsScreens( false );
}
2006-01-18 00:06:25 +00:00
virtual void LoadInternal( const Commands &cmds )
{
ASSERT( cmds.v.size() > 1 );
Commands temp = cmds;
temp.v.erase( temp.v.begin() );
m_gc.Load( 0, temp );
ASSERT( !m_gc.m_sName.empty() );
2006-01-18 00:06:25 +00:00
m_Def.m_sName = m_gc.m_sName;
m_Def.m_bOneChoiceForAllPlayers = true;
m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
m_Def.m_selectType = SELECT_NONE;
m_Def.m_vsChoices.push_back( "" );
}
2009-03-22 08:42:27 +00:00
virtual void ImportOption( OptionRow *pRow, const vector<PlayerNumber> &vpns, vector<bool> vbSelectedOut[NUM_PLAYERS] ) const
{
}
2006-01-19 03:43:29 +00:00
virtual int ExportOption( const vector<PlayerNumber> &vpns, const vector<bool> vbSelected[NUM_PLAYERS] ) const
{
2007-06-20 15:17:52 +00:00
if( vbSelected[PLAYER_1][0] || vbSelected[PLAYER_2][0] )
m_gc.ApplyToAllPlayers();
return 0;
}
2006-01-22 01:00:06 +00:00
virtual void GetIconTextAndGameCommand( int iFirstSelection, RString &sIconTextOut, GameCommand &gcOut ) const
{
sIconTextOut = "";
gcOut = m_gc;
}
virtual RString GetScreen( int iChoice ) const
{
return m_gc.m_sScreen;
}
};
2006-01-17 20:39:56 +00:00
class OptionRowHandlerNull: public OptionRowHandler
{
public:
OptionRowHandlerNull() { Init(); }
};
2005-02-25 05:44:56 +00:00
///////////////////////////////////////////////////////////////////////////////////
2005-02-24 11:36:19 +00:00
2006-01-17 20:36:29 +00:00
OptionRowHandler* OptionRowHandlerUtil::Make( const Commands &cmds )
{
OptionRowHandler* pHand = NULL;
if( cmds.v.size() == 0 )
return NULL;
2006-01-22 01:00:06 +00:00
const RString &name = cmds.v[0].GetName();
2006-01-17 20:36:29 +00:00
#define MAKE( type ) { type *p = new type; p->Load( cmds ); pHand = p; }
// XXX: merge these, and merge "Steps" and "list,Steps"
if( name == "list" )
{
const Command &command = cmds.v[0];
2006-10-11 02:41:24 +00:00
RString sParam = command.GetArg(1).s;
if( command.m_vsArgs.size() != 2 || !sParam.size() )
return NULL;
if( sParam.CompareNoCase("NoteSkins")==0 ) MAKE( OptionRowHandlerListNoteSkins )
else if( sParam.CompareNoCase("Steps")==0 ) MAKE( OptionRowHandlerListSteps )
else if( sParam.CompareNoCase("StepsLocked")==0 )
{
MAKE( OptionRowHandlerListSteps );
pHand->m_Def.m_bOneChoiceForAllPlayers = true;
}
else if( sParam.CompareNoCase("Characters")==0 ) MAKE( OptionRowHandlerListCharacters )
else if( sParam.CompareNoCase("Styles")==0 ) MAKE( OptionRowHandlerListStyles )
else if( sParam.CompareNoCase("Groups")==0 ) MAKE( OptionRowHandlerListGroups )
else if( sParam.CompareNoCase("Difficulties")==0 ) MAKE( OptionRowHandlerListDifficulties )
else if( sParam.CompareNoCase("SongsInCurrentSongGroup")==0 ) MAKE( OptionRowHandlerListSongsInCurrentSongGroup )
else MAKE( OptionRowHandlerList )
}
2006-01-17 23:26:49 +00:00
else if( name == "lua" ) MAKE( OptionRowHandlerLua )
else if( name == "conf" ) MAKE( OptionRowHandlerConfig )
else if( name == "stepstype" ) MAKE( OptionRowHandlerStepsType )
2006-01-17 23:26:49 +00:00
else if( name == "steps" ) MAKE( OptionRowHandlerSteps )
else if( name == "gamecommand" ) MAKE( OptionRowHandlerGameCommand )
return pHand;
}
2006-01-17 20:39:56 +00:00
OptionRowHandler* OptionRowHandlerUtil::MakeNull()
{
OptionRowHandler* pHand = NULL;
Commands cmds;
MAKE( OptionRowHandlerNull )
return pHand;
}
OptionRowHandler* OptionRowHandlerUtil::MakeSimple( const MenuRowDef &mr )
{
OptionRowHandler *pHand = OptionRowHandlerUtil::MakeNull();
pHand->m_Def.m_sName = mr.sName;
FontCharAliases::ReplaceMarkers( pHand->m_Def.m_sName ); // Allow special characters
pHand->m_Def.m_vEnabledForPlayers.clear();
if( mr.pfnEnabled? mr.pfnEnabled():mr.bEnabled )
{
FOREACH_EnabledPlayer( pn )
pHand->m_Def.m_vEnabledForPlayers.insert( pn );
}
pHand->m_Def.m_bOneChoiceForAllPlayers = true;
pHand->m_Def.m_selectType = SELECT_ONE;
pHand->m_Def.m_layoutType = LAYOUT_SHOW_ONE_IN_ROW;
2006-09-01 04:29:24 +00:00
pHand->m_Def.m_bExportOnChange = false;//true;
pHand->m_Def.m_vsChoices = mr.choices;
// Each row must have at least one choice.
if( pHand->m_Def.m_vsChoices.empty() )
pHand->m_Def.m_vsChoices.push_back( "" );
pHand->m_Def.m_bAllowThemeTitle = mr.bThemeTitle;
pHand->m_Def.m_bAllowThemeItems = mr.bThemeItems;
FOREACH( RString, pHand->m_Def.m_vsChoices, c )
FontCharAliases::ReplaceMarkers( *c ); // Allow special characters
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.
*/