Skip to content

Commit c830f6c

Browse files
committed
fix callback issue, fix input issues (maybe)
1 parent 0204fca commit c830f6c

File tree

4 files changed

+39
-24
lines changed

4 files changed

+39
-24
lines changed

modules/config/src/main/java/org/polyfrost/oneconfig/api/config/v1/Property.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,20 @@ public final void set(@Nullable T value) {
214214
*/
215215
public void setReferential(@Nullable T value) {
216216
if (callbacks != null) {
217+
T prev = get();
218+
set0(value);
217219
for (Predicate<T> p : callbacks) {
218220
try {
219221
if (p.test(value)) {
220222
LOGGER.info("property {} set cancelled by {}", this.getID(), p);
223+
set0(prev);
221224
return;
222225
}
223226
} catch (Throwable t) {
224227
LOGGER.error("failed to call cancellable callback {} on property {}", p, this.getID(), t);
225228
}
226229
}
227-
}
228-
set0(value);
230+
} else set0(value);
229231
}
230232

231233
protected abstract void set0(@Nullable T value);

modules/hud/src/main/kotlin/org/polyfrost/oneconfig/api/hud/v1/HudManager.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,14 @@ object HudManager {
117117
LOGGER.info("Initializing HUD...")
118118
val now = System.nanoTime()
119119
Runtime.getRuntime().addShutdownHook(Thread {
120+
LOGGER.info("Saving size lock as ${polyUI.size}")
120121
ConfigManager.internal().folder.resolve("size.lock").writeText(polyUI.size.value.toString())
121122
})
122123
val sizeFile = ConfigManager.internal().folder.resolve("size.lock")
123124
val size = Vec2(if (sizeFile.exists()) sizeFile.readText().toLongOrNull() ?: 0L else 0L)
124125
val prevSize: Vec2
125126
if (size.isPositive) {
127+
LOGGER.info("Size to restore: $size")
126128
prevSize = polyUI.size
127129
polyUI.resize(size.x, size.y)
128130
} else {

modules/ui/src/main/kotlin/org/polyfrost/oneconfig/api/ui/v1/keybind/KeybindManager.kt

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -112,29 +112,29 @@ object KeybindManager {
112112
@JvmStatic
113113
fun translateKey(inputManager: InputManager, key: Int, character: Char, state: Boolean) {
114114
if (character != '\u0000' && !character.isISOControl() && character.isDefined()) {
115-
inputManager.keyTyped(character)
115+
if (state) {
116+
inputManager.keyTyped(character)
117+
inputManager.keyDown(character.code)
118+
} else inputManager.keyUp(character.code)
119+
return
116120
}
117121

118-
if (state) {
119-
keysMap[key]?.let { inputManager.keyDown(it); return }
120-
val m = modsMap[key]
121-
if (m != 0) {
122-
inputManager.addModifier(m.toByte())
123-
return
124-
}
125-
// modern fix because glfwModCharCallback doesn't work correctly
126-
if (inputManager.mods > 1 && key < 255) {
127-
inputManager.keyTyped((key + 32).toChar())
128-
} else inputManager.keyDown(key)
129-
} else {
130-
keysMap[key]?.let { inputManager.keyUp(it); return }
131-
val m = modsMap[key]
132-
if (m != 0) {
133-
inputManager.removeModifier(m.toByte())
134-
return
135-
}
136-
inputManager.keyUp(key)
122+
val k = keysMap[key]
123+
if (k != null) {
124+
if (state) inputManager.keyDown(k)
125+
else inputManager.keyUp(k)
126+
return
137127
}
138128

129+
val m = modsMap[key].toByte()
130+
if (m != 0.toByte()) {
131+
if (state) inputManager.addModifier(m)
132+
else inputManager.removeModifier(m)
133+
return
134+
}
135+
136+
val raw = if (inputManager.mods > 1) key + 48 else key
137+
if (state) inputManager.keyDown(raw)
138+
else inputManager.keyUp(raw)
139139
}
140140
}

versions/src/main/java/org/polyfrost/oneconfig/test/TestConfig_Test.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@
2626

2727
package org.polyfrost.oneconfig.test;
2828

29+
import kotlin.Unit;
2930
import org.polyfrost.oneconfig.api.config.v1.Config;
3031
import org.polyfrost.oneconfig.api.config.v1.annotations.Number;
3132
import org.polyfrost.oneconfig.api.config.v1.annotations.*;
33+
import org.polyfrost.oneconfig.api.ui.v1.Notifications;
34+
import org.polyfrost.oneconfig.api.ui.v1.keybind.OCKeybindHelper;
35+
import org.polyfrost.polyui.color.ColorUtils;
3236
import org.polyfrost.polyui.color.PolyColor;
37+
import org.polyfrost.polyui.input.KeyBinder;
38+
import org.polyfrost.polyui.input.KeyModifiers;
3339
import org.polyfrost.polyui.unit.Align;
34-
import org.polyfrost.polyui.color.ColorUtils;
3540
import org.polyfrost.universal.UChat;
3641

3742
@SuppressWarnings("unused")
@@ -47,7 +52,7 @@ public class TestConfig_Test extends Config {
4752
@Number(title = "number", unit = "px", category = "bob")
4853
public static int number = 50;
4954

50-
// @Keybind(title = "keybinding", description = "please send help")
55+
// @Keybind(title = "keybinding", description = "please send help")
5156
// KeyBinder.Bind bind0 = new KeyBinder.Bind('A', null, null, Modifiers.mods(Modifiers.LCONTROL, Modifiers.LSHIFT), () -> {
5257
// UChat.chat("you pressed a bind");
5358
// return true;
@@ -87,6 +92,12 @@ public class TestConfig_Test extends Config {
8792
@Color(title = "color", category = "bob")
8893
PolyColor color = ColorUtils.rgba(255, 0, 100, 1f);
8994

95+
@Keybind(title = "keybind")
96+
private KeyBinder.Bind bind = ((OCKeybindHelper) OCKeybindHelper.builder().mods(KeyModifiers.CONTROL).chars('g').does((a) -> {
97+
Notifications.enqueue(Notifications.Type.Info, "state: " + a);
98+
return Unit.INSTANCE;
99+
})).register();
100+
90101
public TestConfig_Test() {
91102
super("test_mod.json", "Test Mod", Category.QOL);
92103
addDependency("c3ow", "c2ow");

0 commit comments

Comments
 (0)