private void DrawBars(Dictionary <int, double> levelProbabilities, double maxProbability)
        {
            SuspendLayout();
            Clear(false);

            int    totalWidth       = Width;
            int    totalHeight      = Height - 14;
            double heightMultiplier = totalHeight / maxProbability;

            int barNumber = levelProbabilities.Count;

            if (barNumber > 0)
            {
                int barWidth = totalWidth / barNumber;
                int i        = 0;
                foreach (KeyValuePair <int, double> prob in levelProbabilities.OrderBy(l => l.Key))
                {
                    Panel p = new Panel
                    {
                        Width  = barWidth,
                        Height = (int)Math.Ceiling(prob.Value * heightMultiplier)
                    };
                    tt.SetToolTip(p, $"Level {prob.Key} ({Math.Round(prob.Value * 100, 2)}%)");
                    p.Left        = i * barWidth;
                    p.Top         = totalHeight - p.Height;
                    p.BackColor   = Utils.GetColorFromPercent(100 * (prob.Key - maxWildLevel / 2) / (2 * maxWildLevel)); // color range from maxWildLevel/2 up to 2*maxWildLevel
                    p.BorderStyle = BorderStyle.FixedSingle;
                    Controls.Add(p);
                    barPanels.Add(p);

                    // min/max-labels
                    if (i == 0)
                    {
                        labelMin.Text = prob.Key.ToString();
                    }
                    if (i == barNumber - 1)
                    {
                        labelMax.Text = prob.Key.ToString();
                    }

                    i++;
                }
                labelMax.Left     = i * barWidth - labelMax.Width;
                labelMaxProb.Text = Math.Round(maxProbability * 100, 2) + "%";
            }
            ResumeLayout();
        }
Esempio n. 2
0
        /// <summary>
        /// Draws a chart with the given levels.
        /// </summary>
        /// <param name="levels">If null, the previous values are redrawn.</param>
        public void SetLevels(int[] levels = null)
        {
            if ((levels != null && levels.Length <= 6) || _maxR <= 5)
            {
                return;
            }

            Bitmap bmp = new Bitmap(Width, Height);

            using (Graphics g = Graphics.FromImage(bmp))
                using (Pen penLine = new Pen(Color.FromArgb(128, 255, 255, 255)))
                    using (var font = new Font("Microsoft Sans Serif", 8f))
                    {
                        g.SmoothingMode = SmoothingMode.AntiAlias;

                        // the indices of the displayed stats
                        var levelIndices = new[]
                        {
                            (int)StatNames.Health, (int)StatNames.Stamina, (int)StatNames.Oxygen, (int)StatNames.Food,
                            (int)StatNames.Weight, (int)StatNames.MeleeDamageMultiplier, (int)StatNames.SpeedMultiplier
                        };

                        for (int s = 0; s < levelIndices.Length; s++)
                        {
                            if (levels == null || levels[levelIndices[s]] != _oldLevels[s])
                            {
                                if (levels != null)
                                {
                                    _oldLevels[s] = levels[levelIndices[s]];
                                }
                                int r = _oldLevels[s] * _maxR / _maxLevel;
                                if (r < 0)
                                {
                                    r = 0;
                                }
                                if (r > _maxR)
                                {
                                    r = _maxR;
                                }
                                double angle = AnglePerStat * s - AngleOffset;
                                _ps[s] = new Point(_xm + (int)(r * Math.Cos(angle)), _ym + (int)(r * Math.Sin(angle)));
                            }
                        }

                        g.FillEllipse(_grBrushBg, _xm - _maxR, _ym - _maxR, 2 * _maxR + 1, 2 * _maxR + 1);

                        g.FillPolygon(_grBrushFg, _ps.ToArray());
                        g.DrawPolygon(penLine, _ps.ToArray());

                        double stepFactor = (double)_step / _maxLevel;
                        for (int r = 0; r < 5; r++)
                        {
                            using (var pen = new Pen(Utils.GetColorFromPercent((int)(100 * r * stepFactor), -0.4)))
                                g.DrawEllipse(pen,
                                              (int)(_xm - _maxR * r * stepFactor), (int)(_ym - _maxR * r * stepFactor),
                                              (int)(2 * _maxR * r * stepFactor + 1), (int)(2 * _maxR * r * stepFactor + 1));
                        }

                        using (var pen = new Pen(Utils.GetColorFromPercent(100, -0.4)))
                            g.DrawEllipse(pen, _xm - _maxR, _ym - _maxR, 2 * _maxR + 1, 2 * _maxR + 1);

                        using (var pen = new Pen(Color.Gray))
                            for (int s = 0; s < levelIndices.Length; s++)
                            {
                                pen.Width = 1;
                                pen.Color = Color.Gray;
                                g.DrawLine(pen, _xm, _ym, _maxPs[s].X, _maxPs[s].Y);
                                Color cl = Utils.GetColorFromPercent(100 * _oldLevels[s] / _maxLevel);
                                pen.Color = cl;
                                pen.Width = 3;
                                g.DrawLine(pen, _xm, _ym, _ps[s].X, _ps[s].Y);
                                Brush b = new SolidBrush(cl);
                                g.FillEllipse(b, _ps[s].X - 4, _ps[s].Y - 4, 8, 8);
                                g.DrawEllipse(penLine, _ps[s].X - 4, _ps[s].Y - 4, 8, 8);
                                b.Dispose();
                            }

                        using (var brush = new SolidBrush(Color.FromArgb(190, 255, 255, 255)))
                        {
                            for (int r = 1; r < 5; r++)
                            {
                                g.DrawString((_step * r).ToString("N0"), font,
                                             brush, _xm - 8, _ym - 6 + r * _maxR / 5);
                            }

                            g.DrawString((_maxLevel).ToString("N0"), font,
                                         brush, _xm - 8, _ym - 11 + _maxR);
                        }

                        g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

                        using (var brushBlack = new SolidBrush(Color.Black))
                        {
                            for (int s = 0; s < levelIndices.Length; s++)
                            {
                                double angle = AnglePerStat * s - AngleOffset;
                                g.DrawString(Utils.StatName(levelIndices[s], true), font,
                                             brushBlack, _xm - 9 + (int)((_maxR + 10) * Math.Cos(angle)),
                                             _ym - 5 + (int)((_maxR + 10) * Math.Sin(angle)));
                            }
                        }
                    }

            Image?.Dispose();
            Image = bmp;
        }
Esempio n. 3
0
        public void setLevels(int[] levels)
        {
            if (levels != null && levels.Length > 6 && maxR > 5)
            {
                Bitmap   bmp = new Bitmap(Width, Height);
                Graphics g   = Graphics.FromImage(bmp);
                g.SmoothingMode = SmoothingMode.AntiAlias;

                const double angleSeven = Math.PI / 3.5;
                const double offset     = Math.PI / 2;

                // the indices of the displayed stats
                var levelIndices = new int[] { (int)StatNames.Health, (int)StatNames.Stamina, (int)StatNames.Oxygen, (int)StatNames.Food, (int)StatNames.Weight, (int)StatNames.MeleeDamageMultiplier, (int)StatNames.SpeedMultiplier };

                for (int s = 0; s < levelIndices.Length; s++)
                {
                    if (levels[levelIndices[s]] != oldLevels[s])
                    {
                        oldLevels[s] = levels[levelIndices[s]];
                        int r = oldLevels[s] * maxR / maxLevel;
                        if (r < 0)
                        {
                            r = 0;
                        }
                        if (r > maxR)
                        {
                            r = maxR;
                        }
                        double angle = angleSeven * s - offset;
                        ps[s] = new Point(xm + (int)(r * Math.Cos(angle)), ym + (int)(r * Math.Sin(angle)));
                    }
                }
                g.FillEllipse(grBrushBG, xm - maxR, ym - maxR, 2 * maxR + 1, 2 * maxR + 1);

                Pen penL = new Pen(Color.FromArgb(128, 255, 255, 255));
                g.FillPolygon(grBrushFG, ps.ToArray());
                g.DrawPolygon(penL, ps.ToArray());

                double stepFactor = (double)step / maxLevel;
                for (int r = 0; r < 5; r++)
                {
                    g.DrawEllipse(new Pen(Utils.GetColorFromPercent((int)(100 * r * stepFactor), -0.4)),
                                  (int)(xm - maxR * r * stepFactor), (int)(ym - maxR * r * stepFactor),
                                  (int)(2 * maxR * r * stepFactor + 1), (int)(2 * maxR * r * stepFactor + 1));
                }
                g.DrawEllipse(new Pen(Utils.GetColorFromPercent(100, -0.4)), xm - maxR, ym - maxR, 2 * maxR + 1, 2 * maxR + 1);

                Pen pen = new Pen(Color.Black);
                for (int s = 0; s < levelIndices.Length; s++)
                {
                    pen.Width = 1;
                    pen.Color = Color.Gray;
                    g.DrawLine(pen, xm, ym, maxPs[s].X, maxPs[s].Y);
                    Color cl = Utils.GetColorFromPercent(100 * oldLevels[s] / maxLevel);
                    pen.Color = cl;
                    pen.Width = 3;
                    g.DrawLine(pen, xm, ym, ps[s].X, ps[s].Y);
                    Brush b = new SolidBrush(cl);
                    g.FillEllipse(b, ps[s].X - 4, ps[s].Y - 4, 8, 8);
                    g.DrawEllipse(penL, ps[s].X - 4, ps[s].Y - 4, 8, 8);
                    b.Dispose();
                }
                for (int r = 1; r < 5; r++)
                {
                    g.DrawString((step * r).ToString("N0"), new Font("Microsoft Sans Serif", 8f), new SolidBrush(Color.FromArgb(190, 255, 255, 255)), xm - 8, ym - 6 + r * maxR / 5);
                }
                g.DrawString((maxLevel).ToString("N0"), new Font("Microsoft Sans Serif", 8f), new SolidBrush(Color.FromArgb(190, 255, 255, 255)), xm - 8, ym - 11 + maxR);

                g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
                for (int s = 0; s < levelIndices.Length; s++)
                {
                    double angle = angleSeven * s - offset;
                    g.DrawString(Utils.StatName(levelIndices[s], true), new Font("Microsoft Sans Serif", 8f), new SolidBrush(Color.Black), xm - 9 + (int)((maxR + 10) * Math.Cos(angle)), ym - 5 + (int)((maxR + 10) * Math.Sin(angle)));
                }

                g.Dispose();

                Image = bmp;
            }
        }