Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SelectionWidgetComponent.c
Go to the documentation of this file.
2 {
3  [Attribute()]
4  ref array<string> m_aElementNames;
5 
6  protected ref array<ref Managed> m_aElementData = new array<ref Managed>;
7 
8  [Attribute("-1", UIWidgets.EditBox, "Element selected by default")]
9  int m_iSelectedItem;
10 
11  //------------------------------------------------------------------------------------------------
12  int AddItem(string item, bool last = false, Managed data = null)
13  {
14  if (!m_aElementNames)
15  m_aElementNames = new array<string>;
16 
17  int id = m_aElementNames.Insert(item);
18 
19  m_aElementData.Insert(data);
20 
21  return id;
22  }
23 
24  //------------------------------------------------------------------------------------------------
25  void ClearAll()
26  {
27  m_iSelectedItem = -1;
28 
29  if (m_aElementNames)
30  m_aElementNames.Clear();
31 
32  if (m_aElementData)
33  m_aElementData.Clear();
34  }
35 
36  //------------------------------------------------------------------------------------------------
37  void RemoveItem(int item, bool last = false)
38  {
39  if (!m_aElementNames || item < 0 || item >= m_aElementNames.Count())
40  return;
41 
42  m_aElementNames.Remove(item);
43  m_aElementData.Remove(item);
44 
45  m_iSelectedItem = -1;
46  }
47 
48  //------------------------------------------------------------------------------------------------
49  int GetCurrentIndex()
50  {
51  return m_iSelectedItem;
52  }
53 
54  //------------------------------------------------------------------------------------------------
55  string GetCurrentItem()
56  {
57  return GetItemName(m_iSelectedItem);
58  }
59 
60  //------------------------------------------------------------------------------------------------
61  Managed GetCurrentItemData()
62  {
63  if (!m_aElementData.IsIndexValid(m_iSelectedItem))
64  return null;
65 
66  return m_aElementData[m_iSelectedItem];
67  }
68 
69  //------------------------------------------------------------------------------------------------
70  string GetItemName(int item)
71  {
72  if (!m_aElementNames || !m_aElementData || item < 0 || item >= m_aElementNames.Count())
73  return string.Empty;
74 
75  return m_aElementNames[item];
76  }
77 
78  //------------------------------------------------------------------------------------------------
79  Managed GetItemData(int item)
80  {
81  if (!m_aElementNames || !m_aElementData || item < 0 || item >= m_aElementNames.Count() || item >= m_aElementData.Count())
82  return null;
83 
84  return m_aElementData[item];
85  }
86 
87  //------------------------------------------------------------------------------------------------
88  int GetNumItems()
89  {
90  if (!m_aElementNames)
91  return 0;
92 
93  return m_aElementNames.Count();
94  }
95 
96  //------------------------------------------------------------------------------------------------
97  bool SetCurrentItem(int i, bool playSound = false, bool animate = false)
98  {
99  if (i < 0 || !m_aElementNames || !m_aElementData || i >= m_aElementNames.Count())
100  return false;
101 
102  if (playSound)
103  PlaySound(m_sSoundClicked);
104 
105  if (m_iSelectedItem == i)
106  return false;
107 
108  m_iSelectedItem = i;
109 
110  return true;
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  static SCR_SelectionWidgetComponent GetSelectionComponent(string name, Widget parent, bool searchAllChildren = true)
115  {
116  auto comp = SCR_SelectionWidgetComponent.Cast(
117  SCR_WLibComponentBase.GetComponent(SCR_SelectionWidgetComponent, name, parent, searchAllChildren)
118  );
119  return comp;
120  }
121 };
SCR_ChangeableComponentBase
Base class for all widgets that can change their internal state as editbox or spinbox.
Definition: SCR_ChangeableComponentBase.c:4
PlaySound
SCR_ParticleContactComponentClass ScriptComponentClass PlaySound(IEntity owner, SCR_ParticleContactComponentClass prefabData, Contact contact)
Definition: SCR_ParticleContactComponent.c:38
SCR_WLibComponentBase
Base class for all final Reforger interactive elements.
Definition: SCR_WLibComponentBase.c:4
Attribute
typedef Attribute
Post-process effect of scripted camera.
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
SCR_SelectionWidgetComponent
Definition: SCR_SelectionWidgetComponent.c:1