Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ChangeableComponentBase.c
Go to the documentation of this file.
1
2
3//------------------------------------------------------------------------------------------------
5{
6 [Attribute("true")]
7 protected bool m_bUseLabel;
8
9 [Attribute("", UIWidgets.EditBox, "")]
10 protected string m_sLabel;
11
12 [Attribute("true")]
13 protected bool m_bForceSize;
14
15 [Attribute("50", UIWidgets.EditBox, "")]
16 protected float m_fSizeWithLabel;
17
18 [Attribute("36", UIWidgets.EditBox, "")]
19 protected float m_fSizeWithoutLabel;
20
21 [Attribute("{829BC1189A899017}UI/layouts/WidgetLibrary/WLibRefined/WLib_Label.layout", UIWidgets.EditBox, "")]
23
24 [Attribute("SizeLayout", UIWidgets.EditBox, "Name of size layout if you want to find size that is not root child")]
25 protected string m_sSizeLayout;
26
27 protected Widget m_wBorder;
30
31//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
32// Untyped invoker abuse! Not only passing different data to the same invoker is very prone to mistakes in listeners, child components' interpretation of what OnChanged means to them is very different, and led to mistakes in menus that resulted in huge amounts of pointless calls. We need different events for init, changes, and user interactions that are specific to each child
33
35 // Arguments passed:
36 // Toolbox (multiselect off): SCR_ToolboxComponent, int (selected item)
37 // Toolbox (multiselect on): SCR_ToolboxComponent, int (current item), bool (is selected)
38 // Checkbox: SCR_CheckboxComponent, bool (checked)
39 // Spinbox: SCR_SpinBoxComponent, int (selected item)
40 // ComboBox: SCR_ComboBoxComponent, int (selected item)
41 // EditBox: SCR_EditBoxComponent, string (text)
42 // Slider: SCR_SliderComponent, float (value)
43
44//---- REFACTOR NOTE END ----
45
46 //------------------------------------------------------------------------------------------------
47 override void HandlerAttached(Widget w)
48 {
49 super.HandlerAttached(w);
50
51 m_wBorder = m_wRoot.FindAnyWidget("Border");
52 m_wBackground = m_wRoot.FindAnyWidget("Background");
53
54 if (m_wBackground)
55 m_wBackground.SetColor(Color.FromInt(UIColors.BACKGROUND_DEFAULT.PackToInt()));
56
57 if (m_wBorder)
58 m_wBorder.SetOpacity(0);
59
60 if (m_bUseLabel)
61 SetupLabel();
62 else
63 ClearLabel();
64 }
65
66//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
67// Unmantained, and not generic enough! Too tied to Reforger's old look: this handling of borders and backgrounds is now pointless because they were mostly abandoned
68
69 //------------------------------------------------------------------------------------------------
70 override bool OnFocus(Widget w, int x, int y)
71 {
72 super.OnFocus(w, x, y);
73 if (m_wBorder)
75
76 AnimateWidget.Color(m_wBackground, Color.FromInt(UIColors.BACKGROUND_HOVERED.PackToInt()), m_fAnimationRate);
77 return false;
78 }
79
80 //------------------------------------------------------------------------------------------------
81 override bool OnFocusLost(Widget w, int x, int y)
82 {
83 super.OnFocusLost(w, x, y);
84
85 if (m_wBorder)
87
88 Widget mouseOver = WidgetManager.GetWidgetUnderCursor();
89 if (w != mouseOver && !IsChildWidget(w, mouseOver))
90 AnimateWidget.Color(m_wBackground, Color.FromInt(UIColors.BACKGROUND_DEFAULT.PackToInt()), m_fAnimationRate);
91
92 return false;
93 }
94
95 //------------------------------------------------------------------------------------------------
96 override bool OnMouseEnter(Widget w, int x, int y)
97 {
98 AnimateWidget.Color(m_wBackground, Color.FromInt(UIColors.BACKGROUND_HOVERED.PackToInt()), m_fAnimationRate);
99 return super.OnMouseEnter(w, x, y);
100 }
101
102 //------------------------------------------------------------------------------------------------
103 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
104 {
105 super.OnMouseLeave(w, enterW, x, y);
106 if (GetGame().GetWorkspace().GetFocusedWidget() == w || IsChildWidget(w, enterW))
107 return false;
108
109 AnimateWidget.Color(m_wBackground, Color.FromInt(UIColors.BACKGROUND_DEFAULT.PackToInt()), m_fAnimationRate);
110 return false;
111 }
112
113
114//---- REFACTOR NOTE END ----
115
116 //------------------------------------------------------------------------------------------------
117 protected void SetupLabel()
118 {
119 if (m_wLabelRoot)
120 return;
121
122 SizeLayoutWidget size = SizeLayoutWidget.Cast(m_wRoot.GetChildren());
123 if (!size && !m_sSizeLayout.IsEmpty())
124 size = SizeLayoutWidget.Cast(m_wRoot.FindAnyWidget(m_sSizeLayout));
125
126 if (size)
127 {
128 size.EnableHeightOverride(m_bForceSize);
129 size.SetHeightOverride(m_fSizeWithLabel);
130 }
131
132 Widget contentRoot = m_wRoot.FindAnyWidget("HorizontalLayout");
133 if (!contentRoot)
134 return;
135
136 m_wLabelRoot = GetGame().GetWorkspace().CreateWidgets(m_sLabelLayout, contentRoot);
137 if (!m_wLabelRoot)
138 return;
139
140 TextWidget text = TextWidget.Cast(m_wLabelRoot.FindAnyWidget("Text"));
141 if (!text)
142 return;
143
144 text.SetText(m_sLabel);
145 }
146
147 //------------------------------------------------------------------------------------------------
148 protected void ClearLabel()
149 {
150 if (m_wLabelRoot)
151 {
152 m_wLabelRoot.RemoveFromHierarchy();
153 m_wLabelRoot = null;
154 }
155
156 SizeLayoutWidget size = SizeLayoutWidget.Cast(m_wRoot.GetChildren());
157 if (size)
158 {
159 size.EnableHeightOverride(m_bForceSize);
160 size.SetHeightOverride(m_fSizeWithoutLabel);
161 }
162
163 Widget layout = m_wRoot.FindAnyWidget("HorizontalLayout");
164 if (layout)
165 AlignableSlot.SetPadding(layout, 2, 2, 2, 2);
166 }
167
168 //------------------------------------------------------------------------------------------------
170 {
171 return TextWidget.Cast(m_wLabelRoot.FindAnyWidget("Text"));
172 }
173
174 //------------------------------------------------------------------------------------------------
175 void SetLabel(string label)
176 {
177 if (!m_wLabelRoot)
178 return;
179
180 TextWidget w = TextWidget.Cast(m_wLabelRoot.FindAnyWidget("Text"));
181 if (!w)
182 return;
183
184 m_sLabel = label;
185
186 w.SetText(m_sLabel);
187 }
188
189 //------------------------------------------------------------------------------------------------
190 void UseLabel(bool use)
191 {
192 if (use == m_bUseLabel)
193 return;
194
195 m_bUseLabel = use;
196
197 if (use)
198 SetupLabel();
199 else
200 ClearLabel();
201 }
202
203 //------------------------------------------------------------------------------------------------
205 {
206 return m_bUseLabel;
207 }
208
210 //------------------------------------------------------------------------------------------------
212 {
213 return m_wLabelRoot;
214 }
215
216 //------------------------------------------------------------------------------------------------
218 {
220 if (m_bUseLabel)
221 SetupLabel();
222 }
223
224 //------------------------------------------------------------------------------------------------
226 {
228 if (!m_bUseLabel)
229 ClearLabel();
230 }
231};
ArmaReforgerScripted GetGame()
Definition game.c:1398
int size
UI layouts Menus CleanSweep CleanSweepAreaSelection layout
static WidgetAnimationOpacity Opacity(Widget widget, float targetValue, float speed, bool toggleVisibility=false)
static WidgetAnimationColor Color(Widget widget, Color color, float speed)
Definition Color.c:13
Base class for all widgets that can change their internal state as editbox or spinbox.
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Widget GetLabelWidget()
If label is not used, label widget might not exist at all!
override bool OnFocus(Widget w, int x, int y)
override bool OnMouseEnter(Widget w, int x, int y)
override bool OnFocusLost(Widget w, int x, int y)
Base class for all final Reforger interactive elements.
bool IsChildWidget(Widget parent, Widget child)
SCR_FieldOfViewSettings Attribute
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134