Project64-input: Allow deadzone to be configurable
This commit is contained in:
parent
f89d027a09
commit
fa3196f75a
|
@ -307,7 +307,7 @@ void CDirectInput::GetAxis(N64CONTROLLER & Controller, BUTTONS * Keys)
|
|||
long lAxisValueX = 0;
|
||||
long lAxisValueY = 0;
|
||||
|
||||
int bPadDeadZone = 5;
|
||||
uint8_t bPadDeadZone = Controller.DeadZone;
|
||||
long lDeadZoneValue = bPadDeadZone * RANGE_RELATIVE / 100;
|
||||
float fDeadZoneRelation = (float)RANGE_RELATIVE / (float)(RANGE_RELATIVE - lDeadZoneValue);
|
||||
|
||||
|
|
|
@ -54,6 +54,7 @@ private:
|
|||
CBitmapPicture m_ControllerImg;
|
||||
CButton m_PluggedIn;
|
||||
CTrackBarCtrl m_Range;
|
||||
CTrackBarCtrl m_DeadZone;
|
||||
CScanButton m_ButtonUDPad, m_ButtonDDPad, m_ButtonLDPad, m_ButtonRDPad;
|
||||
CScanButton m_ButtonCUp, m_ButtonCDown, m_ButtonCLeft, m_ButtonCRight;
|
||||
CScanButton m_ButtonA, m_ButtonB, m_ButtonStart;
|
||||
|
@ -90,6 +91,10 @@ CControllerSettings::CControllerSettings(uint32_t ControllerNumber) :
|
|||
|
||||
BOOL CControllerSettings::OnInitDialog(CWindow /*wndFocus*/, LPARAM /*lInitParam*/)
|
||||
{
|
||||
m_DeadZone.Attach(GetDlgItem(IDC_SLIDE_DEADZONE));
|
||||
m_DeadZone.SetTicFreq(1);
|
||||
m_DeadZone.SetRangeMin(1);
|
||||
m_DeadZone.SetRangeMax(100);
|
||||
m_Range.Attach(GetDlgItem(IDC_SLIDER_RANGE));
|
||||
m_Range.SetTicFreq(1);
|
||||
m_Range.SetRangeMin(1);
|
||||
|
@ -132,6 +137,7 @@ bool CControllerSettings::OnApply()
|
|||
N64CONTROLLER & Controller = g_InputPlugin->Controllers(m_ControllerNumber);
|
||||
CONTROL & ControlInfo = g_InputPlugin->ControlInfo(m_ControllerNumber);
|
||||
Controller.Range = (uint8_t)m_Range.GetPos();
|
||||
Controller.DeadZone = (uint8_t)m_DeadZone.GetPos();
|
||||
ControlInfo.Present = (m_PluggedIn.GetCheck() == BST_CHECKED) ? 1 : 0;
|
||||
|
||||
return g_InputPlugin->SaveController(m_ControllerNumber);
|
||||
|
@ -143,6 +149,12 @@ LRESULT CControllerSettings::OnScroll(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM l
|
|||
if (SliderId == IDC_SLIDER_RANGE)
|
||||
{
|
||||
CWindow(GetDlgItem(IDC_LABEL_RANGE)).SetWindowText(stdstr_f("%d%%", m_Range.GetPos()).ToUTF16().c_str());
|
||||
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
|
||||
}
|
||||
if (SliderId == IDC_SLIDE_DEADZONE)
|
||||
{
|
||||
CWindow(GetDlgItem(IDC_GROUP_DEADZONE)).SetWindowText(stdstr_f("Deadzone: %d%%", m_DeadZone.GetPos()).ToUTF16().c_str());
|
||||
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -206,7 +218,9 @@ void CControllerSettings::DisplayController(void)
|
|||
CONTROL & ControlInfo = g_InputPlugin->ControlInfo(m_ControllerNumber);
|
||||
m_PluggedIn.SetCheck(ControlInfo.Present != 0 ? BST_CHECKED : BST_UNCHECKED);
|
||||
m_Range.SetPos(Controller.Range);
|
||||
m_DeadZone.SetPos(Controller.DeadZone);
|
||||
CWindow(GetDlgItem(IDC_LABEL_RANGE)).SetWindowText(stdstr_f("%d%%", m_Range.GetPos()).ToUTF16().c_str());
|
||||
CWindow(GetDlgItem(IDC_GROUP_DEADZONE)).SetWindowText(stdstr_f("Deadzone: %d%%", m_DeadZone.GetPos()).ToUTF16().c_str());
|
||||
CScanButton * Buttons[] = {
|
||||
&m_ButtonUDPad, &m_ButtonDDPad, &m_ButtonLDPad, &m_ButtonRDPad, &m_ButtonA, &m_ButtonB,
|
||||
&m_ButtonCUp, &m_ButtonCDown, &m_ButtonCLeft, &m_ButtonCRight, &m_ButtonStart,
|
||||
|
|
|
@ -56,12 +56,15 @@ void CInputSettings::LoadController(uint32_t ControlIndex, CONTROL & ControllerI
|
|||
InputSettingID PresentSettings[] = { Set_Control0_Present };
|
||||
InputSettingID PluginSettings[] = { Set_Control0_Plugin };
|
||||
InputSettingID RangeSettings[] = { Set_Control0_Range };
|
||||
InputSettingID DeadZoneSettings[] = { Set_Control0_Deadzone };
|
||||
|
||||
ControllerInfo.Present = ControlIndex < (sizeof(PresentSettings) / sizeof(PresentSettings[0])) ? GetSetting((short)PresentSettings[ControlIndex]) != 0 : 0;
|
||||
ControllerInfo.Plugin = ControlIndex < (sizeof(PluginSettings) / sizeof(PluginSettings[0])) ? GetSetting((short)PluginSettings[ControlIndex]) : PLUGIN_NONE;
|
||||
Controller.Range = (uint8_t)(ControlIndex < (sizeof(RangeSettings) / sizeof(RangeSettings[0])) ? GetSetting((short)RangeSettings[ControlIndex]) : 100);
|
||||
if (Controller.Range == 0) { Controller.Range = 1; }
|
||||
if (Controller.Range > 100) { Controller.Range = 100; }
|
||||
Controller.DeadZone = (uint8_t)(ControlIndex < (sizeof(DeadZoneSettings) / sizeof(DeadZoneSettings[0])) ? GetSetting((short)DeadZoneSettings[ControlIndex]) : 5);
|
||||
if (Controller.DeadZone > 100) { Controller.DeadZone = 100; }
|
||||
}
|
||||
|
||||
void CInputSettings::SaveController(uint32_t ControlIndex, const CONTROL & ControllerInfo, const N64CONTROLLER & Controller)
|
||||
|
@ -93,6 +96,11 @@ void CInputSettings::SaveController(uint32_t ControlIndex, const CONTROL & Contr
|
|||
{ Controller.R_ANALOG, Set_Control0_R_ANALOG, 0 },
|
||||
};
|
||||
|
||||
InputSettingID PresentSettings[] = { Set_Control0_Present };
|
||||
InputSettingID PluginSettings[] = { Set_Control0_Plugin };
|
||||
InputSettingID RangeSettings[] = { Set_Control0_Range };
|
||||
InputSettingID DeadzoneSettings[] = { Set_Control0_Deadzone };
|
||||
|
||||
for (size_t i = 0, n = sizeof(Buttons) / sizeof(Buttons[0]); i < n; i++)
|
||||
{
|
||||
if (Buttons[i].ControlIndex != ControlIndex)
|
||||
|
@ -102,22 +110,24 @@ void CInputSettings::SaveController(uint32_t ControlIndex, const CONTROL & Contr
|
|||
SetSettingSz((short)Buttons[i].SettingId, ButtonToStr(Buttons[i].Button).c_str());
|
||||
}
|
||||
|
||||
InputSettingID PresentSettings[] = { Set_Control0_Present };
|
||||
if (ControlIndex < (sizeof(PresentSettings) / sizeof(PresentSettings[0])))
|
||||
{
|
||||
SetSetting((short)PresentSettings[ControlIndex], ControllerInfo.Present);
|
||||
}
|
||||
InputSettingID PluginSettings[] = { Set_Control0_Plugin };
|
||||
if (ControlIndex < (sizeof(PluginSettings) / sizeof(PluginSettings[0])))
|
||||
{
|
||||
SetSetting((short)PluginSettings[ControlIndex], ControllerInfo.Plugin);
|
||||
}
|
||||
|
||||
InputSettingID RangeSettings[] = { Set_Control0_Range };
|
||||
if (ControlIndex < (sizeof(RangeSettings) / sizeof(RangeSettings[0])))
|
||||
{
|
||||
SetSetting((short)RangeSettings[ControlIndex], Controller.Range);
|
||||
}
|
||||
|
||||
if (ControlIndex < (sizeof(DeadzoneSettings) / sizeof(DeadzoneSettings[0])))
|
||||
{
|
||||
SetSetting((short)DeadzoneSettings[ControlIndex], Controller.DeadZone);
|
||||
}
|
||||
FlushSettings();
|
||||
}
|
||||
|
||||
|
@ -191,6 +201,7 @@ void CInputSettings::RegisterSettings(void)
|
|||
RegisterSetting(Set_Control0_Present, Data_DWORD_General, "Present", "Controller 1", 1, nullptr);
|
||||
RegisterSetting(Set_Control0_Plugin, Data_DWORD_General, "Plugin", "Controller 1", PLUGIN_MEMPAK, nullptr);
|
||||
RegisterSetting(Set_Control0_Range, Data_DWORD_General, "Range", "Controller 1", 100, nullptr);
|
||||
RegisterSetting(Set_Control0_Deadzone, Data_DWORD_General, "Deadzone", "Controller 1", 25, nullptr);
|
||||
RegisterSetting(Set_Control0_U_DPAD, Data_String_General, "DPadUp", "Controller 1", 0, "{6F1D2B61-D5A0-11CF-BFC7-444553540000} 17 0 5");
|
||||
RegisterSetting(Set_Control0_D_DPAD, Data_String_General, "DPadDown", "Controller 1", 0, "{6F1D2B61-D5A0-11CF-BFC7-444553540000} 25 0 5");
|
||||
RegisterSetting(Set_Control0_L_DPAD, Data_String_General, "DPadLeft", "Controller 1", 0, "{6F1D2B61-D5A0-11CF-BFC7-444553540000} 24 0 5");
|
||||
|
|
|
@ -5,6 +5,7 @@ enum InputSettingID
|
|||
Set_Control0_Present,
|
||||
Set_Control0_Plugin,
|
||||
Set_Control0_Range,
|
||||
Set_Control0_Deadzone,
|
||||
Set_Control0_U_DPAD,
|
||||
Set_Control0_D_DPAD,
|
||||
Set_Control0_L_DPAD,
|
||||
|
|
|
@ -22,4 +22,5 @@ typedef struct
|
|||
BUTTON L_ANALOG;
|
||||
BUTTON R_ANALOG;
|
||||
uint8_t Range;
|
||||
uint8_t DeadZone;
|
||||
} N64CONTROLLER;
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue