project64/Source/Project64-input/InputConfigUI.cpp

331 lines
12 KiB
C++
Raw Normal View History

2020-06-17 07:23:10 +00:00
#include "InputConfigUI.h"
2020-06-23 07:47:46 +00:00
#include "CProject64Input.h"
2020-06-17 07:23:10 +00:00
#include "wtl.h"
#include "wtl-BitmapPicture.h"
2020-06-23 07:47:46 +00:00
#include "wtl-ScanButton.h"
2020-07-27 11:51:30 +00:00
#include "OptionsUI.h"
2020-06-17 07:23:10 +00:00
#include <Common\stdtypes.h>
#include <Common\StdString.h>
#include "resource.h"
class CInputConfigUI;
2020-06-17 07:23:10 +00:00
class CControllerSettings :
public CPropertyPageImpl<CControllerSettings>
{
friend CInputConfigUI;
2020-06-23 07:47:46 +00:00
enum
{
DETECT_KEY_TIMER = 1
};
2020-06-17 07:23:10 +00:00
public:
enum { IDD = IDD_Controller };
2020-07-15 11:04:23 +00:00
BEGIN_MSG_MAP(CControllerSettings)
2020-06-17 07:23:10 +00:00
MSG_WM_INITDIALOG(OnInitDialog)
2020-06-23 07:47:46 +00:00
MSG_WM_CTLCOLORSTATIC(OnCtlColorStatic)
2020-07-15 11:38:48 +00:00
COMMAND_HANDLER_EX(IDC_BTN_DEFAULTS, BN_CLICKED, DefaultBtnClicked)
2020-07-15 11:04:23 +00:00
COMMAND_HANDLER_EX(IDC_BTN_SETUP, BN_CLICKED, SetupBtnClicked)
2020-07-27 11:51:30 +00:00
COMMAND_HANDLER_EX(IDC_BTN_OPTIONS, BN_CLICKED, OptionsBtnClicked)
COMMAND_HANDLER_EX(IDC_CHK_PLUGGED_IN, BN_CLICKED, ItemChanged)
NOTIFY_HANDLER_EX(IDC_TACK_RANGE, NM_RELEASEDCAPTURE, ItemChangedNotify);
MESSAGE_HANDLER(WM_HSCROLL, OnScroll)
2020-07-15 11:04:23 +00:00
MESSAGE_HANDLER(CScanButton::WM_SCAN_SUCCESS, OnScanSuccess)
MESSAGE_HANDLER(CScanButton::WM_SCAN_CANCELED, OnScanCanceled)
2020-06-17 07:23:10 +00:00
CHAIN_MSG_MAP(CPropertyPageImpl<CControllerSettings>)
END_MSG_MAP()
2020-06-23 07:47:46 +00:00
CControllerSettings(uint32_t ControllerNumber);
2020-06-17 07:23:10 +00:00
BOOL OnInitDialog(CWindow /*wndFocus*/, LPARAM /*lInitParam*/);
2020-06-23 07:47:46 +00:00
HBRUSH OnCtlColorStatic(CDCHandle dc, CWindow wndStatic);
bool OnApply();
2020-06-17 07:23:10 +00:00
private:
LRESULT OnScroll(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
2020-07-15 11:04:23 +00:00
LRESULT OnScanSuccess(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnScanCanceled(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
2020-07-15 11:38:48 +00:00
void DefaultBtnClicked(UINT Code, int id, HWND ctl);
2020-07-15 11:04:23 +00:00
void SetupBtnClicked(UINT Code, int id, HWND ctl);
2020-07-27 11:51:30 +00:00
void OptionsBtnClicked(UINT Code, int id, HWND ctl);
void ItemChanged(UINT Code, int id, HWND ctl);
LRESULT ItemChangedNotify(NMHDR* /*pNMHDR*/);
2020-07-15 11:38:48 +00:00
void DisplayController(void);
void ButtonChannged(void);
static void stButtonChanged(size_t data) { ((CControllerSettings *)data)->ButtonChannged(); }
2020-06-17 07:23:10 +00:00
std::wstring m_Title;
uint32_t m_ControllerNumber;
2020-06-23 07:47:46 +00:00
uint32_t m_ScanCount;
2020-07-15 11:04:23 +00:00
int32_t m_SetupIndex;
N64CONTROLLER m_Controller;
CONTROL m_ControlInfo;
2020-06-17 07:23:10 +00:00
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;
CScanButton m_ButtonZtrigger, m_ButtonRTrigger, m_ButtonLTrigger;
CScanButton m_ButtonAnalogU, m_ButtonAnalogD, m_ButtonAnalogL, m_ButtonAnalogR;
2020-06-17 07:23:10 +00:00
};
2020-06-23 07:47:46 +00:00
CControllerSettings::CControllerSettings(uint32_t ControllerNumber) :
m_ControllerNumber(ControllerNumber),
m_ScanCount(0),
2020-07-15 11:04:23 +00:00
m_SetupIndex(-1),
m_Controller(g_InputPlugin->Controllers(ControllerNumber)),
m_ControlInfo(g_InputPlugin->ControlInfo(ControllerNumber)),
m_ButtonUDPad(m_Controller.U_DPAD, IDC_EDIT_DIGITIAL_UP, IDC_BTN_DIGITIAL_UP),
m_ButtonDDPad(m_Controller.D_DPAD, IDC_EDIT_DIGITIAL_DOWN, IDC_BTN_DIGITIAL_DOWN),
m_ButtonLDPad(m_Controller.L_DPAD, IDC_EDIT_DIGITIAL_LEFT, IDC_BTN_DIGITIAL_LEFT),
m_ButtonRDPad(m_Controller.R_DPAD, IDC_EDIT_DIGITIAL_RIGHT, IDC_BTN_DIGITIAL_RIGHT),
m_ButtonA(m_Controller.A_BUTTON, IDC_EDIT_BUTTON_A, IDC_BTN_BUTTON_A),
m_ButtonB(m_Controller.B_BUTTON, IDC_EDIT_BUTTON_B, IDC_BTN_BUTTON_B),
m_ButtonCUp(m_Controller.U_CBUTTON, IDC_EDIT_CBUTTON_UP, IDC_BTN_CBUTTON_UP),
m_ButtonCDown(m_Controller.D_CBUTTON, IDC_EDIT_CBUTTON_DOWN, IDC_BTN_CBUTTON_DOWN),
m_ButtonCLeft(m_Controller.L_CBUTTON, IDC_EDIT_CBUTTON_LEFT, IDC_BTN_CBUTTON_LEFT),
m_ButtonCRight(m_Controller.R_CBUTTON, IDC_EDIT_CBUTTON_RIGHT, IDC_BTN_CBUTTON_RIGHT),
m_ButtonStart(m_Controller.START_BUTTON, IDC_EDIT_BUTTON_START, IDC_BTN_BUTTON_START),
m_ButtonZtrigger(m_Controller.Z_TRIG, IDC_EDIT_BUTTON_Z, IDC_BTN_BUTTON_Z),
m_ButtonRTrigger(m_Controller.R_TRIG, IDC_EDIT_RTRIGGER, IDC_BTN_RTRIGGER),
m_ButtonLTrigger(m_Controller.L_TRIG, IDC_EDIT_LTRIGGER, IDC_BTN_LTRIGGER),
m_ButtonAnalogU(m_Controller.U_ANALOG, IDC_EDIT_ANALOG_UP, IDC_BTN_ANALOG_UP),
m_ButtonAnalogD(m_Controller.D_ANALOG, IDC_EDIT_ANALOG_DOWN, IDC_BTN_ANALOG_DOWN),
m_ButtonAnalogL(m_Controller.L_ANALOG, IDC_EDIT_ANALOG_LEFT, IDC_BTN_ANALOG_LEFT),
m_ButtonAnalogR(m_Controller.R_ANALOG, IDC_EDIT_ANALOG_RIGHT, IDC_BTN_ANALOG_RIGHT)
2020-06-17 07:23:10 +00:00
{
m_Title = stdstr_f("Player %d", ControllerNumber + 1).ToUTF16();
SetTitle(m_Title.c_str());
}
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);
m_Range.SetRangeMax(100);
m_PluggedIn.Attach(GetDlgItem(IDC_CHK_PLUGGED_IN));
2020-06-17 07:23:10 +00:00
m_ControllerImg.SubclassWindow(GetDlgItem(IDC_BMP_CONTROLLER));
m_ControllerImg.SetBitmap(MAKEINTRESOURCE(IDB_CONTROLLER));
CScanButton * Buttons[] = {
&m_ButtonUDPad, &m_ButtonDDPad, &m_ButtonLDPad, &m_ButtonRDPad, &m_ButtonA, &m_ButtonB,
&m_ButtonCUp, &m_ButtonCDown, &m_ButtonCLeft, &m_ButtonCRight, &m_ButtonStart,
&m_ButtonZtrigger, &m_ButtonRTrigger, &m_ButtonLTrigger,
&m_ButtonAnalogU, &m_ButtonAnalogD, &m_ButtonAnalogL, &m_ButtonAnalogR
};
for (size_t i = 0, n = sizeof(Buttons) / sizeof(Buttons[0]); i < n; i++)
{
Buttons[i]->SubclassWindow(m_hWnd);
Buttons[i]->SetChangeCallback(stButtonChanged, (size_t)this);
}
2020-07-15 11:38:48 +00:00
DisplayController();
2020-06-17 07:23:10 +00:00
return TRUE;
}
2020-06-23 07:47:46 +00:00
HBRUSH CControllerSettings::OnCtlColorStatic(CDCHandle dc, CWindow wndStatic)
{
if (g_InputPlugin->IsScanning() && wndStatic.GetDlgCtrlID() == g_InputPlugin->DisplayCtrlId())
{
dc.SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT));
dc.SetBkColor(GetSysColor(COLOR_HIGHLIGHT));
return ::GetSysColorBrush(COLOR_HIGHLIGHT);
}
dc.SetTextColor(GetSysColor(COLOR_WINDOWTEXT));
dc.SetBkColor(GetSysColor(COLOR_WINDOW));
return ::GetSysColorBrush(COLOR_WINDOW);
}
bool CControllerSettings::OnApply()
{
N64CONTROLLER & Controller = g_InputPlugin->Controllers(m_ControllerNumber);
Controller = m_Controller;
Controller.Range = (uint8_t)m_Range.GetPos();
Controller.DeadZone = (uint8_t)m_DeadZone.GetPos();
CONTROL & ControlInfo = g_InputPlugin->ControlInfo(m_ControllerNumber);
ControlInfo.Present = (m_PluggedIn.GetCheck() == BST_CHECKED) ? 1 : 0;
return g_InputPlugin->SaveController(m_ControllerNumber);
}
LRESULT CControllerSettings::OnScroll(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
{
LONG SliderId = CWindow((HWND)lParam).GetWindowLong(GWL_ID);
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;
}
2020-07-15 11:04:23 +00:00
LRESULT CControllerSettings::OnScanSuccess(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
if (m_SetupIndex < 0)
{
return 0;
}
CScanButton * Buttons[] = {
&m_ButtonUDPad, &m_ButtonDDPad, &m_ButtonLDPad, &m_ButtonRDPad,
&m_ButtonAnalogU, &m_ButtonAnalogD, &m_ButtonAnalogL, &m_ButtonAnalogR,
&m_ButtonCUp, &m_ButtonCDown, &m_ButtonCLeft, &m_ButtonCRight,
&m_ButtonB, &m_ButtonA, &m_ButtonStart, &m_ButtonZtrigger,
&m_ButtonLTrigger, &m_ButtonRTrigger
};
m_SetupIndex += 1;
if (m_SetupIndex < (sizeof(Buttons) / sizeof(Buttons[0])))
{
Buttons[m_SetupIndex]->DetectKey();
}
return 0;
}
LRESULT CControllerSettings::OnScanCanceled(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
m_SetupIndex = -1;
return 0;
}
void CControllerSettings::DefaultBtnClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
2020-07-15 11:38:48 +00:00
{
g_InputPlugin->ResetController(m_ControllerNumber, m_ControlInfo, m_Controller);
2020-07-15 11:38:48 +00:00
DisplayController();
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
}
2020-07-15 11:04:23 +00:00
void CControllerSettings::SetupBtnClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
m_SetupIndex = 0;
m_ButtonUDPad.DetectKey();
}
2020-07-27 11:51:30 +00:00
void CControllerSettings::OptionsBtnClicked(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
ConfigOption(m_ControllerNumber, m_ControlInfo, m_Controller);
}
void CControllerSettings::ItemChanged(UINT /*Code*/, int /*id*/, HWND /*ctl*/)
{
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
}
LRESULT CControllerSettings::ItemChangedNotify(NMHDR* /*pNMHDR*/)
{
SendMessage(GetParent(), PSM_CHANGED, (WPARAM)m_hWnd, 0);
return 0;
}
2020-07-15 11:38:48 +00:00
void CControllerSettings::DisplayController(void)
{
m_PluggedIn.SetCheck(m_ControlInfo.Present != 0 ? BST_CHECKED : BST_UNCHECKED);
m_Range.SetPos(m_Controller.Range);
m_DeadZone.SetPos(m_Controller.DeadZone);
2020-07-15 11:38:48 +00:00
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());
2020-07-15 11:38:48 +00:00
CScanButton * Buttons[] = {
&m_ButtonUDPad, &m_ButtonDDPad, &m_ButtonLDPad, &m_ButtonRDPad, &m_ButtonA, &m_ButtonB,
&m_ButtonCUp, &m_ButtonCDown, &m_ButtonCLeft, &m_ButtonCRight, &m_ButtonStart,
&m_ButtonZtrigger, &m_ButtonRTrigger, &m_ButtonLTrigger,
&m_ButtonAnalogU, &m_ButtonAnalogD, &m_ButtonAnalogL, &m_ButtonAnalogR
};
for (size_t i = 0, n = sizeof(Buttons) / sizeof(Buttons[0]); i < n; i++)
{
Buttons[i]->DisplayButton();
}
GetDlgItem(IDC_BOUND_DEVICE).SetWindowText(g_InputPlugin->ControllerDevices(m_Controller).c_str());
2020-07-15 11:38:48 +00:00
}
void CControllerSettings::ButtonChannged(void)
{
GetDlgItem(IDC_BOUND_DEVICE).SetWindowText(g_InputPlugin->ControllerDevices(m_Controller).c_str());
CPropertySheetWindow(GetParent()).SetModified(m_hWnd);
}
2020-06-17 07:23:10 +00:00
class CInputConfigUI:
public CPropertySheetImpl<CInputConfigUI>
{
public:
CInputConfigUI();
~CInputConfigUI();
void UpdateDeviceMapping(void);
2020-06-17 07:23:10 +00:00
void OnSheetInitialized();
private:
2020-06-23 07:47:46 +00:00
CControllerSettings m_pgController0, m_pgController1, m_pgController2, m_pgController3;
2020-06-17 07:23:10 +00:00
};
CInputConfigUI * g_ConfigUI = nullptr;
2020-06-17 07:23:10 +00:00
void ConfigInput(void * hParent)
{
CInputConfigUI ConfigUI;
g_ConfigUI = &ConfigUI;
ConfigUI.DoModal((HWND)hParent);
g_ConfigUI = nullptr;
2020-06-17 07:23:10 +00:00
}
2020-06-23 07:47:46 +00:00
CInputConfigUI::CInputConfigUI() :
m_pgController0(0),
m_pgController1(1),
m_pgController2(2),
m_pgController3(3)
2020-06-17 07:23:10 +00:00
{
m_psh.pszCaption = L"Configure Input";
2020-06-23 07:47:46 +00:00
AddPage(&m_pgController0.m_psp);
AddPage(&m_pgController1.m_psp);
AddPage(&m_pgController2.m_psp);
AddPage(&m_pgController3.m_psp);
2020-06-17 07:23:10 +00:00
}
CInputConfigUI::~CInputConfigUI()
{
}
void CInputConfigUI::OnSheetInitialized()
{
ModifyStyleEx(WS_EX_CONTEXTHELP,0);
}
void CInputConfigUI::UpdateDeviceMapping(void)
{
CControllerSettings * Pages[] = {
&m_pgController0,
&m_pgController1,
&m_pgController2,
&m_pgController3
};
for (size_t i = 0, n = GetPageCount(); i < n; i++)
{
HWND hPage = IndexToHwnd(i);
if (hPage != nullptr && i < (sizeof(Pages) / sizeof(Pages[0])))
{
N64CONTROLLER & Controller = Pages[i]->m_Controller;
CWindow(::GetDlgItem(hPage, IDC_BOUND_DEVICE)).SetWindowText(g_InputPlugin->ControllerDevices(Controller).c_str());
}
}
}
void ConfigUIDeviceAdded(void)
{
if (g_ConfigUI != nullptr)
{
g_ConfigUI->UpdateDeviceMapping();
}
}