From 83ee296cc4ffb18d0d3d912646ec7bceae6ce4cd Mon Sep 17 00:00:00 2001 From: MathemanFlo Date: Tue, 14 Feb 2023 15:20:29 +0100 Subject: [PATCH] Add context menu to browser --- armorpaint/Sources/arm/ui/TabBrowser.hx | 70 ++++++++++++++++++++++++- armorpaint/Sources/arm/ui/UIFiles.hx | 6 ++- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/armorpaint/Sources/arm/ui/TabBrowser.hx b/armorpaint/Sources/arm/ui/TabBrowser.hx index d6ae6814..e6e259cb 100644 --- a/armorpaint/Sources/arm/ui/TabBrowser.hx +++ b/armorpaint/Sources/arm/ui/TabBrowser.hx @@ -3,6 +3,7 @@ package arm.ui; import kha.input.KeyCode; import zui.Zui; import zui.Id; +import arm.sys.File; import arm.sys.Path; import arm.io.ImportAsset; import arm.Enums; @@ -92,7 +93,74 @@ class TabBrowser { var _y = ui._y; ui._x = bookmarksW; ui._w -= bookmarksW; - UIFiles.fileBrowser(ui, hpath, false, true, hsearch.text, refresh); + UIFiles.fileBrowser(ui, hpath, false, true, hsearch.text, refresh, function(file) { + var fileName = file.substr(file.lastIndexOf(Path.sep)+1); + if (fileName != "..") { + UIMenu.draw(function(ui: Zui) { + ui.text(fileName, Right, ui.t.HIGHLIGHT_COL); + if (ui.button(tr("Import"), Left)) { + ImportAsset.run(file); + } + if (Path.isTexture(file)) { + if (ui.button(tr("Set as Envmap"), Left)) { + ImportAsset.run(file, -1.0, -1.0, true, true, function() { + App.notifyOnNextFrame(function() { + var assetIndex = -1; + for (i in 0...Project.assets.length) { + if (Project.assets[i].file == file) { + assetIndex = i; + break; + } + } + if (assetIndex != -1) + arm.io.ImportEnvmap.run(file, Project.getImage(Project.assets[assetIndex])); + }); + }); + } + if (ui.button(tr("Set as Mask"), Left)) { + ImportAsset.run(file, -1.0, -1.0, true, true, function() { + App.notifyOnNextFrame(function() { + var assetIndex = -1; + for (i in 0...Project.assets.length) { + if (Project.assets[i].file == file) { + assetIndex = i; + break; + } + } + if (assetIndex != -1) + Layers.createImageMask(Project.assets[assetIndex]); + }); + }); + } + if (ui.button(tr("Set as Color ID Map"), Left)) { + ImportAsset.run(file, -1.0, -1.0, true, true, function() { + App.notifyOnNextFrame(function() { + var assetIndex = -1; + for (i in 0...Project.assets.length) { + if (Project.assets[i].file == file) { + assetIndex = i; + break; + } + } + if (assetIndex != -1) { + Context.colorIdHandle.position = assetIndex; + Context.colorIdPicked = false; + UIToolbar.inst.toolbarHandle.redraws = 1; + if (Context.tool == ToolColorId) { + UIHeader.inst.headerHandle.redraws = 2; + Context.ddirty = 2; + } + } + }); + }); + } + } + if (ui.button(tr("Open externally"), Left)) { + File.start(file); + } + }, Path.isTexture(file) ? 6 : 3); + } + }); if (known) { var path = hpath.text; diff --git a/armorpaint/Sources/arm/ui/UIFiles.hx b/armorpaint/Sources/arm/ui/UIFiles.hx index 7c16e355..4e586470 100644 --- a/armorpaint/Sources/arm/ui/UIFiles.hx +++ b/armorpaint/Sources/arm/ui/UIFiles.hx @@ -82,7 +82,7 @@ class UIFiles { @:access(zui.Zui) @:access(arm.sys.File) - public static function fileBrowser(ui: Zui, handle: Handle, foldersOnly = false, dragFiles = false, search = "", refresh = false): String { + public static function fileBrowser(ui: Zui, handle: Handle, foldersOnly = false, dragFiles = false, search = "", refresh = false, contextMenu : String -> Void = null): String { var icons = Res.get("icons.k"); var folder = Res.tile50(icons, 2, 1); @@ -257,6 +257,10 @@ class UIFiles { state = ui.image(icons, col, 50 * ui.SCALE(), rect.x, rect.y, rect.w, rect.h); } + if (ui.isHovered && ui.inputReleasedR && contextMenu != null) { + contextMenu(handle.text + Path.sep + f); + } + if (state == Started) { if (f != ".." && dragFiles) { var mouse = Input.getMouse();