Exemplo n.º 1
0
        public virtual UIElement CreateControl()
        {
            var options = this.Options.Where(o => !o.IsHidden).ToList();

            if (options.Count <= 0)
            {
                return(new TextBlock()
                {
                    // ReSharper disable once CanExtractXamlLocalizableStringCSharp
                    Text = "This category has no options",
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment = VerticalAlignment.Center
                });
            }

            var tableControl = new TableControl()
            {
                VerticalAlignment   = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            tableControl.Loaded += (_, e) =>
            {
                // populate options
                tableControl.Clear();

                // local helper method for getting option order
                IEnumerable <IProtoOption> GetOptionOrder(IProtoOption tab)
                {
                    if (tab.OrderAfterOption != null)
                    {
                        yield return(tab.OrderAfterOption);
                    }
                }

                foreach (var option in options.OrderBy(o => o.ShortId)
                         .TopologicalSort(GetOptionOrder)
                         .Where(o => !o.IsHidden))
                {
                    option.CreateControl(out var labelControl, out var optionControl);
                    tableControl.Add(labelControl, optionControl);
                }
            };

            return(new ScrollViewer()
            {
                Content = tableControl,
                VerticalScrollBarVisibility = ScrollBarVisibility.Visible
            });
        }
Exemplo n.º 2
0
        private static void PopulateKeys(TableControl tableControl)
        {
            tableControl.Clear();
            tableControl.FontSize = 14;

            var categories = ClientInputManager.GetKnownButtons()
                             .GroupBy(pair => pair.Value.Category)
                             .OrderBy(category => category.Key);

            var isFirstCategory = true;

            foreach (var category in categories)
            {
                var textHeader = category.Key;
                if (string.IsNullOrEmpty(textHeader))
                {
                    textHeader = TitleGeneralControlsCategory;
                }

                // add category header
                var marginTop = isFirstCategory ? 0 : 8;
                isFirstCategory = false;
                var categoryHeader = new TextBlock()
                {
                    Text                = textHeader,
                    FontWeight          = FontWeights.Bold,
                    FontSize            = 16,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    Margin              = new Thickness(0, marginTop, 0, 5)
                };

                Grid.SetColumnSpan(categoryHeader, 3);
                tableControl.Add(categoryHeader, null);

                // add keys for this category
                foreach (var pair in category)
                {
                    var button = pair.Key;
                    var info   = pair.Value;

                    var labelControl = new FormattedTextBlock
                    {
                        // ReSharper disable once CanExtractXamlLocalizableStringCSharp
                        Content              = info.Title,
                        TextWrapping         = TextWrapping.Wrap,
                        FontSize             = 12,
                        LineHeight           = 13,
                        LineStackingStrategy = LineStackingStrategy.BlockLineHeight,
                        MaxWidth             = 150,
                        Margin              = new Thickness(0, 0, 0, 6),
                        TextAlignment       = TextAlignment.Right,
                        HorizontalAlignment = HorizontalAlignment.Right,
                        VerticalAlignment   = VerticalAlignment.Center
                    };

                    //ToolTipServiceExtend.SetToolTip(
                    //    labelControl,
                    //    new TextBlock()
                    //    {
                    //        Text = info.Description ?? info.Name,
                    //        TextWrapping = TextWrapping.Wrap,
                    //        MaxWidth = 200,
                    //        VerticalAlignment = VerticalAlignment.Center
                    //    });

                    var inputMappingControl = GetInputMappingControl(button, info);
                    tableControl.Add(labelControl, inputMappingControl);
                }
            }
        }
Exemplo n.º 3
0
        public virtual UIElement CreateControl()
        {
            var options = this.Options.Where(o => !o.IsHidden).ToList();

            if (options.Count <= 0)
            {
                return(new TextBlock()
                {
                    // ReSharper disable once CanExtractXamlLocalizableStringCSharp
                    Text = "This category has no options",
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment = VerticalAlignment.Center
                });
            }

            var tableControl = new TableControl()
            {
                VerticalAlignment   = VerticalAlignment.Top,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            tableControl.Loaded
                += (_, e) =>
                {
                if (!tableControl.IsEmpty)
                {
                    return;
                }

                // populate options
                tableControl.Clear();

                // local helper method for getting option order
                IEnumerable <IProtoOption> GetOptionOrder(IProtoOption tab)
                {
                    if (tab.OrderAfterOption is not null)
                    {
                        yield return(tab.OrderAfterOption);
                    }
                }

                foreach (var option in options.OrderBy(o => o.ShortId)
                         .TopologicalSort(GetOptionOrder)
                         .Where(o => !o.IsHidden))
                {
                    option.CreateControl(out var labelControl, out var optionControl);
                    optionControl.Focusable = false;

                    if (!string.IsNullOrEmpty(option.Description))
                    {
                        // wrap into a stackpanel with an info tooltip control
                        var controlInfoPoint = new Control
                        {
                            Style = Api.Client.UI.GetApplicationResource <Style>(
                                "ControlInfoQuestionPointStyle"),
                            VerticalAlignment = VerticalAlignment.Bottom,
                            Margin            = new Thickness(0, 0, 0, 3)
                        };

                        var stackPanel = new StackPanel
                        {
                            Orientation = Orientation.Horizontal,
                            Background  = Brushes.Transparent
                        };

                        stackPanel.Children.Add(optionControl);
                        stackPanel.Children.Add(controlInfoPoint);
                        optionControl = stackPanel;

                        var tooltipContent = new FormattedTextBlock()
                        {
                            Content  = option.Description,
                            MaxWidth = 300
                        };

                        ToolTipServiceExtend.SetToolTip(stackPanel, tooltipContent);
                        ToolTipServiceExtend.SetToolTip(labelControl, tooltipContent);
                    }

                    tableControl.Add(labelControl, optionControl);
                }
                };

            return(new ScrollViewer()
            {
                Content = tableControl,
                VerticalScrollBarVisibility = ScrollBarVisibility.Visible
            });
        }