diff --git a/Sources/arm/Config.hx b/Sources/arm/Config.hx index fe79aab7..c2dab6a3 100644 --- a/Sources/arm/Config.hx +++ b/Sources/arm/Config.hx @@ -87,6 +87,7 @@ class Config { raw.keymap.file_reload_assets = "ctrl+r"; raw.keymap.edit_undo = "ctrl+z"; raw.keymap.edit_redo = "ctrl+shift+z"; + raw.keymap.edit_prefs = "ctrl+k"; raw.keymap.view_reset = "0"; raw.keymap.view_front = "1"; raw.keymap.view_back = "ctrl+1"; diff --git a/Sources/arm/Project.hx b/Sources/arm/Project.hx index 3d02e3f8..67be5d81 100644 --- a/Sources/arm/Project.hx +++ b/Sources/arm/Project.hx @@ -1,6 +1,8 @@ package arm; import kha.Window; +import zui.Zui; +import zui.Id; import zui.Nodes; import iron.data.SceneFormat; import iron.data.MeshData; @@ -14,6 +16,7 @@ import arm.util.Path; import arm.ui.UITrait; import arm.ui.UINodes; import arm.ui.UIFiles; +import arm.ui.UIBox; import arm.data.LayerSlot; import arm.data.BrushSlot; import arm.data.MaterialSlot; @@ -81,6 +84,21 @@ class Project { }; } + public static function projectNewBox() { + UIBox.showCustom(function(ui:Zui) { + if (ui.tab(Id.handle(), "New Project")) { + ui.row([1/2, 1/2]); + UITrait.inst.projectType = ui.combo(Id.handle({position: UITrait.inst.projectType}), ["Paint", "Material", "Terrain"], "Template"); + if (ui.button("OK") || ui.isReturnDown) { + Project.projectNew(); + ViewportUtil.scaleToBounds(); + UIBox.show = false; + App.redrawUI(); + } + } + }); + } + public static function projectNew(resetLayers = true) { Window.get(0).title = "ArmorPaint"; filepath = ""; diff --git a/Sources/arm/ui/TabPreferences.hx b/Sources/arm/ui/BoxPreferences.hx similarity index 85% rename from Sources/arm/ui/TabPreferences.hx rename to Sources/arm/ui/BoxPreferences.hx index 1858acad..a06e7776 100644 --- a/Sources/arm/ui/TabPreferences.hx +++ b/Sources/arm/ui/BoxPreferences.hx @@ -6,31 +6,23 @@ import iron.data.Data; import arm.nodes.MaterialParser; import arm.data.LayerSlot; -class TabPreferences { +class BoxPreferences { @:access(zui.Zui) - public static function draw() { - var ui = UITrait.inst.ui; - if (ui.tab(UITrait.inst.htab, "Preferences")) { + public static function show() { + UIBox.showCustom(function(ui:Zui) { + var _w = ui._w; + ui._w = Std.int(_w / 2); + var htab = Id.handle(); - ui.row([1/4]); - if (ui.button("Restore")) { - UIMenu.draw(function(ui:Zui) { - ui.fill(0, 0, ui._w / ui.SCALE, ui.t.ELEMENT_H * 2, ui.t.SEPARATOR_COL); - ui.text("Restore defaults?", Right); - if (ui.button("Confirm", Left)) { - Config.restore(); - } - }); - } + if (ui.tab(htab, "Interface")) { - if (ui.panel(Id.handle({selected: false}), "Interface", 1)) { var hscale = Id.handle({value: Config.raw.window_scale}); ui.slider(hscale, "UI Scale", 0.5, 4.0, true); if (!hscale.changed && UITrait.inst.hscaleWasChanged) { if (hscale.value == null || Math.isNaN(hscale.value)) hscale.value = 1.0; Config.raw.window_scale = hscale.value; - ui.setScale(hscale.value); + UITrait.inst.ui.setScale(hscale.value); App.uibox.setScale(hscale.value); UINodes.inst.ui.setScale(hscale.value); UIView2D.inst.ui.setScale(hscale.value); @@ -69,10 +61,20 @@ class TabPreferences { } // ui.text("Node Editor"); // var gridSnap = ui.check(Id.handle({selected: false}), "Grid Snap"); - } - ui.separator(); - if (ui.panel(Id.handle({selected: false}), "Usage", 1)) { + ui.endElement(); + ui.row([1/2]); + if (ui.button("Restore Defaults")) { + // UIMenu.draw(function(ui:Zui) { + // ui.fill(0, 0, ui._w / ui.SCALE, ui.t.ELEMENT_H * 2, ui.t.SEPARATOR_COL); + // ui.text("Restore defaults?", Right); + // if (ui.button("Confirm", Left)) { + Config.restore(); + // } + // }); + } + } + if (ui.tab(htab, "Usage")) { UITrait.inst.undoHandle = Id.handle({value: Config.raw.undo_steps}); Config.raw.undo_steps = Std.int(ui.slider(UITrait.inst.undoHandle, "Undo Steps", 2, 64, false, 1)); if (UITrait.inst.undoHandle.changed) { @@ -117,9 +119,7 @@ class TabPreferences { } ui.enabled = true; } - - ui.separator(); - if (ui.panel(Id.handle({selected: false}), "Pen Pressure", 1)) { + if (ui.tab(htab, "Pen")) { UITrait.penPressureRadius = ui.check(Id.handle({selected: UITrait.penPressureRadius}), "Brush Radius"); UITrait.penPressureOpacity = ui.check(Id.handle({selected: UITrait.penPressureOpacity}), "Brush Opacity"); UITrait.penPressureHardness = ui.check(Id.handle({selected: UITrait.penPressureHardness}), "Brush Hardness"); @@ -130,15 +130,12 @@ class TabPreferences { UITrait.inst.hbloom = Id.handle({selected: Config.raw.rp_bloom}); UITrait.inst.hsupersample = Id.handle({position: Config.getSuperSampleQuality(Config.raw.rp_supersample)}); UITrait.inst.hvxao = Id.handle({selected: Config.raw.rp_gi}); - ui.separator(); - if (ui.panel(Id.handle({selected: false}), "Viewport Quality", 1)) { - ui.row([1/2, 1/2]); + if (ui.tab(htab, "Viewport")) { + ui.combo(UITrait.inst.hsupersample, ["0.25x", "0.5x", "1.0x", "1.5x", "2.0x", "4.0x"], "Super Sample", true); + if (UITrait.inst.hsupersample.changed) Config.applyConfig(); var vsyncHandle = Id.handle({selected: Config.raw.window_vsync}); Config.raw.window_vsync = ui.check(vsyncHandle, "VSync"); if (vsyncHandle.changed) Config.save(); - ui.combo(UITrait.inst.hsupersample, ["0.25x", "0.5x", "1.0x", "1.5x", "2.0x", "4.0x"], "Super Sample", true); - if (UITrait.inst.hsupersample.changed) Config.applyConfig(); - ui.row([1/2, 1/2]); var cullHandle = Id.handle({selected: Config.raw.rp_culling}); Config.raw.rp_culling = ui.check(cullHandle, "Cull Backfaces"); if (cullHandle.changed) { @@ -150,10 +147,7 @@ class TabPreferences { if (filterHandle.changed) { MaterialParser.parseMeshMaterial(); } - ui.row([1/2, 1/2]); - #if kha_direct3d12 - ui.check(Id.handle(), "Empty"); - #else + #if (!kha_direct3d12) ui.check(UITrait.inst.hvxao, "Voxel AO"); if (ui.isHovered) ui.tooltip("Cone-traced AO and shadows"); #end @@ -165,7 +159,6 @@ class TabPreferences { } ui.check(UITrait.inst.hssgi, "SSAO"); if (UITrait.inst.hssgi.changed) Config.applyConfig(); - ui.row([1/2, 1/2]); ui.check(UITrait.inst.hbloom, "Bloom"); if (UITrait.inst.hbloom.changed) Config.applyConfig(); ui.check(UITrait.inst.hssr, "SSR"); @@ -180,10 +173,7 @@ class TabPreferences { } #end } - - ui.separator(); - if (ui.panel(Id.handle({selected: false}), "Keymap", 1)) { - + if (ui.tab(htab, "Keymap")) { var presetHandle = Id.handle(); ui.combo(presetHandle, ["Default", "Blender"], "Preset", true); if (presetHandle.changed) { @@ -213,13 +203,8 @@ class TabPreferences { } if (ui.changed) Config.applyConfig(); } - } - } - #if arm_creator - static function roundfp(f:Float, precision = 2):Float { - f *= Math.pow(10, precision); - return Math.round(f) / Math.pow(10, precision); + ui._w = _w; + }); } - #end } diff --git a/Sources/arm/ui/UIBox.hx b/Sources/arm/ui/UIBox.hx index 11378d4f..fa7077b7 100644 --- a/Sources/arm/ui/UIBox.hx +++ b/Sources/arm/ui/UIBox.hx @@ -10,10 +10,11 @@ class UIBox { public static var show = false; public static var hwnd = new Handle(); - public static var modalW = 625; - public static var modalH = 545; + public static var boxTitle = ""; public static var boxText = ""; public static var boxCommands:Zui->Void = null; + static var modalW = 400; + static var modalH = 170; @:access(zui.Zui) public static function render(g:kha.graphics2.Graphics) { @@ -21,37 +22,38 @@ class UIBox { var uibox = App.uibox; var appw = System.windowWidth(); var apph = System.windowHeight(); - var modalW = Std.int(300 * uibox.SCALE); - var modalH = Std.int(115 * uibox.SCALE); + modalW = Std.int(400 * uibox.SCALE); + modalH = Std.int(170 * uibox.SCALE); var left = Std.int(appw / 2 - modalW / 2); var right = Std.int(appw / 2 + modalW / 2); var top = Std.int(apph / 2 - modalH / 2); var bottom = Std.int(apph / 2 + modalH / 2); - g.color = uibox.t.SEPARATOR_COL; - g.fillRect(left, top, modalW, modalH); g.end(); if (boxCommands == null) { uibox.begin(g); if (uibox.window(hwnd, left, top, modalW, modalH)) { uibox._y += 10; - for (line in boxText.split("\n")) { - uibox.text(line); + if (uibox.tab(Id.handle(), boxTitle)) { + for (line in boxText.split("\n")) { + uibox.text(line); + } + + uibox.row([2/3, 1/3]); + uibox.endElement(); + if (uibox.button("OK")) { + UIBox.show = false; + App.redrawUI(); + } } } - uibox.end(false); - uibox.beginLayout(g, right - Std.int(uibox.ELEMENT_W()), bottom - Std.int(uibox.ELEMENT_H() * 1.2), Std.int(uibox.ELEMENT_W())); - if (uibox.button("OK")) { - UIBox.show = false; - App.redrawUI(); - } - uibox.endLayout(false); + uibox.end(); } else { uibox.begin(g); if (uibox.window(hwnd, left, top, modalW, modalH)) { - uibox._y += 20; + uibox._y += 10; boxCommands(uibox); } uibox.end(); @@ -62,7 +64,8 @@ class UIBox { public static function update() { var mouse = Input.getMouse(); - if (mouse.released()) { + var inUse = @:privateAccess App.uibox.comboSelectedHandle != null; + if (App.uibox.inputReleased && !inUse) { var appw = System.windowWidth(); var apph = System.windowHeight(); var left = appw / 2 - modalW / 2; @@ -78,22 +81,9 @@ class UIBox { } } - public static function newProject() { - showCustom(function(ui:Zui) { - ui.text("New Project"); - ui.row([1/2, 1/2]); - UITrait.inst.projectType = ui.combo(Id.handle({position: UITrait.inst.projectType}), ["Paint", "Material", "Terrain"], "Template"); - if (ui.button("OK") || ui.isReturnDown) { - Project.projectNew(); - ViewportUtil.scaleToBounds(); - UIBox.show = false; - App.redrawUI(); - } - }); - } - - public static function showMessage(text:String) { + public static function showMessage(title:String, text:String) { UIBox.show = true; + boxTitle = title; boxText = text; boxCommands = null; } diff --git a/Sources/arm/ui/UIMenu.hx b/Sources/arm/ui/UIMenu.hx index f65a308b..baa8919b 100644 --- a/Sources/arm/ui/UIMenu.hx +++ b/Sources/arm/ui/UIMenu.hx @@ -29,7 +29,7 @@ class UIMenu { var menuButtonW = Std.int(ui.ELEMENT_W() * 0.5); var px = panelx + menuButtonW * menuCategory; var py = UITrait.inst.headerh; - var menuItems = [6, 2, 14, 5]; + var menuItems = [6, 3, 14, 5]; var ph = 24 * menuItems[menuCategory] * ui.SCALE; g.color = ui.t.SEPARATOR_COL; @@ -62,7 +62,7 @@ class UIMenu { } else { if (menuCategory == 0) { - if (ui.button("New Project...", Left, Config.keymap.file_new)) UIBox.newProject(); + if (ui.button("New Project...", Left, Config.keymap.file_new)) Project.projectNewBox(); if (ui.button("Open...", Left, Config.keymap.file_open)) Project.projectOpen(); if (ui.button("Save", Left, Config.keymap.file_save)) Project.projectSave(); if (ui.button("Save As...", Left, Config.keymap.file_save_as)) Project.projectSaveAs(); @@ -76,7 +76,8 @@ class UIMenu { else if (menuCategory == 1) { if (ui.button("Undo", Left, Config.keymap.edit_undo)) History.undo(); if (ui.button("Redo", Left, Config.keymap.edit_redo)) History.redo(); - // ui.button("Preferences...", Left); + ui.fill(0, 0, sepw, 1, ui.t.ACCENT_SELECT_COL); + if (ui.button("Preferences...", Left, Config.keymap.edit_prefs)) BoxPreferences.show(); } else if (menuCategory == 2) { if (ui.button("Reset", Left, Config.keymap.view_reset)) { ViewportUtil.resetViewport(); ViewportUtil.scaleToBounds(); } @@ -157,10 +158,10 @@ class UIMenu { var date = Macro.buildDate().split(" ")[0].substr(2); // 2019 -> 19 var dateInt = Std.parseInt(date.replace("-", "")); if (updateVersion > dateInt) { - UIBox.showMessage("Update is available!\nPlease visit armorpaint.org to download."); + UIBox.showMessage("Update", "Update is available!\nPlease visit armorpaint.org to download."); } else { - UIBox.showMessage("You are up to date!"); + UIBox.showMessage("Update", "You are up to date!"); } } Data.deleteBlob(outFile); @@ -189,7 +190,7 @@ class UIMenu { // { lshw -C display } #end - UIBox.showMessage(msg); + UIBox.showMessage("About", msg); } } } diff --git a/Sources/arm/ui/UITrait.hx b/Sources/arm/ui/UITrait.hx index d4341911..1187b36d 100644 --- a/Sources/arm/ui/UITrait.hx +++ b/Sources/arm/ui/UITrait.hx @@ -439,7 +439,7 @@ class UITrait { else if (Operator.shortcut(Config.keymap.file_save)) Project.projectSave(); else if (Operator.shortcut(Config.keymap.file_open)) Project.projectOpen(); else if (Operator.shortcut(Config.keymap.file_reload_assets)) Project.reloadAssets(); - else if (Operator.shortcut(Config.keymap.file_new)) UIBox.newProject(); + else if (Operator.shortcut(Config.keymap.file_new)) Project.projectNewBox(); else if (Operator.shortcut(Config.keymap.export_textures)) { if (textureExportPath == "") { // First export, ask for path UIFiles.show = true; @@ -460,6 +460,7 @@ class UITrait { Importer.importFile(path); } } + else if (Operator.shortcut(Config.keymap.edit_prefs)) BoxPreferences.show(); if (kb.started(Config.keymap.view_distract_free) || (kb.started("escape") && !show && !UIBox.show)) { @@ -1173,7 +1174,6 @@ class UITrait { TabLayers.draw(); TabHistory.draw(); TabPlugins.draw(); - TabPreferences.draw(); } if (ui.window(hwnd1, tabx, tabh, windowW, tabh1)) { Context.object = Context.paintObject; @@ -1196,7 +1196,6 @@ class UITrait { if (ui.window(hwnd, tabx, 0, windowW, tabh)) { TabOutliner.draw(); TabPlugins.draw(); - TabPreferences.draw(); } if (ui.window(hwnd1, tabx, tabh, windowW, tabh1)) { TabMaterials.draw();