Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BaseMultiSelectPresetsEditorAttribute.c
Go to the documentation of this file.
1 // Script File
2 //Only works with SCR_ButtonBoxMultiSelectAttributeUIComponent layout
5 {
6  [Attribute("0", "If multiselect uses custom flags. If false it will use the default system and sets states of flags either true or false")]
7  protected bool m_bCustomFlags;
8 
9  //Which state will be checked
10  private int m_iFlagChecker = 1;
11 
12  //Saves the true/false states
13  protected vector m_vFlags;
14 
15  //Which vector index the states are saved
16  private int m_iStateVectorIndex;
17 
18  //How many flags can be added to each vector index
19  private int m_iFlagsPerIndex = 31;
20 
21  //Current flags for the current vector index
22  private int m_iCurrentFlagsPerIndex;
23 
24  //Saves the next entity state
25  protected void AddOrderedState(bool state)
26  {
27  if (m_iStateVectorIndex > 2)
28  {
29  Debug.Error2(Type().ToString(), string.Format("Attribute multiselect has reach the max element limit of '%1'!", (31 * 3).ToString()));
30  return;
31  }
32 
33  if (state)
34  {
35  int stateValue = m_vFlags[m_iStateVectorIndex];
36  stateValue |= m_iFlagChecker;
37  m_vFlags[m_iStateVectorIndex] = stateValue;
38  }
39 
40  m_iFlagChecker *= 2;
41  m_iCurrentFlagsPerIndex++;
42 
43  if (m_iCurrentFlagsPerIndex >= m_iFlagsPerIndex)
44  ResetLoopValues(true);
45  }
46 
47  //Gets the next entity state
48  protected bool GetOrderedState()
49  {
50  if (m_iStateVectorIndex > 2)
51  {
52  Print(string.Format("Attribute multiselect has reach the max element limit of '%1' and is therefore set to false!", (31 * 3).ToString()), LogLevel.WARNING);
53  return false;
54  }
55 
56  int stateValue = m_vFlags[m_iStateVectorIndex];
57  bool returnState = (stateValue & m_iFlagChecker);
58 
59  m_iFlagChecker *= 2;
60  m_iCurrentFlagsPerIndex++;
61 
62  if (m_iCurrentFlagsPerIndex >= m_iFlagsPerIndex)
63  ResetLoopValues(true);
64 
65  return returnState;
66  }
67 
68  protected int GetStateVectorIndex()
69  {
70  return m_iStateVectorIndex;
71  }
72 
73  //Add flag in specific vector index. Returns false if invalid index
74  protected bool AddFlag(int flag, int vectorIndex = 0)
75  {
76  if (vectorIndex > 2 || vectorIndex < 0)
77  return false;
78 
79  int flagValue = m_vFlags[vectorIndex];
80  flagValue |= flag;
81  m_vFlags[vectorIndex] = flagValue;
82 
83  return true;
84  }
85 
86  //Sets all flags of the specific index. Returns false if vector indext is invalid
87  protected bool SetFlags(int flags, int vectorIndex = 0)
88  {
89  if (vectorIndex > 2 || vectorIndex < 0)
90  return false;
91 
92  m_vFlags[vectorIndex] = flags;
93  return true;
94  }
95 
96  //Gets all flags of index
97  protected int GetFlags(int vectorIndex)
98  {
99  if (vectorIndex > 2 || vectorIndex < 0)
100  return 0;
101 
102  return m_vFlags[vectorIndex];
103  }
104 
105  //Check if Var has flag
106  protected bool HasFlag(int flagToCheck)
107  {
108  int flagValue;
109  int vectorIndex = 0;
110 
111  while (vectorIndex < 3)
112  {
113  flagValue = m_vFlags[vectorIndex];
114  if (flagValue & flagToCheck)
115  return true;
116 
117  vectorIndex++;
118  }
119 
120  return false;
121  }
122 
123  protected void ResetLoopValues(bool increaseVectorIndex)
124  {
125  m_iFlagChecker = 1;
126  m_iCurrentFlagsPerIndex = 0;
127 
128  if (increaseVectorIndex)
129  m_iStateVectorIndex++;
130  else
131  m_iStateVectorIndex = 0;
132  }
133 
134  protected vector GetFlagVector()
135  {
136  return m_vFlags;
137  }
138 
139  //Reset vars
140  override SCR_BaseEditorAttributeVar ReadVariable(Managed item, SCR_AttributesManagerEditorComponent manager)
141  {
142  ResetLoopValues(false);
143  m_vFlags = Vector(0,0,0);
144 
145  return null;
146  }
147 
148  //Reset bit check and get states
149  override void WriteVariable(Managed item, SCR_BaseEditorAttributeVar var, SCR_AttributesManagerEditorComponent manager, int playerID)
150  {
151  if (!var)
152  return;
153 
154  ResetLoopValues(false);
155  m_vFlags = var.GetVector();
156  }
157 
158  override int GetEntries(notnull array<ref SCR_BaseEditorAttributeEntry> outEntries)
159  {
160  CreatePresets();
161  outEntries.Insert(new SCR_EditorAttributePresetMultiSelectEntry(m_iButtonsOnRow, m_bHasRandomizeButton, m_sRandomizeButtonIcon, m_bUseIcon, m_bHasButtonDescription, m_sButtonDescription, m_fButtonHeight, m_bCustomFlags));
162  outEntries.Insert(new SCR_BaseEditorAttributeFloatStringValues(m_aValues));
163  return outEntries.Count();
164  }
165 };
m_aValues
SCR_BaseEditorAttributeEntryTimeSlider m_aValues
SCR_BaseEditorAttributeCustomTitle
Definition: SCR_BaseEditorAttribute.c:868
SCR_BaseEditorAttributeVar
Definition: SCR_BaseEditorAttributeVar.c:1
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_BaseEditorAttributeFloatStringValues
void SCR_BaseEditorAttributeFloatStringValues(array< ref SCR_EditorAttributeFloatStringValueHolder > values)
Definition: SCR_BaseEditorAttribute.c:627
SCR_EditorAttributePresetMultiSelectEntry
void SCR_EditorAttributePresetMultiSelectEntry(int buttonsOnRow, bool hasRandomizeButton, ResourceName iconOfRandomizeButton=string.Empty, bool hasIcon=false, bool hasButtonDescription=false, string buttonDescription=string.Empty, int buttonHeight=-1, int customFlags=false)
Definition: SCR_BaseEditorAttribute.c:815
SCR_BaseMultiSelectPresetsEditorAttribute
Definition: SCR_BaseMultiSelectPresetsEditorAttribute.c:4
SCR_BasePresetsEditorAttribute
Definition: SCR_BasePresetsEditorAttribute.c:5
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
m_bCustomFlags
SCR_EditorAttributePresetEntry m_bCustomFlags