Changed default ScreenSelecStyle to use functions for choice names and positions instead of metrics. _fallback SSS remains the same for compatibility. Fixed style stomping bug in SetCompatibleStylesForPlayers.

This commit is contained in:
Kyzentun
2015-01-20 18:40:59 -07:00
parent f4a718a824
commit aeaead95c9
10 changed files with 231 additions and 111 deletions
+2 -2
View File
@@ -1300,9 +1300,9 @@ void Actor::QueueMessage( const RString& sMessageName )
TI.m_sCommandName = "!" + sMessageName;
}
void Actor::AddCommand( const RString &sCmdName, apActorCommands apac )
void Actor::AddCommand( const RString &sCmdName, apActorCommands apac, bool warn )
{
if( HasCommand(sCmdName) )
if( HasCommand(sCmdName) && warn)
{
RString sWarning = GetLineage()+"'s command '"+sCmdName+"' defined twice";
LuaHelpers::ReportScriptError(sWarning, "COMMAND_DEFINED_TWICE");
+1 -1
View File
@@ -577,7 +577,7 @@ public:
virtual void PushContext( lua_State *L );
// Named commands
void AddCommand( const RString &sCmdName, apActorCommands apac );
void AddCommand( const RString &sCmdName, apActorCommands apac, bool warn= true );
bool HasCommand( const RString &sCmdName ) const;
const apActorCommands *GetCommand( const RString &sCommandName ) const;
void PlayCommand( const RString &sCommandName ) { HandleMessage( Message(sCommandName) ); } // convenience
+3 -3
View File
@@ -3163,12 +3163,12 @@ static const Style g_Style_Kickbox_Arachnid_Versus=
static const Style* g_apGame_Kickbox_Styles[] =
{
&g_Style_Kickbox_Human,
&g_Style_Kickbox_Human_Versus,
&g_Style_Kickbox_Quadarm,
&g_Style_Kickbox_Quadarm_Versus,
&g_Style_Kickbox_Insect,
&g_Style_Kickbox_Insect_Versus,
&g_Style_Kickbox_Arachnid,
&g_Style_Kickbox_Human_Versus,
&g_Style_Kickbox_Quadarm_Versus,
&g_Style_Kickbox_Insect_Versus,
&g_Style_Kickbox_Arachnid_Versus,
NULL
};
+17 -28
View File
@@ -998,7 +998,7 @@ void GameState::SetCompatibleStylesForPlayers()
SetCurrentStyle(style, PLAYER_INVALID);
}
}
else
else if(GetCurrentStyle(PLAYER_INVALID) == NULL)
{
vector<StepsType> vst;
GAMEMAN->GetStepsTypesForGame(m_pCurGame, vst);
@@ -1009,37 +1009,26 @@ void GameState::SetCompatibleStylesForPlayers()
}
if(!style_set)
{
if(GetCurrentGame()->m_PlayersHaveSeparateStyles)
FOREACH_EnabledPlayer(pn)
{
FOREACH_EnabledPlayer(pn)
StepsType st= StepsType_Invalid;
if(m_pCurSteps[pn] != NULL)
{
StepsType st= StepsType_Invalid;
if(m_pCurSteps[pn] != NULL)
{
st= m_pCurSteps[pn]->m_StepsType;
}
else if(m_pCurTrail[pn] != NULL)
{
st= m_pCurTrail[pn]->m_StepsType;
}
else
{
vector<StepsType> vst;
GAMEMAN->GetStepsTypesForGame(m_pCurGame, vst);
st= vst[0];
}
const Style *style = GAMEMAN->GetFirstCompatibleStyle(
m_pCurGame, GetNumSidesJoined(), st);
SetCurrentStyle(style, pn);
st= m_pCurSteps[pn]->m_StepsType;
}
else if(m_pCurTrail[pn] != NULL)
{
st= m_pCurTrail[pn]->m_StepsType;
}
else
{
vector<StepsType> vst;
GAMEMAN->GetStepsTypesForGame(m_pCurGame, vst);
st= vst[0];
}
}
else
{
vector<StepsType> vst;
GAMEMAN->GetStepsTypesForGame(m_pCurGame, vst);
const Style *style = GAMEMAN->GetFirstCompatibleStyle(
m_pCurGame, GetNumSidesJoined(), vst[0]);
SetCurrentStyle(style, PLAYER_INVALID);
m_pCurGame, GetNumSidesJoined(), st);
SetCurrentStyle(style, pn);
}
}
}
+40
View File
@@ -31,6 +31,46 @@ void ScreenSelect::Init()
this->SubscribeToMessage( Message_PlayerJoined );
// Load choices
// Allow lua as an alternative to metrics.
RString choice_names= CHOICE_NAMES;
if(choice_names.Left(4) == "lua,")
{
RString command= choice_names.Right(choice_names.size()-4);
Lua* L= LUA->Get();
if(LuaHelpers::RunExpression(L, command, m_sName + "::ChoiceNames"))
{
if(!lua_istable(L, 1))
{
LuaHelpers::ReportScriptError(m_sName + "::ChoiceNames expression did not return a table of gamecommands.");
}
else
{
size_t len= lua_objlen(L, 1);
for(size_t i= 1; i <= len; ++i)
{
lua_rawgeti(L, 1, i);
if(!lua_isstring(L, -1))
{
LuaHelpers::ReportScriptErrorFmt(m_sName + "::ChoiceNames element %zu is not a string.", i);
}
else
{
RString com= SArg(-1);
GameCommand mc;
mc.ApplyCommitsScreens(false);
mc.m_sName = ssprintf("%zu", i);
Commands cmd= ParseCommands(com);
mc.Load(i, cmd);
m_aGameCommands.push_back(mc);
}
lua_pop(L, 1);
}
}
}
lua_settop(L, 0);
LUA->Release(L);
}
else
{
// Instead of using NUM_CHOICES, use a comma-separated list of choices.
// Each element in the list is a choice name. This level of indirection
+82 -1
View File
@@ -104,6 +104,68 @@ void ScreenSelectMaster::Init()
FOREACH( PlayerNumber, vpns, p )
m_vsprScroll[*p].resize( m_aGameCommands.size() );
vector<RageVector3> positions;
bool positions_set_by_lua= false;
if(THEME->HasMetric(m_sName, "IconChoicePosFunction"))
{
positions_set_by_lua= true;
LuaReference command= THEME->GetMetricR(m_sName, "IconChoicePosFunction");
if(command.GetLuaType() != LUA_TFUNCTION)
{
LuaHelpers::ReportScriptError(m_sName+"::IconChoicePosFunction must be a function.");
positions_set_by_lua= false;
}
else
{
Lua* L= LUA->Get();
command.PushSelf(L);
lua_pushnumber(L, m_aGameCommands.size());
RString err= m_sName + "::IconChoicePosFunction: ";
if(!LuaHelpers::RunScriptOnStack(L, err, 1, 1, true))
{
positions_set_by_lua= false;
}
else
{
if(!lua_istable(L, -1))
{
LuaHelpers::ReportScriptError(m_sName+"::IconChoicePosFunction did not return a table of positions.");
positions_set_by_lua= false;
}
else
{
size_t poses= lua_objlen(L, -1);
for(size_t p= 1; p <= poses; ++p)
{
lua_rawgeti(L, -1, p);
RageVector3 pos(0.0f, 0.0f, 0.0f);
if(!lua_istable(L, -1))
{
LuaHelpers::ReportScriptErrorFmt("Position %zu is not a table.", p);
}
else
{
#define SET_POS_PART(i, part) \
lua_rawgeti(L, -1, i); \
pos.part= lua_tonumber(L, -1); \
lua_pop(L, 1);
// If part of the position is not provided, we want it to
// default to zero, which lua_tonumber does. -Kyz
SET_POS_PART(1, x);
SET_POS_PART(2, y);
SET_POS_PART(3, z);
#undef SET_POS_PART
}
lua_pop(L, 1);
positions.push_back(pos);
}
}
}
lua_settop(L, 0);
LUA->Release(L);
}
}
for( unsigned c=0; c<m_aGameCommands.size(); c++ )
{
GameCommand& mc = m_aGameCommands[c];
@@ -122,7 +184,26 @@ void ScreenSelectMaster::Init()
RString sName = "Icon" "Choice" + mc.m_sName;
m_vsprIcon[c]->SetName( sName );
if( USE_ICON_METRICS )
LOAD_ALL_COMMANDS_AND_SET_XY( m_vsprIcon[c] );
{
if(positions_set_by_lua)
{
LOAD_ALL_COMMANDS(m_vsprIcon[c]);
m_vsprIcon[c]->SetXY(positions[c].x, positions[c].y);
m_vsprIcon[c]->SetZ(positions[c].z);
}
else
{
LOAD_ALL_COMMANDS_AND_SET_XY( m_vsprIcon[c] );
}
#define OPTIONAL_COMMAND(onoff) \
if(THEME->HasMetric(m_sName, "IconChoice" onoff "Command")) \
{ \
m_vsprIcon[c]->AddCommand(onoff, THEME->GetMetricA(m_sName, "IconChoice" onoff "Command"), false); \
}
OPTIONAL_COMMAND("On");
OPTIONAL_COMMAND("Off");
#undef OPTIONAL_COMMAND
}
this->AddChild( m_vsprIcon[c] );
}