Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ShowHideInEditorComponent.c
Go to the documentation of this file.
1 
4 [ComponentEditorProps(category: "GameScripted/Editor", description: "")]
5 class SCR_ShowHideInEditorComponentClass : ScriptComponentClass
6 {
7 };
8 
10 {
11  [Attribute("1", desc: "Set when the entity is visible. If false will hide itself in editor and show outside of editor. This component is ignored if attached to an EditableEntity or if parent is editable entity", uiwidget: UIWidgets.Flags, enums: ParamEnumArray.FromEnum(EShowHideInEditor))]
12  protected EShowHideInEditor m_eShowHideInEditor;
13 
14  [Attribute("0", desc: "If true will also Show/Hide children when entity is hidden")]
15  protected bool m_bShowHideChildren;
16 
17  [Attribute("1", desc: "If true will also Show/Hide when editor UI is hidden")]
18  protected bool m_bHideWhenEditorUiHidden;
19 
20  //~ Always true if m_bHideWhenEditorUiHidden is false
21  protected bool m_bEditorMenuVisible = true;
22 
23  //~ If true make sure to remove the on editor create scriptinvoker Subscription
24  protected bool m_bSubscribedToOnEditorCreate;
25 
26  //------------------------------------------------------------------------------------------------
27  protected void OnEditorOpen()
28  {
29  ShowHideEntity(true, SCR_EditorModeEntity.GetInstance());
30  }
31 
32  //------------------------------------------------------------------------------------------------
33  protected void OnEditorClosed()
34  {
35  ShowHideEntity(false, SCR_EditorModeEntity.GetInstance());
36  }
37 
38  //------------------------------------------------------------------------------------------------
39  protected void OnEditorModeChanged(SCR_EditorModeEntity currentMode, SCR_EditorModeEntity prevMode)
40  {
41  ShowHideEntity(SCR_EditorManagerEntity.IsOpenedInstance(), currentMode);
42  }
43 
44  //------------------------------------------------------------------------------------------------
45  protected void OnEditorMenuVisibilityChanged(bool isVisible)
46  {
47  m_bEditorMenuVisible = isVisible;
48 
49  if (!m_bEditorMenuVisible)
50  {
51  GetOwner().ClearFlags(EntityFlags.VISIBLE, m_bShowHideChildren);
52  }
53  else
54  {
55  SCR_EditorManagerEntity editorManagerEntity = SCR_EditorManagerEntity.GetInstance();
56  if (!editorManagerEntity)
57  {
58  GetOwner().ClearFlags(EntityFlags.VISIBLE, m_bShowHideChildren);
59  return;
60  }
61 
62  ShowHideEntity(editorManagerEntity.IsOpened(), SCR_EditorModeEntity.GetInstance());
63  }
64  }
65 
66  //------------------------------------------------------------------------------------------------
67  protected void ShowHideEntity(bool editorIsOpen, SCR_EditorModeEntity mode)
68  {
69  //~ UI not visible so no need to set visible again
70  if (!m_bEditorMenuVisible || !editorIsOpen)
71  {
72  GetOwner().ClearFlags(EntityFlags.VISIBLE, m_bShowHideChildren);
73  return;
74  }
75 
76  bool isLimited = !mode || mode.IsLimited();
77 
78  if (isLimited)
79  {
80  if (SCR_Enum.HasFlag(m_eShowHideInEditor, EShowHideInEditor.SHOW_IN_LIMITED_EDITOR))
81  GetOwner().SetFlags(EntityFlags.VISIBLE, m_bShowHideChildren);
82  else
83  GetOwner().ClearFlags(EntityFlags.VISIBLE, m_bShowHideChildren);
84  }
85  else
86  {
87  if (SCR_Enum.HasFlag(m_eShowHideInEditor, EShowHideInEditor.SHOW_IN_UNLIMITED_EDITOR))
88  GetOwner().SetFlags(EntityFlags.VISIBLE, m_bShowHideChildren);
89  else
90  GetOwner().ClearFlags(EntityFlags.VISIBLE, m_bShowHideChildren);
91  }
92  }
93 
94  //------------------------------------------------------------------------------------------------
95  override void EOnInit(IEntity owner)
96  {
97  //~ Use editor logic if attached to editable entity
98  if (owner.FindComponent(SCR_EditableEntityComponent))
99  return;
100 
101  //~ Use editor logic if attached to parent that is an editable entity
102  IEntity parent = owner.GetParent();
103  if (parent && parent.FindComponent(SCR_EditableEntityComponent))
104  return;
105 
106  //~ Set invisible on init
107  GetOwner().ClearFlags(EntityFlags.VISIBLE, m_bShowHideChildren);
108 
109  if (m_eShowHideInEditor <= 0)
110  return;
111 
112  SCR_EditorManagerEntity editorManager = SCR_EditorManagerEntity.GetInstance();
113  if (editorManager)
114  {
115  Init(editorManager);
116  return;
117  }
118 
119  //~ No editor manager found wait until it is created
121  if (editorManagerCore)
122  editorManagerCore.Event_OnEditorManagerInitOwner.Insert(Init);
123  }
124 
125  //------------------------------------------------------------------------------------------------
126  protected void Init(SCR_EditorManagerEntity editorManagerEntity)
127  {
128  if (m_bSubscribedToOnEditorCreate)
129  {
131  if (editorManagerCore)
132  {
133  m_bSubscribedToOnEditorCreate = false;
134  editorManagerCore.Event_OnEditorManagerInitOwner.Remove(Init);
135  }
136  }
137 
138  editorManagerEntity.GetOnOpened().Insert(OnEditorOpen);
139  editorManagerEntity.GetOnClosed().Insert(OnEditorClosed);
140  editorManagerEntity.GetOnModeChange().Insert(OnEditorModeChanged);
141 
142  if (m_bHideWhenEditorUiHidden)
143  {
145  if (menuManager)
146  {
147  menuManager.GetOnVisibilityChange().Insert(OnEditorMenuVisibilityChanged);
148 
149  m_bEditorMenuVisible = menuManager.IsVisible();
150  if (!m_bEditorMenuVisible)
151  GetOwner().ClearFlags(EntityFlags.VISIBLE, m_bShowHideChildren);
152  }
153  }
154 
155  if (editorManagerEntity.IsOpened())
156  OnEditorOpen();
157  else
158  OnEditorClosed();
159  }
160 
161  //------------------------------------------------------------------------------------------------
162  override void OnDelete(IEntity owner)
163  {
164  //~ Hide in workbench
165  if (SCR_Global.IsEditMode())
166  return;
167 
168  //~ Use editor logic if attached to editable entity
169  if (owner.FindComponent(SCR_EditableEntityComponent))
170  return;
171 
172  //~ Use editor logic if attached to parent that is an editable entity
173  IEntity parent = owner.GetParent();
174  if (parent && parent.FindComponent(SCR_EditableEntityComponent))
175  return;
176 
177  if (m_eShowHideInEditor <= 0)
178  return;
179 
180  //~ Remove on editor creation event
181  if (m_bSubscribedToOnEditorCreate)
182  {
184  if (editorManagerCore)
185  editorManagerCore.Event_OnEditorManagerInitOwner.Remove(Init);
186  }
187 
188  SCR_EditorManagerEntity editorManagerEntity = SCR_EditorManagerEntity.GetInstance();
189  if (!editorManagerEntity)
190  return;
191 
192  editorManagerEntity.GetOnOpened().Remove(OnEditorOpen);
193  editorManagerEntity.GetOnClosed().Remove(OnEditorClosed);
194  editorManagerEntity.GetOnModeChange().Remove(OnEditorModeChanged);
195  }
196 
197  //------------------------------------------------------------------------------------------------
198  override void OnPostInit(IEntity owner)
199  {
200  //~ Hide in workbench
201  if (SCR_Global.IsEditMode())
202  return;
203 
204  SetEventMask(owner, EntityEvent.INIT);
205  }
206 };
207 
208 //------------------------------------------------------------------------------------------------
210 {
213 };
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
SCR_ShowHideInEditorComponent
Definition: SCR_ShowHideInEditorComponent.c:9
EShowHideInEditor
EShowHideInEditor
Definition: SCR_ShowHideInEditorComponent.c:209
SCR_Enum
Definition: SCR_Enum.c:1
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_EditorModeEntity
Definition: SCR_EditorModeEntity.c:22
SHOW_IN_UNLIMITED_EDITOR
@ SHOW_IN_UNLIMITED_EDITOR
Definition: SCR_ShowHideInEditorComponent.c:211
SHOW_IN_LIMITED_EDITOR
@ SHOW_IN_LIMITED_EDITOR
Definition: SCR_ShowHideInEditorComponent.c:212
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_EditorManagerCore
Core component to manage SCR_EditorManagerEntity.
Definition: SCR_EditorManagerCore.c:5
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
SCR_Global
Definition: Functions.c:6
SCR_MenuEditorComponent
Definition: SCR_MenuEditorComponent.c:8
SCR_ShowHideInEditorComponentClass
Definition: SCR_ShowHideInEditorComponent.c:5
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26