Rewrite thumbnail creation

This commit is contained in:
johni0702
2015-10-04 15:43:19 +02:00
parent 3c3cf3317a
commit 213c16c81d
5 changed files with 145 additions and 100 deletions

View File

@@ -1,18 +1,17 @@
package eu.crushedpixel.replaymod.gui.online;
import com.google.common.base.Optional;
import com.replaymod.core.ReplayMod;
import com.replaymod.replay.gui.screen.GuiReplayViewer;
import de.johni0702.replaystudio.replay.ReplayFile;
import de.johni0702.replaystudio.replay.ReplayMetaData;
import de.johni0702.replaystudio.replay.ZipReplayFile;
import de.johni0702.replaystudio.studio.ReplayStudio;
import com.replaymod.core.ReplayMod;
import eu.crushedpixel.replaymod.api.replay.FileUploader;
import eu.crushedpixel.replaymod.api.replay.holders.Category;
import eu.crushedpixel.replaymod.gui.GuiConstants;
import eu.crushedpixel.replaymod.gui.elements.*;
import eu.crushedpixel.replaymod.gui.elements.listeners.ProgressUpdateListener;
import com.replaymod.replay.gui.screen.GuiReplayViewer;
import eu.crushedpixel.replaymod.registry.KeybindRegistry;
import eu.crushedpixel.replaymod.registry.ResourceHelper;
import eu.crushedpixel.replaymod.utils.ImageUtils;
import eu.crushedpixel.replaymod.utils.MouseUtils;
@@ -359,7 +358,7 @@ public class GuiUploadFile extends GuiScreen implements ProgressUpdateListener {
Gui.drawScaledCustomSizeModalRect(columnRight, 20, 0, 0, 1280, 720, columnWidth, height, 1280, 720);
if (!hasThumbnail) {
KeyBinding keyBinding = KeybindRegistry.getKeyBinding(KeybindRegistry.KEY_THUMBNAIL);
KeyBinding keyBinding = ReplayMod.instance.getKeyBindingRegistry().getKeyBindings().get("replaymod.input.thumbnail");
String str = I18n.format("replaymod.gui.upload.nothumbnail",
keyBinding == null ? "???" : GameSettings.getKeyDisplayString(keyBinding.getKeyCode()));
int y = 20 + height + 10;

View File

@@ -47,7 +47,6 @@ public class KeybindRegistry {
replayModKeyBindings.add(new KeyBinding(KEY_SYNC_TIMELINE, Keyboard.KEY_V, "replaymod.title"));
replayModKeyBindings.add(new KeyBinding(KEY_THUMBNAIL, Keyboard.KEY_N, "replaymod.title"));
replayModKeyBindings.add(new KeyBinding(KEY_PLAYER_OVERVIEW, Keyboard.KEY_B, "replaymod.title"));
replayModKeyBindings.add(new KeyBinding(KEY_LIGHTING, Keyboard.KEY_Z, "replaymod.title"));

View File

@@ -1,95 +0,0 @@
package eu.crushedpixel.replaymod.video;
import com.replaymod.core.ReplayMod;
import eu.crushedpixel.replaymod.chat.ChatMessageHandler.ChatMessageType;
import eu.crushedpixel.replaymod.events.handlers.TickAndRenderListener;
import eu.crushedpixel.replaymod.utils.ImageUtils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import java.awt.*;
import java.awt.image.BufferedImage;
public class ReplayScreenshot {
private static Minecraft mc = Minecraft.getMinecraft();
private static boolean before;
private static double beforeSpeed;
private static GuiScreen beforeScreen;
private static boolean locked = false;
public static void prepareScreenshot() {
before = mc.gameSettings.hideGUI;
beforeSpeed = ReplayMod.replaySender.getReplaySpeed();
beforeScreen = mc.currentScreen;
}
public static void saveScreenshot() {
if(locked) return;
locked = true;
try {
mc.gameSettings.hideGUI = true;
mc.currentScreen = null;
mc.entityRenderer.updateCameraAndRender(0);
ReplayMod.replaySender.setReplaySpeed(0);
final BufferedImage fbi = ScreenCapture.captureScreen();
mc.gameSettings.hideGUI = before;
mc.currentScreen = beforeScreen;
ReplayMod.replaySender.setReplaySpeed(beforeSpeed);
//The actual cropping and saving should be executed in a separate thread
Thread ioThread = new Thread(new Runnable() {
@Override
public void run() {
try {
float aspect = 16f/9f;
Rectangle rect;
if((float) fbi.getWidth() / (float) fbi.getHeight() <= aspect) {
int h = Math.round(fbi.getWidth() / aspect);
int y = (fbi.getHeight() / 2) - (h / 2);
rect = new Rectangle(0, y, fbi.getWidth(), h);
} else {
int w = Math.round(fbi.getHeight() * aspect);
int x = (fbi.getWidth() / 2) - (w / 2);
rect = new Rectangle(x, 0, w, fbi.getHeight());
}
final BufferedImage nbi = ImageUtils.cropImage(fbi, rect);
int h = 720;
int w = 1280;
BufferedImage img = ImageUtils.scaleImage(nbi, new Dimension(w, h));
// TODO
// ReplayHandler.getReplayFile().writeThumb(img);
ReplayMod.chatMessageHandler.addLocalizedChatMessage("replaymod.chat.savedthumb", ChatMessageType.INFORMATION);
} catch(Exception e) {
e.printStackTrace();
} finally {
locked = false;
TickAndRenderListener.finishScreenshot();
}
}
}, "replaymod-screenshot-saver");
ioThread.start();
} catch(Exception exception) {
exception.printStackTrace();
mc.gameSettings.hideGUI = before;
mc.currentScreen = beforeScreen;
ReplayMod.replaySender.setReplaySpeed(beforeSpeed);
exception.printStackTrace();
ReplayMod.chatMessageHandler.addLocalizedChatMessage("replaymod.chat.failedthumb", ChatMessageType.WARNING);
}
}
}