Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_ModEntryComponent.c
Go to the documentation of this file.
1
//------------------------------------------------------------------------------------------------
2
class
SCR_ModEntryComponent
:
SCR_ContentEntryComponent
3
{
4
const
string
WIDGET_MOD_RATING =
"hRating"
;
5
const
string
WIDGET_MOD_SIZE =
"hDataSize"
;
6
7
// Widgets
8
protected
TextWidget
m_wTxtRating
;
9
protected
TextWidget
m_wTxtDataSize
;
10
11
// Mod handling
12
protected
ref
SCR_WorkshopItem
m_Item
;
// Strong ref!
13
ref
ScriptInvoker
m_OnModDonwloaded
=
new
ScriptInvoker
();
14
ref
Revision
m_Version
;
15
16
// Handling button
17
protected
SCR_MultipleStatesButtonComponent
m_BtnDownload
;
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
{
47
m_BtnDownload
=
SCR_MultipleStatesButtonComponent
.Cast(btnDownloadWidget.FindHandler(
SCR_MultipleStatesButtonComponent
));
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
//------------------------------------------------------------------------------------------------
88
void
UpdateAllWidgets
()
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
125
this.
UpdateDownloadButtonState
();
126
}
127
128
//------------------------------------------------------------------------------------------------
129
/*
130
void UpdateEachFrame()
131
{
132
this.Update();
133
GetGame().GetCallqueue().CallLater(UpdateEachFrame, 1);
134
}
135
*/
136
137
//------------------------------------------------------------------------------------------------
138
void
UpdateDownloadButtonState
()
139
{
140
if
(!m_Item)
141
{
142
return
;
143
}
144
145
// Update the state of the main button
146
147
SCR_WorkshopItem
item =
m_Item
;
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
//------------------------------------------------------------------------------------------------
229
void
OnDownloadClick
(
SCR_ButtonBaseComponent
button)
230
{
231
int
state =
m_BtnDownload
.GetSelectedItem();
232
233
switch
(state)
234
{
235
// Ready to download
236
case
STATE_DOWNLOAD
:
237
DownloadContent
();
238
break
;
239
240
// Is downloading
241
case
STATE_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
255
this.
UpdateDownloadButtonState
();
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
//------------------------------------------------------------------------------------------------
277
void
DownloadContent
()
278
{
279
if
(!
m_Item
)
280
return
;
281
282
// Dowload
283
SCR_WorkshopItemActionDownload
action;
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
//------------------------------------------------------------------------------------------------
304
protected
void
OnDownloadButtonHoverLeave
()
305
{
306
m_bHover
=
false
;
307
}
308
309
//------------------------------------------------------------------------------------------------
311
protected
void
OnItemDownload
()
312
{
313
Print
(
"on item download"
);
314
this.
UpdateDownloadButtonState
();
315
}
316
317
//------------------------------------------------------------------------------------------------
318
void
MarkAsUpdated
()
319
{
320
m_BtnDownload.
SetProgress
(0);
321
UpdateDownloadButtonState
();
322
}
323
324
//------------------------------------------------------------------------------------------------
325
SCR_WorkshopItem
GetWorkshopItem
() {
return
m_Item
; }
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
{
355
UpdateAllWidgets
();
356
}
357
};
Dependency
Definition
Dependency.c:29
Revision
Definition
Revision.c:13
SCR_ButtonBaseComponent
Base class for any button, regardless its own content.
Definition
SCR_ButtonBaseComponent.c:7
SCR_ByteFormat
Definition
SCR_ByteFormat.c:6
SCR_ContentEntryComponent
Base component for widgets displaying content data.
Definition
SCR_ContentEntryComponent.c:6
SCR_ContentEntryComponent::SetTextSafe
void SetTextSafe(TextWidget txt, string str)
Just simple on line text setting.
Definition
SCR_ContentEntryComponent.c:31
SCR_ContentEntryComponent::SetLabelText
void SetLabelText(string str)
Definition
SCR_ContentEntryComponent.c:38
SCR_ModEntryComponent
Definition
SCR_ModEntryComponent.c:3
SCR_ModEntryComponent::UpdateAllWidgets
void UpdateAllWidgets()
Definition
SCR_ModEntryComponent.c:88
SCR_ModEntryComponent::GetWorkshopItem
SCR_WorkshopItem GetWorkshopItem()
Definition
SCR_ModEntryComponent.c:325
SCR_ModEntryComponent::STATE_CANCEL
const int STATE_CANCEL
Definition
SCR_ModEntryComponent.c:26
SCR_ModEntryComponent::OnItemDownload
void OnItemDownload()
Call this on download addon dat.
Definition
SCR_ModEntryComponent.c:311
SCR_ModEntryComponent::STATE_DOWNLOADING
const int STATE_DOWNLOADING
Definition
SCR_ModEntryComponent.c:25
SCR_ModEntryComponent::DownloadContent
void DownloadContent()
Definition
SCR_ModEntryComponent.c:277
SCR_ModEntryComponent::OnFocus
override bool OnFocus(Widget w, int x, int y)
Definition
SCR_ModEntryComponent.c:67
SCR_ModEntryComponent::UpdateDownloadButtonState
void UpdateDownloadButtonState()
Definition
SCR_ModEntryComponent.c:138
SCR_ModEntryComponent::m_bFocus
bool m_bFocus
Definition
SCR_ModEntryComponent.c:21
SCR_ModEntryComponent::m_wTxtDataSize
TextWidget m_wTxtDataSize
Definition
SCR_ModEntryComponent.c:9
SCR_ModEntryComponent::SetModRating
void SetModRating(string str)
Definition
SCR_ModEntryComponent.c:271
SCR_ModEntryComponent::OnFocusLost
override bool OnFocusLost(Widget w, int x, int y)
Definition
SCR_ModEntryComponent.c:78
SCR_ModEntryComponent::GetDependency
Dependency GetDependency()
Definition
SCR_ModEntryComponent.c:351
SCR_ModEntryComponent::SetModDataSize
void SetModDataSize(string str)
Definition
SCR_ModEntryComponent.c:274
SCR_ModEntryComponent::m_Item
ref SCR_WorkshopItem m_Item
Definition
SCR_ModEntryComponent.c:12
SCR_ModEntryComponent::IsDownloading
bool IsDownloading(WorkshopItem item=null)
Definition
SCR_ModEntryComponent.c:334
SCR_ModEntryComponent::m_Version
ref Revision m_Version
Definition
SCR_ModEntryComponent.c:14
SCR_ModEntryComponent::HandlerAttached
override void HandlerAttached(Widget w)
Definition
SCR_ModEntryComponent.c:30
SCR_ModEntryComponent::m_bHover
bool m_bHover
Definition
SCR_ModEntryComponent.c:20
SCR_ModEntryComponent::IsUpdated
bool IsUpdated(WorkshopItem item=null)
Definition
SCR_ModEntryComponent.c:328
SCR_ModEntryComponent::m_BtnDownload
SCR_MultipleStatesButtonComponent m_BtnDownload
Definition
SCR_ModEntryComponent.c:17
SCR_ModEntryComponent::m_wTxtRating
TextWidget m_wTxtRating
Definition
SCR_ModEntryComponent.c:8
SCR_ModEntryComponent::OnDownloadClick
void OnDownloadClick(SCR_ButtonBaseComponent button)
Do this actions on using button on.
Definition
SCR_ModEntryComponent.c:229
SCR_ModEntryComponent::m_OnModDonwloaded
ref ScriptInvoker m_OnModDonwloaded
Definition
SCR_ModEntryComponent.c:13
SCR_ModEntryComponent::OnDownloadButtonHover
void OnDownloadButtonHover()
Definition
SCR_ModEntryComponent.c:298
SCR_ModEntryComponent::STATE_DOWNLOAD
const int STATE_DOWNLOAD
Definition
SCR_ModEntryComponent.c:24
SCR_ModEntryComponent::Callback_OnChanged
void Callback_OnChanged()
Definition
SCR_ModEntryComponent.c:353
SCR_ModEntryComponent::HandlerDeattached
override void HandlerDeattached(Widget w)
Definition
SCR_ModEntryComponent.c:61
SCR_ModEntryComponent::SetModContent
void SetModContent(SCR_WorkshopItem item, string version)
Definition
SCR_ModEntryComponent.c:260
SCR_ModEntryComponent::STATE_DOWNLOADED
const int STATE_DOWNLOADED
Definition
SCR_ModEntryComponent.c:27
SCR_ModEntryComponent::MarkAsUpdated
void MarkAsUpdated()
Definition
SCR_ModEntryComponent.c:318
SCR_ModEntryComponent::OnDownloadButtonHoverLeave
void OnDownloadButtonHoverLeave()
Definition
SCR_ModEntryComponent.c:304
SCR_MultipleStatesButtonComponent
Definition
SCR_MultipleStatesButtonComponent.c:7
SCR_MultipleStatesButtonComponent::SetProgress
void SetProgress(int progress)
Definition
SCR_MultipleStatesButtonComponent.c:121
SCR_WorkshopItemActionDownload
Definition
SCR_WorkshopItemActionDownload.c:10
SCR_WorkshopItem
Definition
SCR_WorkshopItem.c:28
SCR_WorkshopItem::GetOffline
bool GetOffline()
True when we have the item on our local storage.
Definition
SCR_WorkshopItem.c:658
SCR_WorkshopItem::GetDownloadState
void GetDownloadState(out bool inProgress, out bool paused, out float progress, out Revision targetRevision)
Returns state of the download process.
Definition
SCR_WorkshopItem.c:798
TextWidget
Definition
TextWidget.c:16
Widget
Definition
Widget.c:13
WorkshopItem
Workshop Item instance.
Definition
WorkshopItem.c:14
Print
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
ScriptInvoker
ScriptInvokerBase< func > ScriptInvoker
Definition
tools.c:134
scripts
Game
UI
Menu
ContentBrowser
Deprecated
SCR_ModEntryComponent.c
Generated by
1.17.0