8 [
Attribute(
"", UIWidgets.ResourceNamePicker,
desc:
"Image used as fallback for addon image",
params:
"edds")]
9 protected ResourceName m_sFallbackImage;
12 protected ref BackendImage m_BackendImage;
15 protected bool m_bIsWaitingForWidgetInit;
16 protected int m_iPreferredWidth;
19 protected int m_iScreenWidth;
24 protected void InvokeEventOnImageSelected()
26 if (Event_OnImageSelected)
41 void SetImage(BackendImage image)
43 bool showDefaultImage =
true;
46 if (image.GetScale(0))
47 showDefaultImage =
false;
54 #ifdef BACKEND_IMAGE_DEBUG
55 ShowDebugText(
"Image unavailable\nShowing default image");
62 CheckWidgetInitialized();
66 protected void CheckWidgetInitialized()
68 Widget wImageSize = GetImageSizeWidget();
71 #ifdef BACKEND_IMAGE_DEBUG
72 ShowDebugText(
"SCR_BackendImageComponent - IsWidgetReady() - no image size widget!");
78 float fWidth, fHeight;
79 wImageSize.GetScreenSize(fWidth, fHeight);
84 int preferredWidth = Math.Round(fWidth);
85 if (preferredWidth == 0)
87 #ifdef BACKEND_IMAGE_WIDGET_DEBUG
88 Debug.Error(
string.Format(
"SCR_BackendImageComponent - IsWidgetReady() - widget has no size: %1 | %2", m_wRoot,
m_wRoot.GetName()));
91 if (!m_bIsWaitingForWidgetInit)
93 ShowLoadingImage(
string.Empty);
94 GetGame().GetCallqueue().CallLater(CheckWidgetInitialized, 0,
true);
102 GetGame().GetCallqueue().Remove(CheckWidgetInitialized);
112 protected void SetImage_Internal()
114 BackendApi backend =
GetGame().GetBackendApi();
115 bool connected = backend.IsActive() && backend.IsAuthenticated();
119 ImageScale imageScale =
m_BackendImage.GetScale(m_iPreferredWidth);
124 if (m_DownloadImageCallback)
137 bool downloadStarted = imageScale.Download(m_DownloadImageCallback);
141 ImageScale localImageScale =
m_BackendImage.GetLocalScale(m_iPreferredWidth);
144 if (!localImageScale.Path().IsEmpty())
145 ShowLoadingImage(localImageScale.Path());
147 ShowLoadingImage(
string.Empty);
150 ShowLoadingImage(
string.Empty);
152 #ifdef BACKEND_IMAGE_DEBUG
153 ShowDebugText(
"Waiting");
159 string imagePath = imageScale.Path();
160 if (!imagePath.IsEmpty())
162 #ifdef BACKEND_IMAGE_DEBUG
163 string dbgtxt =
string.Format(
"Local Image: %1x%2", imageScale.Width(), imageScale.Height());
164 ShowDebugText(dbgtxt);
167 ShowImage(imagePath);
176 ImageScale localImageScale =
m_BackendImage.GetLocalScale(m_iPreferredWidth);
179 string imagePath = localImageScale.Path();
180 if (!imagePath.IsEmpty())
181 ShowImage(localImageScale.Path());
201 string imgPath =
callback.m_Scale.Path();
203 if (!imgPath.IsEmpty())
207 #ifdef BACKEND_IMAGE_DEBUG
208 string dbgtxt =
string.Format(
"Received %1x%2",
callback.m_Scale.Width(),
callback.m_Scale.Height());
209 ShowDebugText(dbgtxt);
220 protected void ShowLoadingImage(
string fallbackImage);
221 protected void ShowDefaultImage();
222 protected void ShowImage(
string imagePath);
223 protected Widget GetImageSizeWidget();
224 protected void ShowDebugText(
string txt);
235 [
Attribute(
"", UIWidgets.EditBox,
"Widget from which we will be reading size of image widget. It can be detached from image widget, since its reported size can be different when wrapped into a scale widget.")]
259 if (fallbackImage.IsEmpty())
289 if (imagePath.IsEmpty())
295 m_wImage.LoadImageTexture(0, imagePath,
false,
true);
318 super.HandlerAttached(w);
342 #ifdef BACKEND_IMAGE_DEBUG
358 string commotDebugData;
361 commotDebugData =
string.Format(
"Widget Screen Width: %1\nPrefered Width: %2\nScales in Backend:\n%3",
373 array<ImageScale> scales = {};
378 for (
int i = 0; i < scales.Count(); i++)
383 s =
string.Format(
"%1x%2 ", scales[i].Width(), scales[i].Height());