Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ContentBrowser_ScenarioLineComponent.c
Go to the documentation of this file.
1 /*
2 Component for a line in scenario browser.
3 */
5 {
7 
8  protected MissionWorkshopItem m_Mission;
9 
10  protected const string MOD_ICON = "modIcon";
11 
12  protected Widget m_wLineBackground;
13 
14  //------------------------------------------------------------------------------------------------
15  override void HandlerAttached(Widget w)
16  {
17  m_wRoot = w;
18  m_Widgets.Init(w);
19 
20  if (!GetGame().InPlayMode())
21  return;
22 
23  // Mouse interaction buttons
24  m_FavComponent = m_Widgets.m_FavouriteButtonComponent;
25 
26  m_aMouseButtons.Insert(m_FavComponent);
27  m_aMouseButtons.Insert(m_Widgets.m_PlayComponent);
28  m_aMouseButtons.Insert(m_Widgets.m_ContinueComponent);
29  m_aMouseButtons.Insert(m_Widgets.m_RestartComponent);
30  m_aMouseButtons.Insert(m_Widgets.m_HostComponent);
31  m_aMouseButtons.Insert(m_Widgets.m_FindServersComponent);
32 
33  m_aMouseButtonsError.Insert(m_Widgets.m_HostComponent);
34  m_aMouseButtonsError.Insert(m_Widgets.m_FindServersComponent);
35 
36  m_Widgets.m_PlayComponent.m_OnClicked.Insert(OnPlay);
37  m_Widgets.m_ContinueComponent.m_OnClicked.Insert(OnContinue);
38  m_Widgets.m_RestartComponent.m_OnClicked.Insert(OnRestart);
39  m_Widgets.m_HostComponent.m_OnClicked.Insert(OnHost);
40  m_Widgets.m_FindServersComponent.m_OnClicked.Insert(OnFindServers);
41 
42  SCR_ServicesStatusHelper.RefreshPing();
43  SCR_ServicesStatusHelper.GetOnCommStatusCheckFinished().Insert(OnCommStatusCheckFinished);
44 
45  m_wLineBackground = w.FindAnyWidget("LineBackground");
46 
47  super.HandlerAttached(w);
48  }
49 
50  //------------------------------------------------------------------------------------------------
51  override void HandlerDeattached(Widget w)
52  {
53  super.HandlerDeattached(w);
54  SCR_ServicesStatusHelper.GetOnCommStatusCheckFinished().Remove(OnCommStatusCheckFinished);
55  }
56 
57  //------------------------------------------------------------------------------------------------
58  override void UpdateModularButtons()
59  {
60  if (!m_Mission)
61  return;
62 
63  // Visibility
64  bool mp = SCR_ScenarioEntryHelper.IsMultiplayer(m_Mission);
65  bool canContinue = SCR_ScenarioEntryHelper.HasSave(m_Mission);
66  bool show = m_bMouseButtonsEnabled && m_bFocused && SCR_ScenarioEntryHelper.IsReady(m_Mission);
67 
68  m_Widgets.m_Play.SetVisible(show && !canContinue);
69  m_Widgets.m_Continue.SetVisible(show && canContinue);
70  m_Widgets.m_Restart.SetVisible(canContinue);
71 
72  m_Widgets.m_Host.SetVisible(show && !GetGame().IsPlatformGameConsole() && mp);
73 
74  m_Widgets.m_FindServers.SetVisible(show && mp);
75 
76  m_bIsInErrorState = SCR_ScenarioEntryHelper.IsInErrorState(m_Mission);
77  SCR_ScenarioEntryHelper.UpdateErrorMouseButtonsTooltip(m_CurrentTooltip, m_Mission);
78 
79  bool inError = SCR_ScenarioEntryHelper.IsModInErrorState(m_Mission);
80 
81  if (m_Widgets.m_SourceImageCommunity.IsVisible())
82  {
83  string icon = MOD_ICON;
84  Color color = Color.FromInt(UIColors.NEUTRAL_INFORMATION.PackToInt());
85 
86  if (inError)
87  {
88  icon = SCR_ScenarioEntryHelper.GetErrorTexture(m_Mission);
89  if (m_bFocused)
90  color = Color.FromInt(UIColors.WARNING.PackToInt());
91  else
92  color = Color.FromInt(UIColors.WARNING_DISABLED.PackToInt());
93  }
94 
95  m_Widgets.m_SourceImageCommunity.LoadImageFromSet(0, UIConstants.ICONS_IMAGE_SET, icon);
96  m_Widgets.m_SourceImageCommunity.SetIsColorInherited(!inError);
97  m_Widgets.m_SourceImageCommunity.SetColor(color);
98  }
99 
100  super.UpdateModularButtons();
101  }
102 
103  //------------------------------------------------------------------------------------------------
104  override bool SetFavorite(bool favorite)
105  {
106  if (!m_Mission || !super.SetFavorite(favorite))
107  return false;
108 
109  m_Mission.SetFavorite(favorite);
110  return true;
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  override void OnTooltipShow(SCR_ScriptedWidgetTooltip tooltipClass, Widget tooltipWidget, Widget hoverWidget, SCR_ScriptedWidgetTooltipPreset preset, string tag)
115  {
116  SCR_ScenarioEntryHelper.UpdateErrorMouseButtonsTooltip(tooltipClass, m_Mission);
117 
118  super.OnTooltipShow(tooltipClass, tooltipWidget, hoverWidget, preset, tag);
119  }
120 
121  //------------------------------------------------------------------------------------------------
122  protected void UpdateAllWidgets()
123  {
124  if (!m_Mission)
125  return;
126 
127  // Fav button
128  if (m_Mission)
129  SetFavorite(m_Mission.IsFavorite());
130 
132  m_Widgets.m_NameText.SetText(m_Mission.Name());
133 
135  /*
136  // Not supported yet - todo
137  */
138 
140  int playerCount = m_Mission.GetPlayerCount();
141  bool mp = SCR_ScenarioEntryHelper.IsMultiplayer(m_Mission);
142 
143  m_Widgets.m_SinglePlayerImage.SetVisible(!m_bMouseButtonsEnabled && !mp);
144  m_Widgets.m_MultiPlayerImage.SetVisible(!m_bMouseButtonsEnabled && mp);
145  m_Widgets.m_PlayerCountText.SetText(playerCount.ToString());
146 
148  int timeSinceLastPlayedSeconds = m_Mission.GetTimeSinceLastPlay();
149  string timeSinceLastPlayText;
150 
151  if (timeSinceLastPlayedSeconds > 0)
152  timeSinceLastPlayText = SCR_FormatHelper.GetTimeSinceEventImprecise(timeSinceLastPlayedSeconds);
153  else
154  timeSinceLastPlayText = "-";
155 
156  m_Widgets.m_LastPlayedText.SetText(timeSinceLastPlayText);
157 
159  WorkshopItem sourceAddon = m_Mission.GetOwner();
160  m_Widgets.m_SourceImageOfficial.SetVisible(sourceAddon == null);
161  m_Widgets.m_SourceImageCommunity.SetVisible(sourceAddon != null);
162  m_Widgets.m_SourceNameTextOfficial.SetVisible(sourceAddon == null);
163  m_Widgets.m_SourceNameTextCommunity.SetVisible(sourceAddon != null);
164  string sourceAddonText = string.Empty;
165  if (sourceAddon)
166  m_Widgets.m_SourceNameTextCommunity.SetText(sourceAddon.Name());
167  else
168  m_Widgets.m_SourceNameTextOfficial.SetText("#AR-Editor_Attribute_OverlayLogo_Reforger");
169 
171  UpdateModularButtons();
172  }
173 
174  //------------------------------------------------------------------------------------------------
175  protected void OnPlay()
176  {
177  if (m_OnMouseInteractionButtonClicked)
178  m_OnMouseInteractionButtonClicked.Invoke(SCR_ScenarioEntryHelper.BUTTON_PLAY);
179  }
180 
181  //------------------------------------------------------------------------------------------------
182  protected void OnContinue()
183  {
184  if (m_OnMouseInteractionButtonClicked)
185  m_OnMouseInteractionButtonClicked.Invoke(SCR_ScenarioEntryHelper.BUTTON_CONTINUE);
186  }
187 
188  //------------------------------------------------------------------------------------------------
189  protected void OnRestart()
190  {
191  if (m_OnMouseInteractionButtonClicked)
192  m_OnMouseInteractionButtonClicked.Invoke(SCR_ScenarioEntryHelper.BUTTON_RESTART);
193  }
194 
195  //------------------------------------------------------------------------------------------------
196  protected void OnHost()
197  {
198  if (m_bIsInErrorState)
199  return;
200 
201  if (m_OnMouseInteractionButtonClicked)
202  m_OnMouseInteractionButtonClicked.Invoke(SCR_ScenarioEntryHelper.BUTTON_HOST);
203  }
204 
205  //------------------------------------------------------------------------------------------------
206  protected void OnFindServers()
207  {
208  if (m_bIsInErrorState)
209  return;
210 
211  if (m_OnMouseInteractionButtonClicked)
212  m_OnMouseInteractionButtonClicked.Invoke(SCR_ScenarioEntryHelper.BUTTON_FIND_SERVERS);
213  }
214 
215  //------------------------------------------------------------------------------------------------
216  protected void OnCommStatusCheckFinished(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
217  {
218  UpdateModularButtons();
219  }
220 
221  //------------------------------------------------------------------------------------------------
223  void NotifyScenarioUpdate()
224  {
225  UpdateAllWidgets();
226  }
227 
228  //------------------------------------------------------------------------------------------------
229  void SetScenario(MissionWorkshopItem mission)
230  {
231  m_Mission = mission;
232 
233  UpdateAllWidgets();
234  }
235 
236  //------------------------------------------------------------------------------------------------
237  MissionWorkshopItem GetScenario()
238  {
239  return m_Mission;
240  }
241 
242  //------------------------------------------------------------------------------------------------
243  void ShowFavouriteButton(bool show)
244  {
245  m_Widgets.m_FavouriteButtonOverlay.SetVisible(show);
246  }
247 
248  //------------------------------------------------------------------------------------------------
249  void ShowName(bool show)
250  {
251  m_Widgets.m_NameText.SetVisible(show);
252  }
253 
254  //------------------------------------------------------------------------------------------------
255  void ShowPlayerCount(bool show)
256  {
257  m_Widgets.m_PlayerCount.SetVisible(show);
258  }
259 
260  //------------------------------------------------------------------------------------------------
261  void ShowLastPlayedText(bool show)
262  {
263  m_Widgets.m_LastPlayedTextSize.SetVisible(show);
264  }
265 
266  //------------------------------------------------------------------------------------------------
267  void ShowSource(bool show)
268  {
269  m_Widgets.m_Source.SetVisible(show);
270  }
271 
272  //------------------------------------------------------------------------------------------------
273  static SCR_ContentBrowser_ScenarioLineComponent FindComponent(Widget w)
274  {
276  }
277 }
SCR_ECommStatus
SCR_ECommStatus
This class may become obsolete on BackendAPI update.
Definition: SCR_ServicesStatusHelper.c:2
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_FormatHelper
Definition: SCR_FormatHelper.c:1
UIConstants
Definition: Constants.c:130
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
IsPlatformGameConsole
bool IsPlatformGameConsole()
Definition: game.c:1393
SCR_ContentBrowser_ScenarioLineComponent
Definition: SCR_ContentBrowser_ScenarioLineComponent.c:4
m_Widgets
ref SCR_VoNOverlay_ElementWidgets m_Widgets
Definition: SCR_VonDisplay.c:3
UIColors
Definition: Constants.c:16
SCR_ContentBrowser_ScenarioLineWidgets
Definition: SCR_ContentBrowser_ScenarioLineWidgets.c:4
SCR_ServicesStatusHelper
Definition: SCR_ServicesStatusHelper.c:15
SCR_ListMenuEntryComponent
Definition: SCR_ListMenuEntryComponent.c:9
SCR_ScriptedWidgetTooltip
Definition: SCR_ScriptedWidgetTooltip.c:15