槽位渲染布局
This commit is contained in:
parent
b0bb51f8f6
commit
c2f931eefc
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.extendedae_plus.client.gui;
|
||||||
|
|
||||||
|
public final class PageLayoutContext {
|
||||||
|
private static final ThreadLocal<Boolean> ACTIVE = ThreadLocal.withInitial(() -> false);
|
||||||
|
private static final ThreadLocal<Integer> CURRENT_PAGE = ThreadLocal.withInitial(() -> 0);
|
||||||
|
|
||||||
|
private PageLayoutContext() {}
|
||||||
|
|
||||||
|
public static void enable(int page) {
|
||||||
|
ACTIVE.set(true);
|
||||||
|
CURRENT_PAGE.set(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void disable() {
|
||||||
|
ACTIVE.set(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isActive() {
|
||||||
|
Boolean b = ACTIVE.get();
|
||||||
|
return b != null && b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getCurrentPage() {
|
||||||
|
Integer i = CURRENT_PAGE.get();
|
||||||
|
return i != null ? i : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void withPage(int page, Runnable action) {
|
||||||
|
enable(page);
|
||||||
|
try {
|
||||||
|
action.run();
|
||||||
|
} finally {
|
||||||
|
disable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,8 +4,10 @@ import appeng.client.gui.Icon;
|
||||||
import appeng.client.gui.implementations.PatternProviderScreen;
|
import appeng.client.gui.implementations.PatternProviderScreen;
|
||||||
import appeng.client.gui.style.ScreenStyle;
|
import appeng.client.gui.style.ScreenStyle;
|
||||||
import appeng.menu.SlotSemantics;
|
import appeng.menu.SlotSemantics;
|
||||||
|
import appeng.menu.slot.AppEngSlot;
|
||||||
import com.extendedae_plus.NewIcon;
|
import com.extendedae_plus.NewIcon;
|
||||||
import com.extendedae_plus.api.ExPatternButtonsAccessor;
|
import com.extendedae_plus.api.ExPatternButtonsAccessor;
|
||||||
|
import com.extendedae_plus.api.ExPatternPageAccessor;
|
||||||
import com.extendedae_plus.config.ModConfigs;
|
import com.extendedae_plus.config.ModConfigs;
|
||||||
import com.glodblock.github.extendedae.client.button.ActionEPPButton;
|
import com.glodblock.github.extendedae.client.button.ActionEPPButton;
|
||||||
import com.glodblock.github.extendedae.client.gui.GuiExPatternProvider;
|
import com.glodblock.github.extendedae.client.gui.GuiExPatternProvider;
|
||||||
|
|
@ -162,6 +164,8 @@ public abstract class GuiExPatternProviderMixin extends PatternProviderScreen<Co
|
||||||
this.repositionSlots(SlotSemantics.ENCODED_PATTERN);
|
this.repositionSlots(SlotSemantics.ENCODED_PATTERN);
|
||||||
this.repositionSlots(SlotSemantics.STORAGE);
|
this.repositionSlots(SlotSemantics.STORAGE);
|
||||||
this.hoveredSlot = null;
|
this.hoveredSlot = null;
|
||||||
|
// 更新当前页可见状态
|
||||||
|
eap$updatePageSlotActivity();
|
||||||
}, Icon.ARROW_LEFT);
|
}, Icon.ARROW_LEFT);
|
||||||
|
|
||||||
this.nextPage = new ActionEPPButton((b) -> {
|
this.nextPage = new ActionEPPButton((b) -> {
|
||||||
|
|
@ -189,6 +193,8 @@ public abstract class GuiExPatternProviderMixin extends PatternProviderScreen<Co
|
||||||
this.repositionSlots(SlotSemantics.ENCODED_PATTERN);
|
this.repositionSlots(SlotSemantics.ENCODED_PATTERN);
|
||||||
this.repositionSlots(SlotSemantics.STORAGE);
|
this.repositionSlots(SlotSemantics.STORAGE);
|
||||||
this.hoveredSlot = null;
|
this.hoveredSlot = null;
|
||||||
|
// 更新当前页可见状态
|
||||||
|
eap$updatePageSlotActivity();
|
||||||
}, Icon.ARROW_RIGHT);
|
}, Icon.ARROW_RIGHT);
|
||||||
|
|
||||||
// 恢复到 AE2 左侧工具栏
|
// 恢复到 AE2 左侧工具栏
|
||||||
|
|
@ -361,9 +367,33 @@ public abstract class GuiExPatternProviderMixin extends PatternProviderScreen<Co
|
||||||
this.x10Button.setX(bx);
|
this.x10Button.setX(bx);
|
||||||
this.x10Button.setY(by + spacing * 5);
|
this.x10Button.setY(by + spacing * 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 每帧确保当前页槽位处于启用状态,非当前页禁用
|
||||||
|
eap$updatePageSlotActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 本文件原包含本地样板缩放实现(单机模式)和 ExtendedAE 网络派发,已移除以兼容 1.21.1 与最小可构建集。
|
// 本文件原包含本地样板缩放实现(单机模式)和 ExtendedAE 网络派发,已移除以兼容 1.21.1 与最小可构建集。
|
||||||
|
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private void eap$updatePageSlotActivity() {
|
||||||
|
try {
|
||||||
|
if (!(((Object) this) instanceof GuiExPatternProvider)) return;
|
||||||
|
var list = this.getMenu().getSlots(SlotSemantics.ENCODED_PATTERN);
|
||||||
|
if (list == null || list.isEmpty()) return;
|
||||||
|
|
||||||
|
int currentPage = getCurrentPage();
|
||||||
|
int base = currentPage * SLOTS_PER_PAGE;
|
||||||
|
int end = Math.min(list.size(), base + SLOTS_PER_PAGE);
|
||||||
|
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
var slot = list.get(i);
|
||||||
|
if (slot instanceof AppEngSlot s) {
|
||||||
|
boolean enabled = i >= base && i < end;
|
||||||
|
s.setActive(enabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Throwable ignored) {}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -27,6 +27,7 @@
|
||||||
"ae2.client.gui.AEBaseScreenMixin",
|
"ae2.client.gui.AEBaseScreenMixin",
|
||||||
"ae2.client.gui.PatternEncodingTermScreenMixin",
|
"ae2.client.gui.PatternEncodingTermScreenMixin",
|
||||||
"ae2.client.gui.PatternProviderScreenMixin",
|
"ae2.client.gui.PatternProviderScreenMixin",
|
||||||
|
"ae2.client.gui.SlotGridLayoutMixin",
|
||||||
"jei.EncodePatternTransferHandlerMixin",
|
"jei.EncodePatternTransferHandlerMixin",
|
||||||
"jei.AE2JeiEncodePatternTransferHandlerMixin",
|
"jei.AE2JeiEncodePatternTransferHandlerMixin",
|
||||||
"ae2.accessor.AEBaseScreenAccessor",
|
"ae2.accessor.AEBaseScreenAccessor",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user