7 protected const string NAV_ENABLE =
"#AR-Workshop_ButtonEnable";
8 protected const string NAV_DISABLE =
"#AR-Workshop_ButtonDisable";
9 protected const string NAV_ENABLE_ALL =
"#AR-ServerHosting_EnableAll";
10 protected const string NAV_DISABLE_ALL =
"#AR-Workshop_DisableAll";
12 protected const string SORT_BTN_SORT_LABEL =
"#AR-Editor_TooltipDetail_WaypointIndex_Name";
13 protected const string SORT_BTN_SORT_ACTION =
"MenuFilter";
14 protected const string SORT_BTN_PLACE_LABEL =
"#AR-Button_Confirm-UC";
15 protected const string SORT_BTN_PLACE_ACTION =
"MenuSelect";
18 [
Attribute(
"", UIWidgets.ResourceNamePicker,
"Used layout for mod enabling",
"layout")]
19 protected ResourceName m_EntryLayout;
30 protected ScrollLayoutWidget m_wDisableScroll;
31 protected ScrollLayoutWidget m_wEnableScroll;
35 protected ref array<ref Widget> m_aEnabled = {};
36 protected ref array<ref Widget> m_aDisabled = {};
49 protected ref map<ref SCR_WorkshopItem, ref SCR_AddonLineDSConfigComponent> m_aEnabledMods =
new map<ref SCR_WorkshopItem, ref SCR_AddonLineDSConfigComponent>();
51 protected bool m_bIsListeningForCommStatus;
52 protected bool m_bIsSorting;
58 override void HandlerAttached(Widget w)
60 super.HandlerAttached(w);
65 m_wDisableScroll = ScrollLayoutWidget.Cast(
m_Widgets.m_wDisabledAddonsList.GetParent());
66 m_wEnableScroll = ScrollLayoutWidget.Cast(
m_Widgets.m_wEnabledAddonsList.GetParent());
72 m_Widgets.m_ButtonEnableAllComponent0.m_OnClicked.Insert(OnEnableAllClicked);
73 m_Widgets.m_ButtonEnableAllComponent0.m_OnClicked.Insert(OnDisableAllClicked);
76 m_Widgets.m_wDeleteAllEnabled.SetVisible(
false);
77 m_Widgets.m_wDeleteAllDisabled.SetVisible(
false);
81 SetupDownloadingCallbacks();
85 override void HandlerDeattached(Widget w)
87 super.HandlerDeattached(w);
88 ClearDownloadingCallbacks();
91 m_bIsListeningForCommStatus =
false;
95 override void OnTabCreate(Widget menuRoot, ResourceName buttonsLayout,
int index)
97 super.OnTabCreate(menuRoot, buttonsLayout,
index);
99 m_NavWorkshop = CreateNavigationButton(
"MenuDownloadManager",
"#AR-Workshop_WorkshopPageName",
false);
101 m_NavWorkshop.m_OnActivated.Insert(OnOpenWorkshopButton);
103 m_NavSelectSort = CreateNavigationButton(SORT_BTN_SORT_ACTION, SORT_BTN_SORT_LABEL,
true);
105 m_NavSelectSort.m_OnActivated.Insert(OnNavSelectSortActivate);
107 m_NavChangeSortOrder = CreateNavigationButton(
"MenuVertical", SORT_BTN_SORT_LABEL,
true);
108 if (m_NavChangeSortOrder)
109 FlagNavigationButtonVisibility(m_NavChangeSortOrder,
false);
111 m_NavEnableAll = CreateNavigationButton(
"MenuEnableAll", NAV_ENABLE_ALL,
true);
113 m_NavEnableAll.m_OnActivated.Insert(OnNavEnableAllActivated);
115 m_NavEnable = CreateNavigationButton(
"MenuEnable", NAV_ENABLE,
true);
117 m_NavEnable.m_OnActivated.Insert(OnNavEnableActivated);
119 ShowNavigationButtons(
false);
123 override void OnTabShow()
126 GetGame().GetCallqueue().Call(FocusFirstEntry);
130 if (!m_bIsListeningForCommStatus)
133 m_bIsListeningForCommStatus =
true;
134 UpdateWorkshopButton();
140 override void OnTabHide()
147 m_bIsListeningForCommStatus =
false;
151 protected void UpdateWorkshopButton()
160 protected void OnCommStatusCheckFinished(
SCR_ECommStatus status,
float responseTime,
float lastSuccessTime,
float lastFailTime)
162 UpdateWorkshopButton();
166 override void ShowNavigationButtons(
bool show)
168 super.ShowNavigationButtons(show && !m_aEnabledMods.IsEmpty());
175 protected void FocusFirstEntry()
177 if (!m_aDisabled.IsEmpty())
180 GetGame().GetWorkspace().SetFocusedWidget(m_aDisabled[0]);
184 if (!m_aEnabled.IsEmpty() && m_aEnabled[0])
185 GetGame().GetWorkspace().SetFocusedWidget(m_aEnabled[0]);
191 protected void CreateAddonList()
196 array<ref SCR_WorkshopItem> addons =
SCR_AddonManager.GetInstance().GetOfflineAddons();
198 for (
int i = 0, count = addons.Count(); i < count; i++)
203 AddLineEntry(addons[i], i);
211 Widget w =
GetGame().GetWorkspace().CreateWidgets(m_EntryLayout,
m_Widgets.m_wDisabledAddonsList);
219 line.GetOnEnableButton().Insert(OnAddonEnabled);
220 line.GetOnDisableButton().Insert(OnAddonDisabled);
221 line.GetOnSortConfirm().Insert(OnSortConfirm);
222 line.GetEventOnButtonUp().Insert(OnLineButtonUp);
223 line.GetEventOnButtonDown().Insert(OnLineButtonDown);
224 line.GetOnFocus().Insert(OnLineFocus);
225 line.GetOnFocusLost().Insert(OnLineFocusLost);
228 m_aDisabled.Insert(w);
232 m_aEnabledMods.Insert(item, line);
239 for (
int i = 0, count = m_aEnabledMods.Count(); i < count; i++)
241 if (m_aEnabledMods.GetElement(i) == line)
249 protected int LastFocusedId(Widget line,
bool enabled)
251 array<ref Widget> list = {};
259 if (list.Count() == 1)
262 return list.Find(line);
267 protected Widget ClosestAddonLine(
int lineId,
bool enabled)
269 array<ref Widget> list = {};
287 if (lineId < list.Count())
288 closestLine = list[lineId];
290 closestLine = list[lineId - 1];
297 void EnableModsFromDSConfig(notnull
SCR_DSConfig config)
299 array<ref DSMod> mods = config.game.mods;
300 array<ref SCR_WorkshopItem> items = {};
302 for (
int i = 0, count = mods.Count(); i < count; i++)
308 if (line.HasItemAnyIssue())
311 items.Insert(line.GetWorkshopItem());
315 EnableItems(
true, items);
321 for (
int i = 0, count = m_aEnabledMods.Count(); i < count; i++)
331 if (
id == item.GetId())
340 protected void SetupDownloadingCallbacks()
343 if (!downloadManager)
346 array<ref SCR_WorkshopItemActionDownload> actions = downloadManager.GetDownloadQueue();
348 for (
int i = 0, count = actions.Count(); i < count; i++)
350 actions[i].m_OnCompleted.Insert(OnDownloadComplete);
355 protected void ClearDownloadingCallbacks()
357 array<ref SCR_WorkshopItemActionDownload> actions = {};
364 for (
int i = 0, count = actions.Count(); i < count; i++)
366 actions[i].m_OnCompleted.Remove(OnDownloadComplete);
374 forceDisabled =
true;
376 bool enabled = line && line.GetWidgetEnabled();
380 bool issues = line && line.HasItemAnyIssue();
382 m_NavEnable.SetEnabled(!m_OrderedLine && !issues && !forceDisabled,
false);
397 m_NavEnableAll.SetEnabled(!m_OrderedLine && !forceDisabled,
false);
400 m_NavEnableAll.SetLabel(NAV_DISABLE_ALL);
402 m_NavEnableAll.SetLabel(NAV_ENABLE_ALL);
406 m_NavSelectSort.SetEnabled(!forceDisabled && enabled,
false);
410 item = line.GetWorkshopItem();
412 bool dependenciesRequired;
414 dependenciesRequired = item.GetAnyDependencyMissing() || item.GetAnyDependencyUpdateAvailable();
432 array<ref SCR_WorkshopItem> dependencies = item.GetLatestDependencies();
433 dependencies.Insert(item);
435 EnableItems(!line.GetWidgetEnabled(), dependencies);
450 array<ref SCR_WorkshopItem> dependent = item.GetDependentAddons();
453 dependent.Insert(item);
455 EnableItems(
false, dependent);
465 m_FocusedLine = line;
467 UpdateNavigationButtons(line);
473 m_FocusedLine =
null;
476 UpdateNavigationButtons(line,
true);
479 if (m_OrderedLine && m_OrderedLine != m_FocusedLine)
480 GetGame().GetCallqueue().Call(FocusLine, m_OrderedLine);
487 AddLineEntry(action.GetWorkshopItem(), m_aDisabled.Count());
488 action.m_OnCompleted.Remove(OnDownloadComplete);
493 protected void EnableItems(
bool enable, array<ref SCR_WorkshopItem> items)
504 Widget lineRoot = line.GetRootWidget();
507 if (enable && !line.GetWidgetEnabled())
510 m_Widgets.m_wEnabledAddonsList.AddChild(lineRoot);
511 m_aEnabled.Insert(lineRoot);
512 m_aDisabled.RemoveItem(lineRoot);
514 lineRoot.SetZOrder(m_aEnabled.Count() - 1);
516 else if (!enable && line.GetWidgetEnabled())
519 m_Widgets.m_wDisabledAddonsList.AddChild(lineRoot);
520 m_aDisabled.Insert(lineRoot);
521 m_aEnabled.RemoveItem(lineRoot);
523 lineRoot.SetZOrder(m_aDisabled.Count() - 1);
526 line.SetWidgetEnabled(enable);
530 for (
int i = 0, count = m_aDisabled.Count(); i < count; i++)
532 m_aDisabled[i].SetZOrder(i);
536 for (
int i = 0, count = m_aEnabled.Count(); i < count; i++)
538 m_aEnabled[i].SetZOrder(i);
542 lineCmp.SetOnBottom(i == m_aEnabled.Count() - 1);
547 if (!items.IsEmpty())
549 GetGame().GetCallqueue().Call(EnableItems, enable, items);
555 m_wDisableScroll.GetSliderPos(x, y);
558 m_wDisableScroll.SetSliderPos(0, 1,
true);
560 m_wEnableScroll.GetSliderPos(x, y);
563 m_wEnableScroll.SetSliderPos(0, 1,
true);
567 OnLineFocus(m_FocusedLine);
579 int id = line.GetRootWidget().GetZOrder();
581 if (
id == -1 ||
id == 0)
589 m_aEnabled[id] = m_aEnabled[
id-1];
590 m_aEnabled[id].SetZOrder(
id);
592 m_aEnabled[
id-1] = line.GetRootWidget();
593 m_aEnabled[
id-1].SetZOrder(
id-1);
596 if (
id == m_aEnabled.Count() - 1)
600 otherLine.SetOnBottom(
true);
603 line.SetOnBottom(
false);
614 int id = line.GetRootWidget().GetZOrder();
616 if (
id == -1 ||
id >= m_aEnabled.Count() - 1)
624 m_aEnabled[id] = m_aEnabled[
id+1];
625 m_aEnabled[id].SetZOrder(
id);
627 m_aEnabled[
id+1] = line.GetRootWidget();
628 m_aEnabled[
id+1].SetZOrder(
id+1);
633 otherLine.SetOnBottom(
false);
635 if (
id + 1 == m_aEnabled.Count() - 1)
636 line.SetOnBottom(
true);
648 protected void OnEnableAllClicked()
650 array<ref SCR_WorkshopItem> enable = {};
652 for (
int i = 0, count = m_aEnabledMods.Count(); i < count; i++)
659 if (!line.HasItemAnyIssue())
663 EnableItems(
true, enable);
667 protected void OnDisableAllClicked()
669 array<ref SCR_WorkshopItem> disable = {};
671 for (
int i = 0, count = m_aEnabledMods.Count(); i < count; i++)
673 disable.Insert(m_aEnabledMods.GetKey(i));
676 EnableItems(
false, disable);
680 protected void OnOpenWorkshopButton()
682 if (Event_OnWorkshopButtonActivate)
683 Event_OnWorkshopButtonActivate.Invoke();
692 bool enabled = m_FocusedLine.GetWidgetEnabled();
695 GetGame().GetCallqueue().Call(SetLineEnabled, enabled);
699 protected void SetLineEnabled(
bool enabled)
701 GetGame().GetCallqueue().Remove(SetLineEnabled);
704 m_FocusedLine.OnDisableButton();
706 m_FocusedLine.OnEnableButton();
710 protected void OnNavEnableAllActivated()
715 bool enabled = m_FocusedLine.GetWidgetEnabled();
718 OnDisableAllClicked();
720 OnEnableAllClicked();
744 if (!line || !line.GetWidgetEnabled())
747 m_OrderedLine = line;
749 m_OrderedLine.NotifySorting(
true);
751 GetGame().GetInputManager().AddActionListener(
"MenuDown", EActionTrigger.DOWN, OnDownSort);
752 GetGame().GetInputManager().AddActionListener(
"MenuUp", EActionTrigger.DOWN, OnUpSort);
754 if (m_NavChangeSortOrder)
755 SetNavigationButtonVisibile(m_NavChangeSortOrder,
true);
760 m_NavSelectSort.SetLabel(SORT_BTN_PLACE_LABEL);
761 m_NavSelectSort.SetAction(SORT_BTN_PLACE_ACTION);
768 SetNavigationButtonVisibile(m_NavEnableAll,
false);
771 m_Widgets.m_ButtonEnableAllComponent0.SetEnabled(
false);
772 m_Widgets.m_ButtonDisableAllComponent0.SetEnabled(
false);
778 protected void ReleaseSort()
783 m_OrderedLine.NotifySorting(
false);
784 m_OrderedLine =
null;
786 GetGame().GetInputManager().RemoveActionListener(
"MenuDown", EActionTrigger.DOWN, OnDownSort);
787 GetGame().GetInputManager().RemoveActionListener(
"MenuUp", EActionTrigger.DOWN, OnUpSort);
789 if (m_NavChangeSortOrder)
790 SetNavigationButtonVisibile(m_NavChangeSortOrder,
false);
795 m_NavSelectSort.SetLabel(SORT_BTN_SORT_LABEL);
796 m_NavSelectSort.SetAction(SORT_BTN_SORT_ACTION);
803 SetNavigationButtonVisibile(m_NavEnableAll,
true);
806 m_Widgets.m_ButtonEnableAllComponent0.SetEnabled(
true);
807 m_Widgets.m_ButtonDisableAllComponent0.SetEnabled(
true);
810 OnLineFocus(m_FocusedLine);
812 m_bIsSorting =
false;
816 protected void OnDownSort()
821 OnLineButtonDown(m_OrderedLine);
822 GetGame().GetCallqueue().Call(FocusLine, m_OrderedLine);
826 protected void OnUpSort()
831 OnLineButtonUp(m_OrderedLine);
832 GetGame().GetCallqueue().Call(FocusLine, m_OrderedLine);
838 GetGame().GetWorkspace().SetFocusedWidget(line.GetRootWidget());
846 array<ref DSMod> SelectedModsList()
848 array<ref DSMod> mods = {};
850 for (
int i = 0, count = m_aEnabled.Count(); i < count; i++)
857 if (line.GetWidgetEnabled())
863 DSMod mod =
new DSMod();
865 mod.modId = item.GetId();
866 mod.name = item.GetName();
867 mod.version = item.GetCurrentLocalRevision().GetVersion();
879 if (!Event_OnWorkshopButtonActivate)
882 return Event_OnWorkshopButtonActivate;