Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SaveDialogUIComponent.c
Go to the documentation of this file.
1
6{
7 [Attribute()]
8 protected bool m_bIsLoad;
9
10 [Attribute()]
11 protected bool m_bCurrentMissionOnly;
12
13 [Attribute("false", UIWidgets.CheckBox)]
14 protected bool m_bVerboseDate;
15
16 [Attribute(uiwidget: UIWidgets.ResourceNamePicker, params: "layout")]
18
19 [Attribute(uiwidget: UIWidgets.ResourceNamePicker, params: "layout")]
21
22 [Attribute("session_save_override")]
23 protected string m_sConfirmPrompt;
24
25 [Attribute("session_delete")]
26 protected string m_sDeletePrompt;
27
28 [Attribute("session_load_bad_version")]
29 protected string m_sLoadBadVersionPrompt;
30
31 [Attribute("session_load_bad_addons")]
32 protected string m_sLoadBadAddonsPrompt;
33
34 [Attribute("save-published")]
35 protected string m_sDownloadIconName;
36
38 protected ref array<Widget> m_aEntriesHidden = {};
39 protected ref array<Widget> m_aEntriesToShow = {};
40
42
45
51
52 protected float m_fSliderPosY;
53
55 // Control buttons
57
58 //------------------------------------------------------------------------------------------------
59 protected void OnClose(SCR_InputButtonComponent button, string actionName)
60 {
61 CloseMenu();
62 }
63
64 //------------------------------------------------------------------------------------------------
65 protected void OnConfirm(SCR_InputButtonComponent button, string actionName);
66
67 //------------------------------------------------------------------------------------------------
68 protected void OnConfirmPrompt()
69 {
70 if (m_bIsLoad)
71 {
72 LoadEntry();
73 return;
74 }
75
76 SaveEntry();
77 CloseMenu();
78 }
79
80 //------------------------------------------------------------------------------------------------
82 protected void OnDelete(SCR_InputButtonComponent button, string actionName)
83 {
84 if (!m_SelectedSave)
85 return;
86
87 // Open delete dialog
89 m_DeletePrompt.m_OnConfirm.Insert(OnDeletePrompt);
90
91 // Setup string
92 const string displayName = GetSaveDisplayName(m_SelectedSave);
93 m_DeletePrompt.SetTitle(displayName);
94 }
95
96 //------------------------------------------------------------------------------------------------
97 protected void OnDeletePrompt()
98 {
99 SelectEntry(null, null);
100 }
101
102 //------------------------------------------------------------------------------------------------
103 protected void RemoveSaveEntry(notnull SaveGame save)
104 {
106 {
107 if (entry.GetSaveData() == save)
108 {
109 widget.RemoveFromHierarchy();
110 m_mComponentEntries.Remove(widget);
112 return;
113 }
114 }
115 }
116
117 //------------------------------------------------------------------------------------------------
118 protected void CloseMenu()
119 {
120 //--- Confirmation prompt opened, ignore
121 if (GetGame().GetWorkspace().GetModal() != m_wRoot)
122 return;
123
124 MenuBase menu = MenuBase.Cast(m_wRoot.FindHandler(MenuBase));
125 menu.Close();
126 }
127
129 // Main operations
131
132 //------------------------------------------------------------------------------------------------
133 protected void SaveEntry();
134
135 //------------------------------------------------------------------------------------------------
136 protected void LoadEntry();
137
138 //------------------------------------------------------------------------------------------------
140 {
141 CloseMenu();
142 }
143
144 //------------------------------------------------------------------------------------------------
146 {
147 SCR_CommonDialogs.CreateRequestErrorDialog();
148
150 m_LoadingOverlay.Close();
151
152 CloseMenu();
153 }
154
156 // Interaction
158
159 //------------------------------------------------------------------------------------------------
160 protected void SelectEntry(Widget w, SCR_SaveLoadEntryComponent entryComponent)
161 {
162 SCR_SaveLoadEntryComponent previousEntryComponent;
163 if (m_mComponentEntries.Find(m_wSelectedWidget, previousEntryComponent))
164 {
165 previousEntryComponent.GetOnDeleteSave().Remove(OnDelete);
166 previousEntryComponent.GetOnLoadSave().Remove(OnConfirm);
167 previousEntryComponent.GetOnOverrideSave().Remove(OnConfirm);
168 }
169
171
172 if (entryComponent)
173 {
174 m_SelectedSave = entryComponent.GetSaveData();
175 entryComponent.GetOnDeleteSave().Insert(OnDelete);
176 entryComponent.GetOnLoadSave().Insert(OnConfirm);
177 entryComponent.GetOnOverrideSave().Insert(OnConfirm);
178 }
179
181 }
182
183 //------------------------------------------------------------------------------------------------
184 protected void UpdateButtons();
185
186 //------------------------------------------------------------------------------------------------
187 protected void OnFrame()
188 {
189 //--- Ignore if all entries were shown
190 if (m_aEntriesHidden.IsEmpty())
191 {
192 GetGame().GetCallqueue().Remove(OnFrame);
193 return;
194 }
195
196 float sliderPosX, sliderPosY;
197 m_Widgets.m_wSaveScroller.GetSliderPos(sliderPosX, sliderPosY);
198
199 if (sliderPosY != m_fSliderPosY)
200 {
201 float scrollPosX, scrollPosY, scrollSizeW, scrollSizeH;
202 m_Widgets.m_wSaveScroller.GetScreenPos(scrollPosX, scrollPosY);
203 m_Widgets.m_wSaveScroller.GetScreenSize(scrollSizeW, scrollSizeH);
204
205 //--- Widget not loaded yet, terminate
206 if (scrollSizeH == 0)
207 return;
208
209 //--- Find widgets in view
210 foreach (int i, Widget entryWidget : m_aEntriesHidden)
211 {
212 //--- Already shown
213 if (entryWidget.GetOpacity() > 0)
214 continue;
215
216 float posX, posY, sizeW, sizeH;
217 entryWidget.GetScreenPos(posX, posY);
218 entryWidget.GetScreenSize(sizeW, sizeH);
219
220 if ((posY + sizeH) > scrollPosY && posY < (scrollPosY + scrollSizeH))
221 {
222 //--- When the entry is in the scrolled view, mark it for showing
223 if (!m_aEntriesToShow.Contains(entryWidget))
224 m_aEntriesToShow.Insert(entryWidget);
225 }
226 else
227 {
228 //--- When the entry is not in the scrolled view, removing it from queue of entries to show again (to prioritize entries that are actually shown)
229 m_aEntriesToShow.RemoveItemOrdered(entryWidget);
230 }
231 }
232 }
233
234 //--- Process the queue of entries to show, with one entry per frame
235 if (!m_aEntriesToShow.IsEmpty())
237
238 m_fSliderPosY = sliderPosY;
239 }
240
241 //------------------------------------------------------------------------------------------------
242 protected void DisplaySaveEntries()
243 {
244 Widget entryWidget = m_aEntriesToShow[0];
245
246 SCR_SaveLoadEntryComponent entryComponent;
247 m_mComponentEntries.Find(entryWidget, entryComponent);
248 if (entryWidget.GetOpacity() == 0)
249 {
250 int y, m, d, hh, mm, s;
251 SaveGame saveEntry = entryComponent.GetSaveData();
252 saveEntry.GetSavePointCreatedLocalDateTime(y, m, d, hh, mm, s);
253
254 if (false) // TODO: Workshop sharing support
255 {
256 entryComponent.SetIsDownloaded(true);
257 entryComponent.SetSaveIcon(Color.FromInt(Color.WHITE), m_sDownloadIconName);
258 }
259
260 entryComponent.SetDisplayName(GetSaveDisplayName(saveEntry));
261 entryComponent.SetDateTime(SCR_DateTimeHelper.GetDateString(d, m, y, m_bVerboseDate), SCR_FormatHelper.GetTimeFormattingHoursMinutes(hh, mm));
262 entryComponent.SetVersion(saveEntry.GetSavePointGameVersion(), saveEntry.IsSavePointGameVersionCompatible());
263 entryComponent.SetCanLoad(m_bIsLoad);
264 entryComponent.SetCanSave(!m_bIsLoad);
265 entryComponent.SetCanDelete(true);
266
267 if (!saveEntry.AreSavePointAddonsCompatible())
268 entryComponent.SetSaveIcon(UIColors.WARNING, m_sDownloadIconName);
269 else
270 entryComponent.SetSaveIcon(Color.FromInt(Color.WHITE), "save");
271
272 /*
273 ResourceName headerResourceName = saveEntry.GetMissionResource();
274 if (!headerResourceName.IsEmpty())
275 {
276 Resource missionHeaderResource = Resource.Load(headerResourceName);
277 if (missionHeaderResource.IsValid())
278 {
279 SCR_MissionHeader missionHeader = SCR_MissionHeader.Cast(BaseContainerTools.CreateInstanceFromContainer(missionHeaderResource.GetResource().ToBaseContainer()));
280
281 entryComponent.SetScenarioDataVisible(true);
282 entryComponent.SetScenarioName(missionHeader.m_sName);
283
284 if (missionHeader.m_sIcon)
285 entryComponent.SetScenarioIcon(Color.FromInt(Color.WHITE), missionHeader.m_sIcon);
286 }
287 }
288 */
289
290 AnimateWidget.Opacity(entryWidget, 1, 3);
291 }
292 else if (entryWidget.GetOpacity() > 0)
293 {
294 //--- Started fading in, move on to the next entry
295 m_aEntriesToShow.RemoveOrdered(0);
296 m_aEntriesHidden.RemoveItemOrdered(entryWidget);
297 }
298 }
299
300 //------------------------------------------------------------------------------------------------
302 {
303 if (!saveEntry)
304 return string.Empty;
305
306 return GetSaveDisplayName(saveEntry.GetSaveData());
307 }
308
309 //------------------------------------------------------------------------------------------------
310 protected string GetSaveDisplayName(SaveGame save)
311 {
312 if (!save )
313 return string.Empty;
314
315 return save.GetSavePointName();
316 }
317
319 // Overrides
321
322 //------------------------------------------------------------------------------------------------
323 override void HandlerAttached(Widget w)
324 {
325 m_wRoot = w;
326 m_Widgets.Init(w);
327 m_fSliderPosY = -1;
328
329 m_Widgets.m_SaveNameInputComponent0.m_OnChanged.Insert(UpdateButtons);
330
331 m_Widgets.m_ExitButtonComponent.m_OnActivated.Insert(OnClose);
332 m_Widgets.m_DeleteButtonComponent.m_OnActivated.Insert(OnDelete);
333 m_Widgets.m_OverrideButtonComponent.m_OnActivated.Insert(OnConfirm);
334 m_Widgets.m_ConfirmButtonComponent.m_OnActivated.Insert(OnConfirm);
335
337
338 const SaveGameManager manager = GetGame().GetSaveGameManager();
339 manager.GetSaves(manager.GetCurrentMissionResource(), new SaveGameObtainCallback(OnSavesLoaded));
340 }
341
342 //------------------------------------------------------------------------------------------------
343 protected void OnSavesLoaded(bool success, array<SaveGame> saves)
344 {
345 //--- Create new entries
346 WorkspaceWidget workspace = GetGame().GetWorkspace();
347 Widget entryWidget;
348 SCR_ModularButtonComponent entryButton;
349 SCR_SaveLoadEntryComponent entryCompoment;
350 SCR_RewindComponent rewind = SCR_RewindComponent.GetInstance();
351 foreach (int idx, SaveGame save : saves)
352 {
353 if (rewind && rewind.IsRewindPoint(save))
354 continue;
355
356 entryWidget = workspace.CreateWidgets(m_sEntryLayout, m_Widgets.m_wSaveList);
357 entryButton = SCR_ModularButtonComponent.Cast(entryWidget.FindHandler(SCR_ModularButtonComponent));
358 if (entryButton)
359 {
360 entryButton.m_OnFocus.Insert(OnEntryFocus);
361 entryButton.m_OnDoubleClicked.Insert(OnEntryDoubleClick);
362 }
363
364 entryCompoment = SCR_SaveLoadEntryComponent.Cast(entryWidget.FindHandler(SCR_SaveLoadEntryComponent));
365 entryCompoment.SetSaveData(save);
366 entryWidget.SetZOrder(save.GetSavePointCreatedUnix());
367
368 m_mComponentEntries.Insert(entryWidget, entryCompoment);
369 m_aEntriesHidden.Insert(entryWidget);
370
371 //--- Hide by default
372 entryWidget.SetOpacity(0);
373
374 if (m_bIsLoad && idx == 0)
375 GetGame().GetCallqueue().CallLater(SelectEntry, 10, false, entryWidget, entryCompoment);
376 }
377
378 //--- Initiate periodic check which will load and show metadata only for entries that are actually shown. Doing it all at once here would be too expensive.
379 GetGame().GetCallqueue().CallLater(OnFrame, 1, true);
380 }
381
382 //------------------------------------------------------------------------------------------------
383 protected void OnEntryFocus(SCR_ModularButtonComponent button)
384 {
385 //--- Save entry
386 Widget w = button.GetRootWidget();
387 SCR_SaveLoadEntryComponent entryComponent;
388 if (!m_mComponentEntries.Find(w, entryComponent))
389 return;
390
391 SelectEntry(w, entryComponent);
392 }
393
394 //------------------------------------------------------------------------------------------------
395 protected void OnEntryDoubleClick(SCR_ModularButtonComponent button)
396 {
397 //--- Activate
398 OnConfirm(null, string.Empty);
399 }
400
401 //------------------------------------------------------------------------------------------------
402 override void HandlerDeattached(Widget w)
403 {
404 GetGame().GetCallqueue().Remove(OnFrame);
405 }
406}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_NewSessionToolbarAction SCR_EditorToolbarAction OnConfirm()
static WidgetAnimationOpacity Opacity(Widget widget, float targetValue, float speed, bool toggleVisibility=false)
Definition Color.c:13
static SCR_ConfigurableDialogUi CreateFromPreset(ResourceName presetsResourceName, string tag, SCR_ConfigurableDialogUi customDialogObj=null)
Creates a dialog from preset.
static string GetTimeFormattingHoursMinutes(int hours, int minutes, ETimeFormatParam hideEmpty=0, ETimeFormatParam hideLeadingZeroes=0)
void RemoveSaveEntry(notnull SaveGame save)
SCR_ConfigurableDialogUi m_LoadBadVersionPrompt
ref SCR_EditorSaveDialogWidgets m_Widgets
void OnSavesLoaded(bool success, array< SaveGame > saves)
SCR_ConfigurableDialogUi m_ConfirmPrompt
void OnConfirm(SCR_InputButtonComponent button, string actionName)
void OnDelete(SCR_InputButtonComponent button, string actionName)
Callback on clicking delete button or actoin.
override void HandlerAttached(Widget w)
void OnLoadEntryUploadError(BackendCallback callback)
void OnLoadEntryUploadResponse(BackendCallback callback)
SCR_LoadingOverlayDialog m_LoadingOverlay
SCR_ConfigurableDialogUi m_LoadBadAddonsPrompt
string GetSaveDisplayName(SCR_SaveLoadEntryComponent saveEntry)
void OnEntryFocus(SCR_ModularButtonComponent button)
SCR_ConfigurableDialogUi m_DeletePrompt
void OnClose(SCR_InputButtonComponent button, string actionName)
ref map< Widget, SCR_SaveLoadEntryComponent > m_mComponentEntries
string GetSaveDisplayName(SaveGame save)
override void HandlerDeattached(Widget w)
void OnEntryDoubleClick(SCR_ModularButtonComponent button)
void SelectEntry(Widget w, SCR_SaveLoadEntryComponent entryComponent)
void SetIsDownloaded(bool state)
void SetCanLoad(bool state)
void SetSaveData(SaveGame saveData)
ScriptInvokerButton GetOnDeleteSave()
void SetCanDelete(bool state)
void SetDisplayName(string name)
ScriptInvokerButton GetOnOverrideSave()
ScriptInvokerButton GetOnLoadSave()
void SetSaveIcon(Color imageColor, string icon)
void SetVersion(string version, bool isVersionCompatible)
void SetCanSave(bool state)
void SetDateTime(string date, string time)
SaveGame GetSaveData()
Definition Types.c:486
SCR_FieldOfViewSettings Attribute