8 [
Attribute(
"#AR-Editor_Attribute_Randomize_Name")]
11 [
Attribute(
"{0C6A9655C33FB75D}UI/layouts/Editor/Attributes/Base/ButtonImageUnderlined.layout")]
12 protected ResourceName m_sButtonWithIcon;
14 [
Attribute(
"{B98EA1D6487A6F45}UI/layouts/Editor/Attributes/Base/AttributeEmptyButton.layout")]
15 protected ResourceName m_sEmptyButton;
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;
24 protected bool m_bButtonValueInitCalled;
27 protected bool m_bHasRandomizeButton;
30 protected bool m_bSelectionButtonIsSelected =
true;
35 Widget toolBox = w.FindAnyWidget(m_sUiComponentName);
39 if (!m_ToolBoxComponent)
return;
42 m_ToolBoxComponent.m_bAllowMultiselection =
false;
44 m_ToolBoxComponent.m_bAllowMultiselection =
true;
49 array<ref SCR_BaseEditorAttributeEntry> entries =
new array<ref SCR_BaseEditorAttributeEntry>;
50 attribute.GetEntries(entries);
52 bool hasIcon, hasButtonDescription;
53 ResourceName iconOfRandomizeButton;
58 foreach (SCR_BaseEditorAttributeEntry entry: entries)
64 string buttonDescription;
65 presetEntry.GetPresetValues(buttonsOnRow, m_bHasRandomizeButton, iconOfRandomizeButton, hasIcon, hasButtonDescription, buttonDescription, buttonHeight);
67 if (hasButtonDescription)
70 newButtonDescription.CopyFromEditorAttributeUIInfo(m_ButtonDescriptionUIInfo, buttonDescription);
71 m_ButtonDescriptionUIInfo = newButtonDescription;
76 multiLine.SetMaxItemsInRow(buttonsOnRow);
78 if (buttonHeight != -1)
79 multiLine.m_fElementHeight = buttonHeight;
83 m_ToolBoxComponent.m_ElementLayout = m_sButtonWithIcon;
91 m_ButtonBoxData =
data;
92 int count = m_ButtonBoxData.GetValueCount();
94 for (
int i = 0; i < count; i++)
96 m_ToolBoxComponent.AddItem(m_ButtonBoxData.GetValuesEntry(i).GetName());
99 Widget buttonRow = w.FindAnyWidget(
"ButtonRow");
102 if (buttonRow && !m_sEmptyButton.IsEmpty())
104 while (count < buttonsOnRow)
106 Widget emptyButton =
GetGame().GetWorkspace().CreateWidgets(m_sEmptyButton, buttonRow);
107 UniformGridSlot.SetRow(emptyButton, 0);
108 UniformGridSlot.SetColumn(emptyButton, count);
117 if (hasIcon || hasButtonDescription)
118 GetGame().GetCallqueue().CallLater(DelayedInit, 1,
false, hasIcon, hasButtonDescription);
121 m_ToolBoxComponent.m_OnChanged.Insert(OnSingleButton);
123 m_ToolBoxComponent.m_OnChanged.Insert(OnSelectableButton);
125 m_ToolBoxComponent.m_OnChanged.Insert(OnMultiSelectButton);
130 int value = var.GetInt();
131 if (value >= 0 && value < m_ButtonBoxData.GetValueCount())
132 m_ToolBoxComponent.SetItemSelected(value,
false);
138 m_ToolBoxComponent.AddItem(m_sRandomizeButtonLabel);
140 if (hasIcon && !iconOfRandomizeButton.IsEmpty())
142 array<SCR_ButtonBaseComponent> elements =
new array<SCR_ButtonBaseComponent>;
143 int count = m_ToolBoxComponent.GetItems(elements);
149 ImageWidget imageWidget = ImageWidget.Cast(randomizeButton.GetRootWidget().FindAnyWidget(
"Image"));
152 imageWidget.LoadImageTexture(0, iconOfRandomizeButton);
170 int value = var.GetInt();
171 m_ToolBoxComponent.SetFocusedItem(value);
174 super.Init(w, attribute);
178 protected void DelayedInit(
bool hasIcon,
bool hasDescription)
180 array<SCR_ButtonBaseComponent> elements =
new array<SCR_ButtonBaseComponent>;
181 int count = m_ToolBoxComponent.GetItems(elements);
183 if (m_bHasRandomizeButton)
186 for (
int i = 0; i < count; i++)
194 ResourceName icon = value.GetIcon();
195 ImageWidget imageWidget = ImageWidget.Cast(elements[i].
GetRootWidget().FindAnyWidget(
"Image"));
201 imageWidget.LoadImageTexture(0, icon);
206 imageWidget.SetVisible(
false);
207 Widget textWidget = elements[i].GetRootWidget().FindAnyWidget(
"Text");
209 textWidget.SetVisible(
true);
220 elements[i].GetRootWidget().AddHandler(button);
223 button.ButtonDescriptionInit(
this, elements[i], value.GetDescription(), value.GetName());
232 ToggleButtonSelected(
true, 0);
234 ToggleButtonSelected(
false, -1);
242 SetFromVarOrDefault();
252 if (!m_bButtonValueInitCalled)
254 m_ToolBoxComponent.SetItemSelected(var.GetInt(),
true,
false);
255 m_bButtonValueInitCalled =
true;
259 ToggleButtonSelected(
true, var.GetInt());
262 m_bSelectionButtonIsSelected =
true;
266 SetFromVarOrDefault();
275 return m_ToolBoxComponent;
284 return m_ButtonBoxData;
288 override void ToggleButtonSelected(
bool selected,
int index,
bool animated =
true)
292 if (m_bSelectionButtonIsSelected == selected)
295 m_bSelectionButtonIsSelected = selected;
298 int count = m_ToolBoxComponent.m_aSelectionElements.Count();
306 for(
int i = 0; i < count; ++i)
308 m_ToolBoxComponent.SetItemSelected(i, selected);
309 m_ToolBoxComponent.GetItem(i).ShowBorder(selected, animated);
316 for(
int i = 0; i < count; ++i)
318 if (m_ToolBoxComponent.m_aSelectionElements[i].IsToggled())
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);
333 m_ToolBoxComponent.SetItemSelected(
index, selected);
334 m_ToolBoxComponent.GetItem(
index).ShowBorder(selected, animated);
343 OnChange(
null,
index, state,
false);
344 m_ToolBoxComponent.SetItemSelected(
index,
false);
349 m_bSelectionButtonIsSelected =
true;
350 OnChange(
null,
index, 0,
false);
358 protected void UpdateButtonBorder(
int selectedIndex)
360 array<SCR_ButtonBaseComponent> elements =
new array<SCR_ButtonBaseComponent>;
362 int count = m_ToolBoxComponent.GetItems(elements);
364 for(
int i = 0; i < count; i++)
367 if (i == selectedIndex)
368 elements[i].ShowBorder(
true);
371 elements[i].ShowBorder(
false);
376 override bool OnChange(Widget w,
int x,
int y,
bool finished)
378 if (m_bHasRandomizeButton && x == m_ButtonBoxData.GetValueCount())
380 int currentIndex = m_ToolBoxComponent.GetCurrentIndex();
381 int count = m_ToolBoxComponent.m_aSelectionElements.Count();
383 for(
int i = 0; i < count; ++i)
385 m_ToolBoxComponent.SetItemSelected(i,
false);
387 GetGame().GetCallqueue().CallLater(DelayedButtonRandomizer, 100,
false, currentIndex);
393 if (!attribute)
return false;
397 super.OnChange(w, x, y, finished);
399 GetGame().GetCallqueue().CallLater(UpdateButtonBorder, 1,
false, x);
405 protected void DelayedButtonRandomizer(
int currentIndex)
407 int index = currentIndex;
409 while (
index == currentIndex && overflow > 0)
411 index = Math.RandomInt(m_iRandomizerButtonStart, m_ButtonBoxData.GetValueCount());
415 m_ToolBoxComponent.SetCurrentItem(
index,
false,
true);
416 UpdateButtonBorder(
index);
439 override void HandlerDeattached(Widget w)
441 if (m_ToolBoxComponent)
444 m_ToolBoxComponent.m_OnChanged.Remove(OnSingleButton);
446 m_ToolBoxComponent.m_OnChanged.Remove(OnSelectableButton);
448 m_ToolBoxComponent.m_OnChanged.Remove(OnMultiSelectButton);