diff --git a/gradle.properties b/gradle.properties index c29854d..40d900f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings=1.16.5+build.5 loader_version=0.11.3 # Mod Properties -mod_version = 1.6.0-dev2 +mod_version = 1.6.0-dev3 maven_group = dev.lambdaurora.lambdacontrols archives_base_name = lambdacontrols diff --git a/src/main/java/dev/lambdaurora/lambdacontrols/client/LambdaControlsConfig.java b/src/main/java/dev/lambdaurora/lambdacontrols/client/LambdaControlsConfig.java index b4b3c9f..ebe2dd4 100644 --- a/src/main/java/dev/lambdaurora/lambdacontrols/client/LambdaControlsConfig.java +++ b/src/main/java/dev/lambdaurora/lambdacontrols/client/LambdaControlsConfig.java @@ -51,6 +51,7 @@ public class LambdaControlsConfig { // Controller private static final ControllerType DEFAULT_CONTROLLER_TYPE = ControllerType.DEFAULT; private static final double DEFAULT_DEAD_ZONE = 0.25; + private static final double DEFAULT_MAX_VALUE = 1; private static final double DEFAULT_ROTATION_SPEED = 40.0; private static final double DEFAULT_MOUSE_SPEED = 25.0; private static final boolean DEFAULT_UNFOCUSED_INPUT = false; @@ -70,6 +71,7 @@ public class LambdaControlsConfig { // Controller settings private double rightDeadZone; private double leftDeadZone; + private double[] maxAnalogValues = new double[]{DEFAULT_MAX_VALUE, DEFAULT_MAX_VALUE, DEFAULT_MAX_VALUE, DEFAULT_MAX_VALUE}; private double rotationSpeed; private double mouseSpeed; private boolean unfocusedInput; @@ -100,7 +102,9 @@ public class LambdaControlsConfig { LambdaControlsFeature.HORIZONTAL_REACHAROUND.setEnabled(this.config.getOrElse("gameplay.reacharound.horizontal", DEFAULT_HORIZONTAL_REACHAROUND)); LambdaControlsFeature.VERTICAL_REACHAROUND.setEnabled(this.config.getOrElse("gameplay.reacharound.vertical", DEFAULT_VERTICAL_REACHAROUND)); this.shouldRenderReacharoundOutline = this.config.getOrElse("gameplay.reacharound.outline", DEFAULT_REACHAROUND_OUTLINE); - this.reacharoundOutlineColor = this.config.getOptional("gameplay.reacharound.outline_color").map(hex -> parseColor((String) hex)).orElse(DEFAULT_REACHAROUND_OUTLINE_COLOR); + this.reacharoundOutlineColor = this.config.getOptional("gameplay.reacharound.outline_color") + .map(hex -> parseColor((String) hex)) + .orElse(DEFAULT_REACHAROUND_OUTLINE_COLOR); // Controller settings. this.controllerType = ControllerType.byId(this.config.getOrElse("controller.type", DEFAULT_CONTROLLER_TYPE.getName())).orElse(DEFAULT_CONTROLLER_TYPE); this.rightDeadZone = this.config.getOrElse("controller.right_dead_zone", DEFAULT_DEAD_ZONE); @@ -110,6 +114,10 @@ public class LambdaControlsConfig { this.unfocusedInput = this.config.getOrElse("controller.unfocused_input", DEFAULT_UNFOCUSED_INPUT); this.virtualMouse = this.config.getOrElse("controller.virtual_mouse", DEFAULT_VIRTUAL_MOUSE); this.virtualMouseSkin = VirtualMouseSkin.byId(this.config.getOrElse("controller.virtual_mouse_skin", DEFAULT_VIRTUAL_MOUSE_SKIN.getName())).orElse(DEFAULT_VIRTUAL_MOUSE_SKIN); + + for (int i = 0; i < this.maxAnalogValues.length; i++) { + this.maxAnalogValues[i] = this.config.getOrElse("controller.max_value_" + i, DEFAULT_MAX_VALUE); + } // Controller controls. InputManager.loadButtonBindings(this); @@ -126,6 +134,10 @@ public class LambdaControlsConfig { this.config.set("controller.mouse_speed", this.mouseSpeed); this.config.set("controller.unfocused_input", this.unfocusedInput); this.config.set("controller.virtual_mouse", this.virtualMouse); + + for (int i = 0; i < this.maxAnalogValues.length; i++) { + this.config.set("controller.max_value_" + i, this.maxAnalogValues[i]); + } this.config.save(); this.mod.log("Configuration saved."); } @@ -193,6 +205,8 @@ public class LambdaControlsConfig { this.setUnfocusedInput(DEFAULT_UNFOCUSED_INPUT); this.setVirtualMouse(DEFAULT_VIRTUAL_MOUSE); this.setVirtualMouseSkin(DEFAULT_VIRTUAL_MOUSE_SKIN); + + Arrays.fill(this.maxAnalogValues, DEFAULT_MAX_VALUE); // HUD this.setHudEnabled(DEFAULT_HUD_ENABLE); this.setHudSide(DEFAULT_HUD_SIDE); @@ -304,6 +318,7 @@ public class LambdaControlsConfig { /** * Gets whether analog movement is enabled. + * * @return {@code true} if analog movement is enabled, else {@code false} */ public boolean hasAnalogMovement() { @@ -312,6 +327,7 @@ public class LambdaControlsConfig { /** * Sets whether analog movement is enabled. + * * @param analogMovement {@code true} if analog movement is enabled, else {@code false} */ public void setAnalogMovement(boolean analogMovement) { @@ -447,9 +463,9 @@ public class LambdaControlsConfig { /** * Gets the used controller. * - * @return The used controller. + * @return the controller */ - public @NotNull Controller getController() { + public Controller getController() { Object raw = this.config.getRaw("controller.id"); if (raw instanceof Number) { return Controller.byId((Integer) raw); @@ -462,18 +478,18 @@ public class LambdaControlsConfig { /** * Sets the used controller. * - * @param controller The used controller. + * @param controller the controller */ - public void setController(@NotNull Controller controller) { + public void setController(Controller controller) { this.config.set("controller.id", controller.getId()); } /** * Gets the second controller (for Joy-Con supports). * - * @return The second controller. + * @return the second controller */ - public @NotNull Optional getSecondController() { + public Optional getSecondController() { Object raw = this.config.getRaw("controller.id2"); if (raw instanceof Number) { if ((int) raw == -1) @@ -488,7 +504,7 @@ public class LambdaControlsConfig { /** * Sets the second controller. * - * @param controller The second controller. + * @param controller the second controller */ public void setSecondController(@Nullable Controller controller) { this.config.set("controller.id2", controller == null ? -1 : controller.getId()); @@ -694,6 +710,17 @@ public class LambdaControlsConfig { return this.doesInvertRightYAxis() ? -1.0 : 1.0; } + public double getAxisMaxValue(int axis) { + if (axis >= this.maxAnalogValues.length) + return DEFAULT_MAX_VALUE; + return this.maxAnalogValues[axis]; + } + + public void setAxisMaxValue(int axis, double value) { + if (axis < this.maxAnalogValues.length) + this.maxAnalogValues[axis] = value; + } + /** * Loads the button binding from configuration. * diff --git a/src/main/java/dev/lambdaurora/lambdacontrols/client/LambdaInput.java b/src/main/java/dev/lambdaurora/lambdacontrols/client/LambdaInput.java index 0a92f76..ad8d2e8 100644 --- a/src/main/java/dev/lambdaurora/lambdacontrols/client/LambdaInput.java +++ b/src/main/java/dev/lambdaurora/lambdacontrols/client/LambdaInput.java @@ -80,12 +80,12 @@ public class LambdaInput { private boolean ignoreNextARelease = false; private double targetYaw = 0.0; private double targetPitch = 0.0; - private float prevXAxis = 0.F; - private float prevYAxis = 0.F; + private float prevXAxis = 0.f; + private float prevYAxis = 0.f; private int targetMouseX = 0; private int targetMouseY = 0; - private float mouseSpeedX = 0.F; - private float mouseSpeedY = 0.F; + private float mouseSpeedX = 0.f; + private float mouseSpeedY = 0.f; private int inventoryInteractionCooldown = 0; private ControllerControlsWidget controlsInput = null; @@ -478,6 +478,8 @@ public class LambdaInput { double deadZone = this.getDeadZoneValue(axis); float axisValue = absValue < deadZone ? 0.f : (float) (absValue - deadZone); axisValue /= (1.0 - deadZone); + + axisValue = (float) Math.min(axisValue / this.config.getAxisMaxValue(axis), 1); if (currentPlusState) InputManager.BUTTON_VALUES.put(axisAsButton(axis, true), axisValue); else @@ -525,10 +527,12 @@ public class LambdaInput { } } + absValue -= deadZone; + absValue /= (1.0 - deadZone); + absValue = (float) MathHelper.clamp(absValue / this.config.getAxisMaxValue(axis), 0.f, 1.f); if (client.currentScreen == null) { // Handles the look direction. - absValue -= this.getDeadZoneValue(axis); - this.handleLook(client, axis, (float) (absValue / (1.0 - this.getDeadZoneValue(axis))), state); + this.handleLook(client, axis, absValue, state); } else { boolean allowMouseControl = true; @@ -558,7 +562,7 @@ public class LambdaInput { } if (client.currentScreen != null && allowMouseControl) { - boolean moving = Math.abs(movementY) >= deadZone || Math.abs(movementX) >= deadZone; + boolean moving = movementY != 0 || movementX != 0; if (moving) { /* Updates the target mouse position when the initial movement stick movement is detected. @@ -568,15 +572,8 @@ public class LambdaInput { INPUT_MANAGER.resetMouseTarget(client); } - if (Math.abs(movementX) >= deadZone) - this.mouseSpeedX = movementX; - else - this.mouseSpeedX = 0.f; - - if (Math.abs(movementY) >= deadZone) - this.mouseSpeedY = movementY; - else - this.mouseSpeedY = 0.f; + this.mouseSpeedX = movementX; + this.mouseSpeedY = movementY; } else { this.mouseSpeedX = 0.f; this.mouseSpeedY = 0.f; diff --git a/src/main/java/dev/lambdaurora/lambdacontrols/client/gui/LambdaControlsSettingsScreen.java b/src/main/java/dev/lambdaurora/lambdacontrols/client/gui/LambdaControlsSettingsScreen.java index 19141d1..972c35a 100644 --- a/src/main/java/dev/lambdaurora/lambdacontrols/client/gui/LambdaControlsSettingsScreen.java +++ b/src/main/java/dev/lambdaurora/lambdacontrols/client/gui/LambdaControlsSettingsScreen.java @@ -12,6 +12,7 @@ package dev.lambdaurora.lambdacontrols.client.gui; import dev.lambdaurora.lambdacontrols.ControlsMode; import dev.lambdaurora.lambdacontrols.LambdaControls; import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient; +import dev.lambdaurora.lambdacontrols.client.LambdaControlsConfig; import dev.lambdaurora.lambdacontrols.client.controller.Controller; import dev.lambdaurora.lambdacontrols.client.gui.widget.ControllerControlsWidget; import me.lambdaurora.spruceui.Position; @@ -43,13 +44,15 @@ import org.lwjgl.glfw.GLFW; public class LambdaControlsSettingsScreen extends SpruceScreen { private static final Text SDL2_GAMEPAD_TOOL = new LiteralText("SDL2 Gamepad Tool").formatted(Formatting.GREEN); public static final String GAMEPAD_TOOL_URL = "https://generalarcade.com/gamepadtool/"; - final LambdaControlsClient mod; + final LambdaControlsClient mod = LambdaControlsClient.get(); + private final LambdaControlsConfig config = this.mod.config; private final Screen parent; // General options private final SpruceOption inputModeOption; private final SpruceOption autoSwitchModeOption; private final SpruceOption rotationSpeedOption; private final SpruceOption mouseSpeedOption; + private final SpruceOption virtualMouseOption; private final SpruceOption resetOption; // Gameplay options private final SpruceOption analogMovementOption; @@ -65,168 +68,203 @@ public class LambdaControlsSettingsScreen extends SpruceScreen { private final SpruceOption hudEnableOption; private final SpruceOption hudSideOption; // Controller options - private final SpruceOption controllerOption; - private final SpruceOption secondControllerOption; - private final SpruceOption rightDeadZoneOption; - private final SpruceOption leftDeadZoneOption; + private final SpruceOption controllerOption = + new SpruceCyclingOption("lambdacontrols.menu.controller", + amount -> { + int id = this.config.getController().getId(); + id += amount; + if (id > GLFW.GLFW_JOYSTICK_LAST) + id = GLFW.GLFW_JOYSTICK_1; + id = searchNextAvailableController(id, false); + this.config.setController(Controller.byId(id)); + }, + option -> { + Controller controller = this.config.getController(); + String controllerName = controller.getName(); + if (!controller.isConnected()) + return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.RED)); + else if (!controller.isGamepad()) + return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.GOLD)); + else + return option.getDisplayText(new LiteralText(controllerName)); + }, null); + private final SpruceOption secondControllerOption = new SpruceCyclingOption("lambdacontrols.menu.controller2", + amount -> { + int id = this.config.getSecondController().map(Controller::getId).orElse(-1); + id += amount; + if (id > GLFW.GLFW_JOYSTICK_LAST) + id = -1; + id = searchNextAvailableController(id, true); + this.config.setSecondController(id == -1 ? null : Controller.byId(id)); + }, + option -> this.config.getSecondController().map(controller -> { + String controllerName = controller.getName(); + if (!controller.isConnected()) + return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.RED)); + else if (!controller.isGamepad()) + return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.GOLD)); + else + return option.getDisplayText(new LiteralText(controllerName)); + }).orElse(option.getDisplayText(SpruceTexts.OPTIONS_OFF.shallowCopy().formatted(Formatting.RED))), + new TranslatableText("lambdacontrols.tooltip.controller2")); + private final SpruceOption unfocusedInputOption; private final SpruceOption invertsRightXAxis; private final SpruceOption invertsRightYAxis; - private final SpruceOption unfocusedInputOption; - private final SpruceOption virtualMouseOption; + private final SpruceOption rightDeadZoneOption; + private final SpruceOption leftDeadZoneOption; + private final SpruceOption[] maxAnalogValueOptions = new SpruceOption[]{ + maxAnalogValueOption(this.config, "lambdacontrols.menu.max_left_x_value", GLFW.GLFW_GAMEPAD_AXIS_LEFT_X), + maxAnalogValueOption(this.config, "lambdacontrols.menu.max_left_y_value", GLFW.GLFW_GAMEPAD_AXIS_LEFT_Y), + maxAnalogValueOption(this.config, "lambdacontrols.menu.max_right_x_value", GLFW.GLFW_GAMEPAD_AXIS_RIGHT_X), + maxAnalogValueOption(this.config, "lambdacontrols.menu.max_right_y_value", GLFW.GLFW_GAMEPAD_AXIS_RIGHT_Y) + }; + + private static SpruceOption maxAnalogValueOption(LambdaControlsConfig config, String key, int axis) { + return new SpruceDoubleOption(key, .25f, 1.f, 0.05f, + () -> config.getAxisMaxValue(axis), + newValue -> config.setAxisMaxValue(axis, newValue), + option -> option.getDisplayText(new LiteralText(String.format("%.2f", option.get()))), + new TranslatableText(key.replace("menu", "tooltip")) + ); + } + private final MutableText controllerMappingsUrlText = new LiteralText("(") .append(new LiteralText(GAMEPAD_TOOL_URL).formatted(Formatting.GOLD)) .append("),"); + private static int searchNextAvailableController(int newId, boolean allowNone) { + if ((allowNone && newId == -1) || newId == 0) return newId; + + boolean connected = Controller.byId(newId).isConnected(); + if (!connected) { + newId++; + } + + if (newId > GLFW.GLFW_JOYSTICK_LAST) + newId = allowNone ? -1 : GLFW.GLFW_JOYSTICK_1; + + return connected ? newId : searchNextAvailableController(newId, allowNone); + } + public LambdaControlsSettingsScreen(Screen parent, boolean hideControls) { super(new TranslatableText("lambdacontrols.title.settings")); - this.mod = LambdaControlsClient.get(); this.parent = parent; // General options this.inputModeOption = new SpruceCyclingOption("lambdacontrols.menu.controls_mode", amount -> { - ControlsMode next = this.mod.config.getControlsMode().next(); - this.mod.config.setControlsMode(next); - this.mod.config.save(); + ControlsMode next = this.config.getControlsMode().next(); + this.config.setControlsMode(next); + this.config.save(); if (this.client.player != null) { ClientPlayNetworking.getSender().sendPacket(LambdaControls.CONTROLS_MODE_CHANNEL, this.mod.makeControlsModeBuffer(next)); } - }, option -> option.getDisplayText(new TranslatableText(this.mod.config.getControlsMode().getTranslationKey())), + }, option -> option.getDisplayText(new TranslatableText(this.config.getControlsMode().getTranslationKey())), new TranslatableText("lambdacontrols.tooltip.controls_mode")); - this.autoSwitchModeOption = new SpruceToggleBooleanOption("lambdacontrols.menu.auto_switch_mode", this.mod.config::hasAutoSwitchMode, - this.mod.config::setAutoSwitchMode, new TranslatableText("lambdacontrols.tooltip.auto_switch_mode")); - this.rotationSpeedOption = new SpruceDoubleOption("lambdacontrols.menu.rotation_speed", 0.0, 100.0, 0.5F, this.mod.config::getRotationSpeed, + this.autoSwitchModeOption = new SpruceToggleBooleanOption("lambdacontrols.menu.auto_switch_mode", this.config::hasAutoSwitchMode, + this.config::setAutoSwitchMode, new TranslatableText("lambdacontrols.tooltip.auto_switch_mode")); + this.rotationSpeedOption = new SpruceDoubleOption("lambdacontrols.menu.rotation_speed", 0.0, 100.0, .5f, + this.config::getRotationSpeed, newValue -> { - synchronized (this.mod.config) { - this.mod.config.setRotationSpeed(newValue); + synchronized (this.config) { + this.config.setRotationSpeed(newValue); } }, option -> option.getDisplayText(new LiteralText(String.valueOf(option.get()))), new TranslatableText("lambdacontrols.tooltip.rotation_speed")); - this.mouseSpeedOption = new SpruceDoubleOption("lambdacontrols.menu.mouse_speed", 0.0, 150.0, 0.5F, this.mod.config::getMouseSpeed, + this.mouseSpeedOption = new SpruceDoubleOption("lambdacontrols.menu.mouse_speed", 0.0, 150.0, .5f, + this.config::getMouseSpeed, newValue -> { - synchronized (this.mod.config) { - this.mod.config.setMouseSpeed(newValue); + synchronized (this.config) { + this.config.setMouseSpeed(newValue); } }, option -> option.getDisplayText(new LiteralText(String.valueOf(option.get()))), new TranslatableText("lambdacontrols.tooltip.mouse_speed")); this.resetOption = SpruceSimpleActionOption.reset(btn -> { - this.mod.config.reset(); + this.config.reset(); MinecraftClient client = MinecraftClient.getInstance(); this.init(client, client.getWindow().getScaledWidth(), client.getWindow().getScaledHeight()); }); // Gameplay options this.analogMovementOption = new SpruceToggleBooleanOption("lambdacontrols.menu.analog_movement", - this.mod.config::hasAnalogMovement, this.mod.config::setAnalogMovement, + this.config::hasAnalogMovement, this.config::setAnalogMovement, new TranslatableText("lambdacontrols.tooltip.analog_movement")); this.autoJumpOption = new SpruceToggleBooleanOption("options.autoJump", () -> this.client.options.autoJump, newValue -> this.client.options.autoJump = newValue, null); - this.fastBlockPlacingOption = new SpruceToggleBooleanOption("lambdacontrols.menu.fast_block_placing", this.mod.config::hasFastBlockPlacing, - this.mod.config::setFastBlockPlacing, new TranslatableText("lambdacontrols.tooltip.fast_block_placing")); - this.frontBlockPlacingOption = new SpruceToggleBooleanOption("lambdacontrols.menu.reacharound.horizontal", this.mod.config::hasFrontBlockPlacing, - this.mod.config::setFrontBlockPlacing, new TranslatableText("lambdacontrols.tooltip.reacharound.horizontal")); - this.verticalReacharoundOption = new SpruceToggleBooleanOption("lambdacontrols.menu.reacharound.vertical", this.mod.config::hasVerticalReacharound, - this.mod.config::setVerticalReacharound, new TranslatableText("lambdacontrols.tooltip.reacharound.vertical")); - this.flyDriftingOption = new SpruceToggleBooleanOption("lambdacontrols.menu.fly_drifting", this.mod.config::hasFlyDrifting, - this.mod.config::setFlyDrifting, new TranslatableText("lambdacontrols.tooltip.fly_drifting")); - this.flyVerticalDriftingOption = new SpruceToggleBooleanOption("lambdacontrols.menu.fly_drifting_vertical", this.mod.config::hasFlyVerticalDrifting, - this.mod.config::setFlyVerticalDrifting, new TranslatableText("lambdacontrols.tooltip.fly_drifting_vertical")); + this.fastBlockPlacingOption = new SpruceToggleBooleanOption("lambdacontrols.menu.fast_block_placing", this.config::hasFastBlockPlacing, + this.config::setFastBlockPlacing, new TranslatableText("lambdacontrols.tooltip.fast_block_placing")); + this.frontBlockPlacingOption = new SpruceToggleBooleanOption("lambdacontrols.menu.reacharound.horizontal", this.config::hasFrontBlockPlacing, + this.config::setFrontBlockPlacing, new TranslatableText("lambdacontrols.tooltip.reacharound.horizontal")); + this.verticalReacharoundOption = new SpruceToggleBooleanOption("lambdacontrols.menu.reacharound.vertical", this.config::hasVerticalReacharound, + this.config::setVerticalReacharound, new TranslatableText("lambdacontrols.tooltip.reacharound.vertical")); + this.flyDriftingOption = new SpruceToggleBooleanOption("lambdacontrols.menu.fly_drifting", this.config::hasFlyDrifting, + this.config::setFlyDrifting, new TranslatableText("lambdacontrols.tooltip.fly_drifting")); + this.flyVerticalDriftingOption = new SpruceToggleBooleanOption("lambdacontrols.menu.fly_drifting_vertical", this.config::hasFlyVerticalDrifting, + this.config::setFlyVerticalDrifting, new TranslatableText("lambdacontrols.tooltip.fly_drifting_vertical")); // Appearance options this.controllerTypeOption = new SpruceCyclingOption("lambdacontrols.menu.controller_type", - amount -> this.mod.config.setControllerType(this.mod.config.getControllerType().next()), - option -> option.getDisplayText(this.mod.config.getControllerType().getTranslatedText()), + amount -> this.config.setControllerType(this.config.getControllerType().next()), + option -> option.getDisplayText(this.config.getControllerType().getTranslatedText()), new TranslatableText("lambdacontrols.tooltip.controller_type")); this.virtualMouseSkinOption = new SpruceCyclingOption("lambdacontrols.menu.virtual_mouse.skin", - amount -> this.mod.config.setVirtualMouseSkin(this.mod.config.getVirtualMouseSkin().next()), - option -> option.getDisplayText(this.mod.config.getVirtualMouseSkin().getTranslatedText()), + amount -> this.config.setVirtualMouseSkin(this.config.getVirtualMouseSkin().next()), + option -> option.getDisplayText(this.config.getVirtualMouseSkin().getTranslatedText()), null); - this.hudEnableOption = new SpruceToggleBooleanOption("lambdacontrols.menu.hud_enable", this.mod.config::isHudEnabled, + this.hudEnableOption = new SpruceToggleBooleanOption("lambdacontrols.menu.hud_enable", this.config::isHudEnabled, this.mod::setHudEnabled, new TranslatableText("lambdacontrols.tooltip.hud_enable")); this.hudSideOption = new SpruceCyclingOption("lambdacontrols.menu.hud_side", - amount -> this.mod.config.setHudSide(this.mod.config.getHudSide().next()), - option -> option.getDisplayText(this.mod.config.getHudSide().getTranslatedText()), + amount -> this.config.setHudSide(this.config.getHudSide().next()), + option -> option.getDisplayText(this.config.getHudSide().getTranslatedText()), new TranslatableText("lambdacontrols.tooltip.hud_side")); // Controller options - this.controllerOption = new SpruceCyclingOption("lambdacontrols.menu.controller", amount -> { - int id = this.mod.config.getController().getId(); - id += amount; - if (id > GLFW.GLFW_JOYSTICK_LAST) - id = GLFW.GLFW_JOYSTICK_1; - this.mod.config.setController(Controller.byId(id)); - }, option -> { - String controllerName = this.mod.config.getController().getName(); - if (!this.mod.config.getController().isConnected()) - return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.RED)); - else if (!this.mod.config.getController().isGamepad()) - return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.GOLD)); - else - return option.getDisplayText(new LiteralText(controllerName)); - }, null); - this.secondControllerOption = new SpruceCyclingOption("lambdacontrols.menu.controller2", - amount -> { - int id = this.mod.config.getSecondController().map(Controller::getId).orElse(-1); - id += amount; - if (id > GLFW.GLFW_JOYSTICK_LAST) - id = -1; - this.mod.config.setSecondController(id == -1 ? null : Controller.byId(id)); - }, option -> this.mod.config.getSecondController().map(controller -> { - String controllerName = controller.getName(); - if (!controller.isConnected()) - return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.RED)); - else if (!controller.isGamepad()) - return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.GOLD)); - else - return option.getDisplayText(new LiteralText(controllerName)); - }).orElse(option.getDisplayText(SpruceTexts.OPTIONS_OFF.shallowCopy().formatted(Formatting.RED))), - new TranslatableText("lambdacontrols.tooltip.controller2")); - this.rightDeadZoneOption = new SpruceDoubleOption("lambdacontrols.menu.right_dead_zone", 0.05, 1.0, 0.05f, - this.mod.config::getRightDeadZone, + this.rightDeadZoneOption = new SpruceDoubleOption("lambdacontrols.menu.right_dead_zone", 0.05, 1.0, .05f, + this.config::getRightDeadZone, newValue -> { - synchronized (this.mod.config) { - this.mod.config.setRightDeadZone(newValue); + synchronized (this.config) { + this.config.setRightDeadZone(newValue); } }, option -> { String value = String.valueOf(option.get()); return option.getDisplayText(new LiteralText(value.substring(0, Math.min(value.length(), 5)))); }, new TranslatableText("lambdacontrols.tooltip.right_dead_zone")); - this.leftDeadZoneOption = new SpruceDoubleOption("lambdacontrols.menu.left_dead_zone", 0.05, 1.0, 0.05f, - this.mod.config::getLeftDeadZone, + this.leftDeadZoneOption = new SpruceDoubleOption("lambdacontrols.menu.left_dead_zone", 0.05, 1.0, .05f, + this.config::getLeftDeadZone, newValue -> { - synchronized (this.mod.config) { - this.mod.config.setLeftDeadZone(newValue); + synchronized (this.config) { + this.config.setLeftDeadZone(newValue); } }, option -> { String value = String.valueOf(option.get()); return option.getDisplayText(new LiteralText(value.substring(0, Math.min(value.length(), 5)))); }, new TranslatableText("lambdacontrols.tooltip.left_dead_zone")); - this.invertsRightXAxis = new SpruceToggleBooleanOption("lambdacontrols.menu.invert_right_x_axis", this.mod.config::doesInvertRightXAxis, + this.invertsRightXAxis = new SpruceToggleBooleanOption("lambdacontrols.menu.invert_right_x_axis", this.config::doesInvertRightXAxis, newValue -> { - synchronized (this.mod.config) { - this.mod.config.setInvertRightXAxis(newValue); + synchronized (this.config) { + this.config.setInvertRightXAxis(newValue); } }, null); - this.invertsRightYAxis = new SpruceToggleBooleanOption("lambdacontrols.menu.invert_right_y_axis", this.mod.config::doesInvertRightYAxis, + this.invertsRightYAxis = new SpruceToggleBooleanOption("lambdacontrols.menu.invert_right_y_axis", this.config::doesInvertRightYAxis, newValue -> { - synchronized (this.mod.config) { - this.mod.config.setInvertRightYAxis(newValue); + synchronized (this.config) { + this.config.setInvertRightYAxis(newValue); } }, null); - this.unfocusedInputOption = new SpruceToggleBooleanOption("lambdacontrols.menu.unfocused_input", this.mod.config::hasUnfocusedInput, - this.mod.config::setUnfocusedInput, new TranslatableText("lambdacontrols.tooltip.unfocused_input")); - this.virtualMouseOption = new SpruceToggleBooleanOption("lambdacontrols.menu.virtual_mouse", this.mod.config::hasVirtualMouse, - this.mod.config::setVirtualMouse, new TranslatableText("lambdacontrols.tooltip.virtual_mouse")); + this.unfocusedInputOption = new SpruceToggleBooleanOption("lambdacontrols.menu.unfocused_input", this.config::hasUnfocusedInput, + this.config::setUnfocusedInput, new TranslatableText("lambdacontrols.tooltip.unfocused_input")); + this.virtualMouseOption = new SpruceToggleBooleanOption("lambdacontrols.menu.virtual_mouse", this.config::hasVirtualMouse, + this.config::setVirtualMouse, new TranslatableText("lambdacontrols.tooltip.virtual_mouse")); } @Override public void removed() { - this.mod.config.save(); + this.config.save(); super.removed(); } @Override public void onClose() { - this.mod.config.save(); + this.config.save(); super.onClose(); } @@ -338,6 +376,9 @@ public class LambdaControlsSettingsScreen extends SpruceScreen { list.addOptionEntry(this.invertsRightXAxis, this.invertsRightYAxis); list.addSingleOptionEntry(this.rightDeadZoneOption); list.addSingleOptionEntry(this.leftDeadZoneOption); + for (SpruceOption option : this.maxAnalogValueOptions) { + list.addSingleOptionEntry(option); + } root.addChild(list); root.addChild(labels); diff --git a/src/main/resources/assets/lambdacontrols/lang/en_us.json b/src/main/resources/assets/lambdacontrols/lang/en_us.json index eee570b..b8fd8fe 100644 --- a/src/main/resources/assets/lambdacontrols/lang/en_us.json +++ b/src/main/resources/assets/lambdacontrols/lang/en_us.json @@ -95,6 +95,10 @@ "lambdacontrols.menu.keyboard_controls": "Keyboard Controls...", "lambdacontrols.menu.left_dead_zone": "Left Dead Zone", "lambdacontrols.menu.mappings.open_input_str": "Open Mappings File Editor", + "lambdacontrols.menu.max_left_x_value": "Left X Axis Max Value", + "lambdacontrols.menu.max_left_y_value": "Left Y Axis Max Value", + "lambdacontrols.menu.max_right_x_value": "Right X Axis Max Value", + "lambdacontrols.menu.max_right_y_value": "Right Y Axis Max Value", "lambdacontrols.menu.mouse_speed": "Mouse Speed", "lambdacontrols.menu.reacharound.horizontal": "Front Block Placing", "lambdacontrols.menu.reacharound.vertical": "Vertical Reacharound", @@ -127,6 +131,10 @@ "lambdacontrols.tooltip.hud_enable": "Toggles the on-screen controller button indicator.", "lambdacontrols.tooltip.hud_side": "The position of the HUD.", "lambdacontrols.tooltip.left_dead_zone": "The dead zone for the controller's left analogue stick.", + "lambdacontrols.tooltip.max_left_x_value": "Changes what the mod considers the highest value for the left X axis. Useful if your axis does not use the full range and seems slow.", + "lambdacontrols.tooltip.max_left_y_value": "Changes what the mod considers the highest value for the left Y axis. Useful if your axis does not use the full range and seems slow.", + "lambdacontrols.tooltip.max_right_x_value": "Changes what the mod considers the highest value for the right X axis. Useful if your axis does not use the full range and seems slow.", + "lambdacontrols.tooltip.max_right_y_value": "Changes what the mod considers the highest value for the right Y axis. Useful if your axis does not use the full range and seems slow.", "lambdacontrols.tooltip.mouse_speed": "The controller's emulated mouse speed.", "lambdacontrols.tooltip.reacharound.horizontal": "Enables front block placing, §cmight be considered cheating on some servers§r.", "lambdacontrols.tooltip.reacharound.vertical": "Enables vertical reacharound, §cmight be considered cheating on some servers§r.", diff --git a/src/main/resources/assets/lambdacontrols/lang/fr_ca.json b/src/main/resources/assets/lambdacontrols/lang/fr_ca.json index 69c623f..0ef9706 100644 --- a/src/main/resources/assets/lambdacontrols/lang/fr_ca.json +++ b/src/main/resources/assets/lambdacontrols/lang/fr_ca.json @@ -95,6 +95,10 @@ "lambdacontrols.menu.keyboard_controls": "Contrôles clavier...", "lambdacontrols.menu.left_dead_zone": "Zone morte axe gauche", "lambdacontrols.menu.mappings.open_input_str": "Ouvrir l'éditeur de fichier des manettes", + "lambdacontrols.menu.max_left_x_value": "Valeur maximale de l'axe X gauche", + "lambdacontrols.menu.max_left_y_value": "Valeur maximale de l'axe Y gauche", + "lambdacontrols.menu.max_right_x_value": "Valeur maximale de l'axe X droit", + "lambdacontrols.menu.max_right_y_value": "Valeur maximale de l'axe Y droit", "lambdacontrols.menu.mouse_speed": "Vitesse de la souris", "lambdacontrols.menu.reacharound.horizontal": "Placement avant de bloc", "lambdacontrols.menu.reacharound.vertical": "Placement vertical", @@ -127,6 +131,10 @@ "lambdacontrols.tooltip.hud_enable": "Détermine si l'indicateur des buttons de la manette doit être affiché ou non.", "lambdacontrols.tooltip.hud_side": "Change la position du HUD.", "lambdacontrols.tooltip.left_dead_zone": "Zone morte de l'axe gauche de la manette.", + "lambdacontrols.tooltip.max_left_x_value": "Change ce que le mod considère comme valeur maximale pour l'axe X gauche. Utile si votre axe n'utilise pas l'entièreté de l'ensemble des valeurs et paraît lent.", + "lambdacontrols.tooltip.max_left_y_value": "Change ce que le mod considère comme valeur maximale pour l'axe Y gauche. Utile si votre axe n'utilise pas l'entièreté de l'ensemble des valeurs et paraît lent.", + "lambdacontrols.tooltip.max_right_x_value": "Change ce que le mod considère comme valeur maximale pour l'axe X droit. Utile si votre axe n'utilise pas l'entièreté de l'ensemble des valeurs et paraît lent.", + "lambdacontrols.tooltip.max_right_y_value": "Change ce que le mod considère comme valeur maximale pour l'axe Y droit. Utile si votre axe n'utilise pas l'entièreté de l'ensemble des valeurs et paraît lent.", "lambdacontrols.tooltip.mouse_speed": "Change la vitesse de la souris émulée par la manette.", "lambdacontrols.tooltip.reacharound.horizontal": "Active le placement avant de blocs, §cpeut être considérer comme de la triche sur certains serveurs§r.", "lambdacontrols.tooltip.reacharound.vertical": "Active le placement vertical de blocs, c'est-à-dire de blocs en dessous du bloc sur lequel vous êtes placé, §cpeut être considérer comme de la triche sur certains serveurs§r.", diff --git a/src/main/resources/assets/lambdacontrols/lang/fr_fr.json b/src/main/resources/assets/lambdacontrols/lang/fr_fr.json index 69c623f..0ef9706 100644 --- a/src/main/resources/assets/lambdacontrols/lang/fr_fr.json +++ b/src/main/resources/assets/lambdacontrols/lang/fr_fr.json @@ -95,6 +95,10 @@ "lambdacontrols.menu.keyboard_controls": "Contrôles clavier...", "lambdacontrols.menu.left_dead_zone": "Zone morte axe gauche", "lambdacontrols.menu.mappings.open_input_str": "Ouvrir l'éditeur de fichier des manettes", + "lambdacontrols.menu.max_left_x_value": "Valeur maximale de l'axe X gauche", + "lambdacontrols.menu.max_left_y_value": "Valeur maximale de l'axe Y gauche", + "lambdacontrols.menu.max_right_x_value": "Valeur maximale de l'axe X droit", + "lambdacontrols.menu.max_right_y_value": "Valeur maximale de l'axe Y droit", "lambdacontrols.menu.mouse_speed": "Vitesse de la souris", "lambdacontrols.menu.reacharound.horizontal": "Placement avant de bloc", "lambdacontrols.menu.reacharound.vertical": "Placement vertical", @@ -127,6 +131,10 @@ "lambdacontrols.tooltip.hud_enable": "Détermine si l'indicateur des buttons de la manette doit être affiché ou non.", "lambdacontrols.tooltip.hud_side": "Change la position du HUD.", "lambdacontrols.tooltip.left_dead_zone": "Zone morte de l'axe gauche de la manette.", + "lambdacontrols.tooltip.max_left_x_value": "Change ce que le mod considère comme valeur maximale pour l'axe X gauche. Utile si votre axe n'utilise pas l'entièreté de l'ensemble des valeurs et paraît lent.", + "lambdacontrols.tooltip.max_left_y_value": "Change ce que le mod considère comme valeur maximale pour l'axe Y gauche. Utile si votre axe n'utilise pas l'entièreté de l'ensemble des valeurs et paraît lent.", + "lambdacontrols.tooltip.max_right_x_value": "Change ce que le mod considère comme valeur maximale pour l'axe X droit. Utile si votre axe n'utilise pas l'entièreté de l'ensemble des valeurs et paraît lent.", + "lambdacontrols.tooltip.max_right_y_value": "Change ce que le mod considère comme valeur maximale pour l'axe Y droit. Utile si votre axe n'utilise pas l'entièreté de l'ensemble des valeurs et paraît lent.", "lambdacontrols.tooltip.mouse_speed": "Change la vitesse de la souris émulée par la manette.", "lambdacontrols.tooltip.reacharound.horizontal": "Active le placement avant de blocs, §cpeut être considérer comme de la triche sur certains serveurs§r.", "lambdacontrols.tooltip.reacharound.vertical": "Active le placement vertical de blocs, c'est-à-dire de blocs en dessous du bloc sur lequel vous êtes placé, §cpeut être considérer comme de la triche sur certains serveurs§r.",