mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-10 20:11:35 +01:00
Widget resize
- Condensed the main reading space of config UIs - Reworked some of the widgets to better arrange themselves in a column
This commit is contained in:
parent
de00f90a37
commit
35d0ce8387
11 changed files with 91 additions and 70 deletions
|
@ -28,22 +28,22 @@ public class BaseConfigScreen extends ConfigScreen {
|
|||
widgets.clear();
|
||||
super.init();
|
||||
|
||||
TextStencilElement text = new TextStencilElement(client.fontRenderer, new StringTextComponent("CLIENT CONFIG").formatted(TextFormatting.BOLD)).centered(true, true);
|
||||
widgets.add(clientConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15 - 50, 200, 30)
|
||||
TextStencilElement text = new TextStencilElement(client.fontRenderer, new StringTextComponent("Client Settings").formatted(TextFormatting.BOLD)).centered(true, true);
|
||||
widgets.add(clientConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15 - 30, 200, 16)
|
||||
.showingElement(text)
|
||||
.withCallback(() -> ScreenOpener.open(new SubMenuConfigScreen(this, ModConfig.Type.CLIENT, AllConfigs.CLIENT.specification)))
|
||||
);
|
||||
text.withElementRenderer(BoxWidget.gradientFactory.apply(clientConfigWidget));
|
||||
|
||||
TextStencilElement text2 = new TextStencilElement(client.fontRenderer, new StringTextComponent("COMMON CONFIG").formatted(TextFormatting.BOLD)).centered(true, true);
|
||||
widgets.add(commonConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15, 200, 30)
|
||||
TextStencilElement text2 = new TextStencilElement(client.fontRenderer, new StringTextComponent("World Generation Settings").formatted(TextFormatting.BOLD)).centered(true, true);
|
||||
widgets.add(commonConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15, 200, 16)
|
||||
.showingElement(text2)
|
||||
.withCallback(() -> ScreenOpener.open(new SubMenuConfigScreen(this, ModConfig.Type.COMMON, AllConfigs.COMMON.specification)))
|
||||
);
|
||||
text2.withElementRenderer(BoxWidget.gradientFactory.apply(commonConfigWidget));
|
||||
|
||||
TextStencilElement text3 = new TextStencilElement(client.fontRenderer, new StringTextComponent("SERVER CONFIG").formatted(TextFormatting.BOLD)).centered(true, true);
|
||||
widgets.add(serverConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15 + 50, 200, 30)
|
||||
TextStencilElement text3 = new TextStencilElement(client.fontRenderer, new StringTextComponent("Gameplay Settings").formatted(TextFormatting.BOLD)).centered(true, true);
|
||||
widgets.add(serverConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15 + 30, 200, 16)
|
||||
.showingElement(text3)
|
||||
);
|
||||
|
||||
|
|
|
@ -142,12 +142,12 @@ 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, getLabelWidth(width) + ((width - getLabelWidth(width)) / 3), 0xdd_000000);
|
||||
UIRenderHelper.streak(ms, 0, x, y + height / 2, height - 10, width, 0xdd_000000);
|
||||
IFormattableTextComponent component = label.getComponent();
|
||||
if (Minecraft.getInstance().fontRenderer.getWidth(component) > getLabelWidth(width) - 10) {
|
||||
label.withText(Minecraft.getInstance().fontRenderer.trimToWidth(component, getLabelWidth(width) - 15).getString() + "...");
|
||||
}
|
||||
label.at(x + 5, y + height / 2 - 4, 0).render(ms);
|
||||
label.at(x + 10, y + height / 2 - 4, 0).render(ms);
|
||||
|
||||
if (mouseX > x && mouseX < x + getLabelWidth(width) && mouseY > y + 5 && mouseY < y + height - 5) {
|
||||
List<ITextComponent> tooltip = getLabelTooltip();
|
||||
|
|
|
@ -117,7 +117,7 @@ public class SubMenuConfigScreen extends ConfigScreen {
|
|||
super.init();
|
||||
|
||||
//leave 40px on either side and dont be wider than 500px
|
||||
listWidth = Math.min(width - 80, 500);
|
||||
listWidth = Math.min(width - 80, 300);
|
||||
|
||||
int yCenter = height / 2;
|
||||
int listL = this.width / 2 - listWidth / 2;
|
||||
|
@ -189,7 +189,7 @@ public class SubMenuConfigScreen extends ConfigScreen {
|
|||
widgets.add(discardChanges);
|
||||
widgets.add(goBack);
|
||||
|
||||
list = new ConfigScreenList(client, listWidth, height - 60, 45, height - 15, 50);
|
||||
list = new ConfigScreenList(client, listWidth, height - 60, 45, height - 15, 40);
|
||||
list.setLeftPos(this.width / 2 - list.getWidth() / 2);
|
||||
|
||||
children.add(list);
|
||||
|
|
|
@ -1,32 +1,41 @@
|
|||
package com.simibubi.create.foundation.config.ui.entries;
|
||||
|
||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.simibubi.create.foundation.gui.TextStencilElement;
|
||||
import com.simibubi.create.foundation.gui.AllIcons;
|
||||
import com.simibubi.create.foundation.gui.RenderElement;
|
||||
import com.simibubi.create.foundation.gui.UIRenderHelper;
|
||||
import com.simibubi.create.foundation.gui.widgets.BoxWidget;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
|
||||
public class BooleanEntry extends ValueEntry<Boolean> {
|
||||
|
||||
TextStencilElement enabled;
|
||||
TextStencilElement disabled;
|
||||
RenderElement enabled;
|
||||
RenderElement disabled;
|
||||
BoxWidget button;
|
||||
|
||||
public BooleanEntry(String label, ForgeConfigSpec.ConfigValue<Boolean> value, ForgeConfigSpec.ValueSpec spec) {
|
||||
super(label, value, spec);
|
||||
|
||||
enabled = new TextStencilElement(Minecraft.getInstance().fontRenderer, "Enabled")
|
||||
.centered(true, true)
|
||||
.withElementRenderer((ms, width, height, alpha) -> UIRenderHelper.angledGradient(ms, 0, 0, height/2, height, width, 0xff_88f788, 0xff_20cc20));
|
||||
// enabled = new TextStencilElement(Minecraft.getInstance().fontRenderer, "Enabled")
|
||||
// .centered(true, true)
|
||||
// .withElementRenderer((ms, width, height, alpha) -> UIRenderHelper.angledGradient(ms, 0, 0, height/2, height, width, 0xff_88f788, 0xff_20cc20));
|
||||
//
|
||||
// disabled = new TextStencilElement(Minecraft.getInstance().fontRenderer, "Disabled")
|
||||
// .centered(true, true)
|
||||
// .withElementRenderer((ms, width, height, alpha) -> UIRenderHelper.angledGradient(ms, 0, 0, height/2, height, width, 0xff_f78888, 0xff_cc2020));
|
||||
|
||||
disabled = new TextStencilElement(Minecraft.getInstance().fontRenderer, "Disabled")
|
||||
.centered(true, true)
|
||||
.withElementRenderer((ms, width, height, alpha) -> UIRenderHelper.angledGradient(ms, 0, 0, height/2, height, width, 0xff_f78888, 0xff_cc2020));
|
||||
enabled = AllIcons.I_CONFIRM.asStencil()
|
||||
.withElementRenderer((ms, width, height, alpha) -> UIRenderHelper.angledGradient(ms, 0, 0, height / 2,
|
||||
height, width, 0xff_88f788, 0xff_20cc20))
|
||||
.<RenderElement>at(10, 0);
|
||||
|
||||
button = new BoxWidget()
|
||||
.showingElement(enabled)
|
||||
disabled = AllIcons.I_DISABLE.asStencil()
|
||||
.withElementRenderer((ms, width, height, alpha) -> UIRenderHelper.angledGradient(ms, 0, 0, height / 2,
|
||||
height, width, 0xff_f78888, 0xff_cc2020))
|
||||
.<RenderElement>at(10, 0);
|
||||
|
||||
button = new BoxWidget().showingElement(enabled)
|
||||
.withCallback(() -> setValue(!getValue()));
|
||||
|
||||
listeners.add(button);
|
||||
|
@ -46,12 +55,13 @@ public class BooleanEntry extends ValueEntry<Boolean> {
|
|||
}
|
||||
|
||||
@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) {
|
||||
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);
|
||||
|
||||
button.x = x + getLabelWidth(width);
|
||||
button.x = x + width - 80 - resetWidth;
|
||||
button.y = y + 10;
|
||||
button.setWidth(width - getLabelWidth(width) - resetWidth - 4);
|
||||
button.setWidth(35);
|
||||
button.setHeight(height - 20);
|
||||
button.render(ms, mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import net.minecraftforge.common.ForgeConfigSpec;
|
|||
|
||||
public class EnumEntry extends ValueEntry<Enum<?>> {
|
||||
|
||||
protected static final int cycleWidth = 34;//including 2px offset on either side
|
||||
protected static final int cycleWidth = 34;// including 2px offset on either side
|
||||
|
||||
protected TextStencilElement valueText;
|
||||
protected BoxWidget cycleLeft;
|
||||
|
@ -23,20 +23,20 @@ public class EnumEntry extends ValueEntry<Enum<?>> {
|
|||
super(label, value, spec);
|
||||
|
||||
valueText = new TextStencilElement(Minecraft.getInstance().fontRenderer, "YEP").centered(true, true);
|
||||
valueText.withElementRenderer((ms, width, height, alpha) -> UIRenderHelper.angledGradient(ms, 0 ,0, height/2, height, width, Theme.i(Theme.Key.TEXT_1), Theme.i(Theme.Key.TEXT_2)));
|
||||
valueText.withElementRenderer((ms, width, height, alpha) -> UIRenderHelper.angledGradient(ms, 0, 0, height / 2,
|
||||
height, width, Theme.i(Theme.Key.TEXT_1), Theme.i(Theme.Key.TEXT_2)));
|
||||
|
||||
DelegatedStencilElement l = AllIcons.I_CONFIG_PREV.asStencil();
|
||||
cycleLeft = new BoxWidget(0, 0, 22, 22)
|
||||
.showingElement(l)
|
||||
.rescaleElement(16, 16)
|
||||
cycleLeft = new BoxWidget(0, 0, cycleWidth + 8, 16).showingElement(l)
|
||||
// .rescaleElement(16, 16)
|
||||
.withCallback(() -> cycleValue(-1));
|
||||
l.withElementRenderer(BoxWidget.gradientFactory.apply(cycleLeft));
|
||||
|
||||
DelegatedStencilElement r = AllIcons.I_CONFIG_NEXT.asStencil();
|
||||
cycleRight = new BoxWidget(0, 0, 22, 22)
|
||||
.showingElement(r)
|
||||
.rescaleElement(16, 16)
|
||||
cycleRight = new BoxWidget(0, 0, cycleWidth + 8, 16).showingElement(r)
|
||||
// .rescaleElement(16, 16)
|
||||
.withCallback(() -> cycleValue(1));
|
||||
r.at(cycleWidth - 8, 0);
|
||||
r.withElementRenderer(BoxWidget.gradientFactory.apply(cycleRight));
|
||||
|
||||
listeners.add(cycleLeft);
|
||||
|
@ -47,7 +47,8 @@ public class EnumEntry extends ValueEntry<Enum<?>> {
|
|||
|
||||
protected void cycleValue(int direction) {
|
||||
Enum<?> e = getValue();
|
||||
Enum<?>[] options = e.getDeclaringClass().getEnumConstants();
|
||||
Enum<?>[] options = e.getDeclaringClass()
|
||||
.getEnumConstants();
|
||||
e = options[Math.floorMod(e.ordinal() + direction, options.length)];
|
||||
setValue(e);
|
||||
bumpCog(direction * 15f);
|
||||
|
@ -70,22 +71,29 @@ public class EnumEntry extends ValueEntry<Enum<?>> {
|
|||
}
|
||||
|
||||
@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) {
|
||||
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 + 12;
|
||||
cycleLeft.x = x + getLabelWidth(width) + 4;
|
||||
cycleLeft.y = y + 10;
|
||||
cycleLeft.render(ms, mouseX, mouseY, partialTicks);
|
||||
|
||||
valueText
|
||||
.at(cycleLeft.x - 4 + cycleWidth, y + 12, 0)
|
||||
.withBounds(width - getLabelWidth(width) - 2 * cycleWidth - resetWidth - 4, 22)
|
||||
valueText.at(cycleLeft.x + cycleWidth - 8, y + 10, 200)
|
||||
.withBounds(width - getLabelWidth(width) - 2 * cycleWidth - resetWidth - 4, 16)
|
||||
.render(ms);
|
||||
|
||||
cycleRight.x = x + width - cycleWidth - resetWidth + 2;
|
||||
cycleRight.y = y + 12;
|
||||
cycleRight.x = x + width - cycleWidth * 2 - resetWidth + 10;
|
||||
cycleRight.y = y + 10;
|
||||
cycleRight.render(ms, mouseX, mouseY, partialTicks);
|
||||
|
||||
BoxWidget boxWidget = new BoxWidget(0, 0, 10, 10);
|
||||
boxWidget.x = cycleLeft.x + cycleWidth + 4;
|
||||
boxWidget.y = cycleLeft.y + 3;
|
||||
boxWidget.withBorderColors(java.awt.Color.black, java.awt.Color.black);
|
||||
boxWidget.active = false;
|
||||
boxWidget.render(ms, mouseX, mouseY, partialTicks);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -38,7 +38,7 @@ public abstract class NumberEntry<T extends Number> extends ValueEntry<T> {
|
|||
|
||||
public NumberEntry(String label, ForgeConfigSpec.ConfigValue<T> value, ForgeConfigSpec.ValueSpec spec) {
|
||||
super(label, value, spec);
|
||||
textField = new ConfigTextField(Minecraft.getInstance().fontRenderer, 0, 0, 200, 26, unit);
|
||||
textField = new ConfigTextField(Minecraft.getInstance().fontRenderer, 0, 0, 200, 20, unit);
|
||||
textField.setText(String.valueOf(getValue()));
|
||||
|
||||
Object range = spec.getRange();
|
||||
|
@ -51,13 +51,13 @@ public abstract class NumberEntry<T extends Number> extends ValueEntry<T> {
|
|||
T max = (T) maxField.get(range);
|
||||
|
||||
FontRenderer font = Minecraft.getInstance().fontRenderer;
|
||||
if (!min.equals(getTypeMin())) {
|
||||
if (min.doubleValue() > getTypeMin().doubleValue()) {
|
||||
StringTextComponent t = new StringTextComponent(formatBound(min) + " < ");
|
||||
minText = new TextStencilElement(font, t).centered(true, false);
|
||||
minText.withElementRenderer((ms, width, height, alpha) -> UIRenderHelper.angledGradient(ms, 0 ,0, height/2, height, width, Theme.c(Theme.Key.TEXT_1).darker().getRGB(), Theme.c(Theme.Key.TEXT_2).darker().getRGB()));
|
||||
minOffset = font.getWidth(t);
|
||||
}
|
||||
if (!max.equals(getTypeMax())) {
|
||||
if (max.doubleValue() < getTypeMax().doubleValue()) {
|
||||
StringTextComponent t = new StringTextComponent(" < " + formatBound(max));
|
||||
maxText = new TextStencilElement(font, t).centered(true, false);
|
||||
maxText.withElementRenderer((ms, width, height, alpha) -> UIRenderHelper.angledGradient(ms, 0 ,0, height/2, height, width, Theme.c(Theme.Key.TEXT_1).darker().getRGB(), Theme.c(Theme.Key.TEXT_2).darker().getRGB()));
|
||||
|
@ -123,10 +123,10 @@ public abstract class NumberEntry<T extends Number> extends ValueEntry<T> {
|
|||
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);
|
||||
|
||||
textField.x = x + getLabelWidth(width) + minOffset;
|
||||
textField.y = y + 10;
|
||||
textField.setWidth(width - getLabelWidth(width) - resetWidth - minOffset - maxOffset);
|
||||
textField.setHeight(26);
|
||||
textField.x = x + width - 82 - resetWidth;
|
||||
textField.y = y + 8;
|
||||
textField.setWidth(Math.min(width - getLabelWidth(width) - resetWidth - minOffset - maxOffset, 40));
|
||||
textField.setHeight(20);
|
||||
textField.render(ms, mouseX, mouseY, partialTicks);
|
||||
|
||||
if (minText != null)
|
||||
|
@ -172,7 +172,7 @@ public abstract class NumberEntry<T extends Number> extends ValueEntry<T> {
|
|||
|
||||
@Override
|
||||
protected Float getTypeMin() {
|
||||
return Float.MIN_VALUE;
|
||||
return -Float.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -194,12 +194,12 @@ public abstract class NumberEntry<T extends Number> extends ValueEntry<T> {
|
|||
|
||||
@Override
|
||||
protected Double getTypeMin() {
|
||||
return Double.MIN_VALUE;
|
||||
return (double) -Float.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Double getTypeMax() {
|
||||
return Double.MAX_VALUE;
|
||||
return (double) Float.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,11 +4,11 @@ import com.electronwill.nightconfig.core.UnmodifiableConfig;
|
|||
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||
import com.simibubi.create.foundation.config.ui.ConfigScreenList;
|
||||
import com.simibubi.create.foundation.config.ui.SubMenuConfigScreen;
|
||||
import com.simibubi.create.foundation.gui.AllIcons;
|
||||
import com.simibubi.create.foundation.gui.DelegatedStencilElement;
|
||||
import com.simibubi.create.foundation.gui.ScreenOpener;
|
||||
import com.simibubi.create.foundation.gui.TextStencilElement;
|
||||
import com.simibubi.create.foundation.gui.widgets.BoxWidget;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
|
||||
public class SubMenuEntry extends ConfigScreenList.LabeledEntry {
|
||||
|
@ -17,12 +17,13 @@ public class SubMenuEntry extends ConfigScreenList.LabeledEntry {
|
|||
|
||||
public SubMenuEntry(SubMenuConfigScreen parent, String label, ForgeConfigSpec spec, UnmodifiableConfig config) {
|
||||
super(label);
|
||||
TextStencilElement text = new TextStencilElement(Minecraft.getInstance().fontRenderer, "Click to open").centered(true, true);
|
||||
DelegatedStencilElement element = AllIcons.I_CONFIG_OPEN.asStencil();
|
||||
|
||||
button = new BoxWidget()
|
||||
.showingElement(text)
|
||||
.showingElement(element)
|
||||
.withCallback(() -> ScreenOpener.open(new SubMenuConfigScreen(parent, label, parent.type, spec, config)));
|
||||
text.withElementRenderer(BoxWidget.gradientFactory.apply(button));
|
||||
element.withElementRenderer(BoxWidget.gradientFactory.apply(button));
|
||||
element.at(10, 0);
|
||||
|
||||
listeners.add(button);
|
||||
}
|
||||
|
@ -37,15 +38,15 @@ public class SubMenuEntry extends ConfigScreenList.LabeledEntry {
|
|||
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);
|
||||
|
||||
button.x = x + getLabelWidth(width);
|
||||
button.x = x + width - 108;
|
||||
button.y = y + 10;
|
||||
button.setWidth(width - getLabelWidth(width) - 4);
|
||||
button.setWidth(35);
|
||||
button.setHeight(height - 20);
|
||||
button.render(ms, mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLabelWidth(int totalWidth) {
|
||||
return (int) (totalWidth * labelWidthMult);
|
||||
return (int) (totalWidth * labelWidthMult) + 30;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,13 +108,13 @@ public class ValueEntry<T> extends ConfigScreenList.LabeledEntry {
|
|||
}
|
||||
|
||||
resetButton.x = x + width - resetWidth + 6;
|
||||
resetButton.y = y + 15;
|
||||
resetButton.y = y + 10;
|
||||
resetButton.render(ms, mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLabelWidth(int totalWidth) {
|
||||
return (int) (totalWidth * labelWidthMult);
|
||||
return (int) (totalWidth * labelWidthMult) + 30;
|
||||
}
|
||||
|
||||
public void setValue(@Nonnull T value) {
|
||||
|
|
|
@ -134,7 +134,9 @@ public class AllIcons implements IScreenRenderable {
|
|||
I_CONFIG_RESET = next(),
|
||||
I_CONFIG_BACK = next(),
|
||||
I_CONFIG_PREV = next(),
|
||||
I_CONFIG_NEXT = next();
|
||||
I_CONFIG_NEXT = next(),
|
||||
I_DISABLE = next(),
|
||||
I_CONFIG_OPEN = next();
|
||||
|
||||
public AllIcons(int x, int y) {
|
||||
iconX = x * 16;
|
||||
|
|
|
@ -119,8 +119,8 @@ public class ElementWidget extends AbstractSimiWidget {
|
|||
//element x/y get treated as a border around the element
|
||||
float eX = element.getX();
|
||||
float eY = element.getY();
|
||||
float eWidth = width - 2 * eX;
|
||||
float eHeight = height - 2 * eY;
|
||||
float eWidth = width;// - 2 * eX;
|
||||
float eHeight = height;// - 2 * eY;
|
||||
if (rescaleElement) {
|
||||
float xScale = eWidth / rescaleSizeX;
|
||||
float yScale = eHeight / rescaleSizeY;
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 3.5 KiB |
Loading…
Reference in a new issue