-
Notifications
You must be signed in to change notification settings - Fork 0
/
dfCheckbox.cs
171 lines (158 loc) · 3.71 KB
/
dfCheckbox.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
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
using System;
using System.Runtime.CompilerServices;
using UnityEngine;
[Serializable, RequireComponent(typeof(BoxCollider)), AddComponentMenu("Daikon Forge/User Interface/Checkbox"), ExecuteInEditMode]
public class dfCheckbox : dfControl
{
[SerializeField]
protected dfControl checkIcon;
[SerializeField]
protected dfControl group;
[SerializeField]
protected bool isChecked;
[SerializeField]
protected dfLabel label;
public event PropertyChangedEventHandler<bool> CheckChanged;
protected internal void OnCheckChanged()
{
object[] args = new object[] { this.isChecked };
base.SignalHierarchy("OnCheckChanged", args);
if (this.CheckChanged != null)
{
this.CheckChanged(this, this.isChecked);
}
if (this.checkIcon != null)
{
if (this.IsChecked)
{
this.checkIcon.BringToFront();
}
this.checkIcon.IsVisible = this.IsChecked;
}
}
protected internal override void OnClick(dfMouseEventArgs args)
{
if (this.group == null)
{
this.IsChecked = !this.IsChecked;
}
else
{
foreach (dfCheckbox checkbox in base.transform.parent.GetComponentsInChildren<dfCheckbox>())
{
if (((checkbox != this) && (checkbox.GroupContainer == this.GroupContainer)) && checkbox.IsChecked)
{
checkbox.IsChecked = false;
}
}
this.IsChecked = true;
}
args.Use();
base.OnClick(args);
}
protected internal override void OnKeyPress(dfKeyEventArgs args)
{
if (args.KeyCode == KeyCode.Space)
{
this.OnClick(new dfMouseEventArgs(this, dfMouseButtons.Left, 1, new Ray(), Vector2.zero, 0f));
}
else
{
base.OnKeyPress(args);
}
}
public override void Start()
{
base.Start();
if (this.checkIcon != null)
{
this.checkIcon.BringToFront();
this.checkIcon.IsVisible = this.IsChecked;
}
}
public override bool CanFocus
{
get
{
return (base.IsEnabled && base.IsVisible);
}
}
public dfControl CheckIcon
{
get
{
return this.checkIcon;
}
set
{
if (value != this.checkIcon)
{
this.checkIcon = value;
this.Invalidate();
}
}
}
public dfControl GroupContainer
{
get
{
return this.group;
}
set
{
if (value != this.group)
{
this.group = value;
this.Invalidate();
}
}
}
public bool IsChecked
{
get
{
return this.isChecked;
}
set
{
if (value != this.isChecked)
{
this.isChecked = value;
this.OnCheckChanged();
}
}
}
public dfLabel Label
{
get
{
return this.label;
}
set
{
if (value != this.label)
{
this.label = value;
this.Invalidate();
}
}
}
public string Text
{
get
{
if (this.label != null)
{
return this.label.Text;
}
return "[LABEL NOT SET]";
}
set
{
if (this.label != null)
{
this.label.Text = value;
}
}
}
}