Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SaveManualCameraComponent.c
Go to the documentation of this file.
1 
4 [BaseContainerProps(), SCR_BaseManualCameraComponentTitle()]
6 {
7  [Attribute(params: "layout")]
8  protected ResourceName m_LayoutSave;
9 
10  [Attribute(params: "layout")]
11  protected ResourceName m_LayoutLoad;
12 
13  [Attribute("5")]
14  protected float m_fFadeInSpeed;
15 
16  private Widget m_WidgetSave;
17  private Widget m_WidgetLoad;
18 
19  protected void SaveCamera1() { SaveCamera(1); }
20  protected void SaveCamera2() { SaveCamera(2); }
21  protected void SaveCamera3() { SaveCamera(3); }
22  protected void SaveCamera4() { SaveCamera(4); }
23  protected void SaveCamera5() { SaveCamera(5); }
24  protected void SaveCamera6() { SaveCamera(6); }
25  protected void SaveCamera7() { SaveCamera(7); }
26  protected void SaveCamera8() { SaveCamera(8); }
27  //protected void SaveCamera9() { SaveCamera(9); }
28 
29  //------------------------------------------------------------------------------------------------
30  protected void SaveCamera(int index)
31  {
33  ResourceName worldPath = GetGame().GetWorldFile();// SCR_Global.GetRootWorld(); //--- Does not return ResourceName, TODO: use it again when it does
34  if (!worldPath)
35  {
36  Print("Unable to save camera data, world path not found!", LogLevel.WARNING);
37  return;
38  }
39 
41  BaseContainer settingsContainer = GetGame().GetGameUserSettings().GetModule("SCR_ManualCameraSettings");
42  BaseContainerTools.WriteToInstance(settings, settingsContainer);
43 
44  if (!settings.m_aSavedData)
45  settings.m_aSavedData = {};
46 
47  //--- Find existing save, and override it if found
49  foreach (SCR_ManualCameraSave saveCandidate: settings.m_aSavedData)
50  {
51  if (saveCandidate.m_iIndex == index && saveCandidate.m_sWorldPath == worldPath)
52  save = saveCandidate;
53  }
54 
55  //---- Save on given world with given index does not exist, create it
56  if (!save)
57  {
58  save = new SCR_ManualCameraSave();
59  settings.m_aSavedData.Insert(save);
60  }
61 
62  //--- Store data
63  save.m_sWorldPath = worldPath;
64  save.m_iIndex = index;
65  save.m_aComponentData = {};
66  camera.SaveComponents(save.m_aComponentData);
67 
68  //--- Save to settings
69  BaseContainerTools.ReadFromInstance(settings, settingsContainer);
70  GetGame().UserSettingsChanged();
71 
72  PlayAnimation(m_WidgetSave);
73 
74  SCR_NotificationsComponent.SendLocal(ENotification.EDITOR_SAVED_CAMERA_POSITION, index);
75  //Print(string.Format("Camera params #%1 saved", index), LogLevel.VERBOSE);
76  }
77 
78  protected void LoadCamera1() { LoadCamera(1); }
79  protected void LoadCamera2() { LoadCamera(2); }
80  protected void LoadCamera3() { LoadCamera(3); }
81  protected void LoadCamera4() { LoadCamera(4); }
82  protected void LoadCamera5() { LoadCamera(5); }
83  protected void LoadCamera6() { LoadCamera(6); }
84  protected void LoadCamera7() { LoadCamera(7); }
85  protected void LoadCamera8() { LoadCamera(8); }
86  //protected void LoadCamera9() { LoadCamera(9); }
87 
88  //------------------------------------------------------------------------------------------------
89  protected void LoadCamera(int index)
90  {
91  ResourceName worldPath = GetGame().GetWorldFile();// SCR_Global.GetRootWorld(); //--- Does not return ResourceName, TODO: use it again when it does
92  if (!worldPath)
93  {
94  Print("Unable to save camera data, world path not found!", LogLevel.WARNING);
95  return;
96  }
97 
99  BaseContainer settingsContainer = GetGame().GetGameUserSettings().GetModule("SCR_ManualCameraSettings");
100  BaseContainerTools.WriteToInstance(settings, settingsContainer);
101 
102  if (!settings.m_aSavedData)
103  return;
104 
105  settings.m_aSavedData.Debug();
106 
107  //--- Apply saved values to components
109  foreach (SCR_ManualCameraSave saveCandidate: settings.m_aSavedData)
110  {
111  Print(string.Format("%1 == %2 && %3 == %4", saveCandidate.m_iIndex, index, saveCandidate.m_sWorldPath, worldPath), LogLevel.NORMAL);
112  if (saveCandidate.m_iIndex == index && saveCandidate.m_sWorldPath == worldPath)
113  {
114  camera.LoadComponents(saveCandidate.m_aComponentData);
115 
116  //--- Stop inertia
117  m_Camera.GetCameraParam().velocityOriginal = vector.Zero;
118 
119  PlayAnimation(m_WidgetLoad);
120 
121  SCR_NotificationsComponent.SendLocal(ENotification.EDITOR_LOADED_CAMERA_POSITION, index);
122  //Print(string.Format("Camera params #%1 loaded", index), LogLevel.VERBOSE);
123  }
124  }
125  }
126 
127  //------------------------------------------------------------------------------------------------
128  override bool EOnCameraInit()
129  {
130  InputManager inputManager = GetGame().GetInputManager();
131  if (!inputManager)
132  return false;
133 
134  inputManager.AddActionListener("ManualCameraSave1", EActionTrigger.DOWN, SaveCamera1);
135  inputManager.AddActionListener("ManualCameraSave2", EActionTrigger.DOWN, SaveCamera2);
136  inputManager.AddActionListener("ManualCameraSave3", EActionTrigger.DOWN, SaveCamera3);
137  inputManager.AddActionListener("ManualCameraSave4", EActionTrigger.DOWN, SaveCamera4);
138  inputManager.AddActionListener("ManualCameraSave5", EActionTrigger.DOWN, SaveCamera5);
139  inputManager.AddActionListener("ManualCameraSave6", EActionTrigger.DOWN, SaveCamera6);
140  inputManager.AddActionListener("ManualCameraSave7", EActionTrigger.DOWN, SaveCamera7);
141  inputManager.AddActionListener("ManualCameraSave8", EActionTrigger.DOWN, SaveCamera8);
142  //inputManager.AddActionListener("ManualCameraSave9", EActionTrigger.DOWN, SaveCamera9);
143 
144  inputManager.AddActionListener("ManualCameraLoad1", EActionTrigger.DOWN, LoadCamera1);
145  inputManager.AddActionListener("ManualCameraLoad2", EActionTrigger.DOWN, LoadCamera2);
146  inputManager.AddActionListener("ManualCameraLoad3", EActionTrigger.DOWN, LoadCamera3);
147  inputManager.AddActionListener("ManualCameraLoad4", EActionTrigger.DOWN, LoadCamera4);
148  inputManager.AddActionListener("ManualCameraLoad5", EActionTrigger.DOWN, LoadCamera5);
149  inputManager.AddActionListener("ManualCameraLoad6", EActionTrigger.DOWN, LoadCamera6);
150  inputManager.AddActionListener("ManualCameraLoad7", EActionTrigger.DOWN, LoadCamera7);
151  inputManager.AddActionListener("ManualCameraLoad8", EActionTrigger.DOWN, LoadCamera8);
152  //inputManager.AddActionListener("ManualCameraLoad9", EActionTrigger.DOWN, LoadCamera9);
153 
154  if (m_LayoutSave)
155  {
156  m_WidgetSave = GetCameraEntity().CreateCameraWidget(m_LayoutSave);
157  m_WidgetSave.SetOpacity(0);
158  }
159 
160  if (m_LayoutLoad)
161  {
162  m_WidgetLoad = GetCameraEntity().CreateCameraWidget(m_LayoutLoad);
163  m_WidgetLoad.SetOpacity(0);
164  }
165 
166  return false;
167  }
168 
169  //------------------------------------------------------------------------------------------------
170  protected void PlayAnimation(Widget widget)
171  {
172  if (widget)
173  {
174  widget.SetOpacity(1);
175  AnimateWidget.Opacity(widget, 0, m_fFadeInSpeed);
176  }
177  }
178 
179  //------------------------------------------------------------------------------------------------
180  override void EOnCameraExit()
181  {
182  InputManager inputManager = GetGame().GetInputManager();
183  if (!inputManager)
184  return;
185 
186  inputManager.RemoveActionListener("ManualCameraSave1", EActionTrigger.DOWN, SaveCamera1);
187  inputManager.RemoveActionListener("ManualCameraSave2", EActionTrigger.DOWN, SaveCamera2);
188  inputManager.RemoveActionListener("ManualCameraSave3", EActionTrigger.DOWN, SaveCamera3);
189  inputManager.RemoveActionListener("ManualCameraSave4", EActionTrigger.DOWN, SaveCamera4);
190  inputManager.RemoveActionListener("ManualCameraSave5", EActionTrigger.DOWN, SaveCamera5);
191  inputManager.RemoveActionListener("ManualCameraSave6", EActionTrigger.DOWN, SaveCamera6);
192  inputManager.RemoveActionListener("ManualCameraSave7", EActionTrigger.DOWN, SaveCamera7);
193  inputManager.RemoveActionListener("ManualCameraSave8", EActionTrigger.DOWN, SaveCamera8);
194  //inputManager.RemoveActionListener("ManualCameraSave9", EActionTrigger.DOWN, SaveCamera9);
195 
196  inputManager.RemoveActionListener("ManualCameraLoad1", EActionTrigger.DOWN, LoadCamera1);
197  inputManager.RemoveActionListener("ManualCameraLoad2", EActionTrigger.DOWN, LoadCamera2);
198  inputManager.RemoveActionListener("ManualCameraLoad3", EActionTrigger.DOWN, LoadCamera3);
199  inputManager.RemoveActionListener("ManualCameraLoad4", EActionTrigger.DOWN, LoadCamera4);
200  inputManager.RemoveActionListener("ManualCameraLoad5", EActionTrigger.DOWN, LoadCamera5);
201  inputManager.RemoveActionListener("ManualCameraLoad6", EActionTrigger.DOWN, LoadCamera6);
202  inputManager.RemoveActionListener("ManualCameraLoad7", EActionTrigger.DOWN, LoadCamera7);
203  inputManager.RemoveActionListener("ManualCameraLoad8", EActionTrigger.DOWN, LoadCamera8);
204  //inputManager.RemoveActionListener("ManualCameraLoad9", EActionTrigger.DOWN, LoadCamera9);
205 
206  if (m_WidgetSave)
207  m_WidgetSave.RemoveFromHierarchy();
208 
209  if (m_WidgetLoad)
210  m_WidgetLoad.RemoveFromHierarchy();
211  }
212 }
SCR_ManualCamera
Definition: SCR_ManualCamera.c:16
SCR_BaseManualCameraComponent
Parent class from which all SCR_ManualCamera components inherit.
Definition: SCR_BaseManualCameraComponent.c:5
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SaveManualCameraComponent
Persistently save/load camera params.
Definition: SCR_SaveManualCameraComponent.c:5
m_Camera
protected SCR_ManualCamera m_Camera
Definition: SCR_BaseManualCameraComponent.c:14
ENotification
ENotification
Definition: ENotification.c:4
Attribute
typedef Attribute
Post-process effect of scripted camera.
GetCameraEntity
protected SCR_ManualCamera GetCameraEntity()
Definition: SCR_BaseManualCameraComponent.c:59
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_ManualCameraSave
Definition: SCR_ManualCameraSave.c:2
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_ManualCameraSettings
Definition: SCR_ManualCameraSettings.c:1
m_fFadeInSpeed
protected float m_fFadeInSpeed
Definition: SCR_TooltipManagerEditorUIComponent.c:11
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