Pushed missing files
Started adding Replay Editor using johni0702's excellent ReplayStudio Library Added fully functional GuiDropdown GUI Element (useable in other projects as well)
This commit is contained in:
@@ -24,11 +24,15 @@ public class GuiConstants {
|
||||
public static final int REPLAY_OPTIONS_BUTTON_ID = 8000;
|
||||
|
||||
public static final int REPLAY_MANAGER_BUTTON_ID = 9001;
|
||||
|
||||
public static final int REPLAY_CENTER_BUTTON_ID = 1000;
|
||||
public static final int REPLAY_CENTER_LOGIN_TEXT_ID = 1001;
|
||||
public static final int REPLAY_CENTER_PASSWORD_TEXT_ID = 1002;
|
||||
public static final int REPLAY_EDITOR_BUTTON_ID = 9002;
|
||||
public static final int REPLAY_CENTER_BUTTON_ID = 9003;
|
||||
public static final int REPLAY_CENTER_LOGIN_TEXT_ID = 9004;
|
||||
public static final int REPLAY_CENTER_PASSWORD_TEXT_ID = 9005;
|
||||
|
||||
public static final int LOGIN_OKAY_BUTTON = 1100;
|
||||
public static final int LOGIN_CANCEL_BUTTON = 1101;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
156
src/main/java/eu/crushedpixel/replaymod/gui/GuiDropdown.java
Normal file
156
src/main/java/eu/crushedpixel/replaymod/gui/GuiDropdown.java
Normal file
@@ -0,0 +1,156 @@
|
||||
package eu.crushedpixel.replaymod.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
|
||||
public class GuiDropdown extends GuiTextField {
|
||||
|
||||
private int selectionIndex = 0;
|
||||
private boolean open = false;
|
||||
|
||||
private Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private final int visibleDropout = 5;
|
||||
private final int dropoutElementHeight = 14;
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawTextBox() {
|
||||
|
||||
if(elements.size() > selectionIndex) {
|
||||
setText(elements.get(selectionIndex).toString());
|
||||
} else {
|
||||
setText("");
|
||||
}
|
||||
super.drawTextBox();
|
||||
|
||||
//Draw the right part of the Dropdown
|
||||
drawRect(xPosition+width-height, yPosition, xPosition+width, yPosition+height, -16777216);
|
||||
drawRect(xPosition+width-height, yPosition, this.xPosition+width-height+1, yPosition+height, -6250336);
|
||||
|
||||
//heroically draw the triangle line by line instead of using a texture
|
||||
for(int i=0; i<=Math.ceil(height/2)-4; i++) {
|
||||
drawHorizontalLine(xPosition+width-height+i+4, xPosition+width-i-4, yPosition+(height/4)+i+2, -6250336);
|
||||
}
|
||||
|
||||
if(open) {
|
||||
//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);
|
||||
|
||||
//The dark inside
|
||||
drawRect(xPosition, yPosition+height+1, xPosition+width, yPosition+height+requiredHeight, -16777216);
|
||||
|
||||
//The elements
|
||||
int y = 0;
|
||||
int i = 0;
|
||||
for(Object obj : elements) {
|
||||
if(i<upperIndex) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
drawHorizontalLine(xPosition, xPosition+width, yPosition+height+y, -6250336);
|
||||
drawString(mc.fontRendererObj, obj.toString(), xPosition+4, yPosition+height+y+4, Color.WHITE.getRGB());
|
||||
|
||||
y += dropoutElementHeight;
|
||||
i++;
|
||||
if(y >= requiredHeight) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(drawScrollBar) {
|
||||
//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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int xPos, int yPos, int mouseButton) {
|
||||
if(xPos > xPosition+width-height && xPos < xPosition+width && yPos > yPosition && yPos < yPosition+height) {
|
||||
open = !open;
|
||||
} else {
|
||||
if(xPos > xPosition && xPos < xPosition+width) {
|
||||
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;
|
||||
this.selectionIndex = clickedIndex;
|
||||
}
|
||||
open = false;
|
||||
} else {
|
||||
open = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(String text) {
|
||||
if(!getText().equals(text)) {
|
||||
super.setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
private List<Object> elements = new ArrayList<Object>();
|
||||
|
||||
private void select(int index) {
|
||||
this.selectionIndex = index;
|
||||
}
|
||||
|
||||
public void setElements(List<Object> elements) {
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
public void addElement(Object element) {
|
||||
this.elements.add(element);
|
||||
}
|
||||
|
||||
public Object getElement(int index) {
|
||||
return elements.get(index);
|
||||
}
|
||||
|
||||
public int getSelectionIndex() {
|
||||
return selectionIndex;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -17,7 +17,7 @@ import net.minecraft.client.gui.GuiListExtended.IGuiListEntry;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
|
||||
import eu.crushedpixel.replaymod.gui.replaymanager.ResourceHelper;
|
||||
import eu.crushedpixel.replaymod.utils.ResourceHelper;
|
||||
|
||||
public class GuiReplayListEntry implements IGuiListEntry {
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package eu.crushedpixel.replaymod.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import eu.crushedpixel.replaymod.gui.replaymanager.GuiReplayManager;
|
||||
import eu.crushedpixel.replaymod.gui.replayviewer.GuiReplayViewer;
|
||||
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiIngameMenu;
|
||||
|
||||
@@ -22,7 +22,7 @@ import eu.crushedpixel.replaymod.api.client.SearchQuery;
|
||||
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
|
||||
import eu.crushedpixel.replaymod.gui.GuiConstants;
|
||||
import eu.crushedpixel.replaymod.gui.GuiReplayListExtended;
|
||||
import eu.crushedpixel.replaymod.gui.replaymanager.GuiReplayManager;
|
||||
import eu.crushedpixel.replaymod.gui.replayviewer.GuiReplayViewer;
|
||||
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
||||
|
||||
public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
||||
@@ -127,7 +127,7 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
||||
} else if(button.id == GuiConstants.CENTER_LOGOUT_BUTTON) {
|
||||
mc.displayGuiScreen(getYesNoGui(this, LOGOUT_CALLBACK_ID));
|
||||
} else if(button.id == GuiConstants.CENTER_MANAGER_BUTTON) {
|
||||
mc.displayGuiScreen(new GuiReplayManager());
|
||||
mc.displayGuiScreen(new GuiReplayViewer());
|
||||
} else if(button.id == GuiConstants.CENTER_RECENT_BUTTON) {
|
||||
showOnlineRecent();
|
||||
} else if(button.id == GuiConstants.CENTER_BEST_BUTTON) {
|
||||
|
||||
@@ -35,12 +35,12 @@ import eu.crushedpixel.replaymod.api.client.ApiException;
|
||||
import eu.crushedpixel.replaymod.api.client.FileUploader;
|
||||
import eu.crushedpixel.replaymod.api.client.holders.Category;
|
||||
import eu.crushedpixel.replaymod.gui.GuiConstants;
|
||||
import eu.crushedpixel.replaymod.gui.replaymanager.ResourceHelper;
|
||||
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.utils.ImageUtils;
|
||||
import eu.crushedpixel.replaymod.utils.ResourceHelper;
|
||||
|
||||
public class GuiUploadFile extends GuiScreen {
|
||||
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.gui.replaymanager;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class ResourceHelper {
|
||||
|
||||
private static BufferedImage defaultThumb;
|
||||
|
||||
static {
|
||||
try {
|
||||
defaultThumb = ImageIO.read(MCPNames.class.getClassLoader().getResourceAsStream("default_thumb.jpg"));
|
||||
} catch(Exception e) {
|
||||
defaultThumb = new BufferedImage(1, 1, BufferedImage.TYPE_3BYTE_BGR);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private static List<ResourceLocation> openResources = new ArrayList<ResourceLocation>();
|
||||
|
||||
public static void registerResource(ResourceLocation loc) {
|
||||
openResources.add(loc);
|
||||
}
|
||||
|
||||
public static void freeResource(ResourceLocation loc) {
|
||||
Minecraft.getMinecraft().getTextureManager().deleteTexture(loc);
|
||||
openResources.remove(loc);
|
||||
}
|
||||
|
||||
public static void freeAllResources() {
|
||||
for(ResourceLocation loc : openResources) {
|
||||
Minecraft.getMinecraft().getTextureManager().deleteTexture(loc);
|
||||
}
|
||||
|
||||
openResources = new ArrayList<ResourceLocation>();
|
||||
}
|
||||
|
||||
public static BufferedImage getDefaultThumbnail() {
|
||||
return defaultThumb;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package eu.crushedpixel.replaymod.gui.replaymanager;
|
||||
package eu.crushedpixel.replaymod.gui.replayviewer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -1,4 +1,4 @@
|
||||
package eu.crushedpixel.replaymod.gui.replaymanager;
|
||||
package eu.crushedpixel.replaymod.gui.replayviewer;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufInputStream;
|
||||
@@ -48,7 +48,7 @@ import eu.crushedpixel.replaymod.reflection.MCPNames;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import eu.crushedpixel.replaymod.utils.ImageUtils;
|
||||
|
||||
public class GuiReplayManager extends GuiScreen implements GuiYesNoCallback {
|
||||
public class GuiReplayViewer extends GuiScreen implements GuiYesNoCallback {
|
||||
|
||||
private GuiScreen parentScreen;
|
||||
private GuiButton btnEditServer;
|
||||
@@ -144,7 +144,7 @@ public class GuiReplayManager extends GuiScreen implements GuiYesNoCallback {
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
replayGuiList = new ReplayManagerReplayList(this, this.mc, this.width, this.height, 32, this.height - 64, 36);
|
||||
replayGuiList = new ReplayList(this, this.mc, this.width, this.height, 32, this.height - 64, 36);
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
this.buttonList.clear();
|
||||
|
||||
@@ -193,7 +193,7 @@ public class GuiReplayManager extends GuiScreen implements GuiYesNoCallback {
|
||||
this.hoveringText = null;
|
||||
this.drawDefaultBackground();
|
||||
this.replayGuiList.drawScreen(mouseX, mouseY, partialTicks);
|
||||
this.drawCenteredString(this.fontRendererObj, I18n.format("Replay Manager", new Object[0]), this.width / 2, 20, 16777215);
|
||||
this.drawCenteredString(this.fontRendererObj, "Replay Viewer", this.width / 2, 20, 16777215);
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package eu.crushedpixel.replaymod.gui.replaymanager;
|
||||
package eu.crushedpixel.replaymod.gui.replayviewer;
|
||||
|
||||
import eu.crushedpixel.replaymod.gui.GuiReplayListExtended;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public class ReplayManagerReplayList extends GuiReplayListExtended {
|
||||
public class ReplayList extends GuiReplayListExtended {
|
||||
|
||||
private GuiReplayManager parent;
|
||||
private GuiReplayViewer parent;
|
||||
|
||||
public ReplayManagerReplayList(GuiReplayManager parent, Minecraft mcIn,
|
||||
public ReplayList(GuiReplayViewer parent, Minecraft mcIn,
|
||||
int p_i45010_2_, int p_i45010_3_, int p_i45010_4_, int p_i45010_5_,
|
||||
int p_i45010_6_) {
|
||||
super(mcIn, p_i45010_2_, p_i45010_3_, p_i45010_4_, p_i45010_5_,
|
||||
Reference in New Issue
Block a user