mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 09:55:11 +00:00
Changed script GUIs to allow third part script GUIs to be added
This commit is contained in:
1 parent
3b0879b0db
commit
3d40e2dfd1
2 files changed
+41
-18
No files matched your search
@@ -193,7 +193,7 @@ public class PacketHandlerServer{
|
||||
}
|
||||
}
|
||||
|
||||
private void getScripts(IScriptHandler data, ByteBuf buffer, EntityPlayerMP player) {
|
||||
public static void getScripts(IScriptHandler data, ByteBuf buffer, EntityPlayerMP player) {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
compound.setBoolean("ScriptEnabled", data.getEnabled());
|
||||
compound.setString("ScriptLanguage", data.getLanguage());
|
||||
@@ -211,7 +211,7 @@ public class PacketHandlerServer{
|
||||
}
|
||||
}
|
||||
|
||||
private void saveScripts(IScriptHandler data, ByteBuf buffer, EntityPlayerMP player) throws Exception {
|
||||
public static void saveScripts(IScriptHandler data, ByteBuf buffer, EntityPlayerMP player) throws IOException {
|
||||
int tab = buffer.readInt();
|
||||
int totalScripts = buffer.readInt();
|
||||
if (totalScripts == 0) {
|
||||
@@ -245,9 +245,9 @@ public class PacketHandlerServer{
|
||||
private void npcEventScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws Exception {
|
||||
DataScript data = npc.script;
|
||||
if(type == EnumPacketServer.EventScriptDataGet) {
|
||||
this.getScripts(data,buffer,player);
|
||||
getScripts(data,buffer,player);
|
||||
} else if(type == EnumPacketServer.EventScriptDataSave) {
|
||||
this.saveScripts(data,buffer,player);
|
||||
saveScripts(data,buffer,player);
|
||||
npc.updateAI = true;
|
||||
npc.script.hasInited = false;
|
||||
if(ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){
|
||||
@@ -259,9 +259,9 @@ public class PacketHandlerServer{
|
||||
private void playerScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception {
|
||||
PlayerDataScript data = ScriptController.Instance.playerScripts;
|
||||
if(type == EnumPacketServer.ScriptPlayerGet) {
|
||||
this.getScripts(data,buffer,player);
|
||||
getScripts(data,buffer,player);
|
||||
} else if(type == EnumPacketServer.ScriptPlayerSave) {
|
||||
this.saveScripts(data,buffer,player);
|
||||
saveScripts(data,buffer,player);
|
||||
ScriptController.Instance.lastPlayerUpdate = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
@@ -269,9 +269,9 @@ public class PacketHandlerServer{
|
||||
private void forgeScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception {
|
||||
ForgeDataScript data = ScriptController.Instance.forgeScripts;
|
||||
if (type == EnumPacketServer.ScriptForgeGet) {
|
||||
this.getScripts(data,buffer,player);
|
||||
getScripts(data,buffer,player);
|
||||
} else if (type == EnumPacketServer.ScriptForgeSave) {
|
||||
this.saveScripts(data,buffer,player);
|
||||
saveScripts(data,buffer,player);
|
||||
ScriptController.Instance.lastForgeUpdate = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
@@ -279,9 +279,9 @@ public class PacketHandlerServer{
|
||||
private void npcGlobalScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception {
|
||||
GlobalNPCDataScript data = ScriptController.Instance.globalNpcScripts;
|
||||
if(type == EnumPacketServer.ScriptGlobalNPCGet) {
|
||||
this.getScripts(data,buffer,player);
|
||||
getScripts(data,buffer,player);
|
||||
} else if(type == EnumPacketServer.ScriptGlobalNPCSave) {
|
||||
this.saveScripts(data,buffer,player);
|
||||
saveScripts(data,buffer,player);
|
||||
ScriptController.Instance.lastGlobalNpcUpdate = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user