void ChangeValue(float change) { // This gets a bit complicated because we want to deal with both ints and floats float newDictVal = 0; float newFieldVal = 0; // Do the actual alteration if (dict) { newDictVal = dict.GetFloat(key) + change; } if (field.member != "") { newFieldVal = field.GetFloat() + change; } if (loopMaxAndMin) { if (((newDictVal > maximum && increasePerSecond > 0) || (newDictVal < minimum && increasePerSecond < 0)) || ((newFieldVal > maximum && increasePerSecond > 0) || (newFieldVal < minimum && increasePerSecond < 0))) { increasePerSecond = -increasePerSecond; } print(newFieldVal + " " + change); } else if (limitToMaxAndMin) { newDictVal = newDictVal.LimitToRange(minimum, maximum); newFieldVal = newFieldVal.LimitToRange(minimum, maximum); } // Set the values, making sure we use correct type if (dict) { if (dict.Get(key) is int) { dict.Set(key, (int)newDictVal); } else { dict.Set(key, newDictVal); } } if (field.member != "") { if (field.GetObject() is int) { field.SetValue((int)newFieldVal); } else { field.SetValue(newFieldVal); } } }
private void comCb_SelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBox cb = sender as ComboBox; ComponentField cf = cb.Tag as ComponentField; cf.SetValue(cb.SelectedIndex == 0 ? "true" : "false"); }
private void VecElement_EnterKeyDown(object sender, KeyEventArgs e) { Vector3Control vc = sender as Vector3Control; ComponentField cf = vc.Tag as ComponentField; cf.SetValue(vc.X + "," + vc.Y + "," + vc.Z); }
private void comNumTb__KeyUp(object sender, KeyEventArgs e) { if (e.Key != Key.Enter) { return; } NumberTextBox tb = sender as NumberTextBox; ComponentField cf = tb.Tag as ComponentField; cf.SetValue(tb.Text); }
void Update() { GameObject selected; try { selected = stSelection.selectedObjects[0]; } catch { selected = null; } if (lastSelected != selected) { field.SetValue(selected); } lastSelected = selected; }
void Update() { float change = 0; if (oncePerClick) { if (Input.GetButtonDown(input)) { change = stTools.GetAxisNorm(input) * delta; } } else { if (softenInput) { change = Input.GetAxis(input) * delta; } else { change = stTools.GetAxisNorm(input) * delta; } } if (change != 0) { float newVal; if (dict) { newVal = dict.GetFloat(key) + change; if (limits) { newVal = newVal.LimitToRange(minLimit, maxLimit); } dict.Set(key, newVal); } if (field.member != "") { newVal = field.GetFloat() + change; if (limits) { newVal = newVal.LimitToRange(minLimit, maxLimit); } field.SetValue(newVal); } } }
public void SetField() { field.SetValue(dict.Get(key)); }
void Alter() { if (!enabled) { return; } // This gets a bit complicated because we want to deal with both ints and floats float newDictVal = 0; float newFieldVal = 0; // Do the actual alteration switch (operation) { case OperationEnum.Add: if (dict) { newDictVal = dict.GetFloat(key) + value; } if (field.member != "") { newFieldVal = field.GetFloat() + value; } break; case OperationEnum.SetTo: if (dict) { newDictVal = value; } if (field.member != "") { newFieldVal = value; } break; case OperationEnum.Multiply: if (dict) { newDictVal = dict.GetFloat(key) * value; } if (field.member != "") { newFieldVal = field.GetFloat() * value; } break; } // Set the values, making sure we use correct type if (dict) { if (dict.Get(key) is int) { dict.Set(key, (int)newDictVal); } else { dict.Set(key, newDictVal); } } if (field.member != "") { if (field.GetObject() is int) { field.SetValue((int)newFieldVal); } else { field.SetValue(newFieldVal); } } }
private void createComponentRow(PropertyInfo prop, int row, PropertyFieldAttribute attr) { IList <ComponentRef> componentList = prop.GetValue(_selectedObject) as IList <ComponentRef>; Type comType = typeof(ComponentRef); for (int i = 0; i < componentList.Count; i++) { gridAddRowDef(); CheckBox check = createCheckBox(); check.IsChecked = componentList[i].GetIsActive(); check.Tag = componentList[i]; check.Checked += Check_Checked; check.Unchecked += Check_Unchecked; gridAddTitle(15, componentList[i].GetName()); gridAddEnd(); ComponentRef com = componentList[i]; List <ComponentField> fieldList = com.GetFields(); for (int j = 0; j < fieldList.Count; j++) { gridAddRowDef(); TextBlock title = gridAddTitle(30, fieldList[j].Name); if ((fieldList[j].Type & ComponentFieldType.FT_FLOAT) == ComponentFieldType.FT_FLOAT || (fieldList[j].Type & ComponentFieldType.FT_INT) == ComponentFieldType.FT_INT) { NumberTextBox tb = createNumberTextBox(); tb.Text = fieldList[j].Value; tb.Tag = fieldList[j]; tb._KeyUp += comNumTb__KeyUp; title.Tag = fieldList[j]; float value = Convert.ToSingle(fieldList[j].Value); title.MouseLeftButtonDown += new MouseButtonEventHandler((object sender, MouseButtonEventArgs e) => { _mouseDown = true; _mousePosX = e.GetPosition(null).X; title.CaptureMouse(); }); title.MouseMove += new MouseEventHandler((object sender, MouseEventArgs e) => { if (_mouseDown) { double xPos = e.GetPosition(null).X; ComponentField f = (sender as TextBlock).Tag as ComponentField; if ((f.Type & ComponentFieldType.FT_READONLY) == ComponentFieldType.FT_READONLY) { return; } if ((f.Type & ComponentFieldType.FT_FLOAT) == ComponentFieldType.FT_FLOAT) { if (xPos > _mousePosX) { value += 0.01f; } else if (xPos < _mousePosX) { value -= 0.01f; } } else if ((f.Type & ComponentFieldType.FT_INT) == ComponentFieldType.FT_INT) { if (xPos > _mousePosX) { value += 1; } else if (xPos < _mousePosX) { value -= 1; } } tb.Text = value.ToString(); f.SetValue(tb.Text); _mousePosX = xPos; } }); title.MouseLeftButtonUp += new MouseButtonEventHandler((object sender, MouseButtonEventArgs e) => { _mouseDown = false; _mousePosX = 0; title.ReleaseMouseCapture(); }); } else if (fieldList[j].Type == ComponentFieldType.FT_OBJECT) { TextBox tb = createTextBox(true); tb.Tag = fieldList[j]; tb.KeyUp += comTb_KeyUp; tb.Text = fieldList[j].Value; } else if (fieldList[j].Type == ComponentFieldType.FT_BOOLEAN) { ComboBox cb = createBoolControl(); cb.Tag = fieldList[j]; cb.SelectionChanged += comCb_SelectionChanged; cb.SelectedIndex = fieldList[j].Value == "true" ? 0 : 1; } else if (fieldList[j].Type == ComponentFieldType.FT_VECTOR3) { var vecElement = new Vector3Control(); string[] vStr = fieldList[j].Value.Split(','); Vector3 vec = new Vector3(Convert.ToSingle(vStr[0]), Convert.ToSingle(vStr[1]), Convert.ToSingle(vStr[2])); vecElement.ValueObject = vec; vecElement.Margin = new Thickness(0, 2, 2, 0); vecElement.BorderThickness = new Thickness(0); vecElement.Tag = fieldList[j]; Grid.SetColumn(vecElement, 1); Grid.SetRow(vecElement, _panelParent.RowDefinitions.Count - 1); var template = (ControlTemplate)_View.Resources["validationErrorTemplate"]; Validation.SetErrorTemplate(vecElement, template); vecElement.EnterKeyDown += VecElement_EnterKeyDown; _panelParent.Children.Add(vecElement); } else { TextBox tb = createTextBox(false); tb.Tag = fieldList[j]; tb.KeyUp += comTb_KeyUp; tb.Text = fieldList[j].Value; } gridAddEnd(); } } }