Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ModEntryComponent.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
3{
4 const string WIDGET_MOD_RATING = "hRating";
5 const string WIDGET_MOD_SIZE = "hDataSize";
6
7 // Widgets
10
11 // Mod handling
12 protected ref SCR_WorkshopItem m_Item; // Strong ref!
15
16 // Handling button
18
19 // Other
20 protected bool m_bHover = false;
21 protected bool m_bFocus = false;
22
23 // Constants
24 const int STATE_DOWNLOAD = 0;
25 const int STATE_DOWNLOADING = 1;
26 const int STATE_CANCEL = 2;
27 const int STATE_DOWNLOADED = 3;
28
29 //------------------------------------------------------------------------------------------------
30 override void HandlerAttached(Widget w)
31 {
32 super.HandlerAttached(w);
33
34 // Mini texts widgets
35 Widget wRating = w.FindAnyWidget(WIDGET_MOD_RATING);
36 if (wRating)
37 m_wTxtRating = TextWidget.Cast(wRating.FindAnyWidget("Text"));
38
39 Widget wSize = w.FindAnyWidget(WIDGET_MOD_SIZE);
40 if (wSize)
41 m_wTxtDataSize = TextWidget.Cast(wSize.FindAnyWidget("Text"));
42
43 // Handling setup
44 Widget btnDownloadWidget = w.FindAnyWidget(WIDGET_BTN_DOWNLOAD);
45 if (btnDownloadWidget)
46 {
48 if (m_BtnDownload)
49 {
50 m_BtnDownload.m_OnClicked.Insert(OnDownloadClick);
51 m_BtnDownload.m_OnHover.Insert(OnDownloadButtonHover);
52 m_BtnDownload.m_OnHoverLeave.Insert(OnDownloadButtonHoverLeave);
53 }
54 }
55
56 this.UpdateAllWidgets();
57 //GetGame().GetCallqueue().CallLater(UpdateEachFrame, 1);
58 }
59
60 //------------------------------------------------------------------------------------------------
61 override void HandlerDeattached(Widget w)
62 {
63 //GetGame().GetCallqueue().Remove(UpdateEachFrame);
64 }
65
66 //------------------------------------------------------------------------------------------------
67 override bool OnFocus(Widget w, int x, int y)
68 {
69 //super.OnFocus(w, x, y);
70 //m_OnFocus.Invoke(m_wRoot, m_Dependency);
71
72 //m_bFocus = true;
73
74 return false;
75 }
76
77 //------------------------------------------------------------------------------------------------
78 override bool OnFocusLost(Widget w, int x, int y)
79 {
80 super.OnFocusLost(w, x, y);
81
82 m_bFocus = false;
83
84 return true;
85 }
86
87 //------------------------------------------------------------------------------------------------
89 {
90 if (!m_Item)
91 return;
92
93 // Set data from the workshop item, if it's fetched
94
95 if (m_Item.GetRequestFailed())
96 {
97 SetLabelText("[Failed to load data]");
98 return;
99 }
100
101 // Texts and image
102 /*
103 SetDescriptionText(m_Item.GetSummary());
104 bool imageLoaded, backendHasImage;
105 ImageScale image;
106 m_Item.GetPreviewImage(imageLoaded, backendHasImage, image);
107 if (imageLoaded)
108 {
109 SetThumbnail(image.Path());
110 }
111 */
112
113 // Rating
114 int rating = m_Item.GetAverageRating() * 100;
115 SetModRating(rating.ToString() + "%");
116
117 // Set name
118 SetLabelText(m_Item.GetName());
119
120 // Size
121 string sizeStr = SCR_ByteFormat.GetReadableSize(m_Item.GetSizeBytes());
122 this.SetModDataSize(sizeStr);
123
124
126 }
127
128 //------------------------------------------------------------------------------------------------
129 /*
130 void UpdateEachFrame()
131 {
132 this.Update();
133 GetGame().GetCallqueue().CallLater(UpdateEachFrame, 1);
134 }
135 */
136
137 //------------------------------------------------------------------------------------------------
139 {
140 if (!m_Item)
141 {
142 return;
143 }
144
145 // Update the state of the main button
146
148 bool downloading = false;
149 bool paused = false;
150 bool downloaded = false;
151 Revision targetRevision;
152 float progress = -1.0;
153 int newState = -1;
154
155 item.GetDownloadState(downloading, paused, progress, targetRevision);
156 downloaded = item.GetOffline();
157
158 // Set state of the button
159 /*
160 if (m_bHover)
161 {
162 // Hovering the cursor
163 if (downloading)
164 newState = STATE_CANCEL;
165 else
166 {
167 if (!downloaded)
168 newState = STATE_DOWNLOAD;
169 else
170 newState = STATE_DOWNLOADED;
171 }
172 }
173 else
174 {
175
176 if (downloaded)
177 {
178 newState = STATE_DOWNLOADED;
179 }
180 else
181 {
182 // NOT hovering the cursor
183 if (downloading)
184 newState = STATE_DOWNLOADING;
185 else
186 newState = STATE_DOWNLOAD;
187 }
188 }
189 */
190
191
192
193 // On consoles we can't hover, so hovering is irrelevant
194 if (downloaded)
195 {
196 newState = STATE_DOWNLOADED;
197 }
198 else
199 {
200 // NOT hovering the cursor
201 if (downloading)
202 newState = STATE_CANCEL;
203 else
204 newState = STATE_DOWNLOAD;
205 }
206
207 if (m_BtnDownload.GetSelectedItem() != newState)
208 {
209 m_BtnDownload.ChangeState(newState);
210 }
211
212 // Set progress
213 if (progress != -1.0 && downloading)
214 {
215 m_BtnDownload.StartProgress();
216 m_BtnDownload.SetProgress(progress * 100.0);
217 }
218 else
219 {
220 m_BtnDownload.FinishProgress();
221 }
222
223 // Show or hide the hint
224 m_BtnDownload.SetHintVisible(m_BtnDownload.GetSelectedItem() != STATE_DOWNLOADED && m_bFocus);
225 }
226
227 //------------------------------------------------------------------------------------------------
230 {
231 int state = m_BtnDownload.GetSelectedItem();
232
233 switch (state)
234 {
235 // Ready to download
236 case STATE_DOWNLOAD:
238 break;
239
240 // Is downloading
242 m_Item.CancelDownload();
243 break;
244
245 // Is downloading and hovered
246 case STATE_CANCEL:
247 m_Item.CancelDownload();
248 break;
249
250 // Is up to date
251 case STATE_DOWNLOADED:
252 break;
253 }
254
256 }
257
258
259 //------------------------------------------------------------------------------------------------
260 void SetModContent(SCR_WorkshopItem item, string version)
261 {
262 m_Item = item;
263
264 if (item)
265 m_Item.m_OnChanged.Insert(Callback_OnChanged);
266
267 this.UpdateAllWidgets();
268 }
269
270 //------------------------------------------------------------------------------------------------
271 void SetModRating(string str) { SetTextSafe(m_wTxtRating, str); }
272
273 //------------------------------------------------------------------------------------------------
274 void SetModDataSize(string str) { SetTextSafe(m_wTxtDataSize, str); }
275
276 //------------------------------------------------------------------------------------------------
278 {
279 if (!m_Item)
280 return;
281
282 // Dowload
284 if (m_Version == null)
285 {
286 // No speficic version, just get the latest one
287 action = m_Item.DownloadLatestVersion();
288 }
289 else
290 {
291 // Download a specific version
292 action = m_Item.Download(m_Version);
293 }
294 action.Activate();
295 }
296
297 //------------------------------------------------------------------------------------------------
298 protected void OnDownloadButtonHover()
299 {
300 m_bHover = true;
301 }
302
303 //------------------------------------------------------------------------------------------------
305 {
306 m_bHover = false;
307 }
308
309 //------------------------------------------------------------------------------------------------
311 protected void OnItemDownload()
312 {
313 Print("on item download");
315 }
316
317 //------------------------------------------------------------------------------------------------
319 {
320 m_BtnDownload.SetProgress(0);
322 }
323
324 //------------------------------------------------------------------------------------------------
326
327 //------------------------------------------------------------------------------------------------
328 bool IsUpdated(WorkshopItem item = null)
329 {
330 return m_Item.GetOffline() && !m_Item.GetUpdateAvailable();
331 }
332
333 //------------------------------------------------------------------------------------------------
334 bool IsDownloading(WorkshopItem item = null)
335 {
336 /*
337 if (!item)
338 item = m_Dependency.GetCachedItem();
339 int flags = item.GetStateFlags();
340
341 if (flags & EWorkshopItemState.EWSTATE_DOWNLOADING)
342 {
343 return true;
344 }
345 */
346
347 return false;
348 }
349
350 // TODO remove this, server browser must be switched use SCR_WorkshopItem
351 Dependency GetDependency() { return null; }
352
353 protected void Callback_OnChanged()
354 {
356 }
357};
Base class for any button, regardless its own content.
Base component for widgets displaying content data.
void SetTextSafe(TextWidget txt, string str)
Just simple on line text setting.
void SetLabelText(string str)
void UpdateAllWidgets()
SCR_WorkshopItem GetWorkshopItem()
const int STATE_CANCEL
void OnItemDownload()
Call this on download addon dat.
const int STATE_DOWNLOADING
void DownloadContent()
override bool OnFocus(Widget w, int x, int y)
void UpdateDownloadButtonState()
bool m_bFocus
TextWidget m_wTxtDataSize
void SetModRating(string str)
override bool OnFocusLost(Widget w, int x, int y)
Dependency GetDependency()
void SetModDataSize(string str)
ref SCR_WorkshopItem m_Item
bool IsDownloading(WorkshopItem item=null)
ref Revision m_Version
override void HandlerAttached(Widget w)
bool m_bHover
bool IsUpdated(WorkshopItem item=null)
SCR_MultipleStatesButtonComponent m_BtnDownload
TextWidget m_wTxtRating
void OnDownloadClick(SCR_ButtonBaseComponent button)
Do this actions on using button on.
ref ScriptInvoker m_OnModDonwloaded
void OnDownloadButtonHover()
const int STATE_DOWNLOAD
void Callback_OnChanged()
override void HandlerDeattached(Widget w)
void SetModContent(SCR_WorkshopItem item, string version)
const int STATE_DOWNLOADED
void MarkAsUpdated()
void OnDownloadButtonHoverLeave()
bool GetOffline()
True when we have the item on our local storage.
void GetDownloadState(out bool inProgress, out bool paused, out float progress, out Revision targetRevision)
Returns state of the download process.
Workshop Item instance.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134