-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1f5d22
commit 253faf1
Showing
5 changed files
with
123 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<UserControl x:Class="UndertaleModTool.FlagsBox" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:local="clr-namespace:UndertaleModTool" | ||
mc:Ignorable="d" | ||
d:DesignHeight="450" d:DesignWidth="800" | ||
x:Name="flagsBox"> | ||
<UserControl.Resources> | ||
<local:EnumToValuesConverter x:Key="enumToValuesConverter" /> | ||
</UserControl.Resources> | ||
<StackPanel> | ||
<TextBox Text="{Binding Value, ElementName=flagsBox}" /> | ||
<Expander Header="Flags"> | ||
<ItemsControl ItemsSource="{Binding Value, ElementName=flagsBox, Converter={StaticResource enumToValuesConverter}}"> | ||
<ItemsControl.ItemTemplate> | ||
<DataTemplate> | ||
<StackPanel> | ||
<CheckBox> | ||
<CheckBox.Resources> | ||
<local:EnumFlagToBoolConverter x:Key="enumFlagToBoolConverter"/> | ||
</CheckBox.Resources> | ||
<CheckBox.IsChecked> | ||
<MultiBinding Converter="{StaticResource enumFlagToBoolConverter}"> | ||
<Binding Path="Value" ElementName="flagsBox" /> | ||
<Binding Path="."/> | ||
</MultiBinding> | ||
</CheckBox.IsChecked> | ||
<Label Content="{Binding}" Padding="0" /> | ||
</CheckBox> | ||
</StackPanel> | ||
</DataTemplate> | ||
</ItemsControl.ItemTemplate> | ||
</ItemsControl> | ||
</Expander> | ||
</StackPanel> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
/// <summary> | ||
/// Interaction logic for FlagsBox.xaml | ||
/// </summary> | ||
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<string>(); | ||
} | ||
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 }; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters