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 904c14b commit 7a6b6b7
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public abstract class AbstractModelMenuScreen extends Screen {
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");
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");
protected final Screen lastScreen;

public AbstractModelMenuScreen(@Nullable Screen lastScreen) {
Expand Down Expand Up @@ -82,7 +82,7 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta)
super.render(guiGraphics, mouseX, mouseY, delta);
RenderSystem.enableBlend();
guiGraphics.blit(MENU_BACKGROUND_OUTLINE_TEXTURE, getCenterX(BACKGROUND_TEXTURE_WIDTH), getCenterY(BACKGROUND_TEXTURE_HEIGHT), 0, 0, BACKGROUND_TEXTURE_WIDTH, BACKGROUND_TEXTURE_HEIGHT, BACKGROUND_TEXTURE_WIDTH, BACKGROUND_TEXTURE_HEIGHT);
guiGraphics.blit(MENU_TOP_LAYER_TEXTURE, getCenterX(BACKGROUND_TEXTURE_WIDTH), getCenterY(BACKGROUND_TEXTURE_HEIGHT), 0, 0, BACKGROUND_TEXTURE_WIDTH, BACKGROUND_TEXTURE_HEIGHT, BACKGROUND_TEXTURE_WIDTH, BACKGROUND_TEXTURE_HEIGHT);
guiGraphics.blit(renderTopLayer(), getCenterX(BACKGROUND_TEXTURE_WIDTH), getCenterY(BACKGROUND_TEXTURE_HEIGHT), 0, 0, BACKGROUND_TEXTURE_WIDTH, BACKGROUND_TEXTURE_HEIGHT, BACKGROUND_TEXTURE_WIDTH, BACKGROUND_TEXTURE_HEIGHT);
RenderSystem.disableBlend();

WidgetSprites settingSprites = new WidgetSprites(
Expand All @@ -97,9 +97,8 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta)
BUTTON_SIZE,
settingSprites,
button -> {
if(!(this instanceof SettingsScreen)) {
if (!(this instanceof SettingsScreen)) {
minecraft.setScreen(new SettingsScreen(this));

}
},
Component.empty()
Expand All @@ -109,8 +108,32 @@ public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float delta)
} else {
addRenderableWidget(settingsButton);
}

Component text = Component.translatable(setTranslatableTitle());

// 计算居中显示的 X 坐标
int centerX = getCenteredStringX(text);

// 渲染文本
guiGraphics.drawString(this.font, text, centerX, font.lineHeight, 0xFFFFFFFF, true);
}

private ResourceLocation renderTopLayer() {
if(renderTopLayerResourceLocation() != null){
return renderTopLayerResourceLocation();
}else {
Ayame.LOGGER.error("renderTopLayer cannot be null and has fallback to the default topLayer");
return MENU_TOP_LAYER_TEXTURE;
}
}

/**
* 实现一个自定义的指定图层
* @return 你要传入的图片路径
*/
protected abstract ResourceLocation renderTopLayerResourceLocation();

