mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-28 16:06:48 +01:00
align style with ponderUI
This commit is contained in:
parent
6b80ea1d04
commit
f0dfc5a6bc
12 changed files with 122 additions and 150 deletions
|
@ -1,10 +1,10 @@
|
||||||
package com.simibubi.create.foundation.config.ui;
|
package com.simibubi.create.foundation.config.ui;
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
|
||||||
import com.simibubi.create.foundation.config.AllConfigs;
|
import com.simibubi.create.foundation.config.AllConfigs;
|
||||||
import com.simibubi.create.foundation.gui.ScreenOpener;
|
import com.simibubi.create.foundation.gui.ScreenOpener;
|
||||||
import com.simibubi.create.foundation.gui.StencilElement;
|
|
||||||
import com.simibubi.create.foundation.gui.TextStencilElement;
|
import com.simibubi.create.foundation.gui.TextStencilElement;
|
||||||
|
import com.simibubi.create.foundation.gui.UIRenderHelper;
|
||||||
|
import com.simibubi.create.foundation.ponder.ui.PonderButton;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
@ -13,9 +13,9 @@ import net.minecraft.util.text.TextFormatting;
|
||||||
|
|
||||||
public class BaseConfigScreen extends ConfigScreen {
|
public class BaseConfigScreen extends ConfigScreen {
|
||||||
|
|
||||||
ConfigButton clientConfigWidget;
|
PonderButton clientConfigWidget;
|
||||||
ConfigButton commonConfigWidget;
|
PonderButton commonConfigWidget;
|
||||||
ConfigButton serverConfigWidget;
|
PonderButton serverConfigWidget;
|
||||||
|
|
||||||
public BaseConfigScreen(Screen parent) {
|
public BaseConfigScreen(Screen parent) {
|
||||||
super(parent);
|
super(parent);
|
||||||
|
@ -26,48 +26,31 @@ public class BaseConfigScreen extends ConfigScreen {
|
||||||
widgets.clear();
|
widgets.clear();
|
||||||
super.init();
|
super.init();
|
||||||
|
|
||||||
StencilElement text = new TextStencilElement(client.fontRenderer, new StringTextComponent("CLIENT CONFIG").formatted(TextFormatting.BOLD)).centered(true, true);
|
TextStencilElement text = new TextStencilElement(client.fontRenderer, new StringTextComponent("CLIENT CONFIG").formatted(TextFormatting.BOLD)).centered(true, true);
|
||||||
widgets.add(clientConfigWidget = ConfigButton.createFromStencilElement(
|
text.withElementRenderer((ms, width, height) -> UIRenderHelper.angledGradient(ms, 0, 0, height / 2, height, width, ConfigButton.Palette.button_idle_1, ConfigButton.Palette.button_idle_2));
|
||||||
width / 2 - 100,
|
widgets.add(clientConfigWidget = new PonderButton(width / 2 - 100, height / 2 - 15 - 50, (_$, _$$) -> {
|
||||||
height / 2 - 15 - 50,
|
ScreenOpener.transitionTo(new SubMenuConfigScreen(this, AllConfigs.CLIENT.specification));
|
||||||
text
|
}, 200, 30).showingUnscaled(text));
|
||||||
)
|
clientConfigWidget.fade(1);
|
||||||
.withBounds(200, 30)
|
|
||||||
.withCallback(() -> ScreenOpener.transitionTo(new SubMenuConfigScreen(this, AllConfigs.CLIENT.specification)))
|
|
||||||
);
|
|
||||||
|
|
||||||
StencilElement text2 = new TextStencilElement(client.fontRenderer, new StringTextComponent("COMMON CONFIG").formatted(TextFormatting.BOLD)).centered(true, true);
|
TextStencilElement text2 = new TextStencilElement(client.fontRenderer, new StringTextComponent("COMMON CONFIG").formatted(TextFormatting.BOLD)).centered(true, true);
|
||||||
widgets.add(commonConfigWidget = ConfigButton.createFromStencilElement(
|
text2.withElementRenderer((ms, width, height) -> UIRenderHelper.angledGradient(ms, 0, 0, height / 2, height, width, ConfigButton.Palette.button_idle_1, ConfigButton.Palette.button_idle_2));
|
||||||
width / 2 - 100,
|
widgets.add(commonConfigWidget = new PonderButton(width / 2 - 100, height / 2 - 15, (_$, _$$) -> {
|
||||||
height / 2 - 15,
|
ScreenOpener.transitionTo(new SubMenuConfigScreen(this, AllConfigs.COMMON.specification));
|
||||||
text2
|
}, 200, 30).showingUnscaled(text2));
|
||||||
)
|
commonConfigWidget.fade(1);
|
||||||
.withBounds(200, 30)
|
|
||||||
.withCallback(() -> ScreenOpener.transitionTo(new SubMenuConfigScreen(this, AllConfigs.COMMON.specification)))
|
|
||||||
);
|
|
||||||
|
|
||||||
StencilElement text3 = new TextStencilElement(client.fontRenderer, new StringTextComponent("SERVER CONFIG").formatted(TextFormatting.BOLD)).centered(true, true);
|
TextStencilElement text3 = new TextStencilElement(client.fontRenderer, new StringTextComponent("SERVER CONFIG").formatted(TextFormatting.BOLD)).centered(true, true);
|
||||||
widgets.add(serverConfigWidget = ConfigButton.createFromStencilElement(
|
text3.withElementRenderer((ms, width, height) -> UIRenderHelper.angledGradient(ms, 0, 0, height / 2, height, width, ConfigButton.Palette.button_idle_1, ConfigButton.Palette.button_idle_2));
|
||||||
width / 2 - 100,
|
widgets.add(serverConfigWidget = new PonderButton(width / 2 - 100, height / 2 - 15 + 50, (_$, _$$) -> {
|
||||||
height / 2 - 15 + 50,
|
}, 200, 30).showingUnscaled(text3));
|
||||||
text3
|
serverConfigWidget.fade(1);
|
||||||
)
|
|
||||||
.withBounds(200, 30)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (Minecraft.getInstance().world != null) {
|
if (Minecraft.getInstance().world != null) {
|
||||||
serverConfigWidget.withCallback(() -> ScreenOpener.transitionTo(new ServerSubMenuConfigScreen(this, AllConfigs.SERVER.specification)));
|
serverConfigWidget.withCallback(() -> ScreenOpener.transitionTo(new ServerSubMenuConfigScreen(this, AllConfigs.SERVER.specification)));
|
||||||
} else {
|
} else {
|
||||||
serverConfigWidget.active = false;
|
serverConfigWidget.active = false;
|
||||||
serverConfigWidget.updateColorsFromState();
|
text3.withElementRenderer((ms, width, height) -> UIRenderHelper.angledGradient(ms, 0, 0, height / 2, height, width, ConfigButton.Palette.button_disable_1, ConfigButton.Palette.button_disable_2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class ConfigButton extends StencilWidget {
|
||||||
|
|
||||||
RenderSystem.enableBlend();
|
RenderSystem.enableBlend();
|
||||||
RenderSystem.blendFunc(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE);
|
RenderSystem.blendFunc(GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ONE);
|
||||||
fill(ms, x, y, x + width, y + height, 0x30_ffffff);
|
fill(ms, x, y, x + width, y + height, 0x10_ffffff);
|
||||||
RenderSystem.defaultBlendFunc();
|
RenderSystem.defaultBlendFunc();
|
||||||
super.renderButton(ms, mouseX, mouseY, partialTicks);
|
super.renderButton(ms, mouseX, mouseY, partialTicks);
|
||||||
wasHovered = hovered;
|
wasHovered = hovered;
|
||||||
|
|
|
@ -25,14 +25,29 @@ import net.minecraft.util.Direction;
|
||||||
public abstract class ConfigScreen extends NavigatableSimiScreen {
|
public abstract class ConfigScreen extends NavigatableSimiScreen {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO match style with ponderUI
|
|
||||||
* TODO cache changes before setting values and saving to file
|
|
||||||
* TODO don't exit on ESC
|
|
||||||
* TODO reset text field focus for any click inside screen
|
|
||||||
* TODO adjust transition animation of screens
|
|
||||||
* TODO allow backspace in text fields
|
|
||||||
*
|
*
|
||||||
* TODO some color themes maybe?
|
* TODO
|
||||||
|
* zelo's list for configUI
|
||||||
|
*
|
||||||
|
* match style with ponderUI
|
||||||
|
* cache changes before setting values and saving to file
|
||||||
|
* don't exit on ESC
|
||||||
|
* reset text field focus for any click inside screen
|
||||||
|
* adjust transition animation of screens
|
||||||
|
* allow backspace in text fields
|
||||||
|
* move config button's animations to ponder button or a new superclass
|
||||||
|
* get some proper icons for reset button and enum cycle
|
||||||
|
* some small shadow effect for top and bottom of the list
|
||||||
|
* add the 'think back' button back, just with a different caption
|
||||||
|
* add a title to the current config screen, maybe in the form of breadcrumbs
|
||||||
|
*
|
||||||
|
* some color themes maybe?
|
||||||
|
* at least a helper class to unite colors throughout different uis
|
||||||
|
*
|
||||||
|
* FIXME
|
||||||
|
*
|
||||||
|
* tooltip are hidden underneath the scrollbar, if the bar is near the middle
|
||||||
|
* misalignment of the label-streak and textboxes/enum stuff
|
||||||
*
|
*
|
||||||
* */
|
* */
|
||||||
|
|
||||||
|
@ -97,7 +112,7 @@ public abstract class ConfigScreen extends NavigatableSimiScreen {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderElement(MatrixStack ms) {
|
protected void renderElement(MatrixStack ms) {
|
||||||
fill(ms, -200, -200, 200, 200, 0x40_000000);
|
fill(ms, -200, -200, 200, 200, 0x60_000000);
|
||||||
}
|
}
|
||||||
}.at(width * 0.5f, height * 0.5f, 0).render(ms);
|
}.at(width * 0.5f, height * 0.5f, 0).render(ms);
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.simibubi.create.foundation.config.ui;
|
package com.simibubi.create.foundation.config.ui;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
|
@ -10,7 +9,6 @@ import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.simibubi.create.foundation.gui.TextStencilElement;
|
import com.simibubi.create.foundation.gui.TextStencilElement;
|
||||||
import com.simibubi.create.foundation.gui.UIRenderHelper;
|
import com.simibubi.create.foundation.gui.UIRenderHelper;
|
||||||
import com.simibubi.create.foundation.gui.widgets.AbstractSimiWidget;
|
|
||||||
|
|
||||||
import net.minecraft.client.MainWindow;
|
import net.minecraft.client.MainWindow;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
@ -20,7 +18,6 @@ import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||||
import net.minecraft.client.gui.widget.list.ExtendedList;
|
import net.minecraft.client.gui.widget.list.ExtendedList;
|
||||||
import net.minecraft.util.text.IFormattableTextComponent;
|
import net.minecraft.util.text.IFormattableTextComponent;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraft.util.text.StringTextComponent;
|
|
||||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||||
|
|
||||||
public class ConfigScreenList extends ExtendedList<ConfigScreenList.Entry> {
|
public class ConfigScreenList extends ExtendedList<ConfigScreenList.Entry> {
|
||||||
|
@ -39,7 +36,7 @@ public class ConfigScreenList extends ExtendedList<ConfigScreenList.Entry> {
|
||||||
@Override
|
@Override
|
||||||
public void render(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
|
public void render(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
|
||||||
//render tmp background
|
//render tmp background
|
||||||
fill(ms, left, top, left+width, top+height, 0x44_000000);
|
fill(ms, left, top, left + width, top + height, 0x10_000000);
|
||||||
|
|
||||||
super.render(ms, mouseX, mouseY, partialTicks);
|
super.render(ms, mouseX, mouseY, partialTicks);
|
||||||
}
|
}
|
||||||
|
@ -48,19 +45,19 @@ public class ConfigScreenList extends ExtendedList<ConfigScreenList.Entry> {
|
||||||
protected void renderList(MatrixStack p_238478_1_, int p_238478_2_, int p_238478_3_, int p_238478_4_, int p_238478_5_, float p_238478_6_) {
|
protected void renderList(MatrixStack p_238478_1_, int p_238478_2_, int p_238478_3_, int p_238478_4_, int p_238478_5_, float p_238478_6_) {
|
||||||
MainWindow window = Minecraft.getInstance().getWindow();
|
MainWindow window = Minecraft.getInstance().getWindow();
|
||||||
double d0 = window.getGuiScaleFactor();
|
double d0 = window.getGuiScaleFactor();
|
||||||
RenderSystem.enableScissor((int) (this.left * d0), (int) (window.getFramebufferHeight() - (this.bottom* d0)), (int)(this.width * d0), (int)(this.height * d0));
|
RenderSystem.enableScissor((int) (this.left * d0), (int) (window.getFramebufferHeight() - (this.bottom * d0)), (int) (this.width * d0), (int) (this.height * d0));
|
||||||
super.renderList(p_238478_1_, p_238478_2_, p_238478_3_, p_238478_4_, p_238478_5_, p_238478_6_);
|
super.renderList(p_238478_1_, p_238478_2_, p_238478_3_, p_238478_4_, p_238478_5_, p_238478_6_);
|
||||||
RenderSystem.disableScissor();
|
RenderSystem.disableScissor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getRowWidth() {
|
public int getRowWidth() {
|
||||||
return width-18;
|
return width - 18;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getScrollbarPositionX() {
|
protected int getScrollbarPositionX() {
|
||||||
return left + this.width-5;
|
return left + this.width - 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void tick() {
|
public void tick() {
|
||||||
|
@ -117,17 +114,18 @@ public class ConfigScreenList extends ExtendedList<ConfigScreenList.Entry> {
|
||||||
|
|
||||||
public LabeledEntry(String label) {
|
public LabeledEntry(String label) {
|
||||||
this.label = new TextStencilElement(Minecraft.getInstance().fontRenderer, label);
|
this.label = new TextStencilElement(Minecraft.getInstance().fontRenderer, label);
|
||||||
|
this.label.withElementRenderer((ms, width, height) -> UIRenderHelper.angledGradient(ms, 0, 0, height / 2, height, width, ConfigButton.Palette.button_idle_1, ConfigButton.Palette.button_idle_2));
|
||||||
labelTooltip = new ArrayList<>();
|
labelTooltip = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
||||||
UIRenderHelper.streak(ms, 0, x, y+height/2, height - 10, getLabelWidth(width), 0x0);
|
UIRenderHelper.streak(ms, 0, x, y + height / 2, height - 10, getLabelWidth(width) + ((width - getLabelWidth(width)) / 3), 0xdd_000000);
|
||||||
IFormattableTextComponent component = label.getComponent();
|
IFormattableTextComponent component = label.getComponent();
|
||||||
if (Minecraft.getInstance().fontRenderer.getWidth(component) > getLabelWidth(width) - 10) {
|
if (Minecraft.getInstance().fontRenderer.getWidth(component) > getLabelWidth(width) - 10) {
|
||||||
label.withText(Minecraft.getInstance().fontRenderer.trimToWidth(component, getLabelWidth(width) - 15).getString() + "...");
|
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 + 5, y + height / 2 - 4, 0).render(ms);
|
||||||
|
|
||||||
if (mouseX > x && mouseX < x + getLabelWidth(width) && mouseY > y + 5 && mouseY < y + height - 5) {
|
if (mouseX > x && mouseX < x + getLabelWidth(width) && mouseY > y + 5 && mouseY < y + height - 5) {
|
||||||
List<ITextComponent> tooltip = getLabelTooltip();
|
List<ITextComponent> tooltip = getLabelTooltip();
|
||||||
|
@ -136,7 +134,10 @@ public class ConfigScreenList extends ExtendedList<ConfigScreenList.Entry> {
|
||||||
|
|
||||||
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
GL11.glDisable(GL11.GL_SCISSOR_TEST);
|
||||||
Screen screen = Minecraft.getInstance().currentScreen;
|
Screen screen = Minecraft.getInstance().currentScreen;
|
||||||
|
ms.push();
|
||||||
|
ms.translate(0, 0, 400);
|
||||||
GuiUtils.drawHoveringText(ms, tooltip, mouseX, mouseY, screen.width, screen.height, 300, Minecraft.getInstance().fontRenderer);
|
GuiUtils.drawHoveringText(ms, tooltip, mouseX, mouseY, screen.width, screen.height, 300, Minecraft.getInstance().fontRenderer);
|
||||||
|
ms.pop();
|
||||||
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
GL11.glEnable(GL11.GL_SCISSOR_TEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,33 +150,4 @@ public class ConfigScreenList extends ExtendedList<ConfigScreenList.Entry> {
|
||||||
return totalWidth;
|
return totalWidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class WrappedEntry extends Entry {
|
|
||||||
|
|
||||||
AbstractSimiWidget widget;
|
|
||||||
|
|
||||||
public WrappedEntry(AbstractSimiWidget widget) {
|
|
||||||
this.widget = widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick() {
|
|
||||||
if (widget instanceof ConfigButton)
|
|
||||||
((ConfigButton) widget).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) {
|
|
||||||
widget.x = x;
|
|
||||||
widget.y = y;
|
|
||||||
widget.setWidth(width);
|
|
||||||
widget.setHeight(height);
|
|
||||||
widget.render(ms, mouseX, mouseY, partialTicks);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean mouseClicked(double x, double y, int button) {
|
|
||||||
return widget.mouseClicked(x, y, button);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,11 +2,8 @@ package com.simibubi.create.foundation.config.ui;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
|
||||||
import net.minecraftforge.common.ForgeConfigSpec;
|
|
||||||
|
|
||||||
import org.apache.commons.lang3.mutable.MutableInt;
|
import org.apache.commons.lang3.mutable.MutableInt;
|
||||||
|
|
||||||
import com.electronwill.nightconfig.core.AbstractConfig;
|
import com.electronwill.nightconfig.core.AbstractConfig;
|
||||||
import com.electronwill.nightconfig.core.UnmodifiableConfig;
|
import com.electronwill.nightconfig.core.UnmodifiableConfig;
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
|
@ -14,9 +11,10 @@ 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.EnumEntry;
|
||||||
import com.simibubi.create.foundation.config.ui.entries.NumberEntry;
|
import com.simibubi.create.foundation.config.ui.entries.NumberEntry;
|
||||||
import com.simibubi.create.foundation.config.ui.entries.SubMenuEntry;
|
import com.simibubi.create.foundation.config.ui.entries.SubMenuEntry;
|
||||||
import com.simibubi.create.foundation.gui.ScreenOpener;
|
|
||||||
import com.simibubi.create.foundation.gui.TextStencilElement;
|
import net.minecraft.client.Minecraft;
|
||||||
import com.simibubi.create.foundation.gui.widgets.AbstractSimiWidget;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
import net.minecraftforge.common.ForgeConfigSpec;
|
||||||
|
|
||||||
public class SubMenuConfigScreen extends ConfigScreen {
|
public class SubMenuConfigScreen extends ConfigScreen {
|
||||||
|
|
||||||
|
@ -50,7 +48,7 @@ public class SubMenuConfigScreen extends ConfigScreen {
|
||||||
|
|
||||||
int lWidth = Math.min(width - 66, 500);
|
int lWidth = Math.min(width - 66, 500);
|
||||||
list = new ConfigScreenList(client, lWidth, height - 30, 15, height - 15, 50);
|
list = new ConfigScreenList(client, lWidth, height - 30, 15, height - 15, 50);
|
||||||
list.setLeftPos(this.width /2 - list.getWidth()/2);
|
list.setLeftPos(this.width / 2 - list.getWidth() / 2);
|
||||||
|
|
||||||
children.add(list);
|
children.add(list);
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package com.simibubi.create.foundation.config.ui.entries;
|
package com.simibubi.create.foundation.config.ui.entries;
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
import com.simibubi.create.foundation.config.ui.ConfigButton;
|
|
||||||
import com.simibubi.create.foundation.gui.CombinedStencilElement;
|
|
||||||
import com.simibubi.create.foundation.gui.TextStencilElement;
|
import com.simibubi.create.foundation.gui.TextStencilElement;
|
||||||
import com.simibubi.create.foundation.gui.UIRenderHelper;
|
import com.simibubi.create.foundation.gui.UIRenderHelper;
|
||||||
|
import com.simibubi.create.foundation.ponder.ui.PonderButton;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraftforge.common.ForgeConfigSpec;
|
import net.minecraftforge.common.ForgeConfigSpec;
|
||||||
|
@ -13,8 +12,7 @@ public class BooleanEntry extends ValueEntry<Boolean> {
|
||||||
|
|
||||||
TextStencilElement enabled;
|
TextStencilElement enabled;
|
||||||
TextStencilElement disabled;
|
TextStencilElement disabled;
|
||||||
CombinedStencilElement buttonStencil;
|
PonderButton button;
|
||||||
ConfigButton button;
|
|
||||||
|
|
||||||
public BooleanEntry(String label, ForgeConfigSpec.ConfigValue<Boolean> value, ForgeConfigSpec.ValueSpec spec) {
|
public BooleanEntry(String label, ForgeConfigSpec.ConfigValue<Boolean> value, ForgeConfigSpec.ValueSpec spec) {
|
||||||
super(label, value, spec);
|
super(label, value, spec);
|
||||||
|
@ -27,16 +25,11 @@ public class BooleanEntry extends ValueEntry<Boolean> {
|
||||||
.centered(true, true)
|
.centered(true, true)
|
||||||
.withElementRenderer((ms, width, height) -> UIRenderHelper.angledGradient(ms, 0, 0, height/2, height, width, 0xff_f78888, 0xff_cc2020));
|
.withElementRenderer((ms, width, height) -> UIRenderHelper.angledGradient(ms, 0, 0, height/2, height, width, 0xff_f78888, 0xff_cc2020));
|
||||||
|
|
||||||
button = ConfigButton.createFromStencilElement(0, 0, enabled)
|
button = new PonderButton(0, 0, () -> {
|
||||||
.withCallback(() -> {
|
|
||||||
value.set(!value.get());
|
value.set(!value.get());
|
||||||
buttonStencil.withSecond(value.get() ? enabled : disabled);
|
|
||||||
onValueChange();
|
onValueChange();
|
||||||
});
|
}).showingUnscaled(enabled);
|
||||||
|
button.fade(1);
|
||||||
buttonStencil = ((CombinedStencilElement) button.getStencilElement())
|
|
||||||
.withMode(CombinedStencilElement.ElementMode.BOTH)
|
|
||||||
.withSecond(value.get() ? enabled : disabled);
|
|
||||||
|
|
||||||
listeners.add(button);
|
listeners.add(button);
|
||||||
onReset();
|
onReset();
|
||||||
|
@ -46,13 +39,11 @@ public class BooleanEntry extends ValueEntry<Boolean> {
|
||||||
protected void setEditable(boolean b) {
|
protected void setEditable(boolean b) {
|
||||||
super.setEditable(b);
|
super.setEditable(b);
|
||||||
button.active = b;
|
button.active = b;
|
||||||
button.animateGradientFromState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
super.tick();
|
super.tick();
|
||||||
button.tick();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,14 +51,16 @@ public class BooleanEntry extends ValueEntry<Boolean> {
|
||||||
super.render(ms, index, y, x, width, height, mouseX, mouseY, p_230432_9_, partialTicks);
|
super.render(ms, index, y, x, width, height, mouseX, mouseY, p_230432_9_, partialTicks);
|
||||||
|
|
||||||
button.x = x + getLabelWidth(width);
|
button.x = x + getLabelWidth(width);
|
||||||
button.y = y;
|
button.y = y + 10;
|
||||||
button.withBounds(width - getLabelWidth(width) - resetWidth, height).render(ms, mouseX, mouseY, partialTicks);
|
button.setWidth(width - getLabelWidth(width) - resetWidth - 4);
|
||||||
|
button.setHeight(height - 20);
|
||||||
|
button.render(ms, mouseX, mouseY, partialTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onValueChange() {
|
protected void onValueChange() {
|
||||||
super.onValueChange();
|
super.onValueChange();
|
||||||
buttonStencil.withSecond(value.get() ? enabled : disabled);
|
button.showingUnscaled(value.get() ? enabled : disabled);
|
||||||
bumpCog(value.get() ? 15f : -16f);
|
bumpCog(value.get() ? 15f : -16f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.simibubi.create.foundation.config.ui.entries;
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
import com.simibubi.create.foundation.config.ui.ConfigButton;
|
import com.simibubi.create.foundation.config.ui.ConfigButton;
|
||||||
import com.simibubi.create.foundation.gui.TextStencilElement;
|
import com.simibubi.create.foundation.gui.TextStencilElement;
|
||||||
|
import com.simibubi.create.foundation.gui.UIRenderHelper;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraftforge.common.ForgeConfigSpec;
|
import net.minecraftforge.common.ForgeConfigSpec;
|
||||||
|
@ -19,6 +20,7 @@ public class EnumEntry extends ValueEntry<Enum<?>> {
|
||||||
super(label, value, spec);
|
super(label, value, spec);
|
||||||
|
|
||||||
valueText = new TextStencilElement(Minecraft.getInstance().fontRenderer, "YEP").centered(true, true);
|
valueText = new TextStencilElement(Minecraft.getInstance().fontRenderer, "YEP").centered(true, true);
|
||||||
|
valueText.withElementRenderer((ms, width, height) -> UIRenderHelper.angledGradient(ms, 0 ,0, height/2, height, width, ConfigButton.Palette.button_hover_1, ConfigButton.Palette.button_hover_2));
|
||||||
|
|
||||||
TextStencilElement l = new TextStencilElement(Minecraft.getInstance().fontRenderer, "<").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));
|
cycleLeft = ConfigButton.createAndInjectElementRenderer(0, 0, l).withBounds(30, 30).withCallback(() -> cycleValue(-1));
|
||||||
|
|
|
@ -6,8 +6,10 @@ import java.util.function.Function;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
|
import com.simibubi.create.foundation.config.ui.ConfigButton;
|
||||||
import com.simibubi.create.foundation.config.ui.ConfigTextField;
|
import com.simibubi.create.foundation.config.ui.ConfigTextField;
|
||||||
import com.simibubi.create.foundation.gui.TextStencilElement;
|
import com.simibubi.create.foundation.gui.TextStencilElement;
|
||||||
|
import com.simibubi.create.foundation.gui.UIRenderHelper;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.FontRenderer;
|
import net.minecraft.client.gui.FontRenderer;
|
||||||
|
@ -52,11 +54,13 @@ public abstract class NumberEntry<T extends Number> extends ValueEntry<T> {
|
||||||
if (!min.equals(getTypeMin())) {
|
if (!min.equals(getTypeMin())) {
|
||||||
StringTextComponent t = new StringTextComponent(formatBound(min) + " < ");
|
StringTextComponent t = new StringTextComponent(formatBound(min) + " < ");
|
||||||
minText = new TextStencilElement(font, t).centered(true, false);
|
minText = new TextStencilElement(font, t).centered(true, false);
|
||||||
|
minText.withElementRenderer((ms, width, height) -> UIRenderHelper.angledGradient(ms, 0 ,0, height/2, height, width, ConfigButton.Palette.button_hover_1, ConfigButton.Palette.button_hover_2));
|
||||||
minOffset = font.getWidth(t);
|
minOffset = font.getWidth(t);
|
||||||
}
|
}
|
||||||
if (!max.equals(getTypeMax())) {
|
if (!max.equals(getTypeMax())) {
|
||||||
StringTextComponent t = new StringTextComponent(" < " + formatBound(max));
|
StringTextComponent t = new StringTextComponent(" < " + formatBound(max));
|
||||||
maxText = new TextStencilElement(font, t).centered(true, false);
|
maxText = new TextStencilElement(font, t).centered(true, false);
|
||||||
|
maxText.withElementRenderer((ms, width, height) -> UIRenderHelper.angledGradient(ms, 0 ,0, height/2, height, width, ConfigButton.Palette.button_hover_1, ConfigButton.Palette.button_hover_2));
|
||||||
maxOffset = font.getWidth(t);
|
maxOffset = font.getWidth(t);
|
||||||
}
|
}
|
||||||
} catch (NoSuchFieldException | IllegalAccessException | ClassCastException | NullPointerException ignored) {
|
} catch (NoSuchFieldException | IllegalAccessException | ClassCastException | NullPointerException ignored) {
|
||||||
|
|
|
@ -8,6 +8,8 @@ import com.simibubi.create.foundation.config.ui.ServerSubMenuConfigScreen;
|
||||||
import com.simibubi.create.foundation.config.ui.SubMenuConfigScreen;
|
import com.simibubi.create.foundation.config.ui.SubMenuConfigScreen;
|
||||||
import com.simibubi.create.foundation.gui.ScreenOpener;
|
import com.simibubi.create.foundation.gui.ScreenOpener;
|
||||||
import com.simibubi.create.foundation.gui.TextStencilElement;
|
import com.simibubi.create.foundation.gui.TextStencilElement;
|
||||||
|
import com.simibubi.create.foundation.gui.UIRenderHelper;
|
||||||
|
import com.simibubi.create.foundation.ponder.ui.PonderButton;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.screen.Screen;
|
import net.minecraft.client.gui.screen.Screen;
|
||||||
|
@ -15,16 +17,17 @@ import net.minecraftforge.common.ForgeConfigSpec;
|
||||||
|
|
||||||
public class SubMenuEntry extends ConfigScreenList.LabeledEntry {
|
public class SubMenuEntry extends ConfigScreenList.LabeledEntry {
|
||||||
|
|
||||||
protected ConfigButton button;
|
protected PonderButton button;
|
||||||
|
|
||||||
public SubMenuEntry(Screen parent, String label, ForgeConfigSpec spec, UnmodifiableConfig config) {
|
public SubMenuEntry(Screen parent, String label, ForgeConfigSpec spec, UnmodifiableConfig config) {
|
||||||
super(label);
|
super(label);
|
||||||
TextStencilElement text = new TextStencilElement(Minecraft.getInstance().fontRenderer, "Click to open").centered(true, true);
|
TextStencilElement text = new TextStencilElement(Minecraft.getInstance().fontRenderer, "Click to open").centered(true, true);
|
||||||
button = ConfigButton.createFromStencilElement(0, 0, text)
|
text.withElementRenderer((ms, width, height) -> UIRenderHelper.angledGradient(ms, 0 ,0, height/2, height, width, ConfigButton.Palette.button_idle_1, ConfigButton.Palette.button_idle_2));
|
||||||
.withCallback(() -> ScreenOpener.transitionTo(isForServer() ?
|
button = new PonderButton(0, 0, () -> ScreenOpener.transitionTo(isForServer() ?
|
||||||
new ServerSubMenuConfigScreen(parent, spec, config) :
|
new ServerSubMenuConfigScreen(parent, spec, config) :
|
||||||
new SubMenuConfigScreen(parent, spec, config)
|
new SubMenuConfigScreen(parent, spec, config))
|
||||||
));
|
).showingUnscaled(text);
|
||||||
|
button.fade(1);
|
||||||
|
|
||||||
listeners.add(button);
|
listeners.add(button);
|
||||||
}
|
}
|
||||||
|
@ -32,7 +35,6 @@ public class SubMenuEntry extends ConfigScreenList.LabeledEntry {
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
super.tick();
|
super.tick();
|
||||||
button.tick();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -40,8 +42,9 @@ public class SubMenuEntry extends ConfigScreenList.LabeledEntry {
|
||||||
super.render(ms, index, y, x, width, height, mouseX, mouseY, p_230432_9_, partialTicks);
|
super.render(ms, index, y, x, width, height, mouseX, mouseY, p_230432_9_, partialTicks);
|
||||||
|
|
||||||
button.x = x + getLabelWidth(width);
|
button.x = x + getLabelWidth(width);
|
||||||
button.y = y;
|
button.y = y + 10;
|
||||||
button.withBounds(width - getLabelWidth(width), height);
|
button.setWidth(width - getLabelWidth(width) - 4);
|
||||||
|
button.setHeight(height - 20);
|
||||||
button.render(ms, mouseX, mouseY, partialTicks);
|
button.render(ms, mouseX, mouseY, partialTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,9 +52,4 @@ public class SubMenuEntry extends ConfigScreenList.LabeledEntry {
|
||||||
protected int getLabelWidth(int totalWidth) {
|
protected int getLabelWidth(int totalWidth) {
|
||||||
return (int) (totalWidth * labelWidthMult);
|
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_);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,9 @@ import com.simibubi.create.foundation.config.ui.CConfigureConfigPacket;
|
||||||
import com.simibubi.create.foundation.config.ui.ConfigButton;
|
import com.simibubi.create.foundation.config.ui.ConfigButton;
|
||||||
import com.simibubi.create.foundation.config.ui.ConfigScreenList;
|
import com.simibubi.create.foundation.config.ui.ConfigScreenList;
|
||||||
import com.simibubi.create.foundation.gui.TextStencilElement;
|
import com.simibubi.create.foundation.gui.TextStencilElement;
|
||||||
|
import com.simibubi.create.foundation.gui.UIRenderHelper;
|
||||||
import com.simibubi.create.foundation.networking.AllPackets;
|
import com.simibubi.create.foundation.networking.AllPackets;
|
||||||
|
import com.simibubi.create.foundation.ponder.ui.PonderButton;
|
||||||
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.util.text.StringTextComponent;
|
import net.minecraft.util.text.StringTextComponent;
|
||||||
|
@ -22,12 +24,12 @@ import net.minecraftforge.common.ForgeConfigSpec;
|
||||||
|
|
||||||
public class ValueEntry<T> extends ConfigScreenList.LabeledEntry {
|
public class ValueEntry<T> extends ConfigScreenList.LabeledEntry {
|
||||||
|
|
||||||
protected static final int resetWidth = 24;//including 2px offset on either side
|
protected static final int resetWidth = 28;//including 6px offset on either side
|
||||||
public static final Pattern unitPattern = Pattern.compile("\\[(in .*)]");
|
public static final Pattern unitPattern = Pattern.compile("\\[(in .*)]");
|
||||||
|
|
||||||
protected ForgeConfigSpec.ConfigValue<T> value;
|
protected ForgeConfigSpec.ConfigValue<T> value;
|
||||||
protected ForgeConfigSpec.ValueSpec spec;
|
protected ForgeConfigSpec.ValueSpec spec;
|
||||||
protected ConfigButton reset;
|
protected PonderButton resetButton;
|
||||||
protected boolean editable = true;
|
protected boolean editable = true;
|
||||||
protected String unit = null;
|
protected String unit = null;
|
||||||
|
|
||||||
|
@ -37,14 +39,15 @@ public class ValueEntry<T> extends ConfigScreenList.LabeledEntry {
|
||||||
this.spec = spec;
|
this.spec = spec;
|
||||||
|
|
||||||
TextStencilElement text = new TextStencilElement(Minecraft.getInstance().fontRenderer, "R").centered(true, true);
|
TextStencilElement text = new TextStencilElement(Minecraft.getInstance().fontRenderer, "R").centered(true, true);
|
||||||
reset = ConfigButton.createFromStencilElement(0, 0, text)
|
text.withElementRenderer((ms, width, height) -> UIRenderHelper.angledGradient(ms, 0 ,0, height/2, height, width, ConfigButton.Palette.button_idle_1, ConfigButton.Palette.button_idle_2));
|
||||||
.withBounds(resetWidth - 4, 20)
|
resetButton = new PonderButton(0, 0, (_$, _$$) -> {
|
||||||
.withCallback(() -> {
|
|
||||||
value.set((T) spec.getDefault());
|
value.set((T) spec.getDefault());
|
||||||
this.onReset();
|
this.onReset();
|
||||||
});
|
}, resetWidth - 12, 16).showingUnscaled(text);
|
||||||
|
resetButton.fade(1);
|
||||||
|
|
||||||
|
listeners.add(resetButton);
|
||||||
|
|
||||||
listeners.add(reset);
|
|
||||||
List<String> path = value.getPath();
|
List<String> path = value.getPath();
|
||||||
labelTooltip.add(new StringTextComponent(path.get(path.size()-1)).formatted(TextFormatting.GRAY));
|
labelTooltip.add(new StringTextComponent(path.get(path.size()-1)).formatted(TextFormatting.GRAY));
|
||||||
String comment = spec.getComment();
|
String comment = spec.getComment();
|
||||||
|
@ -79,22 +82,16 @@ public class ValueEntry<T> extends ConfigScreenList.LabeledEntry {
|
||||||
@Override
|
@Override
|
||||||
protected void setEditable(boolean b) {
|
protected void setEditable(boolean b) {
|
||||||
editable = b;
|
editable = b;
|
||||||
reset.active = editable && !value.get().equals(spec.getDefault());
|
resetButton.active = editable && !value.get().equals(spec.getDefault());
|
||||||
reset.animateGradientFromState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void tick() {
|
|
||||||
reset.tick();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
super.render(ms, index, y, x, width, height, mouseX, mouseY, p_230432_9_, partialTicks);
|
||||||
|
|
||||||
reset.x = x + width - resetWidth + 2;
|
resetButton.x = x + width - resetWidth + 6;
|
||||||
reset.y = y + 15;
|
resetButton.y = y + 15;
|
||||||
reset.render(ms, mouseX, mouseY, partialTicks);
|
resetButton.render(ms, mouseX, mouseY, partialTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -107,8 +104,7 @@ public class ValueEntry<T> extends ConfigScreenList.LabeledEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onValueChange() {
|
protected void onValueChange() {
|
||||||
reset.active = editable && !value.get().equals(spec.getDefault());
|
resetButton.active = editable && !value.get().equals(spec.getDefault());
|
||||||
reset.animateGradientFromState();
|
|
||||||
|
|
||||||
if (!isForServer())
|
if (!isForServer())
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -43,4 +43,9 @@ public abstract class AbstractSimiWidget extends Widget {
|
||||||
public void runCallback(double mouseX, double mouseY) {
|
public void runCallback(double mouseX, double mouseY) {
|
||||||
onClick.accept((int) mouseX, (int) mouseY);
|
onClick.accept((int) mouseX, (int) mouseY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(double mouseX, double mouseY) {
|
||||||
|
runCallback(mouseX, mouseY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
import com.simibubi.create.foundation.gui.GuiGameElement;
|
import com.simibubi.create.foundation.gui.GuiGameElement;
|
||||||
import com.simibubi.create.foundation.gui.IScreenRenderable;
|
import com.simibubi.create.foundation.gui.IScreenRenderable;
|
||||||
|
import com.simibubi.create.foundation.gui.StencilElement;
|
||||||
import com.simibubi.create.foundation.gui.widgets.AbstractSimiWidget;
|
import com.simibubi.create.foundation.gui.widgets.AbstractSimiWidget;
|
||||||
import com.simibubi.create.foundation.ponder.PonderUI;
|
import com.simibubi.create.foundation.ponder.PonderUI;
|
||||||
import com.simibubi.create.foundation.utility.ColorHelper;
|
import com.simibubi.create.foundation.utility.ColorHelper;
|
||||||
|
@ -133,6 +134,11 @@ public class PonderButton extends AbstractSimiWidget {
|
||||||
ms.translate(x + 2, y + 2, 0);
|
ms.translate(x + 2, y + 2, 0);
|
||||||
if (this.scaleIcon)
|
if (this.scaleIcon)
|
||||||
ms.scale((width - 4) / 16f, (height - 4) / 16f, 1);
|
ms.scale((width - 4) / 16f, (height - 4) / 16f, 1);
|
||||||
|
else {
|
||||||
|
if (icon instanceof StencilElement){
|
||||||
|
((StencilElement) icon).withBounds(width - 4, height - 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
icon.draw(ms, this, 0, 0);
|
icon.draw(ms, this, 0, 0);
|
||||||
ms.pop();
|
ms.pop();
|
||||||
|
|
Loading…
Reference in a new issue