4 protected bool m_bIsLoad;
13 protected bool m_bCurrentMissionOnly;
16 protected string m_sScrollWidgetName;
19 protected string m_sListWidgetName;
22 protected string m_sNameInputWidgetName;
25 protected string m_sCloseButtonWidgetName;
28 protected string m_sDeleteButtonWidgetName;
31 protected string m_sOverrideButtonWidgetName;
34 protected string m_sConfirmButtonWidgetName;
37 protected string m_sConfirmPromptWidgetName;
40 protected string m_sDeletePromptWidgetName;
43 protected string m_sLoadBadVersionPromptWidgetName;
46 protected string m_sLoadBadAddonsPromptWidgetName;
49 protected string m_sEntryNameWidgetName;
52 protected string m_sEntryMeta;
55 protected string m_sEntryDateWidgetName;
58 protected string m_sEntryTimeWidgetName;
61 protected string m_sEntryMissionNameWidgetName;
64 protected string m_sEntryVersionWidgetName;
67 protected string m_sEntryImageWidgetName;
70 protected string m_sEntryIconWidgetName;
73 protected bool m_bVerboseDate;
76 protected ResourceName m_sCreateLayout;
79 protected ResourceName m_sEntryLayout;
82 protected string m_sConfirmPrompt;
85 protected string m_sDeletePrompt;
88 protected string m_sLoadBadVersionPrompt;
91 protected string m_sLoadBadAddonsPrompt;
93 protected Widget m_wRoot;
94 protected ScrollLayoutWidget m_wScroll;
95 protected Widget m_wList;
96 protected Widget m_wLastFocusedEntry;
109 protected float m_fSliderPosY = -1;
110 protected Widget m_wSelectedWidget;
111 protected string m_sSelectedFileName;
113 protected ref map<Widget, string> m_mEntries =
new map<Widget, string>();
114 protected ref map<string, string> m_mEntryNames =
new map<string, string>();
115 protected ref array<Widget> m_aEntriesHidden = {};
116 protected ref array<Widget> m_aEntriesToShow = {};
134 string customName = m_SaveNameInput.GetValue();
139 m_ConfirmPrompt.m_OnConfirm.Insert(OnConfirmPrompt);
148 m_ConfirmPrompt.SetTitle(m_SaveNameInput.GetValue());
153 string displayName = m_mEntryNames[m_sSelectedFileName];
155 if (m_mEntries.Find(
GetGame().GetWorkspace().GetFocusedWidget(), fileName))
160 if (!meta.IsVersionCompatible())
164 m_LoadBadVersionPrompt.m_OnConfirm.Insert(LoadEntry);
165 m_LoadBadVersionPrompt.SetTitle(displayName);
168 else if (!meta.AreAddonsCompatible())
172 m_LoadBadAddonsPrompt.m_OnConfirm.Insert(LoadEntry);
173 m_LoadBadAddonsPrompt.SetTitle(displayName);
180 m_ConfirmPrompt.m_OnConfirm.Insert(OnConfirmPrompt);
181 m_ConfirmPrompt.SetTitle(displayName);
186 protected void OnConfirmPrompt()
202 m_DeletePrompt.m_OnConfirm.Insert(OnDeletePrompt);
205 string displayName = m_mEntryNames[m_sSelectedFileName];
206 m_DeletePrompt.SetTitle(displayName);
210 protected void OnDeletePrompt()
213 GetGame().GetSaveManager().Delete(m_sSelectedFileName);
216 m_mEntries.Remove(m_wSelectedWidget);
217 m_mEntryNames.Remove(m_sSelectedFileName);
219 m_wSelectedWidget.RemoveFromHierarchy();
220 SelectEntry(
null,
string.Empty);
224 protected void CloseMenu()
230 MenuBase menu = MenuBase.Cast(
m_wRoot.FindHandler(MenuBase));
239 protected void SaveEntry()
241 string customName = m_SaveNameInput.GetValue();
242 GetGame().GetSaveManager().Save(m_eWriteSaveType, customName);
246 protected void LoadEntry()
249 if (m_mEntries.Find(m_wLastFocusedEntry, fileName))
253 saveManager.RestartAndLoad(fileName);
255 if (saveManager.GetUploadCallback())
257 saveManager.GetUploadCallback().GetEventOnResponse().Insert(OnLoadEntryUploadResponse);
266 callback.GetEventOnResponse().Remove(OnLoadEntryUploadResponse);
282 protected void SelectEntry(Widget w,
string fileName)
284 string customName =
GetGame().GetSaveManager().GetCustomName(fileName);
285 m_SaveNameInput.SetValue(customName);
287 m_wSelectedWidget = w;
288 m_sSelectedFileName = fileName;
294 protected void UpdateButtons()
296 string customName = m_SaveNameInput.GetValue();
297 bool isValid = !customName.IsEmpty();
298 bool isOverride = !m_bIsLoad && customName &&
GetGame().GetSaveManager().FileExists(m_eWriteSaveType, customName);
301 m_DeleteButton.SetEnabled(m_sSelectedFileName &&
GetGame().
GetSaveManager().FileExists(m_sSelectedFileName));
303 m_DeleteButton.SetEnabled(isOverride);
305 m_OverrideButton.SetVisible(isOverride,
false);
306 m_OverrideButton.SetEnabled(isOverride && isValid);
308 m_ConfirmButton.SetVisible(!isOverride,
false);
309 m_ConfirmButton.SetEnabled(!isOverride && isValid);
313 protected void OnFrame()
316 if (m_aEntriesHidden.IsEmpty())
318 GetGame().GetCallqueue().Remove(OnFrame);
322 float sliderPosX, sliderPosY;
323 m_wScroll.GetSliderPos(sliderPosX, sliderPosY);
325 if (sliderPosY != m_fSliderPosY)
327 float scrollPosX, scrollPosY, scrollSizeW, scrollSizeH;
328 m_wScroll.GetScreenPos(scrollPosX, scrollPosY);
329 m_wScroll.GetScreenSize(scrollSizeW, scrollSizeH);
332 if (scrollSizeH == 0)
336 foreach (
int i, Widget entryWidget: m_aEntriesHidden)
339 if (entryWidget.GetOpacity() > 0)
342 float posX, posY, sizeW, sizeH;
343 entryWidget.GetScreenPos(posX, posY);
344 entryWidget.GetScreenSize(sizeW, sizeH);
346 if ((posY + sizeH) > scrollPosY && posY < (scrollPosY + scrollSizeH))
349 if (!m_aEntriesToShow.Contains(entryWidget))
350 m_aEntriesToShow.Insert(entryWidget);
355 m_aEntriesToShow.RemoveItemOrdered(entryWidget);
361 if (!m_aEntriesToShow.IsEmpty())
363 Widget entryWidget = m_aEntriesToShow[0];
364 if (entryWidget.GetOpacity() == 0)
366 TextWidget entryNameWidget = TextWidget.Cast(entryWidget.FindAnyWidget(m_sEntryNameWidgetName));
367 ImageWidget entryImageWidget = ImageWidget.Cast(entryWidget.FindAnyWidget(m_sEntryImageWidgetName));
368 ImageWidget entryIconWidget = ImageWidget.Cast(entryWidget.FindAnyWidget(m_sEntryIconWidgetName));
370 string fileName = m_mEntries[entryWidget];
371 string entryName =
GetGame().GetSaveManager().GetCustomName(fileName);
374 if (meta && meta.IsValid())
377 meta.GetDateAndTime(y, m, d, hh, mm);
380 string displayName = entryName;
381 Color imageColor = Color.FromInt(Color.WHITE);
384 info.SetIconTo(entryIconWidget);
385 displayName = info.GetName() +
" " + displayName;
389 imageColor = colorInfo.GetColor();
391 m_mEntryNames.Insert(fileName, displayName);
393 entryNameWidget.SetText(displayName);
395 TextWidget entryDateWidget = TextWidget.Cast(entryWidget.FindAnyWidget(m_sEntryDateWidgetName));
398 TextWidget entryTimeWidget = TextWidget.Cast(entryWidget.FindAnyWidget(m_sEntryTimeWidgetName));
399 entryTimeWidget.SetText(
SCR_FormatHelper.GetTimeFormattingHoursMinutes(hh, mm));
401 TextWidget entryVersionWidget = TextWidget.Cast(entryWidget.FindAnyWidget(m_sEntryVersionWidgetName));
403 bool isVersionCompatible = meta.IsVersionCompatible(versionText);
404 entryVersionWidget.SetText(versionText);
405 if (!isVersionCompatible)
406 entryVersionWidget.SetColor(
UIColors.WARNING);
408 Resource missionHeaderResource = Resource.Load(meta.GetHeaderResource());
409 if (missionHeaderResource.IsValid())
413 TextWidget entryMissionNameWidget = TextWidget.Cast(entryWidget.FindAnyWidget(m_sEntryMissionNameWidgetName));
414 entryMissionNameWidget.SetText(missionHeader.m_sName);
416 if (missionHeader.m_sIcon)
418 entryImageWidget.LoadImageTexture(0, missionHeader.m_sIcon);
419 entryImageWidget.SetColor(imageColor);
423 if (!meta.AreAddonsCompatible())
425 entryIconWidget.SetColor(
UIColors.WARNING);
431 entryNameWidget.SetText(entryName);
432 entryImageWidget.SetVisible(
false);
434 Widget entryMetaWidget = entryWidget.FindAnyWidget(m_sEntryMeta);
435 entryMetaWidget.SetVisible(
false);
437 entryIconWidget.SetColor(Color.FromInt(
UIColors.WARNING.PackToInt()));
440 AnimateWidget.Opacity(entryWidget, 1, 3);
442 else if (entryWidget.GetOpacity() > 0)
445 m_aEntriesToShow.RemoveOrdered(0);
446 m_aEntriesHidden.RemoveItemOrdered(entryWidget);
450 m_fSliderPosY = sliderPosY;
458 override bool OnClick(Widget w,
int x,
int y,
int button)
465 if (m_mEntries.Find(w, fileName))
466 SelectEntry(w, fileName);
472 override bool OnFocus(Widget w,
int x,
int y)
476 if (m_mEntries.Find(w, fileName))
478 m_wLastFocusedEntry = w;
479 SelectEntry(w, fileName);
486 override bool OnDoubleClick(Widget w,
int x,
int y,
int button)
492 OnClick(w, x, y, button);
495 OnConfirm(
null,
string.Empty);
501 override void HandlerAttached(Widget w)
508 m_wList = w.FindAnyWidget(m_sListWidgetName);
509 m_wScroll = ScrollLayoutWidget.Cast(w.FindAnyWidget(m_sScrollWidgetName));
513 m_SaveNameInput.m_OnChanged.Insert(UpdateButtons);
516 Widget closeButtonWidget = w.FindAnyWidget(m_sCloseButtonWidgetName);
517 Widget deleteButtonWidget = w.FindAnyWidget(m_sDeleteButtonWidgetName);
518 Widget overrideButtonWidget = w.FindAnyWidget(m_sOverrideButtonWidgetName);
519 Widget confirmButtonWidget = w.FindAnyWidget(m_sConfirmButtonWidgetName);
526 closeButton.m_OnActivated.Insert(OnClose);
527 m_DeleteButton.m_OnActivated.Insert(OnDelete);
528 m_OverrideButton.m_OnActivated.Insert(OnConfirm);
529 m_ConfirmButton.m_OnActivated.Insert(OnConfirm);
537 array<string> fileNames = {};
538 int fileCount =
GetGame().GetSaveManager().GetLocalSaveFiles(fileNames, m_eReadSaveTypes, m_bCurrentMissionOnly);
541 WorkspaceWidget workspace =
GetGame().GetWorkspace();
547 TextWidget entryNameWidget;
548 for (
int i = 0; i < fileCount * debugCoef; i++)
550 int ii = i % fileCount;
551 string fileName = fileNames[ii];
552 entryWidget = workspace.CreateWidgets(m_sEntryLayout,
m_wList);
553 m_mEntries.Insert(entryWidget, fileName);
554 m_aEntriesHidden.Insert(entryWidget);
557 entryWidget.SetOpacity(0);
559 if (m_bIsLoad && i == 0)
560 SelectEntry(entryWidget, fileName);
564 GetGame().GetCallqueue().CallLater(OnFrame, 1,
true);
568 override void HandlerDeattached(Widget w)
570 GetGame().GetCallqueue().Remove(OnFrame);