Multiple scenes per doc
This commit is contained in:
parent
6836bd97f4
commit
e178cab4a8
15 changed files with 172 additions and 18 deletions
|
@ -6,6 +6,8 @@ public abstract class MetaDocInstruction {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reset(MetaDocScene scene) {}
|
||||||
|
|
||||||
public abstract boolean isComplete();
|
public abstract boolean isComplete();
|
||||||
|
|
||||||
public abstract void tick(MetaDocScene scene);
|
public abstract void tick(MetaDocScene scene);
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.util.Set;
|
||||||
import com.mojang.blaze3d.matrix.MatrixStack;
|
import com.mojang.blaze3d.matrix.MatrixStack;
|
||||||
import com.simibubi.create.foundation.metadoc.instructions.DelayInstruction;
|
import com.simibubi.create.foundation.metadoc.instructions.DelayInstruction;
|
||||||
import com.simibubi.create.foundation.metadoc.instructions.DisplayWorldSectionInstruction;
|
import com.simibubi.create.foundation.metadoc.instructions.DisplayWorldSectionInstruction;
|
||||||
|
import com.simibubi.create.foundation.metadoc.instructions.HideAllInstruction;
|
||||||
import com.simibubi.create.foundation.metadoc.instructions.ShowCompleteSchematicInstruction;
|
import com.simibubi.create.foundation.metadoc.instructions.ShowCompleteSchematicInstruction;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
import net.minecraft.client.renderer.IRenderTypeBuffer;
|
||||||
|
@ -34,11 +35,21 @@ public class MetaDocScene {
|
||||||
activeSchedule = new ArrayList<>();
|
activeSchedule = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void begin() {
|
public void reset() {
|
||||||
activeSchedule.clear();
|
activeSchedule.clear();
|
||||||
|
schedule.forEach(mdi -> mdi.reset(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void begin() {
|
||||||
|
reset();
|
||||||
activeSchedule.addAll(schedule);
|
activeSchedule.addAll(schedule);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void fadeOut() {
|
||||||
|
reset();
|
||||||
|
activeSchedule.add(new HideAllInstruction(10, Direction.DOWN));
|
||||||
|
}
|
||||||
|
|
||||||
public void render(IRenderTypeBuffer buffer, MatrixStack ms) {
|
public void render(IRenderTypeBuffer buffer, MatrixStack ms) {
|
||||||
ms.push();
|
ms.push();
|
||||||
MutableBoundingBox bounds = world.getBounds();
|
MutableBoundingBox bounds = world.getBounds();
|
||||||
|
@ -71,6 +82,10 @@ public class MetaDocScene {
|
||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<MetaDocSceneElement> getElements() {
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
|
||||||
public MutableBoundingBox getBounds() {
|
public MutableBoundingBox getBounds() {
|
||||||
return world.getBounds();
|
return world.getBounds();
|
||||||
}
|
}
|
||||||
|
@ -88,11 +103,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(10, fadeInDirection, new WorldSectionElement.Cuboid(origin, size)));
|
new DisplayWorldSectionInstruction(20, fadeInDirection, new WorldSectionElement.Cuboid(origin, size)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public SceneBuilder showSection(WorldSectionElement element, Direction fadeInDirection) {
|
public SceneBuilder showSection(WorldSectionElement element, Direction fadeInDirection) {
|
||||||
return addInstruction(new DisplayWorldSectionInstruction(10, fadeInDirection, element));
|
return addInstruction(new DisplayWorldSectionInstruction(20, fadeInDirection, element));
|
||||||
}
|
}
|
||||||
|
|
||||||
public SceneBuilder debugSchematic() {
|
public SceneBuilder debugSchematic() {
|
||||||
|
|
|
@ -10,4 +10,8 @@ public abstract class MetaDocSceneElement {
|
||||||
|
|
||||||
public abstract void render(MetaDocWorld world, IRenderTypeBuffer buffer, MatrixStack ms);
|
public abstract void render(MetaDocWorld world, IRenderTypeBuffer buffer, MatrixStack ms);
|
||||||
|
|
||||||
|
public void setVisible(boolean visible) {
|
||||||
|
this.visible = visible;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,16 +11,21 @@ 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.util.math.MathHelper;
|
||||||
import net.minecraftforge.fml.client.gui.GuiUtils;
|
import net.minecraftforge.fml.client.gui.GuiUtils;
|
||||||
|
|
||||||
public class MetaDocScreen extends AbstractSimiScreen {
|
public class MetaDocScreen extends AbstractSimiScreen {
|
||||||
|
|
||||||
private List<MetaDocScene> stories;
|
private List<MetaDocScene> stories;
|
||||||
private int index = 0;
|
|
||||||
private LerpedFloat fadeIn;
|
private LerpedFloat fadeIn;
|
||||||
|
|
||||||
|
private LerpedFloat lazyIndex;
|
||||||
|
private int index = 0;
|
||||||
|
|
||||||
public MetaDocScreen(List<MetaDocScene> stories) {
|
public MetaDocScreen(List<MetaDocScene> stories) {
|
||||||
this.stories = stories;
|
this.stories = stories;
|
||||||
|
lazyIndex = LerpedFloat.linear()
|
||||||
|
.startWithValue(index);
|
||||||
fadeIn = LerpedFloat.linear()
|
fadeIn = LerpedFloat.linear()
|
||||||
.startWithValue(0)
|
.startWithValue(0)
|
||||||
.chase(1, .5f, Chaser.EXP);
|
.chase(1, .5f, Chaser.EXP);
|
||||||
|
@ -28,27 +33,63 @@ public class MetaDocScreen extends AbstractSimiScreen {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
|
lazyIndex.tickChaser();
|
||||||
fadeIn.tickChaser();
|
fadeIn.tickChaser();
|
||||||
stories.get(index)
|
stories.get(index)
|
||||||
.tick();
|
.tick();
|
||||||
|
float lazyIndexValue = lazyIndex.getValue();
|
||||||
|
if (Math.abs(lazyIndexValue - index) > 1 / 512f)
|
||||||
|
stories.get(lazyIndexValue < index ? index - 1 : index + 1)
|
||||||
|
.tick();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
|
||||||
|
int prevIndex = index;
|
||||||
|
index = delta > 0 ? index + 1 : index - 1;
|
||||||
|
index = MathHelper.clamp(index, 0, stories.size() - 1);
|
||||||
|
if (prevIndex != index && Math.abs(index - lazyIndex.getValue()) < 1.25f) {
|
||||||
|
stories.get(prevIndex)
|
||||||
|
.fadeOut();
|
||||||
|
stories.get(index)
|
||||||
|
.begin();
|
||||||
|
lazyIndex.chase(index, 1 / 4f, Chaser.EXP);
|
||||||
|
return true;
|
||||||
|
} else
|
||||||
|
index = prevIndex;
|
||||||
|
return super.mouseScrolled(mouseX, mouseY, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderWindow(int mouseX, int mouseY, float partialTicks) {
|
protected void renderWindow(int mouseX, int mouseY, float partialTicks) {
|
||||||
RenderSystem.enableBlend();
|
RenderSystem.enableBlend();
|
||||||
renderStory();
|
renderStories(partialTicks);
|
||||||
renderWidgets(partialTicks);
|
renderWidgets(mouseX, mouseY, partialTicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void renderStory() {
|
protected void renderStories(float partialTicks) {
|
||||||
MetaDocScene story = stories.get(index);
|
renderStory(index, partialTicks);
|
||||||
|
float lazyIndexValue = lazyIndex.getValue(partialTicks);
|
||||||
|
if (Math.abs(lazyIndexValue - index) > 1 / 512f)
|
||||||
|
renderStory(lazyIndexValue < index ? index - 1 : index + 1, partialTicks);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void renderStory(int i, float partialTicks) {
|
||||||
|
MetaDocScene story = stories.get(i);
|
||||||
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);
|
||||||
|
float diff = i - value;
|
||||||
|
float slide = i == index ? 400 : MathHelper.lerp(Math.abs(diff), 0, 400);
|
||||||
|
ms.translate(diff * slide, 0, 0);
|
||||||
|
|
||||||
ms.scale(30, -30, 30);
|
ms.scale(30, -30, 30);
|
||||||
|
|
||||||
SuperRenderTypeBuffer buffer = SuperRenderTypeBuffer.getInstance();
|
SuperRenderTypeBuffer buffer = SuperRenderTypeBuffer.getInstance();
|
||||||
|
@ -57,7 +98,7 @@ public class MetaDocScreen extends AbstractSimiScreen {
|
||||||
ms.pop();
|
ms.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void renderWidgets(float pt) {
|
protected void renderWidgets(int mouseX, int mouseY, float pt) {
|
||||||
float fade = fadeIn.getValue(pt);
|
float fade = fadeIn.getValue(pt);
|
||||||
int textColor = 0xeeeeee;
|
int textColor = 0xeeeeee;
|
||||||
|
|
||||||
|
@ -72,7 +113,12 @@ public class MetaDocScreen extends AbstractSimiScreen {
|
||||||
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;
|
||||||
renderBox(closeX, closeY, closeWidth, closeHeight, 0xdd000000, 0x30eebb00, 0x10eebb00);
|
|
||||||
|
boolean hovered = !(mouseX < closeX || mouseX > closeX + closeWidth);
|
||||||
|
hovered &= !(mouseY < closeY || mouseY > closeY + closeHeight);
|
||||||
|
|
||||||
|
renderBox(closeX, closeY, closeWidth, closeHeight, 0xdd000000, hovered ? 0x70ffffff : 0x30eebb00,
|
||||||
|
hovered ? 0x30ffffff : 0x10eebb00);
|
||||||
AllIcons.I_CONFIRM.draw(closeX + 4, closeY + 4);
|
AllIcons.I_CONFIRM.draw(closeX + 4, closeY + 4);
|
||||||
|
|
||||||
RenderSystem.popMatrix();
|
RenderSystem.popMatrix();
|
||||||
|
|
|
@ -3,12 +3,28 @@ package com.simibubi.create.foundation.metadoc;
|
||||||
import com.simibubi.create.content.schematics.SchematicWorld;
|
import com.simibubi.create.content.schematics.SchematicWorld;
|
||||||
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.LightType;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
public class MetaDocWorld extends SchematicWorld {
|
public class MetaDocWorld extends SchematicWorld {
|
||||||
|
|
||||||
|
int overrideLight;
|
||||||
|
|
||||||
public MetaDocWorld(BlockPos anchor, World original) {
|
public MetaDocWorld(BlockPos anchor, World original) {
|
||||||
super(anchor, original);
|
super(anchor, original);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void pushFakeLight(int light) {
|
||||||
|
this.overrideLight = light;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void popLight() {
|
||||||
|
this.overrideLight = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getLightLevel(LightType p_226658_1_, BlockPos p_226658_2_) {
|
||||||
|
return overrideLight == -1 ? super.getLightLevel(p_226658_1_, p_226658_2_) : overrideLight;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.simibubi.create.foundation.metadoc;
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -30,7 +31,8 @@ public class MetaDocs {
|
||||||
|
|
||||||
public static void register() {
|
public static void register() {
|
||||||
|
|
||||||
addStoryBoard(AllBlocks.COGWHEEL, new CogwheelStory());
|
for (int i = 1; i < 6; i++)
|
||||||
|
addStoryBoard(AllBlocks.COGWHEEL, new CogwheelStory(i));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,9 +61,12 @@ public class MetaDocs {
|
||||||
public static Template loadSchematic(String path) {
|
public static Template loadSchematic(String path) {
|
||||||
Template t = new Template();
|
Template t = new Template();
|
||||||
String filepath = "doc/" + path + ".nbt";
|
String filepath = "doc/" + path + ".nbt";
|
||||||
|
InputStream resourceAsStream = Create.class.getClassLoader()
|
||||||
|
.getResourceAsStream(filepath);
|
||||||
|
if (resourceAsStream == null)
|
||||||
|
throw new IllegalStateException("Could not find metadoc schematic: " + filepath);
|
||||||
try (DataInputStream stream =
|
try (DataInputStream stream =
|
||||||
new DataInputStream(new BufferedInputStream(new GZIPInputStream(Create.class.getClassLoader()
|
new DataInputStream(new BufferedInputStream(new GZIPInputStream(resourceAsStream)))) {
|
||||||
.getResourceAsStream(filepath))))) {
|
|
||||||
CompoundNBT nbt = CompressedStreamTools.read(stream, new NBTSizeTracker(0x20000000L));
|
CompoundNBT nbt = CompressedStreamTools.read(stream, new NBTSizeTracker(0x20000000L));
|
||||||
t.read(nbt);
|
t.read(nbt);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -44,7 +44,14 @@ public abstract class WorldSectionElement extends AnimatedSceneElement implement
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
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;
|
||||||
|
if (fade != 1)
|
||||||
|
light = (int) (0xF * fade);
|
||||||
|
|
||||||
|
world.pushFakeLight(light);
|
||||||
renderTileEntities(world, ms, buffer);
|
renderTileEntities(world, ms, buffer);
|
||||||
|
world.popLight();
|
||||||
|
|
||||||
if (buffer instanceof IRenderTypeBuffer.Impl)
|
if (buffer instanceof IRenderTypeBuffer.Impl)
|
||||||
((IRenderTypeBuffer.Impl) buffer).draw();
|
((IRenderTypeBuffer.Impl) buffer).draw();
|
||||||
renderStructure(world, ms, buffer, fade);
|
renderStructure(world, ms, buffer, fade);
|
||||||
|
@ -87,7 +94,7 @@ public abstract class WorldSectionElement extends AnimatedSceneElement implement
|
||||||
protected void renderStructure(MetaDocWorld world, MatrixStack ms, IRenderTypeBuffer buffer, float fade) {
|
protected void renderStructure(MetaDocWorld world, MatrixStack ms, IRenderTypeBuffer buffer, float fade) {
|
||||||
SuperByteBufferCache bufferCache = CreateClient.bufferCache;
|
SuperByteBufferCache bufferCache = CreateClient.bufferCache;
|
||||||
List<RenderType> blockLayers = RenderType.getBlockLayers();
|
List<RenderType> blockLayers = RenderType.getBlockLayers();
|
||||||
int code = hashCode();
|
int code = hashCode() ^ world.hashCode();
|
||||||
|
|
||||||
buffer.getBuffer(RenderType.getSolid());
|
buffer.getBuffer(RenderType.getSolid());
|
||||||
for (int i = 0; i < blockLayers.size(); i++) {
|
for (int i = 0; i < blockLayers.size(); i++) {
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.simibubi.create.foundation.metadoc.instructions;
|
||||||
|
|
||||||
|
import com.simibubi.create.foundation.metadoc.AnimatedSceneElement;
|
||||||
|
import com.simibubi.create.foundation.metadoc.MetaDocScene;
|
||||||
|
|
||||||
|
import net.minecraft.util.Direction;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
|
public class HideAllInstruction extends TickingInstruction {
|
||||||
|
|
||||||
|
private Direction fadeOutTo;
|
||||||
|
|
||||||
|
public HideAllInstruction(int fadeOutTicks, Direction fadeOutTo) {
|
||||||
|
super(false, fadeOutTicks);
|
||||||
|
this.fadeOutTo = fadeOutTo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void firstTick(MetaDocScene scene) {
|
||||||
|
super.firstTick(scene);
|
||||||
|
scene.getElements()
|
||||||
|
.forEach(element -> {
|
||||||
|
if (element instanceof AnimatedSceneElement) {
|
||||||
|
AnimatedSceneElement animatedSceneElement = (AnimatedSceneElement) element;
|
||||||
|
animatedSceneElement.setFade(1);
|
||||||
|
animatedSceneElement.setFadeVec(new Vec3d(fadeOutTo.getDirectionVec()).scale(.5f));
|
||||||
|
} else
|
||||||
|
element.setVisible(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick(MetaDocScene scene) {
|
||||||
|
super.tick(scene);
|
||||||
|
float fade = (remainingTicks / (float) totalTicks);
|
||||||
|
scene.getElements()
|
||||||
|
.forEach(element -> {
|
||||||
|
if (!(element instanceof AnimatedSceneElement))
|
||||||
|
return;
|
||||||
|
AnimatedSceneElement animatedSceneElement = (AnimatedSceneElement) element;
|
||||||
|
animatedSceneElement.setFade(fade * fade);
|
||||||
|
if (remainingTicks == 0)
|
||||||
|
animatedSceneElement.setFade(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -14,6 +14,12 @@ public abstract class TickingInstruction extends MetaDocInstruction {
|
||||||
remainingTicks = totalTicks = ticks;
|
remainingTicks = totalTicks = ticks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset(MetaDocScene scene) {
|
||||||
|
super.reset(scene);
|
||||||
|
remainingTicks = totalTicks;
|
||||||
|
}
|
||||||
|
|
||||||
protected void firstTick(MetaDocScene scene) {}
|
protected void firstTick(MetaDocScene scene) {}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -9,9 +9,15 @@ import net.minecraft.util.math.Vec3i;
|
||||||
|
|
||||||
public class CogwheelStory extends MetaDocStoryBoard {
|
public class CogwheelStory extends MetaDocStoryBoard {
|
||||||
|
|
||||||
|
private int index;
|
||||||
|
|
||||||
|
public CogwheelStory(int index) {
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSchematicName() {
|
public String getSchematicName() {
|
||||||
return "cogwheel/test";
|
return "cogwheel/s" + index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
BIN
src/main/resources/doc/cogwheel/s2.nbt
Normal file
BIN
src/main/resources/doc/cogwheel/s2.nbt
Normal file
Binary file not shown.
BIN
src/main/resources/doc/cogwheel/s3.nbt
Normal file
BIN
src/main/resources/doc/cogwheel/s3.nbt
Normal file
Binary file not shown.
BIN
src/main/resources/doc/cogwheel/s4.nbt
Normal file
BIN
src/main/resources/doc/cogwheel/s4.nbt
Normal file
Binary file not shown.
BIN
src/main/resources/doc/cogwheel/s5.nbt
Normal file
BIN
src/main/resources/doc/cogwheel/s5.nbt
Normal file
Binary file not shown.
Loading…
Reference in a new issue