Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_DropdownEditorAttributeUIComponent.c
Go to the documentation of this file.
1 
4 {
5  protected SCR_ComboBoxComponent m_ComboBoxComponent;
6  protected ref SCR_BaseEditorAttributeFloatStringValues m_comboboxData;
7  protected bool m_bInitCalled;
8 
9  protected ref array<string> m_aDropdownArray = {};
10 
11  override void Init(Widget w, SCR_BaseEditorAttribute attribute)
12  {
13  Widget comboBoxWidget = w.FindAnyWidget(m_sUiComponentName);
14 
15  if (!comboBoxWidget)
16  return;
17 
18  m_ComboBoxComponent = SCR_ComboBoxComponent.Cast(comboBoxWidget.FindHandler(SCR_ComboBoxComponent));
19 
20  if (!m_ComboBoxComponent)
21  return;
22 
23  m_ComboBoxComponent.m_OnChanged.Insert(OnChangeComboBox);
24 
25  SCR_BaseEditorAttributeVar var = attribute.GetVariableOrCopy();
26  if (var)
27  {
28  array<ref SCR_BaseEditorAttributeEntry> entries = new array<ref SCR_BaseEditorAttributeEntry>;
29  attribute.GetEntries(entries);
30 
31  foreach (SCR_BaseEditorAttributeEntry entry: entries)
32  {
33  m_comboboxData = SCR_BaseEditorAttributeFloatStringValues.Cast(entry);
34  if (m_comboboxData)
35  {
36  int count = m_comboboxData.GetValueCount();
37 
38  for (int i = 0; i < count; i++)
39  {
40  m_ComboBoxComponent.AddItem(m_comboboxData.GetValuesEntry(i).GetName());
41  }
42 
43  continue;
44  }
45  }
46 
47  //Drop box uses text entries
48  if (!m_comboboxData)
49  {
50  int entriesCount = entries.Count();
51  for (int i = 0; i < entriesCount; i++)
52  {
54  if (entry)
55  m_aDropdownArray.Insert(entry.GetText());
56  }
57  }
58  }
59 
60  //~ Create the entries
61  CreateDropdownEntries();
62 
63  super.Init(w, attribute);
64  }
65 
66  //~ Create the actual dropdown array
67  protected void CreateDropdownEntries()
68  {
69  if (!m_ComboBoxComponent)
70  return;
71 
72  foreach(string entry : m_aDropdownArray)
73  {
74  m_ComboBoxComponent.AddItem(GetFullDropdownEntryText(entry));
75  }
76  }
77 
78  //~ Override for any additional functionality for the text entries
79  protected string GetFullDropdownEntryText(string text)
80  {
81  return text;
82  }
83 
89  {
90  return m_comboboxData;
91  }
92 
93  //Sets a default state for the UI and var value if conflicting attribute
94  override void SetVariableToDefaultValue(SCR_BaseEditorAttributeVar var)
95  {
96  m_ComboBoxComponent.SetCurrentItem(0);
97 
98  if (var)
99  var.SetInt(0);
100  }
101 
102  override void SetFromVar(SCR_BaseEditorAttributeVar var)
103  {
104  super.SetFromVar(var);
105 
106  if (!var)
107  return;
108 
109  m_ComboBoxComponent.SetCurrentItem(var.GetInt(), false, false);
110  m_bInitCalled = true;
111 
112  }
113 
114  override bool OnChange(Widget w, int x, int y, bool finished)
115  {
116  SCR_BaseEditorAttribute attribute = GetAttribute();
117  if (!attribute) return false;
118  SCR_BaseEditorAttributeVar var = attribute.GetVariable(true);
119 
120  if (var.GetInt() == x)
121  return false;
122 
123  var.SetInt(x);
124  super.OnChange(w, x, y, finished);
125  return false;
126  }
127 
128  protected void OnChangeComboBox(SCR_ComboBoxComponent comboBox, int value)
129  {
130  if (m_bInitCalled)
131  OnChange(comboBox.GetRootWidget(), value, 0, false);
132  }
133 
134 
135  override void HandlerDeattached(Widget w)
136  {
137  if (m_ComboBoxComponent)
138  m_ComboBoxComponent.m_OnChanged.Remove(OnChangeComboBox);
139  }
140 };
SCR_ComboBoxComponent
Definition: SCR_ComboBoxComponent.c:1
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_BaseEditorAttributeEntryText
void SCR_BaseEditorAttributeEntryText(string text)
Definition: SCR_BaseEditorAttribute.c:486
SCR_BaseEditorAttributeUIComponent
Definition: SCR_BaseEditorAttributeUIComponent.c:3
SCR_DropdownEditorAttributeUIComponent
Definition: SCR_DropdownEditorAttributeUIComponent.c:3