Refactored and reformatted code to use less static variables
This commit is contained in:
@@ -1,40 +1,38 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class GuiArrowButton extends GuiButton {
|
||||
|
||||
private Minecraft mc = Minecraft.getMinecraft();
|
||||
private boolean upwards = false;
|
||||
|
||||
private boolean upwards = false;
|
||||
public GuiArrowButton(int buttonId, int x, int y, String buttonText, boolean upwards) {
|
||||
super(buttonId, x, y, buttonText);
|
||||
|
||||
public GuiArrowButton(int buttonId, int x, int y, String buttonText, boolean upwards) {
|
||||
super(buttonId, x, y, buttonText);
|
||||
this.upwards = upwards;
|
||||
width = 20;
|
||||
height = 20;
|
||||
}
|
||||
|
||||
this.upwards = upwards;
|
||||
width = 20;
|
||||
height = 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
try {
|
||||
super.drawButton(mc, mouseX, mouseY);
|
||||
if(upwards) {
|
||||
for(int i=0; i<=Math.ceil(height/2)-5; i++) {
|
||||
drawHorizontalLine(xPosition+width-height+i+4, xPosition+width-i-6, yPosition+height-((height/3)+i+2), Color.BLACK.getRGB());
|
||||
}
|
||||
} else {
|
||||
for(int i=0; i<=Math.ceil(height/2)-5; i++) {
|
||||
drawHorizontalLine(xPosition+width-height+i+4, xPosition+width-i-6, yPosition+(height/3)+i+2, Color.BLACK.getRGB());
|
||||
}
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
try {
|
||||
super.drawButton(mc, mouseX, mouseY);
|
||||
if(upwards) {
|
||||
for(int i = 0; i <= Math.ceil(height / 2) - 5; i++) {
|
||||
drawHorizontalLine(xPosition + width - height + i + 4, xPosition + width - i - 6, yPosition + height - ((height / 3) + i + 2), Color.BLACK.getRGB());
|
||||
}
|
||||
} else {
|
||||
for(int i = 0; i <= Math.ceil(height / 2) - 5; i++) {
|
||||
drawHorizontalLine(xPosition + width - height + i + 4, xPosition + width - i - 6, yPosition + (height / 3) + i + 2, Color.BLACK.getRGB());
|
||||
}
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,197 +1,192 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import eu.crushedpixel.replaymod.gui.elements.listeners.SelectionListener;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiDropdown<T> extends GuiTextField {
|
||||
|
||||
private int selectionIndex = -1;
|
||||
private boolean open = false;
|
||||
private final int visibleDropout;
|
||||
private final int dropoutElementHeight = 14;
|
||||
private final int maxDropoutHeight;
|
||||
private int selectionIndex = -1;
|
||||
private boolean open = false;
|
||||
private Minecraft mc = Minecraft.getMinecraft();
|
||||
private List<SelectionListener> selectionListeners = new ArrayList<SelectionListener>();
|
||||
|
||||
private Minecraft mc = Minecraft.getMinecraft();
|
||||
private int upperIndex = 0;
|
||||
private List<T> elements = new ArrayList<T>();
|
||||
|
||||
private final int visibleDropout;
|
||||
private final int dropoutElementHeight = 14;
|
||||
private final int maxDropoutHeight;
|
||||
public GuiDropdown(int id, FontRenderer fontRenderer,
|
||||
int xPos, int yPos, int width, int visibleDropout) {
|
||||
super(id, fontRenderer, xPos, yPos, width, 20);
|
||||
this.visibleDropout = visibleDropout;
|
||||
this.maxDropoutHeight = dropoutElementHeight * visibleDropout;
|
||||
}
|
||||
|
||||
private List<SelectionListener> selectionListeners = new ArrayList<SelectionListener>();
|
||||
|
||||
private int upperIndex = 0;
|
||||
@Override
|
||||
public void drawTextBox() {
|
||||
if(elements.size() > selectionIndex && selectionIndex >= 0) {
|
||||
setText(mc.fontRendererObj.trimStringToWidth(
|
||||
elements.get(selectionIndex).toString(), width - 8));
|
||||
} else {
|
||||
setText("");
|
||||
}
|
||||
super.drawTextBox();
|
||||
|
||||
public GuiDropdown(int id, FontRenderer fontRenderer,
|
||||
int xPos, int yPos, int width, int visibleDropout) {
|
||||
super(id, fontRenderer, xPos, yPos, width, 20);
|
||||
this.visibleDropout = visibleDropout;
|
||||
this.maxDropoutHeight = dropoutElementHeight*visibleDropout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawTextBox() {
|
||||
if(elements.size() > selectionIndex && selectionIndex >= 0) {
|
||||
setText(mc.fontRendererObj.trimStringToWidth(
|
||||
elements.get(selectionIndex).toString(), width-8));
|
||||
} 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);
|
||||
|
||||
//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);
|
||||
}
|
||||
|
||||
//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 && elements.size() > 0) {
|
||||
//draw the dropout part when opened
|
||||
|
||||
if(open && elements.size() > 0) {
|
||||
//draw the dropout part when opened
|
||||
boolean drawScrollBar = false;
|
||||
|
||||
boolean drawScrollBar = false;
|
||||
int requiredHeight = elements.size() * dropoutElementHeight;
|
||||
if(requiredHeight > maxDropoutHeight) {
|
||||
requiredHeight = maxDropoutHeight;
|
||||
drawScrollBar = true;
|
||||
}
|
||||
|
||||
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 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 dark inside
|
||||
drawRect(xPosition, yPosition+height+1, xPosition+width, yPosition+height+requiredHeight, -16777216);
|
||||
//The elements
|
||||
int y = 0;
|
||||
int i = 0;
|
||||
for(T obj : elements) {
|
||||
if(i < upperIndex) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
drawHorizontalLine(xPosition, xPosition + width, yPosition + height + y, -6250336);
|
||||
String toWrite = mc.fontRendererObj.trimStringToWidth(obj.toString(), width - 8);
|
||||
drawString(mc.fontRendererObj, toWrite, xPosition + 4, yPosition + height + y + 4, Color.WHITE.getRGB());
|
||||
|
||||
//The elements
|
||||
int y = 0;
|
||||
int i = 0;
|
||||
for(T obj : elements) {
|
||||
if(i<upperIndex) {
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
drawHorizontalLine(xPosition, xPosition+width, yPosition+height+y, -6250336);
|
||||
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++;
|
||||
if(y >= requiredHeight) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
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());
|
||||
|
||||
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 visiblePerc = ((float)visibleDropout)/elements.size();
|
||||
int barHeight = (int)(visiblePerc*(requiredHeight-1));
|
||||
float posPerc = ((float) upperIndex) / elements.size();
|
||||
int barY = (int) (posPerc * (requiredHeight - 1));
|
||||
|
||||
float posPerc = ((float)upperIndex)/elements.size();
|
||||
int barY = (int)(posPerc*(requiredHeight-1));
|
||||
drawRect(xPosition + width - 3, yPosition + height + barY, xPosition + width, yPosition + height + 2 + barY + barHeight, -6250336);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
drawRect(xPosition+width-3, yPosition+height+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 && 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;
|
||||
this.selectionIndex = clickedIndex;
|
||||
fireSelectionChangeEvent();
|
||||
}
|
||||
open = false;
|
||||
} else {
|
||||
open = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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 && 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;
|
||||
this.selectionIndex = clickedIndex;
|
||||
fireSelectionChangeEvent();
|
||||
}
|
||||
open = false;
|
||||
} else {
|
||||
open = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void setText(String text) {
|
||||
if(!getText().equals(text)) {
|
||||
super.setText(text);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(String text) {
|
||||
if(!getText().equals(text)) {
|
||||
super.setText(text);
|
||||
}
|
||||
}
|
||||
public void setElements(List<T> elements) {
|
||||
this.elements = elements;
|
||||
if(selectionIndex == -1 && elements.size() > 0) {
|
||||
selectionIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private List<T> elements = new ArrayList<T>();
|
||||
public void clearElements() {
|
||||
this.elements = new ArrayList<T>();
|
||||
selectionIndex = -1;
|
||||
}
|
||||
|
||||
public void setSelectionIndex(int index) {
|
||||
this.selectionIndex = index;
|
||||
if(selectionIndex < 0) selectionIndex = -1;
|
||||
fireSelectionChangeEvent();
|
||||
}
|
||||
public void addElement(T element) {
|
||||
this.elements.add(element);
|
||||
if(selectionIndex == -1) {
|
||||
selectionIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void setElements(List<T> elements) {
|
||||
this.elements = elements;
|
||||
if(selectionIndex == -1 && elements.size() > 0) {
|
||||
selectionIndex = 0;
|
||||
}
|
||||
}
|
||||
public T getElement(int index) {
|
||||
return elements.get(index);
|
||||
}
|
||||
|
||||
public void clearElements() {
|
||||
this.elements = new ArrayList<T>();
|
||||
selectionIndex = -1;
|
||||
}
|
||||
public List<T> getAllElements() {
|
||||
return elements;
|
||||
}
|
||||
|
||||
public void addElement(T element) {
|
||||
this.elements.add(element);
|
||||
if(selectionIndex == -1) {
|
||||
selectionIndex = 0;
|
||||
}
|
||||
}
|
||||
public int getSelectionIndex() {
|
||||
return selectionIndex;
|
||||
}
|
||||
|
||||
public T getElement(int index) {
|
||||
return elements.get(index);
|
||||
}
|
||||
public void setSelectionIndex(int index) {
|
||||
this.selectionIndex = index;
|
||||
if(selectionIndex < 0) selectionIndex = -1;
|
||||
fireSelectionChangeEvent();
|
||||
}
|
||||
|
||||
public List<T> getAllElements() {
|
||||
return elements;
|
||||
}
|
||||
|
||||
public int getSelectionIndex() {
|
||||
return selectionIndex;
|
||||
}
|
||||
private void fireSelectionChangeEvent() {
|
||||
for(SelectionListener listener : selectionListeners) {
|
||||
listener.onSelectionChanged(selectionIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private void fireSelectionChangeEvent() {
|
||||
for(SelectionListener listener : selectionListeners) {
|
||||
listener.onSelectionChanged(selectionIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public void addSelectionListener(SelectionListener listener) {
|
||||
this.selectionListeners.add(listener);
|
||||
}
|
||||
public void addSelectionListener(SelectionListener listener) {
|
||||
this.selectionListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeSelectionListener(SelectionListener listener) {
|
||||
this.selectionListeners.remove(listener);
|
||||
}
|
||||
public void removeSelectionListener(SelectionListener listener) {
|
||||
this.selectionListeners.remove(listener);
|
||||
}
|
||||
|
||||
public boolean isExpanded() {
|
||||
return open;
|
||||
}
|
||||
public boolean isExpanded() {
|
||||
return open;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,150 +1,146 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import eu.crushedpixel.replaymod.gui.elements.listeners.SelectionListener;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiEntryList<T> extends GuiTextField {
|
||||
|
||||
private int selectionIndex = -1;
|
||||
public final static int elementHeight = 14;
|
||||
private int selectionIndex = -1;
|
||||
private Minecraft mc = Minecraft.getMinecraft();
|
||||
private int visibleElements;
|
||||
private int upperIndex = 0;
|
||||
|
||||
private Minecraft mc = Minecraft.getMinecraft();
|
||||
private List<SelectionListener> selectionListeners = new ArrayList<SelectionListener>();
|
||||
private List<T> elements = new ArrayList<T>();
|
||||
|
||||
private int visibleElements;
|
||||
public final static int elementHeight = 14;
|
||||
public GuiEntryList(int id, FontRenderer fontRenderer,
|
||||
int xPos, int yPos, int width, int visibleEntries) {
|
||||
super(id, fontRenderer, xPos, yPos, width, elementHeight * visibleEntries - 1);
|
||||
this.visibleElements = visibleEntries;
|
||||
}
|
||||
|
||||
private int upperIndex = 0;
|
||||
public void setVisibleElements(int rows) {
|
||||
this.visibleElements = rows;
|
||||
this.height = elementHeight * visibleElements - 1;
|
||||
}
|
||||
|
||||
private List<SelectionListener> selectionListeners = new ArrayList<SelectionListener>();
|
||||
@Override
|
||||
public void drawTextBox() {
|
||||
try {
|
||||
super.drawTextBox();
|
||||
//drawing the entries
|
||||
for(int i = 0; i - upperIndex < visibleElements; i++) {
|
||||
if(i < upperIndex) continue;
|
||||
|
||||
public GuiEntryList(int id, FontRenderer fontRenderer,
|
||||
int xPos, int yPos, int width, int visibleEntries) {
|
||||
super(id, fontRenderer, xPos, yPos, width, elementHeight*visibleEntries-1);
|
||||
this.visibleElements = visibleEntries;
|
||||
}
|
||||
if(i >= elements.size()) break;
|
||||
|
||||
public void setVisibleElements(int rows) {
|
||||
this.visibleElements = rows;
|
||||
this.height = elementHeight*visibleElements-1;
|
||||
}
|
||||
if(i == selectionIndex) {
|
||||
drawRect(xPosition, yPosition + (i - upperIndex) * elementHeight, xPosition + width,
|
||||
yPosition + (i + 1 - upperIndex) * elementHeight - 1, Color.GRAY.getRGB());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawTextBox() {
|
||||
try {
|
||||
super.drawTextBox();
|
||||
//drawing the entries
|
||||
for(int i=0; i-upperIndex<visibleElements; i++) {
|
||||
if(i<upperIndex) continue;
|
||||
drawRect(xPosition, yPosition + (i + 1 - upperIndex) * elementHeight - 1, xPosition + width,
|
||||
yPosition + (i + 1 - upperIndex) * elementHeight, -6250336);
|
||||
drawString(mc.fontRendererObj, mc.fontRendererObj.trimStringToWidth(elements.get(i).toString(), width - 4),
|
||||
xPosition + 2, yPosition + (i - upperIndex) * elementHeight + 3, Color.WHITE.getRGB());
|
||||
}
|
||||
|
||||
if(i >= elements.size()) break;
|
||||
//drawing the scroll bar
|
||||
if(elements.size() > visibleElements) {
|
||||
//handle scroll events
|
||||
int dw = Mouse.getDWheel();
|
||||
if(dw > 0) {
|
||||
dw = -1;
|
||||
} else if(dw < 0) {
|
||||
dw = 1;
|
||||
}
|
||||
|
||||
if(i == selectionIndex) {
|
||||
drawRect(xPosition, yPosition+(i-upperIndex)*elementHeight, xPosition+width,
|
||||
yPosition+(i+1-upperIndex)*elementHeight-1, Color.GRAY.getRGB());
|
||||
}
|
||||
upperIndex = Math.max(Math.min(upperIndex + dw, elements.size() - visibleElements), 0);
|
||||
|
||||
drawRect(xPosition, yPosition+(i+1-upperIndex)*elementHeight-1, xPosition+width,
|
||||
yPosition+(i+1-upperIndex)*elementHeight, -6250336);
|
||||
drawString(mc.fontRendererObj, mc.fontRendererObj.trimStringToWidth(elements.get(i).toString(), width-4),
|
||||
xPosition+2, yPosition+(i-upperIndex)*elementHeight+3, Color.WHITE.getRGB());
|
||||
}
|
||||
float visiblePerc = ((float) visibleElements) / elements.size();
|
||||
int barHeight = (int) (visiblePerc * (height - 1));
|
||||
|
||||
//drawing the scroll bar
|
||||
if(elements.size() > visibleElements) {
|
||||
//handle scroll events
|
||||
int dw = Mouse.getDWheel();
|
||||
if(dw > 0) {
|
||||
dw = -1;
|
||||
} else if(dw < 0) {
|
||||
dw = 1;
|
||||
}
|
||||
float posPerc = ((float) upperIndex) / elements.size();
|
||||
int barY = (int) (posPerc * (height - 1));
|
||||
|
||||
upperIndex = Math.max(Math.min(upperIndex+dw, elements.size()-visibleElements), 0);
|
||||
drawRect(xPosition + width - 3, yPosition, xPosition + width, yPosition + height, Color.DARK_GRAY.getRGB());
|
||||
drawRect(xPosition + width - 3, yPosition + barY, xPosition + width, yPosition + 1 + barY + barHeight, -6250336);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
float visiblePerc = ((float)visibleElements)/elements.size();
|
||||
int barHeight = (int)(visiblePerc*(height-1));
|
||||
@Override
|
||||
public void mouseClicked(int xPos, int yPos, int mouseButton) {
|
||||
if(!(xPos >= xPosition && xPos <= xPosition + width && yPos >= yPosition && yPos <= yPosition + height)) return;
|
||||
int clickedIndex = (int) Math.floor((yPos - yPosition) / elementHeight) + upperIndex;
|
||||
if(clickedIndex < elements.size() && clickedIndex >= 0) {
|
||||
selectionIndex = clickedIndex;
|
||||
fireSelectionChangeEvent();
|
||||
}
|
||||
}
|
||||
|
||||
float posPerc = ((float)upperIndex)/elements.size();
|
||||
int barY = (int)(posPerc*(height-1));
|
||||
private void fireSelectionChangeEvent() {
|
||||
for(SelectionListener listener : selectionListeners) {
|
||||
listener.onSelectionChanged(selectionIndex);
|
||||
}
|
||||
}
|
||||
|
||||
drawRect(xPosition+width-3, yPosition, xPosition+width, yPosition+height, Color.DARK_GRAY.getRGB());
|
||||
drawRect(xPosition+width-3, yPosition+barY, xPosition+width, yPosition+1+barY+barHeight, -6250336);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void setText(String text) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int xPos, int yPos, int mouseButton) {
|
||||
if(!(xPos >= xPosition && xPos <= xPosition+width && yPos >= yPosition && yPos <= yPosition+height)) return;
|
||||
int clickedIndex = (int)Math.floor((yPos-yPosition) / elementHeight) + upperIndex;
|
||||
if(clickedIndex < elements.size() && clickedIndex >= 0) {
|
||||
selectionIndex = clickedIndex;
|
||||
fireSelectionChangeEvent();
|
||||
}
|
||||
}
|
||||
public void setElements(List<T> elements) {
|
||||
this.elements = elements;
|
||||
if(selectionIndex == -1 && elements.size() > 0) {
|
||||
selectionIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void fireSelectionChangeEvent() {
|
||||
for(SelectionListener listener : selectionListeners) {
|
||||
listener.onSelectionChanged(selectionIndex);
|
||||
}
|
||||
}
|
||||
public void clearElements() {
|
||||
this.elements = new ArrayList<T>();
|
||||
selectionIndex = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(String text) {}
|
||||
public void addElement(T element) {
|
||||
this.elements.add(element);
|
||||
if(selectionIndex == -1) {
|
||||
selectionIndex = 0;
|
||||
}
|
||||
}
|
||||
|
||||
private List<T> elements = new ArrayList<T>();
|
||||
public T getElement(int index) {
|
||||
if(index >= 0) {
|
||||
return elements.get(index);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setElements(List<T> elements) {
|
||||
this.elements = elements;
|
||||
if(selectionIndex == -1 && elements.size() > 0) {
|
||||
selectionIndex = 0;
|
||||
}
|
||||
}
|
||||
public int getSelectionIndex() {
|
||||
return selectionIndex;
|
||||
}
|
||||
|
||||
public void clearElements() {
|
||||
this.elements = new ArrayList<T>();
|
||||
selectionIndex = -1;
|
||||
}
|
||||
public void setSelectionIndex(int index) {
|
||||
this.selectionIndex = index;
|
||||
if(selectionIndex < 0) selectionIndex = -1;
|
||||
fireSelectionChangeEvent();
|
||||
}
|
||||
|
||||
public void addElement(T element) {
|
||||
this.elements.add(element);
|
||||
if(selectionIndex == -1) {
|
||||
selectionIndex = 0;
|
||||
}
|
||||
}
|
||||
public void addSelectionListener(SelectionListener listener) {
|
||||
this.selectionListeners.add(listener);
|
||||
}
|
||||
|
||||
public T getElement(int index) {
|
||||
if(index >= 0) {
|
||||
return elements.get(index);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getSelectionIndex() {
|
||||
return selectionIndex;
|
||||
}
|
||||
|
||||
public void setSelectionIndex(int index) {
|
||||
this.selectionIndex = index;
|
||||
if(selectionIndex < 0) selectionIndex = -1;
|
||||
fireSelectionChangeEvent();
|
||||
}
|
||||
|
||||
public void addSelectionListener(SelectionListener listener) {
|
||||
this.selectionListeners.add(listener);
|
||||
}
|
||||
|
||||
public void removeSelectionListener(SelectionListener listener) {
|
||||
this.selectionListeners.remove(listener);
|
||||
}
|
||||
public void removeSelectionListener(SelectionListener listener) {
|
||||
this.selectionListeners.remove(listener);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
|
||||
public class GuiMouseInput extends GuiScreen {
|
||||
|
||||
}
|
||||
@@ -1,26 +1,26 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
|
||||
public class GuiNumberInput extends GuiTextField {
|
||||
|
||||
private int limit;
|
||||
|
||||
public GuiNumberInput(int id, FontRenderer fontRenderer,
|
||||
int xPos, int yPos, int width, int limit) {
|
||||
super(id, fontRenderer, xPos, yPos, width, 20);
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeText(String text) {
|
||||
try {
|
||||
Integer.valueOf(text);
|
||||
if(limit > 0 && (getText()+text).length() > limit) return;
|
||||
super.writeText(text);
|
||||
} catch(NumberFormatException e) {}
|
||||
}
|
||||
private int limit;
|
||||
|
||||
public GuiNumberInput(int id, FontRenderer fontRenderer,
|
||||
int xPos, int yPos, int width, int limit) {
|
||||
super(id, fontRenderer, xPos, yPos, width, 20);
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeText(String text) {
|
||||
try {
|
||||
Integer.valueOf(text);
|
||||
if(limit > 0 && (getText() + text).length() > limit) return;
|
||||
super.writeText(text);
|
||||
} catch(NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
|
||||
import eu.crushedpixel.replaymod.utils.ResourceHelper;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiListExtended.IGuiListEntry;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.text.DateFormat;
|
||||
@@ -9,114 +18,102 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
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.utils.ResourceHelper;
|
||||
|
||||
public class GuiReplayListEntry implements IGuiListEntry {
|
||||
|
||||
private Minecraft minecraft = Minecraft.getMinecraft();
|
||||
private final DateFormat dateFormat = new SimpleDateFormat();
|
||||
private final DateFormat dateFormat = new SimpleDateFormat();
|
||||
boolean registered = false;
|
||||
private Minecraft minecraft = Minecraft.getMinecraft();
|
||||
private FileInfo fileInfo;
|
||||
private ResourceLocation textureResource;
|
||||
private DynamicTexture dynTex = null;
|
||||
private File imageFile;
|
||||
private BufferedImage image = null;
|
||||
private GuiReplayListExtended parent;
|
||||
|
||||
private FileInfo fileInfo;
|
||||
|
||||
private ResourceLocation textureResource;
|
||||
private DynamicTexture dynTex = null;
|
||||
public GuiReplayListEntry(GuiReplayListExtended parent, FileInfo fileInfo, File imageFile) {
|
||||
this.fileInfo = fileInfo;
|
||||
this.parent = parent;
|
||||
dynTex = null;
|
||||
this.imageFile = imageFile;
|
||||
}
|
||||
|
||||
private File imageFile;
|
||||
private BufferedImage image = null;
|
||||
private GuiReplayListExtended parent;
|
||||
|
||||
public FileInfo getFileInfo() {
|
||||
return fileInfo;
|
||||
}
|
||||
public FileInfo getFileInfo() {
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
public GuiReplayListEntry(GuiReplayListExtended parent, FileInfo fileInfo, File imageFile) {
|
||||
this.fileInfo = fileInfo;
|
||||
this.parent = parent;
|
||||
dynTex = null;
|
||||
this.imageFile = imageFile;
|
||||
}
|
||||
@Override
|
||||
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected) {
|
||||
try {
|
||||
if(fileInfo.getName() == null || fileInfo.getName().length() < 1) {
|
||||
fileInfo.setName("No Name");
|
||||
}
|
||||
minecraft.fontRendererObj.drawString(fileInfo.getName(), x + 3, y + 1, 16777215);
|
||||
|
||||
boolean registered = false;
|
||||
if(y < -slotHeight || y > parent.height) {
|
||||
if(registered) {
|
||||
registered = false;
|
||||
ResourceHelper.freeResource(textureResource);
|
||||
textureResource = null;
|
||||
image = null;
|
||||
dynTex = null;
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
if(!registered) {
|
||||
textureResource = new ResourceLocation("thumbs/" + fileInfo.getName() + fileInfo.getId());
|
||||
if(imageFile == null) {
|
||||
image = ResourceHelper.getDefaultThumbnail();
|
||||
} else {
|
||||
image = ImageIO.read(imageFile);
|
||||
}
|
||||
dynTex = new DynamicTexture(image);
|
||||
minecraft.getTextureManager().loadTexture(textureResource, dynTex);
|
||||
dynTex.updateDynamicTexture();
|
||||
ResourceHelper.registerResource(textureResource);
|
||||
registered = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected) {
|
||||
try {
|
||||
if(fileInfo.getName() == null || fileInfo.getName().length() < 1) {
|
||||
fileInfo.setName("No Name");
|
||||
}
|
||||
minecraft.fontRendererObj.drawString(fileInfo.getName(), x + 3, y + 1, 16777215);
|
||||
minecraft.getTextureManager().bindTexture(textureResource);
|
||||
Gui.drawScaledCustomSizeModalRect(x - 60, y, 0, 0, 1280, 720, 57, 32, 1280, 720);
|
||||
}
|
||||
|
||||
if(y < -slotHeight || y > parent.height) {
|
||||
if(registered) {
|
||||
registered = false;
|
||||
ResourceHelper.freeResource(textureResource);
|
||||
textureResource = null;
|
||||
image = null;
|
||||
dynTex = null;
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
if(!registered) {
|
||||
textureResource = new ResourceLocation("thumbs/"+fileInfo.getName()+fileInfo.getId());
|
||||
if(imageFile == null) {
|
||||
image = ResourceHelper.getDefaultThumbnail();
|
||||
} else {
|
||||
image = ImageIO.read(imageFile);
|
||||
}
|
||||
dynTex = new DynamicTexture(image);
|
||||
minecraft.getTextureManager().loadTexture(textureResource, dynTex);
|
||||
dynTex.updateDynamicTexture();
|
||||
ResourceHelper.registerResource(textureResource);
|
||||
registered = true;
|
||||
}
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.add(fileInfo.getMetadata().getServerName() + " (" + dateFormat.format(new Date(fileInfo.getMetadata().getDate())) + ")");
|
||||
|
||||
minecraft.getTextureManager().bindTexture(textureResource);
|
||||
Gui.drawScaledCustomSizeModalRect(x-60, y, 0, 0, 1280, 720, 57, 32, 1280, 720);
|
||||
}
|
||||
list.add(String.format("%02dm%02ds",
|
||||
TimeUnit.MILLISECONDS.toMinutes(fileInfo.getMetadata().getDuration()),
|
||||
TimeUnit.MILLISECONDS.toSeconds(fileInfo.getMetadata().getDuration()) -
|
||||
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(fileInfo.getMetadata().getDuration()))
|
||||
));
|
||||
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.add(fileInfo.getMetadata().getServerName()+" ("+dateFormat.format(new Date(fileInfo.getMetadata().getDate()))+")");
|
||||
for(int l1 = 0; l1 < Math.min(list.size(), 2); ++l1) {
|
||||
minecraft.fontRendererObj.drawString((String) list.get(l1), x + 3, y + 12 + minecraft.fontRendererObj.FONT_HEIGHT * l1, 8421504);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
list.add(String.format("%02dm%02ds",
|
||||
TimeUnit.MILLISECONDS.toMinutes(fileInfo.getMetadata().getDuration()),
|
||||
TimeUnit.MILLISECONDS.toSeconds(fileInfo.getMetadata().getDuration()) -
|
||||
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(fileInfo.getMetadata().getDuration()))
|
||||
));
|
||||
@Override
|
||||
public void setSelected(int p_178011_1_, int p_178011_2_, int p_178011_3_) {
|
||||
}
|
||||
|
||||
for (int l1 = 0; l1 < Math.min(list.size(), 2); ++l1) {
|
||||
minecraft.fontRendererObj.drawString((String)list.get(l1), x + 3, y + 12 + minecraft.fontRendererObj.FONT_HEIGHT * l1, 8421504);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean mousePressed(int p_148278_1_, int p_148278_2_,
|
||||
int p_148278_3_, int p_148278_4_, int p_148278_5_, int p_148278_6_) {
|
||||
for(int slot = 0; slot < parent.getSize(); slot++) {
|
||||
if(parent.getListEntry(slot) == this) {
|
||||
parent.elementClicked(slot, false, p_148278_5_, p_148278_6_);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(int p_178011_1_, int p_178011_2_, int p_178011_3_) {}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(int p_148278_1_, int p_148278_2_,
|
||||
int p_148278_3_, int p_148278_4_, int p_148278_5_, int p_148278_6_) {
|
||||
for(int slot = 0; slot<parent.getSize(); slot++) {
|
||||
if(parent.getListEntry(slot) == this) {
|
||||
parent.elementClicked(slot, false, p_148278_5_, p_148278_6_);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int slotIndex, int x, int y, int mouseEvent,
|
||||
int relativeX, int relativeY) {}
|
||||
@Override
|
||||
public void mouseReleased(int slotIndex, int x, int y, int mouseEvent,
|
||||
int relativeX, int relativeY) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,196 +1,163 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiListExtended;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class GuiReplayListExtended extends GuiListExtended {
|
||||
|
||||
public GuiReplayListExtended(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_, p_i45010_6_);
|
||||
}
|
||||
public int selected = -1;
|
||||
private List<GuiReplayListEntry> entries = new ArrayList<GuiReplayListEntry>();
|
||||
|
||||
public int selected = -1;
|
||||
|
||||
@Override
|
||||
protected void elementClicked(int slotIndex, boolean isDoubleClick,
|
||||
int mouseX, int mouseY) {
|
||||
super.elementClicked(slotIndex, isDoubleClick, mouseX, mouseY);
|
||||
this.selected = slotIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawSelectionBox(int p_148120_1_, int p_148120_2_, int p_148120_3_, int p_148120_4_)
|
||||
{
|
||||
public GuiReplayListExtended(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_, p_i45010_6_);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void elementClicked(int slotIndex, boolean isDoubleClick,
|
||||
int mouseX, int mouseY) {
|
||||
super.elementClicked(slotIndex, isDoubleClick, mouseX, mouseY);
|
||||
this.selected = slotIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawSelectionBox(int p_148120_1_, int p_148120_2_, int p_148120_3_, int p_148120_4_) {
|
||||
int i1 = this.getSize();
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
WorldRenderer worldrenderer = tessellator.getWorldRenderer();
|
||||
|
||||
for (int j1 = 0; j1 < i1; ++j1)
|
||||
{
|
||||
|
||||
for(int j1 = 0; j1 < i1; ++j1) {
|
||||
|
||||
int k1 = p_148120_2_ + j1 * this.slotHeight + this.headerPadding;
|
||||
int l1 = this.slotHeight - 4;
|
||||
|
||||
if (k1 > this.bottom || k1 + l1 < this.top)
|
||||
{
|
||||
if(k1 > this.bottom || k1 + l1 < this.top) {
|
||||
this.func_178040_a(j1, p_148120_1_, k1);
|
||||
}
|
||||
|
||||
if (this.showSelectionBox && selected == j1)
|
||||
{
|
||||
if(this.showSelectionBox && selected == j1) {
|
||||
int i2 = this.left + (this.width / 2 - this.getListWidth() / 2);
|
||||
int j2 = this.left + this.width / 2 + this.getListWidth() / 2;
|
||||
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
GlStateManager.disableTexture2D();
|
||||
worldrenderer.startDrawingQuads();
|
||||
worldrenderer.setColorOpaque_I(8421504);
|
||||
worldrenderer.addVertexWithUV((double)i2, (double)(k1 + l1 + 2), 0.0D, 0.0D, 1.0D);
|
||||
worldrenderer.addVertexWithUV((double)j2, (double)(k1 + l1 + 2), 0.0D, 1.0D, 1.0D);
|
||||
worldrenderer.addVertexWithUV((double)j2, (double)(k1 - 2), 0.0D, 1.0D, 0.0D);
|
||||
worldrenderer.addVertexWithUV((double)i2, (double)(k1 - 2), 0.0D, 0.0D, 0.0D);
|
||||
worldrenderer.addVertexWithUV((double) i2, (double) (k1 + l1 + 2), 0.0D, 0.0D, 1.0D);
|
||||
worldrenderer.addVertexWithUV((double) j2, (double) (k1 + l1 + 2), 0.0D, 1.0D, 1.0D);
|
||||
worldrenderer.addVertexWithUV((double) j2, (double) (k1 - 2), 0.0D, 1.0D, 0.0D);
|
||||
worldrenderer.addVertexWithUV((double) i2, (double) (k1 - 2), 0.0D, 0.0D, 0.0D);
|
||||
worldrenderer.setColorOpaque_I(0);
|
||||
worldrenderer.addVertexWithUV((double)(i2 + 1), (double)(k1 + l1 + 1), 0.0D, 0.0D, 1.0D);
|
||||
worldrenderer.addVertexWithUV((double)(j2 - 1), (double)(k1 + l1 + 1), 0.0D, 1.0D, 1.0D);
|
||||
worldrenderer.addVertexWithUV((double)(j2 - 1), (double)(k1 - 1), 0.0D, 1.0D, 0.0D);
|
||||
worldrenderer.addVertexWithUV((double)(i2 + 1), (double)(k1 - 1), 0.0D, 0.0D, 0.0D);
|
||||
worldrenderer.addVertexWithUV((double) (i2 + 1), (double) (k1 + l1 + 1), 0.0D, 0.0D, 1.0D);
|
||||
worldrenderer.addVertexWithUV((double) (j2 - 1), (double) (k1 + l1 + 1), 0.0D, 1.0D, 1.0D);
|
||||
worldrenderer.addVertexWithUV((double) (j2 - 1), (double) (k1 - 1), 0.0D, 1.0D, 0.0D);
|
||||
worldrenderer.addVertexWithUV((double) (i2 + 1), (double) (k1 - 1), 0.0D, 0.0D, 0.0D);
|
||||
tessellator.draw();
|
||||
GlStateManager.enableTexture2D();
|
||||
}
|
||||
|
||||
|
||||
this.drawSlot(j1, p_148120_1_, k1, l1, p_148120_3_, p_148120_4_);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<GuiReplayListEntry> entries = new ArrayList<GuiReplayListEntry>();
|
||||
|
||||
public void clearEntries() {
|
||||
entries = new ArrayList<GuiReplayListEntry>();
|
||||
}
|
||||
|
||||
public void addEntry(FileInfo fileInfo, File image) {
|
||||
entries.add(new GuiReplayListEntry(this, fileInfo, image));
|
||||
}
|
||||
public void clearEntries() {
|
||||
entries = new ArrayList<GuiReplayListEntry>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiReplayListEntry getListEntry(int index) {
|
||||
return entries.get(index);
|
||||
}
|
||||
public void addEntry(FileInfo fileInfo, File image) {
|
||||
entries.add(new GuiReplayListEntry(this, fileInfo, image));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSize() {
|
||||
return entries.size();
|
||||
}
|
||||
@Override
|
||||
public GuiReplayListEntry getListEntry(int index) {
|
||||
return entries.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSize() {
|
||||
return entries.size();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handleMouseInput()
|
||||
{
|
||||
if (this.isMouseYWithinSlotBounds(this.mouseY))
|
||||
{
|
||||
if (Mouse.isButtonDown(0))
|
||||
{
|
||||
if (this.initialClickY == -1.0F)
|
||||
{
|
||||
int i2 = this.getScrollBarX();
|
||||
@Override
|
||||
public void handleMouseInput() {
|
||||
if(this.isMouseYWithinSlotBounds(this.mouseY)) {
|
||||
if(Mouse.isButtonDown(0)) {
|
||||
if(this.initialClickY == -1.0F) {
|
||||
int i2 = this.getScrollBarX();
|
||||
int i1 = i2 + 6;
|
||||
|
||||
|
||||
boolean flag = true;
|
||||
|
||||
if (this.mouseY >= this.top && this.mouseY <= this.bottom && this.mouseX <= i1)
|
||||
{
|
||||
if(this.mouseY >= this.top && this.mouseY <= this.bottom && this.mouseX <= i1) {
|
||||
int i = this.width / 2 - this.getListWidth() / 2;
|
||||
int j = this.width / 2 + this.getListWidth() / 2;
|
||||
int k = this.mouseY - this.top - this.headerPadding + (int)this.amountScrolled - 4;
|
||||
int k = this.mouseY - this.top - this.headerPadding + (int) this.amountScrolled - 4;
|
||||
int l = k / this.slotHeight;
|
||||
|
||||
if (this.mouseX >= i && this.mouseX <= j && l >= 0 && k >= 0 && l < this.getSize())
|
||||
{
|
||||
if(this.mouseX >= i && this.mouseX <= j && l >= 0 && k >= 0 && l < this.getSize()) {
|
||||
boolean flag1 = l == this.selectedElement && Minecraft.getSystemTime() - this.lastClicked < 250L;
|
||||
this.elementClicked(l, flag1, this.mouseX, this.mouseY);
|
||||
this.selectedElement = l;
|
||||
this.lastClicked = Minecraft.getSystemTime();
|
||||
}
|
||||
else if (this.mouseX >= i && this.mouseX <= j && k < 0)
|
||||
{
|
||||
this.func_148132_a(this.mouseX - i, this.mouseY - this.top + (int)this.amountScrolled - 4);
|
||||
} else if(this.mouseX >= i && this.mouseX <= j && k < 0) {
|
||||
this.func_148132_a(this.mouseX - i, this.mouseY - this.top + (int) this.amountScrolled - 4);
|
||||
flag = false;
|
||||
}
|
||||
|
||||
if (this.mouseX >= i2 && this.mouseX <= i1)
|
||||
{
|
||||
if(this.mouseX >= i2 && this.mouseX <= i1) {
|
||||
this.scrollMultiplier = -1.0F;
|
||||
int j1 = this.func_148135_f();
|
||||
|
||||
if (j1 < 1)
|
||||
{
|
||||
if(j1 < 1) {
|
||||
j1 = 1;
|
||||
}
|
||||
|
||||
int k1 = (int)((float)((this.bottom - this.top) * (this.bottom - this.top)) / (float)this.getContentHeight());
|
||||
int k1 = (int) ((float) ((this.bottom - this.top) * (this.bottom - this.top)) / (float) this.getContentHeight());
|
||||
k1 = MathHelper.clamp_int(k1, 32, this.bottom - this.top - 8);
|
||||
this.scrollMultiplier /= (float)(this.bottom - this.top - k1) / (float)j1;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.scrollMultiplier /= (float) (this.bottom - this.top - k1) / (float) j1;
|
||||
} else {
|
||||
this.scrollMultiplier = 1.0F;
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
this.initialClickY = (float)this.mouseY;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(flag) {
|
||||
this.initialClickY = (float) this.mouseY;
|
||||
} else {
|
||||
this.initialClickY = -2.0F;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
this.initialClickY = -2.0F;
|
||||
}
|
||||
} else if(this.initialClickY >= 0.0F) {
|
||||
this.amountScrolled -= ((float) this.mouseY - this.initialClickY) * this.scrollMultiplier;
|
||||
this.initialClickY = (float) this.mouseY;
|
||||
}
|
||||
else if (this.initialClickY >= 0.0F)
|
||||
{
|
||||
this.amountScrolled -= ((float)this.mouseY - this.initialClickY) * this.scrollMultiplier;
|
||||
this.initialClickY = (float)this.mouseY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
this.initialClickY = -1.0F;
|
||||
}
|
||||
|
||||
int l1 = Mouse.getEventDWheel();
|
||||
|
||||
if (l1 != 0)
|
||||
{
|
||||
if (l1 > 0)
|
||||
{
|
||||
if(l1 != 0) {
|
||||
if(l1 > 0) {
|
||||
l1 = -1;
|
||||
}
|
||||
else if (l1 < 0)
|
||||
{
|
||||
} else if(l1 < 0) {
|
||||
l1 = 1;
|
||||
}
|
||||
|
||||
this.amountScrolled += (float)(l1 * this.slotHeight / 2);
|
||||
this.amountScrolled += (float) (l1 * this.slotHeight / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements.listeners;
|
||||
|
||||
public abstract class SelectionListener {
|
||||
public interface SelectionListener {
|
||||
|
||||
void onSelectionChanged(int selectionIndex);
|
||||
|
||||
public abstract void onSelectionChanged(int selectionIndex);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user