Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_BaseEditorComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/Editor", insertable: false)]
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 {
32 if (component)
34 else
35 return null;
36 }
37};
38
40
120{
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 //------------------------------------------------------------------------------------------------
227
228 //------------------------------------------------------------------------------------------------
230 protected void EOnEditorCloseServer();
231
232 //------------------------------------------------------------------------------------------------
235
236 //------------------------------------------------------------------------------------------------
240 protected void EOnEditorActivateServer();
241
242 //------------------------------------------------------------------------------------------------
248
250 //--- Event handlers
252
253 //------------------------------------------------------------------------------------------------
254 sealed void OnInitBase()
255 {
257 }
258
259 //------------------------------------------------------------------------------------------------
260 sealed void OnDeleteBase()
261 {
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;
277 }
278
279 //------------------------------------------------------------------------------------------------
280 sealed void OnClosedBase()
281 {
282 m_bOpen = false;
283 //OnDeactivateBase();
285 }
286
287 //------------------------------------------------------------------------------------------------
288 sealed void OnPreActivateBase()
289 {
291 }
292
293 //------------------------------------------------------------------------------------------------
294 sealed void OnActivateBase()
295 {
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 {
313
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
332 if (prefabData)
333 SCR_BaseEditorEffect.Activate(prefabData.GetEffectsDeactivate(), this);
334 }
335
336 //------------------------------------------------------------------------------------------------
338 {
340 }
341
342 //------------------------------------------------------------------------------------------------
345 sealed bool OnDeactivateAsyncBase(int attempt)
346 {
347 return EOnEditorDeactivateAsync(attempt);
348 }
349
350 //------------------------------------------------------------------------------------------------
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 //------------------------------------------------------------------------------------------------
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 //------------------------------------------------------------------------------------------------
517 {
518 if (m_Owner)
520 else
521 return null;
522 }
523
524 //------------------------------------------------------------------------------------------------
529 {
530 return !m_Owner || m_Owner.IsDeleted();
531 }
532
533 //------------------------------------------------------------------------------------------------
538
539 //------------------------------------------------------------------------------------------------
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 //------------------------------------------------------------------------------------------------
583 {
584 return m_Parent;
585 }
586
587 //------------------------------------------------------------------------------------------------
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 //------------------------------------------------------------------------------------------------
607 {
608 if (!m_Owner)
609 return;
610
612 if (!m_Manager)
613 m_Manager = m_Owner.GetManager();
614
615 if (m_Owner.GetOnOpenedServer())
616 m_Owner.GetOnOpenedServer().Insert(EOnEditorOpenServer);
617
618 if (m_Owner.GetOnOpenedServerCallback())
619 m_Owner.GetOnOpenedServerCallback().Insert(EOnEditorOpenServerCallback);
620
621 if (m_Owner.GetOnActivateServer())
622 m_Owner.GetOnActivateServer().Insert(EOnEditorActivateServer);
623
624 if (m_Owner.GetOnDeactivateServer())
625 m_Owner.GetOnDeactivateServer().Insert(EOnEditorDeactivateServer);
626
627 if (m_Owner.GetOnClosedServer())
628 m_Owner.GetOnClosedServer().Insert(EOnEditorCloseServer);
629
630 if (m_Owner.GetOnClosedServerCallback())
631 m_Owner.GetOnClosedServerCallback().Insert(EOnEditorCloseServerCallback);
632
634 }
635
636 //------------------------------------------------------------------------------------------------
639 {
640 if (!m_Owner)
641 return;
642
643 //if (m_Owner.GetOnInit()) m_Owner.GetOnInit().Insert(OnInitBase);
644 //if (m_Owner.GetOnRequest()) m_Owner.GetOnRequest().Insert(OnRequestBase);
645 //if (m_Owner.GetOnOpened()) m_Owner.GetOnOpened().Insert(OnOpenedBase);
646 //if (m_Owner.GetOnPreActivate()) m_Owner.GetOnPreActivate().Insert(OnPreActivateBase);
647 //if (m_Owner.GetOnActivate()) m_Owner.GetOnActivate().Insert(OnActivateBase);
648 //if (m_Owner.GetOnPostActivate()) m_Owner.GetOnPostActivate().Insert(OnPostActivateBase);
649 //if (m_Owner.GetOnDeactivate()) m_Owner.GetOnDeactivate().Insert(OnDeactivateBase);
650 //if (m_Owner.GetOnClosed()) m_Owner.GetOnClosed().Insert(OnClosedBase);
651 if (m_Owner.GetOnDebug())
652 m_Owner.GetOnDebug().Insert(EOnEditorDebug);
653
655 if (!m_Manager)
656 m_Manager = m_Owner.GetManager();
657
658// if (m_Owner.IsOpened())
659// {
660// OnInitBase();
661// OnOpenedBase();
662// }
663 }
664
666 //--- Default functions
668
669 //------------------------------------------------------------------------------------------------
670 override void OnPostInit(IEntity owner)
671 {
672 if (!m_Owner)
673 return;
674
675 m_RplComponent = RplComponent.Cast(m_Owner.FindComponent(RplComponent)); //--- Must be here, it's too early in the constructor
676 }
677
678 //------------------------------------------------------------------------------------------------
679 // constructor
684 {
685 if (SCR_Global.IsEditMode(ent)) //--- Run-time only
686 return;
687
688 m_Owner = SCR_EditorBaseEntity.Cast(ent);
689 if (!m_Owner)
690 {
691 Print("SCR_BaseEditorComponent must be attached to SCR_EditorBaseEntity!", LogLevel.ERROR);
692 return;
693 }
694
695 Deactivate(null);
696 }
697
698 //------------------------------------------------------------------------------------------------
699 // destructor
701 {
702 if (Replication.IsServer())
704 }
705}
ENotification
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
void Deactivate()
void Activate()
SCR_CharacterSoundComponentClass GetComponentData()
EDamageType type
vector position
override int GetPlayerID()
void SCR_EditorManagerEntity(IEntitySource src, IEntity parent)
proto external bool IsActive()
Main replication API.
Definition Replication.c:14
void SCR_BaseEditorComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void EOnEditorDeleteServer()
When the entity is destroyed (called on server).
void EOnEditorOpen()
When the editor is opened.
void EOnEditorDelete()
When the entity is destroyed.
sealed void OnRequestBase(bool isOpen)
sealed bool OnActivateAsyncBase(int attempt)
void EOnEditorCloseServerCallback()
When the editor is closed (called on server after async loading finished on client).
sealed void OnEffectBase(SCR_BaseEditorEffect effect)
SCR_BaseEditorComponent GetParentComponent()
SCR_EditorManagerEntity m_Manager
void SetParentComponent(SCR_BaseEditorComponent parent)
void EOnEffect(SCR_BaseEditorEffect effect)
When an effect is created in reaction an an event.
bool EOnEditorActivateAsync(int attempt)
void EOnEditorCloseServer()
When the editor is closed (called on server).
static int GetAllInstances(typename type, out notnull array< Managed > outComponents)
static Managed GetInstance(typename type, bool showError=false, bool modeFirst=false)
void EOnEditorInit()
When the entity is created.
void EOnEditorInitServer()
When the entity is created (called on server).
EntityComponentPrefabData GetEditorComponentData()
void SendNotification(ENotification notificationID, int selfID=0, int targetID=0, vector position=vector.Zero)
void EOnEditorRequest(bool isOpen)
When opening/closing request is sent to server.
void EOnEditorOpenServer()
When the editor is opened (called on server).
void EOnEditorDebug(array< string > debugTexts)
Every frame while the editor is opened and debug menu is shown.
static Managed GetInstance(SCR_EditorBaseEntity editorManager, typename type, bool showError=false)
void EOnEditorClose()
When the editor is closed.
SCR_BaseEditorComponent m_Parent
SCR_BaseEditorComponent FindEditorComponent(typename type, bool showError=false, bool modeFirst=false)
void EOnEditorPostActivate()
When the component is activated, but after EOnEditorActivate() function was called in all components.
void EOnEditorOpenServerCallback()
When the editor is opened (called on server after async loading finished on client).
override void OnPostInit(IEntity owner)
SCR_EditorManagerEntity GetManager()
bool EOnEditorDeactivateAsync(int attempt)
void EOnEditorPostDeactivate()
When the component is deactivated, but after the next mode is activated.
sealed bool OnDeactivateAsyncBase(int attempt)
static bool IsEditMode()
Definition Functions.c:1566
static bool IsAdmin(int playerID)
Definition Functions.c:1927
proto external GenericEntity GetOwner()
Get owner entity.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134