Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AddonLineBaseComponent.c
Go to the documentation of this file.
1 
8 {
9  protected const string ICON_UPDATE = "update";
10  protected const string TOOLTIP_UPDATE = "#AR-Workshop_ButtonUpdate";
11  protected const string TOOLTIP_CANCEL_DOWNLOAD = "#AR-Workshop_ButtonCancelDownload";
12 
13  // Fields
14  protected ref SCR_AddonLineBaseWidgets m_Widgets = new SCR_AddonLineBaseWidgets();
15 
16  protected ref SCR_WorkshopItem m_Item;
17 
18  protected bool m_bCanUpdate = true;
19 
20  protected ref ScriptInvokerScriptedWidgetComponent m_OnEnableButton;
21  protected ref ScriptInvokerScriptedWidgetComponent m_OnDisableButton;
22  protected ref ScriptInvokerScriptedWidgetComponent m_OnFixButton;
23 
24  // Image effects
25  protected SCR_ButtonEffectColor m_UpdateButtonIconColor;
26 
27  // Error flags
28  protected SCR_EAddonLineErrorFlags m_eAddonLineErrorFlags;
29 
30  //----------------------------------------------------------------------------------------------
31  // Overrides
32  //----------------------------------------------------------------------------------------------
33  //----------------------------------------------------------------------------------------------
34  override void HandlerAttached(Widget w)
35  {
36  if (SCR_Global.IsEditMode())
37  return;
38 
39  m_Widgets.Init(w);
40 
41  // Setup
42  m_aMouseButtons.Insert(m_Widgets.m_MoveLeftButtonComponent0);
43  m_aMouseButtons.Insert(m_Widgets.m_MoveRightButtonComponent0);
44  m_aMouseButtons.Insert(m_Widgets.m_DeleteButtonComponent0);
45 
46  m_aMouseButtonsError.Insert(m_Widgets.m_MoveRightButtonComponent0);
47 
48  // Button callbacks
49  m_Widgets.m_DeleteButtonComponent0.m_OnClicked.Insert(OnDeleteButton);
50  m_Widgets.m_MoveRightButtonComponent0.m_OnClicked.Insert(OnEnableButton);
51  m_Widgets.m_MoveLeftButtonComponent0.m_OnClicked.Insert(OnDisableButton);
52 
53  // Fix update
54  m_Widgets.m_UpdateButtonComponent0.m_OnClicked.Insert(OnUpdateButton);
55  m_Widgets.m_FixButtonComponent0.m_OnClicked.Insert(OnFixButton);
56 
57  // Find button image effects
58  m_UpdateButtonIconColor = SCR_ButtonEffectColor.Cast(m_Widgets.m_UpdateButtonComponent0.FindEffect("IconColor"));
59 
60  // Setup tooltip callbacks
61  m_Widgets.m_UpdateButtonComponent0.m_OnMouseEnter.Insert(OnUpdateButtonMouseEnter);
62  m_Widgets.m_UpdateButtonComponent0.m_OnMouseLeave.Insert(OnUpdateButtonMouseLeave);
63 
64  m_Widgets.m_IncompatibleButtonComponent0.m_OnMouseEnter.Insert(OnIncompatibleButtonMouseEnter);
65  m_Widgets.m_IncompatibleButtonComponent0.m_OnMouseLeave.Insert(OnIncompatibleButtonMouseLeave);
66 
67  m_Widgets.m_MoveLeftButtonComponent0.m_OnMouseEnter.Insert(OnSideButtonMouseEnter);
68  m_Widgets.m_MoveLeftButtonComponent0.m_OnMouseLeave.Insert(OnSideButtonMouseLeave);
69  m_Widgets.m_MoveRightButtonComponent0.m_OnMouseEnter.Insert(OnSideButtonMouseEnter);
70  m_Widgets.m_MoveRightButtonComponent0.m_OnMouseLeave.Insert(OnSideButtonMouseLeave);
71 
72  super.HandlerAttached(w);
73  }
74 
75  //------------------------------------------------------------------------------------------------
76  override bool OnFocus(Widget w, int x, int y)
77  {
78  bool result = super.OnFocus(w, x, y);
79  UpdateIssueState();
80  UpdateAllWidgets();
81 
82  return result;
83  }
84 
85  //------------------------------------------------------------------------------------------------
86  override bool OnFocusLost(Widget w, int x, int y)
87  {
88  bool result = super.OnFocusLost(w, x, y);
89  UpdateIssueState();
90  UpdateAllWidgets();
91 
92  return result;
93  }
94 
95  //------------------------------------------------------------------------------------------------
96  override void OnTooltipShow(SCR_ScriptedWidgetTooltip tooltipClass, Widget tooltipWidget, Widget hoverWidget, SCR_ScriptedWidgetTooltipPreset preset, string tag)
97  {
98  super.OnTooltipShow(tooltipClass, tooltipWidget, hoverWidget, preset, tag);
99 
100  if (tag == "MissingDependencies")
101  tooltipClass.SetMessageColor(Color.FromInt(UIColors.WARNING.PackToInt()));
102  }
103 
104  //----------------------------------------------------------------------------------------------
105  // Protected
106  //----------------------------------------------------------------------------------------------
107  //----------------------------------------------------------------------------------------------
109  protected void UpdateAllWidgets()
110  {
111  if (!m_bCanUpdate || !m_Item)
112  return;
113 
114  // Update name
115  m_Widgets.m_wNameText.SetText(m_Item.GetName());
116 
117  // Update state text
118  string stateText;
119  bool downloading = m_Item.GetDownloadAction() || m_Item.GetDependencyCompositeAction();
120  bool problemCritical;
121  string problemDescription;
122 
123  if (downloading)
124  {
125  float progress = SCR_DownloadManager.GetItemDownloadActionsProgress(m_Item);
126  stateText = string.Format("%1%%", Math.Round(100.0*progress));
127  m_Widgets.m_wHorizontalState.SetVisible(true);
128  m_Widgets.m_wUpdateButton.SetVisible(false);
129  }
130  else
131  {
132  m_Widgets.m_wHorizontalState.SetVisible(false);
133  }
134 
135  m_Widgets.m_wStateText.SetText(stateText);
136 
137  m_Widgets.m_wUpdateButton.SetVisible(m_Item.GetHighestPriorityProblem() == EWorkshopItemProblem.UPDATE_AVAILABLE);
138  ShowCompatibilityState();
139 
140  // Delete Button
141  SCR_ERevisionAvailability availability = SCR_AddonManager.ItemAvailability(m_Item.Internal_GetWorkshopItem());
142 
143  m_Widgets.m_wDeleteButton.SetVisible(
144  !downloading &&
145  m_bFocused &&
146  availability != SCR_ERevisionAvailability.ERA_DOWNLOAD_NOT_FINISHED &&
147  GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.MOUSE
148  );
149 
150  // Dependencies Button
151  m_Widgets.m_wFixButton.SetVisible(RequiresDownloadingDependencies());
152  }
153 
154  //----------------------------------------------------------------------------------------------
155  protected void HandleEnableButtons(bool addonEnabled, bool forceHidden = false)
156  {
157  // Left Panel
158  m_Widgets.m_wLeftSeparator.SetVisible(!addonEnabled || forceHidden);
159  m_Widgets.m_wSizeMoveRight.SetVisible(!addonEnabled && !forceHidden);
160  m_Widgets.m_wMoveRightButton.SetVisible(!addonEnabled && m_bFocused && !forceHidden);
161 
162  // Right Panel
163  m_Widgets.m_wRightSeparator.SetVisible(addonEnabled || forceHidden);
164  m_Widgets.m_wSizeMoveLeft.SetVisible(addonEnabled || forceHidden);
165  m_Widgets.m_wMoveLeftButton.SetVisible(addonEnabled && m_bFocused && !forceHidden);
166  }
167 
168  //------------------------------------------------------------------------------------------------
171  protected void ShowCompatibilityState()
172  {
173  SCR_ERevisionAvailability availability = SCR_AddonManager.ItemAvailability(m_Item.Internal_GetWorkshopItem());
174 
175  // Incompatible
176  bool showIncompatibility = availability == SCR_ERevisionAvailability.ERA_OBSOLETE ||
177  availability == SCR_ERevisionAvailability.ERA_DELETED;
178 
179  m_Widgets.m_wIncompatibleButton.SetVisible(showIncompatibility);
180 
181  if (!showIncompatibility)
182  {
183  if (availability == SCR_ERevisionAvailability.ERA_DELETED)
184  {
185  m_Widgets.m_IncompatibleButtonComponent1.SetImage(SCR_WorkshopUiCommon.ICON_MOD_NOT_AVAILABLE_REMOVED);
186  }
187  else
188  {
189  string texture = SCR_WorkshopUiCommon.GetRevisionAvailabilityErrorTexture(m_Item.Internal_GetWorkshopItem());
190  if (!texture.IsEmpty())
191  m_Widgets.m_IncompatibleButtonComponent1.SetImage(texture);
192  }
193  }
194 
195  // Update
196  // Displaying button to update and fixing issues with download
197  bool showUpdate = availability == SCR_ERevisionAvailability.ERA_COMPATIBLE_UPDATE_AVAILABLE ||
198  availability == SCR_ERevisionAvailability.ERA_DOWNLOAD_NOT_FINISHED ||
199  availability == SCR_ERevisionAvailability.ERA_AVAILABLE && m_Item.GetHighestPriorityProblem() == EWorkshopItemProblem.UPDATE_AVAILABLE;
200 
201  m_Widgets.m_wUpdateButton.SetVisible(showUpdate);
202 
203  if (showUpdate)
204  {
205  string updateImage;
206  if (m_Item && m_Item.IsDownloadRunning())
207  updateImage = SCR_WorkshopUiCommon.GetRevisionAvailabilityErrorTexture(m_Item.Internal_GetWorkshopItem());
208 
209  // Compatible update available for incompatible local revision
210  if (availability != SCR_ERevisionAvailability.ERA_AVAILABLE && m_Item && m_Item.IsDownloadRunning())
211  m_UpdateButtonIconColor.m_cDefault = Color.FromInt(UIColors.WARNING_DISABLED.PackToInt());
212 
213  m_Widgets.m_UpdateButtonComponent0.InvokeAllEnabledEffects(true);
214 
215  if (updateImage.IsEmpty())
216  updateImage = ICON_UPDATE;
217 
218  m_Widgets.m_UpdateButtonComponent1.SetImage(updateImage);
219  }
220  }
221 
222  //------------------------------------------------------------------------------------------------
223  protected void UpdateIssueState()
224  {
225  SCR_ERevisionAvailability availability = SCR_AddonManager.ItemAvailability(m_Item.Internal_GetWorkshopItem());
226  bool downloadIssue = availability == SCR_ERevisionAvailability.ERA_DOWNLOAD_NOT_FINISHED;
227  bool issues = HasItemAnyIssue();
228 
229  m_bIsInErrorState = issues || downloadIssue;
230  m_bDisabled = m_bIsInErrorState;
231 
232  // Update flags
233  m_eAddonLineErrorFlags = 0;
234 
235  if (issues)
236  m_eAddonLineErrorFlags |= SCR_EAddonLineErrorFlags.ITEM_ISSUES;
237 
238  if (availability != SCR_ERevisionAvailability.ERA_AVAILABLE)
239  m_eAddonLineErrorFlags |= SCR_EAddonLineErrorFlags.REVISION_AVAILABILITY_ISSUE;
240 
241  if (RequiresDownloadingDependencies())
242  m_eAddonLineErrorFlags |= SCR_EAddonLineErrorFlags.MISSING_DEPENDENCIES;
243 
244  if (downloadIssue)
245  m_eAddonLineErrorFlags |= SCR_EAddonLineErrorFlags.DOWNLOAD_ISSUES;
246  }
247 
248  //----------------------------------------------------------------------------------------------
249  // Callbacks
250  //----------------------------------------------------------------------------------------------
251  //----------------------------------------------------------------------------------------------
252  protected void OnDeleteButton();
253  protected void OnActionButton();
254  protected void OnUpdateButton();
255 
256  //----------------------------------------------------------------------------------------------
257  protected void OnFixButton()
258  {
259  if (m_OnFixButton)
260  m_OnFixButton.Invoke(this);
261  }
262 
263  //----------------------------------------------------------------------------------------------
264  void OnOpenDetailsButton()
265  {
266  if (!m_Item)
267  return;
268 
269  ContentBrowserDetailsMenu.OpenForWorkshopItem(m_Item);
270  }
271 
272  //----------------------------------------------------------------------------------------------
273  void OnEnableButton()
274  {
275  if (!m_Item)
276  return;
277 
278  SCR_ERevisionAvailability availability = SCR_AddonManager.ItemAvailability(m_Item.Internal_GetWorkshopItem());
279  if (availability == SCR_ERevisionAvailability.ERA_DOWNLOAD_NOT_FINISHED || m_eAddonLineErrorFlags & SCR_EAddonLineErrorFlags.MISSING_DEPENDENCIES)
280  return;
281 
282  // Enable
283  if (m_OnEnableButton)
284  m_OnEnableButton.Invoke(this);
285 
286  HandleEnableButtons(true);
288  }
289 
290  //----------------------------------------------------------------------------------------------
291  void OnDisableButton()
292  {
293  if (!m_Item)
294  return;
295 
296  if (m_OnDisableButton)
297  m_OnDisableButton.Invoke(this);
298 
299  HandleEnableButtons(false);
301  }
302 
303  // --- Tooltips ---
304  // Update Button Tooltip
305  //------------------------------------------------------------------------------------------------
306  protected void OnUpdateButtonMouseEnter()
307  {
308  SCR_ScriptedWidgetTooltip.GetOnTooltipShow().Insert(OnUpdateTooltipooltipShow);
309  }
310 
311  //------------------------------------------------------------------------------------------------
312  protected void OnUpdateButtonMouseLeave()
313  {
314  SCR_ScriptedWidgetTooltip.GetOnTooltipShow().Remove(OnUpdateTooltipooltipShow);
315  }
316 
317  //------------------------------------------------------------------------------------------------
318  protected void OnUpdateTooltipooltipShow(SCR_ScriptedWidgetTooltip tooltipClass, Widget tooltipWidget, Widget hoverWidget, SCR_ScriptedWidgetTooltipPreset preset, string tag)
319  {
320  SCR_ERevisionAvailability availability = SCR_AddonManager.ItemAvailability(m_Item.Internal_GetWorkshopItem());
321  bool downloading = m_Item.GetDownloadAction() || m_Item.GetDependencyCompositeAction();
322  string message = TOOLTIP_UPDATE;
323  Color color = Color.FromInt(UIColors.NEUTRAL_INFORMATION.PackToInt());
324 
325  bool error = availability != SCR_ERevisionAvailability.ERA_UNKNOWN_AVAILABILITY &&
326  availability != SCR_ERevisionAvailability.ERA_AVAILABLE &&
327  availability != SCR_ERevisionAvailability.ERA_DOWNLOAD_NOT_FINISHED;
328 
329  if (downloading)
330  message = TOOLTIP_CANCEL_DOWNLOAD;
331 
332  else if (error)
333  {
334  message = SCR_WorkshopUiCommon.GetRevisionAvailabilityErrorMessage(availability);
335  color = Color.FromInt(UIColors.WARNING.PackToInt());
336  }
337 
338  tooltipClass.SetMessage(message);
339  tooltipClass.SetMessageColor(color);
340  }
341 
342  // Incompatible Button Tooltip
343  //------------------------------------------------------------------------------------------------
344  protected void OnIncompatibleButtonMouseEnter()
345  {
346  SCR_ScriptedWidgetTooltip.GetOnTooltipShow().Insert(OnIncompatibleTooltipooltipShow);
347  }
348 
349  //------------------------------------------------------------------------------------------------
350  protected void OnIncompatibleButtonMouseLeave()
351  {
352  SCR_ScriptedWidgetTooltip.GetOnTooltipShow().Remove(OnIncompatibleTooltipooltipShow);
353  }
354 
355  //------------------------------------------------------------------------------------------------
356  protected void OnIncompatibleTooltipooltipShow(SCR_ScriptedWidgetTooltip tooltipClass, Widget tooltipWidget, Widget hoverWidget, SCR_ScriptedWidgetTooltipPreset preset, string tag)
357  {
358  tooltipClass.SetMessageColor(Color.FromInt(UIColors.WARNING.PackToInt()));
359 
360  SCR_ERevisionAvailability availability = SCR_AddonManager.ItemAvailability(m_Item.Internal_GetWorkshopItem());
361 
362  tooltipClass.SetMessage(SCR_WorkshopUiCommon.GetRevisionAvailabilityErrorMessage(availability));
363  tooltipClass.SetMessageColor(Color.FromInt(UIColors.WARNING.PackToInt()));
364  }
365 
366  // Side Buttons Tooltip
367  //------------------------------------------------------------------------------------------------
368  protected void OnSideButtonMouseEnter()
369  {
370  SCR_ScriptedWidgetTooltip.GetOnTooltipShow().Insert(OnSideTooltipooltipShow);
371  }
372 
373  //------------------------------------------------------------------------------------------------
374  protected void OnSideButtonMouseLeave()
375  {
376  SCR_ScriptedWidgetTooltip.GetOnTooltipShow().Remove(OnSideTooltipooltipShow);
377  }
378 
379  //------------------------------------------------------------------------------------------------
380  protected void OnSideTooltipooltipShow(SCR_ScriptedWidgetTooltip tooltipClass, Widget tooltipWidget, Widget hoverWidget, SCR_ScriptedWidgetTooltipPreset preset, string tag)
381  {
382  if (m_bIsInErrorState && m_Item && !m_Item.GetEnabled())
383  tooltipClass.SetMessageColor(Color.FromInt(UIColors.WARNING.PackToInt()));
384  }
385 
386  //----------------------------------------------------------------------------------------------
387  // API
388  //----------------------------------------------------------------------------------------------
389  //----------------------------------------------------------------------------------------------
391  void Init(SCR_WorkshopItem item)
392  {
393  m_Item = item;
394 
395  UpdateIssueState();
396 
397  UpdateAllWidgets();
399  }
400 
401  //----------------------------------------------------------------------------------------------
402  SCR_WorkshopItem GetWorkshopItem()
403  {
404  return m_Item;
405  }
406 
407  //----------------------------------------------------------------------------------------------
408  void EnableUpdate(bool enable)
409  {
410  m_bCanUpdate = enable;
411  }
412 
413  //------------------------------------------------------------------------------------------------
414  bool HasItemAnyIssue()
415  {
416  EWorkshopItemProblem problem = m_Item.GetHighestPriorityProblem();
417 
418  bool hasIssue = (
419  problem == EWorkshopItemProblem.BROKEN ||
420  problem == EWorkshopItemProblem.DEPENDENCY_MISSING ||
421  problem == EWorkshopItemProblem.DEPENDENCY_OUTDATED
422  );
423 
424  return hasIssue;
425  }
426 
427  //------------------------------------------------------------------------------------------------
428  bool RequiresDownloadingDependencies()
429  {
430  if (!m_Item)
431  return false;
432 
433  array<ref SCR_WorkshopItem> dependencies = m_Item.GetLatestDependencies();
434 
435  if (!dependencies.IsEmpty())
436  dependencies = SCR_AddonManager.SelectItemsOr(dependencies, EWorkshopItemQuery.NOT_OFFLINE | EWorkshopItemQuery.UPDATE_AVAILABLE);
437 
438  return !dependencies.IsEmpty();
439  }
440 
441  //------------------------------------------------------------------------------------------------
442  SCR_EAddonLineErrorFlags GetErrorFlags()
443  {
444  return m_eAddonLineErrorFlags;
445  }
446 
447  //------------------------------------------------------------------------------------------------
448  ScriptInvokerScriptedWidgetComponent GetOnEnableButton()
449  {
450  if (!m_OnEnableButton)
451  m_OnEnableButton = new ScriptInvokerScriptedWidgetComponent();
452 
453  return m_OnEnableButton;
454  }
455 
456  //------------------------------------------------------------------------------------------------
457  ScriptInvokerScriptedWidgetComponent GetOnDisableButton()
458  {
459  if (!m_OnDisableButton)
460  m_OnDisableButton = new ScriptInvokerScriptedWidgetComponent();
461 
462  return m_OnDisableButton;
463  }
464 
465  //------------------------------------------------------------------------------------------------
466  ScriptInvokerScriptedWidgetComponent GetOnFixButton()
467  {
468  if (!m_OnFixButton)
469  m_OnFixButton = new ScriptInvokerScriptedWidgetComponent();
470 
471  return m_OnFixButton;
472  }
473 }
474 
475 //TODO: unify error states, there's no reason this should have it's custom handling compared to workshop tiles or othe reperesentations of mods
476 enum SCR_EAddonLineErrorFlags
477 {
478  MISSING_DEPENDENCIES = 1 << 0,
479  ITEM_ISSUES = 1 << 1,
481  DOWNLOAD_ISSUES = 1 << 3
482 }
SCR_AddonLineBaseComponent
Definition: SCR_AddonLineBaseComponent.c:7
EWorkshopItemProblem
EWorkshopItemProblem
Definition: SCR_WorkshopItem.c:11
SCR_ERevisionAvailability
SCR_ERevisionAvailability
Definition: SCR_AddonManager.c:1090
m_Item
NewsFeedItem m_Item
Definition: SCR_NewsSubMenu.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
UpdateModularButtons
override void UpdateModularButtons()
Definition: SCR_ServerBrowserEntryComponent.c:168
m_Widgets
ref SCR_VoNOverlay_ElementWidgets m_Widgets
Definition: SCR_VonDisplay.c:3
SCR_WorkshopItem
Definition: SCR_WorkshopItem.c:21
SCR_ButtonEffectColor
Effect which colorizes a widget with given name.
Definition: SCR_ButtonEffectColor.c:3
ContentBrowserDetailsMenu
Definition: ContentBrowserDetailsMenu.c:2
MISSING_DEPENDENCIES
SCR_AddonLineBaseComponent MISSING_DEPENDENCIES
UIColors
Definition: Constants.c:16
SCR_AddonLineBaseWidgets
Definition: SCR_AddonLineBaseWidgets.c:3
ITEM_ISSUES
SCR_AddonLineBaseComponent ITEM_ISSUES
SCR_ListMenuEntryComponent
Definition: SCR_ListMenuEntryComponent.c:9
SCR_Global
Definition: Functions.c:6
GetInputManager
protected InputManager GetInputManager()
Definition: SCR_BaseManualCameraComponent.c:65
SCR_AddonManager
Definition: SCR_AddonManager.c:72
SCR_WorkshopUiCommon
Definition: SCR_WorkshopUiCommon.c:5
SCR_ScriptedWidgetTooltip
Definition: SCR_ScriptedWidgetTooltip.c:15
SCR_DownloadManager
Definition: SCR_DownloadManager.c:20
ScriptInvokerScriptedWidgetComponent
ScriptInvokerBase< ScriptInvokerScriptedWidgetComponentMethod > ScriptInvokerScriptedWidgetComponent
Definition: SCR_ScriptedWidgetComponent.c:4
REVISION_AVAILABILITY_ISSUE
SCR_AddonLineBaseComponent REVISION_AVAILABILITY_ISSUE
EWorkshopItemQuery
EWorkshopItemQuery
Definition: SCR_AddonManager.c:34