예제 #1
0
        /// <inheritdoc />
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            var formatter = values[0] as IQuantityFormatter;

            if (formatter == null)
            {
                return("first argument must be a IQuantityFormatter");
            }

            var row = values[0] as Row;

            if (row == null)
            {
                return("first argument must be a Row");
            }

            var oldValueStringFormat = row.OldValueStringFormat;

            if (!string.IsNullOrEmpty(oldValueStringFormat) &&
                FormatString.IsValidFormat(oldValueStringFormat, out var numberOfArguments, out var anyItemHasFormat))
            {
                if (numberOfArguments == 1 && anyItemHasFormat == false)
                {
                    var formattedValue = formatter.Format(row.OldValue as IQuantity);
                    return(string.Format(row.OldValueStringFormat, formattedValue));
                }

                return(string.Format(NumericBox.GetCulture(row), oldValueStringFormat, row.OldValue));
            }

            return(oldValueStringFormat);
        }
예제 #2
0
 public void Initialize()
 {
     NumericBox.Initialize();
     ActionPointManager.Initialize();
     CurrentHealth.SetMaxValue(NumericBox.HealthPoint_I.Value);
     CurrentHealth.Reset();
 }
예제 #3
0
 public void Initialize()
 {
     NumericBox.Initialize();
     ActionTrigger.Initialize();
     HealthPoint.SetMaxValue(99_999);
     HealthPoint.Reset();
 }
        public static Grid Grid_Number(ref NumericBox number, string str_lbl, string str_txt)
        {
            //-----------------------Label----------------
            Label lbl = new Label();

            lbl.Content             = str_lbl;
            lbl.HorizontalAlignment = HorizontalAlignment.Left;


            //---------------------TimeControl-----------------
            number.Name = str_txt;
            number.HorizontalAlignment = HorizontalAlignment.Left;
            number.Margin = new Thickness(150, 0, 0, 0);
            number.Width  = 200;


            //-----------------------Grid-----------------
            Grid grid = new Grid();

            grid.Children.Add(lbl);
            grid.Children.Add(number);
            grid.Margin = new Thickness(300, 10, 300, 0);
            DockPanel.SetDock(grid, Dock.Top);

            return(grid);
        }
예제 #5
0
 public void Initialize()
 {
     NumericBox.Initialize();
     ActionPointManager.Initialize();
     AddComponent <ConditionEventManagerComponent>();
     CurrentHealth.SetMaxValue(NumericBox.HealthPoint_I.Value);
     CurrentHealth.Reset();
 }
예제 #6
0
        public void SetUp()
        {
            UITester.Init(typeof(Utils.Net.Sample.App));

            UITester.Dispatcher.Invoke(() => UITester.Get <System.Windows.Controls.ComboBox>().SelectedItem = "OthersPage");
            System.Threading.Thread.Sleep(100);

            testNumericBox = UITester.Get <NumericBox>();
        }
예제 #7
0
 public void Update(string text, int caretIndex, bool increase, string expectedText, int expectedCaretIndex)
 {
     var doubleBox = new NumericBox
     {
         Text = text,
         CaretIndex = caretIndex
     };
     Assert.AreEqual(caretIndex, doubleBox.CaretIndex);
     doubleBox.Update(increase, CultureInfo.InvariantCulture);
     Assert.AreEqual(expectedText, doubleBox.Text);
     Assert.AreEqual(expectedCaretIndex, doubleBox.CaretIndex);
 }
예제 #8
0
        private void RenderNumericBox(XmlNode item)
        {
            var txtLabel = new Label();

            txtLabel.Content = item.Attributes["label"].Value;

            var numBox = new NumericBox();

            numBox.BorderBrush     = Brushes.Black;
            numBox.BorderThickness = new Thickness(1, 1, 1, 1);
            numBox.MaxLength       = Convert.ToInt32(item.Attributes["length"].Value);

            Canvas.SetTop(txtLabel, Convert.ToDouble(item.Attributes["top"].Value));
            Canvas.SetLeft(txtLabel, Convert.ToDouble(item.Attributes["left"].Value));
            numBox.Width  = Convert.ToDouble(item.Attributes["width"].Value);
            numBox.Height = Convert.ToDouble(item.Attributes["height"].Value);
            Canvas.SetTop(numBox, Convert.ToInt32(item.Attributes["top"].Value) + 23);
            Canvas.SetLeft(numBox, Convert.ToInt32(item.Attributes["left"].Value));


            RenderZone.Children.Add(numBox);
            RenderZone.Children.Add(txtLabel);
        }
