public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { Type type = value.GetType(); var das = type.GetCustomAttributes <DescriptionAttribute>(); if (das.Count() == 0) { return(type.Name); } var da = das.First(); List <String> formatValues = new List <String>(); foreach (PropertyInfo pInfo in type.GetProperties()) { ELogicType gameType = AssemblyUtil.GetPropertyLogicType(pInfo); if (gameType == ELogicType.Ivalid) { LogManager.Instance.Warn("找不到属性对应的逻辑类型: " + pInfo.Name); continue; } if (gameType == ELogicType.Int || gameType == ELogicType.String) { formatValues.Add(pInfo.GetValue(value).ToString()); } else if (gameType == ELogicType.Percent) { formatValues.Add(pInfo.GetValue(value).ToString() + "%"); } else if (gameType == ELogicType.BuffType) { formatValues.Add("Buff:" + ID2BuffNameConverter.ConvertTypeToBuffName((int)pInfo.GetValue(value))); } else if (gameType == ELogicType.Element) { formatValues.Add(((EElement)pInfo.GetValue(value)).ToString()); } else { LogManager.Instance.Warn("SkillCondition2FormatDescConverter未定义属性格式化的方法:" + gameType + " 默认格式化为字符串"); formatValues.Add(pInfo.GetValue(value).ToString()); } } return(string.Format(da.Description, formatValues.ToArray())); }
// 创建一个动态属性编辑项 private Grid createPropEntryGrid(PropertyInfo propInfo) { Grid grid = new Grid(); Label lbSCParamName = new Label(); lbSCParamName.Content = propInfo.Name; grid.Children.Add(lbSCParamName); ELogicType logicType = AssemblyUtil.GetPropertyLogicType(propInfo); if (logicType == ELogicType.Int || logicType == ELogicType.Percent) { TextBox tbSCParamValue = new TextBox(); Binding tbBinding = new Binding(propInfo.Name); tbBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; tbSCParamValue.SetBinding(TextBox.TextProperty, tbBinding); tbSCParamValue.Margin = new Thickness(80, 4, 0, 4); grid.Children.Add(tbSCParamValue); } else if (logicType == ELogicType.String) { LogManager.Instance.Error("此版本不支持String类型的动态类属性: " + propInfo.Name); } else if (logicType == ELogicType.BuffType) { Button btnBuff = new Button(); Binding txtBinding = new Binding(propInfo.Name); txtBinding.Converter = (IValueConverter)Application.Current.TryFindResource("ID2BuffNameConverter"); btnBuff.SetBinding(Button.ContentProperty, txtBinding); btnBuff.Margin = new Thickness(80, 4, 0, 4); grid.Children.Add(btnBuff); btnBuff.Click += (o, re) => { BuffPickWindow buffPickWindow = new BuffPickWindow(); if (buffPickWindow.ShowDialog() == true) { propInfo.SetValue(btnBuff.DataContext, buffPickWindow.PickedBuffType); } }; } else if (logicType == ELogicType.Element) { ComboBox cb = new ComboBox(); cb.ItemsSource = Enum.GetNames(typeof(EElement)); Binding binding = new Binding(propInfo.Name); binding.Converter = (IValueConverter)Application.Current.TryFindResource("Enum2StrConverter"); binding.ConverterParameter = typeof(EElement); cb.SetBinding(ComboBox.TextProperty, binding); cb.Margin = new Thickness(80, 4, 0, 4); grid.Children.Add(cb); } else { LogManager.Instance.Error("配置了不支持的参数类型: " + propInfo.Name + " - " + logicType); } return(grid); }
public LogicTypeAttribute(ELogicType logicType) { LogicType = logicType; }