-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathCheckListGUI.cs
More file actions
193 lines (166 loc) · 5.67 KB
/
CheckListGUI.cs
File metadata and controls
193 lines (166 loc) · 5.67 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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
namespace EqualchanceGames.Tools.GUIPro
{
public class CheckListGUI : BaseGUI
{
public List<RowCheckList> RowCheckLists { get; private set; }
public int Width = 1000;
public int MinWidth = 100;
public int Height;
public int MinHeight = 200;
public Color BackColor = Color.gray;
private GUIStyle CheckListStyle;
private Texture2D texture2D;
private Vector2 vector2 = Vector2.zero;
public CheckListGUI(List<string> elements, bool isActive = true, bool isAvailable = true, int width = 400, int height = 0)
{
Width = width;
Height = height;
RowCheckLists = new List<RowCheckList>();
FillElements(elements, isActive, isAvailable);
texture2D = HelperGUI.MakeTex(600, 10, BackColor);
}
public CheckListGUI(List<RowCheckList> elements, int width = 400, int height = 0)
{
Width = width;
Height = height;
RowCheckLists = elements;
texture2D = HelperGUI.MakeTex(600, 10, BackColor);
}
public void FillElements(List<string> elements, bool isActive = true, bool isAvailable = true)
{
RowCheckLists.Clear();
foreach (string element in elements)
{
RowCheckLists.Add(new RowCheckList(element, isActive, isAvailable));
}
}
private void SetStyle()
{
CheckListStyle = new GUIStyle("button");
CheckListStyle.padding = new RectOffset(7, 7, 7, 7);
CheckListStyle.normal.background = texture2D;
vector2 = EditorGUILayout.BeginScrollView(vector2, CheckListStyle, GUILayout.ExpandWidth(true), GUILayout.MaxHeight(Height), GUILayout.MinHeight(MinHeight));
}
private void DrawElements()
{
foreach (RowCheckList element in RowCheckLists)
{
GUI.enabled = element.IsAvailable;
EditorGUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
EditorGUILayout.LabelField(element.Name);
element.IsActive = EditorGUILayout.Toggle(element.IsActive, GUILayout.Width(20));
EditorGUILayout.EndHorizontal();
}
}
public void Draw()
{
SetStyle();
DrawElements();
GUI.enabled = true;
EditorGUILayout.EndScrollView();
}
public void DrawButtons()
{
SetStyle();
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Deselect All")) { RowCheckLists.Where(w => w.IsAvailable == true).ToList().ForEach(w => w.IsActive = false); }
if (GUILayout.Button("Select All")) { RowCheckLists.Where(w => w.IsAvailable == true).ToList().ForEach(w => w.IsActive = true); }
EditorGUILayout.EndHorizontal();
DrawElements();
GUI.enabled = true;
EditorGUILayout.EndScrollView();
}
public void DrawButtons(string name)
{
GUILayout.Label(name);
DrawButtons();
}
public void Update(List<string> elements, bool newvalue = false)
{
List<RowCheckList> newRowCheckLists = new List<RowCheckList>();
bool pair = false;
foreach (string newelement in elements)
{
foreach (RowCheckList rowCheckLists in RowCheckLists)
{
if ( rowCheckLists.Name == newelement)
{
newRowCheckLists.Add(new RowCheckList(rowCheckLists.Name, rowCheckLists.IsActive, rowCheckLists.IsAvailable));
pair = true;
}
}
if ( pair == false) newRowCheckLists.Add(new RowCheckList(newelement, newvalue));
pair = false;
}
RowCheckLists = newRowCheckLists;
}
public void UpdateCheck(List<string> elements, bool isActive = true, bool isAvailable = true )
{
foreach (string newelement in elements)
{
foreach (RowCheckList rowCheckLists in RowCheckLists)
{
if (rowCheckLists.Name == newelement)
{
rowCheckLists.IsActive = isActive;
rowCheckLists.IsAvailable = isAvailable;
}
}
}
}
public Dictionary<string, bool> GetElements(bool OnlyActive = true, bool OnlyAvailable = true)
{
Dictionary<string, bool> elements = new Dictionary<string, bool>();
foreach (RowCheckList rowCheckList in RowCheckLists)
{
if (rowCheckList.IsActive == OnlyActive && rowCheckList.IsAvailable == OnlyAvailable)
{
elements.Add(rowCheckList.Name, rowCheckList.IsActive);
}
}
return elements;
}
public List<string> GetNames(bool OnlyActive = true, bool OnlyAvailable = true)
{
List<string> names = new List<string>();
foreach (RowCheckList rowCheckList in RowCheckLists)
{
if (rowCheckList.IsActive == OnlyActive && rowCheckList.IsAvailable == OnlyAvailable)
{
names.Add(rowCheckList.Name);
}
}
return names;
}
public bool CheckDifferent(List<string> elements)
{
foreach (string newelement in elements)
{
foreach (RowCheckList rowCheckLists in RowCheckLists)
{
if (rowCheckLists.Name != newelement)
{
return true;
}
}
}
return false;
}
}
public class RowCheckList
{
public string Name;
public bool IsActive;
public bool IsAvailable;
public RowCheckList(string name, bool isActive, bool isAvailable = true)
{
Name = name;
IsActive = isActive;
IsAvailable = isAvailable;
}
}
}