mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-31 01:59:52 -06:00
ControllerEmu: Split the Setting class
The Setting class was used for both numeric values and booleans, and other parts of the code had hacks to make it work with booleans. By splitting Setting into NumericSetting and BooleanSetting, it is clear which settings are numeric, and which are boolean, so there is no need to guess by checking the default values or anything like that. Also, booleans are stored as booleans in config files, instead of 1.0.
This commit is contained in:
@ -100,8 +100,8 @@ void PadSettingExtension::UpdateValue()
|
||||
}
|
||||
|
||||
PadSettingCheckBox::PadSettingCheckBox(wxWindow* const parent,
|
||||
ControllerEmu::ControlGroup::Setting* const _setting)
|
||||
: PadSetting(new wxCheckBox(parent, wxID_ANY, wxGetTranslation(StrToWxStr(_setting->name)))),
|
||||
ControllerEmu::ControlGroup::BooleanSetting* const _setting)
|
||||
: PadSetting(new wxCheckBox(parent, wxID_ANY, wxGetTranslation(StrToWxStr(_setting->m_name)))),
|
||||
setting(_setting)
|
||||
{
|
||||
UpdateGUI();
|
||||
@ -109,13 +109,12 @@ PadSettingCheckBox::PadSettingCheckBox(wxWindow* const parent,
|
||||
|
||||
void PadSettingCheckBox::UpdateGUI()
|
||||
{
|
||||
((wxCheckBox*)wxcontrol)->SetValue(!!setting->GetValue());
|
||||
((wxCheckBox*)wxcontrol)->SetValue(setting->GetValue());
|
||||
}
|
||||
|
||||
void PadSettingCheckBox::UpdateValue()
|
||||
{
|
||||
// 0.01 so its saved to the ini file as just 1. :(
|
||||
setting->SetValue(0.01 * ((wxCheckBox*)wxcontrol)->GetValue());
|
||||
setting->SetValue(((wxCheckBox*)wxcontrol)->GetValue());
|
||||
}
|
||||
|
||||
void PadSettingSpin::UpdateGUI()
|
||||
@ -827,13 +826,13 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
|
||||
wxBITMAP_TYPE_BMP);
|
||||
|
||||
wxBoxSizer* const szr = new wxBoxSizer(wxVERTICAL);
|
||||
for (auto& groupSetting : group->settings)
|
||||
for (auto& groupSetting : group->numeric_settings)
|
||||
{
|
||||
PadSettingSpin* setting = new PadSettingSpin(parent, groupSetting.get());
|
||||
setting->wxcontrol->Bind(wxEVT_SPINCTRL, &GamepadPage::AdjustSetting, eventsink);
|
||||
options.push_back(setting);
|
||||
szr->Add(
|
||||
new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(groupSetting->name))));
|
||||
new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(groupSetting->m_name))));
|
||||
szr->Add(setting->wxcontrol, 0, wxLEFT, 0);
|
||||
}
|
||||
|
||||
@ -856,7 +855,7 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
|
||||
static_bitmap = new wxStaticBitmap(parent, wxID_ANY, bitmap, wxDefaultPosition, wxDefaultSize,
|
||||
wxBITMAP_TYPE_BMP);
|
||||
|
||||
PadSettingSpin* const threshold_cbox = new PadSettingSpin(parent, group->settings[0].get());
|
||||
auto* const threshold_cbox = new PadSettingSpin(parent, group->numeric_settings[0].get());
|
||||
threshold_cbox->wxcontrol->Bind(wxEVT_SPINCTRL, &GamepadPage::AdjustSetting, eventsink);
|
||||
|
||||
threshold_cbox->wxcontrol->SetToolTip(
|
||||
@ -865,9 +864,9 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
|
||||
options.push_back(threshold_cbox);
|
||||
|
||||
wxBoxSizer* const szr = new wxBoxSizer(wxHORIZONTAL);
|
||||
szr->Add(
|
||||
new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(group->settings[0]->name))),
|
||||
0, wxCENTER | wxRIGHT, 3);
|
||||
szr->Add(new wxStaticText(parent, wxID_ANY,
|
||||
wxGetTranslation(StrToWxStr(group->numeric_settings[0]->m_name))),
|
||||
0, wxCENTER | wxRIGHT, 3);
|
||||
szr->Add(threshold_cbox->wxcontrol, 0, wxRIGHT, 3);
|
||||
|
||||
Add(szr, 0, wxALL | wxCENTER, 3);
|
||||
@ -893,14 +892,15 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
|
||||
static_bitmap = new wxStaticBitmap(parent, wxID_ANY, bitmap, wxDefaultPosition, wxDefaultSize,
|
||||
wxBITMAP_TYPE_BMP);
|
||||
|
||||
for (auto& groupSetting : group->settings)
|
||||
for (auto& groupSetting : group->numeric_settings)
|
||||
{
|
||||
PadSettingSpin* setting = new PadSettingSpin(parent, groupSetting.get());
|
||||
setting->wxcontrol->Bind(wxEVT_SPINCTRL, &GamepadPage::AdjustSetting, eventsink);
|
||||
options.push_back(setting);
|
||||
wxBoxSizer* const szr = new wxBoxSizer(wxHORIZONTAL);
|
||||
szr->Add(new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(groupSetting->name))),
|
||||
0, wxCENTER | wxRIGHT, 3);
|
||||
szr->Add(
|
||||
new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(groupSetting->m_name))), 0,
|
||||
wxCENTER | wxRIGHT, 3);
|
||||
szr->Add(setting->wxcontrol, 0, wxRIGHT, 3);
|
||||
Add(szr, 0, wxALL | wxCENTER, 3);
|
||||
}
|
||||
@ -926,35 +926,32 @@ ControlGroupBox::ControlGroupBox(ControllerEmu::ControlGroup* const group, wxWin
|
||||
default:
|
||||
{
|
||||
// options
|
||||
for (auto& groupSetting : group->settings)
|
||||
for (auto& groupSetting : group->boolean_settings)
|
||||
{
|
||||
if (groupSetting->high == DEFAULT_HIGH_VALUE)
|
||||
PadSettingCheckBox* setting_cbox = new PadSettingCheckBox(parent, groupSetting.get());
|
||||
if (groupSetting->m_name == "Iterative Input")
|
||||
{
|
||||
PadSettingCheckBox* setting_cbox = new PadSettingCheckBox(parent, groupSetting.get());
|
||||
if (groupSetting->is_iterate == true)
|
||||
{
|
||||
setting_cbox->wxcontrol->Bind(wxEVT_CHECKBOX, &GamepadPage::AdjustSettingUI, eventsink);
|
||||
groupSetting->value = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
setting_cbox->wxcontrol->Bind(wxEVT_CHECKBOX, &GamepadPage::AdjustSetting, eventsink);
|
||||
}
|
||||
options.push_back(setting_cbox);
|
||||
Add(setting_cbox->wxcontrol, 0, wxALL | wxLEFT, 5);
|
||||
setting_cbox->wxcontrol->Bind(wxEVT_CHECKBOX, &GamepadPage::AdjustSettingUI, eventsink);
|
||||
groupSetting->SetValue(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
PadSettingSpin* setting = new PadSettingSpin(parent, groupSetting.get());
|
||||
setting->wxcontrol->Bind(wxEVT_SPINCTRL, &GamepadPage::AdjustSetting, eventsink);
|
||||
options.push_back(setting);
|
||||
wxBoxSizer* const szr = new wxBoxSizer(wxHORIZONTAL);
|
||||
szr->Add(
|
||||
new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(groupSetting->name))), 0,
|
||||
wxCENTER | wxRIGHT, 3);
|
||||
szr->Add(setting->wxcontrol, 0, wxRIGHT, 3);
|
||||
Add(szr, 0, wxALL | wxCENTER, 3);
|
||||
setting_cbox->wxcontrol->Bind(wxEVT_CHECKBOX, &GamepadPage::AdjustSetting, eventsink);
|
||||
}
|
||||
options.push_back(setting_cbox);
|
||||
Add(setting_cbox->wxcontrol, 0, wxALL | wxLEFT, 5);
|
||||
}
|
||||
for (auto& groupSetting : group->numeric_settings)
|
||||
{
|
||||
PadSettingSpin* setting = new PadSettingSpin(parent, groupSetting.get());
|
||||
setting->wxcontrol->Bind(wxEVT_SPINCTRL, &GamepadPage::AdjustSetting, eventsink);
|
||||
options.push_back(setting);
|
||||
wxBoxSizer* const szr = new wxBoxSizer(wxHORIZONTAL);
|
||||
szr->Add(
|
||||
new wxStaticText(parent, wxID_ANY, wxGetTranslation(StrToWxStr(groupSetting->m_name))), 0,
|
||||
wxCENTER | wxRIGHT, 3);
|
||||
szr->Add(setting->wxcontrol, 0, wxRIGHT, 3);
|
||||
Add(szr, 0, wxALL | wxCENTER, 3);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -980,7 +977,8 @@ ControlGroupsSizer::ControlGroupsSizer(ControllerEmu* const controller, wxWindow
|
||||
new wxStaticBoxSizer(wxVERTICAL, parent, wxGetTranslation(StrToWxStr(group->ui_name)));
|
||||
control_group->Add(control_group_box);
|
||||
|
||||
const size_t grp_size = group->controls.size() + group->settings.size();
|
||||
const size_t grp_size =
|
||||
group->controls.size() + group->numeric_settings.size() + group->boolean_settings.size();
|
||||
col_size += grp_size;
|
||||
if (col_size > 8 || nullptr == stacked_groups)
|
||||
{
|
||||
|
@ -61,10 +61,11 @@ public:
|
||||
class PadSettingSpin : public PadSetting
|
||||
{
|
||||
public:
|
||||
PadSettingSpin(wxWindow* const parent, ControllerEmu::ControlGroup::Setting* const _setting)
|
||||
PadSettingSpin(wxWindow* const parent,
|
||||
ControllerEmu::ControlGroup::NumericSetting* const _setting)
|
||||
: PadSetting(new wxSpinCtrl(parent, wxID_ANY, wxEmptyString, wxDefaultPosition,
|
||||
wxSize(54, -1), 0, _setting->low, _setting->high,
|
||||
(int)(_setting->value * 100))),
|
||||
wxSize(54, -1), 0, _setting->m_low, _setting->m_high,
|
||||
(int)(_setting->GetValue() * 100))),
|
||||
setting(_setting)
|
||||
{
|
||||
}
|
||||
@ -72,17 +73,18 @@ public:
|
||||
void UpdateGUI() override;
|
||||
void UpdateValue() override;
|
||||
|
||||
ControllerEmu::ControlGroup::Setting* const setting;
|
||||
ControllerEmu::ControlGroup::NumericSetting* const setting;
|
||||
};
|
||||
|
||||
class PadSettingCheckBox : public PadSetting
|
||||
{
|
||||
public:
|
||||
PadSettingCheckBox(wxWindow* const parent, ControllerEmu::ControlGroup::Setting* const setting);
|
||||
PadSettingCheckBox(wxWindow* const parent,
|
||||
ControllerEmu::ControlGroup::BooleanSetting* const setting);
|
||||
void UpdateGUI() override;
|
||||
void UpdateValue() override;
|
||||
|
||||
ControllerEmu::ControlGroup::Setting* const setting;
|
||||
ControllerEmu::ControlGroup::BooleanSetting* const setting;
|
||||
};
|
||||
|
||||
class InputEventFilter : public wxEventFilter
|
||||
|
@ -228,7 +228,7 @@ static void DrawControlGroupBox(wxDC& dc, ControlGroupBox* g)
|
||||
{
|
||||
// deadzone circle
|
||||
dc.SetBrush(*wxLIGHT_GREY_BRUSH);
|
||||
dc.DrawCircle(32, 32, g->control_group->settings[SETTING_DEADZONE]->value * 32);
|
||||
dc.DrawCircle(32, 32, g->control_group->numeric_settings[SETTING_DEADZONE]->GetValue() * 32);
|
||||
}
|
||||
|
||||
// raw dot
|
||||
@ -259,7 +259,7 @@ static void DrawControlGroupBox(wxDC& dc, ControlGroupBox* g)
|
||||
{
|
||||
ControlState raw_dot[3];
|
||||
ControlState adj_dot[3];
|
||||
const ControlState deadzone = g->control_group->settings[0]->value;
|
||||
const ControlState deadzone = g->control_group->numeric_settings[0]->GetValue();
|
||||
|
||||
// adjusted
|
||||
((ControllerEmu::Force*)g->control_group)->GetState(adj_dot);
|
||||
@ -358,7 +358,7 @@ static void DrawControlGroupBox(wxDC& dc, ControlGroupBox* g)
|
||||
|
||||
// draw the shit
|
||||
dc.SetPen(*wxGREY_PEN);
|
||||
ControlState deadzone = g->control_group->settings[0]->value;
|
||||
ControlState deadzone = g->control_group->numeric_settings[0]->GetValue();
|
||||
|
||||
ControlState* const trigs = new ControlState[trigger_count];
|
||||
((ControllerEmu::Triggers*)g->control_group)->GetState(trigs);
|
||||
@ -398,7 +398,7 @@ static void DrawControlGroupBox(wxDC& dc, ControlGroupBox* g)
|
||||
|
||||
// draw the shit
|
||||
dc.SetPen(*wxGREY_PEN);
|
||||
ControlState thresh = g->control_group->settings[0]->value;
|
||||
ControlState thresh = g->control_group->numeric_settings[0]->GetValue();
|
||||
|
||||
for (unsigned int n = 0; n < trigger_count; ++n)
|
||||
{
|
||||
@ -428,7 +428,7 @@ static void DrawControlGroupBox(wxDC& dc, ControlGroupBox* g)
|
||||
break;
|
||||
case GROUP_TYPE_SLIDER:
|
||||
{
|
||||
const ControlState deadzone = g->control_group->settings[0]->value;
|
||||
const ControlState deadzone = g->control_group->numeric_settings[0]->GetValue();
|
||||
|
||||
ControlState state = g->control_group->controls[1]->control_ref->State() -
|
||||
g->control_group->controls[0]->control_ref->State();
|
||||
|
Reference in New Issue
Block a user