修修修
This commit is contained in:
parent
20071e126d
commit
e6d2125e07
|
|
@ -0,0 +1,102 @@
|
|||
package com.extendedae_plus.mixin.ae2;
|
||||
|
||||
import appeng.client.gui.AEBaseScreen;
|
||||
import appeng.client.gui.style.PaletteColor;
|
||||
import appeng.client.gui.style.ScreenStyle;
|
||||
import com.extendedae_plus.api.ExPatternPageAccessor;
|
||||
import com.glodblock.github.extendedae.client.gui.GuiExPatternProvider;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(AEBaseScreen.class)
|
||||
public abstract class AEBaseScreenMixin {
|
||||
|
||||
@Unique
|
||||
private ScreenStyle eap$getStyle(Object self) {
|
||||
try {
|
||||
var f = self.getClass().getDeclaredField("style");
|
||||
f.setAccessible(true);
|
||||
Object v = f.get(self);
|
||||
if (v instanceof ScreenStyle s) return s;
|
||||
} catch (Throwable ignored) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Unique
|
||||
private static int eap$getIntField(Object self, String name, int def) {
|
||||
Class<?> c = self.getClass();
|
||||
while (c != null && c != Object.class) {
|
||||
try {
|
||||
var f = c.getDeclaredField(name);
|
||||
f.setAccessible(true);
|
||||
Object v = f.get(self);
|
||||
if (v instanceof Integer i) return i;
|
||||
} catch (Throwable ignored) {}
|
||||
c = c.getSuperclass();
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
@Unique
|
||||
private static Font eap$getFont(Object self) {
|
||||
Class<?> c = self.getClass();
|
||||
while (c != null && c != Object.class) {
|
||||
try {
|
||||
var f = c.getDeclaredField("font");
|
||||
f.setAccessible(true);
|
||||
Object v = f.get(self);
|
||||
if (v instanceof Font font) return font;
|
||||
} catch (Throwable ignored) {}
|
||||
c = c.getSuperclass();
|
||||
}
|
||||
return net.minecraft.client.Minecraft.getInstance().font;
|
||||
}
|
||||
|
||||
// 在标签绘制后追加页码绘制,仅限扩展样板供应器界面
|
||||
@Inject(method = "renderLabels", at = @At("TAIL"), remap = false)
|
||||
private void eap$renderPageIndicator(GuiGraphics guiGraphics, int x, int y, CallbackInfo ci) {
|
||||
Object self = this;
|
||||
if (!(self instanceof GuiExPatternProvider)) {
|
||||
return;
|
||||
}
|
||||
int cur = 1;
|
||||
int max = 1;
|
||||
try {
|
||||
if (self instanceof ExPatternPageAccessor accessor) {
|
||||
cur = Math.max(0, accessor.eap$getCurrentPage()) + 1;
|
||||
}
|
||||
// 读取最大页(从 GUI 本地字段)
|
||||
try {
|
||||
var fMax = self.getClass().getDeclaredField("eap$maxPageLocal");
|
||||
fMax.setAccessible(true);
|
||||
Object v = fMax.get(self);
|
||||
if (v instanceof Integer i) {
|
||||
max = Math.max(1, i);
|
||||
}
|
||||
} catch (Throwable ignored) {}
|
||||
|
||||
ScreenStyle style = eap$getStyle(self);
|
||||
Font font = eap$getFont(self);
|
||||
int leftPos = eap$getIntField(self, "leftPos", 0);
|
||||
int topPos = eap$getIntField(self, "topPos", 0);
|
||||
int imageWidth = eap$getIntField(self, "imageWidth", 0);
|
||||
|
||||
String text = cur + "/" + max;
|
||||
int tx = leftPos + imageWidth - font.width(text) - 6;
|
||||
int ty = topPos + 6;
|
||||
int color = 0xFFFFFFFF;
|
||||
if (style != null) {
|
||||
try {
|
||||
color = style.getColor(PaletteColor.MUTED_TEXT_COLOR).toARGB();
|
||||
} catch (Throwable ignored) {}
|
||||
}
|
||||
guiGraphics.drawString(font, text, tx, ty, color, false);
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -193,6 +193,7 @@ public abstract class GuiExPatternProviderMixin extends PatternProviderScreen<Co
|
|||
this.hoveredSlot = null;
|
||||
}, Icon.ARROW_RIGHT);
|
||||
|
||||
// 恢复到 AE2 左侧工具栏
|
||||
this.addToLeftToolbar(this.nextPage);
|
||||
this.addToLeftToolbar(this.prevPage);
|
||||
}
|
||||
|
|
@ -242,6 +243,8 @@ public abstract class GuiExPatternProviderMixin extends PatternProviderScreen<Co
|
|||
return getCurrentPage();
|
||||
}
|
||||
|
||||
// 页码文本绘制移交给 AEBaseScreenMixin.renderLabels 尾部执行
|
||||
|
||||
// 注意:不再注入 Screen#init,避免混入在某些映射情况下失败导致 TransformerError
|
||||
|
||||
@Override
|
||||
|
|
@ -270,7 +273,7 @@ public abstract class GuiExPatternProviderMixin extends PatternProviderScreen<Co
|
|||
this.x5Button.setVisibility(true);
|
||||
}
|
||||
|
||||
// 如果屏幕尺寸发生变化(窗口/GUI缩放),重新注册按钮,避免被 Screen.init 清空
|
||||
// 如果屏幕尺寸发生变化(窗口/GUI缩放),重新注册右侧外列的自定义按钮,翻页按钮由左侧工具栏托管
|
||||
if (this.width != eap$lastScreenWidth || this.height != eap$lastScreenHeight) {
|
||||
eap$lastScreenWidth = this.width;
|
||||
eap$lastScreenHeight = this.height;
|
||||
|
|
@ -306,6 +309,7 @@ public abstract class GuiExPatternProviderMixin extends PatternProviderScreen<Co
|
|||
int bx = this.leftPos + this.imageWidth + 1; // 向右平移 1px 到面板外侧
|
||||
int by = this.topPos + 20;
|
||||
int spacing = 22;
|
||||
// 翻页按钮交由左侧工具栏布局,无需手动定位
|
||||
if (this.divideBy2Button != null) {
|
||||
this.divideBy2Button.setX(bx);
|
||||
this.divideBy2Button.setY(by);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
"compatibilityLevel": "JAVA_17",
|
||||
"minVersion": "0.8",
|
||||
"client": [
|
||||
"ae2.AEBaseScreenMixin",
|
||||
"PickFromWirelessMixin",
|
||||
"accessor.AbstractContainerScreenAccessor",
|
||||
"accessor.ScreenAccessor",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user