예제 #9
0
        private void ShowStyleProperties(IntellectualEntityStyle style)
        {
            var topGrid = new Grid();

            topGrid.RowDefinitions.Add(new RowDefinition {
                Height = GridLength.Auto
            });
            topGrid.RowDefinitions.Add(new RowDefinition {
                Height = GridLength.Auto
            });
            topGrid.RowDefinitions.Add(new RowDefinition {
                Height = GridLength.Auto
            });
            topGrid.RowDefinitions.Add(new RowDefinition {
                Height = GridLength.Auto
            });
            topGrid.RowDefinitions.Add(new RowDefinition());

            #region Set main data

            var headerName = new TextBlock
            {
                Margin = (Thickness)FindResource("ModPlusDefaultMargin"),
                Text   = ModPlusAPI.Language.GetItem(Invariables.LangItem, "h54")
            };
            Grid.SetRow(headerName, 0);
            topGrid.Children.Add(headerName);

            var tbName = new TextBox {
                IsEnabled = style.StyleType == StyleType.User
            };
            Grid.SetRow(tbName, 1);
            var binding = new Binding
            {
                Mode = BindingMode.TwoWay,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                Source = style,
                Path   = new PropertyPath("Name")
            };
            BindingOperations.SetBinding(tbName, TextBox.TextProperty, binding);
            topGrid.Children.Add(tbName);

            var headerDescription = new TextBlock
            {
                Margin = (Thickness)FindResource("ModPlusDefaultMargin"),
                Text   = ModPlusAPI.Language.GetItem(Invariables.LangItem, "h55")
            };
            Grid.SetRow(headerDescription, 2);
            topGrid.Children.Add(headerDescription);

            var tbDescription = new TextBox {
                IsEnabled = style.StyleType == StyleType.User
            };
            Grid.SetRow(tbDescription, 3);
            binding = new Binding
            {
                Mode = BindingMode.TwoWay,
                UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                Source = style,
                Path   = new PropertyPath("Description")
            };
            BindingOperations.SetBinding(tbDescription, TextBox.TextProperty, binding);
            topGrid.Children.Add(tbDescription);

            #endregion

            var propertiesGrid = new Grid();
            propertiesGrid.ColumnDefinitions.Add(new ColumnDefinition());
            propertiesGrid.ColumnDefinitions.Add(new ColumnDefinition {
                Width = GridLength.Auto
            });
            propertiesGrid.ColumnDefinitions.Add(new ColumnDefinition());
            Grid.SetRow(propertiesGrid, 4);

            var groupsByCategory = style.Properties.GroupBy(p => p.Category).ToList();
            groupsByCategory.Sort((g1, g2) => g1.Key.CompareTo(g2.Key));
            var rowIndex = 0;
            foreach (var categoryGroup in groupsByCategory)
            {
                propertiesGrid.RowDefinitions.Add(new RowDefinition {
                    Height = GridLength.Auto
                });

                var categoryHeader = new TextBox {
                    Text = LocalizationUtils.GetCategoryLocalizationName(categoryGroup.Key)
                };
                Grid.SetRow(categoryHeader, rowIndex);
                Grid.SetColumn(categoryHeader, 0);
                Grid.SetColumnSpan(categoryHeader, 3);
                categoryHeader.Style = Resources["HeaderTextBoxForStyleEditor"] as Style;
                propertiesGrid.Children.Add(categoryHeader);
                rowIndex++;
                var gridSplitterStartIndex = rowIndex;
                foreach (var property in categoryGroup.OrderBy(p => p.OrderIndex))
                {
                    propertiesGrid.RowDefinitions.Add(new RowDefinition {
                        Height = GridLength.Auto
                    });

                    // property name
                    var propertyDescription = GetPropertyDescription(property);
                    var propertyHeader      = new TextBox
                    {
                        Text  = GetPropertyDisplayName(property),
                        Style = Resources["PropertyHeaderInStyleEditor"] as Style
                    };
                    SetDescription(propertyHeader, propertyDescription);
                    Grid.SetColumn(propertyHeader, 0);
                    Grid.SetRow(propertyHeader, rowIndex);
                    propertiesGrid.Children.Add(propertyHeader);

                    if (property.Name == "LayerName")
                    {
                        try
                        {
                            var cb = new ComboBox {
                                IsEnabled = style.StyleType == StyleType.User
                            };
                            Grid.SetColumn(cb, 2);
                            Grid.SetRow(cb, rowIndex);
                            var layers = AcadUtils.Layers;
                            layers.Insert(0, ModPlusAPI.Language.GetItem(Invariables.LangItem, "defl")); // "По умолчанию"
                            if (!layers.Contains(style.GetLayerNameProperty()))
                            {
                                layers.Insert(1, style.GetLayerNameProperty());
                            }

                            cb.ItemsSource = layers;
                            cb.Style       = Resources["PropertyValueComboBoxForStyleEditor"] as Style;
                            SetDescription(cb, propertyDescription);
                            BindingOperations.SetBinding(cb, Selector.SelectedItemProperty, CreateTwoWayBindingForProperty(property));
                            propertiesGrid.Children.Add(cb);
                        }
                        catch (Exception exception)
                        {
                            ExceptionBox.Show(exception);
                        }
                    }
                    else if (property.Name == "Scale")
                    {
                        try
                        {
                            var cb = new ComboBox {
                                IsEnabled = style.StyleType == StyleType.User
                            };
                            Grid.SetColumn(cb, 2);
                            Grid.SetRow(cb, rowIndex);
                            cb.ItemsSource = AcadUtils.Scales;
                            cb.Style       = Resources["PropertyValueComboBoxForStyleEditor"] as Style;
                            SetDescription(cb, propertyDescription);
                            BindingOperations.SetBinding(cb, ComboBox.TextProperty, CreateTwoWayBindingForProperty(property, new AnnotationScaleValueConverter()));
                            propertiesGrid.Children.Add(cb);
                        }
                        catch (Exception exception)
                        {
                            ExceptionBox.Show(exception);
                        }
                    }
                    else if (property.Name == "LineType")
                    {
                        try
                        {
                            var tb = new TextBox {
                                IsEnabled = style.StyleType == StyleType.User
                            };
                            Grid.SetColumn(tb, 2);
                            Grid.SetRow(tb, rowIndex);
                            tb.Cursor            = Cursors.Hand;
                            tb.Style             = Resources["PropertyValueTextBoxForStyleEditor"] as Style;
                            tb.PreviewMouseDown += LineType_OnPreviewMouseDown;
                            SetDescription(tb, propertyDescription);
                            BindingOperations.SetBinding(tb, TextBox.TextProperty, CreateTwoWayBindingForProperty(property));
                            propertiesGrid.Children.Add(tb);
                        }
                        catch (Exception exception)
                        {
                            ExceptionBox.Show(exception);
                        }
                    }
                    else if (property.Name.Contains("TextStyle"))
                    {
                        try
                        {
                            var cb = new ComboBox {
                                IsEnabled = style.StyleType == StyleType.User
                            };
                            Grid.SetColumn(cb, 2);
                            Grid.SetRow(cb, rowIndex);
                            cb.ItemsSource = AcadUtils.TextStyles;
                            cb.Style       = Resources["PropertyValueComboBoxForStyleEditor"] as Style;
                            SetDescription(cb, propertyDescription);
                            BindingOperations.SetBinding(cb, Selector.SelectedItemProperty, CreateTwoWayBindingForProperty(property));
                            propertiesGrid.Children.Add(cb);
                        }
                        catch (Exception exception)
                        {
                            ExceptionBox.Show(exception);
                        }
                    }
                    else if (property.Value is Enum)
                    {
                        try
                        {
                            var cb = new ComboBox {
                                IsEnabled = style.StyleType == StyleType.User
                            };
                            Grid.SetColumn(cb, 2);
                            Grid.SetRow(cb, rowIndex);
                            cb.Style = Resources["PropertyValueComboBoxForStyleEditor"] as Style;
                            var type = property.Value.GetType();
                            SetDescription(cb, propertyDescription);
                            cb.ItemsSource = LocalizationUtils.GetEnumPropertyLocalizationFields(type);

                            BindingOperations.SetBinding(cb, ComboBox.TextProperty,
                                                         CreateTwoWayBindingForProperty(property, new EnumPropertyValueConverter()));

                            propertiesGrid.Children.Add(cb);
                        }
                        catch (Exception exception)
                        {
                            ExceptionBox.Show(exception);
                        }
                    }
                    else if (property.Value is int)
                    {
                        try
                        {
                            var tb = new NumericBox
                            {
                                IsEnabled = style.StyleType == StyleType.User
                            };
                            Grid.SetColumn(tb, 2);
                            Grid.SetRow(tb, rowIndex);
                            tb.Minimum = Convert.ToInt32(property.Minimum);
                            tb.Maximum = Convert.ToInt32(property.Maximum);
                            tb.Style   = Resources["PropertyValueIntTextBoxForStyleEditor"] as Style;
                            SetDescription(tb, propertyDescription);
                            BindingOperations.SetBinding(tb, NumericBox.ValueProperty, CreateTwoWayBindingForPropertyForNumericValue(property, true));
                            propertiesGrid.Children.Add(tb);
                        }
                        catch (Exception exception)
                        {
                            ExceptionBox.Show(exception);
                        }
                    }
                    else if (property.Value is double)
                    {
                        try
                        {
                            var tb = new NumericBox
                            {
                                IsEnabled = style.StyleType == StyleType.User
                            };
                            Grid.SetColumn(tb, 2);
                            Grid.SetRow(tb, rowIndex);
                            tb.Minimum = Convert.ToDouble(property.Minimum);
                            tb.Maximum = Convert.ToDouble(property.Maximum);
                            tb.Style   = Resources["PropertyValueDoubleTextBoxForStyleEditor"] as Style;
                            SetDescription(tb, propertyDescription);
                            BindingOperations.SetBinding(tb, NumericBox.ValueProperty, CreateTwoWayBindingForPropertyForNumericValue(property, false));

                            propertiesGrid.Children.Add(tb);
                        }
                        catch (Exception exception)
                        {
                            ExceptionBox.Show(exception);
                        }
                    }
                    else if (property.Value is bool)
                    {
                        try
                        {
                            var chb = new CheckBox {
                                IsEnabled = style.StyleType == StyleType.User
                            };
                            SetDescription(chb, propertyDescription);
                            BindingOperations.SetBinding(chb, ToggleButton.IsCheckedProperty, CreateTwoWayBindingForProperty(property));

                            var outerBorder = new Border();
                            outerBorder.Style = Resources["PropertyBorderForCheckBoxForStyleEditor"] as Style;
                            Grid.SetColumn(outerBorder, 2);
                            Grid.SetRow(outerBorder, rowIndex);

                            outerBorder.Child = chb;
                            propertiesGrid.Children.Add(outerBorder);
                        }
                        catch (Exception exception)
                        {
                            ExceptionBox.Show(exception);
                        }
                    }
                    else if (property.Value is string)
                    {
                        try
                        {
                            var tb = new TextBox {
                                IsEnabled = style.StyleType == StyleType.User
                            };
                            Grid.SetColumn(tb, 2);
                            Grid.SetRow(tb, rowIndex);
                            tb.Style = Resources["PropertyValueTextBoxForStyleEditor"] as Style;
                            SetDescription(tb, propertyDescription);
                            BindingOperations.SetBinding(tb, TextBox.TextProperty, CreateTwoWayBindingForProperty(property));

                            propertiesGrid.Children.Add(tb);
                        }
                        catch (Exception exception)
                        {
                            ExceptionBox.Show(exception);
                        }
                    }

                    rowIndex++;
                }

                propertiesGrid.Children.Add(CreateGridSplitter(gridSplitterStartIndex, rowIndex - gridSplitterStartIndex));
            }

            topGrid.Children.Add(propertiesGrid);
            BorderProperties.Child = topGrid;
        }
