Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BaseEditorComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Editor", insertable: false)]
2 class SCR_BaseEditorComponentClass: ScriptComponentClass
3 {
4  [Attribute(category: "Effects")]
5  private ref array<ref SCR_BaseEditorEffect> m_EffectsActivate;
6 
7  [Attribute(category: "Effects")]
8  private ref array<ref SCR_BaseEditorEffect> m_EffectsDeactivate;
9 
10  //------------------------------------------------------------------------------------------------
12  array<ref SCR_BaseEditorEffect> GetEffectsActivate()
13  {
14  return m_EffectsActivate;
15  }
16 
17  //------------------------------------------------------------------------------------------------
19  array<ref SCR_BaseEditorEffect> GetEffectsDeactivate()
20  {
21  return m_EffectsDeactivate;
22  }
23 
24  //------------------------------------------------------------------------------------------------
29  static SCR_BaseEditorComponentClass GetInstance(typename type, bool showError)
30  {
31  SCR_BaseEditorComponent component = SCR_BaseEditorComponent.Cast(SCR_BaseEditorComponent.GetInstance(type, showError));
32  if (component)
33  return SCR_BaseEditorComponentClass.Cast(component.GetEditorComponentData());
34  else
35  return null;
36  }
37 };
38 
40 
120 {
121  protected SCR_EditorBaseEntity m_Owner;
122  protected SCR_EditorManagerEntity m_Manager;
123  protected SCR_BaseEditorComponent m_Parent;
124  protected RplComponent m_RplComponent;
125  private bool m_bOpen;
126 
127  private ref ScriptInvoker m_OnEffect;
128 
133 
134  //------------------------------------------------------------------------------------------------
136  protected void EOnEditorInit();
137 
138  //------------------------------------------------------------------------------------------------
140  protected void EOnEditorDelete();
141 
142  //------------------------------------------------------------------------------------------------
144  protected void EOnEditorRequest(bool isOpen);
145 
146  //------------------------------------------------------------------------------------------------
148  protected void EOnEditorOpen();
149 
150  //------------------------------------------------------------------------------------------------
152  protected void EOnEditorClose();
153 
154  //------------------------------------------------------------------------------------------------
158  protected void EOnEditorPreActivate();
159 
160  //------------------------------------------------------------------------------------------------
164  protected void EOnEditorActivate();
165 
166  //------------------------------------------------------------------------------------------------
170  protected bool EOnEditorActivateAsync(int attempt)
171  {
172  return true;
173  }
174 
175  //------------------------------------------------------------------------------------------------
177  protected void EOnEditorPostActivate();
178 
179  //------------------------------------------------------------------------------------------------
183  protected void EOnEditorDeactivate();
184 
185  //------------------------------------------------------------------------------------------------
189  protected bool EOnEditorDeactivateAsync(int attempt)
190  {
191  return true;
192  }
193 
194  //------------------------------------------------------------------------------------------------
196  protected void EOnEditorPostDeactivate();
197 
198  //------------------------------------------------------------------------------------------------
200  protected void EOnEditorDebug(array<string> debugTexts);
201 
202  //------------------------------------------------------------------------------------------------
204  protected void EOnEffect(SCR_BaseEditorEffect effect);
206 
211 
212  //------------------------------------------------------------------------------------------------
214  protected void EOnEditorInitServer();
215 
216  //------------------------------------------------------------------------------------------------
218  protected void EOnEditorDeleteServer();
219 
220  //------------------------------------------------------------------------------------------------
222  protected void EOnEditorOpenServer();
223 
224  //------------------------------------------------------------------------------------------------
226  protected void EOnEditorOpenServerCallback();
227 
228  //------------------------------------------------------------------------------------------------
230  protected void EOnEditorCloseServer();
231 
232  //------------------------------------------------------------------------------------------------
234  protected void EOnEditorCloseServerCallback();
235 
236  //------------------------------------------------------------------------------------------------
240  protected void EOnEditorActivateServer();
241 
242  //------------------------------------------------------------------------------------------------
246  protected void EOnEditorDeactivateServer();
248 
250  //--- Event handlers
252 
253  //------------------------------------------------------------------------------------------------
254  sealed void OnInitBase()
255  {
256  EOnEditorInit();
257  }
258 
259  //------------------------------------------------------------------------------------------------
260  sealed void OnDeleteBase()
261  {
262  EOnEditorDelete();
263  }
264 
265  //------------------------------------------------------------------------------------------------
267  sealed void OnRequestBase(bool isOpen)
268  {
269  EOnEditorRequest(isOpen);
270  }
271 
272  //------------------------------------------------------------------------------------------------
273  sealed void OnOpenedBase()
274  {
275  m_bOpen = true;
276  EOnEditorOpen();
277  }
278 
279  //------------------------------------------------------------------------------------------------
280  sealed void OnClosedBase()
281  {
282  m_bOpen = false;
283  //OnDeactivateBase();
284  EOnEditorClose();
285  }
286 
287  //------------------------------------------------------------------------------------------------
288  sealed void OnPreActivateBase()
289  {
290  EOnEditorPreActivate();
291  }
292 
293  //------------------------------------------------------------------------------------------------
294  sealed void OnActivateBase()
295  {
296  Activate(m_Owner);
297  //SetEventMask(m_Owner, EntityEvent.FRAME);
299  }
300 
301  //------------------------------------------------------------------------------------------------
304  sealed bool OnActivateAsyncBase(int attempt)
305  {
306  return EOnEditorActivateAsync(attempt);
307  }
308 
309  //------------------------------------------------------------------------------------------------
310  sealed void OnPostActivateBase()
311  {
312  EOnEditorPostActivate();
313 
314  SCR_BaseEditorComponentClass prefabData = SCR_BaseEditorComponentClass.Cast(GetEditorComponentData());
315  if (prefabData)
316  SCR_BaseEditorEffect.Activate(prefabData.GetEffectsActivate(), this);
317  }
318 
319  //------------------------------------------------------------------------------------------------
320  sealed void OnDeactivateBase()
321  {
322  if (!IsActive())
323  return;
324 
325  //--- Deactivate only when it's not being deleted, so that proper cleanup can be arranged in destructor
326  if (!GetOwner().IsDeleted())
328 
330 
331  SCR_BaseEditorComponentClass prefabData = SCR_BaseEditorComponentClass.Cast(GetEditorComponentData());
332  if (prefabData)
333  SCR_BaseEditorEffect.Activate(prefabData.GetEffectsDeactivate(), this);
334  }
335 
336  //------------------------------------------------------------------------------------------------
337  sealed void OnPostDeactivateBase()
338  {
339  EOnEditorPostDeactivate();
340  }
341 
342  //------------------------------------------------------------------------------------------------
345  sealed bool OnDeactivateAsyncBase(int attempt)
346  {
347  return EOnEditorDeactivateAsync(attempt);
348  }
349 
350  //------------------------------------------------------------------------------------------------
352  sealed void OnEffectBase(SCR_BaseEditorEffect effect)
353  {
354  EOnEffect(effect);
355  }
356 
358  //--- Custom functions
360 
361  //------------------------------------------------------------------------------------------------
368  static Managed GetInstance(typename type, bool showError = false, bool modeFirst = false)
369  {
370  //--- Find the component in Editor Manager entity
371  SCR_EditorManagerEntity editorManager = SCR_EditorManagerEntity.GetInstance();
372  if (!editorManager)
373  {
374  if (showError)
375  Print(string.Format("Cannot find editor component '%1', local instance of editor manager not found!", type), LogLevel.ERROR);
376  return null;
377  }
378 
379  Managed component = editorManager.FindComponent(type);
380  if (component && !modeFirst)
381  return component;
382 
383  //--- Find the component in Editor Mode entity
384  SCR_EditorModeEntity editorMode = SCR_EditorModeEntity.GetInstance();
385  if (editorMode)
386  {
387  Managed componentMode = editorMode.FindComponent(type);
388  if (componentMode)
389  {
390  return componentMode;
391  }
392  else if (showError)
393  {
394  Print(string.Format("Cannot find editor component '%1' on local instance of editor manager or on the curent editor mode!", type), LogLevel.ERROR);
395  }
396  }
397  else if (showError)
398  {
399  Print(string.Format("Cannot find editor component '%1' on local instance of editor manager, and no current editor mode exists!", type), LogLevel.ERROR);
400  }
401  return component;
402  }
403 
404  //------------------------------------------------------------------------------------------------
411  static Managed GetInstance(SCR_EditorBaseEntity editorManager, typename type, bool showError = false)
412  {
413  Managed component = editorManager.FindComponent(type);
414  if (component)
415  return component;
416 
417  SCR_EditorModeEntity editorMode = SCR_EditorModeEntity.Cast(editorManager);
418  if (!editorMode)
419  return null;
420 
421  editorManager = editorMode.GetManager();
422  if (!editorManager)
423  return null;
424 
425  return editorManager.FindComponent(type);
426  }
427 
428  //------------------------------------------------------------------------------------------------
433  static int GetAllInstances(typename type, out notnull array<Managed> outComponents)
434  {
435  outComponents.Clear();
436 
437  SCR_EditorManagerEntity editorManager = SCR_EditorManagerEntity.GetInstance();
438  if (!editorManager)
439  return 0;
440 
441  Managed component = editorManager.FindComponent(type);
442  if (component)
443  outComponents.Insert(component);
444 
445  array<SCR_EditorModeEntity> modeEntities = {};
446  int modesCount = editorManager.GetModeEntities(modeEntities);
447  for (int i = 0; i < modesCount; i++)
448  {
449  component = modeEntities[i].FindComponent(type);
450  if (component)
451  outComponents.Insert(component);
452  }
453  return outComponents.Count();
454  }
455 
456  //------------------------------------------------------------------------------------------------
459  SCR_EditorManagerEntity GetManager()
460  {
461  if (!m_Owner)
462  return null;
463 
465  if (!manager)
466  manager = m_Owner.GetManager();
467 
468  return manager;
469  }
470 
471  //------------------------------------------------------------------------------------------------
477  SCR_BaseEditorComponent FindEditorComponent(typename type, bool showError = false, bool modeFirst = false)
478  {
479  //--- Find the component in Editor Manager entity
480  SCR_EditorManagerEntity editorManager = GetManager();
481  if (!editorManager)
482  {
483  if (showError)
484  Print(string.Format("Cannot find editor component '%1', local instance of editor manager not found!", type), LogLevel.ERROR);
485  return null;
486  }
487 
488  SCR_BaseEditorComponent component = SCR_BaseEditorComponent.Cast(editorManager.FindComponent(type));
489  if (component && !modeFirst)
490  return component;
491 
492  //--- Find the component in Editor Mode entity
493  SCR_EditorModeEntity editorMode = editorManager.GetCurrentModeEntity();
494  if (editorMode)
495  {
496  SCR_BaseEditorComponent componentMode = SCR_BaseEditorComponent.Cast(editorMode.FindComponent(type));
497  if (componentMode)
498  {
499  component = componentMode;
500  }
501  else if (showError && !component)
502  {
503  Print(string.Format("Cannot find editor component '%1' on local instance of editor manager or on the curent editor mode!", type), LogLevel.ERROR);
504  }
505  }
506  else if (showError && !component)
507  {
508  Print(string.Format("Cannot find editor component '%1' on local instance of editor manager, and no current editor mode exists!", type), LogLevel.ERROR);
509  }
510  return component;
511  }
512 
513  //------------------------------------------------------------------------------------------------
516  EntityComponentPrefabData GetEditorComponentData()
517  {
518  if (m_Owner)
519  return GetComponentData(m_Owner);
520  else
521  return null;
522  }
523 
524  //------------------------------------------------------------------------------------------------
528  bool IsRemoved()
529  {
530  return !m_Owner || m_Owner.IsRemoved();
531  }
532 
533  //------------------------------------------------------------------------------------------------
537  void ResetEditorComponent();
538 
539  //------------------------------------------------------------------------------------------------
542  ScriptInvoker GetOnEffect()
543  {
544  if (!m_OnEffect)
545  m_OnEffect = new ScriptInvoker();
546 
547  return m_OnEffect;
548  }
549 
550  //------------------------------------------------------------------------------------------------
551  protected bool IsOnEditorManager()
552  {
553  return m_Owner && m_Owner.IsInherited(SCR_EditorManagerEntity);
554  }
555 
556  //------------------------------------------------------------------------------------------------
557  protected bool IsOwner()
558  {
559  return m_RplComponent && m_RplComponent.IsOwner();
560  }
561 
562  //------------------------------------------------------------------------------------------------
563  protected bool IsProxy()
564  {
565  return m_RplComponent && m_RplComponent.IsProxy();
566  }
567 
568  //------------------------------------------------------------------------------------------------
569  protected bool IsMaster()
570  {
571  return m_RplComponent && m_RplComponent.IsMaster();
572  }
573 
574  //------------------------------------------------------------------------------------------------
575  protected bool IsAdmin()
576  {
577  //--- ToDo: Proper admin detection once admin feature is implemented
578  return SCR_Global.IsAdmin(GetManager().GetPlayerID()) && Replication.IsRunning();
579  }
580 
581  //------------------------------------------------------------------------------------------------
582  protected SCR_BaseEditorComponent GetParentComponent()
583  {
584  return m_Parent;
585  }
586 
587  //------------------------------------------------------------------------------------------------
588  protected void SetParentComponent(SCR_BaseEditorComponent parent)
589  {
590  if (m_Parent)
591  return;
592 
593  m_Parent = parent;
594  }
595 
596  //------------------------------------------------------------------------------------------------
597  //If target Entity is given then location is used to target position unless: m_bSetLocationOnce is true in the data found in m_aNotificationDisplayInfos (SCR_NotificationManagerEditorComponent on the EditorManager)
598  protected void SendNotification(ENotification notificationID, int selfID = 0, int targetID = 0, vector position = vector.Zero)
599  {
600  //Send notification
601  SCR_NotificationsComponent.SendLocal(notificationID, position, selfID, targetID);
602  }
603 
604  //------------------------------------------------------------------------------------------------
606  void InitServer()
607  {
608  if (!m_Owner)
609  return;
610 
611  if (m_Owner.GetOnOpenedServer())
612  m_Owner.GetOnOpenedServer().Insert(EOnEditorOpenServer);
613 
614  if (m_Owner.GetOnOpenedServerCallback())
615  m_Owner.GetOnOpenedServerCallback().Insert(EOnEditorOpenServerCallback);
616 
617  if (m_Owner.GetOnActivateServer())
618  m_Owner.GetOnActivateServer().Insert(EOnEditorActivateServer);
619 
620  if (m_Owner.GetOnDeactivateServer())
621  m_Owner.GetOnDeactivateServer().Insert(EOnEditorDeactivateServer);
622 
623  if (m_Owner.GetOnClosedServer())
624  m_Owner.GetOnClosedServer().Insert(EOnEditorCloseServer);
625 
626  if (m_Owner.GetOnClosedServerCallback())
627  m_Owner.GetOnClosedServerCallback().Insert(EOnEditorCloseServerCallback);
628 
630  }
631 
632  //------------------------------------------------------------------------------------------------
634  void InitOwner()
635  {
636  if (!m_Owner)
637  return;
638 
639  //if (m_Owner.GetOnInit()) m_Owner.GetOnInit().Insert(OnInitBase);
640  //if (m_Owner.GetOnRequest()) m_Owner.GetOnRequest().Insert(OnRequestBase);
641  //if (m_Owner.GetOnOpened()) m_Owner.GetOnOpened().Insert(OnOpenedBase);
642  //if (m_Owner.GetOnPreActivate()) m_Owner.GetOnPreActivate().Insert(OnPreActivateBase);
643  //if (m_Owner.GetOnActivate()) m_Owner.GetOnActivate().Insert(OnActivateBase);
644  //if (m_Owner.GetOnPostActivate()) m_Owner.GetOnPostActivate().Insert(OnPostActivateBase);
645  //if (m_Owner.GetOnDeactivate()) m_Owner.GetOnDeactivate().Insert(OnDeactivateBase);
646  //if (m_Owner.GetOnClosed()) m_Owner.GetOnClosed().Insert(OnClosedBase);
647  if (m_Owner.GetOnDebug())
648  m_Owner.GetOnDebug().Insert(EOnEditorDebug);
649 
650  m_Manager = SCR_EditorManagerEntity.Cast(m_Owner);
651  if (!m_Manager)
652  m_Manager = m_Owner.GetManager();
653 
654 // if (m_Owner.IsOpened())
655 // {
656 // OnInitBase();
657 // OnOpenedBase();
658 // }
659  }
660 
662  //--- Default functions
664 
665  //------------------------------------------------------------------------------------------------
666  override void OnPostInit(IEntity owner)
667  {
668  if (!m_Owner)
669  return;
670 
671  m_RplComponent = RplComponent.Cast(m_Owner.FindComponent(RplComponent)); //--- Must be here, it's too early in the constructor
672  }
673 
674  //------------------------------------------------------------------------------------------------
675  // constructor
679  void SCR_BaseEditorComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
680  {
681  if (SCR_Global.IsEditMode(ent)) //--- Run-time only
682  return;
683 
684  m_Owner = SCR_EditorBaseEntity.Cast(ent);
685  if (!m_Owner)
686  {
687  Print("SCR_BaseEditorComponent must be attached to SCR_EditorBaseEntity!", LogLevel.ERROR);
688  return;
689  }
690 
691  Deactivate(null);
692  }
693 
694  //------------------------------------------------------------------------------------------------
695  // destructor
697  {
698  if (Replication.IsServer())
699  EOnEditorDeleteServer();
700  }
701 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
EOnEditorInitServer
override void EOnEditorInitServer()
Definition: SCR_AttributesManagerEditorComponent.c:997
EOnEditorOpenServer
override protected void EOnEditorOpenServer()
Definition: SCR_CampaignBuildingEditorComponent.c:519
EOnEditorDebug
override void EOnEditorDebug(array< string > debugTexts)
Definition: SCR_AccessKeysEditorComponent.c:191
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
EOnEditorClose
override protected void EOnEditorClose()
Definition: SCR_CampaignBuildingPlacingEditorComponent.c:352
EOnEditorDeactivate
override void EOnEditorDeactivate()
Definition: SCR_AttributesManagerEditorComponent.c:974
EOnEditorInit
override void EOnEditorInit()
Definition: SCR_AccessKeysEditorComponent.c:265
EOnEditorDeactivateServer
override protected void EOnEditorDeactivateServer()
Definition: SCR_CampaignBuildingPlacingEditorComponent.c:387
SCR_EditorModeEntity
Definition: SCR_EditorModeEntity.c:22
EOnEditorCloseServer
override protected void EOnEditorCloseServer()
Definition: SCR_CampaignBuildingEditorComponent.c:539
GetPlayerID
override int GetPlayerID()
Definition: SCR_EditableCharacterComponent.c:484
ENotification
ENotification
Definition: ENotification.c:4
SCR_BaseEditorComponent
Definition: SCR_BaseEditorComponent.c:119
Attribute
typedef Attribute
Post-process effect of scripted camera.
EOnEditorOpen
SCR_BaseEditorServerComponentClass EOnEditorOpen
EOnEditorActivateServer
protected override void EOnEditorActivateServer()
Definition: SCR_CampaignBuildingBudgetEditorComponent.c:16
Deactivate
protected void Deactivate()
Definition: SCR_BaseHintCondition.c:27
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
Activate
protected void Activate()
Definition: SCR_BaseHintCondition.c:9
SCR_BaseEditorComponentClass
Definition: SCR_BaseEditorComponent.c:2
m_RplComponent
protected RplComponent m_RplComponent
Definition: SCR_CampaignBuildingManagerComponent.c:42
SCR_Global
Definition: Functions.c:6
EOnEditorActivate
override protected void EOnEditorActivate()
Definition: SCR_AccessKeysEditorComponent.c:259
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
EOnEditorDelete
override protected void EOnEditorDelete()
Definition: SCR_AccessKeysEditorComponent.c:295
SCR_EditorBaseEntity
Definition: SCR_EditorBaseEntity.c:14
position
vector position
Definition: SCR_DestructibleTreeV2.c:30
IsActive
bool IsActive()
Definition: SCR_LoadoutSaveBlackListHolder.c:82
m_Owner
SCR_AIGroupUtilityComponentClass m_Owner
SCR_BaseEditorEffect
Definition: SCR_BaseEditorEffect.c:7
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26