mirror of
https://github.com/2006-Scape/Script-Factory.git
synced 2026-07-02 16:49:10 +00:00
Made it Java 1.7 LOL
This commit is contained in:
@@ -50,7 +50,12 @@ public class Action {
|
||||
|
||||
public int[] getParamArray()
|
||||
{
|
||||
return params.stream().mapToInt(Integer::parseInt).toArray();
|
||||
int[] array = new int[params.size()];
|
||||
for (int i = 0; i < params.size(); i++) {
|
||||
array[i] = Integer.parseInt(params.get(i));
|
||||
}
|
||||
return array;
|
||||
//return params.stream().mapToInt(Integer::parseInt).toArray();
|
||||
}
|
||||
|
||||
public Action(String action, ArrayList<JTextArea> inputs) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package scriptfactory.Actions;
|
||||
|
||||
import org.parabot.environment.api.utils.Filter;
|
||||
import org.parabot.environment.api.utils.Time;
|
||||
import org.parabot.environment.input.Keyboard;
|
||||
import org.parabot.environment.input.Mouse;
|
||||
@@ -97,9 +98,14 @@ public class ActionHandler {
|
||||
Time.sleep(a.getParam(2));
|
||||
}
|
||||
|
||||
public void handleGroundItemInteract(Action a) {
|
||||
public void handleGroundItemInteract(final Action a) {
|
||||
try {
|
||||
GroundItem item = GroundItems.getNearest(o -> o.getId() == a.getParam(0))[0];
|
||||
GroundItem item = GroundItems.getNearest(new Filter<GroundItem>() {
|
||||
@Override
|
||||
public boolean accept(GroundItem o) {
|
||||
return o.getId() == a.getParam(0);
|
||||
}
|
||||
})[0];
|
||||
if (item == null)
|
||||
{
|
||||
log("Could not find item with id" + a.getParam(0));
|
||||
@@ -121,20 +127,40 @@ public class ActionHandler {
|
||||
Bank.depositAllExcept(a.getParamArray());
|
||||
}
|
||||
|
||||
private void interactWithEntity(int[] id, String option)
|
||||
private void interactWithEntity(final int[] id, String option)
|
||||
{
|
||||
SceneObject candidateObject = SceneObjects.getClosest(id);
|
||||
Npc candidateNpc = Npcs.getClosest(o -> !o.isInCombat() && Arrays.stream(id).anyMatch(i -> i == o.getDef().getId()));
|
||||
Npc candidateNpc = Npcs.getClosest(new Filter<Npc>() {
|
||||
@Override
|
||||
public boolean accept(Npc o) {
|
||||
for (int i1 : id) {
|
||||
if (o.getDef().getId() == i1) {
|
||||
return !o.isInCombat();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
debugString = "id: " + Arrays.toString(id);
|
||||
tryToInteract(candidateObject, candidateNpc, option);
|
||||
}
|
||||
|
||||
private void interactWithEntityByTile(Tile tile, String option) {
|
||||
SceneObject[] sos = SceneObjects.getNearest(o -> o.getLocation().equals(tile));
|
||||
private void interactWithEntityByTile(final Tile tile, String option) {
|
||||
SceneObject[] sos = SceneObjects.getNearest(new Filter<SceneObject>() {
|
||||
@Override
|
||||
public boolean accept(SceneObject o) {
|
||||
return o.getLocation().equals(tile);
|
||||
}
|
||||
});
|
||||
SceneObject candidateObject = null;
|
||||
if (sos.length > 0)
|
||||
candidateObject = sos[0];
|
||||
Npc[] npca = Npcs.getNearest(o -> o.getLocation().equals(tile));
|
||||
Npc[] npca = Npcs.getNearest(new Filter<Npc>() {
|
||||
@Override
|
||||
public boolean accept(Npc o) {
|
||||
return o.getLocation().equals(tile);
|
||||
}
|
||||
});
|
||||
Npc candidateNpc = null;
|
||||
if (npca.length > 0)
|
||||
candidateNpc = npca[0];
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package scriptfactory.Actions.Logic;
|
||||
|
||||
import org.parabot.environment.api.utils.Filter;
|
||||
import org.rev317.min.api.wrappers.GroundItem;
|
||||
import scriptfactory.Actions.Action;
|
||||
import org.rev317.min.api.methods.*;
|
||||
|
||||
@@ -9,7 +11,7 @@ import static scriptfactory.VarsMethods.log;
|
||||
import static scriptfactory.VarsMethods.toPintArray;
|
||||
|
||||
public class LogicHandler {
|
||||
public boolean determineIf(Action a) {
|
||||
public boolean determineIf(final Action a) {
|
||||
switch (a.getMethod().replaceAll("-", " "))
|
||||
{
|
||||
case "Item is in Inventory":
|
||||
@@ -17,7 +19,12 @@ public class LogicHandler {
|
||||
case "Inventory slots used":
|
||||
return Inventory.getCount() >= a.getParam(0);
|
||||
case "Item is on Ground":
|
||||
return GroundItems.getGroundItems(o-> o.getId() == a.getParam(0)).length > 0;
|
||||
return GroundItems.getGroundItems(new Filter<GroundItem>() {
|
||||
@Override
|
||||
public boolean accept(GroundItem o) {
|
||||
return o.getId() == a.getParam(0);
|
||||
}
|
||||
}).length > 0;
|
||||
case "Entity is around":
|
||||
ArrayList<Integer> ids = new ArrayList<>();
|
||||
for (int i = 0; i < a.getParamCount(); i++)
|
||||
|
||||
@@ -2,15 +2,17 @@ package scriptfactory.AdvancedGui;
|
||||
|
||||
import scriptfactory.Actions.Action;
|
||||
import scriptfactory.AdvancedGui.ScriptFactorySDN.ScriptFactorySDNGui;
|
||||
import scriptfactory.Consumer;
|
||||
import scriptfactory.GUI.EnterJButton;
|
||||
import scriptfactory.NewGuis.UncommonActionGuiInfo;
|
||||
import scriptfactory.VarsMethods;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static scriptfactory.NewGuis.NewStatementGUI.addEscapeHotkey;
|
||||
import static scriptfactory.VarsMethods.log;
|
||||
@@ -71,8 +73,8 @@ public class AdvancedOptionsGUI extends JFrame {
|
||||
}
|
||||
|
||||
private void generateMoveLineFrame() {
|
||||
JTextField lineToMove = new JTextField(6);
|
||||
JTextField lineToInsertAbove = new JTextField(6);
|
||||
final JTextField lineToMove = new JTextField(6);
|
||||
final JTextField lineToInsertAbove = new JTextField(6);
|
||||
EnterJButton submitMove = new EnterJButton("Submit");
|
||||
|
||||
moveLineFrame.setLayout(new GridLayout(5, 1, 5, 15));
|
||||
@@ -87,49 +89,64 @@ public class AdvancedOptionsGUI extends JFrame {
|
||||
|
||||
moveLineFrame.pack();
|
||||
|
||||
submitMove.addActionListener(b ->
|
||||
{
|
||||
int lineToMoveAsPint = VarsMethods.parsePint(lineToMove.getText());
|
||||
int lineToPlaceAboveAsPint = VarsMethods.parsePint(lineToInsertAbove.getText());
|
||||
submitMove.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent b) {
|
||||
int lineToMoveAsPint = VarsMethods.parsePint(lineToMove.getText());
|
||||
int lineToPlaceAboveAsPint = VarsMethods.parsePint(lineToInsertAbove.getText());
|
||||
|
||||
Action removed = actions.remove(lineToMoveAsPint);
|
||||
if (lineToPlaceAboveAsPint <= lineToMoveAsPint)
|
||||
actions.add(lineToPlaceAboveAsPint, removed);
|
||||
else
|
||||
if (lineToPlaceAboveAsPint > actions.size())
|
||||
Action removed = actions.remove(lineToMoveAsPint);
|
||||
if (lineToPlaceAboveAsPint <= lineToMoveAsPint)
|
||||
actions.add(lineToPlaceAboveAsPint, removed);
|
||||
else if (lineToPlaceAboveAsPint > actions.size())
|
||||
actions.add(removed);
|
||||
else
|
||||
actions.add(lineToPlaceAboveAsPint - 1, removed);
|
||||
updateTextfield.accept(5);
|
||||
moveLineFrame.setVisible(false);
|
||||
log("Successfully moved line " + lineToMove.getText() + ".");
|
||||
updateTextfield.accept(5);
|
||||
moveLineFrame.setVisible(false);
|
||||
log("Successfully moved line " + lineToMove.getText() + ".");
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void initButtons()
|
||||
{
|
||||
tipsAndTricksButton.addActionListener(o -> {
|
||||
tipsFrame.setVisible(true);
|
||||
this.setVisible(false);
|
||||
tipsAndTricksButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent o) {
|
||||
tipsFrame.setVisible(true);
|
||||
AdvancedOptionsGUI.this.setVisible(false);
|
||||
}
|
||||
});
|
||||
moveLineButton.addActionListener(o -> {
|
||||
moveLineFrame.setVisible(true);
|
||||
this.setVisible(false);
|
||||
moveLineButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent o) {
|
||||
moveLineFrame.setVisible(true);
|
||||
AdvancedOptionsGUI.this.setVisible(false);
|
||||
}
|
||||
});
|
||||
recoverPreviousScript.addActionListener(o ->
|
||||
{
|
||||
VarsMethods.loadscript(actions, new File(VarsMethods.CACHED_LOC));
|
||||
updateTextfield.accept(5);
|
||||
this.setVisible(false);
|
||||
recoverPreviousScript.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent o) {
|
||||
VarsMethods.loadscript(actions, new File(VarsMethods.CACHED_LOC));
|
||||
updateTextfield.accept(5);
|
||||
AdvancedOptionsGUI.this.setVisible(false);
|
||||
}
|
||||
});
|
||||
uncommonActionButton.addActionListener(o -> {
|
||||
uncommonActionGui.setVisible(true);
|
||||
this.setVisible(false);
|
||||
uncommonActionButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent o) {
|
||||
uncommonActionGui.setVisible(true);
|
||||
AdvancedOptionsGUI.this.setVisible(false);
|
||||
}
|
||||
});
|
||||
premadeScriptsButton.addActionListener(o -> {
|
||||
sdnGui.setVisible(true);
|
||||
this.setVisible(false);
|
||||
premadeScriptsButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent o) {
|
||||
sdnGui.setVisible(true);
|
||||
AdvancedOptionsGUI.this.setVisible(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreeCellRenderer;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
@@ -169,20 +171,26 @@ public class ScriptFactorySDNGui extends JFrame {
|
||||
|
||||
JButton cmdStart = new JButton("Download");
|
||||
cmdStart.setBounds(WIDTH - 156 - 4, HEIGHT - 24 - 4, 156, 24);
|
||||
cmdStart.addActionListener(e -> {
|
||||
String s = getScriptName(tree.getSelectionPath().toString());
|
||||
downloadScript(format.get(s));
|
||||
JOptionPane.showMessageDialog(null, "Script downloaded successfully. You can now run it by clicking \"Load\" in the main menu.");
|
||||
cmdStart.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
String s = ScriptFactorySDNGui.this.getScriptName(tree.getSelectionPath().toString());
|
||||
ScriptFactorySDNGui.this.downloadScript(format.get(s));
|
||||
JOptionPane.showMessageDialog(null, "Script downloaded successfully. You can now run it by clicking \"Load\" in the main menu.");
|
||||
}
|
||||
});
|
||||
|
||||
JButton cmdHome = new JButton("Open home");
|
||||
cmdHome.setBounds(WIDTH - (96 * 2 + 60) - 4 - 32, HEIGHT - 24 - 4, 96 + 32,
|
||||
24);
|
||||
cmdHome.addActionListener(e -> {
|
||||
try {
|
||||
Desktop.getDesktop().open(new File(DEFAULT_DIR));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
cmdHome.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
Desktop.getDesktop().open(new File(DEFAULT_DIR));
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package scriptfactory;
|
||||
|
||||
public interface Consumer<T> {
|
||||
void accept(T t);
|
||||
}
|
||||
@@ -8,7 +8,7 @@ public class EnterJButton extends JButton {
|
||||
public EnterJButton(String text)
|
||||
{
|
||||
super(text);
|
||||
EnterJButton me = this;
|
||||
final EnterJButton me = this;
|
||||
this.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent keyEvent) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import scriptfactory.Actions.Logic.If;
|
||||
import scriptfactory.Actions.Logic.Endif;
|
||||
import scriptfactory.Actions.Action;
|
||||
import scriptfactory.Actions.Logic.IfNot;
|
||||
import scriptfactory.Consumer;
|
||||
import scriptfactory.GUI.MainPanels.ActionPanel;
|
||||
import scriptfactory.AdvancedGui.AdvancedOptionsGUI;
|
||||
import scriptfactory.NewGuis.ActionGuiInfo;
|
||||
@@ -14,12 +15,14 @@ import javax.swing.*;
|
||||
import javax.swing.border.EtchedBorder;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static scriptfactory.VarsMethods.log;
|
||||
|
||||
|
||||
/**
|
||||
* Created by Cyn on 1/9/2018.
|
||||
*/
|
||||
@@ -41,12 +44,12 @@ public class GUI extends JFrame {
|
||||
private AdvancedOptionsGUI advancedOptions;
|
||||
private ArrayList<Action> actions;
|
||||
|
||||
public GUI(ArrayList<Action> actions)
|
||||
public GUI(final ArrayList<Action> actions)
|
||||
{
|
||||
this.actions = actions;
|
||||
|
||||
//These are like little functions we pass around
|
||||
Consumer<Integer> updateTextfield = (Integer i) -> {
|
||||
/*Consumer<Integer> updateTextfield = (Integer i) -> {
|
||||
updateActionList();
|
||||
};
|
||||
Consumer<Integer> removeAction = (Integer toRemove) -> {
|
||||
@@ -58,6 +61,28 @@ public class GUI extends JFrame {
|
||||
Consumer<Boolean> endIf = (Boolean remove) -> {
|
||||
actions.add(new Endif());
|
||||
updateTextfield.accept(1);
|
||||
};*/
|
||||
final Consumer<Integer> updateTextfield = new Consumer<Integer>() {
|
||||
@Override
|
||||
public void accept(Integer i) {
|
||||
GUI.this.updateActionList();
|
||||
}
|
||||
};
|
||||
Consumer<Integer> removeAction = new Consumer<Integer>() {
|
||||
@Override
|
||||
public void accept(Integer toRemove) {
|
||||
log("Trying to remove " + toRemove);
|
||||
int pint = toRemove;
|
||||
actions.remove(pint);
|
||||
GUI.this.updateActionList();
|
||||
}
|
||||
};
|
||||
Consumer<Boolean> endIf = new Consumer<Boolean>() {
|
||||
@Override
|
||||
public void accept(Boolean remove) {
|
||||
actions.add(new Endif());
|
||||
updateTextfield.accept(1);
|
||||
}
|
||||
};
|
||||
|
||||
newAction = new ActionGuiInfo(actions, updateTextfield);
|
||||
@@ -82,34 +107,45 @@ public class GUI extends JFrame {
|
||||
}
|
||||
|
||||
private void addActionListeners() {
|
||||
startButton.addActionListener(o -> {
|
||||
this.setVisible(false);
|
||||
log("Executing the following script:");
|
||||
for (Action a : actions)
|
||||
{
|
||||
log(a.toString());
|
||||
startButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent o) {
|
||||
GUI.this.setVisible(false);
|
||||
log("Executing the following script:");
|
||||
for (Action a : actions) {
|
||||
log(a.toString());
|
||||
}
|
||||
VarsMethods.tickSpeed = VarsMethods.parsePint(tickSpeedField.getText());
|
||||
selectedFile = new File(VarsMethods.CACHED_LOC);
|
||||
GUI.this.saveContents();
|
||||
scriptStarted = true;
|
||||
}
|
||||
VarsMethods.tickSpeed = VarsMethods.parsePint(tickSpeedField.getText());
|
||||
selectedFile = new File(VarsMethods.CACHED_LOC);
|
||||
saveContents();
|
||||
scriptStarted = true;
|
||||
});
|
||||
|
||||
saveButton.addActionListener(o -> {
|
||||
if (updateFile())
|
||||
saveContents();
|
||||
saveButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent o) {
|
||||
if (GUI.this.updateFile())
|
||||
GUI.this.saveContents();
|
||||
}
|
||||
});
|
||||
|
||||
loadButton.addActionListener(o -> {
|
||||
if (updateFile())
|
||||
loadContents();
|
||||
loadButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent o) {
|
||||
if (GUI.this.updateFile())
|
||||
GUI.this.loadContents();
|
||||
}
|
||||
});
|
||||
|
||||
addSleepButton.addActionListener(o -> {
|
||||
ArrayList<JTextArea> sleepAmountFieldAsAL = new ArrayList<>();
|
||||
sleepAmountFieldAsAL.add(sleepAmountField);
|
||||
actions.add(new Action("Sleep", sleepAmountFieldAsAL));
|
||||
updateActionList();
|
||||
addSleepButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent o) {
|
||||
ArrayList<JTextArea> sleepAmountFieldAsAL = new ArrayList<>();
|
||||
sleepAmountFieldAsAL.add(sleepAmountField);
|
||||
actions.add(new Action("Sleep", sleepAmountFieldAsAL));
|
||||
GUI.this.updateActionList();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package scriptfactory.GUI.MainPanels;
|
||||
|
||||
import scriptfactory.Consumer;
|
||||
import scriptfactory.GUI.EnterJButton;
|
||||
import scriptfactory.AdvancedGui.AdvancedOptionsGUI;
|
||||
import scriptfactory.NewGuis.ActionGuiInfo;
|
||||
@@ -10,7 +11,8 @@ import javax.swing.*;
|
||||
import javax.swing.text.Style;
|
||||
import javax.swing.text.StyleConstants;
|
||||
import java.awt.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
* Created by SRH on 1/10/2018.
|
||||
@@ -65,26 +67,41 @@ public class ActionPanel extends JPanel {
|
||||
}
|
||||
|
||||
private void initButtons() {
|
||||
actionButton.addActionListener(o -> {
|
||||
newAction.setVisible(true);
|
||||
actionButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent o) {
|
||||
newAction.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
startIfButton.addActionListener(o -> {
|
||||
newCondition.setVisible(true);
|
||||
startIfButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent o) {
|
||||
newCondition.setVisible(true);
|
||||
}
|
||||
});
|
||||
|
||||
endIfButton.addActionListener(o -> {
|
||||
endIf.accept(true);
|
||||
endIfButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent o) {
|
||||
endIf.accept(true);
|
||||
}
|
||||
});
|
||||
|
||||
removeButton.addActionListener(o -> {
|
||||
String path = JOptionPane.showInputDialog("Enter the line# you wish to delete:");
|
||||
removeButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent o) {
|
||||
String path = JOptionPane.showInputDialog("Enter the line# you wish to delete:");
|
||||
|
||||
removeAction.accept(VarsMethods.parsePint(path));
|
||||
removeAction.accept(VarsMethods.parsePint(path));
|
||||
}
|
||||
});
|
||||
|
||||
advancedButton.addActionListener(o -> {
|
||||
advancedOptions.setVisible(true);
|
||||
advancedButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent o) {
|
||||
advancedOptions.setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ package scriptfactory.NewGuis;
|
||||
|
||||
|
||||
import scriptfactory.Actions.Action;
|
||||
import scriptfactory.Consumer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Created by SRH on 1/9/2018.
|
||||
|
||||
@@ -2,8 +2,9 @@ package scriptfactory.NewGuis;
|
||||
|
||||
|
||||
import scriptfactory.Actions.Action;
|
||||
import scriptfactory.Consumer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Created by SRH on 1/9/2018.
|
||||
|
||||
@@ -3,15 +3,16 @@ package scriptfactory.NewGuis;
|
||||
import scriptfactory.Actions.Action;
|
||||
import scriptfactory.Actions.Logic.If;
|
||||
import scriptfactory.Actions.Logic.IfNot;
|
||||
import scriptfactory.Consumer;
|
||||
import scriptfactory.GUI.EnterJButton;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static scriptfactory.VarsMethods.MAX_PARAMS;
|
||||
|
||||
@@ -37,7 +38,7 @@ public class NewStatementGUI extends JFrame {
|
||||
* @param actionTypes: List of possible actions the user can select
|
||||
* @param descStrings: Descriptions to display for the actions
|
||||
*/
|
||||
void initGui(String title, ArrayList<Action> actionList, Consumer<Integer> updateTextfield, String[] actionTypes, Descriptions[] descStrings) {
|
||||
void initGui(String title, final ArrayList<Action> actionList, final Consumer<Integer> updateTextfield, String[] actionTypes, Descriptions[] descStrings) {
|
||||
setTitle(title);
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
@@ -59,20 +60,26 @@ public class NewStatementGUI extends JFrame {
|
||||
|
||||
addEscapeHotkey(this);
|
||||
|
||||
add.addActionListener(o -> {
|
||||
if (this.getTitle().contains("action"))
|
||||
actionList.add(new Action(selectedAction, inputs));
|
||||
else
|
||||
actionList.add(new If(selectedAction, inputs));
|
||||
updateTextfield.accept(5);
|
||||
this.setVisible(false);
|
||||
clearInputs();
|
||||
add.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent o) {
|
||||
if (NewStatementGUI.this.getTitle().contains("action"))
|
||||
actionList.add(new Action(selectedAction, inputs));
|
||||
else
|
||||
actionList.add(new If(selectedAction, inputs));
|
||||
updateTextfield.accept(5);
|
||||
NewStatementGUI.this.setVisible(false);
|
||||
NewStatementGUI.this.clearInputs();
|
||||
}
|
||||
});
|
||||
addInverse.addActionListener(o -> {
|
||||
actionList.add(new IfNot(selectedAction, inputs));
|
||||
updateTextfield.accept(5);
|
||||
this.setVisible(false);
|
||||
clearInputs();
|
||||
addInverse.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent o) {
|
||||
actionList.add(new IfNot(selectedAction, inputs));
|
||||
updateTextfield.accept(5);
|
||||
NewStatementGUI.this.setVisible(false);
|
||||
NewStatementGUI.this.clearInputs();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -82,15 +89,18 @@ public class NewStatementGUI extends JFrame {
|
||||
* @param actionTypes: scriptfactory.Actions user can select
|
||||
* @param descs: Field descriptions for that action
|
||||
*/
|
||||
private JComboBox actionTypeCombo(String[] actionTypes, Descriptions[] descs) {
|
||||
JComboBox actionType = new JComboBox(actionTypes);
|
||||
private JComboBox actionTypeCombo(String[] actionTypes, final Descriptions[] descs) {
|
||||
final JComboBox actionType = new JComboBox(actionTypes);
|
||||
selectedAction = actionTypes[0]; //prevents null
|
||||
setupInputFields(descs[0]);
|
||||
|
||||
actionType.addActionListener(o -> {
|
||||
selectedAction = actionType.getSelectedItem().toString();
|
||||
actionType.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent o) {
|
||||
selectedAction = actionType.getSelectedItem().toString();
|
||||
|
||||
setupInputFields(descs[actionType.getSelectedIndex()]);
|
||||
NewStatementGUI.this.setupInputFields(descs[actionType.getSelectedIndex()]);
|
||||
}
|
||||
});
|
||||
|
||||
return actionType;
|
||||
@@ -145,7 +155,7 @@ public class NewStatementGUI extends JFrame {
|
||||
* Currently supports Tab, Shift Tab
|
||||
* @param textArea current TextArea to operate on
|
||||
*/
|
||||
private void setHKNavigation(JTextArea textArea) {
|
||||
private void setHKNavigation(final JTextArea textArea) {
|
||||
textArea.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent keyEvent) {
|
||||
@@ -160,8 +170,13 @@ public class NewStatementGUI extends JFrame {
|
||||
});
|
||||
}
|
||||
|
||||
public static void addEscapeHotkey(JFrame temp) {
|
||||
ActionListener escListener = e -> temp.setVisible(false);
|
||||
public static void addEscapeHotkey(final JFrame temp) {
|
||||
ActionListener escListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
temp.setVisible(false);
|
||||
}
|
||||
};
|
||||
temp.getRootPane().registerKeyboardAction(escListener,
|
||||
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
|
||||
JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package scriptfactory.NewGuis;
|
||||
|
||||
import scriptfactory.Actions.Action;
|
||||
import scriptfactory.Consumer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class UncommonActionGuiInfo extends NewStatementGUI {
|
||||
public UncommonActionGuiInfo(ArrayList<Action> actionList, Consumer<Integer> updateTextField)
|
||||
|
||||
Reference in New Issue
Block a user