Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ButtonBoxMultiSelectAttributeUIComponent.c
Go to the documentation of this file.
1 
4 {
5  protected bool m_bUseCustomFlags = false;
6 
7  override void Init(Widget w, SCR_BaseEditorAttribute attribute)
8  {
9  //Get if uses custom flags
10  array<ref SCR_BaseEditorAttributeEntry> entries = new array<ref SCR_BaseEditorAttributeEntry>;
11  attribute.GetEntries(entries);
12 
13  foreach (SCR_BaseEditorAttributeEntry entry: entries)
14  {
16  if (multiSelectPresetEntry)
17  {
18  m_bUseCustomFlags = multiSelectPresetEntry.GetUsesCustomFlags();
19  break;
20  }
21  }
22 
23  super.Init(w, attribute);
24  }
25 
26  override void SetFromVar(SCR_BaseEditorAttributeVar var)
27  {
28  if (!var)
29  return;
30 
31  int count = m_ToolBoxComponent.GetNumItems();
32  vector flags = var.GetVector();
33  int value;
34 
35  if (!m_bUseCustomFlags)
36  {
37  int index = 0;
38  int flagPerIndex = 0;
39  int flag = 1;
40 
41  //Set State
42  for (int i = 0; i < count; i++)
43  {
44  value = flags[index];
45  m_ToolBoxComponent.SetItemSelected(i, (value & flag), false);
46  flag *= 2;
47  flagPerIndex++;
48 
49  if (flagPerIndex >= 31)
50  {
51  flagPerIndex = 0;
52  flag = 1;
53  index++;
54 
55  if (index > 2)
56  break;
57  }
58  }
59  }
60  else
61  {
62  value = flags[0];
63 
64  //Check if has custom flag
65  for (int i = 0; i < count; i++)
66  {
67  m_ToolBoxComponent.SetItemSelected(i, (value & (int)m_ButtonBoxData.GetEntryFloatValue(i)), false);
68  }
69 
70  }
71 
72  m_bButtonValueInitCalled = true;
73 
74  SetFromVarOrDefault();
75  }
76 
77  //x is index, y is selectState
78  override bool OnChange(Widget w, int x, int y, bool finished)
79  {
80  if (!m_bButtonValueInitCalled)
81  return false;
82 
83  SCR_BaseEditorAttribute attribute = GetAttribute();
84  if (!attribute)
85  return false;
86  SCR_BaseEditorAttributeVar var = attribute.GetVariable(true);
87 
88  vector flags;
89  int count = m_ToolBoxComponent.GetNumItems();
90  if (!m_bUseCustomFlags)
91  {
92  flags = Vector(0,0,0);
93  int index = 0;
94  int flagPerIndex = 0;
95  int flag = 1;
96  int value;
97 
98  for (int i = 0; i < count; i++)
99  {
100  //If selected add
101  if (m_ToolBoxComponent.IsItemSelected(i))
102  {
103  value = flags[index];
104  value |= flag;
105  flags[index] = value;
106  }
107 
108  flag *= 2;
109  flagPerIndex++;
110 
111  if (flagPerIndex >= 31)
112  {
113  flagPerIndex = 0;
114  flag = 1;
115  index++;
116 
117  if (index > 2)
118  break;
119  }
120  }
121  }
122  else
123  {
124  int flagValues = flags[0];
125 
126  for (int i = 0; i < count; i++)
127  {
128  if (m_ToolBoxComponent.IsItemSelected(i))
129  flagValues |= (int)m_ButtonBoxData.GetEntryFloatValue(i);
130  else
131  flagValues &= ~(int)m_ButtonBoxData.GetEntryFloatValue(i);
132  }
133 
134  flags[0] = flagValues;
135  }
136  var.SetVector(flags);
137  AttributeValueChanged();
138  return false;
139  }
140 
141  protected override void OnMultiSelectButton(SCR_ToolboxComponent toolbox, int index, bool state)
142  {
143  super.OnMultiSelectButton(toolbox, index, state);
144  OnChange(toolbox.GetRootWidget(), index, state, false);
145  }
146 };
SCR_ButtonBoxMultiSelectAttributeUIComponent
Definition: SCR_ButtonBoxMultiSelectAttributeUIComponent.c:3
SCR_BaseEditorAttributeVar
Definition: SCR_BaseEditorAttributeVar.c:1
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_BaseEditorAttribute
Base Attribute Script for other attributes to inherent from to get and set varriables in Editor Attri...
Definition: SCR_BaseEditorAttribute.c:3
SCR_ButtonBoxAttributeUIComponent
Definition: SCR_ButtonBoxAttributeUIComponent.c:3
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_ToolboxComponent
Definition: SCR_ToolboxComponent.c:2
int
SCR_PossessingManagerComponentClass int