Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ContentBrowserDetails_GalleryComponent.c
Go to the documentation of this file.
1/*
2Component of a gallery in addon details menu.
3*/
4
6{
7 [Attribute("", UIWidgets.Auto, "Names of tile widgets")]
8 protected ref array<string> m_aTileWidgetNames;
9
10 // Array with image preview widgets
11 protected ref array<Widget> m_aTiles = {};
12 protected ref array<SCR_BackendImageComponent> m_aTileComponents = {};
13 protected ref array<BackendImage> m_aImages = {};
15
17
18 protected int m_iCurrentItem;
19 protected int m_iSelectedItem;
20
21 protected const int UPDATE_DELAY = 250;
22
23 //------------------------------------------------------------------------------------------
24 override void HandlerAttached(Widget w)
25 {
26 m_Widgets.Init(w);
27
28 // Find image gallery widgets
29 foreach (string widgetName : m_aTileWidgetNames)
30 {
31 Widget wImageTile = w.FindAnyWidget(widgetName);
32 if (!wImageTile)
33 continue;
34
35 m_aTiles.Insert(wImageTile);
36
37 SCR_ModularButtonComponent comp = SCR_ModularButtonComponent.FindComponent(wImageTile);
38 comp.m_OnClicked.Insert(OnTileClick);
39
40 SCR_BackendImageComponent backendImgComp = SCR_BackendImageComponent.Cast(wImageTile.FindHandler(SCR_BackendImageComponent));
41 m_aTileComponents.Insert(backendImgComp);
42 }
43
45 {
46 m_Widgets.m_SpinBoxComponent.ClearAll();
47
48 GetGame().GetInputManager().AddActionListener(UIConstants.MENU_ACTION_RIGHT, EActionTrigger.DOWN, OnNextAction);
49 GetGame().GetInputManager().AddActionListener(UIConstants.MENU_ACTION_LEFT, EActionTrigger.DOWN, OnPrevAction);
50 }
51
52 m_Widgets.m_NextButtonComponent.m_OnClicked.Insert(OnNextButton);
53 m_Widgets.m_PrevButtonComponent.m_OnClicked.Insert(OnPrevButton);
54
55 m_Widgets.m_SpinBoxComponent.SetCurrentItem(0);
56
58
59 GetGame().GetCallqueue().CallLater(Update, UPDATE_DELAY, true);
60 }
61
62 //------------------------------------------------------------------------------------------
63 override void HandlerDeattached(Widget w)
64 {
66 {
67 GetGame().GetInputManager().RemoveActionListener(UIConstants.MENU_ACTION_RIGHT, EActionTrigger.DOWN, OnNextAction);
68 GetGame().GetInputManager().RemoveActionListener(UIConstants.MENU_ACTION_LEFT, EActionTrigger.DOWN, OnPrevAction);
69 }
70
71 GetGame().GetCallqueue().Remove(Update);
72 }
73
74 // --- Public ---
75 //------------------------------------------------------------------------------------------
76 void SetImages(array<BackendImage> images)
77 {
78 m_Widgets.m_SpinBoxComponent.ClearAll();
79 m_aImages.Clear();
80 m_aImages = images;
81
82 int total = m_aImages.Count();
83 foreach (int i, BackendImage img : m_aImages)
84 {
85 m_Widgets.m_SpinBoxComponent.AddItem(string.Empty, i == total - 1);
86 }
87
89
92 }
93
94 // --- Protected ---
95 //------------------------------------------------------------------------------------------
96 protected void Update()
97 {
98 // Update current highlighted dot
99 int tileId = m_aTiles.Find(GetGame().GetWorkspace().GetFocusedWidget());
100 if (tileId != -1)
101 {
102 int spinBoxItemId = m_iCurrentItem + tileId;
103 if (m_Widgets.m_SpinBoxComponent.GetCurrentIndex() != spinBoxItemId)
104 m_Widgets.m_SpinBoxComponent.SetCurrentItem(spinBoxItemId);
105 }
106 else
107 {
108 int currentItem = m_Widgets.m_SpinBoxComponent.GetCurrentIndex();
109 int spinBoxItemId = Math.ClampInt(currentItem, m_iCurrentItem, m_iCurrentItem + m_aTiles.Count() - 1);
110 if (m_Widgets.m_SpinBoxComponent.GetCurrentIndex() != spinBoxItemId)
111 m_Widgets.m_SpinBoxComponent.SetCurrentItem(spinBoxItemId);
112 }
113 }
114
115 //------------------------------------------------------------------------------------------
116 protected void UpdateAllWidgets()
117 {
118 UpdateTiles();
119
120 m_Widgets.m_NextButtonComponent.SetEnabled(m_iCurrentItem < (m_aImages.Count() - m_aTiles.Count()));
121 m_Widgets.m_PrevButtonComponent.SetEnabled(m_iCurrentItem > 0);
122 }
123
124 //------------------------------------------------------------------------------------------
126 protected void UpdateTiles()
127 {
128 int iImage;
129 int nImages = m_aImages.Count();
130
131 foreach (int iTile, Widget tile : m_aTiles)
132 {
133 iImage = m_iCurrentItem + iTile;
134
135 if (iImage < nImages && iImage >= 0)
136 ShowImageOnTile(iTile, m_aImages[iImage]);
137 else
138 ShowImageOnTile(iTile, null);
139 }
140 }
141
142 //------------------------------------------------------------------------------------------
146 protected void ShowImageOnTile(int id, BackendImage backendImage)
147 {
149 if (!comp)
150 return;
151
152 Widget tile = m_aTiles[id];
153 ImageWidget wImage = ImageWidget.Cast(tile.FindAnyWidget("Image"));
154
155 // If we want to show no image, hide image widget, disable the tile so it can't be focused
156 wImage.SetVisible(backendImage != null);
157 tile.SetEnabled(backendImage != null);
158
159 comp.SetImage(backendImage);
160 }
161
162 //------------------------------------------------------------------------------------------
164 protected void OffsetCurrentItem(int offset)
165 {
167 int maxItemId = m_aImages.Count() - m_aTiles.Count();
168 if (maxItemId < 0)
169 maxItemId = 0;
170 m_iCurrentItem = Math.ClampInt(m_iCurrentItem, 0, maxItemId);
172 }
173
174 //------------------------------------------------------------------------------------------
176 protected void OnTileClick(SCR_ModularButtonComponent comp)
177 {
178 // Bail if we have no images at all
179 if (m_aImages.IsEmpty())
180 return;
181
182 // Find what image was selected in this tile
183 int tileId = m_aTiles.Find(comp.GetRootWidget());
184 if (tileId == -1)
185 return;
186
187 m_iSelectedItem = Math.Clamp(m_iCurrentItem + tileId, 0, m_aImages.Count() - 1);
189 }
190
191 //------------------------------------------------------------------------------------------
192 protected void OnNextAction()
193 {
194 if (GetGame().GetWorkspace().GetFocusedWidget() != m_aTiles[m_aTiles.Count()-1])
195 return;
196
198 }
199
200 //------------------------------------------------------------------------------------------
201 protected void OnPrevAction()
202 {
203 if (GetGame().GetWorkspace().GetFocusedWidget() != m_aTiles[0])
204 return;
205
207 }
208
209 //------------------------------------------------------------------------------------------
210 protected void OnNextButton()
211 {
213 GetGame().GetWorkspace().SetFocusedWidget(m_aTiles[m_aTiles.Count()-1]);
214 }
215
216 //------------------------------------------------------------------------------------------
217 protected void OnPrevButton()
218 {
220 GetGame().GetWorkspace().SetFocusedWidget(m_aTiles[0]);
221 }
222
223 //------------------------------------------------------------------------------------------
224 override bool OnUpdate(Widget w)
225 {
227 return super.OnUpdate(w);
228
229 if (w != m_wRoot)
230 return false;
231
232 GetGame().GetCallqueue().Call(UpdateSize);
233
234 return super.OnUpdate(w);
235 }
236
237 //------------------------------------------------------------------------------------------
238 protected void UpdateSize()
239 {
240 if (m_aTiles.IsEmpty())
241 return;
242
243 // Resize the height of all images, we must keep same aspect ratio
244 float sizex, sizey;
245 m_aTiles[0].GetScreenSize(sizex, sizey);
246 float sizexUnscaled = GetGame().GetWorkspace().DPIUnscale(sizex);
247 m_Widgets.m_ImagesHeightSize.EnableHeightOverride(true);
248 m_Widgets.m_ImagesHeightSize.SetHeightOverride(sizexUnscaled / SCR_WorkshopUiCommon.IMAGE_SIZE_RATIO);
249 }
250}
AddonBuildInfoTool id
ArmaReforgerScripted GetGame()
Definition game.c:1398
Definition Math.c:13
void SetImage(BackendImage image)
image can be null
static bool IsEditMode()
Definition Functions.c:1566
SCR_FieldOfViewSettings Attribute
EActionTrigger