Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ButtonComponent.c
Go to the documentation of this file.
1 
3 //------------------------------------------------------------------------------------------------
5 {
6  [Attribute(uiwidget: UIWidgets.LocaleEditBox)]
7  protected LocalizedString m_sContent;
8 
9  protected Widget m_wOverlay;
10  protected Widget m_wContent;
11 
12  protected ref Color COLOR_BACKGROUND_DEFAULT = UIColors.BACKGROUND_DEFAULT;
13  protected ref Color COLOR_BACKGROUND_HOVERED = UIColors.BACKGROUND_HOVERED;
14  protected ref Color COLOR_BACKGROUND_FOCUSED = UIColors.BACKGROUND_HOVERED;
15  protected ref Color COLOR_BACKGROUND_CLICKED = UIColors.BACKGROUND_HOVERED;
16 
17  protected ref Color COLOR_CONTENT_DEFAULT = Color.White;
18  protected ref Color COLOR_CONTENT_HOVERED = Color.White;
19  protected ref Color COLOR_CONTENT_FOCUSED = Color.White;
20  protected ref Color COLOR_CONTENT_CLICKED = Color.White;
21 
22  //ref ScriptInvoker m_OnClicked = new ScriptInvoker();
23  ref ScriptInvoker m_OnHover = new ScriptInvoker();
24  ref ScriptInvoker<Widget> m_OnHoverLeave = new ScriptInvoker();
25 
26  //------------------------------------------------------------------------------------------------
27  override void HandlerAttached(Widget w)
28  {
29  super.HandlerAttached(w);
30  m_wOverlay = w.FindAnyWidget("Overlay");
31  m_wBackground = w.FindAnyWidget("Background");
32 
33  m_wContent = w.FindAnyWidget("Content");
34  if (m_wContent && m_sContent != string.Empty)
35  SetContent(m_sContent);
36 
37  if (m_wBackground)
38  m_wBackground.SetColor(COLOR_BACKGROUND_DEFAULT);
39 
40  if (m_wOverlay)
41  m_wOverlay.SetColor(COLOR_CONTENT_DEFAULT);
42  }
43 
44  /*
45  //------------------------------------------------------------------------------------------------
46  override bool OnClick(Widget w, int x, int y, int button)
47  {
48  super.OnClick(w, x, y, button);
49  if (button != 0)
50  return false;
51 
52  m_OnClicked.Invoke(w);
53  return false;
54  }
55  */
56 
57  /*
58  //------------------------------------------------------------------------------------------------
59  override protected void OnMenuSelect()
60  {
61  super.OnMenuSelect();
62  if (!m_wRoot.IsEnabled())
63  return;
64 
65  //ColorizeWidgets(COLOR_BACKGROUND_CLICKED, COLOR_CONTENT_CLICKED, m_fAnimationRate * 2);
66  //GetGame().GetCallqueue().CallLater(ResetPadding, m_fAnimationTime * 500 + 1, false);
67  }
68  */
69 
70  /*
71  //------------------------------------------------------------------------------------------------
72  override bool OnMouseButtonDown(Widget w, int x, int y, int button)
73  {
74  if (GetGame().GetWorkspace().GetFocusedWidget() == w)
75  ColorizeWidgets(COLOR_BACKGROUND_CLICKED, COLOR_CONTENT_CLICKED);
76  return false;
77  }
78 
79  //------------------------------------------------------------------------------------------------
80  override bool OnMouseButtonUp(Widget w, int x, int y, int button)
81  {
82  if (GetGame().GetWorkspace().GetFocusedWidget() == w)
83  ColorizeWidgets(COLOR_BACKGROUND_FOCUSED, COLOR_CONTENT_FOCUSED);
84  else
85  ColorizeWidgets(COLOR_BACKGROUND_HOVERED, COLOR_CONTENT_HOVERED);
86 
87  return false;
88  }
89  */
90 
91  //------------------------------------------------------------------------------------------------
92  override bool OnMouseEnter(Widget w, int x, int y)
93  {
94  super.OnMouseEnter(w, x, y);
95  m_OnHover.Invoke();
96  //if (GetGame().GetWorkspace().GetFocusedWidget() != w)
97  //ColorizeWidgets(COLOR_BACKGROUND_HOVERED, COLOR_CONTENT_HOVERED);
98 
99  return false;
100  }
101 
102  //------------------------------------------------------------------------------------------------
103  override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
104  {
105  super.OnMouseLeave(w, enterW, x, y);
106  m_OnHoverLeave.Invoke(w);
107  //if (GetGame().GetWorkspace().GetFocusedWidget() != w)
108  //ColorizeWidgets(COLOR_BACKGROUND_DEFAULT, COLOR_CONTENT_DEFAULT);
109 
110  return false;
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  override bool OnFocus(Widget w, int x, int y)
115  {
116  super.OnFocus(w, x, y);
117  m_OnFocus.Invoke(w);
118  //ColorizeWidgets(COLOR_BACKGROUND_FOCUSED, COLOR_CONTENT_FOCUSED);
119  //GetGame().GetInputManager().AddActionListener("MenuSelect", EActionTrigger.DOWN, OnMenuSelect);
120  return false;
121  }
122 
123  //------------------------------------------------------------------------------------------------
124  override bool OnFocusLost(Widget w, int x, int y)
125  {
126  super.OnFocusLost(w, x, y);
127 
128  //GetGame().GetInputManager().RemoveActionListener("MenuSelect", EActionTrigger.DOWN, OnMenuSelect);
129  //if (GetWidgetUnderCursor() == w)
130  //ColorizeWidgets(COLOR_BACKGROUND_HOVERED, COLOR_CONTENT_HOVERED);
131  //else
132  //ColorizeWidgets(COLOR_BACKGROUND_DEFAULT, COLOR_CONTENT_DEFAULT);
133  return false;
134  }
135 
136  /*
137  //------------------------------------------------------------------------------------------------
138  protected void ResetPadding()
139  {
140  ColorizeWidgets(COLOR_BACKGROUND_FOCUSED, COLOR_CONTENT_FOCUSED);
141  }
142  */
143 
144  //------------------------------------------------------------------------------------------------
145  void ColorizeWidgets(Color colorBackground, Color colorContent, float speed = -1)
146  {
147  if (speed < 0)
148  speed = m_fAnimationRate;
149 
150  AnimateWidget.Color(m_wBackground, colorBackground, speed);
151  AnimateWidget.Color(m_wOverlay, colorContent, speed);
152  }
153 
154  //------------------------------------------------------------------------------------------------
155  void SetHorizontalAlign(LayoutHorizontalAlign horizontalAlign)
156  {
157  if (!m_wContent)
158  return;
159 
160  TextWidget content = TextWidget.Cast(m_wContent);
161  if (content)
162  AlignableSlot.SetHorizontalAlign(content, horizontalAlign);
163  }
164 
165  /*
166  //------------------------------------------------------------------------------------------------
167  void SetPadding(float left = 4, float top = 4, float right = 4, float bottom = 4)
168  {
169  if (!m_wContent)
170  return;
171 
172  OverlaySlot.SetPadding(m_wContent, left, top, right, bottom);
173  }
174  */
175 
176  //------------------------------------------------------------------------------------------------
177  void SetContent(string text)
178  {
179  if (!m_wContent)
180  return;
181 
182  TextWidget content = TextWidget.Cast(m_wContent);
183  if (content)
184  {
185  content.SetText(text);
186  return;
187  }
188 
189  ImageWidget img = ImageWidget.Cast(m_wContent);
190  if (img)
191  {
192  img.LoadImageTexture(0, text);
193  return;
194  }
195  }
196 
197  //------------------------------------------------------------------------------------------------
198  void SetContentFromUIInfo(SCR_UIInfo info)
199  {
200  if (!m_wContent)
201  return;
202 
203  if (!info.SetNameTo(TextWidget.Cast(m_wContent)))
204  info.SetIconTo(ImageWidget.Cast(m_wContent));
205  }
206 
207  //------------------------------------------------------------------------------------------------
208  string GetContent()
209  {
210  return m_sContent;
211  }
212 
213  //------------------------------------------------------------------------------------------------
216  static SCR_ButtonComponent GetButtonComponent(string name, Widget parent, bool searchAllChildren = true)
217  {
218  auto comp = SCR_ButtonComponent.Cast(
219  SCR_WLibComponentBase.GetComponent(SCR_ButtonComponent, name, parent, searchAllChildren)
220  );
221  return comp;
222  }
223 };
SCR_WLibComponentBase
Base class for all final Reforger interactive elements.
Definition: SCR_WLibComponentBase.c:4
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_wContent
protected Widget m_wContent
Definition: SCR_InfoDisplay.c:64
UIColors
Definition: Constants.c:16
SCR_ButtonBaseComponent
Base class for any button, regardless its own content.
Definition: SCR_ButtonBaseComponent.c:3
SCR_UIInfo
Definition: SCR_UIInfo.c:7
m_wBackground
protected ImageWidget m_wBackground
Definition: SCR_InventoryHitZonePointUI.c:382
m_OnFocus
ref ScriptInvoker m_OnFocus
Definition: SCR_ModularButtonComponent.c:63
m_wOverlay
private Widget m_wOverlay
Definition: SCR_AISettingsComponent.c:46
LocalizedString
Definition: LocalizedString.c:21