Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_WeatherInstantEditorAttribute.c
Go to the documentation of this file.
1 
6 {
7  [Attribute("MISSING NAME", desc: "Text shown if weather State has no weather name assigned")]
8  protected LocalizedString m_sUnknownWeatherName;
9 
10  [Attribute("{4B4B51FACB828BF9}UI/Textures/Tasks/TaskIcons/96/Icon_Task_Unknown.edds", desc: "Icon used when weather is unknown")]
11  protected ResourceName m_sUnknownWeatherIcon;
12 
13  override SCR_BaseEditorAttributeVar ReadVariable(Managed item, SCR_AttributesManagerEditorComponent manager)
14  {
15  //If opened in global attributes
16  if (!IsGameMode(item))
17  return null;
18 
19  GenericEntity ent = GenericEntity.Cast(item);
20  ChimeraWorld world = ent.GetWorld();
21  TimeAndWeatherManagerEntity weatherManager = world.GetTimeAndWeatherManager();
22  if (!weatherManager)
23  return null;
24 
25  WeatherStateTransitionManager weatherTransitionManager = weatherManager.GetTransitionManager();
26  if (!weatherTransitionManager)
27  return null;
28 
29  array<ref WeatherState> weatherStates = new array<ref WeatherState>;
30 
31  //Get weather states
32  weatherManager.GetWeatherStatesList(weatherStates);
33  if (weatherStates.IsEmpty())
34  return null;
35 
36  WeatherState currentState = weatherManager.GetCurrentWeatherState();
37  return SCR_BaseEditorAttributeVar.CreateInt(currentState.GetStateID());
38  }
39 
40  override void WriteVariable(Managed item, SCR_BaseEditorAttributeVar var, SCR_AttributesManagerEditorComponent manager, int playerID)
41  {
42  if (!var)
43  return;
44 
45  BaseGameMode gameMode = GetGame().GetGameMode();
46  if (!gameMode)
47  return;
48 
49  ChimeraWorld world = ChimeraWorld.CastFrom(gameMode.GetWorld());
50  if (!world)
51  return;
52 
53  TimeAndWeatherManagerEntity weatherManager = world.GetTimeAndWeatherManager();
54  if (!weatherManager)
55  return;
56 
57  int stateIndex = var.GetInt();
58 
59  array<ref WeatherState> weatherStates = new array<ref WeatherState>;
60  weatherManager.GetWeatherStatesList(weatherStates);
61 
62  //Valid state
63  if (weatherStates.IsEmpty() || stateIndex >= weatherStates.Count())
64  return;
65 
66  WeatherState weatherToSet = weatherStates[stateIndex];
67 
68  //Preview Weather
69  if (!item)
70  {
71  weatherManager.SetWeatherStatePreview(true, weatherToSet.GetStateName());
72  return;
73  }
74 
75  float transitionTime = 0;
76 
77  SCR_BaseEditorAttributeVar transitionVar;
78  if (manager && manager.GetAttributeVariable(SCR_WeatherInstantTransitionTimeEditorAttribute, transitionVar))
79  transitionTime = transitionVar.GetInt();
80 
81  weatherManager.ForceWeatherTo(true, weatherToSet.GetStateName(), transitionTime / 3600, 0.001, playerID);
82  }
83 
84  override void PreviewVariable(bool setPreview, SCR_AttributesManagerEditorComponent manager)
85  {
86  //Preview weather. Note that if advanced is turned on preview should disapear
87  if (setPreview)
88  {
89  WriteVariable(null, GetVariable(), manager, -1);
90  }
91  else
92  {
93  ChimeraWorld world = GetGame().GetWorld();
94  TimeAndWeatherManagerEntity weatherManager = world.GetTimeAndWeatherManager();
95  if (!weatherManager)
96  return;
97 
98  WeatherStateTransitionManager weatherTransitionManager = weatherManager.GetTransitionManager();
99  if (!weatherTransitionManager)
100  return;
101 
102  //Remove preview
103  if (weatherTransitionManager.IsPreviewingState())
104  weatherManager.SetWeatherStatePreview(false);
105  }
106  }
107 
108  protected override void CreatePresets()
109  {
110  m_aValues.Clear();
111 
113 
114  array<ref WeatherState> weatherStates = new array<ref WeatherState>;
115  ChimeraWorld world = GetGame().GetWorld();
116  TimeAndWeatherManagerEntity weatherManager = world.GetTimeAndWeatherManager();
117  if (!weatherManager)
118  return;
119 
120  weatherManager.GetWeatherStatesList(weatherStates);
121 
122  int count = weatherStates.Count();
123  string weatherName, weatherIconPath;
124 
125  //Create preset list
126  for (int i = 0; i < count; i++)
127  {
129 
130  weatherName = weatherStates[i].GetLocalizedName();
131  weatherIconPath = weatherStates[i].GetIconPath();
132 
133  if (SCR_StringHelper.IsEmptyOrWhiteSpace(weatherName))
134  {
135  weatherName = m_sUnknownWeatherName;
136  Print("WeatherState: '" + weatherStates[i].GetStateID() + "' does not have weather localization name assigned!", LogLevel.ERROR);
137  }
138 
139 
140  if (SCR_StringHelper.IsEmptyOrWhiteSpace(weatherIconPath))
141  {
142  weatherIconPath = m_sUnknownWeatherIcon;
143  Print("WeatherState: '" + weatherStates[i].GetStateID() + "' does not have weather icon assigned!", LogLevel.ERROR);
144  }
145 
146  value.SetName(weatherName);
147  value.SetIcon(weatherIconPath);
148  value.SetFloatValue(weatherStates[i].GetStateID());
149 
150  m_aValues.Insert(value);
151  }
152  }
153 };
WeatherStateTransitionManager
Definition: WeatherStateTransitionManager.c:7
ChimeraWorld
Definition: ChimeraWorld.c:12
m_aValues
SCR_BaseEditorAttributeEntryTimeSlider m_aValues
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_WeatherInstantTransitionTimeEditorAttribute
Definition: SCR_WeatherInstantTransitionTimeEditorAttribute.c:7
SCR_WeatherInstantEditorAttribute
Definition: SCR_WeatherInstantEditorAttribute.c:5
SCR_StringHelper
Definition: SCR_StringHelper.c:1
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_BaseEditorAttributeCustomTitle
Definition: SCR_BaseEditorAttribute.c:868
SCR_BaseEditorAttributeVar
Definition: SCR_BaseEditorAttributeVar.c:1
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_EditorAttributeFloatStringValueHolder
Definition: SCR_BaseFloatValueHolderEditorAttribute.c:17
SCR_BasePresetsEditorAttribute
Definition: SCR_BasePresetsEditorAttribute.c:5
LocalizedString
Definition: LocalizedString.c:21
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