mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
Feat: HUD
This commit is contained in:
1 parent
572a3535bd
commit
e09fe98d72
5 files changed
+67
-3
No files matched your search
@@ -10,11 +10,13 @@ public class StbFontManager {
|
||||
private byte[] proximaBoldData;
|
||||
private byte[] notoData;
|
||||
private byte[] poppinsData;
|
||||
private byte[] jelloMediumData;
|
||||
|
||||
private final ConcurrentMap<Integer, SmoothFontRenderer> regularFonts = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<Integer, SmoothFontRenderer> boldFonts = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<Integer, SmoothFontRenderer> notoFonts = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<Integer, SmoothFontRenderer> poppinsFonts = new ConcurrentHashMap<>();
|
||||
private final ConcurrentMap<Integer, SmoothFontRenderer> jelloMediumFonts = new ConcurrentHashMap<>();
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
@@ -23,6 +25,7 @@ public class StbFontManager {
|
||||
this.proximaBoldData = readResource("proximabd.ttf");
|
||||
this.notoData = readResource("noto.ttf");
|
||||
this.poppinsData = readResource("poppins_rg.ttf");
|
||||
this.jelloMediumData = readResource("JelloMedium.ttf");
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
@@ -60,6 +63,10 @@ public class StbFontManager {
|
||||
return getFont(poppinsFonts, poppinsData, size, "Poppins");
|
||||
}
|
||||
|
||||
public SmoothFontRenderer getJelloMedium(int size) {
|
||||
return getFont(jelloMediumFonts, jelloMediumData, size, "Jello Medium");
|
||||
}
|
||||
|
||||
private SmoothFontRenderer getFont(ConcurrentMap<Integer, SmoothFontRenderer> cache, byte[] data, int size, String name) {
|
||||
if (!cache.containsKey(size)) {
|
||||
if (data == null) return null;
|
||||
|
||||
@@ -35,9 +35,6 @@ public class MixinGuiIngame {
|
||||
mc.entityRenderer.setupOverlayRendering();
|
||||
|
||||
OrangeX.getInstance().getEventBus().post(new EventRender2D(partialTicks));
|
||||
SmoothFontRenderer font = OrangeX.getInstance().getStbFontManager().getProxima(18);
|
||||
font.drawString("Hello World!", 50, 50, 0xFFFFFFFF);
|
||||
|
||||
|
||||
GlStateManager.enableDepth();
|
||||
GlStateManager.disableBlend();
|
||||
|
||||
@@ -32,6 +32,11 @@ public class Module {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public Module(String name, String description, ModuleCategory category, int key, boolean enabled) {
|
||||
this(name, description, category, key);
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public void addOption(Option<?> option) {
|
||||
options.add(option);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.event.impl.EventKey;
|
||||
import cn.xiaozhou233.orangex.module.config.ModuleConfig;
|
||||
import cn.xiaozhou233.orangex.module.impl.TestModule;
|
||||
import cn.xiaozhou233.orangex.module.impl.render.*;
|
||||
import lombok.Getter;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
@@ -28,6 +29,7 @@ public class ModuleManager {
|
||||
public void registerModules() {
|
||||
OrangeX.getInstance().getEventBus().register(this);
|
||||
addModule(new TestModule());
|
||||
addModule(new HUD());
|
||||
}
|
||||
|
||||
public List<Module> getModulesByCategory(ModuleCategory category) {
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
package cn.xiaozhou233.orangex.module.impl.render;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.event.impl.EventRender2D;
|
||||
import cn.xiaozhou233.orangex.font.SmoothFontRenderer;
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.ModuleCategory;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class HUD extends Module {
|
||||
|
||||
private SmoothFontRenderer font;
|
||||
|
||||
private static final int LOGO_COLOR = 0xFFA500;
|
||||
|
||||
public HUD() {
|
||||
super("HUD", "Render HUD", ModuleCategory.RENDER);
|
||||
setEnabled(true);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onRender2D(EventRender2D event) {
|
||||
|
||||
if (font == null) {
|
||||
font = OrangeX.getInstance()
|
||||
.getStbFontManager()
|
||||
.getJelloMedium(44);
|
||||
}
|
||||
|
||||
font.drawString(
|
||||
"Orange",
|
||||
10,
|
||||
10,
|
||||
LOGO_COLOR
|
||||
);
|
||||
|
||||
font.drawString(
|
||||
"X",
|
||||
10 + font.getStringWidth("Orange"),
|
||||
10,
|
||||
getRainbow(1500)
|
||||
);
|
||||
}
|
||||
|
||||
private int getRainbow(long offset) {
|
||||
float hue = ((System.currentTimeMillis() + offset) % 8000L)
|
||||
/ 8000.0f;
|
||||
|
||||
return Color.HSBtoRGB(hue, 0.7f, 1.0f) & 0xFFFFFF;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user