Add block limit editor, various UI tweaks

This commit is contained in:
John Gross
2018-01-24 12:48:01 -08:00
parent 0328876d50
commit 6fbc06081e
12 changed files with 346 additions and 190 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
@@ -15,6 +16,7 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using VRage.Game;
using VRage.Serialization;
namespace Torch.Views
{
@@ -52,8 +54,8 @@ namespace Torch.Views
var properties = t.GetProperties(BindingFlags.Instance | BindingFlags.Public);
var grid = new Grid();
grid.ColumnDefinitions.Add(new ColumnDefinition());
grid.ColumnDefinitions.Add(new ColumnDefinition());
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(2, GridUnitType.Star) });
grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
var curRow = 0;
foreach (var property in properties.OrderBy(x => x.Name))
@@ -64,6 +66,7 @@ namespace Torch.Views
grid.RowDefinitions.Add(new RowDefinition());
var displayName = property.GetCustomAttribute<DisplayAttribute>()?.Name;
var propertyType = property.PropertyType;
var text = new TextBlock
{
@@ -86,12 +89,12 @@ namespace Torch.Views
};
valueControl.SetBinding(TextBlock.TextProperty, binding);
}
else if (property.PropertyType == typeof(bool) || property.PropertyType == typeof(bool?))
else if (propertyType == typeof(bool) || propertyType == typeof(bool?))
{
valueControl = new CheckBox();
valueControl.SetBinding(CheckBox.IsCheckedProperty, property.Name);
}
else if (property.PropertyType.IsEnum)
else if (propertyType.IsEnum)
{
valueControl = new ComboBox
{
@@ -99,6 +102,28 @@ namespace Torch.Views
};
valueControl.SetBinding(ComboBox.SelectedItemProperty, property.Name);
}
else if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Dictionary<,>))
{
var button = new Button
{
Content = "Edit Collection"
};
button.SetBinding(Button.DataContextProperty, property.Name);
button.Click += (sender, args) => EditDictionary(((Button)sender).DataContext);
valueControl = button;
}
else if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(SerializableDictionary<,>))
{
var button = new Button
{
Content = "Edit Collection"
};
button.SetBinding(Button.DataContextProperty, $"{property.Name}.Dictionary");
button.Click += (sender, args) => EditDictionary(((Button)sender).DataContext);
valueControl = button;
}
else
{
valueControl = new TextBox();
@@ -118,6 +143,12 @@ namespace Torch.Views
return grid;
}
private void EditDictionary(object dict)
{
var dic = (IDictionary)dict;
new DictionaryEditorDialog().Edit(dic);
}
private void UpdateFilter(object sender, TextChangedEventArgs e)
{
var filterText = ((TextBox)sender).Text;