diff --git a/src/main/java/de/bwravencl/controllerbuddy/input/action/AxisToAxisAction.java b/src/main/java/de/bwravencl/controllerbuddy/input/action/AxisToAxisAction.java index 89c648ed..0cc509bc 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/input/action/AxisToAxisAction.java +++ b/src/main/java/de/bwravencl/controllerbuddy/input/action/AxisToAxisAction.java @@ -20,24 +20,34 @@ import de.bwravencl.controllerbuddy.input.action.annotation.Action; import de.bwravencl.controllerbuddy.input.action.annotation.Action.ActionCategory; import de.bwravencl.controllerbuddy.input.action.annotation.ActionProperty; +import de.bwravencl.controllerbuddy.input.action.gui.AxisValueEditorBuilder; import de.bwravencl.controllerbuddy.input.action.gui.DeadZoneEditorBuilder; import de.bwravencl.controllerbuddy.input.action.gui.ExponentEditorBuilder; -import de.bwravencl.controllerbuddy.input.action.gui.InitialValueEditorBuilder; +import de.bwravencl.controllerbuddy.input.action.gui.MaxAxisValueEditorBuilder; +import de.bwravencl.controllerbuddy.input.action.gui.MinAxisValueEditorBuilder; @Action(label = "TO_AXIS_ACTION", category = ActionCategory.AXIS, order = 10) public class AxisToAxisAction extends ToAxisAction implements IAxisToAction, IInitializationAction { private static final float DEFAULT_INITIAL_VALUE = 0f; + private static final float DEFAULT_MIN_VALUE = -1f; + private static final float DEFAULT_MAX_VALUE = 1f; private static final float DEFAULT_DEAD_ZONE = 0f; private static final float DEFAULT_EXPONENT = 1f; @ActionProperty(label = "DEAD_ZONE", editorBuilder = DeadZoneEditorBuilder.class, order = 100) float deadZone = DEFAULT_DEAD_ZONE; - @ActionProperty(label = "EXPONENT", editorBuilder = ExponentEditorBuilder.class, order = 101) + @ActionProperty(label = "MIN_AXIS_VALUE", editorBuilder = MinAxisValueEditorBuilder.class, order = 101) + float minValue = DEFAULT_MIN_VALUE; + + @ActionProperty(label = "MAX_AXIS_VALUE", editorBuilder = MaxAxisValueEditorBuilder.class, order = 102) + float maxValue = DEFAULT_MAX_VALUE; + + @ActionProperty(label = "EXPONENT", editorBuilder = ExponentEditorBuilder.class, order = 103) float exponent = DEFAULT_EXPONENT; - @ActionProperty(label = "INITIAL_VALUE", editorBuilder = InitialValueEditorBuilder.class, order = 202) + @ActionProperty(label = "INITIAL_VALUE", editorBuilder = AxisValueEditorBuilder.class, order = 202) float initialValue = DEFAULT_INITIAL_VALUE; @Override @@ -50,7 +60,7 @@ public void doAction(final Input input, final int component, Float value) { value = 0f; } else { final float inMax; - if (exponent > 1f) { + if (exponent != 0f) { inMax = (float) Math.pow((1f - deadZone) * 100f, exponent); value = Math.signum(value) * (float) Math.pow((Math.abs(value) - deadZone) * 100f, exponent); @@ -59,9 +69,9 @@ public void doAction(final Input input, final int component, Float value) { } if (value >= 0f) { - value = Input.normalize(value, deadZone, inMax, 0f, 1f); + value = Input.normalize(value, deadZone, inMax, 0f, maxValue); } else { - value = Input.normalize(value, -inMax, -deadZone, -1f, 0f); + value = Input.normalize(value, -inMax, -deadZone, minValue, 0f); } } @@ -80,6 +90,14 @@ public float getInitialValue() { return initialValue; } + public float getMaxValue() { + return maxValue; + } + + public float getMinValue() { + return minValue; + } + @Override public void init(final Input input) { if (!input.isSkipAxisInitialization()) { @@ -98,4 +116,12 @@ public void setExponent(final float exponent) { public void setInitialValue(final float initialValue) { this.initialValue = initialValue; } + + public void setMaxValue(final float maxValue) { + this.maxValue = maxValue; + } + + public void setMinValue(final float minValue) { + this.minValue = minValue; + } } diff --git a/src/main/java/de/bwravencl/controllerbuddy/input/action/AxisToRelativeAxisAction.java b/src/main/java/de/bwravencl/controllerbuddy/input/action/AxisToRelativeAxisAction.java index 5e1dfe04..61d09173 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/input/action/AxisToRelativeAxisAction.java +++ b/src/main/java/de/bwravencl/controllerbuddy/input/action/AxisToRelativeAxisAction.java @@ -67,7 +67,11 @@ public void doAction(final Input input, final int component, final Float value) final var runMode = input.getRunMode(); final var oldValue = Input.normalize( - input.getAxes().get(virtualAxis), runMode.getMinAxisValue(), runMode.getMaxAxisValue(), -1f, 1f); + input.getAxes().get(virtualAxis), + runMode.getMinAxisValue(), + runMode.getMaxAxisValue(), + minValue, + maxValue); input.setAxis(virtualAxis, oldValue + (invert ? -d : d), hapticFeedback, detentValue); } diff --git a/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/AxisValueEditorBuilder.java b/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/AxisValueEditorBuilder.java index 732419ad..c754d352 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/AxisValueEditorBuilder.java +++ b/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/AxisValueEditorBuilder.java @@ -20,7 +20,7 @@ import de.bwravencl.controllerbuddy.input.action.IAction; import java.lang.reflect.InvocationTargetException; -public final class AxisValueEditorBuilder extends NumberEditorBuilder { +public class AxisValueEditorBuilder extends NumberEditorBuilder { public AxisValueEditorBuilder( final EditActionsDialog editActionsDialog, diff --git a/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/ExponentEditorBuilder.java b/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/ExponentEditorBuilder.java index 9cd12c3b..fa6dbd95 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/ExponentEditorBuilder.java +++ b/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/ExponentEditorBuilder.java @@ -67,7 +67,7 @@ Comparable getMaximum() { @Override Comparable getMinimum() { - return 1f; + return 0.1f; } @Override diff --git a/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/InitialValueEditorBuilder.java b/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/MaxAxisValueEditorBuilder.java similarity index 80% rename from src/main/java/de/bwravencl/controllerbuddy/input/action/gui/InitialValueEditorBuilder.java rename to src/main/java/de/bwravencl/controllerbuddy/input/action/gui/MaxAxisValueEditorBuilder.java index 9a9bf7de..b4e8530e 100644 --- a/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/InitialValueEditorBuilder.java +++ b/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/MaxAxisValueEditorBuilder.java @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Matteo Hausner +/* Copyright (C) 2024 Matteo Hausner * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,9 +20,9 @@ import de.bwravencl.controllerbuddy.input.action.IAction; import java.lang.reflect.InvocationTargetException; -public final class InitialValueEditorBuilder extends NumberEditorBuilder { +public final class MaxAxisValueEditorBuilder extends AxisValueEditorBuilder { - public InitialValueEditorBuilder( + public MaxAxisValueEditorBuilder( final EditActionsDialog editActionsDialog, final IAction action, final String fieldName, @@ -32,18 +32,8 @@ public InitialValueEditorBuilder( super(editActionsDialog, action, fieldName, fieldType); } - @Override - Comparable getMaximum() { - return 1f; - } - @Override Comparable getMinimum() { - return -1f; - } - - @Override - Number getStepSize() { - return 0.05f; + return 0f; } } diff --git a/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/MinAxisValueEditorBuilder.java b/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/MinAxisValueEditorBuilder.java new file mode 100644 index 00000000..53e447eb --- /dev/null +++ b/src/main/java/de/bwravencl/controllerbuddy/input/action/gui/MinAxisValueEditorBuilder.java @@ -0,0 +1,39 @@ +/* Copyright (C) 2024 Matteo Hausner + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package de.bwravencl.controllerbuddy.input.action.gui; + +import de.bwravencl.controllerbuddy.gui.EditActionsDialog; +import de.bwravencl.controllerbuddy.input.action.IAction; +import java.lang.reflect.InvocationTargetException; + +public final class MinAxisValueEditorBuilder extends AxisValueEditorBuilder { + + public MinAxisValueEditorBuilder( + final EditActionsDialog editActionsDialog, + final IAction action, + final String fieldName, + final Class fieldType) + throws SecurityException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, + InvocationTargetException { + super(editActionsDialog, action, fieldName, fieldType); + } + + @Override + Comparable getMaximum() { + return 0f; + } +}