2021-09-30 21:44:30 -05:00
|
|
|
package noppes.npcs.client.gui.script;
|
|
|
|
|
|
2026-01-12 03:28:18 +02:00
|
|
|
import net.minecraft.client.gui.*;
|
2021-09-30 21:44:30 -05:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.nbt.NBTTagList;
|
2024-03-19 14:35:32 -04:00
|
|
|
import net.minecraft.util.StatCollector;
|
2021-09-30 21:44:30 -05:00
|
|
|
import noppes.npcs.NoppesStringUtils;
|
|
|
|
|
import noppes.npcs.client.NoppesUtil;
|
2025-07-23 14:22:52 -04:00
|
|
|
import noppes.npcs.client.gui.util.GuiCustomScroll;
|
|
|
|
|
import noppes.npcs.client.gui.util.GuiMenuTopButton;
|
|
|
|
|
import noppes.npcs.client.gui.util.GuiNPCInterface;
|
|
|
|
|
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.GuiNpcTextField;
|
|
|
|
|
import noppes.npcs.client.gui.util.GuiScriptTextArea;
|
2025-12-22 15:06:54 +02:00
|
|
|
import noppes.npcs.client.gui.util.GuiUtil;
|
2025-07-23 14:22:52 -04:00
|
|
|
import noppes.npcs.client.gui.util.ICustomScrollListener;
|
|
|
|
|
import noppes.npcs.client.gui.util.IGuiData;
|
|
|
|
|
import noppes.npcs.client.gui.util.IJTextAreaListener;
|
|
|
|
|
import noppes.npcs.client.gui.util.ITextChangeListener;
|
|
|
|
|
import noppes.npcs.client.gui.util.ITextfieldListener;
|
2023-01-12 21:33:06 -05:00
|
|
|
import noppes.npcs.controllers.ScriptContainer;
|
2021-09-30 21:44:30 -05:00
|
|
|
import noppes.npcs.controllers.ScriptController;
|
2026-01-09 22:59:13 -05:00
|
|
|
import noppes.npcs.constants.ScriptContext;
|
2021-10-17 16:11:29 -05:00
|
|
|
import noppes.npcs.controllers.data.ForgeDataScript;
|
2023-01-12 21:33:06 -05:00
|
|
|
import noppes.npcs.controllers.data.IScriptHandler;
|
2026-01-13 17:34:14 +02:00
|
|
|
import noppes.npcs.controllers.data.IScriptUnit;
|
2022-05-11 13:30:13 -05:00
|
|
|
import noppes.npcs.scripted.item.ScriptCustomItem;
|
2025-12-22 15:06:54 +02:00
|
|
|
import org.lwjgl.opengl.Display;
|
2021-09-30 21:44:30 -05:00
|
|
|
|
2025-07-23 14:22:52 -04:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
2023-01-12 21:33:06 -05:00
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
|
2021-10-18 06:33:39 -05:00
|
|
|
public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallback, IGuiData, ITextChangeListener, ICustomScrollListener, IJTextAreaListener, ITextfieldListener {
|
2025-02-09 04:02:16 -05:00
|
|
|
protected int activeTab = 0;
|
2021-10-17 16:11:29 -05:00
|
|
|
public IScriptHandler handler;
|
2021-09-30 21:44:30 -05:00
|
|
|
public Map<String, List<String>> languages = new HashMap();
|
2026-01-12 03:56:22 +02:00
|
|
|
protected int scriptLimit = 1;
|
2023-03-16 04:27:19 -05:00
|
|
|
public List<String> hookList = new ArrayList<String>();
|
2025-05-29 21:09:58 -04:00
|
|
|
protected boolean loaded = false;
|
2021-09-30 21:44:30 -05:00
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
protected Map<Integer, GuiScriptTextArea> textAreas = new HashMap<>();
|
2026-01-12 03:28:18 +02:00
|
|
|
protected GuiScreen parent;
|
|
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
public boolean singleContainer = false;
|
|
|
|
|
|
|
|
|
|
/** If true, uses scroll-based tab selection instead of top buttons */
|
|
|
|
|
protected boolean useScrollTabs = false;
|
|
|
|
|
|
|
|
|
|
/** If true, shows settings/script toggle instead of numbered tabs */
|
|
|
|
|
protected boolean useSettingsToggle = false;
|
2025-12-22 15:06:54 +02:00
|
|
|
|
|
|
|
|
// ==================== FULLSCREEN MODE ====================
|
|
|
|
|
/** Whether the editor viewport is currently in fullscreen mode */
|
2025-12-22 15:52:52 +02:00
|
|
|
public static boolean isFullscreen = false;
|
2025-12-22 15:06:54 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fullscreen Layout Configuration
|
|
|
|
|
* Adjust these values to customize the fullscreen viewport appearance.
|
|
|
|
|
* All padding values are in scaled GUI pixels.
|
|
|
|
|
*/
|
|
|
|
|
public static class FullscreenConfig {
|
|
|
|
|
/** Padding from the top edge of the screen */
|
2025-12-22 15:52:52 +02:00
|
|
|
public static int paddingTop = 20;
|
2025-12-22 15:06:54 +02:00
|
|
|
/** Padding from the bottom edge of the screen */
|
2025-12-22 15:52:52 +02:00
|
|
|
public static int paddingBottom = 20;
|
2025-12-22 15:06:54 +02:00
|
|
|
/** Padding from the left edge of the screen */
|
2025-12-22 15:52:52 +02:00
|
|
|
public static int paddingLeft = 20;
|
2025-12-22 15:06:54 +02:00
|
|
|
/** Padding from the right edge of the screen */
|
2025-12-22 15:52:52 +02:00
|
|
|
public static int paddingRight = 20;
|
2025-12-22 15:06:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Fullscreen toggle button drawn at top-right of viewport */
|
2026-01-04 02:13:33 +02:00
|
|
|
public final FullscreenButton fullscreenButton = new FullscreenButton();
|
2025-12-22 15:06:54 +02:00
|
|
|
|
2021-09-30 21:44:30 -05:00
|
|
|
public GuiScriptInterface() {
|
|
|
|
|
this.drawDefaultBackground = true;
|
|
|
|
|
this.closeOnEsc = true;
|
|
|
|
|
this.xSize = 420;
|
|
|
|
|
this.setBackground("menubg.png");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void initGui() {
|
2025-12-22 15:06:54 +02:00
|
|
|
// ==================== BASE LAYOUT CALCULATION ====================
|
2025-03-13 17:14:45 -04:00
|
|
|
this.ySize = (int) ((double) this.xSize * 0.56D);
|
|
|
|
|
if ((double) this.ySize > (double) this.height * 0.95D) {
|
|
|
|
|
this.ySize = (int) ((double) this.height * 0.95D);
|
|
|
|
|
this.xSize = (int) ((double) this.ySize / 0.56D);
|
2021-10-01 01:17:12 -05:00
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
this.bgScale = (float) this.xSize / 400.0F;
|
2021-09-30 21:44:30 -05:00
|
|
|
super.initGui();
|
2021-10-01 01:17:12 -05:00
|
|
|
this.guiTop += 10;
|
2025-03-13 17:14:45 -04:00
|
|
|
int yoffset = (int) ((double) this.ySize * 0.02D);
|
2025-12-22 15:06:54 +02:00
|
|
|
|
|
|
|
|
// ==================== TAB BUTTONS ====================
|
2026-01-12 03:56:22 +02:00
|
|
|
// Skip standard tab creation for GUIs that use custom toggle/scroll tabs
|
|
|
|
|
if (!useSettingsToggle) {
|
|
|
|
|
GuiMenuTopButton top;
|
|
|
|
|
int topButtonsX = isFullscreen && activeTab != 0 ? FullscreenConfig.paddingLeft : this.guiLeft + 4;
|
|
|
|
|
int topButtonsY = isFullscreen && activeTab != 0 ? FullscreenConfig.paddingTop - 20 : this.guiTop - 17;
|
|
|
|
|
this.addTopButton(top = new GuiMenuTopButton(0, topButtonsX, topButtonsY, "gui.settings"));
|
|
|
|
|
|
|
|
|
|
int topXoffset = 0;
|
|
|
|
|
int topYoffset = 0;
|
|
|
|
|
if(!singleContainer) {
|
|
|
|
|
for (int ta = 0; ta < this.handler.getScripts().size(); ++ta) {
|
|
|
|
|
if (ta % 20 == 0 && ta > 0) {
|
|
|
|
|
topYoffset -= 20;
|
|
|
|
|
topXoffset -= top.width + 20 * 22;
|
|
|
|
|
}
|
|
|
|
|
this.addTopButton(top = new GuiMenuTopButton(ta + 1, top.xPosition + top.width + topXoffset,
|
|
|
|
|
top.yPosition + topYoffset, ta + 1 + ""));
|
|
|
|
|
topXoffset = 0;
|
|
|
|
|
topYoffset = 0;
|
|
|
|
|
scriptLimit = ta + 2;
|
2026-01-12 03:28:18 +02:00
|
|
|
}
|
2021-10-15 09:17:31 -05:00
|
|
|
}
|
2021-10-01 01:17:12 -05:00
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
if (singleContainer && getFirst() != null)
|
|
|
|
|
this.addTopButton(
|
|
|
|
|
top = new GuiMenuTopButton(1, top.xPosition + top.width + topXoffset, top.yPosition + topYoffset,
|
|
|
|
|
"Script"));
|
|
|
|
|
else if (this.handler.getScripts().size() < 100)
|
|
|
|
|
this.addTopButton(new GuiMenuTopButton(scriptLimit, top.xPosition + top.width, top.yPosition, "+"));
|
2021-10-01 01:17:12 -05:00
|
|
|
|
2026-01-12 03:28:18 +02:00
|
|
|
|
2026-01-12 03:56:22 +02:00
|
|
|
top = this.getTopButton(this.activeTab);
|
|
|
|
|
if (top == null) {
|
|
|
|
|
this.activeTab = 0;
|
|
|
|
|
top = this.getTopButton(0);
|
|
|
|
|
}
|
|
|
|
|
top.active = true;
|
2021-10-01 01:17:12 -05:00
|
|
|
}
|
2025-12-22 15:06:54 +02:00
|
|
|
|
|
|
|
|
// ==================== SCRIPT EDITOR TAB (activeTab > 0) ====================
|
2026-01-12 03:56:22 +02:00
|
|
|
// Skip for GUIs that handle their own view initialization (useSettingsToggle)
|
|
|
|
|
if (!useSettingsToggle) {
|
|
|
|
|
if (this.activeTab > 0) {
|
|
|
|
|
initScriptEditorTab(yoffset);
|
|
|
|
|
} else {
|
|
|
|
|
// ==================== SETTINGS TAB (activeTab == 0) ====================
|
|
|
|
|
initSettingsTab(yoffset);
|
|
|
|
|
}
|
2025-12-22 15:06:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.xSize = 420;
|
|
|
|
|
this.ySize = 256;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initialize the script editor tab layout.
|
|
|
|
|
* Handles both normal and fullscreen modes.
|
|
|
|
|
*/
|
|
|
|
|
private void initScriptEditorTab(int yoffset) {
|
2026-01-13 17:34:14 +02:00
|
|
|
IScriptUnit container = getCurrentContainer();
|
2025-12-22 15:06:54 +02:00
|
|
|
|
|
|
|
|
// ==================== CALCULATE VIEWPORT BOUNDS ====================
|
|
|
|
|
int editorX, editorY, editorWidth, editorHeight;
|
|
|
|
|
|
2025-12-22 15:52:52 +02:00
|
|
|
FullscreenConfig.paddingTop = 30;
|
|
|
|
|
FullscreenConfig.paddingBottom = 20;
|
|
|
|
|
FullscreenConfig.paddingLeft = 20;
|
|
|
|
|
FullscreenConfig.paddingRight = 20;
|
2025-12-22 15:06:54 +02:00
|
|
|
if (isFullscreen) {
|
|
|
|
|
// Fullscreen: viewport fills screen with configured padding
|
|
|
|
|
editorX = FullscreenConfig.paddingLeft;
|
|
|
|
|
editorY = FullscreenConfig.paddingTop;
|
|
|
|
|
editorWidth = this.width - FullscreenConfig.paddingLeft - FullscreenConfig.paddingRight;
|
|
|
|
|
editorHeight = this.height - FullscreenConfig.paddingTop - FullscreenConfig.paddingBottom;
|
|
|
|
|
} else {
|
|
|
|
|
// Normal: viewport within the GUI panel, leaving space for right panel
|
|
|
|
|
editorX = guiLeft + 1 + yoffset;
|
|
|
|
|
editorY = guiTop + yoffset;
|
|
|
|
|
editorWidth = xSize - 108 - yoffset;
|
|
|
|
|
editorHeight = (int) (ySize * 0.96) - yoffset * 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ==================== HOOKS SCROLL (hidden in fullscreen) ====================
|
|
|
|
|
if (!isFullscreen) {
|
2021-10-23 02:43:28 -05:00
|
|
|
GuiCustomScroll hooks = new GuiCustomScroll(this, 1);
|
|
|
|
|
hooks.allowUserInput = false;
|
|
|
|
|
hooks.setSize(108, 198);
|
|
|
|
|
hooks.guiLeft = guiLeft - 110;
|
|
|
|
|
hooks.guiTop = guiTop + 14;
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (handler instanceof ForgeDataScript) {
|
2021-10-23 02:43:28 -05:00
|
|
|
hooks.setSize(238, 198);
|
|
|
|
|
hooks.guiLeft = guiLeft - 240;
|
2021-10-18 06:33:39 -05:00
|
|
|
}
|
2021-10-18 22:01:15 -05:00
|
|
|
hooks.setUnsortedList(hookList);
|
|
|
|
|
addScroll(hooks);
|
|
|
|
|
|
2021-10-23 02:43:28 -05:00
|
|
|
GuiNpcLabel hookLabel = new GuiNpcLabel(0, "script.hooks", hooks.guiLeft, guiTop + 5);
|
|
|
|
|
hookLabel.color = 0xaaaaaa;
|
|
|
|
|
addLabel(hookLabel);
|
2025-12-22 15:06:54 +02:00
|
|
|
}
|
2021-10-23 02:43:28 -05:00
|
|
|
|
2025-12-22 15:06:54 +02:00
|
|
|
// ==================== SCRIPT TEXT AREA ====================
|
2026-01-12 03:56:22 +02:00
|
|
|
int idx = getActiveScriptIndex();
|
2025-12-22 15:06:54 +02:00
|
|
|
GuiScriptTextArea activeArea = getActiveScriptArea();
|
|
|
|
|
if (activeArea == null) {
|
|
|
|
|
activeArea = new GuiScriptTextArea(this, 2, editorX, editorY, editorWidth, editorHeight,
|
2026-01-13 17:34:14 +02:00
|
|
|
container == null ? "" : container.getScript());
|
2025-12-22 15:06:54 +02:00
|
|
|
activeArea.setListener(this);
|
|
|
|
|
this.closeOnEsc(activeArea::closeOnEsc);
|
|
|
|
|
textAreas.put(idx, activeArea);
|
|
|
|
|
} else {
|
|
|
|
|
activeArea.init(editorX, editorY, editorWidth, editorHeight,
|
2026-01-13 17:34:14 +02:00
|
|
|
container == null ? "" : container.getScript());
|
2025-12-22 15:06:54 +02:00
|
|
|
}
|
2026-01-03 05:06:41 +02:00
|
|
|
|
|
|
|
|
// Set the scripting language for proper syntax highlighting
|
|
|
|
|
activeArea.setLanguage(this.handler.getLanguage());
|
2025-12-22 02:22:01 +02:00
|
|
|
|
2026-01-09 22:59:13 -05:00
|
|
|
// Set the script context for context-aware hook autocomplete
|
|
|
|
|
activeArea.setScriptContext(getScriptContext());
|
|
|
|
|
|
2025-12-22 15:06:54 +02:00
|
|
|
// Setup fullscreen key binding
|
|
|
|
|
GuiScriptTextArea.KEYS.FULLSCREEN.setTask(e -> {
|
|
|
|
|
if (e.isPress()) {
|
|
|
|
|
toggleFullscreen();
|
2025-12-22 02:22:01 +02:00
|
|
|
}
|
2025-12-22 15:06:54 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
activeArea.enableCodeHighlighting();
|
|
|
|
|
this.addTextField(activeArea);
|
2023-07-30 01:26:36 -05:00
|
|
|
|
2025-12-22 15:06:54 +02:00
|
|
|
// ==================== FULLSCREEN BUTTON ====================
|
|
|
|
|
int scrollbarOffset = activeArea.hasVerticalScrollbar() ? -8 : -2;
|
|
|
|
|
fullscreenButton.initGui(editorX + editorWidth, editorY, scrollbarOffset);
|
2023-07-30 01:26:36 -05:00
|
|
|
|
2025-12-22 15:06:54 +02:00
|
|
|
// ==================== RIGHT PANEL BUTTONS (hidden in fullscreen) ====================
|
|
|
|
|
if (!isFullscreen) {
|
2021-10-01 01:17:12 -05:00
|
|
|
int left1 = this.guiLeft + this.xSize - 104;
|
|
|
|
|
this.addButton(new GuiNpcButton(102, left1, this.guiTop + yoffset, 60, 20, "gui.clear"));
|
|
|
|
|
this.addButton(new GuiNpcButton(101, left1 + 61, this.guiTop + yoffset, 60, 20, "gui.paste"));
|
|
|
|
|
this.addButton(new GuiNpcButton(100, left1, this.guiTop + 21 + yoffset, 60, 20, "gui.copy"));
|
|
|
|
|
this.addButton(new GuiNpcButton(105, left1 + 61, this.guiTop + 21 + yoffset, 60, 20, "gui.remove"));
|
|
|
|
|
this.addButton(new GuiNpcButton(107, left1, this.guiTop + 66 + yoffset, 80, 20, "script.loadscript"));
|
2025-12-22 15:06:54 +02:00
|
|
|
|
2021-10-01 01:17:12 -05:00
|
|
|
GuiCustomScroll scroll = (new GuiCustomScroll(this, 0)).setUnselectable();
|
2025-03-13 17:14:45 -04:00
|
|
|
scroll.setSize(100, (int) ((double) this.ySize * 0.54D) - yoffset * 2);
|
2021-10-01 01:17:12 -05:00
|
|
|
scroll.guiLeft = left1;
|
|
|
|
|
scroll.guiTop = this.guiTop + 88 + yoffset;
|
2025-03-13 17:14:45 -04:00
|
|
|
if (container != null) {
|
2026-01-13 17:34:14 +02:00
|
|
|
scroll.setList(container.getExternalScripts());
|
2021-10-01 01:17:12 -05:00
|
|
|
}
|
|
|
|
|
this.addScroll(scroll);
|
2025-12-22 15:06:54 +02:00
|
|
|
}
|
|
|
|
|
}
|
2021-10-01 01:17:12 -05:00
|
|
|
|
2025-12-22 15:06:54 +02:00
|
|
|
/**
|
|
|
|
|
* Initialize the settings tab layout (console view).
|
|
|
|
|
*/
|
|
|
|
|
private void initSettingsTab(int yoffset) {
|
|
|
|
|
GuiNpcTextArea var8 = new GuiNpcTextArea(2, this, this.guiLeft + 4 + yoffset, this.guiTop + 6 + yoffset,
|
|
|
|
|
this.xSize - 160 - yoffset, (int) ((float) this.ySize * 0.92F) - yoffset * 2, this.getConsoleText());
|
|
|
|
|
var8.canEdit = false;
|
|
|
|
|
var8.setFocused(true);
|
|
|
|
|
this.addTextField(var8);
|
|
|
|
|
|
|
|
|
|
int var9 = this.guiLeft + this.xSize - 150;
|
|
|
|
|
this.addButton(new GuiNpcButton(100, var9, this.guiTop + 125, 60, 20, "gui.copy"));
|
|
|
|
|
this.addButton(new GuiNpcButton(102, var9, this.guiTop + 146, 60, 20, "gui.clear"));
|
|
|
|
|
this.addLabel(new GuiNpcLabel(1, "script.language", var9, this.guiTop + 15));
|
|
|
|
|
this.addButton(new GuiNpcButton(103, var9 + 60, this.guiTop + 10, 80, 20,
|
|
|
|
|
(String[]) this.languages.keySet().toArray(new String[this.languages.keySet().size()]),
|
|
|
|
|
this.getScriptIndex()));
|
|
|
|
|
this.getButton(103).enabled = this.languages.size() > 0;
|
|
|
|
|
this.addLabel(new GuiNpcLabel(2, "gui.enabled", var9, this.guiTop + 36));
|
|
|
|
|
this.addButton(new GuiNpcButton(104, var9 + 60, this.guiTop + 31, 50, 20,
|
|
|
|
|
new String[]{"gui.no", "gui.yes"}, this.handler.getEnabled() ? 1 : 0));
|
|
|
|
|
|
|
|
|
|
if (this.player.worldObj.isRemote) {
|
|
|
|
|
this.addButton(new GuiNpcButton(106, var9, this.guiTop + 55, 150, 20, "script.openfolder"));
|
2021-10-01 01:17:12 -05:00
|
|
|
}
|
|
|
|
|
|
2025-12-22 15:06:54 +02:00
|
|
|
this.addButton(new GuiNpcButton(109, var9, this.guiTop + 78, 80, 20, "gui.website"));
|
|
|
|
|
this.addButton(new GuiNpcButton(112, var9 + 81, this.guiTop + 78, 80, 20, "gui.forum"));
|
|
|
|
|
this.addButton(new GuiNpcButton(110, var9, this.guiTop + 99, 80, 20, "script.apidoc"));
|
|
|
|
|
this.addButton(new GuiNpcButton(111, var9 + 81, this.guiTop + 99, 80, 20, "script.apisrc"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ==================== RENDERING ====================
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
|
|
|
|
super.drawScreen(mouseX, mouseY, partialTicks);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ==================== MOUSE HANDLING ====================
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void mouseClicked(int mouseX, int mouseY, int mouseButton) {
|
2026-01-04 01:56:13 +02:00
|
|
|
// Check if click is within autocomplete menu bounds and consume it if so
|
|
|
|
|
GuiScriptTextArea activeArea = getActiveScriptArea();
|
2026-01-04 02:13:33 +02:00
|
|
|
boolean isOverAutocomplete = activeArea != null
|
|
|
|
|
&& activeArea.isPointOnAutocompleteMenu(mouseX, mouseY);
|
|
|
|
|
if (isOverAutocomplete) {
|
2026-01-04 01:56:13 +02:00
|
|
|
activeArea.mouseClicked(mouseX, mouseY, mouseButton);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-22 15:06:54 +02:00
|
|
|
// Check fullscreen button first when on script editor tab
|
2026-01-04 01:56:13 +02:00
|
|
|
// BUT only if autocomplete is not visible (don't let clicks pass through autocomplete menu)
|
2026-01-04 02:13:33 +02:00
|
|
|
if (this.activeTab > 0 && !isOverAutocomplete
|
2026-01-04 01:56:13 +02:00
|
|
|
&& fullscreenButton.mouseClicked(mouseX, mouseY, mouseButton)) {
|
2025-12-22 15:06:54 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
super.mouseClicked(mouseX, mouseY, mouseButton);
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
2021-12-03 21:13:56 -06:00
|
|
|
public String previousHookClicked = "";
|
2025-03-13 17:14:45 -04:00
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
@Override
|
|
|
|
|
public void customScrollClicked(int i, int j, int k, GuiCustomScroll scroll) {
|
2021-12-03 21:13:56 -06:00
|
|
|
String hook = scroll.getSelected();
|
2025-03-13 17:14:45 -04:00
|
|
|
if (previousHookClicked.equals(hook)) {
|
2021-12-03 21:13:56 -06:00
|
|
|
String addString = "";
|
2025-03-13 17:14:45 -04:00
|
|
|
if (!this.getTextField(2).getText().isEmpty())
|
2021-12-03 21:13:56 -06:00
|
|
|
addString += "\n";
|
2025-03-13 17:14:45 -04:00
|
|
|
addString += "function " + hook + "(event) {\n \n}\n";
|
2021-12-03 21:13:56 -06:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
this.getTextField(2).setText(this.getTextField(2).getText() + addString);
|
2021-12-03 21:13:56 -06:00
|
|
|
previousHookClicked = "";
|
|
|
|
|
} else {
|
|
|
|
|
previousHookClicked = hook;
|
|
|
|
|
}
|
2021-10-11 06:49:30 -05:00
|
|
|
}
|
|
|
|
|
|
2021-10-18 06:33:39 -05:00
|
|
|
@Override
|
|
|
|
|
public void unFocused(GuiNpcTextField textfield) {
|
2021-12-22 03:33:50 -06:00
|
|
|
|
2021-10-18 06:33:39 -05:00
|
|
|
}
|
|
|
|
|
|
2025-02-09 04:02:16 -05:00
|
|
|
protected String getConsoleText() {
|
2021-10-17 16:11:29 -05:00
|
|
|
Map<Long, String> map = this.handler.getConsoleText();
|
2021-09-30 21:44:30 -05:00
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
Iterator var3 = map.entrySet().iterator();
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
while (var3.hasNext()) {
|
|
|
|
|
Entry<Long, String> entry = (Entry) var3.next();
|
|
|
|
|
builder.insert(0, new Date((Long) entry.getKey()) + (String) entry.getValue() + "\n");
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return builder.toString();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-12 03:28:18 +02:00
|
|
|
public int getScriptIndex() {
|
2021-09-30 21:44:30 -05:00
|
|
|
int i = 0;
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
for (Iterator var2 = this.languages.keySet().iterator(); var2.hasNext(); ++i) {
|
|
|
|
|
String language = (String) var2.next();
|
|
|
|
|
if (language.equalsIgnoreCase(this.handler.getLanguage())) {
|
2021-09-30 21:44:30 -05:00
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-01 01:17:12 -05:00
|
|
|
public void confirmClicked(boolean flag, int i) {
|
2025-03-13 17:14:45 -04:00
|
|
|
if (flag) {
|
|
|
|
|
if (i == 0) {
|
2022-07-12 11:58:54 -05:00
|
|
|
this.openLink("https://www.curseforge.com/minecraft/mc-mods/customnpc-plus");
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (i == 1) {
|
2022-07-12 11:58:54 -05:00
|
|
|
this.openLink("https://kamkeel.github.io/CustomNPC-Plus/");
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (i == 2) {
|
2023-02-28 03:35:37 -05:00
|
|
|
this.openLink("https://kamkeel.github.io/CustomNPC-Plus/");
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (i == 3) {
|
2021-09-30 21:44:30 -05:00
|
|
|
this.openLink("http://www.minecraftforge.net/forum/index.php/board,122.0.html");
|
|
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
if (i == 10) {
|
2026-01-12 03:28:18 +02:00
|
|
|
if (singleContainer)
|
|
|
|
|
setHandlerContainer(null);
|
|
|
|
|
else
|
|
|
|
|
this.handler.getScripts().remove(this.activeTab - 1);
|
2021-09-30 21:44:30 -05:00
|
|
|
this.activeTab = 0;
|
|
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
if (i == 101) {
|
2024-03-19 14:35:32 -04:00
|
|
|
(this.getTextField(2)).setText(NoppesStringUtils.getClipboardContents());
|
|
|
|
|
this.setScript();
|
|
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
if (i == 102) {
|
2024-03-19 14:35:32 -04:00
|
|
|
ScriptContainer container;
|
2025-03-13 17:14:45 -04:00
|
|
|
if (this.activeTab > 0) {
|
|
|
|
|
container = (ScriptContainer) this.handler.getScripts().get(this.activeTab - 1);
|
2024-03-19 14:35:32 -04:00
|
|
|
container.script = "";
|
|
|
|
|
} else {
|
|
|
|
|
this.handler.clearConsole();
|
|
|
|
|
if (this.handler instanceof ScriptCustomItem) {
|
|
|
|
|
((ScriptCustomItem) this.handler).saveScriptData();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
this.initGui();
|
|
|
|
|
}
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.displayGuiScreen(this);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-12 03:28:18 +02:00
|
|
|
public GuiScriptTextArea getActiveScriptArea() {
|
2026-01-12 03:56:22 +02:00
|
|
|
int idx = getActiveScriptIndex();
|
|
|
|
|
if (idx >= 0 && textAreas.containsKey(idx))
|
|
|
|
|
return textAreas.get(idx);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the current script index for text area storage.
|
|
|
|
|
* Override in subclasses with different tab logic.
|
|
|
|
|
*/
|
|
|
|
|
protected int getActiveScriptIndex() {
|
|
|
|
|
return this.activeTab - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the current script container.
|
|
|
|
|
* Override in subclasses with different container access patterns.
|
|
|
|
|
*/
|
2026-01-13 17:34:14 +02:00
|
|
|
protected IScriptUnit getCurrentContainer() {
|
2026-01-12 03:56:22 +02:00
|
|
|
int idx = getActiveScriptIndex();
|
|
|
|
|
if (idx >= 0 && idx < this.handler.getScripts().size())
|
|
|
|
|
return this.handler.getScripts().get(idx);
|
2025-12-22 02:22:01 +02:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public GuiNpcTextField getTextField(int id) {
|
|
|
|
|
if (id == 2) {
|
|
|
|
|
GuiScriptTextArea area = getActiveScriptArea();
|
|
|
|
|
if (area != null)
|
|
|
|
|
return area;
|
|
|
|
|
}
|
|
|
|
|
return super.getTextField(id);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-13 17:34:14 +02:00
|
|
|
public IScriptUnit getFirst() {
|
2026-01-12 03:28:18 +02:00
|
|
|
if (this.handler.getScripts().isEmpty())
|
|
|
|
|
return null;
|
|
|
|
|
return this.handler.getScripts().get(0);
|
|
|
|
|
}
|
2021-10-15 09:17:31 -05:00
|
|
|
@Override
|
2021-09-30 21:44:30 -05:00
|
|
|
protected void actionPerformed(GuiButton guibutton) {
|
2025-03-13 17:14:45 -04:00
|
|
|
if (guibutton.id >= 0 && guibutton.id < scriptLimit) {
|
2021-10-01 01:17:12 -05:00
|
|
|
this.setScript();
|
|
|
|
|
this.activeTab = guibutton.id;
|
|
|
|
|
this.initGui();
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (guibutton.id == scriptLimit) {
|
2026-01-12 03:28:18 +02:00
|
|
|
if (singleContainer) {
|
|
|
|
|
if (getFirst() == null)
|
|
|
|
|
setHandlerContainer(new ScriptContainer(handler));
|
|
|
|
|
else
|
|
|
|
|
this.setScript();
|
|
|
|
|
this.activeTab = 1;
|
|
|
|
|
} else {
|
|
|
|
|
this.handler.getScripts().add(new ScriptContainer(this.handler));
|
|
|
|
|
this.activeTab = this.handler.getScripts().size();
|
|
|
|
|
}
|
2021-10-01 01:17:12 -05:00
|
|
|
this.initGui();
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (guibutton.id == 109) {
|
2023-02-28 03:35:37 -05:00
|
|
|
this.displayGuiScreen(new GuiConfirmOpenLink(this, "https://kamkeel.github.io/CustomNPC-Plus/", 0, true));
|
2021-10-01 01:17:12 -05:00
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (guibutton.id == 110) {
|
2023-02-28 03:35:37 -05:00
|
|
|
this.displayGuiScreen(new GuiConfirmOpenLink(this, "https://github.com/KAMKEEL/CustomNPC-Plus-API", 1, true));
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
2021-10-01 01:17:12 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (guibutton.id == 111) {
|
2021-10-01 01:17:12 -05:00
|
|
|
this.displayGuiScreen(new GuiConfirmOpenLink(this, "https://github.com/Noppes/CustomNPCsAPI", 2, true));
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
2021-10-01 01:17:12 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (guibutton.id == 112) {
|
2021-10-01 01:17:12 -05:00
|
|
|
this.displayGuiScreen(new GuiConfirmOpenLink(this, "http://www.minecraftforge.net/forum/index.php/board,122.0.html", 3, true));
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
2021-10-01 01:17:12 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (guibutton.id == 100) {
|
2021-10-11 06:49:30 -05:00
|
|
|
NoppesStringUtils.setClipboardContents((this.getTextField(2)).getText());
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
2021-10-01 01:17:12 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (guibutton.id == 101) {
|
2024-03-19 14:35:32 -04:00
|
|
|
GuiYesNo guiyesno = new GuiYesNo(this, StatCollector.translateToLocal("gui.paste"), StatCollector.translateToLocal("gui.sure"), 101);
|
|
|
|
|
displayGuiScreen(guiyesno);
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
2021-10-01 01:17:12 -05:00
|
|
|
|
2021-12-01 15:31:05 -06:00
|
|
|
ScriptContainer container;
|
2025-03-13 17:14:45 -04:00
|
|
|
if (guibutton.id == 102) {
|
2024-03-19 14:35:32 -04:00
|
|
|
GuiYesNo guiyesno = new GuiYesNo(this, StatCollector.translateToLocal("gui.clear"), StatCollector.translateToLocal("gui.sure"), 102);
|
|
|
|
|
displayGuiScreen(guiyesno);
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
2021-10-01 01:17:12 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (guibutton.id == 103) {
|
|
|
|
|
this.handler.setLanguage(((GuiNpcButton) guibutton).displayString);
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
2021-10-01 01:17:12 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (guibutton.id == 104) {
|
|
|
|
|
this.handler.setEnabled((((GuiNpcButton) guibutton).getValue() == 1));
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
2021-10-01 01:17:12 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (guibutton.id == 105) {
|
|
|
|
|
GuiYesNo container1 = new GuiYesNo(this, "", ((GuiNpcButton) guibutton).displayString, 10);
|
2021-10-01 01:17:12 -05:00
|
|
|
this.displayGuiScreen(container1);
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
2021-10-01 01:17:12 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (guibutton.id == 106) {
|
2025-10-19 22:06:11 -04:00
|
|
|
// TODO: Opens the ScriptController shared directory; this screen is available only to editors with the scripter
|
|
|
|
|
// tool and CustomNpcsPermissions.TOOL_SCRIPTER.
|
2021-09-30 21:44:30 -05:00
|
|
|
NoppesUtil.openFolder(ScriptController.Instance.dir);
|
|
|
|
|
}
|
2021-10-01 01:17:12 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (guibutton.id == 107) {
|
|
|
|
|
container = (ScriptContainer) this.handler.getScripts().get(this.activeTab - 1);
|
|
|
|
|
if (container == null) {
|
2026-01-12 03:28:18 +02:00
|
|
|
container = new ScriptContainer(this.handler);
|
|
|
|
|
if (singleContainer)
|
|
|
|
|
setHandlerContainer(container);
|
|
|
|
|
else
|
|
|
|
|
this.handler.getScripts().add(container);
|
2021-10-01 01:17:12 -05:00
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
this.setSubGui(new EventGuiScriptList((List) this.languages.get(this.handler.getLanguage()), container));
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-12 03:28:18 +02:00
|
|
|
protected void setScript() {
|
2026-01-12 03:56:22 +02:00
|
|
|
if (this.activeTab > 0 || useScrollTabs) {
|
2026-01-13 17:34:14 +02:00
|
|
|
IScriptUnit container = getCurrentContainer();
|
2025-03-13 17:14:45 -04:00
|
|
|
if (container == null) {
|
2026-01-12 03:28:18 +02:00
|
|
|
container = new ScriptContainer(this.handler);
|
|
|
|
|
if (singleContainer)
|
|
|
|
|
setHandlerContainer(container);
|
|
|
|
|
else
|
|
|
|
|
this.handler.getScripts().add(container);
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
String text = (this.getTextField(2)).getText();
|
2021-09-30 21:44:30 -05:00
|
|
|
text = text.replace("\r\n", "\n");
|
|
|
|
|
text = text.replace("\r", "\n");
|
2026-01-13 17:34:14 +02:00
|
|
|
container.setScript(text);
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setGuiData(NBTTagCompound compound) {
|
|
|
|
|
NBTTagList data = compound.getTagList("Languages", 10);
|
2021-10-01 01:17:12 -05:00
|
|
|
HashMap languages = new HashMap();
|
2021-09-30 21:44:30 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
for (int i = 0; i < data.tagCount(); ++i) {
|
2021-09-30 21:44:30 -05:00
|
|
|
NBTTagCompound comp = data.getCompoundTagAt(i);
|
2021-10-01 01:17:12 -05:00
|
|
|
ArrayList scripts = new ArrayList();
|
2021-09-30 21:44:30 -05:00
|
|
|
NBTTagList list = comp.getTagList("Scripts", 8);
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
for (int j = 0; j < list.tagCount(); ++j) {
|
2021-09-30 21:44:30 -05:00
|
|
|
scripts.add(list.getStringTagAt(j));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
languages.put(comp.getString("Language"), scripts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.languages = languages;
|
|
|
|
|
this.initGui();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-09 22:59:13 -05:00
|
|
|
/**
|
|
|
|
|
* Get the script context for this GUI.
|
|
|
|
|
* Override in subclasses to return the appropriate context.
|
|
|
|
|
*
|
|
|
|
|
* @return The script context (default: GLOBAL)
|
|
|
|
|
*/
|
|
|
|
|
protected ScriptContext getScriptContext() {
|
|
|
|
|
return ScriptContext.GLOBAL;
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-12 03:28:18 +02:00
|
|
|
// ==================== UNIFIED SCRIPT DATA HANDLING ====================
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unified setGuiData for script GUIs with old container system.
|
|
|
|
|
* Handles both language data and tab-specific script loading.
|
|
|
|
|
*/
|
|
|
|
|
protected void setGuiDataWithOldContainer(NBTTagCompound compound) {
|
|
|
|
|
if (compound.hasKey("LoadComplete")) {
|
|
|
|
|
loaded = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!compound.hasKey("Tab")) {
|
|
|
|
|
this.handler.setLanguage(compound.getString("ScriptLanguage"));
|
|
|
|
|
this.handler.setEnabled(compound.getBoolean("ScriptEnabled"));
|
|
|
|
|
this.loadLanguagesData(compound);
|
|
|
|
|
} else {
|
|
|
|
|
int tab = compound.getInteger("Tab");
|
|
|
|
|
ScriptContainer container = new ScriptContainer(this.handler);
|
|
|
|
|
container.readFromNBT(compound.getCompoundTag("Script"));
|
|
|
|
|
this.setHandlerContainer(container);
|
|
|
|
|
this.initGui();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Load languages data from NBT.
|
|
|
|
|
* Separated for potential override in subclasses if needed.
|
|
|
|
|
*/
|
|
|
|
|
protected void loadLanguagesData(NBTTagCompound compound) {
|
|
|
|
|
NBTTagList data = compound.getTagList("Languages", 10);
|
|
|
|
|
HashMap languages = new HashMap();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < data.tagCount(); ++i) {
|
|
|
|
|
NBTTagCompound comp = data.getCompoundTagAt(i);
|
|
|
|
|
java.util.ArrayList scripts = new java.util.ArrayList();
|
|
|
|
|
NBTTagList list = comp.getTagList("Scripts", 8);
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < list.tagCount(); ++j) {
|
|
|
|
|
scripts.add(list.getStringTagAt(j));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
languages.put(comp.getString("Language"), scripts);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.languages = languages;
|
|
|
|
|
this.initGui();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the handler's container. Override if handler is not IScriptHandler.
|
|
|
|
|
*/
|
2026-01-13 17:34:14 +02:00
|
|
|
protected void setHandlerContainer(IScriptUnit container) {
|
2026-01-12 03:28:18 +02:00
|
|
|
// Default implementation - subclasses may need to cast and set differently
|
|
|
|
|
// e.g., ((LinkedItemScript) handler).container = container;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Unified save method for script GUIs with packet-based saving.
|
|
|
|
|
* Subclasses only need to override sendScriptPackets() and sendMetadataPacket().
|
|
|
|
|
*/
|
|
|
|
|
protected void saveWithPackets() {
|
|
|
|
|
if (loaded) {
|
|
|
|
|
this.setScript();
|
|
|
|
|
|
2026-01-13 17:34:14 +02:00
|
|
|
List<IScriptUnit> containers = this.handler.getScripts();
|
2026-01-12 03:28:18 +02:00
|
|
|
for (int i = 0; i < containers.size(); i++) {
|
2026-01-13 17:34:14 +02:00
|
|
|
IScriptUnit container = containers.get(i);
|
2026-01-12 03:28:18 +02:00
|
|
|
sendSavePacket(i, containers.size(), container.writeToNBT(new NBTTagCompound()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NBTTagCompound scriptData = new NBTTagCompound();
|
|
|
|
|
scriptData.setString("ScriptLanguage", this.handler.getLanguage());
|
|
|
|
|
scriptData.setBoolean("ScriptEnabled", this.handler.getEnabled());
|
|
|
|
|
scriptData.setTag("ScriptConsole", noppes.npcs.NBTTags.NBTLongStringMap(this.handler.getConsoleText()));
|
|
|
|
|
|
|
|
|
|
sendSavePacket(-1, containers.size(), scriptData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send a script container packet. Override in subclasses.
|
|
|
|
|
* @param index The index of this script
|
|
|
|
|
* @param totalCount Total number of scripts
|
|
|
|
|
* @param scriptNBT The script container NBT data
|
|
|
|
|
*/
|
|
|
|
|
protected void sendSavePacket(int index, int totalCount, NBTTagCompound scriptNBT) {
|
|
|
|
|
// Default: do nothing (for non-packet-based GUIs like GuiScriptItem)
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-30 21:44:30 -05:00
|
|
|
public void save() {
|
2025-07-23 14:22:52 -04:00
|
|
|
if (loaded)
|
2025-05-29 21:09:58 -04:00
|
|
|
this.setScript();
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void textUpdate(String text) {
|
2026-01-13 17:34:14 +02:00
|
|
|
IScriptUnit container = getCurrentContainer();
|
2025-03-13 17:14:45 -04:00
|
|
|
if (container != null) {
|
2026-01-13 17:34:14 +02:00
|
|
|
container.setScript(text);
|
2021-09-30 21:44:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2021-10-11 06:49:30 -05:00
|
|
|
|
2026-01-12 03:28:18 +02:00
|
|
|
@Deprecated
|
2021-10-11 06:49:30 -05:00
|
|
|
@Override
|
2026-01-12 03:28:18 +02:00
|
|
|
//NEVER USED
|
2021-10-11 06:49:30 -05:00
|
|
|
public void saveText(String text) {
|
2026-01-13 17:34:14 +02:00
|
|
|
IScriptUnit container = getCurrentContainer();
|
2025-03-13 17:14:45 -04:00
|
|
|
if (container != null)
|
2026-01-13 17:34:14 +02:00
|
|
|
container.setScript(text);
|
2021-10-11 06:49:30 -05:00
|
|
|
initGui();
|
|
|
|
|
}
|
2025-12-22 15:06:54 +02:00
|
|
|
|
2026-01-12 03:28:18 +02:00
|
|
|
@Override
|
|
|
|
|
public void close() {
|
|
|
|
|
if (parent != null) {
|
|
|
|
|
this.save();
|
|
|
|
|
parent.setWorldAndResolution(mc, width, height);
|
|
|
|
|
parent.initGui();
|
|
|
|
|
mc.currentScreen = parent;
|
|
|
|
|
} else
|
|
|
|
|
super.close();
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-22 15:06:54 +02:00
|
|
|
// ==================== FULLSCREEN METHODS ====================
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Toggle fullscreen mode for the editor viewport.
|
|
|
|
|
* When entering fullscreen, maximizes the game window if it's not already.
|
|
|
|
|
*/
|
|
|
|
|
public void toggleFullscreen() {
|
|
|
|
|
isFullscreen = !isFullscreen;
|
|
|
|
|
|
|
|
|
|
// When entering fullscreen, maximize the game window if not already fullscreen
|
|
|
|
|
if (isFullscreen && !Display.isFullscreen()) {
|
|
|
|
|
// Note: Display.setFullscreen(true) would make it truly fullscreen,
|
|
|
|
|
// but that's usually not desirable for an in-game editor.
|
|
|
|
|
// The viewport will expand to fill whatever window size exists.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initGui();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check if editor is currently in fullscreen mode
|
|
|
|
|
*/
|
|
|
|
|
public boolean isEditorFullscreen() {
|
|
|
|
|
return isFullscreen;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ==================== FULLSCREEN BUTTON ====================
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Button to toggle fullscreen mode, displayed at top-right corner of viewport.
|
|
|
|
|
* Shows expand icon when minimized, collapse icon when fullscreen.
|
|
|
|
|
*/
|
|
|
|
|
|
2025-12-22 15:52:52 +02:00
|
|
|
public class FullscreenButton {
|
2025-12-22 15:06:54 +02:00
|
|
|
public int x, y;
|
|
|
|
|
public int size = 12;
|
|
|
|
|
public boolean hovered = false;
|
|
|
|
|
|
|
|
|
|
/** Initialize button position relative to viewport bounds */
|
|
|
|
|
public void initGui(int viewportEndX, int viewportY, int scrollbarOffset) {
|
|
|
|
|
// Position at top-right, accounting for scrollbar
|
|
|
|
|
this.x = viewportEndX + scrollbarOffset - size - 4;
|
|
|
|
|
this.y = viewportY + 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Draw the fullscreen toggle button */
|
|
|
|
|
public void draw(int mouseX, int mouseY) {
|
|
|
|
|
hovered = isMouseOver(mouseX, mouseY);
|
2025-12-22 15:52:52 +02:00
|
|
|
int y = this.y + getYOffset();
|
2025-12-22 15:06:54 +02:00
|
|
|
|
|
|
|
|
// Button background
|
|
|
|
|
int bgColor = hovered ? 0x80666666 : 0x60444444;
|
|
|
|
|
GuiUtil.drawRectD(x, y, x + size, y + size, bgColor);
|
|
|
|
|
|
|
|
|
|
// Draw corner brackets to indicate expand/collapse
|
|
|
|
|
int iconColor = hovered ? 0xFFFFFFFF : 0xFFAAAAAA;
|
|
|
|
|
int inset = 2;
|
|
|
|
|
int cornerLen = 3;
|
|
|
|
|
|
|
|
|
|
if (isFullscreen) {
|
2025-12-22 16:06:20 +02:00
|
|
|
// Draw collapse icon (corners pointing inward) — inward L-shapes
|
|
|
|
|
int top = y + inset + 2;
|
|
|
|
|
int left = x + inset + 2;
|
|
|
|
|
int right = x + size - inset - 3;
|
|
|
|
|
int bottom = y + size - inset - 3;
|
|
|
|
|
|
|
|
|
|
drawRect(left, top - cornerLen + 1, left + 1, top + 1, iconColor);
|
|
|
|
|
drawRect(left - cornerLen + 1, top, left + 1, top + 1, iconColor);
|
|
|
|
|
|
|
|
|
|
drawRect(right, top, right + cornerLen, top + 1, iconColor);
|
|
|
|
|
drawRect(right, top - cornerLen + 1, right + 1, top + 1, iconColor);
|
|
|
|
|
|
|
|
|
|
drawRect(left - cornerLen + 1, bottom, left + 1, bottom + 1, iconColor);
|
|
|
|
|
drawRect(left, bottom, left + 1, bottom + cornerLen, iconColor);
|
|
|
|
|
|
|
|
|
|
drawRect(right, bottom, right + cornerLen, bottom + 1, iconColor);
|
|
|
|
|
drawRect(right, bottom, right + 1, bottom + cornerLen, iconColor);
|
|
|
|
|
|
2025-12-22 15:06:54 +02:00
|
|
|
} else {
|
|
|
|
|
// Draw expand icon (corners pointing outward) ⌐¬⌙⌞
|
|
|
|
|
// Top-left corner pointing outward
|
|
|
|
|
drawRect(x + inset, y + inset, x + inset + 1, y + inset + cornerLen, iconColor);
|
|
|
|
|
drawRect(x + inset, y + inset, x + inset + cornerLen, y + inset + 1, iconColor);
|
|
|
|
|
// Top-right corner pointing outward
|
|
|
|
|
drawRect(x + size - inset - 1, y + inset, x + size - inset, y + inset + cornerLen, iconColor);
|
|
|
|
|
drawRect(x + size - inset - cornerLen, y + inset, x + size - inset, y + inset + 1, iconColor);
|
|
|
|
|
// Bottom-left corner pointing outward
|
|
|
|
|
drawRect(x + inset, y + size - inset - cornerLen, x + inset + 1, y + size - inset, iconColor);
|
|
|
|
|
drawRect(x + inset, y + size - inset - 1, x + inset + cornerLen, y + size - inset, iconColor);
|
|
|
|
|
// Bottom-right corner pointing outward
|
|
|
|
|
drawRect(x + size - inset - 1, y + size - inset - cornerLen, x + size - inset, y + size - inset,
|
|
|
|
|
iconColor);
|
|
|
|
|
drawRect(x + size - inset - cornerLen, y + size - inset - 1, x + size - inset, y + size - inset,
|
|
|
|
|
iconColor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void drawRect(int x1, int y1, int x2, int y2, int color) {
|
|
|
|
|
GuiUtil.drawRectD(x1, y1, x2, y2, color);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Check if mouse is over the button */
|
|
|
|
|
public boolean isMouseOver(int mouseX, int mouseY) {
|
2025-12-22 15:52:52 +02:00
|
|
|
int y = this.y + getYOffset();
|
2025-12-22 15:06:54 +02:00
|
|
|
return mouseX >= x && mouseX < x + size && mouseY >= y && mouseY < y + size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Handle click - returns true if click was consumed */
|
|
|
|
|
public boolean mouseClicked(int mouseX, int mouseY, int button) {
|
|
|
|
|
if (button == 0 && isMouseOver(mouseX, mouseY)) {
|
|
|
|
|
toggleFullscreen();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2025-12-22 15:52:52 +02:00
|
|
|
|
|
|
|
|
public int getYOffset() {
|
|
|
|
|
return GuiScriptTextArea.searchBar.getTotalHeight();
|
|
|
|
|
}
|
2025-12-22 15:06:54 +02:00
|
|
|
}
|
2024-03-19 14:35:32 -04:00
|
|
|
}
|