Changed script GUIs to allow third part script GUIs to be added

This commit is contained in:
Luis C.M committed 2023-07-13 21:42:22 -05:00
1 parent 3b0879b0db
commit 3d40e2dfd1
2 files changed
+41 -18

No files matched your search

@@ -6,6 +6,7 @@
package noppes.npcs.client.gui.script;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import noppes.npcs.client.Client;
@@ -15,8 +16,11 @@ import noppes.npcs.client.gui.util.IGuiData;
import noppes.npcs.constants.EnumPacketServer;
import org.lwjgl.opengl.GL11;
import java.util.HashMap;
public class GuiScriptGlobal extends GuiNPCInterface implements IGuiData {
private final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/smallbg.png");
private HashMap<Integer,Class<?>> scriptGuiClasses = new HashMap<>();
public GuiScriptGlobal() {
this.xSize = 176;
@@ -27,20 +31,33 @@ public class GuiScriptGlobal extends GuiNPCInterface implements IGuiData {
public void initGui() {
super.initGui();
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);
Client.sendData(EnumPacketServer.ScriptGlobalGuiDataGet, new Object[0]);
}
public void setGuiData(NBTTagCompound compound) {
GuiNpcButton playerButton = new GuiNpcButton(0, this.guiLeft + 38, this.guiTop + 20, 100, 20, "Players");
playerButton.setEnabled(compound.getBoolean("PlayerScriptsEnabled") && compound.getBoolean("ScriptsEnabled"));
this.addButton(playerButton);
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"));
}
GuiNpcButton forgeButton = new GuiNpcButton(1, this.guiLeft + 38, this.guiTop + 50, 100, 20, "Forge");
forgeButton.setEnabled(compound.getBoolean("ForgeScriptsEnabled") && compound.getBoolean("ScriptsEnabled"));
this.addButton(forgeButton);
//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);
GuiNpcButton npcButton = new GuiNpcButton(2, this.guiLeft + 38, this.guiTop + 80, 100, 20, "All NPCs");
npcButton.setEnabled(compound.getBoolean("GlobalNPCScriptsEnabled") && compound.getBoolean("ScriptsEnabled"));
GuiNpcButton npcButton = new GuiNpcButton(buttonId, this.guiLeft + 38, this.guiTop + 80 + (buttonId - 2) * 30, 100, 20, buttonText);
npcButton.setEnabled(enabled);
this.addButton(npcButton);
}
@@ -62,6 +79,12 @@ public class GuiScriptGlobal extends GuiNPCInterface implements IGuiData {
if (guibutton.id == 2) {
this.displayGuiScreen(new GuiScriptAllNPCs());
}
if (guibutton.id > 2) {
try {
Class<?> guiClass = this.scriptGuiClasses.get(guibutton.id);
this.displayGuiScreen((GuiScreen) guiClass.newInstance());
} catch (Exception ignored) {}
}
}
public void keyTyped(char c, int i) {