4 protected string m_sEditBoxXName;
6 protected string m_sEditBoxYName;
8 protected string m_sEditBoxZName;
10 protected string m_sEditBoxComponentName;
12 protected BaseWorld m_World;
13 protected vector m_vMinWorldBounding;
14 protected vector m_vMaxWorldBounding;
20 protected Widget m_root;
21 protected vector m_vStartingValue;
22 protected vector m_vHideValue;
24 protected bool m_bSnapToSurface;
25 protected float m_fPositionY;
27 protected int m_iInitCalledAmount = 0;
32 GetGame().OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
38 m_World.GetBoundBox(m_vMinWorldBounding, m_vMaxWorldBounding);
40 Widget editBoxX = w.FindAnyWidget(m_sEditBoxXName);
41 Widget editBoxY = w.FindAnyWidget(m_sEditBoxYName);
42 Widget editBoxZ = w.FindAnyWidget(m_sEditBoxZName);
44 if (!editBoxX || !editBoxY || !editBoxZ)
47 Widget editBoxComponentX = editBoxX.FindAnyWidget(m_sEditBoxComponentName);
48 Widget editBoxComponentY = editBoxY.FindAnyWidget(m_sEditBoxComponentName);
49 Widget editBoxComponentZ = editBoxZ.FindAnyWidget(m_sEditBoxComponentName);
51 if (!editBoxComponentX || !editBoxComponentY || !editBoxComponentZ)
58 if (!m_EditBoxX || !m_EditBoxY || !m_EditBoxZ)
61 m_EditBoxX.m_OnConfirm.Insert(OnEditBoxValueChanged);
62 m_EditBoxY.m_OnConfirm.Insert(OnEditBoxValueChanged);
63 m_EditBoxZ.m_OnConfirm.Insert(OnEditBoxValueChanged);
72 snapYAttribute.GetOnChanged().Insert(OnSnapYChanged);
73 OnSnapYChanged(snapYAttribute.GetVariableOrCopy().GetBool());
85 m_vStartingValue = var.GetVector();
89 super.Init(w, attribute);
92 protected void OnSnapYChanged(
bool snapEnabled)
94 m_bSnapToSurface = snapEnabled;
95 m_EditBoxY.SetEnabled(!snapEnabled);
99 m_fPositionY = m_EditBoxY.GetValue().ToFloat();
100 m_EditBoxY.SetValue(
" ");
104 m_EditBoxY.SetValue(CapValueToString(m_fPositionY));
107 OnChange(
null, 1, 0,
false);
110 protected void OnInputDeviceIsGamepad(
bool isGamepad)
112 SetVisible(!isGamepad);
115 protected void SetVisible(
bool newVisible)
127 m_vHideValue = var.GetVector();
128 var.SetVector(m_vStartingValue);
132 var.SetVector(m_vHideValue);
135 m_root.SetVisible(newVisible);
141 m_EditBoxX.SetValue(CapValueToString(m_vMinWorldBounding[0]));
142 m_EditBoxZ.SetValue(CapValueToString(m_vMinWorldBounding[2]));
144 if (!m_bSnapToSurface)
145 m_EditBoxY.SetValue(CapValueToString(m_vMinWorldBounding[1]));
147 m_fPositionY = m_vMinWorldBounding[1];
152 super.SetFromVar(var);
157 vector value = var.GetVector();
158 m_EditBoxX.SetValue(CapValueToString(value[0]));
159 m_EditBoxZ.SetValue(CapValueToString(value[2]));
161 if (!m_bSnapToSurface)
162 m_EditBoxY.SetValue(CapValueToString(value[1]));
164 m_fPositionY = value[1];
167 override bool OnChange(Widget w,
int x,
int y,
bool finished)
180 float xValue = m_EditBoxX.GetValue().ToFloat();
182 float zValue = m_EditBoxZ.GetValue().ToFloat();
184 if (m_bSnapToSurface)
185 yValue =
m_World.GetSurfaceY(xValue, zValue);
187 yValue = m_EditBoxY.GetValue().ToFloat();
189 vector Value = Vector(xValue, yValue, zValue);
191 var.SetVector(Value);
197 float value = stringValue.ToFloat();
200 if (editBox == m_EditBoxX)
202 if (value < m_vMinWorldBounding[0])
203 value = m_vMinWorldBounding[0];
204 else if (value > m_vMaxWorldBounding[0])
205 value = m_vMaxWorldBounding[0];
208 else if (editBox == m_EditBoxY)
210 if (!m_bSnapToSurface)
212 if (value < m_vMinWorldBounding[1])
213 value = m_vMinWorldBounding[1];
214 else if (value > m_vMaxWorldBounding[1])
215 value = m_vMaxWorldBounding[1];
221 if (value < m_vMinWorldBounding[2])
222 value = m_vMinWorldBounding[2];
223 else if (value > m_vMaxWorldBounding[2])
224 value = m_vMaxWorldBounding[2];
227 editBox.SetValue(CapValueToString(value));
229 OnChange(
null, 1, 0,
false);
232 protected string CapValueToString(
float value)
236 float coef = Math.Pow(10, decimals);
237 value = Math.Round(value * coef);
238 string valueText = value.ToString();
240 for (
int i = 0, count = decimals - valueText.Length() + 1; i < count; i++)
242 valueText =
"0" + valueText;
244 int length = valueText.Length();
245 valueText = valueText.Substring(0, length - decimals) +
"." + valueText.Substring(length - decimals, decimals);
251 override void HandlerDeattached(Widget w)
253 GetGame().OnInputDeviceIsGamepadInvoker().Remove(OnInputDeviceIsGamepad);
255 if (m_AttributeManager && m_EditBoxY)
263 snapYAttribute.GetOnChanged().Remove(OnSnapYChanged);