Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_HintUIComponent.c
Go to the documentation of this file.
1 class SCR_HintUIComponent: ScriptedWidgetComponent
2 {
3  [Attribute()]
4  protected string m_sTitleWidgetName;
5 
6  [Attribute()]
7  protected string m_sDescriptionWidgetName;
8 
9  [Attribute()]
10  protected string m_sIconWidgetName;
11 
12  [Attribute()]
13  protected string m_sToggleButtonWidgetName;
14 
15  [Attribute()]
16  protected string m_sContextButtonWidgetName;
17 
18  [Attribute()]
19  protected string m_sTimeLeftWidgetName;
20 
21  [Attribute()]
22  protected string m_sPageWidgetName;
23 
24  [Attribute()]
25  protected string m_sVisibilitySelectorName;
26 
27  [Attribute()]
28  protected string m_sColorWidgetName;
29 
30  [Attribute("Name of a widget under the same parent in which highlights will be created.\nOptional; when undefined, highlights will be created directly in workspace.")]
31  protected string m_sHighlightParentWidgetName;
32 
33  [Attribute(uiwidget: UIWidgets.LocaleEditBox)]
34  protected LocalizedString m_ToggleButtonTextHide;
35 
36  [Attribute(uiwidget: UIWidgets.LocaleEditBox)]
37  protected LocalizedString m_ToggleButtonTextNext;
38 
39  [Attribute("1", desc: "When enabled, the widget will show currently shown hint opn init.\nWhen disabled, currently shown hint will be cleared upon init.")]
40  protected bool m_bPreserveCurrentHint;
41 
42  [Attribute(params: "layout")]
43  protected ResourceName m_HighlightLayout;
44 
45  [Attribute(defvalue: "0.76078 0.39216 0.07843 1.0", UIWidgets.ColorPicker, desc: "Reforger default color")]
46  protected ref Color m_cReforgerColor;
47 
48  [Attribute(defvalue: "0.760006 0.392004 0.078004 1.000000", UIWidgets.ColorPicker, desc: "Color of the time bar")]
49  protected ref Color m_cTimerColor;
50 
51  protected Widget m_Widget;
52  protected TextWidget m_NameWidget;
53  protected TextWidget m_DescriptionWidget;
54  protected ImageWidget m_IconWidget;
55  protected Widget m_HighlightParentWidget;
56  protected ref array<Widget> m_aHighlightWidgets;
57  protected Widget m_ToggleButtonWidget;
58  protected Widget m_ContextButtonWidget;
59  protected TextWidget m_PageWidget;
60  protected SizeLayoutWidget m_TimeWidget;
61  protected LocalizedString m_sPageText;
62  protected ImageWidget m_BarColor;
63  protected SCR_InputButtonComponent m_ToggleButton;
64  protected MenuBase m_Menu;
65  protected SCR_WLibProgressBarComponent m_ProgressBar;
66  protected bool m_bMenuScanned;
67  protected Widget m_VisibilitySelector;
68 
69  protected bool m_bIsHintShown;
70  protected ref ScriptInvokerBool m_OnHintShown;
71 
72  //------------------------------------------------------------------------------------------------
73  protected void OnHintShow(SCR_HintUIInfo info, bool isSilent)
74  {
75  //--- When part of a menu, check if the menu is focused
76  if (!m_bMenuScanned && SCR_WidgetTools.InHierarchy(m_Widget, GetGame().GetWorkspace()))
77  {
78  m_bMenuScanned = true;
79  m_Menu = SCR_WidgetTools.FindMenu(m_Widget);
80  }
81 
82  m_Widget.SetVisible(true);
83 
84  if (m_OnHintShown)
85  m_OnHintShown.Invoke(true);
86 
87  m_bIsHintShown = true;
88 
89  if (m_Widget.IsVisibleInHierarchy() && info && info.HasDescription() && (!m_Menu || m_Menu.IsFocused()))
90  {
91  bool showName = info.SetNameTo(m_NameWidget);
92  bool showDescription = info.SetDescriptionTo(m_DescriptionWidget);
93  bool showIcon = info.SetIconTo(m_IconWidget);
94 
95  m_NameWidget.SetVisible(showName);
96  m_DescriptionWidget.SetVisible(showDescription);
97  m_IconWidget.SetVisible(showIcon);
98  m_ContextButtonWidget.SetVisible(info.GetFieldManualLink() != EFieldManualEntryId.NONE);
99 
100  //--- Initialize pagination label
101  int sequencePage = info.GetSequencePage();
102  int sequenceCount = info.GetSequenceCount();
103  bool showNextButton;
104  if (sequenceCount > 1)
105  {
106  m_PageWidget.SetTextFormat(m_sPageText, sequencePage, sequenceCount);
107  m_PageWidget.SetVisible(true);
108  showNextButton = sequenceCount != sequencePage;
109  }
110  else
111  {
112  m_PageWidget.SetVisible(false);
113  }
114 
115  m_ProgressBar.StopProgressAnimation();
116 
117  if (showNextButton)
118  m_ToggleButton.SetLabel(m_ToggleButtonTextNext);
119  else
120  m_ToggleButton.SetLabel(m_ToggleButtonTextHide);
121 
122  float startvalue;
123  int duration;
124  ChimeraWorld world = GetGame().GetWorld();
125  WorldTimestamp currentTime = world.GetServerTimestamp();
126  if (info.GetTimeStarted() != 0 || currentTime == info.GetTimeStarted() || info.GetDuration() == -1 || !info.IsTimerVisible())
127  {
128  startvalue = 1;
129  duration = info.GetDuration();
130  }
131  else
132  {
133  int timeDifferenceFromStart = currentTime.DiffMilliseconds(info.GetTimeStarted());
134  startvalue = 1 - timeDifferenceFromStart / info.GetDuration() / 1000;
135  duration = info.GetDuration() - timeDifferenceFromStart / 1000;
136  }
137 
138  if (info.IsTimerVisible() && m_TimeWidget)
139  {
140  m_TimeWidget.SetVisible(true);
141  m_BarColor.SetColor(m_cTimerColor);
142  m_ProgressBar.SetValue(startvalue, false);
143  m_ProgressBar.SetAnimationTime(duration);
144  m_ProgressBar.SetValue(0);
145  }
146  else if (m_TimeWidget)
147  {
148  m_TimeWidget.SetVisible(false);
149  }
150 
151  if (!info.GetName())
152  m_VisibilitySelector.SetVisible(false);
153  else
154  m_VisibilitySelector.SetVisible(true);
155 
156  if (info.GetDuration() == -1 || !info.IsTimerVisible())
157  {
158  m_BarColor.SetColor(m_cReforgerColor);
159  m_ProgressBar.SetValue(1, false);
160  }
161 
162  AnimateWidget.Opacity(m_Widget, 1, UIConstants.FADE_RATE_FAST);
163 
164  //--- Create highlights a bit later, so widgets which are part of the menu this hint UI belongs to have time to register
165  if (m_HighlightLayout)
166  GetGame().GetCallqueue().CallLater(CreateHighlights, 1, false, info);
167 
168  if (!isSilent)
169  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.HINT, true);
170  }
171  else
172  {
173  OnHintHide(info, isSilent);
174  }
175  }
176 
177  //------------------------------------------------------------------------------------------------
178  protected void OnHintHide(SCR_HintUIInfo info, bool isSilent)
179  {
180  AnimateWidget.Opacity(m_Widget, 0, UIConstants.FADE_RATE_DEFAULT, true);
181 
182  if (m_aHighlightWidgets)
183  {
184  foreach (Widget hightlightWidget: m_aHighlightWidgets)
185  {
186  if (hightlightWidget)
187  hightlightWidget.RemoveFromHierarchy();
188  }
189  }
190 
191  if (m_OnHintShown)
192  m_OnHintShown.Invoke(false);
193 
194  m_bIsHintShown = false;
195  }
196 
197  //------------------------------------------------------------------------------------------------
198  protected void CreateHighlights(SCR_HintUIInfo info)
199  {
200  if (!m_HighlightParentWidget && m_sHighlightParentWidgetName)
201  m_HighlightParentWidget = m_Widget.GetParent().FindAnyWidget(m_sHighlightParentWidgetName);
202 
203  array<string> hightlightWidgetNames = {};
204  m_aHighlightWidgets = {};
205  Widget hightlightWidget;
206  for (int i, count = info.GetHighlightWidgetNames(hightlightWidgetNames); i < count; i++)
207  {
208  hightlightWidget = SCR_WidgetHighlightUIComponent.CreateHighlight(hightlightWidgetNames[i], m_HighlightLayout, m_HighlightParentWidget);
209  if (hightlightWidget)
210  m_aHighlightWidgets.Insert(hightlightWidget);
211  }
212  }
213 
214  //------------------------------------------------------------------------------------------------
215  override bool OnClick(Widget w, int x, int y, int button)
216  {
217  if (SCR_WidgetTools.InHierarchy(w, m_ToggleButtonWidget))
218  {
219  SCR_HintManagerComponent hintManager = SCR_HintManagerComponent.GetInstance();
220  if (hintManager)
221  hintManager.Toggle();
222  }
223  if (SCR_WidgetTools.InHierarchy(w, m_ContextButtonWidget))
224  {
225  SCR_HintManagerComponent hintManager = SCR_HintManagerComponent.GetInstance();
226  if (hintManager)
227  hintManager.OpenContext();
228  }
229  return false;
230  }
231 
232  //------------------------------------------------------------------------------------------------
233  //--- Refresh hint, as it sometimes uses device-specific lines
234  protected void OnInputDeviceIsGamepad(bool isGamepad)
235  {
236  SCR_HintManagerComponent hintManager = SCR_HintManagerComponent.GetInstance();
237  if (hintManager)
238  hintManager.Refresh();
239  }
240 
241  //------------------------------------------------------------------------------------------------
242  override void HandlerAttached(Widget w)
243  {
244  m_Widget = w;
245 
246  m_ToggleButtonWidget = m_Widget.FindAnyWidget(m_sToggleButtonWidgetName);
247  m_ToggleButton = SCR_InputButtonComponent.Cast(m_ToggleButtonWidget.FindHandler(SCR_InputButtonComponent));
248  if (m_ToggleButton)
249  m_ToggleButton.SetLabel(m_ToggleButtonTextHide);
250 
251  if (SCR_Global.IsEditMode())
252  return;
253 
254  m_Widget.SetOpacity(0);
255  m_Widget.SetVisible(false);
256 
257  SCR_HintManagerComponent hintManager = SCR_HintManagerComponent.GetInstance();
258  if (!hintManager)
259  return;
260 
261  m_NameWidget = TextWidget.Cast(m_Widget.FindAnyWidget(m_sTitleWidgetName));
262  m_DescriptionWidget = TextWidget.Cast(m_Widget.FindAnyWidget(m_sDescriptionWidgetName));
263  m_IconWidget = ImageWidget.Cast(m_Widget.FindAnyWidget(m_sIconWidgetName));
264  m_ContextButtonWidget = m_Widget.FindAnyWidget(m_sContextButtonWidgetName);
265  m_PageWidget = TextWidget.Cast(m_Widget.FindAnyWidget(m_sPageWidgetName));
266  m_sPageText = m_PageWidget.GetText();
267  m_TimeWidget = SizeLayoutWidget.Cast(m_Widget.FindAnyWidget(m_sTimeLeftWidgetName));
268  m_VisibilitySelector = m_Widget.FindAnyWidget(m_sVisibilitySelectorName);
269  m_BarColor = ImageWidget.Cast(m_Widget.FindAnyWidget(m_sColorWidgetName));
270  m_ProgressBar = SCR_WLibProgressBarComponent.GetProgressBar(m_sTimeLeftWidgetName, m_Widget, true);
271 
272  hintManager.GetOnHintShow().Insert(OnHintShow);
273  hintManager.GetOnHintHide().Insert(OnHintHide);
274 
275  SCR_HintUIInfo currentHint = hintManager.GetCurrentHint();
276  if (currentHint)
277  {
278  if (m_bPreserveCurrentHint)
279  {
280  //--- Show the current hint again in the new area
281  OnHintShow(currentHint, true);
282  }
283  else if (!currentHint.IsInSequence())
284  {
285  //--- Hide the current hint because it doesn't make sense in the current context (not sequence hints, they should not be interrupted)
286  hintManager.Hide();
287  }
288  }
289 
290  GetGame().OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
291  }
292 
293  //------------------------------------------------------------------------------------------------
294  override void HandlerDeattached(Widget w)
295  {
296  GetGame().OnInputDeviceIsGamepadInvoker().Remove(OnInputDeviceIsGamepad);
297 
298  SCR_HintManagerComponent hintManager = SCR_HintManagerComponent.GetInstance();
299  if (!hintManager)
300  return;
301 
302  hintManager.GetOnHintShow().Remove(OnHintShow);
303  hintManager.GetOnHintHide().Remove(OnHintHide);
304  }
305 
306  //------------------------------------------------------------------------------------------------
307  ScriptInvokerBool GetOnHintShown()
308  {
309  if (!m_OnHintShown)
310  m_OnHintShown = new ScriptInvokerBool();
311 
312  return m_OnHintShown;
313  }
314 
315  //------------------------------------------------------------------------------------------------
316  bool IsHintShown()
317  {
318  return m_bIsHintShown;
319  }
320 }
ChimeraWorld
Definition: ChimeraWorld.c:12
SCR_WidgetTools
Definition: SCR_WidgetTools.c:1
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
UIConstants
Definition: Constants.c:130
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_sIconWidgetName
protected string m_sIconWidgetName
Definition: SCR_GroupEditableEntityUIComponent.c:6
SCR_HintUIComponent
Definition: SCR_HintUIComponent.c:1
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_HintUIInfo
Definition: SCR_HintUIInfo.c:2
ScriptInvokerBool
ScriptInvokerBase< ScriptInvokerBoolMethod > ScriptInvokerBool
Definition: SCR_ScriptInvokerHelper.c:41
SCR_Global
Definition: Functions.c:6
SCR_WidgetHighlightUIComponent
Definition: SCR_WidgetHighlightUIComponent.c:1
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_WLibProgressBarComponent
Minimalist progress bar.
Definition: SCR_WLibProgressBar.c:3
LocalizedString
Definition: LocalizedString.c:21
EFieldManualEntryId
EFieldManualEntryId
used to grab the first id-matching Field Manual entry
Definition: EFieldManualEntryId.c:2
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1