Skip to content

Commit

Permalink
Add hide GUI when taking screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
zbx1425 committed Dec 20, 2023
1 parent 29671eb commit e96d7c3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ public static void grabScreenshot(Consumer<byte[]> callback) {
callback.accept(nativeImage.asByteArray());
} catch (IOException ex) {
Main.LOGGER.error("Failed to save screenshot", ex);
} finally {
OverlayLayer.isTakingScreenshot = false;
}
}

Expand Down Expand Up @@ -61,10 +59,15 @@ public static boolean handleKeyF2() {
if (item.getOrCreateTag().contains("uploadJobId", Tag.TAG_LONG)) return false;

if (minecraft.screen == null) {
grabScreenshot(imageBytes -> {
Minecraft.getInstance().execute(() -> {
minecraft.player.playSound(shutterSoundEvent);
Minecraft.getInstance().setScreen(new CommentToolScreen(imageBytes));
minecraft.tell(() -> {
boolean prevHideGui = minecraft.options.hideGui;
minecraft.options.hideGui = !minecraft.options.keySprint.isDown();
RenderSystem.recordRenderCall(() -> {
grabScreenshot(imageBytes -> minecraft.execute(() -> {
minecraft.player.playSound(shutterSoundEvent);
Minecraft.getInstance().setScreen(new CommentToolScreen(imageBytes));
}));
minecraft.options.hideGui = prevHideGui;
});
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,14 @@ public class ControlTipRenderer implements IGuiCommon {
Component.translatable("gui.worldcomment.control_tip.scroll"), 1,
null, false
);
public static final ControlTip TIP_INCLUDE_HUD = new ControlTip(
Component.translatable("gui.worldcomment.control_tip.screenshot_hud"), 2,
Minecraft.getInstance().options.keySprint, false
);

public static final List<ControlTip> TIPS =
List.of(TIP_PLACE_COMMENT, TIP_TOGGLE_SHOW, TIP_TOGGLE_HIDE, TIP_CREATE, TIP_VIEW_MANAGE, TIP_SCROLL, TIP_DETAIL);
List.of(TIP_PLACE_COMMENT, TIP_TOGGLE_SHOW, TIP_TOGGLE_HIDE, TIP_CREATE,
TIP_VIEW_MANAGE, TIP_SCROLL, TIP_DETAIL, TIP_INCLUDE_HUD);

public static void render(GuiGraphics guiGraphics) {
update();
Expand All @@ -71,6 +76,7 @@ public static void update() {
return; // De-clutter
} else {
TIP_CREATE.visible = true;
TIP_INCLUDE_HUD.visible = true;
if (MainClient.CLIENT_CONFIG.isCommentVisible) {
TIP_TOGGLE_HIDE.visible = true;
} else {
Expand Down Expand Up @@ -116,8 +122,16 @@ public void render(GuiGraphics guiGraphics, int x, int y) {
guiGraphics.blit(ATLAS_LOCATION, x, y, 20, 20,
176 + imgIndex * 20, 0, 20, 20, 256, 256);
if (key != null) {
guiGraphics.drawCenteredString(font, key.getTranslatedKeyMessage(),
x + 10, y + 10 - 4, 0xFFFFECB3);
Component keyMessage = key.getTranslatedKeyMessage();
int keyMessageWidth = font.width(keyMessage);
if (keyMessageWidth < 30) {
guiGraphics.drawCenteredString(font, keyMessage, x + 10, y + 10 - 4, 0xFFFFECB3);
} else {
guiGraphics.enableScissor(x, y, x + 20, y + 20);
int xOffset = (int)((System.currentTimeMillis() / 50) % (keyMessageWidth + 40));
guiGraphics.drawString(font, keyMessage, x - xOffset + 20, y + 10 - 4, 0xFFFFECB3);
guiGraphics.disableScissor();
}
}
guiGraphics.drawString(font, text, x + 20 + 4, y + 10 - 4, 0xFFFFFFFF, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

public class OverlayLayer {

public static boolean isTakingScreenshot = false;

public static void render(GuiGraphics guiGraphics) {
Minecraft minecraft = Minecraft.getInstance();
if (minecraft.player == null || minecraft.screen != null) return;
Expand Down
7 changes: 4 additions & 3 deletions common/src/main/resources/assets/worldcomment/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"item.worldcomment.comment_tool": "§l§6Subnoteica§r Comment Tool",
"item.worldcomment.comment_tool": "§l§6World Comment§r Tool",

"gui.worldcomment.comment_type.r1": "Your valuable opinion",
"gui.worldcomment.comment_type.1": "Great",
Expand All @@ -13,7 +13,7 @@
"gui.worldcomment.comment_type.8": "Memo",

"gui.worldcomment.message": "Enter feedback here (Optional)",
"gui.worldcomment.message.placeholder": "(Example) I WANNA EAAAAAAAAAT TEA CAKE AHHHHHHH",
"gui.worldcomment.message.placeholder": "(Example) Amazing Chest Ahead",
"gui.worldcomment.exclude_screenshot": "No Image",
"gui.worldcomment.anonymous": "Anonymous",
"gui.worldcomment.save_screenshot": "Save Screenshot",
Expand All @@ -28,8 +28,9 @@
"gui.worldcomment.control_tip.view_manage": "View or Manage All Comments",
"gui.worldcomment.control_tip.detail": "See Detail",
"gui.worldcomment.control_tip.scroll": "Scroll",
"gui.worldcomment.control_tip.screenshot_hud": "Include HUD in Screenshot",

"gui.worldcomment.list.title": "Subnoteica Comment Management",
"gui.worldcomment.list.title": "World Comment Management",
"gui.worldcomment.list.nearby_posts": "Nearby Posts",
"gui.worldcomment.list.recent_posts": "Recent Posts",
"gui.worldcomment.list.my_posts": "My Posts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"gui.worldcomment.comment_type.8": "留言",

"gui.worldcomment.message": "请在此处留言 (非必须)",
"gui.worldcomment.message.placeholder": "(示例) 我要吃吃吃吃吃吃吃吃吃吃吃吃吃吃吃茶点啊啊啊啊啊",
"gui.worldcomment.message.placeholder": "(示例) 前有巨大宝箱",
"gui.worldcomment.exclude_screenshot": "不包含截图",
"gui.worldcomment.anonymous": "匿名评论",
"gui.worldcomment.save_screenshot": "另存截图",
Expand All @@ -28,6 +28,7 @@
"gui.worldcomment.control_tip.view_manage": "查看或管理所有评论",
"gui.worldcomment.control_tip.detail": "查看详情",
"gui.worldcomment.control_tip.scroll": "滚动",
"gui.worldcomment.control_tip.screenshot_hud": "截图包括叠加层",

"gui.worldcomment.list.title": "§l随处随笔§r 评论管理",
"gui.worldcomment.list.nearby_posts": "附近评论",
Expand Down

0 comments on commit e96d7c3

Please sign in to comment.