Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SpinboxEditorAttributeUIComponent.c
Go to the documentation of this file.
1 
4 {
5  protected SCR_SpinBoxComponent m_SpinboxWidgetComponent;
6  protected bool m_bInitCalled;
7 
8  override void Init(Widget w, SCR_BaseEditorAttribute attribute)
9  {
10  Widget spingBoxWidget = w.FindAnyWidget(m_sUiComponentName);
11 
12  if (!spingBoxWidget) return;
13  m_SpinboxWidgetComponent = SCR_SpinBoxComponent.Cast(spingBoxWidget.FindHandler(SCR_SpinBoxComponent));
14 
15  if (!m_SpinboxWidgetComponent) return;
16  m_SpinboxWidgetComponent.m_OnChanged.Insert(OnChangeSpinbox);
17 
18  SCR_BaseEditorAttributeVar var = attribute.GetVariableOrCopy();
19  if (var)
20  {
22  array<ref SCR_BaseEditorAttributeEntry> entries = new array<ref SCR_BaseEditorAttributeEntry>;
23  attribute.GetEntries(entries);
24 
25  foreach (SCR_BaseEditorAttributeEntry entry: entries)
26  {
27  spinboxData = SCR_BaseEditorAttributeFloatStringValues.Cast(entry);
28  if (spinboxData)
29  {
30  int count = spinboxData.GetValueCount();
31 
32  for (int i = 0; i < count; i++)
33  {
34  m_SpinboxWidgetComponent.AddItem(spinboxData.GetValuesEntry(i).GetName(), i == count - 1);
35  }
36 
37  continue;
38  }
39  }
40 
41  //Spin box uses text entries
42  if (!spinboxData)
43  {
44  int entriesCount = entries.Count();
45  for (int i = 0; i < entriesCount; i++)
46  {
48  if (entry)
49  m_SpinboxWidgetComponent.AddItem(entry.GetText(), i == entriesCount - 1);
50  }
51  }
52  }
53 
54  super.Init(w, attribute);
55  }
56 
57  //Sets a default state for the UI and var value if conflicting attribute
58  override void SetVariableToDefaultValue(SCR_BaseEditorAttributeVar var)
59  {
60  m_SpinboxWidgetComponent.SetCurrentItem(0);
61 
62  if (var)
63  var.SetInt(0);
64  }
65 
66  override void SetFromVar(SCR_BaseEditorAttributeVar var)
67  {
68  super.SetFromVar(var);
69 
70  if (!var)
71  return;
72 
73  m_SpinboxWidgetComponent.SetCurrentItem(var.GetInt(), false, false);
74  m_bInitCalled = true;
75  }
76 
77  override bool OnChange(Widget w, int x, int y, bool finished)
78  {
79  SCR_BaseEditorAttribute attribute = GetAttribute();
80  if (!attribute) return false;
81  SCR_BaseEditorAttributeVar var = attribute.GetVariable(true);
82 
83  if (var.GetInt() == x)
84  return false;
85 
86  var.SetInt(x);
87  super.OnChange(w, x, y, finished);
88  return false;
89  }
90 
91  protected void OnChangeSpinbox(SCR_SpinBoxComponent spinbox, int value)
92  {
93  if (m_bInitCalled)
94  OnChange(spinbox.GetRootWidget(), value, 0, false);
95  }
96 
97 
98  override void HandlerDeattached(Widget w)
99  {
100  if (m_SpinboxWidgetComponent)
101  m_SpinboxWidgetComponent.m_OnChanged.Remove(OnChangeSpinbox);
102  }
103 };
SCR_BaseEditorAttributeVar
Definition: SCR_BaseEditorAttributeVar.c:1
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_SpinBoxComponent
Definition: SCR_SpinBoxComponent.c:1
SCR_SpinboxEditorAttributeUIComponent
Definition: SCR_SpinboxEditorAttributeUIComponent.c:3
SCR_BaseEditorAttributeEntryText
void SCR_BaseEditorAttributeEntryText(string text)
Definition: SCR_BaseEditorAttribute.c:486
SCR_BaseEditorAttributeUIComponent
Definition: SCR_BaseEditorAttributeUIComponent.c:3