From 904c14b5a3a203c1e4a8e6c3cfdcce10b4d6f4ac Mon Sep 17 00:00:00 2001 From: HappyRespawnanchor <80967824+HappyRespawnanchor@users.noreply.github.com> Date: Thu, 3 Oct 2024 19:51:19 +0800 Subject: [PATCH] =?UTF-8?q?=E7=95=8C=E9=9D=A2=E5=B8=83=E5=B1=80=E4=B8=8E?= =?UTF-8?q?=E5=B1=8F=E5=B9=95=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gui/screen/AbstractModelMenuScreen.java | 32 +++++++---- .../gui/screen/ModelSelectMenuScreen.java | 21 +++++++- .../client/gui/screen/SettingsScreen.java | 50 ++++++++++++++++++ .../resources/assets/ayame/lang/en_us.json | 4 +- .../resources/assets/ayame/lang/zh_cn.json | 4 +- .../assets/ayame/textures/gui/top_layer.png | Bin 1308 -> 1427 bytes 6 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 common/src/main/java/org/ayamemc/ayame/client/gui/screen/SettingsScreen.java 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 12dae3a..89795ab 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 @@ -37,15 +37,13 @@ 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 ResourceLocation MENU_TOP_LAYER_TEXTURE = withAyameNamespace("textures/gui/top_layer.png"); - public static ResourceLocation SETTINGS_TEXTURE = withAyameNamespace("textures/gui/settings.png"); - 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; - + public static ResourceLocation MENU_TOP_LAYER_TEXTURE = withAyameNamespace("textures/gui/top_layer.png"); + public static ResourceLocation SETTINGS_TEXTURE = withAyameNamespace("textures/gui/settings.png"); protected final Screen lastScreen; public AbstractModelMenuScreen(@Nullable Screen lastScreen) { @@ -92,19 +90,25 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) withAyameNamespace("settings_disabled"), // 似乎不会被使用 withAyameNamespace("settings_enabled_focused") ); - ImageButton imageButton = new ImageButton( + ImageButton settingsButton = new ImageButton( getLeftAlignedX(BACKGROUND_TEXTURE_WIDTH, LEFT_MARGIN), getBottomAlignedY(BACKGROUND_TEXTURE_HEIGHT, BUTTON_SIZE, BOTTOM_MARGIN), BUTTON_SIZE, BUTTON_SIZE, settingSprites, button -> { - // 按钮点击后的行为 - System.out.println("ImageButton"); + if(!(this instanceof SettingsScreen)) { + minecraft.setScreen(new SettingsScreen(this)); + + } }, - Component.literal("Image Button") + Component.empty() ); - addRenderableWidget(imageButton); + if (this instanceof SettingsScreen) { + addRenderableOnly(settingsButton); + } else { + addRenderableWidget(settingsButton); + } } /** @@ -134,4 +138,14 @@ protected int getLeftAlignedX(int containerWidth, int margin) { protected int getBottomAlignedY(int containerHeight, int elementHeight, int margin) { return getCenterY(containerHeight) + containerHeight - elementHeight - margin; } + + protected int getCenteredStringX(Component text) { + int textWidth = this.font.width(text); + return (this.width - textWidth) / 2; + } + + @Override + public void onClose() { + minecraft.setScreen(lastScreen); + } } 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 a687d55..12d3540 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,13 @@ 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.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; import org.ayamemc.ayame.client.api.ModelResourceAPI; import org.ayamemc.ayame.client.resource.IModelResource; import org.ayamemc.ayame.model.AyameModelCache; @@ -125,6 +128,22 @@ protected void init() { super.init(); // 调用父类的初始化方法,加载通用的背景和组件 } + @Override + public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) { + super.render(guiGraphics, mouseX, mouseY, delta); + + // 获取要渲染的文本 + Component text = Component.translatable("ayame.screen.warningscreen.modelselectscreen.title"); + + // 计算居中显示的 X 坐标 + int centerX = getCenteredStringX(text); + + // 渲染文本 + guiGraphics.drawString(this.font, text, centerX, font.lineHeight, 0xFFFFFFFF, true); + } + + + // int count = 0; // for (IModelResource res : modelResources){ @@ -151,7 +170,7 @@ protected void init() { */ @Override public void onClose() { - minecraft.setScreen(lastScreen); + super.onClose(); if (closeCallback != null) { closeCallback.close(modelResources, selectedModel); } 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 new file mode 100644 index 0000000..5c47579 --- /dev/null +++ b/common/src/main/java/org/ayamemc/ayame/client/gui/screen/SettingsScreen.java @@ -0,0 +1,50 @@ +/* + * 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.screen; + +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.Nullable; + +public class SettingsScreen extends AbstractModelMenuScreen{ + public SettingsScreen(@Nullable Screen lastScreen) { + super(lastScreen); + } + @Override + public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta) { + super.render(guiGraphics, mouseX, mouseY, delta); + + // 获取要渲染的文本 + Component text = Component.translatable("ayame.screen.warningscreen.settingsscreen.title"); + + // 计算居中显示的 X 坐标 + int centerX = getCenteredStringX(text); + + // 渲染文本 + guiGraphics.drawString(this.font, text, centerX, font.lineHeight, 0xFFFFFFFF, true); + } + + @Override + public void onClose() { + 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 6a8ed28..5a4f1e3 100644 --- a/common/src/main/resources/assets/ayame/lang/en_us.json +++ b/common/src/main/resources/assets/ayame/lang/en_us.json @@ -4,5 +4,7 @@ "key.categories.ayame": "Ayame", "key.ayame.model_select_menu": "Open Player Model GUI", "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.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" } \ 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 d44024d..52d7960 100644 --- a/common/src/main/resources/assets/ayame/lang/zh_cn.json +++ b/common/src/main/resources/assets/ayame/lang/zh_cn.json @@ -4,5 +4,7 @@ "key.categories.ayame": "Ayame", "key.ayame.model_select_menu": "打开玩家模型界面", "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.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 设置" } \ No newline at end of file diff --git a/common/src/main/resources/assets/ayame/textures/gui/top_layer.png b/common/src/main/resources/assets/ayame/textures/gui/top_layer.png index c555b9df67c592aec06d6592a81a72cafd8e5f73..699fafd2d5a1bc3a6c298814652cf35a3010f333 100755 GIT binary patch delta 327 zcmV-N0l5C03X==4wE6g%;wW>;B=5uU< zx1YWDGXM}-Gc)I$&yC@KBX?^)KbuR^JNW&-+ur+Gx0itLa!~y|E(yQOpW6!n@NScl z0z^ltb$bE$uD$njdk5g({)^B!C;;B;dT7o$pW8bCcerH!4*sJ7ASE;aq=W{5l+XZ> z5*h$fYsQx!0Cd*Oy-$n<4&ePfodJ`P17;biH8ZpKer_)Uz&ov(nRCwP#&CfHct1~P zlc54<8EVbU?7g4civaLWYi8!0^SLox-~isw(;1WT0%sRmGc$Yd=k_81ywf`8d~OXF zIDq%_bOw__1KtzJn}+0%x(Yx002ovPDHLkV1j1Ipz#0z delta 200 zcmbQtJ%?+1Q|