Refined animations, key input

This commit is contained in:
simibubi 2021-02-10 16:40:30 +01:00
parent e178cab4a8
commit fd3d7bd7fd
6 changed files with 104 additions and 25 deletions

View file

@ -42,12 +42,13 @@ public class MetaDocScene {
public void begin() { public void begin() {
reset(); reset();
elements.clear();
activeSchedule.addAll(schedule); activeSchedule.addAll(schedule);
} }
public void fadeOut() { public void fadeOut() {
reset(); reset();
activeSchedule.add(new HideAllInstruction(10, Direction.DOWN)); activeSchedule.add(new HideAllInstruction(10, null));
} }
public void render(IRenderTypeBuffer buffer, MatrixStack ms) { public void render(IRenderTypeBuffer buffer, MatrixStack ms) {
@ -103,11 +104,11 @@ public class MetaDocScene {
public SceneBuilder showSection(BlockPos origin, Vec3i size, Direction fadeInDirection) { public SceneBuilder showSection(BlockPos origin, Vec3i size, Direction fadeInDirection) {
return addInstruction( 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) { public SceneBuilder showSection(WorldSectionElement element, Direction fadeInDirection) {
return addInstruction(new DisplayWorldSectionInstruction(20, fadeInDirection, element)); return addInstruction(new DisplayWorldSectionInstruction(15, fadeInDirection, element));
} }
public SceneBuilder debugSchematic() { public SceneBuilder debugSchematic() {

View file

@ -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.LerpedFloat.Chaser;
import com.simibubi.create.foundation.utility.MatrixStacker; 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.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.client.gui.GuiUtils; import net.minecraftforge.fml.client.gui.GuiUtils;
@ -28,7 +30,7 @@ public class MetaDocScreen extends AbstractSimiScreen {
.startWithValue(index); .startWithValue(index);
fadeIn = LerpedFloat.linear() fadeIn = LerpedFloat.linear()
.startWithValue(0) .startWithValue(0)
.chase(1, .5f, Chaser.EXP); .chase(1, .1f, Chaser.EXP);
} }
@Override @Override
@ -45,10 +47,16 @@ public class MetaDocScreen extends AbstractSimiScreen {
@Override @Override
public boolean mouseScrolled(double mouseX, double mouseY, double delta) { 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; int prevIndex = index;
index = delta > 0 ? index + 1 : index - 1; index = forward ? index + 1 : index - 1;
index = MathHelper.clamp(index, 0, stories.size() - 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) stories.get(prevIndex)
.fadeOut(); .fadeOut();
stories.get(index) stories.get(index)
@ -57,11 +65,14 @@ public class MetaDocScreen extends AbstractSimiScreen {
return true; return true;
} else } else
index = prevIndex; index = prevIndex;
return super.mouseScrolled(mouseX, mouseY, delta); return false;
} }
@Override @Override
protected void renderWindow(int mouseX, int mouseY, float partialTicks) { protected void renderWindow(int mouseX, int mouseY, float partialTicks) {
partialTicks = Minecraft.getInstance()
.getRenderPartialTicks();
RenderSystem.enableBlend(); RenderSystem.enableBlend();
renderStories(partialTicks); renderStories(partialTicks);
renderWidgets(mouseX, mouseY, partialTicks); renderWidgets(mouseX, mouseY, partialTicks);
@ -79,15 +90,14 @@ public class MetaDocScreen extends AbstractSimiScreen {
MatrixStack ms = new MatrixStack(); MatrixStack ms = new MatrixStack();
ms.push(); ms.push();
ms.translate(width / 2, height / 2, 200); ms.translate(width / 2, height / 2, 200);
MatrixStacker.of(ms) MatrixStacker.of(ms)
.rotateX(-45) .rotateX(-45)
.rotateY(45); .rotateY(45);
float value = lazyIndex.getValue(partialTicks); double value = lazyIndex.getValue(partialTicks);
float diff = i - value; double diff = i - value;
float slide = i == index ? 400 : MathHelper.lerp(Math.abs(diff), 0, 400); double slide = MathHelper.lerp(diff * diff, 200, 600);
ms.translate(diff * slide, 0, 0); ms.translate(diff * slide, 0, 0);
ms.scale(30, -30, 30); ms.scale(30, -30, 30);
@ -106,16 +116,14 @@ public class MetaDocScreen extends AbstractSimiScreen {
RenderSystem.pushMatrix(); RenderSystem.pushMatrix();
if (fade < 1) if (fade < fadeIn.getChaseTarget())
RenderSystem.translated(0, (1 - fade) * 5, 0); RenderSystem.translated(0, (1 - fade) * 5, 0);
int closeWidth = 24; int closeWidth = 24;
int closeHeight = 24; int closeHeight = 24;
int closeX = (width - closeWidth) / 2; int closeX = (width - closeWidth) / 2;
int closeY = height - closeHeight - 31; int closeY = height - closeHeight - 31;
boolean hovered = isMouseOver(mouseX, mouseY, closeX, closeY, closeWidth, closeHeight);
boolean hovered = !(mouseX < closeX || mouseX > closeX + closeWidth);
hovered &= !(mouseY < closeY || mouseY > closeY + closeHeight);
renderBox(closeX, closeY, closeWidth, closeHeight, 0xdd000000, hovered ? 0x70ffffff : 0x30eebb00, renderBox(closeX, closeY, closeWidth, closeHeight, 0xdd000000, hovered ? 0x70ffffff : 0x30eebb00,
hovered ? 0x30ffffff : 0x10eebb00); hovered ? 0x30ffffff : 0x10eebb00);
@ -124,6 +132,54 @@ public class MetaDocScreen extends AbstractSimiScreen {
RenderSystem.popMatrix(); 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, protected void renderBox(int tooltipX, int tooltipY, int tooltipTextWidth, int tooltipHeight, int backgroundColor,
int borderColorStart, int borderColorEnd) { int borderColorStart, int borderColorEnd) {
int zLevel = 400; int zLevel = 400;

View file

@ -2,6 +2,8 @@ package com.simibubi.create.foundation.metadoc;
import com.simibubi.create.content.schematics.SchematicWorld; 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.util.math.BlockPos;
import net.minecraft.world.LightType; import net.minecraft.world.LightType;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -9,6 +11,7 @@ import net.minecraft.world.World;
public class MetaDocWorld extends SchematicWorld { public class MetaDocWorld extends SchematicWorld {
int overrideLight; int overrideLight;
WorldSectionElement mask;
public MetaDocWorld(BlockPos anchor, World original) { public MetaDocWorld(BlockPos anchor, World original) {
super(anchor, original); super(anchor, original);
@ -24,7 +27,22 @@ public class MetaDocWorld extends SchematicWorld {
@Override @Override
public int getLightLevel(LightType p_226658_1_, BlockPos p_226658_2_) { 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);
} }
} }

View file

@ -31,6 +31,7 @@ import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.MutableBoundingBox; import net.minecraft.util.math.MutableBoundingBox;
import net.minecraft.util.math.Vec3i; import net.minecraft.util.math.Vec3i;
import net.minecraftforge.client.ForgeHooksClient; import net.minecraftforge.client.ForgeHooksClient;
@ -46,7 +47,7 @@ public abstract class WorldSectionElement extends AnimatedSceneElement implement
public void render(MetaDocWorld world, IRenderTypeBuffer buffer, MatrixStack ms, float fade) { public void render(MetaDocWorld world, IRenderTypeBuffer buffer, MatrixStack ms, float fade) {
int light = -1; int light = -1;
if (fade != 1) if (fade != 1)
light = (int) (0xF * fade); light = (int) (MathHelper.lerp(fade, 5, 14));
world.pushFakeLight(light); world.pushFakeLight(light);
renderTileEntities(world, ms, buffer); renderTileEntities(world, ms, buffer);
@ -136,6 +137,7 @@ public abstract class WorldSectionElement extends AnimatedSceneElement implement
Random random = new Random(); Random random = new Random();
BufferBuilder builder = new BufferBuilder(DefaultVertexFormats.BLOCK.getIntegerSize()); BufferBuilder builder = new BufferBuilder(DefaultVertexFormats.BLOCK.getIntegerSize());
builder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK); builder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
world.setMask(this);
all().forEach(pos -> { all().forEach(pos -> {
BlockState state = world.getBlockState(pos); BlockState state = world.getBlockState(pos);
@ -152,6 +154,7 @@ public abstract class WorldSectionElement extends AnimatedSceneElement implement
ms.pop(); ms.pop();
}); });
world.clearMask();
builder.finishDrawing(); builder.finishDrawing();
return new SuperByteBuffer(builder); return new SuperByteBuffer(builder);
} }

View file

@ -23,7 +23,8 @@ public class HideAllInstruction extends TickingInstruction {
if (element instanceof AnimatedSceneElement) { if (element instanceof AnimatedSceneElement) {
AnimatedSceneElement animatedSceneElement = (AnimatedSceneElement) element; AnimatedSceneElement animatedSceneElement = (AnimatedSceneElement) element;
animatedSceneElement.setFade(1); animatedSceneElement.setFade(1);
animatedSceneElement.setFadeVec(new Vec3d(fadeOutTo.getDirectionVec()).scale(.5f)); animatedSceneElement
.setFadeVec(fadeOutTo == null ? null : new Vec3d(fadeOutTo.getDirectionVec()).scale(.5f));
} else } else
element.setVisible(false); element.setVisible(false);
}); });

View file

@ -23,7 +23,7 @@ public class CogwheelStory extends MetaDocStoryBoard {
@Override @Override
public void program(SceneBuilder scene, Vec3i worldSize) { public void program(SceneBuilder scene, Vec3i worldSize) {
scene.showBasePlate() scene.showBasePlate()
.idle(5) .idle(10)
.showSection(BlockPos.ZERO.up(), worldSize, Direction.DOWN); .showSection(BlockPos.ZERO.up(), worldSize, Direction.DOWN);
} }