2021-09-30 21:44:30 -05:00
|
|
|
package noppes.npcs.client.gui.script;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.client.gui.GuiButton;
|
2023-07-13 21:42:22 -05:00
|
|
|
import net.minecraft.client.gui.GuiScreen;
|
2022-05-16 00:42:40 -05:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2021-09-30 21:44:30 -05:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2022-05-16 00:42:40 -05:00
|
|
|
import noppes.npcs.client.Client;
|
2021-09-30 21:44:30 -05:00
|
|
|
import noppes.npcs.client.gui.util.GuiNPCInterface;
|
|
|
|
|
import noppes.npcs.client.gui.util.GuiNpcButton;
|
2022-05-16 00:42:40 -05:00
|
|
|
import noppes.npcs.client.gui.util.IGuiData;
|
|
|
|
|
import noppes.npcs.constants.EnumPacketServer;
|
2021-10-01 01:17:12 -05:00
|
|
|
import org.lwjgl.opengl.GL11;
|
2021-09-30 21:44:30 -05:00
|
|
|
|
2023-07-13 21:42:22 -05:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
2022-05-16 00:42:40 -05:00
|
|
|
public class GuiScriptGlobal extends GuiNPCInterface implements IGuiData {
|
2021-09-30 21:44:30 -05:00
|
|
|
private final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/smallbg.png");
|
2023-07-13 21:42:22 -05:00
|
|
|
private HashMap<Integer,Class<?>> scriptGuiClasses = new HashMap<>();
|
2021-09-30 21:44:30 -05:00
|
|
|
|
|
|
|
|
public GuiScriptGlobal() {
|
|
|
|
|
this.xSize = 176;
|
|
|
|
|
this.ySize = 222;
|
|
|
|
|
this.drawDefaultBackground = false;
|
|
|
|
|
this.title = "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void initGui() {
|
|
|
|
|
super.initGui();
|
2023-07-13 21:42:22 -05:00
|
|
|
GuiNpcButton playerButton = new GuiNpcButton(0, this.guiLeft + 38, this.guiTop + 20, 100, 20, "Players");
|
|
|
|
|
playerButton.setEnabled(false);
|
|
|
|
|
this.addButton(playerButton);
|
|
|
|
|
GuiNpcButton forgeButton = new GuiNpcButton(1, this.guiLeft + 38, this.guiTop + 50, 100, 20, "Forge");
|
|
|
|
|
forgeButton.setEnabled(false);
|
|
|
|
|
this.addButton(forgeButton);
|
|
|
|
|
GuiNpcButton npcButton = new GuiNpcButton(2, this.guiLeft + 38, this.guiTop + 80, 100, 20, "All NPCs");
|
|
|
|
|
npcButton.setEnabled(false);
|
|
|
|
|
this.addButton(npcButton);
|
2022-05-16 00:42:40 -05:00
|
|
|
Client.sendData(EnumPacketServer.ScriptGlobalGuiDataGet, new Object[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setGuiData(NBTTagCompound compound) {
|
2023-07-13 21:42:22 -05:00
|
|
|
getButton(0).setEnabled(compound.getBoolean("PlayerScriptsEnabled") && compound.getBoolean("ScriptsEnabled"));
|
|
|
|
|
getButton(1).setEnabled(compound.getBoolean("ForgeScriptsEnabled") && compound.getBoolean("ScriptsEnabled"));
|
|
|
|
|
getButton(2).setEnabled(compound.getBoolean("GlobalNPCScriptsEnabled") && compound.getBoolean("ScriptsEnabled"));
|
|
|
|
|
}
|
2022-03-23 18:54:55 -05:00
|
|
|
|
2023-07-13 21:42:22 -05:00
|
|
|
//For use with mods wanting to add their own scripts/APIs. Add the class of your GUI that extends from GuiScriptInterface as
|
|
|
|
|
//a parameter, the text the new button that appears when the scripter is right clicked should show, and whether it's enabled.
|
|
|
|
|
//For examples of what kind of GUI class to create, look at GuiScriptForge.
|
|
|
|
|
public void addScriptGui(Class<?> guiClass, String buttonText, boolean enabled) {
|
|
|
|
|
int buttonId = this.buttons.size();
|
|
|
|
|
this.scriptGuiClasses.put(buttonId,guiClass);
|
2022-03-23 18:54:55 -05:00
|
|
|
|
2023-07-13 21:42:22 -05:00
|
|
|
GuiNpcButton npcButton = new GuiNpcButton(buttonId, this.guiLeft + 38, this.guiTop + 80 + (buttonId - 2) * 30, 100, 20, buttonText);
|
|
|
|
|
npcButton.setEnabled(enabled);
|
2022-03-23 18:54:55 -05:00
|
|
|
this.addButton(npcButton);
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void drawScreen(int i, int j, float f) {
|
|
|
|
|
this.drawDefaultBackground();
|
2021-10-01 01:17:12 -05:00
|
|
|
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
2021-09-30 21:44:30 -05:00
|
|
|
this.mc.renderEngine.bindTexture(this.resource);
|
|
|
|
|
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
|
|
|
|
|
super.drawScreen(i, j, f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void actionPerformed(GuiButton guibutton) {
|
|
|
|
|
if (guibutton.id == 0) {
|
|
|
|
|
this.displayGuiScreen(new GuiScriptPlayers());
|
|
|
|
|
}
|
2021-10-18 06:33:39 -05:00
|
|
|
if (guibutton.id == 1) {
|
2021-09-30 21:44:30 -05:00
|
|
|
this.displayGuiScreen(new GuiScriptForge());
|
2021-10-18 06:33:39 -05:00
|
|
|
}
|
2022-03-23 03:54:06 -05:00
|
|
|
if (guibutton.id == 2) {
|
|
|
|
|
this.displayGuiScreen(new GuiScriptAllNPCs());
|
|
|
|
|
}
|
2023-07-13 21:42:22 -05:00
|
|
|
if (guibutton.id > 2) {
|
|
|
|
|
try {
|
|
|
|
|
Class<?> guiClass = this.scriptGuiClasses.get(guibutton.id);
|
|
|
|
|
this.displayGuiScreen((GuiScreen) guiClass.newInstance());
|
|
|
|
|
} catch (Exception ignored) {}
|
|
|
|
|
}
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void keyTyped(char c, int i) {
|
|
|
|
|
if (i == 1 || this.isInventoryKey(i)) {
|
|
|
|
|
this.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void save() {
|
|
|
|
|
}
|
|
|
|
|
}
|