1 [
ComponentEditorProps(
category:
"GameScripted/Editor", description:
"Attribute for managing attributes. Works only with SCR_EditorBaseEntity!", icon:
"WBData/ComponentEditorProps/componentEditor.png")]
5 protected ref array<ref SCR_EditorAttributeList> m_AttributeLists;
7 protected ref array<SCR_BaseEditorAttribute> m_aAttributes = {};
14 return m_aAttributes[
index];
19 int GetAttributesCount()
21 return m_aAttributes.Count();
30 return m_aAttributes.Find(attribute);
40 list.InsertAllAttributes(m_aAttributes);
58 [
Attribute(
desc:
"Dialog created when attributes are edited.", defvalue:
"-1", uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(
ChimeraMenuPreset))]
61 [
Attribute(
desc:
"Displayed description and icon when hovering over an locked attribute. All attributes need access to this.",
category:
"Attributes")]
95 if (!item || item.IsInherited(array) || item.IsInherited(set) || item.IsInherited(map))
99 array<Managed> items = {};
101 Print(
"Opening attributes with NULL entity!", LogLevel.WARNING);
106 Print(
string.Format(
"Cannot edit attributes of %1, must be explicitly array<Managed> (even when the array element itself inherits from Managed)!", item.Type()), LogLevel.ERROR);
110 array<Managed> items = {item};
123 void StartEditing(notnull array<Managed> items,
bool onlyServer =
true)
141 array<int> itemIds = {};
143 foreach (Managed item: items)
145 int id = Replication.FindId(item);
159 foreach (Managed item: items)
170 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
174 foreach (
int id: itemIds)
176 Managed item = Replication.FindItem(
id);
182 array<int> attributesIds = {};
183 array<ref SCR_BaseEditorAttributeVar> attributesVars = {};
184 array<ref EEditorAttributeMultiSelect> attributesMultiSelect = {};
189 foreach (
int i,
int attributeId: attributesIds)
195 Print(
string.Format(
"Trying to add editor attribute of type '%1' but there is already an attribute of the same type", attribute.Type()), LogLevel.ERROR);
206 int simulatedDelay = DiagMenu.GetValue(
SCR_DebugMenuID.DEBUGUI_EDITOR_NETWORK_DELAY) * 100;
207 if (simulatedDelay > 0 && !Replication.IsRunning())
208 GetGame().GetCallqueue().CallLater(
StartEditingOwner, simulatedDelay,
false, attributesIds, attributesVars, attributesMultiSelect);
214 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
215 protected void StartEditingOwner(notnull array<int> attributesIds, notnull array<ref SCR_BaseEditorAttributeVar> attributesVars, notnull array<ref EEditorAttributeMultiSelect> attributesMultiSelect)
232 foreach (
int i,
int attributeId: attributesIds)
241 Print(
string.Format(
"Trying to add editor attribute of type '%1' but there is already an attribute of the same type", attribute.Type()), LogLevel.ERROR);
251 SSnapshot snapshot =
null;
255 SSnapSerializer snapWriter = SSnapSerializer.MakeWriter(snapshot);
258 attribute.StartEditing(var, snapshot);
269 attribute.UpdateInterlinkedVariables(attribute.GetVariable(),
this,
true);
283 if (attributeEntry.Type() ==
type)
310 if (playerController)
311 PlayerID = playerController.GetPlayerId();
313 bool attributeChangesApplied =
false;
316 array<int> attributesIds = {};
317 array<ref SCR_BaseEditorAttributeVar> attributesVars = {};
321 SSnapshot snapshot = attribute.GetSnapshot();
328 if (!attribute.IsEnabled())
333 if (!attribute.GetIsMultiSelect() || !attribute.GetHasConflictingValues() || !attribute.GetIsOverridingValues())
338 SSnapSerializer snapReader = SSnapSerializer.MakeReader(snapshot);
344 if (attribute.IsServer())
347 attributesIds.Insert(
m_PrefabData.FindAttribute(attribute));
348 attributesVars.Insert(var);
355 if (attribute.ReadVariable(item,
this))
356 attribute.WriteVariable(item, var,
this, PlayerID);
360 attributeChangesApplied =
true;
364 if (!attributesIds.IsEmpty())
373 if (attributeChangesApplied)
383 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
384 protected void ConfirmEditingServer(notnull array<int> attributesIds, notnull array<ref SCR_BaseEditorAttributeVar> attributesVars,
int PlayerID)
389 foreach (
int i,
int attributeId: attributesIds)
395 if (attribute.ReadVariable(item,
this))
397 attribute.WriteVariable(item, var,
this, PlayerID);
402 editableEntity.SetHierarchyAsDirtyInParents();
437 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
462 SSnapshot snapshot = attribute.GetSnapshot();
466 SSnapSerializer snapReader = SSnapSerializer.MakeReader(snapshot);
470 snapReader = SSnapSerializer.MakeReader(snapshot);
475 attribute.TelegraphChange(
true);
479 if (attribute.ReadVariable(item,
this))
481 attribute.PreviewVariable(
false,
this);
482 attribute.UpdateInterlinkedVariables(var,
this);
488 else if (attribute.GetHasConflictingValues())
491 attribute.TelegraphChange(
true);
498 attribute.TelegraphChange(
true);
516 attribute.StopEditing();
525 protected int GetVariables(
bool onlyServer, notnull array<Managed> items, notnull out array<int> outIds, notnull out array<ref SCR_BaseEditorAttributeVar> outVars, notnull out array<ref EEditorAttributeMultiSelect> outAttributesMultiSelect)
528 for (
int i = 0, count =
m_PrefabData.GetAttributesCount(); i < count; i++)
534 if (attribute.IsServer() != onlyServer)
538 bool isCompatible =
false;
541 SSnapSerializer snapWriter;
542 SSnapSerializer snapReader;
546 foreach (Managed item: items)
561 snapWriter = SSnapSerializer.MakeWriter(snapshot);
562 snapReader = SSnapSerializer.MakeReader(snapshot);
587 outAttributesMultiSelect.Insert(multiSelectState);
589 multiSelectState = 0;
591 return outVars.Count();
602 for (
int i = 0, count =
m_PrefabData.GetAttributesCount(); i < count; i++)
610 foreach (Managed item: items)
640 if (attributeEntry.Type() ==
type)
642 attribute = attributeEntry;
649 return attribute.SetVariable(var);
653 Debug.Error2(
type.ToString(),
"Attribute type not found to set variable!");
670 if (attributeEntry.Type() ==
type)
672 var = attributeEntry.GetVariableOrCopy();
674 Print(
"SCR_AttributesManagerEditorComponent could not find the attribute var which will cause certain attributes to break", LogLevel.ERROR);
699 if (((includedInherit && attributeEntry.Type().IsInherited(
type)) || (!includedInherit && attributeEntry.Type() ==
type)) && attributeEntry != ignoreAttribute)
700 attributes.Insert(attributeEntry);
703 return attributes.Count();
718 if (attributeEntry.Type() ==
type)
720 attribute = attributeEntry;
723 return !attributeEntry.IsServer();
741 if (attributeEntry.Type() ==
type)
743 attribute = attributeEntry;
750 attribute.Enable(enabled);
774 if (attributeEntry.Type() ==
type)
776 attribute = attributeEntry;
783 attribute.ToggleSelected(selected,
index);
788 Debug.Error2(
type.ToString(),
"Attribute type not found to set attriabute selected!");
803 if (attributeEntry.Type() ==
type)
805 attribute = attributeEntry;
812 attribute.SetAsSubAttribute();
828 if (attributeEntry.Type() ==
type)
829 return attributeEntry;
986 for (
int i = 0, count =
m_PrefabData.GetAttributesCount(); i < count; i++)