mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
DolphinQt/Mapping: Add setting to enable waiting for alternate mappings
using the OR-operator.
This commit is contained in:
@ -19,8 +19,10 @@
|
||||
namespace MappingCommon
|
||||
{
|
||||
constexpr auto INPUT_DETECT_INITIAL_TIME = std::chrono::seconds(3);
|
||||
constexpr auto INPUT_DETECT_CONFIRMATION_TIME = std::chrono::milliseconds(0);
|
||||
constexpr auto INPUT_DETECT_CONFIRMATION_TIME = std::chrono::milliseconds(750);
|
||||
constexpr auto INPUT_DETECT_MAXIMUM_TIME = std::chrono::seconds(5);
|
||||
// Ignore the mouse-click when queuing more buttons with "alternate mappings" enabled.
|
||||
constexpr auto INPUT_DETECT_ENDING_IGNORE_TIME = std::chrono::milliseconds(50);
|
||||
|
||||
class MappingProcessor : public QWidget
|
||||
{
|
||||
@ -50,7 +52,7 @@ public:
|
||||
button->StartMapping();
|
||||
|
||||
std::vector device_strings{default_device.ToString()};
|
||||
if (m_parent->IsMappingAllDevices())
|
||||
if (m_parent->IsCreateOtherDeviceMappingsEnabled())
|
||||
device_strings = g_controller_interface.GetAllDeviceStrings();
|
||||
|
||||
m_input_detector = std::make_unique<ciface::Core::InputDetector>();
|
||||
@ -63,35 +65,41 @@ public:
|
||||
if (!m_input_detector)
|
||||
return;
|
||||
|
||||
m_input_detector->Update(INPUT_DETECT_INITIAL_TIME, INPUT_DETECT_CONFIRMATION_TIME,
|
||||
const auto confirmation_time =
|
||||
INPUT_DETECT_CONFIRMATION_TIME * (m_parent->IsWaitForAlternateMappingsEnabled() ? 1 : 0);
|
||||
|
||||
m_input_detector->Update(INPUT_DETECT_INITIAL_TIME, confirmation_time,
|
||||
INPUT_DETECT_MAXIMUM_TIME);
|
||||
|
||||
if (m_input_detector->IsComplete())
|
||||
{
|
||||
auto detections = m_input_detector->TakeResults();
|
||||
ciface::MappingCommon::RemoveSpuriousTriggerCombinations(&detections);
|
||||
|
||||
// No inputs detected. Cancel this and any other queued mappings.
|
||||
if (detections.empty())
|
||||
{
|
||||
if (!FinalizeMapping(m_input_detector->TakeResults()))
|
||||
CancelMapping();
|
||||
return;
|
||||
}
|
||||
|
||||
const auto& default_device = m_parent->GetController()->GetDefaultDevice();
|
||||
auto& button = m_clicked_mapping_buttons.front();
|
||||
auto* const control_reference = button->GetControlReference();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
bool FinalizeMapping(ciface::Core::InputDetector::Results detections)
|
||||
{
|
||||
if (!ciface::MappingCommon::ContainsCompleteDetection(detections))
|
||||
return false;
|
||||
|
||||
ciface::MappingCommon::RemoveSpuriousTriggerCombinations(&detections);
|
||||
|
||||
const auto& default_device = m_parent->GetController()->GetDefaultDevice();
|
||||
auto& button = m_clicked_mapping_buttons.front();
|
||||
auto* const control_reference = button->GetControlReference();
|
||||
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
|
||||
void UpdateInputDetectionStartTimer()
|
||||
{
|
||||
m_input_detector.reset();
|
||||
@ -121,6 +129,15 @@ public:
|
||||
|
||||
button->setText(QStringLiteral("[ ... ]"));
|
||||
m_clicked_mapping_buttons.push_back(button);
|
||||
|
||||
if (m_input_detector)
|
||||
{
|
||||
// Ignore the mouse-click that queued this new detection and finalize the current mapping.
|
||||
auto results = m_input_detector->TakeResults();
|
||||
ciface::MappingCommon::RemoveDetectionsAfterTimePoint(
|
||||
&results, ciface::Core::DeviceContainer::Clock::now() - INPUT_DETECT_ENDING_IGNORE_TIME);
|
||||
FinalizeMapping(std::move(results));
|
||||
}
|
||||
UpdateInputDetectionStartTimer();
|
||||
}
|
||||
|
||||
|
@ -111,11 +111,15 @@ void MappingWindow::CreateDevicesLayout()
|
||||
const auto refresh_action = new QAction(tr("Refresh"), options);
|
||||
connect(refresh_action, &QAction::triggered, this, &MappingWindow::RefreshDevices);
|
||||
|
||||
m_all_devices_action = new QAction(tr("Create mappings for other devices"), options);
|
||||
m_all_devices_action->setCheckable(true);
|
||||
m_other_device_mappings = new QAction(tr("Create Mappings for Other Devices"), options);
|
||||
m_other_device_mappings->setCheckable(true);
|
||||
|
||||
m_wait_for_alternate_mappings = new QAction(tr("Wait for Alternate Input Mappings"), options);
|
||||
m_wait_for_alternate_mappings->setCheckable(true);
|
||||
|
||||
options->addAction(refresh_action);
|
||||
options->addAction(m_all_devices_action);
|
||||
options->addAction(m_other_device_mappings);
|
||||
options->addAction(m_wait_for_alternate_mappings);
|
||||
options->setDefaultAction(refresh_action);
|
||||
|
||||
m_devices_combo->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
||||
@ -354,9 +358,14 @@ void MappingWindow::OnSelectDevice(int)
|
||||
m_controller->UpdateReferences(g_controller_interface);
|
||||
}
|
||||
|
||||
bool MappingWindow::IsMappingAllDevices() const
|
||||
bool MappingWindow::IsCreateOtherDeviceMappingsEnabled() const
|
||||
{
|
||||
return m_all_devices_action->isChecked();
|
||||
return m_other_device_mappings->isChecked();
|
||||
}
|
||||
|
||||
bool MappingWindow::IsWaitForAlternateMappingsEnabled() const
|
||||
{
|
||||
return m_wait_for_alternate_mappings->isChecked();
|
||||
}
|
||||
|
||||
void MappingWindow::RefreshDevices()
|
||||
|
@ -51,7 +51,8 @@ public:
|
||||
|
||||
int GetPort() const;
|
||||
ControllerEmu::EmulatedController* GetController() const;
|
||||
bool IsMappingAllDevices() const;
|
||||
bool IsCreateOtherDeviceMappingsEnabled() const;
|
||||
bool IsWaitForAlternateMappingsEnabled() const;
|
||||
void ShowExtensionMotionTabs(bool show);
|
||||
void ActivateExtensionTab();
|
||||
|
||||
@ -103,7 +104,8 @@ private:
|
||||
QGroupBox* m_devices_box;
|
||||
QHBoxLayout* m_devices_layout;
|
||||
QComboBox* m_devices_combo;
|
||||
QAction* m_all_devices_action;
|
||||
QAction* m_other_device_mappings;
|
||||
QAction* m_wait_for_alternate_mappings;
|
||||
|
||||
// Profiles
|
||||
QGroupBox* m_profiles_box;
|
||||
|
Reference in New Issue
Block a user