diff --git a/Assets/plugins/theme_editor.js b/Assets/plugins/theme_editor.js new file mode 100644 index 00000000..5279d1f4 --- /dev/null +++ b/Assets/plugins/theme_editor.js @@ -0,0 +1,57 @@ + +let plugin = new arm.Plugin(); +let hpanel = new zui.Handle(); +let hlist = new zui.Handle(); + +function stringToBytes(str) { + let ab = new ArrayBuffer(str.length); + let u8 = new Uint8Array(ab); + for (let i = 0; i < str.length; ++i) { + u8[i] = str.charCodeAt(i); + } + return ab; +} + +plugin.drawUI = function(ui) { + if (ui.panel(hpanel, "Theme Editor")) { + ui.row([1 / 4]); + if (ui.button("Export")) { + arm.UIFiles.show("json", true, function(path) { + path += arm.Path.sep + arm.UIFiles.filename; + if (!path.endsWith(".json")) path += ".json"; + Krom.fileSaveBytes(path, stringToBytes(JSON.stringify(arm.App.theme))); + }); + } + + let i = 0; + let theme = arm.App.theme; + for (let key in theme) { + let h = hlist.nest(i); + let val = theme[key]; + let isHex = key.endsWith("_COL"); + if (isHex && val < 0) val += 4294967295; + + if (isHex) { + ui.row([1 / 8, 7 / 8]); + ui.text("", 0, val); + if (ui.isHovered && ui.inputReleased) { + arm.UIMenu.draw(function(ui) { + ui.fill(0, 0, ui._w / ui.ops.scaleFactor, ui.t.ELEMENT_H * 6, ui.t.SEPARATOR_COL); + ui.changed = false; + h.color = theme[key]; + theme[key] = zui.Ext.colorWheel(ui, h, false, null, false, false); + if (ui.changed) arm.UIMenu.keepOpen = true; + }); + } + } + + h.text = isHex ? val.toString(16) : val.toString(); + let res = ui.textInput(h, key); + if (res === "true") theme[key] = true; + else if (res === "false") theme[key] = false; + else if (isHex) theme[key] = parseInt(h.text, 16); + else theme[key] = parseInt(h.text); + i++; + } + } +} diff --git a/Sources/arm/Plugin.hx b/Sources/arm/Plugin.hx index 6e3b5a84..fa77587d 100644 --- a/Sources/arm/Plugin.hx +++ b/Sources/arm/Plugin.hx @@ -81,6 +81,7 @@ class ArmBridge { public static var UITrait = arm.ui.UITrait; public static var UINodes = arm.ui.UINodes; public static var UIFiles = arm.ui.UIFiles; + public static var UIMenu = arm.ui.UIMenu; public static var MeshUtil = arm.util.MeshUtil; public static var MaterialUtil = arm.util.MaterialUtil; public static var RenderUtil = arm.util.RenderUtil; @@ -94,6 +95,7 @@ class ArmBridge { @:expose("zui") class ZuiBridge { public static var Handle = zui.Zui.Handle; + public static var Ext = zui.Ext; } @:keep