Skip to content

Commit

Permalink
界面布局与屏幕更新
Browse files Browse the repository at this point in the history
  • Loading branch information
HappyRespawnanchor committed Oct 3, 2024
1 parent 2128fdf commit 904c14b
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}

/**
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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){
Expand All @@ -151,7 +170,7 @@ protected void init() {
*/
@Override
public void onClose() {
minecraft.setScreen(lastScreen);
super.onClose();
if (closeCallback != null) {
closeCallback.close(modelResources, selectedModel);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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);
}
}
4 changes: 3 additions & 1 deletion common/src/main/resources/assets/ayame/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://www.gnu.org/licenses/>."
"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 <https://www.gnu.org/licenses/>.",
"ayame.screen.warningscreen.modelselectscreen.title": "Select Model",
"ayame.screen.warningscreen.settingsscreen.title": "Ayame Settings"
}
4 changes: 3 additions & 1 deletion common/src/main/resources/assets/ayame/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -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宽通用公共许可证的副本。如果没有,请参阅 <https://www.gnu.org/licenses/>。"
"ayame.screen.warningscreen.statementscreen.content": "Ayame是自由软件:您可以按照自由软件基金会发布的GNU宽通用公共许可证的条款重新分发和/或修改Ayame;\n许可证的第3版或(根据您的选择)任何更高版本均适用。\n\nAyame的发布是为了希望它能够发挥作用,但并不提供任何担保;甚至不包含适销性或针对特定用途的适用性的默示担保。有关详细信息,请参阅GNU宽通用公共许可证。\n\n您应该已经随Ayame一同收到了GNU宽通用公共许可证的副本。如果没有,请参阅 <https://www.gnu.org/licenses/>。",
"ayame.screen.warningscreen.modelselectscreen.title": "选择模型",
"ayame.screen.warningscreen.settingsscreen.title": "Ayame 设置"
}
Binary file modified common/src/main/resources/assets/ayame/textures/gui/top_layer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 904c14b

Please sign in to comment.