completing the set

This commit is contained in:
zelophed 2021-04-14 03:27:11 +02:00
parent bb8153f140
commit fdbdf0ec8d
9 changed files with 125 additions and 14 deletions

View file

@ -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,15 +54,20 @@ public class BaseConfigScreen extends ConfigScreen {
)
.withBounds(200, 30)
);
if (Minecraft.getInstance().world != null) {
serverConfigWidget.withCallback(() -> ScreenOpener.transitionTo(new SubMenuConfigScreen(this, AllConfigs.SERVER.specification)));
} else {
serverConfigWidget.active = false;
serverConfigWidget.updateColorsFromState();
}
}
@Override
protected void renderWindow(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
super.renderWindow(ms, mouseX, mouseY, partialTicks);
testStencil.at(200, 200, 0).render(ms);
//<testStencil.at(200, 200, 0).render(ms);
}
}

View file

@ -6,6 +6,7 @@ import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.foundation.gui.CombinedStencilElement;
import com.simibubi.create.foundation.gui.DelegatedStencilElement;
import com.simibubi.create.foundation.gui.StencilElement;
import com.simibubi.create.foundation.gui.UIRenderHelper;
import com.simibubi.create.foundation.gui.widgets.StencilWidget;
@ -41,6 +42,12 @@ public class ConfigButton extends StencilWidget {
return button;
}
public static ConfigButton createAndInjectElementRenderer(int x, int y, DelegatedStencilElement stencil) {
ConfigButton button = new ConfigButton(x, y);
button.stencilElement = stencil.withElementRenderer((ms, $width, $height) -> 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);
}

View file

@ -18,7 +18,6 @@ import net.minecraft.util.text.IFormattableTextComponent;
public class ConfigScreenList extends ExtendedList<ConfigScreenList.Entry> {
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<ConfigScreenList.Entry> {
children().forEach(Entry::tick);
}
public void bumpCog(float force) {
ConfigScreen.cogSpin.bump(3, force);
}
public static abstract class Entry extends ExtendedList.AbstractListEntry<Entry> {
protected List<IGuiEventListener> listeners;
@ -98,7 +101,7 @@ public class ConfigScreenList extends ExtendedList<ConfigScreenList.Entry> {
@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<ConfigScreenList.Entry> {
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;
}
}

View file

@ -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<Boolean>) configValue, valueSpec);
list.children().add(entry);
} else if (value instanceof Enum) {
EnumEntry entry = new EnumEntry(humanKey, (ForgeConfigSpec.ConfigValue<Enum<?>>) configValue, valueSpec);
list.children().add(entry);
} else if (value instanceof Number) {
NumberEntry<? extends Number> entry = NumberEntry.create(value, humanKey, configValue, valueSpec);
if (entry != null) {

View file

@ -58,9 +58,10 @@ public class BooleanEntry extends ValueEntry<Boolean> {
}
@Override
protected void onReset() {
super.onReset();
protected void onValueChange() {
super.onValueChange();
buttonStencil.withSecond(value.get() ? enabled : disabled);
bumpCog(value.get() ? 15f : -16f);
}
/*@Override

View file

@ -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<Enum<?>> {
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<Enum<?>> 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());
}
}

View file

@ -83,7 +83,7 @@ public abstract class NumberEntry<T extends Number> extends ValueEntry<T> {
}
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;
}

View file

@ -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_);

View file

@ -10,7 +10,7 @@ import net.minecraftforge.common.ForgeConfigSpec;
public class ValueEntry<T> 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<T> value;
protected ForgeConfigSpec.ValueSpec spec;
@ -46,6 +46,11 @@ public class ValueEntry<T> 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<T> 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);
}
}