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() {
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() {

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.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;

View file

@ -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);
}
}

View file

@ -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);
}

View file

@ -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);
});

View file

@ -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);
}