diff --git a/UndertaleModTool/Controls/FlagsBox.xaml b/UndertaleModTool/Controls/FlagsBox.xaml new file mode 100644 index 000000000..0a6c541bc --- /dev/null +++ b/UndertaleModTool/Controls/FlagsBox.xaml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/UndertaleModTool/Controls/FlagsBox.xaml.cs b/UndertaleModTool/Controls/FlagsBox.xaml.cs new file mode 100644 index 000000000..af0c3c1c1 --- /dev/null +++ b/UndertaleModTool/Controls/FlagsBox.xaml.cs @@ -0,0 +1,79 @@ +using System; +using System.Globalization; +using System.Linq; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; + +namespace UndertaleModTool +{ + /// + /// Interaction logic for FlagsBox.xaml + /// + public partial class FlagsBox : UserControl + { + public object Value + { + get { return (object)GetValue(ValueProperty); } + set { SetValue(ValueProperty, value); } + } + + public static readonly DependencyProperty ValueProperty = + DependencyProperty.Register("Value", typeof(object), + typeof(FlagsBox), + new FrameworkPropertyMetadata(null, + FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); + + public FlagsBox() + { + InitializeComponent(); + } + } + + public class EnumToValuesConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is null) + { + return Array.Empty(); + } + return Enum.GetValues(value.GetType()); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return null; + } + } + + public class EnumFlagToBoolConverter : IMultiValueConverter + { + dynamic enumValue; + dynamic flag; + + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + if (values.Any(x => x == DependencyProperty.UnsetValue)) + return DependencyProperty.UnsetValue; + + enumValue = (Enum)values[0]; + flag = (Enum)values[1]; + + return enumValue.HasFlag(flag); + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + if ((bool)value) + { + enumValue |= flag; + } + else + { + enumValue &= ~flag; + } + return new object[] { enumValue, flag }; + } + } +} diff --git a/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml b/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml index 9502b18e2..d8ac82f02 100644 --- a/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml +++ b/UndertaleModTool/Editors/UndertaleGeneralInfoEditor.xaml @@ -118,7 +118,7 @@ Flags - + License MD5 @@ -148,7 +148,7 @@ Function classifications - + Steam AppID @@ -262,7 +262,7 @@ Flags - + Scale diff --git a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml index c1a3a53d9..63e3b417a 100644 --- a/UndertaleModTool/Editors/UndertaleRoomEditor.xaml +++ b/UndertaleModTool/Editors/UndertaleRoomEditor.xaml @@ -384,7 +384,7 @@ - + @@ -433,7 +433,7 @@ Flags - + World diff --git a/UndertaleModTool/Editors/UndertaleSoundEditor.xaml b/UndertaleModTool/Editors/UndertaleSoundEditor.xaml index 5bc2145c2..cd76c5958 100644 --- a/UndertaleModTool/Editors/UndertaleSoundEditor.xaml +++ b/UndertaleModTool/Editors/UndertaleSoundEditor.xaml @@ -31,7 +31,7 @@ Flags - + Type