Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_RestrictionZoneWarningHUDComponent.c
Go to the documentation of this file.
2 {
3  [Attribute("Holds array of warning info's to display the proper warning visuals.")]
4  protected ref array<ref SCR_RestrictionZoneWarningInfo> m_aWarningUIInfos; //~ Add new entries in SCR_HUDManagerComponent on PlayerController
5 
6  [Attribute("Icon")]
7  protected string m_sIconWidgetName;
8 
9  [Attribute("Warning")]
10  protected string m_sWarningWidgetName;
11 
12  [Attribute("Explanation")]
13  protected string m_sExplanationWidgetName;
14 
15  [Attribute("WarningZoneDistanceVisuals")]
16  protected string m_sWarningZoneDistanceVisualsName;
17 
18  [Attribute("WarningVisualsHolder")]
19  protected string m_sWarningVisualsHolderName;
20 
21  [Attribute("0.05", desc: "If zone is active how fast does the zone visuals update depending on the distance? In seconds.")]
22  protected float m_fWarningVisualsUpdateTime;
23 
24  [Attribute("0", desc: "Min waning visuals opacity. Opacity becomes stronger when moving closer to edge of the zone.", uiwidget: UIWidgets.Slider, params: "0 1 0.00001")]
25  protected float m_fMinWarningDistanceVisualsOpacity;
26 
27  [Attribute("1", desc: "Max waning visuals opacity. Opacity becomes stronger when moving closer to edge of the zone.", uiwidget: UIWidgets.Slider, params: "0 1 0.00001")]
28  protected float m_fMaxWarningDistanceVisualsOpacity;
29 
30  [Attribute("0.4", desc: "The minimum opacity of the warning text", uiwidget: UIWidgets.Slider, params: "0 1 0.00001")]
31  protected float m_fWarningVisualsMinOpacity;
32 
33  protected Widget m_WarningZoneDistanceVisuals;
34  protected Widget m_WarningVisualsHolder;
35 
36  protected ERestrictionZoneWarningType m_iCurrentDisplayedWarning = -1;
37 
38  protected vector m_vZoneCenter;
39  protected float m_fWarningRadiusSq;
40  protected float m_fZoneMinusWarningSq;
41 
42 
48  void ShowZoneWarning(bool show, ERestrictionZoneWarningType warningType, vector zoneCenter, float warningRadiusSq, float zoneRadiusSq, float speed = UIConstants.FADE_RATE_DEFAULT)
49  {
50  if (!show)
51  {
52  if (m_bShown)
53  GetGame().GetCallqueue().Remove(UpdateVisualWarning);
54 
55  Show(false, speed);
56  return;
57  }
58 
59  m_vZoneCenter = zoneCenter;
60  m_fWarningRadiusSq = warningRadiusSq;
61  m_fZoneMinusWarningSq = zoneRadiusSq - warningRadiusSq;
62 
63  if (m_iCurrentDisplayedWarning != warningType)
64  {
65  foreach (SCR_RestrictionZoneWarningInfo warningInfo: m_aWarningUIInfos)
66  {
67  if (warningInfo.m_iWarningType == warningType)
68  {
69  if (warningInfo.m_UIInfo)
70  {
71  warningInfo.m_UIInfo.SetIconTo(ImageWidget.Cast(m_wRoot.FindAnyWidget(m_sIconWidgetName)));
72  warningInfo.m_UIInfo.SetNameTo(TextWidget.Cast(m_wRoot.FindAnyWidget(m_sWarningWidgetName)));
73  warningInfo.m_UIInfo.SetDescriptionTo(TextWidget.Cast(m_wRoot.FindAnyWidget(m_sExplanationWidgetName)));
74  }
75  break;
76  }
77  }
78  }
79 
80  m_iCurrentDisplayedWarning = warningType;
81 
82  if (!m_bShown)
83  GetGame().GetCallqueue().CallLater(UpdateVisualWarning, m_fWarningVisualsUpdateTime * 1000, true);
84 
85  Show(true, speed);
86 
87  }
88 
89  protected void UpdateVisualWarning()
90  {
91  IEntity playerEntity = SCR_PlayerController.GetLocalControlledEntity();
92  vector playerPosition = playerEntity.GetOrigin();
93 
94  //~ Calculate opacity Strenght depending on distance
95  float opacityCalc = ((vector.DistanceSqXZ(playerPosition, m_vZoneCenter) - m_fWarningRadiusSq) / m_fZoneMinusWarningSq) + m_fMinWarningDistanceVisualsOpacity;
96  float opacity = Math.Clamp(opacityCalc, m_fMinWarningDistanceVisualsOpacity, m_fMaxWarningDistanceVisualsOpacity);
97 
98  float ratio = 0;
99  CameraManager cameraManager = GetGame().GetCameraManager();
100  if (cameraManager)
101  {
102  CameraBase camera = cameraManager.CurrentCamera();
103  if (camera)
104  {
105  //~ Calculate opacity multiplier depending on where the player is looking (Looking towards center == less opacity)
106  vector cameraTransform[4];
107  camera.GetWorldTransform(cameraTransform);
108 
109  //~ Grab the ratio between zone and center. Looking at zone == 1 and looking fully away from zone == -1
110  ratio = vector.DotXZ((m_vZoneCenter - playerPosition).Normalized(), cameraTransform[2]);
111  }
112  }
113 
114  //~ If looking less the 180 degrees towards the center start reducing the opacity using a multiplier
115  float opacityLookDirectionMultiplier = 1;
116  if (ratio > 0)
117  opacityLookDirectionMultiplier = 1 - ratio;
118 
119  //~ Set final Opacity
120  m_WarningZoneDistanceVisuals.SetOpacity(opacity * opacityLookDirectionMultiplier);
121 
122  //~ Warning visuals opacity
123  if (opacityLookDirectionMultiplier > m_fWarningVisualsMinOpacity)
124  m_WarningVisualsHolder.SetOpacity(opacityLookDirectionMultiplier);
125  else
126  m_WarningVisualsHolder.SetOpacity(m_fWarningVisualsMinOpacity);
127  }
128 
129 
130  override event void OnStartDraw(IEntity owner)
131  {
132  super.OnStartDraw(owner);
133 
134  if (!m_wRoot)
135  return;
136 
137  if (!m_WarningZoneDistanceVisuals)
138  {
139  if (m_fMinWarningDistanceVisualsOpacity > m_fMaxWarningDistanceVisualsOpacity)
140  {
141  Print("'SCR_RestrictionZoneWarningHUDComponent' m_fMinWarningDistanceVisualsOpacity is greater then m_fMaxWarningDistanceVisualsOpacity! This should never be greater then max and is set the same.", LogLevel.WARNING);
142  m_fMinWarningDistanceVisualsOpacity = m_fMaxWarningDistanceVisualsOpacity;
143  }
144 
145  m_WarningZoneDistanceVisuals = m_wRoot.FindAnyWidget(m_sWarningZoneDistanceVisualsName);
146  m_WarningVisualsHolder = m_wRoot.FindAnyWidget(m_sWarningVisualsHolderName);
147 
148  if (m_WarningZoneDistanceVisuals)
149  m_WarningZoneDistanceVisuals.SetOpacity(0);
150  else
151  Print("'SCR_RestrictionZoneWarningHUDComponent' could not find m_WarningZoneDistanceVisuals. This will break the zone restriction warning!", LogLevel.ERROR);
152 
153  if (m_WarningVisualsHolder)
154  m_WarningVisualsHolder.SetOpacity(0);
155  else
156  Print("'SCR_RestrictionZoneWarningHUDComponent' could not find m_WarningVisualsHolder. This will break the zone restriction warning!", LogLevel.ERROR);
157  }
158  }
159 
160 
162  {
163  if (m_bShown)
164  GetGame().GetCallqueue().Remove(UpdateVisualWarning);
165  }
166 };
167 
173 {
174  [Attribute("0", desc: "Which warning UIinfo needs to be shown on the screen as defined in 'SCR_RestrictionZoneWarningHUDComponent'", uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(ERestrictionZoneWarningType))]
175  ERestrictionZoneWarningType m_iWarningType;
176 
177  [Attribute(desc: "UI info to dictate what to display in warning")]
178  ref SCR_UIInfo m_UIInfo;
179 }
m_bShown
protected bool m_bShown
Definition: SCR_InfoDisplay.c:61
SCR_PlayerController
Definition: SCR_PlayerController.c:31
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
UIConstants
Definition: Constants.c:130
SCR_BaseContainerCustomTitleEnum
class SCR_CampaignHintStorage SCR_BaseContainerCustomTitleEnum(EHint, "m_eHintId")
Definition: SCR_CampaignHintStorage.c:22
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_sIconWidgetName
protected string m_sIconWidgetName
Definition: SCR_GroupEditableEntityUIComponent.c:6
Show
override void Show(WorkspaceWidget pWorkspace, Widget pToolTipWidget, float desiredPosX, float desiredPosY)
Definition: SCR_ScriptedWidgetTooltip.c:55
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_UIInfo
Definition: SCR_UIInfo.c:7
SCR_RestrictionZoneWarningInfo
Definition: SCR_RestrictionZoneWarningHUDComponent.c:172
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
ERestrictionZoneWarningType
ERestrictionZoneWarningType
Definition: ERestrictionZoneWarningType.c:4
SCR_RestrictionZoneWarningHUDComponent
Definition: SCR_RestrictionZoneWarningHUDComponent.c:1
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