|
|
|
@@ -4,12 +4,13 @@ import com.google.common.collect.Lists;
|
|
|
|
import com.google.gson.*; import com.google.gson.stream.*;
|
|
|
|
import com.google.gson.*; import com.google.gson.stream.*;
|
|
|
|
import eu.midnightdust.lib.util.PlatformFunctions;
|
|
|
|
import eu.midnightdust.lib.util.PlatformFunctions;
|
|
|
|
import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment;
|
|
|
|
import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment;
|
|
|
|
import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext;
|
|
|
|
import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer;
|
|
|
|
|
|
|
|
import net.minecraft.client.gl.RenderPipelines;
|
|
|
|
|
|
|
|
import net.minecraft.client.gui.DrawContext;
|
|
|
|
import net.minecraft.client.gui.Element; import net.minecraft.client.gui.Selectable;
|
|
|
|
import net.minecraft.client.gui.Element; import net.minecraft.client.gui.Selectable;
|
|
|
|
import net.minecraft.client.gui.screen.ConfirmLinkScreen; import net.minecraft.client.gui.screen.Screen;
|
|
|
|
import net.minecraft.client.gui.screen.ConfirmLinkScreen; import net.minecraft.client.gui.screen.Screen;
|
|
|
|
import net.minecraft.client.gui.tab.GridScreenTab; import net.minecraft.client.gui.tab.Tab; import net.minecraft.client.gui.tab.TabManager;
|
|
|
|
import net.minecraft.client.gui.tab.GridScreenTab; import net.minecraft.client.gui.tab.Tab; import net.minecraft.client.gui.tab.TabManager;
|
|
|
|
import net.minecraft.client.gui.tooltip.Tooltip; import net.minecraft.client.gui.widget.*;
|
|
|
|
import net.minecraft.client.gui.tooltip.Tooltip; import net.minecraft.client.gui.widget.*;
|
|
|
|
import net.minecraft.client.render.RenderLayer;
|
|
|
|
|
|
|
|
import net.minecraft.client.resource.language.I18n;
|
|
|
|
import net.minecraft.client.resource.language.I18n;
|
|
|
|
import net.minecraft.registry.Registries;
|
|
|
|
import net.minecraft.registry.Registries;
|
|
|
|
import net.minecraft.screen.ScreenTexts;
|
|
|
|
import net.minecraft.screen.ScreenTexts;
|
|
|
|
@@ -131,7 +132,7 @@ public abstract class MidnightConfig {
|
|
|
|
entries.values().forEach(info -> {
|
|
|
|
entries.values().forEach(info -> {
|
|
|
|
if (info.field != null && info.entry != null) {
|
|
|
|
if (info.field != null && info.entry != null) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
info.value = info.field.get(null);
|
|
|
|
info.value = info.field.get(null) == null ? info.defaultValue : info.field.get(null);
|
|
|
|
info.tempValue = info.toTemporaryValue();
|
|
|
|
info.tempValue = info.toTemporaryValue();
|
|
|
|
info.updateConditions();
|
|
|
|
info.updateConditions();
|
|
|
|
} catch (IllegalAccessException ignored) {}
|
|
|
|
} catch (IllegalAccessException ignored) {}
|
|
|
|
@@ -446,7 +447,7 @@ public abstract class MidnightConfig {
|
|
|
|
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
|
|
|
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
|
|
|
super.render(context, mouseX, mouseY, delta);
|
|
|
|
super.render(context, mouseX, mouseY, delta);
|
|
|
|
this.list.render(context, mouseX, mouseY, delta);
|
|
|
|
this.list.render(context, mouseX, mouseY, delta);
|
|
|
|
if (tabs.size() < 2) context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 10, 0xFFFFFF);
|
|
|
|
if (tabs.size() < 2) context.drawCenteredTextWithShadow(textRenderer, title, width / 2, 10, 0xFFFFFFFF);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
|
|
@Environment(EnvType.CLIENT)
|
|
|
|
@@ -458,7 +459,7 @@ public abstract class MidnightConfig {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected void drawHeaderAndFooterSeparators(DrawContext context) {
|
|
|
|
protected void drawHeaderAndFooterSeparators(DrawContext context) {
|
|
|
|
if (renderHeaderSeparator) super.drawHeaderAndFooterSeparators(context);
|
|
|
|
if (renderHeaderSeparator) super.drawHeaderAndFooterSeparators(context);
|
|
|
|
else context.drawTexture(RenderLayer::getGuiTextured, this.client.world == null ? Screen.FOOTER_SEPARATOR_TEXTURE : Screen.INWORLD_FOOTER_SEPARATOR_TEXTURE, this.getX(), this.getBottom(), 0, 0, this.getWidth(), 2, 32, 2);
|
|
|
|
else context.drawTexture(RenderPipelines.GUI_TEXTURED, this.client.world == null ? Screen.FOOTER_SEPARATOR_TEXTURE : Screen.INWORLD_FOOTER_SEPARATOR_TEXTURE, this.getX(), this.getBottom(), 0, 0, this.getWidth(), 2, 32, 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void addButton(List<ClickableWidget> buttons, Text text, EntryInfo info) { this.addEntry(new ButtonEntry(buttons, text, info)); }
|
|
|
|
public void addButton(List<ClickableWidget> buttons, Text text, EntryInfo info) { this.addEntry(new ButtonEntry(buttons, text, info)); }
|
|
|
|
public void clear() { this.clearEntries(); }
|
|
|
|
public void clear() { this.clearEntries(); }
|
|
|
|
@@ -479,18 +480,16 @@ public abstract class MidnightConfig {
|
|
|
|
|
|
|
|
|
|
|
|
if (text != null && (!text.getString().contains("spacer") || !buttons.isEmpty())) {
|
|
|
|
if (text != null && (!text.getString().contains("spacer") || !buttons.isEmpty())) {
|
|
|
|
title = new MultilineTextWidget((centered) ? (scaledWidth / 2 - (textRenderer.getWidth(text) / 2)) : 12, 0, Text.of(text), textRenderer);
|
|
|
|
title = new MultilineTextWidget((centered) ? (scaledWidth / 2 - (textRenderer.getWidth(text) / 2)) : 12, 0, Text.of(text), textRenderer);
|
|
|
|
|
|
|
|
title.setCentered(centered);
|
|
|
|
if (info != null) title.setTooltip(info.getTooltip(false));
|
|
|
|
if (info != null) title.setTooltip(info.getTooltip(false));
|
|
|
|
title.setMaxWidth(buttons.size() > 1 ? buttons.get(1).getX() - 24 : scaledWidth - 24);
|
|
|
|
title.setMaxWidth(!buttons.isEmpty() ? buttons.get(buttons.size() > 2 ? buttons.size()-1 : 0).getX() - 16 : scaledWidth - 24);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
|
|
|
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
|
|
|
|
buttons.forEach(b -> { b.setY(y); b.render(context, mouseX, mouseY, tickDelta);});
|
|
|
|
buttons.forEach(b -> { b.setY(y); b.render(context, mouseX, mouseY, tickDelta);});
|
|
|
|
if (title != null) {
|
|
|
|
if (title != null) {
|
|
|
|
title.setY(y+5);
|
|
|
|
title.setY(y+5);
|
|
|
|
title.renderWidget(context, mouseX, mouseY, tickDelta);
|
|
|
|
title.render(context, mouseX, mouseY, tickDelta);
|
|
|
|
|
|
|
|
|
|
|
|
boolean tooltipVisible = mouseX >= title.getX() && mouseX < title.getWidth() + title.getX() && mouseY >= title.getY() && mouseY < title.getHeight() + title.getY();
|
|
|
|
|
|
|
|
if (tooltipVisible && title.getTooltip() != null) context.drawOrderedTooltip(textRenderer, title.getTooltip().getLines(MinecraftClient.getInstance()), mouseX, mouseY);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (info.entry != null && !this.buttons.isEmpty() && this.buttons.getFirst() instanceof ClickableWidget widget) {
|
|
|
|
if (info.entry != null && !this.buttons.isEmpty() && this.buttons.getFirst() instanceof ClickableWidget widget) {
|
|
|
|
int idMode = this.info.entry.idMode();
|
|
|
|
int idMode = this.info.entry.idMode();
|
|
|
|
|