Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BaseFactionEditableAttribute.c
Go to the documentation of this file.
1 
6 {
7  override SCR_BaseEditorAttributeVar ReadVariable(Managed item, SCR_AttributesManagerEditorComponent manager)
8  {
10  if (!editableEntity)
11  return null;
12 
13  if (!ValidEntity(editableEntity.GetOwner()))
14  return null;
15 
16  FactionManager factionManager = GetGame().GetFactionManager();
17  if (!factionManager)
18  return null;
19 
20  Faction faction = GetFaction(editableEntity.GetOwner());
21  if (!faction)
22  return null;
23 
24  SCR_DelegateFactionManagerComponent delegateFactionManager = SCR_DelegateFactionManagerComponent.GetInstance();
25  if (!delegateFactionManager)
26  return null;
27 
28  SCR_SortedArray<SCR_EditableFactionComponent> factionDelegates = new SCR_SortedArray<SCR_EditableFactionComponent>;
29  int count = delegateFactionManager.GetSortedFactionDelegates(factionDelegates);
30 
31  if (factionDelegates.IsEmpty())
32  return null;
33 
34  int factionIndex = factionManager.GetFactionIndex(faction);
35 
36  for (int i = 0; i < count; i++)
37  {
38  if (factionDelegates.GetValue(i).GetFactionIndex() == factionIndex)
39  return SCR_BaseEditorAttributeVar.CreateInt(i);
40  }
41 
42  return null;
43  }
44 
45  //~ Check if entity is valid to set faction
46  protected bool ValidEntity(GenericEntity entity)
47  {
48  return false;
49  }
50 
51  //~ Get the entity faction
52  protected Faction GetFaction(GenericEntity entity)
53  {
54  return null;
55  }
56 
57  //~ Set the entity faction
58  protected void SetFaction(GenericEntity entity, Faction faction)
59  {
60 
61  }
62 
63  //~ Creates the buttons to select faction
64  protected override void CreatePresets()
65  {
66  SCR_DelegateFactionManagerComponent delegateFactionManager = SCR_DelegateFactionManagerComponent.GetInstance();
67  if (!delegateFactionManager)
68  return;
69 
70  FactionManager factionManager = GetGame().GetFactionManager();
71  if (!factionManager)
72  return;
73 
74  m_aValues.Clear();
75 
76  SCR_SortedArray<SCR_EditableFactionComponent> factionDelegates = new SCR_SortedArray<SCR_EditableFactionComponent>;
77  int count = delegateFactionManager.GetSortedFactionDelegates(factionDelegates);
78 
79  SCR_Faction scrFaction;
80 
81  for(int i = 0; i < count; ++i)
82  {
83  scrFaction = SCR_Faction.Cast(factionDelegates.Get(i).GetFaction());
84 
85  if (!scrFaction)
86  continue;
87 
89  value.SetWithUIInfo(scrFaction.GetUIInfo(), factionDelegates.GetValue(i).GetFactionIndex());
90  m_aValues.Insert(value);
91  }
92  }
93 
94  override void WriteVariable(Managed item, SCR_BaseEditorAttributeVar var, SCR_AttributesManagerEditorComponent manager, int playerID)
95  {
96  if (!var)
97  return;
98 
99  FactionManager factionManager = GetGame().GetFactionManager();
100  if (!factionManager)
101  return;
102 
103  SCR_EditableEntityComponent editableEntity = SCR_EditableEntityComponent.Cast(item);
104  if (!editableEntity)
105  return;
106 
107  SCR_DelegateFactionManagerComponent delegateFactionManager = SCR_DelegateFactionManagerComponent.GetInstance();
108  if (!delegateFactionManager)
109  return;
110 
111  SCR_SortedArray<SCR_EditableFactionComponent> factionDelegates = new SCR_SortedArray<SCR_EditableFactionComponent>;
112  delegateFactionManager.GetSortedFactionDelegates(factionDelegates);
113 
114  if (factionDelegates.IsEmpty())
115  return;
116 
117  //Faction faction = factionManager.GetFactionByIndex(var.GetInt());
118  Faction faction = factionManager.GetFactionByIndex(factionDelegates.GetValue(var.GetInt()).GetFactionIndex());
119  if (!faction)
120  return;
121 
122  SetFaction(editableEntity.GetOwner(), faction);
123  }
124 };
125 
m_aValues
SCR_BaseEditorAttributeEntryTimeSlider m_aValues
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_BaseEditorAttributeCustomTitle
Definition: SCR_BaseEditorAttribute.c:868
SCR_BaseEditorAttributeVar
Definition: SCR_BaseEditorAttributeVar.c:1
SCR_BaseFactionEditableAttribute
Definition: SCR_BaseFactionEditableAttribute.c:5
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
Faction
Definition: Faction.c:12
SCR_EditorAttributeFloatStringValueHolder
Definition: SCR_BaseFloatValueHolderEditorAttribute.c:17
SCR_BasePresetsEditorAttribute
Definition: SCR_BasePresetsEditorAttribute.c:5
SCR_DelegateFactionManagerComponent
Definition: SCR_DelegateFactionManagerComponent.c:15
SCR_Faction
Definition: SCR_Faction.c:6
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468