confirm again

- fix confirmation screen not rendering its stencil elements corectly
- add a title with the current modId to config base screen
This commit is contained in:
zelophed 2021-07-02 12:56:58 +02:00
parent c6fa055d9b
commit 8550b07011
6 changed files with 108 additions and 20 deletions

View file

@ -1,8 +1,11 @@
package com.simibubi.create.foundation.config.ui; package com.simibubi.create.foundation.config.ui;
import java.util.Locale;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.Create; import com.simibubi.create.Create;
import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.gui.AllIcons; import com.simibubi.create.foundation.gui.AllIcons;
@ -35,6 +38,7 @@ public class BaseConfigScreen extends ConfigScreen {
BoxWidget commonConfigWidget; BoxWidget commonConfigWidget;
BoxWidget serverConfigWidget; BoxWidget serverConfigWidget;
BoxWidget goBack; BoxWidget goBack;
BoxWidget title;
ForgeConfigSpec clientSpec; ForgeConfigSpec clientSpec;
ForgeConfigSpec commonSpec; ForgeConfigSpec commonSpec;
@ -140,14 +144,12 @@ public class BaseConfigScreen extends ConfigScreen {
TextStencilElement serverText = new TextStencilElement(client.fontRenderer, new StringTextComponent(serverTile)).centered(true, true); TextStencilElement serverText = new TextStencilElement(client.fontRenderer, new StringTextComponent(serverTile)).centered(true, true);
widgets.add(serverConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15 + 30, 200, 16).showingElement(serverText)); widgets.add(serverConfigWidget = new BoxWidget(width / 2 - 100, height / 2 - 15 + 30, 200, 16).showingElement(serverText));
if (serverSpec != null && Minecraft.getInstance().world != null) { if (serverSpec == null) {
serverConfigWidget.withCallback(() -> linkTo(new SubMenuConfigScreen(this, ModConfig.Type.SERVER, serverSpec)));
serverText.withElementRenderer(BoxWidget.gradientFactory.apply(serverConfigWidget));
} else {
serverConfigWidget.active = false; serverConfigWidget.active = false;
serverConfigWidget.updateColorsFromState(); serverConfigWidget.updateColorsFromState();
serverText.withElementRenderer(DISABLED_RENDERER); serverText.withElementRenderer(DISABLED_RENDERER);
serverConfigWidget.active = true; } else if (Minecraft.getInstance().world == null) {
serverText.withElementRenderer(DISABLED_RENDERER);
serverConfigWidget.getToolTip() serverConfigWidget.getToolTip()
.add(new StringTextComponent("Stored individually per World")); .add(new StringTextComponent("Stored individually per World"));
serverConfigWidget.getToolTip() serverConfigWidget.getToolTip()
@ -155,8 +157,31 @@ public class BaseConfigScreen extends ConfigScreen {
new StringTextComponent( new StringTextComponent(
"Gameplay settings can only be accessed from the in-game menu after joining a World or Server."), "Gameplay settings can only be accessed from the in-game menu after joining a World or Server."),
TextFormatting.GRAY, TextFormatting.GRAY)); TextFormatting.GRAY, TextFormatting.GRAY));
} else {
serverConfigWidget.withCallback(() -> linkTo(new SubMenuConfigScreen(this, ModConfig.Type.SERVER, serverSpec)));
serverText.withElementRenderer(BoxWidget.gradientFactory.apply(serverConfigWidget));
} }
TextStencilElement titleText = new TextStencilElement(client.fontRenderer, modID.toUpperCase(Locale.ROOT))
.centered(true, true)
.withElementRenderer((ms, w, h, alpha) -> {
UIRenderHelper.angledGradient(ms, 0, 0, h / 2, h, w / 2, Theme.p(Theme.Key.CONFIG_TITLE_A));
UIRenderHelper.angledGradient(ms, 0, w / 2, h / 2, h, w / 2, Theme.p(Theme.Key.CONFIG_TITLE_B));
});
int boxWidth = width + 10;
int boxHeight = 32;
int boxPadding = 4;
title = new BoxWidget(-5, height / 2 - 110, boxWidth, boxHeight)
//.withCustomBackground(new Color(0x20_000000, true))
.withBorderColors(Theme.p(Theme.Key.BUTTON_IDLE))
.withPadding(0, boxPadding)
.rescaleElement(boxWidth / 2f, (boxHeight - 2 * boxPadding) / 2f)//double the text size by telling it the element is only half as big as the available space
.showingElement(titleText.at(0, 5));
title.active = false;
widgets.add(title);
ConfigScreen.modID = this.modID; ConfigScreen.modID = this.modID;
goBack = new BoxWidget(width / 2 - 134, height / 2, 20, 20).withPadding(2, 2) goBack = new BoxWidget(width / 2 - 134, height / 2, 20, 20).withPadding(2, 2)
@ -168,6 +193,11 @@ public class BaseConfigScreen extends ConfigScreen {
widgets.add(goBack); widgets.add(goBack);
} }
@Override
protected void renderWindow(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
drawCenteredString(ms, client.fontRenderer, "Access Configs for Mod:", width / 2, height / 2 - 110, Theme.i(Theme.Key.TEXT_ACCENT_STRONG));
}
private void linkTo(Screen screen) { private void linkTo(Screen screen) {
returnOnClose = false; returnOnClose = false;
ScreenOpener.open(screen); ScreenOpener.open(screen);

View file

@ -132,6 +132,11 @@ public abstract class ConfigScreen extends AbstractSimiScreen {
return super.mouseScrolled(mouseX, mouseY, delta); return super.mouseScrolled(mouseX, mouseY, delta);
} }
@Override
public boolean isPauseScreen() {
return true;
}
public static String toHumanReadable(String key) { public static String toHumanReadable(String key) {
String s = key.replaceAll("_", " "); String s = key.replaceAll("_", " ");
s = Arrays.stream(StringUtils.splitByCharacterTypeCamelCase(s)).map(StringUtils::capitalize).collect(Collectors.joining(" ")); s = Arrays.stream(StringUtils.splitByCharacterTypeCamelCase(s)).map(StringUtils::capitalize).collect(Collectors.joining(" "));

View file

@ -6,14 +6,19 @@ import java.util.function.Consumer;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GL30; import org.lwjgl.opengl.GL30;
import com.jozufozu.flywheel.backend.Backend;
import com.jozufozu.flywheel.backend.gl.versioned.GlCompat;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.matrix.MatrixStack;
import com.simibubi.create.foundation.gui.widgets.BoxWidget; import com.simibubi.create.foundation.gui.widgets.BoxWidget;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.shader.Framebuffer; import net.minecraft.client.shader.Framebuffer;
import net.minecraft.client.shader.FramebufferConstants;
import net.minecraft.util.text.ITextProperties; import net.minecraft.util.text.ITextProperties;
import net.minecraft.util.text.Style; import net.minecraft.util.text.Style;
@ -198,28 +203,52 @@ public class ConfirmationScreen extends AbstractSimiScreen {
@Override @Override
protected void renderWindowBackground(MatrixStack ms, int mouseX, int mouseY, float partialTicks) { protected void renderWindowBackground(MatrixStack ms, int mouseX, int mouseY, float partialTicks) {
endFrame();
UIRenderHelper.framebuffer.framebufferClear(Minecraft.IS_RUNNING_ON_MAC);
ms.push();
UIRenderHelper.framebuffer.bindFramebuffer(true);
source.render(ms, 0, 0, 10); // zero mouse coords to prevent further tooltips source.render(ms, 0, 0, 10); // zero mouse coords to prevent further tooltips
UIRenderHelper.framebuffer.unbindFramebuffer();
Framebuffer mainBuffer = Minecraft.getInstance().getFramebuffer();
ms.pop();
//fixme replace with glVersioned-backend calls once they are merged from jozu's branch prepareFrame();
GL30.glBindFramebuffer(GL30.GL_READ_FRAMEBUFFER, UIRenderHelper.framebuffer.framebufferObject);
GL30.glBindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, mainBuffer.framebufferObject);
GL30.glBlitFramebuffer(0, 0, mainBuffer.framebufferWidth, mainBuffer.framebufferHeight, 0, 0, mainBuffer.framebufferWidth, mainBuffer.framebufferHeight, GL30.GL_COLOR_BUFFER_BIT, GL30.GL_LINEAR);
mainBuffer.bindFramebuffer(true);
this.fillGradient(ms, 0, 0, this.width, this.height, 0x70101010, 0x80101010); this.fillGradient(ms, 0, 0, this.width, this.height, 0x70101010, 0x80101010);
} }
@Override
protected void prepareFrame() {
Framebuffer thisBuffer = UIRenderHelper.framebuffer;
Framebuffer mainBuffer = Minecraft.getInstance().getFramebuffer();
GlCompat functions = Backend.getInstance().compat;
functions.fbo.bindFramebuffer(GL30.GL_READ_FRAMEBUFFER, mainBuffer.framebufferObject);
functions.fbo.bindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, thisBuffer.framebufferObject);
functions.blit.blitFramebuffer(0, 0, mainBuffer.framebufferWidth, mainBuffer.framebufferHeight, 0, 0, mainBuffer.framebufferWidth, mainBuffer.framebufferHeight, GL30.GL_COLOR_BUFFER_BIT, GL20.GL_LINEAR);
functions.fbo.bindFramebuffer(FramebufferConstants.FRAME_BUFFER, thisBuffer.framebufferObject);
GL11.glClear(GL30.GL_STENCIL_BUFFER_BIT | GL30.GL_DEPTH_BUFFER_BIT);
}
@Override
protected void endFrame() {
Framebuffer thisBuffer = UIRenderHelper.framebuffer;
Framebuffer mainBuffer = Minecraft.getInstance().getFramebuffer();
GlCompat functions = Backend.getInstance().compat;
functions.fbo.bindFramebuffer(GL30.GL_READ_FRAMEBUFFER, thisBuffer.framebufferObject);
functions.fbo.bindFramebuffer(GL30.GL_DRAW_FRAMEBUFFER, mainBuffer.framebufferObject);
functions.blit.blitFramebuffer(0, 0, mainBuffer.framebufferWidth, mainBuffer.framebufferHeight, 0, 0, mainBuffer.framebufferWidth, mainBuffer.framebufferHeight, GL30.GL_COLOR_BUFFER_BIT, GL20.GL_LINEAR);
functions.fbo.bindFramebuffer(FramebufferConstants.FRAME_BUFFER, mainBuffer.framebufferObject);
}
@Override @Override
public void resize(@Nonnull Minecraft client, int width, int height) { public void resize(@Nonnull Minecraft client, int width, int height) {
super.resize(client, width, height); super.resize(client, width, height);
source.resize(client, width, height); source.resize(client, width, height);
} }
@Override
public boolean isPauseScreen() {
return true;
}
} }

