From 2d0fc8f8593afe619d0c6d3bc1321c3b3badcf47 Mon Sep 17 00:00:00 2001
From: HappyRespawnanchor
<80967824+HappyRespawnanchor@users.noreply.github.com>
Date: Fri, 4 Oct 2024 20:01:21 +0800
Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=BC=80=E6=96=87=E4=BB=B6=E5=A4=B9?=
=?UTF-8?q?=E6=8C=89=E9=92=AE=E6=B7=BB=E5=8A=A0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../gui/screen/AbstractModelMenuScreen.java | 75 +++++++++++++++---
.../resources/assets/ayame/lang/en_us.json | 4 +-
.../resources/assets/ayame/lang/zh_cn.json | 4 +-
.../ayame/textures/gui/sprites/opendir.png | Bin 0 -> 179 bytes
.../gui/sprites/opendir_enabled_focused.png | Bin 0 -> 207 bytes
5 files changed, 69 insertions(+), 14 deletions(-)
create mode 100755 common/src/main/resources/assets/ayame/textures/gui/sprites/opendir.png
create mode 100755 common/src/main/resources/assets/ayame/textures/gui/sprites/opendir_enabled_focused.png
diff --git a/common/src/main/java/org/ayamemc/ayame/client/gui/screen/AbstractModelMenuScreen.java b/common/src/main/java/org/ayamemc/ayame/client/gui/screen/AbstractModelMenuScreen.java
index 06a59b5..31e5c83 100644
--- a/common/src/main/java/org/ayamemc/ayame/client/gui/screen/AbstractModelMenuScreen.java
+++ b/common/src/main/java/org/ayamemc/ayame/client/gui/screen/AbstractModelMenuScreen.java
@@ -23,8 +23,11 @@
import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
+import net.minecraft.Util;
import net.minecraft.client.gui.GuiGraphics;
+import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.components.ImageButton;
+import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.components.WidgetSprites;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
@@ -33,17 +36,19 @@
import org.ayamemc.ayame.client.gui.widget.BlurWidget;
import org.jetbrains.annotations.Nullable;
+import java.nio.file.Path;
+
@Environment(EnvType.CLIENT)
public abstract class AbstractModelMenuScreen extends Screen {
public static final ResourceLocation MENU_BACKGROUND_TEXTURE = withAyameNamespace("textures/gui/background.png");
public static final ResourceLocation MENU_BACKGROUND_OUTLINE_TEXTURE = withAyameNamespace("textures/gui/background_outline.png");
public static final ResourceLocation MENU_TOP_LAYER_TEXTURE = withAyameNamespace("textures/gui/top_layer.png");
public static final ResourceLocation SETTINGS_TEXTURE = withAyameNamespace("textures/gui/settings.png");
+ private static final Path MODEL_DIR = Path.of("config/ayame/models/");
private static final int BACKGROUND_TEXTURE_WIDTH = 410;
private static final int BACKGROUND_TEXTURE_HEIGHT = 220;
private static final int BUTTON_SIZE = 32;
- private static final int LEFT_MARGIN = 0;
- private static final int BOTTOM_MARGIN = 0;
+
protected final Screen lastScreen;
public AbstractModelMenuScreen(@Nullable Screen lastScreen) {
@@ -62,8 +67,19 @@ private static ResourceLocation withAyameNamespace(String location) {
protected void init() {
BlurWidget blurredBackgroundWidget = new BlurWidget(getCenterX(BACKGROUND_TEXTURE_WIDTH), getCenterY(BACKGROUND_TEXTURE_HEIGHT), BACKGROUND_TEXTURE_WIDTH, BACKGROUND_TEXTURE_HEIGHT);
this.addRenderableOnly(blurredBackgroundWidget);
+ EditBox searchBarEditBox = new EditBox(
+ this.font,
+ getComponentCenterX(208),
+ getComponentCenterY(20) - 90,
+ 208,
+ 20,
+ Component.translatable("ayame.widget.searchBarEditBox")
+ );
+ addRenderableWidget(searchBarEditBox);
+
}
+
/**
* 渲染背景纹理
*/
@@ -72,6 +88,7 @@ public void renderBackground(GuiGraphics guiGraphics, int mouseX, int mouseY, fl
RenderSystem.enableBlend();
guiGraphics.blit(MENU_BACKGROUND_TEXTURE, getCenterX(BACKGROUND_TEXTURE_WIDTH), getCenterY(BACKGROUND_TEXTURE_HEIGHT), 0, 0, BACKGROUND_TEXTURE_WIDTH, BACKGROUND_TEXTURE_HEIGHT, BACKGROUND_TEXTURE_WIDTH, BACKGROUND_TEXTURE_HEIGHT);
RenderSystem.disableBlend();
+
}
/**
@@ -90,24 +107,44 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta)
withAyameNamespace("settings_disabled"), // 似乎不会被使用
withAyameNamespace("settings_enabled_focused")
);
+ WidgetSprites opendirSprites = new WidgetSprites(
+ withAyameNamespace("opendir"),
+ withAyameNamespace("opendir"), // 似乎不会被使用
+ withAyameNamespace("opendir_enabled_focused")
+ );
ImageButton settingsButton = new ImageButton(
- getLeftAlignedX(BACKGROUND_TEXTURE_WIDTH, LEFT_MARGIN),
- getBottomAlignedY(BACKGROUND_TEXTURE_HEIGHT, BUTTON_SIZE, BOTTOM_MARGIN),
+ getLeftAlignedX(BACKGROUND_TEXTURE_WIDTH, 0),
+ getBottomAlignedY(BACKGROUND_TEXTURE_HEIGHT, BUTTON_SIZE, 0),
BUTTON_SIZE,
BUTTON_SIZE,
settingSprites,
button -> {
- if (!(this instanceof SettingsScreen)) {
- minecraft.setScreen(new SettingsScreen(this));
- }
+ Ayame.LOGGER.info("Setting button clicked.");
+ minecraft.setScreen(new SettingsScreen(this));
},
Component.empty()
);
- if (this instanceof SettingsScreen) {
- addRenderableOnly(settingsButton);
- } else {
- addRenderableWidget(settingsButton);
- }
+ ImageButton opendirButton = new ImageButton(
+ getLeftAlignedX(BACKGROUND_TEXTURE_WIDTH, 0),
+ getBottomAlignedY(BACKGROUND_TEXTURE_HEIGHT, BUTTON_SIZE, 90),
+ BUTTON_SIZE,
+ BUTTON_SIZE,
+ opendirSprites,
+ button -> {
+ Ayame.LOGGER.info("Opendir button clicked.");
+ Util.getPlatform().openPath(MODEL_DIR);
+ },
+ Component.empty()
+ );
+ opendirButton.setTooltip(Tooltip.create(Component.translatable("ayame.button.opendir.tooltip")));
+
+ addRenderableWidget(settingsButton);
+ addRenderableWidget(opendirButton);
+// if (this instanceof SettingsScreen) {
+// addRenderableOnly(settingsButton);
+// } else {
+// addRenderableWidget(settingsButton);
+// }
Component text = Component.translatable(setTranslatableTitle());
@@ -169,6 +206,20 @@ protected int getCenteredStringX(Component text) {
return (this.width - textWidth) / 2;
}
+ /**
+ * 获取与贴图无关的组件在屏幕中心的 X 坐标
+ */
+ protected int getComponentCenterX(int componentWidth) {
+ return (this.width - componentWidth) / 2;
+ }
+
+ /**
+ * 获取与贴图无关的组件在屏幕中心的 Y 坐标
+ */
+ protected int getComponentCenterY(int componentHeight) {
+ return (this.height - componentHeight) / 2;
+ }
+
@Override
public void onClose() {
minecraft.setScreen(lastScreen);
diff --git a/common/src/main/resources/assets/ayame/lang/en_us.json b/common/src/main/resources/assets/ayame/lang/en_us.json
index 5a4f1e3..97f26bc 100644
--- a/common/src/main/resources/assets/ayame/lang/en_us.json
+++ b/common/src/main/resources/assets/ayame/lang/en_us.json
@@ -6,5 +6,7 @@
"ayame.screen.warningscreen.statementscreen.title": "Statement",
"ayame.screen.warningscreen.statementscreen.content": "Ayame is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.\n\nAyame is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program. If not, see .",
"ayame.screen.warningscreen.modelselectscreen.title": "Select Model",
- "ayame.screen.warningscreen.settingsscreen.title": "Ayame Settings"
+ "ayame.screen.warningscreen.settingsscreen.title": "Ayame Settings",
+ "ayame.button.opendir.tooltip": "Open Model Folder\n(Place model files here)",
+ "ayame.widget.searchBarEditBox": "Search Model ..."
}
\ No newline at end of file
diff --git a/common/src/main/resources/assets/ayame/lang/zh_cn.json b/common/src/main/resources/assets/ayame/lang/zh_cn.json
index 52d7960..ec68b5a 100644
--- a/common/src/main/resources/assets/ayame/lang/zh_cn.json
+++ b/common/src/main/resources/assets/ayame/lang/zh_cn.json
@@ -6,5 +6,7 @@
"ayame.screen.warningscreen.statementscreen.title": "声明",
"ayame.screen.warningscreen.statementscreen.content": "Ayame是自由软件:您可以按照自由软件基金会发布的GNU宽通用公共许可证的条款重新分发和/或修改Ayame;\n许可证的第3版或(根据您的选择)任何更高版本均适用。\n\nAyame的发布是为了希望它能够发挥作用,但并不提供任何担保;甚至不包含适销性或针对特定用途的适用性的默示担保。有关详细信息,请参阅GNU宽通用公共许可证。\n\n您应该已经随Ayame一同收到了GNU宽通用公共许可证的副本。如果没有,请参阅 。",
"ayame.screen.warningscreen.modelselectscreen.title": "选择模型",
- "ayame.screen.warningscreen.settingsscreen.title": "Ayame 设置"
+ "ayame.screen.warningscreen.settingsscreen.title": "Ayame 设置",
+ "ayame.button.opendir.tooltip": "打开模型文件夹\n(请将模型文件放在这里)",
+ "ayame.widget.searchBarEditBox": "搜索模型……"
}
\ No newline at end of file
diff --git a/common/src/main/resources/assets/ayame/textures/gui/sprites/opendir.png b/common/src/main/resources/assets/ayame/textures/gui/sprites/opendir.png
new file mode 100755
index 0000000000000000000000000000000000000000..41cd7a25767571d392097fbaeba5dea9d0be0080
GIT binary patch
literal 179
zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}xt=bLArY;~
z2@i1!4IprNmr*QqE!GR{<5C8xFcac1G;)KV>^Bb)i
zq}YVHABY7?O!4GGp}
bCI*J4Sh=H)E5FgTe~DWM4f9A!Tw
literal 0
HcmV?d00001
diff --git a/common/src/main/resources/assets/ayame/textures/gui/sprites/opendir_enabled_focused.png b/common/src/main/resources/assets/ayame/textures/gui/sprites/opendir_enabled_focused.png
new file mode 100755
index 0000000000000000000000000000000000000000..8bd478a5fea9c44fdfbe087db04b5f857fa70048
GIT binary patch
literal 207
zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}ot`d^ArY-_
zr*GtIP~dTSf5Eff8iD;Xud
zKb7yo^7iDLUGo;rc3;IXMMS&x9}B}LXUX6-ybA&?!VCH4yuNozm_c9}qsq@6jk65?
z2F{ZHY*xa+UI0b`ktbI@&EClzp;gv+mHldrxbj1zw?1A
BOQZk*
literal 0
HcmV?d00001