Project64-input: Display device bound to

This commit is contained in:
zilmar 2020-07-22 13:13:42 +09:30
parent fc51e39738
commit 878725490b
6 changed files with 135 additions and 8 deletions

View File

@ -1,5 +1,6 @@
#include "CProject64Input.h"
#include "InputSettings.h"
#include "InputConfigUI.h"
CProject64Input * g_InputPlugin = nullptr;
@ -25,6 +26,11 @@ void CProject64Input::DevicesChanged(void)
}
}
void CProject64Input::DeviceAdded(void)
{
ConfigUIDeviceAdded();
}
void CProject64Input::InitiateControllers(CONTROL_INFO * ControlInfo)
{
CGuard guard(m_CS);
@ -107,6 +113,20 @@ std::wstring CProject64Input::ButtonAssignment(BUTTON & Button)
return L"Unknown";
}
std::wstring CProject64Input::ControllerDevices(uint32_t ControlIndex)
{
if (ControlIndex >= sizeof(m_Controllers) / sizeof(m_Controllers[0]))
{
return false;
}
if (m_DirectInput.get() != NULL)
{
return m_DirectInput->ControllerDevices(m_Controllers[ControlIndex]);
}
return L"";
}
bool CProject64Input::SaveController(uint32_t ControlIndex)
{
CGuard guard(m_CS);

View File

@ -12,12 +12,14 @@ public:
~CProject64Input();
void DevicesChanged(void);
void DeviceAdded(void);
void InitiateControllers(CONTROL_INFO * ControlInfo);
void GetKeys(int32_t Control, BUTTONS * Keys);
void StartScanDevices(int32_t DisplayCtrlId);
void EndScanDevices(void);
CDirectInput::ScanResult ScanDevices(BUTTON & Button);
std::wstring ButtonAssignment(BUTTON & Button);
std::wstring ControllerDevices(uint32_t ControlIndex);
bool SaveController(uint32_t ControlIndex);
bool ResetController(uint32_t ControlIndex);

View File

@ -1,6 +1,8 @@
#include "DirectInput.h"
#include <Common\StdString.h>
#include <Common\SyncEvent.h>
#include <set>
#include "CProject64Input.h"
CDirectInput::CDirectInput(HINSTANCE hinst) :
m_hDirectInputDLL(nullptr),
@ -32,6 +34,8 @@ CDirectInput::CDirectInput(HINSTANCE hinst) :
CDirectInput::~CDirectInput()
{
CGuard Guard(m_DeviceCS);
for (DEVICE_MAP::iterator itr = m_Devices.begin(); itr != m_Devices.end(); itr++)
{
if (itr->second.didHandle != nullptr)
@ -71,6 +75,7 @@ void CDirectInput::MapControllerDevice(N64CONTROLLER & Controller)
&Controller.R_ANALOG,
};
CGuard Guard(m_DeviceCS);
for (size_t i = 0, n = sizeof(Buttons) / sizeof(Buttons[0]); i < n; i++)
{
DEVICE_MAP::iterator itr = m_Devices.find(Buttons[i]->DeviceGuid);
@ -99,10 +104,13 @@ BOOL CDirectInput::EnumMakeDeviceList(LPCDIDEVICEINSTANCE lpddi)
return DIENUM_CONTINUE;
}
DEVICE_MAP::iterator itr = m_Devices.find(lpddi->guidInstance);
if (itr != m_Devices.end())
{
return DIENUM_CONTINUE;
CGuard Guard(m_DeviceCS);
DEVICE_MAP::iterator itr = m_Devices.find(lpddi->guidInstance);
if (itr != m_Devices.end())
{
return DIENUM_CONTINUE;
}
}
DEVICE Device = { 0 };
@ -142,11 +150,15 @@ BOOL CDirectInput::EnumMakeDeviceList(LPCDIDEVICEINSTANCE lpddi)
return DIENUM_CONTINUE;
}
std::pair<DEVICE_MAP::iterator, bool> res = m_Devices.insert(DEVICE_MAP::value_type(lpddi->guidInstance, Device));
if (!res.second)
{
Device.didHandle->Release();
CGuard Guard(m_DeviceCS);
std::pair<DEVICE_MAP::iterator, bool> res = m_Devices.insert(DEVICE_MAP::value_type(lpddi->guidInstance, Device));
if (!res.second)
{
Device.didHandle->Release();
}
}
g_InputPlugin->DeviceAdded();
return DIENUM_CONTINUE;
}
@ -154,6 +166,7 @@ CDirectInput::ScanResult CDirectInput::ScanDevices(BUTTON & Button)
{
ScanResult Result = SCAN_FAILED;
CGuard Guard(m_DeviceCS);
for (DEVICE_MAP::iterator itr = m_Devices.begin(); itr != m_Devices.end(); itr++)
{
DEVICE &device = itr->second;
@ -272,6 +285,64 @@ std::wstring CDirectInput::ButtonAssignment(BUTTON & Button)
return L"Unknown";
}
std::wstring CDirectInput::ControllerDevices(N64CONTROLLER & Controller)
{
BUTTON * Buttons[] =
{
&Controller.U_DPAD,
&Controller.D_DPAD,
&Controller.L_DPAD,
&Controller.R_DPAD,
&Controller.A_BUTTON,
&Controller.B_BUTTON,
&Controller.U_CBUTTON,
&Controller.D_CBUTTON,
&Controller.L_CBUTTON,
&Controller.R_CBUTTON,
&Controller.START_BUTTON,
&Controller.Z_TRIG,
&Controller.R_TRIG,
&Controller.L_TRIG,
&Controller.U_ANALOG,
&Controller.D_ANALOG,
&Controller.L_ANALOG,
&Controller.R_ANALOG,
};
typedef std::set<GUID, GUIDComparer> GUID_LIST;
GUID_LIST DeviceGuids;
for (size_t i = 0, n = sizeof(Buttons) / sizeof(Buttons[0]); i < n; i++)
{
GUID_LIST::iterator itr = DeviceGuids.find(Buttons[i]->DeviceGuid);
if (itr != DeviceGuids.end())
{
continue;
}
DeviceGuids.insert(Buttons[i]->DeviceGuid);
}
std::wstring DeviceList;
CGuard Guard(m_DeviceCS);
bool UnknownDevice = false;
for (GUID_LIST::iterator itr = DeviceGuids.begin(); itr != DeviceGuids.end(); itr++)
{
DEVICE_MAP::iterator DeviceItr = m_Devices.find(*itr);
if (DeviceItr == m_Devices.end())
{
UnknownDevice = true;
continue;
}
if (!DeviceList.empty()) { DeviceList += L", "; }
DeviceList += stdstr(DeviceItr->second.ProductName).ToUTF16();
}
if (UnknownDevice)
{
if (!DeviceList.empty()) { DeviceList += L", "; }
DeviceList += L"Unknown Device";
}
return DeviceList;
}
bool CDirectInput::IsButtonPressed(BUTTON & Button)
{
if (Button.Device == nullptr)
@ -390,6 +461,7 @@ void CDirectInput::GetAxis(N64CONTROLLER & Controller, BUTTONS * Keys)
void CDirectInput::UpdateDeviceData(void)
{
CGuard Guard(m_DeviceCS);
for (DEVICE_MAP::iterator itr = m_Devices.begin(); itr != m_Devices.end(); itr++)
{
DEVICE & device = itr->second;

View File

@ -3,6 +3,7 @@
#include "Button.h"
#include "DeviceNotification.h"
#include "N64Controller.h"
#include <Common\CriticalSection.h>
#define DIRECTINPUT_VERSION 0x0800
#include <Windows.h>
#include <dinput.h>
@ -45,10 +46,12 @@ public:
void MapControllerDevice(N64CONTROLLER & Controller);
ScanResult ScanDevices(BUTTON & Button);
std::wstring ButtonAssignment(BUTTON & Button);
std::wstring ControllerDevices(N64CONTROLLER & Controller);
bool IsButtonPressed(BUTTON & Button);
void GetAxis(N64CONTROLLER & Controller, BUTTONS * Keys);
void UpdateDeviceData(void);
void DevicesChanged(void);
void DeviceAdded(void);
private:
CDirectInput();
@ -88,6 +91,7 @@ private:
DeviceNotification m_DeviceNotification;
DEVICE_MAP m_Devices;
CriticalSection m_DeviceCS;
HMODULE m_hDirectInputDLL;
LPDIRECTINPUT8 m_pDIHandle;
HINSTANCE m_hinst;

View File

@ -188,7 +188,7 @@ LRESULT CControllerSettings::OnScanCanceled(UINT /*uMsg*/, WPARAM /*wParam*/, LP
return 0;
}
void CControllerSettings::DefaultBtnClicked(UINT Code, int id, HWND ctl)
void CControllerSettings::DefaultBtnClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
g_InputPlugin->ResetController(m_ControllerNumber);
DisplayController();
@ -232,10 +232,12 @@ void CControllerSettings::DisplayController(void)
{
Buttons[i]->DisplayButton();
}
GetDlgItem(IDC_BOUND_DEVICE).SetWindowText(g_InputPlugin->ControllerDevices(m_ControllerNumber).c_str());
}
void CControllerSettings::ButtonChannged(void)
{
GetDlgItem(IDC_BOUND_DEVICE).SetWindowText(g_InputPlugin->ControllerDevices(m_ControllerNumber).c_str());
CPropertySheetWindow(GetParent()).SetModified(m_hWnd);
}
@ -246,15 +248,21 @@ public:
CInputConfigUI();
~CInputConfigUI();
void UpdateDeviceMapping(void);
void OnSheetInitialized();
private:
CControllerSettings m_pgController0, m_pgController1, m_pgController2, m_pgController3;
};
CInputConfigUI * g_ConfigUI = nullptr;
void ConfigInput(void * hParent)
{
CInputConfigUI().DoModal((HWND)hParent);
CInputConfigUI ConfigUI;
g_ConfigUI = &ConfigUI;
ConfigUI.DoModal((HWND)hParent);
g_ConfigUI = nullptr;
}
CInputConfigUI::CInputConfigUI() :
@ -278,3 +286,23 @@ void CInputConfigUI::OnSheetInitialized()
{
ModifyStyleEx(WS_EX_CONTEXTHELP,0);
}
void CInputConfigUI::UpdateDeviceMapping(void)
{
for (size_t i = 0, n = GetPageCount(); i < n; i++)
{
HWND hPage = IndexToHwnd(i);
if (hPage != nullptr)
{
CWindow(::GetDlgItem(hPage, IDC_BOUND_DEVICE)).SetWindowText(g_InputPlugin->ControllerDevices(i).c_str());
}
}
}
void ConfigUIDeviceAdded(void)
{
if (g_ConfigUI != nullptr)
{
g_ConfigUI->UpdateDeviceMapping();
}
}

View File

@ -1,3 +1,4 @@
#pragma once
void ConfigInput(void * hParent);
void ConfigUIDeviceAdded(void);