Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_DateEditorAttribute.c
Go to the documentation of this file.
3 {
4  //TODO: Needs proper system to know the order of dmy
5  [Attribute(defvalue: "dmy", desc: "The order in which days, months and years appear. this could be dmy ymd mdy etc. This is a temporary system until a more permanent solution is added")]
6  protected string m_sDateFormatOrder;
7 
8  [Attribute(uiwidget: UIWidgets.LocaleEditBox, defvalue: "#AR-Date_Day")]
9  protected LocalizedString m_sDayLabel;
10 
11  [Attribute(uiwidget: UIWidgets.LocaleEditBox, defvalue: "#AR-Date_Month")]
12  protected LocalizedString m_sMonthLabel;
13 
14  [Attribute(uiwidget: UIWidgets.LocaleEditBox, defvalue: "#AR-Date_Year")]
15  protected LocalizedString m_sYearLabel;
16 
17  [Attribute(uiwidget: UIWidgets.LocaleEditBox)]
18  protected ref array<ref LocalizedString> m_aMonthList;
19 
20  [Attribute(defvalue: "1940")]
21  protected int m_iYearStartDate;
22  [Attribute(defvalue: "1995")]
23  protected int m_iYearEndDate;
24 
25  ref array<ref int> m_aYearArray = new array<ref int>();
26 
27 
28  override SCR_BaseEditorAttributeVar ReadVariable(Managed item, SCR_AttributesManagerEditorComponent manager)
29  {
30  //If opened in global attributes
31  if (!IsGameMode(item))
32  return null;
33 
34  GenericEntity ent = GenericEntity.Cast(item);
35  ChimeraWorld world = ent.GetWorld();
36  TimeAndWeatherManagerEntity timeManager = world.GetTimeAndWeatherManager();
37  if (!timeManager)
38  return null;
39 
40  //Get date
41  vector date = Vector(timeManager.GetDay() -1, timeManager.GetMonth() -1, GetYearIndex(timeManager.GetYear()));
42  return SCR_BaseEditorAttributeVar.CreateVector(date);
43  }
44 
45  override void WriteVariable(Managed item, SCR_BaseEditorAttributeVar var, SCR_AttributesManagerEditorComponent manager, int playerID)
46  {
47  if (!var) return;
48 
49  GenericEntity ent = GenericEntity.Cast(item);
50  ChimeraWorld world = ent.GetWorld();
51  TimeAndWeatherManagerEntity timeManager = world.GetTimeAndWeatherManager();
52  if (!timeManager) return;
53 
54  CreateYearArray();
55  vector date = var.GetVector();
56  int day = date[0] +1;
57  int month = date[1] +1;
58  int year = m_aYearArray[date[2]];
59 
60  if (item)
61  {
62  SCR_NotificationsComponent.SendToUnlimitedEditorPlayers(ENotification.EDITOR_ATTRIBUTES_DATE_CHANGED, playerID, day, month, year);
63  }
64 
65  timeManager.SetDate(year, month, day);
66  }
67 
68  override void UpdateInterlinkedVariables(SCR_BaseEditorAttributeVar var, SCR_AttributesManagerEditorComponent manager, bool isInit = false)
69  {
70  if (!var || isInit)
71  return;
72 
73  //If date changed set time preset selected false
74  manager.SetAttributeSelected(SCR_TimePresetsEditorAttribute, false, -1);
75  }
76 
81  void GetYearArray(notnull out array<int> yearArray)
82  {
83  CreateYearArray();
84 
85  foreach(int year : m_aYearArray)
86  {
87  yearArray.Insert(year);
88  }
89  }
90 
91  protected void CreateYearArray()
92  {
93  if (m_aYearArray.Count() != 0)
94  return;
95 
96  ChimeraWorld world = GetGame().GetWorld();
97  TimeAndWeatherManagerEntity timeManager = world.GetTimeAndWeatherManager();
98  if (!timeManager)
99  return;
100 
101  int currentYear = timeManager.GetYear();
102 
103  //Safty
104  if (currentYear < m_iYearStartDate)
105  m_iYearStartDate = currentYear;
106  if (currentYear > m_iYearEndDate)
107  m_iYearEndDate = currentYear;
108  if (m_iYearEndDate <= m_iYearStartDate)
109  m_iYearEndDate = m_iYearStartDate +1;
110 
111  //Create year list
112  for (int y = m_iYearStartDate; y <= m_iYearEndDate; y++)
113  {
114  m_aYearArray.Insert(y);
115  }
116  }
117 
118  protected int GetYearIndex(int year)
119  {
120  CreateYearArray();
121 
122  if (m_aYearArray.Contains(year))
123  {
124  return m_aYearArray.Find(year);
125  }
126  else
127  {
128  return 0;
129  }
130  }
131 
132  /* Returns year by given index, called by SCR_DaytimeEditorAttribute preview
133  \param index given index
134  \return int year
135  */
136  int GetYearByIndex(int index)
137  {
138  CreateYearArray();
139 
140  if (index < 0 || index >= m_aYearArray.Count())
141  return 1990;
142 
143  return m_aYearArray[index];
144  }
145 
146  override int GetEntries(notnull array<ref SCR_BaseEditorAttributeEntry> outEntries)
147  {
148  outEntries.Insert(new SCR_BaseEditorAttributeEntryText(GetUIInfo().GetName()));
149  outEntries.Insert(new SCR_BaseEditorAttributeEntryText(m_sDateFormatOrder));
150  outEntries.Insert(new SCR_BaseEditorAttributeEntryText(m_sDayLabel));
151  outEntries.Insert(new SCR_BaseEditorAttributeEntryText(m_sMonthLabel));
152  outEntries.Insert(new SCR_BaseEditorAttributeEntryText(m_sYearLabel));
153  outEntries.Insert(new SCR_EditorAttributeEntryStringArray(m_aMonthList));
154 
155  CreateYearArray();
156  outEntries.Insert(new SCR_EditorAttributeEntryIntArray(m_aYearArray));
157  return outEntries.Count();
158  }
159 
160  override void PreviewVariable(bool setPreview, SCR_AttributesManagerEditorComponent manager)
161  {
162  if (!manager)
163  return;
164 
165  SCR_BaseEditorAttribute timeAttribute = manager.GetAttributeRef(SCR_DaytimeEditorAttribute);
166  if (timeAttribute)
167  timeAttribute.PreviewVariable(setPreview, manager);
168  }
169 };
ChimeraWorld
Definition: ChimeraWorld.c:12
GetName
string GetName()
Definition: SCR_ScenarioFrameworkLayerBase.c:85
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_DaytimeEditorAttribute
Definition: SCR_DaytimeEditorAttribute.c:5
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_DateEditorAttribute
Definition: SCR_DateEditorAttribute.c:2
SCR_BaseEditorAttributeCustomTitle
Definition: SCR_BaseEditorAttribute.c:868
SCR_TimePresetsEditorAttribute
Definition: SCR_TimePresetsEditorAttribute.c:5
ENotification
ENotification
Definition: ENotification.c:4
GetUIInfo
SCR_UIInfo GetUIInfo()
Definition: SCR_EditableEntityCampaignBuildingModeLabelSetting.c:27
SCR_BaseEditorAttributeVar
Definition: SCR_BaseEditorAttributeVar.c:1
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_BaseEditorAttribute
Base Attribute Script for other attributes to inherent from to get and set varriables in Editor Attri...
Definition: SCR_BaseEditorAttribute.c:3
SCR_BaseEditorAttributeEntryText
void SCR_BaseEditorAttributeEntryText(string text)
Definition: SCR_BaseEditorAttribute.c:486
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_EditorAttributeEntryIntArray
Definition: SCR_BaseEditorAttribute.c:711
SCR_EditorAttributeEntryStringArray
void SCR_EditorAttributeEntryStringArray(array< ref LocalizedString > values)
Definition: SCR_BaseEditorAttribute.c:691
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