Added post-screenshot GUI
This commit is contained in:
@@ -45,6 +45,7 @@ public class ReplayModExtras {
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
LOGGER = event.getModLog();
|
||||
ReplayMod.instance.getSettingsRegistry().register(Setting.class);
|
||||
}
|
||||
|
||||
@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.hooks.ChunkLoadingRenderGlobal;
|
||||
import com.replaymod.render.rendering.Pipelines;
|
||||
import com.replaymod.replay.ReplayModReplay;
|
||||
import com.replaymod.replay.events.ReplayDispatchKeypressesEvent;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiControls;
|
||||
@@ -21,25 +22,35 @@ import java.io.File;
|
||||
|
||||
public class AdvancedScreenshots implements Extra {
|
||||
|
||||
private ReplayMod mod;
|
||||
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
@Override
|
||||
public void register(ReplayMod mod) throws Exception {
|
||||
this.mod = mod;
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
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
|
||||
if (i != 0 && !Keyboard.isRepeatEvent()
|
||||
if (keyCode != 0 && !Keyboard.isRepeatEvent()
|
||||
&& (!(mc.currentScreen instanceof GuiControls) || ((GuiControls) mc.currentScreen).time <= mc.getSystemTime() - 20L)
|
||||
&& Keyboard.getEventKeyState()
|
||||
&& i == mc.gameSettings.keyBindScreenshot.getKeyCode()) {
|
||||
&& keyCode == mc.gameSettings.keyBindScreenshot.getKeyCode()) {
|
||||
|
||||
if (GuiScreen.isCtrlKeyDown()) {
|
||||
ReplayMod.instance.runLater(() -> {
|
||||
ReplayMod.instance.runLater(this::createEquirectangularScreenshot);
|
||||
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createEquirectangularScreenshot() {
|
||||
// take 360° screenshot
|
||||
File screenshotFolder = new File(mc.mcDataDir, "screenshots");
|
||||
screenshotFolder.mkdir();
|
||||
@@ -84,10 +95,7 @@ public class AdvancedScreenshots implements Extra {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
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.Event;
|
||||
|
||||
@Cancelable
|
||||
public abstract class ReplayDispatchKeypressesEvent extends Event {
|
||||
|
||||
@Cancelable
|
||||
public static class Pre extends ReplayDispatchKeypressesEvent {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user