2022-01-12 04:44:08 -06:00
|
|
|
package noppes.npcs.scripted.gui;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2022-11-15 15:25:53 -05:00
|
|
|
import noppes.npcs.api.gui.IButton;
|
|
|
|
|
import noppes.npcs.api.gui.ICustomGuiComponent;
|
2022-01-12 04:44:08 -06:00
|
|
|
|
|
|
|
|
public class ScriptGuiButton extends ScriptGuiComponent implements IButton {
|
|
|
|
|
int width;
|
|
|
|
|
int height;
|
|
|
|
|
String label;
|
|
|
|
|
String texture;
|
|
|
|
|
int textureX;
|
|
|
|
|
int textureY;
|
2023-02-04 11:14:49 -06:00
|
|
|
float scale;
|
|
|
|
|
boolean enabled;
|
2022-01-12 04:44:08 -06:00
|
|
|
|
|
|
|
|
public ScriptGuiButton() {
|
|
|
|
|
this.height = -1;
|
|
|
|
|
this.textureY = -1;
|
2023-02-04 11:14:49 -06:00
|
|
|
this.scale = 1.0F;
|
2022-01-12 04:44:08 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ScriptGuiButton(int id, String label, int x, int y) {
|
|
|
|
|
this.height = -1;
|
|
|
|
|
this.textureY = -1;
|
2023-02-04 11:14:49 -06:00
|
|
|
this.scale = 1.0F;
|
2022-01-12 04:44:08 -06:00
|
|
|
this.setID(id);
|
|
|
|
|
this.setLabel(label);
|
|
|
|
|
this.setPos(x, y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ScriptGuiButton(int id, String label, int x, int y, int width, int height) {
|
|
|
|
|
this(id, label, x, y);
|
|
|
|
|
this.setSize(width, height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ScriptGuiButton(int id, String label, int x, int y, int width, int height, String texture) {
|
|
|
|
|
this(id, label, x, y, width, height);
|
|
|
|
|
this.setTexture(texture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ScriptGuiButton(int id, String label, int x, int y, int width, int height, String texture, int textureX, int textureY) {
|
|
|
|
|
this(id, label, x, y, width, height, texture);
|
|
|
|
|
this.setTextureOffset(textureX, textureY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getWidth() {
|
|
|
|
|
return this.width;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getHeight() {
|
|
|
|
|
return this.height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IButton setSize(int width, int height) {
|
|
|
|
|
this.width = width;
|
|
|
|
|
this.height = height;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getLabel() {
|
|
|
|
|
return this.label;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IButton setLabel(String label) {
|
|
|
|
|
this.label = label;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getTexture() {
|
|
|
|
|
return this.texture;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean hasTexture() {
|
|
|
|
|
return this.texture != null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IButton setTexture(String texture) {
|
|
|
|
|
this.texture = texture;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getTextureX() {
|
|
|
|
|
return this.textureX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getTextureY() {
|
|
|
|
|
return this.textureY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IButton setTextureOffset(int textureX, int textureY) {
|
|
|
|
|
this.textureX = textureX;
|
|
|
|
|
this.textureY = textureY;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getID() {
|
|
|
|
|
return this.id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ICustomGuiComponent setID(int id) {
|
|
|
|
|
this.id = id;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getPosX() {
|
|
|
|
|
return this.posX;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getPosY() {
|
|
|
|
|
return this.posY;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-04 11:14:49 -06:00
|
|
|
public void setScale(float scale) {
|
|
|
|
|
this.scale = scale;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public float getScale() {
|
|
|
|
|
return this.scale;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setEnabled(boolean enabled) {
|
|
|
|
|
this.enabled = enabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isEnabled() {
|
|
|
|
|
return this.enabled;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-12 04:44:08 -06:00
|
|
|
public int getType() {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public NBTTagCompound toNBT(NBTTagCompound nbt) {
|
|
|
|
|
super.toNBT(nbt);
|
|
|
|
|
if (this.width > 0 && this.height > 0) {
|
|
|
|
|
nbt.setIntArray("size", new int[]{this.width, this.height});
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-04 11:14:49 -06:00
|
|
|
nbt.setFloat("scale",this.scale);
|
|
|
|
|
nbt.setBoolean("enabled",this.enabled);
|
|
|
|
|
|
2022-01-12 04:44:08 -06:00
|
|
|
nbt.setString("label", this.label);
|
|
|
|
|
if (this.hasTexture()) {
|
|
|
|
|
nbt.setString("texture", this.texture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.textureX >= 0 && this.textureY >= 0) {
|
|
|
|
|
nbt.setIntArray("texPos", new int[]{this.textureX, this.textureY});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nbt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ScriptGuiComponent fromNBT(NBTTagCompound nbt) {
|
|
|
|
|
super.fromNBT(nbt);
|
|
|
|
|
if (nbt.hasKey("size")) {
|
|
|
|
|
this.setSize(nbt.getIntArray("size")[0], nbt.getIntArray("size")[1]);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-04 11:14:49 -06:00
|
|
|
this.setScale(nbt.getFloat("scale"));
|
|
|
|
|
this.setEnabled(nbt.getBoolean("enabled"));
|
|
|
|
|
|
2022-01-12 04:44:08 -06:00
|
|
|
this.setLabel(nbt.getString("label"));
|
|
|
|
|
if (nbt.hasKey("texture")) {
|
|
|
|
|
this.setTexture(nbt.getString("texture"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (nbt.hasKey("texPos")) {
|
|
|
|
|
this.setTextureOffset(nbt.getIntArray("texPos")[0], nbt.getIntArray("texPos")[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
}
|