Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_HintManagerComponent.c
Go to the documentation of this file.
3
4[ComponentEditorProps(category: "GameScripted/GameMode/Components", description: "")]
6{
7 [Attribute()]
8 protected ref array<ref SCR_HintConditionList> m_aConditionLists;
9
10 //------------------------------------------------------------------------------------------------
14 {
15 for (int i, count = m_aConditionLists.Count(); i < count; i++)
16 {
17 m_aConditionLists[i].Init(owner);
18 }
19 }
20
21 //------------------------------------------------------------------------------------------------
25 {
26 for (int i, count = m_aConditionLists.Count(); i < count; i++)
27 {
28 m_aConditionLists[i].Exit(owner);
29 }
30 }
31}
32
33class SCR_HintManagerComponent : SCR_BaseGameModeComponent
34{
35 [Attribute("4")]
36 protected float m_fDefaultDuration;
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>();
55 //--- Public functions
57
58 //------------------------------------------------------------------------------------------------
60
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 if (!info.ShouldFactionSeeHint())
71 return false;
72
73 //--- Ignore if the new hint has lower priority than the current one
74 if (m_bIsShown && m_LatestHint)
75 {
76 if (info.GetPriority() < m_LatestHint.GetPriority())
77 return false;
78 }
79
80 //--- Check if timer is visible, if yes, set the timestamp of start.
81
82 if (info.IsTimerVisible())
83 {
84 info.SetTimeStamp();
85 }
86
87 //--- Always silent when refreshing the same hint
88 isSilent |= m_bIsShown && info == m_LatestHint;
89
90 //--- Hide current hint (need to call associated event)
91 Hide();
92
93 //--- Set new current hint
94 m_bIsShown = true;
95 m_LatestHint = info;
96
97 //--- Call an event for GUI systems which will actually show the hint (no GUI here!)
98 m_OnHintShow.Invoke(info, isSilent);
99
100 //--- Set duration (only when the value is *not* negative, which means endless hint)
101 float duration;
102 if (m_fDurationOverride != 0)
103 duration = m_fDurationOverride;
104 else
105 duration = info.GetDuration();
106
107 GetGame().GetCallqueue().Remove(Hide);
108 if (duration >= 0)
109 {
110 //--- Use default duration when the value is 0
111 if (duration == 0)
112 duration = m_fDefaultDuration;
113
114 GetGame().GetCallqueue().CallLater(Hide, duration * 1000, false, info);
115 }
116
117 //--- 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)
118 GetGame().GetCallqueue().Remove(SetShown);
119 int type = info.GetType();
120 if (type > 0)
121 {
122 //--- Make sure the delay is shorter than duration
123 float delay = m_fPersistentDelay;
124 if (duration > 0)
125 delay = Math.Min(delay, duration);
126
127 GetGame().GetCallqueue().CallLater(SetShown, delay * 1000, false, info);
128 }
129
130 //info.Log("SCR_HintManagerComponent.Show: ");
131 return true;
132 }
133
134 //------------------------------------------------------------------------------------------------
153 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)
154 {
155 m_CustomHint = SCR_HintUIInfo.CreateInfo(description, name, duration, type, fieldManualEntry, isTimerVisible);
156 return Show(m_CustomHint, isSilent);
157 }
158
159 //------------------------------------------------------------------------------------------------
163 {
164 if(m_LatestHint)
165 {
166 m_LatestHint = null;
167 return true;
168 }
169 else
170 return false;
171 }
172
173 //------------------------------------------------------------------------------------------------
177 bool Repeat(bool isSilent = false)
178 {
179 if (m_LatestHint)
180 return Show(m_LatestHint, isSilent, true);
181 else
182 return false;
183 }
184
185 //------------------------------------------------------------------------------------------------
188 bool Refresh()
189 {
190 if (m_bIsShown)
191 return Show(m_LatestHint, true, true);
192 else
193 return false;
194 }
195
196 //------------------------------------------------------------------------------------------------
200 bool Hide(SCR_HintUIInfo info = null)
201 {
202 //--- Nothing to clear
203 if (!m_bIsShown)
204 return false;
205
206 //--- Check if it's the hint passed in a param
207 if (info && info != m_LatestHint)
208 return false;
209
210 GetGame().GetCallqueue().Remove(Hide);
211
212 m_bIsShown = false;
213 m_OnHintHide.Invoke(m_LatestHint, false);
214 return true;
215 }
216
217 //------------------------------------------------------------------------------------------------
219 void Toggle()
220 {
221 if (m_Settings && !m_Settings.AreHintsEnabled())
222 return;
223
224 if (IsShown())
225 Hide();
226 else
227 Repeat();
228 }
229
230 //------------------------------------------------------------------------------------------------
233 {
234 if (!IsShown() || !m_LatestHint || (m_Settings && !m_Settings.AreHintsEnabled()))
235 return;
236
237 EFieldManualEntryId link = m_LatestHint.GetFieldManualLink();
238 if (link != EFieldManualEntryId.NONE)
240 }
241
242 //------------------------------------------------------------------------------------------------
246 {
247 return m_LatestHint;
248 }
249
250 //------------------------------------------------------------------------------------------------
254 {
255 if (m_bIsShown)
256 return m_LatestHint;
257 else
258 return null;
259 }
260
261 //------------------------------------------------------------------------------------------------
264 bool IsShown()
265 {
266 return m_bIsShown;
267 }
268
269 //------------------------------------------------------------------------------------------------
272 bool CanShow()
273 {
274 return m_bIgnoreHintSettings || !m_Settings || m_Settings.AreHintsEnabled();
275 }
276
277 //------------------------------------------------------------------------------------------------
282 bool WasShown(EHint hint, int limit = 1)
283 {
284 return hint > 0 //--- Is type defined (hints without type are never remembered)?
285 && (
286 (m_Settings && (m_Settings.GetCount(hint) < 0 || m_Settings.GetCount(hint) >= limit) //--- Can the hint be shown again? How many times was the hint shown across instances?
287 || m_aSessionShownHints.Contains(hint)) //--- Was the hint shown in this instance?
288 )
289 && !DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_HINT_IGNORE_SHOWN); //--- Is debug mode suppressing this check?
290 }
291
292 //------------------------------------------------------------------------------------------------
296 {
297 return info && WasShown(info.GetType(), info.GetShowLimit());
298 }
299
300 //------------------------------------------------------------------------------------------------
303 void SetDurationOverride(float duration)
304 {
305 m_fDurationOverride = duration;
306 }
307 //------------------------------------------------------------------------------------------------
311 {
312 return m_fDurationOverride;
313 }
314
315 //------------------------------------------------------------------------------------------------
318 ScriptInvokerBase<SCR_HintManagerComponent_OnHint> GetOnHintShow()
319 {
320 return m_OnHintShow;
321 }
322
323 //------------------------------------------------------------------------------------------------
326 ScriptInvokerBase<SCR_HintManagerComponent_OnHint> GetOnHintHide()
327 {
328 return m_OnHintHide;
329 }
330
332 //--- Static functions
334
335 //------------------------------------------------------------------------------------------------
338 static SCR_HintManagerComponent GetInstance()
339 {
340 BaseGameMode gameMode = GetGame().GetGameMode();
341 if (gameMode)
342 return SCR_HintManagerComponent.Cast(gameMode.FindComponent(SCR_HintManagerComponent));
343 else
344 return null;
345 }
346
347 //------------------------------------------------------------------------------------------------
353 static bool ShowHint(SCR_HintUIInfo info, bool isSilent = false, bool ignoreShown = false)
354 {
355 SCR_HintManagerComponent hintManager = GetInstance();
356 if (hintManager)
357 return hintManager.Show(info, isSilent, ignoreShown);
358 else
359 return false;
360 }
361
362 //------------------------------------------------------------------------------------------------
380 static bool ShowCustomHint(string description, string name = string.Empty, float duration = 0, bool isSilent = false, EFieldManualEntryId fieldManualEntry = EFieldManualEntryId.NONE, bool isTimerVisible = false)
381 {
382 SCR_HintManagerComponent hintManager = GetInstance();
383 if (hintManager)
384 return hintManager.ShowCustom(description, name, duration, isSilent, EHint.UNDEFINED, fieldManualEntry, isTimerVisible);
385 else
386 return false;
387 }
388
389 //------------------------------------------------------------------------------------------------
391 static bool ClearLatestHint()
392 {
393 SCR_HintManagerComponent hintManager = GetInstance();
394 if (hintManager)
395 return hintManager.ClearHint();
396 else
397 return false;
398 }
399
400 //------------------------------------------------------------------------------------------------
404 static bool RepeatHint(bool isSilent = false)
405 {
406 SCR_HintManagerComponent hintManager = GetInstance();
407 if (hintManager)
408 return hintManager.Repeat(isSilent);
409 else
410 return false;
411 }
412
413 //------------------------------------------------------------------------------------------------
417 static bool HideHint(SCR_HintUIInfo info = null)
418 {
419 SCR_HintManagerComponent hintManager = GetInstance();
420 if (hintManager)
421 return hintManager.Hide(info);
422 else
423 return false;
424 }
425
426 //------------------------------------------------------------------------------------------------
429 static bool IsHintShown()
430 {
431 SCR_HintManagerComponent hintManager = GetInstance();
432 if (hintManager)
433 return hintManager.IsShown();
434 else
435 return false;
436 }
437
438 //------------------------------------------------------------------------------------------------
441 static bool CanShowHints()
442 {
443 SCR_HintManagerComponent hintManager = GetInstance();
444 if (hintManager)
445 return hintManager.CanShow();
446 else
447 return false;
448 }
449
451 //--- Protected functions
453
454 //------------------------------------------------------------------------------------------------
455 protected void LoadSettings()
456 {
458 if (!hudManager)
459 return;
460
461 BaseContainer interfaceSettings = GetGame().GetGameUserSettings().GetModule(hudManager.GetInterfaceSettingsClass());
462 if (!interfaceSettings)
463 return;
464
465 bool state;
466 interfaceSettings.Get("m_bShowHints", state);
467
468 m_SettingsContainer = GetGame().GetGameUserSettings().GetModule("SCR_HintSettings");
469 m_Settings.SetHintsEnabled(state);
470 m_Settings.LoadShownHints(m_SettingsContainer);
471
472 if (m_bIsShown && !m_Settings.AreHintsEnabled())
473 Hide();
474 }
475
476 //------------------------------------------------------------------------------------------------
477 protected void SetShown(SCR_HintUIInfo info)
478 {
479 if (!info || WasShown(info) || DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_HINT_IGNORE_SHOWN))
480 return;
481
482 EHint type = info.GetType();
483 m_aSessionShownHints.Insert(type);
484 int count = m_Settings.AddCount(type);
485 m_Settings.SaveShownHints(m_SettingsContainer);
486
487 Print(string.Format("Hint %1 = %2 saved persistently, count = %3.", typename.EnumToString(EHint, type), type, count), LogLevel.VERBOSE);
488 }
489
490 //------------------------------------------------------------------------------------------------
492 {
493 if (!m_Settings || !m_LatestHint)
494 return;
495
496 EHint hintType = m_LatestHint.GetType();
497 if (hintType <= 0)
498 return;
499
500 m_Settings.DontShowAgain(hintType, m_SettingsContainer);
501 Hide();
502 }
503
505 //--- Default functions
507
508 //------------------------------------------------------------------------------------------------
509 override void OnPostInit(IEntity owner)
510 {
511 if (System.IsConsoleApp())
512 return;
513
514 DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_HINT_IGNORE_SHOWN, "", "Ignore hint persistency", "UI");
515
516 if (SCR_Global.IsEditMode(owner))
517 return;
518
519 //--- Call only for the owner, not server (disabled, called before ownership is transferred)
520 //RplComponent rplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
521 //if (rplComponent && !rplComponent.IsOwner())
522 // return;
523
525 componentPrefab.InitConditionLists(owner);
526
527 m_Settings = new SCR_HintSettings();
528
529 GetGame().GetOnHUDManagerChanged().Insert(LoadSettings);
530 GetGame().OnUserSettingsChangedInvoker().Insert(LoadSettings);
531
532 GetGame().GetInputManager().AddActionListener("HintToggle", EActionTrigger.DOWN, Toggle);
533 GetGame().GetInputManager().AddActionListener("HintContext", EActionTrigger.DOWN, OpenContext);
534 GetGame().GetInputManager().AddActionListener("HintDismiss", EActionTrigger.DOWN, DontShowAgainCurrent);
535 }
536
537 //------------------------------------------------------------------------------------------------
538 override void OnDelete(IEntity owner)
539 {
540 if (System.IsConsoleApp())
541 return;
542
543 DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_HINT_IGNORE_SHOWN);
544
546 componentPrefab.ExitConditionLists(owner);
547
548 GetGame().GetOnHUDManagerChanged().Remove(LoadSettings);
549 GetGame().OnUserSettingsChangedInvoker().Remove(LoadSettings);
550
551 GetGame().GetInputManager().RemoveActionListener("HintToggle", EActionTrigger.DOWN, Toggle);
552 GetGame().GetInputManager().RemoveActionListener("HintContext", EActionTrigger.DOWN, OpenContext);
553 GetGame().GetInputManager().RemoveActionListener("HintDismiss", EActionTrigger.DOWN, DontShowAgainCurrent);
554 }
555}
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
EFieldManualEntryId
used to grab the first id-matching Field Manual entry
EHint
Definition EHint.c:11
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
SCR_CharacterSoundComponentClass GetComponentData()
EDamageType type
void HideHint()
ScriptInvokerBase< SCR_HintManagerComponent_OnHint > GetOnHintHide()
void Toggle()
Toggle hint. Hide it if it's shown, and open it again if it's hidden.
bool CanShow()
bool Refresh()
void LoadSettings()
SCR_HintUIInfo GetCurrentHint()
float GetDurationOverride()
void SetDurationOverride(float duration)
bool IsShown()
SCR_HintUIInfo GetLatestHint()
func SCR_HintManagerComponent_OnHint
bool Repeat(bool isSilent=false)
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)
ScriptInvokerBase< SCR_HintManagerComponent_OnHint > GetOnHintShow()
bool WasShown(EHint hint, int limit=1)
bool ClearHint()
bool Hide(SCR_HintUIInfo info=null)
void OpenContext()
Open context to currently shown hint.
void DontShowAgainCurrent()
void SetShown(SCR_HintUIInfo info)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Diagnostic and developer menu system.
Definition DiagMenu.c:18
Definition Math.c:13
static SCR_FieldManualUI Open(EFieldManualEntryId entryId)
opens the first entry matching the EFieldManualEntryId enum value
static bool IsEditMode()
Definition Functions.c:1566
static SCR_HUDManagerComponent GetHUDManager()
ref array< ref SCR_HintConditionList > m_aConditionLists
bool ShouldFactionSeeHint()
void SetTimeStamp()
Set the time stamp of Hint start. Needed for hint timer timekeeping.
static SCR_HintUIInfo CreateInfo(string description, string name, float duration, EHint type, EFieldManualEntryId fieldManualEntry, bool isTimerVisible)
EFieldManualEntryId GetFieldManualLink()
override void Hide()
Definition gameLib.c:268
override void Show()
Definition gameLib.c:262
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
EActionTrigger