4 const string WIDGET_MOD_RATING =
"hRating";
5 const string WIDGET_MOD_SIZE =
"hDataSize";
8 protected TextWidget m_wTxtRating;
9 protected TextWidget m_wTxtDataSize;
13 ref ScriptInvoker m_OnModDonwloaded =
new ScriptInvoker();
14 ref Revision m_Version;
20 protected bool m_bHover =
false;
21 protected bool m_bFocus =
false;
24 const int STATE_DOWNLOAD = 0;
25 const int STATE_DOWNLOADING = 1;
26 const int STATE_CANCEL = 2;
27 const int STATE_DOWNLOADED = 3;
30 override void HandlerAttached(Widget w)
32 super.HandlerAttached(w);
35 Widget wRating = w.FindAnyWidget(WIDGET_MOD_RATING);
37 m_wTxtRating = TextWidget.Cast(wRating.FindAnyWidget(
"Text"));
39 Widget wSize = w.FindAnyWidget(WIDGET_MOD_SIZE);
41 m_wTxtDataSize = TextWidget.Cast(wSize.FindAnyWidget(
"Text"));
44 Widget btnDownloadWidget = w.FindAnyWidget(WIDGET_BTN_DOWNLOAD);
45 if (btnDownloadWidget)
50 m_BtnDownload.m_OnClicked.Insert(OnDownloadClick);
51 m_BtnDownload.m_OnHover.Insert(OnDownloadButtonHover);
52 m_BtnDownload.m_OnHoverLeave.Insert(OnDownloadButtonHoverLeave);
56 this.UpdateAllWidgets();
61 override void HandlerDeattached(Widget w)
67 override bool OnFocus(Widget w,
int x,
int y)
78 override bool OnFocusLost(Widget w,
int x,
int y)
80 super.OnFocusLost(w, x, y);
88 void UpdateAllWidgets()
95 if (
m_Item.GetRequestFailed())
97 SetLabelText(
"[Failed to load data]");
114 int rating =
m_Item.GetAverageRating() * 100;
115 SetModRating(rating.ToString() +
"%");
118 SetLabelText(
m_Item.GetName());
122 this.SetModDataSize(sizeStr);
125 this.UpdateDownloadButtonState();
138 void UpdateDownloadButtonState()
148 bool downloading =
false;
150 bool downloaded =
false;
151 Revision targetRevision;
152 float progress = -1.0;
155 item.GetDownloadState(downloading, paused, progress, targetRevision);
156 downloaded = item.GetOffline();
196 newState = STATE_DOWNLOADED;
202 newState = STATE_CANCEL;
204 newState = STATE_DOWNLOAD;
207 if (m_BtnDownload.GetSelectedItem() != newState)
209 m_BtnDownload.ChangeState(newState);
213 if (progress != -1.0 && downloading)
215 m_BtnDownload.StartProgress();
216 m_BtnDownload.SetProgress(progress * 100.0);
220 m_BtnDownload.FinishProgress();
224 m_BtnDownload.SetHintVisible(m_BtnDownload.GetSelectedItem() != STATE_DOWNLOADED &&
m_bFocus);
231 int state = m_BtnDownload.GetSelectedItem();
251 case STATE_DOWNLOADED:
255 this.UpdateDownloadButtonState();
265 m_Item.m_OnChanged.Insert(Callback_OnChanged);
267 this.UpdateAllWidgets();
271 void SetModRating(
string str) { SetTextSafe(m_wTxtRating, str); }
274 void SetModDataSize(
string str) { SetTextSafe(m_wTxtDataSize, str); }
277 void DownloadContent()
284 if (m_Version ==
null)
287 action =
m_Item.DownloadLatestVersion();
292 action =
m_Item.Download(m_Version);
298 protected void OnDownloadButtonHover()
304 protected void OnDownloadButtonHoverLeave()
311 protected void OnItemDownload()
313 Print(
"on item download");
314 this.UpdateDownloadButtonState();
320 m_BtnDownload.SetProgress(0);
321 UpdateDownloadButtonState();
328 bool IsUpdated(WorkshopItem item =
null)
330 return m_Item.GetOffline() && !
m_Item.GetUpdateAvailable();
334 bool IsDownloading(WorkshopItem item =
null)
351 Dependency GetDependency() {
return null; }
353 protected void Callback_OnChanged()