Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit a32f9de

Browse files
committed
fix scaling bug on KeystrokePositioningScreens
1 parent c1fc4ff commit a32f9de

File tree

37 files changed

+216
-724
lines changed

37 files changed

+216
-724
lines changed

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/HudManager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,11 @@ public void saveCustomEntries() {
176176
if (hudEntry instanceof CustomHudEntry hud) {
177177
json.beginObject();
178178
for (Option<?> opt : hud.getCategory().getOptions()) {
179-
json.name(opt.getName());
180-
json.value(opt.toSerializedValue());
179+
var value = opt.toSerializedValue();
180+
if (value != null) {
181+
json.name(opt.getName());
182+
json.value(value);
183+
}
181184
}
182185
json.endObject();
183186
}

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/gui/hud/KeystrokeHud.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ public LabelKeystroke(Rectangle bounds, DrawPosition offset, KeyBinding key, Str
403403

404404
drawString(matrices, getLabel(), (int) x, (int) y, stroke.getFGColor().toInt(), shadow.get());
405405
};
406-
this.synchronizeLabel = synchronizeLabel;
406+
setSynchronizeLabel(synchronizeLabel);
407407
}
408408

409409
@Override

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/gui/keystrokes/KeyBindsList.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ public class KeyBindsList extends ElementListWidget<KeyBindsList.Entry> {
4242
final KeystrokesScreen keyBindsScreen;
4343
private int maxNameWidth;
4444

45-
public KeyBindsList(KeystrokesScreen keyBindsScreen, List<KeystrokeHud.Keystroke> keys) {
45+
public KeyBindsList(KeystrokesScreen keyBindsScreen) {
4646
super(MinecraftClient.getInstance(), keyBindsScreen.width, keyBindsScreen.height, 33, keyBindsScreen.height-33, 24);
4747
this.keyBindsScreen = keyBindsScreen;
4848

49-
reload(keys);
49+
reload();
5050
}
5151

52-
public void reload(List<KeystrokeHud.Keystroke> keys) {
52+
public void reload() {
5353
clearEntries();
54-
for (KeystrokeHud.Keystroke keyMapping : keys) {
54+
for (KeystrokeHud.Keystroke keyMapping : keyBindsScreen.hud.keystrokes) {
5555

5656
Text component = new TranslatableText(keyMapping.getKey().getTranslationKey());
5757
int i = client.textRenderer.getWidth(component);

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/gui/keystrokes/KeystrokePositioningScreen.java

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -88,31 +88,29 @@ public void render(MatrixStack guiGraphics, int mouseX, int mouseY, float partia
8888
fillGradient(guiGraphics, 0, 0, this.width, this.height, -1072689136, -804253680);
8989
super.render(guiGraphics, mouseX, mouseY, partialTick);
9090
if (editing != null) {
91-
var rect = editing.getRenderPosition();
92-
if (rect.isMouseOver(mouseX, mouseY)) {
93-
DrawUtil.fillRect(guiGraphics, rect, ClientColors.SELECTOR_BLUE.withAlpha(100));
94-
} else {
95-
DrawUtil.fillRect(guiGraphics, rect, ClientColors.WHITE.withAlpha(50));
96-
}
97-
editing.render(guiGraphics);
98-
DrawUtil.outlineRect(guiGraphics, rect, Colors.BLACK);
91+
drawStroke(guiGraphics, mouseX, mouseY, editing);
9992
} else {
100-
hud.keystrokes.forEach(s -> {
101-
var rect = s.getRenderPosition();
102-
if (rect.isMouseOver(mouseX, mouseY)) {
103-
DrawUtil.fillRect(guiGraphics, rect, ClientColors.SELECTOR_BLUE.withAlpha(100));
104-
} else {
105-
DrawUtil.fillRect(guiGraphics, rect, ClientColors.WHITE.withAlpha(50));
106-
}
107-
s.render(guiGraphics);
108-
DrawUtil.outlineRect(guiGraphics, rect, Colors.BLACK);
109-
});
93+
hud.keystrokes.forEach(s -> drawStroke(guiGraphics, mouseX, mouseY, s));
11094
}
11195
if (mouseDown && snap != null) {
11296
snap.renderSnaps(guiGraphics);
11397
}
11498
}
11599

100+
private void drawStroke(MatrixStack guiGraphics, int mouseX, int mouseY, KeystrokeHud.Keystroke s) {
101+
var rect = getScaledRenderPos(s);
102+
if (rect.isMouseOver(mouseX, mouseY)) {
103+
DrawUtil.fillRect(guiGraphics, rect, ClientColors.SELECTOR_BLUE.withAlpha(100));
104+
} else {
105+
DrawUtil.fillRect(guiGraphics, rect, ClientColors.WHITE.withAlpha(50));
106+
}
107+
guiGraphics.push();
108+
guiGraphics.scale(hud.getScale(), hud.getScale(), 1);
109+
s.render(guiGraphics);
110+
guiGraphics.pop();
111+
DrawUtil.outlineRect(guiGraphics, rect, Colors.BLACK);
112+
}
113+
116114
@Override
117115
public boolean mouseClicked(double mouseX, double mouseY, int button) {
118116
var value = super.mouseClicked(mouseX, mouseY, button);
@@ -121,14 +119,14 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
121119
Optional<Rectangle> pos = Optional.empty();
122120
if (editing == null) {
123121
for (KeystrokeHud.Keystroke k : hud.keystrokes) {
124-
pos = Optional.of(k.getRenderPosition());
122+
pos = Optional.of(getScaledRenderPos(k));
125123
if (pos.get().isMouseOver(mouseX, mouseY)) {
126124
entry = Optional.of(k);
127125
break;
128126
}
129127
}
130128
} else {
131-
pos = Optional.of(editing.getRenderPosition());
129+
pos = Optional.of(getScaledRenderPos(editing));
132130
if (pos.get().isMouseOver(mouseX, mouseY)) {
133131
entry = Optional.of(editing);
134132
}
@@ -168,31 +166,35 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) {
168166
@Override
169167
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
170168
if (focused != null && mouseDown) {
171-
focused.setX((int) mouseX - offset.x());
172-
focused.setY((int) mouseY - offset.y());
169+
focused.setX((int) Math.round((mouseX - offset.x())/hud.getScale()));
170+
focused.setY((int) Math.round((mouseY - offset.y())/hud.getScale()));
173171
if (snap != null) {
174172
Integer snapX, snapY;
175-
var rect = focused.getRenderPosition();
173+
var rect = getScaledRenderPos(focused);
176174
snap.setCurrent(rect);
177175
if ((snapX = snap.getCurrentXSnap()) != null) {
178-
focused.setX(snapX);
176+
focused.setX((int) (snapX/hud.getScale()));
179177
}
180178
if ((snapY = snap.getCurrentYSnap()) != null) {
181-
focused.setY(snapY);
179+
focused.setY(Math.round(snapY/hud.getScale()));
182180
}
183181
}
184182
return true;
185183
}
186184
return false;
187185
}
188186

187+
private Rectangle getScaledRenderPos(KeystrokeHud.Keystroke stroke) {
188+
return stroke.getRenderPosition().scale(hud.getScale());
189+
}
190+
189191
private List<Rectangle> getAllBounds() {
190-
return Stream.concat(HudManager.getInstance().getAllBounds().stream(), hud.keystrokes.stream().map(KeystrokeHud.Keystroke::getRenderPosition)).toList();
192+
return Stream.concat(HudManager.getInstance().getAllBounds().stream(), hud.keystrokes.stream().map(this::getScaledRenderPos)).toList();
191193
}
192194

193195
private void updateSnapState() {
194196
if (HudEditScreen.isSnappingEnabled() && focused != null) {
195-
snap = new SnappingHelper(getAllBounds(), focused.getRenderPosition());
197+
snap = new SnappingHelper(getAllBounds(), getScaledRenderPos(focused));
196198
} else if (snap != null) {
197199
snap = null;
198200
}

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/gui/keystrokes/KeystrokesScreen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ public void render(MatrixStack graphics, int mouseX, int mouseY, float delta) {
5858
public void init() {
5959
super.init();
6060

61-
var keyBindsList = addDrawableChild(new KeyBindsList(this, keys));
61+
var keyBindsList = addDrawableChild(new KeyBindsList(this));
6262
addDrawableChild(new ButtonWidget(width / 2 - 150 - 4, height - 33 / 2 - 10, 150, 20,
6363
new TranslatableText("controls.resetAll"), button -> {
6464
keys.clear();
6565
hud.setDefaultKeystrokes();
66-
keyBindsList.reload(keys);
66+
keyBindsList.reload();
6767
hud.saveKeystrokes();
6868
}));
6969
addDrawableChild(new ButtonWidget(width / 2 + 4, height - 33 / 2 - 10, 150, 20, ScreenTexts.DONE, button -> this.onClose()));

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/hud/util/Rectangle.java

Lines changed: 0 additions & 78 deletions
This file was deleted.

1.20/src/main/java/io/github/axolotlclient/modules/hud/HudManager.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,11 @@ public void saveCustomEntries() {
169169
if (hudEntry instanceof CustomHudEntry hud) {
170170
json.beginObject();
171171
for (Option<?> opt : hud.getCategory().getOptions()) {
172-
json.name(opt.getName());
173-
json.value(opt.toSerializedValue());
172+
var value = opt.toSerializedValue();
173+
if (value != null) {
174+
json.name(opt.getName());
175+
json.value(value);
176+
}
174177
}
175178
json.endObject();
176179
}

1.20/src/main/java/io/github/axolotlclient/modules/hud/gui/hud/KeystrokeHud.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ public LabelKeystroke(Rectangle bounds, DrawPosition offset, KeyBind key, String
403403

404404
drawString(matrices, getLabel(), (int) x, (int) y, stroke.getFGColor().toInt(), shadow.get());
405405
};
406-
this.synchronizeLabel = synchronizeLabel;
406+
setSynchronizeLabel(synchronizeLabel);
407407
}
408408

409409
@Override

1.20/src/main/java/io/github/axolotlclient/modules/hud/gui/keystrokes/KeyBindsList.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ public class KeyBindsList extends ElementListWidget<KeyBindsList.Entry> {
4545
final KeystrokesScreen keyBindsScreen;
4646
private int maxNameWidth;
4747

48-
public KeyBindsList(KeystrokesScreen keyBindsScreen, List<KeystrokeHud.Keystroke> keys) {
48+
public KeyBindsList(KeystrokesScreen keyBindsScreen) {
4949
super(MinecraftClient.getInstance(), keyBindsScreen.width, keyBindsScreen.height, 33, keyBindsScreen.height-33, 24);
5050
this.keyBindsScreen = keyBindsScreen;
5151

52-
reload(keys);
52+
reload();
5353
}
5454

55-
public void reload(List<KeystrokeHud.Keystroke> keys) {
55+
public void reload() {
5656
clearEntries();
57-
for (KeystrokeHud.Keystroke keyMapping : keys) {
57+
for (KeystrokeHud.Keystroke keyMapping : keyBindsScreen.hud.keystrokes) {
5858

5959
Text component = Text.translatable(keyMapping.getKey().getTranslationKey());
6060
int i = client.textRenderer.getWidth(component);

1.20/src/main/java/io/github/axolotlclient/modules/hud/gui/keystrokes/KeystrokePositioningScreen.java

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -87,31 +87,29 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partia
8787
guiGraphics.fillGradient(0, 0, this.width, this.height, -1072689136, -804253680);
8888
super.render(guiGraphics, mouseX, mouseY, partialTick);
8989
if (editing != null) {
90-
var rect = editing.getRenderPosition();
91-
if (rect.isMouseOver(mouseX, mouseY)) {
92-
DrawUtil.fillRect(guiGraphics, rect, ClientColors.SELECTOR_BLUE.withAlpha(100));
93-
} else {
94-
DrawUtil.fillRect(guiGraphics, rect, ClientColors.WHITE.withAlpha(50));
95-
}
96-
editing.render(guiGraphics);
97-
DrawUtil.outlineRect(guiGraphics, rect, Colors.BLACK);
90+
drawStroke(guiGraphics, mouseX, mouseY, editing);
9891
} else {
99-
hud.keystrokes.forEach(s -> {
100-
var rect = s.getRenderPosition();
101-
if (rect.isMouseOver(mouseX, mouseY)) {
102-
DrawUtil.fillRect(guiGraphics, rect, ClientColors.SELECTOR_BLUE.withAlpha(100));
103-
} else {
104-
DrawUtil.fillRect(guiGraphics, rect, ClientColors.WHITE.withAlpha(50));
105-
}
106-
s.render(guiGraphics);
107-
DrawUtil.outlineRect(guiGraphics, rect, Colors.BLACK);
108-
});
92+
hud.keystrokes.forEach(s -> drawStroke(guiGraphics, mouseX, mouseY, s));
10993
}
11094
if (mouseDown && snap != null) {
11195
snap.renderSnaps(guiGraphics);
11296
}
11397
}
11498

99+
private void drawStroke(GuiGraphics guiGraphics, int mouseX, int mouseY, KeystrokeHud.Keystroke s) {
100+
var rect = getScaledRenderPos(s);
101+
if (rect.isMouseOver(mouseX, mouseY)) {
102+
DrawUtil.fillRect(guiGraphics, rect, ClientColors.SELECTOR_BLUE.withAlpha(100));
103+
} else {
104+
DrawUtil.fillRect(guiGraphics, rect, ClientColors.WHITE.withAlpha(50));
105+
}
106+
guiGraphics.getMatrices().push();
107+
guiGraphics.getMatrices().scale(hud.getScale(), hud.getScale(), 1);
108+
s.render(guiGraphics);
109+
guiGraphics.getMatrices().pop();
110+
DrawUtil.outlineRect(guiGraphics, rect, Colors.BLACK);
111+
}
112+
115113
@Override
116114
public boolean mouseClicked(double mouseX, double mouseY, int button) {
117115
var value = super.mouseClicked(mouseX, mouseY, button);
@@ -120,14 +118,14 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
120118
Optional<Rectangle> pos = Optional.empty();
121119
if (editing == null) {
122120
for (KeystrokeHud.Keystroke k : hud.keystrokes) {
123-
pos = Optional.of(k.getRenderPosition());
121+
pos = Optional.of(getScaledRenderPos(k));
124122
if (pos.get().isMouseOver(mouseX, mouseY)) {
125123
entry = Optional.of(k);
126124
break;
127125
}
128126
}
129127
} else {
130-
pos = Optional.of(editing.getRenderPosition());
128+
pos = Optional.of(getScaledRenderPos(editing));
131129
if (pos.get().isMouseOver(mouseX, mouseY)) {
132130
entry = Optional.of(editing);
133131
}
@@ -167,31 +165,35 @@ public boolean mouseReleased(double mouseX, double mouseY, int button) {
167165
@Override
168166
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
169167
if (focused != null && mouseDown) {
170-
focused.setX((int) mouseX - offset.x());
171-
focused.setY((int) mouseY - offset.y());
168+
focused.setX((int) Math.round((mouseX - offset.x())/hud.getScale()));
169+
focused.setY((int) Math.round((mouseY - offset.y())/hud.getScale()));
172170
if (snap != null) {
173171
Integer snapX, snapY;
174-
var rect = focused.getRenderPosition();
172+
var rect = getScaledRenderPos(focused);
175173
snap.setCurrent(rect);
176174
if ((snapX = snap.getCurrentXSnap()) != null) {
177-
focused.setX(snapX);
175+
focused.setX((int) (snapX/hud.getScale()));
178176
}
179177
if ((snapY = snap.getCurrentYSnap()) != null) {
180-
focused.setY(snapY);
178+
focused.setY(Math.round(snapY/hud.getScale()));
181179
}
182180
}
183181
return true;
184182
}
185183
return false;
186184
}
187185

186+
private Rectangle getScaledRenderPos(KeystrokeHud.Keystroke stroke) {
187+
return stroke.getRenderPosition().scale(hud.getScale());
188+
}
189+
188190
private List<Rectangle> getAllBounds() {
189-
return Stream.concat(HudManager.getInstance().getAllBounds().stream(), hud.keystrokes.stream().map(KeystrokeHud.Keystroke::getRenderPosition)).toList();
191+
return Stream.concat(HudManager.getInstance().getAllBounds().stream(), hud.keystrokes.stream().map(this::getScaledRenderPos)).toList();
190192
}
191193

192194
private void updateSnapState() {
193195
if (HudEditScreen.isSnappingEnabled() && focused != null) {
194-
snap = new SnappingHelper(getAllBounds(), focused.getRenderPosition());
196+
snap = new SnappingHelper(getAllBounds(), getScaledRenderPos(focused));
195197
} else if (snap != null) {
196198
snap = null;
197199
}

0 commit comments

Comments
 (0)