add button adds name and command to GUI

This commit is contained in:
Joseph 2020-12-14 15:01:11 -06:00
parent 81a66dd837
commit 4ee594b033
2 changed files with 36 additions and 19 deletions

View File

@ -43,8 +43,8 @@ public class MacroButtons implements ModInitializer {
} }
// player can run a command here // player can run a command here
public static void printMessage() { public static void printMessage(String savedCommand) {
MinecraftClient.getInstance().player.sendChatMessage("/seed"); MinecraftClient.getInstance().player.sendChatMessage(savedCommand);
} }
public static void sayMessage(String message) { public static void sayMessage(String message) {

View File

@ -27,7 +27,7 @@ public class ButtonGUI extends LightweightGuiDescription {
// example button to create config JSON // example button to create config JSON
WButton button = new WButton(new TranslatableText("Serialize")); WButton button = new WButton(new TranslatableText("Serialize"));
button.setOnClick(() -> { button.setOnClick(() -> {
MacroButtons.printMessage(); MacroButtons.printMessage("serializing");
ConfigFile.serializeCommand(); ConfigFile.serializeCommand();
}); });
root.add(button, xValue, yValue + 9, 4, 1); root.add(button, xValue, yValue + 9, 4, 1);
@ -35,7 +35,7 @@ public class ButtonGUI extends LightweightGuiDescription {
// example load serialization button // example load serialization button
WButton button2 = new WButton(new TranslatableText("Load Serialization")); WButton button2 = new WButton(new TranslatableText("Load Serialization"));
button2.setOnClick(() -> { button2.setOnClick(() -> {
MacroButtons.printMessage(); MacroButtons.printMessage("load serialization");
ConfigFile.loadSerialization(); ConfigFile.loadSerialization();
}); });
root.add(button2, xValue + 4, yValue + 9, 6, 1); root.add(button2, xValue + 4, yValue + 9, 6, 1);
@ -65,33 +65,50 @@ public class ButtonGUI extends LightweightGuiDescription {
// Add text field for command NAME entry // Add text field for command NAME entry
WTextField nameTextField = new WTextField(); WTextField nameTextField = new WTextField();
nameTextField.setSuggestion("Name"); nameTextField.setSuggestion("Name");
root.add(nameTextField, 5, 12, 6, 1); root.add(nameTextField, 0, 12, 6, 1);
// Add text field for command / entry // Add text field for command / entry
WTextField textField = new WTextField(); WTextField commandTextField = new WTextField();
textField.setSuggestion("/command"); commandTextField.setSuggestion("/command");
root.add(textField, 11, 12, 6, 1); 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, xValue, nameTextField, commandTextField);
}); });
root.add(addCmdBtn, 18, 12, 1, 1); root.add(addCmdBtn, 18, 12, 1, 1);
} }
private void addGUIButton(WGridPanel root, int x) { private void addGUIButton(WGridPanel root, int x, WTextField name, WTextField command) {
WButton button = new WButton(new TranslatableText("Button")); // Only add the button if there are contents in both
button.setOnClick(() -> { if (!name.getText().equals("") && !command.getText().equals("")) {
// MacroButtons.printMessage();
});
// int newX = incrementNumber(x, 4);
System.out.println("x val: " + xValue);
System.out.println("y val: " + yValue);
root.add(button, xValue, yValue, 4, 1); System.out.println("Here, command is " + command.getText());
String instancedString = command.getText();
adjustBounds(); WButton button = new WButton(new TranslatableText(name.getText()));
button.setOnClick(() -> {
MacroButtons.printMessage(instancedString);
System.out.println("Command was " + instancedString);
});
// int newX = incrementNumber(x, 4);
System.out.println("x val: " + xValue);
System.out.println("y val: " + yValue);
root.add(button, xValue, yValue, 4, 1);
adjustBounds();
name.setText("");
command.setText("");
root.validate(this);
} else {
System.out.println("No name and value entered!");
}
} }