Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ButtonSplitComponent.c
Go to the documentation of this file.
1 
4 //------------------------------------------------------------------------------------------------
6 {
7  protected ref array<ref Widget> m_aWidgetCells = new array<ref Widget>();
8  protected ref array<bool> m_aPreventContentChange = new array<bool>;
9 
10  protected ref array<SCR_ButtonComponent> m_aInnerButtons = new array<SCR_ButtonComponent>;
11 
12  protected Color m_cColorContent;
13 
14  protected ref Widget m_wHoverWidget;
15 
16  [Attribute(defvalue: "0")]
17  protected int m_iButtonPaddingLeft;
18  [Attribute(defvalue: "0")]
19  protected int m_iButtonPaddingTop;
20  [Attribute(defvalue: "0")]
21  protected int m_iButtonPaddingRigh;
22  [Attribute(defvalue: "0")]
23  protected int m_iButtonPaddingBottom;
24 
25  protected bool m_bColorizeFocusLost = true;
26 
27  //------------------------------------------------------------------------------------------------
28  void SetColorizeFocusLost(bool colorize) { m_bColorizeFocusLost = colorize; }
29 
30  //------------------------------------------------------------------------------------------------
31  override protected void HandlerAttached(Widget w)
32  {
33  super.HandlerAttached(w);
34  HorizontalLayoutSlot.SetPadding(m_wOverlay, m_iButtonPaddingLeft, m_iButtonPaddingTop, m_iButtonPaddingRigh, m_iButtonPaddingBottom);
35  m_cColorContent = COLOR_CONTENT_DEFAULT;
36  }
37 
38  //------------------------------------------------------------------------------------------------
39  override bool OnMouseEnter(Widget w, int x, int y)
40  {
41  if (!m_bColorizeFocusLost)
42  return false;
43 
44  super.OnMouseEnter(w, x, y);
45  m_wHoverWidget = w;
46 
47  return false;
48  }
49 
50  //------------------------------------------------------------------------------------------------
51  override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
52  {
53  super.OnMouseLeave(w, enterW, x, y);
54 
55  if (!m_bColorizeFocusLost)
56  {
57  m_OnHoverLeave.Invoke();
58  return false;
59  }
60 
61  return false;
62  }
63 
64  //------------------------------------------------------------------------------------------------
65  override protected void ColorizeWidgets(Color colorBackground, Color colorContent, float speed = -1)
66  {
67  if (speed < 0)
68  speed = m_fAnimationRate;
69 
70  m_cColorContent = colorContent;
71  ColorizeCellPart("Background", colorBackground, speed, false);
72  ColorizeCellPart("Content", m_cColorContent, speed, true);
73  }
74 
75  //------------------------------------------------------------------------------------------------
76  void InsertWidgetCells(array<string> cellNames)
77  {
78  int i = 0;
79 
80  foreach (string cellName : cellNames)
81  {
82  Widget w = m_wRoot.FindAnyWidget(cellName);
83  if(w)
84  {
85  m_aWidgetCells.Insert(w);
86  m_aPreventContentChange.Insert(false);
87  }
88  }
89  }
90 
91  //------------------------------------------------------------------------------------------------
93  void SetupInnerButton(string widgetName)
94  {
95  Widget w = m_wRoot.FindAnyWidget(widgetName);
96  if(!w)
97  return;
98 
99  // Has this cell a button?
100  SCR_ButtonComponent button = SCR_ButtonComponent.Cast(w.FindHandler(SCR_ButtonComponent));
101  if(!button)
102  return;
103 
104  // Insert on click to focus root
105  button.m_OnFocus.Insert(OnInnerButtonFocus);
106  }
107 
108  //------------------------------------------------------------------------------------------------
110  protected void OnInnerButtonFocus(Widget w)
111  {
112  if(!m_wHoverWidget)
113  return;
114  GetGame().GetWorkspace().SetFocusedWidget(m_wHoverWidget);
115 
116  if(!m_wRoot)
117  return;
118  GetGame().GetWorkspace().SetFocusedWidget(m_wRoot);
119  }
120 
121  //------------------------------------------------------------------------------------------------
123  protected void ColorizeCellPart(string partName, Color c, float speed, float prevent)
124  {
125  for (int i = 0; i < m_aWidgetCells.Count(); i++)
126  {
127  if (i > m_aPreventContentChange.Count())
128  break;
129 
130  if (prevent && m_aPreventContentChange[i])
131  {
132  continue;
133  }
134 
135  Widget w = m_aWidgetCells[i];
136  Widget wPart = null;
137  string name = w.GetName();
138  if (!w)
139  continue;
140 
141  wPart = w.FindAnyWidget(partName);
142 
143  if (!wPart)
144  wPart = w.FindAnyWidget("Overlay");
145 
146  if (wPart)
147  AnimateWidget.Color(wPart, c, speed);
148  }
149  }
150 
151  //------------------------------------------------------------------------------------------------
153  void ColorizeCellPart(string partName, Color c, float speed, float prevent, int id)
154  {
155  if (prevent)
156  return;
157 
158  Widget w = m_aWidgetCells[id];
159  Widget wPart = null;
160 
161  if (w)
162  wPart = w.FindAnyWidget(partName);
163 
164  if (!wPart)
165  wPart = w.FindAnyWidget("Overlay");
166 
167  if (wPart)
168  AnimateWidget.Color(wPart, c, speed);
169  }
170 
171  //------------------------------------------------------------------------------------------------
172  void PreventContentColoringOn(int iCellId, bool bPrevent)
173  {
174  m_aPreventContentChange[iCellId] = bPrevent;
175  }
176 
177  //------------------------------------------------------------------------------------------------
178  Color GetColorContent()
179  {
180  return Color.FromInt(m_cColorContent.PackToInt());
181  }
182 };
SCR_ButtonSplitComponent
Definition: SCR_ButtonSplitComponent.c:5
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_wHoverWidget
protected Widget m_wHoverWidget
Definition: SCR_ScriptedWidgetTooltip.c:22
SCR_ButtonComponent
Deprecated button component. Still used in many prefabs, so it works, it's just stripped of most of t...
Definition: SCR_ButtonComponent.c:4
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_wOverlay
private Widget m_wOverlay
Definition: SCR_AISettingsComponent.c:46