diff --git a/src/common/engine/m_joy.cpp b/src/common/engine/m_joy.cpp index dec49377f8..49ad103aee 100644 --- a/src/common/engine/m_joy.cpp +++ b/src/common/engine/m_joy.cpp @@ -120,6 +120,11 @@ bool M_LoadJoystickConfig(IJoystickConfig *joy) { return false; } + value = GameConfig->GetValueForKey("Enabled"); + if (value != NULL) + { + joy->SetEnabled((bool)atoi(value)); + } value = GameConfig->GetValueForKey("Sensitivity"); if (value != NULL) { @@ -176,6 +181,10 @@ void M_SaveJoystickConfig(IJoystickConfig *joy) if (GameConfig != NULL && M_SetJoystickConfigSection(joy, true, GameConfig)) { GameConfig->ClearCurrentSection(); + if (!joy->GetEnabled()) + { + GameConfig->SetValueForKey("Enabled", "0"); + } if (!joy->IsSensitivityDefault()) { mysnprintf(value, countof(value), "%g", joy->GetSensitivity()); diff --git a/src/common/engine/m_joy.h b/src/common/engine/m_joy.h index fc99379b04..650e325063 100644 --- a/src/common/engine/m_joy.h +++ b/src/common/engine/m_joy.h @@ -36,6 +36,9 @@ struct NOVTABLE IJoystickConfig virtual void SetAxisMap(int axis, EJoyAxis gameaxis) = 0; virtual void SetAxisScale(int axis, float scale) = 0; + virtual bool GetEnabled() = 0; + virtual void SetEnabled(bool enabled) = 0; + // Used by the saver to not save properties that are at their defaults. virtual bool IsSensitivityDefault() = 0; virtual bool IsAxisDeadZoneDefault(int axis) = 0; diff --git a/src/common/menu/joystickmenu.cpp b/src/common/menu/joystickmenu.cpp index 21c667d318..10408d9167 100644 --- a/src/common/menu/joystickmenu.cpp +++ b/src/common/menu/joystickmenu.cpp @@ -119,6 +119,20 @@ DEFINE_ACTION_FUNCTION(IJoystickConfig, GetNumAxes) ACTION_RETURN_INT(self->GetNumAxes()); } +DEFINE_ACTION_FUNCTION(IJoystickConfig, GetEnabled) +{ + PARAM_SELF_STRUCT_PROLOGUE(IJoystickConfig); + ACTION_RETURN_BOOL(self->GetEnabled()); +} + +DEFINE_ACTION_FUNCTION(IJoystickConfig, SetEnabled) +{ + PARAM_SELF_STRUCT_PROLOGUE(IJoystickConfig); + PARAM_BOOL(enabled); + self->SetEnabled(enabled); + return 0; +} + void UpdateJoystickMenu(IJoystickConfig *selected) { diff --git a/src/common/platform/posix/cocoa/i_joystick.cpp b/src/common/platform/posix/cocoa/i_joystick.cpp index 7333803669..a2a27eaff0 100644 --- a/src/common/platform/posix/cocoa/i_joystick.cpp +++ b/src/common/platform/posix/cocoa/i_joystick.cpp @@ -104,6 +104,9 @@ public: virtual bool IsAxisMapDefault(int axis); virtual bool IsAxisScaleDefault(int axis); + virtual bool GetEnabled(); + virtual void SetEnabled(bool enabled); + virtual void SetDefaultConfig(); virtual FString GetIdentifier(); @@ -165,6 +168,7 @@ private: TArray m_buttons; TArray m_POVs; + bool m_enabled; bool m_useAxesPolling; io_object_t m_notification; @@ -279,6 +283,7 @@ IOKitJoystick::IOKitJoystick(const io_object_t device) : m_interface(CreateDeviceInterface(device)) , m_queue(CreateDeviceQueue(m_interface)) , m_sensitivity(DEFAULT_SENSITIVITY) +, m_enabled(true) , m_useAxesPolling(true) , m_notification(0) { @@ -430,6 +435,17 @@ bool IOKitJoystick::IsAxisScaleDefault(int axis) : true; } + + +bool IOKitJoystick::GetEnabled() +{ + return m_enabled; +} +void IOKitJoystick::SetEnabled(bool enabled) +{ + m_enabled = enabled; +} + #undef IS_AXIS_VALID void IOKitJoystick::SetDefaultConfig() @@ -547,7 +563,7 @@ void IOKitJoystick::Update() if (kIOReturnSuccess == eventResult) { - if (use_joystick) + if (use_joystick && m_enabled) { ProcessAxis(event) || ProcessButton(event) || ProcessPOV(event); } @@ -557,7 +573,7 @@ void IOKitJoystick::Update() Printf(TEXTCOLOR_RED "IOHIDQueueInterface::getNextEvent() failed with code 0x%08X\n", eventResult); } - ProcessAxes(); + if(m_enabled) ProcessAxes(); } diff --git a/src/common/platform/posix/sdl/i_joystick.cpp b/src/common/platform/posix/sdl/i_joystick.cpp index 0fa33ba636..8b76f33069 100644 --- a/src/common/platform/posix/sdl/i_joystick.cpp +++ b/src/common/platform/posix/sdl/i_joystick.cpp @@ -44,7 +44,7 @@ class SDLInputJoystick: public IJoystickConfig { public: - SDLInputJoystick(int DeviceIndex) : DeviceIndex(DeviceIndex), Multiplier(1.0f) + SDLInputJoystick(int DeviceIndex) : DeviceIndex(DeviceIndex), Multiplier(1.0f) , Enabled(true) { Device = SDL_JoystickOpen(DeviceIndex); if(Device != NULL) @@ -154,6 +154,17 @@ public: Axes.Push(info); } } + + bool GetEnabled() + { + return Enabled; + } + + void SetEnabled(bool enabled) + { + Enabled = enabled; + } + FString GetIdentifier() { char id[16]; @@ -248,6 +259,7 @@ protected: SDL_Joystick *Device; float Multiplier; + bool Enabled; TArray Axes; int NumAxes; int NumHats; @@ -291,7 +303,7 @@ public: void ProcessInput() const { for(unsigned int i = 0;i < Joysticks.Size();++i) - Joysticks[i]->ProcessInput(); + if(Joysticks[i]->Enabled) Joysticks[i]->ProcessInput(); } protected: TArray Joysticks; diff --git a/src/common/platform/win32/i_dijoy.cpp b/src/common/platform/win32/i_dijoy.cpp index 11f60a35f4..c22c5492ba 100644 --- a/src/common/platform/win32/i_dijoy.cpp +++ b/src/common/platform/win32/i_dijoy.cpp @@ -180,6 +180,9 @@ public: bool IsAxisMapDefault(int axis); bool IsAxisScaleDefault(int axis); + bool GetEnabled(); + void SetEnabled(bool enabled); + void SetDefaultConfig(); FString GetIdentifier(); @@ -219,6 +222,8 @@ protected: DIOBJECTDATAFORMAT *Objects; DIDATAFORMAT DataFormat; + bool Enabled; + static BOOL CALLBACK EnumObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef); void OrderAxes(); bool ReorderAxisPair(const GUID &x, const GUID &y, int pos); @@ -297,6 +302,7 @@ FDInputJoystick::FDInputJoystick(const GUID *instance, FString &name) Instance = *instance; Name = name; Marked = false; + Enabled = true; } //=========================================================================== @@ -410,7 +416,7 @@ void FDInputJoystick::ProcessInput() { hr = Device->Acquire(); } - if (FAILED(hr)) + if (FAILED(hr) || !Enabled) { return; } @@ -984,6 +990,28 @@ bool FDInputJoystick::IsAxisScaleDefault(int axis) return true; } +//=========================================================================== +// +// FDInputJoystick :: GetEnabled +// +//=========================================================================== + +bool FDInputJoystick::GetEnabled() +{ + return Enabled; +} + +//=========================================================================== +// +// FDInputJoystick :: SetEnabled +// +//=========================================================================== + +void FDInputJoystick::SetEnabled(bool enabled) +{ + Enabled = enabled; +} + //=========================================================================== // // FDInputJoystick :: IsAxisMapDefault diff --git a/src/common/platform/win32/i_rawps2.cpp b/src/common/platform/win32/i_rawps2.cpp index f063788039..8344315809 100644 --- a/src/common/platform/win32/i_rawps2.cpp +++ b/src/common/platform/win32/i_rawps2.cpp @@ -114,6 +114,9 @@ public: bool IsAxisMapDefault(int axis); bool IsAxisScaleDefault(int axis); + bool GetEnabled(); + void SetEnabled(bool enabled); + void SetDefaultConfig(); FString GetIdentifier(); @@ -153,6 +156,7 @@ protected: bool Connected; bool Marked; bool Active; + bool Enabled; void Attached(); void Detached(); @@ -376,6 +380,7 @@ FRawPS2Controller::FRawPS2Controller(HANDLE handle, EAdapterType type, int seque ControllerNumber = controller; Sequence = sequence; DeviceID = devid; + Enabled = true; // The EMS USB2 controller provides attachment status. The others do not. Connected = (Descriptors[type].ControllerStatus < 0); @@ -849,6 +854,28 @@ bool FRawPS2Controller::IsAxisScaleDefault(int axis) return true; } +//=========================================================================== +// +// FRawPS2Controller :: GetEnabled +// +//=========================================================================== + +bool FRawPS2Controller::GetEnabled() +{ + return Enabled; +} + +//=========================================================================== +// +// FRawPS2Controller :: SetEnabled +// +//=========================================================================== + +void FRawPS2Controller::SetEnabled(bool enabled) +{ + Enabled = enabled; +} + //=========================================================================== // // FRawPS2Controller :: IsAxisMapDefault @@ -972,7 +999,7 @@ bool FRawPS2Manager::ProcessRawInput(RAWINPUT *raw, int code) { if (Devices[i]->Handle == raw->header.hDevice) { - if (Devices[i]->ProcessInput(&raw->data.hid, code)) + if (Devices[i]->Enabled && Devices[i]->ProcessInput(&raw->data.hid, code)) { return true; } diff --git a/src/common/platform/win32/i_xinput.cpp b/src/common/platform/win32/i_xinput.cpp index ba4605dd0f..d1dc4364d8 100644 --- a/src/common/platform/win32/i_xinput.cpp +++ b/src/common/platform/win32/i_xinput.cpp @@ -102,6 +102,9 @@ public: bool IsAxisMapDefault(int axis); bool IsAxisScaleDefault(int axis); + bool GetEnabled(); + void SetEnabled(bool enabled); + void SetDefaultConfig(); FString GetIdentifier(); @@ -138,6 +141,7 @@ protected: DWORD LastPacketNumber; int LastButtons; bool Connected; + bool Enabled; void Attached(); void Detached(); @@ -221,6 +225,7 @@ FXInputController::FXInputController(int index) { Index = index; Connected = false; + Enabled = true; M_LoadJoystickConfig(this); } @@ -269,7 +274,7 @@ void FXInputController::ProcessInput() { Attached(); } - if (state.dwPacketNumber == LastPacketNumber) + if (state.dwPacketNumber == LastPacketNumber || !Enabled) { // Nothing has changed since last time. return; } @@ -628,6 +633,28 @@ bool FXInputController::IsAxisScaleDefault(int axis) return true; } +//=========================================================================== +// +// FXInputController :: GetEnabled +// +//=========================================================================== + +bool FXInputController::GetEnabled() +{ + return Enabled; +} + +//=========================================================================== +// +// FXInputController :: SetEnabled +// +//=========================================================================== + +void FXInputController::SetEnabled(bool enabled) +{ + Enabled = enabled; +} + //=========================================================================== // // FXInputController :: IsAxisMapDefault diff --git a/wadsrc/static/zscript/engine/ui/menu/joystickmenu.zs b/wadsrc/static/zscript/engine/ui/menu/joystickmenu.zs index 06b412f177..206a31098c 100644 --- a/wadsrc/static/zscript/engine/ui/menu/joystickmenu.zs +++ b/wadsrc/static/zscript/engine/ui/menu/joystickmenu.zs @@ -220,6 +220,29 @@ class OptionMenuItemInverter : OptionMenuItemOptionBase // //============================================================================= + +class OptionMenuJoyEnable : OptionMenuItemOptionBase +{ + JoystickConfig mJoy; + + OptionMenuJoyEnable Init(String label, JoystickConfig joy) + { + Super.Init(label,"none","YesNo",null,0); + mJoy = joy; + return self; + } + + override int GetSelection() + { + return mJoy.GetEnabled() ? 1 : 0; + } + + override void SetSelection(int Selection) + { + mJoy.SetEnabled(Selection); + } +} + class OptionMenuItemJoyConfigMenu : OptionMenuItemSubmenu { JoystickConfig mJoy; @@ -259,6 +282,9 @@ class OptionMenuItemJoyConfigMenu : OptionMenuItemSubmenu it = new("OptionMenuItemStaticText").Init(joy.GetName(), false); it = new("OptionMenuItemStaticText").Init("", false); + it = new("OptionMenuJoyEnable").Init("$JOYMNU_JOYENABLE", joy); + opt.mItems.Push(it); + it = new("OptionMenuSliderJoySensitivity").Init("$JOYMNU_OVRSENS", 0, 2, 0.1, 3, joy); opt.mItems.Push(it); it = new("OptionMenuItemStaticText").Init(" ", false); diff --git a/wadsrc/static/zscript/engine/ui/menu/menu.zs b/wadsrc/static/zscript/engine/ui/menu/menu.zs index 1812348085..1c18770411 100644 --- a/wadsrc/static/zscript/engine/ui/menu/menu.zs +++ b/wadsrc/static/zscript/engine/ui/menu/menu.zs @@ -84,6 +84,9 @@ struct JoystickConfig native version("2.4") native int GetNumAxes(); native String GetAxisName(int axis); + native bool GetEnabled(); + native void SetEnabled(bool enabled); + } class Menu : Object native ui version("2.4")