Use a lua transform function to position SOptions rows instead of having a Y metric for each row
This commit is contained in:
@@ -12,6 +12,7 @@ struct lua_State;
|
||||
class LuaReference;
|
||||
class LuaClass;
|
||||
#include "MessageManager.h"
|
||||
#include "RageUtil.h" // for ARRAYSIZE
|
||||
|
||||
|
||||
#define DRAW_ORDER_BEFORE_EVERYTHING -200
|
||||
@@ -55,6 +56,25 @@ public:
|
||||
|
||||
struct TweenState
|
||||
{
|
||||
bool operator==( const TweenState &other ) const
|
||||
{
|
||||
#define COMPARE( x ) if( x != other.x ) return false;
|
||||
COMPARE( pos );
|
||||
COMPARE( rotation );
|
||||
COMPARE( quat );
|
||||
COMPARE( scale );
|
||||
COMPARE( fSkewX );
|
||||
COMPARE( crop );
|
||||
COMPARE( fade );
|
||||
for( int i=0; i<ARRAYSIZE(diffuse); i++ )
|
||||
COMPARE( diffuse[i] );
|
||||
COMPARE( glow );
|
||||
COMPARE( aux );
|
||||
#undef COMPARE
|
||||
return true;
|
||||
}
|
||||
bool operator!=( const TweenState &other ) const { return !operator==(other); }
|
||||
|
||||
// start and end position for tweening
|
||||
RageVector3 pos;
|
||||
RageVector3 rotation;
|
||||
|
||||
@@ -190,8 +190,8 @@ public:
|
||||
BitmapText &GetTextItemForRow( PlayerNumber pn, int iChoiceOnRow );
|
||||
void GetWidthXY( PlayerNumber pn, int iChoiceOnRow, int &iWidthOut, int &iXOut, int &iYOut );
|
||||
|
||||
void SetRowY( float fRowY ) { m_fY = fRowY; }
|
||||
float GetRowY() { return m_fY; }
|
||||
// ScreenOptions calls positions m_FrameDestination, then m_Frame tween to that same TweenState.
|
||||
Actor &GetFrameDestination() { return m_FrameDestination; }
|
||||
void SetRowHidden( bool bRowHidden ) { m_bHidden = bRowHidden; }
|
||||
bool GetRowHidden() { return m_bHidden; }
|
||||
unsigned GetTextItemsSize() { return m_textItems.size(); }
|
||||
@@ -234,7 +234,7 @@ protected:
|
||||
// Only one will true at a time if m_RowDef.bMultiSelect
|
||||
vector<bool> m_vbSelected[NUM_PLAYERS]; // size = m_RowDef.choices.size()
|
||||
|
||||
float m_fY;
|
||||
Actor m_FrameDestination; // m_Frame should approach the destination TweenState of this.
|
||||
bool m_bHidden; // currently off screen
|
||||
};
|
||||
|
||||
|
||||
@@ -215,6 +215,18 @@ public:
|
||||
T GetCenterX() const { return (left+right)/2; };
|
||||
T GetCenterY() const { return (top+bottom)/2; };
|
||||
|
||||
bool operator==( const Rect &other ) const
|
||||
{
|
||||
#define COMPARE( x ) if( x != other.x ) return false;
|
||||
COMPARE( left );
|
||||
COMPARE( top );
|
||||
COMPARE( right );
|
||||
COMPARE( bottom );
|
||||
#undef COMPARE
|
||||
return true;
|
||||
}
|
||||
bool operator!=( const Rect &other ) const { return !operator==(other); }
|
||||
|
||||
T left, top, right, bottom;
|
||||
};
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
#include "ActorUtil.h"
|
||||
#include "ScreenDimensions.h"
|
||||
#include "Command.h"
|
||||
#include "GameCommand.h"
|
||||
#include "OptionRowHandler.h"
|
||||
|
||||
|
||||
/*
|
||||
@@ -59,7 +61,6 @@
|
||||
* in player options menus, but it should in the options menu.
|
||||
*/
|
||||
|
||||
static CString ROW_Y_NAME( size_t r ) { return ssprintf("Row%dY",int(r+1)); }
|
||||
static CString EXPLANATION_X_NAME( size_t p ) { return ssprintf("ExplanationP%dX",int(p+1)); }
|
||||
static CString EXPLANATION_Y_NAME( size_t p ) { return ssprintf("ExplanationP%dY",int(p+1)); }
|
||||
static CString EXPLANATION_ON_COMMAND_NAME( size_t p ) { return ssprintf("ExplanationP%dOnCommand",int(p+1)); }
|
||||
@@ -72,10 +73,6 @@ static CString OPTION_EXPLANATION( CString s )
|
||||
//REGISTER_SCREEN_CLASS( ScreenOptions ); // can't be instantiated
|
||||
ScreenOptions::ScreenOptions( CString sClassName ) : ScreenWithMenuElements(sClassName),
|
||||
NUM_ROWS_SHOWN (m_sName,"NumRowsShown"),
|
||||
ROW_Y (m_sName,ROW_Y_NAME,NUM_ROWS_SHOWN),
|
||||
ROW_Y_OFF_SCREEN_TOP (m_sName,"RowYOffScreenTop"),
|
||||
ROW_Y_OFF_SCREEN_CENTER (m_sName,"RowYOffScreenCenter"),
|
||||
ROW_Y_OFF_SCREEN_BOTTOM (m_sName,"RowYOffScreenBottom"),
|
||||
EXPLANATION_X (m_sName,EXPLANATION_X_NAME,NUM_PLAYERS),
|
||||
EXPLANATION_Y (m_sName,EXPLANATION_Y_NAME,NUM_PLAYERS),
|
||||
EXPLANATION_ON_COMMAND (m_sName,EXPLANATION_ON_COMMAND_NAME,NUM_PLAYERS),
|
||||
@@ -95,13 +92,18 @@ ScreenOptions::ScreenOptions( CString sClassName ) : ScreenWithMenuElements(sCla
|
||||
CURSOR_TWEEN_SECONDS (m_sName,"CursorTweenSeconds"),
|
||||
WRAP_VALUE_IN_ROW (m_sName,"WrapValueInRow")
|
||||
{
|
||||
LOG->Trace( "ScreenOptions::ScreenOptions()" );
|
||||
|
||||
m_fLockInputSecs = 0.0001f; // always lock for a tiny amount of time so that we throw away any queued inputs during the load.
|
||||
|
||||
// These can be overridden in a derived Init().
|
||||
m_OptionsNavigation = PREFSMAN->m_bArcadeOptionsNavigation? NAV_THREE_KEY:NAV_FIVE_KEY;
|
||||
m_InputMode = INPUTMODE_SHARE_CURSOR;
|
||||
|
||||
LOG->Trace( "ScreenOptions::ScreenOptions()" );
|
||||
m_exprRowPositionTransformFunction .SetFromExpression( THEME->GetMetric(m_sName,"RowPositionTransformFunction") );
|
||||
m_exprRowOffScreenTopTransformFunction .SetFromExpression( THEME->GetMetric(m_sName,"RowOffScreenTopTransformFunction") );
|
||||
m_exprRowOffScreenCenterTransformFunction .SetFromExpression( THEME->GetMetric(m_sName,"RowOffScreenCenterTransformFunction") );
|
||||
m_exprRowOffScreenBottomTransformFunction .SetFromExpression( THEME->GetMetric(m_sName,"RowOffScreenBottomTransformFunction") );
|
||||
}
|
||||
|
||||
|
||||
@@ -406,9 +408,42 @@ void ScreenOptions::PositionIcons()
|
||||
}
|
||||
}
|
||||
|
||||
void ScreenOptions::RefreshIcons( int row, PlayerNumber pn )
|
||||
void ScreenOptions::RefreshIcons( int iRow, PlayerNumber pn )
|
||||
{
|
||||
// overridden by ScreenOptionsMaster
|
||||
OptionRow &row = *m_pRows[iRow];
|
||||
|
||||
if( row.GetRowType() == OptionRow::ROW_EXIT )
|
||||
return; // skip
|
||||
|
||||
const OptionRowDefinition &def = row.GetRowDef();
|
||||
|
||||
// find first selection and whether multiple are selected
|
||||
int iFirstSelection = row.GetOneSelection( pn, true );
|
||||
|
||||
// set icon name and bullet
|
||||
CString sIcon;
|
||||
GameCommand gc;
|
||||
|
||||
if( iFirstSelection == -1 )
|
||||
{
|
||||
sIcon = "Multi";
|
||||
}
|
||||
else if( iFirstSelection != -1 )
|
||||
{
|
||||
const OptionRowHandler *pHand = row.GetHandler();
|
||||
if( pHand )
|
||||
{
|
||||
int iSelection = iFirstSelection+(m_OptionsNavigation==NAV_TOGGLE_THREE_KEY?-1:0);
|
||||
pHand->GetIconTextAndGameCommand( def, iSelection, sIcon, gc );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* XXX: hack to not display text in the song options menu */
|
||||
if( def.m_bOneChoiceForAllPlayers )
|
||||
sIcon = "";
|
||||
|
||||
SetOptionIcon( pn, iRow, sIcon, gc );
|
||||
}
|
||||
|
||||
void ScreenOptions::RefreshAllIcons()
|
||||
@@ -668,31 +703,45 @@ void ScreenOptions::PositionItems()
|
||||
int pos = 0;
|
||||
for( int i=0; i<(int) Rows.size(); i++ ) // foreach row
|
||||
{
|
||||
float fY;
|
||||
if( i < first_start )
|
||||
fY = ROW_Y_OFF_SCREEN_TOP;
|
||||
else if( i < first_end )
|
||||
fY = ROW_Y.GetValue( pos++ );
|
||||
else if( i < second_start )
|
||||
fY = ROW_Y_OFF_SCREEN_CENTER;
|
||||
else if( i < second_end )
|
||||
fY = ROW_Y.GetValue( pos++ );
|
||||
else
|
||||
fY = ROW_Y_OFF_SCREEN_BOTTOM;
|
||||
|
||||
OptionRow &row = *Rows[i];
|
||||
|
||||
row.SetRowY( fY );
|
||||
|
||||
LuaExpression *pExpr = NULL;
|
||||
if( i < first_start )
|
||||
pExpr = &m_exprRowOffScreenTopTransformFunction;
|
||||
else if( i < first_end )
|
||||
pExpr = &m_exprRowPositionTransformFunction;
|
||||
else if( i < second_start )
|
||||
pExpr = &m_exprRowOffScreenCenterTransformFunction;
|
||||
else if( i < second_end )
|
||||
pExpr = &m_exprRowPositionTransformFunction;
|
||||
else
|
||||
pExpr = &m_exprRowOffScreenBottomTransformFunction;
|
||||
|
||||
Lua *L = LUA->Get();
|
||||
|
||||
pExpr->PushSelf( L );
|
||||
|
||||
ASSERT( !lua_isnil(L, -1) );
|
||||
row.GetFrameDestination().PushSelf( L );
|
||||
LuaHelpers::Push( pos, L );
|
||||
LuaHelpers::Push( i, L );
|
||||
LuaHelpers::Push( NUM_ROWS_SHOWN, L );
|
||||
lua_call( L, 4, 0 ); // 4 args, 0 results
|
||||
LUA->Release(L);
|
||||
|
||||
bool bHidden =
|
||||
i < first_start ||
|
||||
(i >= first_end && i < second_start) ||
|
||||
i >= second_end;
|
||||
if( !bHidden )
|
||||
pos++;
|
||||
row.SetRowHidden( bHidden );
|
||||
}
|
||||
|
||||
if( ExitRow )
|
||||
{
|
||||
ExitRow->SetRowY( SEPARATE_EXIT_ROW_Y );
|
||||
ExitRow->GetFrameDestination().SetY( SEPARATE_EXIT_ROW_Y );
|
||||
ExitRow->SetRowHidden( second_end != (int) Rows.size() );
|
||||
}
|
||||
}
|
||||
@@ -713,7 +762,7 @@ void ScreenOptions::AfterChangeValueOrRow( PlayerNumber pn )
|
||||
|
||||
/* Do positioning. */
|
||||
PositionAllUnderlines();
|
||||
RefreshIcons( iCurRow, pn );
|
||||
this->RefreshIcons( iCurRow, pn );
|
||||
PositionIcons();
|
||||
UpdateEnabledDisabled();
|
||||
|
||||
|
||||
@@ -46,19 +46,19 @@ protected:
|
||||
|
||||
void InitOptionsText();
|
||||
void GetWidthXY( PlayerNumber pn, int iRow, int iChoiceOnRow, int &iWidthOut, int &iXOut, int &iYOut );
|
||||
CString GetExplanationText( int row ) const;
|
||||
CString GetExplanationText( int iRow ) const;
|
||||
BitmapText &GetTextItemForRow( PlayerNumber pn, int iRow, int iChoiceOnRow );
|
||||
void PositionUnderlines( int row, PlayerNumber pn );
|
||||
void PositionUnderlines( int iRow, PlayerNumber pn );
|
||||
void PositionAllUnderlines();
|
||||
void PositionIcons();
|
||||
virtual void RefreshIcons( int row, PlayerNumber pn );
|
||||
virtual void RefreshIcons( int iRow, PlayerNumber pn );
|
||||
void RefreshAllIcons();
|
||||
void PositionCursors();
|
||||
void PositionItems();
|
||||
void TweenCursor( PlayerNumber pn );
|
||||
void UpdateText( int row );
|
||||
void UpdateText( int iRow );
|
||||
void UpdateEnabledDisabled();
|
||||
void UpdateEnabledDisabled( int row );
|
||||
void UpdateEnabledDisabled( int iRow );
|
||||
|
||||
virtual void MenuBack( PlayerNumber pn );
|
||||
virtual void MenuStart( PlayerNumber pn, const InputEventType type );
|
||||
@@ -134,10 +134,10 @@ protected:
|
||||
|
||||
// metrics
|
||||
ThemeMetric<int> NUM_ROWS_SHOWN;
|
||||
ThemeMetric1D<float> ROW_Y;
|
||||
ThemeMetric<float> ROW_Y_OFF_SCREEN_TOP;
|
||||
ThemeMetric<float> ROW_Y_OFF_SCREEN_CENTER;
|
||||
ThemeMetric<float> ROW_Y_OFF_SCREEN_BOTTOM;
|
||||
LuaExpression m_exprRowPositionTransformFunction; // params: self,positionIndex,itemIndex,numItems
|
||||
LuaExpression m_exprRowOffScreenTopTransformFunction; // params: self,positionIndex,itemIndex,numItems
|
||||
LuaExpression m_exprRowOffScreenCenterTransformFunction; // params: self,positionIndex,itemIndex,numItems
|
||||
LuaExpression m_exprRowOffScreenBottomTransformFunction; // params: self,positionIndex,itemIndex,numItems
|
||||
ThemeMetric1D<float> EXPLANATION_X;
|
||||
ThemeMetric1D<float> EXPLANATION_Y;
|
||||
ThemeMetric1D<apActorCommands> EXPLANATION_ON_COMMAND;
|
||||
|
||||
@@ -159,37 +159,7 @@ void ScreenOptionsMaster::BeginFadingOut()
|
||||
|
||||
void ScreenOptionsMaster::RefreshIcons( int r, PlayerNumber pn )
|
||||
{
|
||||
OptionRow &row = *m_pRows[r];
|
||||
|
||||
if( row.GetRowType() == OptionRow::ROW_EXIT )
|
||||
return; // skip
|
||||
|
||||
const OptionRowDefinition &def = row.GetRowDef();
|
||||
|
||||
// find first selection and whether multiple are selected
|
||||
int iFirstSelection = row.GetOneSelection( pn, true );
|
||||
|
||||
// set icon name and bullet
|
||||
CString sIcon;
|
||||
GameCommand gc;
|
||||
|
||||
if( iFirstSelection == -1 )
|
||||
{
|
||||
sIcon = "Multi";
|
||||
}
|
||||
else if( iFirstSelection != -1 )
|
||||
{
|
||||
const OptionRowHandler *pHand = m_OptionRowHandlers[r];
|
||||
int iSelection = iFirstSelection+(m_OptionsNavigation==NAV_TOGGLE_THREE_KEY?-1:0);
|
||||
pHand->GetIconTextAndGameCommand( def, iSelection, sIcon, gc );
|
||||
}
|
||||
|
||||
|
||||
/* XXX: hack to not display text in the song options menu */
|
||||
if( def.m_bOneChoiceForAllPlayers )
|
||||
sIcon = "";
|
||||
|
||||
SetOptionIcon( pn, r, sIcon, gc );
|
||||
ScreenOptions::RefreshIcons( r, pn );
|
||||
}
|
||||
|
||||
void ScreenOptionsMaster::HandleScreenMessage( const ScreenMessage SM )
|
||||
|
||||
Reference in New Issue
Block a user