Files
CustomNPC-Plus/src/main/java/noppes/npcs/client/gui/script/GuiScriptGlobal.java
T

96 lines
4.0 KiB
Java
Raw Normal View History

package noppes.npcs.client.gui.script;
2025-02-02 23:15:53 -05:00
import kamkeel.npcs.network.packets.request.script.ScriptInfoPacket;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
2022-05-16 00:42:40 -05:00
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
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;
2026-01-22 20:05:07 +02:00
import noppes.npcs.controllers.data.ForgeDataScript;
import noppes.npcs.controllers.data.GlobalNPCDataScript;
import noppes.npcs.controllers.data.PlayerDataScript;
import org.lwjgl.opengl.GL11;
import java.util.HashMap;
2022-05-16 00:42:40 -05:00
public class GuiScriptGlobal extends GuiNPCInterface implements IGuiData {
2026-02-24 18:55:52 -05:00
private final ResourceLocation resource = new ResourceLocation("customnpcs", "textures/gui/menubg.png");
2025-03-13 17:14:45 -04:00
private HashMap<Integer, Class<?>> scriptGuiClasses = new HashMap<>();
public GuiScriptGlobal() {
this.xSize = 176;
this.ySize = 222;
this.drawDefaultBackground = false;
this.title = "";
}
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);
2025-02-02 23:15:53 -05:00
ScriptInfoPacket.Get();
2022-05-16 00:42:40 -05:00
}
public void setGuiData(NBTTagCompound compound) {
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"));
}
//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();
2025-03-13 17:14:45 -04:00
this.scriptGuiClasses.put(buttonId, guiClass);
GuiNpcButton npcButton = new GuiNpcButton(buttonId, this.guiLeft + 38, this.guiTop + 80 + (buttonId - 2) * 30, 100, 20, buttonText);
npcButton.setEnabled(enabled);
this.addButton(npcButton);
}
public void drawScreen(int i, int j, float f) {
this.drawDefaultBackground();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
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) {
2026-01-22 20:05:07 +02:00
GuiScriptInterface.open(this, new PlayerDataScript(null));
}
if (guibutton.id == 1) {
2026-01-22 20:05:07 +02:00
GuiScriptInterface.open(this, new ForgeDataScript());
}
2022-03-23 03:54:06 -05:00
if (guibutton.id == 2) {
2026-01-22 20:05:07 +02:00
GuiScriptInterface.open(this, new GlobalNPCDataScript(null));
2022-03-23 03:54:06 -05:00
}
if (guibutton.id > 2) {
try {
Class<?> guiClass = this.scriptGuiClasses.get(guibutton.id);
this.displayGuiScreen((GuiScreen) guiClass.newInstance());
2025-03-13 17:14:45 -04:00
} catch (Exception ignored) {
}
}
}
public void keyTyped(char c, int i) {
if (i == 1 || this.isInventoryKey(i)) {
this.close();
}
}
public void save() {
}
}