From 06ec0577e15867d58db75a7fde546df5136c4ac7 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Sun, 26 Apr 2020 19:42:31 +0200 Subject: [PATCH] Update nodes on texture delete --- Sources/arm/io/ImportArm.hx | 2 +- Sources/arm/ui/TabTextures.hx | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Sources/arm/io/ImportArm.hx b/Sources/arm/io/ImportArm.hx index 8823e235..4dc8651b 100644 --- a/Sources/arm/io/ImportArm.hx +++ b/Sources/arm/io/ImportArm.hx @@ -420,4 +420,4 @@ class ImportArm { } } } -} \ No newline at end of file +} diff --git a/Sources/arm/ui/TabTextures.hx b/Sources/arm/ui/TabTextures.hx index 673329d0..5fcd7f42 100644 --- a/Sources/arm/ui/TabTextures.hx +++ b/Sources/arm/ui/TabTextures.hx @@ -1,6 +1,7 @@ package arm.ui; import zui.Zui; +import zui.Nodes; import iron.data.Data; import iron.system.Time; import iron.system.Input; @@ -116,12 +117,15 @@ class TabTextures { Project.assets.splice(i, 1); Project.assetNames.splice(i, 1); function _parse(g: kha.graphics4.Graphics) { - arm.node.MaterialParser.parsePaintMaterial(); - arm.util.RenderUtil.makeMaterialPreview(); - UISidebar.inst.hwnd1.redraws = 2; - iron.App.removeRender(_parse); + arm.node.MaterialParser.parsePaintMaterial(); + arm.util.RenderUtil.makeMaterialPreview(); + UISidebar.inst.hwnd1.redraws = 2; + iron.App.removeRender(_parse); } iron.App.notifyOnRender(_parse); + + for (m in Project.materials) updateTexturePointers(m.canvas.nodes, i); + for (b in Project.brushes) updateTexturePointers(b.canvas.nodes, i); } }, 4); } @@ -136,4 +140,17 @@ class TabTextures { } } } + + static function updateTexturePointers(nodes: Array, i: Int) { + for (n in nodes) { + if (n.type == "TEX_IMAGE") { + if (n.buttons[0].default_value == i) { + n.buttons[0].default_value = 9999; // Texture deleted, use pink now + } + else if (n.buttons[0].default_value > i) { + n.buttons[0].default_value--; // Offset by deleted texture + } + } + } + } }