public void SetConfigType(ConfigBase <T> tp) { this.config_current = tp; configSetting = ConfigEditorAttribute.GetCurrentAttribute <ConfigEditorAttribute>(tp); this.titleContent = new GUIContent(string.IsNullOrEmpty(configSetting.EditorTitle) ? typeof(T).Name : configSetting.EditorTitle); fieldinfos = typeof(T).GetFields().ToList(); Chache = new List <ConfigEditorSchemaChache>(); foreach (var item in fieldinfos) { var infos = item.GetCustomAttributes(typeof(ConfigEditorFieldAttribute), true); ConfigEditorSchemaChache f = new ConfigEditorSchemaChache(); f.field_info = item; f.order = 0; if (infos.Length == 0) { continue; } else { ConfigEditorFieldAttribute cefa = (ConfigEditorFieldAttribute)infos[0]; f.order = cefa.Order; f.config_editor_field = cefa; } Chache.Add(f); } if (Chache.Count > 0) { Chache = Chache.OrderByDescending(x => x.order).ToList(); } initialized = true; }
private void CreateFilesystemControl(NameAttribute displayNameAttribute, RequiredAttribute requiredAttribute, ConfigEditorAttribute editorTypeAttribute, Binding b) { var fileSystemControl = new ConfigFileSystemControl(); fileSystemControl.ConfigItemDisplayName = _localController.GetLocalString(displayNameAttribute.LocalType, displayNameAttribute.DisplayName); fileSystemControl.SetBinding(ConfigFileSystemControl.ConfigItemValueProperty, b); fileSystemControl.WaterMarkText = requiredAttribute != null?_localController.GetLocalStrings <SDGuiStrings>().Mandatory : _localController.GetLocalStrings <SDGuiStrings>().Optional; fileSystemControl.WaterMarkColor = requiredAttribute != null ? (SolidColorBrush)TryFindResource("Color_FadedRed") : (SolidColorBrush)TryFindResource("Color_FadedGray"); fileSystemControl.IsFileSelector = editorTypeAttribute.Editor == EditorType.Filepicker; configItemPanel.Children.Add(fileSystemControl); }
private void CreateComboboxControl(NameAttribute displayNameAttribute, RequiredAttribute requiredAttribute, ConfigEditorAttribute editorTypeAttribute, Binding b) { var dropDownControl = new ConfigComboBoxControl(); dropDownControl.ConfigItemDisplayName = _localController.GetLocalString(displayNameAttribute.LocalType, displayNameAttribute.DisplayName); dropDownControl.SourceList = (ComboBoxList)Activator.CreateInstance(editorTypeAttribute.SourceListType); dropDownControl.SetBinding(ConfigComboBoxControl.SelectedValueProperty, b); dropDownControl.WaterMarkText = requiredAttribute != null?_localController.GetLocalStrings <SDGuiStrings>().Mandatory : _localController.GetLocalStrings <SDGuiStrings>().Optional; dropDownControl.WaterMarkColor = requiredAttribute != null ? (SolidColorBrush)TryFindResource("Color_FadedRed") : (SolidColorBrush)TryFindResource("Color_FadedGray"); configItemPanel.Children.Add(dropDownControl); }
public void SetConfigType(ConfigBase <T> tp) { this.config_current = tp; configSetting = ConfigEditorAttribute.GetCurrentAttribute <ConfigEditorAttribute>(tp) ?? new ConfigEditorAttribute(); this.titleContent = new GUIContent(string.IsNullOrEmpty(configSetting.Setting.EditorTitle) ? typeof(T).Name : configSetting.Setting.EditorTitle); fieldinfos = typeof(T).GetFields().ToList(); Chache = new List <ConfigEditorSchemaChache>(); foreach (var item in fieldinfos) { var infos = item.GetCustomAttributes(typeof(ConfigEditorFieldAttribute), true); ConfigEditorSchemaChache f = new ConfigEditorSchemaChache(); f.field_info = item; f.order = 0; if (infos.Length == 0) { int id = (int)GetCurrentFieldType(item.FieldType); f.config_editor_setting = Utility.GetDefaultControlConfig().SearchByID(id); if (f.config_editor_setting == null) { Log("Can't find default control id :" + id); } else { if (!f.config_editor_setting.Visibility) { continue; } } } else { ConfigEditorFieldAttribute cefa = (ConfigEditorFieldAttribute)infos[0]; f.order = cefa.Setting.Order; f.config_editor_setting = cefa.Setting; if (f.config_editor_setting.Width == 0) { int id = (int)GetCurrentFieldType(item.FieldType); var setting = Utility.GetDefaultControlConfig().SearchByID(id); f.config_editor_setting.Width = setting.Width; } if (!cefa.Setting.Visibility) { continue; } } Chache.Add(f); } if (Chache.Count > 0) { Chache = Chache.OrderByDescending(x => x.order).ToList(); } initialized = true; }
/// <summary> /// 设置想要编辑的类 /// </summary> /// <param name="tp"></param> public void SetConfigType(ConfigBase <T> tp) { Data = new ConfigEditorSchemaData <T>(); Data.config_current = tp; var configSetting = ConfigEditorAttribute.GetFirstAttribute <ConfigEditorAttribute>(tp) ?? new ConfigEditorAttribute(); //先读取用户定义的 如果没有配置直接读取默认的 Data.currentEditorSetting = EditorConfig.GetCustomEditorPropertyConfig().SearchByOrderKey(configSetting.EditorConfigID) ?? EditorConfig.GetDefaultEditorPropertyConfig().SearchByOrderKey(configSetting.EditorConfigID); titleContent = new GUIContent(string.IsNullOrEmpty(Data.currentEditorSetting.EditorTitle) ? typeof(T).Name : Data.currentEditorSetting.EditorTitle); fieldinfos = typeof(T).GetFields().ToList(); //-- Chache -- Data.CurrentAssembly = Assembly.GetExecutingAssembly(); //-- Chache -- //-- Error -- ErrorLine = new List <int>(); //-- Error -- foreach (var item in fieldinfos) { var infos = item.GetCustomAttributes(typeof(ConfigEditorFieldAttribute), true); var f = new ConfigEditorSchemaChache { field_info = item }; if (infos.Length == 0) { int id = (int)ReflectionHelper.GetFieldTypeMapping(item.FieldType); f.config_editor_setting = EditorConfig.GetDefaultControlPropertyConfig().SearchByOrderKey(id); if (f.config_editor_setting == null) { Log("Can't find default control id :" + id); } else { if (!f.config_editor_setting.Visibility) { continue; } } } else { var cefa = (ConfigEditorFieldAttribute)infos[0]; f.CurrentFiledProperty = cefa.CurrentFiledProperty; //先查Custom配置 f.config_editor_setting = EditorConfig.GetCustomControlPropertyConfig().SearchByOrderKey(cefa.ControlPropertyID); //走属性默认配置 if (f.config_editor_setting == null && cefa.ControlPropertyID == 0) { int id = (int)ReflectionHelper.GetFieldTypeMapping(item.FieldType); f.config_editor_setting = EditorConfig.GetDefaultControlPropertyConfig().SearchByOrderKey(id); f.config_editor_setting = EditorConfig.GetDefaultControlPropertyConfig().SearchByOrderKey(id); } //走默认配置 if (f.config_editor_setting == null && cefa.ControlPropertyID != 0) { f.config_editor_setting = EditorConfig.GetDefaultControlPropertyConfig() .SearchByOrderKey(cefa.ControlPropertyID); } //如果默认配置被删除 为了防止报错 if (f.config_editor_setting == null) { Log("Can't find default control id :" + cefa.ControlPropertyID); continue; } if (!f.config_editor_setting.Visibility) { continue; } } Data.CurrentClassFieldsCache.Add(f); } if (Data.CurrentClassFieldsCache.Count > 0) { Data.CurrentClassFieldsCache = Data.CurrentClassFieldsCache.OrderByDescending(x => x.config_editor_setting.Order).ToList(); } initialized = true; }