Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_HintManagerComponent.c
Go to the documentation of this file.
1 void SCR_HintManagerComponent_OnHint(SCR_HintUIInfo info, bool isSilent);
3 
4 [ComponentEditorProps(category: "GameScripted/GameMode/Components", description: "")]
6 {
7  [Attribute()]
8  protected ref array<ref SCR_HintConditionList> m_aConditionLists;
9 
10  //------------------------------------------------------------------------------------------------
13  void InitConditionLists(IEntity owner)
14  {
15  for (int i, count = m_aConditionLists.Count(); i < count; i++)
16  {
17  m_aConditionLists[i].Init(owner);
18  }
19  }
20 
21  //------------------------------------------------------------------------------------------------
24  void ExitConditionLists(IEntity owner)
25  {
26  for (int i, count = m_aConditionLists.Count(); i < count; i++)
27  {
28  m_aConditionLists[i].Exit(owner);
29  }
30  }
31 }
32 
33 class SCR_HintManagerComponent : SCR_BaseGameModeComponent
34 {
35  [Attribute("4")]
36  protected float m_fDefaultDuration;
37 
38  [Attribute("1", desc: "Mark the hint as shown only if it was display for this duration (seconds).\nIf the hint duration is shorter, mark it as shown when it's hidden.")]
39  protected float m_fPersistentDelay;
40 
41  [Attribute("0", desc: "When enabled, hints will be shown in this scenario even when they're disabled in game settings.\nUseful for tutorial scenarios.")]
42  protected bool m_bIgnoreHintSettings;
43 
44  protected bool m_bIsShown;
45  protected float m_fDurationOverride;
46  protected SCR_HintUIInfo m_LatestHint;
47  protected BaseContainer m_SettingsContainer;
48  protected ref SCR_HintSettings m_Settings;
49  protected ref SCR_HintUIInfo m_CustomHint; //--- Strong reference to hint info created in run-time from texts
50  protected ref set<EHint> m_aSessionShownHints = new set<EHint>();
51  protected ref ScriptInvokerBase<SCR_HintManagerComponent_OnHint> m_OnHintShow = new ScriptInvokerBase<SCR_HintManagerComponent_OnHint>();
52  protected ref ScriptInvokerBase<SCR_HintManagerComponent_OnHint> m_OnHintHide = new ScriptInvokerBase<SCR_HintManagerComponent_OnHint>();
53 
55  //--- Public functions
57 
58  //------------------------------------------------------------------------------------------------
64  bool Show(SCR_HintUIInfo info, bool isSilent = false, bool ignoreShown = false)
65  {
66  //--- Ignore if hints are disabled in gameplay settings (not for sequence hints, because they're triggered manually)
67  if ((!CanShow() || (!ignoreShown && WasShown(info))) && !info.IsInSequence())
68  return false;
69 
70  //--- Ignore if the new hint has lower priority than the current one
71  if (m_bIsShown && m_LatestHint)
72  {
73  if (info.GetPriority() < m_LatestHint.GetPriority())
74  return false;
75  }
76 
77  //--- Check if timer is visible, if yes, set the timestamp of start.
78 
79  if (info.IsTimerVisible())
80  {
81  info.SetTimeStamp();
82  }
83 
84  //--- Always silent when refreshing the same hint
85  isSilent |= m_bIsShown && info == m_LatestHint;
86 
87  //--- Hide current hint (need to call associated event)
88  Hide();
89 
90  //--- Set new current hint
91  m_bIsShown = true;
92  m_LatestHint = info;
93 
94  //--- Call an event for GUI systems which will actually show the hint (no GUI here!)
95  m_OnHintShow.Invoke(info, isSilent);
96 
97  //--- Set duration (only when the value is *not* negative, which means endless hint)
98  float duration;
99  if (m_fDurationOverride != 0)
100  duration = m_fDurationOverride;
101  else
102  duration = info.GetDuration();
103 
104  GetGame().GetCallqueue().Remove(Hide);
105  if (duration >= 0)
106  {
107  //--- Use default duration when the value is 0
108  if (duration == 0)
109  duration = m_fDefaultDuration;
110 
111  GetGame().GetCallqueue().CallLater(Hide, duration * 1000, false, info);
112  }
113 
114  //--- Mark the hint as shown after a delay (multiple hints may be triggered on the same frame, delay will make sure only the actually shown one will be saved)
115  GetGame().GetCallqueue().Remove(SetShown);
116  int type = info.GetType();
117  if (type > 0)
118  {
119  //--- Make sure the delay is shorter than duration
120  float delay = m_fPersistentDelay;
121  if (duration > 0)
122  delay = Math.Min(delay, duration);
123 
124  GetGame().GetCallqueue().CallLater(SetShown, delay * 1000, false, info);
125  }
126 
127  //info.Log("SCR_HintManagerComponent.Show: ");
128  return true;
129  }
130 
131  //------------------------------------------------------------------------------------------------
150  bool ShowCustom(string description, string name = string.Empty, float duration = 0, bool isSilent = false, EHint type = EHint.UNDEFINED, EFieldManualEntryId fieldManualEntry = EFieldManualEntryId.NONE, bool isTimerVisible = false)
151  {
152  m_CustomHint = SCR_HintUIInfo.CreateInfo(description, name, duration, type, fieldManualEntry, isTimerVisible);
153  return Show(m_CustomHint, isSilent);
154  }
155 
156  //------------------------------------------------------------------------------------------------
159  bool ClearHint()
160  {
161  if(m_LatestHint)
162  {
163  m_LatestHint = null;
164  return true;
165  }
166  else
167  return false;
168  }
169 
170  //------------------------------------------------------------------------------------------------
174  bool Repeat(bool isSilent = false)
175  {
176  if (m_LatestHint)
177  return Show(m_LatestHint, isSilent, true);
178  else
179  return false;
180  }
181 
182  //------------------------------------------------------------------------------------------------
185  bool Refresh()
186  {
187  if (m_bIsShown)
188  return Show(m_LatestHint, true, true);
189  else
190  return false;
191  }
192 
193  //------------------------------------------------------------------------------------------------
197  bool Hide(SCR_HintUIInfo info = null)
198  {
199  //--- Nothing to clear
200  if (!m_bIsShown)
201  return false;
202 
203  //--- Check if it's the hint passed in a param
204  if (info && info != m_LatestHint)
205  return false;
206 
207  GetGame().GetCallqueue().Remove(Hide);
208 
209  m_bIsShown = false;
210  m_OnHintHide.Invoke(m_LatestHint, false);
211  return true;
212  }
213 
214  //------------------------------------------------------------------------------------------------
216  void Toggle()
217  {
218  if (IsShown())
219  Hide();
220  else
221  Repeat();
222  }
223 
224  //------------------------------------------------------------------------------------------------
226  void OpenContext()
227  {
228  if (!IsShown() || !m_LatestHint)
229  return;
230 
231  EFieldManualEntryId link = m_LatestHint.GetFieldManualLink();
232  if (link != EFieldManualEntryId.NONE)
233  SCR_FieldManualUI.Open(link);
234  }
235 
236  //------------------------------------------------------------------------------------------------
240  {
241  return m_LatestHint;
242  }
243 
244  //------------------------------------------------------------------------------------------------
248  {
249  if (m_bIsShown)
250  return m_LatestHint;
251  else
252  return null;
253  }
254 
255  //------------------------------------------------------------------------------------------------
258  bool IsShown()
259  {
260  return m_bIsShown;
261  }
262 
263  //------------------------------------------------------------------------------------------------
266  bool CanShow()
267  {
268  return m_bIgnoreHintSettings || !m_Settings || m_Settings.AreHintsEnabled();
269  }
270 
271  //------------------------------------------------------------------------------------------------
276  bool WasShown(EHint hint, int limit = 1)
277  {
278  return hint > 0 //--- Is type defined (hints without type are never remembered)?
279  && (
280  (m_Settings && m_Settings.GetCount(hint) >= limit //--- How many times was the hint shown across instances?
281  || m_aSessionShownHints.Contains(hint)) //--- Was the hint shown in this instance?
282  )
283  && !DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_HINT_IGNORE_SHOWN); //--- Is debug mode suppressing this check?
284  }
285 
286  //------------------------------------------------------------------------------------------------
290  {
291  return info && WasShown(info.GetType(), info.GetShowLimit());
292  }
293 
294  //------------------------------------------------------------------------------------------------
297  void SetDurationOverride(float duration)
298  {
299  m_fDurationOverride = duration;
300  }
301  //------------------------------------------------------------------------------------------------
305  {
306  return m_fDurationOverride;
307  }
308 
309  //------------------------------------------------------------------------------------------------
312  ScriptInvokerBase<SCR_HintManagerComponent_OnHint> GetOnHintShow()
313  {
314  return m_OnHintShow;
315  }
316 
317  //------------------------------------------------------------------------------------------------
320  ScriptInvokerBase<SCR_HintManagerComponent_OnHint> GetOnHintHide()
321  {
322  return m_OnHintHide;
323  }
324 
326  //--- Static functions
328 
329  //------------------------------------------------------------------------------------------------
332  static SCR_HintManagerComponent GetInstance()
333  {
334  BaseGameMode gameMode = GetGame().GetGameMode();
335  if (gameMode)
336  return SCR_HintManagerComponent.Cast(gameMode.FindComponent(SCR_HintManagerComponent));
337  else
338  return null;
339  }
340 
341  //------------------------------------------------------------------------------------------------
347  static bool ShowHint(SCR_HintUIInfo info, bool isSilent = false, bool ignoreShown = false)
348  {
349  SCR_HintManagerComponent hintManager = GetInstance();
350  if (hintManager)
351  return hintManager.Show(info, isSilent, ignoreShown);
352  else
353  return false;
354  }
355 
356  //------------------------------------------------------------------------------------------------
374  static bool ShowCustomHint(string description, string name = string.Empty, float duration = 0, bool isSilent = false, EFieldManualEntryId fieldManualEntry = EFieldManualEntryId.NONE, bool isTimerVisible = false)
375  {
376  SCR_HintManagerComponent hintManager = GetInstance();
377  if (hintManager)
378  return hintManager.ShowCustom(description, name, duration, isSilent, EHint.UNDEFINED, fieldManualEntry, isTimerVisible);
379  else
380  return false;
381  }
382 
383  //------------------------------------------------------------------------------------------------
385  static bool ClearLatestHint()
386  {
387  SCR_HintManagerComponent hintManager = GetInstance();
388  if (hintManager)
389  return hintManager.ClearHint();
390  else
391  return false;
392  }
393 
394  //------------------------------------------------------------------------------------------------
398  static bool RepeatHint(bool isSilent = false)
399  {
400  SCR_HintManagerComponent hintManager = GetInstance();
401  if (hintManager)
402  return hintManager.Repeat(isSilent);
403  else
404  return false;
405  }
406 
407  //------------------------------------------------------------------------------------------------
411  static bool HideHint(SCR_HintUIInfo info = null)
412  {
413  SCR_HintManagerComponent hintManager = GetInstance();
414  if (hintManager)
415  return hintManager.Hide(info);
416  else
417  return false;
418  }
419 
420  //------------------------------------------------------------------------------------------------
423  static bool IsHintShown()
424  {
425  SCR_HintManagerComponent hintManager = GetInstance();
426  if (hintManager)
427  return hintManager.IsShown();
428  else
429  return false;
430  }
431 
432  //------------------------------------------------------------------------------------------------
435  static bool CanShowHints()
436  {
437  SCR_HintManagerComponent hintManager = GetInstance();
438  if (hintManager)
439  return hintManager.CanShow();
440  else
441  return false;
442  }
443 
445  //--- Protected functions
447 
448  //------------------------------------------------------------------------------------------------
449  protected void LoadSettings()
450  {
451  m_Settings = new SCR_HintSettings();
452  m_SettingsContainer = GetGame().GetGameUserSettings().GetModule("SCR_HintSettings");
453 
454  m_Settings.LoadShownHints(m_SettingsContainer);
455 
456  if (!m_Settings.AreHintsEnabled() && (m_bIsShown && !m_LatestHint.IsInSequence()))
457  Hide();
458  }
459 
460  //------------------------------------------------------------------------------------------------
461  protected void SetShown(SCR_HintUIInfo info)
462  {
463  if (!info || WasShown(info) || DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_HINT_IGNORE_SHOWN))
464  return;
465 
466  EHint type = info.GetType();
467  m_aSessionShownHints.Insert(type);
468  int count = m_Settings.AddCount(type);
469  m_Settings.SaveShownHints(m_SettingsContainer);
470 
471  Print(string.Format("Hint %1 = %2 saved persistently, count = %3.", typename.EnumToString(EHint, type), type, count), LogLevel.VERBOSE);
472  }
473 
475  //--- Default functions
477 
478  //------------------------------------------------------------------------------------------------
479  override void OnPostInit(IEntity owner)
480  {
481  if (System.IsConsoleApp())
482  return;
483 
484  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_HINT_IGNORE_SHOWN, "", "Ignore hint persistency", "UI");
485 
486  if (SCR_Global.IsEditMode(owner))
487  return;
488 
489  //--- Call only for the owner, not server (disabled, called before ownership is transferred)
490  //RplComponent rplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
491  //if (rplComponent && !rplComponent.IsOwner())
492  // return;
493 
494  SCR_HintManagerComponentClass componentPrefab = SCR_HintManagerComponentClass.Cast(GetComponentData(owner));
495  componentPrefab.InitConditionLists(owner);
496 
497  LoadSettings();
498  GetGame().OnUserSettingsChangedInvoker().Insert(LoadSettings);
499 
500  GetGame().GetInputManager().AddActionListener("HintToggle", EActionTrigger.DOWN, Toggle);
501  GetGame().GetInputManager().AddActionListener("HintContext", EActionTrigger.DOWN, OpenContext);
502  }
503 
504  //------------------------------------------------------------------------------------------------
505  override void OnDelete(IEntity owner)
506  {
507  if (System.IsConsoleApp())
508  return;
509 
510  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_HINT_IGNORE_SHOWN);
511 
512  SCR_HintManagerComponentClass componentPrefab = SCR_HintManagerComponentClass.Cast(GetComponentData(owner));
513  componentPrefab.ExitConditionLists(owner);
514 
515  GetGame().OnUserSettingsChangedInvoker().Remove(LoadSettings);
516 
517  GetGame().GetInputManager().RemoveActionListener("HintToggle", EActionTrigger.DOWN, Toggle);
518  GetGame().GetInputManager().RemoveActionListener("HintContext", EActionTrigger.DOWN, OpenContext);
519  }
520 }
SCR_FieldManualUI
Definition: SCR_FieldManualUI.c:1
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
WasShown
bool WasShown(EHint hint, int limit=1)
Definition: SCR_HintManagerComponent.c:276
GetOnHintHide
ScriptInvokerBase< SCR_HintManagerComponent_OnHint > GetOnHintHide()
Definition: SCR_HintManagerComponent.c:320
GetInstance
SCR_TextsTaskManagerComponentClass ScriptComponentClass GetInstance()
Definition: SCR_TextsTaskManagerComponent.c:50
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
OnDelete
override void OnDelete(IEntity owner)
Definition: SCR_HintManagerComponent.c:505
IsShown
bool IsShown()
Definition: SCR_HintManagerComponent.c:258
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
Hide
bool Hide(SCR_HintUIInfo info=null)
Definition: SCR_HintManagerComponent.c:197
func
func
Definition: SCR_AIThreatSystem.c:5
Repeat
bool Repeat(bool isSilent=false)
Definition: SCR_HintManagerComponent.c:174
Show
override void Show(WorkspaceWidget pWorkspace, Widget pToolTipWidget, float desiredPosX, float desiredPosY)
Definition: SCR_ScriptedWidgetTooltip.c:55
CanShow
bool CanShow()
Definition: SCR_HintManagerComponent.c:266
Toggle
void Toggle()
Toggle hint. Hide it if it's shown, and open it again if it's hidden.
Definition: SCR_HintManagerComponent.c:216
SCR_HintManagerComponentClass
Definition: SCR_HintManagerComponent.c:5
SCR_HintUIInfo
Definition: SCR_HintUIInfo.c:2
ClearHint
bool ClearHint()
Definition: SCR_HintManagerComponent.c:159
Attribute
SCR_HintManagerComponentClass SCR_BaseGameModeComponentClass Attribute("4")
Definition: SCR_HintManagerComponent.c:35
GetCurrentHint
SCR_HintUIInfo GetCurrentHint()
Definition: SCR_HintManagerComponent.c:247
LoadSettings
protected void LoadSettings()
Definition: SCR_HintManagerComponent.c:449
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_HintManagerComponent.c:479
Refresh
bool Refresh()
Definition: SCR_HintManagerComponent.c:185
GetDurationOverride
float GetDurationOverride()
Definition: SCR_HintManagerComponent.c:304
ShowCustom
bool ShowCustom(string description, string name=string.Empty, float duration=0, bool isSilent=false, EHint type=EHint.UNDEFINED, EFieldManualEntryId fieldManualEntry=EFieldManualEntryId.NONE, bool isTimerVisible=false)
Definition: SCR_HintManagerComponent.c:150
OpenContext
void OpenContext()
Open context to currently shown hint.
Definition: SCR_HintManagerComponent.c:226
SCR_HintManagerComponent_OnHint
func SCR_HintManagerComponent_OnHint
Definition: SCR_HintManagerComponent.c:2
GetLatestHint
SCR_HintUIInfo GetLatestHint()
Definition: SCR_HintManagerComponent.c:239
m_aConditionLists
protected ref array< ref SCR_HintConditionList > m_aConditionLists
Definition: SCR_HintManagerComponent.c:4
SCR_Global
Definition: Functions.c:6
ShowHint
void ShowHint(EHint hintID, bool showImmediately=false, bool showMultipleTimes=false)
Definition: SCR_CampaignFeedbackComponent.c:432
SetDurationOverride
void SetDurationOverride(float duration)
Definition: SCR_HintManagerComponent.c:297
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
SCR_HintSettings
Definition: SCR_GameplaySettings.c:78
SetShown
protected void SetShown(SCR_HintUIInfo info)
Definition: SCR_HintManagerComponent.c:461
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
EHint
EHint
Definition: EHint.c:10
GetOnHintShow
ScriptInvokerBase< SCR_HintManagerComponent_OnHint > GetOnHintShow()
Definition: SCR_HintManagerComponent.c:312
EFieldManualEntryId
EFieldManualEntryId
used to grab the first id-matching Field Manual entry
Definition: EFieldManualEntryId.c:2
SCR_BaseGameModeComponentClass
Definition: SCR_BaseGameModeComponent.c:2
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
SCR_BaseGameModeComponent
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_BaseGameModeComponent.c:199