Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BaseVehicleInfo.c
Go to the documentation of this file.
1 //#define DEBUG_VEHICLE_UI
2 
3 //------------------------------------------------------------------------------------------------
6 {
12 };
13 
14 //------------------------------------------------------------------------------------------------
17 {
23 };
24 
25 //------------------------------------------------------------------------------------------------
27 [BaseContainerProps(configRoot: true)]
28 class SCR_BaseVehicleInfo : SCR_InfoDisplayExtended
29 {
30  protected ResourceName m_Imageset = "{3262679C50EF4F01}UI/Textures/Icons/icons_wrapperUI.imageset";
31  protected ResourceName m_ImagesetGlow = "{00FE3DBDFD15227B}UI/Textures/Icons/icons_wrapperUI-glow.imageset";
32 
33  protected ImageWidget m_wIcon;
34  protected ImageWidget m_wGlow;
35  protected OverlayWidget m_wSizeOverlay;
36 
37  [Attribute("", UIWidgets.EditBox, "Indicator icon to be displayed.")]
38  protected string m_sIcon;
39 
40  [Attribute(SCR_Enum.GetDefault(EVehicleInfoColor.WHITE), UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EVehicleInfoColor))]
41  EVehicleInfoColor m_eColor;
42 
43  [Attribute("0.8", UIWidgets.Slider, "Indicator scale", "0.25 2 0.05")]
44  protected float m_fWidgetScale;
45 
46  [Attribute("1", UIWidgets.CheckBox, "Show the greyed-out indicator, if it is inactive, otherwise it will be hidden.")]
47  protected bool m_bShowGhost;
48 
49  protected EVehicleInfoState m_eState = EVehicleInfoState.ERROR;
50  protected bool m_bIsBlinking;
51  protected int m_iBlinkingOffset;
52 
53  protected Color m_aColors[5];
54  protected Color m_aColorsGlow[5];
55 
56  protected const int ICON_SIZE = 64;
57 
58  //------------------------------------------------------------------------------------------------
60  protected EVehicleInfoState GetState()
61  {
62  return m_eState;
63  }
64 
65  //------------------------------------------------------------------------------------------------
67  protected bool IsBlinking()
68  {
69  return m_bIsBlinking;
70  }
71 
72  //------------------------------------------------------------------------------------------------
73  protected void Scale(ImageWidget widget, float scale)
74  {
75  if (!widget)
76  return;
77 
78  int imageWidth = 0;
79  int imageHeight = 0;
80  int image = widget.GetImage();
81 
82  widget.GetImageSize(image, imageWidth, imageHeight);
83  widget.SetSize((float)imageWidth * scale, (float)imageHeight * scale);
84  }
85 
86  //------------------------------------------------------------------------------------------------
87  protected void Scale(TextWidget widget, float scale)
88  {
89  if (!widget)
90  return;
91 
92  float sizeY = FrameSlot.GetSizeY(widget);
93 
94  FrameSlot.SetSizeY(widget, sizeY * scale);
95  }
96 
97  //------------------------------------------------------------------------------------------------
98  protected void Scale(OverlayWidget widget, float scale)
99  {
100  if (!widget)
101  return;
102 
103  FrameSlot.SetSizeX(widget, scale * ICON_SIZE);
104  FrameSlot.SetSizeY(widget, scale * ICON_SIZE);
105  }
106 
107  //------------------------------------------------------------------------------------------------
108  protected void SetIcon(string icon)
109  {
110  if (!m_wIcon || !m_wGlow)
111  return;
112 
113  m_wIcon.LoadImageFromSet(0, m_Imageset, icon);
114  m_wGlow.LoadImageFromSet(0, m_ImagesetGlow, icon);
115 
116  Scale(m_wSizeOverlay, m_fWidgetScale);
117  }
118 
119  //------------------------------------------------------------------------------------------------
120  protected void SetColor(EVehicleInfoState state, EVehicleInfoColor color)
121  {
122  if (!m_wIcon || !m_wGlow)
123  return;
124 
125  switch(state)
126  {
127  case EVehicleInfoState.DISABLED:
128  m_wIcon.SetColor(Color.FromInt(GUIColors.DISABLED.PackToInt()));
129  m_wGlow.SetColor(Color.FromInt(GUIColors.DISABLED_GLOW.PackToInt()));
130  break;
131 
132  case EVehicleInfoState.ENABLED:
133  m_wIcon.SetColor(Color.FromInt(m_aColors[color].PackToInt()));
134  m_wGlow.SetColor(Color.FromInt(m_aColorsGlow[color].PackToInt()));
135  break;
136 
137  case EVehicleInfoState.WARNING:
138  m_wIcon.SetColor(Color.FromInt(GUIColors.ORANGE.PackToInt()));
139  m_wGlow.SetColor(Color.FromInt(GUIColors.ORANGE_DARK.PackToInt()));
140  break;
141 
142  case EVehicleInfoState.ERROR:
143  m_wIcon.SetColor(Color.FromInt(GUIColors.RED.PackToInt()));
144  m_wGlow.SetColor(Color.FromInt(GUIColors.RED_DARK.PackToInt()));
145  break;
146  }
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  protected bool UpdateRequired(EVehicleInfoState state)
151  {
152  return m_eState != state;
153  }
154 
155  //------------------------------------------------------------------------------------------------
156  override event void DisplayUpdate(IEntity owner, float timeSlice)
157  {
158  if (!m_wRoot)
159  return;
160 
161  EVehicleInfoState state = GetState();
162 
163  bool isBlinking = IsBlinking();
164  int time = GetGame().GetWorld().GetWorldTime();
165 
166  if (isBlinking)
167  {
168  if (Math.Mod(time - m_iBlinkingOffset, 1000) < 500)
169  state = Math.Max(state - 1, EVehicleInfoState.DISABLED);
170  }
171  else
172  {
173  m_iBlinkingOffset = Math.Mod(time, 1000);
174  }
175 
176  if (UpdateRequired(state))
177  {
178  #ifdef DEBUG_VEHICLE_UI
179  PrintFormat("%1 Update -> state: %2 | icon: %3", this, state, m_sIcon);
180  #endif
181 
182  m_eState = state;
183 
184  SetIcon(m_sIcon);
185  SetColor(state, m_eColor);
186 
187  bool show = isBlinking || m_bShowGhost || state != EVehicleInfoState.DISABLED;
188 
189  if (m_bShown != show)
190  Show(show);
191  }
192  }
193 
194  //------------------------------------------------------------------------------------------------
195  override bool DisplayStartDrawInit(IEntity owner)
196  {
197  // Terminate if widget already exists
198  if (m_wRoot)
199  return false;
200 
201  // Fallback to avoid the need to fill-in always the same layout filename
202  if (m_LayoutPath == "")
203  m_LayoutPath = "{D2E54F91C85CAB6C}UI/layouts/HUD/VehicleInfo/VehicleInfoIcon.layout";
204 
205  return true;
206  }
207 
208  //------------------------------------------------------------------------------------------------
210  override void DisplayStartDraw(IEntity owner)
211  {
212  if (!m_wRoot)
213  return;
214 
215  m_wIcon = ImageWidget.Cast(m_wRoot.FindAnyWidget("Icon"));
216  m_wGlow = ImageWidget.Cast(m_wRoot.FindAnyWidget("Glow"));
217  m_wSizeOverlay = OverlayWidget.Cast(m_wRoot.FindAnyWidget("SizeOverlay"));
218 
219  m_eState = EVehicleInfoState.NOT_INITIALIZED;
220 
221  DisplayUpdate(owner, 0);
222  }
223 
224  //------------------------------------------------------------------------------------------------
226  override void DisplayStopDraw(IEntity owner)
227  {
228  }
229 
230  //------------------------------------------------------------------------------------------------
232  override void DisplayInit(IEntity owner)
233  {
234  if (m_wRoot)
235  m_wRoot.RemoveFromHierarchy();
236 
237  m_aColors[EVehicleInfoColor.WHITE] = GUIColors.ENABLED;
238  m_aColors[EVehicleInfoColor.BLUE] = GUIColors.BLUE_BRIGHT2;
239  m_aColors[EVehicleInfoColor.GREEN] = GUIColors.GREEN_BRIGHT2;
240  m_aColors[EVehicleInfoColor.ORANGE] = GUIColors.ORANGE_BRIGHT2;
241  m_aColors[EVehicleInfoColor.RED] = GUIColors.RED_BRIGHT2;
242 
243  m_aColorsGlow[EVehicleInfoColor.WHITE] = GUIColors.ENABLED_GLOW;
244  m_aColorsGlow[EVehicleInfoColor.BLUE] = GUIColors.BLUE;
245  m_aColorsGlow[EVehicleInfoColor.GREEN] = GUIColors.GREEN;
246  m_aColorsGlow[EVehicleInfoColor.ORANGE] = GUIColors.ORANGE;
247  m_aColorsGlow[EVehicleInfoColor.RED] = GUIColors.RED;
248  }
249 };
BLUE
@ BLUE
Definition: SCR_BaseVehicleInfo.c:19
m_bShown
protected bool m_bShown
Definition: SCR_InfoDisplay.c:61
m_wIcon
protected ImageWidget m_wIcon
Definition: SCR_InventoryHitZonePointUI.c:374
SCR_Enum
Definition: SCR_Enum.c:1
ORANGE
@ ORANGE
Definition: SCR_BaseVehicleInfo.c:21
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
EVehicleInfoColor
EVehicleInfoColor
Predefined colors that can be assigned in the InfoDisplay configuration.
Definition: SCR_BaseVehicleInfo.c:16
SCR_BaseVehicleInfo
Base class for all vehicle UI state and damage indicators.
Definition: SCR_BaseVehicleInfo.c:28
WARNING
@ WARNING
Definition: SCR_BaseVehicleInfo.c:10
WHITE
@ WHITE
Definition: SCR_BaseVehicleInfo.c:18
RED
@ RED
Definition: SCR_BaseVehicleInfo.c:22
NOT_INITIALIZED
@ NOT_INITIALIZED
Definition: SCR_BaseVehicleInfo.c:7
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
Show
override void Show(WorkspaceWidget pWorkspace, Widget pToolTipWidget, float desiredPosX, float desiredPosY)
Definition: SCR_ScriptedWidgetTooltip.c:55
m_eState
EAITargetClusterState m_eState
Definition: SCR_AITargetClusterState.c:24
Attribute
typedef Attribute
Post-process effect of scripted camera.
GREEN
@ GREEN
Definition: SCR_BaseVehicleInfo.c:20
ENABLED
@ ENABLED
Definition: SCR_BaseVehicleInfo.c:9
EVehicleInfoState
EVehicleInfoState
UI indicator state, controlling colors and opacity.
Definition: SCR_BaseVehicleInfo.c:5
DISABLED
@ DISABLED
Definition: SCR_BaseVehicleInfo.c:8
m_sIcon
protected string m_sIcon
Definition: SCR_InventoryHitZonePointUI.c:373
ERROR
@ ERROR
Definition: SCR_BaseVehicleInfo.c:11
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468