Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ButtonTextComponent.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4  [Attribute("Text", desc: "Text widget name within the button")]
5  protected LocalizedString m_sTextWidgetName;
6 
7  [Attribute()]
8  protected LocalizedString m_sText;
9 
10  [Attribute("0", UIWidgets.CheckBox)]
11  bool m_bUseTextColorization;
12 
13  [Attribute(UIColors.GetColorAttribute(UIColors.NEUTRAL_INFORMATION), UIWidgets.ColorPicker)]
14  ref Color m_TextDefault;
15 
16  [Attribute(UIColors.GetColorAttribute(UIColors.CONTRAST_COLOR), UIWidgets.ColorPicker)]
17  ref Color m_TextToggled;
18 
19  protected TextWidget m_wText;
20 
21  protected ref ScriptInvokerVoid m_OnMouseEnter;
22  protected ref ScriptInvokerVoid m_OnMouseLeave;
23 
24  //------------------------------------------------------------------------------------------------
25  override void HandlerAttached(Widget w)
26  {
27  super.HandlerAttached(w);
28  m_wText = TextWidget.Cast(w.FindAnyWidget(m_sTextWidgetName));
29  if (m_wText)
30  m_wText.SetText(m_sText);
31  }
32 
33  //------------------------------------------------------------------------------------------------
34  override void SetToggled(bool toggled, bool animate = true, bool invokeChange = true)
35  {
36  if (!m_bCanBeToggled)
37  return;
38 
39  super.SetToggled(toggled, animate, invokeChange);
40  ColorizeText(animate);
41  }
42 
43  //------------------------------------------------------------------------------------------------
44  override bool OnMouseEnter(Widget w, int x, int y)
45  {
46  if (m_OnMouseEnter)
47  m_OnMouseEnter.Invoke();
48 
49  return super.OnMouseEnter(w, x, y);
50  }
51 
52  //------------------------------------------------------------------------------------------------
53  override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
54  {
55  if (m_OnMouseLeave)
56  m_OnMouseLeave.Invoke();
57 
58  return super.OnMouseLeave(w, enterW, x, y);
59  }
60 
61  //------------------------------------------------------------------------------------------------
62  protected void ColorizeText(bool animate = true)
63  {
64  if (!m_bUseTextColorization || !m_wText)
65  return;
66 
67  Color color;
68  if (m_bIsToggled && m_bCanBeToggled)
69  color = m_TextToggled;
70  else
71  color = m_TextDefault;
72 
73  if (animate)
74  AnimateWidget.Color(m_wText, color, m_fAnimationRate);
75  else
76  {
77  AnimateWidget.StopAnimation(m_wText, WidgetAnimationColor);
78  m_wText.SetColor(color);
79  }
80  }
81 
82  //------------------------------------------------------------------------------------------------
83  void SetText(string text)
84  {
85  if (m_sText == text)
86  return;
87 
88  m_sText = text;
89  if (m_wText)
90  m_wText.SetText(text);
91  }
92 
93  //------------------------------------------------------------------------------------------------
94  void SetTextWithParam(string text, string param1, string param2)
95  {
96  m_sText = text;
97  if (m_wText)
98  m_wText.SetTextFormat(text, param1, param2);
99  }
100 
101  //------------------------------------------------------------------------------------------------
102  string GetText()
103  {
104  return m_sText;
105  }
106 
107  //------------------------------------------------------------------------------------------------
108  TextWidget GetTextWidget()
109  {
110  return m_wText;
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  ScriptInvokerVoid GetOnMouseEnter()
115  {
116  if (!m_OnMouseEnter)
118 
119  return m_OnMouseEnter;
120  }
121 
122  //------------------------------------------------------------------------------------------------
123  ScriptInvokerVoid GetOnMouseLeave()
124  {
125  if (!m_OnMouseLeave)
127 
128  return m_OnMouseLeave;
129  }
130 
131  //------------------------------------------------------------------------------------------------
132  static SCR_ButtonTextComponent GetButtonText(string name, Widget parent, bool searchAllChildren = true)
133  {
134  auto comp = SCR_ButtonTextComponent.Cast(
135  SCR_WLibComponentBase.GetComponent(SCR_ButtonTextComponent, name, parent, searchAllChildren)
136  );
137  return comp;
138  }
139 
140  //------------------------------------------------------------------------------------------------
141  static SCR_ButtonTextComponent FindButtonTextComponent(notnull Widget w)
142  {
143  return SCR_ButtonTextComponent.Cast(w.FindHandler(SCR_ButtonTextComponent));
144  }
145 };
SCR_WLibComponentBase
Base class for all final Reforger interactive elements.
Definition: SCR_WLibComponentBase.c:4
m_bCanBeToggled
protected bool m_bCanBeToggled
Definition: SCR_ModularButtonComponent.c:41
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_OnMouseEnter
ref ScriptInvoker m_OnMouseEnter
Definition: SCR_ModularButtonComponent.c:65
Attribute
typedef Attribute
Post-process effect of scripted camera.
UIColors
Definition: Constants.c:16
SCR_ButtonTextComponent
Definition: SCR_ButtonTextComponent.c:2
SCR_ButtonBaseComponent
Base class for any button, regardless its own content.
Definition: SCR_ButtonBaseComponent.c:3
ScriptInvokerVoid
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
Definition: SCR_ScriptInvokerHelper.c:9
LocalizedString
Definition: LocalizedString.c:21
m_OnMouseLeave
ref ScriptInvoker m_OnMouseLeave
Definition: SCR_ModularButtonComponent.c:66
m_sText
class SCR_BaseEditorAttribute m_sText