1 // Copyright (C) 2016 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
16 using System.Collections.Generic;
\r
17 using System.Drawing;
\r
19 using System.Windows.Forms;
\r
21 namespace KancolleSniffer
\r
23 public class AntiAirPanel : Panel
\r
25 private const int LineHeight = 16;
\r
26 private readonly List<ShipLabel[]> _labelList = new List<ShipLabel[]>();
\r
27 private readonly List<Panel> _panelList = new List<Panel>();
\r
28 private readonly List<Record> _table = new List<Record>();
\r
30 public void Update(Sniffer sniffer)
\r
32 CreateTable(sniffer);
\r
39 private class Record
\r
41 public string Fleet { get; set; }
\r
42 public string Ship { get; set; }
\r
43 public int Id { get; set; }
\r
44 public string Rate { get; set; }
\r
45 public string Diff { get; set; }
\r
49 Fleet = Ship = Rate = Diff = "";
\r
53 private void CreateTable(Sniffer sniffer)
\r
56 var fn = new[] {"第一艦隊", "第二艦隊", "第三艦隊", "第四艦隊"};
\r
57 for (var f = 0; f < fn.Length; f++)
\r
59 var ships = sniffer.GetShipStatuses(f);
\r
60 var rawForFleet = ships.Sum(ship => ship.EffectiveAntiAirForFleet);
\r
61 var forFleet = new[] {1.0, 1.2, 1.6}.Select(r => (int)(rawForFleet * r) * 2 / 1.3).ToArray();
\r
62 _table.Add(new Record {Fleet = fn[f] + " : " + string.Join("/", forFleet.Select(x => x.ToString("f1")))});
\r
63 foreach (var ship in ships)
\r
65 var rate = ship.EffectiveAntiAirForShip / 4.0;
\r
66 var diff = forFleet.Select(x => (x + ship.EffectiveAntiAirForShip) / 10.0);
\r
67 _table.Add(new Record
\r
69 Ship = ship.Name + " Lv" + ship.Level +
\r
70 " : " + ship.EffectiveAntiAirForShip.ToString("d"),
\r
73 _table.Add(new Record
\r
75 Rate = "割合: " + rate.ToString("f1") + "% ",
\r
76 Diff = "固定: " + string.Join("/", diff.Select(d => d.ToString("f1")))
\r
82 private void CreateLabels()
\r
84 for (var i = _labelList.Count; i < _table.Count; i++)
\r
88 private void CreateLabels(int i)
\r
90 var y = 1 + LineHeight * i;
\r
93 Location = new Point(0, y),
\r
94 Size = new Size(ListForm.PanelWidth, LineHeight),
\r
95 BackColor = ShipLabels.ColumnColors[(i + 1) % 2],
\r
98 lbp.Scale(ShipLabel.ScaleFactor);
\r
99 lbp.Tag = lbp.Location.Y;
\r
102 new ShipLabel {Location = new Point(1, 3), AutoSize = true},
\r
103 new ShipLabel {Location = new Point(10, 3), AutoSize = true},
\r
104 new ShipLabel {Location = new Point(35, 3), AutoSize = true},
\r
105 new ShipLabel {Location = new Point(100, 3), AutoSize = true},
\r
107 _labelList.Add(labels);
\r
108 _panelList.Add(lbp);
\r
109 // ReSharper disable once CoVariantArrayConversion
\r
110 lbp.Controls.AddRange(labels);
\r
112 foreach (var label in labels)
\r
115 label.PresetColor =
\r
116 label.BackColor = ShipLabels.ColumnColors[(i + 1) % 2];
\r
120 private void SetRecords()
\r
122 for (var i = 0; i < _table.Count; i++)
\r
124 for (var i = _table.Count; i < _panelList.Count; i++)
\r
125 _panelList[i].Visible = false;
\r
128 private void SetRecord(int i)
\r
130 var lbp = _panelList[i];
\r
132 lbp.Location = new Point(lbp.Left, (int)lbp.Tag + AutoScrollPosition.Y);
\r
133 var column = _table[i];
\r
134 var labels = _labelList[i];
\r
135 labels[0].Text = column.Fleet;
\r
136 labels[1].SetName(column.Ship);
\r
137 labels[2].Text = column.Rate;
\r
138 labels[3].Text = column.Diff;
\r
139 lbp.Visible = true;
\r
142 public void ShowShip(int id)
\r
144 var i = _table.FindIndex(e => e.Id == id);
\r
147 var y = (int)Math.Round(ShipLabel.ScaleFactor.Height * LineHeight * i);
\r
148 AutoScrollPosition = new Point(0, y);
\r