Add error popup when trying to play path with reversed time keyframes
Update jGui
This commit is contained in:
2
jGui
2
jGui
Submodule jGui updated: 4125b3ac20...163cfe2f8a
@@ -121,24 +121,42 @@ public class GuiKeyframeTimeline extends AbstractGuiTimeline<GuiKeyframeTimeline
|
|||||||
|| !segment.getInterpolator().getKeyframeProperties().contains(SpectatorProperty.PROPERTY)) {
|
|| !segment.getInterpolator().getKeyframeProperties().contains(SpectatorProperty.PROPERTY)) {
|
||||||
continue; // Not a spectator segment
|
continue; // Not a spectator segment
|
||||||
}
|
}
|
||||||
long startFrameTime = segment.getStartKeyframe().getTime();
|
drawQuadOnSegment(renderer, visibleWidth, segment, BORDER_TOP + 1, 0xFF0088FF);
|
||||||
long endFrameTime = segment.getEndKeyframe().getTime();
|
}
|
||||||
if (startFrameTime >= endTime || endFrameTime <= startTime) {
|
|
||||||
continue; // Segment out of display range
|
|
||||||
}
|
|
||||||
|
|
||||||
double relativeStart = startFrameTime - startTime;
|
// Draw red quads on time path segments that would require time going backwards
|
||||||
double relativeEnd = endFrameTime - startTime;
|
for (PathSegment segment : mod.getCurrentTimeline().getPaths().get(GuiPathing.TIME_PATH).getSegments()) {
|
||||||
int startX = BORDER_LEFT + Math.max(0, (int) (relativeStart / visibleTime * visibleWidth) + KEYFRAME_SIZE / 2 + 1);
|
long startTimestamp = segment.getStartKeyframe().getValue(TimestampProperty.PROPERTY).orElseThrow(IllegalStateException::new);
|
||||||
int endX = BORDER_LEFT + Math.min(visibleWidth, (int) (relativeEnd / visibleTime * visibleWidth) - KEYFRAME_SIZE / 2);
|
long endTimestamp = segment.getEndKeyframe().getValue(TimestampProperty.PROPERTY).orElseThrow(IllegalStateException::new);
|
||||||
if (startX < endX) {
|
if (endTimestamp >= startTimestamp) {
|
||||||
renderer.drawRect(startX + 1, BORDER_TOP + 1, endX - startX - 2, KEYFRAME_SIZE - 2, 0xFF0088FF);
|
continue; // All is fine, time is not moving backwards
|
||||||
}
|
}
|
||||||
|
drawQuadOnSegment(renderer, visibleWidth, segment, BORDER_TOP + KEYFRAME_SIZE + 1, 0xFFFF0000);
|
||||||
}
|
}
|
||||||
|
|
||||||
super.drawTimelineCursor(renderer, size);
|
super.drawTimelineCursor(renderer, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void drawQuadOnSegment(GuiRenderer renderer, int visibleWidth, PathSegment segment, int y, int color) {
|
||||||
|
int startTime = getOffset();
|
||||||
|
int visibleTime = (int) (getZoom() * getLength());
|
||||||
|
int endTime = getOffset() + visibleTime;
|
||||||
|
|
||||||
|
long startFrameTime = segment.getStartKeyframe().getTime();
|
||||||
|
long endFrameTime = segment.getEndKeyframe().getTime();
|
||||||
|
if (startFrameTime >= endTime || endFrameTime <= startTime) {
|
||||||
|
return; // Segment out of display range
|
||||||
|
}
|
||||||
|
|
||||||
|
double relativeStart = startFrameTime - startTime;
|
||||||
|
double relativeEnd = endFrameTime - startTime;
|
||||||
|
int startX = BORDER_LEFT + Math.max(0, (int) (relativeStart / visibleTime * visibleWidth) + KEYFRAME_SIZE / 2 + 1);
|
||||||
|
int endX = BORDER_LEFT + Math.min(visibleWidth, (int) (relativeEnd / visibleTime * visibleWidth) - KEYFRAME_SIZE / 2);
|
||||||
|
if (startX < endX) {
|
||||||
|
renderer.drawRect(startX + 1, y, endX - startX - 2, KEYFRAME_SIZE - 2, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the keyframe at the specified position.
|
* Returns the keyframe at the specified position.
|
||||||
* @param position The raw position
|
* @param position The raw position
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import de.johni0702.minecraft.gui.layout.CustomLayout;
|
|||||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||||
import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||||
import de.johni0702.minecraft.gui.popup.AbstractGuiPopup;
|
import de.johni0702.minecraft.gui.popup.AbstractGuiPopup;
|
||||||
|
import de.johni0702.minecraft.gui.popup.GuiInfoPopup;
|
||||||
import de.johni0702.minecraft.gui.popup.GuiYesNoPopup;
|
import de.johni0702.minecraft.gui.popup.GuiYesNoPopup;
|
||||||
import de.johni0702.minecraft.gui.utils.Colors;
|
import de.johni0702.minecraft.gui.utils.Colors;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
@@ -75,7 +76,7 @@ public class GuiPathing {
|
|||||||
public final GuiTexturedButton renderButton = new GuiTexturedButton().onClick(new Runnable() {
|
public final GuiTexturedButton renderButton = new GuiTexturedButton().onClick(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
preparePathsForPlayback();
|
if (!preparePathsForPlayback()) return;
|
||||||
new GuiRenderSettings(replayHandler, mod.getCurrentTimeline()).display();
|
new GuiRenderSettings(replayHandler, mod.getCurrentTimeline()).display();
|
||||||
}
|
}
|
||||||
}).setSize(20, 20).setTexture(ReplayMod.TEXTURE, ReplayMod.TEXTURE_SIZE).setTexturePosH(40, 0);
|
}).setSize(20, 20).setTexture(ReplayMod.TEXTURE, ReplayMod.TEXTURE_SIZE).setTexturePosH(40, 0);
|
||||||
@@ -231,7 +232,7 @@ public class GuiPathing {
|
|||||||
Timeline timeline = mod.getCurrentTimeline();
|
Timeline timeline = mod.getCurrentTimeline();
|
||||||
Path timePath = timeline.getPaths().get(TIME_PATH);
|
Path timePath = timeline.getPaths().get(TIME_PATH);
|
||||||
|
|
||||||
preparePathsForPlayback();
|
if (!preparePathsForPlayback()) return;
|
||||||
|
|
||||||
timePath.setActive(!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT));
|
timePath.setActive(!Keyboard.isKeyDown(Keyboard.KEY_LSHIFT));
|
||||||
ListenableFuture<Void> future = player.start(timeline);
|
ListenableFuture<Void> future = player.start(timeline);
|
||||||
@@ -438,10 +439,27 @@ public class GuiPathing {
|
|||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void preparePathsForPlayback() {
|
private boolean preparePathsForPlayback() {
|
||||||
Timeline timeline = mod.getCurrentTimeline();
|
Timeline timeline = mod.getCurrentTimeline();
|
||||||
timeline.getPaths().get(TIME_PATH).updateAll();
|
timeline.getPaths().get(TIME_PATH).updateAll();
|
||||||
timeline.getPaths().get(POSITION_PATH).updateAll();
|
timeline.getPaths().get(POSITION_PATH).updateAll();
|
||||||
|
|
||||||
|
// Make sure time keyframes's values are monotonically increasing
|
||||||
|
int lastTime = 0;
|
||||||
|
for (Keyframe keyframe : timeline.getPaths().get(TIME_PATH).getKeyframes()) {
|
||||||
|
int time = keyframe.getValue(TimestampProperty.PROPERTY).orElseThrow(IllegalStateException::new);
|
||||||
|
if (time < lastTime) {
|
||||||
|
// We are going backwards in time
|
||||||
|
GuiInfoPopup.open(replayHandler.getOverlay(),
|
||||||
|
"replaymod.error.negativetime1",
|
||||||
|
"replaymod.error.negativetime2",
|
||||||
|
"replaymod.error.negativetime3");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
lastTime = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void zoomTimeline(double factor) {
|
public void zoomTimeline(double factor) {
|
||||||
|
|||||||
@@ -485,6 +485,9 @@ replaymod.gui.objects=Custom Objects
|
|||||||
#Errors
|
#Errors
|
||||||
replaymod.error.unknownrestriction1=This replay cannot be played with your current version.
|
replaymod.error.unknownrestriction1=This replay cannot be played with your current version.
|
||||||
replaymod.error.unknownrestriction2=It tried to enforce %s which is unknown.
|
replaymod.error.unknownrestriction2=It tried to enforce %s which is unknown.
|
||||||
|
replaymod.error.negativetime1=Some of your time keyframes are out of order.
|
||||||
|
replaymod.error.negativetime2=Going backwards in time is not supported.
|
||||||
|
replaymod.error.negativetime3=The invalid parts are marked in red.
|
||||||
|
|
||||||
#Replay Mod Incompatibility Warning
|
#Replay Mod Incompatibility Warning
|
||||||
replaymod.gui.modwarning.title=Incompatibility detected
|
replaymod.gui.modwarning.title=Incompatibility detected
|
||||||
|
|||||||
Reference in New Issue
Block a user