Tweaked GuiDropdown a bit
Continued work on GuiReplayStudio
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
package eu.crushedpixel.replaymod;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
@@ -14,7 +12,6 @@ import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import eu.crushedpixel.replaymod.api.client.ApiClient;
|
||||
import eu.crushedpixel.replaymod.editor.ReplayTrimmer;
|
||||
import eu.crushedpixel.replaymod.events.GuiEventHandler;
|
||||
import eu.crushedpixel.replaymod.events.GuiReplayOverlay;
|
||||
import eu.crushedpixel.replaymod.events.KeyInputHandler;
|
||||
|
||||
@@ -35,4 +35,7 @@ public class GuiConstants {
|
||||
public static final int REPLAY_EDITOR_TRIM_TAB = 5000;
|
||||
public static final int REPLAY_EDITOR_CONNECT_TAB = 5001;
|
||||
public static final int REPLAY_EDITOR_MODIFY_TAB = 5002;
|
||||
|
||||
public static final int REPLAY_EDITOR_SAVEMODE_BUTTON = 5003;
|
||||
public static final int REPLAY_EDITOR_SAVE_BUTTON = 5004;
|
||||
}
|
||||
|
||||
@@ -22,17 +22,19 @@ public class GuiDropdown extends GuiTextField {
|
||||
private final int maxDropoutHeight = dropoutElementHeight*visibleDropout;
|
||||
|
||||
private int upperIndex = 0;
|
||||
|
||||
|
||||
public GuiDropdown(int id, FontRenderer fontRenderer,
|
||||
int xPos, int yPos, int width) {
|
||||
super(id, fontRenderer, xPos, yPos, width, 20);
|
||||
setCursorPositionZero();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawTextBox() {
|
||||
|
||||
setCursorPositionZero();
|
||||
if(elements.size() > selectionIndex) {
|
||||
setText(elements.get(selectionIndex).toString());
|
||||
setText(mc.fontRendererObj.trimStringToWidth(
|
||||
elements.get(selectionIndex).toString(), width-8));
|
||||
} else {
|
||||
setText("");
|
||||
}
|
||||
@@ -47,17 +49,17 @@ public class GuiDropdown extends GuiTextField {
|
||||
drawHorizontalLine(xPosition+width-height+i+4, xPosition+width-i-4, yPosition+(height/4)+i+2, -6250336);
|
||||
}
|
||||
|
||||
if(open) {
|
||||
if(open && elements.size() > 0) {
|
||||
//draw the dropout part when opened
|
||||
|
||||
|
||||
boolean drawScrollBar = false;
|
||||
|
||||
|
||||
int requiredHeight = elements.size()*dropoutElementHeight;
|
||||
if(requiredHeight > maxDropoutHeight) {
|
||||
requiredHeight = maxDropoutHeight;
|
||||
drawScrollBar = true;
|
||||
}
|
||||
|
||||
|
||||
//The light outline
|
||||
drawRect(xPosition-1, yPosition+height, xPosition+width+1, yPosition+height+requiredHeight+1, -6250336);
|
||||
|
||||
@@ -73,7 +75,8 @@ public class GuiDropdown extends GuiTextField {
|
||||
continue;
|
||||
}
|
||||
drawHorizontalLine(xPosition, xPosition+width, yPosition+height+y, -6250336);
|
||||
drawString(mc.fontRendererObj, obj.toString(), xPosition+4, yPosition+height+y+4, Color.WHITE.getRGB());
|
||||
String toWrite = mc.fontRendererObj.trimStringToWidth(obj.toString(), width-8);
|
||||
drawString(mc.fontRendererObj, toWrite, xPosition+4, yPosition+height+y+4, Color.WHITE.getRGB());
|
||||
|
||||
y += dropoutElementHeight;
|
||||
i++;
|
||||
@@ -81,26 +84,26 @@ public class GuiDropdown extends GuiTextField {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(drawScrollBar) {
|
||||
//The scroll bar
|
||||
//The scroll bar
|
||||
int dw = Mouse.getDWheel();
|
||||
if(dw > 0) {
|
||||
dw = -1;
|
||||
} else if(dw < 0) {
|
||||
dw = 1;
|
||||
}
|
||||
|
||||
|
||||
upperIndex = Math.max(Math.min(upperIndex+dw, elements.size()-visibleDropout), 0);
|
||||
|
||||
|
||||
drawRect(xPosition+width-3, yPosition+height+1, xPosition+width, yPosition+height+requiredHeight, Color.DARK_GRAY.getRGB());
|
||||
|
||||
|
||||
float visiblePerc = ((float)visibleDropout)/elements.size();
|
||||
int barHeight = (int)(visiblePerc*(requiredHeight-1));
|
||||
|
||||
|
||||
float posPerc = ((float)upperIndex)/elements.size();
|
||||
int barY = (int)(posPerc*(requiredHeight-1));
|
||||
|
||||
|
||||
drawRect(xPosition+width-3, yPosition+height+1+barY, xPosition+width, yPosition+height+2+barY+barHeight, -6250336);
|
||||
}
|
||||
}
|
||||
@@ -111,7 +114,7 @@ public class GuiDropdown extends GuiTextField {
|
||||
if(xPos > xPosition+width-height && xPos < xPosition+width && yPos > yPosition && yPos < yPosition+height) {
|
||||
open = !open;
|
||||
} else {
|
||||
if(xPos > xPosition && xPos < xPosition+width) {
|
||||
if(xPos > xPosition && xPos < xPosition+width && open) {
|
||||
int requiredHeight = Math.min(maxDropoutHeight, elements.size()*dropoutElementHeight);
|
||||
if(yPos > yPosition+height && yPos < yPosition+height+requiredHeight) {
|
||||
int clickedIndex = (int)Math.floor((yPos - (yPosition+height)) / dropoutElementHeight) + upperIndex;
|
||||
@@ -123,7 +126,7 @@ public class GuiDropdown extends GuiTextField {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setText(String text) {
|
||||
if(!getText().equals(text)) {
|
||||
@@ -141,6 +144,10 @@ public class GuiDropdown extends GuiTextField {
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
public void clearElements() {
|
||||
this.elements = new ArrayList<Object>();
|
||||
}
|
||||
|
||||
public void addElement(Object element) {
|
||||
this.elements.add(element);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package eu.crushedpixel.replaymod.gui.replayviewer;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufInputStream;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedReader;
|
||||
@@ -24,7 +20,6 @@ import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiYesNo;
|
||||
import net.minecraft.client.gui.GuiYesNoCallback;
|
||||
import net.minecraft.client.renderer.texture.TextureUtil;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.util.Util;
|
||||
|
||||
@@ -44,9 +39,9 @@ import eu.crushedpixel.replaymod.gui.online.GuiUploadFile;
|
||||
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
||||
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
|
||||
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
|
||||
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import eu.crushedpixel.replaymod.utils.ImageUtils;
|
||||
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
||||
|
||||
public class GuiReplayViewer extends GuiScreen implements GuiYesNoCallback {
|
||||
|
||||
@@ -77,47 +72,42 @@ public class GuiReplayViewer extends GuiScreen implements GuiYesNoCallback {
|
||||
replayGuiList.clearEntries();
|
||||
replayFileList = new ArrayList<Pair<Pair<File, ReplayMetaData>, File>>();
|
||||
|
||||
File folder = new File("./replay_recordings/");
|
||||
folder.mkdirs();
|
||||
for(File file : ReplayFileIO.getAllReplayFiles()) {
|
||||
try {
|
||||
ZipFile archive = new ZipFile(file);
|
||||
ZipArchiveEntry recfile = archive.getEntry("recording"+ConnectionEventHandler.TEMP_FILE_EXTENSION);
|
||||
ZipArchiveEntry metadata = archive.getEntry("metaData"+ConnectionEventHandler.JSON_FILE_EXTENSION);
|
||||
|
||||
for(File file : folder.listFiles()) {
|
||||
if(("."+FilenameUtils.getExtension(file.getAbsolutePath())).equals(ConnectionEventHandler.ZIP_FILE_EXTENSION)) {
|
||||
try {
|
||||
ZipFile archive = new ZipFile(file);
|
||||
ZipArchiveEntry recfile = archive.getEntry("recording"+ConnectionEventHandler.TEMP_FILE_EXTENSION);
|
||||
ZipArchiveEntry metadata = archive.getEntry("metaData"+ConnectionEventHandler.JSON_FILE_EXTENSION);
|
||||
|
||||
ZipArchiveEntry image = archive.getEntry("thumb");
|
||||
BufferedImage img = null;
|
||||
if(image != null) {
|
||||
InputStream is = archive.getInputStream(image);
|
||||
is.skip(7);
|
||||
BufferedImage bimg = ImageIO.read(is);
|
||||
if(bimg != null) {
|
||||
img = ImageUtils.scaleImage(bimg, new Dimension(1280, 720));
|
||||
}
|
||||
ZipArchiveEntry image = archive.getEntry("thumb");
|
||||
BufferedImage img = null;
|
||||
if(image != null) {
|
||||
InputStream is = archive.getInputStream(image);
|
||||
is.skip(7);
|
||||
BufferedImage bimg = ImageIO.read(is);
|
||||
if(bimg != null) {
|
||||
img = ImageUtils.scaleImage(bimg, new Dimension(1280, 720));
|
||||
}
|
||||
}
|
||||
|
||||
File tmp = null;
|
||||
if(img != null) {
|
||||
tmp = File.createTempFile(FilenameUtils.getBaseName(file.getAbsolutePath()), "jpg");
|
||||
tmp.deleteOnExit();
|
||||
File tmp = null;
|
||||
if(img != null) {
|
||||
tmp = File.createTempFile(FilenameUtils.getBaseName(file.getAbsolutePath()), "jpg");
|
||||
tmp.deleteOnExit();
|
||||
|
||||
ImageIO.write(img, "jpg", tmp);
|
||||
}
|
||||
ImageIO.write(img, "jpg", tmp);
|
||||
}
|
||||
|
||||
InputStream is = archive.getInputStream(metadata);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
||||
InputStream is = archive.getInputStream(metadata);
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
||||
|
||||
String json = br.readLine();
|
||||
String json = br.readLine();
|
||||
|
||||
ReplayMetaData metaData = gson.fromJson(json, ReplayMetaData.class);
|
||||
ReplayMetaData metaData = gson.fromJson(json, ReplayMetaData.class);
|
||||
|
||||
replayFileList.add(Pair.of(Pair.of(file, metaData), tmp));
|
||||
replayFileList.add(Pair.of(Pair.of(file, metaData), tmp));
|
||||
|
||||
archive.close();
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
archive.close();
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
Collections.sort(replayFileList, new FileAgeComparator());
|
||||
|
||||
@@ -1,29 +1,49 @@
|
||||
package eu.crushedpixel.replaymod.studio;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import de.johni0702.replaystudio.studio.ReplayStudio;
|
||||
import eu.crushedpixel.replaymod.gui.GuiConstants;
|
||||
import eu.crushedpixel.replaymod.gui.GuiDropdown;
|
||||
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
||||
|
||||
public class GuiReplayStudio extends GuiScreen {
|
||||
|
||||
|
||||
private GuiDropdown replayDropdown;
|
||||
|
||||
private ReplayStudio studio = new ReplayStudio();
|
||||
|
||||
private GuiButton saveModeButton, saveButton;
|
||||
|
||||
private boolean overrideSave = false;
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
private List<File> replayFiles = new ArrayList<File>();
|
||||
|
||||
private void refreshReplayDropdown() {
|
||||
replayDropdown.clearElements();
|
||||
replayFiles = ReplayFileIO.getAllReplayFiles();
|
||||
for(File file : replayFiles) {
|
||||
String name = FilenameUtils.getBaseName(file.getAbsolutePath());
|
||||
replayDropdown.addElement(name);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
List<GuiButton> tabButtons = new ArrayList<GuiButton>();
|
||||
|
||||
|
||||
tabButtons.add(new GuiButton(GuiConstants.REPLAY_EDITOR_TRIM_TAB, 0, 0, "Trim Replay"));
|
||||
tabButtons.add(new GuiButton(GuiConstants.REPLAY_EDITOR_CONNECT_TAB, 0, 0, "Connect Replays"));
|
||||
tabButtons.add(new GuiButton(GuiConstants.REPLAY_EDITOR_MODIFY_TAB, 0, 0, "Modify Replay"));
|
||||
|
||||
|
||||
int w = this.width - 30;
|
||||
int w2 = w/tabButtons.size();
|
||||
int i = 0;
|
||||
@@ -37,18 +57,53 @@ public class GuiReplayStudio extends GuiScreen {
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if(!initialized) {
|
||||
replayDropdown = new GuiDropdown(1, fontRendererObj, 15+2+1+100, 60, this.width-30-8-100);
|
||||
refreshReplayDropdown();
|
||||
} else {
|
||||
replayDropdown.width = this.width-30-8-100;
|
||||
}
|
||||
|
||||
List<GuiButton> saveButtons = new ArrayList<GuiButton>();
|
||||
|
||||
replayDropdown = new GuiDropdown(1, fontRendererObj, 15+2+1, 60, 100);
|
||||
replayDropdown.addElement("test1");
|
||||
replayDropdown.addElement("test2");
|
||||
replayDropdown.addElement("test3");
|
||||
replayDropdown.addElement("test4");
|
||||
replayDropdown.addElement("test5");
|
||||
replayDropdown.addElement("test6");
|
||||
replayDropdown.addElement("test7");
|
||||
replayDropdown.addElement("test8");
|
||||
replayDropdown.addElement("test9");
|
||||
if(!initialized) {
|
||||
saveButtons.add(saveModeButton = new GuiButton(GuiConstants.REPLAY_EDITOR_SAVEMODE_BUTTON, 0, 0, getSaveModeLabel()));
|
||||
saveButtons.add(saveButton = new GuiButton(GuiConstants.REPLAY_EDITOR_SAVE_BUTTON, 0, 0, "Save Replay"));
|
||||
} else {
|
||||
saveButtons.add(saveModeButton);
|
||||
saveButtons.add(saveButton);
|
||||
}
|
||||
|
||||
w = this.width-30-100;
|
||||
w2 = w/saveButtons.size();
|
||||
i = 0;
|
||||
for(GuiButton b : saveButtons) {
|
||||
int x = 15+100+(w2*i);
|
||||
b.xPosition = x+2;
|
||||
b.yPosition = 90;
|
||||
b.width = w2-4;
|
||||
|
||||
buttonList.add(b);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
if(!button.enabled) return;
|
||||
if(button.id == GuiConstants.REPLAY_EDITOR_SAVEMODE_BUTTON) {
|
||||
overrideSave = !overrideSave;
|
||||
button.displayString = getSaveModeLabel();
|
||||
}
|
||||
}
|
||||
|
||||
private String getSaveModeLabel() {
|
||||
return overrideSave ? "Replace Source File" : "Save to new File";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton)
|
||||
@@ -56,13 +111,15 @@ public class GuiReplayStudio extends GuiScreen {
|
||||
replayDropdown.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
this.drawDefaultBackground();
|
||||
this.drawCenteredString(this.fontRendererObj, "Replay Studio", this.width / 2, 10, 16777215);
|
||||
this.drawString(fontRendererObj, "Replay File:", 30, 67, Color.WHITE.getRGB());
|
||||
this.drawString(fontRendererObj, "Save Mode:", 30, 97, Color.WHITE.getRGB());
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
replayDropdown.drawTextBox();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user