From 4eecbcf9339981070767988c9454998850363a6b Mon Sep 17 00:00:00 2001 From: RhythmLunatic Date: Tue, 26 Mar 2019 20:29:37 -0500 Subject: [PATCH] Make OptionsList inputs remappable --- Themes/_fallback/Scripts/03 Gameplay.lua | 26 +++++++++++++++++ Themes/_fallback/metrics.ini | 6 ++-- src/OptionsList.cpp | 37 ++++++++++++------------ src/OptionsList.h | 5 +++- 4 files changed, 53 insertions(+), 21 deletions(-) diff --git a/Themes/_fallback/Scripts/03 Gameplay.lua b/Themes/_fallback/Scripts/03 Gameplay.lua index fb284cb076..dc29180ecd 100644 --- a/Themes/_fallback/Scripts/03 Gameplay.lua +++ b/Themes/_fallback/Scripts/03 Gameplay.lua @@ -461,6 +461,32 @@ function GetCodeForGame(codeName) return inputCode[gameName] or inputCode["default"] end +local OptionsListKeys = { + PrevMenu = { + pump="MenuUp", + default="MenuLeft" + }, + NextMenu = { + pump="MenuDown", + default="MenuRight" + }, + PrevItem = { + pump="MenuLeft", + default="MenuUp" + }, + NextItem = { + pump="MenuRight", + default="MenuDown" + } +}; + +function GetOptionsListMapping(name) + local sGame = string.lower(GAMESTATE:GetCurrentGame():GetName()) + local map = OptionsListKeys[name] + return map[sGame] or map["default"] +end + + function oitg_zoom_mode_actor() return Def.Actor{ OnCommand= function(self) diff --git a/Themes/_fallback/metrics.ini b/Themes/_fallback/metrics.ini index 896781eb62..805d6907d1 100644 --- a/Themes/_fallback/metrics.ini +++ b/Themes/_fallback/metrics.ini @@ -2878,8 +2878,10 @@ Fallback="ScreenOptionsServiceChild" [OptionsList] Fallback="ScreenWithMenuElements" -#If true, holding left and pressing right will go to the next menu, and holding right and pressing left will go to the previous menu. -LeftAndRightSwitchesMenu=true +PrevMenuButton=GetOptionsListMapping("PrevMenu") +NextMenuButton=GetOptionsListMapping("NextMenu") +PrevItemButton=GetOptionsListMapping("PrevItem") +NextItemButton=GetOptionsListMapping("NextItem") CodeNames="" #It takes from ScreenOptionsMaster. diff --git a/src/OptionsList.cpp b/src/OptionsList.cpp index 5f68e87b95..4ebde8728b 100644 --- a/src/OptionsList.cpp +++ b/src/OptionsList.cpp @@ -188,8 +188,11 @@ void OptionsList::Load( RString sType, PlayerNumber pn ) m_pn = pn; m_bStartIsDown = false; - m_bLeftAndRightSwitchesMenu = THEME->GetMetricB( m_sName,"LeftAndRightSwitchesMenu" ); - + m_GameButtonPreviousMenu = INPUTMAPPER->GetInputScheme()->ButtonNameToIndex( THEME->GetMetric( m_sName,"PrevMenuButton" ) ); + m_GameButtonNextMenu = INPUTMAPPER->GetInputScheme()->ButtonNameToIndex( THEME->GetMetric( m_sName,"NextMenuButton" ) ); + m_GameButtonPreviousItem = INPUTMAPPER->GetInputScheme()->ButtonNameToIndex( THEME->GetMetric( m_sName,"PrevItemButton" ) ); + m_GameButtonNextItem = INPUTMAPPER->GetInputScheme()->ButtonNameToIndex( THEME->GetMetric( m_sName,"NextItemButton" ) ); + m_Codes.Load( sType ); m_Cursor.Load( THEME->GetPathG(sType, "cursor") ); @@ -417,18 +420,11 @@ bool OptionsList::Input( const InputEventPlus &input ) } } - if( input.MenuI == GAME_BUTTON_LEFT ) + if( input.MenuI == m_GameButtonPreviousItem ) { if( input.type == IET_RELEASE ) return false; - if(m_bLeftAndRightSwitchesMenu and INPUTMAPPER->IsBeingPressed(GAME_BUTTON_RIGHT, pn) ) - { - if( input.type == IET_FIRST_PRESS ) - SwitchMenu( -1 ); - return true; - } - --m_iMenuStackSelection; wrap( m_iMenuStackSelection, pHandler->m_Def.m_vsChoices.size()+1 ); // +1 for exit row PositionCursor(); @@ -439,18 +435,11 @@ bool OptionsList::Input( const InputEventPlus &input ) MESSAGEMAN->Broadcast( lMsg ); return true; } - else if( input.MenuI == GAME_BUTTON_RIGHT ) + else if( input.MenuI == m_GameButtonNextItem ) { if( input.type == IET_RELEASE ) return false; - if(m_bLeftAndRightSwitchesMenu and INPUTMAPPER->IsBeingPressed(GAME_BUTTON_LEFT, pn) ) - { - if( input.type == IET_FIRST_PRESS ) - SwitchMenu( +1 ); - return true; - } - ++m_iMenuStackSelection; wrap( m_iMenuStackSelection, pHandler->m_Def.m_vsChoices.size()+1 ); // +1 for exit row PositionCursor(); @@ -461,6 +450,18 @@ bool OptionsList::Input( const InputEventPlus &input ) MESSAGEMAN->Broadcast( lMsg ); return true; } + else if ( input.MenuI == m_GameButtonPreviousMenu ) + { + if( input.type == IET_FIRST_PRESS ) + SwitchMenu( -1 ); + return true; + } + else if ( input.MenuI == m_GameButtonNextMenu ) + { + if( input.type == IET_FIRST_PRESS ) + SwitchMenu( +1 ); + return true; + } else if( input.MenuI == GAME_BUTTON_START ) { if( input.type == IET_FIRST_PRESS ) diff --git a/src/OptionsList.h b/src/OptionsList.h index 2291244626..017caba714 100644 --- a/src/OptionsList.h +++ b/src/OptionsList.h @@ -102,7 +102,10 @@ private: vector m_asMenuStack; int m_iMenuStackSelection; protected: - bool m_bLeftAndRightSwitchesMenu; + GameButton m_GameButtonPreviousMenu; + GameButton m_GameButtonNextMenu; + GameButton m_GameButtonPreviousItem; + GameButton m_GameButtonNextItem; };