mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-16 18:54:53 +00:00
temp SingleScriptHandlers tuff
This commit is contained in:
1 parent
23c44cc5d4
commit
f6e589ac67
2 files changed
+105
-37
No files matched your search
@@ -27,6 +27,7 @@ import noppes.npcs.constants.ScriptContext;
|
||||
import noppes.npcs.controllers.data.ForgeDataScript;
|
||||
import noppes.npcs.controllers.data.IScriptHandler;
|
||||
import noppes.npcs.controllers.data.IScriptUnit;
|
||||
import noppes.npcs.controllers.data.SingleScriptHandler;
|
||||
import noppes.npcs.scripted.item.ScriptCustomItem;
|
||||
import org.lwjgl.opengl.Display;
|
||||
|
||||
@@ -49,9 +50,6 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
protected Map<Integer, GuiScriptTextArea> textAreas = new HashMap<>();
|
||||
protected GuiScreen parent;
|
||||
|
||||
/** Single script being edited (handler-less mode) */
|
||||
protected IScriptUnit singleScript;
|
||||
|
||||
public boolean singleContainer = false;
|
||||
|
||||
/** If true, uses scroll-based tab selection instead of top buttons */
|
||||
@@ -91,35 +89,15 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for single JaninoScript editing (handler-less mode).
|
||||
* Used for scripts like OverlayScript that don't have an IScriptHandler.
|
||||
*
|
||||
* @param parent The parent GUI to return to when closing
|
||||
* @param script The JaninoScript to edit
|
||||
*/
|
||||
public GuiScriptInterface(GuiScreen parent, IScriptUnit script) {
|
||||
this();
|
||||
this.parent = parent;
|
||||
this.singleScript = script;
|
||||
this.singleContainer = true;
|
||||
this.loaded = true;
|
||||
|
||||
// Start on script tab (tab 1)
|
||||
this.activeTab = 1;
|
||||
|
||||
// Build hook list from the script's type using reflection
|
||||
// this.hookList = script.getHookList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and initialize a GuiScriptInterface for a JaninoScript.
|
||||
* This is the main entry point for handler-less script editing.
|
||||
* Create a GuiScriptInterface for a single script without a handler.
|
||||
* Wraps the script in a SingleScriptHandler automatically.
|
||||
*/
|
||||
public static GuiScriptInterface create(GuiScreen parent, IScriptUnit script) {
|
||||
GuiScriptInterface gui = new GuiScriptInterface(parent, script);
|
||||
gui.setWorldAndResolution(Minecraft.getMinecraft(), gui.width, gui.height);
|
||||
Minecraft.getMinecraft().currentScreen = gui;
|
||||
gui.initGui();
|
||||
GuiScriptInterface gui = new GuiScriptInterface();
|
||||
gui.handler = new SingleScriptHandler(script);
|
||||
gui.parent = parent;
|
||||
gui.singleContainer = true;
|
||||
gui.displayGuiScreen(gui);
|
||||
return gui;
|
||||
}
|
||||
|
||||
@@ -489,10 +467,6 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
* Override in subclasses with different container access patterns.
|
||||
*/
|
||||
protected IScriptUnit getCurrentContainer() {
|
||||
// Handler-less single JaninoScript mode
|
||||
if (singleScript != null)
|
||||
return singleScript;
|
||||
|
||||
int idx = getActiveScriptIndex();
|
||||
if (idx >= 0 && idx < this.handler.getScripts().size())
|
||||
return this.handler.getScripts().get(idx);
|
||||
@@ -639,11 +613,10 @@ public class GuiScriptInterface extends GuiNPCInterface implements GuiYesNoCallb
|
||||
}
|
||||
|
||||
protected void setScript() {
|
||||
if (this.activeTab > 0 || useScrollTabs || singleScript != null) {
|
||||
if (this.activeTab > 0 || useScrollTabs) {
|
||||
IScriptUnit container = getCurrentContainer();
|
||||
|
||||
// Skip container creation for single JaninoScript mode
|
||||
if (container == null && singleScript == null) {
|
||||
if (container == null) {
|
||||
container = new ScriptContainer(this.handler);
|
||||
if (singleContainer)
|
||||
setHandlerUnit(container);
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package noppes.npcs.controllers.data;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Simple IScriptHandler implementation for single scripts that don't have their own handler.
|
||||
* Useful for standalone scripts like OverlayScript that need to be edited in GuiScriptInterface.
|
||||
*/
|
||||
public class SingleScriptHandler implements IScriptHandler {
|
||||
private final IScriptUnit script;
|
||||
private final List<IScriptUnit> scripts = new ArrayList<>();
|
||||
|
||||
public SingleScriptHandler(IScriptUnit script) {
|
||||
this.script = script;
|
||||
this.scripts.add(script);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callScript(EnumScriptType type, Event event) {
|
||||
// No-op: single scripts don't respond to standard hook calls
|
||||
}
|
||||
|
||||
@Override
|
||||
public void callScript(String hookName, Event event) {
|
||||
// No-op: single scripts don't respond to standard hook calls
|
||||
}
|
||||
|
||||
public boolean isClient() {
|
||||
return FMLCommonHandler.instance()
|
||||
.getEffectiveSide()
|
||||
.isClient();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
// No-op: single scripts are always enabled
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLanguage() {
|
||||
return script.getLanguage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLanguage(String language) {
|
||||
// No-op: language is determined by script type
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setScripts(List<IScriptUnit> list) {
|
||||
// No-op: single script handler only manages one script
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IScriptUnit> getScripts() {
|
||||
return scripts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String noticeString() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, String> getConsoleText() {
|
||||
return script.getConsole();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearConsole() {
|
||||
script.clearConsole();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IScriptUnit createJaninoScriptUnit() {
|
||||
return null; // Single script handlers don't create new scripts
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsJanino() {
|
||||
return script.isJanino();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user