InputManager: Add push to toggle for macros
This commit is contained in:
@ -86,10 +86,11 @@ struct PadVibrationBinding
|
||||
struct MacroButton
|
||||
{
|
||||
std::vector<u32> buttons; ///< Buttons to activate.
|
||||
u32 toggle_frequency; ///< Interval at which the buttons will be toggled, if not 0.
|
||||
u32 toggle_counter; ///< When this counter reaches zero, buttons will be toggled.
|
||||
u16 toggle_frequency; ///< Interval at which the buttons will be toggled, if not 0.
|
||||
u16 toggle_counter; ///< When this counter reaches zero, buttons will be toggled.
|
||||
bool toggle_state; ///< Current state for turbo.
|
||||
bool trigger_state; ///< Whether the macro button is active.
|
||||
bool trigger_toggle; ///< Whether the macro is trigged by holding or press.
|
||||
};
|
||||
|
||||
} // namespace
|
||||
@ -1578,10 +1579,13 @@ void InputManager::LoadMacroButtonConfig(SettingsInterface& si, const std::strin
|
||||
for (u32 i = 0; i < NUM_MACRO_BUTTONS_PER_CONTROLLER; i++)
|
||||
{
|
||||
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;
|
||||
|
||||
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
|
||||
std::vector<u32> bind_indices;
|
||||
@ -1612,7 +1616,8 @@ void InputManager::LoadMacroButtonConfig(SettingsInterface& si, const std::strin
|
||||
continue;
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
mb.toggle_counter = mb.toggle_frequency;
|
||||
mb.trigger_state = state;
|
||||
if (mb.toggle_state != state)
|
||||
mb.trigger_state = trigger_state;
|
||||
if (mb.toggle_state != trigger_state)
|
||||
{
|
||||
mb.toggle_state = state;
|
||||
mb.toggle_state = trigger_state;
|
||||
ApplyMacroButton(pad, mb);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user