Ejemplo n.º 1
0
        private static double AddButtonPart(string caption, double[] margins, double actualPrevPartWidth,
                                            string id, Brush background, double?partWidth = null, bool enabled = true, bool countable = false)
        {
            Label newPart = new Label
            {
                Tag     = id,
                Content = caption,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                Foreground = Brushes.White,
                Background = background,
            };

            newPart.Width = partWidth ?? (countable ? 51 : 77);

            if (countable && enabled && (caption == "+" || caption == "-"))
            {
                newPart.MouseDown += CountableOption_Click;
            }
            else if (!countable && enabled)
            {
                newPart.MouseDown += AddOption_Click;
            }

            if (!String.IsNullOrEmpty(caption))
            {
                Border border = new Border
                {
                    BorderThickness = new Thickness(1),
                    BorderBrush     = Brushes.Black,
                    Background      = background,
                    Child           = newPart,
                };
                border.Margin = Changes.Thick(newPart, margins[0] + 2 + actualPrevPartWidth, margins[1] + 20);
                border.Width  = partWidth ?? (countable ? 51 : 77);

                Changes.main.unitDetail.Children.Add(border);
            }
            else
            {
                newPart.Margin = Changes.Thick(newPart, margins[0] + 2 + actualPrevPartWidth, margins[1] + 21);
                Changes.main.unitDetail.Children.Add(newPart);
            }

            Changes.main.UpdateLayout();

            return(newPart.ActualWidth);
        }
Ejemplo n.º 2
0
        private static double AddLabel(string caption, double[] margins, double height, ref double lastColumnMaxWidth,
                                       bool selected  = false, double points = 0, bool perModel = false, bool bold = false, string addLine = "",
                                       int fixPadding = 0, bool enabled      = true)
        {
            Label newOption = new Label();

            string[] captionLines = Other.WordSplit(caption);

            newOption.Content = String.Empty;

            foreach (string line in captionLines)
            {
                newOption.Content += (String.IsNullOrEmpty(newOption.Content.ToString()) ? String.Empty : Environment.NewLine + "   ") + line;
            }

            newOption.Margin = Changes.Thick(newOption, margins[0], margins[1]);

            if (!enabled)
            {
                newOption.Foreground = Brushes.Gray;
            }
            else if (selected)
            {
                newOption.Foreground = ArmyBook.Data.AdditionalColor;
            }

            if (selected || bold)
            {
                newOption.FontWeight = FontWeights.Bold;
            }

            if (bold)
            {
                newOption.Foreground = Brushes.White;
                newOption.Background = ArmyBook.Data.MainColor;
            }

            Changes.main.unitDetail.Children.Add(newOption);
            Changes.main.UpdateLayout();

            double actualWidth = newOption.ActualWidth;

            if (points > 0 || points < 0 || !String.IsNullOrEmpty(addLine))
            {
                double leftPadding = (points > 0 ? -5 : 5);

                bool pointsNeed = (points > 0) || (points < 0);

                Label optionPoints = new Label
                {
                    Content = (pointsNeed ? points.ToString() + " pts" + (perModel ? "/m" : String.Empty) : addLine)
                };
                optionPoints.Margin = Changes.Thick(optionPoints, margins[0] + newOption.ActualWidth + leftPadding, margins[1]);

                if (!enabled)
                {
                    optionPoints.Foreground = Brushes.Gray;
                }
                else
                {
                    optionPoints.Foreground = ArmyBook.Data.MainColor;
                }

                Changes.main.unitDetail.Children.Add(optionPoints);
                Changes.main.UpdateLayout();

                actualWidth += optionPoints.ActualWidth - 5;
            }

            if (captionLines.Length > 1)
            {
                Line longOptionLine = new Line
                {
                    X1 = newOption.Margin.Left + 8,
                    Y1 = newOption.Margin.Top + height + 8
                };
                longOptionLine.X2 = longOptionLine.X1;
                longOptionLine.Y2 = longOptionLine.Y1 + height * (captionLines.Length - 1);

                longOptionLine.StrokeThickness = 2;
                longOptionLine.Stroke          = ArmyBook.Data.MainColor;

                Changes.main.unitDetail.Children.Add(longOptionLine);
            }

            if (actualWidth > lastColumnMaxWidth)
            {
                lastColumnMaxWidth = actualWidth;
            }

            double bottomPadding = (captionLines.Length > 1 ? 5 : 0);

            return((height * captionLines.Length) + bottomPadding + fixPadding);
        }