2015-12-17 22:09:24 +01:00
|
|
|
package com.pahimar.ee3.client.gui.component;
|
|
|
|
|
|
|
|
import com.pahimar.ee3.client.gui.GuiBase;
|
2015-12-23 18:06:26 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2015-12-17 22:09:24 +01:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
|
2015-12-22 21:52:20 +01:00
|
|
|
import java.util.Comparator;
|
|
|
|
|
2015-12-18 21:55:19 +01:00
|
|
|
public abstract class GuiComponent implements Comparable<GuiComponent> {
|
2015-12-17 22:09:24 +01:00
|
|
|
|
2015-12-22 21:52:20 +01:00
|
|
|
public static Comparator<GuiComponent> orderingComparator = new Comparator<GuiComponent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int compare(GuiComponent guiComponent1, GuiComponent guiComponent2) {
|
|
|
|
if (guiComponent1.ordering == guiComponent2.ordering) {
|
|
|
|
if (guiComponent1.zIndex == guiComponent2.zIndex) {
|
|
|
|
if (guiComponent1.id != null && guiComponent2.id != null) {
|
|
|
|
return guiComponent1.id.compareToIgnoreCase(guiComponent2.id);
|
|
|
|
} else {
|
|
|
|
return guiComponent1.hashCode() - guiComponent2.hashCode();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Purposefully sorting so that higher z-indices appear first in the map
|
|
|
|
return guiComponent2.zIndex - guiComponent1.zIndex;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return guiComponent1.ordering - guiComponent2.ordering;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
public static Comparator<GuiComponent> zIndexComparator = new Comparator<GuiComponent>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int compare(GuiComponent guiComponent1, GuiComponent guiComponent2) {
|
|
|
|
if (guiComponent1.zIndex == guiComponent2.zIndex) {
|
|
|
|
if (guiComponent1.ordering == guiComponent2.ordering) {
|
|
|
|
if (guiComponent1.id != null && guiComponent2.id != null) {
|
|
|
|
return guiComponent1.id.compareToIgnoreCase(guiComponent2.id);
|
|
|
|
} else {
|
|
|
|
return guiComponent1.hashCode() - guiComponent2.hashCode();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return guiComponent1.ordering - guiComponent2.ordering;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Purposefully sorting so that higher z-indices appear first in the map
|
|
|
|
return guiComponent2.zIndex - guiComponent1.zIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-12-17 22:09:24 +01:00
|
|
|
protected final GuiBase parentGui;
|
|
|
|
protected final String id;
|
2015-12-23 18:06:26 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2015-12-17 22:09:24 +01:00
|
|
|
protected ResourceLocation texture;
|
|
|
|
protected int positionX, positionY, componentWidth, componentHeight, textureWidth, textureHeight;
|
2015-12-18 21:55:19 +01:00
|
|
|
protected int ordering = 0;
|
2015-12-21 21:54:07 +01:00
|
|
|
protected int zIndex = 0;
|
2015-12-17 22:09:24 +01:00
|
|
|
protected boolean isVisible = true;
|
|
|
|
protected boolean isEnabled = true;
|
2016-01-04 03:28:43 +01:00
|
|
|
protected boolean isFocusable = true;
|
2015-12-17 22:09:24 +01:00
|
|
|
|
2015-12-21 21:54:07 +01:00
|
|
|
public GuiComponent(GuiBase parentGui, String id) {
|
|
|
|
this(parentGui, id, null, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public GuiComponent(GuiBase parentGui, String id, ResourceLocation texture, int positionX, int positionY) {
|
|
|
|
this(parentGui, id, texture, positionX, positionY, 256, 256);
|
|
|
|
}
|
|
|
|
|
|
|
|
public GuiComponent(GuiBase parentGui, String id, ResourceLocation texture, int positionX, int positionY, int componentWidth, int componentHeight) {
|
|
|
|
this(parentGui, id, texture, positionX, positionY, componentWidth, componentHeight, 256, 256);
|
|
|
|
}
|
|
|
|
|
|
|
|
public GuiComponent(GuiBase parentGui, String id, ResourceLocation texture, int positionX, int positionY, int componentWidth, int componentHeight, int textureWidth, int textureHeight) {
|
2015-12-17 22:09:24 +01:00
|
|
|
this.parentGui = parentGui;
|
|
|
|
this.id = id;
|
2015-12-21 21:54:07 +01:00
|
|
|
this.texture = texture;
|
2015-12-17 22:09:24 +01:00
|
|
|
this.positionX = positionX;
|
|
|
|
this.positionY = positionY;
|
2015-12-21 21:54:07 +01:00
|
|
|
this.componentWidth = componentWidth;
|
|
|
|
this.componentHeight = componentHeight;
|
|
|
|
this.textureWidth = textureWidth;
|
|
|
|
this.textureHeight = textureHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final GuiBase getParentGui() {
|
|
|
|
return parentGui;
|
2015-12-17 22:09:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public final String getId() {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
public ResourceLocation getTexture() {
|
|
|
|
return texture;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GuiComponent setTexture(ResourceLocation texture) {
|
|
|
|
this.texture = texture;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GuiComponent setTexture(ResourceLocation texture, int textureWidth, int textureHeight) {
|
|
|
|
this.texture = texture;
|
|
|
|
return this.setTextureSize(textureWidth, textureHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getPositionX() {
|
|
|
|
return positionX;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getPositionY() {
|
|
|
|
return positionY;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GuiComponent setPosition(int positionX, int positionY) {
|
|
|
|
this.positionX = positionX;
|
|
|
|
this.positionY = positionY;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getComponentWidth() {
|
|
|
|
return componentWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getComponentHeight() {
|
|
|
|
return componentHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GuiComponent setComponentSize(int componentWidth, int componentHeight) {
|
|
|
|
this.componentWidth = componentWidth;
|
|
|
|
this.componentHeight = componentHeight;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getTextureWidth() {
|
|
|
|
return textureWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getTextureHeight() {
|
|
|
|
return textureHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GuiComponent setTextureSize(int textureWidth, int textureHeight) {
|
|
|
|
this.textureWidth = textureWidth;
|
|
|
|
this.textureHeight = textureHeight;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-12-21 21:54:07 +01:00
|
|
|
public int getOrdering() {
|
|
|
|
return ordering;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GuiComponent setOrdering(int ordering) {
|
|
|
|
this.ordering = ordering;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getZIndex() {
|
|
|
|
return zIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GuiComponent setZIndex(int zIndex) {
|
|
|
|
this.zIndex = zIndex;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-12-17 22:09:24 +01:00
|
|
|
public boolean isVisible() {
|
|
|
|
return isVisible;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GuiComponent setVisible(boolean isVisible) {
|
2015-12-18 21:55:19 +01:00
|
|
|
|
|
|
|
if (this.isVisible && !isVisible) {
|
|
|
|
this.onHide();
|
|
|
|
} else if (!this.isVisible && isVisible) {
|
|
|
|
this.onShow();
|
|
|
|
}
|
|
|
|
|
2015-12-17 22:09:24 +01:00
|
|
|
this.isVisible = isVisible;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isEnabled() {
|
|
|
|
return isEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GuiComponent setEnabled(boolean isEnabled) {
|
2015-12-18 21:55:19 +01:00
|
|
|
|
|
|
|
if (this.isEnabled && !isEnabled) {
|
|
|
|
this.onDisable();
|
|
|
|
} else if (!this.isEnabled && isEnabled) {
|
|
|
|
this.onEnable();
|
|
|
|
}
|
|
|
|
|
2015-12-17 22:09:24 +01:00
|
|
|
this.isEnabled = isEnabled;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2016-01-04 03:28:43 +01:00
|
|
|
public boolean isFocusable() {
|
|
|
|
return isFocusable;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GuiComponent setIsFocusable(boolean isFocusable) {
|
|
|
|
this.isFocusable = isFocusable;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasFocus() {
|
|
|
|
if (isFocusable) {
|
|
|
|
return getParentGui().getActiveGuiComponentId().equals(getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-12-22 21:52:20 +01:00
|
|
|
public abstract void drawForeground(int rawMouseX, int rawMouseY, float partialTicks);
|
2015-12-17 22:09:24 +01:00
|
|
|
|
2015-12-22 21:52:20 +01:00
|
|
|
public abstract void drawBackground(int rawMouseX, int rawMouseY, float partialTicks);
|
2015-12-17 22:09:24 +01:00
|
|
|
|
2015-12-22 21:52:20 +01:00
|
|
|
public abstract void onUpdate(int rawMouseX, int rawMouseY, float partialTicks);
|
2015-12-17 22:09:24 +01:00
|
|
|
|
|
|
|
/**
|
2015-12-21 21:54:07 +01:00
|
|
|
* Checks whether or not the specified coordinate intersects with this GuiComponent
|
2015-12-17 22:09:24 +01:00
|
|
|
*
|
2015-12-21 21:54:07 +01:00
|
|
|
* @param xCoord x position
|
|
|
|
* @param yCoord y position
|
|
|
|
* @return true if the specified coordinates intersect with this GuiComponent, false otherwise
|
|
|
|
*/
|
|
|
|
public boolean intersectsWith(int xCoord, int yCoord) {
|
|
|
|
return (xCoord >= this.positionX && xCoord <= this.positionX + this.componentWidth) && (yCoord >= this.positionY && yCoord <= this.positionY + this.componentHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether or not the specified coordinate and z index intersects with this GuiComponent
|
|
|
|
*
|
|
|
|
* @param xCoord x position
|
|
|
|
* @param yCoord y position
|
|
|
|
* @param zIndex z index
|
|
|
|
* @return
|
2015-12-17 22:09:24 +01:00
|
|
|
*/
|
2015-12-21 21:54:07 +01:00
|
|
|
public boolean intersectsWith(int xCoord, int yCoord, int zIndex) {
|
|
|
|
return (xCoord >= this.positionX && xCoord <= this.positionX + this.componentWidth) && (yCoord >= this.positionY && yCoord <= this.positionY + this.componentHeight) && (zIndex == this.zIndex);
|
2015-12-17 22:09:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-23 18:06:26 +01:00
|
|
|
/**
|
|
|
|
* @param rawMouseX
|
|
|
|
* @param rawMouseY
|
|
|
|
* @param mouseButton
|
|
|
|
*/
|
|
|
|
public abstract void onMouseButtonClicked(int rawMouseX, int rawMouseY, int mouseButton);
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param rawMouseX
|
|
|
|
* @param rawMouseY
|
|
|
|
* @param mouseButton
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean onMouseButtonClick(int rawMouseX, int rawMouseY, int mouseButton) {
|
|
|
|
onMouseButtonClicked(rawMouseX, rawMouseY, mouseButton);
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-17 22:09:24 +01:00
|
|
|
|
2015-12-23 18:06:26 +01:00
|
|
|
public abstract void onMouseButtonDown(int rawMouseX, int rawMouseY, int mouseButton);
|
2015-12-17 22:09:24 +01:00
|
|
|
|
2015-12-23 18:06:26 +01:00
|
|
|
public abstract void onMouseButtonUp(int rawMouseX, int rawMouseY, int mouseButton);
|
2015-12-17 22:09:24 +01:00
|
|
|
|
2015-12-23 18:06:26 +01:00
|
|
|
public abstract void onMouseButtonRelease(int rawMouseX, int rawMouseY, int mouseButton, long duration);
|
2015-12-17 22:09:24 +01:00
|
|
|
|
2015-12-23 18:06:26 +01:00
|
|
|
public abstract void onMouseMove(int prevRawMouseX, int prevRawMouseY, int newRawMouseX, int newRawMouseY);
|
2015-12-17 22:09:24 +01:00
|
|
|
|
2015-12-23 18:06:26 +01:00
|
|
|
public abstract void onMouseEnter(int rawMouseX, int rawMouseY);
|
2015-12-17 22:09:24 +01:00
|
|
|
|
2015-12-23 18:06:26 +01:00
|
|
|
public abstract void onMouseOver(int rawMouseX, int rawMouseY, float partialTicks);
|
2015-12-17 22:09:24 +01:00
|
|
|
|
2015-12-23 18:06:26 +01:00
|
|
|
public abstract void onMouseLeave(int rawMouseX, int rawMouseY);
|
|
|
|
|
|
|
|
public abstract void onMouseWheel(int rawMouseX, int rawMouseY, int change);
|
|
|
|
|
|
|
|
public abstract void onKeyPressed(char characterTyped, int keyPressed);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param characterTyped
|
|
|
|
* @param keyPressed
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean onKeyPress(char characterTyped, int keyPressed) {
|
|
|
|
onKeyPress(characterTyped, keyPressed);
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-17 22:09:24 +01:00
|
|
|
|
2016-01-04 03:28:43 +01:00
|
|
|
public abstract void onFocusGained();
|
2015-12-18 21:55:19 +01:00
|
|
|
|
|
|
|
public abstract void onFocusLost();
|
|
|
|
|
|
|
|
public abstract void onInit();
|
|
|
|
|
|
|
|
public abstract void onClose();
|
|
|
|
|
|
|
|
public abstract void onHide();
|
|
|
|
|
|
|
|
public abstract void onShow();
|
|
|
|
|
|
|
|
public abstract void onEnable();
|
|
|
|
|
|
|
|
public abstract void onDisable();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compares this GuiComponent with another one to determine sort order
|
|
|
|
*
|
|
|
|
* @param guiComponent the GuiComponent we are comparing this one against
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public int compareTo(GuiComponent guiComponent) {
|
2015-12-22 21:52:20 +01:00
|
|
|
return orderingComparator.compare(this, guiComponent);
|
2015-12-18 21:55:19 +01:00
|
|
|
}
|
2015-12-17 22:09:24 +01:00
|
|
|
}
|