正确初始化&ui绘制分割线

This commit is contained in:
GaLicn 2025-12-12 11:35:01 +08:00
parent cba7b9a36a
commit a82876824d
4 changed files with 23 additions and 9 deletions

View File

@ -37,10 +37,10 @@ public class LabeledWirelessTransceiverScreen extends AbstractContainerScreen<La
private static final int TEX_H = 256; private static final int TEX_H = 256;
private static final int LIST_X = 9; private static final int LIST_X = 9;
private static final int LIST_Y = 25; private static final int LIST_Y = 27;
private static final int LIST_W = 110; // 118-9+1 private static final int LIST_W = 110; // 118-9+1
private static final int LIST_H = 116; // 140-25+1 private static final int LIST_H = 114; // 140-27+1
private static final int ROW_H = 12; private static final int ROW_H = 11; // 10px text height + 1px 分隔
private static final int VISIBLE_ROWS = LIST_H / ROW_H; // 10 private static final int VISIBLE_ROWS = LIST_H / ROW_H; // 10
private static final int SCROLL_X = 123; private static final int SCROLL_X = 123;
private static final int SCROLL_Y = 21; private static final int SCROLL_Y = 21;
@ -148,7 +148,7 @@ public class LabeledWirelessTransceiverScreen extends AbstractContainerScreen<La
// 占位绘制列表和信息区内的内容框线 // 占位绘制列表和信息区内的内容框线
// 标签列表区域 // 标签列表区域
gfx.fill(this.leftPos + 9, this.topPos + 25, this.leftPos + 118 + 1, this.topPos + 140 + 1, 0x20FFFFFF); gfx.fill(this.leftPos + 9, this.topPos + 27, this.leftPos + 118 + 1, this.topPos + 140 + 1, 0x20FFFFFF);
// 滚动条区域 // 滚动条区域
gfx.fill(this.leftPos + 123, this.topPos + 21, this.leftPos + 128 + 1, this.topPos + 141 + 1, 0x20000000); gfx.fill(this.leftPos + 123, this.topPos + 21, this.leftPos + 128 + 1, this.topPos + 141 + 1, 0x20000000);
// 当前收发器信息区域 // 当前收发器信息区域
@ -210,8 +210,9 @@ public class LabeledWirelessTransceiverScreen extends AbstractContainerScreen<La
gfx.fill(baseX, y, baseX + LIST_W, y + ROW_H, 0x40FFFFFF); gfx.fill(baseX, y, baseX + LIST_W, y + ROW_H, 0x40FFFFFF);
} }
LabelEntry e = filtered.get(idx); LabelEntry e = filtered.get(idx);
String text = this.font.plainSubstrByWidth(e.label(), LIST_W - 4); String text = this.font.plainSubstrByWidth(e.label(), LIST_W - 2);
gfx.drawString(this.font, text, baseX + 2, y + 2, 0x404040, false); int ty = y + (ROW_H - this.font.lineHeight) / 2;
gfx.drawString(this.font, text, baseX + 2, ty, 0x404040, false);
} }
// 信息显示 // 信息显示

View File

@ -170,8 +170,9 @@ public class LabeledWirelessTransceiverBlockEntity extends AEBaseBlockEntity imp
/** /**
* 在加载或跨区块迁移后重新获取网络并重连 * 在加载或跨区块迁移后重新获取网络并重连
* @param ensureRegister true 如果保存的标签不存在网络则尝试重新注册
*/ */
public void refreshLabel() { public void refreshLabel(boolean ensureRegister) {
ServerLevel sl = getServerLevel(); ServerLevel sl = getServerLevel();
if (sl == null) return; if (sl == null) return;
if (labelForDisplay == null || labelForDisplay.isEmpty()) { if (labelForDisplay == null || labelForDisplay.isEmpty()) {
@ -180,11 +181,17 @@ public class LabeledWirelessTransceiverBlockEntity extends AEBaseBlockEntity imp
updateState(); updateState();
return; return;
} }
var network = LabelNetworkRegistry.get(sl).getNetwork(sl, labelForDisplay, placerId); var registry = LabelNetworkRegistry.get(sl);
var network = registry.getNetwork(sl, labelForDisplay, placerId);
if (network == null && ensureRegister) {
network = registry.register(sl, labelForDisplay, placerId, this);
}
if (network == null) { if (network == null) {
this.frequency = 0L; this.frequency = 0L;
this.labelLink.clearTarget(); this.labelLink.clearTarget();
} else { } else {
// 确保虚拟节点重建网络从存档恢复时 managedNode 为空
network.ensureVirtualNode(sl);
this.frequency = network.channel(); this.frequency = network.channel();
this.labelLink.setTarget(network); this.labelLink.setTarget(network);
} }
@ -192,6 +199,10 @@ public class LabeledWirelessTransceiverBlockEntity extends AEBaseBlockEntity imp
setChanged(); setChanged();
} }
public void refreshLabel() {
refreshLabel(false);
}
public void onRemoved() { public void onRemoved() {
this.beingRemoved = true; this.beingRemoved = true;
labelLink.onUnloadOrRemove(); labelLink.onUnloadOrRemove();
@ -260,7 +271,9 @@ public class LabeledWirelessTransceiverBlockEntity extends AEBaseBlockEntity imp
if (sl == null) return; if (sl == null) return;
GridHelper.onFirstTick(this, be -> { GridHelper.onFirstTick(this, be -> {
be.managedNode.create(be.getLevel(), be.getBlockPos()); be.managedNode.create(be.getLevel(), be.getBlockPos());
be.refreshLabel(); be.refreshLabel(true);
be.labelLink.updateStatus();
be.updateState();
}); });
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB