Exemplo n.º 1
0
 private static void ShowColor(TextBlock control, Border border, ArkColor color)
 {
     if (color == null)
     {
         control.Text           = string.Empty;
         control.Background     = Brushes.White;
         control.Tag            = null;
         border.BorderBrush     = Brushes.LightGray;
         border.BorderThickness = ThinBorder;
     }
     else
     {
         control.Text           = color.Name;
         control.Background     = color.Color;
         control.Tag            = color;
         border.BorderBrush     = Brushes.Black;
         border.BorderThickness = ThickBorder;
     }
 }
Exemplo n.º 2
0
        private void DrawData(Creature creature, bool highlight, int highlightStatIndex, ToolTip tt)
        {
            if (creature?.Species == null)
            {
                return;
            }

            var usedStats    = Enumerable.Range(0, Values.STATS_COUNT).Where(si => si != (int)StatNames.Torpidity && creature.Species.UsesStat(si)).ToArray();
            var anglePerStat = 360f / usedStats.Length;

            const int borderWidth = 1;

            // used for the tooltip text
            var colors = new ArkColor[Species.ColorRegionCount];

            (_statInheritances, _mutationInColor) = DetermineInheritanceAndMutations(creature, usedStats);

            var mutationOccurred = _mutationInColor != null;

            Bitmap bmp = new Bitmap(Width, Height);

            using (Graphics g = Graphics.FromImage(bmp))
                using (var font = new Font("Microsoft Sans Serif", _fontSize))
                    using (var pen = new Pen(Color.Black))
                        using (var brush = new SolidBrush(Color.Black))
                        {
                            g.SmoothingMode = SmoothingMode.AntiAlias;

                            var   borderColor      = Color.FromArgb(219, 219, 219);
                            float drawnBorderWidth = borderWidth;
                            if (highlight)
                            {
                                borderColor      = Color.DodgerBlue;
                                drawnBorderWidth = 1.5f;
                            }
                            else
                            {
                                Cursor = Cursors.Hand;
                                if (highlightStatIndex != -1)
                                {
                                    borderColor = Color.Black;
                                }
                            }

                            if (mutationOccurred)
                            {
                                borderColor      = Utils.MutationMarkerColor;
                                drawnBorderWidth = 1.5f;
                            }

                            pen.Color = borderColor;
                            pen.Width = drawnBorderWidth;
                            g.DrawRectangle(pen, drawnBorderWidth, drawnBorderWidth, Width - 2 * drawnBorderWidth, Height - 2 * drawnBorderWidth);

                            // stats
                            var chartMax          = CreatureCollection.CurrentCreatureCollection?.maxChartLevel ?? 50;
                            int radiusInnerCircle = (_statSize - 2 * borderWidth) / 7;
                            int centerCoord       = _statSize / 2 - 1;

                            var i = 0;
                            if (creature.levelsWild != null)
                            {
                                pen.Color = Color.Black;
                                foreach (var si in usedStats)
                                {
                                    var level = creature.levelsWild[si];

                                    var statSize  = Math.Min((double)level / chartMax, 1);
                                    var pieRadius = (int)(radiusInnerCircle + (centerCoord - radiusInnerCircle - borderWidth) * statSize);
                                    var leftTop   = centerCoord - pieRadius;
                                    var angle     = AngleOffset + anglePerStat * i++;
                                    brush.Color = Utils.GetColorFromPercent((int)(100 * statSize), creature.topBreedingStats[si] ? 0 : 0.7);
                                    g.FillPie(brush, leftTop, leftTop, 2 * pieRadius, 2 * pieRadius, angle, anglePerStat);

                                    pen.Width = highlightStatIndex == si ? 2 : 1;
                                    g.DrawPie(pen, leftTop, leftTop, 2 * pieRadius, 2 * pieRadius, angle, anglePerStat);

                                    var       mutationStatus  = _statInheritances[si];
                                    const int anyMutationMask = 0b01110111;
                                    if ((mutationStatus & anyMutationMask) == 0)
                                    {
                                        continue;
                                    }

                                    const int mutationIsNotGuaranteedMask = 0b10001000;
                                    var       guaranteedMutation          = (mutationStatus & mutationIsNotGuaranteedMask) == 0;

                                    var anglePosition = Math.PI * 2 / 360 * (angle + anglePerStat / 2);
                                    var x             = (int)Math.Round(pieRadius * Math.Cos(anglePosition) + centerCoord - _mutationMarkerRadius - 1);
                                    var y             = (int)Math.Round(pieRadius * Math.Sin(anglePosition) + centerCoord - _mutationMarkerRadius - 1);
                                    DrawFilledCircle(g, brush, pen, guaranteedMutation ? Utils.MutationMarkerColor : Utils.MutationMarkerPossibleColor, x, y, 2 * _mutationMarkerRadius);
                                }
                            }

                            // draw sex in the center
                            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                            brush.Color         = Utils.AdjustColorLight(Utils.SexColor(creature.sex), 0.2);
                            g.FillEllipse(brush, centerCoord - radiusInnerCircle, centerCoord - radiusInnerCircle, 2 * radiusInnerCircle, 2 * radiusInnerCircle);
                            pen.Width = 1;
                            g.DrawEllipse(pen, centerCoord - radiusInnerCircle, centerCoord - radiusInnerCircle, 2 * radiusInnerCircle, 2 * radiusInnerCircle);

                            brush.Color = Color.Black;
                            using (var format = new StringFormat
                            {
                                Alignment = StringAlignment.Center,
                                LineAlignment = StringAlignment.Center
                            })
                            {
                                g.DrawString(Utils.SexSymbol(creature.sex), font, brush,
                                             new RectangleF(centerCoord - radiusInnerCircle + 1, centerCoord - radiusInnerCircle + 2, 2 * radiusInnerCircle, 2 * radiusInnerCircle),
                                             format);
                                g.DrawString(creature.name, font, brush,
                                             new RectangleF(borderWidth, _statSize + borderWidth - 2, ControlWidth - borderWidth, _colorSize),
                                             format);
                            }

                            // colors
                            if (creature.colors != null)
                            {
                                var displayedColorRegions = Enumerable.Range(0, Species.ColorRegionCount)
                                                            .Where(ci => creature.Species.EnabledColorRegions[ci]).ToArray();

                                var usedColorRegionCount = displayedColorRegions.Length;
                                if (usedColorRegionCount != 0)
                                {
                                    const int margin    = 1;
                                    var       colorSize = new Size(_colorSize - 3 * margin - borderWidth,
                                                                   (_statSize - 2 * borderWidth) / usedColorRegionCount - 3 * margin);

                                    // only check for color mutations if the colors of both parents are available
                                    mutationOccurred = mutationOccurred && creature.Mother?.colors != null &&
                                                       creature.Father?.colors != null;

                                    i = 0;
                                    var left = _statSize + 2 * margin;
                                    foreach (var ci in displayedColorRegions)
                                    {
                                        var color = CreatureColors.CreatureArkColor(creature.colors[ci]);
                                        colors[ci]  = color;
                                        brush.Color = color.Color;
                                        var y = borderWidth + margin + i++ *(colorSize.Height + 2 * margin);
                                        g.FillRectangle(brush, left, y, colorSize.Width,
                                                        colorSize.Height);
                                        g.DrawRectangle(pen, left, y, colorSize.Width,
                                                        colorSize.Height);

                                        var colorMutationOccurred =
                                            mutationOccurred && creature.colors[ci] != creature.Mother.colors[ci] &&
                                            creature.colors[ci] != creature.Father.colors[ci];
                                        if (colorMutationOccurred)
                                        {
                                            var x = left - _colorMutationMarkerRadius - 2;
                                            y = y + colorSize.Height / 2 - _colorMutationMarkerRadius;
                                            DrawFilledCircle(g, brush, pen, Color.Yellow, x, y, 2 * _colorMutationMarkerRadius);
                                            _mutationInColor[ci] = true;
                                        }
                                    }
                                }
                            }

                            if (_mutationInColor != null && !_mutationInColor.Any(m => m))
                            {
                                _mutationInColor = null; // not needed, no possible mutations
                            }
                            // mutation indicator
                            if (!creature.flags.HasFlag(CreatureFlags.Placeholder))
                            {
                                int   yMarker       = _statSize - _mutationIndicatorSize - 1 - borderWidth;
                                Color mutationColor = creature.Mutations == 0 ? Color.GreenYellow
                        : creature.Mutations < GameConstants.MutationPossibleWithLessThan ? Utils.MutationColor
                        : Color.DarkRed;

                                DrawFilledCircle(g, brush, pen, mutationColor, borderWidth + 1, yMarker, _mutationIndicatorSize);
                            }
                        }

            var oldImage = Image;

            Image = bmp;
            oldImage?.Dispose();

            var statNames = creature.Species?.statNames;

            var toolTipText = $"{creature.name} ({Utils.SexSymbol(creature.sex)})";

            if (creature.flags.HasFlag(CreatureFlags.Placeholder))
            {
                toolTipText += "\nThis creature is not yet in this library. This entry is a placeholder and contains no more info";
            }
            else
            {
                string InheritanceExplanation(int statIndex)
                {
                    var mutationStatus = _statInheritances[statIndex];

                    if (mutationStatus == 0)
                    {
                        return(null);
                    }
                    var resultMother = Mutation(true);
                    var resultFather = Mutation(false);

                    if (resultMother == null && resultFather == null)
                    {
                        return(null);
                    }

                    return($" ({resultMother}{(resultMother != null && resultFather != null ? " or " : null)}{resultFather})");

                    string Mutation(bool mother)
                    {
                        var status = (mutationStatus >> (!mother ? 4 : 0)) & 0xf;

                        if (status == 0)
                        {
                            return(null);
                        }
                        var sex = mother ? "♀" : "♂";

                        if (status == 8)
                        {
                            return(sex);
                        }
                        if (status > 8)
                        {
                            var mutationCount = status & 7;
                            return($"{sex} with possible {mutationCount} mutation{(mutationCount > 1 ? "s" : null)}");
                        }
                        return($"{sex} with {status} mutation{(status > 1 ? "s" : null)}");
                    }
                }

                if (creature.levelsWild != null)
                {
                    toolTipText +=
                        $"\n{string.Join("\n", usedStats.Select(si => $"{Utils.StatName(si, true, statNames)}:\t{creature.levelsWild[si],3}{InheritanceExplanation(si)}"))}";
                }
                toolTipText +=
                    $"\n{Loc.S("Mutations")}: {creature.Mutations} = {creature.mutationsMaternal} (♀) + {creature.mutationsPaternal} (♂)";
                if (creature.colors != null)
                {
                    toolTipText +=
                        $"\n{Loc.S("Colors")}\n{string.Join("\n", colors.Select((c, i) => c == null ? null : $"[{i}]:\t{c.Id} ({c.Name}){((_mutationInColor?[i] ?? false) ? " (mutated color)" : null)}").Where(s => s != null))}";
                }
            }