2018-09-13 12:03:28 -04:00
|
|
|
package noppes.npcs.client.gui;
|
|
|
|
|
|
2025-02-02 23:15:53 -05:00
|
|
|
import kamkeel.npcs.network.packets.request.script.NPCScriptPacket;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraft.client.gui.GuiButton;
|
|
|
|
|
import net.minecraft.client.gui.GuiConfirmOpenLink;
|
2024-03-19 14:35:32 -04:00
|
|
|
import net.minecraft.client.gui.GuiYesNo;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.server.MinecraftServer;
|
2024-03-19 14:35:32 -04:00
|
|
|
import net.minecraft.util.StatCollector;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.NoppesStringUtils;
|
|
|
|
|
import noppes.npcs.client.NoppesUtil;
|
2026-01-12 03:56:22 +02:00
|
|
|
import noppes.npcs.client.gui.script.GuiScriptInterface;
|
2026-01-22 23:07:38 -05:00
|
|
|
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
|
|
|
|
import noppes.npcs.client.gui.util.GuiMenuTopButton;
|
|
|
|
|
import noppes.npcs.client.gui.util.GuiNpcButton;
|
|
|
|
|
import noppes.npcs.client.gui.util.GuiNpcLabel;
|
|
|
|
|
import noppes.npcs.client.gui.util.GuiNpcTextArea;
|
|
|
|
|
import noppes.npcs.client.gui.util.GuiScriptTextArea;
|
2026-01-26 03:49:38 +02:00
|
|
|
import noppes.npcs.client.gui.util.script.interpreter.ScriptTextContainer;
|
|
|
|
|
import noppes.npcs.constants.EnumScriptType;
|
2026-01-09 22:59:13 -05:00
|
|
|
import noppes.npcs.constants.ScriptContext;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.controllers.ScriptContainer;
|
|
|
|
|
import noppes.npcs.controllers.ScriptController;
|
2023-01-12 21:33:06 -05:00
|
|
|
import noppes.npcs.controllers.data.DataScript;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.entity.EntityNPCInterface;
|
|
|
|
|
|
2026-01-22 23:07:38 -05:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
2023-01-12 21:33:06 -05:00
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
/**
|
|
|
|
|
* NPC Script GUI - extends GuiScriptInterface but with unique behavior:
|
|
|
|
|
* - Uses scroll-based tab selection instead of top buttons
|
2026-01-22 23:07:38 -05:00
|
|
|
* - Shows settings/script toggle
|
2026-01-12 03:56:22 +02:00
|
|
|
* - Uses DataScript with getNPCScript(index) access pattern
|
|
|
|
|
* - Has console filtering by hook type
|
|
|
|
|
*/
|
|
|
|
|
public class GuiScript extends GuiScriptInterface {
|
2025-03-13 17:14:45 -04:00
|
|
|
public boolean showScript = false;
|
|
|
|
|
public DataScript script;
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
private static int activeConsole = 0;
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public GuiScript(EntityNPCInterface npc) {
|
2026-01-12 03:56:22 +02:00
|
|
|
super();
|
|
|
|
|
this.npc = npc;
|
|
|
|
|
this.script = npc.script;
|
|
|
|
|
this.handler = script;
|
|
|
|
|
this.useScrollTabs = true;
|
|
|
|
|
this.useSettingsToggle = true;
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
// Initialize hook list for NPC scripts
|
|
|
|
|
hookList.add("script.init");
|
|
|
|
|
hookList.add("script.update");
|
|
|
|
|
hookList.add("script.interact");
|
|
|
|
|
hookList.add("dialog.dialog");
|
|
|
|
|
hookList.add("script.damaged");
|
|
|
|
|
hookList.add("script.killed");
|
|
|
|
|
hookList.add("script.attack");
|
|
|
|
|
hookList.add("script.target");
|
|
|
|
|
hookList.add("script.collide");
|
|
|
|
|
hookList.add("script.kills");
|
|
|
|
|
hookList.add("script.dialog_closed");
|
|
|
|
|
hookList.add("script.timer");
|
|
|
|
|
hookList.add("script.targetLost");
|
|
|
|
|
hookList.add("script.projectileTick");
|
|
|
|
|
hookList.add("script.projectileImpact");
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2025-02-02 23:15:53 -05:00
|
|
|
NPCScriptPacket.Get();
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
@Override
|
|
|
|
|
protected ScriptContext getScriptContext() {
|
|
|
|
|
return ScriptContext.NPC;
|
|
|
|
|
}
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
@Override
|
|
|
|
|
protected int getActiveScriptIndex() {
|
|
|
|
|
return this.activeTab;
|
|
|
|
|
}
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
@Override
|
|
|
|
|
protected ScriptContainer getCurrentContainer() {
|
|
|
|
|
return script.getNPCScript(activeTab);
|
|
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
@Override
|
2025-03-13 17:14:45 -04:00
|
|
|
public void initGui() {
|
|
|
|
|
super.initGui();
|
2026-01-12 03:56:22 +02:00
|
|
|
this.guiTop += 10;
|
2026-01-22 22:52:04 -05:00
|
|
|
|
2026-01-26 05:18:09 +02:00
|
|
|
if (isFullscreen) {
|
|
|
|
|
FullscreenConfig.paddingTop = 30;
|
2026-01-22 22:52:04 -05:00
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
|
2026-01-26 05:18:09 +02:00
|
|
|
// ==================== TOP BUTTONS ====================
|
|
|
|
|
boolean isFullscreenView = isFullscreen && showScript;
|
|
|
|
|
int menuX = isFullscreenView ? FullscreenConfig.paddingLeft : guiLeft + 4;
|
|
|
|
|
int menuY = isFullscreenView ? FullscreenConfig.paddingTop - 20 : guiTop - 17;
|
|
|
|
|
int rightX = isFullscreenView ? width - FullscreenConfig.paddingRight : guiLeft + xSize;
|
|
|
|
|
|
|
|
|
|
GuiMenuTopButton top;
|
|
|
|
|
addTopButton(top = new GuiMenuTopButton(13, menuX, menuY, "script.scripts"));
|
|
|
|
|
addTopButton(new GuiMenuTopButton(16, rightX - 102, menuY, "eventscript.eventScripts"));
|
|
|
|
|
addTopButton(new GuiMenuTopButton(17, rightX - 22, menuY, "X"));
|
|
|
|
|
top.active = showScript;
|
|
|
|
|
addTopButton(top = new GuiMenuTopButton(14, top, "gui.settings"));
|
|
|
|
|
top.active = !showScript;
|
|
|
|
|
addTopButton(new GuiMenuTopButton(15, top, "gui.website"));
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (showScript) {
|
2026-01-12 03:56:22 +02:00
|
|
|
initScriptView();
|
|
|
|
|
} else {
|
|
|
|
|
initSettingsView();
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
private void initScriptView() {
|
|
|
|
|
ScriptContainer container = getCurrentContainer();
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
// ==================== CALCULATE VIEWPORT BOUNDS ====================
|
|
|
|
|
int editorX, editorY, editorWidth, editorHeight;
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
if (isFullscreen) {
|
|
|
|
|
// Fullscreen: viewport fills screen with configured padding
|
|
|
|
|
FullscreenConfig.paddingTop = 30;
|
|
|
|
|
FullscreenConfig.paddingBottom = 20;
|
|
|
|
|
FullscreenConfig.paddingLeft = 20;
|
|
|
|
|
FullscreenConfig.paddingRight = 20;
|
|
|
|
|
editorX = FullscreenConfig.paddingLeft;
|
|
|
|
|
editorY = FullscreenConfig.paddingTop;
|
|
|
|
|
editorWidth = this.width - FullscreenConfig.paddingLeft - FullscreenConfig.paddingRight;
|
|
|
|
|
editorHeight = this.height - FullscreenConfig.paddingTop - FullscreenConfig.paddingBottom;
|
|
|
|
|
} else {
|
|
|
|
|
// Normal: fixed layout with hooks on left
|
|
|
|
|
editorX = guiLeft + 74;
|
|
|
|
|
editorY = guiTop + 4;
|
|
|
|
|
editorWidth = 239;
|
|
|
|
|
editorHeight = 208;
|
|
|
|
|
}
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
// ==================== HOOKS SCROLL (hidden in fullscreen) ====================
|
|
|
|
|
if (!isFullscreen) {
|
2025-03-13 17:14:45 -04:00
|
|
|
addLabel(new GuiNpcLabel(0, "script.hooks", guiLeft + 4, guiTop + 5));
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
GuiCustomScroll hooks = new GuiCustomScroll(this, 1);
|
|
|
|
|
hooks.setSize(68, 198);
|
|
|
|
|
hooks.guiLeft = guiLeft + 4;
|
|
|
|
|
hooks.guiTop = guiTop + 14;
|
2026-01-12 03:56:22 +02:00
|
|
|
hooks.setUnsortedList(hookList);
|
2025-03-13 17:14:45 -04:00
|
|
|
hooks.selected = activeTab;
|
|
|
|
|
addScroll(hooks);
|
2026-01-12 03:56:22 +02:00
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
// ==================== SCRIPT TEXT AREA ====================
|
|
|
|
|
int idx = getActiveScriptIndex();
|
|
|
|
|
GuiScriptTextArea activeArea = getActiveScriptArea();
|
|
|
|
|
if (activeArea == null) {
|
|
|
|
|
activeArea = new GuiScriptTextArea(this, 2, editorX, editorY, editorWidth, editorHeight,
|
2026-01-22 23:07:38 -05:00
|
|
|
container == null ? "" : container.script);
|
2026-01-12 03:56:22 +02:00
|
|
|
activeArea.setListener(this);
|
|
|
|
|
this.closeOnEsc(activeArea::closeOnEsc);
|
|
|
|
|
textAreas.put(idx, activeArea);
|
|
|
|
|
} else {
|
2026-01-22 23:07:38 -05:00
|
|
|
activeArea.init(editorX, editorY, editorWidth, editorHeight,
|
|
|
|
|
container == null ? "" : container.script);
|
2026-01-12 03:56:22 +02:00
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
|
2026-03-02 16:38:35 -05:00
|
|
|
// Use the container's language for syntax highlighting, fall back to handler default
|
|
|
|
|
String language = (container != null) ? container.getLanguage() : script.getLanguage();
|
|
|
|
|
activeArea.setLanguage(language);
|
2026-01-12 03:56:22 +02:00
|
|
|
activeArea.setScriptContext(getScriptContext());
|
2026-01-26 03:49:38 +02:00
|
|
|
|
|
|
|
|
// Set editor globals based on the active NPC hook
|
|
|
|
|
String hookName = EnumScriptType.values()[activeTab].function;
|
|
|
|
|
applyEditorGlobals(activeArea, hookName);
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
// Setup fullscreen key binding
|
|
|
|
|
GuiScriptTextArea.KEYS.FULLSCREEN.setTask(e -> {
|
|
|
|
|
if (e.isPress()) {
|
|
|
|
|
toggleFullscreen();
|
2025-12-22 02:45:51 +02:00
|
|
|
}
|
2026-01-12 03:56:22 +02:00
|
|
|
});
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
activeArea.enableCodeHighlighting();
|
|
|
|
|
addTextField(activeArea);
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
// Initialize fullscreen button
|
|
|
|
|
int scrollbarOffset = activeArea.hasVerticalScrollbar() ? -8 : -2;
|
|
|
|
|
fullscreenButton.initGui(editorX + editorWidth, editorY, scrollbarOffset);
|
|
|
|
|
|
2026-01-22 22:52:04 -05:00
|
|
|
// ==================== RIGHT PANEL (hidden in fullscreen) ====================
|
|
|
|
|
if (!isFullscreen) {
|
2025-03-13 17:14:45 -04:00
|
|
|
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(107, guiLeft + 315, guiTop + 70, 80, 20, "script.loadscript"));
|
|
|
|
|
|
2026-03-05 01:37:44 -05:00
|
|
|
// Disable all buttons until server data arrives
|
|
|
|
|
if (!serverDataReceived) {
|
|
|
|
|
for (int btnId : new int[]{100, 101, 102, 107}) {
|
|
|
|
|
GuiNpcButton btn = getButton(btnId);
|
|
|
|
|
if (btn != null) btn.enabled = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
GuiCustomScroll scroll = new GuiCustomScroll(this, 0).setUnselectable();
|
|
|
|
|
scroll.setSize(100, 120);
|
|
|
|
|
scroll.guiLeft = guiLeft + 315;
|
|
|
|
|
scroll.guiTop = guiTop + 92;
|
|
|
|
|
if (container != null)
|
|
|
|
|
scroll.setList(container.scripts);
|
|
|
|
|
addScroll(scroll);
|
|
|
|
|
}
|
2026-01-22 22:52:04 -05:00
|
|
|
}
|
2026-01-22 23:07:38 -05:00
|
|
|
|
|
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
private void initSettingsView() {
|
|
|
|
|
addLabel(new GuiNpcLabel(0, "script.console", guiLeft + 4, guiTop + 16));
|
2026-01-22 22:52:04 -05:00
|
|
|
if (getTopButton(14) != null)
|
|
|
|
|
getTopButton(14).active = true;
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
GuiNpcTextArea consoleArea = new GuiNpcTextArea(2, this, guiLeft + 4, guiTop + 26, 226, 186, getConsoleText());
|
|
|
|
|
consoleArea.canEdit = false;
|
|
|
|
|
addTextField(consoleArea);
|
2026-01-22 23:07:38 -05:00
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
addButton(new GuiNpcButton(100, guiLeft + 232, guiTop + 170, 56, 20, "gui.copy"));
|
|
|
|
|
addButton(new GuiNpcButton(102, guiLeft + 232, guiTop + 192, 56, 20, "gui.clear"));
|
|
|
|
|
|
|
|
|
|
List<String> consoleOptions = new ArrayList<>();
|
|
|
|
|
consoleOptions.add("All");
|
|
|
|
|
consoleOptions.addAll(hookList);
|
2026-01-22 23:07:38 -05:00
|
|
|
addButton(new GuiNpcButton(105, guiLeft + 60, guiTop + 4, 80, 20,
|
|
|
|
|
consoleOptions.toArray(new String[0]), activeConsole));
|
2026-01-12 03:56:22 +02:00
|
|
|
|
2026-03-02 16:38:35 -05:00
|
|
|
addLabel(new GuiNpcLabel(1, "script.default", guiLeft + 232, guiTop + 30));
|
2026-01-19 04:06:11 +02:00
|
|
|
List<String> languageOptions = getLanguageOptions();
|
2026-01-22 23:07:38 -05:00
|
|
|
addButton(new GuiNpcButton(103, guiLeft + 294, guiTop + 25, 80, 20,
|
|
|
|
|
languageOptions.toArray(new String[0]), getLanguageIndex(languageOptions)));
|
2026-01-12 03:56:22 +02:00
|
|
|
|
|
|
|
|
addLabel(new GuiNpcLabel(2, "gui.enabled", guiLeft + 232, guiTop + 53));
|
2026-01-22 23:07:38 -05:00
|
|
|
addButton(new GuiNpcButton(104, guiLeft + 294, guiTop + 48, 50, 20,
|
|
|
|
|
new String[]{"gui.no", "gui.yes"}, script.enabled ? 1 : 0));
|
2026-01-12 03:56:22 +02:00
|
|
|
|
|
|
|
|
if (MinecraftServer.getServer() != null)
|
|
|
|
|
addButton(new GuiNpcButton(106, guiLeft + 232, guiTop + 71, 150, 20, "script.openfolder"));
|
2026-03-05 01:37:44 -05:00
|
|
|
|
|
|
|
|
// Disable all buttons until server data arrives
|
|
|
|
|
if (!serverDataReceived) {
|
|
|
|
|
for (int btnId : new int[]{100, 102, 103, 104, 105, 106}) {
|
|
|
|
|
GuiNpcButton btn = getButton(btnId);
|
|
|
|
|
if (btn != null) btn.enabled = false;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
getButton(103).enabled = languageOptions.size() > 0;
|
|
|
|
|
}
|
2025-12-22 02:45:51 +02:00
|
|
|
}
|
|
|
|
|
|
2026-01-26 03:49:38 +02:00
|
|
|
// Apply editor globals for the active NPC hook.
|
|
|
|
|
private void applyEditorGlobals(GuiScriptTextArea activeArea, String hookName) {
|
|
|
|
|
if (activeArea == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
ScriptTextContainer textContainer = activeArea.getContainer();
|
|
|
|
|
if (textContainer == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (script != null)
|
|
|
|
|
textContainer.setEditorGlobalsMap(script.getEditorGlobals(hookName));
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-22 02:45:51 +02:00
|
|
|
@Override
|
2026-01-12 03:56:22 +02:00
|
|
|
protected String getConsoleText() {
|
2025-03-13 17:14:45 -04:00
|
|
|
Map<Long, String> map = this.script.getOldConsoleText();
|
|
|
|
|
StringBuilder builder = new StringBuilder();
|
2026-01-12 03:56:22 +02:00
|
|
|
for (Map.Entry<Long, String> entry : map.entrySet()) {
|
|
|
|
|
builder.insert(0, new Date(entry.getKey()) + entry.getValue() + "\n");
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
return builder.toString();
|
|
|
|
|
}
|
2021-12-01 17:42:48 -06:00
|
|
|
|
2024-03-19 14:35:32 -04:00
|
|
|
@Override
|
|
|
|
|
public void confirmClicked(boolean result, int id) {
|
|
|
|
|
NoppesUtil.openGUI(player, this);
|
2025-03-13 17:14:45 -04:00
|
|
|
if (!result)
|
2024-03-19 14:35:32 -04:00
|
|
|
return;
|
2025-03-13 17:14:45 -04:00
|
|
|
if (id == 0) {
|
2024-03-19 14:35:32 -04:00
|
|
|
openLink("https://kamkeel.github.io/CustomNPC-Plus/");
|
|
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
if (id == 101) {
|
2024-03-19 14:35:32 -04:00
|
|
|
getTextField(2).setText(NoppesStringUtils.getClipboardContents());
|
|
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
if (id == 102) {
|
2024-03-19 14:35:32 -04:00
|
|
|
getTextField(2).setText("");
|
2025-03-13 17:14:45 -04:00
|
|
|
if (!showScript) {
|
|
|
|
|
if (activeConsole == 0) {
|
|
|
|
|
for (ScriptContainer container : script.getNPCScripts())
|
2024-03-19 14:35:32 -04:00
|
|
|
container.console.clear();
|
2025-03-13 17:14:45 -04:00
|
|
|
} else {
|
2024-03-19 14:35:32 -04:00
|
|
|
ScriptContainer container = script.getNPCScript(activeConsole - 1);
|
2025-03-13 17:14:45 -04:00
|
|
|
if (container != null)
|
2024-03-19 14:35:32 -04:00
|
|
|
container.console.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
displayGuiScreen(this);
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
@Override
|
|
|
|
|
protected void actionPerformed(GuiButton guibutton) {
|
|
|
|
|
if (guibutton.id == 13) {
|
|
|
|
|
showScript = true;
|
|
|
|
|
initGui();
|
|
|
|
|
}
|
|
|
|
|
if (guibutton.id == 14) {
|
|
|
|
|
setScript();
|
|
|
|
|
showScript = false;
|
|
|
|
|
initGui();
|
|
|
|
|
}
|
|
|
|
|
if (guibutton.id == 15) {
|
2026-01-12 03:56:22 +02:00
|
|
|
displayGuiScreen(new GuiConfirmOpenLink(this, "https://kamkeel.github.io/CustomNPC-Plus/", 0, true));
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
if (guibutton.id == 16) {
|
|
|
|
|
close();
|
2026-01-22 22:52:04 -05:00
|
|
|
GuiScriptInterface.open(this, this.script);
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
if (guibutton.id == 17) {
|
|
|
|
|
close();
|
|
|
|
|
}
|
|
|
|
|
if (guibutton.id == 100) {
|
|
|
|
|
NoppesStringUtils.setClipboardContents(getTextField(2).getText());
|
|
|
|
|
}
|
|
|
|
|
if (guibutton.id == 101) {
|
2026-01-22 23:07:38 -05:00
|
|
|
displayGuiScreen(new GuiYesNo(this, StatCollector.translateToLocal("gui.paste"),
|
|
|
|
|
StatCollector.translateToLocal("gui.sure"), 101));
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
if (guibutton.id == 102) {
|
2026-01-22 23:07:38 -05:00
|
|
|
displayGuiScreen(new GuiYesNo(this, StatCollector.translateToLocal("gui.clear"),
|
|
|
|
|
StatCollector.translateToLocal("gui.sure"), 102));
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
if (guibutton.id == 103) {
|
|
|
|
|
script.scriptLanguage = ((GuiNpcButton) guibutton).displayString;
|
|
|
|
|
}
|
|
|
|
|
if (guibutton.id == 104) {
|
|
|
|
|
script.enabled = ((GuiNpcButton) guibutton).getValue() == 1;
|
|
|
|
|
}
|
|
|
|
|
if (guibutton.id == 105) {
|
|
|
|
|
activeConsole = ((GuiNpcButton) guibutton).getValue();
|
|
|
|
|
initGui();
|
|
|
|
|
}
|
|
|
|
|
if (guibutton.id == 106) {
|
|
|
|
|
NoppesUtil.openFolder(ScriptController.Instance.dir);
|
|
|
|
|
}
|
|
|
|
|
if (guibutton.id == 107) {
|
2026-01-12 03:56:22 +02:00
|
|
|
ScriptContainer container = getCurrentContainer();
|
2026-03-02 16:38:35 -05:00
|
|
|
if (container == null) {
|
|
|
|
|
container = new ScriptContainer(this.script);
|
|
|
|
|
container.setLanguage(script.getLanguage());
|
|
|
|
|
script.setNPCScript(activeTab, container);
|
|
|
|
|
}
|
|
|
|
|
String lang = container.getLanguage();
|
|
|
|
|
setSubGui(new GuiScriptList(languages.get(lang), container));
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
@Override
|
|
|
|
|
protected void setScript() {
|
2025-03-13 17:14:45 -04:00
|
|
|
if (showScript) {
|
2026-01-12 03:56:22 +02:00
|
|
|
ScriptContainer container = getCurrentContainer();
|
2026-03-02 16:38:35 -05:00
|
|
|
if (container == null) {
|
|
|
|
|
container = new ScriptContainer(this.script);
|
|
|
|
|
container.setLanguage(script.getLanguage());
|
|
|
|
|
script.setNPCScript(activeTab, container);
|
|
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
String text = getTextField(2).getText();
|
|
|
|
|
text = text.replace("\r\n", "\n");
|
|
|
|
|
text = text.replace("\r", "\n");
|
|
|
|
|
container.script = text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setGuiData(NBTTagCompound compound) {
|
2026-03-05 01:37:44 -05:00
|
|
|
// Only process the actual NPCScriptPacket response (has ScriptLanguage + Languages)
|
|
|
|
|
// Ignore unrelated packets (e.g. script config with ScriptsEnabled/GlobalNPCScriptsEnabled)
|
|
|
|
|
if (!compound.hasKey("ScriptLanguage") && !compound.hasKey("Languages")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
script.readFromNBT(compound);
|
2026-01-12 03:56:22 +02:00
|
|
|
loadLanguagesData(compound);
|
2025-05-29 21:09:58 -04:00
|
|
|
loaded = true;
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void save() {
|
2026-03-05 01:37:44 -05:00
|
|
|
if (loaded && serverDataReceived) {
|
2025-05-29 21:09:58 -04:00
|
|
|
setScript();
|
2026-03-04 20:45:33 -05:00
|
|
|
NPCScriptPacket.Save(script.writeToNBT(new NBTTagCompound()));
|
2025-05-29 21:09:58 -04:00
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) {
|
|
|
|
|
if (scroll.id == 1) {
|
|
|
|
|
setScript();
|
|
|
|
|
activeTab = scroll.selected;
|
|
|
|
|
initGui();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
}
|