Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AssetCardFrontUIComponent.c
Go to the documentation of this file.
1 
4 class SCR_AssetCardFrontUIComponent : ScriptedWidgetComponent
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("")]
41  protected string m_sAreaName;
42 
43  [Attribute()]
44  protected ref array<string> m_aFactionColorNames;
45 
46  [Attribute(uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(EEditableEntityLabelGroup))]
47  protected ref array<EEditableEntityLabelGroup> m_sTraitLabelGroups;
48 
49  [Attribute()]
50  protected ref array<string> m_sTraitNames;
51 
52  [Attribute()]
53  private ref Color m_DisabledColor;
54 
55  [Attribute(params: "edds")]
56  protected ref array<ResourceName> m_ImageOverlayTextures;
57 
58  protected ref ImageWidget m_EntityImageWidget;
59 
60  protected Widget m_BudgetCostLayout;
61  protected Widget m_ExceedBudgetLayout;
62  protected ref ScriptInvoker Event_OnCardInit = new ScriptInvoker();
63 
64  //Widgets
65  private Widget m_wWidget;
66  //protected Widget m_Background;
67 
68  //Grid
69  protected int m_iPrefabIndex;
70 
71  protected ref ScriptInvoker m_OnHover = new ScriptInvoker();
72  protected ref ScriptInvoker m_OnFocus = new ScriptInvoker();
73 
74  //Info Ref
75  private ref SCR_UIInfo m_Info;
76 
77  //------------------------------------------------------------------------------------------------
79  ScriptInvoker GetOnCardInit()
80  {
81  return Event_OnCardInit;
82  }
83 
84  //------------------------------------------------------------------------------------------------
87  void UpdateBudgetCost(SCR_EntityBudgetValue entityBudgetCost = null)
88  {
89  m_BudgetCostLayout = m_wWidget.FindAnyWidget(m_sBudgetCostLayoutName);
90  if (!m_BudgetCostLayout)
91  return;
92 
93  if (!entityBudgetCost)
94  m_BudgetCostLayout.SetVisible(false);
95  else
96  {
97  m_BudgetCostLayout.SetVisible(true);
98  TextWidget budgetCostTextWidget = TextWidget.Cast(m_BudgetCostLayout.FindAnyWidget(m_sBudgetCostTextName));
99  if (budgetCostTextWidget)
100  budgetCostTextWidget.SetText(entityBudgetCost.GetBudgetValue().ToString());
101  }
102  }
103 
104  //------------------------------------------------------------------------------------------------
107  void UpdateBlockingBudget(SCR_UIInfo blockingBudgetInfo = null)
108  {
109  if (!m_ExceedBudgetLayout)
110  return;
111 
112  bool canPlace = blockingBudgetInfo == null;
113 
114  m_EntityImageWidget.SetSaturation(canPlace);
115  m_ExceedBudgetLayout.SetVisible(!canPlace);
116 
117  ImageWidget exceedBudgetIcon = ImageWidget.Cast(m_ExceedBudgetLayout.FindWidget(m_sExceedBudgetIconName));
118  if (blockingBudgetInfo)
119  blockingBudgetInfo.SetIconTo(exceedBudgetIcon);
120  }
121 
122  //------------------------------------------------------------------------------------------------
128  void InitCard(int prefabID, SCR_UIInfo info, ResourceName prefab, SCR_UIInfo blockingBudgetInfo = null)
129  {
130  if (!m_wWidget)
131  return;
132 
133  m_iPrefabIndex = prefabID;
134 
135  TextWidget entityNameWidget = TextWidget.Cast(m_wWidget.FindAnyWidget(m_sEntityNameWidgetName));
136  //m_Background = m_wWidget.FindAnyWidget(m_sBackgroundsName);
137 
138  if (info)
139  {
140  m_Info = info;
141  //Set the entity name
142  info.SetNameTo(entityNameWidget);
143 
145  if (infoCard)
146  {
147  //--- Set faction color (all widgets marked by 'Inherit Color' will use it as well)
148  Faction faction = infoCard.GetFaction();
149  if (faction)
150  {
151  Widget factionColor;
152  foreach (string factionColorName: m_aFactionColorNames)
153  {
154  factionColor = m_wWidget.FindAnyWidget(factionColorName);
155  if (factionColor)
156  factionColor.SetColor(Color.FromInt(faction.GetFactionColor().PackToInt()));
157  }
158  }
159 
160  //--- Set icon
161  Widget iconSlotWidget = m_wWidget.FindAnyWidget(m_sIconSlotWidgetName);
162  if (iconSlotWidget)
163  {
165  if (iconSlot)
166  {
167  SCR_EditableEntityUIConfig entityUIConfig = SCR_EditableEntityUIConfig.GetConfig();
168  if (entityUIConfig)
169  {
170  array<ref SCR_EntitiesEditorUIRule> entityRules = entityUIConfig.GetRules();
171  foreach (SCR_EntitiesEditorUIRule rule: entityRules)
172  {
173  if (rule.GetStates() & EEditableEntityState.RENDERED)
174  {
175  iconSlot.CreateWidget(infoCard, rule);
176  }
177  }
178  }
179  }
180  }
181 
182  //--- Set entity image
183  m_EntityImageWidget = ImageWidget.Cast(m_wWidget.FindAnyWidget(m_sEnityImageWidgetName));
184  if (m_EntityImageWidget)
185  infoCard.SetAssetImageTo(m_EntityImageWidget);
186 
187  ImageWidget imageOverlayWidget = ImageWidget.Cast(m_wWidget.FindAnyWidget(m_sImageOverlayName));
188  if (imageOverlayWidget && !m_ImageOverlayTextures.IsEmpty())
189  {
190  int textureIndex = m_iPrefabIndex % m_ImageOverlayTextures.Count();
191  imageOverlayWidget.LoadImageTexture(0, m_ImageOverlayTextures[textureIndex]);
192  }
193 
194  m_ExceedBudgetLayout = m_wWidget.FindAnyWidget(m_sExceedBudgetLayoutName);
195 
196  UpdateBudgetCost();
197  UpdateBlockingBudget(blockingBudgetInfo);
198 
199  //--- Set faction flag
200  int traitIndex;
201  Widget traitWidget;
202  ImageWidget traitIcon;
203  if (faction)
204  {
206  if (!contentBrowser || contentBrowser.AreFactionsShownOnContentCards())
207  {
208  if (FindTraitIcon(traitIndex, traitWidget, traitIcon))
209  {
210  traitWidget.SetVisible(true);
211  traitIcon.LoadImageTexture(0, faction.GetUIInfo().GetIconPath());
212  }
213  }
214  }
215 
216  EEditorMode editorMode = 0;
217  SCR_EditorManagerEntity editorManager = SCR_EditorManagerEntity.GetInstance();
218  if (editorManager)
219  {
220  SCR_EditorModeEntity modeEntity = editorManager.GetCurrentModeEntity();
221  if (modeEntity)
222  editorMode = modeEntity.GetModeType();
223  }
224 
225  //--- Find traits in labels
227  if (core)
228  {
229  EEditableEntityLabelGroup labelGroup;
230  array<EEditableEntityLabel> labels = {};
231  SCR_UIInfo labelInfo;
232  for (int i, count = infoCard.GetEntityLabels(labels); i < count; i++)
233  {
234  if (!core.GetLabelUIInfoIfValid(labels[i], editorMode, labelInfo))
235  continue;
236 
237  if (core.GetLabelGroupType(labels[i], labelGroup) && m_sTraitLabelGroups.Contains(labelGroup) && labelInfo.HasIcon())
238  {
239  if (FindTraitIcon(traitIndex, traitWidget, traitIcon))
240  {
241  traitWidget.SetVisible(true);
242  labelInfo.SetIconTo(traitIcon);
243 
245  if (tooltip)
246  tooltip.SetInfo(labelInfo);
247  }
248  else
249  {
250  //--- Out of trait icons
251  break;
252  }
253  }
254  }
255  }
256 
257  //--- Show area image (only for systems)
258  if (m_sAreaName)
259  {
260  Widget areaWidget = m_wWidget.FindAnyWidget(m_sAreaName);
261  if (areaWidget)
262  areaWidget.SetVisible(infoCard.HasEntityFlag(EEditableEntityFlag.HAS_AREA));
263  }
264  }
265  }
266  else
267  {
268  if (entityNameWidget && prefab)
269  {
270  string path = prefab.GetPath();
271  array<string> pathNames = {};
272  path.Split("/", pathNames, true);
273  entityNameWidget.SetText(pathNames[pathNames.Count() - 1]);
274  }
275  }
276 
277  //Check if asset is modded
278  Widget modIndicator = m_wWidget.FindAnyWidget(m_sModIndicatorWidgetName);
279  if (modIndicator)
280  {
281  array<string> modList = SCR_AddonTool.GetResourceAddons(prefab, true);
282  if (modList)
283  modIndicator.SetVisible(modList.Count() > 0);
284  else
285  modIndicator.SetVisible(false);
286 
287  //~todo: Get Addon Icon. Use m_sModIndicatorIconName to get the ImageWidget
288  }
289 
290  Event_OnCardInit.Invoke(m_iPrefabIndex);
291  }
292 
293  //------------------------------------------------------------------------------------------------
294  protected bool FindTraitIcon(out int outIndex, out Widget traitWidget, out ImageWidget traitIcon)
295  {
296  if (m_sTraitNames && outIndex < m_sTraitNames.Count())
297  {
298  traitWidget = m_wWidget.FindAnyWidget(m_sTraitNames[outIndex]);
299  if (traitWidget)
300  {
301  traitIcon = ImageWidget.Cast(traitWidget.FindAnyWidget("Trait"));
302  outIndex++;
303  return true;
304  }
305  }
306 
307  outIndex = int.MAX;
308  return false;
309  }
310 
311  //------------------------------------------------------------------------------------------------
314  SCR_UIInfo GetInfo()
315  {
316  return m_Info;
317  }
318 
319 // //------------------------------------------------------------------------------------------------
320 // //! Set faction color of specific widgets
321 // //! \param[in] newColor
322 // void SetColor(Color newColor)
323 // {
324 // if (m_Background)
325 // m_Background.SetColor(newColor);
326 // }
327 
328  //------------------------------------------------------------------------------------------------
331  Widget GetButtonWidget()
332  {
333  return m_wWidget;
334  }
335 
336  //------------------------------------------------------------------------------------------------
337  override bool OnMouseEnter(Widget w, int x, int y)
338  {
339  if (m_wWidget)
340  m_OnHover.Invoke(m_wWidget, m_iPrefabIndex, true);
341 
342  return false;
343  }
344 
345  //------------------------------------------------------------------------------------------------
346  override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
347  {
348  if (m_wWidget)
349  m_OnHover.Invoke(m_wWidget, m_iPrefabIndex, false);
350 
351  return false;
352  }
353 
354  //------------------------------------------------------------------------------------------------
357  ScriptInvoker GetOnHover()
358  {
359  return m_OnHover;
360  }
361 
362  //------------------------------------------------------------------------------------------------
363  override bool OnFocus(Widget w, int x, int y)
364  {
365  if (m_wWidget)
366  m_OnFocus.Invoke(m_wWidget, m_iPrefabIndex, true);
367 
368  return false;
369  }
370 
371  //------------------------------------------------------------------------------------------------
372  override bool OnFocusLost(Widget w, int x, int y)
373  {
374  if (m_wWidget)
375  m_OnFocus.Invoke(m_wWidget, m_iPrefabIndex, false);
376 
377  return false;
378  }
379 
380  //------------------------------------------------------------------------------------------------
383  ScriptInvoker GetOnFocus()
384  {
385  return m_OnFocus;
386  }
387 
388  //------------------------------------------------------------------------------------------------
390  int GetPrefabIndex()
391  {
392  return m_iPrefabIndex;
393  }
394 
395  //------------------------------------------------------------------------------------------------
396  override void HandlerAttached(Widget w)
397  {
398  m_wWidget = w;
399  }
400 }
EEditableEntityState
EEditableEntityState
Definition: EEditableEntityState.c:37
EEditableEntityFlag
EEditableEntityFlag
Unique flags of the entity.
Definition: EEditableEntityFlag.c:5
SCR_EditableEntityCore
Definition: SCR_EditableEntityCore.c:10
SCR_EditableEntityUIInfo
Definition: SCR_EditableEntityUIInfo.c:2
SCR_EntitiesEditorUIRule
Definition: SCR_EditableEntityUIRule.c:8
SCR_EditorModeEntity
Definition: SCR_EditorModeEntity.c:22
SCR_EditableEntityBaseSlotUIComponent
Definition: SCR_EditableEntityBaseSlotUIComponent.c:6
SCR_ContentBrowserEditorComponent
Definition: SCR_ContentBrowserEditorComponent.c:16
SCR_AssetCardFrontUIComponent
Content Browser Card.
Definition: SCR_AssetCardFrontUIComponent.c:4
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_Info
protected ref SCR_HintUIInfo m_Info
Definition: SCR_BaseHintCondition.c:3
EEditableEntityLabelGroup
EEditableEntityLabelGroup
Definition: EEditableEntityLabel.c:200
SCR_EntityBudgetValue
Definition: SCR_EntityBudgetValue.c:2
SCR_UIInfo
Definition: SCR_UIInfo.c:7
EEditorMode
EEditorMode
Editor mode that defines overall functionality.
Definition: EEditorMode.c:5
Faction
Definition: Faction.c:12
m_OnFocus
ref ScriptInvoker m_OnFocus
Definition: SCR_ModularButtonComponent.c:63
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_EditableEntityUIConfig
Definition: SCR_EntitiesEditorUIConfig.c:7
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26