Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SimpleWarningOverlayComponent.c
Go to the documentation of this file.
1 /*
2  Component that takes care of displaying error states on tiles. Includes a darkening background, different text visualization modes, and the main icon is a button that will enlarge on mouse hover
3  Since it is meant to either be non-interactable or to be part of tiles, it is not focusable: the menu should provide a gamepad alternative to clicking the icon button.
4 */
5 //------------------------------------------------------------------------------------------------
7 {
8  [Attribute("1")]
9  protected bool m_bShowTextBackground;
10 
11  [Attribute("-10")]
12  protected int m_iNakedTextTopPadding;
13 
14  [Attribute(UIColors.GetColorAttribute(UIColors.WARNING_DISABLED))]
15  protected ref Color m_NakedTextColor;
16 
17  [Attribute("1")]
18  protected bool m_bShowDarkeningBackground;
19 
20  [Attribute("1")]
21  protected bool m_bShowIconGlow;
22 
23  [Attribute("0")]
24  protected bool m_bEnableIconButton;
25 
26  [Attribute("86")]
27  protected float m_fIconSize;
28 
29  [Attribute("1.1")]
30  protected float m_fIconSizeHoveredMultiplier;
31 
32  [Attribute("0 0 0")]
33  protected vector m_vWarningPositionOffset;
34 
35  protected SmartPanelWidget m_wTextBackground;
36  protected ImageWidget m_wWarningImageGlow;
37  protected ImageWidget m_wWarningOuterBackground;
38  protected SizeLayoutWidget m_wWarningTextSize;
39  protected Widget m_wWarningImageOverlay;
40  protected Widget m_wWarningVerticalLayout;
41 
42  protected SCR_ModularButtonComponent m_WarningIconButton;
43 
44  protected ref ScriptInvokerScriptedWidgetComponent m_OnWarningIconButtonClicked = new ScriptInvokerScriptedWidgetComponent();
45 
46  //------------------------------------------------------------------------------------------------
47  override void HandlerAttached(Widget w)
48  {
49  // Needed before super call for SetWarning()
50  m_wWarningImageGlow = ImageWidget.Cast(w.FindAnyWidget("WarningImageGlow"));
51  if (m_wWarningImageGlow)
52  m_wWarningImageGlow.SetVisible(m_bShowIconGlow);
53 
54  super.HandlerAttached(w);
55 
56  m_wTextBackground = SmartPanelWidget.Cast(w.FindAnyWidget("WarningTextBackground"));
57  if (m_wTextBackground)
58  m_wTextBackground.SetVisible(m_bShowTextBackground);
59 
60  m_wWarningOuterBackground = ImageWidget.Cast(w.FindAnyWidget("WarningOuterBackground"));
61  if (m_wWarningOuterBackground)
62  m_wWarningOuterBackground.SetVisible(m_bShowDarkeningBackground);
63 
64  // Adjust text padding
65  m_wWarningTextSize = SizeLayoutWidget.Cast(w.FindAnyWidget("WarningTextSize"));
66  if (m_wWarningTextSize)
67  {
68  if (m_wWarning && !m_bShowTextBackground)
69  {
70  AlignableSlot.SetPadding(m_wWarningTextSize, 0, m_iNakedTextTopPadding, 0, 0);
71  AlignableSlot.SetPadding(m_wWarning, 0, 0, 0, 0);
72  }
73  }
74 
75  m_wWarningVerticalLayout = w.FindAnyWidget("WarningVerticalLayout");
76  if (m_wWarningVerticalLayout)
77  FrameSlot.SetPos(m_wWarningVerticalLayout, m_vWarningPositionOffset[0], m_vWarningPositionOffset[1]);
78 
79  m_wWarningImageOverlay = w.FindAnyWidget("WarningImageOverlay");
80  if (m_wWarningImageOverlay)
81  FrameSlot.SetSize(m_wWarningImageOverlay, m_fIconSize, m_fIconSize);
82 
83  ButtonWidget warningIconButton = ButtonWidget.Cast(w.FindAnyWidget("WarningIconButton"));
84  if (warningIconButton)
85  m_WarningIconButton = SCR_ModularButtonComponent.FindComponent(warningIconButton);
86 
87  if (m_WarningIconButton)
88  {
89  SCR_ButtonEffectSize effect = SCR_ButtonEffectSize.Cast(m_WarningIconButton.FindEffect("ButtonSize"));
90  if (effect)
91  {
92  vector size = {m_fIconSize, m_fIconSize, 0};
93 
94  effect.m_vDefault = size;
95  effect.m_vHovered = size * m_fIconSizeHoveredMultiplier;
96 
97  m_WarningIconButton.InvokeAllEnabledEffects(false);
98 
99  m_WarningIconButton.m_OnClicked.Insert(OnWarningIconButtonClicked);
100  }
101  }
102 
103  SetIconButtonEnabled(m_bEnableIconButton);
104  }
105 
106  //------------------------------------------------------------------------------------------------
107  override void ResetWarningColor()
108  {
109  Color textColor = m_TextColor;
110  if (!m_bShowTextBackground)
111  textColor = m_NakedTextColor;
112 
113  SetWarningColor(m_Color, textColor);
114  }
115 
116  //------------------------------------------------------------------------------------------------
117  override void SetWarning(string text, string iconName)
118  {
119  super.SetWarning(text, iconName);
120 
121  if (m_wWarningImageGlow && !iconName.IsEmpty())
122  m_wWarningImageGlow.LoadImageFromSet(0, UIConstants.ICONS_IMAGE_SET, iconName);
123  }
124 
125  //------------------------------------------------------------------------------------------------
126  override static SCR_SimpleWarningOverlayComponent FindComponentInHierarchy(notnull Widget root)
127  {
128  ScriptedWidgetEventHandler handler = SCR_WidgetTools.FindHandlerInChildren(root, SCR_SimpleWarningOverlayComponent);
129  if (handler)
130  return SCR_SimpleWarningOverlayComponent.Cast(handler);
131 
132  return null;
133  }
134 
135  //------------------------------------------------------------------------------------------------
136  override static SCR_SimpleWarningOverlayComponent FindComponent(notnull Widget w)
137  {
139  }
140 
141  //------------------------------------------------------------------------------------------------
142  protected void OnWarningIconButtonClicked()
143  {
144  m_OnWarningIconButtonClicked.Invoke(this);
145  }
146 
147  //------------------------------------------------------------------------------------------------
148  void SetIconButtonEnabled(bool enabled)
149  {
150  if (!m_wWarningImageSize || !m_WarningIconButton)
151  return;
152 
153  float safeSize = m_fIconSize;
154  float padding;
155 
156  if (enabled)
157  {
158  // When the icon button is enabled, we need to account for it's on hover enlargement animation
159  safeSize *= m_fIconSizeHoveredMultiplier;
160  padding = (m_fIconSize - safeSize) / 2;
161  }
162 
163  LayoutSlot.SetPadding(m_wWarningImageSize, 0, padding, 0, padding);
164 
165  m_wWarningImageSize.SetWidthOverride(safeSize);
166  m_wWarningImageSize.SetHeightOverride(safeSize);
167 
168  m_WarningIconButton.SetEnabled(enabled);
169  }
170 
171  //------------------------------------------------------------------------------------------------
172  ScriptInvokerScriptedWidgetComponent GetOnWarningIconButtonClicked()
173  {
174  return m_OnWarningIconButtonClicked;
175  }
176 }
SCR_WidgetTools
Definition: SCR_WidgetTools.c:1
SCR_SimpleWarningComponent
Definition: SCR_SimpleWarningComponent.c:2
UIConstants
Definition: Constants.c:130
SCR_SimpleWarningOverlayComponent
Definition: SCR_SimpleWarningOverlayComponent.c:6
Attribute
typedef Attribute
Post-process effect of scripted camera.
UIColors
Definition: Constants.c:16
m_Color
ref Color m_Color
Definition: SCR_GeneratorBaseEntity.c:3
ScriptInvokerScriptedWidgetComponent
ScriptInvokerBase< ScriptInvokerScriptedWidgetComponentMethod > ScriptInvokerScriptedWidgetComponent
Definition: SCR_ScriptedWidgetComponent.c:4
SCR_ButtonEffectSize
Definition: SCR_ButtonEffectSize.c:2