Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AttributeTickboxUIComponent.c
Go to the documentation of this file.
1 
4 class SCR_AttributeTickboxUIComponent : ScriptedWidgetComponent
5 {
6 
7  [Attribute()]
8  protected string m_sTickBoxImageName;
9 
10  [Attribute()]
11  protected string m_sTickBoxButtonName;
12 
13  // Visuals
14  [Attribute()]
15  protected ResourceName m_sTickBoxImageToggled;
16 
17  [Attribute()]
18  protected ResourceName m_sTickBoxImageUntoggled;
19 
20  // Reference
21  protected SCR_BaseEditorAttributeUIComponent m_AttributeUI;
22  protected typename m_LinkedOverrideAttributeType = typename.Empty;
23  protected Widget m_Root;
24  protected ImageWidget m_TickBoxImage;
25  protected Widget m_TickBoxButton;
26 
27  protected float m_fDisabledAlphaColor = 0.25;
28 
29  // States
30  protected bool m_bToggled;
31  protected bool m_bEnabled = true;
32 
33  // Events
34  protected ref ScriptInvokerBool m_OnToggleChanged;
35 
36  //------------------------------------------------------------------------------------------------
39  void ToggleTickbox(bool toggled)
40  {
41  if (!m_bEnabled)
42  return;
43 
44  m_bToggled = toggled;
45 
46  if (m_OnToggleChanged)
47  m_OnToggleChanged.Invoke(toggled);
48 
49  if (toggled)
50  {
51  m_TickBoxImage.LoadImageTexture(0, m_sTickBoxImageToggled);
52  m_TickBoxImage.SetImage(0);
53  }
54  else
55  {
56  m_TickBoxImage.LoadImageTexture(0, m_sTickBoxImageUntoggled);
57  m_TickBoxImage.SetImage(0);
58  }
59 
60  SCR_AttributesManagerEditorComponent attributesManager = SCR_AttributesManagerEditorComponent.Cast(SCR_AttributesManagerEditorComponent.GetInstance(SCR_AttributesManagerEditorComponent));
61  if (!attributesManager)
62  return;
63 
64  if (m_LinkedOverrideAttributeType != typename.Empty)
65  {
67  overideValue.SetBool(toggled);
68  attributesManager.SetAttributeVariable(m_LinkedOverrideAttributeType, overideValue);
69  }
70  }
71 
72  //------------------------------------------------------------------------------------------------
75  void ToggleEnableByAttribute(bool enabled)
76  {
77  SetEnabled(enabled);
78  }
79 
80  //------------------------------------------------------------------------------------------------
81  protected void OnButtonToggle()
82  {
83  ToggleTickbox(!m_bToggled);
84  }
85 
86  //------------------------------------------------------------------------------------------------
89  bool GetToggled()
90  {
91  return m_bToggled;
92  }
93 
94  //------------------------------------------------------------------------------------------------
97  bool IsVisibleAndEnabled()
98  {
99  return m_TickBoxButton.IsEnabled() && m_Root.IsVisible();
100  }
101 
102  //------------------------------------------------------------------------------------------------
103  ScriptInvokerBool GetOnToggleChanged()
104  {
105  if (!m_OnToggleChanged)
106  m_OnToggleChanged = new ScriptInvokerBool();
107 
108  return m_OnToggleChanged;
109  }
110 
111  //------------------------------------------------------------------------------------------------
115  protected void SetVisible(bool frameVisible, bool buttonVisible)
116  {
117  m_Root.SetVisible(frameVisible);
118  m_TickBoxButton.SetVisible(buttonVisible);
119  }
120 
121  //------------------------------------------------------------------------------------------------
122  protected void SetEnabled(bool enabled)
123  {
124  m_bEnabled = enabled;
125 
126  //m_TickBoxImage.LoadImageTexture(0, m_sNonConfictingTickBoxImage);
127  Color color = Color.FromInt(m_TickBoxImage.GetColor().PackToInt());
128  if (!enabled)
129  color.SetA(m_fDisabledAlphaColor);
130  else
131  color.SetA(1);
132 
133  m_TickBoxImage.SetColor(color);
134 
135  m_TickBoxButton.SetEnabled(enabled);
136  }
137 
138  //------------------------------------------------------------------------------------------------
141  bool GetEnabled()
142  {
143  return m_bEnabled;
144  }
145 
146  //------------------------------------------------------------------------------------------------
152  void InitTickbox(bool toggleState, SCR_BaseEditorAttributeUIComponent attributeUI, typename linkedOverrideAttributeType = typename.Empty)
153  {
154  m_LinkedOverrideAttributeType = linkedOverrideAttributeType;
155 
156  SetVisible(true, true);
157  ToggleTickbox(toggleState);
158  m_AttributeUI = attributeUI;
159 
160  if (m_AttributeUI)
161  {
162  m_AttributeUI.GetOnEnabledByAttribute().Insert(OnAttributeEnabledByAttribute);
163  SetEnabled(m_AttributeUI.GetAttribute().IsEnabled());
164  }
165  }
166 
167  //------------------------------------------------------------------------------------------------
169  void InitDisabled()
170  {
171  SetVisible(true, true);
172  SetEnabled(false);
173  m_bToggled = true;
174  m_TickBoxImage.LoadImageTexture(0, m_sTickBoxImageToggled);
175  m_TickBoxImage.SetImage(0);
176  }
177 
178  //------------------------------------------------------------------------------------------------
179  protected void OnAttributeEnabledByAttribute(bool enabled)
180  {
181  SetEnabled(enabled);
182  }
183 
184  //------------------------------------------------------------------------------------------------
185  override void HandlerAttached(Widget w)
186  {
187  m_Root = w;
188 
189  m_TickBoxImage = ImageWidget.Cast(w.FindAnyWidget(m_sTickBoxImageName));
190  if (!m_TickBoxImage)
191  return;
192 
193  m_TickBoxButton = w.FindAnyWidget(m_sTickBoxButtonName);
194  if (!m_TickBoxButton)
195  return;
196 
197  ScriptInvoker onButton = ButtonActionComponent.GetOnAction(w, m_sTickBoxButtonName);
198  if (onButton) onButton.Insert(OnButtonToggle);
199  }
200 
201  //------------------------------------------------------------------------------------------------
202  override void HandlerDeattached(Widget w)
203  {
204  if (m_AttributeUI)
205  m_AttributeUI.GetOnEnabledByAttribute().Remove(OnAttributeEnabledByAttribute);
206  }
207 }
m_Root
SCR_ServerHostingModSubMenu m_Root
m_bToggled
protected bool m_bToggled
Definition: SCR_ModularButtonComponent.c:76
SCR_AttributeTickboxUIComponent
Using a controller will show/hide the Select button hint if the attribute with this script is focused...
Definition: SCR_AttributeTickboxUIComponent.c:4
SCR_BaseEditorAttributeVar
Definition: SCR_BaseEditorAttributeVar.c:1
Attribute
typedef Attribute
Post-process effect of scripted camera.
ScriptInvokerBool
ScriptInvokerBase< ScriptInvokerBoolMethod > ScriptInvokerBool
Definition: SCR_ScriptInvokerHelper.c:41
ButtonActionComponent
Component to execute action when the button or its shortcut is pressed.
Definition: ButtonActionComponent.c:2
SCR_BaseEditorAttributeUIComponent
Definition: SCR_BaseEditorAttributeUIComponent.c:3
m_bEnabled
private bool m_bEnabled
Definition: SCR_BaseManualCameraComponent.c:3