@ -86,10 +86,11 @@ struct PadVibrationBinding
struct MacroButton
struct MacroButton
{
{
std : : vector < u32 > buttons ; ///< Buttons to activate.
std : : vector < u32 > buttons ; ///< Buttons to activate.
u 32 toggle_frequency ; ///< Interval at which the buttons will be toggled, if not 0.
u 16 toggle_frequency ; ///< Interval at which the buttons will be toggled, if not 0.
u 32 toggle_counter ; ///< When this counter reaches zero, buttons will be toggled.
u 16 toggle_counter ; ///< When this counter reaches zero, buttons will be toggled.
bool toggle_state ; ///< Current state for turbo.
bool toggle_state ; ///< Current state for turbo.
bool trigger_state ; ///< Whether the macro button is active.
bool trigger_state ; ///< Whether the macro button is active.
bool trigger_toggle ; ///< Whether the macro is trigged by holding or press.
} ;
} ;
} // namespace
} // namespace
@ -1578,10 +1579,13 @@ void InputManager::LoadMacroButtonConfig(SettingsInterface& si, const std::strin
for ( u32 i = 0 ; i < NUM_MACRO_BUTTONS_PER_CONTROLLER ; i + + )
for ( u32 i = 0 ; i < NUM_MACRO_BUTTONS_PER_CONTROLLER ; i + + )
{
{
std : : string binds_string ;
std : : string binds_string ;
if ( ! si . GetStringValue ( section . c_str ( ) , fmt: : format( " Macro{}Binds " , i + 1u ) . c_str ( ) , & binds_string ) )
if ( ! si . GetStringValue ( section . c_str ( ) , TinyString: : from_ format( " Macro{}Binds " , i + 1u ) , & binds_string ) )
continue ;
continue ;
const u32 frequency = si . GetUIntValue ( section . c_str ( ) , fmt : : format ( " Macro{}Frequency " , i + 1u ) . c_str ( ) , 0u ) ;
const u32 frequency =
std : : min < u32 > ( si . GetUIntValue ( section . c_str ( ) , TinyString : : from_format ( " Macro{}Frequency " , i + 1u ) , 0u ) ,
std : : numeric_limits < u16 > : : max ( ) ) ;
const bool toggle = si . GetBoolValue ( section . c_str ( ) , TinyString : : from_format ( " Macro{}Toggle " , i + 1u ) , false ) ;
// convert binds
// convert binds
std : : vector < u32 > bind_indices ;
std : : vector < u32 > bind_indices ;
@ -1612,7 +1616,8 @@ void InputManager::LoadMacroButtonConfig(SettingsInterface& si, const std::strin
continue ;
continue ;
s_macro_buttons [ pad ] [ i ] . buttons = std : : move ( bind_indices ) ;
s_macro_buttons [ pad ] [ i ] . buttons = std : : move ( bind_indices ) ;
s_macro_buttons [ pad ] [ i ] . toggle_frequency = frequency ;
s_macro_buttons [ pad ] [ i ] . toggle_frequency = static_cast < u16 > ( frequency ) ;
s_macro_buttons [ pad ] [ i ] . trigger_toggle = toggle ;
}
}
}
}
@ -1622,14 +1627,18 @@ void InputManager::SetMacroButtonState(u32 pad, u32 index, bool state)
return ;
return ;
MacroButton & mb = s_macro_buttons [ pad ] [ index ] ;
MacroButton & mb = s_macro_buttons [ pad ] [ index ] ;
if ( mb . buttons . empty ( ) | | mb . trigger_state = = state )
if ( mb . buttons . empty ( ) )
return ;
const bool trigger_state = ( mb . trigger_toggle ? ( state ? ! mb . trigger_state : mb . trigger_state ) : state ) ;
if ( mb . trigger_state = = trigger_state )
return ;
return ;
mb . toggle_counter = mb . toggle_frequency ;
mb . toggle_counter = mb . toggle_frequency ;
mb . trigger_state = state ;
mb . trigger_state = trigger_ state;
if ( mb . toggle_state ! = state)
if ( mb . toggle_state ! = trigger_ state)
{
{
mb . toggle_state = state;
mb . toggle_state = trigger_ state;
ApplyMacroButton ( pad , mb ) ;
ApplyMacroButton ( pad , mb ) ;
}
}
}
}