mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 10:47:30 +00:00
Fixed KeyPreset not fully respecting SHIFT/ALT/CTRL modifiers + removed redundant code
This commit is contained in:
1 parent
1ac7c0e797
commit
950a749be6
2 files changed
+3
-37
No files matched your search
@@ -8,7 +8,7 @@ import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class KeyPreset implements Comparable<KeyPreset> {
|
||||
public class KeyPreset {
|
||||
/**
|
||||
* @field SINGLE_PRESS => on releasing before 5 ticks press time
|
||||
* @field PRESS_RELEASE => on pressing and releasing
|
||||
@@ -58,8 +58,7 @@ public class KeyPreset implements Comparable<KeyPreset> {
|
||||
return;
|
||||
|
||||
boolean isDown = isMouseKey() ? Mouse.isButtonDown(keyCode + 100) : Keyboard.isKeyDown(keyCode);
|
||||
isDown = isDown && (hasCtrl() ? isCtrlKeyDown() : true) && (hasAlt() ? isAltKeyDown() : true) && (hasShift() ? isShiftKeyDown() : true);
|
||||
|
||||
isDown = isDown && (isCtrlKeyDown() == hasCtrl()) && (isAltKeyDown() == hasAlt()) && (isShiftKeyDown() == hasShift());
|
||||
setDown(isDown);
|
||||
}
|
||||
|
||||
@@ -148,27 +147,6 @@ public class KeyPreset implements Comparable<KeyPreset> {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(KeyPreset o) {
|
||||
int mySpecialCount = getSpecialKeyCount(this);
|
||||
int otherSpecialCount = getSpecialKeyCount(o);
|
||||
|
||||
return otherSpecialCount - mySpecialCount;
|
||||
}
|
||||
|
||||
private static int getSpecialKeyCount(KeyPreset preset) {
|
||||
int res = 0;
|
||||
if (preset.hasAlt())
|
||||
res += 1;
|
||||
if (preset.hasCtrl())
|
||||
res += 1;
|
||||
if (preset.hasShift())
|
||||
res += 1;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
public static class KeyState {
|
||||
public int keyCode = -1;
|
||||
public boolean hasCtrl, hasAlt, hasShift;
|
||||
|
||||
@@ -11,10 +11,8 @@ import java.util.List;
|
||||
|
||||
public class KeyPresetManager {
|
||||
public List<KeyPreset> keys = new ArrayList<>();
|
||||
public List<KeyPreset> keysSorted = new ArrayList<>();
|
||||
public String fileName;
|
||||
|
||||
private boolean wasSorted = false;
|
||||
|
||||
public KeyPresetManager(String fileName) {
|
||||
this.fileName = fileName;
|
||||
@@ -23,22 +21,12 @@ public class KeyPresetManager {
|
||||
public KeyPreset add(String name) {
|
||||
KeyPreset preset = new KeyPreset(name);
|
||||
keys.add(preset);
|
||||
keysSorted.add(preset);
|
||||
wasSorted = false;
|
||||
return preset;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
if (!wasSorted) {
|
||||
keysSorted.sort(KeyPreset::compareTo);
|
||||
wasSorted = true;
|
||||
}
|
||||
|
||||
for (KeyPreset key : keysSorted) {
|
||||
for (KeyPreset key : keys)
|
||||
key.tick();
|
||||
if (key.isDown && key.shouldConflict)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user