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
15 using System.Collections.Generic;
\r
16 using System.Drawing;
\r
18 using System.Windows.Forms;
\r
20 namespace KancolleSniffer.View
\r
22 public class AntiAirPanel : Panel
\r
24 private const int LineHeight = 16;
\r
25 private readonly List<ShipLabel[]> _labelList = new List<ShipLabel[]>();
\r
26 private readonly List<Panel> _panelList = new List<Panel>();
\r
27 private readonly List<Record> _table = new List<Record>();
\r
29 public void Update(Sniffer sniffer)
\r
31 CreateTable(sniffer);
\r
38 private class Record
\r
40 public string Fleet { get; set; }
\r
41 public string Ship { get; set; }
\r
42 public int Id { get; set; }
\r
43 public string Rate { get; set; }
\r
44 public string Diff { get; set; }
\r
48 Fleet = Ship = Rate = Diff = "";
\r
52 private void CreateTable(Sniffer sniffer)
\r
55 var fn = new[] {"第一艦隊", "第二艦隊", "第三艦隊", "第四艦隊"};
\r
56 foreach (var fleet in sniffer.Fleets)
\r
58 var ships = fleet.ActualShips;
\r
59 var rawForFleet = ships.Sum(ship => ship.EffectiveAntiAirForFleet);
\r
60 var forFleet = new[] {1.0, 1.2, 1.6}.Select(r => (int)(rawForFleet * r) * 2 / 1.3).ToArray();
\r
61 _table.Add(new Record
\r
63 Fleet = fn[fleet.Number] + " : " + string.Join("/", forFleet.Select(x => x.ToString("f1")))
\r
65 foreach (var ship in ships)
\r
67 var rate = ship.EffectiveAntiAirForShip / 4.0;
\r
68 var diff = forFleet.Select(x => (x + ship.EffectiveAntiAirForShip) / 10.0);
\r
69 _table.Add(new Record
\r
71 Ship = ship.Name + " Lv" + ship.Level +
\r
72 " : " + ship.EffectiveAntiAirForShip.ToString("d"),
\r
75 _table.Add(new Record
\r
77 Rate = "割合: " + rate.ToString("f1") + "% ",
\r
78 Diff = "固定: " + string.Join("/", diff.Select(d => d.ToString("f1")))
\r
84 private void CreateLabels()
\r
86 for (var i = _labelList.Count; i < _table.Count; i++)
\r
90 private void CreateLabels(int i)
\r
92 var y = 1 + LineHeight * i;
\r
95 Location = new Point(0, y),
\r
96 Size = new Size(ListForm.PanelWidth, LineHeight),
\r
97 BackColor = CustomColors.ColumnColors.BrightFirst(i),
\r
101 lbp.Tag = lbp.Location.Y;
\r
104 new ShipLabel {Location = new Point(1, 3), AutoSize = true},
\r
105 new ShipLabel {Location = new Point(10, 3), AutoSize = true},
\r
106 new ShipLabel {Location = new Point(35, 3), AutoSize = true},
\r
107 new ShipLabel {Location = new Point(100, 3), AutoSize = true}
\r
109 _labelList.Add(labels);
\r
110 _panelList.Add(lbp);
\r
111 // ReSharper disable once CoVariantArrayConversion
\r
112 lbp.Controls.AddRange(labels);
\r
114 foreach (var label in labels)
\r
116 Scaler.Scale(label);
\r
117 label.BackColor = CustomColors.ColumnColors.BrightFirst(i);
\r
121 private void SetRecords()
\r
123 for (var i = 0; i < _table.Count; i++)
\r
125 for (var i = _table.Count; i < _panelList.Count; i++)
\r
126 _panelList[i].Visible = false;
\r
129 private void SetRecord(int i)
\r
131 var lbp = _panelList[i];
\r
133 lbp.Location = new Point(lbp.Left, (int)lbp.Tag + AutoScrollPosition.Y);
\r
134 var column = _table[i];
\r
135 var labels = _labelList[i];
\r
136 labels[0].Text = column.Fleet;
\r
137 labels[1].SetName(column.Ship);
\r
138 labels[2].Text = column.Rate;
\r
139 labels[3].Text = column.Diff;
\r
140 lbp.Visible = true;
\r
143 public void ShowShip(int id)
\r
145 var i = _table.FindIndex(e => e.Id == id);
\r
148 var y = Scaler.ScaleHeight(LineHeight * i);
\r
149 AutoScrollPosition = new Point(0, y);
\r