diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/BaseConfigScreen.java b/src/main/java/com/simibubi/create/foundation/config/ui/BaseConfigScreen.java index 0e5f61c4a..f3975142e 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/BaseConfigScreen.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/BaseConfigScreen.java @@ -6,6 +6,7 @@ import com.simibubi.create.foundation.gui.ScreenOpener; import com.simibubi.create.foundation.gui.StencilElement; import com.simibubi.create.foundation.gui.TextStencilElement; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.Screen; import net.minecraft.util.text.StringTextComponent; import net.minecraft.util.text.TextFormatting; @@ -42,9 +43,8 @@ public class BaseConfigScreen extends ConfigScreen { text2 ) .withBounds(200, 30) + .withCallback(() -> ScreenOpener.transitionTo(new SubMenuConfigScreen(this, AllConfigs.COMMON.specification))) ); - commonConfigWidget.active = false; - commonConfigWidget.updateColorsFromState(); StencilElement text3 = new TextStencilElement(client.fontRenderer, new StringTextComponent("SERVER CONFIG").formatted(TextFormatting.BOLD)).centered(true, true); widgets.add(serverConfigWidget = ConfigButton.createFromStencilElement( @@ -54,8 +54,13 @@ public class BaseConfigScreen extends ConfigScreen { ) .withBounds(200, 30) ); - serverConfigWidget.active = false; - serverConfigWidget.updateColorsFromState(); + + if (Minecraft.getInstance().world != null) { + serverConfigWidget.withCallback(() -> ScreenOpener.transitionTo(new SubMenuConfigScreen(this, AllConfigs.SERVER.specification))); + } else { + serverConfigWidget.active = false; + serverConfigWidget.updateColorsFromState(); + } } @Override @@ -63,6 +68,6 @@ public class BaseConfigScreen extends ConfigScreen { super.renderWindow(ms, mouseX, mouseY, partialTicks); - testStencil.at(200, 200, 0).render(ms); + // UIRenderHelper.angledGradient(ms, 0, 0, $height/2, $height+2, $width+2, button.gradientColor1, button.gradientColor2)); + return button; + } + protected ConfigButton(int x, int y) { super(x, y); } diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreenList.java b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreenList.java index 9e64a5491..c4af6fbeb 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreenList.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreenList.java @@ -18,7 +18,6 @@ import net.minecraft.util.text.IFormattableTextComponent; public class ConfigScreenList extends ExtendedList { - public ConfigScreenList(Minecraft client, int width, int height, int top, int bottom, int elementHeight) { super(client, width, height, top, bottom, elementHeight); func_244605_b(false); @@ -57,6 +56,10 @@ public class ConfigScreenList extends ExtendedList { children().forEach(Entry::tick); } + public void bumpCog(float force) { + ConfigScreen.cogSpin.bump(3, force); + } + public static abstract class Entry extends ExtendedList.AbstractListEntry { protected List listeners; @@ -98,7 +101,7 @@ public class ConfigScreenList extends ExtendedList { @Override public void render(MatrixStack ms, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean p_230432_9_, float partialTicks) { - UIRenderHelper.streak(ms, 0, x, y+height/2, height - 10, width/2, 0x0); + UIRenderHelper.streak(ms, 0, x, y+height/2, height - 10, getLabelWidth(width), 0x0); IFormattableTextComponent component = label.getComponent(); if (Minecraft.getInstance().fontRenderer.getWidth(component) > getLabelWidth(width) - 10) { label.withText(Minecraft.getInstance().fontRenderer.trimToWidth(component, getLabelWidth(width) - 15).getString() + "..."); @@ -106,8 +109,8 @@ public class ConfigScreenList extends ExtendedList { label.at(x + 5, y + height/2 - 4, 0).render(ms); } - protected static int getLabelWidth(int totalWidth) { - return (int) (totalWidth * labelWidthMult); + protected int getLabelWidth(int totalWidth) { + return totalWidth; } } diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/SubMenuConfigScreen.java b/src/main/java/com/simibubi/create/foundation/config/ui/SubMenuConfigScreen.java index a4c81b70c..a0c4f967f 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/SubMenuConfigScreen.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/SubMenuConfigScreen.java @@ -11,6 +11,7 @@ import com.electronwill.nightconfig.core.AbstractConfig; import com.electronwill.nightconfig.core.UnmodifiableConfig; import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.foundation.config.ui.entries.BooleanEntry; +import com.simibubi.create.foundation.config.ui.entries.EnumEntry; import com.simibubi.create.foundation.config.ui.entries.NumberEntry; import com.simibubi.create.foundation.config.ui.entries.SubMenuEntry; import com.simibubi.create.foundation.gui.ScreenOpener; @@ -47,7 +48,7 @@ public class SubMenuConfigScreen extends ConfigScreen { widgets.clear(); super.init(); - int lWidth = width - 66; + int lWidth = Math.min(width - 66, 500); list = new ConfigScreenList(client, lWidth, height - 30, 15, height - 15, 50); list.setLeftPos(this.width /2 - list.getWidth()/2); @@ -70,6 +71,9 @@ public class SubMenuConfigScreen extends ConfigScreen { if (value instanceof Boolean) { BooleanEntry entry = new BooleanEntry(humanKey, (ForgeConfigSpec.ConfigValue) configValue, valueSpec); list.children().add(entry); + } else if (value instanceof Enum) { + EnumEntry entry = new EnumEntry(humanKey, (ForgeConfigSpec.ConfigValue>) configValue, valueSpec); + list.children().add(entry); } else if (value instanceof Number) { NumberEntry entry = NumberEntry.create(value, humanKey, configValue, valueSpec); if (entry != null) { diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/entries/BooleanEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/entries/BooleanEntry.java index f1426be76..3d620607b 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/entries/BooleanEntry.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/entries/BooleanEntry.java @@ -58,9 +58,10 @@ public class BooleanEntry extends ValueEntry { } @Override - protected void onReset() { - super.onReset(); + protected void onValueChange() { + super.onValueChange(); buttonStencil.withSecond(value.get() ? enabled : disabled); + bumpCog(value.get() ? 15f : -16f); } /*@Override diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/entries/EnumEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/entries/EnumEntry.java new file mode 100644 index 000000000..ceff6eead --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/config/ui/entries/EnumEntry.java @@ -0,0 +1,75 @@ +package com.simibubi.create.foundation.config.ui.entries; + +import com.mojang.blaze3d.matrix.MatrixStack; +import com.simibubi.create.foundation.config.ui.ConfigButton; +import com.simibubi.create.foundation.gui.TextStencilElement; + +import net.minecraft.client.Minecraft; +import net.minecraftforge.common.ForgeConfigSpec; + +public class EnumEntry extends ValueEntry> { + + protected static final int cycleWidth = 34;//including 2px offset on either side + + protected TextStencilElement valueText; + protected ConfigButton cycleLeft; + protected ConfigButton cycleRight; + + public EnumEntry(String label, ForgeConfigSpec.ConfigValue> value, ForgeConfigSpec.ValueSpec spec) { + super(label, value, spec); + + valueText = new TextStencilElement(Minecraft.getInstance().fontRenderer, "YEP").centered(true, true); + + TextStencilElement l = new TextStencilElement(Minecraft.getInstance().fontRenderer, "<").centered(true, true); + cycleLeft = ConfigButton.createAndInjectElementRenderer(0, 0, l).withBounds(30, 30).withCallback(() -> cycleValue(-1)); + + TextStencilElement r = new TextStencilElement(Minecraft.getInstance().fontRenderer, ">").centered(true, true); + cycleRight = ConfigButton.createAndInjectElementRenderer(0, 0, r).withBounds(30, 30).withCallback(() -> cycleValue(1)); + + listeners.add(cycleLeft); + listeners.add(cycleRight); + + onReset(); + } + + protected void cycleValue(int direction) { + Enum e = value.get(); + Enum[] options = e.getDeclaringClass().getEnumConstants(); + e = options[Math.floorMod(e.ordinal() + direction, options.length)]; + value.set(e); + bumpCog(direction * 15f); + onValueChange(); + } + + @Override + public void tick() { + super.tick(); + cycleLeft.tick(); + cycleRight.tick(); + } + + @Override + public void render(MatrixStack ms, int index, int y, int x, int width, int height, int mouseX, int mouseY, boolean p_230432_9_, float partialTicks) { + super.render(ms, index, y, x, width, height, mouseX, mouseY, p_230432_9_, partialTicks); + + cycleLeft.x = x + getLabelWidth(width) + 2; + cycleLeft.y = y + 10; + cycleLeft.render(ms, mouseX, mouseY, partialTicks); + + valueText + .at(cycleLeft.x - 2 + cycleWidth, y + 10, 0) + .withBounds(width - getLabelWidth(width) - 2 * cycleWidth - resetWidth, 30) + .render(ms); + + cycleRight.x = x + width - cycleWidth - resetWidth + 2; + cycleRight.y = y + 10; + cycleRight.render(ms, mouseX, mouseY, partialTicks); + + } + + @Override + protected void onValueChange() { + super.onValueChange(); + valueText.withText(value.get().name()); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/entries/NumberEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/entries/NumberEntry.java index 8569a1a10..b1d3b9a9a 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/entries/NumberEntry.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/entries/NumberEntry.java @@ -83,7 +83,7 @@ public abstract class NumberEntry extends ValueEntry { } protected String formatBound(T bound) { - String sci = String.format("%.2E", bound); + String sci = String.format("%.2E", bound.doubleValue()); String str = String.valueOf(bound); return sci.length() < str.length() ? sci : str; } diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/entries/SubMenuEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/entries/SubMenuEntry.java index 28f5762d1..661db2a3b 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/entries/SubMenuEntry.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/entries/SubMenuEntry.java @@ -41,6 +41,11 @@ public class SubMenuEntry extends ConfigScreenList.LabeledEntry { button.render(ms, mouseX, mouseY, partialTicks); } + @Override + protected int getLabelWidth(int totalWidth) { + return (int) (totalWidth * labelWidthMult); + } + /*@Override public boolean mouseClicked(double p_231044_1_, double p_231044_3_, int p_231044_5_) { return button.mouseClicked(p_231044_1_, p_231044_3_, p_231044_5_); diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/entries/ValueEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/entries/ValueEntry.java index bde5066dc..504fce2e0 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/entries/ValueEntry.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/entries/ValueEntry.java @@ -10,7 +10,7 @@ import net.minecraftforge.common.ForgeConfigSpec; public class ValueEntry extends ConfigScreenList.LabeledEntry { - protected static final int resetWidth = 24;//including 2px offset on each side + protected static final int resetWidth = 24;//including 2px offset on either side protected ForgeConfigSpec.ConfigValue value; protected ForgeConfigSpec.ValueSpec spec; @@ -46,6 +46,11 @@ public class ValueEntry extends ConfigScreenList.LabeledEntry { reset.render(ms, mouseX, mouseY, partialTicks); } + @Override + protected int getLabelWidth(int totalWidth) { + return (int) (totalWidth * labelWidthMult); + } + /*@Override public boolean mouseClicked(double mX, double mY, int button) { return reset.mouseClicked(mX, mY, button); @@ -59,4 +64,10 @@ public class ValueEntry extends ConfigScreenList.LabeledEntry { reset.active = !value.get().equals(spec.getDefault()); reset.animateGradientFromState(); } + + protected void bumpCog() {bumpCog(10f);} + protected void bumpCog(float force) { + if (list != null && list instanceof ConfigScreenList) + ((ConfigScreenList) list).bumpCog(force); + } }