From 1d9dc0df2dff15cf6fb3c9e4228f48fffcce3dda Mon Sep 17 00:00:00 2001 From: ergo720 <45463469+ergo720@users.noreply.github.com> Date: Sun, 13 Jun 2021 17:56:57 +0200 Subject: [PATCH] Added support to mu to input gui --- src/common/Settings.cpp | 2 + src/common/input/Button.h | 2 + src/common/input/InputManager.h | 3 + src/common/input/InputWindow.cpp | 23 +++++++ src/common/input/InputWindow.h | 11 ++- src/common/win32/EmuShared.h | 3 + src/gui/DlgInputConfig.cpp | 2 + .../controllers/DlgDukeControllerConfig.cpp | 69 +++++++++++++------ src/gui/controllers/DlgSBControllerConfig.cpp | 28 -------- src/gui/resource/Cxbx.rc | 21 ++++-- src/gui/resource/ResCxbx.h | 6 +- 11 files changed, 112 insertions(+), 58 deletions(-) diff --git a/src/common/Settings.cpp b/src/common/Settings.cpp index 0faa84d7f..60bf628b8 100644 --- a/src/common/Settings.cpp +++ b/src/common/Settings.cpp @@ -783,6 +783,8 @@ void Settings::SyncToEmulator() // register xbox device input settings for (int i = 0; i < 4; i++) { g_EmuShared->SetInputDevTypeSettings(&m_input_port[i].Type, i); + g_EmuShared->SetInputSlotTypeSettings(&m_input_port[i].TopSlotType, i, MU_SLOT_TOP); + g_EmuShared->SetInputSlotTypeSettings(&m_input_port[i].BottomSlotType, i, MU_SLOT_BOTTOM); if (m_input_port[i].Type != to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID)) { g_EmuShared->SetInputDevNameSettings(m_input_port[i].DeviceName.c_str(), i); auto it = std::find_if(m_input_profiles[m_input_port[i].Type].begin(), diff --git a/src/common/input/Button.h b/src/common/input/Button.h index a74afded5..ac0658bfe 100644 --- a/src/common/input/Button.h +++ b/src/common/input/Button.h @@ -35,6 +35,8 @@ #define SBC_NUM_BUTTONS 56 #define HIGHEST_NUM_BUTTONS SBC_NUM_BUTTONS +#define MU_NUM_SLOTS 2 + #define XBOX_BUTTON_NAME_LENGTH 30 #define HOST_BUTTON_NAME_LENGTH 30 diff --git a/src/common/input/InputManager.h b/src/common/input/InputManager.h index 8edf43dd1..15ce595d7 100644 --- a/src/common/input/InputManager.h +++ b/src/common/input/InputManager.h @@ -37,6 +37,9 @@ #undef SetPort #endif +#define MU_SLOT_TOP 0 +#define MU_SLOT_BOTTOM 1 + extern int dev_num_buttons[to_underlying(XBOX_INPUT_DEVICE::DEVICE_MAX)]; inline XBOX_INPUT_DEVICE input_support_list[] = { diff --git a/src/common/input/InputWindow.cpp b/src/common/input/InputWindow.cpp index 69fcef6ed..485265758 100644 --- a/src/common/input/InputWindow.cpp +++ b/src/common/input/InputWindow.cpp @@ -177,6 +177,29 @@ void InputWindow::BindButton(int ControlID) } } +void InputWindow::UpdateProfile(const std::string &name, int command) +{ + switch (command) + { + case PROFILE_LOAD: + LoadProfile(name); + break; + + case PROFILE_SAVE: + SaveProfile(name); + break; + + case PROFILE_DELETE: + DeleteProfile(name); + break; + + case BUTTON_CLEAR: + case BUTTON_SWAP: + m_bHasChanges = true; + break; + } +} + InputWindow::ProfileIt InputWindow::FindProfile(const std::string& name) { auto it = std::find_if(g_Settings->m_input_profiles[m_dev_type].begin(), diff --git a/src/common/input/InputWindow.h b/src/common/input/InputWindow.h index e860bb52b..025c0c8a5 100644 --- a/src/common/input/InputWindow.h +++ b/src/common/input/InputWindow.h @@ -40,6 +40,7 @@ #define RUMBLE_CLEAR 7 #define BUTTON_CLEAR 8 #define BUTTON_SWAP 9 +#define SLOTS_CHANGED 10 #define XINPUT_DEFAULT 0 #define DINPUT_DEFAULT 1 @@ -58,9 +59,9 @@ public: void UpdateDeviceList(); void BindButton(int ControlID); virtual void ClearBindings() = 0; - virtual void UpdateProfile(const std::string& name, int command) = 0; + virtual void UpdateProfile(const std::string& name, int command); void UpdateCurrentDevice(); - bool IsProfileSaved(); + virtual bool IsProfileSaved(); void SwapMoCursorAxis(Button *button); @@ -106,6 +107,7 @@ public: void BindDefault(); void ClearBindings() override; void UpdateProfile(const std::string &name, int command) override; + bool IsProfileSaved() override; private: @@ -118,6 +120,10 @@ private: HWND m_hwnd_rumble; // handle of the rumble combobox HWND m_hwnd_rumble_list; + // handle of the top slot combobox + HWND m_hwnd_top_slot_list; + // handle of the bottom slot combobox + HWND m_hwnd_bottom_slot_list; // currently selected rumble control std::string m_rumble; }; @@ -127,7 +133,6 @@ class SbcInputWindow : public InputWindow public: void Initialize(HWND hwnd, int port_num, int dev_type) override; void ClearBindings() override; - void UpdateProfile(const std::string &name, int command) override; private: diff --git a/src/common/win32/EmuShared.h b/src/common/win32/EmuShared.h index 923d5f9c7..1b36b352b 100644 --- a/src/common/win32/EmuShared.h +++ b/src/common/win32/EmuShared.h @@ -135,6 +135,8 @@ class EmuShared : public Mutex // ****************************************************************** void GetInputDevTypeSettings(int* type, int port) { Lock(); *type = m_DeviceType[port]; Unlock(); } void SetInputDevTypeSettings(const int* type, int port) { Lock(); m_DeviceType[port] = *type; Unlock(); } + void GetInputSlotTypeSettings(int *type, int port, int slot) { Lock(); *type = m_SlotDeviceType[port][slot]; Unlock(); } + void SetInputSlotTypeSettings(const int *type, int port, int slot) { Lock(); m_SlotDeviceType[port][slot] = *type; Unlock(); } void GetInputDevNameSettings(char* name, int port) { Lock(); strncpy(name, m_DeviceName[port], 50); Unlock(); } void SetInputDevNameSettings(const char* name, int port) { Lock(); strncpy(m_DeviceName[port], name, 50); Unlock(); } void GetInputBindingsSettings(char button_str[][HOST_BUTTON_NAME_LENGTH], int max_num_buttons, int port) @@ -366,6 +368,7 @@ class EmuShared : public Mutex bool m_bClipCursor; unsigned int m_dwKrnlProcID; // Only used for kernel mode level. int m_DeviceType[4]; + int m_SlotDeviceType[4][MU_NUM_SLOTS]; char m_DeviceControlNames[4][HIGHEST_NUM_BUTTONS][HOST_BUTTON_NAME_LENGTH]; char m_DeviceName[4][50]; char m_TitleMountPath[xbox::max_path]; diff --git a/src/gui/DlgInputConfig.cpp b/src/gui/DlgInputConfig.cpp index b614aa38e..f3a782ec7 100644 --- a/src/gui/DlgInputConfig.cpp +++ b/src/gui/DlgInputConfig.cpp @@ -51,6 +51,8 @@ void SyncInputSettings(int port_num, int dev_type, bool is_opt) if (!is_opt) { // Sync updated input to kernel process to use run-time settings. g_EmuShared->SetInputDevTypeSettings(&g_Settings->m_input_port[port_num].Type, port_num); + g_EmuShared->SetInputSlotTypeSettings(&g_Settings->m_input_port[port_num].TopSlotType, port_num, MU_SLOT_TOP); + g_EmuShared->SetInputSlotTypeSettings(&g_Settings->m_input_port[port_num].BottomSlotType, port_num, MU_SLOT_BOTTOM); if (dev_type != to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID)) { std::string dev_name = g_Settings->m_input_port[port_num].DeviceName; diff --git a/src/gui/controllers/DlgDukeControllerConfig.cpp b/src/gui/controllers/DlgDukeControllerConfig.cpp index 0eca3788e..9acbcac51 100644 --- a/src/gui/controllers/DlgDukeControllerConfig.cpp +++ b/src/gui/controllers/DlgDukeControllerConfig.cpp @@ -49,6 +49,8 @@ void DukeInputWindow::Initialize(HWND hwnd, int port_num, int dev_type) m_hwnd_device_list = GetDlgItem(m_hwnd_window, IDC_DEVICE_LIST); m_hwnd_profile_list = GetDlgItem(m_hwnd_window, IDC_PROFILE_NAME); m_hwnd_default = GetDlgItem(m_hwnd_window, IDC_DEFAULT); + m_hwnd_top_slot_list = GetDlgItem(hwnd, IDC_DEVICE_LIST_TOP_SLOT); + m_hwnd_bottom_slot_list = GetDlgItem(hwnd, IDC_DEVICE_LIST_BOTTOM_SLOT); m_dev_type = dev_type; m_max_num_buttons = dev_num_buttons[dev_type]; m_port_num = port_num; @@ -84,6 +86,24 @@ void DukeInputWindow::Initialize(HWND hwnd, int port_num, int dev_type) // Set the maximum profile name lenght the user can enter in the profile combobox SendMessage(m_hwnd_profile_list, CB_LIMITTEXT, 49, 0); + // Set up the device types we support in the slot ports + SendMessage(m_hwnd_top_slot_list, CB_ADDSTRING, 0, + reinterpret_cast(GetInputDeviceName(to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID)).c_str())); + SendMessage(m_hwnd_bottom_slot_list, CB_ADDSTRING, 0, + reinterpret_cast(GetInputDeviceName(to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID)).c_str())); + + if (m_dev_type != to_underlying(XBOX_INPUT_DEVICE::ARCADE_STICK)) { + SendMessage(m_hwnd_top_slot_list, CB_ADDSTRING, 0, + reinterpret_cast(GetInputDeviceName(to_underlying(XBOX_INPUT_DEVICE::MEMORY_UNIT)).c_str())); + SendMessage(m_hwnd_bottom_slot_list, CB_ADDSTRING, 0, + reinterpret_cast(GetInputDeviceName(to_underlying(XBOX_INPUT_DEVICE::MEMORY_UNIT)).c_str())); + } + else { + // The arcade joystick does not have slot ports so always disable the corresponding options + EnableWindow(m_hwnd_top_slot_list, FALSE); + EnableWindow(m_hwnd_bottom_slot_list, FALSE); + } + // construct emu device m_DeviceConfig = new EmuDevice(m_dev_type, m_hwnd_window, this); @@ -181,32 +201,16 @@ void DukeInputWindow::UpdateProfile(const std::string &name, int command) { switch (command) { - case PROFILE_LOAD: { - LoadProfile(name); - } - break; - - case PROFILE_SAVE: { - SaveProfile(name); - } - break; - - case PROFILE_DELETE: { - DeleteProfile(name); - } - break; - - case RUMBLE_CLEAR: { + case RUMBLE_CLEAR: m_rumble = std::string(); - } - break; + break; - case BUTTON_CLEAR: - case BUTTON_SWAP: { + case SLOTS_CHANGED: m_bHasChanges = true; - } - break; + break; + default: + dynamic_cast(this)->UpdateProfile(name, command); } } @@ -239,6 +243,20 @@ void DukeInputWindow::DetectOutput(int ms) } } +bool DukeInputWindow::IsProfileSaved() +{ + if (dynamic_cast(this)->IsProfileSaved()) { + int DeviceType = SendMessage(m_hwnd_top_slot_list, CB_GETITEMDATA, SendMessage(m_hwnd_top_slot_list, CB_GETCURSEL, 0, 0), 0); + g_Settings->m_input_port[m_port_num].TopSlotType = DeviceType; + DeviceType = SendMessage(m_hwnd_bottom_slot_list, CB_GETITEMDATA, SendMessage(m_hwnd_bottom_slot_list, CB_GETCURSEL, 0, 0), 0); + g_Settings->m_input_port[m_port_num].BottomSlotType = DeviceType; + + return true; + } + + return false; +} + static INT_PTR CALLBACK DlgRumbleConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK DlgXidControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) @@ -284,6 +302,13 @@ INT_PTR CALLBACK DlgXidControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wPar } break; + case IDC_DEVICE_LIST_TOP_SLOT: { + if (HIWORD(wParam) == CBN_SELCHANGE) { + g_InputWindow->UpdateProfile(std::string(), SLOTS_CHANGED); + } + } + break; + case IDC_PROFILE_NAME: { if (HIWORD(wParam) == CBN_SELCHANGE) { char name[50]; diff --git a/src/gui/controllers/DlgSBControllerConfig.cpp b/src/gui/controllers/DlgSBControllerConfig.cpp index e7a640c6c..37db7bd8c 100644 --- a/src/gui/controllers/DlgSBControllerConfig.cpp +++ b/src/gui/controllers/DlgSBControllerConfig.cpp @@ -81,34 +81,6 @@ void SbcInputWindow::ClearBindings() m_bHasChanges = true; } -void SbcInputWindow::UpdateProfile(const std::string &name, int command) -{ - switch (command) - { - case PROFILE_LOAD: { - LoadProfile(name); - } - break; - - case PROFILE_SAVE: { - SaveProfile(name); - } - break; - - case PROFILE_DELETE: { - DeleteProfile(name); - } - break; - - case BUTTON_CLEAR: - case BUTTON_SWAP: { - m_bHasChanges = true; - } - break; - - } -} - int SbcInputWindow::EnableDefaultButton() { // The SBC window does not have a default button, so we return a dummy value here diff --git a/src/gui/resource/Cxbx.rc b/src/gui/resource/Cxbx.rc index 75bb11375..e54afd15b 100644 --- a/src/gui/resource/Cxbx.rc +++ b/src/gui/resource/Cxbx.rc @@ -31,6 +31,10 @@ BEGIN BEGIN END + IDD_XID_DUKE_CFG, DIALOG + BEGIN + END + IDD_SBC_CFG, DIALOG BEGIN BOTTOMMARGIN, 269 @@ -113,7 +117,7 @@ BEGIN "Button",BS_AUTOCHECKBOX | BS_LEFTTEXT | WS_TABSTOP,23,166,139,10 END -IDD_XID_DUKE_CFG DIALOGEX 0, 0, 528, 280 +IDD_XID_DUKE_CFG DIALOGEX 0, 0, 528, 300 STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU FONT 8, "Verdana", 0, 0, 0x1 BEGIN @@ -180,8 +184,12 @@ BEGIN GROUPBOX "Rumble",IDC_RUMBLE,396,212,121,34,WS_GROUP PUSHBUTTON "",IDC_SET_MOTOR,443,224,57,14,BS_FLAT LTEXT "Motor",IDC_STATIC,412,224,26,14,SS_CENTERIMAGE - PUSHBUTTON "Default Bindings",IDC_DEFAULT,362,256,69,14,BS_FLAT - PUSHBUTTON "Clear",IDC_CLEAR,443,256,50,14,BS_FLAT + PUSHBUTTON "Default Bindings",IDC_DEFAULT,362,265,69,14,BS_FLAT + PUSHBUTTON "Clear",IDC_CLEAR,443,265,50,14,BS_FLAT + GROUPBOX "Top Slot",IDC_DEVICE_TOP_SLOT,12,254,97,35,WS_GROUP + COMBOBOX IDC_DEVICE_LIST_TOP_SLOT,21,267,79,15,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP + GROUPBOX "Bottom Slot",IDC_DEVICE_BOTTOM_SLOT,117,254,97,35,WS_GROUP + COMBOBOX IDC_DEVICE_LIST_BOTTOM_SLOT,126,267,79,15,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP END IDD_RUMBLE_CFG DIALOGEX 0, 0, 155, 35 @@ -566,6 +574,11 @@ BEGIN 0 END +IDD_XID_DUKE_CFG AFX_DIALOG_LAYOUT +BEGIN + 0 +END + ///////////////////////////////////////////////////////////////////////////// // @@ -687,7 +700,7 @@ BEGIN MENUITEM "&Clear entire Symbol Cache", ID_CACHE_CLEARHLECACHE_ALL,MFT_STRING,MFS_ENABLED MENUITEM "&Rescan title Symbol Cache", ID_CACHE_CLEARHLECACHE_CURRENT,MFT_STRING,MFS_ENABLED END - MENUITEM "Clear Cache Partitions", ID_SETTINGS_CLEAR_PARTITIONS,MFT_STRING,MFS_ENABLED + MENUITEM "Clear Cache Partitions", ID_SETTINGS_CLEAR_PARTITIONS,MFT_STRING,MFS_ENABLED MENUITEM "", -1, MFT_SEPARATOR POPUP "Experimental", 65535,MFT_STRING,MFS_ENABLED BEGIN diff --git a/src/gui/resource/ResCxbx.h b/src/gui/resource/ResCxbx.h index 727aeb028..7d121167e 100644 --- a/src/gui/resource/ResCxbx.h +++ b/src/gui/resource/ResCxbx.h @@ -1,4 +1,4 @@ -//{{NO_DEPENDENCIES}} +//{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. // Used by Cxbx.rc // @@ -94,6 +94,10 @@ #define IDC_LOG_VSHCACHE 962 #define IDC_LOG_RINP 963 #define IDC_LOG_JVS 964 +#define IDC_DEVICE_LIST_TOP_SLOT 995 +#define IDC_DEVICE_LIST_BOTTOM_SLOT 996 +#define IDC_DEVICE_TOP_SLOT 997 +#define IDC_DEVICE_BOTTOM_SLOT 998 #define IDC_SET_MOTOR 999 #define IDC_SET_X 1000 #define IDC_SET_Y 1001