Created GuiOutsideClickableElement interface for GuiElements that can be deselected/closed by clicking outside of them and properly forward mouse clicks to these elements
This commit is contained in:
@@ -66,8 +66,13 @@ public class ComposedElement implements GuiElement {
|
||||
boolean clicked = false;
|
||||
//iterate over elements in reverse order to first handle mouse clicks of elements that are drawn on top
|
||||
for (int i=0; i<parts.size(); i++) {
|
||||
clicked = parts.get(parts.size()-1-i).mouseClick(mc, mouseX, mouseY, button);
|
||||
if(clicked) break;
|
||||
GuiElement part = parts.get(parts.size() - 1 - i);
|
||||
|
||||
//if GuiOutsideClickableElement, forward mouse clicks outside of that element
|
||||
if(!clicked || (part instanceof GuiOutsideClickableElement && !part.isHovering(mouseX, mouseY))) {
|
||||
boolean cl = part.mouseClick(mc, mouseX, mouseY, button);
|
||||
if(cl) clicked = cl;
|
||||
}
|
||||
}
|
||||
return clicked;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.minecraft.client.gui.GuiTextField;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class GuiAdvancedTextField extends GuiTextField implements GuiElement {
|
||||
public class GuiAdvancedTextField extends GuiTextField implements GuiElement, GuiOutsideClickableElement {
|
||||
public String hint;
|
||||
public int hintTextColor = Color.DARK_GRAY.getRGB();
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.lwjgl.util.Point;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class GuiColorPicker extends GuiAdvancedButton implements GuiOverlayElement {
|
||||
public class GuiColorPicker extends GuiAdvancedButton implements GuiOverlayElement, GuiOutsideClickableElement {
|
||||
|
||||
private final int PICKER_SIZE = 100;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiFileChooser extends GuiAdvancedButton {
|
||||
public class GuiFileChooser extends GuiAdvancedButton implements GuiOutsideClickableElement {
|
||||
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
/**
|
||||
* A dummy interface which all Gui Elements that can be unfocused (or closed)
|
||||
* by clicking outside of their bounds have to implement
|
||||
*/
|
||||
public interface GuiOutsideClickableElement {
|
||||
}
|
||||
@@ -37,7 +37,7 @@ import java.util.Arrays;
|
||||
import static net.minecraft.client.renderer.GlStateManager.*;
|
||||
import static net.minecraft.util.MathHelper.clamp_int;
|
||||
|
||||
public class GuiTextArea extends Gui implements GuiElement {
|
||||
public class GuiTextArea extends Gui implements GuiElement, GuiOutsideClickableElement {
|
||||
|
||||
// Constants
|
||||
protected static final int BORDER = 4;
|
||||
|
||||
Reference in New Issue
Block a user