From 49b2acff325fa7cbd5830a2adb75a1566919f1f3 Mon Sep 17 00:00:00 2001
From: HappyRespawnanchor
<80967824+HappyRespawnanchor@users.noreply.github.com>
Date: Sun, 6 Oct 2024 20:07:14 +0800
Subject: [PATCH] =?UTF-8?q?=E6=8B=86=E5=AD=90=E7=B1=BB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ayamemc/ayame/client/gui/Alignment.java | 29 ------
.../client/gui/screen/AyameMainScreen.java | 84 ++++++------------
.../gui/screen/ModelSelectMenuScreen.java | 52 +++++++++++
.../client/gui/screen/SettingsScreen.java | 9 --
.../resources/assets/ayame/lang/en_us.json | 2 +-
.../resources/assets/ayame/lang/zh_cn.json | 2 +-
.../ayame/textures/gui/sprites/opendir.png | Bin 179 -> 177 bytes
.../gui/sprites/opendir_enabled_focused.png | Bin 207 -> 171 bytes
8 files changed, 79 insertions(+), 99 deletions(-)
delete mode 100644 common/src/main/java/org/ayamemc/ayame/client/gui/Alignment.java
diff --git a/common/src/main/java/org/ayamemc/ayame/client/gui/Alignment.java b/common/src/main/java/org/ayamemc/ayame/client/gui/Alignment.java
deleted file mode 100644
index 05f7ad9..0000000
--- a/common/src/main/java/org/ayamemc/ayame/client/gui/Alignment.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Custom player model mod. Powered by GeckoLib.
- * Copyright (C) 2024 CrystalNeko, HappyRespawnanchor, pertaz(Icon Designer)
- *
- * This file is part of Ayame.
- *
- * Ayame is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Ayame 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 Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with Ayame. If not, see .
- */
-
-package org.ayamemc.ayame.client.gui;
-
-public enum Alignment {
- CENTER,
- LEFT,
- RIGHT,
- TOP,
- BOTTOM,
-}
diff --git a/common/src/main/java/org/ayamemc/ayame/client/gui/screen/AyameMainScreen.java b/common/src/main/java/org/ayamemc/ayame/client/gui/screen/AyameMainScreen.java
index 7b7a76b..2cad6fb 100644
--- a/common/src/main/java/org/ayamemc/ayame/client/gui/screen/AyameMainScreen.java
+++ b/common/src/main/java/org/ayamemc/ayame/client/gui/screen/AyameMainScreen.java
@@ -14,7 +14,6 @@
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import org.ayamemc.ayame.Ayame;
-import org.ayamemc.ayame.client.gui.Alignment;
import org.ayamemc.ayame.client.gui.widget.BlurWidget;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -28,13 +27,12 @@ public abstract class AyameMainScreen 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;
+ protected static final int BACKGROUND_TEXTURE_WIDTH = 410;
+ protected static final int BACKGROUND_TEXTURE_HEIGHT = 220;
private static final int BUTTON_SIZE = 32;
+ protected static final int MINI_BUTTON_SIZE = 16;
- protected final Screen lastScreen;
+ protected Screen lastScreen;
public AyameMainScreen(@Nullable Screen lastScreen) {
super(Component.empty());
@@ -45,20 +43,6 @@ public AyameMainScreen(@Nullable Screen lastScreen) {
protected void init() {
BlurWidget blurredBackgroundWidget = new BlurWidget(getCenteredX(BACKGROUND_TEXTURE_WIDTH), getCenteredY(BACKGROUND_TEXTURE_HEIGHT), BACKGROUND_TEXTURE_WIDTH, BACKGROUND_TEXTURE_HEIGHT);
this.addRenderableOnly(blurredBackgroundWidget);
-
- final int searchBarWidth = 112;
- final int searchBarHeight = 23;
- EditBox searchBarEditBox = new EditBox(
- this.font,
- getAlignedX(BACKGROUND_TEXTURE_WIDTH, searchBarWidth, 0, Alignment.CENTER) + 27,
- getAlignedY(BACKGROUND_TEXTURE_HEIGHT, searchBarHeight, 0, Alignment.TOP) + 1,
- searchBarWidth,
- searchBarHeight,
- Component.translatable("ayame.widget.searchBarEditBox")
- );
- searchBarEditBox.setHint(Component.translatable("ayame.widget.searchBarEditBox").withStyle(ChatFormatting.DARK_GRAY));
- searchBarEditBox.setBordered(true);
- addRenderableWidget(searchBarEditBox);
}
@Override
@@ -90,11 +74,7 @@ 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(
getAlignedX(BACKGROUND_TEXTURE_WIDTH, BUTTON_SIZE, 0, Alignment.LEFT),
getAlignedY(BACKGROUND_TEXTURE_HEIGHT, BUTTON_SIZE, 0, Alignment.BOTTOM),
@@ -102,27 +82,13 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta)
BUTTON_SIZE,
settingSprites,
button -> {
- Ayame.LOGGER.info("Setting button clicked.");
minecraft.setScreen(new SettingsScreen(this));
},
- Component.empty()
+ Component.translatable("ayame.screen.warningscreen.settingsscreen.title")
);
- ImageButton opendirButton = new ImageButton(
- getAlignedX(BACKGROUND_TEXTURE_WIDTH, BUTTON_SIZE, 0, Alignment.LEFT),
- getAlignedY(BACKGROUND_TEXTURE_HEIGHT, BUTTON_SIZE, 90, Alignment.BOTTOM),
- 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);
Component titleText = Component.translatable(setTranslatableTitle());
int centerX = getCenteredStringX(titleText);
@@ -143,15 +109,11 @@ protected int getCenteredY(int elementHeight) {
protected int getAlignedX(int containerWidth, int elementWidth, int margin, Alignment alignment) {
int baseX = getCenteredX(containerWidth);
- switch (alignment) {
- case LEFT:
- return baseX + margin;
- case RIGHT:
- return baseX + containerWidth - elementWidth - margin;
- case CENTER:
- default:
- return baseX + (containerWidth - elementWidth) / 2;
- }
+ return switch (alignment) {
+ case LEFT -> baseX + margin;
+ case RIGHT -> baseX + containerWidth - elementWidth - margin;
+ default -> baseX + (containerWidth - elementWidth) / 2;
+ };
}
protected int getCenteredStringX(Component text) {
@@ -162,19 +124,23 @@ protected int getCenteredStringX(Component text) {
protected int getAlignedY(int containerHeight, int elementHeight, int margin, Alignment alignment) {
int baseY = getCenteredY(containerHeight);
- switch (alignment) {
- case TOP:
- return baseY + margin;
- case BOTTOM:
- return baseY + containerHeight - elementHeight - margin;
- case CENTER:
- default:
- return baseY + (containerHeight - elementHeight) / 2;
- }
+ return switch (alignment) {
+ case TOP -> baseY + margin;
+ case BOTTOM -> baseY + containerHeight - elementHeight - margin;
+ default -> baseY + (containerHeight - elementHeight) / 2;
+ };
}
@Override
public void onClose() {
minecraft.setScreen(lastScreen);
}
+
+ protected enum Alignment {
+ CENTER,
+ LEFT,
+ RIGHT,
+ TOP,
+ BOTTOM,
+ }
}
\ No newline at end of file
diff --git a/common/src/main/java/org/ayamemc/ayame/client/gui/screen/ModelSelectMenuScreen.java b/common/src/main/java/org/ayamemc/ayame/client/gui/screen/ModelSelectMenuScreen.java
index ee67900..6503224 100644
--- a/common/src/main/java/org/ayamemc/ayame/client/gui/screen/ModelSelectMenuScreen.java
+++ b/common/src/main/java/org/ayamemc/ayame/client/gui/screen/ModelSelectMenuScreen.java
@@ -20,10 +20,19 @@
package org.ayamemc.ayame.client.gui.screen;
+import com.mojang.blaze3d.vertex.PoseStack;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
+import net.minecraft.ChatFormatting;
+import net.minecraft.Util;
import net.minecraft.client.Minecraft;
+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;
import net.minecraft.resources.ResourceLocation;
import org.ayamemc.ayame.client.api.ModelResourceAPI;
import org.ayamemc.ayame.client.resource.IModelResource;
@@ -33,8 +42,11 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import java.nio.file.Path;
import java.util.List;
+import static org.ayamemc.ayame.util.ResourceLocationHelper.withAyameNamespace;
+
/**
* {@code ModelSelectMenuScreen} 负责处理 Ayame 模型的选择界面。
*
@@ -54,6 +66,11 @@
*/
@Environment(EnvType.CLIENT)
public class ModelSelectMenuScreen extends AyameMainScreen {
+ protected static final Path MODEL_DIR = Path.of("config/ayame/models/");
+
+ public final static int searchBarWidth = 112;
+ public final static int searchBarHeight = 23;
+
public final boolean skipWarningOnce;
public final List modelResources;
public @Nullable AyameModelType selectedModel = AyameModelCache.getPlayerModel(Minecraft.getInstance().player);
@@ -125,6 +142,41 @@ protected void init() {
return;
}
super.init(); // 调用父类的初始化方法,加载通用的背景和组件
+ EditBox searchBox = new EditBox(
+ this.font,
+ getAlignedX(BACKGROUND_TEXTURE_WIDTH, searchBarWidth, 0, Alignment.CENTER) + 27,
+ getAlignedY(BACKGROUND_TEXTURE_HEIGHT, searchBarHeight, 0, Alignment.TOP) + 1,
+ searchBarWidth,
+ searchBarHeight,
+ Component.translatable("ayame.widget.searchBox")
+ );
+ searchBox.setHint(Component.translatable("ayame.widget.searchBox").withStyle(ChatFormatting.DARK_GRAY));
+ searchBox.setBordered(true);
+ addRenderableWidget(searchBox);
+ }
+
+ @Override
+ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) {
+ super.render(guiGraphics, mouseX, mouseY, delta);
+
+ WidgetSprites opendirSprites = new WidgetSprites(
+ withAyameNamespace("opendir"),
+ withAyameNamespace("opendir"),
+ withAyameNamespace("opendir_enabled_focused")
+ );
+ ImageButton opendirButton = new ImageButton(
+ getAlignedX(BACKGROUND_TEXTURE_WIDTH, MINI_BUTTON_SIZE, 0, Alignment.RIGHT) - 125,
+ getAlignedY(BACKGROUND_TEXTURE_HEIGHT, MINI_BUTTON_SIZE, 0, Alignment.BOTTOM) - 3,
+ MINI_BUTTON_SIZE,
+ MINI_BUTTON_SIZE,
+ opendirSprites,
+ button -> {
+ Util.getPlatform().openPath(MODEL_DIR);
+ },
+ Component.translatable("ayame.button.opendir.tooltip")
+ );
+ opendirButton.setTooltip(Tooltip.create(Component.translatable("ayame.button.opendir.tooltip")));
+ addRenderableWidget(opendirButton);
}
diff --git a/common/src/main/java/org/ayamemc/ayame/client/gui/screen/SettingsScreen.java b/common/src/main/java/org/ayamemc/ayame/client/gui/screen/SettingsScreen.java
index d2d0f84..8b2dc9b 100644
--- a/common/src/main/java/org/ayamemc/ayame/client/gui/screen/SettingsScreen.java
+++ b/common/src/main/java/org/ayamemc/ayame/client/gui/screen/SettingsScreen.java
@@ -40,13 +40,4 @@ public SettingsScreen(@Nullable Screen lastScreen) {
protected @NotNull String setTranslatableTitle() {
return "ayame.screen.warningscreen.settingsscreen.title";
}
-
- @Override
- public void onClose() {
- if (minecraft.level == null) { // 玩家不是在世界内打开的话那肯定就是通过模组菜单打开的
- minecraft.setScreen(lastScreen);
- } else {
- minecraft.setScreen(null);
- }
- }
}
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 bb64796..1e2a32e 100644
--- a/common/src/main/resources/assets/ayame/lang/en_us.json
+++ b/common/src/main/resources/assets/ayame/lang/en_us.json
@@ -8,5 +8,5 @@
"ayame.screen.warningscreen.modelselectscreen.title": "Select Model",
"ayame.screen.warningscreen.settingsscreen.title": "Ayame Settings",
"ayame.button.opendir.tooltip": "Open Model Folder\n(Place model files here)",
- "ayame.widget.searchBarEditBox": "Search..."
+ "ayame.widget.searchBox": "Search..."
}
\ 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 5e77a39..86c4fb9 100644
--- a/common/src/main/resources/assets/ayame/lang/zh_cn.json
+++ b/common/src/main/resources/assets/ayame/lang/zh_cn.json
@@ -8,5 +8,5 @@
"ayame.screen.warningscreen.modelselectscreen.title": "选择模型",
"ayame.screen.warningscreen.settingsscreen.title": "Ayame 设置",
"ayame.button.opendir.tooltip": "打开模型文件夹\n(请将模型文件放在这里)",
- "ayame.widget.searchBarEditBox": "搜索..."
+ "ayame.widget.searchBox": "搜索..."
}
\ 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
index 41cd7a25767571d392097fbaeba5dea9d0be0080..b240e180010fe9fb2b34f9368147926edeee3182 100755
GIT binary patch
literal 177
zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|vOQfKLo9ml
zPB!E^pupq$dG&1dPyd?Li>6%nT#?kR>YcevVA6McPQixCL(B{oF|X3ZsxNuT&S{ym
zg;_$TWzH4$=#^(Kq<)dTV`}fnz@p$8oi#bS!9u*eZGF-^?LQ0#Iv?Mvo_WK(U*Wy=
Z{Ii|zO1(|@RsgMK@O1TaS?83{1OPe}KXCv6
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
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
index 8bd478a5fea9c44fdfbe087db04b5f857fa70048..c187bbcc34b1c68c4485117a34eb12c01e9bf443 100755
GIT binary patch
literal 171
zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|QaxQ9Lo9le
z|NQ^|zn+bYft#6``SAYf_fK3pqjK)(0hi9V1>y!EaL0XepvomtiCGC!?~@Hh)^iu!
ztdrlL9l(1aRoSf2HHS^$Wqt~?W?yS!0z=_OhbfFljxk6rxWU~sB`uv{QmnA*?-jS_
Q11)6mboFyt=akR{0FiY%P5=M^
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*