8 [
Attribute(
"0",
desc:
"Set true if you want the GM to be able to set global nightmode. Do not change in runtime",
category:
"Settings")]
9 protected bool m_bAllowGlobalNightMode;
11 [
Attribute(
"0.1",
desc:
"0 means the sun is setting, 1 means the max value the sun is under (though in reality max value is around 0.5 and the sun is fully set around 0.1) this value dictates when the max nightmode EV value is reached if the sun is at the current state",
params:
"0.001 1",
category:
"Settings")]
12 protected float m_fSunStateMaxNightMode;
15 protected int m_iEVValueNormalMode;
18 protected int m_iEVValueNightMode;
20 [
Attribute(
"SOUND_E_TOGGLE_FLASHLIGHT",
desc:
"SFX when local editor nightMode is enabled/disabled",
category:
"Sound")]
21 protected string m_sLocalEditorNightModeToggledSound;
23 [
Attribute(
"ManualCameraLight",
desc:
"Local nightmode shortcut. Toggle On and off")]
24 protected string m_sToggleLocalNightModeShortcut;
27 protected bool m_bLocalEditorNightModeEnabled;
28 protected bool m_bLocalEditorNightModeOnEditorClose;
29 protected bool m_bUnlimitedEditorIsOpen;
30 protected bool m_bGlobalNightModeEnabled;
31 protected bool m_IsPreviewingTimeOrWeather;
32 protected float m_fNightModeAlpha = 0;
35 protected bool m_bUpdateEachFrame;
36 protected float m_fCurrentUpdateTickInSeconds;
37 protected static const float UPDATE_TICK_IN_SECONDS = 1;
41 protected TimeAndWeatherManagerEntity m_TimeAndWeatherManager;
52 override void EOnFrame(IEntity owner,
float timeSlice)
55 if (!m_bUpdateEachFrame)
57 m_fCurrentUpdateTickInSeconds += timeSlice;
59 if (m_fCurrentUpdateTickInSeconds < UPDATE_TICK_IN_SECONDS)
62 m_fCurrentUpdateTickInSeconds = 0;
66 vector Sundirection, moondirection;
68 m_TimeAndWeatherManager.GetCurrentSunMoonDirAndPhase(Sundirection, moondirection, moonphase);
71 float normalizedSun = Math.Clamp(Sundirection[1] / m_fSunStateMaxNightMode, 0, 1);
74 m_bUpdateEachFrame = (normalizedSun != 0);
77 if (normalizedSun != m_fNightModeAlpha)
79 m_fNightModeAlpha = normalizedSun;
80 m_World.AdjustCameraEV(0, Math.Lerp(m_iEVValueNormalMode, m_iEVValueNightMode, m_fNightModeAlpha));
88 return m_bLocalEditorNightModeEnabled;
104 if (m_bLocalEditorNightModeEnabled == enable)
111 m_bLocalEditorNightModeEnabled = enable;
115 if (playSound && !
SCR_StringHelper.IsEmptyOrWhiteSpace(m_sLocalEditorNightModeToggledSound))
119 if (m_OnLocalEditorNightModeEnabledChanged)
120 m_OnLocalEditorNightModeEnabledChanged.Invoke(enable);
127 return m_bAllowGlobalNightMode;
134 return m_bGlobalNightModeEnabled;
157 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
164 m_bGlobalNightModeEnabled = enable;
170 if (m_OnGlobalNightModeEnabledChanged)
171 m_OnGlobalNightModeEnabledChanged.Invoke(enable);
174 if (nightModeChangerPlayerID > 0)
177 SCR_NotificationsComponent.SendLocal(
ENotification.EDITOR_GLOBAL_NIGHTMODE_ENABLED, nightModeChangerPlayerID);
179 SCR_NotificationsComponent.SendLocal(
ENotification.EDITOR_GLOBAL_NIGHTMODE_DISABLED, nightModeChangerPlayerID);
194 return m_TimeAndWeatherManager !=
null;
211 SetEventMask(
GetOwner(), EntityEvent.FRAME);
217 if (m_fNightModeAlpha != 0)
219 m_fNightModeAlpha = 0;
220 m_World.AdjustCameraEV(0, m_iEVValueNormalMode);
224 if (
SCR_Enum.HasPartialFlag(GetEventMask(), EntityEvent.FRAME))
225 ClearEventMask(
GetOwner(), EntityEvent.FRAME);
231 m_bUpdateEachFrame =
true;
232 m_fCurrentUpdateTickInSeconds = 0;
236 if (m_OnNightModeEnabledChanged)
237 m_OnNightModeEnabledChanged.Invoke(enable);
248 if (m_bUnlimitedEditorIsOpen)
255 m_bUnlimitedEditorIsOpen =
false;
277 bool newIsPreviewing = m_WeatherStateTransitionManager.IsPreviewingWind() || m_WeatherStateTransitionManager.IsPreviewingState() || m_WeatherStateTransitionManager.IsPreviewingDateTime();
278 if (m_IsPreviewingTimeOrWeather == newIsPreviewing)
281 m_IsPreviewingTimeOrWeather = newIsPreviewing;
287 if (m_IsPreviewingTimeOrWeather)
290 if (
SCR_Enum.HasPartialFlag(GetEventMask(), EntityEvent.FRAME))
291 ClearEventMask(
GetOwner(), EntityEvent.FRAME);
294 if (m_fNightModeAlpha != 0)
296 m_fNightModeAlpha = 0;
297 m_World.AdjustCameraEV(0, m_iEVValueNormalMode);
299 SCR_NotificationsComponent.SendLocal(
ENotification.EDITOR_PREVIEWING_IN_NIGHTMODE);
301 if (!
SCR_StringHelper.IsEmptyOrWhiteSpace(m_sLocalEditorNightModeToggledSound))
308 if (!
SCR_Enum.HasPartialFlag(GetEventMask(), EntityEvent.FRAME))
310 SetEventMask(
GetOwner(), EntityEvent.FRAME);
312 if (m_TimeAndWeatherManager.IsSunSet() && !
SCR_StringHelper.IsEmptyOrWhiteSpace(m_sLocalEditorNightModeToggledSound))
325 protected void OnWindPreview(
bool preview,
float windSpeed = -1,
float windAngleDegrees = -1)
331 protected void OnDateTimePreview(
bool preview,
int year = -1,
int month = -1,
int day = -1,
float timeOfTheDay = -1)
340 if (!m_OnLocalEditorNightModeEnabledChanged)
343 return m_OnLocalEditorNightModeEnabledChanged;
350 if (!m_OnGlobalNightModeEnabledChanged)
353 return m_OnGlobalNightModeEnabledChanged;
360 if (!m_OnNightModeEnabledChanged)
363 return m_OnNightModeEnabledChanged;
402 Print(
"'SCR_NightModeGameModeComponent' could not find World this means nightmode can never be enabled!", LogLevel.ERROR);
412 m_TimeAndWeatherManager = world.GetTimeAndWeatherManager();
413 if (!m_TimeAndWeatherManager)
415 Print(
"'SCR_NightModeGameModeComponent' could not find TimeAndWeatherEntity this means nightmode can never be enabled!", LogLevel.ERROR);
420 m_WeatherStateTransitionManager = m_TimeAndWeatherManager.GetTransitionManager();
421 if (m_WeatherStateTransitionManager)
424 m_TimeAndWeatherManager.GetOnWindPreview().Insert(
OnWindPreview);
447 SetEventMask(owner, EntityEvent.INIT);
456 super.OnDelete(owner);
465 if (m_TimeAndWeatherManager && m_WeatherStateTransitionManager)
468 m_TimeAndWeatherManager.GetOnWindPreview().Remove(
OnWindPreview);
479 writer.WriteBool(m_bGlobalNightModeEnabled);
487 bool globalNightModeEnabled;
491 reader.ReadBool(globalNightModeEnabled);