Skip to content

Commit

Permalink
打开文件夹按钮添加
Browse files Browse the repository at this point in the history
  • Loading branch information
HappyRespawnanchor committed Oct 4, 2024
1 parent 9ecc520 commit 2d0fc8f
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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);

}


/**
* 渲染背景纹理
*/
Expand All @@ -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();

}

/**
Expand All @@ -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());

Expand Down Expand Up @@ -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);
Expand Down
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 @@ -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 <https://www.gnu.org/licenses/>.",
"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 ..."
}
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 @@ -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宽通用公共许可证的副本。如果没有,请参阅 <https://www.gnu.org/licenses/>。",
"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": "搜索模型……"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 2d0fc8f

Please sign in to comment.