Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_LoadingScreenComponent.c
Go to the documentation of this file.
1 class SCR_LoadingScreenComponent : SCR_BaseLoadingScreenComponent
2 {
3  protected bool m_bMissionDataRetrieved;
4 
5  protected const string AUTHOR_FORMAT = "#AR-AuthorLoadingScreen"; //"Author: "
6  protected const string AUTHOR_UNKNOWN = "#AR-Author_Unknown"; //"By a community author"
7 
8  protected const float MAX_DESCRIPTION_LENGTH = 1000;
9  protected const float FADE_TIME = 1;
10 
11  private float m_fLoadingTime_MissionDataRetrieved;
12  private float m_fProgressBar_Progress;
13  private ref SCR_LoadingHintComponent m_LoadingHintComponent;
14 
15  protected Widget m_wBuildVersion;
16 
17  //---------------------------------------------------------------------------------------------
18  override protected void HandlerAttached(Widget w)
19  {
20  super.HandlerAttached(w);
21 
22  m_wRoot.SetZOrder(10000);
23  }
24 
25  //---------------------------------------------------------------------------------------------
26  override protected void InitWidgets()
27  {
28  super.InitWidgets();
29 
30  m_Widgets.m_wContentOverlay.SetOpacity(0);
31 
32  m_Widgets.m_wContent.SetVisible(false);
33  m_Widgets.m_wPreloadContent.SetVisible(true);
34 
35  m_Widgets.m_wContentOverlay.SetVisible(true);
36  m_Widgets.m_wBlackOverlay.SetVisible(true);
37 
38  #ifdef DEBUG_LOADING_SCREENS
39  m_Widgets.m_wCrossplayWarning.SetVisible(true);
40  m_Widgets.m_wModdedWarning.SetVisible(true);
41  #else
42  m_Widgets.m_wCrossplayWarning.SetVisible(false);
43  m_Widgets.m_wModdedWarning.SetVisible(false);
44  #endif
45  }
46 
47  //---------------------------------------------------------------------------------------------
48  void OnMissionDataRetrieved(SCR_MissionHeader header)
49  {
50  #ifdef DEBUG_LOADING_SCREENS
51  PrintFormat(">> %1 >> OnMissionDataRetrieved | header: %2", this, header);
52  #endif
53 
54  // Create a build version layout
55  m_wBuildVersion = GetGame().GetWorkspace().CreateWidgets("{B7A765172F0BD4D9}UI/layouts/Common/GameVersionWatermark.layout", m_wRoot);
56  m_wBuildVersion.SetZOrder(1);
57  m_wBuildVersion.SetVisible(false);
58 
59  // If loading header failed, keep the preloading state
60  if (!header)
61  return;
62 
63  // Add hint component
64  m_LoadingHintComponent = new SCR_LoadingHintComponent();
65 
66  if (m_LoadingHintComponent)
67  m_Widgets.m_wHintText.AddHandler(m_LoadingHintComponent);
68 
69  // Get description text and check its length
70  string description = header.m_sDetails;
71  if (description == string.Empty)
72  description = header.m_sDescription;
73 
74  description = WidgetManager.Translate(description);
75 
76  if (description.Length() > MAX_DESCRIPTION_LENGTH)
77  {
78  description = description.Substring(0, MAX_DESCRIPTION_LENGTH);
79  description += "...";
80  }
81 
82  string image = header.m_sLoadingScreen;
83  if (image == string.Empty)
84  image = header.m_sIcon;
85 
86  if (m_Widgets.m_wTitle)
87  m_Widgets.m_wTitle.SetText(header.m_sName);
88 
89  if (m_Widgets.m_wDescription)
90  m_Widgets.m_wDescription.SetText(description);
91 
92  if (m_Widgets.m_wAuthor)
93  {
94  if (header.m_sAuthor.IsEmpty())
95  m_Widgets.m_wAuthor.SetText(AUTHOR_UNKNOWN);
96  else
97  {
98  string author = WidgetManager.Translate(AUTHOR_FORMAT);
99  m_Widgets.m_wAuthor.SetText(author + header.m_sAuthor);
100  }
101  }
102 
103  if (m_Widgets.m_wLoadingImage)
104  {
105  m_Widgets.m_wLoadingImage.LoadImageTexture(0, image);
106  }
107 
108  // Allow fade-in Update() animations
109  m_bMissionDataRetrieved = true;
110  m_fLoadingTime_MissionDataRetrieved = m_fLoadingTime;
111  }
112 
113  //---------------------------------------------------------------------------------------------
114  override void OnHide()
115  {
116  if (m_bMissionDataRetrieved)
117  {
118  ResetLoadingTime();
119  }
120  else
121  {
122  if (m_LoadingHintComponent)
123  m_LoadingHintComponent.OnLoadingFinished();
124 
125  SaveLoadingTime(m_fLoadingTime);
126  }
127  }
128 
129  //---------------------------------------------------------------------------------------------
130  override void Update(float timeSlice, float progress = 0, float minDurationRatio = 0)
131  {
132  super.Update(timeSlice, progress, minDurationRatio);
133 
134  #ifdef DEBUG_LOADING_SCREENS
135  PrintFormat(">> %1 >> Update | timeSlice: %2 | progress: %3 | m_fLoadingTime: %4", this, timeSlice, progress, m_fLoadingTime);
136  #endif
137 
138  if (!m_bMissionDataRetrieved)
139  return;
140 
141  // Update loading hints
142  if (m_LoadingHintComponent)
143  m_LoadingHintComponent.Update(timeSlice);
144 
145  // Update progress bar
146  SetProgressBar(progress);
147 
148  // Rotate spinner
149  if (m_SpinnerComp)
150  m_SpinnerComp.Update(timeSlice);
151 
152  // Hiding pre-load conntent
153  if (m_fLoadingTime <= m_fLoadingTime_MissionDataRetrieved + FADE_TIME)
154  {
155  Fade(m_Widgets.m_wContentOverlay, true, FADE_TIME, timeSlice);
156  }
157  // Showing scenario content
158  else if (m_fLoadingTime <= m_fLoadingTime_MissionDataRetrieved + 2 * FADE_TIME)
159  {
160  m_Widgets.m_wPreloadContent.SetVisible(false);
161  m_Widgets.m_wContent.SetVisible(true);
162  m_wBuildVersion.SetVisible(true);
163 
164  Fade(m_Widgets.m_wContentOverlay, false, FADE_TIME, timeSlice);
165  }
166  // Scenario content shown
167  else
168  {
169  m_Widgets.m_wPreloadContent.SetVisible(false);
170  m_Widgets.m_wContent.SetVisible(true);
171  m_Widgets.m_wContentOverlay.SetOpacity(0);
172  }
173  }
174 
175  //---------------------------------------------------------------------------------------------
176  protected void SetProgressBar(float progress)
177  {
178  if (!m_Widgets.m_wProgressBarFill || !m_Widgets.m_wProgressBarSpace)
179  return;
180 
181  // Make sure progression never goes back
182  if (progress < m_fProgressBar_Progress)
183  progress = m_fProgressBar_Progress;
184  else if (progress > m_fProgressBar_Progress)
185  m_fProgressBar_Progress = progress;
186 
187  HorizontalLayoutSlot.SetFillWeight(m_Widgets.m_wProgressBarFill, progress);
188  HorizontalLayoutSlot.SetFillWeight(m_Widgets.m_wProgressBarSpace, 1 - progress);
189  }
190 
191  //------------------------------------------------------------------------------------------------
192  void SetJoiningCrossPlay(bool isCrossPlay)
193  {
194  m_Widgets.m_wCrossplayWarning.SetVisible(isCrossPlay);
195  }
196 
197  //------------------------------------------------------------------------------------------------
198  void SetLoadingModded(bool isModded)
199  {
200  m_Widgets.m_wModdedWarning.SetVisible(isModded);
201  }
202 };
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_LoadingHintComponent
Definition: SCR_LoadingHintComponent.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_Widgets
ref SCR_VoNOverlay_ElementWidgets m_Widgets
Definition: SCR_VonDisplay.c:3
SCR_LoadingScreenComponent
Definition: SCR_LoadingScreenComponent.c:1
SCR_MissionHeader
Definition: SCR_MissionHeader.c:1