fixed rendering order for (most) screens & widgets

This commit is contained in:
maloryware
2025-08-04 05:17:21 +01:00
parent 9fe2ab78c6
commit 206ea38105
8 changed files with 61 additions and 57 deletions

View File

@@ -1,11 +1,14 @@
package eu.midnightdust.core.mixin;
import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.SugarBridge;
import eu.midnightdust.core.config.MidnightLibConfig;
import eu.midnightdust.core.screen.MidnightConfigOverviewScreen;
import eu.midnightdust.lib.util.PlatformFunctions;
import eu.midnightdust.lib.util.screen.TexturedOverlayButtonWidget;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.option.OptionsScreen;
import net.minecraft.client.gui.widget.GridWidget;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
@@ -13,13 +16,29 @@ import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import java.util.Objects;
import static eu.midnightdust.core.config.MidnightLibConfig.shouldShowButton;
@Mixin(OptionsScreen.class)
public class MixinOptionsScreen extends Screen {
@Unique private static final Identifier MIDNIGHTLIB_ICON_TEXTURE = Identifier.of("midnightlib","icon/midnightlib.png");
@Unique
private static final Identifier MIDNIGHTLIB_ICON_TEXTURE = new Identifier("midnightlib","textures/gui/midnightlib_button.png");
TexturedOverlayButtonWidget midnightlib$button = new TexturedOverlayButtonWidget(
this.width / 2 + 158,
this.height / 6 - 12,
20,
20,
0, 0, 20,
MIDNIGHTLIB_ICON_TEXTURE,
32, 64,
(buttonWidget) ->
Objects.requireNonNull(client).setScreen(new MidnightConfigOverviewScreen(this)),
Text.translatable("midnightlib.overview.title"));
protected MixinOptionsScreen(Text title) {
super(title);
@@ -27,7 +46,10 @@ public class MixinOptionsScreen extends Screen {
@Inject(at = @At("HEAD"), method = "init")
private void midnightlib$init(CallbackInfo ci) {
if (MidnightLibConfig.config_screen_list.equals(MidnightLibConfig.ConfigButton.TRUE) || (MidnightLibConfig.config_screen_list.equals(MidnightLibConfig.ConfigButton.MODMENU) && !PlatformFunctions.isModLoaded("modmenu")))
this.addDrawableChild(new TexturedOverlayButtonWidget(this.width / 2 + 158, this.height / 6 - 12, 20, 20, 0, 0, 20, MIDNIGHTLIB_ICON_TEXTURE, 32, 64, (buttonWidget) -> Objects.requireNonNull(client).setScreen(new MidnightConfigOverviewScreen(this)), Text.translatable("midnightlib.overview.title")));
if (shouldShowButton()){
midnightlib$button.setPosition(this.width / 2 + 158, this.height / 6 - 12);
this.addDrawableChild(midnightlib$button);
}
}
}

View File

@@ -2,6 +2,7 @@ package eu.midnightdust.core.screen;
import eu.midnightdust.core.MidnightLib;
import eu.midnightdust.lib.config.MidnightConfig;
import eu.midnightdust.lib.config.MidnightConfig.MidnightConfigListWidget;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
@@ -23,24 +24,30 @@ public class MidnightConfigOverviewScreen extends Screen {
this.parent = parent;
}
private final Screen parent;
private MidnightOverviewListWidget list;
private MidnightConfigListWidget list;
@Override
protected void init() {
this.addDrawableChild(ButtonWidget.builder(ScreenTexts.DONE, (button) -> Objects.requireNonNull(client).setScreen(parent)).dimensions(this.width / 2 - 100, this.height - 28, 200, 20).build());
this.addDrawableChild(
ButtonWidget.builder(
ScreenTexts.DONE,
(button) ->
Objects.requireNonNull(client).setScreen(parent))
.dimensions(this.width / 2 - 100, this.height - 28, 200, 20)
.build());
this.list = new MidnightOverviewListWidget(this.client, this.width, this.height, 32, this.height - 32, 25);
if (this.client != null && this.client.world != null) this.list.setRenderBackground(false);
this.addSelectableChild(this.list);
List<String> sortedMods = new ArrayList<>(MidnightConfig.configClass.keySet());
Collections.sort(sortedMods);
list = new MidnightConfigListWidget(this.client, this.width, this.height, this.height - 57, 25);
sortedMods.forEach((modid) -> {
if (!MidnightLib.hiddenMods.contains(modid)) {
list.addButton(ButtonWidget.builder(Text.translatable(modid +".midnightconfig.title"), (button) ->
Objects.requireNonNull(client).setScreen(MidnightConfig.getScreen(this,modid))).dimensions(this.width / 2 - 125, this.height - 28, 250, 20).build());
}
});
list.addButton(List.of(ButtonWidget.builder(Text.translatable(modid +".midnightconfig.title"), (button) ->
Objects.requireNonNull(client).setScreen(MidnightConfig.getScreen(this, modid))).dimensions(this.width / 2 - 125, this.height - 28, 250, 20).build()), null, null);
}});
if (this.client != null && this.client.world != null) this.list.setRenderBackground(false);
this.addSelectableChild(this.list);
super.init();
}
@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
@@ -48,39 +55,6 @@ public class MidnightConfigOverviewScreen extends Screen {
this.list.render(context, mouseX, mouseY, delta);
context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 15, 0xFFFFFF);
super.render(context, mouseX, mouseY, delta);
}
@Environment(EnvType.CLIENT)
public static class MidnightOverviewListWidget extends ElementListWidget<OverviewButtonEntry> {
TextRenderer textRenderer;
public MidnightOverviewListWidget(MinecraftClient minecraftClient, int i, int j, int k, int l, int m) {
super(minecraftClient, i, j, k, l, m);
this.centerListVertically = false;
textRenderer = minecraftClient.textRenderer;
}
@Override
public int getScrollbarPositionX() {return this.width-7;}
public void addButton(ClickableWidget button) {
this.addEntry(OverviewButtonEntry.create(button));
}
@Override
public int getRowWidth() { return 400; }
}
public static class OverviewButtonEntry extends ElementListWidget.Entry<OverviewButtonEntry> {
private final ClickableWidget button;
private final List<ClickableWidget> buttonList = new ArrayList<>();
private OverviewButtonEntry(ClickableWidget button) {
this.button = button;
this.buttonList.add(button);
}
public static OverviewButtonEntry create(ClickableWidget button) {return new OverviewButtonEntry(button);}
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
button.setY(y);
button.render(context, mouseX, mouseY, tickDelta);
}
public List<? extends Element> children() {return buttonList;}
public List<? extends Selectable> selectableChildren() {return buttonList;}
}
}

