|
@@ -5,6 +5,7 @@ import java.awt.event.KeyEvent;
|
|
|
import java.awt.event.MouseEvent;
|
|
|
import java.awt.event.WindowAdapter;
|
|
|
import java.awt.event.WindowEvent;
|
|
|
+import java.util.function.Consumer;
|
|
|
import javax.swing.JFrame;
|
|
|
import javax.swing.event.MouseInputAdapter;
|
|
|
import me.hammerle.code.Script;
|
|
@@ -30,7 +31,7 @@ public class GraphicFrame extends JFrame
|
|
|
@Override
|
|
|
public void windowClosing(WindowEvent evt)
|
|
|
{
|
|
|
- windowClosingEvent(evt);
|
|
|
+ generalEvent("window-closing", (sc) -> {});
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -63,36 +64,33 @@ public class GraphicFrame extends JFrame
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- private void windowClosingEvent(WindowEvent e)
|
|
|
+ private void generalEvent(String name, Consumer<Script> f)
|
|
|
{
|
|
|
- if(parent.isLoadedEvent("window-closing"))
|
|
|
+ if(parent.isLoadedEvent(name))
|
|
|
{
|
|
|
- parent.setVar("event", "window-closing");
|
|
|
+ parent.setVar("event", name);
|
|
|
+ f.accept(parent);
|
|
|
parent.runCode();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void keyEvent(KeyEvent e, String name)
|
|
|
{
|
|
|
- if(parent.isLoadedEvent("key-" + name))
|
|
|
+ generalEvent("key-" + name, sc ->
|
|
|
{
|
|
|
- parent.setVar("event", "key-" + name);
|
|
|
- parent.setVar("keycode", e.getKeyCode());
|
|
|
- parent.setVar("keychar", e.getKeyChar());
|
|
|
- parent.runCode();
|
|
|
- }
|
|
|
+ sc.setVar("keycode", e.getKeyCode());
|
|
|
+ sc.setVar("keychar", e.getKeyChar());
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
private void mouseEvent(MouseEvent e, String name)
|
|
|
{
|
|
|
- if(parent.isLoadedEvent("mouse-" + name))
|
|
|
+ generalEvent("mouse-" + name, sc ->
|
|
|
{
|
|
|
- parent.setVar("event", "mouse-" + name);
|
|
|
parent.setVar("button", e.getButton());
|
|
|
parent.setVar("count", e.getClickCount());
|
|
|
parent.setVar("x", e.getX());
|
|
|
parent.setVar("y", e.getY());
|
|
|
- parent.runCode();
|
|
|
- }
|
|
|
+ });
|
|
|
}
|
|
|
}
|