예제 #10
0
        public void ParseWidgets(IContainer ParentWidget, Dictionary <string, object> Data)
        {
            foreach (string name in Data.Keys)
            {
                if (!(Data[name] is JObject))
                {
                    throw new Exception($"Expected an Object, but got {Data[name].GetType().Name} in key '{name}' inside 'widgets'");
                }
                Dictionary <string, object> config = ((JObject)Data[name]).ToObject <Dictionary <string, object> >();
                if (!config.ContainsKey("type"))
                {
                    throw new Exception($"Widget definition must contain a 'type' key in widget '{name}'");
                }
                if (!(config["type"] is string))
                {
                    throw new Exception($"Widget type must be a string.");
                }
                Widget w    = null;
                string type = (string)config["type"];
                switch (type)
                {
                case "container":
                    w = new Container(ParentWidget);
                    break;

                case "label":
                    w = new DynamicLabel(ParentWidget);
                    break;

                case "numeric":
                    w = new NumericBox(ParentWidget);
                    break;

                case "textbox":
                    w = new TextBox(ParentWidget);
                    break;

                case "button":
                    w = new Button(ParentWidget);
                    break;

                case "dropdown":
                    w = new DropdownBox(ParentWidget);
                    break;

                case "checkbox":
                    w = new CheckBox(ParentWidget);
                    break;

                case "radiobox":
                    w = new RadioBox(ParentWidget);
                    break;

                case "switch_picker":
                    w = new GameSwitchBox(ParentWidget);
                    break;

                case "variable_picker":
                    w = new GameVariableBox(ParentWidget);
                    break;

                case "multitextbox":
                    w = new MultilineTextBox(ParentWidget);
                    break;

                case "multilabel":
                    w = new MultilineDynamicLabel(ParentWidget);
                    break;

                default:
                    throw new Exception($"Unknown widget type '{type}' in widget '{name}'");
                }
                if (WidgetLookup.ContainsKey(name))
                {
                    throw new Exception($"Two or more widgets with the same were found: '{name}'");
                }
                WidgetLookup.Add(name, w);
                int                X            = 0;
                int                Y            = 0;
                int                Width        = -1;
                int                Height       = -1;
                string             text         = null;
                int                wvalue       = 0;
                int?               min_value    = null;
                int?               max_value    = null;
                Font               font         = null;
                List <ListItem>    items        = null;
                int                idx          = -1;
                bool               enabled      = true;
                List <ClickAction> clickactions = new List <ClickAction>();
                foreach (string key in config.Keys)
                {
                    if (key == "type")
                    {
                        continue;
                    }
                    object value = config[key];
                    switch (key)
                    {
                    case "x":
                        EnsureType(typeof(long), value, "x");
                        X = Convert.ToInt32(value);
                        break;

                    case "y":
                        EnsureType(typeof(long), value, "y");
                        Y = Convert.ToInt32(value);
                        break;

                    case "width":
                        EnsureType(typeof(long), value, "width");
                        Width = Convert.ToInt32(value);
                        if (Width < 1)
                        {
                            throw new Exception($"Widget width ({Width}) must be greater than 0.");
                        }
                        break;

                    case "height":
                        EnsureType(typeof(long), value, "height");
                        Height = Convert.ToInt32(value);
                        if (Height < 1)
                        {
                            throw new Exception($"Widget height ({Height}) must be greater than 0.");
                        }
                        break;

                    case "font":
                        if (type != "label" && type != "textbox" && type != "button" && type != "dropdown" &&
                            type != "checkbox" && type != "radiobox" && type != "multitextbox" && type != "multilabel")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'font' field.");
                        }
                        if (value is string)
                        {
                            if (!Fonts.ContainsKey((string)value))
                            {
                                throw new Exception($"Undefined font name '{(string) value}");
                            }
                            font = Fonts[(string)value];
                        }
                        else if (value is JObject)
                        {
                            font = ParseFont(((JObject)value).ToObject <Dictionary <string, object> >());
                        }
                        else
                        {
                            throw new Exception($"Expected a String or Object, but got {value.GetType().Name} in 'font'");
                        }
                        break;

                    case "value":
                        if (type != "numeric")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'value' field.");
                        }
                        EnsureType(typeof(long), value, "value");
                        wvalue = Convert.ToInt32(value);
                        break;

                    case "min_value":
                        if (type != "numeric")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'min_value' field.");
                        }
                        EnsureType(typeof(long), value, "min_value");
                        min_value = Convert.ToInt32(value);
                        break;

                    case "max_value":
                        if (type != "numeric")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'max_value' field.");
                        }
                        EnsureType(typeof(long), value, "max_value");
                        max_value = Convert.ToInt32(value);
                        break;

                    case "text":
                        if (type != "label" && type != "textbox" && type != "button" && type != "checkbox" &&
                            type != "radiobox" && type != "multitextbox" && type != "multilabel")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'text' field.");
                        }
                        EnsureType(typeof(string), value, "text");
                        text = (string)value;
                        break;

                    case "items":
                        if (type != "dropdown")
                        {
                            throw new Exception($"Widget type ({type}) can not contain an 'items' field.");
                        }
                        if (!(value is JArray))
                        {
                            throw new Exception($"Expected an Array, but got {value.GetType().Name} in key 'items'");
                        }
                        List <object> ary = ((JArray)value).ToObject <List <object> >();
                        items = new List <ListItem>();
                        foreach (object o in ary)
                        {
                            EnsureType(typeof(string), o, "items");
                            items.Add(new ListItem((string)o));
                        }
                        break;

                    case "index":
                        if (type != "dropdown")
                        {
                            throw new Exception($"Widget type ({type}) can not contain an 'index' field.");
                        }
                        EnsureType(typeof(long), value, "index");
                        idx = Convert.ToInt32(value);
                        if (idx < 0)
                        {
                            throw new Exception($"Index field must be greater than or equal to 0.");
                        }
                        break;

                    case "enabled":
                        if (type != "label" && type != "dropdown" && type != "switch_picker" && type != "variable_picker" &&
                            type != "checkbox" && type != "radiobox" && type != "textbox" && type != "numeric" &&
                            type != "button" && type != "multilabel")
                        {
                            throw new Exception($"Widget type ({type}) can not contain an 'enabled' field.");
                        }
                        EnsureType(typeof(bool), value, "enabled");
                        enabled = Convert.ToBoolean(value);
                        break;

                    case "widgets":
                        if (!(value is JObject))
                        {
                            throw new Exception($"Expected an Object, but got a {value.GetType().Name} in key 'widgets'");
                        }
                        ParseWidgets(w, ((JObject)value).ToObject <Dictionary <string, object> >());
                        break;

                    case "clicked":
                        if (type != "radiobox" && type != "dropdown")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'clicked' field.");
                        }
                        if (!(value is JArray))
                        {
                            throw new Exception($"Expected an Array, but got {value.GetType().Name} in key 'clicked'");
                        }
                        List <object> clickdata = ((JArray)value).ToObject <List <object> >();
                        for (int i = 0; i < clickdata.Count; i++)
                        {
                            object action = clickdata[i];
                            if (!(action is JObject))
                            {
                                throw new Exception($"Expected an Object, but got {action.GetType().Name} in key 'clicked', element {i}");
                            }
                            Dictionary <string, object> actionobject = ((JObject)action).ToObject <Dictionary <string, object> >();
                            if (!actionobject.ContainsKey("action"))
                            {
                                throw new Exception($"Click definition in 'clicked', element {i} must contain an 'action' key.");
                            }
                            string        actiontype      = null;
                            List <object> actionparams    = new List <object>();
                            string        actioncondition = null;
                            foreach (string actionkey in actionobject.Keys)
                            {
                                object actionvalue = actionobject[actionkey];
                                switch (actionkey)
                                {
                                case "action":
                                    EnsureType(typeof(string), actionvalue, "action");
                                    actiontype = (string)actionvalue;
                                    if (actiontype != "enable" && actiontype != "disable" && actiontype != "check" && actiontype != "uncheck" &&
                                        actiontype != "set")
                                    {
                                        throw new Exception($"Unknown action type '{actiontype}'.");
                                    }
                                    break;

                                case "parameter":
                                    if (!(actionvalue is string) && !(actionvalue is JArray))
                                    {
                                        throw new Exception($"Expected a string or Array, but got {actionvalue.GetType().Name} in key 'parameter'.");
                                    }
                                    if (actionvalue is string)
                                    {
                                        actionparams.Add((string)actionvalue);
                                    }
                                    else
                                    {
                                        List <object> paramlist = ((JArray)actionvalue).ToObject <List <object> >();
                                        foreach (object paramvalue in paramlist)
                                        {
                                            actionparams.Add(paramvalue);
                                        }
                                    }
                                    break;

                                case "condition":
                                    EnsureType(typeof(string), actionvalue, "condition");
                                    actioncondition = (string)actionvalue;
                                    break;

                                default:
                                    throw new Exception($"Unknown key '{actionkey}' inside 'clicked' definition");
                                }
                            }
                            clickactions.Add(new ClickAction(actiontype, actionparams, actioncondition));
                        }
                        break;

                    default:
                        throw new Exception($"Unknown key '{key}' inside widget definition");
                    }
                }
                EnabledLookup.Add(name, enabled);
                w.SetPosition(X, Y);
                if (Width != -1 && Height != -1)
                {
                    w.SetSize(Width, Height);
                }
                else if (Width != -1)
                {
                    w.SetWidth(Width);
                }
                else if (Height != -1)
                {
                    w.SetHeight(Height);
                }
                if (type == "label")
                {
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((DynamicLabel)w).SetText(text);
                    }
                    if (font != null)
                    {
                        ((DynamicLabel)w).SetFont(font);
                    }
                    //((DynamicLabel) w).SetParser(this);
                    ((DynamicLabel)w).SetColors(ConditionParser.Colors);
                    ((DynamicLabel)w).SetEnabled(enabled);
                }
                if (type == "multilabel")
                {
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((MultilineDynamicLabel)w).SetText(text);
                    }
                    if (font != null)
                    {
                        ((MultilineDynamicLabel)w).SetFont(font);
                    }
                    //((MultilineDynamicLabel) w).SetParser(this);
                    ((MultilineDynamicLabel)w).SetColors(ConditionParser.Colors);
                    ((MultilineDynamicLabel)w).SetEnabled(enabled);
                }
                if (type == "textbox")
                {
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((TextBox)w).SetInitialText(text);
                    }
                    if (font != null)
                    {
                        ((TextBox)w).TextArea.SetFont(font);
                    }
                    ((TextBox)w).OnTextChanged += Save;
                }
                if (type == "numeric")
                {
                    ((NumericBox)w).SetValue(wvalue);
                    if (min_value != null)
                    {
                        ((NumericBox)w).MinValue = (int)min_value;
                    }
                    if (max_value != null)
                    {
                        ((NumericBox)w).MaxValue = (int)max_value;
                    }
                    ((NumericBox)w).OnValueChanged += Save;
                }
                if (type == "button")
                {
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((Button)w).SetText(text);
                    }
                    if (font != null)
                    {
                        ((Button)w).SetFont(font);
                    }
                }
                if (type == "dropdown")
                {
                    if (items == null && idx != -1 || items != null && idx >= items.Count)
                    {
                        throw new Exception($"Index cannot be greater than or equal to the total item size.");
                    }
                    if (items != null)
                    {
                        ((DropdownBox)w).SetItems(items);
                    }
                    if (idx != -1)
                    {
                        ((DropdownBox)w).SetSelectedIndex(idx);
                    }
                    if (font != null)
                    {
                        ((DropdownBox)w).SetFont(font);
                    }
                    ((DropdownBox)w).OnSelectionChanged += Save;
                    ((DropdownBox)w).OnSelectionChanged += delegate(BaseEventArgs e)
                    {
                        EvaluateAction(clickactions);
                    };
                }
                if (type == "checkbox")
                {
                    if (font != null)
                    {
                        ((CheckBox)w).SetFont(font);
                    }
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((CheckBox)w).SetText(text);
                    }
                }
                if (type == "radiobox")
                {
                    if (font != null)
                    {
                        ((RadioBox)w).SetFont(font);
                    }
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((RadioBox)w).SetText(text);
                    }
                    ((RadioBox)w).OnCheckChanged += delegate(BaseEventArgs e)
                    {
                        if (((RadioBox)w).Checked)
                        {
                            EvaluateAction(clickactions);
                        }
                    };
                }
                if (type == "switch_picker")
                {
                    ((GameSwitchBox)w).OnSwitchChanged += Save;
                }
                if (type == "variable_picker")
                {
                    ((GameVariableBox)w).OnVariableChanged += Save;
                }
                if (type == "multitextbox")
                {
                    if (font != null)
                    {
                        ((MultilineTextBox)w).SetFont(font);
                    }
                    if (!string.IsNullOrEmpty(text))
                    {
                        ((MultilineTextBox)w).SetText(text);
                    }
                }
                SetWidgetEnabled(w, enabled);
            }
        }
