Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_PositionEditorAttributeUIComponent.c
Go to the documentation of this file.
2{
3 [Attribute("EditboxX")]
4 protected string m_sEditBoxXName;
5 [Attribute("EditboxY")]
6 protected string m_sEditBoxYName;
7 [Attribute("EditboxZ")]
8 protected string m_sEditBoxZName;
9 [Attribute("EditBoxRoot0")]
10 protected string m_sEditBoxComponentName;
11
12 protected BaseWorld m_World;
15
19
20 protected Widget m_root;
23
24 protected bool m_bSnapToSurface;
25 protected float m_fPositionY;
26
27 protected int m_iInitCalledAmount = 0;
28
29 override void Init(Widget w, SCR_BaseEditorAttribute attribute)
30 {
31 m_root = w;
32 GetGame().OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
33
34 m_World = GetGame().GetWorld();
35 if (!m_World)
36 return;
37
39
40 Widget editBoxX = w.FindAnyWidget(m_sEditBoxXName);
41 Widget editBoxY = w.FindAnyWidget(m_sEditBoxYName);
42 Widget editBoxZ = w.FindAnyWidget(m_sEditBoxZName);
43
44 if (!editBoxX || !editBoxY || !editBoxZ)
45 return;
46
47 Widget editBoxComponentX = editBoxX.FindAnyWidget(m_sEditBoxComponentName);
48 Widget editBoxComponentY = editBoxY.FindAnyWidget(m_sEditBoxComponentName);
49 Widget editBoxComponentZ = editBoxZ.FindAnyWidget(m_sEditBoxComponentName);
50
51 if (!editBoxComponentX || !editBoxComponentY || !editBoxComponentZ)
52 return;
53
54 m_EditBoxX = SCR_EditBoxComponent.Cast(editBoxComponentX.FindHandler(SCR_EditBoxComponent));
55 m_EditBoxY = SCR_EditBoxComponent.Cast(editBoxComponentY.FindHandler(SCR_EditBoxComponent));
56 m_EditBoxZ = SCR_EditBoxComponent.Cast(editBoxComponentZ.FindHandler(SCR_EditBoxComponent));
57
58 if (!m_EditBoxX || !m_EditBoxY || !m_EditBoxZ)
59 return;
60
61 m_EditBoxX.m_OnConfirm.Insert(OnEditBoxValueChanged);
62 m_EditBoxY.m_OnConfirm.Insert(OnEditBoxValueChanged);
63 m_EditBoxZ.m_OnConfirm.Insert(OnEditBoxValueChanged);
64
65 //Enable disable Y
66 SCR_BaseEditorAttribute snapAattribute;
67 if (m_AttributeManager.GetActiveAttribute(SCR_SnapYPositionEditorAttribute, snapAattribute))
68 {
69 SCR_SnapYPositionEditorAttribute snapYAttribute = SCR_SnapYPositionEditorAttribute.Cast(snapAattribute);
70 if (snapYAttribute)
71 {
72 snapYAttribute.GetOnChanged().Insert(OnSnapYChanged);
73 OnSnapYChanged(snapYAttribute.GetVariableOrCopy().GetBool());
74 }
75 }
76 //Always snap if snap attribute not found
77 else
78 {
79 OnSnapYChanged(true);
80 }
81
83
84 if (var)
86
87 //Hide if gamepad
88 OnInputDeviceIsGamepad(!GetGame().GetInputManager().IsUsingMouseAndKeyboard());
89 super.Init(w, attribute);
90 }
91
92 protected void OnSnapYChanged(bool snapEnabled)
93 {
94 m_bSnapToSurface = snapEnabled;
95 m_EditBoxY.SetEnabled(!snapEnabled);
96
97 if (snapEnabled)
98 {
99 m_fPositionY = m_EditBoxY.GetValue().ToFloat();
100 m_EditBoxY.SetValue(" ");
101 }
102 else
103 {
105 }
106
107 OnChangeInternal(null, 1, 0, false);
108 }
109
110 protected void OnInputDeviceIsGamepad(bool isGamepad)
111 {
112 SetVisible(!isGamepad);
113 }
114
115 protected void SetVisible(bool newVisible)
116 {
118 if (!attribute)
119 return;
120
122 if (!var)
123 return;
124
125 if (!newVisible)
126 {
127 m_vHideValue = var.GetVector();
129 }
130 else
131 {
133 }
134
135 m_root.SetVisible(newVisible);
136 }
137
138 //Sets a default state for the UI and var value if conflicting attribute
149
151 {
152 super.SetFromVar(var);
153
154 if (!var)
155 return;
156
157 vector value = var.GetVector();
158 m_EditBoxX.SetValue(CapValueToString(value[0]));
159 m_EditBoxZ.SetValue(CapValueToString(value[2]));
160
161 if (!m_bSnapToSurface)
162 m_EditBoxY.SetValue(CapValueToString(value[1]));
163 else
164 m_fPositionY = value[1];
165 }
166
167 override bool OnChangeInternal(Widget w, int x, int y, bool finished)
168 {
169 if (x != 1)
170 return false;
171
173 if (!attribute)
174 return false;
175
176 SCR_BaseEditorAttributeVar var = attribute.GetVariable(true);
177 if (!var)
178 return false;
179
180 float xValue = m_EditBoxX.GetValue().ToFloat();
181 float yValue;
182 float zValue = m_EditBoxZ.GetValue().ToFloat();
183
185 yValue = m_World.GetSurfaceY(xValue, zValue);
186 else
187 yValue = m_EditBoxY.GetValue().ToFloat();
188
189 vector Value = Vector(xValue, yValue, zValue);
190
191 var.SetVector(Value);
192 return false;
193 }
194
195 protected void OnEditBoxValueChanged(SCR_EditBoxComponent editBox, string stringValue)
196 {
197 float value = stringValue.ToFloat();
198
199 //X box
200 if (editBox == m_EditBoxX)
201 {
202 if (value < m_vMinWorldBounding[0])
203 value = m_vMinWorldBounding[0];
204 else if (value > m_vMaxWorldBounding[0])
205 value = m_vMaxWorldBounding[0];
206 }
207 //Y box
208 else if (editBox == m_EditBoxY)
209 {
210 if (!m_bSnapToSurface)
211 {
212 if (value < m_vMinWorldBounding[1])
213 value = m_vMinWorldBounding[1];
214 else if (value > m_vMaxWorldBounding[1])
215 value = m_vMaxWorldBounding[1];
216 }
217 }
218 //Z box
219 else
220 {
221 if (value < m_vMinWorldBounding[2])
222 value = m_vMinWorldBounding[2];
223 else if (value > m_vMaxWorldBounding[2])
224 value = m_vMaxWorldBounding[2];
225 }
226
227 editBox.SetValue(CapValueToString(value));
228
229 OnChangeInternal(null, 1, 0, false);
230 }
231
232 protected string CapValueToString(float value)
233 {
234 const int decimals = 2;
235
236 float coef = Math.Pow(10, decimals);
237 value = Math.Round(value * coef);
238 string valueText = value.ToString();
239
240 for (int i = 0, count = decimals - valueText.Length() + 1; i < count; i++)
241 {
242 valueText = "0" + valueText;
243 }
244 int length = valueText.Length();
245 valueText = valueText.Substring(0, length - decimals) + "." + valueText.Substring(length - decimals, decimals);
246
247
248 return valueText;
249 }
250
251 override void HandlerDeattached(Widget w)
252 {
253 GetGame().OnInputDeviceIsGamepadInvoker().Remove(OnInputDeviceIsGamepad);
254
256 {
257 SCR_BaseEditorAttribute attribute;
258 if (m_AttributeManager.GetActiveAttribute(SCR_SnapYPositionEditorAttribute, attribute))
259 {
261 if (snapYAttribute)
262 {
263 snapYAttribute.GetOnChanged().Remove(OnSnapYChanged);
264 }
265 }
266 }
267
268 }
269};
270
ArmaReforgerScripted GetGame()
Definition game.c:1398
InputManager GetInputManager()
Definition Math.c:13
Base Attribute Script for other attributes to inherent from to get and set varriables in Editor Attri...
sealed SCR_BaseEditorAttributeVar GetVariable(bool createWhenNull=false)
sealed SCR_BaseEditorAttributeVar GetVariableOrCopy()
Get attribute this component represents return Editor attribute *SCR_BaseEditorAttribute GetAttribute()
SCR_AttributesManagerEditorComponent m_AttributeManager
void SetValue(string value)
User API.
void OnEditBoxValueChanged(SCR_EditBoxComponent editBox, string stringValue)
override void Init(Widget w, SCR_BaseEditorAttribute attribute)
override void SetFromVar(SCR_BaseEditorAttributeVar var)
override void SetVariableToDefaultValue(SCR_BaseEditorAttributeVar var)
override bool OnChangeInternal(Widget w, int x, int y, bool finished)
SCR_FieldOfViewSettings Attribute
proto native vector Vector(float x, float y, float z)