Add pattern terminal slot toggle functionality

This commit is contained in:
GaLi 2025-08-09 02:35:35 +08:00
parent 80d281de95
commit 16e0243f28
2 changed files with 128 additions and 2 deletions

View File

@ -0,0 +1,124 @@
package com.extendedae_plus.mixin;
import appeng.client.gui.Icon;
import appeng.client.gui.AEBaseScreen;
import appeng.client.gui.style.ScreenStyle;
import appeng.client.gui.widgets.IconButton;
import com.glodblock.github.extendedae.client.gui.GuiExPatternTerminal;
import com.glodblock.github.extendedae.client.gui.GuiWirelessExPAT;
import com.glodblock.github.extendedae.container.ContainerExPatternTerminal;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.player.Inventory;
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(GuiExPatternTerminal.class)
public abstract class GuiExPatternTerminalMixin extends AEBaseScreen<ContainerExPatternTerminal> {
@Unique
private IconButton toggleSlotsButton;
@Unique
private boolean showSlots = true; // 默认显示槽位
public GuiExPatternTerminalMixin(ContainerExPatternTerminal menu, Inventory playerInventory, Component title, ScreenStyle style) {
super(menu, playerInventory, title, style);
}
@Inject(method = "<init>", at = @At("TAIL"), remap = false)
private void injectConstructor(ContainerExPatternTerminal menu, Inventory playerInventory, Component title, ScreenStyle style, CallbackInfo ci) {
// 创建切换槽位显示的按钮
this.toggleSlotsButton = new IconButton((b) -> {
System.out.println("ExtendedAE Plus: 按钮被点击当前showSlots: " + this.showSlots);
this.showSlots = !this.showSlots; // 开关状态
System.out.println("ExtendedAE Plus: 切换后showSlots: " + this.showSlots);
// 通过反射调用refreshList方法 - 在GuiExPatternTerminal中
try {
java.lang.reflect.Method refreshMethod = this.getClass().getDeclaredMethod("refreshList");
refreshMethod.setAccessible(true);
refreshMethod.invoke(this);
System.out.println("ExtendedAE Plus: refreshList调用成功");
} catch (Exception e) {
System.out.println("ExtendedAE Plus: 调用refreshList失败: " + e.getMessage());
e.printStackTrace();
}
}) {
@Override
protected Icon getIcon() {
return showSlots ? Icon.PATTERN_ACCESS_HIDE : Icon.PATTERN_ACCESS_SHOW;
}
};
// 设置按钮提示文本
this.toggleSlotsButton.setTooltip(Tooltip.create(Component.translatable("gui.expatternprovider.toggle_slots")));
// 添加到左侧工具栏
this.addToLeftToolbar(this.toggleSlotsButton);
System.out.println("ExtendedAE Plus: 槽位切换按钮已添加到工具栏,默认显示模式: " + this.showSlots);
}
@Inject(method = "refreshList", at = @At("HEAD"), remap = false)
private void onRefreshListStart(CallbackInfo ci) {
System.out.println("ExtendedAE Plus: refreshList开始执行 - 显示槽位: " + this.showSlots);
// 更新按钮图标
if (this.toggleSlotsButton != null) {
this.toggleSlotsButton.setTooltip(Tooltip.create(Component.translatable(
this.showSlots ? "gui.expatternprovider.hide_slots" : "gui.expatternprovider.show_slots"
)));
}
}
@Inject(method = "refreshList", at = @At("TAIL"), remap = false)
private void onRefreshListEnd(CallbackInfo ci) {
System.out.println("ExtendedAE Plus: refreshList结束 - showSlots状态: " + this.showSlots);
// 在refreshList结束后根据showSlots状态过滤SlotsRow
if (!this.showSlots) {
try {
// 通过反射访问rows字段 - 在GuiExPatternTerminal中
java.lang.reflect.Field rowsField = this.getClass().getDeclaredField("rows");
rowsField.setAccessible(true);
java.util.ArrayList<?> rows = (java.util.ArrayList<?>) rowsField.get(this);
System.out.println("ExtendedAE Plus: 找到rows字段当前行数: " + rows.size());
// 移除所有SlotsRow只保留GroupHeaderRow
int removedCount = 0;
for (int i = rows.size() - 1; i >= 0; i--) {
Object row = rows.get(i);
String className = row.getClass().getSimpleName();
System.out.println("ExtendedAE Plus: 检查行 " + i + ",类型: " + className);
if (className.equals("SlotsRow")) {
rows.remove(i);
removedCount++;
System.out.println("ExtendedAE Plus: 移除行 " + i);
}
}
System.out.println("ExtendedAE Plus: 已隐藏 " + removedCount + " 个槽位行,剩余行数: " + rows.size());
// 强制刷新滚动条
try {
java.lang.reflect.Method resetScrollbarMethod = this.getClass().getDeclaredMethod("resetScrollbar");
resetScrollbarMethod.setAccessible(true);
resetScrollbarMethod.invoke(this);
System.out.println("ExtendedAE Plus: 滚动条已重置");
} catch (Exception e) {
System.out.println("ExtendedAE Plus: 重置滚动条失败: " + e.getMessage());
}
} catch (Exception e) {
System.out.println("ExtendedAE Plus: 访问rows字段失败: " + e.getMessage());
e.printStackTrace();
}
} else {
System.out.println("ExtendedAE Plus: showSlots为true不隐藏槽位行");
}
}
}

View File

@ -5,10 +5,12 @@
"minVersion": "0.8",
"client": [
"GuiExPatternProviderMixin",
"SlotGridLayoutMixin"
"SlotGridLayoutMixin",
"GuiExPatternTerminalMixin"
],
"mixins": [
"ContainerExPatternProviderMixin"
"ContainerExPatternProviderMixin",
"ContainerExPatternTerminalMixin"
],
"injectors": {
"defaultRequire": 1