diff --git a/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java b/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java index 0d6860d6..c74a865c 100755 --- a/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java +++ b/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java @@ -47,7 +47,7 @@ public class ReplayMod { public static final ApiClient apiClient = new ApiClient(); private static final Minecraft mc = Minecraft.getMinecraft(); public static GuiEventHandler guiEventHandler; - public static GuiReplayOverlay overlay = new GuiReplayOverlay(); + public static GuiReplayOverlay overlay; public static ReplaySettings replaySettings; public static Configuration config; public static boolean firstMainMenu = true; @@ -89,6 +89,8 @@ public class ReplayMod { @EventHandler public void init(FMLInitializationEvent event) { + overlay = new GuiReplayOverlay(); + FMLCommonHandler.instance().bus().register(new ConnectionEventHandler()); MinecraftForge.EVENT_BUS.register(guiEventHandler = new GuiEventHandler()); diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/GuiMouseInput.java b/src/main/java/eu/crushedpixel/replaymod/gui/GuiMouseInput.java index a2e8cf09..1543035f 100755 --- a/src/main/java/eu/crushedpixel/replaymod/gui/GuiMouseInput.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/GuiMouseInput.java @@ -18,17 +18,17 @@ public class GuiMouseInput extends GuiScreen { @Override protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { - overlay.mouseClicked(mouseX, mouseY); + overlay.mouseClicked(mouseX, mouseY, mouseButton); } @Override protected void mouseReleased(int mouseX, int mouseY, int state) { - overlay.mouseReleased(mouseX, mouseY); + overlay.mouseReleased(mouseX, mouseY, state); } @Override protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { - overlay.mouseDrag(mouseX, mouseY); + overlay.mouseDrag(mouseX, mouseY, clickedMouseButton); } @Override diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplaySpeedSlider.java b/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplaySpeedSlider.java index 06fcd1ae..39a568e4 100755 --- a/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplaySpeedSlider.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplaySpeedSlider.java @@ -1,6 +1,7 @@ package eu.crushedpixel.replaymod.gui; import eu.crushedpixel.replaymod.ReplayMod; +import eu.crushedpixel.replaymod.gui.elements.GuiElement; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; @@ -8,7 +9,7 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraft.util.MathHelper; import net.minecraftforge.fml.client.FMLClientHandler; -public class GuiReplaySpeedSlider extends GuiButton { +public class GuiReplaySpeedSlider extends GuiButton implements GuiElement { private float sliderValue; @@ -18,7 +19,6 @@ public class GuiReplaySpeedSlider extends GuiButton { public GuiReplaySpeedSlider(int buttonId, int p_i45017_2_, int p_i45017_3_, String displayKey) { super(buttonId, p_i45017_2_, p_i45017_3_, 150, 20, ""); - sliderValue = (9f / 38f); this.width = 100; this.valueMin = 1; @@ -26,6 +26,16 @@ public class GuiReplaySpeedSlider extends GuiButton { this.valueStep = 1; this.displayString = displayKey + ": 1x"; this.displayKey = displayKey; + + reset(); + } + + public void copyValueFrom(GuiReplaySpeedSlider other) { + sliderValue = other.sliderValue; + } + + public void reset() { + sliderValue = 9f / 38f; } public static float convertScaleRet(float value) { @@ -58,7 +68,7 @@ public class GuiReplaySpeedSlider extends GuiButton { FontRenderer fontrenderer = mc.fontRendererObj; mc.getTextureManager().bindTexture(buttonTextures); GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - this.hovered = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; + this.hovered = isHovering(mouseX, mouseY); int k = this.getHoverState(this.hovered); GlStateManager.enableBlend(); GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0); @@ -162,4 +172,36 @@ public class GuiReplaySpeedSlider extends GuiButton { this.dragging = false; } + @Override + public void draw(Minecraft mc, int mouseX, int mouseY) { + drawButton(mc, mouseX, mouseY); + } + + @Override + public void drawOverlay(Minecraft mc, int mouseX, int mouseY) { + + } + + @Override + public boolean isHovering(int mouseX, int mouseY) { + return mouseX >= this.xPosition + && mouseY >= this.yPosition + && mouseX < this.xPosition + this.width + && mouseY < this.yPosition + this.height; + } + + @Override + public void mouseClick(Minecraft mc, int mouseX, int mouseY, int button) { + mousePressed(mc, mouseX, mouseY); + } + + @Override + public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) { + mouseDragged(mc, mouseX, mouseY); + } + + @Override + public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) { + mouseReleased(mouseX, mouseY); + } } \ No newline at end of file diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/elements/ComposedElement.java b/src/main/java/eu/crushedpixel/replaymod/gui/elements/ComposedElement.java new file mode 100644 index 00000000..d3a82d4e --- /dev/null +++ b/src/main/java/eu/crushedpixel/replaymod/gui/elements/ComposedElement.java @@ -0,0 +1,56 @@ +package eu.crushedpixel.replaymod.gui.elements; + +import net.minecraft.client.Minecraft; + +public class ComposedElement implements GuiElement { + private final GuiElement[] parts; + + public ComposedElement(GuiElement...parts) { + this.parts = parts; + } + + @Override + public void draw(Minecraft mc, int mouseX, int mouseY) { + for (GuiElement part : parts) { + part.draw(mc, mouseX, mouseY); + } + } + + @Override + public void drawOverlay(Minecraft mc, int mouseX, int mouseY) { + for (GuiElement part : parts) { + part.drawOverlay(mc, mouseX, mouseY); + } + } + + @Override + public boolean isHovering(int mouseX, int mouseY) { + for (GuiElement part : parts) { + if (part.isHovering(mouseX, mouseY)) { + return true; + } + } + return false; + } + + @Override + public void mouseClick(Minecraft mc, int mouseX, int mouseY, int button) { + for (GuiElement part : parts) { + part.mouseClick(mc, mouseX, mouseY, button); + } + } + + @Override + public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) { + for (GuiElement part : parts) { + part.mouseDrag(mc, mouseX, mouseY, button); + } + } + + @Override + public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) { + for (GuiElement part : parts) { + part.mouseRelease(mc, mouseX, mouseY, button); + } + } +} diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/elements/DelegatingElement.java b/src/main/java/eu/crushedpixel/replaymod/gui/elements/DelegatingElement.java new file mode 100644 index 00000000..7bc83e7d --- /dev/null +++ b/src/main/java/eu/crushedpixel/replaymod/gui/elements/DelegatingElement.java @@ -0,0 +1,46 @@ +package eu.crushedpixel.replaymod.gui.elements; + +import net.minecraft.client.Minecraft; + +public abstract class DelegatingElement implements GuiElement { + public static DelegatingElement of(final GuiElement element) { + return new DelegatingElement() { + @Override + public GuiElement delegate() { + return element; + } + }; + } + + public abstract GuiElement delegate(); + + @Override + public void draw(Minecraft mc, int mouseX, int mouseY) { + delegate().draw(mc, mouseX, mouseY); + } + + @Override + public void drawOverlay(Minecraft mc, int mouseX, int mouseY) { + delegate().drawOverlay(mc, mouseX, mouseY); + } + + @Override + public boolean isHovering(int mouseX, int mouseY) { + return delegate().isHovering(mouseX, mouseY); + } + + @Override + public void mouseClick(Minecraft mc, int mouseX, int mouseY, int button) { + delegate().mouseClick(mc, mouseX, mouseY, button); + } + + @Override + public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) { + delegate().mouseDrag(mc, mouseX, mouseY, button); + } + + @Override + public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) { + delegate().mouseRelease(mc, mouseX, mouseY, button); + } +} diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiElement.java b/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiElement.java new file mode 100644 index 00000000..44980e38 --- /dev/null +++ b/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiElement.java @@ -0,0 +1,16 @@ +package eu.crushedpixel.replaymod.gui.elements; + +import net.minecraft.client.Minecraft; + +public interface GuiElement { + + void draw(Minecraft mc, int mouseX, int mouseY); + void drawOverlay(Minecraft mc, int mouseX, int mouseY); + + boolean isHovering(int mouseX, int mouseY); + + void mouseClick(Minecraft mc, int mouseX, int mouseY, int button); + void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button); + void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button); + +} diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiKeyframeTimeline.java b/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiKeyframeTimeline.java index 0815f635..d0441413 100644 --- a/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiKeyframeTimeline.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiKeyframeTimeline.java @@ -22,7 +22,8 @@ public class GuiKeyframeTimeline extends GuiTimeline { showMarkers = true; } - public void mouseClicked(Minecraft mc, int mouseX, int mouseY) { + @Override + public void mouseClick(Minecraft mc, int mouseX, int mouseY, int button) { long time = getTimeAt(mouseX, mouseY); if (time == -1) { return; @@ -58,7 +59,8 @@ public class GuiKeyframeTimeline extends GuiTimeline { this.clickTime = currentTime; } - public void mouseDrag(int mouseX, int mouseY) { + @Override + public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) { long time = getTimeAt(mouseX, mouseY); if (time != -1) { if (clickedKeyFrame != null) { @@ -75,8 +77,9 @@ public class GuiKeyframeTimeline extends GuiTimeline { } } - public void mouseRelease(int mouseX, int mouseY) { - mouseDrag(mouseX, mouseY); + @Override + public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) { + mouseDrag(mc, mouseX, mouseY, button); clickedKeyFrame = null; dragging = false; } diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiScrollbar.java b/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiScrollbar.java index 11b25950..654abbcf 100644 --- a/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiScrollbar.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiScrollbar.java @@ -9,7 +9,7 @@ import static eu.crushedpixel.replaymod.gui.overlay.GuiReplayOverlay.replay_gui; import static org.lwjgl.opengl.GL11.GL_BLEND; import static org.lwjgl.opengl.GL11.glEnable; -public class GuiScrollbar extends Gui { +public class GuiScrollbar extends Gui implements GuiElement { protected static final int BORDER_LEFT = 1; protected static final int BORDER_RIGHT = 2; @@ -56,34 +56,31 @@ public class GuiScrollbar extends Gui { return (int) Math.round((width - BORDER_LEFT - BORDER_RIGHT) * sliderPosition) + BORDER_LEFT; } - public boolean startDragging(int mouseX, int mouseY) { - int offsetX = getSliderOffsetX(); - int minX = positionX + offsetX; - int maxX = positionX + offsetX + (int) (width * size); - int minY = positionY + BORDER_TOP; - int maxY = minY + SLIDER_HEIGHT; - if (mouseX >= minX && mouseY >= minY && mouseX < maxX && mouseY < maxY) { + @Override + public void mouseClick(Minecraft mc, int mouseX, int mouseY, int button) { + if (isHovering(mouseX, mouseY)) { draggingStart = mouseX; draggingStartPosition = sliderPosition; - return true; - } else { - return false; } } - public void doDragging(int mouseX) { + @Override + public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) { if (draggingStart != -1) { double delta = (double) (mouseX - draggingStart) / (width - BORDER_LEFT - BORDER_RIGHT); sliderPosition = Math.max(0, Math.min(1 - size, draggingStartPosition + delta)); + dragged(); } } - public void endDragging(int mouseX) { - doDragging(mouseX); + @Override + public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) { + mouseDrag(mc, mouseX, mouseY, button); draggingStart = -1; } - public void draw(Minecraft mc) { + @Override + public void draw(Minecraft mc, int mouseX, int mouseY) { GlStateManager.resetColor(); mc.renderEngine.bindTexture(replay_gui); glEnable(GL_BLEND); @@ -139,4 +136,23 @@ public class GuiScrollbar extends Gui { drawModalRectWithCustomSizedTexture(x, y, u, v, width, height, TEXTURE_SIZE, TEXTURE_SIZE); } + + @Override + public void drawOverlay(Minecraft mc, int mouseX, int mouseY) { + + } + + @Override + public boolean isHovering(int mouseX, int mouseY) { + int offsetX = getSliderOffsetX(); + int minX = positionX + offsetX; + int maxX = positionX + offsetX + (int) (width * size); + int minY = positionY + BORDER_TOP; + int maxY = minY + SLIDER_HEIGHT; + return mouseX >= minX && mouseY >= minY && mouseX < maxX && mouseY < maxY; + } + + public void dragged() { + + } } diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiTexturedButton.java b/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiTexturedButton.java index 8cfd2406..383ff7a9 100644 --- a/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiTexturedButton.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiTexturedButton.java @@ -5,50 +5,85 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.resources.I18n; import net.minecraft.util.ResourceLocation; -import java.awt.*; - -public class GuiTexturedButton extends GuiButton { +public class GuiTexturedButton extends GuiButton implements GuiElement { private final ResourceLocation texture; private final int u, v; private final int textureWidth, textureHeight; - private final String hoverKey; + private final Runnable action; + private final String hoverText; public GuiTexturedButton(int buttonId, int x, int y, int width, int height, ResourceLocation texture, - int u, int v, int textureWidth, int textureHeight) { - this(buttonId, x, y, width, height, texture, u, v, textureWidth, textureHeight, null); + int u, int v, int textureWidth, int textureHeight, Runnable action) { + this(buttonId, x, y, width, height, texture, u, v, textureWidth, textureHeight, action, null); } public GuiTexturedButton(int buttonId, int x, int y, int width, int height, ResourceLocation texture, - int u, int v, int textureWidth, int textureHeight, String hoverKey) { + int u, int v, int textureWidth, int textureHeight, Runnable action, String hoverText) { super(buttonId, x, y, width, height, ""); this.texture = texture; this.u = u; this.v = v; this.textureWidth = textureWidth; this.textureHeight = textureHeight; - this.hoverKey = hoverKey; + this.action = action; + this.hoverText = hoverText; + } + + @Override + public boolean isHovering(int mouseX, int mouseY) { + return enabled && visible + && mouseX >= xPosition + && mouseY >= yPosition + && mouseX < xPosition + width + && mouseY < yPosition + height; } @Override public void drawButton(Minecraft mc, int mouseX, int mouseY) { if (visible) { - hovered = mouseX >= xPosition - && mouseY >= yPosition - && mouseX < xPosition + width - && mouseY < yPosition + height; + hovered = isHovering(mouseX, mouseY); mc.renderEngine.bindTexture(texture); GlStateManager.color(1, 1, 1); int u = this.u + (hovered ? width : 0); Gui.drawModalRectWithCustomSizedTexture(xPosition, yPosition, u, v, width, height, textureWidth, textureHeight); - - if(hovered && hoverKey != null) { - ReplayMod.tooltipRenderer.drawTooltip(mouseX, mouseY, I18n.format(hoverKey), null, Color.WHITE.getRGB()); - } } } + + @Override + public void draw(Minecraft mc, int mouseX, int mouseY) { + drawButton(mc, mouseX, mouseY); + } + + @Override + public void drawOverlay(Minecraft mc, int mouseX, int mouseY) { + hovered = isHovering(mouseX, mouseY); + if(hovered && hoverText != null) { + ReplayMod.tooltipRenderer.drawTooltip(mouseX, mouseY, hoverText, null, 0xffffffff); + } + } + + @Override + public void mouseClick(Minecraft mc, int mouseX, int mouseY, int button) { + if (isHovering(mouseX, mouseY)) { + performAction(); + } + } + + @Override + public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) { + + } + + @Override + public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) { + + } + + public void performAction() { + action.run(); + } } diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiTimeline.java b/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiTimeline.java index 1b5482e5..c7089d4a 100644 --- a/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiTimeline.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiTimeline.java @@ -11,7 +11,7 @@ import static eu.crushedpixel.replaymod.gui.overlay.GuiReplayOverlay.replay_gui; import static org.lwjgl.opengl.GL11.GL_BLEND; import static org.lwjgl.opengl.GL11.glEnable; -public class GuiTimeline extends Gui { +public class GuiTimeline extends Gui implements GuiElement { protected static final int TEXTURE_WIDTH = 64; protected static final int BORDER_TOP = 4; @@ -146,7 +146,10 @@ public class GuiTimeline extends Gui { rect(cursorX - 2, positionY + BORDER_TOP, 84, 20, 5, 16); } + } + @Override + public void drawOverlay(Minecraft mc, int mouseX, int mouseY) { // Draw time under cursor if the mouse is on the timeline long mouseTime = getTimeAt(mouseX, mouseY); if (mouseTime != -1) { @@ -156,6 +159,26 @@ public class GuiTimeline extends Gui { } } + @Override + public boolean isHovering(int mouseX, int mouseY) { + return getTimeAt(mouseX, mouseY) != -1; + } + + @Override + public void mouseClick(Minecraft mc, int mouseX, int mouseY, int button) { + + } + + @Override + public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) { + + } + + @Override + public void mouseRelease(Minecraft mc, int mouseX, int mouseY, int button) { + + } + protected void rect(int x, int y, int u, int v, int width, int height) { Minecraft.getMinecraft().renderEngine.bindTexture(replay_gui); glEnable(GL_BLEND); diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/overlay/GuiReplayOverlay.java b/src/main/java/eu/crushedpixel/replaymod/gui/overlay/GuiReplayOverlay.java index b83e900a..1e66b5c1 100755 --- a/src/main/java/eu/crushedpixel/replaymod/gui/overlay/GuiReplayOverlay.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/overlay/GuiReplayOverlay.java @@ -5,11 +5,7 @@ import eu.crushedpixel.replaymod.entities.CameraEntity; import eu.crushedpixel.replaymod.gui.GuiMouseInput; import eu.crushedpixel.replaymod.gui.GuiRenderSettings; import eu.crushedpixel.replaymod.gui.GuiReplaySpeedSlider; -import eu.crushedpixel.replaymod.gui.elements.GuiKeyframeTimeline; -import eu.crushedpixel.replaymod.gui.elements.GuiScrollbar; -import eu.crushedpixel.replaymod.gui.elements.GuiTexturedButton; -import eu.crushedpixel.replaymod.gui.elements.GuiTimeline; -import eu.crushedpixel.replaymod.holders.Keyframe; +import eu.crushedpixel.replaymod.gui.elements.*; import eu.crushedpixel.replaymod.holders.Position; import eu.crushedpixel.replaymod.holders.PositionKeyframe; import eu.crushedpixel.replaymod.holders.TimeKeyframe; @@ -18,7 +14,6 @@ import eu.crushedpixel.replaymod.replay.ReplayHandler; import eu.crushedpixel.replaymod.utils.MouseUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; -import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiChat; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.inventory.GuiInventory; @@ -46,8 +41,8 @@ public class GuiReplayOverlay extends Gui { public static final int TEXTURE_SIZE = 128; private static final float ZOOM_STEPS = 0.05f; - private static GuiTexturedButton texturedButton(int x, int y, int u, int v, int size, String hoverKey) { - return new GuiTexturedButton(0, x, y, size, size, replay_gui, u, v, TEXTURE_SIZE, TEXTURE_SIZE, hoverKey); + private static GuiTexturedButton texturedButton(int x, int y, int u, int v, int size, Runnable action, String hoverText) { + return new GuiTexturedButton(0, x, y, size, size, replay_gui, u, v, TEXTURE_SIZE, TEXTURE_SIZE, action, I18n.format(hoverText)); } private final int displayWidth = mc.displayWidth; @@ -73,25 +68,150 @@ public class GuiReplayOverlay extends Gui { private final int TIMELINE_REAL_X = BUTTON_TIME_X + 25; private final int TIMELINE_REAL_WIDTH = WIDTH - 14 - 11 - TIMELINE_REAL_X; - private final GuiButton buttonPlay = texturedButton(BUTTON_PLAY_PAUSE_X, TOP_ROW, 0, 0, 20, "replaymod.gui.ingame.menu.unpause"); - private final GuiButton buttonPause = texturedButton(BUTTON_PLAY_PAUSE_X, TOP_ROW, 0, 20, 20, "replaymod.gui.ingame.menu.pause"); - private final GuiButton buttonExport = texturedButton(BUTTON_EXPORT_X, BOTTOM_ROW, 40, 0, 20, "replaymod.gui.ingame.menu.renderpath"); - private final GuiButton buttonPlayPath = texturedButton(BUTTON_PLAY_PATH_X, BOTTOM_ROW, 0, 0, 20, "replaymod.gui.ingame.menu.playpath"); - private final GuiButton buttonPlace = texturedButton(BUTTON_PLACE_X, BOTTOM_ROW, 0, 40, 20, "replaymod.gui.ingame.menu.addposkeyframe"); - private final GuiButton buttonPlaceSelected = texturedButton(BUTTON_PLACE_X, BOTTOM_ROW, 0, 60, 20, "replaymod.gui.ingame.menu.removeposkeyframe"); - private final GuiButton buttonTime = texturedButton(BUTTON_TIME_X, BOTTOM_ROW, 0, 80, 20, "replaymod.gui.ingame.menu.addtimekeyframe"); - private final GuiButton buttonTimeSelected = texturedButton(BUTTON_TIME_X, BOTTOM_ROW, 0, 100, 20, "replaymod.gui.ingame.menu.removetimekeyframe"); - private final GuiButton buttonZoomIn = texturedButton(WIDTH - 14 - 9, BOTTOM_ROW, 40, 20, 9, "replaymod.gui.ingame.menu.zoomin"); - private final GuiButton buttonZoomOut = texturedButton(WIDTH - 14 - 9, BOTTOM_ROW + 11, 40, 30, 9, "replaymod.gui.ingame.menu.zoomout"); + private final GuiElement buttonPlayPause = new DelegatingElement() { + + private final GuiElement buttonPlay = texturedButton(BUTTON_PLAY_PAUSE_X, TOP_ROW, 0, 0, 20, new Runnable() { + @Override + public void run() { + ReplayMod.replaySender.setReplaySpeed(speedSlider.getSliderValue()); + } + }, "replaymod.gui.ingame.menu.unpause"); + + private final GuiElement buttonPause = texturedButton(BUTTON_PLAY_PAUSE_X, TOP_ROW, 0, 20, 20, new Runnable() { + @Override + public void run() { + ReplayMod.replaySender.setReplaySpeed(0); + } + }, "replaymod.gui.ingame.menu.pause"); + + @Override + public GuiElement delegate() { + return ReplayMod.replaySender.paused() ? buttonPlay : buttonPause; + } + }; + + private final GuiElement buttonExport = texturedButton(BUTTON_EXPORT_X, BOTTOM_ROW, 40, 0, 20, new Runnable() { + @Override + public void run() { + mc.displayGuiScreen(new GuiRenderSettings()); + } + }, "replaymod.gui.ingame.menu.renderpath"); + + private final GuiElement buttonPlayPausePath = new DelegatingElement() { + + private final GuiElement buttonPlay = texturedButton(BUTTON_PLAY_PATH_X, BOTTOM_ROW, 0, 0, 20, new Runnable() { + @Override + public void run() { + ReplayHandler.startPath(null); + + } + }, "replaymod.gui.ingame.menu.playpath"); + + private final GuiElement buttonPause = texturedButton(BUTTON_PLAY_PATH_X, BOTTOM_ROW, 0, 0, 20, new Runnable() { + @Override + public void run() { + ReplayHandler.interruptReplay(); + + } + }, "replaymod.gui.ingame.menu.pausepath"); + + @Override + public GuiElement delegate() { + return ReplayHandler.isInPath() ? buttonPause : buttonPlay; + } + }; + + private final GuiElement buttonPlace = new DelegatingElement() { + private final GuiElement buttonNotSelected = texturedButton(BUTTON_PLACE_X, BOTTOM_ROW, 0, 40, 20, new Runnable() { + @Override + public void run() { + Entity cam = mc.getRenderViewEntity(); + if (cam != null) { + Position position = new Position(cam.posX, cam.posY, cam.posZ, cam.rotationPitch, + cam.rotationYaw % 360, ReplayHandler.getCameraTilt()); + + if (ReplayHandler.isCamera()) + ReplayHandler.addKeyframe(new PositionKeyframe(ReplayHandler.getRealTimelineCursor(), position)); + else + ReplayHandler.addKeyframe(new PositionKeyframe(ReplayHandler.getRealTimelineCursor(), cam.getEntityId())); + } + } + }, "replaymod.gui.ingame.menu.addposkeyframe"); + + private final GuiElement buttonSelected = texturedButton(BUTTON_PLACE_X, BOTTOM_ROW, 0, 60, 20, new Runnable() { + @Override + public void run() { + ReplayHandler.removeKeyframe(ReplayHandler.getSelectedKeyframe()); + } + }, "replaymod.gui.ingame.menu.removeposkeyframe"); + + @Override + public GuiElement delegate() { + return ReplayHandler.getSelectedKeyframe() instanceof PositionKeyframe ? buttonSelected : buttonNotSelected; + } + }; + + private final GuiElement buttonTime = new DelegatingElement() { + + private final GuiElement buttonNotSelected = texturedButton(BUTTON_TIME_X, BOTTOM_ROW, 0, 80, 20, new Runnable() { + @Override + public void run() { + ReplayHandler.addKeyframe(new TimeKeyframe(ReplayHandler.getRealTimelineCursor(), ReplayMod.replaySender.currentTimeStamp())); + } + }, "replaymod.gui.ingame.menu.addtimekeyframe"); + + private final GuiElement buttonSelected = texturedButton(BUTTON_TIME_X, BOTTOM_ROW, 0, 100, 20, new Runnable() { + @Override + public void run() { + ReplayHandler.removeKeyframe(ReplayHandler.getSelectedKeyframe()); + } + }, "replaymod.gui.ingame.menu.removetimekeyframe"); + + @Override + public GuiElement delegate() { + return ReplayHandler.getSelectedKeyframe() instanceof TimeKeyframe ? buttonSelected : buttonNotSelected; + } + }; + + private final GuiElement buttonZoomIn = texturedButton(WIDTH - 14 - 9, BOTTOM_ROW, 40, 20, 9, new Runnable() { + @Override + public void run() { + zoom_scale = Math.max(0.025f, zoom_scale - ZOOM_STEPS); + } + }, "replaymod.gui.ingame.menu.zoomin"); + + private final GuiElement buttonZoomOut = texturedButton(WIDTH - 14 - 9, BOTTOM_ROW + 11, 40, 30, 9, new Runnable() { + + @Override + public void run() { + zoom_scale = Math.min(1f, zoom_scale + ZOOM_STEPS); + pos_left = Math.min(pos_left, 1f - zoom_scale); + } + }, "replaymod.gui.ingame.menu.zoomout"); + + private final GuiTimeline timeline = new GuiTimeline(TIMELINE_X, TOP_ROW - 1, WIDTH - 14 - TIMELINE_X) { + @Override + public void mouseClick(Minecraft mc, int mouseX, int mouseY, int button) { + performJump(timeline.getTimeAt(mouseX, mouseY)); + } + }; - private final GuiTimeline timeline = new GuiTimeline(TIMELINE_X, TOP_ROW - 1, WIDTH - 14 - TIMELINE_X); private final GuiKeyframeTimeline timelineReal = new GuiKeyframeTimeline(TIMELINE_REAL_X, BOTTOM_ROW - 1, TIMELINE_REAL_WIDTH); { timelineReal.timelineLength = 10 * 60 * 1000; } - private final GuiScrollbar scrollbar = new GuiScrollbar(TIMELINE_REAL_X, BOTTOM_ROW + 22, TIMELINE_REAL_WIDTH); - private GuiReplaySpeedSlider speedSlider = new GuiReplaySpeedSlider(1, SPEED_X, TOP_ROW, I18n.format("replaymod.gui.speed")); + private final GuiScrollbar scrollbar = new GuiScrollbar(TIMELINE_REAL_X, BOTTOM_ROW + 22, TIMELINE_REAL_WIDTH) { + @Override + public void dragged() { + pos_left = scrollbar.sliderPosition; + } + }; + + private final GuiReplaySpeedSlider speedSlider = new GuiReplaySpeedSlider(1, SPEED_X, TOP_ROW, I18n.format("replaymod.gui.speed")); + + private final GuiElement content = new ComposedElement(buttonPlayPause, buttonExport, buttonPlace, buttonTime, + buttonPlayPausePath, buttonZoomIn, buttonZoomOut, timeline, timelineReal, scrollbar, speedSlider); private float zoom_scale = 0.1f; //can see 1/10th of the timeline private double pos_left = 0f; //left border of timeline is at 0% @@ -109,8 +229,9 @@ public class GuiReplayOverlay extends Gui { mc.displayGuiScreen(null); } ReplayHandler.setRealTimelineCursor(0); - if(slider) - speedSlider = new GuiReplaySpeedSlider(1, SPEED_X, TOP_ROW, I18n.format("replaymod.gui.speed")); + if (slider) { + speedSlider.reset(); + } } public void register() { @@ -128,7 +249,7 @@ public class GuiReplayOverlay extends Gui { GuiReplayOverlay other = new GuiReplayOverlay(); other.zoom_scale = this.zoom_scale; other.pos_left = this.pos_left; - other.speedSlider = this.speedSlider; + other.speedSlider.copyValueFrom(this.speedSlider); this.unregister(); other.register(); @@ -159,90 +280,23 @@ public class GuiReplayOverlay extends Gui { checkResize(); } - public void mouseDrag(int mouseX, int mouseY) { - speedSlider.mousePressed(mc, mouseX, mouseY); - - scrollbar.doDragging(mouseX); - pos_left = scrollbar.sliderPosition; - - timelineReal.mouseDrag(mouseX, mouseY); + public void mouseDrag(int mouseX, int mouseY, int button) { + content.mouseDrag(mc, mouseX, mouseY, button); } - public void mouseReleased(int mouseX, int mouseY) { - speedSlider.mouseReleased(mouseX, mouseY); - - scrollbar.endDragging(mouseX); - pos_left = scrollbar.sliderPosition; - - timelineReal.mouseRelease(mouseX, mouseY); + public void mouseReleased(int mouseX, int mouseY, int button) { + content.mouseRelease(mc, mouseX, mouseY, button); } - public void mouseClicked(int mouseX, int mouseY) { - if (buttonPlayPath.mousePressed(mc, mouseX, mouseY)) { - if (ReplayHandler.isInPath()) { - ReplayHandler.interruptReplay(); - } else { - ReplayHandler.startPath(null); - } - } - - if (ReplayHandler.isInPath()) { - return; // Only allow clicking of cancel button during path replay - } - - if (ReplayMod.replaySender.paused()) { - if (buttonPlay.mousePressed(mc, mouseX, mouseY)) { - ReplayMod.replaySender.setReplaySpeed(speedSlider.getSliderValue()); - } + public void mouseClicked(int mouseX, int mouseY, int button) { + if (ReplayHandler.isInPath()) { // Only allow clicking of cancel button during path replay + buttonPlayPausePath.mouseClick(mc, mouseX, mouseY, button); } else { - if (buttonPause.mousePressed(mc, mouseX, mouseY)) { - ReplayMod.replaySender.setReplaySpeed(0); - } + content.mouseClick(mc, mouseX, mouseY, button); } + } - speedSlider.mousePressed(mc, mouseX, mouseY); - scrollbar.startDragging(mouseX, mouseY); - timelineReal.mouseClicked(mc, mouseX, mouseY); - - if (buttonExport.mousePressed(mc, mouseX, mouseY)) { - mc.displayGuiScreen(new GuiRenderSettings()); - } - - Keyframe keyframe = ReplayHandler.getSelectedKeyframe(); - - if (buttonPlace.mousePressed(mc, mouseX, mouseY)) { - if (keyframe instanceof PositionKeyframe) { - ReplayHandler.removeKeyframe(keyframe); - } else { - Entity cam = mc.getRenderViewEntity(); - if(cam != null) { - Position position = new Position(cam.posX, cam.posY, cam.posZ, cam.rotationPitch, - cam.rotationYaw % 360, ReplayHandler.getCameraTilt()); - - if(ReplayHandler.isCamera()) ReplayHandler.addKeyframe(new PositionKeyframe(ReplayHandler.getRealTimelineCursor(), position)); - else ReplayHandler.addKeyframe(new PositionKeyframe(ReplayHandler.getRealTimelineCursor(), cam.getEntityId())); - } - } - } - - if (buttonTime.mousePressed(mc, mouseX, mouseY)) { - if (keyframe instanceof TimeKeyframe) { - ReplayHandler.removeKeyframe(keyframe); - } else { - ReplayHandler.addKeyframe(new TimeKeyframe(ReplayHandler.getRealTimelineCursor(), ReplayMod.replaySender.currentTimeStamp())); - } - } - - if (buttonZoomIn.mousePressed(mc, mouseX, mouseY)) { - zoom_scale = Math.max(0.025f, zoom_scale - ZOOM_STEPS); - } - - if (buttonZoomOut.mousePressed(mc, mouseX, mouseY)) { - zoom_scale = Math.min(1f, zoom_scale + ZOOM_STEPS); - pos_left = Math.min(pos_left, 1f - zoom_scale); - } - - long timelineTime = timeline.getTimeAt(mouseX, mouseY); + private void performJump(long timelineTime) { if (timelineTime != -1) { // Click on timeline //When hurrying, no Timeline jumping etc. is possible if(!ReplayMod.replaySender.isHurrying()) { @@ -342,8 +396,6 @@ public class GuiReplayOverlay extends Gui { GlStateManager.resetColor(); - Keyframe keyframe = ReplayHandler.getSelectedKeyframe(); - Point mousePoint = MouseUtils.getMousePos(); int mouseX = mousePoint.getX(); int mouseY = mousePoint.getY(); @@ -354,51 +406,20 @@ public class GuiReplayOverlay extends Gui { mouseX = mouseY = -1000; } - // Draw speed slider - speedSlider.drawButton(mc, mouseX, mouseY); - - // Draw buttons - buttonExport.drawButton(mc, mouseX, mouseY); - - // Draw play/pause button - if (ReplayMod.replaySender.paused()) { - buttonPlay.drawButton(mc, mouseX, mouseY); - } else { - buttonPause.drawButton(mc, mouseX, mouseY); - } - - buttonPlayPath.drawButton(mc, mouseX, mouseY); - - // Keyframe buttons - if (keyframe instanceof PositionKeyframe) { - buttonPlaceSelected.drawButton(mc, mouseX, mouseY); - } else { - buttonPlace.drawButton(mc, mouseX, mouseY); - } - - if (keyframe instanceof TimeKeyframe) { - buttonTimeSelected.drawButton(mc, mouseX, mouseY); - } else { - buttonTime.drawButton(mc, mouseX, mouseY); - } - - buttonZoomIn.drawButton(mc, mouseX, mouseY); - buttonZoomOut.drawButton(mc, mouseX, mouseY); - - // Draw scrollbar for real timeline + // Setup scrollbar and timelines scrollbar.size = zoom_scale; scrollbar.sliderPosition = pos_left; - scrollbar.draw(mc); - // Finally draw timelines so that no other GUI elements overlap the mouse-position strings timeline.cursorPosition = ReplayMod.replaySender.currentTimeStamp(); timeline.timelineLength = ReplayMod.replaySender.replayLength(); - timeline.draw(mc, mouseX, mouseY); timelineReal.cursorPosition = ReplayHandler.getRealTimelineCursor(); timelineReal.zoom = zoom_scale; timelineReal.timeStart = pos_left; - timelineReal.draw(mc, mouseX, mouseY); + + // Draw all elements + content.draw(mc, mouseX, mouseY); + content.drawOverlay(mc, mouseX, mouseY); GlStateManager.enableBlend(); }