Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ChangeableComponentBase.c
Go to the documentation of this file.
1 
3 //------------------------------------------------------------------------------------------------
5 {
6  [Attribute("true")]
7  protected bool m_bUseLabel;
8 
9  [Attribute("", UIWidgets.EditBox, "")]
10  protected string m_sLabel;
11 
12  [Attribute("true")]
13  protected bool m_bForceSize;
14 
15  [Attribute("50", UIWidgets.EditBox, "")]
16  protected float m_fSizeWithLabel;
17 
18  [Attribute("36", UIWidgets.EditBox, "")]
19  protected float m_fSizeWithoutLabel;
20 
21  [Attribute("{829BC1189A899017}UI/layouts/WidgetLibrary/WLibRefined/WLib_Label.layout", UIWidgets.EditBox, "")]
22  protected ResourceName m_sLabelLayout;
23 
24  [Attribute("SizeLayout", UIWidgets.EditBox, "Name of size layout if you want to find size that is not root child")]
25  protected string m_sSizeLayout;
26 
27  protected Widget m_wBorder;
28  protected Widget m_wBackground;
29  protected Widget m_wLabelRoot;
30 
31  ref ScriptInvoker m_OnChanged = new ScriptInvoker();
32  // Arguments passed:
33  // Toolbox (multiselect off): SCR_ToolboxComponent, int (selected item)
34  // Toolbox (multiselect on): SCR_ToolboxComponent, int (current item), bool (is selected)
35  // Checkbox: SCR_CheckboxComponent, bool (checked)
36  // Spinbox: SCR_SpinBoxComponent, int (selected item)
37  // ComboBox: SCR_ComboBoxComponent, int (selected item)
38  // EditBox: SCR_EditBoxComponent, string (text)
39  // Slider: SCR_SliderComponent, float (value)
40 
41  //------------------------------------------------------------------------------------------------
42  override void HandlerAttached(Widget w)
43  {
44  super.HandlerAttached(w);
45 
46  m_wBorder = m_wRoot.FindAnyWidget("Border");
47  m_wBackground = m_wRoot.FindAnyWidget("Background");
48 
49  if (m_wBackground)
50  m_wBackground.SetColor(Color.FromInt(UIColors.BACKGROUND_DEFAULT.PackToInt()));
51 
52  if (m_wBorder)
53  m_wBorder.SetOpacity(0);
54 
55  if (m_bUseLabel)
56  SetupLabel();
57  else
58  ClearLabel();
59  }
60 
61  //------------------------------------------------------------------------------------------------
62  override bool OnFocus(Widget w, int x, int y)
63  {
64  super.OnFocus(w, x, y);
65  if (m_wBorder)
66  AnimateWidget.Opacity(m_wBorder, 1, m_fAnimationRate);
67 
68  AnimateWidget.Color(m_wBackground, Color.FromInt(UIColors.BACKGROUND_HOVERED.PackToInt()), m_fAnimationRate);
69  return false;
70  }
71 
72  //------------------------------------------------------------------------------------------------
73  override bool OnFocusLost(Widget w, int x, int y)
74  {
75  super.OnFocusLost(w, x, y);
76 
77  if (m_wBorder)
78  AnimateWidget.Opacity(m_wBorder, 0, m_fAnimationRate);
79 
80  Widget mouseOver = WidgetManager.GetWidgetUnderCursor();
81  if (w != mouseOver && !IsChildWidget(w, mouseOver))
82  AnimateWidget.Color(m_wBackground, Color.FromInt(UIColors.BACKGROUND_DEFAULT.PackToInt()), m_fAnimationRate);
83 
84  return false;
85  }
86 
87  //------------------------------------------------------------------------------------------------
88  override bool OnMouseEnter(Widget w, int x, int y)
89  {
90  AnimateWidget.Color(m_wBackground, Color.FromInt(UIColors.BACKGROUND_HOVERED.PackToInt()), m_fAnimationRate);
91  return super.OnMouseEnter(w, x, y);
92  }
93 
94  //------------------------------------------------------------------------------------------------
95  override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
96  {
97  super.OnMouseLeave(w, enterW, x, y);
98  if (GetGame().GetWorkspace().GetFocusedWidget() == w || IsChildWidget(w, enterW))
99  return false;
100 
101  AnimateWidget.Color(m_wBackground, Color.FromInt(UIColors.BACKGROUND_DEFAULT.PackToInt()), m_fAnimationRate);
102  return false;
103  }
104 
105  //------------------------------------------------------------------------------------------------
106  protected void SetupLabel()
107  {
108  if (m_wLabelRoot)
109  return;
110 
111  SizeLayoutWidget size = SizeLayoutWidget.Cast(m_wRoot.GetChildren());
112  if (!size && !m_sSizeLayout.IsEmpty())
113  size = SizeLayoutWidget.Cast(m_wRoot.FindAnyWidget(m_sSizeLayout));
114 
115  if (size)
116  {
117  size.EnableHeightOverride(m_bForceSize);
118  size.SetHeightOverride(m_fSizeWithLabel);
119  }
120 
121  Widget contentRoot = m_wRoot.FindAnyWidget("HorizontalLayout");
122  if (!contentRoot)
123  return;
124 
125  m_wLabelRoot = GetGame().GetWorkspace().CreateWidgets(m_sLabelLayout, contentRoot);
126  if (!m_wLabelRoot)
127  return;
128 
129  TextWidget text = TextWidget.Cast(m_wLabelRoot.FindAnyWidget("Text"));
130  if (!text)
131  return;
132 
133  text.SetText(m_sLabel);
134  }
135 
136  //------------------------------------------------------------------------------------------------
137  protected void ClearLabel()
138  {
139  if (m_wLabelRoot)
140  {
141  m_wLabelRoot.RemoveFromHierarchy();
142  m_wLabelRoot = null;
143  }
144 
145  SizeLayoutWidget size = SizeLayoutWidget.Cast(m_wRoot.GetChildren());
146  if (size)
147  {
148  size.EnableHeightOverride(m_bForceSize);
149  size.SetHeightOverride(m_fSizeWithoutLabel);
150  }
151 
152  Widget layout = m_wRoot.FindAnyWidget("HorizontalLayout");
153  if (layout)
154  AlignableSlot.SetPadding(layout, 2, 2, 2, 2);
155  }
156 
157  //------------------------------------------------------------------------------------------------
158  TextWidget GetLabel()
159  {
160  return TextWidget.Cast(m_wLabelRoot.FindAnyWidget("Text"));
161  }
162 
163  //------------------------------------------------------------------------------------------------
164  void SetLabel(string label)
165  {
166  if (!m_wLabelRoot)
167  return;
168 
169  TextWidget w = TextWidget.Cast(m_wLabelRoot.FindAnyWidget("Text"));
170  if (!w)
171  return;
172 
173  m_sLabel = label;
174 
175  w.SetText(m_sLabel);
176  }
177 
178  //------------------------------------------------------------------------------------------------
179  void UseLabel(bool use)
180  {
181  if (use == m_bUseLabel)
182  return;
183 
184  if (use)
185  SetupLabel();
186  else
187  ClearLabel();
188  }
189 
190  //------------------------------------------------------------------------------------------------
191  bool IsUsingLabel()
192  {
193  return m_bUseLabel;
194  }
195 
197  //------------------------------------------------------------------------------------------------
198  Widget GetLabelWidget()
199  {
200  return m_wLabelRoot;
201  }
202 };
SCR_ChangeableComponentBase
Base class for all widgets that can change their internal state as editbox or spinbox.
Definition: SCR_ChangeableComponentBase.c:4
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_WLibComponentBase
Base class for all final Reforger interactive elements.
Definition: SCR_WLibComponentBase.c:4
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
Attribute
typedef Attribute
Post-process effect of scripted camera.
UIColors
Definition: Constants.c:16
layout
UI layouts HUD CampaignMP CampaignMainHUD layout
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:20
m_wBackground
protected ImageWidget m_wBackground
Definition: SCR_InventoryHitZonePointUI.c:382