add ScreenSelectMaster:GetSelectionIndex() Lua binding.

Example usage:
LoadFont("Common normal")..{
	InitCommand=cmd(xy,SCREEN_RIGHT-32,SCREEN_BOTTOM-32;shadowlength,0;horizalign,right);
	OnCommand=cmd(playcommand,"Set");
	SetCommand=function(self)
		local selIdx = SCREENMAN:GetTopScreen():GetSelectionIndex(GAMESTATE:GetMasterPlayerNumber());
		self:settext(selIdx);
	end;
	MenuSelectionChangedMessageCommand=cmd(playcommand,"Set");
};
This commit is contained in:
AJ Kelly
2010-03-09 03:20:44 -06:00
parent 9cf1f44443
commit 74d7895ccd
2 changed files with 40 additions and 16 deletions
+31 -10
View File
@@ -814,7 +814,7 @@ bool ScreenSelectMaster::ChangeSelection( PlayerNumber pn, MenuDir dir, int iNew
if( SHOW_ICON )
{
/* XXX: If !SharedPreviewAndCursor, this is incorrect. (Nothing uses
/* XXX: If !SharedPreviewAndCursor, this is incorrect. (Nothing uses
* both icon focus and !SharedPreviewAndCursor right now.)
* What is SharedPreviewAndCursor? -- Steve */
bool bOldStillHasFocus = false;
@@ -1119,15 +1119,15 @@ void ScreenSelectMaster::MenuStart( const InputEventPlus &input )
this->PostScreenMessage( SM_BeginFadingOut, fSecs );// tell our owner it's time to move on
}
/* We want all items to always run OnCommand and either GainFocus or LoseFocus on
* tween-in. If we only run OnCommand, then it has to contain a copy of either
* GainFocus or LoseFocus, which implies that the default setting is hard-coded
* in the theme. Always run both.
* However, the actual tween-in is OnCommand; we don't always want to actually run
* through the Gain/LoseFocus tweens during initial tween-in. So, we run the focus
* command first, do a FinishTweening to pop it in place, and then run OnCommand.
* This means that the focus command should be position neutral; eg. only use "addx",
* not "x". */
/* We want all items to always run OnCommand and either GainFocus or LoseFocus
* on tween-in. If we only run OnCommand, then it has to contain a copy of
* either GainFocus or LoseFocus, which implies that the default setting is
* hard-coded in the theme. Always run both.
* However, the actual tween-in is OnCommand; we don't always want to actually
* run through the Gain/LoseFocus tweens during initial tween-in. So, we run
* the focus command first, do a FinishTweening to pop it in place, and then
* run OnCommand. This means that the focus command should be position neutral;
* eg. only use "addx", not "x". */
void ScreenSelectMaster::TweenOnScreen()
{
vector<PlayerNumber> vpns;
@@ -1273,6 +1273,27 @@ float ScreenSelectMaster::GetCursorY( PlayerNumber pn )
return spr->GetDestY() + CURSOR_OFFSET_Y_FROM_ICON.GetValue(pn);
}
// lua start
#include "LuaBinding.h"
class LunaScreenSelectMaster: public Luna<ScreenSelectMaster>
{
public:
static int GetSelectionIndex( T* p, lua_State *L ) { lua_pushnumber( L, p->GetSelectionIndexOfPlayer(Enum::Check<PlayerNumber>(L, 1)) ); return 1; }
// should I even bother adding this? -aj
// would have to make a public function to get this in ssmaster.h:
// m_aGameCommands[i].m_sName
// static int SelectionIndexToChoiceName( T* p, lua_State *L ){ return 1; }
LunaScreenSelectMaster()
{
ADD_METHOD( GetSelectionIndex );
}
};
LUA_REGISTER_DERIVED_CLASS( ScreenSelectMaster, ScreenWithMenuElements )
// lua end
/*
* (c) 2003-2004 Chris Danford
* All rights reserved.