Tweaked GuiDropdown a bit
Continued work on GuiReplayStudio
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user