From 675bceff18520c40b220d7b13a8032e4405bd21b Mon Sep 17 00:00:00 2001 From: isXander Date: Mon, 30 Oct 2023 19:31:59 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20Add=20a=20reset=20all=20binds=20but?= =?UTF-8?q?ton?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/bind/ControllerBinding.java | 1 + .../bindings/ControllerBindingImpl.java | 9 ++-- .../screen/ControllerConfigScreenFactory.java | 47 ++++++++++++------- .../assets/controlify/lang/en_us.json | 2 + 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/main/java/dev/isxander/controlify/api/bind/ControllerBinding.java b/src/main/java/dev/isxander/controlify/api/bind/ControllerBinding.java index ec165a3..b195304 100644 --- a/src/main/java/dev/isxander/controlify/api/bind/ControllerBinding.java +++ b/src/main/java/dev/isxander/controlify/api/bind/ControllerBinding.java @@ -61,6 +61,7 @@ public interface ControllerBinding { @Nullable KeyMappingOverride override(); IBind getBind(); + IBind defaultBind(); void resetBind(); boolean isUnbound(); diff --git a/src/main/java/dev/isxander/controlify/bindings/ControllerBindingImpl.java b/src/main/java/dev/isxander/controlify/bindings/ControllerBindingImpl.java index 06c2d03..bb621b5 100644 --- a/src/main/java/dev/isxander/controlify/bindings/ControllerBindingImpl.java +++ b/src/main/java/dev/isxander/controlify/bindings/ControllerBindingImpl.java @@ -122,16 +122,13 @@ public class ControllerBindingImpl implements Control return Optional.ofNullable(this.radialIcon); } - public IBind currentBind() { - return bind; - } - public void setCurrentBind(IBind bind) { this.bind = bind; this.renderer = new BindRendererImpl(bind); Controlify.instance().config().setDirty(); } + @Override public IBind defaultBind() { return defaultBind; } @@ -182,7 +179,7 @@ public class ControllerBindingImpl implements Control @Override public JsonObject toJson() { - return currentBind().toJson(); + return getBind().toJson(); } @Override @@ -194,7 +191,7 @@ public class ControllerBindingImpl implements Control public Option.Builder startYACLOption() { Option.Builder> option = Option.>createBuilder() .name(name()) - .binding(new EmptyBind<>(), this::currentBind, this::setCurrentBind) + .binding(new EmptyBind<>(), this::getBind, this::setCurrentBind) .description(OptionDescription.of(this.description())); if (controller instanceof GamepadController gamepad) { diff --git a/src/main/java/dev/isxander/controlify/gui/screen/ControllerConfigScreenFactory.java b/src/main/java/dev/isxander/controlify/gui/screen/ControllerConfigScreenFactory.java index 9919a04..ed84256 100644 --- a/src/main/java/dev/isxander/controlify/gui/screen/ControllerConfigScreenFactory.java +++ b/src/main/java/dev/isxander/controlify/gui/screen/ControllerConfigScreenFactory.java @@ -33,8 +33,8 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; public class ControllerConfigScreenFactory { - private static final Function percentFormatter = v -> Component.literal(String.format("%.0f%%", v*100)); - private static final Function percentOrOffFormatter = v -> v == 0 ? CommonComponents.OPTION_OFF : percentFormatter.apply(v); + private static final ValueFormatter percentFormatter = v -> Component.literal(String.format("%.0f%%", v*100)); + private static final ValueFormatter percentOrOffFormatter = v -> v == 0 ? CommonComponents.OPTION_OFF : percentFormatter.format(v); private static final Component newOptionLabel = Component.translatable("controlify.gui.new_options.label").withStyle(ChatFormatting.GOLD); private final List> newOptions = new ArrayList<>(); @@ -99,7 +99,7 @@ public class ControllerConfigScreenFactory { .build()) .binding(def.horizontalLookSensitivity, () -> config.horizontalLookSensitivity, v -> config.horizontalLookSensitivity = v) .controller(opt -> FloatSliderControllerBuilder.create(opt) - .range(0.1f, 2f).step(0.05f).valueFormatter(percentFormatter)) + .range(0.1f, 2f).step(0.05f).formatValue(percentFormatter)) .build()) .option(Option.createBuilder() .name(Component.translatable("controlify.gui.vertical_look_sensitivity")) @@ -108,7 +108,7 @@ public class ControllerConfigScreenFactory { .build()) .binding(def.verticalLookSensitivity, () -> config.verticalLookSensitivity, v -> config.verticalLookSensitivity = v) .controller(opt -> FloatSliderControllerBuilder.create(opt) - .range(0.1f, 2f).step(0.05f).valueFormatter(percentFormatter)) + .range(0.1f, 2f).step(0.05f).formatValue(percentFormatter)) .build()) .option(Option.createBuilder() .name(Component.translatable("controlify.gui.vmouse_sensitivity")) @@ -117,7 +117,7 @@ public class ControllerConfigScreenFactory { .build()) .binding(def.virtualMouseSensitivity, () -> config.virtualMouseSensitivity, v -> config.virtualMouseSensitivity = v) .controller(opt -> FloatSliderControllerBuilder.create(opt) - .range(0.1f, 2f).step(0.05f).valueFormatter(percentFormatter)) + .range(0.1f, 2f).step(0.05f).formatValue(percentFormatter)) .build()) .option(Option.createBuilder() .name(Component.translatable("controlify.gui.reduce_aiming_sensitivity")) @@ -132,7 +132,7 @@ public class ControllerConfigScreenFactory { } private OptionGroup makeControlsGroup(Controller controller, ControllerConfig def, ControllerConfig config) { - Function holdToggleFormatter = v -> Component.translatable("controlify.gui.format.hold_toggle." + (v ? "toggle" : "hold")); + ValueFormatter holdToggleFormatter = v -> Component.translatable("controlify.gui.format.hold_toggle." + (v ? "toggle" : "hold")); return OptionGroup.createBuilder() .name(Component.translatable("controlify.gui.config.group.controls")) @@ -143,7 +143,7 @@ public class ControllerConfigScreenFactory { .build()) .binding(def.toggleSprint, () -> config.toggleSprint, v -> config.toggleSprint = v) .controller(opt -> BooleanControllerBuilder.create(opt) - .valueFormatter(holdToggleFormatter) + .formatValue(holdToggleFormatter) .coloured(false)) .build()) .option(Option.createBuilder() @@ -153,7 +153,7 @@ public class ControllerConfigScreenFactory { .build()) .binding(def.toggleSneak, () -> config.toggleSneak, v -> config.toggleSneak = v) .controller(opt -> BooleanControllerBuilder.create(opt) - .valueFormatter(holdToggleFormatter) + .formatValue(holdToggleFormatter) .coloured(false)) .build()) .option(Option.createBuilder() @@ -195,7 +195,7 @@ public class ControllerConfigScreenFactory { .description(OptionDescription.of(Component.translatable("controlify.gui.ingame_button_guide_position.tooltip"))) .binding(def.ingameGuideBottom, () -> config.ingameGuideBottom, v -> config.ingameGuideBottom = v) .controller(opt -> BooleanControllerBuilder.create(opt) - .valueFormatter(v -> Component.translatable(v ? "controlify.gui.format.bottom" : "controlify.gui.format.top"))) + .formatValue(v -> Component.translatable(v ? "controlify.gui.format.bottom" : "controlify.gui.format.top"))) .flag(mc -> Controlify.instance().inGameButtonGuide().ifPresent(InGameButtonGuide::refreshLayout)) .build()) .option(Option.createBuilder() @@ -214,7 +214,7 @@ public class ControllerConfigScreenFactory { .build()) .binding(def.chatKeyboardHeight, () -> config.chatKeyboardHeight, v -> config.chatKeyboardHeight = v) .controller(opt -> FloatSliderControllerBuilder.create(opt) - .range(0f, 8f).step(0.1f).valueFormatter(percentFormatter)) + .range(0f, 8f).step(0.1f).formatValue(percentFormatter)) .build()) .build(); } @@ -241,7 +241,7 @@ public class ControllerConfigScreenFactory { ) .controller(opt -> FloatSliderControllerBuilder.create(opt) .range(0f, 1f).step(0.01f) - .valueFormatter(percentFormatter)) + .formatValue(percentFormatter)) .build(); Option right = Option.createBuilder() @@ -257,7 +257,7 @@ public class ControllerConfigScreenFactory { ) .controller(opt -> FloatSliderControllerBuilder.create(opt) .range(0f, 1f).step(0.01f) - .valueFormatter(percentFormatter)) + .formatValue(percentFormatter)) .build(); group.option(left); @@ -292,7 +292,7 @@ public class ControllerConfigScreenFactory { .binding(jsCfgDef.getDeadzone(i), () -> jsCfg.getDeadzone(i), v -> jsCfg.setDeadzone(i, v)) .controller(opt -> FloatSliderControllerBuilder.create(opt) .range(0f, 1f).step(0.01f) - .valueFormatter(percentFormatter)) + .formatValue(percentFormatter)) .build(); group.option(deadzoneOpt); deadzoneOpts.add(deadzoneOpt); @@ -307,7 +307,7 @@ public class ControllerConfigScreenFactory { .binding(def.buttonActivationThreshold, () -> config.buttonActivationThreshold, v -> config.buttonActivationThreshold = v) .controller(opt -> FloatSliderControllerBuilder.create(opt) .range(0f, 1f).step(0.01f) - .valueFormatter(percentFormatter)) + .formatValue(percentFormatter)) .build()); group.option(ButtonOption.createBuilder() @@ -378,6 +378,19 @@ public class ControllerConfigScreenFactory { }); updateConflictingBinds(optionBinds); + category.option(ButtonOption.createBuilder() + .name(Component.translatable("controlify.gui.reset_all_binds")) + .description(OptionDescription.createBuilder() + .text(Component.translatable("controlify.gui.reset_all_binds.tooltip")) + .build()) + .action((screen, opt) -> { + for (OptionBindPair pair : optionBinds) { + // who needs a type system? + ((Option) pair.option()).requestSet(pair.binding.defaultBind()); + } + }) + .build()); + return category.build(); } @@ -438,7 +451,7 @@ public class ControllerConfigScreenFactory { .controller(opt -> FloatSliderControllerBuilder.create(opt) .range(0f, 2f) .step(0.05f) - .valueFormatter(percentOrOffFormatter)) + .formatValue(percentOrOffFormatter)) .available(allowVibrationOption.pendingValue()) .build(); strengthOptions.add(option); @@ -493,7 +506,7 @@ public class ControllerConfigScreenFactory { .controller(opt -> FloatSliderControllerBuilder.create(opt) .range(0f, 3f) .step(0.1f) - .valueFormatter(percentOrOffFormatter)) + .formatValue(percentOrOffFormatter)) .listener((opt, sensitivity) -> gyroOptions.forEach(o -> { o.setAvailable(sensitivity > 0); o.requestSetDefault(); @@ -507,7 +520,7 @@ public class ControllerConfigScreenFactory { .build()) .binding(gpCfgDef.relativeGyroMode, () -> gpCfg.relativeGyroMode, v -> gpCfg.relativeGyroMode = v) .controller(opt -> BooleanControllerBuilder.create(opt) - .valueFormatter(v -> v ? Component.translatable("controlify.gui.gyro_behaviour.relative") : Component.translatable("controlify.gui.gyro_behaviour.absolute"))) + .formatValue(v -> v ? Component.translatable("controlify.gui.gyro_behaviour.relative") : Component.translatable("controlify.gui.gyro_behaviour.absolute"))) .build(); gyroGroup.option(relativeModeOpt); gyroGroup.option(Util.make(() -> { diff --git a/src/main/resources/assets/controlify/lang/en_us.json b/src/main/resources/assets/controlify/lang/en_us.json index 690ebc9..c4be503 100644 --- a/src/main/resources/assets/controlify/lang/en_us.json +++ b/src/main/resources/assets/controlify/lang/en_us.json @@ -132,6 +132,8 @@ "controlify.gui.radial_menu.btn_text": "CONFIGURE", "controlify.gui.group.controls": "Controls", "controlify.gui.group.controls.tooltip": "Adjust the controller controls.", + "controlify.gui.reset_all_binds": "Reset All Binds", + "controlify.gui.reset_all_binds.tooltip": "Sets all binds to their default values. This can be undone by pressing the undo button.", "controlify.gui.bind_input_awaiting": "Press any button", "controlify.gui.format.ticks": "%s ticks",