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
19 using KancolleSniffer.Forms;
\r
20 using KancolleSniffer.Model;
\r
22 namespace KancolleSniffer.View.ListWindow
\r
24 public class AntiAirPanel : Panel, IPanelResize
\r
26 private const int LineHeight = 16;
\r
27 private readonly List<AntiAirLabels> _labelList = new List<AntiAirLabels>();
\r
28 private readonly List<Record> _table = new List<Record>();
\r
30 private class AntiAirLabels : ShipLabels
\r
32 public Label Rate { get; set; }
\r
33 public Label Diff { get; set; }
\r
35 protected override Control[] AddedControls => new Control[] {Rate, Diff};
\r
38 public void Update(Sniffer sniffer)
\r
40 CreateTable(sniffer);
\r
48 private class Record
\r
50 public string Fleet { get; set; }
\r
51 public string Ship { get; set; }
\r
52 public int Id { get; set; }
\r
53 public string Rate { get; set; }
\r
54 public string Diff { get; set; }
\r
58 Fleet = Ship = Rate = Diff = "";
\r
62 private void CreateTable(Sniffer sniffer)
\r
65 var fn = new[] {"第一艦隊", "第二艦隊", "第三艦隊", "第四艦隊"};
\r
66 foreach (var fleet in sniffer.Fleets)
\r
68 var ships = fleet.ActualShips;
\r
69 var rawForFleet = ships.Sum(ship => ship.EffectiveAntiAirForFleet);
\r
70 var forFleet = new[] {1.0, 1.2, 1.6}.Select(r => (int)(rawForFleet * r) * 2 / 1.3).ToArray();
\r
71 _table.Add(new Record
\r
73 Fleet = fn[fleet.Number] + " 防空" + string.Join("/", forFleet.Select(x => x.ToString("f1")))
\r
75 foreach (var ship in ships)
\r
77 _table.Add(CreateShipRecord(ship));
\r
78 _table.Add(CreateAntiAirRecord(forFleet, ship));
\r
83 private Record CreateShipRecord(ShipStatus ship)
\r
85 var param = " Lv" + ship.Level +
\r
86 " 加重" + ship.EffectiveAntiAirForShip.ToString("d") +
\r
87 AntiAirPropellantBarrageChance(ship);
\r
88 var name = ship.Name;
\r
89 var realWidth = Scaler.ScaleWidth(ListForm.PanelWidth - 10);
\r
92 Ship = StringTruncator.Truncate(name, param, realWidth, GetFont(name)) + param,
\r
97 private Record CreateAntiAirRecord(double[] forFleet, ShipStatus ship)
\r
99 var rate = ship.EffectiveAntiAirForShip / 4.0;
\r
100 var diff = forFleet.Select(x => (x + ship.EffectiveAntiAirForShip) / 10.0);
\r
103 Rate = "割合" + rate.ToString("f1") + "% ",
\r
104 Diff = "固定" + string.Join("/", diff.Select(d => d.ToString("f1")))
\r
108 private static Font GetFont(string name)
\r
110 return ShipLabel.Name.StartWithLetter(name)
\r
111 ? ShipLabel.Name.LatinFont
\r
112 : ShipLabel.Name.BaseFont;
\r
115 private static string AntiAirPropellantBarrageChance(ShipStatus ship)
\r
117 // ReSharper disable once CompareOfFloatsByEqualityOperator
\r
118 if (ship.AntiAirPropellantBarrageChance == 0)
\r
120 var chance = ship.AntiAirPropellantBarrageChance;
\r
121 return " 弾幕" + (chance < 100 ? chance.ToString("f1") : ((int)chance).ToString());
\r
124 private void CreateLabels()
\r
126 for (var i = _labelList.Count; i < _table.Count; i++)
\r
130 private void CreateLabels(int i)
\r
132 var y = 1 + LineHeight * i;
\r
133 var labels = new AntiAirLabels
\r
135 Fleet = new ShipLabel.Fleet(new Point(1, 3)),
\r
136 Name = new ShipLabel.Name(new Point(10, 3), ShipNameWidth.Max),
\r
137 Rate = new Label {Location = new Point(35, 3), AutoSize = true},
\r
138 Diff = new Label {Location = new Point(100, 3), AutoSize = true},
\r
139 BackPanel = new Panel
\r
141 Location = new Point(0, y),
\r
142 Size = new Size(ListForm.PanelWidth, LineHeight),
\r
145 _labelList.Add(labels);
\r
146 labels.Arrange(this, CustomColors.ColumnColors.BrightFirst(i));
\r
148 labels.Move(AutoScrollPosition);
\r
151 public void ApplyResize()
\r
158 private void ResizeLabels()
\r
160 var width = Width - SystemInformation.VerticalScrollBarWidth - 2;
\r
161 foreach (var labels in _labelList)
\r
162 labels.BackPanel.Width = width;
\r
165 private void SetRecords()
\r
167 for (var i = 0; i < _table.Count; i++)
\r
169 for (var i = _table.Count; i < _labelList.Count; i++)
\r
170 _labelList[i].BackPanel.Visible = false;
\r
173 private void SetRecord(int i)
\r
175 var lbp = _labelList[i].BackPanel;
\r
176 var column = _table[i];
\r
177 var labels = _labelList[i];
\r
178 labels.Fleet.Text = column.Fleet;
\r
179 labels.Name.SetName(column.Ship);
\r
180 labels.Rate.Text = column.Rate;
\r
181 labels.Diff.Text = column.Diff;
\r
182 lbp.Visible = true;
\r
185 public void ShowShip(int id)
\r
187 var i = _table.FindIndex(e => e.Id == id);
\r
190 var y = Scaler.ScaleHeight(LineHeight * i);
\r
191 AutoScrollPosition = new Point(0, y);
\r