diff --git a/src/common/engine/m_joy.cpp b/src/common/engine/m_joy.cpp index a2ab71103c..1e4b2f3e0e 100644 --- a/src/common/engine/m_joy.cpp +++ b/src/common/engine/m_joy.cpp @@ -120,16 +120,30 @@ bool M_LoadJoystickConfig(IJoystickConfig *joy) { return false; } + + assert(GameConfig); + value = GameConfig->GetValueForKey("Enabled"); - if (value != NULL) + if (value) { joy->SetEnabled((bool)atoi(value)); } + + if(joy->AllowsEnabledInBackground()) + { + value = GameConfig->GetValueForKey("EnabledInBackground"); + if (value) + { + joy->SetEnabledInBackground((bool)atoi(value)); + } + } + value = GameConfig->GetValueForKey("Sensitivity"); - if (value != NULL) + if (value) { joy->SetSensitivity((float)atof(value)); } + numaxes = joy->GetNumAxes(); for (int i = 0; i < numaxes; ++i) { @@ -137,21 +151,21 @@ bool M_LoadJoystickConfig(IJoystickConfig *joy) mysnprintf(key + axislen, countof(key) - axislen, "deadzone"); value = GameConfig->GetValueForKey(key); - if (value != NULL) + if (value) { joy->SetAxisDeadZone(i, (float)atof(value)); } mysnprintf(key + axislen, countof(key) - axislen, "scale"); value = GameConfig->GetValueForKey(key); - if (value != NULL) + if (value) { joy->SetAxisScale(i, (float)atof(value)); } mysnprintf(key + axislen, countof(key) - axislen, "map"); value = GameConfig->GetValueForKey(key); - if (value != NULL) + if (value) { EJoyAxis gameaxis = (EJoyAxis)atoi(value); if (gameaxis < JOYAXIS_None || gameaxis >= NUM_JOYAXIS) @@ -185,6 +199,12 @@ void M_SaveJoystickConfig(IJoystickConfig *joy) { GameConfig->SetValueForKey("Enabled", "0"); } + + if (!joy->AllowsEnabledInBackground() && joy->GetEnabledInBackground()) + { + GameConfig->SetValueForKey("EnabledInBackground", "1"); + } + 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 088d5bd6d3..e8d9d3b137 100644 --- a/src/common/engine/m_joy.h +++ b/src/common/engine/m_joy.h @@ -39,6 +39,10 @@ struct IJoystickConfig virtual bool GetEnabled() = 0; virtual void SetEnabled(bool enabled) = 0; + virtual bool AllowsEnabledInBackground() = 0; + virtual bool GetEnabledInBackground() = 0; + virtual void SetEnabledInBackground(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 ae152b5f0e..3d3e881b16 100644 --- a/src/common/menu/joystickmenu.cpp +++ b/src/common/menu/joystickmenu.cpp @@ -133,6 +133,26 @@ DEFINE_ACTION_FUNCTION(IJoystickConfig, SetEnabled) return 0; } +DEFINE_ACTION_FUNCTION(IJoystickConfig, AllowsEnabledInBackground) +{ + PARAM_SELF_STRUCT_PROLOGUE(IJoystickConfig); + ACTION_RETURN_BOOL(self->AllowsEnabledInBackground()); +} + +DEFINE_ACTION_FUNCTION(IJoystickConfig, GetEnabledInBackground) +{ + PARAM_SELF_STRUCT_PROLOGUE(IJoystickConfig); + ACTION_RETURN_BOOL(self->GetEnabledInBackground()); +} + +DEFINE_ACTION_FUNCTION(IJoystickConfig, SetEnabledInBackground) +{ + PARAM_SELF_STRUCT_PROLOGUE(IJoystickConfig); + PARAM_BOOL(enabled); + self->SetEnabledInBackground(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 a2a27eaff0..44d1fb961b 100644 --- a/src/common/platform/posix/cocoa/i_joystick.cpp +++ b/src/common/platform/posix/cocoa/i_joystick.cpp @@ -107,6 +107,10 @@ public: virtual bool GetEnabled(); virtual void SetEnabled(bool enabled); + bool AllowsEnabledInBackground() { return false; } + bool GetEnabledInBackground() { return false; } + void SetEnabledInBackground(bool enabled) {} + virtual void SetDefaultConfig(); virtual FString GetIdentifier(); diff --git a/src/common/platform/posix/sdl/i_joystick.cpp b/src/common/platform/posix/sdl/i_joystick.cpp index a7eb59568b..42837ecba6 100644 --- a/src/common/platform/posix/sdl/i_joystick.cpp +++ b/src/common/platform/posix/sdl/i_joystick.cpp @@ -167,6 +167,10 @@ public: Enabled = enabled; } + bool AllowsEnabledInBackground() { return false; } + bool GetEnabledInBackground() { return false; } + void SetEnabledInBackground(bool enabled) {} + FString GetIdentifier() { char id[16]; diff --git a/src/common/platform/win32/i_dijoy.cpp b/src/common/platform/win32/i_dijoy.cpp index 492cbda148..33c4574c97 100644 --- a/src/common/platform/win32/i_dijoy.cpp +++ b/src/common/platform/win32/i_dijoy.cpp @@ -183,6 +183,10 @@ public: bool GetEnabled(); void SetEnabled(bool enabled); + bool AllowsEnabledInBackground() { return false; } + bool GetEnabledInBackground() { return false; } + void SetEnabledInBackground(bool enabled) {} + void SetDefaultConfig(); FString GetIdentifier(); diff --git a/src/common/platform/win32/i_rawps2.cpp b/src/common/platform/win32/i_rawps2.cpp index d406d61ea8..2f89739bd7 100644 --- a/src/common/platform/win32/i_rawps2.cpp +++ b/src/common/platform/win32/i_rawps2.cpp @@ -117,6 +117,10 @@ public: bool GetEnabled(); void SetEnabled(bool enabled); + bool AllowsEnabledInBackground() { return false; } + bool GetEnabledInBackground() { return false; } + void SetEnabledInBackground(bool enabled) {} + void SetDefaultConfig(); FString GetIdentifier(); diff --git a/src/common/platform/win32/i_xinput.cpp b/src/common/platform/win32/i_xinput.cpp index d1dc4364d8..0f3c192378 100644 --- a/src/common/platform/win32/i_xinput.cpp +++ b/src/common/platform/win32/i_xinput.cpp @@ -65,6 +65,8 @@ #endif #endif +extern bool AppActive; + // TYPES ------------------------------------------------------------------- typedef DWORD (WINAPI *XInputGetStateType)(DWORD index, XINPUT_STATE *state); @@ -105,6 +107,10 @@ public: bool GetEnabled(); void SetEnabled(bool enabled); + bool AllowsEnabledInBackground() { return true; } + bool GetEnabledInBackground() { return EnabledInBackground; } + void SetEnabledInBackground(bool enabled) { EnabledInBackground = enabled; } + void SetDefaultConfig(); FString GetIdentifier(); @@ -142,6 +148,7 @@ protected: int LastButtons; bool Connected; bool Enabled; + bool EnabledInBackground; void Attached(); void Detached(); @@ -744,7 +751,10 @@ void FXInputManager::ProcessInput() { for (int i = 0; i < XUSER_MAX_COUNT; ++i) { - Devices[i]->ProcessInput(); + if(AppActive || Devices[i]->GetEnabledInBackground()) + { + Devices[i]->ProcessInput(); + } } } diff --git a/wadsrc/static/zscript/engine/ui/menu/joystickmenu.zs b/wadsrc/static/zscript/engine/ui/menu/joystickmenu.zs index 206a31098c..02669c1a3a 100644 --- a/wadsrc/static/zscript/engine/ui/menu/joystickmenu.zs +++ b/wadsrc/static/zscript/engine/ui/menu/joystickmenu.zs @@ -243,6 +243,29 @@ class OptionMenuJoyEnable : OptionMenuItemOptionBase } } + +class OptionMenuJoyEnableInBackground : OptionMenuItemOptionBase +{ + JoystickConfig mJoy; + + OptionMenuJoyEnableInBackground Init(String label, JoystickConfig joy) + { + Super.Init(label,"none","YesNo",null,0); + mJoy = joy; + return self; + } + + override int GetSelection() + { + return mJoy.GetEnabledInBackground() ? 1 : 0; + } + + override void SetSelection(int Selection) + { + mJoy.SetEnabledInBackground(Selection); + } +} + class OptionMenuItemJoyConfigMenu : OptionMenuItemSubmenu { JoystickConfig mJoy; @@ -279,12 +302,23 @@ class OptionMenuItemJoyConfigMenu : OptionMenuItemSubmenu } else { + /* it = new("OptionMenuItemStaticText").Init(joy.GetName(), false); + opt.mItems.Push(it); + it = new("OptionMenuItemStaticText").Init("", false); + opt.mItems.Push(it); + */ it = new("OptionMenuJoyEnable").Init("$JOYMNU_JOYENABLE", joy); opt.mItems.Push(it); + if(joy.AllowsEnabledInBackground()) + { + it = new("OptionMenuJoyEnableInBackground").Init("$JOYMNU_JOYENABLEINBACKGROUND", 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 154eee82a7..7a0ef20368 100644 --- a/wadsrc/static/zscript/engine/ui/menu/menu.zs +++ b/wadsrc/static/zscript/engine/ui/menu/menu.zs @@ -87,6 +87,10 @@ struct JoystickConfig native version("2.4") native bool GetEnabled(); native void SetEnabled(bool enabled); + native bool AllowsEnabledInBackground(); + native bool GetEnabledInBackground(); + native void SetEnabledInBackground(bool enabled); + } class Menu : Object native ui version("2.4")