Skip to content

Commit f8c6d90

Browse files
committed
fix: stabilize ui scaling and config persistence
1 parent ce4dfd7 commit f8c6d90

40 files changed

Lines changed: 1134 additions & 520 deletions

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/top/fpsmaster/features/GlobalListener.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ public void onChat(EventPacket e) {
4545
public void onChatSend(EventSendChatMessage e) {
4646
}
4747

48+
@Subscribe
49+
public void onValueChange(EventValueChange e) {
50+
if (!FPSMaster.configManager.isLoadingConfig()) {
51+
FPSMaster.configManager.saveConfigQuietly("default");
52+
}
53+
}
54+
4855

4956
Thread tickThread;
5057

src/main/java/top/fpsmaster/features/impl/interfaces/ClientSettings.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class ClientSettings extends InterfaceModule {
3030
};
3131
public static ModeSetting fixedScale = new ModeSetting(
3232
"FixedScale",
33-
2,
33+
5,
3434
() -> fixedScaleEnabled.getValue(),
3535
"0.5x", "0.75x", "1x", "1.25x", "1.5x", "2x", "2.5x", "3x"
3636
);
@@ -41,17 +41,24 @@ public static boolean isFixedScaleEnabled() {
4141
return fixedScaleEnabled.getValue();
4242
}
4343

44-
public static double getUiScale() {
45-
ScaledResolution scaledResolution = new ScaledResolution(mc);
46-
int vanillaScale = scaledResolution.getScaleFactor();
44+
public static double getUiScaleMultiplier() {
4745
if (!fixedScaleEnabled.getValue()) {
48-
return vanillaScale;
46+
return 1.0;
4947
}
5048
int index = fixedScale.getValue();
5149
if (index < 0 || index >= SCALE_VALUES.length) {
52-
return vanillaScale;
50+
return 1.0;
5351
}
54-
return vanillaScale * SCALE_VALUES[index];
52+
return SCALE_VALUES[index];
53+
}
54+
55+
public static int getVanillaGuiScaleFactor() {
56+
ScaledResolution scaledResolution = new ScaledResolution(mc);
57+
return scaledResolution.getScaleFactor();
58+
}
59+
60+
public static double getUiScale() {
61+
return getVanillaGuiScaleFactor() * getUiScaleMultiplier();
5562
}
5663

5764
public ClientSettings() {

src/main/java/top/fpsmaster/features/impl/interfaces/Keystrokes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class Keystrokes extends InterfaceModule {
4040
public Keystrokes() {
4141
super("Keystrokes", Category.Interface);
4242
CPSDisplay.ensureTracking();
43+
roundRadius.setValue(2);
4344
addSettings(
4445
fontShadow, betterFont,
4546
pressedColor, fontColor, pressedFontColor,

src/main/java/top/fpsmaster/features/manager/Module.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public void set(boolean state) {
7373
2f
7474
);
7575
}
76+
saveModuleStateQuietly();
7677
} else if (!state && isEnabled){
7778
isEnabled = false;
7879
onDisable();
@@ -86,6 +87,7 @@ public void set(boolean state) {
8687
2f
8788
);
8889
}
90+
saveModuleStateQuietly();
8991
}
9092
} catch (Exception e) {
9193
ClientLogger.error("An error occurred while toggling module: " + this.name);
@@ -104,6 +106,13 @@ public void onDisable() {
104106
public boolean isEnabled() {
105107
return isEnabled;
106108
}
109+
110+
private void saveModuleStateQuietly() {
111+
if (FPSMaster.configManager == null || FPSMaster.configManager.isLoadingConfig()) {
112+
return;
113+
}
114+
FPSMaster.configManager.saveConfigQuietly("default");
115+
}
107116
}
108117

109118

src/main/java/top/fpsmaster/font/impl/UFontRenderer.java

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
import java.io.File;
1515
import java.io.InputStream;
1616
import java.nio.file.Files;
17+
18+
import org.lwjgl.opengl.GL11;
19+
1720
import static top.fpsmaster.utils.render.state.Alpha.apply;
1821

1922
public class UFontRenderer extends FontRenderer {
@@ -140,24 +143,44 @@ public static boolean isEmojiCharacter(int codePoint) {
140143
*/
141144
@Override
142145
public int drawString(String text, float x, float y, int color, boolean dropShadow) {
143-
if (UiScale.isActive()) {
144-
float scale = UiScale.getScale();
145-
int scaledSize = Math.max(1, Math.round(size * scale));
146-
UFontRenderer renderer = scaledSize == size ? this : FPSMaster.fontManager.getFont(scaledSize);
147-
return renderer.drawStringInternal(text, x * scale, y * scale, color, dropShadow);
146+
float densityScale = getDensityScale();
147+
if (densityScale > 1.0f) {
148+
return drawHighDensityString(text, x, y, color, dropShadow, densityScale);
148149
}
149150
return drawStringInternal(text, x, y, color, dropShadow);
150151
}
151152

153+
private int drawHighDensityString(String text, float x, float y, int color, boolean dropShadow, float densityScale) {
154+
UFontRenderer renderer = getDensityRenderer(densityScale);
155+
if (renderer == this) {
156+
return drawStringInternal(text, x, y, color, dropShadow);
157+
}
158+
159+
float actualDensityScale = renderer.size / (float) size;
160+
float inverseScale = 1.0f / actualDensityScale;
161+
GL11.glPushMatrix();
162+
GL11.glScalef(inverseScale, inverseScale, 1.0f);
163+
try {
164+
int result = renderer.drawStringInternal(text, x * actualDensityScale, y * actualDensityScale, color, dropShadow, actualDensityScale * 0.5f);
165+
return Math.round(result * inverseScale);
166+
} finally {
167+
GL11.glPopMatrix();
168+
}
169+
}
170+
152171
private int drawStringInternal(String text, float x, float y, int color, boolean dropShadow) {
172+
return drawStringInternal(text, x, y, color, dropShadow, 0.5f);
173+
}
174+
175+
private int drawStringInternal(String text, float x, float y, int color, boolean dropShadow, float shadowOffset) {
153176
color = apply(color);
154177
int i;
155178
if (dropShadow) {
156179
if (Colors.toColor(color).getAlpha() > 50) {
157180
stringCache.renderString(
158181
text,
159-
x + 0.5f,
160-
y + 0.5f,
182+
x + shadowOffset,
183+
y + shadowOffset,
161184
new Color(20, 20, 20, Colors.toColor(color).getAlpha()).getRGB(),
162185
true
163186
);
@@ -170,11 +193,13 @@ private int drawStringInternal(String text, float x, float y, int color, boolean
170193
@Override
171194
public int getStringWidth(String text) {
172195
text = GlobalTextFilter.filter(text);
173-
if (UiScale.isActive()) {
174-
float scale = UiScale.getScale();
175-
int scaledSize = Math.max(1, Math.round(size * scale));
176-
UFontRenderer renderer = scaledSize == size ? this : FPSMaster.fontManager.getFont(scaledSize);
177-
return Math.round(renderer.stringCache.getStringWidth(text) / scale);
196+
float densityScale = getDensityScale();
197+
if (densityScale > 1.0f) {
198+
UFontRenderer renderer = getDensityRenderer(densityScale);
199+
if (renderer != this) {
200+
float actualDensityScale = renderer.size / (float) size;
201+
return Math.round(renderer.stringCache.getStringWidth(text) / actualDensityScale);
202+
}
178203
}
179204
return stringCache.getStringWidth(text);
180205
}
@@ -184,15 +209,32 @@ public void drawCenteredString(String text, float x, float y, int color) {
184209
}
185210

186211
public int getHeight() {
187-
if (UiScale.isActive()) {
188-
float scale = UiScale.getScale();
189-
int scaledSize = Math.max(1, Math.round(size * scale));
190-
UFontRenderer renderer = scaledSize == size ? this : FPSMaster.fontManager.getFont(scaledSize);
191-
return Math.round(renderer.stringCache.height / 2f / scale);
212+
float densityScale = getDensityScale();
213+
if (densityScale > 1.0f) {
214+
UFontRenderer renderer = getDensityRenderer(densityScale);
215+
if (renderer != this) {
216+
float actualDensityScale = renderer.size / (float) size;
217+
return Math.round(renderer.stringCache.height / 2f / actualDensityScale);
218+
}
192219
}
193220
return stringCache.height / 2;
194221
}
195222

223+
private float getDensityScale() {
224+
if (!UiScale.isActive()) {
225+
return 1.0f;
226+
}
227+
return Math.max(1.0f, UiScale.getPixelScale());
228+
}
229+
230+
private UFontRenderer getDensityRenderer(float densityScale) {
231+
int scaledSize = Math.max(size, Math.round(size * densityScale));
232+
if (scaledSize == size) {
233+
return this;
234+
}
235+
return FPSMaster.fontManager.getFont(scaledSize);
236+
}
237+
196238
public float drawStringCapableWithEmojiWithShadow(String text, float x, float y, int color) {
197239
String[] sbs = new String[]{"\uD83C\uDF89", "\uD83C\uDF81", "\uD83D\uDC79", "\uD83C\uDFC0", "⚽", "\uD83C\uDF6D", "\uD83C\uDF20", "\uD83D\uDC7E", "\uD83D\uDC0D"
198240
, "\uD83D\uDD2E", "\uD83D\uDC7D", "\uD83D\uDCA3", "\uD83C\uDF6B", "\uD83C\uDF82"};

0 commit comments

Comments
 (0)