2015-12-17 22:09:24 +01:00
|
|
|
package com.pahimar.ee3.client.gui.component;
|
|
|
|
|
|
|
|
import com.pahimar.ee3.client.gui.GuiBase;
|
|
|
|
import net.minecraft.util.ResourceLocation;
|
|
|
|
|
2015-12-18 21:55:19 +01:00
|
|
|
public abstract class GuiComponent implements Comparable<GuiComponent> {
|
2015-12-17 22:09:24 +01:00
|
|
|
|
|
|
|
protected final GuiBase parentGui;
|
|
|
|
protected final String id;
|
|
|
|
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-17 22:09:24 +01:00
|
|
|
protected boolean isVisible = true;
|
|
|
|
protected boolean isEnabled = true;
|
|
|
|
|
|
|
|
public GuiComponent(GuiBase parentGui, String id, int positionX, int positionY) {
|
|
|
|
this.parentGui = parentGui;
|
|
|
|
this.id = id;
|
|
|
|
this.positionX = positionX;
|
|
|
|
this.positionY = positionY;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-12-18 21:55:19 +01:00
|
|
|
public abstract void drawForeground(float partialTicks);
|
2015-12-17 22:09:24 +01:00
|
|
|
|
2015-12-18 21:55:19 +01:00
|
|
|
public abstract void drawBackground(float partialTicks);
|
2015-12-17 22:09:24 +01:00
|
|
|
|
2015-12-18 21:55:19 +01:00
|
|
|
public abstract void onUpdate(int mouseX, int mouseY, float partialTicks);
|
2015-12-17 22:09:24 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks whether or not the mouse cursor is intersecting with this GuiComponent
|
|
|
|
*
|
|
|
|
* @param mouseX x position of mouse cursor on the screen
|
|
|
|
* @param mouseY y position of mouse cursor on the screen
|
|
|
|
* @return true if the mouse cursor is intersecting with this GuiComponent, false otherwise
|
|
|
|
*/
|
|
|
|
public boolean intersectsWithMouse(int mouseX, int mouseY) {
|
2015-12-18 21:55:19 +01:00
|
|
|
return (mouseX >= this.positionX && mouseX <= this.positionX + this.componentWidth) && (mouseY >= this.positionY && mouseY <= this.positionY + this.componentHeight);
|
2015-12-17 22:09:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public abstract void onMouseButtonClick(int mouseX, int mouseY, int mouseButton);
|
|
|
|
|
|
|
|
public abstract void onMouseButtonDown(int mouseX, int mouseY, int mouseButton);
|
|
|
|
|
|
|
|
public abstract void onMouseButtonUp(int mouseX, int mouseY, int mouseButton);
|
|
|
|
|
|
|
|
public abstract void onMouseButtonRelease(int mouseX, int mouseY, int mouseButton, long duration);
|
|
|
|
|
|
|
|
public abstract void onMouseMove(int prevMouseX, int prevMouseY, int newMouseX, int newMouseY);
|
|
|
|
|
|
|
|
public abstract void onMouseEnter(int mouseX, int mouseY);
|
|
|
|
|
|
|
|
public abstract void onMouseOver(int mouseX, int mouseY);
|
|
|
|
|
|
|
|
public abstract void onMouseLeave(int mouseX, int mouseY);
|
|
|
|
|
|
|
|
public abstract void onKeyDown(int keyPressed);
|
|
|
|
|
|
|
|
public abstract void onKeyUp(int keyPressed);
|
|
|
|
|
|
|
|
public abstract void onKeyPress(char characterTyped, int keyPressed);
|
|
|
|
|
2015-12-18 21:55:19 +01:00
|
|
|
public abstract void onFocusGain();
|
|
|
|
|
|
|
|
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) {
|
|
|
|
if (this.ordering == guiComponent.ordering) {
|
|
|
|
if (this.id != null && guiComponent.id != null) {
|
|
|
|
return this.id.compareToIgnoreCase(guiComponent.id);
|
|
|
|
} else {
|
|
|
|
return this.hashCode() - guiComponent.hashCode();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return this.ordering - guiComponent.ordering;
|
|
|
|
}
|
|
|
|
}
|
2015-12-17 22:09:24 +01:00
|
|
|
}
|