Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MapLightUI.c
Go to the documentation of this file.
2 {
3  NONE,
7 }
8 
9 [BaseContainerProps(configRoot: true)]
10 class SCR_MapLightConfig
11 {
12  [Attribute("", UIWidgets.Object, "2D map light modes")]
13  ref array<ref SCR_MapLightMode> m_aMapLightModes;
14 }
15 
18 {
19  [Attribute("0", UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EMapLightMode), desc: "Select light mode to configure")]
20  EMapLightMode m_eMode;
21 
22  [Attribute("1 1 1 1", UIWidgets.ColorPicker, desc: "Light overlay color")]
23  ref Color m_vColor;
24 
25  [Attribute("1", UIWidgets.Slider, desc: "Light overlay opacity", "0 1 0.05")]
26  float m_fOverlayOpacity;
27 
28  [Attribute("1", UIWidgets.Slider, desc: "Light cone opacity", "0 1 0.05")]
29  float m_fLightConeOpacity;
30 
31  [Attribute("{FFCDEB9793720A1C}UI/Textures/Sights/binocular_vignette2_ca.edds", UIWidgets.ResourceNamePicker, desc: "Zones config", params: "edds")]
32  ResourceName m_sConeTexture;
33 }
34 
36 class SCR_MapLightUI : SCR_MapUIBaseComponent
37 {
38  protected bool m_bActive = false;
39  protected bool m_bIsDark = false;
40  protected float m_fSunriseTime;
41  protected float m_fSunsetTime;
43 
44  protected Widget m_wLightOverlay;
45  protected Widget m_wLightCone;
46  protected Widget m_wFillTop;
47  protected Widget m_wFillLeft;
48  protected Widget m_wConeImg;
49 
50  protected TimeAndWeatherManagerEntity m_TimeMgr;
52 
53  // TEMP
54  protected ref SCR_MapLightConfig m_LightCfg;
55 
56  //------------------------------------------------------------------------------------------------
58  void ToggleActive()
59  {
60  if (!m_bActive)
61  ActivateLight();
62  else
64  }
65 
66  //------------------------------------------------------------------------------------------------
68  protected void ActivateLight()
69  {
70  UpdateTime();
71 
72  // Not dark enough
73  if (!m_bIsDark)
74  return;
75 
76  SCR_GadgetManagerComponent gadgetManager = SCR_GadgetManagerComponent.GetGadgetManager(SCR_PlayerController.GetLocalControlledEntity());
77  if (!gadgetManager)
78  return;
79 
80  IEntity flashlight = gadgetManager.GetGadgetByType(EGadgetType.FLASHLIGHT);
81  if (flashlight)
82  {
83  m_bActive = true;
84  m_wLightCone.SetVisible(true);
85  m_eLightMode = EMapLightMode.FLASH_DEFAULT;
86  // SetMode based on flashlight lense
87  }
88  //else
89  //m_eLightMode = EMapLightMode.LIGHTER;
90 
92  }
93 
94  //------------------------------------------------------------------------------------------------
96  protected void DeactivateLight()
97  {
98  m_bActive = false;
99  m_wLightCone.SetVisible(false);
101  UpdateLightMode();
102  }
103 
104  //------------------------------------------------------------------------------------------------
106  protected void UpdateLightMode()
107  {
108  if (m_LightCfg)
109  {
110  foreach ( SCR_MapLightMode mode : m_LightCfg.m_aMapLightModes )
111  {
112  if (mode.m_eMode == m_eLightMode)
113  {
114  m_wLightOverlay.SetColor(mode.m_vColor);
115  m_wLightOverlay.SetOpacity(mode.m_fOverlayOpacity);
116 
117  // Update light cone texture
118  if (m_eLightMode != EMapLightMode.NONE)
119  {
120  ImageWidget.Cast(m_wConeImg).LoadImageTexture(0, mode.m_sConeTexture);
121  m_wLightCone.SetOpacity(mode.m_fLightConeOpacity);
122  }
123 
124  break;
125  }
126  }
127  }
128  }
129 
130  //------------------------------------------------------------------------------------------------
132  protected void UpdateTime()
133  {
134  if (!m_wLightOverlay || !m_wLightCone)
135  return;
136 
137  if (!m_TimeMgr)
138  return;
139 
140  float time = m_TimeMgr.GetTimeOfTheDay();
141 
142  // day/night
143  m_bIsDark = time < m_fSunriseTime || time > m_fSunsetTime;
144  m_wLightOverlay.SetVisible(m_bIsDark);
145  }
146 
147  //------------------------------------------------------------------------------------------------
149  protected void UpdatePosition()
150  {
151  float sizeX, sizeY, cursorX, cursorY;
152 
153  SCR_MapCursorInfo cursorInfo = m_CursorModule.GetCursorInfo();
154  cursorX = cursorInfo.x;
155  cursorY = cursorInfo.y;
156 
157  m_wConeImg.GetScreenSize(sizeX, sizeY);
158 
159  // calculate and set new size of top & left fill imageWidgets
160  WorkspaceWidget workspace = GetGame().GetWorkspace();
161  cursorX = cursorX - workspace.DPIUnscale(sizeX)/2;
162  cursorY = cursorY - workspace.DPIUnscale(sizeY)/2;
163 
164  ImageWidget.Cast(m_wFillLeft).SetSize(cursorX, 0);
165  ImageWidget.Cast(m_wFillTop).SetSize(0, cursorY);
166  }
167 
168  //------------------------------------------------------------------------------------------------
171  protected void Init(Widget widget)
172  {
173  m_wLightOverlay = widget.FindAnyWidget("LightOverlay");
174  m_wLightCone = widget.FindAnyWidget("LightCone");
175  m_wFillTop = widget.FindAnyWidget("FillTop");
176  m_wFillLeft = widget.FindAnyWidget("FillLeft");
177  m_wConeImg = widget.FindAnyWidget("Cone");
178 
179  if (m_wLightCone)
180  m_wLightCone.SetVisible(false);
181 
182  if (m_wLightOverlay)
183  m_wLightOverlay.SetVisible(false);
184 
185  ChimeraWorld world = GetGame().GetWorld();
186  m_TimeMgr = world.GetTimeAndWeatherManager();
187  if (m_TimeMgr)
188  {
189  m_TimeMgr.GetSunriseHour(m_fSunriseTime);
190  m_TimeMgr.GetSunsetHour(m_fSunsetTime);
191  }
192 
193  // TODO hardcoded
194  if (!m_LightCfg)
195  {
196  Resource container = BaseContainerTools.LoadContainer("{D442DD4867C97496}Configs/Map/MapLightModes.conf");
197  if (container)
198  m_LightCfg = SCR_MapLightConfig.Cast( BaseContainerTools.CreateInstanceFromContainer( container.GetResource().ToBaseContainer() ) );
199  }
200  }
201 
202  //------------------------------------------------------------------------------------------------
203  // OVERRIDES
204  //------------------------------------------------------------------------------------------------
205 
206  //------------------------------------------------------------------------------------------------
207  override void OnMapOpen(MapConfiguration config)
208  {
209  super.OnMapOpen(config);
210 
211  Init(SCR_MapEntity.GetMapInstance().GetMapConfig().RootWidgetRef);
212  m_CursorModule = SCR_MapCursorModule.Cast(SCR_MapEntity.GetMapInstance().GetMapModule(SCR_MapCursorModule));
213 
214  ActivateLight();
215 
216  UpdateLightMode();
217  }
218 
219  //------------------------------------------------------------------------------------------------
220  override void OnMapClose(MapConfiguration config)
221  {
222  DeactivateLight();
223 
224  m_wLightOverlay.SetVisible(false);
225  m_bIsDark = false;
226 
227  super.OnMapClose(config);
228  }
229 
230  //------------------------------------------------------------------------------------------------
231  override void Update(float timeSlice)
232  {
233  if (!m_TimeMgr)
234  return;
235 
236  UpdateTime();
237 
238  if (m_eLightMode != EMapLightMode.NONE && m_wLightCone)
239  UpdatePosition();
240  }
241 }
ChimeraWorld
Definition: ChimeraWorld.c:12
SCR_PlayerController
Definition: SCR_PlayerController.c:31
m_eLightMode
protected EMapLightMode m_eLightMode
Definition: SCR_MapLightUI.c:42
m_CursorModule
protected SCR_MapCursorModule m_CursorModule
Definition: SCR_MapLightUI.c:51
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_wFillLeft
protected Widget m_wFillLeft
Definition: SCR_MapLightUI.c:47
FLASH_DEFAULT
FLASH_DEFAULT
Definition: SCR_MapLightUI.c:4
SCR_GadgetManagerComponent
Definition: SCR_GadgetManagerComponent.c:138
UpdatePosition
protected void UpdatePosition()
Update light position.
Definition: SCR_MapLightUI.c:149
Init
protected void Init(Widget widget)
Definition: SCR_MapLightUI.c:171
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
OnMapOpen
override void OnMapOpen(MapConfiguration config)
Definition: SCR_MapLightUI.c:207
m_fSunsetTime
protected float m_fSunsetTime
Definition: SCR_MapLightUI.c:41
SCR_MapCursorModule
Map cursor behavior and mode setup.
Definition: SCR_MapCursorModule.c:39
LIGHTER
LIGHTER
Definition: SCR_MapLightUI.c:3
m_wLightCone
protected Widget m_wLightCone
Definition: SCR_MapLightUI.c:45
Attribute
typedef Attribute
Post-process effect of scripted camera.
BaseContainerProps
enum EMapLightMode BaseContainerProps(configRoot:true)
Definition: SCR_MapLightUI.c:9
EMapLightMode
EMapLightMode
Definition: SCR_MapLightUI.c:1
UpdateLightMode
protected void UpdateLightMode()
Use config to configure light when switching modes.
Definition: SCR_MapLightUI.c:106
NONE
NONE
Definition: SCR_MapLightUI.c:2
OnMapClose
override void OnMapClose(MapConfiguration config)
Definition: SCR_MapLightUI.c:220
m_wLightOverlay
protected Widget m_wLightOverlay
Definition: SCR_MapLightUI.c:44
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
m_bIsDark
protected bool m_bIsDark
Definition: SCR_MapLightUI.c:39
SCR_MapLightMode
Definition: SCR_MapLightUI.c:17
m_wConeImg
protected Widget m_wConeImg
Definition: SCR_MapLightUI.c:48
Update
override void Update(float timeSlice)
Definition: SCR_MapLightUI.c:231
m_LightCfg
protected ref SCR_MapLightConfig m_LightCfg
Definition: SCR_MapLightUI.c:54
m_wFillTop
protected Widget m_wFillTop
Definition: SCR_MapLightUI.c:46
m_fSunriseTime
protected float m_fSunriseTime
Definition: SCR_MapLightUI.c:40
DeactivateLight
protected void DeactivateLight()
Deactivate map light.
Definition: SCR_MapLightUI.c:96
SCR_MapCursorInfo
Cursor data.
Definition: SCR_MapCursorModule.c:3
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
m_TimeMgr
protected TimeAndWeatherManagerEntity m_TimeMgr
Definition: SCR_MapLightUI.c:50
m_bActive
class SCR_MapLightMode m_bActive
Map light effects.
UpdateTime
protected void UpdateTime()
Update light modes based on time of day.
Definition: SCR_MapLightUI.c:132
SCR_MapUIBaseComponent
Definition: SCR_MapUIBaseComponent.c:3
ActivateLight
protected void ActivateLight()
Activate map light.
Definition: SCR_MapLightUI.c:68
FLASH_RED
FLASH_RED
Definition: SCR_MapLightUI.c:6
ToggleActive
void ToggleActive()
Toggle map light.
Definition: SCR_MapLightUI.c:58