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 41cd7a2..b240e18 100755 Binary files a/common/src/main/resources/assets/ayame/textures/gui/sprites/opendir.png and b/common/src/main/resources/assets/ayame/textures/gui/sprites/opendir.png differ 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 8bd478a..c187bbc 100755 Binary files a/common/src/main/resources/assets/ayame/textures/gui/sprites/opendir_enabled_focused.png and b/common/src/main/resources/assets/ayame/textures/gui/sprites/opendir_enabled_focused.png differ