Add max values to axes, fixes #41.

This commit is contained in:
LambdAurora
2021-03-17 23:50:16 +01:00
parent 97521e832d
commit c8989cb9ee
7 changed files with 205 additions and 116 deletions

View File

@@ -8,7 +8,7 @@ yarn_mappings=1.16.5+build.5
loader_version=0.11.3 loader_version=0.11.3
# Mod Properties # Mod Properties
mod_version = 1.6.0-dev2 mod_version = 1.6.0-dev3
maven_group = dev.lambdaurora.lambdacontrols maven_group = dev.lambdaurora.lambdacontrols
archives_base_name = lambdacontrols archives_base_name = lambdacontrols

View File

@@ -51,6 +51,7 @@ public class LambdaControlsConfig {
// Controller // Controller
private static final ControllerType DEFAULT_CONTROLLER_TYPE = ControllerType.DEFAULT; private static final ControllerType DEFAULT_CONTROLLER_TYPE = ControllerType.DEFAULT;
private static final double DEFAULT_DEAD_ZONE = 0.25; 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_ROTATION_SPEED = 40.0;
private static final double DEFAULT_MOUSE_SPEED = 25.0; private static final double DEFAULT_MOUSE_SPEED = 25.0;
private static final boolean DEFAULT_UNFOCUSED_INPUT = false; private static final boolean DEFAULT_UNFOCUSED_INPUT = false;
@@ -70,6 +71,7 @@ public class LambdaControlsConfig {
// Controller settings // Controller settings
private double rightDeadZone; private double rightDeadZone;
private double leftDeadZone; 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 rotationSpeed;
private double mouseSpeed; private double mouseSpeed;
private boolean unfocusedInput; private boolean unfocusedInput;
@@ -100,7 +102,9 @@ public class LambdaControlsConfig {
LambdaControlsFeature.HORIZONTAL_REACHAROUND.setEnabled(this.config.getOrElse("gameplay.reacharound.horizontal", DEFAULT_HORIZONTAL_REACHAROUND)); 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)); 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.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. // Controller settings.
this.controllerType = ControllerType.byId(this.config.getOrElse("controller.type", DEFAULT_CONTROLLER_TYPE.getName())).orElse(DEFAULT_CONTROLLER_TYPE); 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); 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.unfocusedInput = this.config.getOrElse("controller.unfocused_input", DEFAULT_UNFOCUSED_INPUT);
this.virtualMouse = this.config.getOrElse("controller.virtual_mouse", DEFAULT_VIRTUAL_MOUSE); 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); 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. // Controller controls.
InputManager.loadButtonBindings(this); InputManager.loadButtonBindings(this);
@@ -126,6 +134,10 @@ public class LambdaControlsConfig {
this.config.set("controller.mouse_speed", this.mouseSpeed); this.config.set("controller.mouse_speed", this.mouseSpeed);
this.config.set("controller.unfocused_input", this.unfocusedInput); this.config.set("controller.unfocused_input", this.unfocusedInput);
this.config.set("controller.virtual_mouse", this.virtualMouse); 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.config.save();
this.mod.log("Configuration saved."); this.mod.log("Configuration saved.");
} }
@@ -193,6 +205,8 @@ public class LambdaControlsConfig {
this.setUnfocusedInput(DEFAULT_UNFOCUSED_INPUT); this.setUnfocusedInput(DEFAULT_UNFOCUSED_INPUT);
this.setVirtualMouse(DEFAULT_VIRTUAL_MOUSE); this.setVirtualMouse(DEFAULT_VIRTUAL_MOUSE);
this.setVirtualMouseSkin(DEFAULT_VIRTUAL_MOUSE_SKIN); this.setVirtualMouseSkin(DEFAULT_VIRTUAL_MOUSE_SKIN);
Arrays.fill(this.maxAnalogValues, DEFAULT_MAX_VALUE);
// HUD // HUD
this.setHudEnabled(DEFAULT_HUD_ENABLE); this.setHudEnabled(DEFAULT_HUD_ENABLE);
this.setHudSide(DEFAULT_HUD_SIDE); this.setHudSide(DEFAULT_HUD_SIDE);
@@ -304,6 +318,7 @@ public class LambdaControlsConfig {
/** /**
* Gets whether analog movement is enabled. * Gets whether analog movement is enabled.
*
* @return {@code true} if analog movement is enabled, else {@code false} * @return {@code true} if analog movement is enabled, else {@code false}
*/ */
public boolean hasAnalogMovement() { public boolean hasAnalogMovement() {
@@ -312,6 +327,7 @@ public class LambdaControlsConfig {
/** /**
* Sets whether analog movement is enabled. * Sets whether analog movement is enabled.
*
* @param analogMovement {@code true} if analog movement is enabled, else {@code false} * @param analogMovement {@code true} if analog movement is enabled, else {@code false}
*/ */
public void setAnalogMovement(boolean analogMovement) { public void setAnalogMovement(boolean analogMovement) {
@@ -447,9 +463,9 @@ public class LambdaControlsConfig {
/** /**
* Gets the used controller. * 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"); Object raw = this.config.getRaw("controller.id");
if (raw instanceof Number) { if (raw instanceof Number) {
return Controller.byId((Integer) raw); return Controller.byId((Integer) raw);
@@ -462,18 +478,18 @@ public class LambdaControlsConfig {
/** /**
* Sets the used controller. * 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()); this.config.set("controller.id", controller.getId());
} }
/** /**
* Gets the second controller (for Joy-Con supports). * Gets the second controller (for Joy-Con supports).
* *
* @return The second controller. * @return the second controller
*/ */
public @NotNull Optional<Controller> getSecondController() { public Optional<Controller> getSecondController() {
Object raw = this.config.getRaw("controller.id2"); Object raw = this.config.getRaw("controller.id2");
if (raw instanceof Number) { if (raw instanceof Number) {
if ((int) raw == -1) if ((int) raw == -1)
@@ -488,7 +504,7 @@ public class LambdaControlsConfig {
/** /**
* Sets the second controller. * Sets the second controller.
* *
* @param controller The second controller. * @param controller the second controller
*/ */
public void setSecondController(@Nullable Controller controller) { public void setSecondController(@Nullable Controller controller) {
this.config.set("controller.id2", controller == null ? -1 : controller.getId()); this.config.set("controller.id2", controller == null ? -1 : controller.getId());
@@ -694,6 +710,17 @@ public class LambdaControlsConfig {
return this.doesInvertRightYAxis() ? -1.0 : 1.0; 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. * Loads the button binding from configuration.
* *

View File

@@ -80,12 +80,12 @@ public class LambdaInput {
private boolean ignoreNextARelease = false; private boolean ignoreNextARelease = false;
private double targetYaw = 0.0; private double targetYaw = 0.0;
private double targetPitch = 0.0; private double targetPitch = 0.0;
private float prevXAxis = 0.F; private float prevXAxis = 0.f;
private float prevYAxis = 0.F; private float prevYAxis = 0.f;
private int targetMouseX = 0; private int targetMouseX = 0;
private int targetMouseY = 0; private int targetMouseY = 0;
private float mouseSpeedX = 0.F; private float mouseSpeedX = 0.f;
private float mouseSpeedY = 0.F; private float mouseSpeedY = 0.f;
private int inventoryInteractionCooldown = 0; private int inventoryInteractionCooldown = 0;
private ControllerControlsWidget controlsInput = null; private ControllerControlsWidget controlsInput = null;
@@ -478,6 +478,8 @@ public class LambdaInput {
double deadZone = this.getDeadZoneValue(axis); double deadZone = this.getDeadZoneValue(axis);
float axisValue = absValue < deadZone ? 0.f : (float) (absValue - deadZone); float axisValue = absValue < deadZone ? 0.f : (float) (absValue - deadZone);
axisValue /= (1.0 - deadZone); axisValue /= (1.0 - deadZone);
axisValue = (float) Math.min(axisValue / this.config.getAxisMaxValue(axis), 1);
if (currentPlusState) if (currentPlusState)
InputManager.BUTTON_VALUES.put(axisAsButton(axis, true), axisValue); InputManager.BUTTON_VALUES.put(axisAsButton(axis, true), axisValue);
else 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) { if (client.currentScreen == null) {
// Handles the look direction. // Handles the look direction.
absValue -= this.getDeadZoneValue(axis); this.handleLook(client, axis, absValue, state);
this.handleLook(client, axis, (float) (absValue / (1.0 - this.getDeadZoneValue(axis))), state);
} else { } else {
boolean allowMouseControl = true; boolean allowMouseControl = true;
@@ -558,7 +562,7 @@ public class LambdaInput {
} }
if (client.currentScreen != null && allowMouseControl) { if (client.currentScreen != null && allowMouseControl) {
boolean moving = Math.abs(movementY) >= deadZone || Math.abs(movementX) >= deadZone; boolean moving = movementY != 0 || movementX != 0;
if (moving) { if (moving) {
/* /*
Updates the target mouse position when the initial movement stick movement is detected. Updates the target mouse position when the initial movement stick movement is detected.
@@ -568,15 +572,8 @@ public class LambdaInput {
INPUT_MANAGER.resetMouseTarget(client); INPUT_MANAGER.resetMouseTarget(client);
} }
if (Math.abs(movementX) >= deadZone)
this.mouseSpeedX = movementX; this.mouseSpeedX = movementX;
else
this.mouseSpeedX = 0.f;
if (Math.abs(movementY) >= deadZone)
this.mouseSpeedY = movementY; this.mouseSpeedY = movementY;
else
this.mouseSpeedY = 0.f;
} else { } else {
this.mouseSpeedX = 0.f; this.mouseSpeedX = 0.f;
this.mouseSpeedY = 0.f; this.mouseSpeedY = 0.f;

View File

@@ -12,6 +12,7 @@ package dev.lambdaurora.lambdacontrols.client.gui;
import dev.lambdaurora.lambdacontrols.ControlsMode; import dev.lambdaurora.lambdacontrols.ControlsMode;
import dev.lambdaurora.lambdacontrols.LambdaControls; import dev.lambdaurora.lambdacontrols.LambdaControls;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient; import dev.lambdaurora.lambdacontrols.client.LambdaControlsClient;
import dev.lambdaurora.lambdacontrols.client.LambdaControlsConfig;
import dev.lambdaurora.lambdacontrols.client.controller.Controller; import dev.lambdaurora.lambdacontrols.client.controller.Controller;
import dev.lambdaurora.lambdacontrols.client.gui.widget.ControllerControlsWidget; import dev.lambdaurora.lambdacontrols.client.gui.widget.ControllerControlsWidget;
import me.lambdaurora.spruceui.Position; import me.lambdaurora.spruceui.Position;
@@ -43,13 +44,15 @@ import org.lwjgl.glfw.GLFW;
public class LambdaControlsSettingsScreen extends SpruceScreen { public class LambdaControlsSettingsScreen extends SpruceScreen {
private static final Text SDL2_GAMEPAD_TOOL = new LiteralText("SDL2 Gamepad Tool").formatted(Formatting.GREEN); 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/"; 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; private final Screen parent;
// General options // General options
private final SpruceOption inputModeOption; private final SpruceOption inputModeOption;
private final SpruceOption autoSwitchModeOption; private final SpruceOption autoSwitchModeOption;
private final SpruceOption rotationSpeedOption; private final SpruceOption rotationSpeedOption;
private final SpruceOption mouseSpeedOption; private final SpruceOption mouseSpeedOption;
private final SpruceOption virtualMouseOption;
private final SpruceOption resetOption; private final SpruceOption resetOption;
// Gameplay options // Gameplay options
private final SpruceOption analogMovementOption; private final SpruceOption analogMovementOption;
@@ -65,112 +68,36 @@ public class LambdaControlsSettingsScreen extends SpruceScreen {
private final SpruceOption hudEnableOption; private final SpruceOption hudEnableOption;
private final SpruceOption hudSideOption; private final SpruceOption hudSideOption;
// Controller options // Controller options
private final SpruceOption controllerOption; private final SpruceOption controllerOption =
private final SpruceOption secondControllerOption; new SpruceCyclingOption("lambdacontrols.menu.controller",
private final SpruceOption rightDeadZoneOption;
private final SpruceOption leftDeadZoneOption;
private final SpruceOption invertsRightXAxis;
private final SpruceOption invertsRightYAxis;
private final SpruceOption unfocusedInputOption;
private final SpruceOption virtualMouseOption;
private final MutableText controllerMappingsUrlText = new LiteralText("(")
.append(new LiteralText(GAMEPAD_TOOL_URL).formatted(Formatting.GOLD))
.append("),");
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 -> { amount -> {
ControlsMode next = this.mod.config.getControlsMode().next(); int id = this.config.getController().getId();
this.mod.config.setControlsMode(next);
this.mod.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())),
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,
newValue -> {
synchronized (this.mod.config) {
this.mod.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,
newValue -> {
synchronized (this.mod.config) {
this.mod.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();
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,
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"));
// 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()),
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()),
null);
this.hudEnableOption = new SpruceToggleBooleanOption("lambdacontrols.menu.hud_enable", this.mod.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()),
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; id += amount;
if (id > GLFW.GLFW_JOYSTICK_LAST) if (id > GLFW.GLFW_JOYSTICK_LAST)
id = GLFW.GLFW_JOYSTICK_1; id = GLFW.GLFW_JOYSTICK_1;
this.mod.config.setController(Controller.byId(id)); id = searchNextAvailableController(id, false);
}, option -> { this.config.setController(Controller.byId(id));
String controllerName = this.mod.config.getController().getName(); },
if (!this.mod.config.getController().isConnected()) option -> {
Controller controller = this.config.getController();
String controllerName = controller.getName();
if (!controller.isConnected())
return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.RED)); return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.RED));
else if (!this.mod.config.getController().isGamepad()) else if (!controller.isGamepad())
return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.GOLD)); return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.GOLD));
else else
return option.getDisplayText(new LiteralText(controllerName)); return option.getDisplayText(new LiteralText(controllerName));
}, null); }, null);
this.secondControllerOption = new SpruceCyclingOption("lambdacontrols.menu.controller2", private final SpruceOption secondControllerOption = new SpruceCyclingOption("lambdacontrols.menu.controller2",
amount -> { amount -> {
int id = this.mod.config.getSecondController().map(Controller::getId).orElse(-1); int id = this.config.getSecondController().map(Controller::getId).orElse(-1);
id += amount; id += amount;
if (id > GLFW.GLFW_JOYSTICK_LAST) if (id > GLFW.GLFW_JOYSTICK_LAST)
id = -1; id = -1;
this.mod.config.setSecondController(id == -1 ? null : Controller.byId(id)); id = searchNextAvailableController(id, true);
}, option -> this.mod.config.getSecondController().map(controller -> { this.config.setSecondController(id == -1 ? null : Controller.byId(id));
},
option -> this.config.getSecondController().map(controller -> {
String controllerName = controller.getName(); String controllerName = controller.getName();
if (!controller.isConnected()) if (!controller.isConnected())
return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.RED)); return option.getDisplayText(new LiteralText(controllerName).formatted(Formatting.RED));
@@ -180,53 +107,164 @@ public class LambdaControlsSettingsScreen extends SpruceScreen {
return option.getDisplayText(new LiteralText(controllerName)); return option.getDisplayText(new LiteralText(controllerName));
}).orElse(option.getDisplayText(SpruceTexts.OPTIONS_OFF.shallowCopy().formatted(Formatting.RED))), }).orElse(option.getDisplayText(SpruceTexts.OPTIONS_OFF.shallowCopy().formatted(Formatting.RED))),
new TranslatableText("lambdacontrols.tooltip.controller2")); new TranslatableText("lambdacontrols.tooltip.controller2"));
this.rightDeadZoneOption = new SpruceDoubleOption("lambdacontrols.menu.right_dead_zone", 0.05, 1.0, 0.05f, private final SpruceOption unfocusedInputOption;
this.mod.config::getRightDeadZone, private final SpruceOption invertsRightXAxis;
private final SpruceOption invertsRightYAxis;
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.parent = parent;
// General options
this.inputModeOption = new SpruceCyclingOption("lambdacontrols.menu.controls_mode",
amount -> {
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.config.getControlsMode().getTranslationKey())),
new TranslatableText("lambdacontrols.tooltip.controls_mode"));
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 -> { newValue -> {
synchronized (this.mod.config) { synchronized (this.config) {
this.mod.config.setRightDeadZone(newValue); 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, .5f,
this.config::getMouseSpeed,
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.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.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.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.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.config.setVirtualMouseSkin(this.config.getVirtualMouseSkin().next()),
option -> option.getDisplayText(this.config.getVirtualMouseSkin().getTranslatedText()),
null);
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.config.setHudSide(this.config.getHudSide().next()),
option -> option.getDisplayText(this.config.getHudSide().getTranslatedText()),
new TranslatableText("lambdacontrols.tooltip.hud_side"));
// Controller options
this.rightDeadZoneOption = new SpruceDoubleOption("lambdacontrols.menu.right_dead_zone", 0.05, 1.0, .05f,
this.config::getRightDeadZone,
newValue -> {
synchronized (this.config) {
this.config.setRightDeadZone(newValue);
} }
}, option -> { }, option -> {
String value = String.valueOf(option.get()); String value = String.valueOf(option.get());
return option.getDisplayText(new LiteralText(value.substring(0, Math.min(value.length(), 5)))); return option.getDisplayText(new LiteralText(value.substring(0, Math.min(value.length(), 5))));
}, new TranslatableText("lambdacontrols.tooltip.right_dead_zone")); }, new TranslatableText("lambdacontrols.tooltip.right_dead_zone"));
this.leftDeadZoneOption = new SpruceDoubleOption("lambdacontrols.menu.left_dead_zone", 0.05, 1.0, 0.05f, this.leftDeadZoneOption = new SpruceDoubleOption("lambdacontrols.menu.left_dead_zone", 0.05, 1.0, .05f,
this.mod.config::getLeftDeadZone, this.config::getLeftDeadZone,
newValue -> { newValue -> {
synchronized (this.mod.config) { synchronized (this.config) {
this.mod.config.setLeftDeadZone(newValue); this.config.setLeftDeadZone(newValue);
} }
}, option -> { }, option -> {
String value = String.valueOf(option.get()); String value = String.valueOf(option.get());
return option.getDisplayText(new LiteralText(value.substring(0, Math.min(value.length(), 5)))); return option.getDisplayText(new LiteralText(value.substring(0, Math.min(value.length(), 5))));
}, new TranslatableText("lambdacontrols.tooltip.left_dead_zone")); }, 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 -> { newValue -> {
synchronized (this.mod.config) { synchronized (this.config) {
this.mod.config.setInvertRightXAxis(newValue); this.config.setInvertRightXAxis(newValue);
} }
}, null); }, 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 -> { newValue -> {
synchronized (this.mod.config) { synchronized (this.config) {
this.mod.config.setInvertRightYAxis(newValue); this.config.setInvertRightYAxis(newValue);
} }
}, null); }, null);
this.unfocusedInputOption = new SpruceToggleBooleanOption("lambdacontrols.menu.unfocused_input", this.mod.config::hasUnfocusedInput, this.unfocusedInputOption = new SpruceToggleBooleanOption("lambdacontrols.menu.unfocused_input", this.config::hasUnfocusedInput,
this.mod.config::setUnfocusedInput, new TranslatableText("lambdacontrols.tooltip.unfocused_input")); this.config::setUnfocusedInput, new TranslatableText("lambdacontrols.tooltip.unfocused_input"));
this.virtualMouseOption = new SpruceToggleBooleanOption("lambdacontrols.menu.virtual_mouse", this.mod.config::hasVirtualMouse, this.virtualMouseOption = new SpruceToggleBooleanOption("lambdacontrols.menu.virtual_mouse", this.config::hasVirtualMouse,
this.mod.config::setVirtualMouse, new TranslatableText("lambdacontrols.tooltip.virtual_mouse")); this.config::setVirtualMouse, new TranslatableText("lambdacontrols.tooltip.virtual_mouse"));
} }
@Override @Override
public void removed() { public void removed() {
this.mod.config.save(); this.config.save();
super.removed(); super.removed();
} }
@Override @Override
public void onClose() { public void onClose() {
this.mod.config.save(); this.config.save();
super.onClose(); super.onClose();
} }
@@ -338,6 +376,9 @@ public class LambdaControlsSettingsScreen extends SpruceScreen {
list.addOptionEntry(this.invertsRightXAxis, this.invertsRightYAxis); list.addOptionEntry(this.invertsRightXAxis, this.invertsRightYAxis);
list.addSingleOptionEntry(this.rightDeadZoneOption); list.addSingleOptionEntry(this.rightDeadZoneOption);
list.addSingleOptionEntry(this.leftDeadZoneOption); list.addSingleOptionEntry(this.leftDeadZoneOption);
for (SpruceOption option : this.maxAnalogValueOptions) {
list.addSingleOptionEntry(option);
}
root.addChild(list); root.addChild(list);
root.addChild(labels); root.addChild(labels);

View File

@@ -95,6 +95,10 @@
"lambdacontrols.menu.keyboard_controls": "Keyboard Controls...", "lambdacontrols.menu.keyboard_controls": "Keyboard Controls...",
"lambdacontrols.menu.left_dead_zone": "Left Dead Zone", "lambdacontrols.menu.left_dead_zone": "Left Dead Zone",
"lambdacontrols.menu.mappings.open_input_str": "Open Mappings File Editor", "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.mouse_speed": "Mouse Speed",
"lambdacontrols.menu.reacharound.horizontal": "Front Block Placing", "lambdacontrols.menu.reacharound.horizontal": "Front Block Placing",
"lambdacontrols.menu.reacharound.vertical": "Vertical Reacharound", "lambdacontrols.menu.reacharound.vertical": "Vertical Reacharound",
@@ -127,6 +131,10 @@
"lambdacontrols.tooltip.hud_enable": "Toggles the on-screen controller button indicator.", "lambdacontrols.tooltip.hud_enable": "Toggles the on-screen controller button indicator.",
"lambdacontrols.tooltip.hud_side": "The position of the HUD.", "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.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.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.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.", "lambdacontrols.tooltip.reacharound.vertical": "Enables vertical reacharound, §cmight be considered cheating on some servers§r.",

View File

@@ -95,6 +95,10 @@
"lambdacontrols.menu.keyboard_controls": "Contrôles clavier...", "lambdacontrols.menu.keyboard_controls": "Contrôles clavier...",
"lambdacontrols.menu.left_dead_zone": "Zone morte axe gauche", "lambdacontrols.menu.left_dead_zone": "Zone morte axe gauche",
"lambdacontrols.menu.mappings.open_input_str": "Ouvrir l'éditeur de fichier des manettes", "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.mouse_speed": "Vitesse de la souris",
"lambdacontrols.menu.reacharound.horizontal": "Placement avant de bloc", "lambdacontrols.menu.reacharound.horizontal": "Placement avant de bloc",
"lambdacontrols.menu.reacharound.vertical": "Placement vertical", "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_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.hud_side": "Change la position du HUD.",
"lambdacontrols.tooltip.left_dead_zone": "Zone morte de l'axe gauche de la manette.", "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.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.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.", "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.",

View File

@@ -95,6 +95,10 @@
"lambdacontrols.menu.keyboard_controls": "Contrôles clavier...", "lambdacontrols.menu.keyboard_controls": "Contrôles clavier...",
"lambdacontrols.menu.left_dead_zone": "Zone morte axe gauche", "lambdacontrols.menu.left_dead_zone": "Zone morte axe gauche",
"lambdacontrols.menu.mappings.open_input_str": "Ouvrir l'éditeur de fichier des manettes", "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.mouse_speed": "Vitesse de la souris",
"lambdacontrols.menu.reacharound.horizontal": "Placement avant de bloc", "lambdacontrols.menu.reacharound.horizontal": "Placement avant de bloc",
"lambdacontrols.menu.reacharound.vertical": "Placement vertical", "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_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.hud_side": "Change la position du HUD.",
"lambdacontrols.tooltip.left_dead_zone": "Zone morte de l'axe gauche de la manette.", "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.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.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.", "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.",