Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_WorkshopAddonBarComponent.c
Go to the documentation of this file.
2 {
3  protected ref SCR_WorkshopAddonBarWidgets m_Widgets = new SCR_WorkshopAddonBarWidgets();
4 
5  [Attribute("20", UIWidgets.EditBox, desc: "After how many character should be display preset name cut")]
6  protected int m_iPresetNameCap;
7 
8  protected static SCR_ConfigurableDialogUi m_FailDialog;
9 
10  protected ref SCR_AddonPatchSizeLoader m_Loader = new SCR_AddonPatchSizeLoader();
11  protected SCR_LoadingOverlayDialog m_LoadingOverlay;
12 
13  protected const int UPDATE_DELAY = 250;
14 
15  //------------------------------------------------------------------------------------------------
16  override void HandlerAttached(Widget w)
17  {
18  super.HandlerAttached(w);
19 
20  if (!GetGame().InPlayMode())
21  return;
22 
23  m_Widgets.Init(w);
24 
25  SCR_AddonManager mgr = SCR_AddonManager.GetInstance();
26  if (!mgr)
27  return;
28 
29  mgr.m_OnAddonsEnabledChanged.Insert(Callback_OnAddonsEnabledChanged);
30  mgr.GetPresetStorage().GetEventOnUsedPresetChanged().Insert(OnUsedPresetChanged);
31 
32  OnUsedPresetChanged(mgr.GetPresetStorage().GetUsedPreset());
33 
34  UpdateAllWidgets();
35 
36  m_Widgets.m_PresetsButtonComponent.GetButton().m_OnClicked.Insert(SCR_CommonDialogs.CreateModPresetsDialog);
37  m_Widgets.m_UpdateButtonComponent.GetButton().m_OnClicked.Insert(OnUpdateButtonClicked);
38 
39  HandleUpdatesButton();
40  GetGame().GetCallqueue().CallLater(HandleUpdatesButton, UPDATE_DELAY, true);
41 
42  SCR_MenuHelper.GetOnMenuOpen().Insert(OnMenuShow);
43  }
44 
45  //------------------------------------------------------------------------------------------------
46  override void HandlerDeattached(Widget w)
47  {
48  super.HandlerDeattached(w);
49 
50  SCR_AddonManager mgr = SCR_AddonManager.GetInstance();
51 
52  if (mgr)
53  SCR_AddonManager.GetInstance().m_OnAddonsEnabledChanged.Remove(Callback_OnAddonsEnabledChanged);
54 
55  if (m_LoadingOverlay)
56  m_LoadingOverlay.Close();
57 
58  GetGame().GetCallqueue().Remove(HandleUpdatesButton);
59 
60  SCR_MenuHelper.GetOnMenuOpen().Remove(OnMenuShow);
61  }
62 
63  //------------------------------------------------------------------------------------------------
64  protected void OnMenuShow(ChimeraMenuBase menu)
65  {
66  if (ChimeraMenuBase.GetOwnerMenu(m_wRoot) == menu)
67  HandleUpdatesButton();
68  }
69 
70  //------------------------------------------------------------------------------------------------
71  protected void Callback_OnAddonsEnabledChanged()
72  {
73  UpdateAllWidgets();
74  }
75 
76  //------------------------------------------------------------------------------------------------
78  protected void OnUsedPresetChanged(string name)
79  {
80  // Cap
81  if (!name.IsEmpty() && name.Length() > m_iPresetNameCap)
82  name = name.Substring(0, m_iPresetNameCap) + "...";
83 
84  m_Widgets.m_PresetsButtonComponent.SetLabelText(name);
85  }
86 
87  //------------------------------------------------------------------------------------------------
88  protected void UpdateAllWidgets()
89  {
90  SCR_AddonManager mgr = SCR_AddonManager.GetInstance();
91 
92  if (!mgr)
93  return;
94 
95  // Mod count text
96  int nAddonsEnabled = SCR_AddonManager.CountItemsBasic(SCR_AddonManager.GetInstance().GetOfflineAddons(), EWorkshopItemQuery.ENABLED);
97  m_Widgets.m_PresetsButtonComponent.SetCountText(nAddonsEnabled.ToString());
98  }
99 
100  //------------------------------------------------------------------------------------------------
101  protected void OnUpdateButtonClicked()
102  {
103  SCR_AddonManager mgr = SCR_AddonManager.GetInstance();
104  array<ref SCR_WorkshopItem> addonsOutdated = SCR_AddonManager.SelectItemsBasic(mgr.GetOfflineAddons(), EWorkshopItemQuery.UPDATE_AVAILABLE);
105 
106  // Load patch sizes for latest revision
107  m_Loader = new SCR_AddonPatchSizeLoader();
108 
109  foreach (SCR_WorkshopItem item : addonsOutdated)
110  {
111  Revision rev = item.GetLatestRevision();
112  item.SetItemTargetRevision(rev);
113  m_Loader.InsertItem(item);
114  }
115 
117 
118  m_Loader.GetOnAllPatchSizeLoaded().Insert(OnUpdatePatchSizeLoaded);
119  m_Loader.LoadPatchSizes();
120  }
121 
122  //------------------------------------------------------------------------------------------------
123  protected void OnUpdatePatchSizeLoaded(SCR_AddonPatchSizeLoader loader, bool allLoaded)
124  {
125  // Cleanup
126  m_Loader.GetOnAllPatchSizeLoaded().Remove(OnUpdatePatchSizeLoaded);
127  if (m_LoadingOverlay)
128  m_LoadingOverlay.Close();
129 
130  SCR_AddonManager mgr = SCR_AddonManager.GetInstance();
131  array<ref SCR_WorkshopItem> addonsOutdated = SCR_AddonManager.SelectItemsBasic(mgr.GetOfflineAddons(), EWorkshopItemQuery.UPDATE_AVAILABLE);
132 
133  // Open download confirmation dialog
134  array<ref Tuple2<SCR_WorkshopItem, ref Revision>> addonsAndVersions = {};
135  foreach (SCR_WorkshopItem item : addonsOutdated)
136  {
137  addonsAndVersions.Insert(new Tuple2<SCR_WorkshopItem, ref Revision>(item, item.GetLatestRevision()));
138 
139  }
140 
141  SCR_AddonUpdateConfirmationDialog dialog = SCR_AddonUpdateConfirmationDialog.CreateForUpdates(addonsAndVersions, false);
142  if (dialog)
143  dialog.m_OnClose.Insert(OnAddonUpdateDialogClose);
144  }
145 
146  //------------------------------------------------------------------------------------------------
147  protected void OnAddonUpdateDialogClose(SCR_ConfigurableDialogUi dialog)
148  {
149  HandleUpdatesButton();
150  }
151 
152  //------------------------------------------------------------------------------------------------
153  protected void HandleUpdatesButton()
154  {
155  if (!SCR_MenuHelper.IsInTopMenu(GetRootWidget()))
156  {
157  m_Widgets.m_UpdateButtonComponent.SetVisible(false);
158  return;
159  }
160 
161  SCR_AddonManager mgr = SCR_AddonManager.GetInstance();
162  array<ref SCR_WorkshopItem> addonsOutdated = SCR_AddonManager.SelectItemsBasic(mgr.GetOfflineAddons(), EWorkshopItemQuery.UPDATE_AVAILABLE);
163 
164  int nOutdated;
165 
166  foreach (SCR_WorkshopItem item : addonsOutdated)
167  {
168  if (!item.IsDownloadRunning())
169  nOutdated++;
170  }
171 
172  m_Widgets.m_UpdateButtonComponent.SetVisible(nOutdated > 0);
173 
174  if (nOutdated > 0)
175  m_Widgets.m_UpdateButtonComponent.SetCountText(nOutdated.ToString());
176  }
177 
178  //------------------------------------------------------------------------------------------------
179  protected void DisplayFailDialog()
180  {
181  // Check if dialog is not already opened
182  if (m_FailDialog)
183  return;
184 
185  array<ref Tuple2<SCR_WorkshopItem, ref Revision>> failed = {};
186  array<ref SCR_WorkshopItemActionDownload> failedActions = SCR_DownloadManager.GetInstance().GetFailedDownloads();
187 
188  foreach (SCR_WorkshopItemActionDownload action : failedActions)
189  {
190  SCR_WorkshopItem item = action.m_Wrapper;
191  Revision version = item.GetDependency().GetRevision();
192 
193  failed.Insert(new Tuple2<SCR_WorkshopItem, ref Revision>>(item, version));
194  }
195 
196  // Setup dialog
197  SCR_DownloadFailDialog dialog = SCR_DownloadFailDialog.CreateFailedAddonsDialog(failed, false);
198  if (!dialog)
199  return;
200 
201  m_FailDialog = dialog;
202  m_FailDialog.m_OnConfirm.Insert(Callback_OnFailDialogConfirm);
203  }
204 
205  //------------------------------------------------------------------------------------------------
206  protected void Callback_OnFailDialogConfirm(SCR_ConfigurableDialogUi dialog)
207  {
208  // Clear dialog
209  m_FailDialog.m_OnConfirm.Clear();
210  m_FailDialog.Close();
211  m_FailDialog = null;
212  SCR_DownloadManager.GetInstance().ClearFailedDownloads();
213  }
214 }
ChimeraMenuBase
Constant variables used in various menus.
Definition: ChimeraMenuBase.c:70
SCR_AddonPatchSizeLoader
Definition: SCR_AddonPatchSizeLoader.c:9
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_WorkshopAddonBarComponent
Definition: SCR_WorkshopAddonBarComponent.c:1
SCR_DownloadFailDialog
Definition: SCR_DownloadFailDialog.c:6
SCR_CommonDialogs
Definition: CommonDialogs.c:5
SCR_WorkshopItemActionDownload
Definition: SCR_WorkshopItemActionDownload.c:9
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_Widgets
ref SCR_VoNOverlay_ElementWidgets m_Widgets
Definition: SCR_VonDisplay.c:3
SCR_WorkshopItem
Definition: SCR_WorkshopItem.c:21
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
m_LoadingOverlay
protected SCR_LoadingOverlay m_LoadingOverlay
Definition: SCR_BackendImageComponent.c:250
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_LoadingOverlayDialog
Definition: SCR_LoadingOverlayDialog.c:5
SCR_MenuHelper
Definition: SCR_MenuHelper.c:15
SCR_WorkshopAddonBarWidgets
Definition: SCR_WorkshopAddonBarWidgets.c:1
SCR_ConfigurableDialogUi
Definition: SCR_ConfigurableDialogUI.c:13
SCR_AddonManager
Definition: SCR_AddonManager.c:72
SCR_AddonUpdateConfirmationDialog
Definition: SCR_AddonUpdateConfirmationDialog.c:9
SCR_ScriptedWidgetComponent
Definition: SCR_ScriptedWidgetComponent.c:7
SCR_DownloadManager
Definition: SCR_DownloadManager.c:20
EWorkshopItemQuery
EWorkshopItemQuery
Definition: SCR_AddonManager.c:34