Created fully functional scrollable List GUI Element
Added GuiConnect Tab to Replay Studio
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
package eu.crushedpixel.replaymod.gui.replaystudio;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import eu.crushedpixel.replaymod.gui.GuiEntryList;
|
||||
|
||||
public class GuiConnectPart extends GuiStudioPart {
|
||||
|
||||
private Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private static final String DESCRIPTION = "Connects multiple Replays in the same order as the list.";
|
||||
private static final String TITLE = "Connect Replays";
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
private GuiEntryList concatList;
|
||||
|
||||
public GuiConnectPart(int yPos) {
|
||||
super(yPos);
|
||||
fontRendererObj = mc.fontRendererObj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFilters() {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return DESCRIPTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return TITLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
if(!initialized) {
|
||||
concatList = new GuiEntryList(1, fontRendererObj, 30, yPos, 200, 0);
|
||||
concatList.addElement(FilenameUtils.getBaseName(GuiReplayStudio.instance.getSelectedFile().getAbsolutePath()));
|
||||
|
||||
concatList.addElement("test1");
|
||||
concatList.addElement("test2");
|
||||
concatList.addElement("test3");
|
||||
concatList.addElement("test4");
|
||||
concatList.addElement("test5");
|
||||
concatList.addElement("test6");
|
||||
concatList.addElement("test7");
|
||||
concatList.addElement("test8");
|
||||
concatList.addElement("test9");
|
||||
concatList.addElement("test10");
|
||||
concatList.addElement("test11");
|
||||
}
|
||||
int h = GuiReplayStudio.instance.height-yPos-20;
|
||||
int rows = (int)(h / (float)GuiEntryList.elementHeight);
|
||||
concatList.setVisibleElements(rows);
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
concatList.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
concatList.drawTextBox();
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
if(!initialized) initGui();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(char typedChar, int keyCode) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -18,22 +18,30 @@ import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
||||
|
||||
public class GuiReplayStudio extends GuiScreen {
|
||||
|
||||
public static GuiReplayStudio instance = null;
|
||||
|
||||
private static final int tabYPos = 110;
|
||||
|
||||
private enum StudioTab {
|
||||
TRIM(new GuiTrimPart(110)), CONNECT(null), MODIFY(null);
|
||||
|
||||
TRIM(new GuiTrimPart(tabYPos)), CONNECT(new GuiConnectPart(tabYPos)), MODIFY(new GuiConnectPart(tabYPos));
|
||||
|
||||
private GuiStudioPart studioPart;
|
||||
|
||||
|
||||
public GuiStudioPart getStudioPart() {
|
||||
return studioPart;
|
||||
}
|
||||
|
||||
|
||||
private StudioTab(GuiStudioPart part) {
|
||||
this.studioPart = part;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public GuiReplayStudio() {
|
||||
instance = this;
|
||||
}
|
||||
|
||||
private StudioTab currentTab = StudioTab.TRIM;
|
||||
|
||||
|
||||
private GuiDropdown replayDropdown;
|
||||
private GuiButton saveModeButton, saveButton;
|
||||
|
||||
@@ -43,6 +51,14 @@ public class GuiReplayStudio extends GuiScreen {
|
||||
|
||||
private List<File> replayFiles = new ArrayList<File>();
|
||||
|
||||
public File getSelectedFile() {
|
||||
try {
|
||||
return replayFiles.get(replayDropdown.getSelectionIndex());
|
||||
} catch(ArrayIndexOutOfBoundsException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshReplayDropdown() {
|
||||
replayDropdown.clearElements();
|
||||
replayFiles = ReplayFileIO.getAllReplayFiles();
|
||||
@@ -75,14 +91,14 @@ public class GuiReplayStudio extends GuiScreen {
|
||||
}
|
||||
|
||||
int modeWidth = tabButtons.get(0).width;
|
||||
|
||||
|
||||
if(!initialized) {
|
||||
replayDropdown = new GuiDropdown(1, fontRendererObj, 15+2+1+80, 60, this.width-30-8-80-modeWidth-4);
|
||||
refreshReplayDropdown();
|
||||
} else {
|
||||
replayDropdown.width = this.width-30-8-80-modeWidth-4;
|
||||
}
|
||||
|
||||
|
||||
if(!initialized) {
|
||||
saveModeButton = new GuiButton(GuiConstants.REPLAY_EDITOR_SAVEMODE_BUTTON, width-15-modeWidth-3, 60, getSaveModeLabel());
|
||||
} else {
|
||||
@@ -91,15 +107,18 @@ public class GuiReplayStudio extends GuiScreen {
|
||||
saveModeButton.width = modeWidth;
|
||||
buttonList.add(saveModeButton);
|
||||
|
||||
|
||||
|
||||
GuiButton backButton = new GuiButton(GuiConstants.REPLAY_EDITOR_BACK_BUTTON, width-70-18, height-20-5, "Back");
|
||||
backButton.width = 70;
|
||||
buttonList.add(backButton);
|
||||
|
||||
|
||||
saveButton = new GuiButton(GuiConstants.REPLAY_EDITOR_SAVE_BUTTON, width-70-18, height-(2*20)-5-3, "Save");
|
||||
saveButton.width = 70;
|
||||
buttonList.add(saveButton);
|
||||
|
||||
|
||||
for(StudioTab tab : StudioTab.values()) {
|
||||
tab.getStudioPart().initGui();
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
};
|
||||
@@ -116,6 +135,12 @@ public class GuiReplayStudio extends GuiScreen {
|
||||
button.displayString = getSaveModeLabel();
|
||||
} else if(button.id == GuiConstants.REPLAY_EDITOR_BACK_BUTTON) {
|
||||
mc.displayGuiScreen(new GuiMainMenu());
|
||||
} else if(button.id == GuiConstants.REPLAY_EDITOR_TRIM_TAB) {
|
||||
currentTab = StudioTab.TRIM;
|
||||
} else if(button.id == GuiConstants.REPLAY_EDITOR_CONNECT_TAB) {
|
||||
currentTab = StudioTab.CONNECT;
|
||||
} else if(button.id == GuiConstants.REPLAY_EDITOR_MODIFY_TAB) {
|
||||
currentTab = StudioTab.MODIFY;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,8 +157,8 @@ public class GuiReplayStudio extends GuiScreen {
|
||||
drawDefaultBackground();
|
||||
currentTab.getStudioPart().drawScreen(mouseX, mouseY, partialTicks);
|
||||
|
||||
drawCenteredString(fontRendererObj, currentTab.getStudioPart().getTitle(), width/2, 92, Color.WHITE.getRGB());
|
||||
|
||||
drawCenteredString(fontRendererObj, "§n"+currentTab.getStudioPart().getTitle(), width/2, 92, Color.WHITE.getRGB());
|
||||
|
||||
List<String> rows = new ArrayList<String>();
|
||||
String remaining = currentTab.getStudioPart().getDescription();
|
||||
while(remaining.length() > 0) {
|
||||
@@ -158,7 +183,7 @@ public class GuiReplayStudio extends GuiScreen {
|
||||
drawString(fontRendererObj, row, 30, height-(15*(rows.size()-i)), Color.WHITE.getRGB());
|
||||
i++;
|
||||
}
|
||||
|
||||
|
||||
drawCenteredString(fontRendererObj, "Replay Studio", this.width / 2, 10, 16777215);
|
||||
drawString(fontRendererObj, "Replay File:", 30, 67, Color.WHITE.getRGB());
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
|
||||
@@ -3,7 +3,13 @@ package eu.crushedpixel.replaymod.gui.replaystudio;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
public abstract class GuiStudioPart extends GuiScreen {
|
||||
|
||||
|
||||
public GuiStudioPart(int yPos) {
|
||||
this.yPos = yPos;
|
||||
}
|
||||
|
||||
protected int yPos = 0;
|
||||
|
||||
public abstract void applyFilters();
|
||||
|
||||
public abstract String getDescription();
|
||||
|
||||
@@ -12,11 +12,9 @@ import eu.crushedpixel.replaymod.gui.GuiNumberInput;
|
||||
|
||||
public class GuiTrimPart extends GuiStudioPart {
|
||||
|
||||
private int yPos = 0;
|
||||
|
||||
private Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private static final String DESCRIPTION = "Removes the beginning and end of a Replay File and only keeps the Replay between the given Timestamps";
|
||||
private static final String DESCRIPTION = "Removes the beginning and end of a Replay File and only keeps the Replay between the given timestamps.";
|
||||
private static final String TITLE = "Trim Replay";
|
||||
|
||||
private boolean initialized = false;
|
||||
@@ -27,15 +25,8 @@ public class GuiTrimPart extends GuiStudioPart {
|
||||
private List<GuiNumberInput> inputOrder = new ArrayList<GuiNumberInput>();
|
||||
|
||||
public GuiTrimPart(int yPos) {
|
||||
this.yPos = yPos;
|
||||
super(yPos);
|
||||
fontRendererObj = mc.fontRendererObj;
|
||||
initGui();
|
||||
inputOrder.add(startMinInput);
|
||||
inputOrder.add(startSecInput);
|
||||
inputOrder.add(startMsInput);
|
||||
inputOrder.add(endMinInput);
|
||||
inputOrder.add(endSecInput);
|
||||
inputOrder.add(endMsInput);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,6 +34,30 @@ public class GuiTrimPart extends GuiStudioPart {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
private int valueOf(String text) {
|
||||
try {
|
||||
return Integer.valueOf(text);
|
||||
} catch(NumberFormatException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private int getStartTimestamp() {
|
||||
int mins = valueOf(startMinInput.getText());
|
||||
int secs = valueOf(startSecInput.getText());
|
||||
int ms = valueOf(startMsInput.getText());
|
||||
|
||||
return (mins*60*1000)+(secs*1000)+ms;
|
||||
}
|
||||
|
||||
private int getEndTimestamp() {
|
||||
int mins = valueOf(endMinInput.getText());
|
||||
int secs = valueOf(endSecInput.getText());
|
||||
int ms = valueOf(endMsInput.getText());
|
||||
|
||||
return (mins*60*1000)+(secs*1000)+ms;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return DESCRIPTION;
|
||||
@@ -63,6 +78,15 @@ public class GuiTrimPart extends GuiStudioPart {
|
||||
endMinInput = new GuiNumberInput(1, fontRendererObj, 70, yPos+30, 30, 3);
|
||||
endSecInput = new GuiNumberInput(1, fontRendererObj, 120, yPos+30, 25, 2);
|
||||
endMsInput = new GuiNumberInput(1, fontRendererObj, 165, yPos+30, 30, 3);
|
||||
|
||||
inputOrder.clear();
|
||||
|
||||
inputOrder.add(startMinInput);
|
||||
inputOrder.add(startSecInput);
|
||||
inputOrder.add(startMsInput);
|
||||
inputOrder.add(endMinInput);
|
||||
inputOrder.add(endSecInput);
|
||||
inputOrder.add(endMsInput);
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
@@ -70,12 +94,9 @@ public class GuiTrimPart extends GuiStudioPart {
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
||||
startMinInput.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
startSecInput.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
startMsInput.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
endMinInput.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
endSecInput.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
endMsInput.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
for(GuiNumberInput input: inputOrder) {
|
||||
input.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,25 +110,24 @@ public class GuiTrimPart extends GuiStudioPart {
|
||||
drawString(mc.fontRendererObj, "ms", 200, yPos+7, Color.WHITE.getRGB());
|
||||
drawString(mc.fontRendererObj, "ms", 200, yPos+7+30, Color.WHITE.getRGB());
|
||||
|
||||
startMinInput.drawTextBox();
|
||||
startSecInput.drawTextBox();
|
||||
startMsInput.drawTextBox();
|
||||
endMinInput.drawTextBox();
|
||||
endSecInput.drawTextBox();
|
||||
endMsInput.drawTextBox();
|
||||
drawString(mc.fontRendererObj, "Timestamp: "+getStartTimestamp(), 230, yPos+7, Color.WHITE.getRGB());
|
||||
drawString(mc.fontRendererObj, "Timestamp: "+getEndTimestamp(), 230, yPos+30+7, Color.WHITE.getRGB());
|
||||
|
||||
for(GuiNumberInput input: inputOrder) {
|
||||
input.drawTextBox();
|
||||
}
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
if(initialized) {
|
||||
startMinInput.updateCursorCounter();
|
||||
startSecInput.updateCursorCounter();
|
||||
startMsInput.updateCursorCounter();
|
||||
endMinInput.updateCursorCounter();
|
||||
endSecInput.updateCursorCounter();
|
||||
endMsInput.updateCursorCounter();
|
||||
if(!initialized) {
|
||||
initGui();
|
||||
} else {
|
||||
for(GuiNumberInput input: inputOrder) {
|
||||
input.updateCursorCounter();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user