protected override void OnUpdateVisual() { base.OnUpdateVisual(); var first = FirstBlock; if (first != null) { m_color.OnChange -= m_changeColor; m_color.SetColor(Getter(first)); m_color.OnChange += m_changeColor; } }
protected MyGuiControlColor AddColor(String text, Color value, Action <MyGuiControlColor> setter) { MyGuiControlColor colorControl = AddColor(text); colorControl.SetColor(value); colorControl.OnChange += delegate(MyGuiControlColor sender) { setter(colorControl); }; return(colorControl); }
public override void RecreateControls(bool constructor) { base.RecreateControls(constructor); BackgroundColor = new Vector4(1f, 1f, 1f, 0.5f); m_currentPosition = -m_size.Value / 2.0f + new Vector2(0.02f, 0.13f); AddCaption("Voxel materials", Color.Yellow.ToVector4()); AddShareFocusHint(); m_materialsCombo = AddCombo(); var defList = MyDefinitionManager.Static.GetVoxelMaterialDefinitions().OrderBy(x => x.Id.SubtypeName).ToList(); foreach (var material in defList) { m_materialsCombo.AddItem(material.Index, new StringBuilder(material.Id.SubtypeName)); } m_materialsCombo.ItemSelected += materialsCombo_OnSelect; m_currentPosition.Y += 0.01f; m_sliderInitialScale = AddSlider("Initial scale", 0, 1f, 100f, null); m_sliderScaleMultiplier = AddSlider("Scale multiplier", 0, 1f, 100f, null); m_sliderInitialDistance = AddSlider("Initial distance", 0, 1f, 100f, null); m_sliderDistanceMultiplier = AddSlider("Distance multiplier", 0, 1f, 100f, null); m_sliderFar1Distance = AddSlider("Far1 distance", 0, 0f, 20000f, null); m_sliderFar1Scale = AddSlider("Far1 scale", 0, 1f, 50000f, null); m_sliderFar2Distance = AddSlider("Far2 distance", 0, 0f, 20000f, null); m_sliderFar2Scale = AddSlider("Far2 scale", 0, 1f, 50000f, null); m_sliderFar3Distance = AddSlider("Far3 distance", 0, 0f, 40000f, null); m_sliderFar3Scale = AddSlider("Far3 scale", 0, 1f, 50000f, null); m_sliderExtScale = AddSlider("Detail scale (/1000)", 0, 0.01f, 1f, null); m_materialsCombo.SelectItemByIndex(0); m_colorFar3 = AddColor(new StringBuilder("Far3 color"), m_selectedVoxelMaterial, MemberHelper.GetMember(() => m_selectedVoxelMaterial.Far3Color)); m_colorFar3.SetColor(m_selectedVoxelMaterial.Far3Color); m_currentPosition.Y += 0.01f; AddButton(new StringBuilder("Reload definition"), OnReloadDefinition); }
void UpdateValues() { m_canUpdate = false; m_sliderInitialScale.Value = m_selectedVoxelMaterial.InitialScale; m_sliderScaleMultiplier.Value = m_selectedVoxelMaterial.ScaleMultiplier; m_sliderInitialDistance.Value = m_selectedVoxelMaterial.InitialDistance; m_sliderDistanceMultiplier.Value = m_selectedVoxelMaterial.DistanceMultiplier; m_sliderFar1Scale.Value = m_selectedVoxelMaterial.Far1Scale; m_sliderFar1Distance.Value = m_selectedVoxelMaterial.Far1Distance; m_sliderFar2Scale.Value = m_selectedVoxelMaterial.Far2Scale; m_sliderFar2Distance.Value = m_selectedVoxelMaterial.Far2Distance; m_sliderFar3Scale.Value = m_selectedVoxelMaterial.Far3Scale; m_sliderFar3Distance.Value = m_selectedVoxelMaterial.Far3Distance; if (m_colorFar3 != null) { m_colorFar3.SetColor(m_selectedVoxelMaterial.Far3Color); } m_sliderExtScale.Value = 1000.0f * m_selectedVoxelMaterial.ExtensionDetailScale; m_canUpdate = true; }
protected MyGuiControlColor AddColor(StringBuilder text, object instance, MemberInfo memberInfo) { MyGuiControlColor colorControl = AddColor(text); if (memberInfo is PropertyInfo) { PropertyInfo property = (PropertyInfo)memberInfo; var val = property.GetValue(instance, new object[0]); if (val is Color) { colorControl.SetColor((Color)val); } else if (val is Vector3) { colorControl.SetColor((Vector3)val); } else if (val is Vector4) { colorControl.SetColor((Vector4)val); } colorControl.UserData = new Tuple <object, PropertyInfo>(instance, property); colorControl.OnChange += delegate(MyGuiControlColor sender) { Tuple <object, PropertyInfo> tuple = sender.UserData as Tuple <object, PropertyInfo>; if (tuple.Item2.MemberType.GetType() == typeof(Color)) { tuple.Item2.SetValue(tuple.Item1, sender.GetColor(), new object[0]); ValueChanged(sender); } else if (tuple.Item2.MemberType.GetType() == typeof(Vector3)) { tuple.Item2.SetValue(tuple.Item1, sender.GetColor().ToVector3(), new object[0]); ValueChanged(sender); } else if (tuple.Item2.MemberType.GetType() == typeof(Vector4)) { tuple.Item2.SetValue(tuple.Item1, sender.GetColor().ToVector4(), new object[0]); ValueChanged(sender); } }; } else if (memberInfo is FieldInfo) { FieldInfo field = (FieldInfo)memberInfo; var val = field.GetValue(instance); if (val is Color) { colorControl.SetColor((Color)val); } else if (val is Vector3) { colorControl.SetColor((Vector3)val); } else if (val is Vector4) { colorControl.SetColor((Vector4)val); } colorControl.UserData = new Tuple <object, FieldInfo>(instance, field); colorControl.OnChange += delegate(MyGuiControlColor sender) { Tuple <object, FieldInfo> tuple = sender.UserData as Tuple <object, FieldInfo>; if (tuple.Item2.FieldType == typeof(Color)) { tuple.Item2.SetValue(tuple.Item1, sender.GetColor()); ValueChanged(sender); } else if (tuple.Item2.FieldType == typeof(Vector3)) { tuple.Item2.SetValue(tuple.Item1, sender.GetColor().ToVector3()); ValueChanged(sender); } else if (tuple.Item2.FieldType == typeof(Vector4)) { tuple.Item2.SetValue(tuple.Item1, sender.GetColor().ToVector4()); ValueChanged(sender); } }; } else { System.Diagnostics.Debug.Assert(false, "Unknown type of memberInfo"); } return(colorControl); }