mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2025-01-20 15:25:38 +00:00
InputManager: Add push to toggle for macros
This commit is contained in:
parent
446750fb66
commit
f0a4ceb909
|
@ -3803,6 +3803,11 @@ void FullscreenUI::DrawControllerSettingsPage()
|
||||||
DrawInputBindingButton(bsi, InputBindingInfo::Type::Macro, section.c_str(),
|
DrawInputBindingButton(bsi, InputBindingInfo::Type::Macro, section.c_str(),
|
||||||
TinyString::from_format("Macro{}", macro_index + 1),
|
TinyString::from_format("Macro{}", macro_index + 1),
|
||||||
TinyString::from_format(FSUI_FSTR("Macro {} Trigger"), macro_index + 1), nullptr);
|
TinyString::from_format(FSUI_FSTR("Macro {} Trigger"), macro_index + 1), nullptr);
|
||||||
|
DrawToggleSetting(bsi,
|
||||||
|
TinyString::from_format(fmt::runtime(FSUI_ICONSTR(ICON_FA_GAMEPAD, "Macro {} Press To Toggle")),
|
||||||
|
macro_index + 1),
|
||||||
|
nullptr, section.c_str(), TinyString::from_format("Macro{}Toggle", macro_index + 1), false,
|
||||||
|
true, false, LAYOUT_MENU_BUTTON_HEIGHT_NO_SUMMARY);
|
||||||
|
|
||||||
SmallString binds_string =
|
SmallString binds_string =
|
||||||
bsi->GetSmallStringValue(section.c_str(), fmt::format("Macro{}Binds", macro_index + 1).c_str());
|
bsi->GetSmallStringValue(section.c_str(), fmt::format("Macro{}Binds", macro_index + 1).c_str());
|
||||||
|
|
|
@ -569,7 +569,7 @@ ControllerMacroEditWidget::ControllerMacroEditWidget(ControllerMacroWidget* pare
|
||||||
|
|
||||||
// load binds (single string joined by &)
|
// load binds (single string joined by &)
|
||||||
const std::string binds_string(
|
const std::string binds_string(
|
||||||
dialog->getStringValue(section.c_str(), fmt::format("Macro{}Binds", index + 1u).c_str(), ""));
|
dialog->getStringValue(section.c_str(), TinyString::from_format("Macro{}Binds", index + 1u), ""));
|
||||||
const std::vector<std::string_view> buttons_split(StringUtil::SplitString(binds_string, '&', true));
|
const std::vector<std::string_view> buttons_split(StringUtil::SplitString(binds_string, '&', true));
|
||||||
|
|
||||||
for (const std::string_view& button : buttons_split)
|
for (const std::string_view& button : buttons_split)
|
||||||
|
@ -597,7 +597,10 @@ ControllerMacroEditWidget::ControllerMacroEditWidget(ControllerMacroWidget* pare
|
||||||
m_ui.bindList->addItem(item);
|
m_ui.bindList->addItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_frequency = dialog->getIntValue(section.c_str(), fmt::format("Macro{}Frequency", index + 1u).c_str(), 0);
|
m_frequency = dialog->getIntValue(section.c_str(), TinyString::from_format("Macro{}Frequency", index + 1u), 0);
|
||||||
|
ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(dialog->getProfileSettingsInterface(), m_ui.triggerToggle,
|
||||||
|
section.c_str(), fmt::format("Macro{}Toggle", index + 1u),
|
||||||
|
false);
|
||||||
updateFrequencyText();
|
updateFrequencyText();
|
||||||
|
|
||||||
m_ui.trigger->initialize(dialog->getProfileSettingsInterface(), InputBindingInfo::Type::Macro, section,
|
m_ui.trigger->initialize(dialog->getProfileSettingsInterface(), InputBindingInfo::Type::Macro, section,
|
||||||
|
|
|
@ -6,11 +6,11 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>595</width>
|
<width>664</width>
|
||||||
<height>473</height>
|
<height>420</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,0,0">
|
||||||
<property name="leftMargin">
|
<property name="leftMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
|
@ -51,20 +51,31 @@
|
||||||
<string>Trigger</string>
|
<string>Trigger</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout">
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
<item row="0" column="0" colspan="2">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<layout class="QHBoxLayout" name="horizontalLayout_5" stretch="1,0">
|
||||||
<property name="text">
|
<item>
|
||||||
<string>Select the trigger to activate this macro. This can be a single button, or combination of buttons (chord). Shift-click for multiple triggers.</string>
|
<widget class="QLabel" name="label_5">
|
||||||
</property>
|
<property name="text">
|
||||||
<property name="alignment">
|
<string>Select the trigger to activate this macro. This can be a single button, or combination of buttons (chord). Shift-click for multiple triggers.</string>
|
||||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
</property>
|
||||||
</property>
|
<property name="alignment">
|
||||||
<property name="wordWrap">
|
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
|
||||||
<bool>true</bool>
|
</property>
|
||||||
</property>
|
<property name="wordWrap">
|
||||||
</widget>
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="triggerToggle">
|
||||||
|
<property name="text">
|
||||||
|
<string>Press To Toggle</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0" colspan="2">
|
<item row="1" column="0">
|
||||||
<widget class="InputBindingWidget" name="trigger">
|
<widget class="InputBindingWidget" name="trigger">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>PushButton</string>
|
<string>PushButton</string>
|
||||||
|
@ -127,19 +138,6 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<spacer name="verticalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
|
|
@ -1358,7 +1358,7 @@ bool ImGuiFullscreen::ToggleButton(const char* title, const char* summary, bool*
|
||||||
const float toggle_width = LayoutScale(50.0f);
|
const float toggle_width = LayoutScale(50.0f);
|
||||||
const float toggle_height = LayoutScale(25.0f);
|
const float toggle_height = LayoutScale(25.0f);
|
||||||
const float toggle_x = LayoutScale(8.0f);
|
const float toggle_x = LayoutScale(8.0f);
|
||||||
const float toggle_y = (LayoutScale(LAYOUT_MENU_BUTTON_HEIGHT) - toggle_height) * 0.5f;
|
const float toggle_y = (LayoutScale(height) - toggle_height) * 0.5f;
|
||||||
const float toggle_radius = toggle_height * 0.5f;
|
const float toggle_radius = toggle_height * 0.5f;
|
||||||
const ImVec2 toggle_pos(bb.Max.x - toggle_width - toggle_x, bb.Min.y + toggle_y);
|
const ImVec2 toggle_pos(bb.Max.x - toggle_width - toggle_x, bb.Min.y + toggle_y);
|
||||||
|
|
||||||
|
|
|
@ -86,10 +86,11 @@ struct PadVibrationBinding
|
||||||
struct MacroButton
|
struct MacroButton
|
||||||
{
|
{
|
||||||
std::vector<u32> buttons; ///< Buttons to activate.
|
std::vector<u32> buttons; ///< Buttons to activate.
|
||||||
u32 toggle_frequency; ///< Interval at which the buttons will be toggled, if not 0.
|
u16 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_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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue