Fonts
This commit is contained in:
@@ -10,4 +10,6 @@ public abstract class MinecraftProvider {
|
|||||||
public abstract boolean isKeyPressed(int key);
|
public abstract boolean isKeyPressed(int key);
|
||||||
|
|
||||||
public abstract File getRunDirectory();
|
public abstract File getRunDirectory();
|
||||||
|
|
||||||
|
public abstract int getWidth(String text, int font);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,12 @@ public class SaturnIdentifier extends MinecraftBinding {
|
|||||||
public SaturnIdentifier(String namespace, String path) {
|
public SaturnIdentifier(String namespace, String path) {
|
||||||
super(MinecraftProvider.PROVIDER.createIdentifier(namespace, path));
|
super(MinecraftProvider.PROVIDER.createIdentifier(namespace, path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SaturnIdentifier of(String namespace, String path) {
|
||||||
|
return new SaturnIdentifier(namespace, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SaturnIdentifier ofVanilla(String path) {
|
||||||
|
return new SaturnIdentifier("minecraft", path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package org.saturnclient.ui.resources;
|
||||||
|
|
||||||
|
import org.saturnclient.common.minecraft.MinecraftProvider;
|
||||||
|
import org.saturnclient.common.minecraft.bindings.SaturnIdentifier;
|
||||||
|
|
||||||
|
public class Fonts {
|
||||||
|
public static final SaturnIdentifier INTER = SaturnIdentifier.of("saturnclient", "inter");
|
||||||
|
public static final SaturnIdentifier INTER_BOLD = SaturnIdentifier.of("saturnclient", "inter_bold");
|
||||||
|
public static final SaturnIdentifier DEFAULT = SaturnIdentifier.ofVanilla("default");
|
||||||
|
|
||||||
|
public static SaturnIdentifier getFont(int font) {
|
||||||
|
switch (font) {
|
||||||
|
case 0:
|
||||||
|
return DEFAULT;
|
||||||
|
case 1:
|
||||||
|
return INTER;
|
||||||
|
default:
|
||||||
|
return INTER_BOLD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getWidth(String text, int font) {
|
||||||
|
int w = 0;
|
||||||
|
for (String line : text.split("\n")) {
|
||||||
|
w = Math.max(w, MinecraftProvider.PROVIDER.getWidth(line, font));
|
||||||
|
}
|
||||||
|
if (font == 0) {
|
||||||
|
return w * 2;
|
||||||
|
} else {
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getHeight() {
|
||||||
|
return 18;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int centerX(int w, String text, int font) {
|
||||||
|
return (w - Fonts.getWidth(text, font)) / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int centerY(int h) {
|
||||||
|
return (h - 18) / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-3
@@ -1,4 +1,4 @@
|
|||||||
package org.saturnclient.ui.resources;
|
package org.saturnclient.saturnclient.impl;
|
||||||
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
import net.minecraft.text.Style;
|
import net.minecraft.text.Style;
|
||||||
@@ -20,10 +20,10 @@ public class Fonts {
|
|||||||
return INTER_BOLD;
|
return INTER_BOLD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Text setFont(String text, Identifier font) {
|
public static Text setFont(String text, Identifier font) {
|
||||||
return Text.literal(text).setStyle(
|
return Text.literal(text).setStyle(
|
||||||
Style.EMPTY.withFont(font));
|
Style.EMPTY.withFont(font));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getWidth(String text, int font) {
|
public static int getWidth(String text, int font) {
|
||||||
+5
@@ -24,4 +24,9 @@ public class SaturnClientProvider extends MinecraftProvider {
|
|||||||
return GLFW.glfwGetKey(SaturnClient.client.getWindow().getHandle(), key) == GLFW.GLFW_PRESS
|
return GLFW.glfwGetKey(SaturnClient.client.getWindow().getHandle(), key) == GLFW.GLFW_PRESS
|
||||||
&& SaturnClient.client.currentScreen == null;
|
&& SaturnClient.client.currentScreen == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWidth(String text, int font) {
|
||||||
|
return Fonts.getWidth(text, font);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user