-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathColorSelection.cs
84 lines (64 loc) · 1.99 KB
/
ColorSelection.cs
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using Godot;
public class ColorSelection : VBoxContainer
{
[Export]
private string _title = "";
private GridContainer _grid;
private Button _button;
private PackedScene _colorIconScene;
private Godot.Collections.Array<string> _colors = new Godot.Collections.Array<string>()
{
"3e4084ff",
"882b5aff",
"7c9052ff",
"000000"
};
[Signal]
delegate void Selected(Color color);
public override void _Ready()
{
_colorIconScene = ResourceLoader.Load<PackedScene>(Globals.PATHS.COLORICON);
_button = GetNode<Button>("Button");
_button.Text = _title;
_grid = GetNode<GridContainer>("ColorGrid");
_grid.Visible = false;
foreach (string color in _colors)
{
ColorIcon icon = _colorIconScene.Instance<ColorIcon>();
_grid.AddChild(icon);
icon.Color = new Color(color);
icon.Connect("button_down", this, nameof(on_ColorIcon_button_down), new Godot.Collections.Array() { icon.Color });
}
}
private void UpdateColors(string path)
{
_colors.Clear();
foreach(ColorIcon icon in _grid.GetChildren())
{
icon.QueueFree();
}
File f = new File();
f.Open(path, File.ModeFlags.Read);
while (!f.EofReached())
{
string line = f.GetLine();
_colors.Add(line);
ColorIcon icon = _colorIconScene.Instance<ColorIcon>();
_grid.AddChild(icon);
icon.Color = new Color(line);
icon.Connect("button_down", this, nameof(on_ColorIcon_button_down), new Godot.Collections.Array() { icon.Color });
}
}
public void _on_Button_button_down()
{
_grid.Visible = !_grid.Visible;
}
public void on_ColorIcon_button_down(Color color)
{
EmitSignal(nameof(Selected), color);
}
public void _on_ToolsUI_UpdatePalette(string path)
{
UpdateColors(path);
}
}