From 74d7895ccde043195f17643efc9c9b53dfcf3ae3 Mon Sep 17 00:00:00 2001 From: AJ Kelly Date: Tue, 9 Mar 2010 03:20:44 -0600 Subject: [PATCH] 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"); }; --- src/ScreenSelectMaster.cpp | 41 ++++++++++++++++++++++++++++---------- src/ScreenSelectMaster.h | 15 ++++++++------ 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/ScreenSelectMaster.cpp b/src/ScreenSelectMaster.cpp index df126d2ddf..b9ee37161e 100644 --- a/src/ScreenSelectMaster.cpp +++ b/src/ScreenSelectMaster.cpp @@ -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 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 +{ +public: + static int GetSelectionIndex( T* p, lua_State *L ) { lua_pushnumber( L, p->GetSelectionIndexOfPlayer(Enum::Check(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. diff --git a/src/ScreenSelectMaster.h b/src/ScreenSelectMaster.h index 55ff38b885..6e66a39d41 100644 --- a/src/ScreenSelectMaster.h +++ b/src/ScreenSelectMaster.h @@ -39,6 +39,12 @@ public: virtual void HandleScreenMessage( const ScreenMessage SM ); virtual bool AllowLateJoin() const { return true; } + // sm-ssc additions: + int GetSelectionIndexOfPlayer(PlayerNumber pn){ return GetSelectionIndex(pn); } + + // Lua + virtual void PushSelf( lua_State *L ); + protected: enum Page { PAGE_1, PAGE_2, NUM_Page }; // on PAGE_2, cursors are locked together static PlayerNumber GetSharedPlayer(); @@ -75,7 +81,6 @@ protected: map m_mapCurrentChoiceToNextChoice[NUM_MenuDir]; map m_mapCurrentChoiceToNextChoiceB[NUM_MenuDir]; // if using two lists - virtual int GetSelectionIndex( PlayerNumber pn ); virtual void UpdateSelectableChoices(); bool AnyOptionsArePlayable() const; @@ -93,16 +98,14 @@ protected: AutoActor m_sprMore[NUM_Page]; // icon is the shared, per-choice piece vector m_vsprIcon; - vector m_vsprIconB; // used if the user wants two lists + vector m_vsprIconB; // used if a themer wants two lists // preview is per-player, per-choice piece vector m_vsprScroll[NUM_PLAYERS]; - vector m_vsprScrollB[NUM_PLAYERS]; // used if the user wants two lists - + vector m_vsprScrollB[NUM_PLAYERS]; // used if a themer wants two lists 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 AutoActor m_sprCursor[NUM_PLAYERS];