mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 01:27:27 +00:00
Fixed NPC Script GUI error not saving/accessing scripts correctly.
This commit is contained in:
1 parent
72869e6a78
commit
17eb612fb8
2 files changed
+67
-69
No files matched your search
@@ -42,7 +42,7 @@ public class DataScript implements IScriptHandler {
|
||||
public boolean hasInited = false;
|
||||
|
||||
public DataScript(EntityNPCInterface npc) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int i = 0; i < 12; i++) {
|
||||
scripts.add(new ScriptContainer(this));
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public class DataScript implements IScriptHandler {
|
||||
|
||||
private List<ScriptContainer> readScript(NBTTagList list){
|
||||
List<ScriptContainer> scripts = new ArrayList<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int i = 0; i < 12; i++) {
|
||||
scripts.add(new ScriptContainer(this));
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import noppes.npcs.DataScript;
|
||||
import noppes.npcs.NoppesStringUtils;
|
||||
import noppes.npcs.client.Client;
|
||||
import noppes.npcs.client.NoppesUtil;
|
||||
import noppes.npcs.client.gui.script.EventGuiScriptList;
|
||||
import noppes.npcs.client.gui.swing.GuiJTextArea;
|
||||
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
||||
import noppes.npcs.client.gui.util.GuiMenuTopButton;
|
||||
@@ -28,23 +27,23 @@ import noppes.npcs.controllers.ScriptContainer;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCallback, ICustomScrollListener, IJTextAreaListener {
|
||||
public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCallback, ICustomScrollListener, IJTextAreaListener {
|
||||
public boolean showScript = false;
|
||||
private int activeTab = 0;
|
||||
public DataScript script;
|
||||
public Map<String,List<String>> languages = new HashMap<String,List<String>>();
|
||||
|
||||
|
||||
private static int activeConsole = 0;
|
||||
|
||||
|
||||
public GuiScript(EntityNPCInterface npc) {
|
||||
super(npc);
|
||||
script = npc.script;
|
||||
drawDefaultBackground = true;
|
||||
closeOnEsc = true;
|
||||
xSize = 420;
|
||||
|
||||
setBackground("menubg.png");
|
||||
Client.sendData(EnumPacketServer.ScriptDataGet);
|
||||
xSize = 420;
|
||||
|
||||
setBackground("menubg.png");
|
||||
Client.sendData(EnumPacketServer.ScriptDataGet);
|
||||
}
|
||||
|
||||
public void initGui() {
|
||||
@@ -57,38 +56,38 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
||||
top.active = !showScript;
|
||||
addTopButton(new GuiMenuTopButton(15, top, "gui.website"));
|
||||
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.add("script.init");
|
||||
list.add("script.update");
|
||||
list.add("script.interact");
|
||||
list.add("dialog.dialog");
|
||||
list.add("script.damaged");
|
||||
list.add("script.killed");
|
||||
list.add("script.attack");
|
||||
list.add("script.target");
|
||||
list.add("script.collide");
|
||||
list.add("script.kills");
|
||||
list.add("script.dialog_closed");
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.add("script.init");
|
||||
list.add("script.update");
|
||||
list.add("script.interact");
|
||||
list.add("dialog.dialog");
|
||||
list.add("script.damaged");
|
||||
list.add("script.killed");
|
||||
list.add("script.attack");
|
||||
list.add("script.target");
|
||||
list.add("script.collide");
|
||||
list.add("script.kills");
|
||||
list.add("script.dialog_closed");
|
||||
list.add("script.timer");
|
||||
|
||||
|
||||
if(showScript){
|
||||
addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5));
|
||||
GuiCustomScroll hooks = new GuiCustomScroll(this, 1);
|
||||
hooks.setSize(68, 198);
|
||||
hooks.guiLeft = guiLeft + 4;
|
||||
hooks.guiTop = guiTop + 14;
|
||||
hooks.setUnsortedList(list);
|
||||
hooks.selected = activeTab;
|
||||
addScroll(hooks);
|
||||
|
||||
hooks.setUnsortedList(list);
|
||||
hooks.selected = activeTab;
|
||||
addScroll(hooks);
|
||||
|
||||
ScriptContainer container = script.scripts.get(activeTab);
|
||||
|
||||
|
||||
addTextField(new GuiNpcTextArea(2, this, guiLeft + 74, guiTop + 4, 239, 208, container == null?"":container.script));
|
||||
|
||||
addButton(new GuiNpcButton(102, guiLeft + 315, guiTop + 4, 50, 20, "gui.clear"));
|
||||
addButton(new GuiNpcButton(101, guiLeft + 366, guiTop + 4, 50, 20, "gui.paste"));
|
||||
addButton(new GuiNpcButton(100, guiLeft + 315, guiTop + 25, 50, 20, "gui.copy"));
|
||||
|
||||
|
||||
addButton(new GuiNpcButton(108, guiLeft + 315, guiTop + 47, 80, 20, "gui.editor"));
|
||||
|
||||
addButton(new GuiNpcButton(107, guiLeft + 315, guiTop + 70, 80, 20, "script.loadscript"));
|
||||
@@ -113,14 +112,14 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
||||
l.add("All");
|
||||
l.addAll(list);
|
||||
addButton(new GuiNpcButton(105, guiLeft + 60, guiTop + 4, 80, 20, l.toArray(new String[l.size()]), activeConsole));
|
||||
|
||||
|
||||
addLabel(new GuiNpcLabel(1, "script.language", guiLeft + 232, guiTop + 30));
|
||||
addButton(new GuiNpcButton(103, guiLeft + 294, guiTop + 25, 80, 20, languages.keySet().toArray(new String[languages.keySet().size()]), getScriptIndex()));
|
||||
getButton(103).enabled = languages.size() > 0;
|
||||
|
||||
addLabel(new GuiNpcLabel(2, "gui.enabled", guiLeft + 232, guiTop + 53));
|
||||
addButton(new GuiNpcButton(104, guiLeft + 294, guiTop + 48, 50, 20, new String[]{"gui.no","gui.yes"}, script.enabled?1:0));
|
||||
|
||||
|
||||
if(MinecraftServer.getServer() != null)
|
||||
addButton(new GuiNpcButton(106, guiLeft + 232, guiTop + 71, 150, 20, "script.openfolder"));
|
||||
}
|
||||
@@ -148,13 +147,13 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void confirmClicked(boolean flag, int i){
|
||||
if(flag)
|
||||
openLink("http://www.kodevelopment.nl/minecraft/customnpcs/scripting");
|
||||
|
||||
@Override
|
||||
public void confirmClicked(boolean flag, int i){
|
||||
if(flag)
|
||||
openLink("http://www.kodevelopment.nl/minecraft/customnpcs/scripting");
|
||||
displayGuiScreen(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton guibutton) {
|
||||
@@ -169,7 +168,7 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
||||
}
|
||||
if(guibutton.id == 15){
|
||||
GuiConfirmOpenLink guiyesno = new GuiConfirmOpenLink(this, "http://www.kodevelopment.nl/minecraft/customnpcs/scripting", 0, true);
|
||||
mc.displayGuiScreen(guiyesno);
|
||||
mc.displayGuiScreen(guiyesno);
|
||||
}
|
||||
if (guibutton.id == 100) {
|
||||
NoppesStringUtils.setClipboardContents(getTextField(2).getText());
|
||||
@@ -177,16 +176,19 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
||||
if (guibutton.id == 101) {
|
||||
getTextField(2).setText(NoppesStringUtils.getClipboardContents());
|
||||
}
|
||||
ScriptContainer container;
|
||||
if(guibutton.id == 102) {
|
||||
if(this.activeTab > 0) {
|
||||
container = (ScriptContainer)this.script.getScripts().get(this.activeTab - 1);
|
||||
container.script = "";
|
||||
} else {
|
||||
this.script.clearConsole();
|
||||
if (guibutton.id == 102) {
|
||||
getTextField(2).setText("");
|
||||
if(!showScript){
|
||||
if(activeConsole == 0){
|
||||
for(ScriptContainer container : script.scripts)
|
||||
container.console.clear();
|
||||
}
|
||||
else{
|
||||
ScriptContainer container = script.scripts.get(activeConsole - 1);
|
||||
if(container != null)
|
||||
container.console.clear();
|
||||
}
|
||||
}
|
||||
|
||||
this.initGui();
|
||||
}
|
||||
if (guibutton.id == 103) {
|
||||
script.scriptLanguage = ((GuiNpcButton)guibutton).displayString;
|
||||
@@ -201,36 +203,31 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
||||
if (guibutton.id == 106) {
|
||||
NoppesUtil.openFolder(ScriptController.Instance.dir);
|
||||
}
|
||||
if(guibutton.id == 107) {
|
||||
container = (ScriptContainer)this.script.getScripts().get(this.activeTab - 1);
|
||||
if(container == null) {
|
||||
this.script.getScripts().add(container = new ScriptContainer(this.script));
|
||||
}
|
||||
|
||||
this.setSubGui(new EventGuiScriptList((List)this.languages.get(this.script.getLanguage()), container));
|
||||
if (guibutton.id == 107) {
|
||||
ScriptContainer container = script.scripts.get(activeTab);
|
||||
if(container == null)
|
||||
script.scripts.set(activeTab, container = new ScriptContainer(this.script));
|
||||
setSubGui(new GuiScriptList(languages.get(script.scriptLanguage), container));
|
||||
}
|
||||
if(guibutton.id == 108) {
|
||||
container = (ScriptContainer)this.script.getScripts().get(this.activeTab - 1);
|
||||
if(container != null) {
|
||||
this.setScript();
|
||||
if (guibutton.id == 108) {
|
||||
ScriptContainer container = script.scripts.get(activeTab);
|
||||
if(container != null){
|
||||
setScript();
|
||||
this.AWTWindow = new GuiJTextArea(container.script).setListener(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setScript() {
|
||||
if(this.activeTab > 0) {
|
||||
ScriptContainer container = (ScriptContainer)this.script.getScripts().get(this.activeTab - 1);
|
||||
if(container == null) {
|
||||
this.script.getScripts().add(container = new ScriptContainer(this.script));
|
||||
}
|
||||
|
||||
String text = (this.getTextField(2)).getText();
|
||||
private void setScript(){
|
||||
if(showScript){
|
||||
ScriptContainer container = script.scripts.get(activeTab);
|
||||
if(container == null)
|
||||
script.scripts.set(activeTab, container = new ScriptContainer(this.script));
|
||||
String text = getTextField(2).getText();
|
||||
text = text.replace("\r\n", "\n");
|
||||
text = text.replace("\r", "\n");
|
||||
container.script = text;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -254,7 +251,7 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
||||
@Override
|
||||
public void save() {
|
||||
setScript();
|
||||
Client.sendData(EnumPacketServer.ScriptDataSave, script.writeToNBT(new NBTTagCompound()));
|
||||
Client.sendData(EnumPacketServer.ScriptDataSave, script.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -268,10 +265,11 @@ public class GuiScript extends GuiNPCInterface implements IGuiData, GuiYesNoCall
|
||||
|
||||
@Override
|
||||
public void saveText(String text) {
|
||||
ScriptContainer container = script.getScripts().get(activeTab);
|
||||
ScriptContainer container = script.scripts.get(activeTab);
|
||||
if(container != null)
|
||||
container.script = text;
|
||||
initGui();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user