Skip to content

Commit

Permalink
Add size hints for slide item
Browse files Browse the repository at this point in the history
  • Loading branch information
ustc-zzzz committed Aug 16, 2024
1 parent ee4bb42 commit 5fd6fc3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/main/java/org/teacon/slides/screen/SlideItemScreen.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.teacon.slides.screen;

import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.ChatFormatting;
import net.minecraft.FieldsAreNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.client.gui.GuiGraphics;
Expand Down Expand Up @@ -37,7 +38,29 @@ public final class SlideItemScreen extends AbstractContainerScreen<SlideItemCont
private static final Component
IMAGE_TEXT = Component.translatable("gui.slide_show.section.image"),
URL_TEXT = Component.translatable("gui.slide_show.url"),
SIZE_TEXT = Component.translatable("gui.slide_show.size");
SIZE_TEXT = Component.translatable("gui.slide_show.size"),
SIZE_HINT_1 = Component.translatable("gui.slide_show.size_hint.two",
Component.literal("contain").withStyle(ChatFormatting.AQUA),
Component.literal("cover").withStyle(ChatFormatting.AQUA))
.withStyle(ChatFormatting.GRAY),
SIZE_HINT_2 = Component.translatable("gui.slide_show.size_hint.contain_or_cover")
.withStyle(ChatFormatting.GRAY),
SIZE_HINT_3 = Component.translatable("gui.slide_show.size_hint.two",
Component.literal("<width>% auto").withStyle(ChatFormatting.AQUA),
Component.literal("<width>%").withStyle(ChatFormatting.AQUA))
.withStyle(ChatFormatting.GRAY),
SIZE_HINT_4 = Component.translatable("gui.slide_show.size_hint.height_auto")
.withStyle(ChatFormatting.GRAY),
SIZE_HINT_5 = Component.translatable("gui.slide_show.size_hint.one",
Component.literal("auto <height>%").withStyle(ChatFormatting.AQUA))
.withStyle(ChatFormatting.GRAY),
SIZE_HINT_6 = Component.translatable("gui.slide_show.size_hint.width_auto")
.withStyle(ChatFormatting.GRAY),
SIZE_HINT_7 = Component.translatable("gui.slide_show.size_hint.one",
Component.literal("<width>% <height>%").withStyle(ChatFormatting.AQUA))
.withStyle(ChatFormatting.GRAY),
SIZE_HINT_8 = Component.translatable("gui.slide_show.size_hint.both")
.withStyle(ChatFormatting.GRAY);

private static final int
URL_MAX_LENGTH = 1 << 9,
Expand Down Expand Up @@ -180,7 +203,11 @@ protected void renderTooltip(GuiGraphics gui, int mouseX, int mouseY) {
if (offsetX >= 7 && offsetY >= 35 && offsetX < 25 && offsetY < 54) {
gui.renderComponentTooltip(font, this.getUrlTexts(), mouseX, mouseY);
} else if (offsetX >= 7 && offsetY >= 57 && offsetX < 25 && offsetY < 76) {
gui.renderTooltip(font, SIZE_TEXT, mouseX, mouseY);
gui.renderComponentTooltip(font, List.of(SIZE_TEXT,
Component.literal(""), SIZE_HINT_1, SIZE_HINT_2,
Component.literal(""), SIZE_HINT_3, SIZE_HINT_4,
Component.literal(""), SIZE_HINT_5, SIZE_HINT_6,
Component.literal(""), SIZE_HINT_7, SIZE_HINT_8), mouseX, mouseY);
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/assets/slide_show/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
"gui.slide_show.rotate": "Rotate Clockwise",
"gui.slide_show.single_double_sided": "Switch Single-Sided / Double-Sided",

"gui.slide_show.size_hint.one": "%s",
"gui.slide_show.size_hint.two": "%s or %s",
"gui.slide_show.size_hint.contain_or_cover": "While preserving its aspect ratio, the image is rendered at the largest size contained within, or covering, the projection area defined by the projector",
"gui.slide_show.size_hint.height_auto": "The width will be stretched to the specified percentage while the height is computed using the image's corresponding aspect ratio",
"gui.slide_show.size_hint.width_auto": "The height will be stretched to the specified percentage while the width is computed using the image's corresponding aspect ratio",
"gui.slide_show.size_hint.both": "The width and the height will be stretched to the specified percentage of the projection area defined by the projector",

"gui.slide_show.log_comment": "at %s by %s",
"gui.slide_show.log_comment_nobody": "at %s",
"gui.slide_show.log_message.slide_show.create_url": "The image was created in the server",
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/assets/slide_show/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
"gui.slide_show.rotate": "顺时针旋转",
"gui.slide_show.single_double_sided": "切换单面/双面",

"gui.slide_show.size_hint.one": "%s",
"gui.slide_show.size_hint.two": "%s 或 %s",
"gui.slide_show.size_hint.contain_or_cover": "缩放图片以完全覆盖(cover)或最大包含(contain)投影仪定义的投影区域",
"gui.slide_show.size_hint.height_auto": "宽度使用指定百分比,未指定的高度依图片固有长宽比例计算",
"gui.slide_show.size_hint.width_auto": "高度使用指定百分比,未指定的宽度依图片固有长宽比例计算",
"gui.slide_show.size_hint.both": "宽度和高度将拉伸至投影仪定义的投影区域的指定百分比",

"gui.slide_show.log_comment": "%s(操作者:%s)",
"gui.slide_show.log_comment_nobody": "%s",
"gui.slide_show.log_message.slide_show.create_url": "该图片在服务器的创建时间:",
Expand Down

0 comments on commit 5fd6fc3

Please sign in to comment.