v1.1.9: UI 运行日志区域改用小字号并自动换行,最新日志置顶显示

这个提交包含在:
lyizai
2026-08-19 10:45:29 +08:00
父节点 1e99ff39e0
当前提交 385e0d13f1
@@ -28,6 +28,7 @@ import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.CheckboxWidget; import net.minecraft.client.gui.widget.CheckboxWidget;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.text.StringVisitable; import net.minecraft.text.StringVisitable;
import net.minecraft.text.OrderedText;
@Environment(value=EnvType.CLIENT) @Environment(value=EnvType.CLIENT)
/** /**
@@ -470,13 +471,26 @@ extends Screen {
context.drawTextWithShadow(this.textRenderer, "\u72b6\u6001\u4fe1\u606f", statusX, infoTop, -5592406); context.drawTextWithShadow(this.textRenderer, "\u72b6\u6001\u4fe1\u606f", statusX, infoTop, -5592406);
context.fill(statusX - 12, infoTop - 1, statusX - 11, infoTop + 58, -12761518); context.fill(statusX - 12, infoTop - 1, statusX - 11, infoTop + 58, -12761518);
// 运行日志:最多 4 条,最新日志在最下方 // 运行日志:使用较小字体并自动换行,最新日志在最上方,逐行向下显示直到填满可视高度
List<String> logs = this.controller.logs(); List<String> logs = this.controller.logs();
int shown = Math.min(4, logs.size()); float logScale = 0.75f; // 日志字号缩放(比默认小一号)
for (int i = 0; i < shown; ++i) { int logAreaTop = infoTop + 12;
String trimmed = this.textRenderer.trimToWidth(logs.get(logs.size() - shown + i), logWidth - 4); int logAreaBottom = infoTop + 56; // 与竖向分隔线底部对齐
context.drawTextWithShadow(this.textRenderer, trimmed, this.mapX + 2, infoTop + 12 + i * 12, -6577233); int wrapWidth = (int)((logWidth - 4) / logScale); // 缩放后的可用换行宽度(按未缩放坐标计算)
context.getMatrices().push();
context.getMatrices().scale(logScale, logScale, 1.0f);
int lineY = logAreaTop;
outer:
for (int i = logs.size() - 1; i >= 0; --i) {
for (OrderedText line : this.textRenderer.wrapLines(Text.literal(logs.get(i)), wrapWidth)) {
if (lineY + 9 > logAreaBottom) {
break outer;
} }
context.drawTextWithShadow(this.textRenderer, line, (int)((this.mapX + 2) / logScale), (int)(lineY / logScale), -6577233);
lineY += 9;
}
}
context.getMatrices().pop();
// 状态信息:单行截断 + 固定 12px 行距,彻底消除换行重叠 // 状态信息:单行截断 + 固定 12px 行距,彻底消除换行重叠
int target = this.config.targetCount; int target = this.config.targetCount;