This commit is contained in:
luboslenco
2018-04-18 21:35:36 +02:00
parent 3132144e2c
commit dbc1f6db0f
6 changed files with 118 additions and 17 deletions
+30 -1
View File
@@ -1,2 +1,31 @@
arm.Plugin.test();
var plugin = new arm.Plugin();
var h1 = plugin.handle();
var h2 = plugin.handle();
var h3 = plugin.handle();
var h4 = plugin.handle();
var h5 = plugin.handle();
var h6 = plugin.handle();
var h7 = plugin.handle();
plugin.drawUI = function(ui) {
if (ui.panel(h1, "My Plugin")) {
ui.text("Label");
ui.textInput(h7, "Text Input");
if (ui.button("Button")) {
plugin.log("Hello");
}
ui.row([1/2, 1/2]);
ui.button("Button A");
ui.button("Button B");
ui.combo(h5, ["Item 1", "Item 2"], "Combo");
ui.row([1/2, 1/2]);
ui.slider(h2, "Slider", 0, 1, true);
ui.slider(h3, "Slider", 0, 1, true);
ui.check(h4, "Check");
ui.radio(h6, 0, "Radio 1");
ui.radio(h6, 1, "Radio 2");
ui.radio(h6, 2, "Radio 3");
}
}
+33
View File
@@ -0,0 +1,33 @@
var plugin = new arm.Plugin();
var h1 = plugin.handle();
var h2 = plugin.handle();
var h3 = plugin.handle();
var h4 = plugin.handle();
var h5 = plugin.handle();
var h6 = plugin.handle();
var h7 = plugin.handle();
var x = 0.0;
var y = 0.0;
var z = 0.0;
plugin.drawUI = function(ui) {
if (ui.panel(h1, "Presentation Mode Plugin")) {
ui.slider(h2, "Rotate X", 0, 1, true);
ui.slider(h3, "Rotate Y", 0, 1, true);
ui.slider(h4, "Rotate Z", 0, 1, true);
}
}
plugin.update = function(ui) {
x += h2.value / 50;
y += h3.value / 50;
z += h4.value / 50;
var scene = plugin.scene();
var o = scene.meshes[0];
o.transform.setRotation(x, y, z);
}
+33 -2
View File
@@ -1,11 +1,42 @@
package arm;
// ArmorPaint plugin API
@:expose
class Plugin {
public static function keep() {}
public static function test() {
UITrait.inst.customText = "hello world";
public static var plugins:Array<Plugin> = [];
public var drawUI:zui.Zui->Void = null;
public var draw:Void->Void = null;
public var update:Void->Void = null;
public function handle(ops: zui.Zui.HandleOptions = null) {
return new zui.Zui.Handle(ops);
}
public function new() {
plugins.push(this);
}
public function log(s) {
trace(s);
}
public function scene() {
return iron.Scene.active;
}
}
// my_plugin.js
// plugin = new arm.Plugin();
// h = plugin.handle();
// plugin.drawUI = function(ui) {
// if (ui.panel(h, "My Plugin")) {
// if (ui.button("Hello")) {
// plugin.log("World");
// }
// }
// }
+1 -1
View File
@@ -49,7 +49,7 @@ class UINodes extends iron.Trait {
canvasBlob = b1.toString();
canvasBrushBlob = b2.toString();
kha.Assets.loadImage('color_wheel', function(image:kha.Image) {
kha.Assets.loadImageFromPath('color_wheel.png', false, function(image:kha.Image) {
canvas = haxe.Json.parse(canvasBlob);
canvasBrush = haxe.Json.parse(canvasBrushBlob);
+21 -13
View File
@@ -56,7 +56,7 @@ class UITrait extends iron.Trait {
function loadBundled(names:Array<String>, done:Void->Void) {
var loaded = 0;
for (s in names) {
kha.Assets.loadImage(s, function(image:kha.Image) {
kha.Assets.loadImageFromPath(s, false, function(image:kha.Image) {
bundled.set(s, image);
loaded++;
if (loaded == names.length) done();
@@ -210,7 +210,7 @@ class UITrait extends iron.Trait {
var scale = armory.data.Config.raw.window_scale;
ui = new Zui( { font: arm.App.font, scaleFactor: scale } );
loadBundled(['cursor', 'mat', 'mat_empty', 'brush', 'cay_thumb'], done);
loadBundled(['cursor.png', 'mat.jpg', 'mat_empty.jpg', 'brush.jpg', 'cay_thumb.jpg'], done);
}
function showMessage(s:String) {
@@ -270,10 +270,13 @@ class UITrait extends iron.Trait {
iron.App.notifyOnRender(clearTargetsHandler);
// Init plugins
// iron.data.Data.getBlob('my_plugin.js', function(blob:kha.Blob) {
// Plugin.keep();
// untyped __js__("(1, eval)({0})", blob.toString());
// });
Plugin.keep();
iron.data.Data.getBlob('my_plugin.js', function(blob:kha.Blob) {
untyped __js__("(1, eval)({0})", blob.toString());
});
iron.data.Data.getBlob('plugin_presentation_mode.js', function(blob:kha.Blob) {
untyped __js__("(1, eval)({0})", blob.toString());
});
});
}
@@ -290,6 +293,8 @@ class UITrait extends iron.Trait {
}
pickColorId = kb.down("alt");
for (p in Plugin.plugins) if (p.update != null) p.update();
}
function updateUI() {
@@ -444,9 +449,9 @@ class UITrait extends iron.Trait {
if (!arm.App.uienabled && ui.inputRegistered) ui.unregisterInput();
if (arm.App.uienabled && !ui.inputRegistered) ui.registerInput();
var brushImg = bundled.get('brush');
var envThumbCay = bundled.get('cay_thumb');
var cursorImg = bundled.get('cursor');
var brushImg = bundled.get('brush.jpg');
var envThumbCay = bundled.get('cay_thumb.jpg');
var cursorImg = bundled.get('cursor.png');
var mouse = iron.system.Input.getMouse();
g.color = 0xffffffff;
@@ -696,8 +701,8 @@ class UITrait extends iron.Trait {
showBrushNodes();
}
var img = bundled.get("brush");
var img2 = bundled.get("mat_empty");
var img = bundled.get("brush.jpg");
var img2 = bundled.get("mat_empty.jpg");
ui.row([1/5,1/5,1/5,1/5,1/5]);
for (i in 0...5) {
var im = img;
@@ -785,8 +790,8 @@ class UITrait extends iron.Trait {
showMaterialNodes();
}
var img = bundled.get("mat");
var img2 = bundled.get("mat_empty");
var img = bundled.get("mat.jpg");
var img2 = bundled.get("mat_empty.jpg");
ui.row([1/5,1/5,1/5,1/5,1/5]);
for (i in 0...5) {
var im = img;
@@ -822,6 +827,9 @@ class UITrait extends iron.Trait {
var cid = ui.combo(colorIdHandle, App.getEnumTexts(), "Color ID");
if (UILibrary.inst.assets.length > 0) ui.image(UITrait.inst.getImage(UILibrary.inst.assets[cid]));
}
// Draw plugins
for (p in Plugin.plugins) if (p.drawUI != null) p.drawUI(ui);
}
ui.end();
g.begin(false);
BIN
View File
Binary file not shown.