diff --git a/src/common/engine/m_joy.cpp b/src/common/engine/m_joy.cpp index 28ba17e6c..1c8c58f64 100644 --- a/src/common/engine/m_joy.cpp +++ b/src/common/engine/m_joy.cpp @@ -410,10 +410,7 @@ CCMD (gamepad) if (command == "reset") { if (set) return usage(); - sticks[pad]->SetDefaultConfig(); - sticks[pad]->SetEnabled(true); - sticks[pad]->SetEnabledInBackground(sticks[pad]->AllowsEnabledInBackground()); - sticks[pad]->SetSensitivity(1); + sticks[pad]->Reset(); return; } if (command == "enabled") diff --git a/src/common/engine/m_joy.h b/src/common/engine/m_joy.h index b4bda3f20..a1a237229 100644 --- a/src/common/engine/m_joy.h +++ b/src/common/engine/m_joy.h @@ -78,6 +78,14 @@ struct IJoystickConfig virtual void SetDefaultConfig() = 0; virtual FString GetIdentifier() = 0; + + void Reset() + { + SetDefaultConfig(); + SetEnabled(true); + SetEnabledInBackground(AllowsEnabledInBackground()); + SetSensitivity(1); + } }; EXTERN_CVAR(Bool, use_joystick); diff --git a/src/common/menu/joystickmenu.cpp b/src/common/menu/joystickmenu.cpp index 662a004ae..39a58fded 100644 --- a/src/common/menu/joystickmenu.cpp +++ b/src/common/menu/joystickmenu.cpp @@ -188,6 +188,14 @@ DEFINE_ACTION_FUNCTION(IJoystickConfig, SetEnabledInBackground) } +DEFINE_ACTION_FUNCTION(IJoystickConfig, Reset) +{ + PARAM_SELF_STRUCT_PROLOGUE(IJoystickConfig); + self->Reset(); + return 0; +} + + void UpdateJoystickMenu(IJoystickConfig *selected) { DMenuDescriptor **desc = MenuDescriptors.CheckKey(NAME_JoystickOptions); diff --git a/wadsrc/static/zscript/engine/ui/menu/joystickmenu.zs b/wadsrc/static/zscript/engine/ui/menu/joystickmenu.zs index 39f5e8e38..bf03c073d 100644 --- a/wadsrc/static/zscript/engine/ui/menu/joystickmenu.zs +++ b/wadsrc/static/zscript/engine/ui/menu/joystickmenu.zs @@ -400,6 +400,44 @@ class OptionMenuJoyEnableInBackground : OptionMenuItemOptionBase } } + +class OptionMenuJoyReset : OptionMenuItemSubmenu +{ + JoystickConfig mJoy; + + OptionMenuJoyReset Init(String label, JoystickConfig joy) + { + Super.Init(label, ""); + mJoy = joy; + return self; + } + + override bool MenuEvent(int mkey, bool fromcontroller) + { + if (mkey == Menu.MKEY_MBYes) + { + Menu.MenuSound("menu/choose"); + mJoy.Reset(); + return true; + } + + return Super.MenuEvent(mkey, fromcontroller); + } + + override bool Activate() + { + String msg = "$SAFEMESSAGE"; + msg = StringTable.Localize(msg); + String actionLabel = StringTable.localize(mLabel); + + String FullString; + FullString = String.Format("%s%s%s\n\n%s", TEXTCOLOR_WHITE, actionLabel, TEXTCOLOR_NORMAL, msg); + Menu.StartMessage(FullString, 0); + return true; + } +} + + class OptionMenuItemJoyConfigMenu : OptionMenuItemSubmenu { JoystickConfig mJoy; @@ -455,6 +493,8 @@ class OptionMenuItemJoyConfigMenu : OptionMenuItemSubmenu it = new("OptionMenuSliderJoySensitivity").Init("$JOYMNU_OVRSENS", 0, 2, 0.1, 3, joy); opt.mItems.Push(it); + it = new("OptionMenuJoyReset").Init("$JOYMNU_RESETALL", joy); + opt.mItems.Push(it); it = new("OptionMenuItemStaticText").Init(" ", false); opt.mItems.Push(it); diff --git a/wadsrc/static/zscript/engine/ui/menu/menu.zs b/wadsrc/static/zscript/engine/ui/menu/menu.zs index 1119c8962..9719474ec 100644 --- a/wadsrc/static/zscript/engine/ui/menu/menu.zs +++ b/wadsrc/static/zscript/engine/ui/menu/menu.zs @@ -117,6 +117,7 @@ struct JoystickConfig native version("2.4") native bool GetEnabledInBackground(); native void SetEnabledInBackground(bool enabled); + native void Reset(); } class Menu : Object native ui version("2.4")