Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ScenarioEntryHelper.c
Go to the documentation of this file.
2 {
3  // Modular button effect tags
4  static const string EFFECT_ICON_COLOR = "IconColor";
5  static const string EFFECT_BACKGROUND_COLOR = "BackgroundColor";
6  static const string EFFECT_NAME_COLOR = "NameColor";
7  static const string EFFECT_WRAPPER_COLOR = "WrapperColor";
8 
9  //------------------------------------------------------------------------------------------------
10  static void UpdateMouseButtons(array<SCR_ModularButtonComponent> mouseButtons, array<SCR_ModularButtonComponent> errorMouseButtons, bool inErrorState, bool focused)
11  {
12  Color color = Color.FromInt(UIColors.IDLE_DISABLED.PackToInt());
13  SCR_ButtonEffectColor effect;
14 
15  // --- Mouse buttons color ---
16  if (focused)
17  color = Color.FromInt(UIColors.NEUTRAL_ACTIVE_STANDBY.PackToInt());
18 
19  foreach (SCR_ModularButtonComponent button : mouseButtons)
20  {
21  effect = SCR_ButtonEffectColor.Cast(button.FindEffect(EFFECT_ICON_COLOR));
22  if (!effect)
23  continue;
24 
25  effect.m_cDefault = color;
26  effect.m_cToggledOff = color;
27  button.InvokeAllEnabledEffects(false);
28  }
29 
30  // --- Mouse buttons with error state color ---
31  Color highlightedColor = Color.FromInt(UIColors.HIGHLIGHTED.PackToInt());
32  if (inErrorState)
33  {
34  color = Color.FromInt(UIColors.WARNING_DISABLED.PackToInt());
35  highlightedColor = Color.FromInt(UIColors.WARNING.PackToInt());
36  }
37 
38  foreach (SCR_ModularButtonComponent button : errorMouseButtons)
39  {
40  effect = SCR_ButtonEffectColor.Cast(button.FindEffect(EFFECT_ICON_COLOR));
41  if (effect)
42  {
43  effect.m_cDefault = color;
44  effect.m_cToggledOff = color;
45  effect.m_cHovered = highlightedColor;
46  effect.m_cActivatedHovered = highlightedColor;
47  effect.m_cFocusGained = highlightedColor;
48  }
49 
50  effect = SCR_ButtonEffectColor.Cast(button.FindEffect(EFFECT_BACKGROUND_COLOR));
51  if (effect)
52  {
53  effect.m_cHovered = highlightedColor;
54  effect.m_cActivatedHovered = highlightedColor;
55  effect.m_cFocusGained = highlightedColor;
56  }
57 
58  button.InvokeAllEnabledEffects(false);
59  }
60  }
61 }
62 
63 //------------------------------------------------------------------------------------------------
64 class SCR_ScenarioEntryHelper
65 {
66  // Short messages
67  static const string MESSAGE_CONNECTION_ISSUES = "#AR-CoreMenus_Tooltips_NoConnection";
68 
69  // Verbose messages
70  static const string MESSAGE_VERBOSE_CONNECTION_ISSUES = "AR-Workshop_WarningNoConnection";
71 
72  // Button names
73  static const string BUTTON_PLAY = "Play";
74  static const string BUTTON_CONTINUE = "Continue";
75  static const string BUTTON_RESTART = "Restart";
76  static const string BUTTON_HOST = "Host";
77  static const string BUTTON_FIND_SERVERS = "FindServers";
78  static const string BUTTON_FAVORITE = "Favorite";
79 
80  // Actions
81  static const string ACTION_DOUBLE_CLICK = "MenuSelectDouble";
82  static const string ACTION_RESTART = "MenuRestart";
83  static const string ACTION_FIND_SERVERS = "MenuJoin";
84  static const string ACTION_FAVORITE = "MenuFavourite";
85  static const string ACTION_HOST = "MenuHost";
86 
87  // --- Modular buttons ---
88  //------------------------------------------------------------------------------------------------
89  static void UpdateMouseButtons(array<SCR_ModularButtonComponent> mouseButtons, array<SCR_ModularButtonComponent> errorMouseButtons, MissionWorkshopItem mission, bool focused)
90  {
91  SCR_ListEntryHelper.UpdateMouseButtons(mouseButtons, errorMouseButtons, IsInErrorState(mission), focused);
92  }
93 
94  //------------------------------------------------------------------------------------------------
95  static void UpdateErrorMouseButtonsTooltip(SCR_ScriptedWidgetTooltip tooltip, MissionWorkshopItem mission)
96  {
97  if (!tooltip || (tooltip.GetTag() != BUTTON_HOST && tooltip.GetTag() != BUTTON_FIND_SERVERS))
98  return;
99 
100  if (!IsInErrorState(mission))
101  {
102  tooltip.ResetMessage();
103  tooltip.SetMessageColor(Color.FromInt(UIColors.NEUTRAL_INFORMATION.PackToInt()));
104  return;
105  }
106 
107  tooltip.SetMessage(GetErrorMessage(mission));
108  tooltip.SetMessageColor(Color.FromInt(UIColors.WARNING.PackToInt()));
109  }
110 
111  // --- Input buttons ---
112  //------------------------------------------------------------------------------------------------
113  static void UpdateInputButtons(MissionWorkshopItem mission, array<SCR_InputButtonComponent> buttons, bool visible = true)
114  {
115  visible = visible && IsReady(mission);
116 
117  bool mp;
118  bool canBeLoaded;
119 
120  if (visible)
121  {
122  mp = IsMultiplayer(mission);
123  canBeLoaded = HasSave(mission);
124  }
125 
126  foreach (SCR_InputButtonComponent button : buttons)
127  {
128  Widget w = button.GetRootWidget();
129  if (!w)
130  continue;
131 
132  switch (w.GetName())
133  {
134  case SCR_ConfigurableDialogUi.BUTTON_CONFIRM:
135  {
136  button.SetVisible(visible && !canBeLoaded, false);
137  break;
138  }
139 
140  case SCR_ScenarioEntryHelper.BUTTON_PLAY:
141  {
142  button.SetVisible(visible && !canBeLoaded, false);
143  break;
144  }
145 
146  case SCR_ScenarioEntryHelper.BUTTON_CONTINUE:
147  {
148  button.SetVisible(visible && canBeLoaded, false);
149  break;
150  }
151 
152  case SCR_ScenarioEntryHelper.BUTTON_RESTART:
153  {
154  button.SetVisible(visible && canBeLoaded, false);
155  break;
156  }
157 
158  case SCR_ScenarioEntryHelper.BUTTON_FIND_SERVERS:
159  {
160  button.SetVisible(visible && mp, false);
161  if (button.IsVisible())
162  UpdateInputButton(button, mission);
163 
164  break;
165  }
166 
167  case SCR_ScenarioEntryHelper.BUTTON_HOST:
168  {
169  button.SetVisible(visible && mp && !GetGame().IsPlatformGameConsole(), false);
170  if (button.IsVisible())
171  UpdateInputButton(button, mission);
172 
173  break;
174  }
175  }
176  }
177  }
178 
179  //------------------------------------------------------------------------------------------------
180  static void UpdateInputButton(SCR_InputButtonComponent button, MissionWorkshopItem mission, string service = SCR_ServicesStatusHelper.SERVICE_BI_BACKEND_MULTIPLAYER)
181  {
182  if (!button)
183  return;
184 
185  switch (GetErrorState(mission))
186  {
188  {
189  button.ResetTexture();
190  button.SetEnabled(true);
191  break;
192  }
193 
194  case SCR_EScenarioEntryErrorState.CONNECTION_ISSUES:
195  {
196  SCR_InputButtonComponent.SetConnectionButtonEnabled(button, service);
197  break;
198  }
199 
200  case SCR_EScenarioEntryErrorState.MOD_ISSUES:
201  {
202  SetInputButtonEnabled(button, mission);
203  break;
204  }
205  }
206  }
207 
208  //------------------------------------------------------------------------------------------------
209  static bool SetInputButtonEnabled(SCR_InputButtonComponent button, MissionWorkshopItem mission, bool animate = true)
210  {
211  if (!button)
212  return false;
213 
214  bool enabled = !IsInErrorState(mission);
215  button.SetEnabled(enabled, animate);
216 
217  if (enabled)
218  {
219  button.ResetTexture();
220  return true;
221  }
222 
223  string texture = GetErrorTexture(mission);
224  button.SetTexture(UIConstants.ICONS_IMAGE_SET, texture, Color.FromInt(UIColors.WARNING_DISABLED.PackToInt()));
225 
226  return true;
227  }
228 
229  // --- Getters ---
230  //------------------------------------------------------------------------------------------------
231  static SCR_EScenarioEntryErrorState GetErrorState(MissionWorkshopItem mission)
232  {
233  if (!mission)
234  return SCR_EScenarioEntryErrorState.MOD_ISSUES;
235 
236  WorkshopItem item = mission.GetOwner();
237 
238  // No item means it's an Arma Reforger default
239  if (!item)
240  {
241  if (!SCR_ServicesStatusHelper.AreMultiplayerServicesAvailable())
242  return SCR_EScenarioEntryErrorState.CONNECTION_ISSUES;
243  else
244  return SCR_EScenarioEntryErrorState.NONE;
245  }
246 
247  return GetErrorState(item);
248  }
249 
250  //------------------------------------------------------------------------------------------------
251  protected static SCR_EScenarioEntryErrorState GetErrorState(WorkshopItem item)
252  {
253  BackendApi backend = GetGame().GetBackendApi();
254  WorkshopApi workshop;
255  if (backend)
256  workshop = backend.GetWorkshop();
257 
258  SCR_ERevisionAvailability availability;
259  if (item)
260  availability = SCR_AddonManager.ItemAvailability(item);
261 
262  bool modIssue =
263  !item ||
264  !workshop ||
265  workshop.NeedScan() ||
266  (availability != SCR_ERevisionAvailability.ERA_AVAILABLE && availability != SCR_ERevisionAvailability.ERA_UNKNOWN_AVAILABILITY);
267 
268  if (modIssue)
269  return SCR_EScenarioEntryErrorState.MOD_ISSUES;
270 
271  if (!SCR_ServicesStatusHelper.AreMultiplayerServicesAvailable())
272  return SCR_EScenarioEntryErrorState.CONNECTION_ISSUES;
273 
274  return SCR_EScenarioEntryErrorState.NONE;
275  }
276 
277  //------------------------------------------------------------------------------------------------
278  static bool IsInErrorState(MissionWorkshopItem mission)
279  {
280  return IsInErrorState(GetErrorState(mission));
281  }
282 
283  //------------------------------------------------------------------------------------------------
284  static bool IsInErrorState(SCR_EScenarioEntryErrorState state)
285  {
286  return state != SCR_EScenarioEntryErrorState.NONE;
287  }
288 
289  //------------------------------------------------------------------------------------------------
290  static bool IsModInErrorState(MissionWorkshopItem mission)
291  {
292  return GetErrorState(mission) == SCR_EScenarioEntryErrorState.MOD_ISSUES;
293  }
294 
295  //------------------------------------------------------------------------------------------------
296  static bool HasSave(MissionWorkshopItem mission)
297  {
298  if (!mission)
299  return false;
300 
301  SCR_MissionHeader header = SCR_MissionHeader.Cast(MissionHeader.ReadMissionHeader(mission.Id()));
302  return header && GetGame().GetSaveManager().HasLatestSave(header);
303  }
304 
305  //------------------------------------------------------------------------------------------------
306  static bool IsMultiplayer(MissionWorkshopItem mission)
307  {
308  return mission && mission.GetPlayerCount() > 1;
309  }
310 
311  //------------------------------------------------------------------------------------------------
312  // Default scenarios don't have a owner workshop item, so they're always ready. For the others we need to check
313  static bool IsReady(MissionWorkshopItem mission)
314  {
315  if (!mission)
316  return false;
317 
318  if (mission.GetOwner())
319  return mission.GetOwner().IsReadyToRun();
320 
321  return true;
322  }
323 
324  //------------------------------------------------------------------------------------------------
325  static string GetErrorMessage(MissionWorkshopItem mission)
326  {
327  string output = string.Empty;
328 
329  switch (GetErrorState(mission))
330  {
331  case SCR_EScenarioEntryErrorState.CONNECTION_ISSUES:
332  {
333  if (SCR_ServicesStatusHelper.GetLastReceivedCommStatus() == SCR_ECommStatus.FINISHED)
334  output = UIConstants.MESSAGE_SERVICES_ISSUES;
335  else
336  output = UIConstants.MESSAGE_DISCONNECTION;
337 
338  break;
339  }
340 
341  case SCR_EScenarioEntryErrorState.MOD_ISSUES:
342  {
343  if (!mission || GetGame().GetBackendApi().GetWorkshop().NeedScan())
344  output = SCR_WorkshopUiCommon.MESSAGE_MOD_NOT_AVAILABLE;
345  else
346  output = SCR_WorkshopUiCommon.GetRevisionAvailabilityErrorMessage(mission.GetOwner());
347 
348  break;
349  }
350  }
351 
352  return output;
353  }
354 
355  //------------------------------------------------------------------------------------------------
356  static string GetErrorMessageVerbose(MissionWorkshopItem mission)
357  {
358  string output = string.Empty;
359 
360  switch (GetErrorState(mission))
361  {
362  case SCR_EScenarioEntryErrorState.CONNECTION_ISSUES:
363  {
364  if (SCR_ServicesStatusHelper.GetLastReceivedCommStatus() == SCR_ECommStatus.FINISHED)
365  output = UIConstants.MESSAGE_SERVICES_ISSUES;
366  else
367  output = UIConstants.MESSAGE_DISCONNECTION;
368 
369  break;
370  }
371 
372  case SCR_EScenarioEntryErrorState.MOD_ISSUES:
373  {
374  if (!mission || GetGame().GetBackendApi().GetWorkshop().NeedScan())
375  output = SCR_WorkshopUiCommon.MESSAGE_VERBOSE_MOD_NOT_AVAILABLE;
376  else
377  output = SCR_WorkshopUiCommon.GetRevisionAvailabilityErrorMessageVerbose(mission.GetOwner());
378 
379  break;
380  }
381  }
382 
383  return output;
384  }
385 
386  //------------------------------------------------------------------------------------------------
387  static string GetErrorTexture(MissionWorkshopItem mission)
388  {
389  string output = string.Empty;
390 
391  switch (GetErrorState(mission))
392  {
393  case SCR_EScenarioEntryErrorState.CONNECTION_ISSUES:
394  {
395  if (SCR_ServicesStatusHelper.GetLastReceivedCommStatus() == SCR_ECommStatus.FINISHED)
396  output = UIConstants.ICON_SERVICES_ISSUES;
397  else
398  output = UIConstants.ICON_DISCONNECTION;
399 
400  break;
401  }
402 
403  case SCR_EScenarioEntryErrorState.MOD_ISSUES:
404  {
405  if (!mission || GetGame().GetBackendApi().GetWorkshop().NeedScan())
406  output = SCR_WorkshopUiCommon.ICON_MOD_NOT_AVAILABLE;
407  else
408  output = SCR_WorkshopUiCommon.GetRevisionAvailabilityErrorTexture(mission.GetOwner());
409 
410  break;
411  }
412  }
413 
414  return output;
415  }
416 }
417 
418 //------------------------------------------------------------------------------------------------
420 {
421  NONE = 0, // No issues
422  CONNECTION_ISSUES, // Issues with internet or services
423  MOD_ISSUES // Issues with mod
424 }
SCR_ERevisionAvailability
SCR_ERevisionAvailability
Definition: SCR_AddonManager.c:1090
SCR_ECommStatus
SCR_ECommStatus
This class may become obsolete on BackendAPI update.
Definition: SCR_ServicesStatusHelper.c:2
UIConstants
Definition: Constants.c:130
CONNECTION_ISSUES
@ CONNECTION_ISSUES
Definition: SCR_ScenarioEntryHelper.c:422
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
MissionHeader
Definition: MissionHeader.c:32
MESSAGE_CONNECTION_ISSUES
class SCR_ListEntryHelper MESSAGE_CONNECTION_ISSUES
IsPlatformGameConsole
bool IsPlatformGameConsole()
Definition: game.c:1393
SCR_ListEntryHelper
Definition: SCR_ScenarioEntryHelper.c:1
SCR_ButtonEffectColor
Effect which colorizes a widget with given name.
Definition: SCR_ButtonEffectColor.c:3
SCR_EScenarioEntryErrorState
SCR_EScenarioEntryErrorState
Definition: SCR_ScenarioEntryHelper.c:419
MOD_ISSUES
@ MOD_ISSUES
Definition: SCR_ScenarioEntryHelper.c:423
UIColors
Definition: Constants.c:16
SCR_ServicesStatusHelper
Definition: SCR_ServicesStatusHelper.c:15
NONE
@ NONE
Definition: SCR_ScenarioEntryHelper.c:421
SCR_ConfigurableDialogUi
Definition: SCR_ConfigurableDialogUI.c:13
SCR_AddonManager
Definition: SCR_AddonManager.c:72
SCR_WorkshopUiCommon
Definition: SCR_WorkshopUiCommon.c:5
SCR_ScriptedWidgetTooltip
Definition: SCR_ScriptedWidgetTooltip.c:15
SCR_MissionHeader
Definition: SCR_MissionHeader.c:1
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1