2020-01-20 21:01:12 +01:00
|
|
|
package arm.ui;
|
|
|
|
|
|
|
|
|
|
import haxe.io.Bytes;
|
|
|
|
|
import zui.Zui;
|
|
|
|
|
import zui.Ext;
|
|
|
|
|
import zui.Id;
|
|
|
|
|
import kha.Blob;
|
|
|
|
|
import iron.data.Data;
|
|
|
|
|
import arm.sys.Path;
|
|
|
|
|
import arm.io.ImportAsset;
|
2020-09-07 14:44:01 +02:00
|
|
|
import arm.Enums;
|
2020-01-20 21:01:12 +01:00
|
|
|
|
|
|
|
|
class TabScript {
|
|
|
|
|
|
|
|
|
|
public static var hscript = Id.handle();
|
|
|
|
|
|
|
|
|
|
@:access(zui.Zui)
|
|
|
|
|
public static function draw() {
|
2020-03-18 20:26:28 +01:00
|
|
|
var ui = UISidebar.inst.ui;
|
2020-09-07 14:44:01 +02:00
|
|
|
var statush = Config.raw.layout[LayoutStatusH];
|
|
|
|
|
if (ui.tab(UIStatus.inst.statustab, tr("Script")) && statush > UIStatus.defaultStatusH * ui.SCALE()) {
|
2020-01-20 21:01:12 +01:00
|
|
|
|
2020-07-08 23:51:42 +02:00
|
|
|
ui.beginSticky();
|
2021-10-18 13:14:06 +02:00
|
|
|
#if arm_touchui
|
|
|
|
|
ui.row([1 / 4, 1 / 4, 1 / 4, 1 / 4]);
|
|
|
|
|
#else
|
2021-08-05 15:01:59 +02:00
|
|
|
ui.row([1 / 14, 1 / 14, 1 / 14, 1 / 14]);
|
2021-10-18 13:14:06 +02:00
|
|
|
#end
|
2020-03-17 19:16:19 +01:00
|
|
|
if (ui.button(tr("Run"))) {
|
2020-01-20 21:01:12 +01:00
|
|
|
try {
|
2020-11-27 13:26:08 +01:00
|
|
|
js.Lib.eval(hscript.text);
|
2020-01-20 21:01:12 +01:00
|
|
|
}
|
|
|
|
|
catch(e: Dynamic) {
|
2021-05-06 16:44:25 +02:00
|
|
|
Console.log(e);
|
2020-01-20 21:01:12 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-03-17 19:16:19 +01:00
|
|
|
if (ui.button(tr("Clear"))) {
|
2020-01-20 21:01:12 +01:00
|
|
|
hscript.text = "";
|
|
|
|
|
}
|
2020-03-17 19:16:19 +01:00
|
|
|
if (ui.button(tr("Import"))) {
|
2021-06-29 11:04:16 +02:00
|
|
|
UIFiles.show("js", false, false, function(path: String) {
|
2020-01-20 21:01:12 +01:00
|
|
|
Data.getBlob(path, function(b: Blob) {
|
|
|
|
|
hscript.text = b.toString();
|
|
|
|
|
Data.deleteBlob(path);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-03-17 19:16:19 +01:00
|
|
|
if (ui.button(tr("Export"))) {
|
2020-01-20 21:01:12 +01:00
|
|
|
var str = hscript.text;
|
2021-06-29 11:04:16 +02:00
|
|
|
UIFiles.show("js", true, false, function(path: String) {
|
2020-01-20 21:01:12 +01:00
|
|
|
var f = UIFiles.filename;
|
2020-03-17 19:16:19 +01:00
|
|
|
if (f == "") f = tr("untitled");
|
2020-02-16 21:50:14 +01:00
|
|
|
path = path + Path.sep + f;
|
2020-01-20 21:01:12 +01:00
|
|
|
if (!path.endsWith(".js")) path += ".js";
|
|
|
|
|
Krom.fileSaveBytes(path, Bytes.ofString(str).getData());
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-07-08 23:51:42 +02:00
|
|
|
ui.endSticky();
|
2020-01-20 21:01:12 +01:00
|
|
|
|
|
|
|
|
var _font = ui.ops.font;
|
|
|
|
|
var _fontSize = ui.fontSize;
|
2020-03-21 13:25:44 +01:00
|
|
|
Data.getFont("font_mono.ttf", function(f: kha.Font) { ui.ops.font = f; }); // Sync
|
2020-01-20 21:01:12 +01:00
|
|
|
ui.fontSize = 15;
|
|
|
|
|
Ext.textArea(ui, hscript);
|
|
|
|
|
ui.ops.font = _font;
|
|
|
|
|
ui.fontSize = _fontSize;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|