11 protected ref array<ref SCR_WorkshopAddonPreset> m_aPresets = {};
12 protected ref array<SCR_AddonLinePresetComponent> m_aPresetLines = {};
14 protected ref SCR_WorkshopAddonPreset m_InteractivePreset;
18 protected SCR_WorkshopAddonPreset m_CreatedPreset;
27 protected ref ScriptInvoker<bool> Event_OnRename;
30 protected void InvokeEventOnRename(
bool renameDone)
33 Event_OnRename.Invoke(renameDone);
37 ScriptInvoker GetEventOnRename()
40 Event_OnRename =
new ScriptInvoker();
42 return Event_OnRename;
46 override void HandlerAttached(Widget w)
48 super.HandlerAttached(w);
53 m_Widgets.m_ButonNewPresetComponent.m_OnClicked.Insert(CreateNewPreset);
54 m_Widgets.m_ButonNewPresetComponent.m_OnFocus.Insert(OnNewPresetFocus);
55 m_Widgets.m_ButonNewPresetComponent.m_OnFocusLost.Insert(OnNewPresetFocusLost);
59 override void HandlerDeattached(Widget w)
61 super.HandlerDeattached(w);
67 override void OnTabShow()
72 m_NavLoad = CreateNavigationButton(
"MenuSelect",
"#AR-PauseMenu_Load",
true);
73 m_NavLoad.m_OnActivated.Insert(OnLoadButton);
78 m_NavRename = CreateNavigationButton(
"MenuRename",
"#AR-MainMenu_Rename",
true);
79 m_NavRename.m_OnActivated.Insert(OnRenameButton);
84 m_NavDelete = CreateNavigationButton(
"MenuDelete",
"#AR-Workshop_ButtonDelete",
true);
85 m_NavDelete.m_OnActivated.Insert(OnDeleteButton);
90 m_NavOverride = CreateNavigationButton(
"MenuSave",
"#AR-PauseMenu_Save",
true);
91 m_NavOverride.m_OnActivated.Insert(OnOverrideButton);
96 UpdatePresetListbox();
101 SCR_AddonManager.GetInstance().GetPresetStorage().GetEventOnUsedPresetChanged().Insert(OnUsedPresetChanged);
104 GetGame().GetWorkspace().SetFocusedWidget(
null);
113 protected void UpdatePresetListbox()
123 while (lb.GetItemCount() > 0)
126 m_aPresetLines.Clear();
136 for (
int i =
m_aPresets.Count() - 1; i >= 0; i--)
138 SCR_WorkshopAddonPreset preset =
m_aPresets[i];
141 int id = lb.AddItem(preset.GetName(),
data);
144 Widget wLine = lb.GetElementComponent(
id).GetRootWidget();
152 line.SetPreset(preset);
153 line.UpdateWidgets();
155 line.GetEventOnNameChanged().Insert(RenamePreset);
156 line.GetEventOnNameEditStart().Insert(OnNameEditStart);
157 line.GetEventOnLoad().Insert(LoadPreset);
158 line.GetEventOnOverride().Insert(OverridePreset);
159 line.GetEventOnDelete().Insert(DeletePreset);
160 line.GetEventOnFocus().Insert(OnLineFocus);
161 line.GetEventOnFocusLost().Insert(OnLineFocusLost);
162 line.GetEventOnButtonClick().Insert(OnLineButtonClick);
164 line.ShowWarning(!HasAllPresetAddons(line));
166 m_aPresetLines.Insert(line);
169 GetGame().GetCallqueue().Call(OnUsedPresetChanged,
SCR_AddonManager.GetInstance().GetPresetStorage().GetUsedPreset(),
"");
176 SCR_WorkshopAddonPreset preset = line.GetPreset();
180 array<ref SCR_WorkshopAddonPresetAddonMeta> addons = preset.GetAddons();
184 string guid = meta.GetGuid();
187 if (!item || !item.GetOffline())
196 protected bool CanCreatePreset(SCR_WorkshopAddonPreset preset)
206 protected bool IsPresetAddonsListEmpty(SCR_WorkshopAddonPreset preset)
208 if (preset.GetAddons().IsEmpty())
219 protected bool IsAddonsListEmpty(array<ref SCR_WorkshopItem> items)
232 protected bool IsNameValid(
string name)
242 bool spaceOnly =
true;
244 for (
int i = 0, len = name.Length(); i < len; i++)
263 protected void OnUsedPresetChanged(
string name)
267 preset.SetSelected(preset.GetName() == name);
273 protected bool IsNameUnique(SCR_WorkshopAddonPreset preset,
string name)
278 dlg.m_OnConfirm.Insert(Callback_OnConfirmOverride);
290 protected void CreateNewPreset()
294 if (addonsCount == 0)
296 SCR_WorkshopAddonPreset empty =
null;
297 if (!CanCreatePreset(empty))
305 int id = lb.AddItem(
"");
306 m_CreatedElement = lb.GetElementComponent(
id);
309 Widget wLine = lb.GetElementComponent(
id).GetRootWidget();
314 m_InteractivePreset =
null;
321 line.ShowModCount(addonsCount);
322 line.ShowWarning(
false);
325 line.ShowDefaultName();
326 line.StartEditName();
328 SetupLineCreationState(line);
330 InvokeEventOnRename(
false);
337 ClearLineCreationState(line);
339 SCR_WorkshopAddonPreset preset =
SCR_AddonManager.GetInstance().CreatePresetFromEnabledAddons(name);
342 if (!CanCreatePreset(preset))
345 if (!IsPresetAddonsListEmpty(preset))
348 if (!IsNameValid(name))
351 if (!IsNameUnique(preset, name))
356 UpdatePresetListbox();
358 InvokeEventOnRename(
true);
361 m_Widgets.m_ScrollPresetsComponent.SetFocusOnFirstItem();
367 UpdatePresetListbox();
368 ClearLineCreationState(line);
374 m_Widgets.m_ButonNewPresetComponent.SetEnabled(
false);
375 SetExistingLinesEnabled(
false);
377 line.GetEventOnNameChanged().Insert(Callback_OnNameNewPreset);
378 line.GetEventOnFocusLost().Insert(Callback_OnNameNewPreset);
379 line.GetEventOnNameEditLeave().Insert(Callback_OnNewPresetFocusLost);
385 m_Widgets.m_ButonNewPresetComponent.SetEnabled(
true);
386 SetExistingLinesEnabled(
true);
388 line.GetEventOnNameChanged().Remove(Callback_OnNameNewPreset);
389 line.GetEventOnFocusLost().Remove(Callback_OnNameNewPreset);
390 line.GetEventOnNameEditLeave().Remove(Callback_OnNewPresetFocusLost);
394 protected void SetExistingLinesEnabled(
bool enabled)
398 line.SetEnabled(enabled);
406 SCR_WorkshopAddonPreset preset = line.GetPreset();
410 array<ref SCR_WorkshopAddonPresetAddonMeta> addonsNotFound = {};
413 if (addonsNotFound.IsEmpty())
414 SCR_AddonManager.GetInstance().GetPresetStorage().SetUsedPreset(line.GetPreset().GetName());
421 SCR_WorkshopAddonPreset preset = line.GetPreset();
426 array<ref SCR_WorkshopItem> enabledAddons = addonMgr.SelectItemsBasic(addonMgr.GetOfflineAddons(),
EWorkshopItemQuery.ENABLED);
428 if (!IsAddonsListEmpty(enabledAddons))
433 dlg.m_OnConfirm.Insert(Callback_OnConfirmOverride);
439 string prevName =
"";
440 if (m_InteractivePreset)
441 prevName = m_InteractivePreset.GetName();
443 SCR_WorkshopAddonPreset preset =
SCR_AddonManager.GetInstance().CreatePresetFromEnabledAddons(dlg.m_Preset.GetName());
448 if (!m_sNameOverride.IsEmpty())
450 SCR_AddonManager.GetInstance().GetPresetStorage().DeletePreset(m_sNameOverride);
451 preset.SetName(m_sNameOverride);
453 m_sNameOverride =
"";
456 SCR_AddonManager.GetInstance().GetPresetStorage().SavePreset(preset, prevName);
459 UpdatePresetListbox();
466 SCR_WorkshopAddonPreset preset = line.GetPreset();
471 dlg.m_OnConfirm.Insert(Callback_OnConfirmDelete);
477 SCR_AddonManager.GetInstance().GetPresetStorage().DeletePreset(dlg.m_sPresetName);
480 UpdatePresetListbox();
483 protected string m_sNameOverride;
489 SCR_WorkshopAddonPreset preset = line.GetPreset();
493 if (!IsNameValid(name))
498 SCR_WorkshopAddonPreset presetCompare = storage.GetPreset(name);
500 m_sNameOverride =
"";
502 if (presetCompare && presetCompare != preset)
504 m_sNameOverride = name;
506 dlg.m_OnConfirm.Insert(Callback_OnConfirmOverride);
510 string prevName = preset.GetName();
511 preset.SetName(name);
513 storage.SavePreset(preset, prevName);
514 UpdatePresetListbox();
516 InvokeEventOnRename(
true);
526 m_InteractivePreset = line.GetPreset();
528 InvokeEventOnRename(
false);
538 m_InteractivePreset = line.GetPreset();
544 InvokeEventOnRename(
true);
552 m_InteractivePreset = line.GetPreset();
559 Widget focused =
GetGame().GetWorkspace().GetFocusedWidget();
571 protected void OnNewPresetFocus()
574 m_NavLoad.SetLabel(
"#AR-Workshop_CreateNewAddonPreset");
577 m_NavOverride.SetEnabled(
false);
580 m_NavDelete.SetEnabled(
false);
583 m_NavRename.SetEnabled(
false);
587 protected void OnNewPresetFocusLost()
590 m_NavLoad.SetLabel(
"#AR-PauseMenu_Load");
593 m_NavOverride.SetEnabled(
true);
596 m_NavDelete.SetEnabled(
true);
599 m_NavRename.SetEnabled(
true);
603 protected void OnRename(
bool done)
608 if (
GetGame().GetWorkspace().GetFocusedWidget() ==
m_Widgets.m_ButonNewPreset)
611 OnNewPresetFocusLost();
616 m_NavLoad.SetLabel(
"#AR-MainMenu_Rename");
619 m_NavOverride.SetEnabled(
false);
622 m_NavDelete.SetEnabled(
false);
625 m_NavRename.SetEnabled(
false);
634 protected void OnLoadButton()
641 LoadPreset(focusedLine);
645 protected void OnOverrideButton()
650 OverridePreset(focusedLine);
654 protected void OnRenameButton()
659 focusedLine.StartEditName();
663 protected void OnDeleteButton()
668 DeletePreset(focusedLine);