Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SelectableButtonComponent.c
Go to the documentation of this file.
1 
4 //------------------------------------------------------------------------------------------------
6 {
7  [Attribute(params: "edds imageset")]
8  protected ResourceName m_sImageResource;
9 
10  [Attribute(defvalue: "", desc: "When the texture is an image set, define the quad name here")]
11  private string m_sImageName;
12 
13  [Attribute(defvalue: "4", UIWidgets.EditBox, "How ,uch of spaceis between image and text - work if both are visible")]
14  protected float m_fContentPadding;
15 
16  //protected string WIDGET_CHECKER = "Checker";
17  protected string WIDGET_CONTET_HLAYOUT = "hLayoutContent";
18  protected string WIDGET_IMAGE = "ImageContent";
19 
20  ref ScriptInvoker m_OnChanged = new ScriptInvoker();
21  protected bool m_bIsSelected = false;
22  protected bool m_bIsTriggered = true;
23 
24  //protected Widget m_wChecked;
25  protected Widget m_wHLayoutContent;
26  protected ImageWidget m_wImageContent;
27 
28  protected ref Color COLOR_CHECKED_TRUE = UIColors.CONTRAST_COLOR;
29  protected ref Color COLOR_CHECKED_FALSE = UIColors.WHITE_DEFAULT;
30 
31  //------------------------------------------------------------------------------------------------
32  override void HandlerAttached(Widget w)
33  {
34  super.HandlerAttached(w);
35 
36  //m_wChecked = m_wRoot.FindAnyWidget(WIDGET_CHECKER);
37  m_wHLayoutContent = m_wRoot.FindAnyWidget(WIDGET_CONTET_HLAYOUT);
38  m_wImageContent = ImageWidget.Cast(m_wRoot.FindAnyWidget(WIDGET_IMAGE));
39 
40  // Set image
41  SetImage(m_sImageResource, m_sImageName);
42 
43  // Set checcker color
44  if (m_wOverlay)
45  {
46  if (m_bIsSelected)
47  m_wOverlay.SetColor(COLOR_CHECKED_TRUE);
48  else
49  m_wOverlay.SetColor(COLOR_CHECKED_FALSE);
50  }
51 
52  // Image - Text padding
53  if (!m_wImageContent || !m_wContent)
54  return;
55 
56  if (m_wImageContent.IsVisible() && m_wContent.IsVisible())
57  {
58  HorizontalLayoutSlot.SetPadding(m_wContent, m_fContentPadding, 0, 0, 0);
59  }
60  }
61 
62  //------------------------------------------------------------------------------------------------
63  void SetImage(ResourceName sResource, string sImageName)
64  {
65  if (!m_wImageContent)
66  return;
67 
68  m_wImageContent.SetVisible(!sResource.IsEmpty());
69 
70  if(sResource.IsEmpty())
71  return;
72 
73  if (sResource.EndsWith("imageset"))
74  m_wImageContent.LoadImageFromSet(0, sResource, sImageName);
75  else
76  m_wImageContent.LoadImageTexture(0, sResource);
77  }
78 
79  //------------------------------------------------------------------------------------------------
80  override bool OnClick(Widget w, int x, int y, int button)
81  {
82  super.OnClick(w, x, y, button);
83  if (button != 0)
84  return false;
85 
86  SetSelected(!m_bIsSelected);
87  return false;
88  }
89 
90  //------------------------------------------------------------------------------------------------
91  override bool OnMouseEnter(Widget w, int x, int y)
92  {
93  if (m_bMouseOverToFocus)
94  GetGame().GetWorkspace().SetFocusedWidget(w);
95 
96  PlaySound(m_sSoundHovered);
97 
98  if (GetGame().GetWorkspace().GetFocusedWidget() != w)
99  ColorizeWidgets(COLOR_BACKGROUND_HOVERED, COLOR_CONTENT_HOVERED);
100 
101  return false;
102  }
103 
104  //------------------------------------------------------------------------------------------------
105  override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
106  {
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  PlaySound(m_sSoundHovered);
117  ColorizeWidgets(COLOR_BACKGROUND_FOCUSED, COLOR_CONTENT_FOCUSED);
118  ColorizeCheckWidget();
119  return false;
120  }
121 
122  //------------------------------------------------------------------------------------------------
123  override bool OnFocusLost(Widget w, int x, int y)
124  {
125 
126  if (WidgetManager.GetWidgetUnderCursor() == w)
127  ColorizeWidgets(COLOR_BACKGROUND_HOVERED, COLOR_CONTENT_HOVERED);
128  else
129  ColorizeWidgets(COLOR_BACKGROUND_DEFAULT, COLOR_CONTENT_DEFAULT);
130 
131  ColorizeCheckWidget();
132 
133  return false;
134  }
135 
136  //------------------------------------------------------------------------------------------------
137  override protected void OnMenuSelect()
138  {
139  if (!m_wRoot.IsEnabled())
140  return;
141 
142  super.OnMenuSelect();
143  ColorizeCheckWidget();
144  }
145 
146  //------------------------------------------------------------------------------------------------
147  override protected void ColorizeWidgets(Color colorBackground, Color colorContent, float speed = -1)
148  {
149  if (speed < 0)
150  speed = m_fAnimationRate;
151 
152  AnimateWidget.Color(m_wBackground, colorBackground, speed);
153  }
154 
155  //------------------------------------------------------------------------------------------------
157  protected void ColorizeCheckWidget()
158  {
159  if (m_bIsSelected)
160  AnimateWidget.Color(m_wOverlay, COLOR_CHECKED_TRUE, m_fAnimationRate);
161  else
162  AnimateWidget.Color(m_wOverlay, COLOR_CHECKED_FALSE, m_fAnimationRate);
163  }
164 
165  // User API
166  //------------------------------------------------------------------------------------------------
167  bool IsSelected()
168  {
169  return m_bIsSelected;
170  }
171 
172  //------------------------------------------------------------------------------------------------
173  void SetSelected(bool selected, bool notify = true)
174  {
175  if (m_bIsSelected == selected)
176  return;
177 
178  m_bIsSelected = selected;
179 
180  ColorizeCheckWidget();
181 
182  if (notify)
183  m_OnChanged.Invoke(this, m_wRoot, m_bIsSelected);
184  }
185 
186  //------------------------------------------------------------------------------------------------
189  static SCR_SelectableButtonComponent GetSelectableButtonComponent(string name, Widget parent, bool searchAllChildren = true)
190  {
191  auto comp = SCR_SelectableButtonComponent.Cast(
192  SCR_WLibComponentBase.GetComponent(SCR_SelectableButtonComponent, name, parent, searchAllChildren)
193  );
194  return comp;
195  }
196 };
PlaySound
SCR_ParticleContactComponentClass ScriptComponentClass PlaySound(IEntity owner, SCR_ParticleContactComponentClass prefabData, Contact contact)
Definition: SCR_ParticleContactComponent.c:38
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
SCR_SelectableButtonComponent
Definition: SCR_SelectableButtonComponent.c:5
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_OnChanged
protected ref ScriptInvokerTabViewIndex m_OnChanged
Definition: SCR_TabViewComponent.c:64
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
m_wBackground
protected ImageWidget m_wBackground
Definition: SCR_InventoryHitZonePointUI.c:382
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
m_wOverlay
private Widget m_wOverlay
Definition: SCR_AISettingsComponent.c:46