-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtils.cs
More file actions
31 lines (27 loc) · 1.04 KB
/
Copy pathUtils.cs
File metadata and controls
31 lines (27 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
namespace SimplifiedVisuals;
using System;
using Godot;
public static class NodeExtensions
{
public static void ModifyChild<T>(this Node? instance, NodePath nodePath, Action<T> action) where T : Node
{
if (instance?.GetNodeOrNull<T>(nodePath) is not { } child) return;
action(child);
}
public static void Modify<T>(this T? instance, Action<T> action) where T : Node
{
if (instance == null) return;
action(instance);
}
public static void HideAndDisable(this Node instance, string pattern, bool remainVisible = false, bool printDebug = false)
{
foreach (var child in instance.FindChildren(pattern, recursive: true, owned: false))
{
if (child is not CanvasItem canvasItem) continue;
if (printDebug) Main.Logger.Info($"Disabling node matching {pattern}: {child.Name} (type {child.GetType().Name})");
canvasItem.ProcessMode = Node.ProcessModeEnum.Disabled;
if (!remainVisible)
canvasItem.Visible = false;
}
}
}