View File

@@ -357,9 +357,8 @@ public abstract class MidnightConfig {
Objects.requireNonNull(client).setScreen(parent);
}).dimensions(this.width / 2 + 4, this.height - 26, 150, 20).build());
this.list = new MidnightConfigListWidget(this.client, this.width, this.height, this.height - 57, 24, 25);
this.list = new MidnightConfigListWidget(this.client, this.width, 0, this.height - 57, 25);
this.addSelectableChild(this.list); fillList();
if (tabs.size() > 1) list.renderHeaderSeparator = false;
}
public void updateList() {
this.list.clear(); fillList();
@@ -377,11 +376,17 @@ public abstract class MidnightConfig {
}
if (info.modid.equals(modid) && (info.tab == null || info.tab == tabManager.getCurrentTab())) {
Text name = Objects.requireNonNullElseGet(info.name, () -> Text.translatable(translationPrefix + info.fieldName));
IconButtonWidget resetButton = IconButtonWidget.builder(Text.translatable("controls.reset"), Identifier.of("midnightlib","icon/reset"), (button -> {
IconButtonWidget resetButton = IconButtonWidget.builder(
Text.translatable("controls.reset"),
Identifier.of("midnightlib","icon/reset.png"),
(button -> {
info.value = info.defaultValue; info.listIndex = 0;
info.tempValue = info.toTemporaryValue();
updateList();
}) ).build();
}))
// .iconSize(12, 12)
.textureSize(12, 12)
.build();
resetButton.setPosition(width - 205 + 150 + 25, 0);
if (info.function != null) {
@@ -429,7 +434,7 @@ public abstract class MidnightConfig {
} catch (Exception ignored) {}
info.actionButton = colorButton;
} else if (e.selectionMode() > -1) {
ButtonWidget explorerButton = IconButtonWidget.builder(Text.empty(), Identifier.of("midnightlib", "icon/explorer"),
ButtonWidget explorerButton = IconButtonWidget.builder(Text.empty(), Identifier.of("midnightlib", "icon/explorer.png"),
button -> new Thread(() -> {
JFileChooser fileChooser = new JFileChooser(info.tempValue);
fileChooser.setFileSelectionMode(e.selectionMode()); fileChooser.setDialogType(e.fileChooserType());
@@ -464,16 +469,18 @@ public abstract class MidnightConfig {
}
}
@Override
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
super.render(context, mouseX, mouseY, delta);
this.renderBackground(context);
this.list.render(context, mouseX, mouseY, delta);
if (tabs.size() < 2) context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 10, 0xFFFFFFFF);
if (tabs.size() < 2) context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 15, 0xFFFFFFFF);
super.render(context, mouseX, mouseY, delta);
}
}
@Environment(EnvType.CLIENT)
public static class MidnightConfigListWidget extends ElementListWidget<ButtonEntry> {
public boolean renderHeaderSeparator = true;
public MidnightConfigListWidget(MinecraftClient client, int width, int height, int yStart, int y, int itemHeight) { super(client, width, height, yStart, y, itemHeight); }
public MidnightConfigListWidget(MinecraftClient client, int width, int height, int y, int itemHeight)
{ super(client, width, height, 30, y, itemHeight); }
@Override public int getScrollbarPositionX() { return this.width - 7; }
/*
@@ -485,6 +492,7 @@ public abstract class MidnightConfig {
RenderSystem.disableBlend(); }
}
*/
public void addButton(List<ClickableWidget> buttons, Text text, EntryInfo info) { this.addEntry(new ButtonEntry(buttons, text, info)); }
public void clear() { this.clearEntries(); }
@Override public int getRowWidth() { return 10000; }

View File

Before

Width:  |  Height:  |  Size: 136 B

After

Width:  |  Height:  |  Size: 136 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

View File

Before

Width:  |  Height:  |  Size: 114 B

After

Width:  |  Height:  |  Size: 114 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 960 B

View File

@@ -28,7 +28,7 @@ public class MidnightLibExtras {
KeybindButton editButton = new KeybindButton(screen.width - 185, 0, 150, 20, binding);
IconButtonWidget resetButton = IconButtonWidget.builder(
Text.translatable("controls.reset"),
Identifier.of("midnightlib", "icon/reset"),
Identifier.of("midnightlib", "icon/reset.png"),
(button -> {
binding.setBoundKey(binding.getDefaultKey());
screen.updateList();