diff --git a/common/src/main/java/cn/zbx1425/worldcomment/ClientConfig.java b/common/src/main/java/cn/zbx1425/worldcomment/ClientConfig.java index 6b06e36..b7989e5 100644 --- a/common/src/main/java/cn/zbx1425/worldcomment/ClientConfig.java +++ b/common/src/main/java/cn/zbx1425/worldcomment/ClientConfig.java @@ -3,6 +3,7 @@ import cn.zbx1425.worldcomment.data.network.upload.ImageUploader; import com.google.gson.JsonElement; import com.google.gson.JsonParser; +import net.minecraft.client.DeltaTracker; import net.minecraft.network.FriendlyByteBuf; import java.util.ArrayList; @@ -15,6 +16,8 @@ public class ClientConfig { public boolean screenshotIncludeGui = false; public boolean screenshotIncludeComments = true; + public float commentHideTimer = 0f; + public List imageUploader; public int allowMarkerUsage; @@ -48,6 +51,15 @@ public static ClientConfig fromServerConfig(ServerConfig serverConfig) { return config; } + public void tick(DeltaTracker deltaTracker) { + if (commentHideTimer > 0) { + commentHideTimer -= deltaTracker.getGameTimeDeltaTicks(); + if (commentHideTimer <= 0) { + isCommentVisible = true; + } + } + } + public ClientConfig() { } diff --git a/common/src/main/java/cn/zbx1425/worldcomment/data/client/Screenshot.java b/common/src/main/java/cn/zbx1425/worldcomment/data/client/Screenshot.java index aec2c29..b37f622 100644 --- a/common/src/main/java/cn/zbx1425/worldcomment/data/client/Screenshot.java +++ b/common/src/main/java/cn/zbx1425/worldcomment/data/client/Screenshot.java @@ -71,7 +71,9 @@ public static boolean handleKeyF2() { if (minecraft.screen == null) { boolean prevHideGui = minecraft.options.hideGui; boolean prevIsCommentVisible = MainClient.CLIENT_CONFIG.isCommentVisible; + float prevCommentHideTimer = MainClient.CLIENT_CONFIG.commentHideTimer; applyClientConfigForScreenshot(); + MainClient.CLIENT_CONFIG.commentHideTimer = 0; // This is a workaround for the issue that the screenshot will be taken before CommentWorldRenderer is hidden minecraft.tell(() -> RenderSystem.recordRenderCall(() -> minecraft.tell(() -> RenderSystem.recordRenderCall(() -> { grabScreenshot(imageBytes -> minecraft.execute(() -> { @@ -80,6 +82,7 @@ public static boolean handleKeyF2() { })); minecraft.options.hideGui = prevHideGui; MainClient.CLIENT_CONFIG.isCommentVisible = prevIsCommentVisible; + MainClient.CLIENT_CONFIG.commentHideTimer = prevCommentHideTimer; })))); } return true; diff --git a/common/src/main/java/cn/zbx1425/worldcomment/item/CommentToolItem.java b/common/src/main/java/cn/zbx1425/worldcomment/item/CommentToolItem.java index 73c1daf..11d6de8 100644 --- a/common/src/main/java/cn/zbx1425/worldcomment/item/CommentToolItem.java +++ b/common/src/main/java/cn/zbx1425/worldcomment/item/CommentToolItem.java @@ -54,6 +54,8 @@ public CommentToolItem() { public static class Client { + public static final int COMMENT_HIDE_TICKS = 60 * 20; + public static ItemStack getHoldingCommentTool() { Player player = Minecraft.getInstance().player; if (player == null) return null; @@ -88,7 +90,13 @@ public static boolean placeUploadJob(Level level, Player player, ItemStack item) } } } else { - MainClient.CLIENT_CONFIG.isCommentVisible = !MainClient.CLIENT_CONFIG.isCommentVisible; + if (MainClient.CLIENT_CONFIG.isCommentVisible) { + MainClient.CLIENT_CONFIG.isCommentVisible = false; + MainClient.CLIENT_CONFIG.commentHideTimer = COMMENT_HIDE_TICKS; + } else { + MainClient.CLIENT_CONFIG.isCommentVisible = true; + MainClient.CLIENT_CONFIG.commentHideTimer = 0; + } } return false; } diff --git a/common/src/main/java/cn/zbx1425/worldcomment/render/ControlTipRenderer.java b/common/src/main/java/cn/zbx1425/worldcomment/render/ControlTipRenderer.java index d751a79..7d97629 100644 --- a/common/src/main/java/cn/zbx1425/worldcomment/render/ControlTipRenderer.java +++ b/common/src/main/java/cn/zbx1425/worldcomment/render/ControlTipRenderer.java @@ -13,6 +13,7 @@ import net.minecraft.world.item.ItemStack; import java.util.List; +import java.util.function.Supplier; public class ControlTipRenderer implements IGuiCommon { @@ -25,7 +26,8 @@ public class ControlTipRenderer implements IGuiCommon { null, true ); public static final ControlTip TIP_TOGGLE_SHOW = new ControlTip( - Component.translatable("gui.worldcomment.control_tip.toggle_show"), 0, + () -> Component.translatable("gui.worldcomment.control_tip.toggle_show", + (int)Math.ceil(MainClient.CLIENT_CONFIG.commentHideTimer / 20)), 0, null, true ); public static final ControlTip TIP_TOGGLE_HIDE = new ControlTip( @@ -61,6 +63,7 @@ public static void render(GuiGraphics guiGraphics) { public static void update() { Minecraft minecraft = Minecraft.getInstance(); + MainClient.CLIENT_CONFIG.tick(minecraft.getTimer()); for (ControlTip tip : TIPS) tip.visible = false; if (minecraft.player == null) { return; @@ -93,11 +96,18 @@ public static class ControlTip { public int imgIndex; public KeyMapping key; public boolean critical; - public Component text; + public Supplier text; public boolean visible = false; public ControlTip(Component text, int imgIndex, KeyMapping key, boolean critical) { + this.text = () -> text; + this.imgIndex = imgIndex; + this.key = key; + this.critical = critical; + } + + public ControlTip(Supplier text, int imgIndex, KeyMapping key, boolean critical) { this.text = text; this.imgIndex = imgIndex; this.key = key; @@ -107,7 +117,7 @@ public ControlTip(Component text, int imgIndex, KeyMapping key, boolean critical public void render(GuiGraphics guiGraphics, int x, int y) { Font font = Minecraft.getInstance().font; if (critical) { - int innerWidth = 20 + 4 + font.width(text); + int innerWidth = 20 + 4 + font.width(text.get()); long currentTime = System.currentTimeMillis(); if (currentTime % 400 < 200) { guiGraphics.fill(x + 1, y + 1, x + innerWidth + 4 + 1, y + 20 + 1, 0xFF444444); @@ -128,7 +138,7 @@ public void render(GuiGraphics guiGraphics, int x, int y) { guiGraphics.disableScissor(); } } - guiGraphics.drawString(font, text, x + 20 + 4, y + 10 - 4, 0xFFFFFFFF, true); + guiGraphics.drawString(font, text.get(), x + 20 + 4, y + 10 - 4, 0xFFFFFFFF, true); } } } diff --git a/common/src/main/resources/assets/worldcomment/lang/en_us.json b/common/src/main/resources/assets/worldcomment/lang/en_us.json index b380e2e..ff80302 100644 --- a/common/src/main/resources/assets/worldcomment/lang/en_us.json +++ b/common/src/main/resources/assets/worldcomment/lang/en_us.json @@ -26,7 +26,7 @@ "gui.worldcomment.config.screenshot_comments": "Include other comments in Screenshot", "gui.worldcomment.control_tip.create": "Make Comment", - "gui.worldcomment.control_tip.toggle_show": "Show Hidden Comments", + "gui.worldcomment.control_tip.toggle_show": "Show Hidden Comments (%d)", "gui.worldcomment.control_tip.toggle_hide": "Hide Comments", "gui.worldcomment.control_tip.place_comment": "Place Down the Comment", "gui.worldcomment.control_tip.view_manage": "View / Manage Comments", diff --git a/common/src/main/resources/assets/worldcomment/lang/zh_cn.json b/common/src/main/resources/assets/worldcomment/lang/zh_cn.json index 935e9ac..1368422 100644 --- a/common/src/main/resources/assets/worldcomment/lang/zh_cn.json +++ b/common/src/main/resources/assets/worldcomment/lang/zh_cn.json @@ -26,7 +26,7 @@ "gui.worldcomment.config.screenshot_comments": "截图中包括其他评论", "gui.worldcomment.control_tip.create": "发表评论", - "gui.worldcomment.control_tip.toggle_show": "显示被隐藏的评论", + "gui.worldcomment.control_tip.toggle_show": "显示被隐藏的评论 (%d)", "gui.worldcomment.control_tip.toggle_hide": "隐藏评论", "gui.worldcomment.control_tip.place_comment": "在喜欢的位置放下评论", "gui.worldcomment.control_tip.view_manage": "查看/管理评论",