예제 #11
0
        public override void Initialize()
        {
            _menu = new Menu();
            var menuButton1 = new MenuItemButton <object>()
            {
                Text = "Menu 1",
            };

            menuButton1.AddChild(new MenuItemButton <object>()
            {
                Text = "Submenu 1.1"
            });
            _menu.AddChild(menuButton1);
            var menuButton2 = new MenuItemButton <object>()
            {
                Text = "Menu 2",
            };

            menuButton2.AddChild(new MenuItemButton <object>()
            {
                Text = "Submenu 2.1"
            });
            menuButton2.AddChild(new MenuItemButton <object>()
            {
                Text = "Submenu 2.2"
            });
            _menu.AddChild(menuButton2);
            Menu = _menu;

            _checkbox1 = new Checkbox {
                Location = new Point {
                    Left = 3, Top = 5
                }, Text = "Checkbox tentative"
            };
            _checkbox1.CheckedChanged += checkbox1_CheckedChanged;
            RootPanel.AddChild(_checkbox1);

            _checkbox2 = new Checkbox {
                Location = new Point {
                    Left = 3, Top = 7
                }, IsChecked = true, Text = "Checkbox checked"
            };
            RootPanel.AddChild(_checkbox2);

            _checkbox3 = new Checkbox {
                Location = new Point {
                    Left = 3, Top = 9
                }, IsChecked = false, Text = "Checkbox unchecked"
            };
            RootPanel.AddChild(_checkbox3);

            _checkbox4 = new Checkbox {
                Location = new Point {
                    Left = 3, Top = 11
                }, IsChecked = false, Text = "Checkbox disabled", IsEnabled = false
            };
            RootPanel.AddChild(_checkbox4);

            _label1 = new Label {
                Location = new Point {
                    Left = 3, Top = 19
                }, Text = "Label"
            };
            RootPanel.AddChild(_label1);

            _radioButton1 = new RadioButton {
                Location = new Point {
                    Left = 3, Top = 13
                }, Text = "Radio unchecked"
            };
            RootPanel.AddChild(_radioButton1);

            _radioButton2 = new RadioButton {
                Location = new Point {
                    Left = 3, Top = 15
                }, Text = "Radio checked", IsChecked = true
            };
            RootPanel.AddChild(_radioButton2);

            _radioButton3 = new RadioButton {
                Location = new Point {
                    Left = 3, Top = 17
                }, Text = "Radio checked", IsChecked = true, IsEnabled = false
            };
            RootPanel.AddChild(_radioButton3);

            _textBox1 = new TextBox {
                Location = new Point {
                    Left = 29, Top = 16
                }
            };
            _textBox1.TextChanged += textBox1_TextChanged;
            RootPanel.AddChild(_textBox1);

            _dateTimeBox1 = new DateTimeBox()
            {
                Location = new Point {
                    Left = 29, Top = 18
                }
            };
            RootPanel.AddChild(_dateTimeBox1);

            _numericBox1 = new NumericBox()
            {
                Location = new Point {
                    Left = 29, Top = 20
                }
            };
            RootPanel.AddChild(_numericBox1);

            _button1 = new Button {
                Location = new Point {
                    Left = 3, Top = 22
                }, Width = 10
            };
            _button1.Pressed += button1_Pressed;
            RootPanel.AddChild(_button1);

            _button2 = new Button {
                Location = new Point {
                    Left = 16, Top = 22
                }, Width = 10, IsEnabled = false, Text = "Disabled button"
            };
            _button2.Pressed += button2_Pressed;
            RootPanel.AddChild(_button2);

            _progressBar1 = new ProgressBar {
                Location = new Point {
                    Left = 3, Top = 3
                }, Width = 74, TextAligment = TitleAligment.Left
            };
            RootPanel.AddChild(_progressBar1);

            _bnext1 = new Button {
                Location = new Point {
                    Left = 40, Top = 22
                }, Width = 10, Text = "Next 1", Tag = 1
            };
            _bnext1.Pressed += bNextPressed;
            RootPanel.AddChild(_bnext1);

            _bnext2 = new Button {
                Location = new Point {
                    Left = 51, Top = 22
                }, Width = 10, Text = "Next 2", Tag = 2
            };
            _bnext2.Pressed += bNextPressed;
            RootPanel.AddChild(_bnext2);

            _bnext3 = new Button {
                Location = new Point {
                    Left = 62, Top = 22
                }, Width = 10, Text = "Next 3", Tag = 3
            };
            _bnext3.Pressed += bNextPressed;
            RootPanel.AddChild(_bnext3);

            _panel1 = new BorderPanel
            {
                Location = new Point {
                    Left = 28, Top = 4
                },
                Size = new Size {
                    Height = 7, Width = 25
                }
            };
            RootPanel.AddChild(_panel1);

            var subRadiobuton1 = new RadioButton
            {
                Location = new Point
                {
                    Left = 1,
                    Top  = 1
                }
            };

            _panel1.AddChild(subRadiobuton1);

            var subRadiobuton2 = new RadioButton
            {
                Location = new Point
                {
                    Left = 1,
                    Top  = 3
                }
            };

            _panel1.AddChild(subRadiobuton2);

            var subRadiobuton3 = new RadioButton
            {
                Location = new Point
                {
                    Left = 1,
                    Top  = 5
                }
            };

            _panel1.AddChild(subRadiobuton3);


            _comboBox1 = new ComboBox
            {
                Location = new Point {
                    Left = 29, Top = 12
                },
                VisibleItemsCount = 7
            };
            _comboBox1.Items.AddRange(new[]
            {
                new ComboBoxItem()
                {
                    Key = 1, Text = "EntityFX"
                },
                new ComboBoxItem()
                {
                    Key = 2, Text = "Green.Dragon"
                },
                new ComboBoxItem()
                {
                    Key = 3, Text = "Guzalianna"
                },
                new ComboBoxItem()
                {
                    Key = 4, Text = "Prozz"
                },
                new ComboBoxItem()
                {
                    Key = 5, Text = "Aik2029"
                },
                new ComboBoxItem()
                {
                    Key = 6, Text = "Zombie"
                },
                new ComboBoxItem()
                {
                    Key = 7, Text = "Wesker"
                },
                new ComboBoxItem()
                {
                    Key = 8, Text = "Perez"
                },
                new ComboBoxItem()
                {
                    Key = 9, Text = "Chuvak"
                },
                new ComboBoxItem()
                {
                    Key = 10, Text = "Magistr"
                },
                new ComboBoxItem()
                {
                    Key = 11, Text = "Mad"
                },
                new ComboBoxItem()
                {
                    Key = 12, Text = "XOBAH"
                }
            });
            RootPanel.AddChild(_comboBox1);

            RootPanel.AddChild(new Checkbox {
                Location = new Point {
                    Left = 29, Top = 14
                }, Text = "Checkbox for overlapp"
            });

            _image = Image.FromString(
                @"───▄▄▄
─▄▀░▄░▀▄
─█░█▄▀░█
─█░▀▄▄▀█▄█▄▀
▄▄█▄▄▄▄███▀
");
            _image.Location = new Point()
            {
                Left = 55, Top = 4
            };
            RootPanel.AddChild(_image);


            _plotChart = new PlotChart()
            {
                Size = new Size()
                {
                    Height = 10, Width = 30
                },
                Location = new Point()
                {
                    Left = 48, Top = 11
                },
                PlotSymbol = ':'
            };
            _plotChart.Points = GenerateSinChartPoints(_plotChart.Size, 7);
            RootPanel.AddChild(_plotChart);

            StatusStrip = new StatusStrip();
            StatusStrip.AddChild(new StatusStripLabel
            {
                Text = "Item 1"
            });

            StatusStrip.AddChild(new StatusStripLabel
            {
                Text = "Item 2"
            });

            _timeStripItem = new StatusStripLabel
            {
                Text         = "Item 3",
                ItemLocation = ItemLocationEnum.Right
            };
            StatusStrip.AddChild(_timeStripItem);

            StatusStrip.AddChild(new StatusStripLabel
            {
                Text         = "Item 4",
                ItemLocation = ItemLocationEnum.Right
            });

            StatusStrip.AddChild(new StatusStripButton
            {
                Text         = "But 1",
                ItemLocation = ItemLocationEnum.Left
            });

            StatusStrip.AddChild(new StatusStripButton
            {
                Text         = "But 2",
                ItemLocation = ItemLocationEnum.Left
            });

            _statusStripProgressBar = new StatusStripProgressBar
            {
                Text    = "P: {0}",
                Width   = 14,
                Minimum = 0,
                Value   = 16,
                Maximum = 25
            };
            StatusStrip.AddChild(_statusStripProgressBar);


            Initializetable();

            _timer.Elapsed += timer_Elapsed;
            _timer.Start();

            _timer2.Elapsed += _timer2_Elapsed;
            _timer2.Start();
        }
예제 #12
0
        public Dictionary <string, Widget> ParseWidgets(IContainer ParentWidget, Dictionary <string, object> Data)
        {
            Dictionary <string, Widget> Widgets = new Dictionary <string, Widget>();

            foreach (string name in Data.Keys)
            {
                if (!(Data[name] is JObject))
                {
                    throw new Exception($"Expected an Object, but got {Data[name].GetType().Name} in key '{name}' inside 'widgets'");
                }
                Dictionary <string, object> config = ((JObject)Data[name]).ToObject <Dictionary <string, object> >();
                if (!config.ContainsKey("type"))
                {
                    throw new Exception($"Widget definition must contain a 'type' key in widget '{name}'");
                }
                if (!(config["type"] is string))
                {
                    throw new Exception($"Widget type must be a string.");
                }
                Widget w    = null;
                string type = (string)config["type"];
                switch (type)
                {
                case "label":
                    w = new Label(ParentWidget);
                    break;

                case "numeric":
                    w = new NumericBox(ParentWidget);
                    break;

                case "textbox":
                    w = new TextBox(ParentWidget);
                    break;

                case "button":
                    w = new Button(ParentWidget);
                    break;

                case "dropdown":
                    w = new DropdownBox(ParentWidget);
                    break;

                default:
                    throw new Exception($"Unknown widget type '{type}' in widget '{name}'");
                }
                if (WidgetLookup.ContainsKey(name))
                {
                    throw new Exception($"Two or more widgets with the same were found: '{name}'");
                }
                WidgetLookup.Add(name, w);
                int             X         = 0;
                int             Y         = 0;
                int             Width     = -1;
                int             Height    = -1;
                string          text      = null;
                int             wvalue    = 0;
                int?            min_value = null;
                int?            max_value = null;
                Font            font      = null;
                List <ListItem> items     = null;
                int             idx       = -1;
                foreach (string key in config.Keys)
                {
                    if (key == "type")
                    {
                        continue;
                    }
                    object value = config[key];
                    switch (key)
                    {
                    case "x":
                        EnsureType(typeof(long), value, "x");
                        X = Convert.ToInt32(value);
                        break;

                    case "y":
                        EnsureType(typeof(long), value, "y");
                        Y = Convert.ToInt32(value);
                        break;

                    case "width":
                        EnsureType(typeof(long), value, "width");
                        Width = Convert.ToInt32(value);
                        if (Width < 1)
                        {
                            throw new Exception($"Widget width ({Width}) must be greater than 0.");
                        }
                        break;

                    case "height":
                        EnsureType(typeof(long), value, "height");
                        Height = Convert.ToInt32(value);
                        if (Height < 1)
                        {
                            throw new Exception($"Widget height ({Height}) must be greater than 0.");
                        }
                        break;

                    case "font":
                        if (type != "label" && type != "textbox" && type != "button" && type != "dropdown")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'font' field.");
                        }
                        if (value is string)
                        {
                            if (!Fonts.ContainsKey((string)value))
                            {
                                throw new Exception($"Undefined font name '{(string) value}");
                            }
                            font = Fonts[(string)value];
                        }
                        else if (value is JObject)
                        {
                            font = ParseFont(((JObject)value).ToObject <Dictionary <string, object> >());
                        }
                        else
                        {
                            throw new Exception($"Expected a String or Object, but got {value.GetType().Name} in 'font'");
                        }
                        break;

                    case "value":
                        if (type != "numeric")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'value' field.");
                        }
                        EnsureType(typeof(long), value, "value");
                        wvalue = Convert.ToInt32(value);
                        break;

                    case "min_value":
                        if (type != "numeric")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'min_value' field.");
                        }
                        EnsureType(typeof(long), value, "min_value");
                        min_value = Convert.ToInt32(value);
                        break;

                    case "max_value":
                        if (type != "numeric")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'max_value' field.");
                        }
                        EnsureType(typeof(long), value, "max_value");
                        max_value = Convert.ToInt32(value);
                        break;

                    case "text":
                        if (type != "label" && type != "textbox" && type != "button")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'text' field.");
                        }
                        EnsureType(typeof(string), value, "text");
                        text = (string)value;
                        break;

                    case "items":
                        if (type != "dropdown")
                        {
                            throw new Exception($"Widget type ({type}) can not contain an 'items' field.");
                        }
                        if (!(value is JArray))
                        {
                            throw new Exception($"Expected an Array, but got {value.GetType().Name} in key 'items'");
                        }
                        List <object> ary = ((JArray)value).ToObject <List <object> >();
                        items = new List <ListItem>();
                        foreach (object o in ary)
                        {
                            EnsureType(typeof(string), o, "items");
                            items.Add(new ListItem((string)o));
                        }
                        break;

                    case "index":
                        if (type != "dropdown")
                        {
                            throw new Exception($"Widget type ({type}) can not contain an 'index' field.");
                        }
                        EnsureType(typeof(long), value, "index");
                        idx = Convert.ToInt32(value);
                        if (idx < 0)
                        {
                            throw new Exception($"Index field must be greater than or equal to 0.");
                        }
                        break;

                    case "clicked":
                        if (type != "button")
                        {
                            throw new Exception($"Widget type ({type}) can not contain a 'clicked' field.");
                        }
                        if (!(value is JObject))
                        {
                            throw new Exception($"Expected an Object, but got {value.GetType().Name} in key 'clicked'");
                        }
                        Dictionary <string, object> clickdata = ((JObject)value).ToObject <Dictionary <string, object> >();
                        if (!clickdata.ContainsKey("type"))
                        {
                            throw new Exception("'clicked' definition must contain a 'type' key.");
                        }
                        if (!(clickdata["type"] is string))
                        {
                            throw new Exception($"Expected a String, but got {clickdata["type"].GetType().Name} in key 'type'");
                        }
                        string clicktype = (string)clickdata["type"];
                        bool   save      = false;
                        bool   close     = false;
                        foreach (string clickkey in clickdata.Keys)
                        {
                            if (clickkey == "type")
                            {
                                continue;
                            }
                            object clickvalue = clickdata[clickkey];
                            switch (clickkey)
                            {
                            case "action":
                                EnsureType(typeof(string), clickvalue, "action");
                                string action = (string)clickvalue;
                                switch (action)
                                {
                                case "save":
                                    save = true;
                                    break;

                                case "close":
                                    close = true;
                                    break;

                                case "save_and_close":
                                    save  = true;
                                    close = true;
                                    break;

                                default:
                                    throw new Exception($"Unknown value '{action}' inside 'action' definition.");
                                }
                                break;

                            default:
                                throw new Exception($"Unknown key '{key}' inside 'clicked' definition");
                            }
                        }
                        ((Button)w).OnClicked += delegate(BaseEventArgs e)
                        {
                            if (save)
                            {
                                Save();
                            }
                            if (close)
                            {
                                Window.Close();
                            }
                        };
                        break;

                    default:
                        throw new Exception($"Unknown key '{key}' inside widget definition");
                    }
                    w.SetPosition(X, Y);
                    if (Width != -1)
                    {
                        w.SetWidth(Width);
                    }
                    if (Height != -1)
                    {
                        w.SetHeight(Height);
                    }
                    if (type == "label")
                    {
                        if (!string.IsNullOrEmpty(text))
                        {
                            ((Label)w).SetText(text);
                        }
                        if (font != null)
                        {
                            ((Label)w).SetFont(font);
                        }
                    }
                    if (type == "textbox")
                    {
                        if (!string.IsNullOrEmpty(text))
                        {
                            ((TextBox)w).SetInitialText(text);
                        }
                        if (font != null)
                        {
                            ((TextBox)w).TextArea.SetFont(font);
                        }
                    }
                    if (type == "numeric")
                    {
                        ((NumericBox)w).SetValue(wvalue);
                        if (min_value != null)
                        {
                            ((NumericBox)w).MinValue = (int)min_value;
                        }
                        if (max_value != null)
                        {
                            ((NumericBox)w).MaxValue = (int)max_value;
                        }
                    }
                    if (type == "button")
                    {
                        if (!string.IsNullOrEmpty(text))
                        {
                            ((Button)w).SetText(text);
                        }
                        if (font != null)
                        {
                            ((Button)w).SetFont(font);
                        }
                    }
                    if (type == "dropdown")
                    {
                        if (items == null && idx != -1 || items != null && idx >= items.Count)
                        {
                            throw new Exception($"Index cannot be greater than or equal to the total item size.");
                        }
                        if (items != null)
                        {
                            ((DropdownBox)w).SetItems(items);
                        }
                        if (idx != -1)
                        {
                            ((DropdownBox)w).SetSelectedIndex(idx);
                        }
                        if (font != null)
                        {
                            ((DropdownBox)w).SetFont(font);
                        }
                    }
                }
                Widgets.Add(name, w);
            }
            return(Widgets);
        }
        /// <summary>
        /// Построение элементов в палитре по данным коллекции свойств
        /// </summary>
        /// <param name="collection"><see cref="SummaryPropertyCollection"/></param>
        public void SetData(SummaryPropertyCollection collection)
        {
            var different = $"*{ModPlusAPI.Language.GetItem("vc1")}*";

            var entityGroups = collection.Where(sp => sp.EntityPropertyDataCollection.Any())
                               .GroupBy(sp => sp.EntityType);

            foreach (var entityGroup in entityGroups)
            {
                // Тип примитива может содержать атрибуты указывающие зависимость видимости свойств
                // Собираю их в список для последующей работы
                var visibilityDependencyAttributes = GetVisibilityDependencyAttributes(entityGroup.Key);
                var allEntitySummaryProperties     = entityGroup.Select(g => g).ToList();

                var c = entityGroup.SelectMany(sp => sp.EntityPropertyDataCollection).Select(p => p.OwnerObjectId).Distinct().Count();
                var entityExpander = new Expander
                {
                    IsExpanded = true,
                    Header     = $"{LocalizationUtils.GetEntityLocalizationName(entityGroup.Key)} [{c}]",
                    Style      = Resources["EntityExpander"] as Style
                };

                var mainGrid = new Grid
                {
                    Visibility = Visibility.Collapsed,
                    Opacity    = 0.0
                };
                Transitions.SetOpacity(mainGrid, new OpacityParams
                {
                    From         = 0.0,
                    To           = 1.0,
                    Duration     = 300,
                    TransitionOn = TransitionOn.Visibility
                });
                var categoryIndex           = 0;
                var summaryPropertiesGroups = entityGroup.GroupBy(sp => sp.Category).ToList();
                summaryPropertiesGroups.Sort((sp1, sp2) => sp1.Key.CompareTo(sp2.Key));

                foreach (var summaryPropertiesGroup in summaryPropertiesGroups)
                {
                    mainGrid.RowDefinitions.Add(new RowDefinition {
                        Height = GridLength.Auto
                    });

                    var grid = new Grid();
                    Grid.SetRow(grid, categoryIndex);

                    var headerRowDefinition = new RowDefinition {
                        Height = GridLength.Auto
                    };
                    var firstColumn = new ColumnDefinition {
                        MinWidth = 50
                    };
                    BindingOperations.SetBinding(firstColumn, ColumnDefinition.WidthProperty, CreateBindingForColumnWidth());
                    var secondColumn = new ColumnDefinition {
                        Width = GridLength.Auto
                    };
                    var thirdColumn = new ColumnDefinition {
                        MinWidth = 50
                    };
                    grid.RowDefinitions.Add(headerRowDefinition);
                    grid.ColumnDefinitions.Add(firstColumn);
                    grid.ColumnDefinitions.Add(secondColumn);
                    grid.ColumnDefinitions.Add(thirdColumn);

                    var categoryHeader = new TextBox
                    {
                        Text = LocalizationUtils.GetCategoryLocalizationName(summaryPropertiesGroup.Key)
                    };
                    Grid.SetRow(categoryHeader, 0);
                    Grid.SetColumn(categoryHeader, 0);
                    Grid.SetColumnSpan(categoryHeader, 3);
                    categoryHeader.Style = Resources["HeaderTextBox"] as Style;
                    grid.Children.Add(categoryHeader);

                    // sort
                    var j = 1;
                    foreach (var summaryProperty in summaryPropertiesGroup.OrderBy(sp => sp.OrderIndex))
                    {
                        if (summaryProperty.PropertyScope == PropertyScope.Hidden)
                        {
                            continue;
                        }

                        var rowDefinition = new RowDefinition {
                            Height = GridLength.Auto
                        };
                        grid.RowDefinitions.Add(rowDefinition);

                        // property name
                        var propertyDescription = GetPropertyDescription(summaryProperty);
                        var propertyHeader      = new TextBox
                        {
                            Text  = GetPropertyDisplayName(summaryProperty),
                            Style = Resources["PropertyNameTextBox"] as Style
                        };
                        SetDescription(propertyHeader, propertyDescription);
                        SetVisibilityDependency(visibilityDependencyAttributes, allEntitySummaryProperties, summaryProperty.PropertyName, propertyHeader);
                        Grid.SetColumn(propertyHeader, 0);
                        Grid.SetRow(propertyHeader, j);
                        grid.Children.Add(propertyHeader);

                        var entityProperty = summaryProperty.EntityPropertyDataCollection.FirstOrDefault();

                        if (entityProperty != null)
                        {
                            if (summaryProperty.PropertyName == "Style")
                            {
                                try
                                {
                                    var cb = new ComboBox();
                                    Grid.SetColumn(cb, 2);
                                    Grid.SetRow(cb, j);
                                    cb.ItemsSource = StyleManager.GetStyles(entityProperty.EntityType).Select(s => s.Name);
                                    cb.Style       = Resources["PropertyValueComboBox"] as Style;
                                    SetDescription(cb, propertyDescription);
                                    SetVisibilityDependency(
                                        visibilityDependencyAttributes, allEntitySummaryProperties, summaryProperty.PropertyName, cb);
                                    SetForegroundBinding(cb, summaryProperty);
                                    BindingOperations.SetBinding(
                                        cb, ComboBox.TextProperty, CreateTwoWayBindingForProperty(summaryProperty));
                                    grid.Children.Add(cb);
                                }
                                catch (Exception exception)
                                {
                                    ExceptionBox.Show(exception);
                                }
                            }
                            else if (summaryProperty.PropertyName == "LayerName")
                            {
                                try
                                {
                                    var cb = new ComboBox();
                                    Grid.SetColumn(cb, 2);
                                    Grid.SetRow(cb, j);
                                    cb.ItemsSource = AcadUtils.Layers;
                                    cb.Style       = Resources["PropertyValueComboBox"] as Style;
                                    SetDescription(cb, propertyDescription);
                                    SetVisibilityDependency(
                                        visibilityDependencyAttributes, allEntitySummaryProperties, summaryProperty.PropertyName, cb);
                                    SetForegroundBinding(cb, summaryProperty);
                                    BindingOperations.SetBinding(
                                        cb, ComboBox.TextProperty, CreateTwoWayBindingForProperty(summaryProperty));
                                    grid.Children.Add(cb);
                                }
                                catch (Exception exception)
                                {
                                    ExceptionBox.Show(exception);
                                }
                            }
                            else if (summaryProperty.PropertyName == "Scale")
                            {
                                try
                                {
                                    var cb = new ComboBox();
                                    Grid.SetColumn(cb, 2);
                                    Grid.SetRow(cb, j);
                                    cb.ItemsSource = AcadUtils.Scales;
                                    cb.Style       = Resources["PropertyValueComboBox"] as Style;
                                    SetDescription(cb, propertyDescription);
                                    SetVisibilityDependency(
                                        visibilityDependencyAttributes, allEntitySummaryProperties, summaryProperty.PropertyName, cb);
                                    SetForegroundBinding(cb, summaryProperty);
                                    BindingOperations.SetBinding(
                                        cb, ComboBox.TextProperty, CreateTwoWayBindingForProperty(summaryProperty));
                                    grid.Children.Add(cb);
                                }
                                catch (Exception exception)
                                {
                                    ExceptionBox.Show(exception);
                                }
                            }
                            else if (summaryProperty.PropertyName == "LineType")
                            {
                                try
                                {
                                    var tb = new TextBox();
                                    Grid.SetColumn(tb, 2);
                                    Grid.SetRow(tb, j);
                                    tb.Style             = Resources["PropertyValueTextBoxClickable"] as Style;
                                    tb.PreviewMouseDown += LineType_OnPreviewMouseDown;
                                    SetDescription(tb, propertyDescription);
                                    SetVisibilityDependency(
                                        visibilityDependencyAttributes, allEntitySummaryProperties, summaryProperty.PropertyName, tb);
                                    SetForegroundBinding(tb, summaryProperty);
                                    BindingOperations.SetBinding(
                                        tb, TextBox.TextProperty, CreateTwoWayBindingForProperty(summaryProperty));
                                    grid.Children.Add(tb);
                                }
                                catch (Exception exception)
                                {
                                    ExceptionBox.Show(exception);
                                }
                            }
                            else if (summaryProperty.PropertyName.Contains("TextStyle"))
                            {
                                try
                                {
                                    var cb = new ComboBox();
                                    Grid.SetColumn(cb, 2);
                                    Grid.SetRow(cb, j);
                                    cb.ItemsSource = AcadUtils.TextStyles;
                                    cb.Style       = Resources["PropertyValueComboBox"] as Style;
                                    SetDescription(cb, propertyDescription);
                                    SetVisibilityDependency(
                                        visibilityDependencyAttributes, allEntitySummaryProperties, summaryProperty.PropertyName, cb);
                                    SetForegroundBinding(cb, summaryProperty);
                                    BindingOperations.SetBinding(
                                        cb, ComboBox.TextProperty, CreateTwoWayBindingForProperty(summaryProperty));
                                    grid.Children.Add(cb);
                                }
                                catch (Exception exception)
                                {
                                    ExceptionBox.Show(exception);
                                }
                            }
                            else if (entityProperty.Value is Enum)
                            {
                                try
                                {
                                    var cb = new ComboBox();
                                    Grid.SetColumn(cb, 2);
                                    Grid.SetRow(cb, j);
                                    cb.Style = Resources["PropertyValueComboBox"] as Style;
                                    var type = entityProperty.Value.GetType();
                                    SetDescription(cb, propertyDescription);
                                    SetVisibilityDependency(
                                        visibilityDependencyAttributes, allEntitySummaryProperties, summaryProperty.PropertyName, cb);
                                    cb.ItemsSource = LocalizationUtils.GetEnumPropertyLocalizationFields(type);
                                    cb.IsEnabled   = !entityProperty.IsReadOnly;
                                    SetForegroundBinding(cb, summaryProperty);

                                    BindingOperations.SetBinding(cb, ComboBox.TextProperty,
                                                                 CreateTwoWayBindingForProperty(summaryProperty, new EnumPropertyValueConverter()));

                                    grid.Children.Add(cb);
                                }
                                catch (Exception exception)
                                {
                                    ExceptionBox.Show(exception);
                                }
                            }
                            else if (entityProperty.Value is int)
                            {
                                try
                                {
                                    if (entityProperty.IsReadOnly)
                                    {
                                        var tb = new TextBox
                                        {
                                            Style = Resources["PropertyValueReadOnlyTextBox"] as Style
                                        };
                                        Grid.SetColumn(tb, 2);
                                        Grid.SetRow(tb, j);

                                        SetDescription(tb, propertyDescription);
                                        SetVisibilityDependency(visibilityDependencyAttributes, allEntitySummaryProperties, summaryProperty.PropertyName, tb);
                                        tb.Text = summaryProperty.IntValue.HasValue
                                            ? summaryProperty.IntValue.ToString()
                                            : different;

                                        grid.Children.Add(tb);
                                    }
                                    else
                                    {
                                        var numericBox = new NumericBox();
                                        Grid.SetColumn(numericBox, 2);
                                        Grid.SetRow(numericBox, j);
                                        numericBox.Minimum = summaryProperty.EntityPropertyDataCollection
                                                             .Select(p => Convert.ToInt32(p.Minimum)).Max();
                                        numericBox.Maximum = summaryProperty.EntityPropertyDataCollection
                                                             .Select(p => Convert.ToInt32(p.Maximum)).Min();
                                        numericBox.Interval         = 1.0;
                                        numericBox.NumericInputMode = NumericInput.Numbers;
                                        numericBox.Style            = Resources["PropertyValueNumericTextBox"] as Style;
                                        HintAssist.SetHint(numericBox, different);
                                        SetDescription(numericBox, propertyDescription);
                                        SetVisibilityDependency(
                                            visibilityDependencyAttributes,
                                            allEntitySummaryProperties,
                                            summaryProperty.PropertyName,
                                            numericBox);

                                        BindingOperations.SetBinding(
                                            numericBox,
                                            NumericBox.ValueProperty,
                                            CreateTwoWayBindingForPropertyForNumericValue(summaryProperty, true));

                                        grid.Children.Add(numericBox);
                                    }
                                }
                                catch (Exception exception)
                                {
                                    ExceptionBox.Show(exception);
                                }
                            }
                            else if (entityProperty.Value is double)
                            {
                                try
                                {
                                    if (entityProperty.IsReadOnly)
                                    {
                                        var tb = new TextBox
                                        {
                                            Style = Resources["PropertyValueReadOnlyTextBox"] as Style
                                        };
                                        Grid.SetColumn(tb, 2);
                                        Grid.SetRow(tb, j);
                                        SetDescription(tb, propertyDescription);
                                        SetVisibilityDependency(
                                            visibilityDependencyAttributes,
                                            allEntitySummaryProperties,
                                            summaryProperty.PropertyName,
                                            tb);
                                        tb.Text = summaryProperty.DoubleValue.HasValue
                                            ? summaryProperty.DoubleValue.ToString()
                                            : different;

                                        grid.Children.Add(tb);
                                    }
                                    else
                                    {
                                        var numericBox = new NumericBox();
                                        Grid.SetColumn(numericBox, 2);
                                        Grid.SetRow(numericBox, j);
                                        numericBox.Minimum = summaryProperty.EntityPropertyDataCollection
                                                             .Select(p => Convert.ToDouble(p.Minimum)).Max();
                                        numericBox.Maximum = summaryProperty.EntityPropertyDataCollection
                                                             .Select(p => Convert.ToDouble(p.Maximum)).Min();
                                        numericBox.NumericInputMode = NumericInput.Decimal;
                                        numericBox.Speedup          = true;
                                        numericBox.Interval         = 0.1;
                                        numericBox.Style            = Resources["PropertyValueNumericTextBox"] as Style;
                                        HintAssist.SetHint(numericBox, different);
                                        SetDescription(numericBox, propertyDescription);
                                        SetVisibilityDependency(
                                            visibilityDependencyAttributes,
                                            allEntitySummaryProperties,
                                            summaryProperty.PropertyName,
                                            numericBox);
                                        BindingOperations.SetBinding(
                                            numericBox,
                                            NumericBox.ValueProperty,
                                            CreateTwoWayBindingForPropertyForNumericValue(summaryProperty, false));

                                        grid.Children.Add(numericBox);
                                    }
                                }
                                catch (Exception exception)
                                {
                                    ExceptionBox.Show(exception);
                                }
                            }
                            else if (entityProperty.Value is bool)
                            {
                                try
                                {
                                    var chb = new CheckBox
                                    {
                                        Style = Resources["PropertyValueCheckBox"] as Style
                                    };
                                    SetDescription(chb, propertyDescription);
                                    SetVisibilityDependency(
                                        visibilityDependencyAttributes,
                                        allEntitySummaryProperties,
                                        summaryProperty.PropertyName,
                                        chb);
                                    chb.IsEnabled = !entityProperty.IsReadOnly;
                                    BindingOperations.SetBinding(
                                        chb,
                                        ToggleButton.IsCheckedProperty,
                                        CreateTwoWayBindingForProperty(summaryProperty));

                                    var outerBorder = new Border
                                    {
                                        Style = Resources["BorderForValueCheckBox"] as Style
                                    };
                                    Grid.SetColumn(outerBorder, 2);
                                    Grid.SetRow(outerBorder, j);

                                    outerBorder.Child = chb;
                                    grid.Children.Add(outerBorder);
                                }
                                catch (Exception exception)
                                {
                                    ExceptionBox.Show(exception);
                                }
                            }
                            else if (entityProperty.Value is string)
                            {
                                try
                                {
                                    var tb = new TextBox();
                                    Grid.SetColumn(tb, 2);
                                    Grid.SetRow(tb, j);
                                    tb.Style = Resources["PropertyValueTextBox"] as Style;
                                    SetDescription(tb, propertyDescription);
                                    SetVisibilityDependency(
                                        visibilityDependencyAttributes, allEntitySummaryProperties, summaryProperty.PropertyName, tb);
                                    SetForegroundBinding(tb, summaryProperty);
                                    BindingOperations.SetBinding(
                                        tb, TextBox.TextProperty, CreateTwoWayBindingForProperty(summaryProperty));
                                    tb.IsReadOnly = entityProperty.IsReadOnly;

                                    grid.Children.Add(tb);
                                }
                                catch (Exception exception)
                                {
                                    ExceptionBox.Show(exception);
                                }
                            }

                            j++;
                        }
                    }

                    grid.Children.Add(CreateGridSplitter(j));

                    mainGrid.Children.Add(grid);

                    categoryIndex++;
                }

                entityExpander.Content = mainGrid;

                StackPanelProperties.Children.Add(entityExpander);

                mainGrid.Visibility = Visibility.Visible;
            }
        }