Merge branch 'jsonToGuiButtons'
This commit is contained in:
commit
72448f9206
3
META-INF/MANIFEST.MF
Normal file
3
META-INF/MANIFEST.MF
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
Main-Class: com.josyf.macrobuttons.MacroButtons
|
||||||
|
|
19
build.gradle
19
build.gradle
@ -15,6 +15,7 @@ repositories {
|
|||||||
name = "CottonMC"
|
name = "CottonMC"
|
||||||
url = "https://server.bbkr.space/artifactory/libs-release"
|
url = "https://server.bbkr.space/artifactory/libs-release"
|
||||||
}
|
}
|
||||||
|
jcenter()
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@ -28,17 +29,23 @@ dependencies {
|
|||||||
|
|
||||||
// Serialization
|
// Serialization
|
||||||
compile group: 'com.alibaba', name: 'fastjson', version: '1.2.56'
|
compile group: 'com.alibaba', name: 'fastjson', version: '1.2.56'
|
||||||
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1'
|
compile 'com.googlecode.json-simple:json-simple:1.1.1'
|
||||||
|
|
||||||
|
|
||||||
implementation 'com.cedarsoftware:json-io:4.10.1'
|
implementation 'com.cedarsoftware:json-io:4.10.1'
|
||||||
|
|
||||||
|
compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
|
||||||
|
|
||||||
|
// includes
|
||||||
|
include 'com.alibaba:fastjson:1.2.56'
|
||||||
|
include 'com.googlecode.json-simple:json-simple:1.1.1'
|
||||||
|
include 'com.cedarsoftware:json-io:4.10.1'
|
||||||
|
|
||||||
|
|
||||||
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
|
// PSA: Some older mods, compiled on Loom 0.2.1, might have outdated Maven POMs.
|
||||||
// You may need to force-disable transitiveness on them.
|
// You may need to force-disable transitiveness on them.
|
||||||
dependencies {
|
|
||||||
modImplementation "io.github.cottonmc:LibGui:3.2.2+1.16.3"
|
modImplementation "io.github.cottonmc:LibGui:3.2.2+1.16.3"
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
processResources {
|
processResources {
|
||||||
inputs.property "version", project.version
|
inputs.property "version", project.version
|
||||||
@ -81,9 +88,5 @@ publishing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// select the repositories you want to publish to
|
|
||||||
repositories {
|
|
||||||
// uncomment to publish to the local maven
|
|
||||||
// mavenLocal()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
5
gradle/wrapper/gradle-wrapper.properties
vendored
5
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,6 @@
|
|||||||
|
#Sun Dec 20 14:49:23 CST 2020
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
|
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
package com.josyf.macrobuttons;
|
|
||||||
|
|
||||||
public class CommandObject {
|
|
||||||
|
|
||||||
public String name;
|
|
||||||
public String command;
|
|
||||||
}
|
|
@ -1,91 +1,43 @@
|
|||||||
package com.josyf.macrobuttons;
|
package com.josyf.macrobuttons;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.cedarsoftware.util.io.JsonWriter;
|
import com.cedarsoftware.util.io.JsonWriter;
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import com.josyf.macrobuttons.gui.ButtonGUI;
|
|
||||||
import io.netty.channel.group.ChannelGroupFuture;
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
|
||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.JSONObject;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
|
import org.json.simple.parser.*;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.logging.Level;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class ConfigFile {
|
public class ConfigFile {
|
||||||
|
|
||||||
|
private static final JSONParser parser = new JSONParser();
|
||||||
static JSONParser parser = new JSONParser();
|
|
||||||
|
|
||||||
private static FileWriter fileWriter;
|
private static FileWriter fileWriter;
|
||||||
private static FileReader fileReader;
|
|
||||||
private static File file;
|
|
||||||
//private static final String configSettings = ButtonGUI.getConfig();
|
|
||||||
|
|
||||||
public static void serializeCommand() {
|
// Read commands.json, convert it to an array, and append A JSON OBJECT
|
||||||
|
public static void appendToFile(JSONObject jsonObject) {
|
||||||
// CREATE OBJECT
|
|
||||||
CommandObject newCommand = new CommandObject();
|
|
||||||
newCommand.name = "Say Hello";
|
|
||||||
newCommand.command = "Hello";
|
|
||||||
|
|
||||||
// add new object to config
|
|
||||||
appendToFile(newCommand);
|
|
||||||
|
|
||||||
// set instance to real config
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void loadSerialization() {
|
|
||||||
String JSONConfig = ButtonGUI.getConfig();
|
|
||||||
if (JSONConfig == null) {
|
|
||||||
MacroButtons.sayMessage("GUI Configuration not yet initialized!");
|
|
||||||
} else {
|
|
||||||
//String deserializedMessage = JSON.parseObject(JSONConfig, String.class);
|
|
||||||
String deserializedMessage = readFile();
|
|
||||||
MacroButtons.sayMessage(deserializedMessage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void appendToFile(CommandObject commandObject) {
|
|
||||||
JSONArray jsonArray = new JSONArray();
|
|
||||||
try {
|
try {
|
||||||
//jsonArray = (JSONArray) parser.parse(new FileReader("commands.json"));
|
|
||||||
|
|
||||||
// if commands.json exists, read it, convert it to an array, and append
|
|
||||||
Object obj = parser.parse(new FileReader("commands.json"));
|
Object obj = parser.parse(new FileReader("commands.json"));
|
||||||
JSONArray array = (JSONArray) parser.parse(obj.toString());
|
JSONArray array = (JSONArray) obj;
|
||||||
array.add(commandObject);
|
array.add(jsonObject);
|
||||||
writeToFile(array);
|
writeToFile(array);
|
||||||
System.out.println("attempting to append");
|
} catch (IOException e) {
|
||||||
|
System.out.println("Commands.json doesn't exist. Creating one...!");
|
||||||
|
JSONArray jsonArray = new JSONArray();
|
||||||
//System.out.println(obj.getClass());
|
jsonArray.add(jsonObject);
|
||||||
System.out.println("Array size: " + array.size());
|
|
||||||
|
|
||||||
} catch (IOException e) { // commands.json doesn't exist
|
|
||||||
System.out.println("catch 1");
|
|
||||||
// create json
|
|
||||||
jsonArray.add(commandObject);
|
|
||||||
writeToFile(jsonArray);
|
writeToFile(jsonArray);
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
System.out.println("catch 2");
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// overwrites current commands.json w/ updated jsonArray
|
||||||
private static void writeToFile(JSONArray jsonArray) {
|
private static void writeToFile(JSONArray jsonArray) {
|
||||||
try {
|
try {
|
||||||
fileWriter = new FileWriter("commands.json");
|
fileWriter = new FileWriter("commands.json");
|
||||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
|
||||||
String jArrayToString = JSON.toJSONString(jsonArray);
|
String jArrayToString = JSON.toJSONString(jsonArray);
|
||||||
String formattedJson = JsonWriter.formatJson(jArrayToString);
|
String formattedJson = JsonWriter.formatJson(jArrayToString);
|
||||||
//fileWriter.write(jArrayToString);
|
|
||||||
fileWriter.write(formattedJson);
|
fileWriter.write(formattedJson);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -99,40 +51,37 @@ public class ConfigFile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeToFile(String jsonMessage) {
|
// parses commands.json into array, loop through array and add JSONObjects. returns array
|
||||||
try {
|
public static ArrayList<JSONObject> getArrayFromJsonFile() {
|
||||||
// these both write to the correct location
|
ArrayList<JSONObject> commandObjects = new ArrayList<>();
|
||||||
fileWriter = new FileWriter("commands.json");
|
|
||||||
// file = new FileWriter(MinecraftClient.getInstance().runDirectory + "/command.json");
|
|
||||||
System.out.println("APPENDING!");
|
|
||||||
|
|
||||||
fileWriter.write(jsonMessage);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
fileWriter.flush();
|
|
||||||
fileWriter.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String readFile() {
|
|
||||||
try {
|
try {
|
||||||
|
// assign array to JSONArray using our commands.json as an object
|
||||||
Object obj = parser.parse(new FileReader("commands.json"));
|
Object obj = parser.parse(new FileReader("commands.json"));
|
||||||
String jsonString = JSONObject.toJSONString(obj);
|
JSONArray array = (JSONArray) obj;
|
||||||
System.out.println(jsonString);
|
// so "array" is now a JSONArray full of JSONObjects
|
||||||
return jsonString;
|
// now we will iterate through the array and add COs to our local CO array
|
||||||
} catch (FileNotFoundException e) {
|
for (int i = 0; i < array.size(); i++) {
|
||||||
|
JSONObject childObject = (JSONObject)array.get(i);
|
||||||
|
commandObjects.add(childObject);
|
||||||
|
System.out.println(i);
|
||||||
|
if (i >= 19) break;
|
||||||
|
}
|
||||||
|
return commandObjects;
|
||||||
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return "Not yet initialized yo";
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void addObjectToCommList(JSONObject jsonObject) {
|
||||||
|
ArrayList<JSONObject> commListCopy = MacroButtons.getMasterCommList();
|
||||||
|
commListCopy.add(jsonObject);
|
||||||
|
MacroButtons.setMasterCommList(commListCopy);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,21 +10,28 @@ import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
|||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.options.KeyBinding;
|
import net.minecraft.client.options.KeyBinding;
|
||||||
import net.minecraft.client.util.InputUtil;
|
import net.minecraft.client.util.InputUtil;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class MacroButtons implements ModInitializer {
|
public class MacroButtons implements ModInitializer {
|
||||||
|
|
||||||
public static final String MOD_ID = "mgbuttons";
|
public static final String MOD_ID = "mgbuttons";
|
||||||
|
private static ArrayList<JSONObject> masterCommList;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
assignGuiToKey();
|
assignGuiToKey();
|
||||||
|
initArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void assignGuiToKey() {
|
private void assignGuiToKey() {
|
||||||
|
|
||||||
System.out.println("I'm getting here");
|
|
||||||
|
|
||||||
// Currently assigns to the G key
|
// Currently assigns to the G key
|
||||||
KeyBinding keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
KeyBinding keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
||||||
"key.macrobuttons.opengui", // The translation key of the keybinding's name
|
"key.macrobuttons.opengui", // The translation key of the keybinding's name
|
||||||
@ -35,23 +42,32 @@ public class MacroButtons implements ModInitializer {
|
|||||||
|
|
||||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||||
while (keyBinding.wasPressed()) {
|
while (keyBinding.wasPressed()) {
|
||||||
// client.player.sendMessage(new LiteralText("Key 1 was pressed!"), false);
|
|
||||||
MinecraftClient.getInstance().openScreen(new ButtonGUIScreen(new ButtonGUI()));
|
MinecraftClient.getInstance().openScreen(new ButtonGUIScreen(new ButtonGUI()));
|
||||||
// printMessage();
|
//client.player.closeScreen();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// player can run a command here
|
public static void runCommand(String command) {
|
||||||
public static void printMessage() {
|
MinecraftClient.getInstance().player.sendChatMessage(command);
|
||||||
MinecraftClient.getInstance().player.sendChatMessage("/seed");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sayMessage(String message) {
|
// Assign masterCommList to JSONArray<objects> (from commands.json). Runs once.
|
||||||
MinecraftClient.getInstance().player.sendChatMessage(message);
|
static void initArray() {
|
||||||
|
masterCommList = ConfigFile.getArrayFromJsonFile();
|
||||||
|
// If commands.json doesn't exist yet, start a global list variable for future creation
|
||||||
|
if (masterCommList == null) {
|
||||||
|
setMasterCommList(new ArrayList<>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ArrayList<JSONObject> getMasterCommList() {
|
||||||
|
return masterCommList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setMasterCommList(ArrayList<JSONObject> commList) {
|
||||||
|
masterCommList = commList;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,85 +8,119 @@ import io.github.cottonmc.cotton.gui.widget.WButton;
|
|||||||
import io.github.cottonmc.cotton.gui.widget.WGridPanel;
|
import io.github.cottonmc.cotton.gui.widget.WGridPanel;
|
||||||
import io.github.cottonmc.cotton.gui.widget.WTextField;
|
import io.github.cottonmc.cotton.gui.widget.WTextField;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.text.TranslatableText;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class ButtonGUI extends LightweightGuiDescription {
|
public class ButtonGUI extends LightweightGuiDescription {
|
||||||
|
|
||||||
int xValue = 0;
|
int xValue = 0;
|
||||||
int yValue = 1;
|
int yValue = 1;
|
||||||
|
|
||||||
private static String ConfigSettings = ConfigFile.readFile();
|
|
||||||
|
|
||||||
public ButtonGUI() {
|
public ButtonGUI() {
|
||||||
|
|
||||||
// initialize root panel of GUI
|
// initialize root panel of GUI
|
||||||
WGridPanel root = new WGridPanel();
|
WGridPanel root = new WGridPanel();
|
||||||
|
|
||||||
setupBackground(root);
|
setupBackground(root);
|
||||||
|
|
||||||
// example button to create config JSON
|
|
||||||
WButton button = new WButton(new TranslatableText("Serialize"));
|
|
||||||
button.setOnClick(() -> {
|
|
||||||
MacroButtons.printMessage();
|
|
||||||
ConfigFile.serializeCommand();
|
|
||||||
});
|
|
||||||
root.add(button, xValue, yValue, 4, 1);
|
|
||||||
|
|
||||||
// example load serialization button
|
|
||||||
WButton button2 = new WButton(new TranslatableText("Load Serialization"));
|
|
||||||
button2.setOnClick(() -> {
|
|
||||||
MacroButtons.printMessage();
|
|
||||||
ConfigFile.loadSerialization();
|
|
||||||
});
|
|
||||||
root.add(button2, xValue + 4, yValue, 6, 1);
|
|
||||||
|
|
||||||
// read json file button
|
|
||||||
WButton button3 = new WButton(new TranslatableText("Read command json"));
|
|
||||||
button3.setOnClick(() -> {
|
|
||||||
ConfigFile.readFile();
|
|
||||||
});
|
|
||||||
root.add(button3, xValue + 10, yValue, 6, 1);
|
|
||||||
|
|
||||||
// Text GUI, not needed yet
|
// Text GUI, not needed yet
|
||||||
// WLabel label = new WLabel(new LiteralText("Test"), 0xFFFFFF);
|
// WLabel label = new WLabel(new LiteralText("Test"), 0xFFFFFF);
|
||||||
// root.add(label, 0, 4, 2, 1);
|
// root.add(label, 0, 4, 2, 1);
|
||||||
|
|
||||||
|
addSavedButtons(root);
|
||||||
addCommandSection(root);
|
addCommandSection(root);
|
||||||
|
|
||||||
root.validate(this);
|
root.validate(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getConfig() {
|
|
||||||
return ConfigSettings;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addCommandSection(WGridPanel root) {
|
private void addCommandSection(WGridPanel root) {
|
||||||
// Add text field for command entry
|
// Add text field for command NAME entry
|
||||||
WTextField textField = new WTextField();
|
WTextField nameTextField = new WTextField();
|
||||||
root.add(textField, 6, 12, 6, 1);
|
nameTextField.setMaxLength(10);
|
||||||
|
nameTextField.setSuggestion("Name");
|
||||||
|
root.add(nameTextField, 0, 12, 6, 1);
|
||||||
|
|
||||||
|
// Add text field for command / entry
|
||||||
|
WTextField commandTextField = new WTextField();
|
||||||
|
commandTextField.setSuggestion("/command");
|
||||||
|
commandTextField.setMaxLength(100);
|
||||||
|
root.add(commandTextField, 6, 12, 11, 1);
|
||||||
|
|
||||||
// Add button for command entry
|
// Add button for command entry
|
||||||
WButton addCmdBtn = new WButton(new TranslatableText("+"));
|
WButton addCmdBtn = new WButton(new TranslatableText("+"));
|
||||||
addCmdBtn.setOnClick(() -> {
|
addCmdBtn.setOnClick(() -> {
|
||||||
addGUIButton(root, xValue);
|
addGUIButton(root, nameTextField, commandTextField);
|
||||||
});
|
});
|
||||||
root.add(addCmdBtn, 13, 12, 1, 1);
|
root.add(addCmdBtn, 18, 12, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addGUIButton(WGridPanel root, int x) {
|
// Function to save newly added buttons to commands.json
|
||||||
WButton button = new WButton(new TranslatableText("Button"));
|
private void addGUIButton(WGridPanel root, WTextField name, WTextField command) {
|
||||||
button.setOnClick(() -> {
|
// Only add the button if there are contents in both
|
||||||
// MacroButtons.printMessage();
|
if (!name.getText().equals("") && !command.getText().equals("")) {
|
||||||
});
|
|
||||||
// int newX = incrementNumber(x, 4);
|
|
||||||
System.out.println("x val: " + xValue);
|
|
||||||
System.out.println("y val: " + yValue);
|
|
||||||
|
|
||||||
|
if (!isListTooLong()) {
|
||||||
|
String commandString = command.getText();
|
||||||
|
WButton button = new WButton(new TranslatableText(name.getText()));
|
||||||
|
button.setOnClick(() -> {
|
||||||
|
MacroButtons.runCommand(commandString);
|
||||||
|
});
|
||||||
root.add(button, xValue, yValue, 4, 1);
|
root.add(button, xValue, yValue, 4, 1);
|
||||||
|
|
||||||
|
// Create a new Json object & append to masterCommList
|
||||||
|
JSONObject newJsonObject = new JSONObject();
|
||||||
|
newJsonObject.put("name", name.getText());
|
||||||
|
newJsonObject.put("command", command.getText());
|
||||||
|
|
||||||
|
// // append the buttons to masterList for future loading
|
||||||
|
ConfigFile.addObjectToCommList(newJsonObject);
|
||||||
|
ConfigFile.appendToFile(newJsonObject);
|
||||||
|
|
||||||
adjustBounds();
|
adjustBounds();
|
||||||
|
}
|
||||||
|
|
||||||
|
name.setText("");
|
||||||
|
command.setText("");
|
||||||
|
|
||||||
|
root.validate(this);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
System.out.println("No name and value entered!");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// function to load buttons from commands.json
|
||||||
|
private void addGUIButton(WGridPanel root, String name, String command) {
|
||||||
|
if (!name.equals("") && !command.equals("")) {
|
||||||
|
WButton button = new WButton(new TranslatableText(name));
|
||||||
|
button.setOnClick(() -> {
|
||||||
|
MacroButtons.runCommand(command);
|
||||||
|
});
|
||||||
|
root.add(button, xValue, yValue, 4, 1);
|
||||||
|
adjustBounds();
|
||||||
|
root.validate(this);
|
||||||
|
} else {
|
||||||
|
System.out.println("No name and value entered!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Array will contain String class types. Convert these to objects.
|
||||||
|
private void addSavedButtons(WGridPanel root) {
|
||||||
|
ArrayList<JSONObject> commListCopy = MacroButtons.getMasterCommList();
|
||||||
|
// Then convert the objects to buttons
|
||||||
|
if (commListCopy != null) {
|
||||||
|
for (int i = 0; i < commListCopy.size(); i++) {
|
||||||
|
String name = commListCopy.get(i).get("name").toString();
|
||||||
|
String command = commListCopy.get(i).get("command").toString();
|
||||||
|
addGUIButton(root, name, command);
|
||||||
|
if (i >= 19) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void adjustBounds() {
|
private void adjustBounds() {
|
||||||
if (xValue % 12 == 0 && xValue != 0) {
|
if (xValue % 12 == 0 && xValue != 0) {
|
||||||
yValue += 2;
|
yValue += 2;
|
||||||
@ -96,6 +130,10 @@ public class ButtonGUI extends LightweightGuiDescription {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isListTooLong() {
|
||||||
|
return MacroButtons.getMasterCommList().size() > 19;
|
||||||
|
}
|
||||||
|
|
||||||
// Change background panel color to transparent black
|
// Change background panel color to transparent black
|
||||||
@Override
|
@Override
|
||||||
public void addPainters() {
|
public void addPainters() {
|
||||||
@ -105,7 +143,7 @@ public class ButtonGUI extends LightweightGuiDescription {
|
|||||||
|
|
||||||
private void setupBackground(WGridPanel root) {
|
private void setupBackground(WGridPanel root) {
|
||||||
setRootPanel(root);
|
setRootPanel(root);
|
||||||
root.setSize(300, 240);
|
root.setSize(350, 240);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package com.josyf.macrobuttons.gui;
|
package com.josyf.macrobuttons.gui;
|
||||||
|
|
||||||
import io.github.cottonmc.cotton.gui.GuiDescription;
|
import io.github.cottonmc.cotton.gui.GuiDescription;
|
||||||
import io.github.cottonmc.cotton.gui.client.BackgroundPainter;
|
|
||||||
import io.github.cottonmc.cotton.gui.client.CottonClientScreen;
|
import io.github.cottonmc.cotton.gui.client.CottonClientScreen;
|
||||||
|
|
||||||
public class ButtonGUIScreen extends CottonClientScreen {
|
public class ButtonGUIScreen extends CottonClientScreen {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"schemaVersion": 1,
|
"schemaVersion": 1,
|
||||||
"id": "mgbuttons",
|
"id": "macro-gui-buttons",
|
||||||
"version": "${version}",
|
"version": "${version}",
|
||||||
|
|
||||||
"name": "Macro GUI Buttons",
|
"name": "Macro GUI Buttons",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user