protected abstract String setTranslatableTitle();
/**
* 获取指定宽度在屏幕中心的X坐标
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +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 net.minecraft.resources.ResourceLocation;
import org.ayamemc.ayame.client.api.ModelResourceAPI;
import org.ayamemc.ayame.client.resource.IModelResource;
import org.ayamemc.ayame.model.AyameModelCache;
Expand Down Expand Up @@ -128,21 +128,16 @@ 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);
@Override
protected ResourceLocation renderTopLayerResourceLocation() {
return MENU_TOP_LAYER_TEXTURE;
}


@Override
protected String setTranslatableTitle() {
return "ayame.screen.warningscreen.modelselectscreen.title";
}


// int count = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,23 @@
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
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);
@Override
protected ResourceLocation renderTopLayerResourceLocation() {
return MENU_TOP_LAYER_TEXTURE;
}

// 渲染文本
guiGraphics.drawString(this.font, text, centerX, font.lineHeight, 0xFFFFFFFF, true);
@Override
protected String setTranslatableTitle() {
return "ayame.screen.warningscreen.settingsscreen.title";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public StatementScreen(@Nullable Screen lastScreen, @Nullable Screen lastLastScr
*/
@Override
protected @NotNull Layout addFooterButtons() {
this.stopShowing.selected = true; // 默认勾选“不再显示此屏幕”
this.setSelected(true); // 默认勾选“不再显示此屏幕”
LinearLayout linearLayout = LinearLayout.horizontal().spacing(8);
linearLayout.addChild(Button.builder(CommonComponents.GUI_PROCEED, button -> {
if (this.stopShowing.selected()) {
Expand All @@ -87,6 +87,10 @@ public StatementScreen(@Nullable Screen lastScreen, @Nullable Screen lastLastScr
return linearLayout;
}

private void setSelected(boolean isSelected) {
this.stopShowing.selected = isSelected;
}


/**
* 当屏幕退出时执行的代码
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@Environment(EnvType.CLIENT)
public class BlurWidget extends AbstractWidget {
Minecraft minecraft = Minecraft.getInstance();
final Minecraft minecraft = Minecraft.getInstance();

public BlurWidget(int x, int y, int width, int height) {
super(x, y, width, height, Component.empty());
Expand Down
23 changes: 10 additions & 13 deletions common/src/main/java/org/ayamemc/ayame/util/JsonInterpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,42 +177,42 @@ public void set(String path, Object value) {
return;
}
// 如果是List<JsonInterpreter>,则转换为JsonElement对象
if (list.get(0) instanceof JsonInterpreter) {
if (list.getFirst() instanceof JsonInterpreter) {
for (Object o : list) {
jsonArray.add(((JsonInterpreter) o).jsonObject);
}
jsonObject.add(path, jsonArray);
return;
}
if (list.get(0) instanceof JsonElement) {
if (list.getFirst() instanceof JsonElement) {
for (Object o : list) {
jsonArray.add((JsonElement) o);
}
jsonObject.add(path, jsonArray);
return;
}
if (list.get(0) instanceof String) {
if (list.getFirst() instanceof String) {
for (Object o : list) {
jsonArray.add((String) o);
}
jsonObject.add(path, jsonArray);
return;
}
if (list.get(0) instanceof Number) {
if (list.getFirst() instanceof Number) {
for (Object o : list) {
jsonArray.add((Number) o);
}
jsonObject.add(path, jsonArray);
return;
}
if (list.get(0) instanceof Boolean) {
if (list.getFirst() instanceof Boolean) {
for (Object o : list) {
jsonArray.add((Boolean) o);
}
jsonObject.add(path, jsonArray);
return;
}
if (list.get(0) instanceof Character) {
if (list.getFirst() instanceof Character) {
for (Object o : list) {
jsonArray.add((Character) o);
}
Expand Down Expand Up @@ -463,8 +463,7 @@ public String getOriginal() {
* @return 是否相等
*/
public boolean equalsCaseIgnoreCase(Object obj) {
if (obj instanceof JsonInterpreter) {
JsonInterpreter other = (JsonInterpreter) obj;
if (obj instanceof JsonInterpreter other) {
return this.jsonObject.equals(other.jsonObject);
}
return obj.toString().equalsIgnoreCase(this.jsonObject.toString());
Expand All @@ -477,8 +476,7 @@ public boolean equalsCaseIgnoreCase(Object obj) {
* @return 是否相等
*/
public boolean equals(Object obj) {
if (obj instanceof JsonInterpreter) {
JsonInterpreter other = (JsonInterpreter) obj;
if (obj instanceof JsonInterpreter other) {
return this.jsonObject.equals(other.jsonObject);
}
return obj.toString().equals(this.jsonObject.toString());
Expand All @@ -491,9 +489,8 @@ public boolean equals(Object obj) {
*/
public List<JsonInterpreter> toJsonList() {
if (jsonObject.isJsonArray()) {
return jsonObject.getAsJsonArray().asList().stream().map(e -> {
return new JsonInterpreter(e.getAsJsonObject());
}).collect(Collectors.toList());
return jsonObject.getAsJsonArray().asList().stream().map(e ->
new JsonInterpreter(e.getAsJsonObject())).collect(Collectors.toList());
}
return Collections.emptyList();
}
Expand Down

0 comments on commit 7a6b6b7

Please sign in to comment.