1 // Copyright (C) 2020 Kazuhiro Fujieda <fujieda@users.osdn.me>
\r
3 // Licensed under the Apache License, Version 2.0 (the "License");
\r
4 // you may not use this file except in compliance with the License.
\r
5 // You may obtain a copy of the License at
\r
7 // http://www.apache.org/licenses/LICENSE-2.0
\r
9 // Unless required by applicable law or agreed to in writing, software
\r
10 // distributed under the License is distributed on an "AS IS" BASIS,
\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 // See the License for the specific language governing permissions and
\r
13 // limitations under the License.
\r
15 using System.Drawing;
\r
16 using System.Windows.Forms;
\r
18 namespace KancolleSniffer.View.MainWindow
\r
20 public class ChargeStatus : Control, IUpdateContext
\r
22 private readonly Color[] _colors = {CUDColors.Yellow, CUDColors.Orange, CUDColors.Red, CUDColors.LightGray};
\r
24 private float IconWidth => Width * 8 / 17.0f;
\r
26 private float Head => Height * 8 / 13f;
\r
28 private float BulletLeft => Width * 9 / 17.0f;
\r
30 private readonly Brush _defaultBrush = new SolidBrush(DefaultBackColor);
\r
32 private Graphics _g;
\r
34 private Model.ChargeStatus _status;
\r
36 public UpdateContext Context { get; set; }
\r
38 public override string Text { get; set; } = "";
\r
40 public new void Update()
\r
42 var fleet = (int)Tag;
\r
43 _status = Context.Sniffer.Fleets[fleet].ChargeStatus;
\r
44 Text = _status.Empty ? "" : $"燃{_status.FuelRatio * 100:f1}% 弾{_status.BullRatio * 100:f1}%";
\r
48 protected override void OnPaint(PaintEventArgs e)
\r
50 if (_status == null)
\r
57 private void DrawFuelStatus()
\r
59 var charge = _status.Fuel;
\r
60 if (charge % 5 == 0)
\r
65 DrawFuelHead(charge);
\r
66 DrawStatus(0, charge % 5 - 1);
\r
69 private void DrawFuelHead(int charge)
\r
72 new SolidBrush(charge <= 4 ? Color.FromArgb(83, 131, 52) : Color.FromArgb(178, 196, 165)),
\r
75 new PointF(0, 0), new PointF(IconWidth, 0), new PointF(IconWidth, Height), new Point(0, Height)
\r
79 private void DrawBulletStatus()
\r
81 var charge = _status.Bull;
\r
82 if (charge % 5 == 0)
\r
87 DrawBulletHead(charge);
\r
88 DrawStatus(BulletLeft, charge % 5 - 1);
\r
91 private void DrawBulletHead(int charge)
\r
94 var r = l + IconWidth;
\r
95 var curve = Height * 6 / 13f;
\r
96 var brush = new SolidBrush(charge <= 4 ? Color.FromArgb(153, 101, 0) : Color.FromArgb(205, 185, 144));
\r
97 _g.FillClosedCurve(brush,
\r
98 new[] {new PointF(l, curve), new PointF(l + IconWidth / 2.0f, -1), new PointF(r, curve)});
\r
99 _g.FillPolygon(brush,
\r
102 new PointF(l, curve), new PointF(r, curve), new PointF(r, Height), new PointF(l, Height)
\r
106 private void DrawStatus(float left, int color)
\r
108 var right = left + IconWidth;
\r
109 _g.FillPolygon(new SolidBrush(_colors[color]),
\r
112 new PointF(left, Head), new PointF(right, Head), new PointF(right, Height), new PointF(left, Height)
\r
116 private void Clear(float left)
\r
118 _g.FillRectangle(_defaultBrush, left, 0, left + IconWidth, Height);
\r