diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 82b20ac..75f3081 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -3,7 +3,7 @@ name: Build
on:
push:
branches:
- - '1.20.2'
+ - '1.20.4'
jobs:
build:
diff --git a/README.md b/README.md
index 4eccbc9..8bee482 100644
--- a/README.md
+++ b/README.md
@@ -10,100 +10,30 @@ DFScript is a mod created for DiamondFire to allow scripting on the client. This
## About
DFScript adds the ability to add new features through the added
-'scripting' ability. Scripting is constructing event based code (similar to DiamondFire) inside a client side menu, with the events and actions being simple client-based activities.
+'scripting' ability. Scripting is constructing event based code (similar to DiamondFire) inside a web ui, with the events and actions being simple client-based activities.
-For example, a script could play a sound when the player receives a message with their name in it, or automatically add the @ character in front of sent messages.
+For example, a script could play a sound when the player receives a message with their name in it, or automatically add the @ character in front of sent messages.
___
-To access the scripting menu, run `/scripts`, and a menu will appear showing all of the scripts you have installed. Here you can toggle, delete, edit and upload scripts.
-*(A simple menu which can disable scripts can be accessed through the button in the top left.)*
+To access the DFScript menu, run `/dfscript`, and a menu will appear showing many different options, you can then press **Installed Scripts** to view scripts you currently have installed, here you can toggle scripts on and off or press **Dashboard** to visit the scripting dashboard and create/install new scripts.
+*(The same many can be accessed on the multiplayer connection screen)*
-To install a script you can click 'Add' and browse through scripts that others have created, or select 'New Script' if you would like to create one yourself.
+To install a script you can locate the one you wish to install via the [public directory](https://dfscript.techstreet.dev/public/) and then press **Install Script** the script will then automatically install on your client and be enabled.
## Creating Scripts
+To create a new script, access the [dashboard](https://dfscript.techstreet.dev/) from here you can press the **New Script** button, and then name and version your script, it will be created and displayed in the main menu. From here, you can edit, upload and delete.
-To create a new script, run `/script`, select 'Add', and 'New Script'. After naming your script, it will be created and displayed in the main menu. From here, you can edit, upload, delete, and toggle your script.
-
-Here is what each of these actions do:
--  Edit: From this menu, you can add options and code to your script.
--  Upload: Uploads the script so that others with the mod can install and use it. (They can not modify the code)
--  Delete: Deletes your script permanently.
-- **/** Toggle: Toggles your script on and off. When a script is off, it does not run at all. (Red means script is currently on, green means script is off)
-
-To edit your script, select the edit icon and a new menu will be opened. From here, you can add code, change your scripts description and add config options.
-
--  From here you can write a short description about your script to tell others who may use it any important information.
-You can also add config options which users can change without accessing the code. The values of these options can be used in your code. (More info [later](https://github.com/not-first/DFScript-updated-readme-/edit/1.19.2/README.md#changing-parameters))
-
-
-
-## Interactions
-**Left click**
-- Use on buttons to click them
-- Use to add code to your script, and to add parameters to code blocks
-- Use in your script menu to edit parameters of a code block
-- Use to select text box
-
-**Right Click**
-- Use on code blocks in your script menu to bring up a small menu where you can:
- - Delete the code block
- - Insert code before the code block
- - Insert new code after the code block
-- Can also be used on buttons to click them
-
-**Escape**
-- Use in any menu to go back to the previous menu
-
- **Scroll**
-- Moves a menu up and down
-
-## Editing Scripts
-*Note that it is only possible to edit code in a script you have made yourself. Any downloaded script will still be able to be deleted, toggled, and have its options changed, but the code will be inaccessible.*
-
-Select the 'Add' button to add code to your script. From there you can select the category, and a specific code block. There is a short description about each block if you hover over them to help you understand what they do.
-
-All code is set in one menu. Just like in DiamondFire, all code must start with an event. When that event is triggered, the code inside it will run from top to bottom.
-
-### Changing Parameters
-Most code blocks need parameters inside them so they can execute properly. You can view what parameters a code blocks needs by hovering over its icon in your script menu. An asterisk after a parameter means that a value for it is not required and the code block can run without it.
-
-To add values for these parameters, left click on the code block you would like to edit and a menu will be brought up. Any parameters already in the code block will show. To add values, click the 'Add' button, and a new menu with a text input box will appear.
-___
-This input screen has two important sections.
-1. The text box. Here is where you input a number, string, name of a variable or any other type of value required. Make sure you have finished the value you would like to add to your code block before selecting a type.
-2. The value type. Here is where you select what type of value you would like to add to your code block. For example, if I wanted to add a variable called 'score', I would type `score` in the text box, then click on the variable icon (magma cream). A variable named 'score' will be added to the code block.
-Most value types and their icons such as a text, a number and a variable you may recognise from DiamondFire, but here are some ones you may not be familiar with:
-
- - Client Value: *(Requires no text input.)* Selecting this value will bring up a menu containing values related to the client, very similar to DiamondFire's game values.
- Some of these can be used in any scenario, such as the number of the players selected hotbar slot, or the players main hand item.
- Others can only used if the code is under a certain event, such as the last received message *(pairs with the 'OnRecieveChat' event)* or the last received sound *(pairs with the 'OnRecieveSound' event)*.
- - Config Value: *(Requires no text input.)* Selecting this value will bring up a menu of all the config options you have added to your script. These will act as a variable and return a value of the option.
-For example, if I had created Option 1 as a string, and the user had set it to `complete`, the config value for options 1 would return 'complete' as a string.
-These can be nearly any value type, so pay attention to make sure the code block you are using supports the value type.
-
-*Currently, changing the order and contents of added parameters is not supported, so you will have to delete and redo if you make a mistake.*
## Disabling Scripts - !!
-Sometimes when you are creating a script, you may accidentally make your client complete actions which are against DiamondFire rules, such as making your client spam, or other similar actions. If this is the case, immediately leave the server. In the top left if your multiplayer screen, there will be a button button () which will open up a version of the scripts menu where scripts can be disabled. When you rejoin the server the script will now be disabled. **You can edit code inside a disabled script, so make sure you have fixed the issue before re-enabling the script.**
-If the issue came from a script you did not make, report the script in the [discord](https://discord.gg/gtfFwWEapx) so it can be removed.
-## Downloading Scripts
-To download a script that someone else has made, open the main scripts menu, select add, and there will be a list of scripts others have made as well as a search bar. Scripts with a star next to their name mean that they are verified and safe to use.
+Sometimes when you are creating a script, you may accidentally make your client complete actions which are against DiamondFire rules, such as making your client spam, or other similar actions. If this is the case, immediately leave the server. In the top left if your multiplayer screen, there will be a button button () which will open up a version of the DFScript menu where scripts can be disabled. When you rejoin the server the script will now be disabled.
-**!! Unverified scripts may potentially be dangerous, not towards your computer, but they may make your client spam or do other activities not appreciated on DiamondFire. You can ask in the discord if you are unsure about a certain script. !!**
-
-Selecting a script from here will bring up a menu showing information about the script such as the authors name, script ID, and if it has been approved or not.
-Clicking the install button from here will add the script to your client. A message will be shown in chat verifying the script has been loaded. This downloaded script will appear in the normal scripts menu, just without the ability to upload it or edit its code.
-
-## Commands and Files
-
-All DFScript commands begin with `/scripts`.
-- `/scripts` Opens the main script menu.
-- `/scripts recursion (number)` Changes the number of events that can trigger in a single tick.
-- `/scripts reload` Reloads all of the scripts on your machine. Use this is you are manually installing are changing scripts through files.
-- `/scripts vars (script name)` Lists the values of all the variables in the selected script. Similar to DiamondFire's /p vars command.
-
-To access script files go to `%appdata%\.minecraft\DFScript` on your machine. Here there will be a 'Scripts' folder, which contains all the scripts you have installed in the form of a json file. If a script manages text files, they will be in a sub folder called `scriptname.json-files`.
+If the issue came from a script you did not make, report the script in the [discord](https://discord.gg/gtfFwWEapx) so it can be removed.
-You can easily back up scripts here by copy and pasting the json file into another location. Pasting and deleting json files from this folder will do the same in-game, so be careful about what you change.
+## Commands
+All DFScript commands begin with `/dfscript`.
+- `/dfscript` Opens the main DFScript menu.
+- `/dfscript recursion (number)` Changes the number of events that can trigger in a single tick.
+- `/dfscript reload` Downloads and reloads all of the scripts on your machine.
+- `/dfscript vars (script name)` Lists the values of all the variables in the selected script. Similar to DiamondFire's /p vars command.
___
diff --git a/build.gradle b/build.gradle
index eded3a9..e962bdf 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,5 +1,5 @@
plugins {
- id 'fabric-loom' version '1.2-SNAPSHOT'
+ id 'fabric-loom' version '1.5-SNAPSHOT'
id 'maven-publish'
id 'com.github.johnrengelman.shadow' version '7.1.2'
}
diff --git a/gradle.properties b/gradle.properties
index 807338d..9ad951b 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -2,13 +2,13 @@
org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
-minecraft_version=1.20.2
-yarn_mappings=1.20.2+build.4
-loader_version=0.15.3
+minecraft_version=1.20.4
+yarn_mappings=1.20.4+build.3
+loader_version=0.15.7
# Mod Properties
mod_version=1.0-SNAPSHOT
maven_group=io.github.techstreet.dfscript
archives_base_name=DFScript
# Dependencies
# check this on https://modmuss50.me/fabric.html
-fabric_version=0.91.2+1.20.2
\ No newline at end of file
+fabric_version=0.96.1+1.20.4
\ No newline at end of file
diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar
index 7454180..c1962a7 100644
Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 59bc51a..509c4a2 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
+networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
diff --git a/gradlew b/gradlew
index c53aefa..aeb74cb 100755
--- a/gradlew
+++ b/gradlew
@@ -1,7 +1,7 @@
#!/bin/sh
#
-# Copyright 2015-2021 the original authors.
+# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -32,10 +32,10 @@
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
-# * expansions $var, ${var}, ${var:-default}, ${var+SET},
-# ${var#prefix}, ${var%suffix}, and $( cmd );
-# * compound commands having a testable exit status, especially case;
-# * various built-in commands including command, set, and ulimit.
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
@@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
-# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -80,13 +80,10 @@ do
esac
done
-APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
-
-APP_NAME="Gradle"
+# This is normally unused
+# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
-
-# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
-DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@@ -143,12 +140,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@@ -193,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
@@ -205,6 +210,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
+fi
+
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
diff --git a/gradlew.bat b/gradlew.bat
index 107acd3..93e3f59 100644
--- a/gradlew.bat
+++ b/gradlew.bat
@@ -14,7 +14,7 @@
@rem limitations under the License.
@rem
-@if "%DEBUG%" == "" @echo off
+@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
-if "%DIRNAME%" == "" set DIRNAME=.
+if "%DIRNAME%"=="" set DIRNAME=.
+@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
-if "%ERRORLEVEL%" == "0" goto execute
+if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
:end
@rem End local scope for the variables with windows NT shell
-if "%ERRORLEVEL%"=="0" goto mainEnd
+if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
-if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
-exit /b 1
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
diff --git a/src/main/java/io/github/techstreet/dfscript/ActiondumpHandler.java b/src/main/java/io/github/techstreet/dfscript/ActiondumpHandler.java
new file mode 100644
index 0000000..2459b31
--- /dev/null
+++ b/src/main/java/io/github/techstreet/dfscript/ActiondumpHandler.java
@@ -0,0 +1,88 @@
+package io.github.techstreet.dfscript;
+
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+import io.github.techstreet.dfscript.loader.Loadable;
+import io.github.techstreet.dfscript.script.action.ScriptActionArgument;
+import io.github.techstreet.dfscript.script.action.ScriptActionArgumentList;
+import io.github.techstreet.dfscript.script.action.ScriptActionType;
+import io.github.techstreet.dfscript.script.argument.ScriptClientValueArgument;
+import io.github.techstreet.dfscript.script.event.ScriptEventType;
+
+import java.io.File;
+import java.nio.file.Files;
+
+public class ActiondumpHandler implements Loadable {
+ @Override
+ public void load() {
+ JsonObject obj = new JsonObject();
+ JsonArray array = new JsonArray();
+
+ for (ScriptEventType type : ScriptEventType.values()) {
+ JsonObject event = new JsonObject();
+ event.addProperty("identifier", type.name());
+ event.addProperty("name", type.getName());
+ event.addProperty("description", type.getDescription());
+ event.addProperty("icon", type.getItem().toString());
+ array.add(event);
+ }
+
+ obj.add("events", array);
+ array = new JsonArray();
+
+ for (ScriptActionType type : ScriptActionType.values()) {
+ JsonObject event = new JsonObject();
+ JsonArray array2 = new JsonArray();
+ event.addProperty("identifier", type.name());
+ event.addProperty("name", type.getName());
+ event.addProperty("category", type.getCategory().name());
+ event.addProperty("description", String.join("\n", type.getDescription()));
+ event.addProperty("icon", type.getItem().toString());
+
+ for (ScriptActionArgument arg : type.getArguments()) {
+ JsonObject arg2 = new JsonObject();
+ arg2.addProperty("type", arg.getType().name());
+ arg2.addProperty("type_icon", arg.getType().getIcon().toString());
+ arg2.addProperty("type_name", arg.getType().getName());
+ arg2.addProperty("name", arg.getName());
+ arg2.addProperty("optional", arg.isOptional());
+ arg2.addProperty("plural", arg.isPlural());
+
+ array2.add(arg2);
+ }
+
+
+ //event.addProperty("icon", type.get().toString());
+ event.add("arguments", array2);
+ array.add(event);
+ }
+
+ obj.add("actions", array);
+ array = new JsonArray();
+
+ for (ScriptClientValueArgument type : ScriptClientValueArgument.values()) {
+ JsonObject event = new JsonObject();
+ event.addProperty("identifier", type.name());
+ event.addProperty("name", type.getName());
+ event.addProperty("description", String.join("\n", type.getDescription()));
+ event.addProperty("icon", type.getItem().toString());
+ event.addProperty("type", type.getType().name());
+ event.addProperty("type_icon", type.getType().getIcon().toString());
+ event.addProperty("type_name", type.getType().getName());
+
+ array.add(event);
+ }
+
+ obj.add("client_values", array);
+
+ File file = new File("DFScript/actiondump.json");
+ DFScript.LOGGER.info("Dumping action data to " + file.getAbsolutePath());
+
+ try {
+ if (!file.exists()) file.createNewFile();
+ Files.write(file.toPath(), DFScript.GSON.toJson(obj).getBytes());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/io/github/techstreet/dfscript/DFScript.java b/src/main/java/io/github/techstreet/dfscript/DFScript.java
index 4a1c34e..992d0d3 100644
--- a/src/main/java/io/github/techstreet/dfscript/DFScript.java
+++ b/src/main/java/io/github/techstreet/dfscript/DFScript.java
@@ -61,13 +61,14 @@ public void onInitialize() {
loader.load(new Scheduler());
loader.load(new UpdateAlerts());
loader.load(new OverlayManager());
+ loader.load(new ActiondumpHandler());
LOGGER.info("Initialized");
}
public void onClose() {
LOGGER.info("Closing...");
-
+ AuthHandler.deauth();
LOGGER.info("Closed.");
}
}
diff --git a/src/main/java/io/github/techstreet/dfscript/commands/CommandManager.java b/src/main/java/io/github/techstreet/dfscript/commands/CommandManager.java
index 28e4b36..89697bf 100644
--- a/src/main/java/io/github/techstreet/dfscript/commands/CommandManager.java
+++ b/src/main/java/io/github/techstreet/dfscript/commands/CommandManager.java
@@ -1,7 +1,7 @@
package io.github.techstreet.dfscript.commands;
import com.mojang.brigadier.CommandDispatcher;
-import io.github.techstreet.dfscript.commands.misc.ScriptsCommand;
+import io.github.techstreet.dfscript.commands.misc.DFScriptCommand;
import io.github.techstreet.dfscript.loader.Loadable;
import java.util.ArrayList;
import java.util.List;
@@ -23,7 +23,7 @@ public CommandManager getInstance() {
@Override
public void load() {
- commands.add(new ScriptsCommand());
+ commands.add(new DFScriptCommand());
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> attachTo(dispatcher));
}
diff --git a/src/main/java/io/github/techstreet/dfscript/commands/misc/ScriptsCommand.java b/src/main/java/io/github/techstreet/dfscript/commands/misc/DFScriptCommand.java
similarity index 87%
rename from src/main/java/io/github/techstreet/dfscript/commands/misc/ScriptsCommand.java
rename to src/main/java/io/github/techstreet/dfscript/commands/misc/DFScriptCommand.java
index 2255ea4..4f5f663 100644
--- a/src/main/java/io/github/techstreet/dfscript/commands/misc/ScriptsCommand.java
+++ b/src/main/java/io/github/techstreet/dfscript/commands/misc/DFScriptCommand.java
@@ -7,10 +7,10 @@
import io.github.techstreet.dfscript.commands.Command;
import io.github.techstreet.dfscript.commands.arguments.StringFuncArgumentType;
import io.github.techstreet.dfscript.event.system.EventManager;
-import io.github.techstreet.dfscript.screen.script.ScriptListScreen;
+import io.github.techstreet.dfscript.features.AuthHandler;
+import io.github.techstreet.dfscript.screen.dfscript.DFScriptScreen;
import io.github.techstreet.dfscript.script.Script;
import io.github.techstreet.dfscript.script.ScriptManager;
-import io.github.techstreet.dfscript.script.values.ScriptValue;
import io.github.techstreet.dfscript.script.values.ScriptVariable;
import io.github.techstreet.dfscript.util.chat.ChatUtil;
import java.util.List;
@@ -19,22 +19,22 @@
import static io.github.techstreet.dfscript.commands.arguments.StringFuncArgumentFunctions.SCRIPTS;
-public class ScriptsCommand implements Command {
+public class DFScriptCommand implements Command {
@Override
public void register(CommandDispatcher cd) {
cd.register(
- literal("scripts")
+ literal("dfscript")
.executes(ctx -> {
- DFScript.MC.send(() -> DFScript.MC.setScreen(new ScriptListScreen(true)));
+ DFScript.MC.send(() -> DFScript.MC.setScreen(new DFScriptScreen()));
return 0;
})
.then(literal("reload")
- .executes(ctx -> {
- ScriptManager.getInstance().reload();
- ChatUtil.info("Scripts reloaded!");
- return 0;
- })
+ .executes(ctx -> {
+ AuthHandler.updateScripts();
+ ChatUtil.info("Scripts updated and reloaded!");
+ return 0;
+ })
)
.then(literal("vars")
.then(argument("script", new StringFuncArgumentType(SCRIPTS, false)
@@ -92,7 +92,7 @@ private void listVars(String script, String filter) {
@Override
public String getDescription() {
return """
- [blue]/scripts[reset]
+ [blue]/dfscript[reset]
Opens a GUI to edit custom DFScript scripts.
""";
@@ -100,6 +100,6 @@ public String getDescription() {
@Override
public String getName() {
- return "/scripts";
+ return "/dfscript";
}
}
diff --git a/src/main/java/io/github/techstreet/dfscript/event/HudRenderEvent.java b/src/main/java/io/github/techstreet/dfscript/event/HudRenderEvent.java
index 90a51de..3979c38 100644
--- a/src/main/java/io/github/techstreet/dfscript/event/HudRenderEvent.java
+++ b/src/main/java/io/github/techstreet/dfscript/event/HudRenderEvent.java
@@ -2,7 +2,6 @@
import io.github.techstreet.dfscript.event.system.Event;
import net.minecraft.client.gui.DrawContext;
-import net.minecraft.client.util.math.MatrixStack;
public record HudRenderEvent(DrawContext context) implements Event {
diff --git a/src/main/java/io/github/techstreet/dfscript/event/ServerJoinEvent.java b/src/main/java/io/github/techstreet/dfscript/event/ServerJoinEvent.java
index b1ae3a6..1a79d62 100644
--- a/src/main/java/io/github/techstreet/dfscript/event/ServerJoinEvent.java
+++ b/src/main/java/io/github/techstreet/dfscript/event/ServerJoinEvent.java
@@ -1,9 +1,10 @@
package io.github.techstreet.dfscript.event;
import io.github.techstreet.dfscript.event.system.Event;
-import java.net.InetSocketAddress;
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
+import java.net.InetSocketAddress;
+
public class ServerJoinEvent implements Event {
private final GameJoinS2CPacket packet;
private final InetSocketAddress address;
diff --git a/src/main/java/io/github/techstreet/dfscript/features/AuthHandler.java b/src/main/java/io/github/techstreet/dfscript/features/AuthHandler.java
index e7cb980..5e6b70b 100644
--- a/src/main/java/io/github/techstreet/dfscript/features/AuthHandler.java
+++ b/src/main/java/io/github/techstreet/dfscript/features/AuthHandler.java
@@ -7,33 +7,119 @@
import com.mojang.authlib.exceptions.AuthenticationException;
import io.github.techstreet.dfscript.DFScript;
import io.github.techstreet.dfscript.loader.Loadable;
+import io.github.techstreet.dfscript.script.ScriptManager;
import io.github.techstreet.dfscript.script.util.AuthcodeResponse;
import io.github.techstreet.dfscript.script.util.ServercodeResponse;
import net.minecraft.client.session.Session;
import org.apache.commons.codec.digest.DigestUtils;
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
+import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.util.ArrayList;
import java.util.Objects;
import java.util.UUID;
-import static io.github.techstreet.dfscript.screen.script.ScriptAddScreen.readAll;
-
public class AuthHandler implements Loadable {
private static String authCode = null;
- private static boolean staff = false;
@Override
public void load() {
regen();
}
+ public static void updateScripts() {
+ try {
+ URL url = new URL("https://api.techstreet.tech/dfscript/scripts/");
+ HttpURLConnection con = (HttpURLConnection) url.openConnection();
+ con.setRequestMethod("POST");
+ con.setRequestProperty("authorization", AuthHandler.getAuthCode());
+ con.setDoOutput(true);
+
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) {
+ StringBuilder response = new StringBuilder();
+ String responseLine;
+
+ while ((responseLine = br.readLine()) != null) {
+ response.append(responseLine.trim());
+ }
+
+ ArrayList expected = new ArrayList<>();
+ JsonObject scripts = JsonParser.parseString(response.toString()).getAsJsonObject();
+ scripts.getAsJsonArray("scripts").forEach(script -> expected.add(script.getAsJsonObject().get("id").getAsLong() + ".json"));
+
+ File file = new File("DFScript/Scripts");
+ for (File f : Objects.requireNonNull(file.listFiles())) {
+ if (!expected.contains(f.getName())) {
+ f.delete();
+ }
+ }
+
+ scripts.getAsJsonArray("scripts").forEach(script -> {
+ try {
+ File f = new File("DFScript/Scripts/" + script.getAsJsonObject().get("id").getAsLong() + ".json");
+ if (!f.exists()) {
+ f.createNewFile();
+
+ JsonObject obj = script.getAsJsonObject();
+ obj.addProperty("disabled", false);
+ obj.add("config", new JsonArray());
+
+ Files.write(f.toPath(), DFScript.GSON.toJson(obj).getBytes(StandardCharsets.UTF_8));
+ } else {
+ JsonObject obj = JsonParser.parseString(new String(Files.readAllBytes(f.toPath()), StandardCharsets.UTF_8)).getAsJsonObject();
+ obj.add("headers", script.getAsJsonObject().get("headers").getAsJsonArray());
+
+ Files.write(f.toPath(), DFScript.GSON.toJson(obj).getBytes(StandardCharsets.UTF_8));
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ });
+
+ ScriptManager.getInstance().reload();
+ }
+ } catch (Exception e) {
+ regen();
+ e.printStackTrace();
+ }
+ }
+
+ public static void checkAuth() {
+ try {
+ URL url = new URL("https://api.techstreet.tech/dfscript/auth/refresh/");
+ HttpURLConnection con = (HttpURLConnection) url.openConnection();
+ con.setRequestMethod("GET");
+ con.setRequestProperty("authorization", AuthHandler.getAuthCode());
+ con.setDoOutput(true);
+
+ con.getInputStream();
+ if (con.getResponseCode() != 200) {
+ regen();
+ }
+ } catch (Exception e) {
+ regen();
+ e.printStackTrace();
+ }
+ }
+
+ public static void deauth() {
+ try {
+ URL url = new URL("https://api.techstreet.tech/dfscript/auth/deauth/");
+ HttpURLConnection con = (HttpURLConnection) url.openConnection();
+ con.setRequestMethod("GET");
+ con.setRequestProperty("authorization", AuthHandler.getAuthCode());
+ con.setDoOutput(true);
+
+ con.getInputStream();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
public static void regen() {
URL url;
HttpURLConnection con;
@@ -42,7 +128,7 @@ public static void regen() {
try {
// Authorization step one - Create a random clientcode
- url = new URL("https://DFScript-Server.techstreetdev.repl.co/auth/secret/");
+ url = new URL("https://api.techstreet.tech/dfscript/auth/clientcode/");
con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
@@ -85,7 +171,7 @@ public static void regen() {
}
// Authorization step two - Generate the authcode
- url = new URL("https://DFScript-Server.techstreetdev.repl.co/auth/auth/");
+ url = new URL("https://api.techstreet.tech/dfscript/auth/");
con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
@@ -115,41 +201,25 @@ public static void regen() {
authCode = authcodeResponse.getAuthcode();
DFScript.LOGGER.info("Server authorization code successfully generated!");
}
+
+ updateScripts();
} catch (Exception e) {
// e.printStackTrace();
}
+ }
- try {
- URLConnection con2 = new URL("https://dfscript-server.techstreetdev.repl.co/staff/").openConnection();
- con2.setReadTimeout(5000);
- con2.setConnectTimeout(5000);
- InputStream is = con2.getInputStream();
- BufferedReader rd = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
- obj = JsonParser.parseString(readAll(rd)).getAsJsonObject();
-
- JsonArray array = obj.get("staff").getAsJsonArray();
- boolean localStaff = false;
-
- for (JsonElement staffMember : array) {
- if (Objects.equals(staffMember.getAsString(), DFScript.PLAYER_UUID)) {
- staff = true;
- localStaff = true;
- }
- }
+ public static String readAll(Reader rd) throws IOException {
+ StringBuilder sb = new StringBuilder();
+ int cp;
- if (!localStaff) {
- staff = false;
- }
- } catch (Exception e) {
-// e.printStackTrace();
+ while ((cp = rd.read()) != -1) {
+ sb.append((char) cp);
}
+
+ return sb.toString();
}
public static String getAuthCode() {
return authCode;
}
-
- public static boolean getStaffMember() {
- return staff;
- }
}
diff --git a/src/main/java/io/github/techstreet/dfscript/mixin/game/MClientCommonNetworkHandler.java b/src/main/java/io/github/techstreet/dfscript/mixin/game/MClientCommonNetworkHandler.java
index 1be8341..e725843 100644
--- a/src/main/java/io/github/techstreet/dfscript/mixin/game/MClientCommonNetworkHandler.java
+++ b/src/main/java/io/github/techstreet/dfscript/mixin/game/MClientCommonNetworkHandler.java
@@ -1,19 +1,9 @@
package io.github.techstreet.dfscript.mixin.game;
-import com.mojang.blaze3d.systems.RenderSystem;
-import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.event.*;
+import io.github.techstreet.dfscript.event.ServerLeaveEvent;
import io.github.techstreet.dfscript.event.system.EventManager;
-import io.github.techstreet.dfscript.util.hypercube.HypercubeRank;
-import io.github.techstreet.dfscript.util.hypercube.HypercubeUtil;
import net.minecraft.client.network.ClientCommonNetworkHandler;
-import net.minecraft.client.network.ClientPlayNetworkHandler;
-import net.minecraft.network.ClientConnection;
-import net.minecraft.network.listener.ClientCommonPacketListener;
import net.minecraft.network.packet.s2c.common.DisconnectS2CPacket;
-import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
-import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket;
-import net.minecraft.network.packet.s2c.play.TeamS2CPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
diff --git a/src/main/java/io/github/techstreet/dfscript/mixin/game/MClientPlayNetworkHandler.java b/src/main/java/io/github/techstreet/dfscript/mixin/game/MClientPlayNetworkHandler.java
index 1f8a4dc..fa70ab6 100644
--- a/src/main/java/io/github/techstreet/dfscript/mixin/game/MClientPlayNetworkHandler.java
+++ b/src/main/java/io/github/techstreet/dfscript/mixin/game/MClientPlayNetworkHandler.java
@@ -6,17 +6,15 @@
import io.github.techstreet.dfscript.event.system.EventManager;
import io.github.techstreet.dfscript.util.hypercube.HypercubeRank;
import io.github.techstreet.dfscript.util.hypercube.HypercubeUtil;
-import java.net.InetSocketAddress;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.ClientConnection;
-import net.minecraft.network.packet.s2c.play.*;
-import net.minecraft.network.packet.s2c.common.*;
-import net.minecraft.text.Text;
+import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
+import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket;
+import net.minecraft.network.packet.s2c.play.TeamS2CPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ClientPlayNetworkHandler.class)
public class MClientPlayNetworkHandler {
diff --git a/src/main/java/io/github/techstreet/dfscript/mixin/player/MLocalPlayer.java b/src/main/java/io/github/techstreet/dfscript/mixin/player/MLocalPlayer.java
index e9bb2f9..2237af3 100644
--- a/src/main/java/io/github/techstreet/dfscript/mixin/player/MLocalPlayer.java
+++ b/src/main/java/io/github/techstreet/dfscript/mixin/player/MLocalPlayer.java
@@ -1,15 +1,12 @@
package io.github.techstreet.dfscript.mixin.player;
-import io.github.techstreet.dfscript.event.SendChatEvent;
import io.github.techstreet.dfscript.event.TickEvent;
import io.github.techstreet.dfscript.event.system.EventManager;
import net.minecraft.client.network.ClientPlayerEntity;
-import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ClientPlayerEntity.class)
public class MLocalPlayer {
diff --git a/src/main/java/io/github/techstreet/dfscript/mixin/render/MInGameHUD.java b/src/main/java/io/github/techstreet/dfscript/mixin/render/MInGameHUD.java
index 2dbf237..afd0574 100644
--- a/src/main/java/io/github/techstreet/dfscript/mixin/render/MInGameHUD.java
+++ b/src/main/java/io/github/techstreet/dfscript/mixin/render/MInGameHUD.java
@@ -1,13 +1,10 @@
package io.github.techstreet.dfscript.mixin.render;
-import io.github.techstreet.dfscript.DFScript;
import io.github.techstreet.dfscript.event.HudRenderEvent;
import io.github.techstreet.dfscript.event.system.EventManager;
import io.github.techstreet.dfscript.screen.overlay.OverlayManager;
-import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.InGameHud;
-import net.minecraft.client.util.math.MatrixStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
diff --git a/src/main/java/io/github/techstreet/dfscript/mixin/render/MMultiplayerScreen.java b/src/main/java/io/github/techstreet/dfscript/mixin/render/MMultiplayerScreen.java
index 206ab99..6fc1c9b 100644
--- a/src/main/java/io/github/techstreet/dfscript/mixin/render/MMultiplayerScreen.java
+++ b/src/main/java/io/github/techstreet/dfscript/mixin/render/MMultiplayerScreen.java
@@ -1,11 +1,11 @@
package io.github.techstreet.dfscript.mixin.render;
import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.screen.script.ScriptListScreen;
+import io.github.techstreet.dfscript.screen.dfscript.DFScriptScreen;
+import io.github.techstreet.dfscript.screen.dfscript.ScriptListScreen;
import io.github.techstreet.dfscript.util.render.BlendableTexturedButtonWidget;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
-import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
@@ -28,7 +28,7 @@ protected MMultiplayerScreen(Text title) {
@Inject(at = @At("HEAD"), method = "init", cancellable = true)
private void init(CallbackInfo ci) {
this.addDrawableChild(new BlendableTexturedButtonWidget(5, 5, 20, 20, identifier_main, identifier_main_highlight, (button) -> {
- ScriptListScreen screen = new ScriptListScreen(false);
+ DFScriptScreen screen = new DFScriptScreen();
DFScript.MC.setScreen(screen);
}));
}
diff --git a/src/main/java/io/github/techstreet/dfscript/mixin/render/MOptionsScreen.java b/src/main/java/io/github/techstreet/dfscript/mixin/render/MOptionsScreen.java
index 568fa36..8b29fbf 100644
--- a/src/main/java/io/github/techstreet/dfscript/mixin/render/MOptionsScreen.java
+++ b/src/main/java/io/github/techstreet/dfscript/mixin/render/MOptionsScreen.java
@@ -1,7 +1,8 @@
package io.github.techstreet.dfscript.mixin.render;
import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.screen.script.ScriptListScreen;
+import io.github.techstreet.dfscript.screen.dfscript.DFScriptScreen;
+import io.github.techstreet.dfscript.screen.dfscript.ScriptListScreen;
import io.github.techstreet.dfscript.util.render.BlendableTexturedButtonWidget;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.option.OptionsScreen;
@@ -33,7 +34,7 @@ public MOptionsScreen(Text literalText) {
@Inject(method = "init()V", at = @At("RETURN"))
protected void init(CallbackInfo callbackInfo) {
this.addDrawableChild(new BlendableTexturedButtonWidget(5, 5, 20, 20, identifier_main, identifier_main_highlight, (button) -> {
- ScriptListScreen screen = new ScriptListScreen(DFScript.MC.player != null);
+ DFScriptScreen screen = new DFScriptScreen();
DFScript.MC.setScreen(screen);
}));
}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/CReloadableScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/CReloadableScreen.java
index 0eaf901..153a844 100644
--- a/src/main/java/io/github/techstreet/dfscript/screen/CReloadableScreen.java
+++ b/src/main/java/io/github/techstreet/dfscript/screen/CReloadableScreen.java
@@ -1,17 +1,5 @@
package io.github.techstreet.dfscript.screen;
-import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.screen.widget.CWidget;
-import io.github.techstreet.dfscript.util.RenderUtil;
-import net.minecraft.client.MinecraftClient;
-import net.minecraft.client.gui.screen.Screen;
-import net.minecraft.client.util.math.MatrixStack;
-import net.minecraft.text.Text;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.ArrayList;
-import java.util.List;
-
public abstract class CReloadableScreen extends CScreen {
public abstract void reload();
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/CScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/CScreen.java
index bb5c533..848aba5 100644
--- a/src/main/java/io/github/techstreet/dfscript/screen/CScreen.java
+++ b/src/main/java/io/github/techstreet/dfscript/screen/CScreen.java
@@ -3,8 +3,6 @@
import io.github.techstreet.dfscript.DFScript;
import io.github.techstreet.dfscript.screen.widget.CWidget;
import io.github.techstreet.dfscript.util.RenderUtil;
-import java.util.ArrayList;
-import java.util.List;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
@@ -13,6 +11,9 @@
import net.minecraft.text.Text;
import org.jetbrains.annotations.NotNull;
+import java.util.ArrayList;
+import java.util.List;
+
public class CScreen extends Screen {
private final int width, height;
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/ContextMenuButton.java b/src/main/java/io/github/techstreet/dfscript/screen/ContextMenuButton.java
index 11b8c9a..470eedc 100644
--- a/src/main/java/io/github/techstreet/dfscript/screen/ContextMenuButton.java
+++ b/src/main/java/io/github/techstreet/dfscript/screen/ContextMenuButton.java
@@ -1,7 +1,6 @@
package io.github.techstreet.dfscript.screen;
import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.screen.script.ScriptEditScreen;
public class ContextMenuButton {
String name;
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/dfscript/Contributor.java b/src/main/java/io/github/techstreet/dfscript/screen/dfscript/Contributor.java
new file mode 100644
index 0000000..e30c47f
--- /dev/null
+++ b/src/main/java/io/github/techstreet/dfscript/screen/dfscript/Contributor.java
@@ -0,0 +1,42 @@
+package io.github.techstreet.dfscript.screen.dfscript;
+
+import net.minecraft.util.Identifier;
+
+public class Contributor {
+ private final String name;
+ private final int id;
+ private final int contributions;
+ private final String avatarUrl;
+ private Identifier avatar;
+
+ public Contributor(String name, int id, int contributions, String avatarUrl) {
+ this.name = name;
+ this.id = id;
+ this.contributions = contributions;
+ this.avatarUrl = avatarUrl;
+ }
+
+ public Identifier getAvatar() {
+ return avatar;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public int getContributions() {
+ return contributions;
+ }
+
+ public String getAvatarUrl() {
+ return avatarUrl;
+ }
+
+ public void setAvatar(Identifier avatar) {
+ this.avatar = avatar;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/dfscript/ContributorsScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/dfscript/ContributorsScreen.java
new file mode 100644
index 0000000..f215ce7
--- /dev/null
+++ b/src/main/java/io/github/techstreet/dfscript/screen/dfscript/ContributorsScreen.java
@@ -0,0 +1,104 @@
+package io.github.techstreet.dfscript.screen.dfscript;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import io.github.techstreet.dfscript.DFScript;
+import io.github.techstreet.dfscript.features.AuthHandler;
+import io.github.techstreet.dfscript.screen.CScreen;
+import io.github.techstreet.dfscript.screen.widget.CImage;
+import io.github.techstreet.dfscript.screen.widget.CPlainPanel;
+import io.github.techstreet.dfscript.screen.widget.CScrollPanel;
+import io.github.techstreet.dfscript.screen.widget.CText;
+import net.minecraft.client.texture.NativeImage;
+import net.minecraft.client.texture.NativeImageBackedTexture;
+import net.minecraft.text.Text;
+import net.minecraft.util.Identifier;
+import org.apache.logging.log4j.Level;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ContributorsScreen extends CScreen {
+ private final List contributors = new ArrayList<>();
+
+ public ContributorsScreen() {
+ super(165, 110);
+ CPlainPanel root = new CPlainPanel(0, 0, 165, 110);
+
+
+ root.add(new CText(5, 3, Text.literal("Contributors"), 0x333333, 1.25f, false, false));
+
+ CPlainPanel panel = new CPlainPanel(0, 10, 165, 95);
+
+ CScrollPanel scrollPanel = new CScrollPanel(0, 0, 165, 95);
+
+
+
+ int y = 0;
+ int x = 5;
+
+ try {
+ URL url = new URL("https://api.github.com/repos/DFScripting/DFScript/contributors");
+ HttpURLConnection con = (HttpURLConnection) url.openConnection();
+ con.setRequestMethod("GET");
+ con.setDoOutput(true);
+
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8))) {
+ for (JsonElement element : JsonParser.parseReader(br).getAsJsonArray()) {
+ JsonObject object = element.getAsJsonObject();
+ this.contributors.add(new Contributor(object.get("login").getAsString(), object.get("id").getAsInt(), object.get("contributions").getAsInt(), object.get("avatar_url").getAsString()));
+ }
+
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ for (Contributor contributor : contributors) {
+
+ if (contributor.getAvatar() == null) {
+ try {
+ URL url = new URL(contributor.getAvatarUrl());
+ Identifier identifier = DFScript.MC.getTextureManager().registerDynamicTexture("contributor_" + contributor.getName().toLowerCase(), new NativeImageBackedTexture(NativeImage.read(url.openStream())));
+ contributor.setAvatar(identifier);
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ CImage image = new CImage(x, y, 16, 16, contributor.getAvatar().toString());
+
+ scrollPanel.add(image);
+ scrollPanel.add(new CText(x + 20, y + 6, Text.of(contributor.getName())));
+
+ DFScript.LOGGER.log(Level.WARN, contributor.getName() + ": (" + x + ", " + y + ")");
+
+ if (x == 75) {
+ x = 5;
+ y += 20;
+ } else {
+ x = 75;
+ }
+ }
+
+ panel.add(scrollPanel);
+
+ root.add(panel);
+
+ widgets.add(root);
+
+ }
+
+ @Override
+ public void close() {
+ DFScript.MC.setScreen(new DFScriptScreen());
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/dfscript/DFScriptScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/dfscript/DFScriptScreen.java
new file mode 100644
index 0000000..2571029
--- /dev/null
+++ b/src/main/java/io/github/techstreet/dfscript/screen/dfscript/DFScriptScreen.java
@@ -0,0 +1,53 @@
+package io.github.techstreet.dfscript.screen.dfscript;
+
+import io.github.techstreet.dfscript.DFScript;
+import io.github.techstreet.dfscript.screen.CScreen;
+import io.github.techstreet.dfscript.screen.widget.CButton;
+import io.github.techstreet.dfscript.screen.widget.CImage;
+import io.github.techstreet.dfscript.screen.widget.CPlainPanel;
+import io.github.techstreet.dfscript.screen.widget.CText;
+import net.minecraft.text.Text;
+import net.minecraft.util.Util;
+
+public class DFScriptScreen extends CScreen {
+ private static final String DFSCRIPT_LOGO = "dfscript:icon_transparent.png";
+
+ public DFScriptScreen() {
+ super(110, 100);
+ CPlainPanel root = new CPlainPanel(0, 0, 110, 110);
+
+ CImage cImage = new CImage(23, 0, 64, 64, DFSCRIPT_LOGO);
+ root.add(cImage);
+ root.add(new CText(55, 63, Text.literal("DFScript"), 0x333333, 1.5f, true, false));
+ root.add(new CText(55, 68, Text.literal("v" + DFScript.MOD_VERSION), 0x333333, 1f, true, false));
+
+ addButtons(root);
+ widgets.add(root);
+ }
+
+ private void addButtons(CPlainPanel panel) {
+ // ------------------------ Features Button ------------------------
+ CButton featuresButton = new CButton(5, 75, 50, 10, 0.8f, "Installed Scripts", () -> {
+ DFScript.MC.send(() -> DFScript.MC.setScreen(new ScriptListScreen(true)));
+ });
+ panel.add(featuresButton);
+
+ // ------------------------ Contributors Button ------------------------
+ CButton contributorsButton = new CButton(5, 85, 50, 10, 0.8f, "Contributors", () -> {
+ DFScript.MC.send(() -> DFScript.MC.setScreen(new ContributorsScreen()));
+ });
+ panel.add(contributorsButton);
+
+ // ------------------------ Bug Report Button ------------------------
+ CButton bugReport = new CButton(55, 75, 50, 10, 0.8f, "Bug Report", () -> {
+ Util.getOperatingSystem().open("https://github.com/DFScripting/DFScript/issues");
+ });
+ panel.add(bugReport);
+
+ // ------------------------ Dashboard Button ------------------------
+ CButton options = new CButton(55, 85, 50, 10, 0.8f, "Dashboard", () -> {
+ Util.getOperatingSystem().open("https://dfscript.techstreet.tech/");
+ });
+ panel.add(options);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/dfscript/ScriptListScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/dfscript/ScriptListScreen.java
new file mode 100644
index 0000000..05b2802
--- /dev/null
+++ b/src/main/java/io/github/techstreet/dfscript/screen/dfscript/ScriptListScreen.java
@@ -0,0 +1,103 @@
+package io.github.techstreet.dfscript.screen.dfscript;
+
+import io.github.techstreet.dfscript.DFScript;
+import io.github.techstreet.dfscript.features.AuthHandler;
+import io.github.techstreet.dfscript.screen.CScreen;
+import io.github.techstreet.dfscript.screen.widget.*;
+import io.github.techstreet.dfscript.script.Script;
+import io.github.techstreet.dfscript.script.ScriptManager;
+import io.github.techstreet.dfscript.util.chat.ChatUtil;
+import net.minecraft.client.gui.DrawContext;
+import net.minecraft.text.MutableText;
+import net.minecraft.text.Text;
+import net.minecraft.util.Formatting;
+import net.minecraft.util.Util;
+
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.List;
+
+public class ScriptListScreen extends CScreen {
+ private final List contextMenu = new ArrayList<>();
+
+
+ public ScriptListScreen(boolean allowEditAndUpload) {
+ super(160, 100);
+ CScrollPanel panel = new CScrollPanel(0, 5, 160, 94);
+ widgets.add(panel);
+
+ int y = 0;
+ for (Script s : ScriptManager.getInstance().getScripts()) {
+ MutableText text = Text.literal(s.getName());
+
+ if (s.disabled()) {
+ text = text.formatted(Formatting.STRIKETHROUGH);
+ }
+
+ panel.add(new CText(6, y + 2, text));
+
+ panel.add(new CButton(4, y-1, 153, 10, "",() -> {}) {
+ @Override
+ public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) {
+ Rectangle b = getBounds();
+ context.fill(b.x, b.y, b.x + b.width, b.y + b.height, 0x33000000);
+ }
+
+ @Override
+ public boolean mouseClicked(double x, double y, int button) {
+ return false;
+ }
+ });
+
+ int addedY = 0;
+ int addedX = 118;
+
+ // Enable or Disable Button
+ CButton enableDisable;
+ if (s.disabled()) {
+ enableDisable = new CTexturedButton(30 + addedX, y + addedY, 8, 8, DFScript.MOD_ID + ":enable.png", DFScript.MOD_ID + ":enable_highlight.png", () -> {
+ s.setDisabled(false);
+ ScriptManager.getInstance().saveScript(s);
+ DFScript.MC.setScreen(new ScriptListScreen(allowEditAndUpload));
+ });
+ } else {
+ enableDisable = new CTexturedButton(30 + addedX, y + addedY, 8, 8, DFScript.MOD_ID + ":disable.png", DFScript.MOD_ID + ":disable_highlight.png", () -> {
+ s.setDisabled(true);
+ ScriptManager.getInstance().saveScript(s);
+ DFScript.MC.setScreen(new ScriptListScreen(allowEditAndUpload));
+ });
+ }
+
+ panel.add(enableDisable);
+ y += 12;
+ }
+
+ CButton refresh = new CButton(60, y + 1, 40, 8, "Refresh", () -> {
+ AuthHandler.checkAuth();
+ AuthHandler.updateScripts();
+ ChatUtil.info("Scripts updated and reloaded!");
+ DFScript.MC.setScreen(new ScriptListScreen(allowEditAndUpload));
+ });
+
+ panel.add(refresh);
+ }
+
+ @Override
+ public void close() {
+ DFScript.MC.setScreen(new DFScriptScreen());
+ }
+
+ @Override
+ public boolean mouseClicked(double mouseX, double mouseY, int button) {
+ boolean b = super.mouseClicked(mouseX, mouseY, button);
+ clearContextMenu();
+ return b;
+ }
+
+ private void clearContextMenu() {
+ for (CWidget w : contextMenu) {
+ widgets.remove(w);
+ }
+ contextMenu.clear();
+ }
+}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/overlay/OverlayManager.java b/src/main/java/io/github/techstreet/dfscript/screen/overlay/OverlayManager.java
index e498f50..ed740b5 100644
--- a/src/main/java/io/github/techstreet/dfscript/screen/overlay/OverlayManager.java
+++ b/src/main/java/io/github/techstreet/dfscript/screen/overlay/OverlayManager.java
@@ -3,7 +3,6 @@
import io.github.techstreet.dfscript.DFScript;
import io.github.techstreet.dfscript.loader.Loadable;
import net.minecraft.client.gui.DrawContext;
-import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import java.util.ArrayList;
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddArgumentScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddArgumentScreen.java
deleted file mode 100644
index b85bfce..0000000
--- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddArgumentScreen.java
+++ /dev/null
@@ -1,143 +0,0 @@
-package io.github.techstreet.dfscript.screen.script;
-
-import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.screen.CScreen;
-import io.github.techstreet.dfscript.screen.widget.CItem;
-import io.github.techstreet.dfscript.screen.widget.CTextField;
-import io.github.techstreet.dfscript.script.Script;
-import io.github.techstreet.dfscript.script.ScriptParametrizedPart;
-import io.github.techstreet.dfscript.script.argument.*;
-import io.github.techstreet.dfscript.script.event.ScriptFunction;
-import io.github.techstreet.dfscript.script.event.ScriptHeader;
-import net.minecraft.item.ItemStack;
-import net.minecraft.item.Items;
-import net.minecraft.text.Style;
-import net.minecraft.text.Text;
-
-public class ScriptAddArgumentScreen extends CScreen {
-
- private final Script script;
-
- private final ScriptHeader header;
- private final ScriptParametrizedPart action;
-
- public ScriptAddArgumentScreen(Script script, ScriptParametrizedPart action, int index, ScriptHeader header) {
- this(script,action,index, header,null);
- }
- public ScriptAddArgumentScreen(Script script, ScriptParametrizedPart action, int index, ScriptHeader header, String overwrite) {
- super(100, 50);
- this.script = script;
- this.action = action;
- this.header = header;
-
- CTextField input = new CTextField("Input", 2, 2, 96, 35, true);
- if(overwrite != null) input.setText(overwrite);
-
- ItemStack textIcon = new ItemStack(Items.BOOK);
- textIcon.setCustomName(Text.literal("Text")
- .fillStyle(Style.EMPTY.withItalic(false)));
-
- ItemStack numberIcon = new ItemStack(Items.SLIME_BALL);
- numberIcon.setCustomName(Text.literal("Number")
- .fillStyle(Style.EMPTY.withItalic(false)));
-
- ItemStack variableIcon = new ItemStack(Items.MAGMA_CREAM);
- variableIcon.setCustomName(Text.literal("Variable")
- .fillStyle(Style.EMPTY.withItalic(false)));
-
- ItemStack clientValueIcon = new ItemStack(Items.NAME_TAG);
- clientValueIcon.setCustomName(Text.literal("Client Value")
- .fillStyle(Style.EMPTY.withItalic(false)));
-
- ItemStack configValueIcon = new ItemStack(Items.INK_SAC);
- configValueIcon.setCustomName(Text.literal("Config Value")
- .fillStyle(Style.EMPTY.withItalic(false)));
-
- ItemStack functionArgumentIcon = new ItemStack(Items.BLUE_DYE);
- functionArgumentIcon.setCustomName(Text.literal("Function Argument")
- .fillStyle(Style.EMPTY.withItalic(false)));
-
- ItemStack trueIcon = new ItemStack(Items.LIME_DYE);
- trueIcon.setCustomName(Text.literal("True")
- .fillStyle(Style.EMPTY.withItalic(false)));
-
- ItemStack falseIcon = new ItemStack(Items.RED_DYE);
- falseIcon.setCustomName(Text.literal("False")
- .fillStyle(Style.EMPTY.withItalic(false)));
-
- CItem addNumber = new CItem(2, 40, numberIcon);
- CItem addText = new CItem(12, 40, textIcon);
- CItem addTrue = new CItem(22, 40, trueIcon);
- CItem addFalse = new CItem(32, 40, falseIcon);
- CItem addVariable = new CItem(42, 40, variableIcon);
- CItem addClientValue = new CItem(52, 40, clientValueIcon);
- CItem addConfigValue = new CItem(62, 40, configValueIcon);
- CItem addFunctionArgument = new CItem(72, 40, functionArgumentIcon);
-
- input.setChangedListener(() -> input.textColor = 0xFFFFFF);
-
- addText.setClickListener((btn) -> {
- if(overwrite != null) action.getArguments().remove(index);
- action.getArguments().add(index, new ScriptTextArgument(input.getText()));
- close();
- });
-
- addNumber.setClickListener((btn) -> {
- try {
- double number = Double.parseDouble(input.getText());
- if(overwrite != null) action.getArguments().remove(index);
- action.getArguments().add(index, new ScriptNumberArgument(number));
- close();
- } catch (Exception err) {
- input.textColor = 0xFF3333;
- }
- });
-
- addVariable.setClickListener((btn) -> {
- if(overwrite != null) action.getArguments().remove(index);
- action.getArguments().add(index, new ScriptVariableArgument(input.getText(), ScriptVariableScope.SCRIPT));
- close();
- });
-
- addClientValue.setClickListener((btn) -> {
- DFScript.MC.setScreen(new ScriptAddClientValueScreen(action, script, index, header, overwrite));
- });
-
- addConfigValue.setClickListener((btn) -> {
- DFScript.MC.setScreen(new ScriptAddConfigValueScreen(action, script, index, header, overwrite));
- });
-
- addFunctionArgument.setClickListener((btn) -> {
- DFScript.MC.setScreen(new ScriptAddFunctionArgValueScreen(action, script, index, header, overwrite));
- });
-
- addTrue.setClickListener((btn) -> {
- if(overwrite != null) action.getArguments().remove(index);
- action.getArguments().add(index, new ScriptBoolArgument(true));
- close();
- });
-
- addFalse.setClickListener((btn) -> {
- if(overwrite != null) action.getArguments().remove(index);
- action.getArguments().add(index, new ScriptBoolArgument(false));
- close();
- });
-
- widgets.add(input);
- widgets.add(addNumber);
- widgets.add(addText);
- widgets.add(addTrue);
- widgets.add(addFalse);
- widgets.add(addVariable);
- widgets.add(addClientValue);
- widgets.add(addConfigValue);
- if(header instanceof ScriptFunction) {
- widgets.add(addFunctionArgument);
- }
- }
-
- @Override
- public void close() {
- DFScript.MC.setScreen(new ScriptEditPartScreen(action, script, header));
- }
-}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddClientValueScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddClientValueScreen.java
deleted file mode 100644
index 38ca1c9..0000000
--- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddClientValueScreen.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package io.github.techstreet.dfscript.screen.script;
-
-import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.screen.CScreen;
-import io.github.techstreet.dfscript.screen.widget.CItem;
-import io.github.techstreet.dfscript.script.Script;
-import io.github.techstreet.dfscript.script.ScriptParametrizedPart;
-import io.github.techstreet.dfscript.script.ScriptPart;
-import io.github.techstreet.dfscript.script.action.ScriptAction;
-import io.github.techstreet.dfscript.script.argument.ScriptClientValueArgument;
-import io.github.techstreet.dfscript.script.event.ScriptHeader;
-
-public class ScriptAddClientValueScreen extends CScreen {
-
- private final Script script;
-
- private final ScriptHeader header;
- private final ScriptParametrizedPart action;
- private final int insertIndex;
- private static final int WIDTH = 58;
-
- public ScriptAddClientValueScreen(ScriptParametrizedPart action, Script script, int insertIndex, ScriptHeader header, String overwrite) {
- super(WIDTH, 58);
- this.script = script;
- this.action = action;
- this.header = header;
- this.insertIndex = insertIndex;
-
- int x = 5;
- int y = 5;
- for (ScriptClientValueArgument arg : ScriptClientValueArgument.values()) {
- CItem item = new CItem(x, y, arg.getIcon());
- item.setClickListener((btn) -> {
- if(overwrite != null) action.getArguments().remove(insertIndex);
- action.getArguments().add(insertIndex, arg);
- DFScript.MC.setScreen(new ScriptEditPartScreen(action, script, header));
- });
- widgets.add(item);
- x += 10;
- if (x > WIDTH-10) {
- x = 5;
- y += 10;
- }
- }
- }
-
- @Override
- public void close() {
- DFScript.MC.setScreen(new ScriptAddArgumentScreen(script, action, insertIndex, header));
- }
-}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddConfigValueScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddConfigValueScreen.java
deleted file mode 100644
index 8472c9d..0000000
--- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddConfigValueScreen.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package io.github.techstreet.dfscript.screen.script;
-
-import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.screen.CScreen;
-import io.github.techstreet.dfscript.screen.widget.CItem;
-import io.github.techstreet.dfscript.screen.widget.CScrollPanel;
-import io.github.techstreet.dfscript.script.Script;
-import io.github.techstreet.dfscript.script.ScriptParametrizedPart;
-import io.github.techstreet.dfscript.script.ScriptPart;
-import io.github.techstreet.dfscript.script.action.ScriptAction;
-import io.github.techstreet.dfscript.script.argument.ScriptConfigArgument;
-import io.github.techstreet.dfscript.script.event.ScriptHeader;
-import io.github.techstreet.dfscript.script.options.ScriptNamedOption;
-
-public class ScriptAddConfigValueScreen extends CScreen {
- private final Script script;
-
- private final ScriptHeader header;
- private final ScriptParametrizedPart action;
- private final int insertIndex;
-
- private static int WIDTH = 200;
- private static int HEIGHT = 94;
-
- public ScriptAddConfigValueScreen(ScriptParametrizedPart action, Script script, int insertIndex, ScriptHeader header, String overwrite) {
- super(WIDTH, HEIGHT);
- this.script = script;
- this.action = action;
- this.header = header;
- this.insertIndex = insertIndex;
-
- CScrollPanel panel = new CScrollPanel(0, 0, WIDTH, HEIGHT);
-
- int x = 5;
- int y = 5;
- for (ScriptNamedOption arg : script.getOptions()) {
- CItem item = new CItem(x, y, arg.getIcon());
- item.setClickListener((btn) -> {
- if(overwrite != null) action.getArguments().remove(insertIndex);
- this.action.getArguments().add(insertIndex, new ScriptConfigArgument(arg.getName(), this.script));
- DFScript.MC.setScreen(new ScriptEditPartScreen(this.action, this.script, this.header));
- });
- panel.add(item);
- x += 10;
- if (x > WIDTH-10) {
- x = 5;
- y += 10;
- }
- }
-
- widgets.add(panel);
- }
-
- @Override
- public void close() {
- DFScript.MC.setScreen(new ScriptAddArgumentScreen(script, action, insertIndex, header));
- }
-}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddFunctionArgValueScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddFunctionArgValueScreen.java
deleted file mode 100644
index 2fe6b9a..0000000
--- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddFunctionArgValueScreen.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package io.github.techstreet.dfscript.screen.script;
-
-import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.screen.CScreen;
-import io.github.techstreet.dfscript.screen.widget.CItem;
-import io.github.techstreet.dfscript.screen.widget.CScrollPanel;
-import io.github.techstreet.dfscript.script.Script;
-import io.github.techstreet.dfscript.script.ScriptParametrizedPart;
-import io.github.techstreet.dfscript.script.action.ScriptActionArgument;
-import io.github.techstreet.dfscript.script.argument.ScriptConfigArgument;
-import io.github.techstreet.dfscript.script.argument.ScriptFunctionArgument;
-import io.github.techstreet.dfscript.script.event.ScriptFunction;
-import io.github.techstreet.dfscript.script.event.ScriptHeader;
-
-public class ScriptAddFunctionArgValueScreen extends CScreen {
- private final Script script;
-
- private final ScriptHeader header;
- private final ScriptParametrizedPart action;
- private final int insertIndex;
-
- private static int WIDTH = 200;
- private static int HEIGHT = 94;
-
- public ScriptAddFunctionArgValueScreen(ScriptParametrizedPart action, Script script, int insertIndex, ScriptHeader header, String overwrite) {
- super(WIDTH, HEIGHT);
- this.script = script;
- this.action = action;
- this.header = header;
- this.insertIndex = insertIndex;
-
- CScrollPanel panel = new CScrollPanel(0, 0, WIDTH, HEIGHT);
-
- if(header instanceof ScriptFunction f)
- {
- int x = 5;
- int y = 5;
- for (ScriptActionArgument arg : f.argList()) {
- CItem item = new CItem(x, y, arg.getIcon());
- item.setClickListener((btn) -> {
- if(overwrite != null) action.getArguments().remove(insertIndex);
- this.action.getArguments().add(insertIndex, new ScriptFunctionArgument(arg.name(), header));
- DFScript.MC.setScreen(new ScriptEditPartScreen(this.action, this.script, this.header));
- });
- panel.add(item);
- x += 10;
- if (x > WIDTH-10) {
- x = 5;
- y += 10;
- }
- }
-
- widgets.add(panel);
- }
- }
-
- @Override
- public void close() {
- DFScript.MC.setScreen(new ScriptAddArgumentScreen(script, action, insertIndex, header));
- }
-}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddFunctionArgumentScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddFunctionArgumentScreen.java
deleted file mode 100644
index f755e66..0000000
--- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddFunctionArgumentScreen.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package io.github.techstreet.dfscript.screen.script;
-
-import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.screen.CScreen;
-import io.github.techstreet.dfscript.screen.widget.CItem;
-import io.github.techstreet.dfscript.script.Script;
-import io.github.techstreet.dfscript.script.ScriptSnippet;
-import io.github.techstreet.dfscript.script.action.*;
-import io.github.techstreet.dfscript.script.conditions.ScriptBranch;
-import io.github.techstreet.dfscript.script.conditions.ScriptBuiltinCondition;
-import io.github.techstreet.dfscript.script.conditions.ScriptConditionType;
-import io.github.techstreet.dfscript.script.event.ScriptFunction;
-import io.github.techstreet.dfscript.script.repetitions.ScriptBuiltinRepetition;
-import io.github.techstreet.dfscript.script.repetitions.ScriptRepetitionType;
-
-import java.util.ArrayList;
-
-public class ScriptAddFunctionArgumentScreen extends CScreen {
-
- private final Script script;
-
- private final ScriptFunction function;
- private final int insertIndex;
-
- public ScriptAddFunctionArgumentScreen(Script script, ScriptFunction function, int insertIndex) {
- super(size(), size());
- int size = size();
- this.script = script;
- this.insertIndex = insertIndex;
- this.function = function;
-
- int x = 3;
- int y = 3;
-
- /*if (category == null) {
- for (ScriptEventType type : ScriptEventType.values()) {
- CItem item = new CItem(x, y, type.getIcon());
- item.setClickListener((btn) -> {
- ScriptEvent event = new ScriptEvent(type);
- script.getParts().add(insertIndex, event);
- DFScript.MC.setScreen(new ScriptEditScreen(script));
- });
- widgets.add(item);
- x += 10;
- if (x >= size - 10) {
- x = 3;
- y += 10;
- }
- }
- }*/
-
- for (ScriptActionArgument.ScriptActionArgumentType type : ScriptActionArgument.ScriptActionArgumentType.values()) {
- CItem item = new CItem(x, y, type.icon());
- item.setClickListener((btn) -> {
- ScriptActionArgument arg = new ScriptActionArgument(function.argList().getUnnamedArgument(), type);
- function.argList().add(insertIndex, arg);
- DFScript.MC.setScreen(new ScriptEditFunctionScreen(function, script));
- });
- widgets.add(item);
- x += 10;
- if (x >= size-10) {
- x = 3;
- y += 10;
- }
- }
- }
-
- private static int size() {
- int amount = ScriptActionArgument.ScriptActionArgumentType.values().length;
- return (int) (Math.ceil(Math.sqrt(amount))*10)+4;
- }
-
- @Override
- public void close() {
- DFScript.MC.setScreen(new ScriptEditFunctionScreen(function, script));
- }
-}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddHeaderScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddHeaderScreen.java
deleted file mode 100644
index 9203514..0000000
--- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddHeaderScreen.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package io.github.techstreet.dfscript.screen.script;
-
-import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.screen.CScreen;
-import io.github.techstreet.dfscript.screen.widget.CItem;
-import io.github.techstreet.dfscript.script.Script;
-import io.github.techstreet.dfscript.script.action.ScriptAction;
-import io.github.techstreet.dfscript.script.action.ScriptActionCategory;
-import io.github.techstreet.dfscript.script.action.ScriptActionCategoryExtra;
-import io.github.techstreet.dfscript.script.action.ScriptActionType;
-import io.github.techstreet.dfscript.script.event.ScriptEvent;
-import io.github.techstreet.dfscript.script.event.ScriptEventType;
-import io.github.techstreet.dfscript.script.event.ScriptHeaderCategory;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class ScriptAddHeaderScreen extends CScreen {
-
- private final Script script;
- private final int insertIndex;
-
- public ScriptAddHeaderScreen(Script script, int insertIndex, ScriptHeaderCategory category) {
- super(size(category), size(category));
- int size = size(category);
- this.script = script;
- this.insertIndex = insertIndex;
-
- int x = 3;
- int y = 3;
-
- for (ScriptEventType type : ScriptEventType.values()) {
- //if (type.getCategory() != category) continue;
-
- CItem item = new CItem(x, y, type.getIcon());
- item.setClickListener((btn) -> {
- ScriptEvent event = new ScriptEvent(type);
- script.getHeaders().add(insertIndex, event);
- DFScript.MC.setScreen(new ScriptEditScreen(script));
- });
- widgets.add(item);
- x += 10;
- if (x >= size-10) {
- x = 3;
- y += 10;
- }
- }
- }
-
- private static int size(ScriptHeaderCategory category) {
- int amount = 0;
- for (ScriptEventType type : ScriptEventType.values()) {
- //if (type.getCategory() != category) continue;
-
- amount++;
- }
- return (int) (Math.ceil(Math.sqrt(amount))*10)+4;
- }
-
- @Override
- public void close() {
- DFScript.MC.setScreen(new ScriptHeaderCategoryScreen(script, insertIndex));
- }
-}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddPartScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddPartScreen.java
deleted file mode 100644
index 384b8de..0000000
--- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddPartScreen.java
+++ /dev/null
@@ -1,149 +0,0 @@
-package io.github.techstreet.dfscript.screen.script;
-
-import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.screen.CScreen;
-import io.github.techstreet.dfscript.screen.widget.CItem;
-import io.github.techstreet.dfscript.script.Script;
-import io.github.techstreet.dfscript.script.ScriptSnippet;
-import io.github.techstreet.dfscript.script.action.*;
-import io.github.techstreet.dfscript.script.conditions.ScriptBranch;
-import io.github.techstreet.dfscript.script.conditions.ScriptBuiltinCondition;
-import io.github.techstreet.dfscript.script.conditions.ScriptCondition;
-import io.github.techstreet.dfscript.script.conditions.ScriptConditionType;
-import io.github.techstreet.dfscript.script.event.ScriptEventType;
-import io.github.techstreet.dfscript.script.repetitions.ScriptBuiltinRepetition;
-import io.github.techstreet.dfscript.script.repetitions.ScriptRepetitionType;
-
-import java.util.ArrayList;
-
-public class ScriptAddPartScreen extends CScreen {
-
- private final Script script;
-
- private final ScriptSnippet snippet;
- private final int insertIndex;
-
- public ScriptAddPartScreen(Script script, ScriptSnippet snippet, int insertIndex, ScriptActionCategory category) {
- super(size(category, script), size(category, script));
- int size = size(category, script);
- this.script = script;
- this.insertIndex = insertIndex;
- this.snippet = snippet;
-
- int x = 3;
- int y = 3;
-
- /*if (category == null) {
- for (ScriptEventType type : ScriptEventType.values()) {
- CItem item = new CItem(x, y, type.getIcon());
- item.setClickListener((btn) -> {
- ScriptEvent event = new ScriptEvent(type);
- script.getParts().add(insertIndex, event);
- DFScript.MC.setScreen(new ScriptEditScreen(script));
- });
- widgets.add(item);
- x += 10;
- if (x >= size - 10) {
- x = 3;
- y += 10;
- }
- }
- }*/
-
- if (category != null)
- {
- for(ScriptActionCategoryExtra extra : category.getExtras(script)) {
- CItem item = new CItem(x, y, extra.getIcon());
- item.setClickListener((btn) -> {
- extra.click(script, snippet, insertIndex);
- });
- widgets.add(item);
- x += 10;
- if (x >= size-10) {
- x = 3;
- y += 10;
- }
- }
- }
-
- for (ScriptActionType type : ScriptActionType.values()) {
- if (type.getCategory() != category) continue;
- if (type.isDeprecated()) continue;
-
- CItem item = new CItem(x, y, type.getIcon());
- item.setClickListener((btn) -> {
- ScriptAction action = new ScriptBuiltinAction(type, new ArrayList<>());
- snippet.add(insertIndex, action);
- DFScript.MC.setScreen(new ScriptEditScreen(script));
- });
- widgets.add(item);
- x += 10;
- if (x >= size-10) {
- x = 3;
- y += 10;
- }
- }
-
- for (ScriptConditionType type : ScriptConditionType.values()) {
- if (type.getCategory() != category) continue;
- if (type.isDeprecated()) continue;
-
- CItem item = new CItem(x, y, type.getIcon("If"));
- item.setClickListener((btn) -> {
- ScriptBranch action = new ScriptBranch(new ArrayList<>(), new ScriptBuiltinCondition(type));
- snippet.add(insertIndex, action);
- DFScript.MC.setScreen(new ScriptEditScreen(script));
- });
- widgets.add(item);
- x += 10;
- if (x >= size-10) {
- x = 3;
- y += 10;
- }
- }
-
- for (ScriptRepetitionType type : ScriptRepetitionType.values()) {
- if (type.getCategory() != category) continue;
- if (type.isDeprecated()) continue;
-
- CItem item = new CItem(x, y, type.getIcon());
- item.setClickListener((btn) -> {
- ScriptBuiltinRepetition action = new ScriptBuiltinRepetition(new ArrayList<>(), type);
- snippet.add(insertIndex, action);
- DFScript.MC.setScreen(new ScriptEditScreen(script));
- });
- widgets.add(item);
- x += 10;
- if (x >= size-10) {
- x = 3;
- y += 10;
- }
- }
- }
-
- private static int size(ScriptActionCategory category, Script script) {
- int amount = 0;
- amount += category.getExtras(script).size();
- for (ScriptActionType type : ScriptActionType.values()) {
- if (type.getCategory() == category) {
- amount++;
- }
- }
- for (ScriptConditionType type : ScriptConditionType.values()) {
- if (type.getCategory() == category) {
- amount++;
- }
- }
- for (ScriptRepetitionType type : ScriptRepetitionType.values()) {
- if (type.getCategory() == category) {
- amount++;
- }
- }
- return (int) (Math.ceil(Math.sqrt(amount))*10)+4;
- }
-
- @Override
- public void close() {
- DFScript.MC.setScreen(new ScriptPartCategoryScreen(script, snippet, insertIndex));
- }
-}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddScreen.java
deleted file mode 100644
index 61f05cc..0000000
--- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddScreen.java
+++ /dev/null
@@ -1,159 +0,0 @@
-package io.github.techstreet.dfscript.screen.script;
-
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.features.AuthHandler;
-import io.github.techstreet.dfscript.screen.CScreen;
-import io.github.techstreet.dfscript.screen.widget.CButton;
-import io.github.techstreet.dfscript.screen.widget.CPlainPanel;
-import io.github.techstreet.dfscript.screen.widget.CScrollPanel;
-import io.github.techstreet.dfscript.screen.widget.CText;
-import io.github.techstreet.dfscript.screen.widget.CTextField;
-import io.github.techstreet.dfscript.script.ScriptManager;
-import io.github.techstreet.dfscript.script.VirtualScript;
-
-import java.io.*;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.util.*;
-
-import net.minecraft.text.LiteralTextContent;
-import net.minecraft.text.MutableText;
-import net.minecraft.text.Text;
-
-public class ScriptAddScreen extends CScreen {
- public static ArrayList scripts = new ArrayList<>();
- public static HashMap scriptHash = new HashMap<>();
-
- CScrollPanel panel;
- CTextField searchBox;
-
- public ScriptAddScreen() {
- super(111, 106);
- open();
- }
-
- private void open() {
- CPlainPanel root = new CPlainPanel(0, 0, 111, 106);
-
- panel = new CScrollPanel(0, 17, 111, 84);
-
- root.add(panel);
-
- searchBox = new CTextField("Search...", 5, 5, 100, 10, true);
- searchBox.setChangedListener(this::update);
- root.add(searchBox);
-
- widgets.add(root);
-
- update();
- }
-
- private void update() {
- List filtered = new ArrayList<>();
- String query = searchBox.getText().toLowerCase();
-
- for (VirtualScript script : scripts) {
- if (!searchBox.getText().equals("Search...")) {
- if (script.getName().toLowerCase().contains(query.toLowerCase()) || script.getOwner().toLowerCase().contains(query.toLowerCase())) {
- filtered.add(script);
- }
- } else {
- filtered.add(script);
- }
- }
-
- panel.clear();
- fillPanel(filtered);
- }
-
- public static void getScripts() {
- ArrayList scripts = new ArrayList<>();
-
- try {
- URL url = new URL("https://DFScript-Server.techstreetdev.repl.co/check/");
- HttpURLConnection con = (HttpURLConnection) url.openConnection();
- con.setRequestMethod("GET");
- con.setRequestProperty("authorization", AuthHandler.getAuthCode());
- con.setDoOutput(true);
-
- con.getInputStream();
- if (con.getResponseCode() != 204) {
- AuthHandler.regen();
- }
- } catch (Exception e) {
- AuthHandler.regen();
-// e.printStackTrace();
- }
-
- try {
- InputStream is = new URL("https://dfscript-server.techstreetdev.repl.co/scripts/get").openStream();
- BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
- JsonObject obj = JsonParser.parseString(readAll(rd)).getAsJsonObject();
-
- for (String key : obj.keySet()) {
- JsonObject scriptObject = obj.getAsJsonObject(key);
-
- VirtualScript script = new VirtualScript(scriptObject.get("name").getAsString(), scriptObject.get("owner").getAsString(), key);
- script.setApproved(scriptObject.get("approved").getAsBoolean());
- script.setApprover((scriptObject.get("approvedBy").isJsonNull() ? "None" : scriptObject.get("approvedBy").getAsString()));
-
- scripts.add(script);
- }
-
- is.close();
-
- for (VirtualScript s : scripts) {
- ScriptAddScreen.scriptHash.put(s.getId(), s);
- }
-
- ScriptAddScreen.scripts = scripts;
- } catch (Exception e) {
-// e.printStackTrace();
- }
- }
-
- public static String readAll(Reader rd) throws IOException {
- StringBuilder sb = new StringBuilder();
- int cp;
-
- while ((cp = rd.read()) != -1) {
- sb.append((char) cp);
- }
-
- return sb.toString();
- }
-
- private void fillPanel(List scriptList) {
- int y = 18;
- CButton newButton = new CButton(7, 6, 96, 10, "New Script", () -> {
- DFScript.MC.setScreen(new ScriptCreationScreen());
- });
-
- panel.add(newButton);
-
- for (VirtualScript script : scriptList) {
- CButton button = new CButton(7, y, 96, 10, (script.isApproved() ? "§e⭐ " : "") + "§f" + script.getName(), () -> {
- DFScript.MC.setScreen(new ScriptInstallScreen(script));
- });
-
- panel.add(button);
- y += 12;
- }
-
- long time = Math.abs((System.currentTimeMillis() / 1000) - ScriptManager.lastServerUpdate);
- long minutes = (time % 3600) / 60;
- long seconds = time % 60;
-
- panel.add(new CText(8, 0, Text.literal("Last update: " + minutes + "m " + seconds + "s" + " ago!")));
- }
-
- @Override
- public void close() {
- DFScript.MC.setScreen(new ScriptListScreen(true));
- }
-}
\ No newline at end of file
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddSettingSubtypeScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddSettingSubtypeScreen.java
index b4610bd..9608fba 100644
--- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddSettingSubtypeScreen.java
+++ b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptAddSettingSubtypeScreen.java
@@ -22,7 +22,6 @@
import java.util.stream.Collectors;
public class ScriptAddSettingSubtypeScreen extends CScreen {
-
private int width;
private int height;
private static final List primitiveTypes;
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptConditionCategoryScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptConditionCategoryScreen.java
index 9a25950..4b2f4a6 100644
--- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptConditionCategoryScreen.java
+++ b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptConditionCategoryScreen.java
@@ -15,7 +15,6 @@
import java.util.function.Function;
public class ScriptConditionCategoryScreen extends CScreen {
-
private static final int size;
static {
@@ -56,6 +55,6 @@ public ScriptConditionCategoryScreen(Script script, ScriptSnippet snippet, int i
@Override
public void close() {
- DFScript.MC.setScreen(new ScriptAddPartScreen(script, snippet, insertIndex, ScriptActionCategory.CONDITIONS));
+
}
}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptConditionSelectScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptConditionSelectScreen.java
index e959a8f..5d0be15 100644
--- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptConditionSelectScreen.java
+++ b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptConditionSelectScreen.java
@@ -41,7 +41,6 @@ public ScriptConditionSelectScreen(Script script, ScriptSnippet snippet, int ins
CItem item = new CItem(x, y, type.getIcon(""));
item.setClickListener((btn) -> {
snippet.add(insertIndex, partCreator.apply(new ScriptBuiltinCondition(type)));
- DFScript.MC.setScreen(new ScriptEditScreen(script));
});
widgets.add(item);
x += 10;
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptCreationScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptCreationScreen.java
deleted file mode 100644
index b9bdce5..0000000
--- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptCreationScreen.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package io.github.techstreet.dfscript.screen.script;
-
-import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.screen.CScreen;
-import io.github.techstreet.dfscript.screen.widget.CButton;
-import io.github.techstreet.dfscript.screen.widget.CText;
-import io.github.techstreet.dfscript.screen.widget.CTextField;
-import io.github.techstreet.dfscript.script.ScriptManager;
-import net.minecraft.text.Text;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-public class ScriptCreationScreen extends CScreen {
-
- // invalid file name chars
- // there's definitely a better place to put this but this felt the simplest rn
- Pattern ILLEGAL_CHARS = Pattern.compile("[\\\\/:*?\"<>|\n]");
-
- protected ScriptCreationScreen() {
- super(100, 33);
-
- widgets.add(new CText(4, 4, Text.of("Create Script")));
-
- CTextField name = new CTextField("My Script", 4, 9, 92, 9, true){
- @Override
- public void keyPressed(int keyCode, int scanCode, int modifiers) {
- if(keyCode == 257) return;
- super.keyPressed(keyCode, scanCode, modifiers);
- }
- };
-
- name.setChangedListener(() -> {
- String scriptName = name.getText();
-
- Matcher m = ILLEGAL_CHARS.matcher(scriptName);
-
- name.textColor = m.find() ? 0xFF3333 : 0xFFFFFF;
- });
-
- widgets.add(name);
-
- widgets.add(new CButton(4, 20, 44, 9, "Create", () -> {
- String scriptName = name.getText();
-
- Matcher m = ILLEGAL_CHARS.matcher(scriptName);
-
- if (m.find()) return;
-
- ScriptManager.getInstance().createScript(name.getText());
- DFScript.MC.setScreen(new ScriptListScreen(true));
- }));
-
- widgets.add(new CButton(52, 20, 44, 9, "Cancel", () -> {
- DFScript.MC.setScreen(new ScriptAddScreen());
- }));
- }
-
- @Override
- public void close() {
- DFScript.MC.setScreen(new ScriptAddScreen());
- }
-}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptDeletionScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptDeletionScreen.java
deleted file mode 100644
index e21cfa8..0000000
--- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptDeletionScreen.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package io.github.techstreet.dfscript.screen.script;
-
-import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.screen.CScreen;
-import io.github.techstreet.dfscript.screen.widget.CButton;
-import io.github.techstreet.dfscript.screen.widget.CText;
-import io.github.techstreet.dfscript.script.Script;
-import io.github.techstreet.dfscript.script.ScriptManager;
-import net.minecraft.text.Text;
-
-public class ScriptDeletionScreen extends CScreen {
-
- public ScriptDeletionScreen(Script script) {
- super(103,27);
-
- widgets.add(new CText(5,5, Text.literal("Delete " + script.getName() + "?")));
-
- widgets.add(new CButton(5,12,45, 10,"Delete",() -> {
- ScriptManager.getInstance().deleteScript(script);
- DFScript.MC.setScreen(new ScriptListScreen(true));
- }));
-
- widgets.add(new CButton(52,12,45, 10,"Cancel",() -> DFScript.MC.setScreen(new ScriptListScreen(true))));
- }
-
- @Override
- public void close() {
- DFScript.MC.setScreen(new ScriptListScreen(true));
- }
-}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditFunctionArgumentScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditFunctionArgumentScreen.java
deleted file mode 100644
index f7ac64a..0000000
--- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditFunctionArgumentScreen.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package io.github.techstreet.dfscript.screen.script;
-
-import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.screen.CScreen;
-import io.github.techstreet.dfscript.screen.widget.CButton;
-import io.github.techstreet.dfscript.screen.widget.CTextField;
-import io.github.techstreet.dfscript.script.Script;
-import io.github.techstreet.dfscript.script.action.ScriptActionArgument;
-import io.github.techstreet.dfscript.script.event.ScriptFunction;
-import io.github.techstreet.dfscript.script.options.ScriptNamedOption;
-
-import java.util.Objects;
-
-public class ScriptEditFunctionArgumentScreen extends CScreen {
- private final Script script;
-
- private final ScriptFunction function;
- private final ScriptActionArgument argument;
-
- public ScriptEditFunctionArgumentScreen(Script script, ScriptFunction f, ScriptActionArgument a) {
- super(100, 50);
- this.script = script;
- argument = a;
- function = f;
-
- CTextField input = new CTextField(argument.name(), 2, 2, 96, 35, true);
-
- input.setChangedListener(() -> input.textColor = 0xFFFFFF);
-
- CButton confirm = new CButton(2, 37, 46, 10, "Rename", () -> {
- if(!Objects.equals(argument.name(), input.getText())) {
- if(function.argList().argumentExists(input.getText())) {
- input.textColor = 0xFF3333;
- } else {
- //script.replaceOption(option.getName(), input.getText());
- function.replaceArgument(argument.name(), input.getText());
- argument.setName(input.getText());
- close();
- }
- } else {
- close();
- }
- });
-
- CButton cancel = new CButton(52, 37, 46, 10, "Cancel", this::close);
-
- widgets.add(input);
- widgets.add(confirm);
- widgets.add(cancel);
- }
-
- @Override
- public void close() {
- DFScript.MC.setScreen(new ScriptEditFunctionScreen(function, script));
- }
-}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditFunctionScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditFunctionScreen.java
deleted file mode 100644
index 739baad..0000000
--- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditFunctionScreen.java
+++ /dev/null
@@ -1,208 +0,0 @@
-package io.github.techstreet.dfscript.screen.script;
-
-import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.screen.CReloadableScreen;
-import io.github.techstreet.dfscript.screen.ContextMenuButton;
-import io.github.techstreet.dfscript.screen.util.ItemMaterialSelectMenu;
-import io.github.techstreet.dfscript.screen.widget.*;
-import io.github.techstreet.dfscript.script.Script;
-import io.github.techstreet.dfscript.script.action.ScriptActionArgument;
-import io.github.techstreet.dfscript.script.event.ScriptFunction;
-import io.github.techstreet.dfscript.script.values.ScriptUnknownValue;
-import net.minecraft.client.font.TextRenderer;
-import net.minecraft.client.gui.DrawContext;
-import net.minecraft.client.sound.PositionedSoundInstance;
-import net.minecraft.item.ItemStack;
-import net.minecraft.sound.SoundEvents;
-import net.minecraft.text.Text;
-
-import java.awt.*;
-import java.util.ArrayList;
-import java.util.List;
-
-public class ScriptEditFunctionScreen extends CReloadableScreen {
-
- private final Script script;
- private final ScriptFunction function;
- private final CScrollPanel panel;
- private final List contextMenu = new ArrayList<>();
-
- public ScriptEditFunctionScreen(ScriptFunction function, Script script) {
- super(90, 100);
- panel = new CScrollPanel(0, 0, 90, 100);
-
- widgets.add(panel);
-
- this.script = script;
- this.function = function;
-
- reload();
- }
-
- @Override
- public void close() {
- DFScript.MC.setScreen(new ScriptEditScreen(script));
- }
-
- @Override
- public boolean mouseClicked(double mouseX, double mouseY, int button) {
- boolean b = super.mouseClicked(mouseX, mouseY, button);
- clearContextMenu();
- return b;
- }
-
- private void clearContextMenu() {
- for (CWidget w : contextMenu) {
- panel.remove(w);
- }
- contextMenu.clear();
- }
-
- public void contextMenu(int x, int y, List contextMenuButtons) {
- clearContextMenu();
-
- int maxWidth = 0;
-
- for(ContextMenuButton w : contextMenuButtons)
- {
- TextRenderer t = DFScript.MC.textRenderer;
- int width = t.getWidth(w.getName())/2 + 4;
-
- if(width > maxWidth) maxWidth = width;
- }
-
- for(ContextMenuButton w : contextMenuButtons)
- {
- CButton button = new CButton(x, y, maxWidth, 8, w.getName(), w.getOnClick());
- y += 8;
-
- panel.add(button);
- contextMenu.add(button);
- }
- }
-
- @Override
- public void reload() {
- clearContextMenu();
- panel.clear();
-
- CTextField nameField = new CTextField(function.getName(), 15, 3, 90-10-10, 8, true);
- nameField.setMultiline(false);
- nameField.setChangedListener(() -> {
- if(script.functionExists(nameField.getText())) {
- nameField.textColor = 0xFF0000;
- }
- else {
- nameField.textColor = 0xFFFFFF;
- script.replaceFunction(function.getName(), nameField.getText());
- function.setName(nameField.getText());
- }
- });
-
- CItem icon = new CItem(5, 3, function.getIcon());
-
- icon.setClickListener((button) -> {
- DFScript.MC.setScreen(new ItemMaterialSelectMenu(function.getRawIcon(), (newIcon) -> {
- function.setIcon(newIcon);
- DFScript.MC.setScreen(new ScriptEditFunctionScreen(function, script));
- }));
- });
-
- CTextField descField = new CTextField(function.getDescription(), 5, 11, 80, 20, true);
- descField.setChangedListener(() -> {
- function.setDescription(descField.getText());
- });
-
- panel.add(icon);
- panel.add(nameField);
- panel.add(descField);
-
- int y = 31+4;
- int index = 0;
- for (ScriptActionArgument arg : function.argList()) {
- ItemStack argIcon = arg.getUnnamedIcon();
- String text = arg.name();
-
- panel.add(new CItem(5, y, argIcon, Text.literal((arg.optional() ? "*" : "") + (arg.plural() ? "s" : ""))));
- panel.add(new CText(15, y + 2, Text.literal(text)));
-
- int currentIndex = index;
-
-
- panel.add(new CButton(5, y-1, 85, 10, "",() -> {}) {
- @Override
- public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) {
- Rectangle b = getBounds();
- if (b.contains(mouseX, mouseY)) {
- context.fill(b.x, b.y, b.x + b.width, b.y + b.height, 0x33000000);
- }
- }
-
- @Override
- public boolean mouseClicked(double x, double y, int button) {
- if (getBounds().contains(x, y)) {
- DFScript.MC.getSoundManager().play(PositionedSoundInstance.ambient(SoundEvents.UI_BUTTON_CLICK.value(),
- 1f,1f));
-
- if (button != 0) {
- List contextMenuButtons = new ArrayList<>();
- contextMenuButtons.add(new ContextMenuButton("Insert Before", () -> {
- DFScript.MC.setScreen(new ScriptAddFunctionArgumentScreen(script, function, currentIndex));
- }, false));
- if (!(currentIndex == function.argList().size() - 1 && arg.plural())) {
- contextMenuButtons.add(new ContextMenuButton("Insert After", () -> {
- DFScript.MC.setScreen(new ScriptAddFunctionArgumentScreen(script, function, currentIndex + 1));
- }, false));
- }
- contextMenuButtons.add(new ContextMenuButton("Delete", () -> {
- function.removeArgument(arg.name());
-
- function.argList().remove(currentIndex);
- }));
- if(arg.type().allowOptional()) {
- contextMenuButtons.add(new ContextMenuButton(arg.optional() ? "Required" : "Optional", () -> {
- arg.optional(!arg.optional());
- }));
- if(currentIndex == function.argList().size()-1) {
- contextMenuButtons.add(new ContextMenuButton(arg.plural() ? "Singular" : "Plural", () -> {
- arg.plural(!arg.plural());
- }));
- }
- if(arg.optional() && !arg.plural() && arg.type().getDefaultValueType() != null) {
- contextMenuButtons.add(new ContextMenuButton("Default Value", () -> {
- DFScript.MC.setScreen(new ScriptSetValueScreen(script, () -> {
- DFScript.MC.setScreen(new ScriptEditFunctionScreen(function, script));
- }, arg::defaultValue, arg.type().getDefaultValueType(),
- arg.defaultValue() instanceof ScriptUnknownValue ? null : arg.defaultValue().asText()));
- }, false));
- }
- }
- DFScript.MC.send(() -> {
- if(DFScript.MC.currentScreen instanceof ScriptEditFunctionScreen screen) {
- screen.contextMenu((int) x, (int) y, contextMenuButtons);
- }
- });
- }
- else
- {
- DFScript.MC.setScreen(new ScriptEditFunctionArgumentScreen(script, function, arg));
- }
-
- return true;
- }
- return false;
- }
- });
-
- y += 10;
- index++;
-
- }
-
- CButton add = new CButton(25, y, 40, 8, "Add", () -> {
- DFScript.MC.setScreen(new ScriptAddFunctionArgumentScreen(script, function, function.argList().size()));
- });
- if(function.argList().size() == 0 || !function.argList().get(function.argList().size() - 1).plural())
- panel.add(add);
- }
-}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditPartScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditPartScreen.java
deleted file mode 100644
index 3a22090..0000000
--- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditPartScreen.java
+++ /dev/null
@@ -1,169 +0,0 @@
-package io.github.techstreet.dfscript.screen.script;
-
-import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.screen.CReloadableScreen;
-import io.github.techstreet.dfscript.screen.CScreen;
-import io.github.techstreet.dfscript.screen.ContextMenuButton;
-import io.github.techstreet.dfscript.screen.widget.*;
-import io.github.techstreet.dfscript.script.Script;
-import io.github.techstreet.dfscript.script.ScriptParametrizedPart;
-import io.github.techstreet.dfscript.script.argument.*;
-import io.github.techstreet.dfscript.script.event.ScriptHeader;
-import net.minecraft.client.font.TextRenderer;
-import net.minecraft.client.gui.DrawContext;
-import net.minecraft.client.sound.PositionedSoundInstance;
-import net.minecraft.item.ItemStack;
-import net.minecraft.item.Items;
-import net.minecraft.sound.SoundEvents;
-import net.minecraft.text.Text;
-
-import java.awt.*;
-import java.math.RoundingMode;
-import java.text.DecimalFormat;
-import java.util.ArrayList;
-import java.util.List;
-public class ScriptEditPartScreen extends CReloadableScreen {
- private final Script script;
-
- private final ScriptHeader header;
- private final ScriptParametrizedPart action;
- private final CScrollPanel panel;
- private final List contextMenu = new ArrayList<>();
-
- public ScriptEditPartScreen(ScriptParametrizedPart action, Script script, ScriptHeader header) {
- super(90, 100);
- panel = new CScrollPanel(0, 0, 90, 100);
-
- widgets.add(panel);
-
- this.script = script;
- this.action = action;
- this.header = header;
-
- reload();
- }
-
- @Override
- public void close() {
- DFScript.MC.setScreen(new ScriptEditScreen(script));
- }
-
- @Override
- public boolean mouseClicked(double mouseX, double mouseY, int button) {
- boolean b = super.mouseClicked(mouseX, mouseY, button);
- clearContextMenu();
- return b;
- }
-
- private void clearContextMenu() {
- for (CWidget w : contextMenu) {
- panel.remove(w);
- }
- contextMenu.clear();
- }
-
- public void contextMenu(int x, int y, List contextMenuButtons) {
- clearContextMenu();
-
- int maxWidth = 0;
-
- for(ContextMenuButton w : contextMenuButtons)
- {
- TextRenderer t = DFScript.MC.textRenderer;
- int width = t.getWidth(w.getName())/2 + 4;
-
- if(width > maxWidth) maxWidth = width;
- }
-
- for(ContextMenuButton w : contextMenuButtons)
- {
- CButton button = new CButton(x, y, maxWidth, 8, w.getName(), w.getOnClick());
- y += 8;
-
- panel.add(button);
- contextMenu.add(button);
- }
- }
-
- @Override
- public void reload() {
- clearContextMenu();
- panel.clear();
-
- panel.add(new CItem(5, 3, action.getIcon()));
- panel.add(new CText(15, 5, Text.of(action.getName())));
-
- int y = 15;
- int index = 0;
- for (ScriptArgument arg : action.getArguments()) {
- ItemStack icon = arg.getArgIcon();
- Text countText = arg.getArgIconText();
- String text = arg.getArgText();
-
- panel.add(new CItem(5, y, icon, countText));
- panel.add(new CText(15, y + 2, Text.literal(text)));
-
- int currentIndex = index;
-
-
- panel.add(new CButton(5, y-1, 85, 10, "",() -> {}) {
- @Override
- public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) {
- Rectangle b = getBounds();
- if (b.contains(mouseX, mouseY)) {
- context.fill(b.x, b.y, b.x + b.width, b.y + b.height, 0x33000000);
- }
- }
-
- @Override
- public boolean mouseClicked(double x, double y, int button) {
- if (getBounds().contains(x, y)) {
- DFScript.MC.getSoundManager().play(PositionedSoundInstance.ambient(SoundEvents.UI_BUTTON_CLICK.value(), 1f,1f));
-
- if (button == 0) {
- ScriptArgument argument = action.getArguments().get(currentIndex);
- String value = "~";
- if(argument instanceof ScriptClientValueArgument clientValue) value = clientValue.getName();
- if(argument instanceof ScriptConfigArgument configArgument) value = configArgument.getName();
- if(argument instanceof ScriptNumberArgument number) value = String.valueOf(number.value());
- if(argument instanceof ScriptTextArgument text) value = text.value();
- if(argument instanceof ScriptVariableArgument var) value = var.name();
- if(argument instanceof ScriptFunctionArgument var) value = var.getName();
- DFScript.MC.setScreen(new ScriptAddArgumentScreen(script, action, currentIndex, header, value));
- }
-
- if (button != 0) {
- List contextMenuButtons = new ArrayList<>();
- contextMenuButtons.add(new ContextMenuButton("Insert Before", () -> {
- DFScript.MC.setScreen(new ScriptAddArgumentScreen(script, action, currentIndex, header));
- }, false));
- contextMenuButtons.add(new ContextMenuButton("Insert After", () -> {
- DFScript.MC.setScreen(new ScriptAddArgumentScreen(script, action, currentIndex+1, header));
- }, false));
- contextMenuButtons.add(new ContextMenuButton("Delete", () -> {
- action.getArguments().remove(currentIndex);
- }));
- contextMenuButtons.addAll(action.getArguments().get(currentIndex).getContextMenu());
- DFScript.MC.send(() -> {
- if(DFScript.MC.currentScreen instanceof ScriptEditPartScreen screen) {
- screen.contextMenu((int) x, (int) y, contextMenuButtons);
- }
- });
- }
- return true;
- }
- return false;
- }
- });
-
- y += 10;
- index++;
-
- }
-
- CButton add = new CButton(25, y, 40, 8, "Add", () -> {
- DFScript.MC.setScreen(new ScriptAddArgumentScreen(script, action, action.getArguments().size(), header));
- });
- panel.add(add);
- }
-}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditScreen.java
deleted file mode 100644
index 2b315e8..0000000
--- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptEditScreen.java
+++ /dev/null
@@ -1,194 +0,0 @@
-package io.github.techstreet.dfscript.screen.script;
-
-import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.screen.CReloadableScreen;
-import io.github.techstreet.dfscript.screen.CScreen;
-import io.github.techstreet.dfscript.screen.ContextMenuButton;
-import io.github.techstreet.dfscript.screen.widget.*;
-import io.github.techstreet.dfscript.script.Script;
-import io.github.techstreet.dfscript.script.ScriptManager;
-
-import io.github.techstreet.dfscript.script.event.ScriptFunction;
-import io.github.techstreet.dfscript.script.event.ScriptHeader;
-import net.minecraft.client.font.TextRenderer;
-import net.minecraft.client.gui.DrawContext;
-import net.minecraft.client.sound.PositionedSoundInstance;
-import net.minecraft.client.util.math.MatrixStack;
-import net.minecraft.sound.SoundEvents;
-import net.minecraft.text.Text;
-import net.minecraft.util.Identifier;
-import java.awt.*;
-import java.util.ArrayList;
-import java.util.List;
-public class ScriptEditScreen extends CReloadableScreen {
- private final Identifier identifier_main = new Identifier(DFScript.MOD_ID + ":wrench.png");
-
- private final Script script;
- private static int scroll = 0;
-
- public final static int width = 125;
- private CScrollPanel panel;
- private final List contextMenu = new ArrayList<>();
-
- public ScriptEditScreen(Script script) {
- super(width, 100);
- this.script = script;
-
- reload();
- }
-
- public void reload()
- {
- clearContextMenu();
- widgets.clear();
-
- if(panel != null)
- {
- scroll = panel.getScroll();
- }
-
- panel = new CScrollPanel(0, 3, 120, 94);
- widgets.add(panel);
-
- int y = 0;
- int index = 0;
-
- CText name = new CText(5,y+2,Text.literal(script.getName()),0,1,false,false);
- panel.add(name);
-
- CButton settings = new CTexturedButton(120-8, y, 8, 8, DFScript.MOD_ID + ":settings.png", DFScript.MOD_ID + ":settings_highlight.png", () -> {
- DFScript.MC.setScreen(new ScriptSettingsScreen(this.script, true));
- });
- panel.add(settings);
-
- y += 10;
-
- for(ScriptHeader header : script.getHeaders()) {
- int origY = y;
- y = header.create(panel, y, index, script);
- int currentIndex = index;
- panel.add(new CButton(5, origY-1, 115, 10, "",() -> {}) {
- @Override
- public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) {
- Rectangle b = getBounds();
-
- if (b.contains(mouseX, mouseY)) {
- int color = 0x33000000;
-
- context.fill(b.x, b.y, b.x + b.width, b.y + b.height, color);
- }
- }
-
- @Override
- public boolean mouseClicked(double x, double y, int button) {
- if (getBounds().contains(x, y)) {
- DFScript.MC.getSoundManager().play(PositionedSoundInstance.ambient(SoundEvents.UI_BUTTON_CLICK.value(), 1f,1f));
-
- if (button != 0) {
- CButton insertBefore = new CButton((int) x, (int) y, 40, 8, "Insert Before", () -> {
- DFScript.MC.setScreen(new ScriptHeaderCategoryScreen(script, currentIndex));
- });
- CButton insertAfter = new CButton((int) x, (int) y+8, 40, 8, "Insert After", () -> {
- DFScript.MC.setScreen(new ScriptHeaderCategoryScreen(script, currentIndex + 1));
- });
- CButton delete = new CButton((int) x, (int) y+16, 40, 8, "Delete", () -> {
- script.getHeaders().remove(currentIndex);
- if(header instanceof ScriptFunction f) {
- script.removeFunction(f.getName());
- }
- reload();
- });
- DFScript.MC.send(() -> {
- panel.add(insertBefore);
- panel.add(insertAfter);
- panel.add(delete);
- contextMenu.add(insertBefore);
- contextMenu.add(insertAfter);
- contextMenu.add(delete);
- });
- }
- else {
- if(header instanceof ScriptFunction f) {
- DFScript.MC.setScreen(new ScriptEditFunctionScreen(f, script));
- }
- }
- return true;
- }
- return false;
- }
- });
- index++;
- }
-
- CButton add = new CButton(37, y, 46, 8, "Add Header", () -> {
- DFScript.MC.setScreen(new ScriptHeaderCategoryScreen(script, script.getHeaders().size()));
- });
-
- panel.add(add);
-
- panel.setScroll(scroll);
- }
-
- public void createIndent(int indent, int y)
- {
- for (int i = 0; i < indent; i += 5) {
- int xpos = 8 + i;
- int ypos = y;
- panel.add(new CWidget() {
- @Override
- public void render(DrawContext context, int mouseX, int mouseY, float tickDelta) {
- context.fill(xpos, ypos, xpos + 1, ypos + 8, 0xFF333333);
- }
-
- @Override
- public Rectangle getBounds() {
- return new Rectangle(0, 0, 0, 0);
- }
- });
- }
- }
-
- @Override
- public void close() {
- scroll = panel.getScroll();
- ScriptManager.getInstance().saveScript(script);
- DFScript.MC.setScreen(new ScriptListScreen(true));
- }
-
- @Override
- public boolean mouseClicked(double mouseX, double mouseY, int button) {
- boolean b = super.mouseClicked(mouseX, mouseY, button);
- clearContextMenu();
- return b;
- }
-
- private void clearContextMenu() {
- for (CWidget w : contextMenu) {
- panel.remove(w);
- }
- contextMenu.clear();
- }
-
- public void contextMenu(int x, int y, List contextMenuButtons) {
- clearContextMenu();
-
- int maxWidth = 0;
-
- for(ContextMenuButton w : contextMenuButtons)
- {
- TextRenderer t = DFScript.MC.textRenderer;
- int width = t.getWidth(w.getName())/2 + 4;
-
- if(width > maxWidth) maxWidth = width;
- }
-
- for(ContextMenuButton w : contextMenuButtons)
- {
- CButton button = new CButton(x, y, maxWidth, 8, w.getName(), w.getOnClick());
- y += 8;
-
- panel.add(button);
- contextMenu.add(button);
- }
- }
-}
diff --git a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptHeaderCategoryScreen.java b/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptHeaderCategoryScreen.java
deleted file mode 100644
index cf07955..0000000
--- a/src/main/java/io/github/techstreet/dfscript/screen/script/ScriptHeaderCategoryScreen.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package io.github.techstreet.dfscript.screen.script;
-
-import io.github.techstreet.dfscript.DFScript;
-import io.github.techstreet.dfscript.screen.CScreen;
-import io.github.techstreet.dfscript.screen.widget.CItem;
-import io.github.techstreet.dfscript.script.Script;
-import io.github.techstreet.dfscript.script.action.ScriptActionArgumentList;
-import io.github.techstreet.dfscript.script.action.ScriptActionCategory;
-import io.github.techstreet.dfscript.script.event.ScriptFunction;
-import io.github.techstreet.dfscript.script.event.ScriptHeader;
-import io.github.techstreet.dfscript.script.event.ScriptHeaderCategory;
-import net.minecraft.item.ItemStack;
-import net.minecraft.item.Items;
-import net.minecraft.text.Style;
-import net.minecraft.text.Text;
-import net.minecraft.util.Formatting;
-
-import java.util.List;
-import java.util.Map;
-import java.util.function.BiConsumer;
-import java.util.function.Consumer;
-import java.util.function.Function;
-
-public class ScriptHeaderCategoryScreen extends CScreen {
-
- private static final int size;
- private static final List extra;
-
- static {
- extra = List.of(
- new HeaderExtra(ScriptFunction.functionIcon, (script, insertIndex) ->
- script.getHeaders().add(insertIndex, new ScriptFunction(
- script.getUnnamedFunction(), Items.LAPIS_LAZULI, new ScriptActionArgumentList(), ""
- )))
- );
- size = (int) (Math.ceil(Math.sqrt(ScriptHeaderCategory.values().length+extra.size())) * 10)+4;
- }
-
- private final Script script;
-
- public ScriptHeaderCategoryScreen(Script script, int insertIndex) {
- super(size, size);
- this.script = script;
-
- int x = 3;
- int y = 3;
-
- for (ScriptHeaderCategory category : ScriptHeaderCategory.values()) {
- CItem actionItem = new CItem(x, y, category.getIcon());
- widgets.add(actionItem);
-
- actionItem.setClickListener(btn -> DFScript.MC.setScreen(new ScriptAddHeaderScreen(script, insertIndex, category)));
-
- x += 10;
- if (x >= size - 10) {
- x = 3;
- y += 10;
- }
- }
-
- for(HeaderExtra headerExtra : extra) {
- CItem item = new CItem(x, y, headerExtra.icon());
- item.setClickListener(button -> {
- headerExtra.onClick().accept(script, insertIndex);
- close();
- });
-
- widgets.add(item);
-
- x += 10;
- if (x >= size - 10) {
- x = 3;
- y += 10;
- }
- }
- }
-
- @Override
- public void close() {
- DFScript.MC.setScreen(new ScriptEditScreen(script));
- }
-
- record HeaderExtra(ItemStack icon, BiConsumer