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 bf56960eb..475ac2db8 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 @@ -8,6 +8,7 @@ import java.util.stream.Collectors; import javax.annotation.Nonnull; import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.util.TriConsumer; import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL20; import org.lwjgl.opengl.GL30; @@ -15,12 +16,15 @@ 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.platform.GlStateManager; +import com.mojang.blaze3d.systems.RenderSystem; import com.simibubi.create.AllBlocks; import com.simibubi.create.content.contraptions.relays.elementary.CogWheelBlock; import com.simibubi.create.foundation.gui.AbstractSimiScreen; import com.simibubi.create.foundation.gui.GuiGameElement; import com.simibubi.create.foundation.gui.StencilElement; import com.simibubi.create.foundation.gui.UIRenderHelper; +import com.simibubi.create.foundation.gui.mainMenu.CreateMainMenuScreen; import com.simibubi.create.foundation.utility.animation.Force; import com.simibubi.create.foundation.utility.animation.PhysicalFloat; @@ -47,7 +51,8 @@ public abstract class ConfigScreen extends AbstractSimiScreen { * * */ - public static final PhysicalFloat cogSpin = PhysicalFloat.create().withDrag(0.3).addForce(new Force.Static(.2f)); + public static final Map> backgrounds = new HashMap<>(); + public static final PhysicalFloat cogSpin = PhysicalFloat.create().withLimit(10f).withDrag(0.3).addForce(new Force.Static(.2f)); public static final BlockState cogwheelState = AllBlocks.LARGE_COGWHEEL.getDefaultState().with(CogWheelBlock.AXIS, Direction.Axis.Y); public static final Map changes = new HashMap<>(); public static String modID = null; @@ -71,9 +76,11 @@ public abstract class ConfigScreen extends AbstractSimiScreen { @Override protected void renderWindowBackground(MatrixStack ms, int mouseX, int mouseY, float partialTicks) { if (this.client != null && this.client.world != null) { + //in game fill(ms, 0, 0, this.width, this.height, 0xb0_282c34); } else { - fill(ms, 0, 0, this.width, this.height, 0xff_282c34); + //in menus + renderMenuBackground(ms, partialTicks); } new StencilElement() { @@ -144,6 +151,30 @@ public abstract class ConfigScreen extends AbstractSimiScreen { return s; } + /** + * By default ConfigScreens will render the Create Panorama as + * their background when opened from the Main- or ModList-Menu. + * If your addon wants to render something else, please add to the + * backgrounds Map in this Class with your modID as the key. + */ + protected void renderMenuBackground(MatrixStack ms, float partialTicks) { + TriConsumer customBackground = backgrounds.get(modID); + if (customBackground != null) { + customBackground.accept(this, ms, partialTicks); + return; + } + + float elapsedPartials = client.getTickLength(); + CreateMainMenuScreen.panorama.render(elapsedPartials, 1); + + client.getTextureManager().bindTexture(CreateMainMenuScreen.PANORAMA_OVERLAY_TEXTURES); + RenderSystem.enableBlend(); + RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); + drawTexture(ms, 0, 0, this.width, this.height, 0.0F, 0.0F, 16, 128, 16, 128); + + fill(ms, 0, 0, this.width, this.height, 0x90_282c34); + } + protected void renderCog(MatrixStack ms, float partialTicks) { ms.push(); diff --git a/src/main/java/com/simibubi/create/foundation/config/ui/entries/EnumEntry.java b/src/main/java/com/simibubi/create/foundation/config/ui/entries/EnumEntry.java index 3d7590762..da4f56137 100644 --- a/src/main/java/com/simibubi/create/foundation/config/ui/entries/EnumEntry.java +++ b/src/main/java/com/simibubi/create/foundation/config/ui/entries/EnumEntry.java @@ -30,13 +30,17 @@ public class EnumEntry extends ValueEntry> { height, width, Theme.p(Theme.Key.TEXT))); DelegatedStencilElement l = AllIcons.I_CONFIG_PREV.asStencil(); - cycleLeft = new BoxWidget(0, 0, cycleWidth + 8, 16).showingElement(l) - .withCallback(() -> cycleValue(-1)); + cycleLeft = new BoxWidget(0, 0, cycleWidth + 8, 16) + .withCustomBackground(Theme.c(Theme.Key.PONDER_BACKGROUND_FLAT)) + .showingElement(l) + .withCallback(() -> cycleValue(-1)); l.withElementRenderer(BoxWidget.gradientFactory.apply(cycleLeft)); DelegatedStencilElement r = AllIcons.I_CONFIG_NEXT.asStencil(); - cycleRight = new BoxWidget(0, 0, cycleWidth + 8, 16).showingElement(r) - .withCallback(() -> cycleValue(1)); + cycleRight = new BoxWidget(0, 0, cycleWidth + 8, 16) + .withCustomBackground(Theme.c(Theme.Key.PONDER_BACKGROUND_FLAT)) + .showingElement(r) + .withCallback(() -> cycleValue(1)); r.at(cycleWidth - 8, 0); r.withElementRenderer(BoxWidget.gradientFactory.apply(cycleRight)); @@ -89,10 +93,10 @@ public class EnumEntry extends ValueEntry> { cycleRight.render(ms, mouseX, mouseY, partialTicks); new BoxElement() - .withBackground(0) - .flatBorder(0) - .withBounds(10, 10) - .at(cycleLeft.x + cycleWidth + 4, cycleLeft.y + 3) + .withBackground(Theme.c(Theme.Key.PONDER_BACKGROUND_FLAT)) + .flatBorder(0x01_000000) + .withBounds(48, 6) + .at(cycleLeft.x + 22, cycleLeft.y + 5) .render(ms); } diff --git a/src/main/java/com/simibubi/create/foundation/gui/mainMenu/CreateMainMenuScreen.java b/src/main/java/com/simibubi/create/foundation/gui/mainMenu/CreateMainMenuScreen.java index 2731dfa4f..36e1ab619 100644 --- a/src/main/java/com/simibubi/create/foundation/gui/mainMenu/CreateMainMenuScreen.java +++ b/src/main/java/com/simibubi/create/foundation/gui/mainMenu/CreateMainMenuScreen.java @@ -37,12 +37,12 @@ public class CreateMainMenuScreen extends AbstractSimiScreen { protected final Screen parent; protected boolean returnOnClose; - private static final RenderSkyboxCube PANORAMA_RESOURCES = + public static final RenderSkyboxCube PANORAMA_RESOURCES = new RenderSkyboxCube(Create.asResource("textures/gui/title/background/panorama")); - private static final ResourceLocation PANORAMA_OVERLAY_TEXTURES = + public static final ResourceLocation PANORAMA_OVERLAY_TEXTURES = new ResourceLocation("textures/gui/title/background/panorama_overlay.png"); private RenderSkybox vanillaPanorama = new RenderSkybox(MainMenuScreen.PANORAMA_RESOURCES); - private RenderSkybox panorama = new RenderSkybox(PANORAMA_RESOURCES); + public static RenderSkybox panorama = new RenderSkybox(PANORAMA_RESOURCES); private long firstRenderTime; private Button gettingStarted; @@ -65,11 +65,12 @@ public class CreateMainMenuScreen extends AbstractSimiScreen { protected void renderWindow(MatrixStack ms, int mouseX, int mouseY, float partialTicks) { float f = (float) (Util.milliTime() - this.firstRenderTime) / 1000.0F; float alpha = MathHelper.clamp(f, 0.0F, 1.0F); + float elapsedPartials = client.getTickLength(); if (parent instanceof MainMenuScreen) { if (alpha < 1) - vanillaPanorama.render(partialTicks, 1); - panorama.render(partialTicks, alpha); + vanillaPanorama.render(elapsedPartials, 1); + panorama.render(elapsedPartials, alpha); client.getTextureManager() .bindTexture(PANORAMA_OVERLAY_TEXTURES); diff --git a/src/main/java/com/simibubi/create/foundation/utility/animation/PhysicalFloat.java b/src/main/java/com/simibubi/create/foundation/utility/animation/PhysicalFloat.java index d56f8e35f..26ae9a246 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/animation/PhysicalFloat.java +++ b/src/main/java/com/simibubi/create/foundation/utility/animation/PhysicalFloat.java @@ -11,6 +11,7 @@ public class PhysicalFloat { float previousSpeed; float speed; + float limit = Float.NaN; float mass; @@ -41,6 +42,11 @@ public class PhysicalFloat { return addForce(new Force.Zeroing((float) g)); } + public PhysicalFloat withLimit(float limit) { + this.limit = limit; + return this; + } + public void tick() { previousSpeed = speed; previousValue = value; @@ -53,6 +59,10 @@ public class PhysicalFloat { forces.removeIf(Force::finished); + if (Float.isFinite(limit)) { + speed = MathHelper.clamp(speed, -limit, limit); + } + value += speed; }