Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ButtonBoxAttributeUIComponent.c
Go to the documentation of this file.
1
4{
5 [Attribute("0", UIWidgets.ComboBox, "Attribute Toolbox type", "", ParamEnumArray.FromEnum(EAttributeToolBoxType))]
7
8 [Attribute("#AR-Editor_Attribute_Randomize_Name")]
10
11 [Attribute("{0C6A9655C33FB75D}UI/layouts/Editor/Attributes/Base/ButtonImageUnderlined.layout")]
13
14 [Attribute("{B98EA1D6487A6F45}UI/layouts/Editor/Attributes/Base/AttributeEmptyButton.layout")]
16
17 [Attribute("0", desc: "At which int the randomizer starts. This is when you want the first few buttons to be ignored by the randomize button")]
19
20 [Attribute("true", desc: "Shows border when hovering over button.")]
21 protected bool m_bShowBorderOnHover;
22
24
26
28
29 //Button specific
30 protected bool m_bHasRandomizeButton;
31
32 //~ If at least one selection button is selected (Only works with EAttributeToolBoxType.SELECTABLE_BUTTON)
33 protected bool m_bSelectionButtonIsSelected = true;
34
35
36 //---- REFACTOR NOTE START: Init is bloated
37 /*
38 Searching for widgets with names hardcoded in method
39 Working with various button types (m_ToolboxType) could be simpler
40 Use of DelayedInit() to setup empty buttons
41 */
42
43 override void Init(Widget w, SCR_BaseEditorAttribute attribute)
44 {
45 Widget toolBox = w.FindAnyWidget(m_sUiComponentName);
46 if (!toolBox) return;
47
49 if (!m_ToolBoxComponent) return;
50
51 if (m_ToolboxType == EAttributeToolBoxType.SELECTABLE_BUTTON)
52 m_ToolBoxComponent.m_bAllowMultiselection = false;
53 else
54 m_ToolBoxComponent.m_bAllowMultiselection = true;
55
57 if (!var) return;
58
59 array<ref SCR_BaseEditorAttributeEntry> entries = new array<ref SCR_BaseEditorAttributeEntry>;
60 attribute.GetEntries(entries);
61
62 bool hasIcon, hasButtonDescription;
63 ResourceName iconOfRandomizeButton;
64 int buttonsOnRow;
65
67
68 foreach (SCR_BaseEditorAttributeEntry entry: entries)
69 {
71 if (presetEntry)
72 {
73 float buttonHeight;
74 string buttonDescription;
75 presetEntry.GetPresetValues(buttonsOnRow, m_bHasRandomizeButton, iconOfRandomizeButton, hasIcon, hasButtonDescription, buttonDescription, buttonHeight);
76
77 if (hasButtonDescription)
78 {
79 SCR_EditorAttributeUIInfo newButtonDescription = new SCR_EditorAttributeUIInfo();
80 newButtonDescription.CopyFromEditorAttributeUIInfo(m_ButtonDescriptionUIInfo, buttonDescription);
81 m_ButtonDescriptionUIInfo = newButtonDescription;
82 }
83
84 if (multiLine)
85 {
86 multiLine.SetMaxItemsInRow(buttonsOnRow);
87
88 if (buttonHeight != -1)
89 multiLine.m_fElementHeight = buttonHeight;
90 }
91
92 if (hasIcon)
93 m_ToolBoxComponent.m_ElementLayout = m_sButtonWithIcon;
94
95 continue;
96 }
97
99 if (data)
100 {
102 int count = m_ButtonBoxData.GetValueCount();
103
104 for (int i = 0; i < count; i++)
105 {
106 m_ToolBoxComponent.AddItem(m_ButtonBoxData.GetValuesEntry(i).GetName());
107 }
108
109 Widget buttonRow = w.FindAnyWidget("ButtonRow");
110
111 //Fill with empty buttons
112 if (buttonRow && !m_sEmptyButton.IsEmpty())
113 {
114 while (count < buttonsOnRow)
115 {
116 Widget emptyButton = GetGame().GetWorkspace().CreateWidgets(m_sEmptyButton, buttonRow);
117 UniformGridSlot.SetRow(emptyButton, 0);
118 UniformGridSlot.SetColumn(emptyButton, count);
119 count++;
120 }
121 }
122 continue;
123 }
124 }
125
126 //Buttons with Icon or description delayed init
127 if (hasIcon || hasButtonDescription)
128 GetGame().GetCallqueue().CallLater(DelayedInit, 1, false, hasIcon, hasButtonDescription);
129
130 if (m_ToolboxType == EAttributeToolBoxType.SINGLE_BUTTON)
131 m_ToolBoxComponent.m_OnChanged.Insert(OnSingleButton);
132 else if (m_ToolboxType == EAttributeToolBoxType.SELECTABLE_BUTTON)
133 m_ToolBoxComponent.m_OnChanged.Insert(OnSelectableButton);
134 else if (m_ToolboxType == EAttributeToolBoxType.MULTI_SELECTABLE_BUTTON)
135 m_ToolBoxComponent.m_OnChanged.Insert(OnMultiSelectButton);
136
137 //Set button selected
138 if (m_ToolboxType == EAttributeToolBoxType.SINGLE_BUTTON)
139 {
140 int value = var.GetInt();
141 if (value >= 0 && value < m_ButtonBoxData.GetValueCount())
142 m_ToolBoxComponent.SetItemSelected(value, false);
143 }
144
145 //Add random button
147 {
149
150 if (hasIcon && !iconOfRandomizeButton.IsEmpty())
151 {
152 array<SCR_ButtonBaseComponent> elements = new array<SCR_ButtonBaseComponent>;
153 int count = m_ToolBoxComponent.GetItems(elements);
154
155 SCR_ButtonBaseComponent randomizeButton = elements[count -1];
156
157 if (randomizeButton)
158 {
159 ImageWidget imageWidget = ImageWidget.Cast(randomizeButton.GetRootWidget().FindAnyWidget("Image"));
160
161 if (imageWidget)
162 imageWidget.LoadImageTexture(0, iconOfRandomizeButton);
163
164 //Note randomize description is currently not supported as randomize is not used.
165 /*
166 SCR_AttributeButtonUIComponent button = SCR_AttributeButtonUIComponent.Cast(randomizeButton.GetRootWidget().FindHandler(SCR_AttributeButtonUIComponent));
167 if (!button)
168 {
169 button = new SCR_AttributeButtonUIComponent();
170 randomizeButton.GetRootWidget().AddHandler(button);
171 }
172
173 button.ButtonDescriptionInit(this, randomizeButton, randomizedescription);*/
174 }
175 }
176 }
177
178 if (m_ToolboxType == EAttributeToolBoxType.SELECTABLE_BUTTON)
179 {
180 int value = var.GetInt();
181 m_ToolBoxComponent.SetFocusedItem(value);
182 }
183
184 super.Init(w, attribute);
185 }
186
187 //Set icon and set button hover description
188 protected void DelayedInit(bool hasIcon, bool hasDescription)
189 {
190 array<SCR_ButtonBaseComponent> elements = new array<SCR_ButtonBaseComponent>;
191 int count = m_ToolBoxComponent.GetItems(elements);
192
194 count -1;
195
196 for (int i = 0; i < count; i++)
197 {
199 if(!value)
200 continue;
201
202 elements[i].m_bShowBorderOnHover = m_bShowBorderOnHover;
203
204 if (hasIcon)
205 {
206 ResourceName icon = value.GetIcon();
207 ImageWidget imageWidget = ImageWidget.Cast(elements[i].GetRootWidget().FindAnyWidget("Image"));
208
209 if (imageWidget)
210 {
211 if (!icon.IsEmpty())
212 {
213 if (!value.IsImageset())
214 imageWidget.LoadImageTexture(0, icon);
215 else
216 imageWidget.LoadImageFromSet(0, icon, value.GetIconName());
217 }
218 else
219 {
220 imageWidget.SetVisible(false);
221 Widget textWidget = elements[i].GetRootWidget().FindAnyWidget("Text");
222 if (textWidget)
223 textWidget.SetVisible(true);
224 }
225 }
226 }
227
228 if (hasDescription)
229 {
231 if (!button)
232 {
233 button = new SCR_AttributeButtonUIComponent();
234 elements[i].GetRootWidget().AddHandler(button);
235 }
236
237 button.ButtonDescriptionInit(this, elements[i], value.GetDescription(), value.GetName());
238 }
239 }
240 }
241
242 //---- REFACTOR NOTE END ----
243
244 //Sets a default state for the UI and var value if conflicting attribute
246 {
247 if (m_ToolboxType == EAttributeToolBoxType.SELECTABLE_BUTTON)
248 ToggleButtonSelected(true, 0);
249 else if (m_ToolboxType == EAttributeToolBoxType.MULTI_SELECTABLE_BUTTON)
250 ToggleButtonSelected(false, -1);
251
252 if (var && m_ToolboxType != EAttributeToolBoxType.SINGLE_BUTTON)
253 {
254 if (var)
255 var.SetInt(0);
256 }
257
259 }
260
262 {
263 if (!var)
264 return;
265
266 if (m_ToolboxType == EAttributeToolBoxType.SELECTABLE_BUTTON)
267 {
269 {
270 m_ToolBoxComponent.SetItemSelected(var.GetInt(), true, false);
272 }
273 else
274 {
275 ToggleButtonSelected(true, var.GetInt());
276
277 if (m_ToolboxType == EAttributeToolBoxType.SELECTABLE_BUTTON)
279 }
280 }
281
283 }
284
293
302
303 //-1 means all are set to selected value
304 override void ToggleButtonSelected(bool selected, int index, bool animated = true)
305 {
306 if (m_ToolboxType == EAttributeToolBoxType.SELECTABLE_BUTTON && index == -1)
307 {
308 if (m_bSelectionButtonIsSelected == selected)
309 return;
310 else
312 }
313
314 int count = m_ToolBoxComponent.m_aSelectionElements.Count();
315
316 if (index > count)
317 return;
318
319 //Set all selected/deselected
320 if (index < 0)
321 {
322 for(int i = 0; i < count; ++i)
323 {
324 m_ToolBoxComponent.SetItemSelected(i, selected);
325 m_ToolBoxComponent.GetItem(i).ShowBorder(selected, animated);
326 }
327
328 }
329 //Deselect current and select new
330 else if (selected && m_ToolboxType == EAttributeToolBoxType.SELECTABLE_BUTTON)
331 {
332 for(int i = 0; i < count; ++i)
333 {
334 if (m_ToolBoxComponent.m_aSelectionElements[i].IsToggled())
335 {
336 if (i != index)
337 {
338 m_ToolBoxComponent.SetItemSelected(i, false, animated);
339 m_ToolBoxComponent.SetItemSelected(index, true, animated);
340 m_ToolBoxComponent.GetItem(i).ShowBorder(false, animated);
341 m_ToolBoxComponent.GetItem(index).ShowBorder(true, animated);
342 }
343 return;
344 }
345 }
346 }
347 //Set item selected/deslected
348 else {
349 m_ToolBoxComponent.SetItemSelected(index, selected);
350 m_ToolBoxComponent.GetItem(index).ShowBorder(selected, animated);
351 }
352 }
353
354 protected void OnSingleButton(SCR_ToolboxComponent toolbox, int index, bool state)
355 {
356 if (!state)
357 return;
358
359 OnChangeInternal(null, index, state, false);
360 m_ToolBoxComponent.SetItemSelected(index, false);
361 }
362
363 protected void OnSelectableButton(SCR_ToolboxComponent toolbox, int index)
364 {
366 OnChangeInternal(null, index, 0, false);
367 }
368
369 protected void OnMultiSelectButton(SCR_ToolboxComponent toolbox, int index, bool state)
370 {
371 //This logic is done via flags and needs custom script
372 }
373
374 protected void UpdateButtonBorder(int selectedIndex)
375 {
376 array<SCR_ButtonBaseComponent> elements = new array<SCR_ButtonBaseComponent>;
377
378 int count = m_ToolBoxComponent.GetItems(elements);
379
380 for(int i = 0; i < count; i++)
381 {
382 //~ Show Border
383 if (i == selectedIndex)
384 elements[i].ShowBorder(true);
385 //~ Hide border
386 else
387 elements[i].ShowBorder(false);
388 }
389 }
390
391 //---- REFACTOR NOTE START: Hardcoded overflow value
392 // Call later for button randomizer
393
394 //protected ref SCR_BaseEditorAttributeEntryToolbox m_ToolboxData;
395 override bool OnChangeInternal(Widget w, int x, int y, bool finished)
396 {
397 if (m_bHasRandomizeButton && x == m_ButtonBoxData.GetValueCount())
398 {
399 int currentIndex = m_ToolBoxComponent.GetCurrentIndex();
400 int count = m_ToolBoxComponent.m_aSelectionElements.Count();
401
402 for(int i = 0; i < count; ++i)
403 {
404 m_ToolBoxComponent.SetItemSelected(i, false);
405 }
406 GetGame().GetCallqueue().CallLater(DelayedButtonRandomizer, 100, false, currentIndex);
407
408 return false;
409 }
410
412 if (!attribute) return false;
413 SCR_BaseEditorAttributeVar var = attribute.GetVariable(true);
414
415 var.SetInt(x);
416 super.OnChangeInternal(w, x, y, finished);
417
418 GetGame().GetCallqueue().CallLater(UpdateButtonBorder, 1, false, x);
419
420 return false;
421 }
422
423 protected void DelayedButtonRandomizer(int currentIndex)
424 {
425 int index = currentIndex;
426 int overflow = 10;
427 while (index == currentIndex && overflow > 0)
428 {
429 index = Math.RandomInt(m_iRandomizerButtonStart, m_ButtonBoxData.GetValueCount());
430 overflow--;
431 }
432
433 m_ToolBoxComponent.SetCurrentItem(index, false, true);
435 }
436
437 //---- REFACTOR NOTE END ----
438
439 /*
440 //Set focus of current selected element
441 override bool OnFocus(Widget w, int x, int y)
442 {
443 if (m_ToolboxType != EAttributeToolBoxType.SELECTABLE_BUTTON || !m_ToolBoxComponent)
444 return super.OnFocus(w, x, y);
445
446 SCR_BaseEditorAttribute attribute = GetAttribute();
447 if (!attribute)
448 return super.OnFocus(w, x, y);
449
450 SCR_BaseEditorAttributeVar var = attribute.GetVariableOrCopy();
451 if (!var)
452 return super.OnFocus(w, x, y);
453
454 m_ToolBoxComponent.SetFocusedItem(var.GetInt(), false);
455 return super.OnFocus(w, x, y);
456 }
457 */
458
459 override void HandlerDeattached(Widget w)
460 {
462 {
463 if (m_ToolboxType == EAttributeToolBoxType.SINGLE_BUTTON)
464 m_ToolBoxComponent.m_OnChanged.Remove(OnSingleButton);
465 else if (m_ToolboxType == EAttributeToolBoxType.SELECTABLE_BUTTON)
466 m_ToolBoxComponent.m_OnChanged.Remove(OnSelectableButton);
467 else if (m_ToolboxType == EAttributeToolBoxType.MULTI_SELECTABLE_BUTTON)
468 m_ToolBoxComponent.m_OnChanged.Remove(OnMultiSelectButton);
469 }
470 }
471};
472
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SCR_BaseEditorAttributeFloatStringValues(array< ref SCR_EditorAttributeFloatStringValueHolder > values)
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Get all prefabs that have the spawner data
Widget GetRootWidget()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition Math.c:13
void ButtonDescriptionInit(SCR_ButtonBoxAttributeUIComponent attributeUIComponent, SCR_ButtonBaseComponent button, string buttonDescription, string buttonName=string.Empty)
Base Attribute Script for other attributes to inherent from to get and set varriables in Editor Attri...
sealed SCR_BaseEditorAttributeVar GetVariable(bool createWhenNull=false)
sealed SCR_BaseEditorAttributeVar GetVariableOrCopy()
int GetEntries(notnull array< ref SCR_BaseEditorAttributeEntry > outEntries)
Get attribute this component represents return Editor attribute *SCR_BaseEditorAttribute GetAttribute()
Base class for any button, regardless its own content.
ref SCR_BaseEditorAttributeFloatStringValues m_ButtonBoxData
void DelayedInit(bool hasIcon, bool hasDescription)
SCR_BaseEditorAttributeFloatStringValues GetButtonBoxData()
override void ToggleButtonSelected(bool selected, int index, bool animated=true)
override void Init(Widget w, SCR_BaseEditorAttribute attribute)
override void SetFromVar(SCR_BaseEditorAttributeVar var)
void OnSelectableButton(SCR_ToolboxComponent toolbox, int index)
override void SetVariableToDefaultValue(SCR_BaseEditorAttributeVar var)
override bool OnChangeInternal(Widget w, int x, int y, bool finished)
void OnMultiSelectButton(SCR_ToolboxComponent toolbox, int index, bool state)
void OnSingleButton(SCR_ToolboxComponent toolbox, int index, bool state)
void GetPresetValues(out int buttonsOnRow, out bool hasRandomizeButton, out ResourceName iconOfRandomizeButton, out bool hasIcon, out bool hasButtonDescription, out string buttonDescription, out int buttonHeight)
UIInfo used by editor attribute system.
void CopyFromEditorAttributeUIInfo(notnull SCR_EditorAttributeUIInfo source, LocalizedString overwriteDescription=string.Empty, Color overwriteColor=null)
SCR_FieldOfViewSettings Attribute