Disable IR/deadzone when relative input is disabled

This changes InputConfigDiag to disable the Dead Zone field in the IR
group when relative input is disabled.
This commit is contained in:
Léo Lam 2016-07-13 12:49:28 +02:00
parent 5cf07fdfbf
commit 2472db4355
2 changed files with 48 additions and 14 deletions

View File

@ -18,6 +18,7 @@
#include <wx/control.h>
#include <wx/dcmemory.h>
#include <wx/dialog.h>
#include <wx/event.h>
#include <wx/font.h>
#include <wx/listbox.h>
#include <wx/msgdlg.h>
@ -110,6 +111,10 @@ PadSettingCheckBox::PadSettingCheckBox(wxWindow* const parent,
void PadSettingCheckBox::UpdateGUI()
{
((wxCheckBox*)wxcontrol)->SetValue(setting->GetValue());
// Force WX to trigger an event after updating the value
wxCommandEvent event(wxEVT_CHECKBOX);
event.SetEventObject(wxcontrol);
wxPostEvent(wxcontrol, event);
}
void PadSettingCheckBox::UpdateValue()
@ -452,15 +457,48 @@ void ControlDialog::AppendControl(wxCommandEvent& event)
UpdateGUI();
}
void GamepadPage::AdjustSetting(wxCommandEvent& event)
void GamepadPage::EnableSettingControl(const std::string& group_name, const std::string& name,
const bool enabled)
{
((PadSetting*)((wxControl*)event.GetEventObject())->GetClientData())->UpdateValue();
const auto box_iterator =
std::find_if(control_groups.begin(), control_groups.end(), [&group_name](const auto& box) {
return group_name == box->control_group->name;
});
if (box_iterator == control_groups.end())
return;
const auto* box = *box_iterator;
const auto it =
std::find_if(box->options.begin(), box->options.end(), [&name](const auto& pad_setting) {
return pad_setting->wxcontrol->GetLabelText() == name;
});
if (it == box->options.end())
return;
(*it)->wxcontrol->Enable(enabled);
}
void GamepadPage::AdjustSettingUI(wxCommandEvent& event)
void GamepadPage::AdjustSetting(wxCommandEvent& event)
{
m_iterate = !m_iterate;
((PadSetting*)((wxControl*)event.GetEventObject())->GetClientData())->UpdateValue();
const auto* const control = static_cast<wxControl*>(event.GetEventObject());
auto* const pad_setting = static_cast<PadSetting*>(control->GetClientData());
pad_setting->UpdateValue();
}
void GamepadPage::AdjustBooleanSetting(wxCommandEvent& event)
{
const auto* const control = static_cast<wxControl*>(event.GetEventObject());
auto* const pad_setting = static_cast<PadSettingCheckBox*>(control->GetClientData());
pad_setting->UpdateValue();
// TODO: find a cleaner way to have actions depending on the setting
if (control->GetLabelText() == "Iterative Input")
{
m_iterate = pad_setting->setting->GetValue();
}
else if (control->GetLabelText() == "Relative Input")
{
EnableSettingControl("IR", "Dead Zone", pad_setting->setting->GetValue());
}
}
void GamepadPage::AdjustControlOption(wxCommandEvent&)
@ -846,7 +884,7 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
for (auto& groupSetting : group->boolean_settings)
{
auto* checkbox = new PadSettingCheckBox(parent, groupSetting.get());
checkbox->wxcontrol->Bind(wxEVT_CHECKBOX, &GamepadPage::AdjustSetting, eventsink);
checkbox->wxcontrol->Bind(wxEVT_CHECKBOX, &GamepadPage::AdjustBooleanSetting, eventsink);
options.push_back(checkbox);
Add(checkbox->wxcontrol, 0, wxALL | wxLEFT, 5);
}
@ -944,15 +982,9 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
for (auto& groupSetting : group->boolean_settings)
{
PadSettingCheckBox* setting_cbox = new PadSettingCheckBox(parent, groupSetting.get());
setting_cbox->wxcontrol->Bind(wxEVT_CHECKBOX, &GamepadPage::AdjustBooleanSetting, eventsink);
if (groupSetting->m_name == "Iterative Input")
{
setting_cbox->wxcontrol->Bind(wxEVT_CHECKBOX, &GamepadPage::AdjustSettingUI, eventsink);
groupSetting->SetValue(false);
}
else
{
setting_cbox->wxcontrol->Bind(wxEVT_CHECKBOX, &GamepadPage::AdjustSetting, eventsink);
}
options.push_back(setting_cbox);
Add(setting_cbox->wxcontrol, 0, wxALL | wxLEFT, 5);
}

View File

@ -68,6 +68,7 @@ public:
(int)(_setting->GetValue() * 100))),
setting(_setting)
{
wxcontrol->SetLabel(setting->m_name);
}
void UpdateGUI() override;
@ -222,8 +223,9 @@ public:
void LoadDefaults(wxCommandEvent& event);
void AdjustControlOption(wxCommandEvent& event);
void EnableSettingControl(const std::string& group_name, const std::string& name, bool enabled);
void AdjustSetting(wxCommandEvent& event);
void AdjustSettingUI(wxCommandEvent& event);
void AdjustBooleanSetting(wxCommandEvent& event);
void GetProfilePath(std::string& path);