Project64-input: Add controller present

This commit is contained in:
zilmar 2020-07-07 11:50:36 +09:30
parent 8df9403bce
commit f1d8910e5f
4 changed files with 17 additions and 6 deletions

View File

@ -26,7 +26,7 @@ void CProject64Input::InitiateControllers(CONTROL_INFO * ControlInfo)
m_DirectInput->Initiate(ControlInfo); m_DirectInput->Initiate(ControlInfo);
for (size_t i = 0, n = sizeof(m_Controllers) / sizeof(m_Controllers[0]); i < n; i++) for (size_t i = 0, n = sizeof(m_Controllers) / sizeof(m_Controllers[0]); i < n; i++)
{ {
g_Settings->LoadController(0, m_Controllers[i]); g_Settings->LoadController(i, m_ControlInfo.Controls[i], m_Controllers[i]);
m_DirectInput->MapControllerDevice(m_Controllers[i]); m_DirectInput->MapControllerDevice(m_Controllers[i]);
} }
} }
@ -96,6 +96,6 @@ bool CProject64Input::SaveController(uint32_t ControlIndex)
{ {
return false; return false;
} }
g_Settings->SaveController(ControlIndex, m_Controllers[ControlIndex]); g_Settings->SaveController(ControlIndex, m_ControlInfo.Controls[ControlIndex], m_Controllers[ControlIndex]);
return true; return true;
} }

View File

@ -14,7 +14,7 @@ CInputSettings::~CInputSettings()
{ {
} }
void CInputSettings::LoadController(uint32_t ControlIndex, N64CONTROLLER & Controller) void CInputSettings::LoadController(uint32_t ControlIndex, CONTROL & ControllerInfo, N64CONTROLLER & Controller)
{ {
struct { struct {
BUTTON & Button; BUTTON & Button;
@ -53,14 +53,16 @@ void CInputSettings::LoadController(uint32_t ControlIndex, N64CONTROLLER & Contr
Buttons[i].Button = StrToButton(GetSettingSz((short)Buttons[i].SettingId, Buffer, sizeof(Buffer) / sizeof(Buffer[0]))); Buttons[i].Button = StrToButton(GetSettingSz((short)Buttons[i].SettingId, Buffer, sizeof(Buffer) / sizeof(Buffer[0])));
} }
InputSettingID PresentSettings[] = { Set_Control0_Present };
InputSettingID RangeSettings[] = { Set_Control0_Range }; InputSettingID RangeSettings[] = { Set_Control0_Range };
ControllerInfo.Present = ControlIndex < (sizeof(PresentSettings) / sizeof(PresentSettings[0])) ? GetSetting((short)PresentSettings[ControlIndex]) != 0 : 0;
Controller.Range = (uint8_t)(ControlIndex < (sizeof(RangeSettings) / sizeof(RangeSettings[0])) ? GetSetting((short)RangeSettings[ControlIndex]) : 100); 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 == 0) { Controller.Range = 1; }
if (Controller.Range > 100) { Controller.Range = 100; } if (Controller.Range > 100) { Controller.Range = 100; }
} }
void CInputSettings::SaveController(uint32_t ControlIndex, const N64CONTROLLER & Controller) void CInputSettings::SaveController(uint32_t ControlIndex, const CONTROL & ControllerInfo, const N64CONTROLLER & Controller)
{ {
struct { struct {
const BUTTON & Button; const BUTTON & Button;
@ -98,6 +100,12 @@ void CInputSettings::SaveController(uint32_t ControlIndex, const N64CONTROLLER &
SetSettingSz((short)Buttons[i].SettingId, ButtonToStr(Buttons[i].Button).c_str()); 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 RangeSettings[] = { Set_Control0_Range }; InputSettingID RangeSettings[] = { Set_Control0_Range };
if (ControlIndex < (sizeof(RangeSettings) / sizeof(RangeSettings[0]))) if (ControlIndex < (sizeof(RangeSettings) / sizeof(RangeSettings[0])))
{ {
@ -136,6 +144,7 @@ std::string CInputSettings::GUIDtoString(const GUID & guid)
void CInputSettings::RegisterSettings(void) void CInputSettings::RegisterSettings(void)
{ {
SetModuleName("Input"); SetModuleName("Input");
RegisterSetting(Set_Control0_Present, Data_DWORD_General, "Present", "Controller 1", 1, nullptr);
RegisterSetting(Set_Control0_Range, Data_DWORD_General, "Range", "Controller 1", 100, nullptr); RegisterSetting(Set_Control0_Range, Data_DWORD_General, "Range", "Controller 1", 100, nullptr);
RegisterSetting(Set_Control0_U_DPAD, Data_String_General, "DPadUp", "Controller 1", 0, "{6F1D2B61-D5A0-11CF-BFC7-444553540000} 17 0 5"); 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_D_DPAD, Data_String_General, "DPadDown", "Controller 1", 0, "{6F1D2B61-D5A0-11CF-BFC7-444553540000} 25 0 5");

View File

@ -2,6 +2,7 @@
#include <Common\stdtypes.h> #include <Common\stdtypes.h>
#include <string> #include <string>
#include "N64Controller.h" #include "N64Controller.h"
#include "ControllerSpec1.1.h"
class CInputSettings class CInputSettings
{ {
@ -9,8 +10,8 @@ public:
CInputSettings(); CInputSettings();
~CInputSettings(); ~CInputSettings();
void LoadController(uint32_t ControlIndex, N64CONTROLLER & Controller); void LoadController(uint32_t ControlIndex, CONTROL & ControllerInfo, N64CONTROLLER & Controller);
void SaveController(uint32_t ControlIndex, const N64CONTROLLER & Controller); void SaveController(uint32_t ControlIndex, const CONTROL & ControllerInfo, const N64CONTROLLER & Controller);
private: private:
CInputSettings(const CInputSettings&); CInputSettings(const CInputSettings&);

View File

@ -2,6 +2,7 @@
enum InputSettingID enum InputSettingID
{ {
Set_Control0_Present,
Set_Control0_Range, Set_Control0_Range,
Set_Control0_U_DPAD, Set_Control0_U_DPAD,
Set_Control0_D_DPAD, Set_Control0_D_DPAD,