View file

@ -90,6 +90,8 @@ public class Theme {
put(Key.PONDER_PROGRESSBAR, new Color(0x80ffeedd, true), new Color(0x50ffeedd, true)); put(Key.PONDER_PROGRESSBAR, new Color(0x80ffeedd, true), new Color(0x50ffeedd, true));
put(Key.PONDER_MISSING_CREATE, new Color(0x70_984500, true), new Color(0x70_692400, true)); put(Key.PONDER_MISSING_CREATE, new Color(0x70_984500, true), new Color(0x70_692400, true));
put(Key.PONDER_MISSING_VANILLA, new Color(0x50_5000ff, true), new Color(0x50_300077, true)); put(Key.PONDER_MISSING_VANILLA, new Color(0x50_5000ff, true), new Color(0x50_300077, true));
put(Key.CONFIG_TITLE_A, new Color(0xffc69fbc, true), new Color(0xfff6b8bb, true));
put(Key.CONFIG_TITLE_B, new Color(0xfff6b8bb, true), new Color(0xfffbf994, true));
//put(Key., new Color(0x, true), new Color(0x, true)); //put(Key., new Color(0x, true), new Color(0x, true));
} }
@ -145,6 +147,9 @@ public class Theme {
public static Key PONDER_BUTTON_CLICK = new Key(); public static Key PONDER_BUTTON_CLICK = new Key();
public static Key PONDER_BUTTON_DISABLE = new Key(); public static Key PONDER_BUTTON_DISABLE = new Key();
public static Key CONFIG_TITLE_A = new Key();
public static Key CONFIG_TITLE_B = new Key();
private static int index = 0; private static int index = 0;
private final String s; private final String s;

View file

@ -23,6 +23,7 @@ public class BoxWidget extends ElementWidget {
protected Color customBorderTop; protected Color customBorderTop;
protected Color customBorderBot; protected Color customBorderBot;
protected Color customBackground;
protected boolean animateColors = true; protected boolean animateColors = true;
protected LerpedFloat colorAnimation = LerpedFloat.linear(); protected LerpedFloat colorAnimation = LerpedFloat.linear();
@ -71,6 +72,12 @@ public class BoxWidget extends ElementWidget {
return (T) this; return (T) this;
} }
public <T extends BoxWidget> T withCustomBackground(Color color) {
this.customBackground = color;
//noinspection unchecked
return (T) this;
}
public <T extends BoxWidget> T animateColors(boolean b) { public <T extends BoxWidget> T animateColors(boolean b) {
this.animateColors = b; this.animateColors = b;
//noinspection unchecked //noinspection unchecked
@ -122,7 +129,7 @@ public class BoxWidget extends ElementWidget {
return; return;
box.withAlpha(fadeValue); box.withAlpha(fadeValue);
box.withBackground(Theme.c(Theme.Key.PONDER_BACKGROUND_TRANSPARENT)) box.withBackground(customBackground != null ? customBackground : Theme.c(Theme.Key.PONDER_BACKGROUND_TRANSPARENT))
.gradientBorder(gradientColor1, gradientColor2) .gradientBorder(gradientColor1, gradientColor2)
.at(x, y, z) .at(x, y, z)
.withBounds(width, height) .withBounds(width, height)

View file

@ -91,6 +91,12 @@ public class ElementWidget extends AbstractSimiWidget {
return (T) this; return (T) this;
} }
/**
* Rescaling and its effects aren't properly tested with most elements.
* Thought it should work fine when using a TextStencilElement.
* Check BaseConfigScreen's title for such an example.
*/
@Deprecated
public <T extends ElementWidget> T rescaleElement(float rescaleSizeX, float rescaleSizeY) { public <T extends ElementWidget> T rescaleElement(float rescaleSizeX, float rescaleSizeY) {
this.rescaleElement = true; this.rescaleElement = true;
this.rescaleSizeX = rescaleSizeX; this.rescaleSizeX = rescaleSizeX;
@ -128,14 +134,20 @@ public class ElementWidget extends AbstractSimiWidget {
ms.translate(x + paddingX, y + paddingY, z); ms.translate(x + paddingX, y + paddingY, z);
float innerWidth = width - 2 * paddingX; float innerWidth = width - 2 * paddingX;
float innerHeight = height - 2 * paddingY; float innerHeight = height - 2 * paddingY;
float eX = element.getX(), eY = element.getY();
if (rescaleElement) { if (rescaleElement) {
float xScale = innerWidth / rescaleSizeX; float xScale = innerWidth / rescaleSizeX;
float yScale = innerHeight / rescaleSizeY; float yScale = innerHeight / rescaleSizeY;
ms.scale(xScale, yScale, 1); ms.scale(xScale, yScale, 1);
element.at(element.getX() / xScale, element.getY() / yScale); element.at(eX / xScale, eY / yScale);
innerWidth /= xScale;
innerHeight /= yScale;
} }
element.withBounds((int) innerWidth, (int) innerHeight).render(ms); element.withBounds((int) innerWidth, (int) innerHeight).render(ms);
ms.pop(); ms.pop();
if (rescaleElement) {
element.at(eX, eY);
}
} }
public RenderElement getRenderElement() { public RenderElement getRenderElement() {