Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AccessKeysEditorComponent.c
Go to the documentation of this file.
1 //#define DISABLE_ADMIN_ACCESS //--- Enable this to prevent admin from seeing all entities
2 
3 [ComponentEditorProps(category: "GameScripted/Editor", description: "Attribute for managing access keys. Works only with SCR_EditorBaseEntity!", icon: "WBData/ComponentEditorProps/componentEditor.png")]
5 {
6 }
7 
9 
13 class SCR_AccessKeysEditorComponent : SCR_BaseEditorComponent
14 {
15  [Attribute("1", UIWidgets.Flags, "", enums: ParamEnumArray.FromEnum(EEditableEntityAccessKey))]
16  private EEditableEntityAccessKey m_AccessKey;
17 
18  ref ScriptInvoker Event_OnChanged = new ScriptInvoker();
19 
20  #ifdef WORKBENCH
21  private bool m_bIsAdmin = true;
22  #endif
23 
24  //------------------------------------------------------------------------------------------------
28  {
29  Rpc(AddAccessKeyServer, accessKey);
30  }
31 
32  //------------------------------------------------------------------------------------------------
37  {
38  Rpc(RemoveAccessKeyServer, accessKey);
39  }
40 
41  //------------------------------------------------------------------------------------------------
42  //--- Manipulate access keys of the editor
43  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
44  protected void AddAccessKeyServer(EEditableEntityAccessKey accessKey)
45  {
46  if (HasAccess(accessKey) || IsAdmin())
47  return;
48 
49  m_AccessKey = m_AccessKey | accessKey;
50  Rpc(AccessKeyChangedOwner, m_AccessKey);
51  }
52 
53  //------------------------------------------------------------------------------------------------
54  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
56  {
57  if (!HasAccess(accessKey) || IsAdmin())
58  return;
59 
60  m_AccessKey = m_AccessKey &~ accessKey;
61  Rpc(AccessKeyChangedOwner, m_AccessKey);
62  }
63 
64  //------------------------------------------------------------------------------------------------
65  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
67  {
68  m_AccessKey = accessKey;
69  Event_OnChanged.Invoke();
70  }
71 
72  //------------------------------------------------------------------------------------------------
76  {
77  return m_AccessKey;
78  }
79 
80  //------------------------------------------------------------------------------------------------
85  {
86  return m_AccessKey & accessKey;
87  }
88 
89  //--- Manipulate access key of an entity
90  //------------------------------------------------------------------------------------------------
95  {
96  Rpc(AddEntityAccessKeyServer, Replication.FindId(entity), accessKey);
97  }
98  //------------------------------------------------------------------------------------------------
103  {
104  Rpc(RemoveEntityAccessKeyServer, Replication.FindId(entity), accessKey);
105  }
106 
107  //------------------------------------------------------------------------------------------------
108  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
109  protected void AddEntityAccessKeyServer (int entityID, EEditableEntityAccessKey accessKey)
110  {
111  SCR_EditableEntityComponent entity = SCR_EditableEntityComponent.Cast(Replication.FindItem(entityID));
112  if (entity)
113  entity.AddAccessKey(accessKey);
114  }
115 
116  //------------------------------------------------------------------------------------------------
117  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
118  protected void RemoveEntityAccessKeyServer (int entityID, EEditableEntityAccessKey accessKey)
119  {
120  SCR_EditableEntityComponent entity = SCR_EditableEntityComponent.Cast(Replication.FindItem(entityID));
121  if (entity)
122  entity.RemoveAccessKey(accessKey);
123  }
124 
125  //--- Debug
126  //------------------------------------------------------------------------------------------------
127  protected string GetKeyDebug()
128  {
129  string output = "";
130  if (IsAdmin())
131  {
132  output = "<ADMIN>";
133  }
134  else
135  {
136  typename enumType = EEditableEntityAccessKey;
137  int enumCount = enumType.GetVariableCount();
138  for (int i = 0; i < enumCount; i++)
139  {
140  int val;
141  if (enumType.GetVariableType(i) == int && enumType.GetVariableValue(null, i, val))
142  {
143  if (HasAccess(val))
144  {
145  if (!output.IsEmpty())
146  output += ", ";
147 
148  output += enumType.GetVariableName(i);
149  }
150  }
151  }
152  }
153  return string.Format("Editor access keys: %1", output);
154  }
155 
156  //------------------------------------------------------------------------------------------------
159  {
161  if (!core)
162  return;
163 
164  Print("--------------------------------------------------", LogLevel.DEBUG);
165  set<SCR_EditableEntityComponent> entities = new set<SCR_EditableEntityComponent>();
166  core.GetAllEntities(entities, true);
167  foreach (SCR_EditableEntityComponent entity: entities)
168  {
169  if (entity.IsLayer())
170  entity.Log("", m_AccessKey);
171  }
172  Print("--------------------------------------------------", LogLevel.DEBUG);
173  }
174 
175  //------------------------------------------------------------------------------------------------
178  {
179  Print(GetKeyDebug(), LogLevel.DEBUG);
180  }
181 
182  #ifdef WORKBENCH
183  //------------------------------------------------------------------------------------------------
184  override bool IsAdmin()
185  {
186  return m_bIsAdmin && super.IsAdmin();
187  }
188  #endif
189 
190  //------------------------------------------------------------------------------------------------
191  override void EOnEditorDebug(array<string> debugTexts)
192  {
193  debugTexts.Insert(GetKeyDebug());
194  }
195 
196  //------------------------------------------------------------------------------------------------
197  override void EOnFrame(IEntity owner, float timeSlice)
198  {
199  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_AVAILABLE))
200  {
202  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_AVAILABLE, false);
203  }
204 
205  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_ACCESS_KEYS))
206  {
207  LogAccessKey();
208  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_ACCESS_KEYS, false);
209  }
210 
211  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_ACCESS_KEY_TOGGLE))
212  {
213  typename keysType = EEditableEntityAccessKey;
214  int keyValue;
215  keysType.GetVariableValue(null, DiagMenu.GetRangeValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_ACCESS_KEY), keyValue);
216  if (!HasAccess(keyValue))
217  {
218  AddAccessKey(keyValue);
219  }
220  else
221  {
222  RemoveAccessKey(keyValue);
223  }
224  LogAccessKey();
225  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_ACCESS_KEY_TOGGLE, false);
226  }
227 
228  #ifdef WORKBENCH
229  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_ACCESS_KEY_ADMIN) != m_bIsAdmin)
230  {
231  m_bIsAdmin = DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_ACCESS_KEY_ADMIN);
232  if (m_bIsAdmin)
233  m_AccessKey = int.MAX;
234  else
235  m_AccessKey = EEditableEntityAccessKey.DEFAULT;
236 
237  Event_OnChanged.Invoke();
238  }
239  #endif
240  }
241 
242  //------------------------------------------------------------------------------------------------
243  //--- JIP on server
244  override bool RplSave(ScriptBitWriter writer)
245  {
246  writer.Write(m_AccessKey, 32);
247  return true;
248  }
249 
250  //------------------------------------------------------------------------------------------------
251  //--- JIP on client
252  override bool RplLoad(ScriptBitReader reader)
253  {
254  reader.Read(m_AccessKey, 32);
255  return true;
256  }
257 
258  //------------------------------------------------------------------------------------------------
259  override protected void EOnEditorActivate()
260  {
261  SetEventMask(GetOwner(), EntityEvent.FRAME);
262  }
263 
264  //------------------------------------------------------------------------------------------------
265  override void EOnEditorInit()
266  {
267  if (SCR_EditableEntityCore.GetInstance(SCR_EditableEntityCore) == null)
268  return;
269 
270  typename keysType = EEditableEntityAccessKey;
271  int keysCount = keysType.GetVariableCount();
272 
273  //--- Unlock everything for admin
274  if (IsAdmin())
275  m_AccessKey = int.MAX;
276 
277  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_AVAILABLE, "", "Log Available", "Editable Entities");
278  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_ACCESS_KEYS, "", "Log Access Keys", "Editable Entities");
279  DiagMenu.RegisterRange(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_ACCESS_KEY, "", "Access Key", "Editable Entities", string.Format("0, %1, 0, 1", keysCount - 1));
280  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_ACCESS_KEY_TOGGLE, "", "Access Key: Toggle", "Editable Entities");
281  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_ACCESS_KEYS, false);
282  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_ACCESS_KEY_TOGGLE, false);
283 
284 #ifdef WORKBENCH
285  m_bIsAdmin = IsAdmin();
286  if (m_bIsAdmin)
287  {
288  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_ACCESS_KEY_ADMIN, "", "Admin Access", "Editable Entities");
289  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_ACCESS_KEY_ADMIN, m_bIsAdmin);
290  }
291 #endif
292  }
293 
294  //------------------------------------------------------------------------------------------------
295  override protected void EOnEditorDelete()
296  {
297  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_AVAILABLE);
298  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_ACCESS_KEYS);
299  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_ACCESS_KEY);
300  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_ACCESS_KEY_TOGGLE);
301  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_ACCESS_KEY_ADMIN);
302  Event_OnChanged = null;
303  }
304 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
LogAccessKey
void LogAccessKey()
Print out access keys.
Definition: SCR_AccessKeysEditorComponent.c:177
Event_OnChanged
ref ScriptInvoker Event_OnChanged
Definition: SCR_AccessKeysEditorComponent.c:18
SCR_EditableEntityCore
Definition: SCR_EditableEntityCore.c:10
AddAccessKey
void AddAccessKey(EEditableEntityAccessKey accessKey)
Definition: SCR_AccessKeysEditorComponent.c:27
EOnEditorDebug
override void EOnEditorDebug(array< string > debugTexts)
Definition: SCR_AccessKeysEditorComponent.c:191
Attribute
SCR_AccessKeysEditorComponentClass SCR_BaseEditorComponentClass Attribute("1", UIWidgets.Flags, "", enums:ParamEnumArray.FromEnum(EEditableEntityAccessKey))] private EEditableEntityAccessKey m_AccessKey
HasAccess
bool HasAccess(EEditableEntityAccessKey accessKey)
Definition: SCR_AccessKeysEditorComponent.c:84
AddAccessKeyServer
protected void AddAccessKeyServer(EEditableEntityAccessKey accessKey)
Definition: SCR_AccessKeysEditorComponent.c:44
LogAvailableEntities
void LogAvailableEntities()
Print out all entities with compatible access keys.
Definition: SCR_AccessKeysEditorComponent.c:158
EOnFrame
override void EOnFrame(IEntity owner, float timeSlice)
Definition: SCR_AccessKeysEditorComponent.c:197
AccessKeyChangedOwner
protected void AccessKeyChangedOwner(EEditableEntityAccessKey accessKey)
Definition: SCR_AccessKeysEditorComponent.c:66
EOnEditorInit
override void EOnEditorInit()
Definition: SCR_AccessKeysEditorComponent.c:265
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
SCR_AccessKeysEditorComponentClass
Definition: SCR_AccessKeysEditorComponent.c:4
SCR_BaseEditorComponent
Definition: SCR_BaseEditorComponent.c:119
RemoveEntityAccessKeyServer
protected void RemoveEntityAccessKeyServer(int entityID, EEditableEntityAccessKey accessKey)
Definition: SCR_AccessKeysEditorComponent.c:118
RemoveEntityAccessKey
void RemoveEntityAccessKey(SCR_EditableEntityComponent entity, EEditableEntityAccessKey accessKey)
Definition: SCR_AccessKeysEditorComponent.c:102
EEditableEntityAccessKey
EEditableEntityAccessKey
Definition: EEditableEntityAccessKey.c:8
RemoveAccessKey
void RemoveAccessKey(EEditableEntityAccessKey accessKey)
Definition: SCR_AccessKeysEditorComponent.c:36
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
RplLoad
override bool RplLoad(ScriptBitReader reader)
Definition: SCR_AccessKeysEditorComponent.c:252
AddEntityAccessKey
void AddEntityAccessKey(SCR_EditableEntityComponent entity, EEditableEntityAccessKey accessKey)
Definition: SCR_AccessKeysEditorComponent.c:94
SCR_BaseEditorComponentClass
Definition: SCR_BaseEditorComponent.c:2
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
EOnEditorActivate
override protected void EOnEditorActivate()
Definition: SCR_AccessKeysEditorComponent.c:259
GetAccessKey
EEditableEntityAccessKey GetAccessKey()
Definition: SCR_AccessKeysEditorComponent.c:75
EOnEditorDelete
override protected void EOnEditorDelete()
Definition: SCR_AccessKeysEditorComponent.c:295
GetKeyDebug
protected string GetKeyDebug()
Definition: SCR_AccessKeysEditorComponent.c:127
AddEntityAccessKeyServer
protected void AddEntityAccessKeyServer(int entityID, EEditableEntityAccessKey accessKey)
Definition: SCR_AccessKeysEditorComponent.c:109
RplSave
override bool RplSave(ScriptBitWriter writer)
Definition: SCR_AccessKeysEditorComponent.c:244
RemoveAccessKeyServer
protected void RemoveAccessKeyServer(EEditableEntityAccessKey accessKey)
Definition: SCR_AccessKeysEditorComponent.c:55
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180