Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AssetCardFrontUIComponent.c
Go to the documentation of this file.
1
2
5{
6 //ToDo: Replace many of these values with automated solutions
7 [Attribute()]
8 private string m_sEntityNameWidgetName;
9
10 //[Attribute()]
11 //private string m_sTitleBackgroundWidgetName;
12
13 [Attribute()]
14 private string m_sEnityImageWidgetName;
15
16 [Attribute()]
17 protected string m_sIconSlotWidgetName;
18
19 [Attribute("ModOverlay")]
20 protected string m_sModIndicatorWidgetName;
21
22 [Attribute("ModIndicatorIcon")]
23 protected string m_sModIndicatorIconName;
24
25 [Attribute("NoBudget")]
26 protected string m_sExceedBudgetLayoutName;
27
28 [Attribute("BudgetIcon")]
29 protected string m_sExceedBudgetIconName;
30
31 [Attribute("CompositionCost")]
32 protected string m_sBudgetCostLayoutName;
33
34 [Attribute("CostValue")]
35 protected string m_sBudgetCostTextName;
36
37 [Attribute("ImageOverlay")]
38 protected string m_sImageOverlayName;
39
40 [Attribute("AssetCardBackground")]
41 protected string m_sImageHoverName;
42
43 [Attribute("Image")]
44 protected string m_sImageName;
45
46 [Attribute("FullBackground")]
47 protected string m_sImageBackgroundName;
48
49 [Attribute("")]
50 protected string m_sAreaName;
51
52 [Attribute()]
53 protected bool m_bEnableHover;
54
55 [Attribute()]
56 protected ref array<string> m_aFactionColorNames;
57
58 [Attribute(uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(EEditableEntityLabelGroup))]
59 protected ref array<EEditableEntityLabelGroup> m_sTraitLabelGroups;
60
61 [Attribute()]
62 protected ref array<string> m_sTraitNames;
63
64 [Attribute()]
65 private ref Color m_DisabledColor;
66
67 [Attribute(params: "edds")]
68 protected ref array<ResourceName> m_ImageOverlayTextures;
69
70 [Attribute("", UIWidgets.EditBox, "Name of frame widget which holds Content meant for Horizontal scrolling")]
72
75
79
80 //Widgets
81 private Widget m_wWidget;
82 private Widget m_wAssetCardName //~ saved for hotfix below (todo ewe)
84
85 //Grid
86 protected int m_iPrefabIndex;
87
88 protected ref ScriptInvoker m_OnHover = new ScriptInvoker();
89 protected ref ScriptInvoker m_OnFocus = new ScriptInvoker();
90
91 //Info Ref
92 private ref SCR_UIInfo m_Info;
93
94 //Component Ref
95 private ref SCR_HorizontalScrollAnimationComponent m_HorizontalScrollComponent;
96
97 //------------------------------------------------------------------------------------------------
99 ScriptInvoker GetOnCardInit()
100 {
101 return Event_OnCardInit;
102 }
103
104 //------------------------------------------------------------------------------------------------
107 void UpdateBudgetCost(SCR_EntityBudgetValue entityBudgetCost = null)
108 {
111 return;
112
113 if (!entityBudgetCost)
114 m_BudgetCostLayout.SetVisible(false);
115 else
116 {
117 m_BudgetCostLayout.SetVisible(true);
118 TextWidget budgetCostTextWidget = TextWidget.Cast(m_BudgetCostLayout.FindAnyWidget(m_sBudgetCostTextName));
119 if (budgetCostTextWidget)
120 budgetCostTextWidget.SetText(entityBudgetCost.GetBudgetValue().ToString());
121 }
122 }
123
124 //------------------------------------------------------------------------------------------------
127 void UpdateBlockingBudget(SCR_UIInfo blockingBudgetInfo = null)
128 {
130 return;
131
132 bool canPlace = blockingBudgetInfo == null;
133
134 m_EntityImageWidget.SetSaturation(canPlace);
135 m_ExceedBudgetLayout.SetVisible(!canPlace);
136
137 ImageWidget exceedBudgetIcon = ImageWidget.Cast(m_ExceedBudgetLayout.FindWidget(m_sExceedBudgetIconName));
138 if (blockingBudgetInfo)
139 blockingBudgetInfo.SetIconTo(exceedBudgetIcon);
140 }
141
142 //------------------------------------------------------------------------------------------------
148 void InitCard(int prefabID, SCR_UIInfo info, ResourceName prefab, SCR_UIInfo blockingBudgetInfo = null, SCR_ContentBrowserEditorComponent contentBrowser = null)
149 {
150 if (!m_wWidget)
151 return;
152
153 m_iPrefabIndex = prefabID;
154
155 TextWidget entityNameWidget = TextWidget.Cast(m_wWidget.FindAnyWidget(m_sEntityNameWidgetName));
156 m_wBackground = ImageWidget.Cast(m_wWidget.FindAnyWidget(m_sImageBackgroundName));
157
158 if (info)
159 {
160 m_Info = info;
161 //Set the entity name
162 info.SetNameTo(entityNameWidget);
163
164 SCR_EditableEntityUIInfo infoCard = SCR_EditableEntityUIInfo.Cast(info);
165 if (infoCard)
166 {
167 SCR_EditableEntityUIInfoColored colorOverwriteInfo = SCR_EditableEntityUIInfoColored.Cast(infoCard);
168 Faction faction = infoCard.GetFaction();
169
170 if (!colorOverwriteInfo)
171 {
172 //--- Set faction color (all widgets marked by 'Inherit Color' will use it as well)
173 if (faction)
174 {
175 Widget factionColor;
176 Color color = Color.FromInt(faction.GetFactionColor().PackToInt());
177 foreach (string factionColorName: m_aFactionColorNames)
178 {
179 if (infoCard.IsFullBackgroundAssetCard() && factionColorName == "ColorOverlay")
180 continue;
181
182 factionColor = m_wWidget.FindAnyWidget(factionColorName);
183 if (factionColor)
184 factionColor.SetColor(color);
185 }
186 }
187 }
188 else
189 {
190 Widget colorOverlay = m_wWidget.FindAnyWidget("ColorOverlay");
191 if (colorOverlay)
192 colorOverlay.SetColor(colorOverwriteInfo.GetOverwriteColor());
193 }
194
195
196 //--- Set icon
197 Widget iconSlotWidget = m_wWidget.FindAnyWidget(m_sIconSlotWidgetName);
198 if (iconSlotWidget)
199 {
200 SCR_EditableEntityBaseSlotUIComponent iconSlot = SCR_EditableEntityBaseSlotUIComponent.Cast(iconSlotWidget.FindHandler(SCR_EditableEntityBaseSlotUIComponent));
201 if (iconSlot)
202 {
203 SCR_EditableEntityUIConfig entityUIConfig = SCR_EditableEntityUIConfig.GetConfig();
204 if (entityUIConfig)
205 {
206 array<ref SCR_EntitiesEditorUIRule> entityRules = entityUIConfig.GetRules();
207 foreach (SCR_EntitiesEditorUIRule rule: entityRules)
208 {
209 if (rule.GetStates() & EEditableEntityState.RENDERED)
210 {
211 iconSlot.CreateWidget(infoCard, rule);
212 }
213 }
214 }
215 }
216 }
217
218 //--- Set entity image
219 m_EntityImageWidget = ImageWidget.Cast(m_wWidget.FindAnyWidget(m_sEnityImageWidgetName));
221 infoCard.SetAssetImageTo(m_EntityImageWidget); // Also, depending on the entity flag, can set the background stretched, check function definition
222
223 ImageWidget imageOverlayWidget = ImageWidget.Cast(m_wWidget.FindAnyWidget(m_sImageOverlayName));
224 if (imageOverlayWidget && !m_ImageOverlayTextures.IsEmpty())
225 {
226 int textureIndex = m_iPrefabIndex % m_ImageOverlayTextures.Count();
227 imageOverlayWidget.LoadImageTexture(0, m_ImageOverlayTextures[textureIndex]);
228 m_EntityImageWidget = imageOverlayWidget;
229 }
230
231 m_ExceedBudgetLayout = m_wWidget.FindAnyWidget(m_sExceedBudgetLayoutName);
232
233 UpdateBudgetCost();
234 UpdateBlockingBudget(blockingBudgetInfo);
235
236 //--- Set faction flag
237 int traitIndex;
238 Widget traitWidget;
239 ImageWidget traitIcon;
240 if (faction)
241 {
242 if (!contentBrowser)
243 contentBrowser = SCR_ContentBrowserEditorComponent.Cast(SCR_ContentBrowserEditorComponent.GetInstance(SCR_ContentBrowserEditorComponent, false, true));
244
245 if (!contentBrowser || contentBrowser.AreFactionsShownOnContentCards())
246 {
247 if (FindTraitIcon(traitIndex, traitWidget, traitIcon))
248 {
249 traitWidget.SetVisible(true);
250 traitIcon.LoadImageTexture(0, faction.GetUIInfo().GetIconPath());
251 }
252 }
253 }
254
255 EEditorMode editorMode = 0;
256 SCR_EditorManagerEntity editorManager = SCR_EditorManagerEntity.GetInstance();
257 if (editorManager)
258 {
259 SCR_EditorModeEntity modeEntity = editorManager.GetCurrentModeEntity();
260 if (modeEntity)
261 editorMode = modeEntity.GetModeType();
262 }
263
264 //--- Find traits in labels
265 SCR_EditableEntityCore core = SCR_EditableEntityCore.Cast(SCR_EditableEntityCore.GetInstance(SCR_EditableEntityCore));
266 if (core)
267 {
268 EEditableEntityLabelGroup labelGroup;
269 array<EEditableEntityLabel> labels = {};
270 SCR_UIInfo labelInfo;
271 for (int i, count = infoCard.GetEntityLabels(labels); i < count; i++)
272 {
273 if (!core.GetLabelUIInfoIfValid(labels[i], editorMode, labelInfo))
274 continue;
275
276 if (core.GetLabelGroupType(labels[i], labelGroup) && m_sTraitLabelGroups.Contains(labelGroup) && labelInfo.HasIcon())
277 {
278 if (FindTraitIcon(traitIndex, traitWidget, traitIcon))
279 {
280 traitWidget.SetVisible(true);
281 labelInfo.SetIconTo(traitIcon);
282
283 SCR_LinkTooltipTargetEditorUIComponent tooltip = SCR_LinkTooltipTargetEditorUIComponent.Cast(traitWidget.FindHandler(SCR_LinkTooltipTargetEditorUIComponent));
284 if (tooltip)
285 tooltip.SetInfo(labelInfo);
286 }
287 else
288 {
289 //--- Out of trait icons
290 break;
291 }
292 }
293 }
294 }
295
296 //--- Show area image (only for systems)
297 if (m_sAreaName)
298 {
299 Widget areaWidget = m_wWidget.FindAnyWidget(m_sAreaName);
300 if (areaWidget)
301 areaWidget.SetVisible(infoCard.HasEntityFlag(EEditableEntityFlag.HAS_AREA));
302 }
303 }
304 }
305 else
306 {
307 if (entityNameWidget && prefab)
308 {
309 string path = prefab.GetPath();
310 array<string> pathNames = {};
311 path.Split("/", pathNames, true);
312 entityNameWidget.SetText(pathNames[pathNames.Count() - 1]);
313 }
314 }
315
316 //--- Hook up events for Asset name horizontal scrolling component
317 m_wAssetCardName = m_wWidget.FindAnyWidget(m_sAssetCardNameFrameWidget);
318
319 if (m_wAssetCardName)
320 {
321 m_HorizontalScrollComponent = SCR_HorizontalScrollAnimationComponent.Cast(m_wAssetCardName.FindHandler(SCR_HorizontalScrollAnimationComponent));
322 if (m_HorizontalScrollComponent)
323 {
324 // Focus is for controller "hover"
326 // Hover is for mouse hover
328
329 // Necessary otherwise animation starts playing on Init
330 m_HorizontalScrollComponent.AnimationStop();
331 m_HorizontalScrollComponent.ResetPosition();
332 }
333 }
334
335 //Check if asset is modded
336 Widget modIndicator = m_wWidget.FindAnyWidget(m_sModIndicatorWidgetName);
337 if (modIndicator)
338 {
339 array<string> modList = SCR_AddonTool.GetResourceAddons(prefab, true);
340 if (modList)
341 modIndicator.SetVisible(modList.Count() > 0);
342 else
343 modIndicator.SetVisible(false);
344
345 //~todo: Get Addon Icon. Use m_sModIndicatorIconName to get the ImageWidget
346 }
347
349 }
350
351 //------------------------------------------------------------------------------------------------
352 set<SCR_EditableEntityComponent> FactionRecipients()
353 {
354 Faction faction;
355
356 SCR_EditableEntityUIInfo infoCard = SCR_EditableEntityUIInfo.Cast(m_Info);
357 if (infoCard)
358 faction = infoCard.GetFaction();
359
360 if (!faction)
361 return null;
362
363 SCR_EditableFactionComponent factionDelegate;
364
365 SCR_DelegateFactionManagerComponent delegateFactionManager = SCR_DelegateFactionManagerComponent.GetInstance();
366 if (delegateFactionManager)
367 factionDelegate = delegateFactionManager.GetFactionDelegate(faction);
368
369 set<SCR_EditableEntityComponent> factionRecipients = new set<SCR_EditableEntityComponent>();
370 if (factionDelegate)
371 factionRecipients.Insert(factionDelegate);
372
373 return factionRecipients;
374 }
375
376 //------------------------------------------------------------------------------------------------
377 protected bool FindTraitIcon(out int outIndex, out Widget traitWidget, out ImageWidget traitIcon)
378 {
379 if (m_sTraitNames && outIndex < m_sTraitNames.Count())
380 {
381 traitWidget = m_wWidget.FindAnyWidget(m_sTraitNames[outIndex]);
382 if (traitWidget)
383 {
384 traitIcon = ImageWidget.Cast(traitWidget.FindAnyWidget("Trait"));
385 outIndex++;
386 return true;
387 }
388 }
389
390 outIndex = int.MAX;
391 return false;
392 }
393
394 //------------------------------------------------------------------------------------------------
395 protected void OnHoverScrollAnimation(Widget widget, int prefabIndex, bool hoverEntered)
396 {
397 //~todo ewe: known issue on Content browser Animation wont start cause frameWidth is always 0 on init
398 // Makes sure name text widget is up to date for ContentFit check
399 widget.Update();
400
401 // Hotfix for animation starting when content fits on Content Browser Init (related to todo above)
402 float width, height;
403
404 m_wAssetCardName.Update();
405 m_wAssetCardName.GetScreenSize(width, height);
406
407 // Checks if content does not fit before starting animation
408 if (hoverEntered && !m_HorizontalScrollComponent.GetContentFitX() && width > 0)
409 {
410 m_HorizontalScrollComponent.AnimationStart();
411 }
412 else if (!hoverEntered || m_HorizontalScrollComponent.GetContentFitX() || width <= 0)
413 {
414 m_HorizontalScrollComponent.AnimationStop();
415 m_HorizontalScrollComponent.ResetPosition();
416 }
417 }
418
419 //------------------------------------------------------------------------------------------------
423 {
424 return m_Info;
425 }
426
427 //------------------------------------------------------------------------------------------------
431 {
432 if (m_wBackground)
433 {
434 if (imageName.IsEmpty())
435 {
436 m_wBackground.SetVisible(false);
437 }
438 else
439 {
440 m_wBackground.LoadImageTexture(0, imageName);
441 m_wBackground.SetVisible(true);
442 }
443 }
444 }
445
446 //------------------------------------------------------------------------------------------------
450 {
452 {
453 if (imageName.IsEmpty())
454 {
455 m_wHoverImageWidget.SetVisible(false);
456 }
457 else
458 {
459 m_wHoverImageWidget.LoadImageTexture(0, imageName);
460 m_wHoverImageWidget.SetVisible(true);
461 }
462 }
463 }
464
465 //------------------------------------------------------------------------------------------------
468 void SetImage(ResourceName imageName)
469 {
471 {
472 if (imageName.IsEmpty())
473 {
474 m_EntityImageWidget.SetVisible(false);
475 }
476 else
477 {
478 m_EntityImageWidget.LoadImageTexture(0, imageName);
479 m_EntityImageWidget.SetVisible(true);
480 }
481 }
482 }
483
484 //------------------------------------------------------------------------------------------------
487 void SetText(string newText)
488 {
489 TextWidget entityNameWidget = TextWidget.Cast(m_wWidget.FindAnyWidget(m_sEntityNameWidgetName));
490 if (entityNameWidget)
491 {
492 if (newText.IsEmpty())
493 {
494 entityNameWidget.SetVisible(false);
495 }
496 else
497 {
498 entityNameWidget.SetVisible(true);
499 entityNameWidget.SetText(newText);
500 }
501 }
502 }
503
504 //------------------------------------------------------------------------------------------------
507 protected void SetHover(bool state)
508 {
509 if (!m_bEnableHover)
510 return;
511
513 AnimateWidget.Opacity(m_wHoverImageWidget, !state, UIConstants.FADE_RATE_DEFAULT);
514 }
515
516 //------------------------------------------------------------------------------------------------
519 protected void SetBackgroundColor(Color newColor, float transition = UIConstants.FADE_RATE_FAST)
520 {
521 if (m_wBackground)
522 AnimateWidget.Color(m_wBackground, newColor, transition);
523 }
524
525 //------------------------------------------------------------------------------------------------
528 protected void SetImageColor(Color newColor, float transition = UIConstants.FADE_RATE_FAST)
529 {
531 AnimateWidget.Color(m_EntityImageWidget, newColor, transition);
532 }
533
534 //------------------------------------------------------------------------------------------------
538 {
539 return m_wWidget;
540 }
541
542 //------------------------------------------------------------------------------------------------
543 override bool OnMouseEnter(Widget w, int x, int y)
544 {
545 if (m_wWidget)
546 m_OnHover.Invoke(m_wWidget, m_iPrefabIndex, true);
547
548 return false;
549 }
550
551 //------------------------------------------------------------------------------------------------
552 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
553 {
554 if (m_wWidget)
555 m_OnHover.Invoke(m_wWidget, m_iPrefabIndex, false);
556
557 return false;
558 }
559
560 //------------------------------------------------------------------------------------------------
564 {
565 return m_OnHover;
566 }
567
568 //------------------------------------------------------------------------------------------------
569 override bool OnFocus(Widget w, int x, int y)
570 {
571 //SetImageColor(UIColors.CONTRAST_CLICKED);
572 SetHover(true);
573
574 if (m_wWidget)
575 m_OnFocus.Invoke(m_wWidget, m_iPrefabIndex, true);
576
577 return false;
578 }
579
580 //------------------------------------------------------------------------------------------------
581 override bool OnFocusLost(Widget w, int x, int y)
582 {
583 //SetImageColor(Color.White);
584 SetHover(false);
585
586 if (m_wWidget)
587 m_OnFocus.Invoke(m_wWidget, m_iPrefabIndex, false);
588
589 return false;
590 }
591
592 //------------------------------------------------------------------------------------------------
596 {
597 return m_OnFocus;
598 }
599
600 //------------------------------------------------------------------------------------------------
603 {
604 return m_iPrefabIndex;
605 }
606
607 //------------------------------------------------------------------------------------------------
608 override void HandlerAttached(Widget w)
609 {
610 m_wWidget = w;
611
613 m_EntityImageWidget = ImageWidget.Cast(m_wWidget.FindAnyWidget(m_sImageName));
614
616 m_wHoverImageWidget = ImageWidget.Cast(m_wWidget.FindAnyWidget(m_sImageHoverName));
617
618 if (!m_wBackground)
619 m_wBackground = ImageWidget.Cast(m_wWidget.FindAnyWidget(m_sImageBackgroundName));
620
621 if (m_bEnableHover)
622 SetHover(false);
623 }
624
625 override void HandlerDeattached(Widget w)
626 {
627 if (m_HorizontalScrollComponent)
628 {
631 }
632 }
633}
string path
EEditableEntityLabelGroup
void SCR_EditorManagerEntity(IEntitySource src, IEntity parent)
Get all prefabs that have the spawner the given labels and are valid in the editor mode param catalogType Type to catalog to get prefabs from param editorMode Editor mode to get valid entries from param faction Faction(Optional)
Widget m_wWidget
static WidgetAnimationOpacity Opacity(Widget widget, float targetValue, float speed, bool toggleVisibility=false)
static WidgetAnimationColor Color(Widget widget, Color color, float speed)
Definition Color.c:13
override bool OnMouseEnter(Widget w, int x, int y)
void SetImageColor(Color newColor, float transition=UIConstants.FADE_RATE_FAST)
override bool OnFocus(Widget w, int x, int y)
void SetBackgroundImage(ResourceName imageName)
void SetHoverImage(ResourceName imageName)
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
void OnHoverScrollAnimation(Widget widget, int prefabIndex, bool hoverEntered)
void SetBackgroundColor(Color newColor, float transition=UIConstants.FADE_RATE_FAST)
bool FindTraitIcon(out int outIndex, out Widget traitWidget, out ImageWidget traitIcon)
ref array< EEditableEntityLabelGroup > m_sTraitLabelGroups
override bool OnFocusLost(Widget w, int x, int y)
ref array< ResourceName > m_ImageOverlayTextures
SCR_EditableFactionComponent GetFactionDelegate(Faction faction)
Widget CreateWidget(SCR_EditableEntityUIInfo info, SCR_EntitiesEditorUIRule rule)
array< ref SCR_EntitiesEditorUIRule > GetRules()
bool HasEntityFlag(EEditableEntityFlag flag)
int GetEntityLabels(out notnull array< EEditableEntityLabel > entityLabels)
bool SetAssetImageTo(ImageWidget imageWidget)
bool HasIcon()
Definition SCR_UIInfo.c:79
bool SetIconTo(ImageWidget imageWidget)
Definition SCR_UIInfo.c:102
EEditableEntityFlag
Unique flags of the entity.
EEditableEntityState
SCR_FieldOfViewSettings Attribute
EEditorMode
Editor mode that defines overall functionality.
Definition EEditorMode.c:6
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134