Skip to content

Commit 7d94650

Browse files
committed
fix: maxActivationInterval being evaluated for non-while-pressed actions
Previously, if maxActivationInterval was set to a non-zero value and afterwards the activation was switched to ACTIVATION_ON_PRESS or ACTIVATION_ON_RELEASE, the ui would display a zero value for maxActivationInterval while within profile the non-zero value would still be retained. Even worse, within ActivationIntervalAction.handleActivationInterval(), the non-zero value would cause hasMaxActivationInterval to be true. This commit fixes both of these issues by: 1. Moving the activation field into ActivationIntervalAction 2. Resetting maxActivationInterval to zero when the activation-setter is called and activation != WHILE_PRESSED 3. Only setting hasMaxActivationInterval = true if both maxActivationInterval is non-zero AND activation != WHILE_PRESSED
1 parent 8fffb5d commit 7d94650

File tree

5 files changed

+25
-45
lines changed

5 files changed

+25
-45
lines changed

src/main/java/de/bwravencl/controllerbuddy/input/action/ActivationIntervalAction.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import de.bwravencl.controllerbuddy.input.Input;
2020
import de.bwravencl.controllerbuddy.input.action.annotation.ActionProperty;
21+
import de.bwravencl.controllerbuddy.input.action.gui.ActivationEditorBuilder;
2122
import de.bwravencl.controllerbuddy.input.action.gui.ActivationIntervalEditorBuilder;
2223
import java.lang.constant.Constable;
2324

@@ -26,8 +27,11 @@ public abstract class ActivationIntervalAction<V extends Constable> extends Desc
2627

2728
public static final String MAX_ACTIVATION_INTERVAL_LABEL = "MAX_ACTIVATION_INTERVAL";
2829

30+
@ActionProperty(label = "ACTIVATION", editorBuilder = ActivationEditorBuilder.class, order = 11)
31+
Activation activation = Activation.WHILE_PRESSED;
32+
2933
@ActionProperty(label = "MIN_ACTIVATION_INTERVAL", editorBuilder = ActivationIntervalEditorBuilder.class, order = 500)
30-
protected int minActivationInterval;
34+
int minActivationInterval;
3135

3236
@ActionProperty(label = MAX_ACTIVATION_INTERVAL_LABEL, editorBuilder = ActivationIntervalEditorBuilder.class, order = 501)
3337
private int maxActivationInterval;
@@ -38,6 +42,15 @@ public abstract class ActivationIntervalAction<V extends Constable> extends Desc
3842

3943
private transient boolean wasUp = true;
4044

