mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-05-28 14:56:35 +00:00
DolphinQt/Mapping: Clear and skip "Modifier" iterative input mappings when using
analog inputs.
This commit is contained in:
parent
3189de6c7a
commit
66624abb12
4 changed files with 72 additions and 23 deletions
|
@ -65,8 +65,9 @@ static QString RefToDisplayString(ControlReference* ref)
|
||||||
return expression;
|
return expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
MappingButton::MappingButton(MappingWidget* parent, ControlReference* ref)
|
MappingButton::MappingButton(MappingWidget* parent, ControlReference* ref, ControlType control_type)
|
||||||
: ElidedButton(RefToDisplayString(ref)), m_mapping_window(parent->GetParent()), m_reference(ref)
|
: ElidedButton{RefToDisplayString(ref)}, m_mapping_window{parent->GetParent()},
|
||||||
|
m_reference{ref}, m_control_type{control_type}
|
||||||
{
|
{
|
||||||
if (m_reference->IsInput())
|
if (m_reference->IsInput())
|
||||||
{
|
{
|
||||||
|
@ -141,3 +142,8 @@ ControlReference* MappingButton::GetControlReference()
|
||||||
{
|
{
|
||||||
return m_reference;
|
return m_reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto MappingButton::GetControlType() const -> ControlType
|
||||||
|
{
|
||||||
|
return m_control_type;
|
||||||
|
}
|
||||||
|
|
|
@ -15,9 +15,17 @@ class MappingButton : public ElidedButton
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
MappingButton(MappingWidget* widget, ControlReference* ref);
|
enum class ControlType
|
||||||
|
{
|
||||||
|
NormalInput,
|
||||||
|
ModifierInput,
|
||||||
|
Output,
|
||||||
|
};
|
||||||
|
|
||||||
|
MappingButton(MappingWidget* widget, ControlReference* ref, ControlType type);
|
||||||
|
|
||||||
ControlReference* GetControlReference();
|
ControlReference* GetControlReference();
|
||||||
|
ControlType GetControlType() const;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void ConfigChanged();
|
void ConfigChanged();
|
||||||
|
@ -32,4 +40,5 @@ private:
|
||||||
|
|
||||||
MappingWindow* const m_mapping_window;
|
MappingWindow* const m_mapping_window;
|
||||||
ControlReference* const m_reference;
|
ControlReference* const m_reference;
|
||||||
|
const ControlType m_control_type;
|
||||||
};
|
};
|
||||||
|
|
|
@ -25,6 +25,11 @@ constexpr auto INPUT_DETECT_MAXIMUM_TIME = std::chrono::seconds(5);
|
||||||
// Ignore the mouse-click when queuing more buttons with "alternate mappings" enabled.
|
// Ignore the mouse-click when queuing more buttons with "alternate mappings" enabled.
|
||||||
constexpr auto INPUT_DETECT_ENDING_IGNORE_TIME = std::chrono::milliseconds(50);
|
constexpr auto INPUT_DETECT_ENDING_IGNORE_TIME = std::chrono::milliseconds(50);
|
||||||
|
|
||||||
|
bool ContainsAnalogInput(const ciface::Core::InputDetector::Results& results)
|
||||||
|
{
|
||||||
|
return std::ranges::any_of(results, [](auto& detection) { return detection.smoothness > 1; });
|
||||||
|
}
|
||||||
|
|
||||||
class MappingProcessor : public QWidget
|
class MappingProcessor : public QWidget
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -75,11 +80,13 @@ public:
|
||||||
m_input_detector->Update(INPUT_DETECT_INITIAL_TIME, confirmation_time,
|
m_input_detector->Update(INPUT_DETECT_INITIAL_TIME, confirmation_time,
|
||||||
INPUT_DETECT_MAXIMUM_TIME);
|
INPUT_DETECT_MAXIMUM_TIME);
|
||||||
|
|
||||||
if (m_input_detector->IsComplete())
|
if (!m_input_detector->IsComplete())
|
||||||
{
|
return;
|
||||||
auto* const button = m_clicked_mapping_buttons.back();
|
|
||||||
|
|
||||||
if (!FinalizeMapping(m_input_detector->TakeResults()))
|
auto* const button = m_clicked_mapping_buttons.front();
|
||||||
|
|
||||||
|
auto results = m_input_detector->TakeResults();
|
||||||
|
if (!FinalizeMapping(&results))
|
||||||
{
|
{
|
||||||
// No inputs detected. Cancel this and any other queued mappings.
|
// No inputs detected. Cancel this and any other queued mappings.
|
||||||
CancelMapping();
|
CancelMapping();
|
||||||
|
@ -87,12 +94,26 @@ public:
|
||||||
else if (m_parent->IsIterativeMappingEnabled() && m_clicked_mapping_buttons.empty())
|
else if (m_parent->IsIterativeMappingEnabled() && m_clicked_mapping_buttons.empty())
|
||||||
{
|
{
|
||||||
button->QueueNextButtonMapping();
|
button->QueueNextButtonMapping();
|
||||||
|
|
||||||
|
if (m_clicked_mapping_buttons.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Skip "Modifier" mappings when using analog inputs.
|
||||||
|
auto* next_button = m_clicked_mapping_buttons.front();
|
||||||
|
if (next_button->GetControlType() == MappingButton::ControlType::ModifierInput &&
|
||||||
|
ContainsAnalogInput(results))
|
||||||
|
{
|
||||||
|
// Clear "Modifier" mapping and queue the next button.
|
||||||
|
SetButtonExpression(next_button, "");
|
||||||
|
UnQueueInputDetection(next_button);
|
||||||
|
next_button->QueueNextButtonMapping();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FinalizeMapping(ciface::Core::InputDetector::Results detections)
|
bool FinalizeMapping(ciface::Core::InputDetector::Results* detections_ptr)
|
||||||
{
|
{
|
||||||
|
auto& detections = *detections_ptr;
|
||||||
if (!ciface::MappingCommon::ContainsCompleteDetection(detections))
|
if (!ciface::MappingCommon::ContainsCompleteDetection(detections))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -100,18 +121,22 @@ public:
|
||||||
|
|
||||||
const auto& default_device = m_parent->GetController()->GetDefaultDevice();
|
const auto& default_device = m_parent->GetController()->GetDefaultDevice();
|
||||||
auto& button = m_clicked_mapping_buttons.front();
|
auto& button = m_clicked_mapping_buttons.front();
|
||||||
auto* const control_reference = button->GetControlReference();
|
SetButtonExpression(
|
||||||
|
button, BuildExpression(detections, default_device, ciface::MappingCommon::Quote::On));
|
||||||
|
|
||||||
control_reference->SetExpression(
|
|
||||||
BuildExpression(detections, default_device, ciface::MappingCommon::Quote::On));
|
|
||||||
m_parent->Save();
|
|
||||||
|
|
||||||
m_parent->GetController()->UpdateSingleControlReference(g_controller_interface,
|
|
||||||
control_reference);
|
|
||||||
UnQueueInputDetection(button);
|
UnQueueInputDetection(button);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetButtonExpression(MappingButton* button, const std::string& expression)
|
||||||
|
{
|
||||||
|
auto* const control_reference = button->GetControlReference();
|
||||||
|
control_reference->SetExpression(expression);
|
||||||
|
m_parent->Save();
|
||||||
|
m_parent->GetController()->UpdateSingleControlReference(g_controller_interface,
|
||||||
|
control_reference);
|
||||||
|
}
|
||||||
|
|
||||||
void UpdateInputDetectionStartTimer()
|
void UpdateInputDetectionStartTimer()
|
||||||
{
|
{
|
||||||
m_input_detector.reset();
|
m_input_detector.reset();
|
||||||
|
@ -146,7 +171,7 @@ public:
|
||||||
auto results = m_input_detector->TakeResults();
|
auto results = m_input_detector->TakeResults();
|
||||||
ciface::MappingCommon::RemoveDetectionsAfterTimePoint(
|
ciface::MappingCommon::RemoveDetectionsAfterTimePoint(
|
||||||
&results, ciface::Core::DeviceContainer::Clock::now() - INPUT_DETECT_ENDING_IGNORE_TIME);
|
&results, ciface::Core::DeviceContainer::Clock::now() - INPUT_DETECT_ENDING_IGNORE_TIME);
|
||||||
FinalizeMapping(std::move(results));
|
FinalizeMapping(&results);
|
||||||
}
|
}
|
||||||
UpdateInputDetectionStartTimer();
|
UpdateInputDetectionStartTimer();
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,7 +313,16 @@ QGroupBox* MappingWidget::CreateControlsBox(const QString& name, ControllerEmu::
|
||||||
void MappingWidget::CreateControl(const ControllerEmu::Control* control, QFormLayout* layout,
|
void MappingWidget::CreateControl(const ControllerEmu::Control* control, QFormLayout* layout,
|
||||||
bool indicator)
|
bool indicator)
|
||||||
{
|
{
|
||||||
auto* const button = new MappingButton(this, control->control_ref.get());
|
// I know this check is terrible, but it's just UI code.
|
||||||
|
const bool is_modifier = control->name == "Modifier";
|
||||||
|
|
||||||
|
using ControlType = MappingButton::ControlType;
|
||||||
|
const auto control_type =
|
||||||
|
control->control_ref->IsInput() ?
|
||||||
|
(is_modifier ? ControlType::ModifierInput : ControlType::NormalInput) :
|
||||||
|
ControlType::Output;
|
||||||
|
|
||||||
|
auto* const button = new MappingButton(this, control->control_ref.get(), control_type);
|
||||||
|
|
||||||
if (control->control_ref->IsInput())
|
if (control->control_ref->IsInput())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue