[BugFix] Remove Notice ,fix font/draw can't render

[BugFix] No OpenGL context found in the current thread.
This commit is contained in:
xiaozhou233 committed 2026-01-22 20:26:26 +08:00
1 parent a7cdf23a39
commit 8e914997e8
5 files changed
+1 -136

No files matched your search

@@ -4,7 +4,6 @@ import cn.xiaozhou233.orangex.alts.AltManager;
import cn.xiaozhou233.orangex.font.FontManager;
import cn.xiaozhou233.orangex.mixin.MixinManager;
import cn.xiaozhou233.orangex.module.ModuleManager;
import cn.xiaozhou233.orangex.ui.notice.NoticeManager;
import lombok.Getter;
import org.greenrobot.eventbus.EventBus;
@@ -21,8 +20,6 @@ public class OrangeX {
private final ModuleManager moduleManager;
private static FontManager fontManager;
@Getter
private final NoticeManager noticeManager;
@Getter
private final AltManager altManager;
public OrangeX() {
@@ -36,9 +33,6 @@ public class OrangeX {
// Module Manager
this.moduleManager = new ModuleManager();
// Notice Manager
this.noticeManager = new NoticeManager(this.eventBus);
// Alt Manager
this.altManager = new AltManager();
@@ -49,7 +43,6 @@ public class OrangeX {
System.out.println("OrangeX start!");
MixinManager.start();
moduleManager.init();
noticeManager.addNotice("Welcome!", "OrangeX Started!", 5000, Color.GREEN.getRGB());
}
public void stop() {
@@ -35,11 +35,8 @@ public class MixinGuiIngame {
OrangeX.getInstance().getEventBus().post(new EventRender2D(partialTicks));
GlStateManager.enableLighting();
GlStateManager.enableDepth();
GlStateManager.disableBlend();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
GlStateManager.popMatrix();
}
}
}
@@ -65,7 +65,6 @@ public abstract class Module {
public void toggle() {
setEnabled(!this.enabled);
OrangeX.getInstance().getNoticeManager().addNotice(getName(), "Toggled", 1000, Color.BLUE.getRGB());
}
protected void addValue(Value<?> value) {
@@ -1,18 +0,0 @@
package cn.xiaozhou233.orangex.ui.notice;
public class Notice {
public String title;
public String content;
public long startTime;
public long duration;
public int bgColor;
public Notice(String title, String content, long duration, int bgColor) {
this.title = title;
this.content = content;
this.duration = duration;
this.bgColor = bgColor;
this.startTime = System.currentTimeMillis();
}
}
@@ -1,106 +0,0 @@
package cn.xiaozhou233.orangex.ui.notice;
import cn.xiaozhou233.orangex.OrangeX;
import cn.xiaozhou233.orangex.event.impl.EventRender2D;
import cn.xiaozhou233.orangex.font.FontManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class NoticeManager {
private final Minecraft mc = Minecraft.getMinecraft();
private final List<Notice> notices = new ArrayList<>();
private final FontManager fontManager = OrangeX.getFontManager();
public NoticeManager(EventBus eventBus) {
eventBus.register(this);
}
public void addNotice(String title, String content, long duration, int bgColor) {
notices.add(new Notice(title, content, duration, bgColor));
}
@Subscribe
public void render(EventRender2D event) {
if (notices.isEmpty()) return;
ScaledResolution sr = new ScaledResolution(mc);
FontRenderer font = mc.fontRendererObj;
Iterator<Notice> it = notices.iterator();
while (it.hasNext()) {
Notice notice = it.next();
long elapsed = System.currentTimeMillis() - notice.startTime;
if (elapsed > notice.duration + 800) {
it.remove();
continue;
}
int titleWidth = font.getStringWidth(notice.title);
int contentWidth = font.getStringWidth(notice.content);
int maxWidth = sr.getScaledWidth() / 3;
int minWidth = 140;
int width = Math.max(Math.max(titleWidth, contentWidth) + 26, minWidth);
width = Math.min(width, maxWidth);
int height = 42;
int targetX = sr.getScaledWidth() - width - 10;
int y = sr.getScaledHeight() - height - 10;
int x;
if (elapsed < 200) {
float t = elapsed / 200f;
x = (int) (sr.getScaledWidth() + (targetX - sr.getScaledWidth()) * t);
} else if (elapsed > notice.duration) {
float t = (elapsed - notice.duration) / 600f;
x = (int) (targetX + (sr.getScaledWidth() - targetX) * t);
} else {
x = targetX;
}
// ====== 渲染状态 ======
GlStateManager.pushMatrix();
GlStateManager.disableDepth();
GlStateManager.disableLighting();
GlStateManager.enableBlend();
int bg = 0xC8000000;
int border = 0xFFFFFFFF;
int textColor = 0xFFFFFFFF;
drawRect(x, y, x + width, y + height, bg);
drawRect(x, y, x + width, y + 1, border);
drawRect(x, y + height - 1, x + width, y + height, border);
drawRect(x, y, x + 1, y + height, border);
drawRect(x + width - 1, y, x + width, y + height, border);
fontManager.MontserratRegular18.drawString(notice.title, x + 8, y + 10, textColor);
fontManager.MontserratRegular18.drawString(notice.content, x + 8, y + 24, textColor);
GlStateManager.popMatrix();
GlStateManager.disableLighting();
GlStateManager.disableDepth();
GlStateManager.disableBlend();
GlStateManager.color(1f, 1f, 1f, 1f);
}
}
private void drawRect(int left, int top, int right, int bottom, int color) {
net.minecraft.client.gui.Gui.drawRect(left, top, right, bottom, color);
}
}