"The Commit that properly implements the disabling of Gui Elements"
Added enabled Field to DelegatingElement, which every instance can handle itself Made isEnabled Field in GuiAdvancedTextField protected for subclasses to access Made GuiDraggingNumberInput only draggable while enabled Made GuiDropdown check enabled field before accepting mouse clicks Properly tints GuiTexturedButton if disabled
This commit is contained in:
@@ -3,6 +3,9 @@ package eu.crushedpixel.replaymod.gui.elements;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public abstract class DelegatingElement implements GuiElement {
|
||||
|
||||
protected boolean enabled = true;
|
||||
|
||||
public static DelegatingElement of(final GuiElement element) {
|
||||
return new DelegatingElement() {
|
||||
@Override
|
||||
@@ -55,5 +58,7 @@ public abstract class DelegatingElement implements GuiElement {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {}
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ public class GuiAdvancedTextField extends GuiTextField implements GuiElement {
|
||||
public String hint;
|
||||
public int hintTextColor = Color.DARK_GRAY.getRGB();
|
||||
|
||||
private boolean isEnabled = true;
|
||||
protected boolean isEnabled = true;
|
||||
private int disabledTextColor;
|
||||
|
||||
public GuiAdvancedTextField(FontRenderer fontRenderer, int x, int y, int width, int height) {
|
||||
|
||||
@@ -24,7 +24,7 @@ public class GuiDraggingNumberInput extends GuiNumberInputWithText {
|
||||
|
||||
@Override
|
||||
public void mouseClick(Minecraft mc, int mouseX, int mouseY, int button) {
|
||||
if(MouseUtils.isMouseWithinBounds(xPosition, yPosition, width, height)) {
|
||||
if(MouseUtils.isMouseWithinBounds(xPosition, yPosition, width, height) && isEnabled) {
|
||||
dragging = false;
|
||||
clicked = true;
|
||||
prevMouseX = mouseX;
|
||||
|
||||
@@ -5,7 +5,6 @@ import eu.crushedpixel.replaymod.gui.elements.listeners.SelectionListener;
|
||||
import eu.crushedpixel.replaymod.utils.MouseUtils;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.util.Point;
|
||||
|
||||
@@ -140,6 +139,7 @@ public class GuiDropdown<T> extends GuiAdvancedTextField {
|
||||
|
||||
public boolean mouseClickedResult(int xPos, int yPos) {
|
||||
boolean success = false;
|
||||
if(!isEnabled) return success;
|
||||
if(xPos > xPosition + width - height && xPos < xPosition + width && yPos > yPosition && yPos < yPosition + height) {
|
||||
open = !open;
|
||||
} else {
|
||||
|
||||
@@ -5,6 +5,8 @@ import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class GuiTexturedButton extends GuiAdvancedButton implements GuiElement {
|
||||
private final ResourceLocation texture;
|
||||
private final int u, v;
|
||||
@@ -23,11 +25,16 @@ public class GuiTexturedButton extends GuiAdvancedButton implements GuiElement {
|
||||
@Override
|
||||
public void drawButton(Minecraft mc, int mouseX, int mouseY) {
|
||||
if (visible) {
|
||||
hovered = isHovering(mouseX, mouseY);
|
||||
hovered = isHovering(mouseX, mouseY) && enabled;
|
||||
|
||||
if(!enabled) {
|
||||
GlStateManager.color(Color.GRAY.getRed() / 255f, Color.GRAY.getGreen() / 255f, Color.GRAY.getBlue() / 255f, 1f);
|
||||
} else {
|
||||
GlStateManager.color(1f, 1f, 1f);
|
||||
}
|
||||
|
||||
mc.renderEngine.bindTexture(texture);
|
||||
|
||||
GlStateManager.color(1, 1, 1);
|
||||
int u = this.u + (hovered ? width : 0);
|
||||
Gui.drawModalRectWithCustomSizedTexture(xPosition, yPosition, u, v, width, height, textureWidth, textureHeight);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user