Skip to content

Commit

Permalink
Add timer for comment hiding
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Dec 15, 2024
1 parent d5d16c1 commit f752c3c
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
12 changes: 12 additions & 0 deletions common/src/main/java/cn/zbx1425/worldcomment/ClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check failure on line 6 in common/src/main/java/cn/zbx1425/worldcomment/ClientConfig.java

View workflow job for this annotation

GitHub Actions / build (1.19.2)

[Task :common:compileJava FAILED] cannot find symbol

Check failure on line 6 in common/src/main/java/cn/zbx1425/worldcomment/ClientConfig.java

View workflow job for this annotation

GitHub Actions / build (1.20.1)

[Task :common:compileJava] cannot find symbol
import net.minecraft.network.FriendlyByteBuf;

import java.util.ArrayList;
Expand All @@ -15,6 +16,8 @@ public class ClientConfig {
public boolean screenshotIncludeGui = false;
public boolean screenshotIncludeComments = true;

public float commentHideTimer = 0f;

public List<ImageUploader> imageUploader;

public int allowMarkerUsage;
Expand Down Expand Up @@ -48,6 +51,15 @@ public static ClientConfig fromServerConfig(ServerConfig serverConfig) {
return config;
}

public void tick(DeltaTracker deltaTracker) {

Check failure on line 54 in common/src/main/java/cn/zbx1425/worldcomment/ClientConfig.java

View workflow job for this annotation

GitHub Actions / build (1.19.2)

[Task :common:compileJava FAILED] cannot find symbol public void tick(DeltaTracker deltaTracker) { ^ symbol: class DeltaTracker

Check failure on line 54 in common/src/main/java/cn/zbx1425/worldcomment/ClientConfig.java

View workflow job for this annotation

GitHub Actions / build (1.20.1)

[Task :common:compileJava] cannot find symbol public void tick(DeltaTracker deltaTracker) { ^ symbol: class DeltaTracker
if (commentHideTimer > 0) {
commentHideTimer -= deltaTracker.getGameTimeDeltaTicks();
if (commentHideTimer <= 0) {
isCommentVisible = true;
}
}
}

public ClientConfig() {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() -> {
Expand All @@ -80,6 +82,7 @@ public static boolean handleKeyF2() {
}));
minecraft.options.hideGui = prevHideGui;
MainClient.CLIENT_CONFIG.isCommentVisible = prevIsCommentVisible;
MainClient.CLIENT_CONFIG.commentHideTimer = prevCommentHideTimer;
}))));
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.world.item.ItemStack;

import java.util.List;
import java.util.function.Supplier;

public class ControlTipRenderer implements IGuiCommon {

Expand All @@ -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(
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -93,11 +96,18 @@ public static class ControlTip {
public int imgIndex;
public KeyMapping key;
public boolean critical;
public Component text;
public Supplier<Component> 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<Component> text, int imgIndex, KeyMapping key, boolean critical) {
this.text = text;
this.imgIndex = imgIndex;
this.key = key;
Expand All @@ -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);
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": "查看/管理评论",
Expand Down

0 comments on commit f752c3c

Please sign in to comment.