Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_LoadingHintComponent.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 class SCR_LoadingHintComponent : ScriptedWidgetComponent
3 {
4  protected const int HINT_INDEX = -1;
5  protected const float SWITCH_TIME = 10;
6 
7  protected int m_iHintCount;
8  protected int m_iHintIndex = -1;
9  protected float m_fTime;
10  protected TextWidget m_wText;
11  protected ResourceName m_Config = "{CB10921F1096D4A0}Configs/UI/LoadingScreenHints.conf";
12  protected ref array<string> m_aAllHints;
13  protected ref array<string> m_aReadHints;
14 
15  //------------------------------------------------------------------------------------------------
16  override void HandlerAttached(Widget w)
17  {
18  m_wText = TextWidget.Cast(w);
19 
20  // Init arrays of all hints and read hints
21  BaseContainer cont = GetGame().GetGameUserSettings().GetModule("SCR_LoadingHints");
22  if (cont)
23  {
24  cont.Get("m_aReadHints", m_aReadHints);
25  if (m_aReadHints)
26  m_iHintCount = m_aReadHints.Count();
27  }
28 
29  Resource resource = BaseContainerTools.LoadContainer(m_Config);
30 
31  if (!resource)
32  return;
33 
34  BaseContainer entries = resource.GetResource().ToBaseContainer();
35 
36  if (!entries)
37  return;
38 
39  entries.Get("m_aHints", m_aAllHints);
40 
41  // Show first hint
42  ShowHint(HINT_INDEX);
43  }
44 
45  //------------------------------------------------------------------------------------------------
46  void OnLoadingFinished()
47  {
48  // Save hints to the settings module
49  UserSettings settings = GetGame().GetGameUserSettings();
50  if (!settings)
51  return;
52 
53  BaseContainer cont = settings.GetModule("SCR_LoadingHints");
54  if (!cont || !m_aReadHints || m_aReadHints.Count() == m_iHintCount)
55  return;
56 
57  cont.Set("m_aReadHints", m_aReadHints);
58  GetGame().UserSettingsChanged();
59  }
60 
61  //------------------------------------------------------------------------------------------------
62  override void HandlerDeattached(Widget w)
63  {
64  // Mark the current hint read if shown for infinite time
65  if (SWITCH_TIME < 0)
66  MarkHintRead();
67  }
68 
69  //------------------------------------------------------------------------------------------------
70  void Update(float timeSlice)
71  {
72  m_fTime += timeSlice;
73 
74  if (m_fTime < SWITCH_TIME)
75  return;
76 
77  // Switch to a new hint
78  MarkHintRead();
79  ShowHint(HINT_INDEX);
80  m_fTime = 0;
81  }
82 
83  //------------------------------------------------------------------------------------------------
84  void ShowHint(int entryIndex = -1)
85  {
86  if (!m_wText || !m_aAllHints)
87  return;
88 
89  if (!m_aReadHints)
90  m_aReadHints = {};
91 
92  string hint;
93  if (entryIndex == -1)
94  {
95  array<string> unread = {};
96  int count = GetUnreadHints(unread);
97  if (count == 0)
98  return;
99 
100  int i = Math.RandomInt(0, count);
101  hint = unread[i];
102  m_iHintIndex = m_aAllHints.Find(hint);
103  }
104  else if (entryIndex < m_aAllHints.Count())
105  {
106  hint = m_aAllHints[entryIndex];
107  }
108 
109  m_wText.SetTextFormat(hint);
110  }
111 
112  //------------------------------------------------------------------------------------------------
113  void MarkHintRead()
114  {
115  if (m_iHintIndex < 0 || m_iHintIndex >= m_aAllHints.Count())
116  return;
117 
118  m_aReadHints.Insert(m_aAllHints[m_iHintIndex]);
119  m_iHintIndex = -1;
120  }
121 
122  // Get all hints which were not read yet
123  //------------------------------------------------------------------------------------------------
124  protected int GetUnreadHints(array<string> hints)
125  {
126  hints.Clear();
127 
128  foreach (string hint : m_aAllHints)
129  {
130  if (!m_aReadHints.Contains(hint))
131  hints.Insert(hint);
132  }
133 
134  // If there is no unread hint, reset the read array and start it again
135  if (hints.Count() == 0)
136  hints.InsertAll(m_aAllHints);
137 
138  return hints.Count();
139  }
140 };
SCR_LoadingHintComponent
Definition: SCR_LoadingHintComponent.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_fTime
float m_fTime
Definition: SCR_CharacterCommandSwim.c:221