45+
public static boolean activationSupportsMaxInterval(final Activation activation) {
46+
return activation == Activation.WHILE_PRESSED;
47+
}
48+
49+
@Override
50+
public Activation getActivation() {
51+
return activation;
52+
}
53+
4154
public int getMaxActivationInterval() {
4255
return maxActivationInterval;
4356
}
@@ -48,7 +61,7 @@ public int getMinActivationInterval() {
4861

4962
boolean handleActivationInterval(final boolean hot) {
5063
final var hasMinActivationInterval = minActivationInterval > 0L;
51-
final var hasMaxActivationInterval = maxActivationInterval > 0L;
64+
final var hasMaxActivationInterval = maxActivationInterval > 0L && activationSupportsMaxInterval(activation);
5265

5366
if (hasMinActivationInterval || hasMaxActivationInterval) {
5467
final var currentTime = System.currentTimeMillis();
@@ -91,6 +104,15 @@ public void init(final Input input) {
91104
maxActivationTime = Long.MAX_VALUE;
92105
}
93106

107+
@Override
108+
public void setActivation(final Activation activation) {
109+
this.activation = activation;
110+
111+
if (!activationSupportsMaxInterval(activation)) {
112+
maxActivationInterval = 0;
113+
}
114+
}
115+
94116
public void setMaxActivationInterval(final int maxActivationInterval) {
95117
this.maxActivationInterval = maxActivationInterval;
96118
}

src/main/java/de/bwravencl/controllerbuddy/input/action/ToButtonAction.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import de.bwravencl.controllerbuddy.gui.Main;
2020
import de.bwravencl.controllerbuddy.input.Input;
2121
import de.bwravencl.controllerbuddy.input.action.annotation.ActionProperty;
22-
import de.bwravencl.controllerbuddy.input.action.gui.ActivationEditorBuilder;
2322
import de.bwravencl.controllerbuddy.input.action.gui.ButtonEditorBuilder;
2423
import de.bwravencl.controllerbuddy.input.action.gui.LongPressEditorBuilder;
2524
import java.lang.constant.Constable;
@@ -33,9 +32,6 @@ public abstract class ToButtonAction<V extends Constable> extends ActivationInte
3332

3433
private transient Activatable activatable;
3534

36-
@ActionProperty(label = "ACTIVATION", editorBuilder = ActivationEditorBuilder.class, order = 11)
37-
private Activation activation = Activation.WHILE_PRESSED;
38-
3935
@ActionProperty(label = "LONG_PRESS", editorBuilder = LongPressEditorBuilder.class, order = 400)
4036
private boolean longPress = DEFAULT_LONG_PRESS;
4137

@@ -46,11 +42,6 @@ public Activatable getActivatable() {
4642
return activatable;
4743
}
4844

49-
@Override
50-
public Activation getActivation() {
51-
return activation;
52-
}
53-
5445
public int getButtonId() {
5546
return buttonId;
5647
}
@@ -159,11 +150,6 @@ public void setActivatable(final Activatable activatable) {
159150
this.activatable = activatable;
160151
}
161152

162-
@Override
163-
public void setActivation(final Activation activation) {
164-
this.activation = activation;
165-
}
166-
167153
public void setButtonId(final int buttonId) {
168154
this.buttonId = buttonId;
169155
}

src/main/java/de/bwravencl/controllerbuddy/input/action/ToKeyAction.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import de.bwravencl.controllerbuddy.input.Input;
2121
import de.bwravencl.controllerbuddy.input.KeyStroke;
2222
import de.bwravencl.controllerbuddy.input.action.annotation.ActionProperty;
23-
import de.bwravencl.controllerbuddy.input.action.gui.ActivationEditorBuilder;
2423
import de.bwravencl.controllerbuddy.input.action.gui.KeystrokeEditorBuilder;
2524
import de.bwravencl.controllerbuddy.input.action.gui.LongPressEditorBuilder;
2625
import java.lang.constant.Constable;
@@ -31,9 +30,6 @@ abstract class ToKeyAction<V extends Constable> extends ActivationIntervalAction
3130

3231
private transient Activatable activatable;
3332

34-
@ActionProperty(label = "ACTIVATION", editorBuilder = ActivationEditorBuilder.class, order = 11)
35-
private Activation activation = Activation.WHILE_PRESSED;
36-
3733
@ActionProperty(label = "KEYSTROKE", editorBuilder = KeystrokeEditorBuilder.class, order = 10)
3834
private KeyStroke keystroke = new KeyStroke();
3935

@@ -55,11 +51,6 @@ public Activatable getActivatable() {
5551
return activatable;
5652
}
5753

58-
@Override
59-
public Activation getActivation() {
60-
return activation;
61-
}
62-
6354
@Override
6455
public String getDescription(final Input input) {
6556
if (!isDescriptionEmpty()) {
@@ -167,11 +158,6 @@ public void setActivatable(final Activatable activatable) {
167158
this.activatable = activatable;
168159
}
169160

170-
@Override
171-
public void setActivation(final Activation activation) {
172-
this.activation = activation;
173-
}
174-
175161
public void setKeystroke(final KeyStroke keystroke) {
176162
this.keystroke = keystroke;
177163
}

src/main/java/de/bwravencl/controllerbuddy/input/action/ToMouseButtonAction.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import de.bwravencl.controllerbuddy.gui.Main;
2020
import de.bwravencl.controllerbuddy.input.Input;
2121
import de.bwravencl.controllerbuddy.input.action.annotation.ActionProperty;
22-
import de.bwravencl.controllerbuddy.input.action.gui.ActivationEditorBuilder;
2322
import de.bwravencl.controllerbuddy.input.action.gui.LongPressEditorBuilder;
2423
import de.bwravencl.controllerbuddy.input.action.gui.MouseButtonEditorBuilder;
2524
import java.lang.constant.Constable;
@@ -32,9 +31,6 @@ abstract class ToMouseButtonAction<V extends Constable> extends ActivationInterv
3231

3332
private transient Activatable activatable;
3433

35-
@ActionProperty(label = "ACTIVATION", editorBuilder = ActivationEditorBuilder.class, order = 11)
36-
private Activation activation = Activation.WHILE_PRESSED;
37-
3834
@ActionProperty(label = "LONG_PRESS", editorBuilder = LongPressEditorBuilder.class, order = 400)
3935
private boolean longPress = DEFAULT_LONG_PRESS;
4036

@@ -48,11 +44,6 @@ public Activatable getActivatable() {
4844
return activatable;
4945
}
5046

51-
@Override
52-
public Activation getActivation() {
53-
return activation;
54-
}
55-
5647
@Override
5748
public String getDescription(final Input input) {
5849
if (!isDescriptionEmpty()) {
@@ -160,11 +151,6 @@ public void setActivatable(final Activatable activatable) {
160151
this.activatable = activatable;
161152
}
162153

163-
@Override
164-
public void setActivation(final Activation activation) {
165-
this.activation = activation;
166-
}
167-
168154
@Override
169155
public void setLongPress(final boolean longPress) {
170156
this.longPress = longPress;

src/main/java/de/bwravencl/controllerbuddy/input/action/gui/ActivationIntervalEditorBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public ActivationIntervalEditorBuilder(final EditActionsDialog editActionsDialog
3838
if (editActionsDialog.isCycleEditor()) {
3939
disable = true;
4040
} else if (action instanceof final IActivatableAction<?> activatableAction
41-
&& activatableAction.getActivation() != IActivatableAction.Activation.WHILE_PRESSED) {
41+
&& !ActivationIntervalAction.activationSupportsMaxInterval(activatableAction.getActivation())) {
4242
final var fieldToActionPropertyMap = EditActionsDialog
4343
.getFieldToActionPropertiesMap(ActivationIntervalAction.class);
4444
disable = fieldToActionPropertyMap.entrySet().stream().filter(e -> fieldName.equals(e.getKey().getName()))

0 commit comments

Comments
 (0)