From fd3d7bd7fd6d0c5d4380036eb852076305b9ed1b Mon Sep 17 00:00:00 2001 From: simibubi <31564874+simibubi@users.noreply.github.com> Date: Wed, 10 Feb 2021 16:40:30 +0100 Subject: [PATCH] Refined animations, key input --- .../foundation/metadoc/MetaDocScene.java | 7 +- .../foundation/metadoc/MetaDocScreen.java | 82 ++++++++++++++++--- .../foundation/metadoc/MetaDocWorld.java | 20 ++++- .../metadoc/WorldSectionElement.java | 15 ++-- .../instructions/HideAllInstruction.java | 3 +- .../metadoc/stories/CogwheelStory.java | 2 +- 6 files changed, 104 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/metadoc/MetaDocScene.java b/src/main/java/com/simibubi/create/foundation/metadoc/MetaDocScene.java index cc17692af..7642c1927 100644 --- a/src/main/java/com/simibubi/create/foundation/metadoc/MetaDocScene.java +++ b/src/main/java/com/simibubi/create/foundation/metadoc/MetaDocScene.java @@ -42,12 +42,13 @@ public class MetaDocScene { public void begin() { reset(); + elements.clear(); activeSchedule.addAll(schedule); } public void fadeOut() { reset(); - activeSchedule.add(new HideAllInstruction(10, Direction.DOWN)); + activeSchedule.add(new HideAllInstruction(10, null)); } public void render(IRenderTypeBuffer buffer, MatrixStack ms) { @@ -103,11 +104,11 @@ public class MetaDocScene { public SceneBuilder showSection(BlockPos origin, Vec3i size, Direction fadeInDirection) { return addInstruction( - new DisplayWorldSectionInstruction(20, fadeInDirection, new WorldSectionElement.Cuboid(origin, size))); + new DisplayWorldSectionInstruction(15, fadeInDirection, new WorldSectionElement.Cuboid(origin, size))); } public SceneBuilder showSection(WorldSectionElement element, Direction fadeInDirection) { - return addInstruction(new DisplayWorldSectionInstruction(20, fadeInDirection, element)); + return addInstruction(new DisplayWorldSectionInstruction(15, fadeInDirection, element)); } public SceneBuilder debugSchematic() { diff --git a/src/main/java/com/simibubi/create/foundation/metadoc/MetaDocScreen.java b/src/main/java/com/simibubi/create/foundation/metadoc/MetaDocScreen.java index faccdf6f1..3f0f7ae8b 100644 --- a/src/main/java/com/simibubi/create/foundation/metadoc/MetaDocScreen.java +++ b/src/main/java/com/simibubi/create/foundation/metadoc/MetaDocScreen.java @@ -11,6 +11,8 @@ import com.simibubi.create.foundation.utility.LerpedFloat; import com.simibubi.create.foundation.utility.LerpedFloat.Chaser; import com.simibubi.create.foundation.utility.MatrixStacker; +import net.minecraft.client.GameSettings; +import net.minecraft.client.Minecraft; import net.minecraft.util.math.MathHelper; import net.minecraftforge.fml.client.gui.GuiUtils; @@ -28,7 +30,7 @@ public class MetaDocScreen extends AbstractSimiScreen { .startWithValue(index); fadeIn = LerpedFloat.linear() .startWithValue(0) - .chase(1, .5f, Chaser.EXP); + .chase(1, .1f, Chaser.EXP); } @Override @@ -45,23 +47,32 @@ public class MetaDocScreen extends AbstractSimiScreen { @Override public boolean mouseScrolled(double mouseX, double mouseY, double delta) { + if (scroll(delta > 0)) + return true; + return super.mouseScrolled(mouseX, mouseY, delta); + } + + protected boolean scroll(boolean forward) { int prevIndex = index; - index = delta > 0 ? index + 1 : index - 1; + index = forward ? index + 1 : index - 1; index = MathHelper.clamp(index, 0, stories.size() - 1); - if (prevIndex != index && Math.abs(index - lazyIndex.getValue()) < 1.25f) { + if (prevIndex != index && Math.abs(index - lazyIndex.getValue()) < 1.5f) { stories.get(prevIndex) .fadeOut(); stories.get(index) .begin(); lazyIndex.chase(index, 1 / 4f, Chaser.EXP); return true; - } else + } else index = prevIndex; - return super.mouseScrolled(mouseX, mouseY, delta); + return false; } @Override protected void renderWindow(int mouseX, int mouseY, float partialTicks) { + partialTicks = Minecraft.getInstance() + .getRenderPartialTicks(); + RenderSystem.enableBlend(); renderStories(partialTicks); renderWidgets(mouseX, mouseY, partialTicks); @@ -78,16 +89,15 @@ public class MetaDocScreen extends AbstractSimiScreen { MetaDocScene story = stories.get(i); MatrixStack ms = new MatrixStack(); ms.push(); - ms.translate(width / 2, height / 2, 200); MatrixStacker.of(ms) .rotateX(-45) .rotateY(45); - float value = lazyIndex.getValue(partialTicks); - float diff = i - value; - float slide = i == index ? 400 : MathHelper.lerp(Math.abs(diff), 0, 400); + double value = lazyIndex.getValue(partialTicks); + double diff = i - value; + double slide = MathHelper.lerp(diff * diff, 200, 600); ms.translate(diff * slide, 0, 0); ms.scale(30, -30, 30); @@ -106,16 +116,14 @@ public class MetaDocScreen extends AbstractSimiScreen { RenderSystem.pushMatrix(); - if (fade < 1) + if (fade < fadeIn.getChaseTarget()) RenderSystem.translated(0, (1 - fade) * 5, 0); int closeWidth = 24; int closeHeight = 24; int closeX = (width - closeWidth) / 2; int closeY = height - closeHeight - 31; - - boolean hovered = !(mouseX < closeX || mouseX > closeX + closeWidth); - hovered &= !(mouseY < closeY || mouseY > closeY + closeHeight); + boolean hovered = isMouseOver(mouseX, mouseY, closeX, closeY, closeWidth, closeHeight); renderBox(closeX, closeY, closeWidth, closeHeight, 0xdd000000, hovered ? 0x70ffffff : 0x30eebb00, hovered ? 0x30ffffff : 0x10eebb00); @@ -124,6 +132,54 @@ public class MetaDocScreen extends AbstractSimiScreen { RenderSystem.popMatrix(); } + @Override + public boolean mouseClicked(double x, double y, int button) { + int closeWidth = 24; + int closeHeight = 24; + int closeX = (width - closeWidth) / 2; + int closeY = height - closeHeight - 31; + if (isMouseOver(x, y, closeX, closeY, closeWidth, closeHeight)) { + onClose(); + return true; + } + + return super.mouseClicked(x, y, button); + } + + @Override + public boolean keyPressed(int code, int p_keyPressed_2_, int p_keyPressed_3_) { + GameSettings settings = Minecraft.getInstance().gameSettings; + int sCode = settings.keyBindBack.getKey() + .getKeyCode(); + int aCode = settings.keyBindLeft.getKey() + .getKeyCode(); + int dCode = settings.keyBindRight.getKey() + .getKeyCode(); + + if (code == sCode) { + onClose(); + return true; + } + + if (code == aCode) { + scroll(false); + return true; + } + + if (code == dCode) { + scroll(true); + return true; + } + + return super.keyPressed(code, p_keyPressed_2_, p_keyPressed_3_); + } + + protected boolean isMouseOver(double mouseX, double mouseY, int x, int y, int w, int h) { + boolean hovered = !(mouseX < x || mouseX > x + w); + hovered &= !(mouseY < y || mouseY > y + h); + return hovered; + } + protected void renderBox(int tooltipX, int tooltipY, int tooltipTextWidth, int tooltipHeight, int backgroundColor, int borderColorStart, int borderColorEnd) { int zLevel = 400; diff --git a/src/main/java/com/simibubi/create/foundation/metadoc/MetaDocWorld.java b/src/main/java/com/simibubi/create/foundation/metadoc/MetaDocWorld.java index 5307ba49c..a4388670d 100644 --- a/src/main/java/com/simibubi/create/foundation/metadoc/MetaDocWorld.java +++ b/src/main/java/com/simibubi/create/foundation/metadoc/MetaDocWorld.java @@ -2,6 +2,8 @@ package com.simibubi.create.foundation.metadoc; import com.simibubi.create.content.schematics.SchematicWorld; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; import net.minecraft.util.math.BlockPos; import net.minecraft.world.LightType; import net.minecraft.world.World; @@ -9,6 +11,7 @@ import net.minecraft.world.World; public class MetaDocWorld extends SchematicWorld { int overrideLight; + WorldSectionElement mask; public MetaDocWorld(BlockPos anchor, World original) { super(anchor, original); @@ -24,7 +27,22 @@ public class MetaDocWorld extends SchematicWorld { @Override public int getLightLevel(LightType p_226658_1_, BlockPos p_226658_2_) { - return overrideLight == -1 ? super.getLightLevel(p_226658_1_, p_226658_2_) : overrideLight; + return overrideLight == -1 ? 15 : overrideLight; + } + + public void setMask(WorldSectionElement mask) { + this.mask = mask; + } + + public void clearMask() { + this.mask = null; + } + + @Override + public BlockState getBlockState(BlockPos globalPos) { + if (mask != null && !mask.test(globalPos.subtract(anchor))) + return Blocks.AIR.getDefaultState(); + return super.getBlockState(globalPos); } } diff --git a/src/main/java/com/simibubi/create/foundation/metadoc/WorldSectionElement.java b/src/main/java/com/simibubi/create/foundation/metadoc/WorldSectionElement.java index 274551085..d1260037f 100644 --- a/src/main/java/com/simibubi/create/foundation/metadoc/WorldSectionElement.java +++ b/src/main/java/com/simibubi/create/foundation/metadoc/WorldSectionElement.java @@ -31,6 +31,7 @@ import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MutableBoundingBox; import net.minecraft.util.math.Vec3i; import net.minecraftforge.client.ForgeHooksClient; @@ -45,13 +46,13 @@ public abstract class WorldSectionElement extends AnimatedSceneElement implement @Override public void render(MetaDocWorld world, IRenderTypeBuffer buffer, MatrixStack ms, float fade) { int light = -1; - if (fade != 1) - light = (int) (0xF * fade); - + if (fade != 1) + light = (int) (MathHelper.lerp(fade, 5, 14)); + world.pushFakeLight(light); renderTileEntities(world, ms, buffer); world.popLight(); - + if (buffer instanceof IRenderTypeBuffer.Impl) ((IRenderTypeBuffer.Impl) buffer).draw(); renderStructure(world, ms, buffer, fade); @@ -104,13 +105,13 @@ public abstract class WorldSectionElement extends AnimatedSceneElement implement bufferCache.get(DOC_WORLD_SECTION, key, () -> buildStructureBuffer(world, layer)); if (contraptionBuffer.isEmpty()) continue; - + int light = 0xF000F0; if (fade != 1) { light = (int) (0xF * fade); light = light << 4 | light << 20; } - + contraptionBuffer.light(light) .renderInto(ms, buffer.getBuffer(layer)); } @@ -136,6 +137,7 @@ public abstract class WorldSectionElement extends AnimatedSceneElement implement Random random = new Random(); BufferBuilder builder = new BufferBuilder(DefaultVertexFormats.BLOCK.getIntegerSize()); builder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); + world.setMask(this); all().forEach(pos -> { BlockState state = world.getBlockState(pos); @@ -152,6 +154,7 @@ public abstract class WorldSectionElement extends AnimatedSceneElement implement ms.pop(); }); + world.clearMask(); builder.finishDrawing(); return new SuperByteBuffer(builder); } diff --git a/src/main/java/com/simibubi/create/foundation/metadoc/instructions/HideAllInstruction.java b/src/main/java/com/simibubi/create/foundation/metadoc/instructions/HideAllInstruction.java index 46d8a2833..678f83772 100644 --- a/src/main/java/com/simibubi/create/foundation/metadoc/instructions/HideAllInstruction.java +++ b/src/main/java/com/simibubi/create/foundation/metadoc/instructions/HideAllInstruction.java @@ -23,7 +23,8 @@ public class HideAllInstruction extends TickingInstruction { if (element instanceof AnimatedSceneElement) { AnimatedSceneElement animatedSceneElement = (AnimatedSceneElement) element; animatedSceneElement.setFade(1); - animatedSceneElement.setFadeVec(new Vec3d(fadeOutTo.getDirectionVec()).scale(.5f)); + animatedSceneElement + .setFadeVec(fadeOutTo == null ? null : new Vec3d(fadeOutTo.getDirectionVec()).scale(.5f)); } else element.setVisible(false); }); diff --git a/src/main/java/com/simibubi/create/foundation/metadoc/stories/CogwheelStory.java b/src/main/java/com/simibubi/create/foundation/metadoc/stories/CogwheelStory.java index f640b6cb5..b5bcdad87 100644 --- a/src/main/java/com/simibubi/create/foundation/metadoc/stories/CogwheelStory.java +++ b/src/main/java/com/simibubi/create/foundation/metadoc/stories/CogwheelStory.java @@ -23,7 +23,7 @@ public class CogwheelStory extends MetaDocStoryBoard { @Override public void program(SceneBuilder scene, Vec3i worldSize) { scene.showBasePlate() - .idle(5) + .idle(10) .showSection(BlockPos.ZERO.up(), worldSize, Direction.DOWN); }