Added setEnabled() method to GuiElement interface and implemented it everywhere

Made GuiFileChooser a child of GuiAdvancedButton instead of GuiButton
This commit is contained in:
CrushedPixel
2015-07-07 16:55:37 +02:00
parent 392db29b34
commit 1b189c0dac
13 changed files with 69 additions and 4 deletions

View File

@@ -202,4 +202,9 @@ public class GuiReplaySpeedSlider extends GuiButton implements GuiElement {
public void tick(Minecraft mc) {
}
@Override
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}

View File

@@ -67,4 +67,11 @@ public class ComposedElement implements GuiElement {
part.tick(mc);
}
}
@Override
public void setEnabled(boolean enabled) {
for(GuiElement part : parts) {
part.setEnabled(enabled);
}
}
}

View File

@@ -53,4 +53,7 @@ public abstract class DelegatingElement implements GuiElement {
public void tick(Minecraft mc) {
delegate().tick(mc);
}
@Override
public void setEnabled(boolean enabled) {}
}

View File

@@ -78,6 +78,11 @@ public class GuiAdvancedButton extends GuiButton implements GuiElement {
}
@Override
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public void performAction() {
if (action != null) {
action.run();

View File

@@ -50,4 +50,9 @@ public class GuiAdvancedCheckBox extends GuiCheckBox implements GuiElement {
public void tick(Minecraft mc) {
}
@Override
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}

View File

@@ -17,4 +17,6 @@ public interface GuiElement {
void tick(Minecraft mc);
void setEnabled(boolean enabled);
}

View File

@@ -3,7 +3,6 @@ package eu.crushedpixel.replaymod.gui.elements;
import eu.crushedpixel.replaymod.gui.elements.listeners.FileChooseListener;
import lombok.Getter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import java.awt.*;
import java.io.File;
@@ -11,7 +10,7 @@ import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;
public class GuiFileChooser extends GuiButton {
public class GuiFileChooser extends GuiAdvancedButton {
@Getter
private File selectedFile;
@@ -37,7 +36,7 @@ public class GuiFileChooser extends GuiButton {
this.allowedExtensions = allowedExtensions;
}
public void registerListener(FileChooseListener listener) {
public void addFileChooseListener(FileChooseListener listener) {
this.listeners.add(listener);
}

View File

@@ -43,6 +43,7 @@ public class GuiKeyframeTimeline extends GuiTimeline {
@Override
public void mouseClick(Minecraft mc, int mouseX, int mouseY, int button) {
if(!enabled) return;
//left mouse button
if(button == 0) {
long time = getTimeAt(mouseX, mouseY);
@@ -108,6 +109,7 @@ public class GuiKeyframeTimeline extends GuiTimeline {
@Override
public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) {
if(!enabled) return;
long time = getTimeAt(mouseX, mouseY);
if (time != -1) {
if (clickedKeyFrame != null) {

View File

@@ -4,6 +4,8 @@ import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import java.awt.*;
import static eu.crushedpixel.replaymod.gui.overlay.GuiReplayOverlay.TEXTURE_SIZE;
import static eu.crushedpixel.replaymod.gui.overlay.GuiReplayOverlay.replay_gui;
import static org.lwjgl.opengl.GL11.GL_BLEND;
@@ -46,6 +48,8 @@ public class GuiScrollbar extends Gui implements GuiElement {
private int draggingStart = -1;
private double draggingStartPosition;
private boolean enabled = true;
public GuiScrollbar(int positionX, int positionY, int width) {
this.positionX = positionX;
this.positionY = positionY;
@@ -58,6 +62,7 @@ public class GuiScrollbar extends Gui implements GuiElement {
@Override
public void mouseClick(Minecraft mc, int mouseX, int mouseY, int button) {
if(!enabled) return;
if (isHovering(mouseX, mouseY)) {
draggingStart = mouseX;
draggingStartPosition = sliderPosition;
@@ -66,6 +71,7 @@ public class GuiScrollbar extends Gui implements GuiElement {
@Override
public void mouseDrag(Minecraft mc, int mouseX, int mouseY, int button) {
if(!enabled) return;
if (draggingStart != -1) {
double delta = (double) (mouseX - draggingStart) / (width - BORDER_LEFT - BORDER_RIGHT);
sliderPosition = Math.max(0, Math.min(1 - size, draggingStartPosition + delta));
@@ -141,6 +147,9 @@ public class GuiScrollbar extends Gui implements GuiElement {
protected void rect(int x, int y, int u, int v, int width, int height) {
GlStateManager.resetColor();
if(!enabled) {
GlStateManager.color(Color.GRAY.getRed()/255f, Color.GRAY.getGreen()/255f, Color.GRAY.getBlue()/255f, 1f);
}
Minecraft.getMinecraft().renderEngine.bindTexture(replay_gui);
glEnable(GL_BLEND);
@@ -165,4 +174,9 @@ public class GuiScrollbar extends Gui implements GuiElement {
public void dragged() {
}
@Override
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}

View File

@@ -10,6 +10,7 @@ public class GuiString extends Gui implements GuiElement {
public int positionX, positionY;
public Color color;
public Callable<String> getContent;
private boolean enabled = true;
public GuiString(int positionX, int positionY, Color color, final String content) {
this(positionX, positionY, color, new Callable<String>() {
@@ -35,7 +36,7 @@ public class GuiString extends Gui implements GuiElement {
} catch (Exception e) {
throw new RuntimeException(e);
}
drawString(mc.fontRendererObj, text, positionX, positionY, color.getRGB());
drawString(mc.fontRendererObj, text, positionX, positionY, enabled ? color.getRGB() : Color.LIGHT_GRAY.getRGB());
}
@Override
@@ -72,4 +73,9 @@ public class GuiString extends Gui implements GuiElement {
public void tick(Minecraft mc) {
}
@Override
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}

View File

@@ -624,6 +624,11 @@ public class GuiTextArea extends Gui implements GuiElement {
blinkCursorTick++;
}
@Override
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public void setWidth(int width) {
this.width = width;
updateCurrentXOffset();

View File

@@ -3,6 +3,7 @@ package eu.crushedpixel.replaymod.gui.elements;
import eu.crushedpixel.replaymod.ReplayMod;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.renderer.GlStateManager;
import java.awt.*;
@@ -56,6 +57,8 @@ public class GuiTimeline extends Gui implements GuiElement {
protected final int positionY;
protected final int width;
protected boolean enabled = true;
public GuiTimeline(int positionX, int positionY, int width) {
this.positionX = positionX;
this.positionY = positionY;
@@ -194,6 +197,9 @@ public class GuiTimeline extends Gui implements GuiElement {
}
protected void rect(int x, int y, int u, int v, int width, int height) {
if(!enabled) {
GlStateManager.color(Color.GRAY.getRed() / 255f, Color.GRAY.getGreen() / 255f, Color.GRAY.getBlue() / 255f, 1f);
}
Minecraft.getMinecraft().renderEngine.bindTexture(replay_gui);
glEnable(GL_BLEND);
@@ -230,4 +236,9 @@ public class GuiTimeline extends Gui implements GuiElement {
return FIVE_M;
}
}
@Override
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}

View File

@@ -236,6 +236,7 @@ public class GuiReplayOverlay extends Gui {
private final GuiKeyframeTimeline timeline = new GuiKeyframeTimeline(TIMELINE_X, TOP_ROW - 1, WIDTH - 14 - TIMELINE_X, false, true, false, false) {
@Override
public void mouseClick(Minecraft mc, int mouseX, int mouseY, int button) {
if(!enabled) return;
super.mouseClick(mc, mouseX, mouseY, button);
if(!(ReplayHandler.getSelectedKeyframe() instanceof MarkerKeyframe))
performJump(timeline.getTimeAt(mouseX, mouseY));