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 01119459e..88bb08595 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 @@ -1,8 +1,11 @@ package com.simibubi.create.foundation.config.ui; +import java.util.Locale; + import javax.annotation.Nonnull; import javax.annotation.Nullable; +import com.mojang.blaze3d.matrix.MatrixStack; import com.simibubi.create.Create; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.gui.AllIcons; @@ -35,6 +38,7 @@ public class BaseConfigScreen extends ConfigScreen { BoxWidget commonConfigWidget; BoxWidget serverConfigWidget; BoxWidget goBack; + BoxWidget title; ForgeConfigSpec clientSpec; ForgeConfigSpec commonSpec; @@ -140,14 +144,12 @@ public class BaseConfigScreen extends ConfigScreen { 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)); - if (serverSpec != null && Minecraft.getInstance().world != null) { - serverConfigWidget.withCallback(() -> linkTo(new SubMenuConfigScreen(this, ModConfig.Type.SERVER, serverSpec))); - serverText.withElementRenderer(BoxWidget.gradientFactory.apply(serverConfigWidget)); - } else { + if (serverSpec == null) { serverConfigWidget.active = false; serverConfigWidget.updateColorsFromState(); serverText.withElementRenderer(DISABLED_RENDERER); - serverConfigWidget.active = true; + } else if (Minecraft.getInstance().world == null) { + serverText.withElementRenderer(DISABLED_RENDERER); serverConfigWidget.getToolTip() .add(new StringTextComponent("Stored individually per World")); serverConfigWidget.getToolTip() @@ -155,8 +157,31 @@ public class BaseConfigScreen extends ConfigScreen { new StringTextComponent( "Gameplay settings can only be accessed from the in-game menu after joining a World or Server."), 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; 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); } + @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) { returnOnClose = false; ScreenOpener.open(screen); diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreen.java b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreen.java index 6bcbc4880..bf56960eb 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreen.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/ConfigScreen.java @@ -132,6 +132,11 @@ public abstract class ConfigScreen extends AbstractSimiScreen { return super.mouseScrolled(mouseX, mouseY, delta); } + @Override + public boolean isPauseScreen() { + return true; + } + public static String toHumanReadable(String key) { String s = key.replaceAll("_", " "); s = Arrays.stream(StringUtils.splitByCharacterTypeCamelCase(s)).map(StringUtils::capitalize).collect(Collectors.joining(" ")); diff --git a/src/main/java/com/simibubi/create/foundation/gui/ConfirmationScreen.java b/src/main/java/com/simibubi/create/foundation/gui/ConfirmationScreen.java index f0de70016..7dcfd715b 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/ConfirmationScreen.java +++ b/src/main/java/com/simibubi/create/foundation/gui/ConfirmationScreen.java @@ -6,14 +6,19 @@ import java.util.function.Consumer; import javax.annotation.Nonnull; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL20; 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.simibubi.create.foundation.gui.widgets.BoxWidget; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.shader.Framebuffer; +import net.minecraft.client.shader.FramebufferConstants; import net.minecraft.util.text.ITextProperties; import net.minecraft.util.text.Style; @@ -198,28 +203,52 @@ public class ConfirmationScreen extends AbstractSimiScreen { @Override 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 - UIRenderHelper.framebuffer.unbindFramebuffer(); - Framebuffer mainBuffer = Minecraft.getInstance().getFramebuffer(); - ms.pop(); - //fixme replace with glVersioned-backend calls once they are merged from jozu's branch - 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); + prepareFrame(); 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 public void resize(@Nonnull Minecraft client, int width, int height) { super.resize(client, width, height); source.resize(client, width, height); } + + @Override + public boolean isPauseScreen() { + return true; + } } diff --git a/src/main/java/com/simibubi/create/foundation/gui/Theme.java b/src/main/java/com/simibubi/create/foundation/gui/Theme.java index 83e218945..44a53e100 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/Theme.java +++ b/src/main/java/com/simibubi/create/foundation/gui/Theme.java @@ -90,6 +90,8 @@ public class Theme { 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_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)); } @@ -145,6 +147,9 @@ public class Theme { public static Key PONDER_BUTTON_CLICK = 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 final String s; diff --git a/src/main/java/com/simibubi/create/foundation/gui/widgets/BoxWidget.java b/src/main/java/com/simibubi/create/foundation/gui/widgets/BoxWidget.java index 672f48b8d..2e5cac63e 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/widgets/BoxWidget.java +++ b/src/main/java/com/simibubi/create/foundation/gui/widgets/BoxWidget.java @@ -23,6 +23,7 @@ public class BoxWidget extends ElementWidget { protected Color customBorderTop; protected Color customBorderBot; + protected Color customBackground; protected boolean animateColors = true; protected LerpedFloat colorAnimation = LerpedFloat.linear(); @@ -71,6 +72,12 @@ public class BoxWidget extends ElementWidget { return (T) this; } + public T withCustomBackground(Color color) { + this.customBackground = color; + //noinspection unchecked + return (T) this; + } + public T animateColors(boolean b) { this.animateColors = b; //noinspection unchecked @@ -122,7 +129,7 @@ public class BoxWidget extends ElementWidget { return; 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) .at(x, y, z) .withBounds(width, height) diff --git a/src/main/java/com/simibubi/create/foundation/gui/widgets/ElementWidget.java b/src/main/java/com/simibubi/create/foundation/gui/widgets/ElementWidget.java index 499e81587..bc782e26f 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/widgets/ElementWidget.java +++ b/src/main/java/com/simibubi/create/foundation/gui/widgets/ElementWidget.java @@ -33,7 +33,7 @@ public class ElementWidget extends AbstractSimiWidget { public ElementWidget(int x, int y, int width, int height) { super(x, y, width, height); } - + public T showingElement(RenderElement element) { this.element = element; //noinspection unchecked @@ -91,6 +91,12 @@ public class ElementWidget extends AbstractSimiWidget { 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 rescaleElement(float rescaleSizeX, float rescaleSizeY) { this.rescaleElement = true; this.rescaleSizeX = rescaleSizeX; @@ -128,14 +134,20 @@ public class ElementWidget extends AbstractSimiWidget { ms.translate(x + paddingX, y + paddingY, z); float innerWidth = width - 2 * paddingX; float innerHeight = height - 2 * paddingY; + float eX = element.getX(), eY = element.getY(); if (rescaleElement) { float xScale = innerWidth / rescaleSizeX; float yScale = innerHeight / rescaleSizeY; 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); ms.pop(); + if (rescaleElement) { + element.at(eX, eY); + } } public RenderElement getRenderElement() {