Added post-screenshot GUI
This commit is contained in:
@@ -45,6 +45,7 @@ public class ReplayModExtras {
|
|||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
public void preInit(FMLPreInitializationEvent event) {
|
public void preInit(FMLPreInitializationEvent event) {
|
||||||
LOGGER = event.getModLog();
|
LOGGER = event.getModLog();
|
||||||
|
ReplayMod.instance.getSettingsRegistry().register(Setting.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mod.EventHandler
|
@Mod.EventHandler
|
||||||
|
|||||||
8
src/main/java/com/replaymod/extras/Setting.java
Normal file
8
src/main/java/com/replaymod/extras/Setting.java
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package com.replaymod.extras;
|
||||||
|
|
||||||
|
import com.replaymod.core.SettingsRegistry;
|
||||||
|
|
||||||
|
public final class Setting<T> {
|
||||||
|
public static final SettingsRegistry.SettingKey<Boolean> SKIP_POST_SCREENSHOT_GUI =
|
||||||
|
new SettingsRegistry.SettingKeys<>("advanced", "skipPostScreenshotGui", null, false);
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import com.replaymod.render.RenderSettings;
|
|||||||
import com.replaymod.render.capturer.RenderInfo;
|
import com.replaymod.render.capturer.RenderInfo;
|
||||||
import com.replaymod.render.hooks.ChunkLoadingRenderGlobal;
|
import com.replaymod.render.hooks.ChunkLoadingRenderGlobal;
|
||||||
import com.replaymod.render.rendering.Pipelines;
|
import com.replaymod.render.rendering.Pipelines;
|
||||||
|
import com.replaymod.replay.ReplayModReplay;
|
||||||
import com.replaymod.replay.events.ReplayDispatchKeypressesEvent;
|
import com.replaymod.replay.events.ReplayDispatchKeypressesEvent;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiControls;
|
import net.minecraft.client.gui.GuiControls;
|
||||||
@@ -21,73 +22,80 @@ import java.io.File;
|
|||||||
|
|
||||||
public class AdvancedScreenshots implements Extra {
|
public class AdvancedScreenshots implements Extra {
|
||||||
|
|
||||||
|
private ReplayMod mod;
|
||||||
|
|
||||||
private final Minecraft mc = Minecraft.getMinecraft();
|
private final Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void register(ReplayMod mod) throws Exception {
|
public void register(ReplayMod mod) throws Exception {
|
||||||
|
this.mod = mod;
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onDispatchKeypresses(ReplayDispatchKeypressesEvent.Pre event) {
|
public void onDispatchKeypresses(ReplayDispatchKeypressesEvent.Pre event) {
|
||||||
int i = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() : Keyboard.getEventKey();
|
int keyCode = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() : Keyboard.getEventKey();
|
||||||
|
|
||||||
// all the conditions required to trigger a screenshot condensed in a single if statement
|
// all the conditions required to trigger a screenshot condensed in a single if statement
|
||||||
if (i != 0 && !Keyboard.isRepeatEvent()
|
if (keyCode != 0 && !Keyboard.isRepeatEvent()
|
||||||
&& (!(mc.currentScreen instanceof GuiControls) || ((GuiControls) mc.currentScreen).time <= mc.getSystemTime() - 20L)
|
&& (!(mc.currentScreen instanceof GuiControls) || ((GuiControls) mc.currentScreen).time <= mc.getSystemTime() - 20L)
|
||||||
&& Keyboard.getEventKeyState()
|
&& Keyboard.getEventKeyState()
|
||||||
&& i == mc.gameSettings.keyBindScreenshot.getKeyCode()) {
|
&& keyCode == mc.gameSettings.keyBindScreenshot.getKeyCode()) {
|
||||||
|
|
||||||
if (GuiScreen.isCtrlKeyDown()) {
|
if (GuiScreen.isCtrlKeyDown()) {
|
||||||
ReplayMod.instance.runLater(() -> {
|
ReplayMod.instance.runLater(this::createEquirectangularScreenshot);
|
||||||
// take 360° screenshot
|
|
||||||
File screenshotFolder = new File(mc.mcDataDir, "screenshots");
|
|
||||||
screenshotFolder.mkdir();
|
|
||||||
File screenshotFile = ScreenShotHelper.getTimestampedPNGFileForDirectory(screenshotFolder);
|
|
||||||
|
|
||||||
int width = 8640;
|
|
||||||
int height = 4320;
|
|
||||||
|
|
||||||
int displayWidthBefore = mc.displayWidth;
|
|
||||||
int displayHeightBefore = mc.displayHeight;
|
|
||||||
|
|
||||||
ChunkLoadingRenderGlobal clrg = new ChunkLoadingRenderGlobal(mc.renderGlobal);
|
|
||||||
|
|
||||||
Pipelines.newEquirectangularPipeline(new RenderInfo() {
|
|
||||||
@Override
|
|
||||||
public ReadableDimension getFrameSize() {
|
|
||||||
return new Dimension(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getTotalFrames() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public float updateForNextFrame() {
|
|
||||||
return mc.timer.renderPartialTicks;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public RenderSettings getRenderSettings() {
|
|
||||||
return new RenderSettings(
|
|
||||||
null, null, width, height, 0, 0, null,
|
|
||||||
true, true, true, true, null,
|
|
||||||
false, RenderSettings.AntiAliasing.NONE, null, null, false
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}, new ScreenshotWriter(screenshotFile)).run();
|
|
||||||
|
|
||||||
clrg.uninstall();
|
|
||||||
|
|
||||||
// the Equirectangular rendering changes mc.displayWidth and mc.displayHeight,
|
|
||||||
// so we have to reset it to the previous value
|
|
||||||
mc.resize(displayWidthBefore, displayHeightBefore);
|
|
||||||
});
|
|
||||||
|
|
||||||
event.setCanceled(true);
|
event.setCanceled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createEquirectangularScreenshot() {
|
||||||
|
// take 360° screenshot
|
||||||
|
File screenshotFolder = new File(mc.mcDataDir, "screenshots");
|
||||||
|
screenshotFolder.mkdir();
|
||||||
|
File screenshotFile = ScreenShotHelper.getTimestampedPNGFileForDirectory(screenshotFolder);
|
||||||
|
|
||||||
|
int width = 8640;
|
||||||
|
int height = 4320;
|
||||||
|
|
||||||
|
int displayWidthBefore = mc.displayWidth;
|
||||||
|
int displayHeightBefore = mc.displayHeight;
|
||||||
|
|
||||||
|
ChunkLoadingRenderGlobal clrg = new ChunkLoadingRenderGlobal(mc.renderGlobal);
|
||||||
|
|
||||||
|
Pipelines.newEquirectangularPipeline(new RenderInfo() {
|
||||||
|
@Override
|
||||||
|
public ReadableDimension getFrameSize() {
|
||||||
|
return new Dimension(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getTotalFrames() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float updateForNextFrame() {
|
||||||
|
return mc.timer.renderPartialTicks;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RenderSettings getRenderSettings() {
|
||||||
|
return new RenderSettings(
|
||||||
|
null, null, width, height, 0, 0, null,
|
||||||
|
true, true, true, true, null,
|
||||||
|
false, RenderSettings.AntiAliasing.NONE, null, null, false
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, new ScreenshotWriter(screenshotFile)).run();
|
||||||
|
|
||||||
|
clrg.uninstall();
|
||||||
|
|
||||||
|
// the Equirectangular rendering changes mc.displayWidth and mc.displayHeight,
|
||||||
|
// so we have to reset it to the previous value
|
||||||
|
mc.resize(displayWidthBefore, displayHeightBefore);
|
||||||
|
|
||||||
|
new GuiUploadScreenshot(ReplayModReplay.instance.getReplayHandler().getOverlay(), mod, screenshotFile).open();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
package com.replaymod.extras.advancedscreenshots;
|
||||||
|
|
||||||
|
import com.replaymod.core.ReplayMod;
|
||||||
|
import com.replaymod.core.SettingsRegistry;
|
||||||
|
import com.replaymod.extras.Setting;
|
||||||
|
import de.johni0702.minecraft.gui.container.GuiContainer;
|
||||||
|
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||||
|
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||||
|
import de.johni0702.minecraft.gui.element.GuiCheckbox;
|
||||||
|
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||||
|
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||||
|
import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||||
|
import de.johni0702.minecraft.gui.popup.AbstractGuiPopup;
|
||||||
|
import org.lwjgl.util.ReadableColor;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
public class GuiUploadScreenshot extends AbstractGuiPopup<GuiUploadScreenshot> {
|
||||||
|
|
||||||
|
public final ReplayMod mod;
|
||||||
|
|
||||||
|
public final File screenshotFile;
|
||||||
|
|
||||||
|
public final GuiLabel successLabel = new GuiLabel()
|
||||||
|
.setI18nText("replaymod.gui.advancedscreenshots.finished.description.360")
|
||||||
|
.setColor(ReadableColor.BLACK);
|
||||||
|
|
||||||
|
public final GuiLabel veerLabel = new GuiLabel()
|
||||||
|
.setI18nText("replaymod.gui.advancedscreenshots.finished.description.veer")
|
||||||
|
.setColor(ReadableColor.BLACK);
|
||||||
|
|
||||||
|
public final GuiButton veerUploadButton = new GuiButton()
|
||||||
|
.setSize(150, 20)
|
||||||
|
.setI18nLabel("replaymod.gui.advancedscreenshots.finished.upload.veer");
|
||||||
|
|
||||||
|
public final GuiButton showOnDiskButton = new GuiButton()
|
||||||
|
.setSize(150, 20)
|
||||||
|
.setI18nLabel("replaymod.gui.advancedscreenshots.finished.showfile");
|
||||||
|
|
||||||
|
public final GuiButton closeButton = new GuiButton()
|
||||||
|
.setSize(150, 20)
|
||||||
|
.setI18nLabel("replaymod.gui.close");
|
||||||
|
|
||||||
|
public final GuiCheckbox neverOpenCheckbox = new GuiCheckbox();
|
||||||
|
|
||||||
|
public final GuiLabel neverOpenLabel = new GuiLabel()
|
||||||
|
.setI18nText("replaymod.gui.notagain")
|
||||||
|
.setColor(ReadableColor.BLACK);
|
||||||
|
|
||||||
|
public final GuiPanel checkboxPanel = GuiPanel.builder()
|
||||||
|
.layout(new HorizontalLayout(HorizontalLayout.Alignment.RIGHT).setSpacing(5))
|
||||||
|
.with(neverOpenCheckbox, new HorizontalLayout.Data(0.5))
|
||||||
|
.with(neverOpenLabel, new HorizontalLayout.Data(0.5))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
public GuiUploadScreenshot(GuiContainer container, ReplayMod mod, File screenshotFile) {
|
||||||
|
super(container);
|
||||||
|
this.mod = mod;
|
||||||
|
this.screenshotFile = screenshotFile;
|
||||||
|
|
||||||
|
veerUploadButton.onClick(() -> {
|
||||||
|
try {
|
||||||
|
Desktop.getDesktop().browse(URI.create("https://veer.tv/upload"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
showOnDiskButton.onClick(() -> {
|
||||||
|
try {
|
||||||
|
Desktop.getDesktop().browse(URI.create("file://" + screenshotFile.getAbsolutePath()));
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
closeButton.onClick(() -> {
|
||||||
|
if (neverOpenCheckbox.isChecked()) {
|
||||||
|
SettingsRegistry settingsRegistry = mod.getSettingsRegistry();
|
||||||
|
settingsRegistry.set(Setting.SKIP_POST_SCREENSHOT_GUI, true);
|
||||||
|
settingsRegistry.save();
|
||||||
|
}
|
||||||
|
close();
|
||||||
|
});
|
||||||
|
|
||||||
|
popup.addElements(new VerticalLayout.Data(0.5),
|
||||||
|
successLabel,
|
||||||
|
veerLabel,
|
||||||
|
veerUploadButton,
|
||||||
|
showOnDiskButton,
|
||||||
|
closeButton);
|
||||||
|
|
||||||
|
popup.addElements(new VerticalLayout.Data(1),
|
||||||
|
checkboxPanel);
|
||||||
|
|
||||||
|
popup.setLayout(new VerticalLayout().setSpacing(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void open() {
|
||||||
|
if (mod.getSettingsRegistry().get(Setting.SKIP_POST_SCREENSHOT_GUI)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected GuiUploadScreenshot getThis() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,8 @@ package com.replaymod.replay.events;
|
|||||||
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
import net.minecraftforge.fml.common.eventhandler.Cancelable;
|
||||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||||
|
|
||||||
@Cancelable
|
|
||||||
public abstract class ReplayDispatchKeypressesEvent extends Event {
|
public abstract class ReplayDispatchKeypressesEvent extends Event {
|
||||||
|
|
||||||
|
@Cancelable
|
||||||
public static class Pre extends ReplayDispatchKeypressesEvent {}
|
public static class Pre extends ReplayDispatchKeypressesEvent {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user