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 ) 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.) * both icon focus and !SharedPreviewAndCursor right now.)
* What is SharedPreviewAndCursor? -- Steve */ * What is SharedPreviewAndCursor? -- Steve */
bool bOldStillHasFocus = false; 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 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 /* We want all items to always run OnCommand and either GainFocus or LoseFocus
* tween-in. If we only run OnCommand, then it has to contain a copy of either * on tween-in. If we only run OnCommand, then it has to contain a copy of
* GainFocus or LoseFocus, which implies that the default setting is hard-coded * either GainFocus or LoseFocus, which implies that the default setting is
* in the theme. Always run both. * hard-coded in the theme. Always run both.
* However, the actual tween-in is OnCommand; we don't always want to actually run * However, the actual tween-in is OnCommand; we don't always want to actually
* through the Gain/LoseFocus tweens during initial tween-in. So, we run the focus * run through the Gain/LoseFocus tweens during initial tween-in. So, we run
* command first, do a FinishTweening to pop it in place, and then run OnCommand. * the focus command first, do a FinishTweening to pop it in place, and then
* This means that the focus command should be position neutral; eg. only use "addx", * run OnCommand. This means that the focus command should be position neutral;
* not "x". */ * eg. only use "addx", not "x". */
void ScreenSelectMaster::TweenOnScreen() void ScreenSelectMaster::TweenOnScreen()
{ {
vector<PlayerNumber> vpns; vector<PlayerNumber> vpns;
@@ -1273,6 +1273,27 @@ float ScreenSelectMaster::GetCursorY( PlayerNumber pn )
return spr->GetDestY() + CURSOR_OFFSET_Y_FROM_ICON.GetValue(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 * (c) 2003-2004 Chris Danford
* All rights reserved. * All rights reserved.
+9 -6
View File
@@ -39,6 +39,12 @@ public:
virtual void HandleScreenMessage( const ScreenMessage SM ); virtual void HandleScreenMessage( const ScreenMessage SM );
virtual bool AllowLateJoin() const { return true; } virtual bool AllowLateJoin() const { return true; }
// sm-ssc additions:
int GetSelectionIndexOfPlayer(PlayerNumber pn){ return GetSelectionIndex(pn); }
// Lua
virtual void PushSelf( lua_State *L );
protected: protected:
enum Page { PAGE_1, PAGE_2, NUM_Page }; // on PAGE_2, cursors are locked together enum Page { PAGE_1, PAGE_2, NUM_Page }; // on PAGE_2, cursors are locked together
static PlayerNumber GetSharedPlayer(); static PlayerNumber GetSharedPlayer();
@@ -75,7 +81,6 @@ protected:
map<int,int> m_mapCurrentChoiceToNextChoice[NUM_MenuDir]; map<int,int> m_mapCurrentChoiceToNextChoice[NUM_MenuDir];
map<int,int> m_mapCurrentChoiceToNextChoiceB[NUM_MenuDir]; // if using two lists map<int,int> m_mapCurrentChoiceToNextChoiceB[NUM_MenuDir]; // if using two lists
virtual int GetSelectionIndex( PlayerNumber pn ); virtual int GetSelectionIndex( PlayerNumber pn );
virtual void UpdateSelectableChoices(); virtual void UpdateSelectableChoices();
bool AnyOptionsArePlayable() const; bool AnyOptionsArePlayable() const;
@@ -93,16 +98,14 @@ protected:
AutoActor m_sprMore[NUM_Page]; AutoActor m_sprMore[NUM_Page];
// icon is the shared, per-choice piece // icon is the shared, per-choice piece
vector<AutoActor> m_vsprIcon; vector<AutoActor> m_vsprIcon;
vector<AutoActor> m_vsprIconB; // used if the user wants two lists vector<AutoActor> m_vsprIconB; // used if a themer wants two lists
// preview is per-player, per-choice piece // preview is per-player, per-choice piece
vector<AutoActor> m_vsprScroll[NUM_PLAYERS]; vector<AutoActor> m_vsprScroll[NUM_PLAYERS];
vector<AutoActor> m_vsprScrollB[NUM_PLAYERS]; // used if the user wants two lists vector<AutoActor> m_vsprScrollB[NUM_PLAYERS]; // used if a themer wants two lists
ActorScroller m_Scroller[NUM_PLAYERS]; ActorScroller m_Scroller[NUM_PLAYERS];
ActorScroller m_ScrollerB[NUM_PLAYERS]; // used if the user wants two lists ActorScroller m_ScrollerB[NUM_PLAYERS]; // used if a themer wants two lists
// cursor is the per-player, shared by all choices // cursor is the per-player, shared by all choices
AutoActor m_sprCursor[NUM_PLAYERS]; AutoActor m_sprCursor[NUM_PLAYERS];