From dc732cc39f6ba362c87c17aebeb9eacb4c7eab02 Mon Sep 17 00:00:00 2001 From: moonleay Date: Thu, 13 Jun 2024 18:52:04 +0200 Subject: [PATCH] feat: add ESC resets mode setting --- .../client/config/GimbalClientConfig.kt | 1 + .../gimbal/client/editor/ClientEditor.kt | 4 ++- .../gimbal/client/screen/GimbalEditHudGui.kt | 1 + .../gimbal/client/screen/GimbalSettingsGui.kt | 28 ++++++++++++++++++- .../gimbal/constants/TranslationKeys.kt | 1 + .../gimbal/datagen/EnUsLanguageProvider.kt | 1 + .../gimbal/mixin/NormalModeMixin.java | 2 +- 7 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/moonleay/gimbal/client/config/GimbalClientConfig.kt b/src/main/java/net/moonleay/gimbal/client/config/GimbalClientConfig.kt index f84b5f3..5fd641c 100644 --- a/src/main/java/net/moonleay/gimbal/client/config/GimbalClientConfig.kt +++ b/src/main/java/net/moonleay/gimbal/client/config/GimbalClientConfig.kt @@ -27,5 +27,6 @@ data class GimbalClientConfig( val guiSettings: GimbalGuiSettings = GimbalGuiSettings(), val toastSettings: ToastSettings = ToastSettings.ALL, val playerFlySpeed: Int = 100, + val shouldEscResetMode: Boolean = true, val defaultMode: Mode = Mode.NORMAL ) diff --git a/src/main/java/net/moonleay/gimbal/client/editor/ClientEditor.kt b/src/main/java/net/moonleay/gimbal/client/editor/ClientEditor.kt index 00c908e..42d54c4 100644 --- a/src/main/java/net/moonleay/gimbal/client/editor/ClientEditor.kt +++ b/src/main/java/net/moonleay/gimbal/client/editor/ClientEditor.kt @@ -55,7 +55,9 @@ object ClientEditor { this.CURRENT_MODE = config.defaultMode return } - this.setMode(config.defaultMode) + if (!config.shouldEscResetMode) return + this.CURRENT_MODE = config.defaultMode + onUpdated() } fun onConnectedToNewWorld() { diff --git a/src/main/java/net/moonleay/gimbal/client/screen/GimbalEditHudGui.kt b/src/main/java/net/moonleay/gimbal/client/screen/GimbalEditHudGui.kt index 3e84af2..0155e35 100644 --- a/src/main/java/net/moonleay/gimbal/client/screen/GimbalEditHudGui.kt +++ b/src/main/java/net/moonleay/gimbal/client/screen/GimbalEditHudGui.kt @@ -88,6 +88,7 @@ class GimbalEditHudGui(private val parent: Screen, private val cfg: ClientConfig ), toastSettings = oldConf.toastSettings, playerFlySpeed = oldConf.playerFlySpeed, + shouldEscResetMode = oldConf.shouldEscResetMode, defaultMode = oldConf.defaultMode ) diff --git a/src/main/java/net/moonleay/gimbal/client/screen/GimbalSettingsGui.kt b/src/main/java/net/moonleay/gimbal/client/screen/GimbalSettingsGui.kt index f5e169f..4e11df4 100644 --- a/src/main/java/net/moonleay/gimbal/client/screen/GimbalSettingsGui.kt +++ b/src/main/java/net/moonleay/gimbal/client/screen/GimbalSettingsGui.kt @@ -74,6 +74,7 @@ class GimbalSettingsGui(private val parent: Screen, private val cfg: ClientConfi guiSettings = newGui, toastSettings = cfg.config.toastSettings, playerFlySpeed = cfg.config.playerFlySpeed, + shouldEscResetMode = cfg.config.shouldEscResetMode, defaultMode = cfg.config.defaultMode ) cfg.updateConfig(newConf) @@ -134,6 +135,7 @@ class GimbalSettingsGui(private val parent: Screen, private val cfg: ClientConfi ), toastSettings = oldConfig.toastSettings, playerFlySpeed = oldConfig.playerFlySpeed, + shouldEscResetMode = oldConfig.shouldEscResetMode, defaultMode = oldConfig.defaultMode ) cfg.updateConfig(newConfig) @@ -179,6 +181,7 @@ class GimbalSettingsGui(private val parent: Screen, private val cfg: ClientConfi guiSettings = oldConfig.guiSettings, toastSettings = this.toastSettings, playerFlySpeed = oldConfig.playerFlySpeed, + shouldEscResetMode = oldConfig.shouldEscResetMode, defaultMode = oldConfig.defaultMode ) cfg.updateConfig(newConfig) @@ -206,11 +209,33 @@ class GimbalSettingsGui(private val parent: Screen, private val cfg: ClientConfi guiSettings = oldConfig.guiSettings, toastSettings = this.toastSettings, playerFlySpeed = this.playerFlySpeed, + shouldEscResetMode = oldConfig.shouldEscResetMode, defaultMode = oldConfig.defaultMode ) cfg.updateConfig(newConfig) }) + this.addDrawableChild(CyclingButtonWidget.onOffBuilder() + .initially(cfg.config.shouldEscResetMode) + .build( + this.width / 2 - 155, + this.height / 6 + 24 * 3, + 150, + 20, + Text.translatable(TranslationKeys.Gui.Config.SHOULD_ESC_RESET_MODE) + ) { _: CyclingButtonWidget?, isEnabled: Boolean? -> + val newConf = GimbalClientConfig( + guiSettings = cfg.config.guiSettings, + toastSettings = cfg.config.toastSettings, + playerFlySpeed = cfg.config.playerFlySpeed, + shouldEscResetMode = isEnabled?: true, + defaultMode = cfg.config.defaultMode + ) + cfg.updateConfig(newConf) + }) + + + this.addDrawableChild>( CyclingButtonWidget.builder { value: Mode? -> if (value == null) { @@ -222,7 +247,7 @@ class GimbalSettingsGui(private val parent: Screen, private val cfg: ClientConfi .initially(this.defaultMode) .build( this.width / 2 - 155 + 160, - this.height / 6 + 24 * 2, + this.height / 6 + 24 * 3, 150, 20, Text.translatable(TranslationKeys.Gui.Config.DEFAULT_MODE) @@ -240,6 +265,7 @@ class GimbalSettingsGui(private val parent: Screen, private val cfg: ClientConfi guiSettings = oldConfig.guiSettings, toastSettings = oldConfig.toastSettings, playerFlySpeed = oldConfig.playerFlySpeed, + shouldEscResetMode = oldConfig.shouldEscResetMode, defaultMode = this.defaultMode ) cfg.updateConfig(newConfig) diff --git a/src/main/java/net/moonleay/gimbal/constants/TranslationKeys.kt b/src/main/java/net/moonleay/gimbal/constants/TranslationKeys.kt index 5aab860..0db8509 100644 --- a/src/main/java/net/moonleay/gimbal/constants/TranslationKeys.kt +++ b/src/main/java/net/moonleay/gimbal/constants/TranslationKeys.kt @@ -32,6 +32,7 @@ object TranslationKeys { const val GENERIC_DISABLED = "${BASE}disabled" const val PLAYER_FLY_SPEED = "${BASE}flySpeed" + const val SHOULD_ESC_RESET_MODE = "${BASE}shouldESCResetMode" const val DEFAULT_MODE = "${BASE}defaultMode" object Hud { diff --git a/src/main/java/net/moonleay/gimbal/datagen/EnUsLanguageProvider.kt b/src/main/java/net/moonleay/gimbal/datagen/EnUsLanguageProvider.kt index 2dc5d6b..00279a1 100644 --- a/src/main/java/net/moonleay/gimbal/datagen/EnUsLanguageProvider.kt +++ b/src/main/java/net/moonleay/gimbal/datagen/EnUsLanguageProvider.kt @@ -56,6 +56,7 @@ class EnUsLanguageProvider(dataGenerator: FabricDataGenerator?) : // Gimbal Generic Settings translationBuilder.add(TranslationKeys.Gui.Config.PLAYER_FLY_SPEED, "Fly Speed") + translationBuilder.add(TranslationKeys.Gui.Config.SHOULD_ESC_RESET_MODE, "ESC Resets Mode") translationBuilder.add(TranslationKeys.Gui.Config.DEFAULT_MODE, "Default Mode") // Gimbal Generic Gui diff --git a/src/main/java/net/moonleay/gimbal/mixin/NormalModeMixin.java b/src/main/java/net/moonleay/gimbal/mixin/NormalModeMixin.java index 023efa8..d8f769a 100644 --- a/src/main/java/net/moonleay/gimbal/mixin/NormalModeMixin.java +++ b/src/main/java/net/moonleay/gimbal/mixin/NormalModeMixin.java @@ -44,7 +44,7 @@ public class NormalModeMixin { @Inject(method = "openPauseMenu", at = @At("HEAD"), cancellable = true) private void setDefaultMode(boolean pause, CallbackInfo ci) { - if (ClientEditor.INSTANCE.isInNonDefaultMode() && ClientEditor.INSTANCE.isAllowed()) { + if (ClientMain.CONFIG.getConfig().getShouldEscResetMode() && ClientEditor.INSTANCE.isInNonDefaultMode() && ClientEditor.INSTANCE.isAllowed()) { assert this.player != null; if (this.player.isCreative()) { // Set the editor mode to normal