7 [
Attribute(
"", UIWidgets.Auto,
"Names of tile widgets")]
8 protected ref array<string> m_aTileWidgetNames;
10 [
Attribute(
"", UIWidgets.Auto,
"See LoadImageTexture documentation")]
11 protected bool m_bFromLocalStorage;
14 protected ref array<Widget> m_aTiles = {};
15 protected ref array<SCR_BackendImageComponent> m_aTileComponents = {};
16 protected ref array<ref BackendImage> m_aImages = {};
20 protected int m_iCurrentItem = 0;
26 void SetImages(array<BackendImage> images)
30 int total = images.Count();
31 foreach (
int i, BackendImage img : images)
33 m_aImages.Insert(img);
34 m_Widgets.m_SpinBoxComponent.AddItem(
string.Empty, i == total - 1);
43 protected void Update()
46 Widget focusedWidget =
GetGame().GetWorkspace().GetFocusedWidget();
48 int tileId = m_aTiles.Find(focusedWidget);
51 int spinBoxItemId = m_iCurrentItem + tileId;
52 if (
m_Widgets.m_SpinBoxComponent.GetCurrentIndex() != spinBoxItemId)
53 m_Widgets.m_SpinBoxComponent.SetCurrentItem(spinBoxItemId);
57 int currentItem =
m_Widgets.m_SpinBoxComponent.GetCurrentIndex();
58 int spinBoxItemId = Math.ClampInt(currentItem, m_iCurrentItem, m_iCurrentItem + m_aTiles.Count() - 1);
59 if (
m_Widgets.m_SpinBoxComponent.GetCurrentIndex() != spinBoxItemId)
60 m_Widgets.m_SpinBoxComponent.SetCurrentItem(spinBoxItemId);
63 GetGame().GetCallqueue().CallLater(Update, 10);
66 protected void UpdateAllWidgets()
70 m_Widgets.m_NextButtonComponent.SetEnabled(m_iCurrentItem < (m_aImages.Count() - m_aTiles.Count()));
71 m_Widgets.m_PrevButtonComponent.SetEnabled(m_iCurrentItem > 0);
76 protected void UpdateTiles()
78 int nTiles = m_aTiles.Count();
79 int nImages = m_aImages.Count();
81 for (
int iTile = 0; iTile < nTiles; iTile++)
83 int iImage = m_iCurrentItem + iTile;
85 if (iImage < nImages && iImage >= 0)
86 ShowImageOnTile(iTile, m_aImages[iImage]);
88 ShowImageOnTile(iTile,
null);
97 protected void ShowImageOnTile(
int id, BackendImage backendImage)
105 Widget tile = m_aTiles[id];
106 ImageWidget wImage = ImageWidget.Cast(tile.FindAnyWidget(
"Image"));
109 wImage.SetVisible(backendImage !=
null);
110 tile.SetEnabled(backendImage !=
null);
112 comp.SetImage(backendImage);
117 protected void OffsetCurrentItem(
int offset)
119 m_iCurrentItem = m_iCurrentItem + offset;
120 int maxItemId = m_aImages.Count() - m_aTiles.Count();
123 m_iCurrentItem = Math.ClampInt(m_iCurrentItem, 0, maxItemId);
130 protected void OnTileClick(SCR_ModularButtonComponent comp)
133 if (m_aImages.IsEmpty())
137 int tileId = m_aTiles.Find(comp.GetRootWidget());
142 int imageId = m_iCurrentItem + tileId;
145 imageId = Math.Clamp(imageId, 0, m_aImages.Count() - 1);
147 array<BackendImage> galleryDialogImages = {};
148 foreach (
auto img : m_aImages)
149 galleryDialogImages.Insert(img);
162 protected void OnNextAction()
164 if (
GetGame().GetWorkspace().GetFocusedWidget() != m_aTiles[m_aTiles.Count()-1])
166 OffsetCurrentItem(1);
171 protected void OnPrevAction()
173 if (
GetGame().GetWorkspace().GetFocusedWidget() != m_aTiles[0])
175 OffsetCurrentItem(-1);
186 protected void OnNextButton()
188 OffsetCurrentItem(1);
189 GetGame().GetWorkspace().SetFocusedWidget(m_aTiles[m_aTiles.Count()-1]);
193 protected void OnPrevButton()
195 OffsetCurrentItem(-1);
196 GetGame().GetWorkspace().SetFocusedWidget(m_aTiles[0]);
204 override bool OnUpdate(Widget w)
207 GetGame().GetCallqueue().CallLater(UpdateSize, 0);
213 protected void UpdateSize()
215 if (m_aTiles.IsEmpty())
220 m_aTiles[0].GetScreenSize(sizex, sizey);
221 float sizexUnscaled =
GetGame().GetWorkspace().DPIUnscale(sizex);
222 m_Widgets.m_ImagesHeightSize.EnableHeightOverride(
true);
228 override void HandlerAttached(Widget w)
234 foreach (
string widgetName : m_aTileWidgetNames)
236 Widget wImageTile = w.FindAnyWidget(widgetName);
237 m_aTiles.Insert(wImageTile);
239 SCR_ModularButtonComponent comp = SCR_ModularButtonComponent.Cast(wImageTile.FindHandler(SCR_ModularButtonComponent));
240 comp.m_OnClicked.Insert(OnTileClick);
244 SCR_BackendImageComponent backendImgComp = SCR_BackendImageComponent.Cast(wImageTile.FindHandler(SCR_BackendImageComponent));
256 GetGame().GetInputManager().AddActionListener(
"MenuRight", EActionTrigger.DOWN, OnNextAction);
257 GetGame().GetInputManager().AddActionListener(
"MenuLeft", EActionTrigger.DOWN, OnPrevAction);
260 m_Widgets.m_NextButtonComponent.m_OnClicked.Insert(OnNextButton);
261 m_Widgets.m_PrevButtonComponent.m_OnClicked.Insert(OnPrevButton);
263 m_Widgets.m_SpinBoxComponent.SetCurrentItem(0);
267 GetGame().GetCallqueue().CallLater(Update, 50);
272 override void HandlerDeattached(Widget w)
276 GetGame().GetInputManager().RemoveActionListener(
"MenuRight", EActionTrigger.DOWN, OnNextAction);
277 GetGame().GetInputManager().RemoveActionListener(
"MenuLeft", EActionTrigger.DOWN, OnPrevAction);
280 GetGame().GetCallqueue().Remove(Update);