Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_LoadingHintComponent.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
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;
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
43 }
44
45 //------------------------------------------------------------------------------------------------
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)
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
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 //------------------------------------------------------------------------------------------------
114 {
116 return;
117
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};
ArmaReforgerScripted GetGame()
Definition game.c:1398
Definition Math.c:13
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
int GetUnreadHints(array< string > hints)
override void HandlerAttached(Widget w)
override void HandlerDeattached(Widget w)
void ShowHint(int entryIndex=-1)