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