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.View
\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 foreach (var fleet in sniffer.Fleets)
\r
59 var ships = fleet.ActualShips;
\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
\r
64 Fleet = fn[fleet.Number] + " : " + string.Join("/", forFleet.Select(x => x.ToString("f1")))
\r
66 foreach (var ship in ships)
\r
68 var rate = ship.EffectiveAntiAirForShip / 4.0;
\r
69 var diff = forFleet.Select(x => (x + ship.EffectiveAntiAirForShip) / 10.0);
\r
70 _table.Add(new Record
\r
72 Ship = ship.Name + " Lv" + ship.Level +
\r
73 " : " + ship.EffectiveAntiAirForShip.ToString("d"),
\r
76 _table.Add(new Record
\r
78 Rate = "割合: " + rate.ToString("f1") + "% ",
\r
79 Diff = "固定: " + string.Join("/", diff.Select(d => d.ToString("f1")))
\r
85 private void CreateLabels()
\r
87 for (var i = _labelList.Count; i < _table.Count; i++)
\r
91 private void CreateLabels(int i)
\r
93 var y = 1 + LineHeight * i;
\r
96 Location = new Point(0, y),
\r
97 Size = new Size(ListForm.PanelWidth, LineHeight),
\r
98 BackColor = ShipLabel.ColumnColors[(i + 1) % 2],
\r
101 lbp.Scale(ShipLabel.ScaleFactor);
\r
102 lbp.Tag = lbp.Location.Y;
\r
105 new ShipLabel {Location = new Point(1, 3), AutoSize = true},
\r
106 new ShipLabel {Location = new Point(10, 3), AutoSize = true},
\r
107 new ShipLabel {Location = new Point(35, 3), AutoSize = true},
\r
108 new ShipLabel {Location = new Point(100, 3), AutoSize = true}
\r
110 _labelList.Add(labels);
\r
111 _panelList.Add(lbp);
\r
112 // ReSharper disable once CoVariantArrayConversion
\r
113 lbp.Controls.AddRange(labels);
\r
115 foreach (var label in labels)
\r
118 label.PresetColor =
\r
119 label.BackColor = ShipLabel.ColumnColors[(i + 1) % 2];
\r
123 private void SetRecords()
\r
125 for (var i = 0; i < _table.Count; i++)
\r
127 for (var i = _table.Count; i < _panelList.Count; i++)
\r
128 _panelList[i].Visible = false;
\r
131 private void SetRecord(int i)
\r
133 var lbp = _panelList[i];
\r
135 lbp.Location = new Point(lbp.Left, (int)lbp.Tag + AutoScrollPosition.Y);
\r
136 var column = _table[i];
\r
137 var labels = _labelList[i];
\r
138 labels[0].Text = column.Fleet;
\r
139 labels[1].SetName(column.Ship);
\r
140 labels[2].Text = column.Rate;
\r
141 labels[3].Text = column.Diff;
\r
142 lbp.Visible = true;
\r
145 public void ShowShip(int id)
\r
147 var i = _table.FindIndex(e => e.Id == id);
\r
150 var y = (int)Math.Round(ShipLabel.ScaleFactor.Height * LineHeight * i);
\r
151 AutoScrollPosition = new Point(0, y);
\r