diff --git a/src/common/Settings.cpp b/src/common/Settings.cpp index cd3082f88..2fc41acef 100644 --- a/src/common/Settings.cpp +++ b/src/common/Settings.cpp @@ -467,25 +467,24 @@ bool Settings::LoadConfig() // ==== Input Port Begin ==== for (int port_num = 0; port_num < 4; port_num++) { - m_input_port[port_num].Type = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID); - m_input_port[port_num].TopSlotType = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID); - m_input_port[port_num].BottomSlotType = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID); + for (int slot = 0; slot < XBOX_CTRL_NUM_SLOTS; ++slot) { + m_input_port[port_num].Type = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID); + m_input_port[port_num].SlotType[slot] = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID); - std::string current_section = std::string(section_input_port) + std::to_string(port_num); - int ret = m_si.GetLongValue(current_section.c_str(), sect_input_port.type, -2); - if (ret == -2) { - continue; + std::string current_section = std::string(section_input_port) + std::to_string(port_num); + int ret = m_si.GetLongValue(current_section.c_str(), sect_input_port.type, -2); + if (ret == -2) { + continue; + } + m_input_port[port_num].Type = ret; + m_input_port[port_num].DeviceName = m_si.GetValue(current_section.c_str(), sect_input_port.device); + m_input_port[port_num].ProfileName = TrimQuoteFromString(m_si.GetValue(current_section.c_str(), sect_input_port.config)); + ret = m_si.GetLongValue(current_section.c_str(), slot == 0 ? sect_input_port.top_slot : sect_input_port.bottom_slot, -2); + if (ret == -2) { + continue; + } + m_input_port[port_num].SlotType[slot] = ret; } - m_input_port[port_num].Type = ret; - m_input_port[port_num].DeviceName = m_si.GetValue(current_section.c_str(), sect_input_port.device); - m_input_port[port_num].ProfileName = TrimQuoteFromString(m_si.GetValue(current_section.c_str(), sect_input_port.config)); - ret = m_si.GetLongValue(current_section.c_str(), sect_input_port.top_slot, -2); - if (ret == -2) { - continue; - } - m_input_port[port_num].TopSlotType = ret; - m_input_port[port_num].BottomSlotType = m_si.GetLongValue(current_section.c_str(), sect_input_port.bottom_slot, -2); - assert(m_input_port[port_num].BottomSlotType != -2); } // ==== Input Port End ============== @@ -656,8 +655,8 @@ bool Settings::Save(std::string file_path) m_si.SetLongValue(current_section.c_str(), sect_input_port.type, m_input_port[port_num].Type, nullptr, false, true); m_si.SetValue(current_section.c_str(), sect_input_port.device, m_input_port[port_num].DeviceName.c_str(), nullptr, true); m_si.SetValue(current_section.c_str(), sect_input_port.config, quoted_prf_str.c_str(), nullptr, true); - m_si.SetLongValue(current_section.c_str(), sect_input_port.top_slot, m_input_port[port_num].TopSlotType, nullptr, false, true); - m_si.SetLongValue(current_section.c_str(), sect_input_port.bottom_slot, m_input_port[port_num].BottomSlotType, nullptr, false, true); + m_si.SetLongValue(current_section.c_str(), sect_input_port.top_slot, m_input_port[port_num].SlotType[SLOT_TOP], nullptr, false, true); + m_si.SetLongValue(current_section.c_str(), sect_input_port.bottom_slot, m_input_port[port_num].SlotType[SLOT_BOTTOM], nullptr, false, true); } // ==== Input Port End ============== @@ -783,8 +782,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, SLOT_TOP); - g_EmuShared->SetInputSlotTypeSettings(&m_input_port[i].BottomSlotType, i, SLOT_BOTTOM); + g_EmuShared->SetInputSlotTypeSettings(&m_input_port[i].SlotType[SLOT_TOP], i, SLOT_TOP); + g_EmuShared->SetInputSlotTypeSettings(&m_input_port[i].SlotType[SLOT_BOTTOM], i, 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/Settings.hpp b/src/common/Settings.hpp index 0d3da1b73..e11f4c829 100644 --- a/src/common/Settings.hpp +++ b/src/common/Settings.hpp @@ -147,10 +147,9 @@ public: struct s_input_port { int Type; + int SlotType[2]; std::string DeviceName; std::string ProfileName; - int TopSlotType; - int BottomSlotType; }; std::array m_input_port; diff --git a/src/common/input/InputManager.cpp b/src/common/input/InputManager.cpp index 6bde93123..9c42093bb 100644 --- a/src/common/input/InputManager.cpp +++ b/src/common/input/InputManager.cpp @@ -297,16 +297,12 @@ void InputDeviceManager::ConnectDevice(DeviceState *dev, DeviceState *upstream, { ConstructHleInputDevice(dev, upstream, type, port); BindHostDevice(type, port); - EmuLog(LOG_LEVEL::INFO, "Attached device %s to port %d", GetInputDeviceName(type).c_str(), - PortUserFormat(port).c_str()); } void InputDeviceManager::DisconnectDevice(DeviceState *dev, std::string_view port, bool ack) { if (ack) { - int type = to_underlying(dev->type); DestructHleInputDevice(dev); - EmuLog(LOG_LEVEL::INFO, "Detached device %s from port %d", GetInputDeviceName(type).c_str(), PortUserFormat(port).c_str()); } else { dev->bPendingRemoval = true; diff --git a/src/common/input/InputWindow.cpp b/src/common/input/InputWindow.cpp index 12d617037..2caec9292 100644 --- a/src/common/input/InputWindow.cpp +++ b/src/common/input/InputWindow.cpp @@ -260,9 +260,6 @@ bool InputWindow::SaveProfile(const std::string& name) g_Settings->m_input_port[m_port_num].DeviceName = profile.DeviceName; g_Settings->m_input_port[m_port_num].ProfileName = profile.ProfileName; g_Settings->m_input_profiles[m_dev_type].push_back(std::move(profile)); - if (auto duke_wnd = dynamic_cast(this)) { - duke_wnd->SaveSlotConfig(); - } m_bHasChanges = false; return true; diff --git a/src/common/input/InputWindow.h b/src/common/input/InputWindow.h index b0fcbdbff..0534dd349 100644 --- a/src/common/input/InputWindow.h +++ b/src/common/input/InputWindow.h @@ -40,7 +40,6 @@ #define RUMBLE_CLEAR 7 #define BUTTON_CLEAR 8 #define BUTTON_SWAP 9 -#define SLOTS_CHANGED 10 #define XINPUT_DEFAULT 0 #define DINPUT_DEFAULT 1 @@ -75,6 +74,7 @@ protected: void OverwriteProfile(const std::string& name); void LoadDefaultProfile(); virtual int EnableDefaultButton() = 0; + virtual void SaveSlotConfig() = 0; // xbox device under configuration EmuDevice* m_DeviceConfig; @@ -107,7 +107,7 @@ public: void BindDefault(); void ClearBindings() override; void UpdateProfile(const std::string &name, int command) override; - void SaveSlotConfig(); + void SaveSlotConfig() override; private: @@ -131,6 +131,7 @@ class SbcInputWindow : public InputWindow public: void Initialize(HWND hwnd, int port_num, int dev_type) override; void ClearBindings() override; + void SaveSlotConfig() override; private: diff --git a/src/core/hle/XAPI/Xapi.cpp b/src/core/hle/XAPI/Xapi.cpp index 7949b86b1..952cddb39 100644 --- a/src/core/hle/XAPI/Xapi.cpp +++ b/src/core/hle/XAPI/Xapi.cpp @@ -277,6 +277,8 @@ void ConstructHleInputDevice(DeviceState *dev, DeviceState *upstream, int type, UpdateXppState(dev, static_cast(type), port); g_bIsDevicesEmulating = false; + + EmuLogEx(CXBXR_MODULE::INPSYS, LOG_LEVEL::INFO, "Attached device %s to port %s", GetInputDeviceName(type).c_str(), PortUserFormat(port).c_str()); } void DestructHleInputDevice(DeviceState *dev) @@ -343,6 +345,8 @@ void DestructHleInputDevice(DeviceState *dev) dev->upstream = nullptr; g_bIsDevicesEmulating = false; + + EmuLogEx(CXBXR_MODULE::INPSYS, LOG_LEVEL::INFO, "Detached device %s from port %s", GetInputDeviceName(to_underlying(type)).c_str(), PortUserFormat(port).c_str()); } void SetupXboxDeviceTypes() diff --git a/src/gui/DlgInputConfig.cpp b/src/gui/DlgInputConfig.cpp index 3530a9c96..69b0fa319 100644 --- a/src/gui/DlgInputConfig.cpp +++ b/src/gui/DlgInputConfig.cpp @@ -51,8 +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, SLOT_TOP); - g_EmuShared->SetInputSlotTypeSettings(&g_Settings->m_input_port[port_num].BottomSlotType, port_num, SLOT_BOTTOM); + g_EmuShared->SetInputSlotTypeSettings(&g_Settings->m_input_port[port_num].SlotType[SLOT_TOP], port_num, SLOT_TOP); + g_EmuShared->SetInputSlotTypeSettings(&g_Settings->m_input_port[port_num].SlotType[SLOT_BOTTOM], port_num, SLOT_BOTTOM); if (dev_type != to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID)) { std::string dev_name = g_Settings->m_input_port[port_num].DeviceName; @@ -165,8 +165,8 @@ INT_PTR CALLBACK DlgInputConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPAR DeviceType != to_underlying(XBOX_INPUT_DEVICE::MS_CONTROLLER_S)) { // Forcefully set the child devices to none. This will happen if the user sets MUs in the controller dialog but // then they set the parent device to a device that cannot support them in the input dialog - g_Settings->m_input_port[port].TopSlotType = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID); - g_Settings->m_input_port[port].BottomSlotType = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID); + g_Settings->m_input_port[port].SlotType[SLOT_TOP] = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID); + g_Settings->m_input_port[port].SlotType[SLOT_BOTTOM] = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID); } SyncInputSettings(port, DeviceType, false); } diff --git a/src/gui/controllers/DlgDukeControllerConfig.cpp b/src/gui/controllers/DlgDukeControllerConfig.cpp index fefaba7a6..5f66839e2 100644 --- a/src/gui/controllers/DlgDukeControllerConfig.cpp +++ b/src/gui/controllers/DlgDukeControllerConfig.cpp @@ -88,31 +88,24 @@ void DukeInputWindow::Initialize(HWND hwnd, int port_num, int dev_type) if (m_dev_type == to_underlying(XBOX_INPUT_DEVICE::ARCADE_STICK)) { // The arcade joystick does not have slot ports so we always disable the corresponding options - LRESULT index_top = SendMessage(m_hwnd_slot_list[SLOT_TOP], CB_ADDSTRING, 0, - reinterpret_cast(GetInputDeviceName(to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID)).c_str())); - LRESULT index_bottom = SendMessage(m_hwnd_slot_list[SLOT_BOTTOM], CB_ADDSTRING, 0, - reinterpret_cast(GetInputDeviceName(to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID)).c_str())); - SendMessage(m_hwnd_slot_list[SLOT_TOP], CB_SETITEMDATA, index_top, to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID)); - SendMessage(m_hwnd_slot_list[SLOT_BOTTOM], CB_SETITEMDATA, index_bottom, to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID)); - SendMessage(m_hwnd_slot_list[SLOT_TOP], CB_SETCURSEL, index_top, 0); - SendMessage(m_hwnd_slot_list[SLOT_BOTTOM], CB_SETCURSEL, index_bottom, 0); - EnableWindow(m_hwnd_slot_list[SLOT_TOP], FALSE); - EnableWindow(m_hwnd_slot_list[SLOT_BOTTOM], FALSE); + for (unsigned slot = 0; slot < XBOX_CTRL_NUM_SLOTS; ++slot) { + LRESULT index = SendMessage(m_hwnd_slot_list[slot], CB_ADDSTRING, 0, + reinterpret_cast(GetInputDeviceName(to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID)).c_str())); + SendMessage(m_hwnd_slot_list[slot], CB_SETITEMDATA, index, to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID)); + SendMessage(m_hwnd_slot_list[slot], CB_SETCURSEL, index, 0); + EnableWindow(m_hwnd_slot_list[slot], FALSE); + } } else { // Set up the device types we support in the slot ports for (auto slot_type : slot_support_list) { - LRESULT index_top = SendMessage(m_hwnd_slot_list[SLOT_TOP], CB_ADDSTRING, 0, - reinterpret_cast(GetInputDeviceName(to_underlying(slot_type)).c_str())); - LRESULT index_bottom = SendMessage(m_hwnd_slot_list[SLOT_BOTTOM], CB_ADDSTRING, 0, - reinterpret_cast(GetInputDeviceName(to_underlying(slot_type)).c_str())); - SendMessage(m_hwnd_slot_list[SLOT_TOP], CB_SETITEMDATA, index_top, to_underlying(slot_type)); - SendMessage(m_hwnd_slot_list[SLOT_BOTTOM], CB_SETITEMDATA, index_bottom, to_underlying(slot_type)); - if (g_Settings->m_input_port[m_port_num].TopSlotType == to_underlying(slot_type)) { - SendMessage(m_hwnd_slot_list[SLOT_TOP], CB_SETCURSEL, index_top, 0); - } - if (g_Settings->m_input_port[m_port_num].BottomSlotType == to_underlying(slot_type)) { - SendMessage(m_hwnd_slot_list[SLOT_BOTTOM], CB_SETCURSEL, index_bottom, 0); + for (unsigned slot = 0; slot < XBOX_CTRL_NUM_SLOTS; ++slot) { + LRESULT index = SendMessage(m_hwnd_slot_list[slot], CB_ADDSTRING, 0, + reinterpret_cast(GetInputDeviceName(to_underlying(slot_type)).c_str())); + SendMessage(m_hwnd_slot_list[slot], CB_SETITEMDATA, index, to_underlying(slot_type)); + if (g_Settings->m_input_port[m_port_num].SlotType[slot] == to_underlying(slot_type)) { + SendMessage(m_hwnd_slot_list[slot], CB_SETCURSEL, index, 0); + } } } } @@ -218,10 +211,6 @@ void DukeInputWindow::UpdateProfile(const std::string &name, int command) m_rumble = std::string(); break; - case SLOTS_CHANGED: - m_bHasChanges = true; - break; - default: InputWindow::UpdateProfile(name, command); } @@ -258,10 +247,10 @@ void DukeInputWindow::DetectOutput(int ms) void DukeInputWindow::SaveSlotConfig() { - int DeviceType = SendMessage(m_hwnd_slot_list[SLOT_TOP], CB_GETITEMDATA, SendMessage(m_hwnd_slot_list[SLOT_TOP], CB_GETCURSEL, 0, 0), 0); - g_Settings->m_input_port[m_port_num].TopSlotType = DeviceType; - DeviceType = SendMessage(m_hwnd_slot_list[SLOT_BOTTOM], CB_GETITEMDATA, SendMessage(m_hwnd_slot_list[SLOT_BOTTOM], CB_GETCURSEL, 0, 0), 0); - g_Settings->m_input_port[m_port_num].BottomSlotType = DeviceType; + for (unsigned slot = 0; slot < XBOX_CTRL_NUM_SLOTS; ++slot) { + g_Settings->m_input_port[m_port_num].SlotType[slot] = SendMessage(m_hwnd_slot_list[slot], CB_GETITEMDATA, + SendMessage(m_hwnd_slot_list[slot], CB_GETCURSEL, 0, 0), 0); + } } static INT_PTR CALLBACK DlgRumbleConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); @@ -291,6 +280,7 @@ INT_PTR CALLBACK DlgXidControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wPar case WM_CLOSE: { if (g_InputWindow->IsProfileSaved()) { + g_InputWindow->SaveSlotConfig(); delete g_InputWindow; g_InputWindow = nullptr; EndDialog(hWndDlg, wParam); @@ -309,14 +299,6 @@ INT_PTR CALLBACK DlgXidControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wPar } break; - case IDC_DEVICE_LIST_TOP_SLOT: - case IDC_DEVICE_LIST_BOTTOM_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 4627c879e..7a83dea9a 100644 --- a/src/gui/controllers/DlgSBControllerConfig.cpp +++ b/src/gui/controllers/DlgSBControllerConfig.cpp @@ -87,6 +87,13 @@ int SbcInputWindow::EnableDefaultButton() return -1; } +void SbcInputWindow::SaveSlotConfig() +{ + for (unsigned slot = 0; slot < XBOX_CTRL_NUM_SLOTS; ++slot) { + g_Settings->m_input_port[m_port_num].SlotType[slot] = to_underlying(XBOX_INPUT_DEVICE::DEVICE_INVALID); + } +} + INT_PTR CALLBACK DlgSBControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) @@ -110,6 +117,7 @@ INT_PTR CALLBACK DlgSBControllerConfigProc(HWND hWndDlg, UINT uMsg, WPARAM wPara case WM_CLOSE: { if (g_InputWindow->IsProfileSaved()) { + g_InputWindow->SaveSlotConfig(); delete g_InputWindow; g_InputWindow = nullptr; EndDialog(hWndDlg, wParam);