Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ComboBoxIconComponent.c
Go to the documentation of this file.
2 {
3  [Attribute()]
4  protected ref array<ResourceName> m_aElementIcons;
5  protected ref array<float> m_aElementIconRotations;
6 
7  [Attribute("ComboBoxIcon")]
8  protected string m_sIconWidgetName;
9 
10  protected ImageWidget m_IconWidget;
11  protected ref ScriptInvoker Event_OnCreateElement = new ScriptInvoker;
12  protected ref Color m_cIconDisabledColor = new Color (0.8, 0.8, 0.8, 1);
13 
14  protected override void UpdateName()
15  {
16  super.UpdateName();
17 
18  if (!m_IconWidget)
19  return;
20 
21  if (m_aElementIcons && m_iSelectedItem >= 0 && m_iSelectedItem < m_aElementIcons.Count() && m_aElementIcons[m_iSelectedItem] != string.Empty)
22  {
23  m_IconWidget.LoadImageTexture(0, m_aElementIcons[m_iSelectedItem]);
24  m_IconWidget.SetImage(0);
25  m_IconWidget.SetRotation(m_aElementIconRotations[m_iSelectedItem]);
26  m_IconWidget.SetVisible(true);
27  }
28  else {
29  m_IconWidget.SetVisible(false);
30  }
31  }
32 
33  //------------------------------------------------------------------------------------------------
34  int AddItemAndIcon(string item, ResourceName icon, float rotation = 0, Managed data = null)
35  {
36  if (!m_aElementIcons)
37  m_aElementIcons = new array<ResourceName>;
38 
39  if (!m_aElementIconRotations)
40  m_aElementIconRotations = new array<float>;
41 
42  m_aElementIcons.Insert(icon);
43  m_aElementIconRotations.Insert(rotation);
44 
45  int i = super.AddItem(item, false, data);
46  return i;
47  }
48 
49  //------------------------------------------------------------------------------------------------
50  ImageWidget GetIconWidget()
51  {
52  return m_IconWidget;
53  }
54 
55  //------------------------------------------------------------------------------------------------
56  override int AddItem(string item, bool last = false, Managed data = null)
57  {
58  m_aElementIcons.Insert(string.Empty);
59  int i = super.AddItem(item, last, data);
60  return i;
61  }
62 
63  //------------------------------------------------------------------------------------------------
64  override void ClearAll()
65  {
66  m_aElementIcons.Clear();
67  super.ClearAll();
68  }
69 
70  void AllowFocus(bool allowFocus)
71  {
72  if (allowFocus)
73  m_wContentRoot.ClearFlags(WidgetFlags.NOFOCUS);
74  else
75  m_wContentRoot.SetFlags(WidgetFlags.NOFOCUS);
76  }
77 
78  //------------------------------------------------------------------------------------------------
79  ScriptInvoker GetOnCreateElement()
80  {
81  return Event_OnCreateElement;
82  }
83 
84  //------------------------------------------------------------------------------------------------
85  protected override void OnCreateElement(Widget elementWidget, int index)
86  {
87  ImageWidget iconWidget = ImageWidget.Cast(elementWidget.FindAnyWidget("Icon"));
88 
89  SCR_ButtonTextComponent textComp = SCR_ButtonTextComponent.Cast(elementWidget.GetHandler(0));
90 
91  if (!iconWidget)
92  return;
93 
94  if (m_aElementIcons && index >= 0 && index < m_aElementIcons.Count() && m_aElementIcons[index] != string.Empty)
95  {
96  iconWidget.LoadImageTexture(0, m_aElementIcons[index]);
97  iconWidget.SetImage(0);
98  iconWidget.SetRotation(m_aElementIconRotations[m_iSelectedItem]);
99  iconWidget.SetVisible(true);
100  }
101  else
102  {
103  iconWidget.SetVisible(false);
104  }
105 
106 
107  Event_OnCreateElement.Invoke(elementWidget, index);
108  }
109 
110  void SetElementEnabled(int index, bool enable)
111  {
112  if (index >= 0 && index < m_aElementWidgets.Count())
113  {
114  m_aElementWidgets[index].SetEnabled(enable);
115 
116  ImageWidget iconWidget = ImageWidget.Cast(m_aElementWidgets[index].FindAnyWidget("Icon"));
117  if (!iconWidget)
118  return;
119 
120  if (enable)
121  iconWidget.SetColor(Color.FromInt(Color.WHITE));
122  else
123  iconWidget.SetColor(m_cIconDisabledColor);
124  }
125  }
126 
127  //------------------------------------------------------------------------------------------------
128  override void RemoveItem(int item, bool last = false)
129  {
130  if (item < m_aElementIcons.Count())
131  m_aElementIcons.Remove(item);
132 
133  super.RemoveItem(item, last);
134  }
135 
136  override void HandlerAttached(Widget w)
137  {
138  m_IconWidget = ImageWidget.Cast(w.FindAnyWidget(m_sIconWidgetName));
139  super.HandlerAttached(w);
140  }
141 };
SCR_ComboBoxComponent
Definition: SCR_ComboBoxComponent.c:1
SCR_ComboBoxIconComponent
Definition: SCR_ComboBoxIconComponent.c:1
m_sIconWidgetName
protected string m_sIconWidgetName
Definition: SCR_GroupEditableEntityUIComponent.c:6
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_ButtonTextComponent
Definition: SCR_ButtonTextComponent.c:2
rotation
RespawnSystemComponentClass GameComponentClass vector vector rotation
Definition: RespawnSystemComponent.c:23
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305