1 // Copyright (C) 2015 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;
\r
17 using System.Collections.Generic;
\r
18 using System.Drawing;
\r
20 using System.Windows.Forms;
\r
22 namespace KancolleSniffer
\r
24 public class FleetPanel : Panel
\r
26 private const int LineHeight = 14;
\r
27 private const int LabelHeight = 12;
\r
28 private Record[] _table;
\r
29 private readonly List<FleetLabels> _labelList = new List<FleetLabels>();
\r
30 private readonly List<Panel> _panelList = new List<Panel>();
\r
31 private readonly ResizableToolTip _toolTip = new ResizableToolTip {ShowAlways = true};
\r
33 private class Record
\r
35 public string Fleet { get; set; }
\r
36 public string Fleet2 { get; set; }
\r
37 public string Ship { get; set; }
\r
38 public string Ship2 { get; set; }
\r
39 public int Id { get; set; }
\r
40 public string Equip { get; set; }
\r
41 public Color Color { get; set; }
\r
42 public string Spec { get; set; }
\r
43 public string Spec2 { get; set; }
\r
44 public string AircraftSpec { get; set; }
\r
48 Fleet = Ship = Equip = AircraftSpec = "";
\r
49 Color = DefaultBackColor;
\r
53 public void Update(Sniffer sniffer)
\r
55 CreateTable(sniffer);
\r
62 private void CreateTable(Sniffer sniffer)
\r
64 var list = new List<Record>();
\r
65 var fn = new[] {"第一", "第二", "第三", "第四"};
\r
66 for (var f = 0; f < fn.Length; f++)
\r
72 var antiAirTotal = 0;
\r
74 var ships = new List<Record>();
\r
75 foreach (var s in sniffer.GetShipStatuses(f))
\r
78 var equips = new List<Record>();
\r
79 for (var i = 0; i < s.Slot.Length; i++)
\r
81 var item = s.Slot[i];
\r
82 var onslot = s.OnSlot[i];
\r
83 var max = s.Spec.MaxEq[i];
\r
86 if (item.Spec.Name == "ドラム缶(輸送用)")
\r
89 if (item.Spec.IsDiveBomber) // 爆撃
\r
92 (25 + (int)((item.Spec.Bomber + item.BomberLevelBonus) * Math.Sqrt(onslot)));
\r
94 else if (item.Spec.IsTorpedoBomber)
\r
96 var normal = 25 + item.Spec.Torpedo * Math.Sqrt(onslot);
\r
97 airspec = "航空戦 " + (int)(normal * 0.8) + "/" + (int)(normal * 1.5);
\r
100 equips.Add(new Record
\r
102 Equip = GenEquipString(item),
\r
103 Spec = item.Spec.IsAircraft ? $"+{item.Alv} {onslot}/{max}" : "",
\r
104 AircraftSpec = airspec,
\r
105 Color = item.Spec.Color
\r
108 if (s.SlotEx.Id > 0)
\r
110 var item = s.SlotEx;
\r
111 equips.Add(new Record {Equip = GenEquipString(item), Color = item.Spec.Color});
\r
116 levelTotal += s.Level;
\r
117 aswTotal += s.AntiSubmarine;
\r
118 antiAirTotal += s.AntiAir;
\r
120 var fire = s.EffectiveFirepower;
\r
121 var subm = s.EffectiveAntiSubmarine;
\r
122 var torp = s.EffectiveTorpedo;
\r
123 var night = s.NightBattlePower;
\r
124 var oasa = s.CanOpeningAntiSubmarineAttack ? "*" : "";
\r
125 var ship = new Record
\r
127 Ship = (s.Escaped ? "[避]" : "") + s.Name + " Lv" + s.Level,
\r
130 // ReSharper disable CompareOfFloatsByEqualityOperator
\r
131 Spec = (fire == 0 ? "" : $"砲{fire:f1}") + (subm == 0 ? "" : $" 潜{subm:f1}{oasa}"),
\r
132 Spec2 = (torp == 0 ? "" : $"雷{torp:f1}") + (night == 0 ? "" : $" 夜{night:f1}")
\r
133 // ReSharper restore CompareOfFloatsByEqualityOperator
\r
135 if (ship.Spec == "")
\r
137 ship.Spec = ship.Spec2;
\r
141 ships.AddRange(equips);
\r
143 var daihatsu = sniffer.GetDaihatsuBonus(f);
\r
144 var tp = sniffer.GetTransportPoint(f);
\r
145 if (sniffer.CombinedFleetType != 0 && f == 0)
\r
146 tp += sniffer.GetTransportPoint(1);
\r
147 list.Add(new Record
\r
149 Fleet = fn[f] + (levelTotal == 0 ? "" : " Lv" + levelTotal) +
\r
150 (drumTotal == 0 ? "" : " 缶" + drumTotal + "(" + drumShips + "隻)") +
\r
151 (aswTotal > 0 ? $" 潜{CutOverFlow(aswTotal)}" : "") +
\r
152 (antiAirTotal > 0 ? $" 空{CutOverFlow(antiAirTotal)}" : "") +
\r
153 (losTotal > 0 ? $" 索{CutOverFlow(losTotal)}" : ""),
\r
154 Fleet2 = (sniffer.CombinedFleetType != 0 && f == 1 ? "" : $"TP:S{(int)tp}A{(int)(tp * 0.7)}") +
\r
155 (daihatsu > 0 ? $" 発{daihatsu * 100:f1}%" : "")
\r
157 list.AddRange(ships);
\r
159 if (sniffer.BaseAirCorps != null)
\r
161 var name = new[] {"第一", "第二", "第三"};
\r
162 foreach (var baseInfo in sniffer.BaseAirCorps)
\r
164 list.Add(new Record {Fleet = baseInfo.AreaName + " 基地航空隊"});
\r
166 foreach (var airCorps in baseInfo.AirCorps)
\r
168 if (i >= name.Length)
\r
170 var corpsFp = airCorps.FighterPower;
\r
173 if (airCorps.Action == 2)
\r
175 spec = "制空:" + RangeString(corpsFp.Interception);
\r
176 spec2 = corpsFp.IsInterceptor ? "制空(出撃):" + RangeString(corpsFp.AirCombat) : "";
\r
180 spec = "制空:" + RangeString(corpsFp.AirCombat);
\r
181 spec2 = corpsFp.IsInterceptor ? "制空(防空):" + RangeString(corpsFp.Interception) : "";
\r
183 var cost = airCorps.CostForSortie;
\r
184 list.Add(new Record
\r
186 Ship = name[i++] + " " + airCorps.ActionName,
\r
187 Ship2 = $"出撃コスト:燃{cost[0]}弾{cost[1]}",
\r
188 Spec = spec + " 距離:" + airCorps.Distance,
\r
191 list.AddRange(airCorps.Planes.Select(plane =>
\r
193 var planeFp = plane.FighterPower;
\r
196 Equip = plane.State != 1 ? plane.StateName : GenEquipString(plane.Slot),
\r
197 Spec = plane.State != 1 ? "" : $"+{plane.Slot.Alv} {plane.Count}/{plane.MaxCount}",
\r
199 $"距離:{plane.Slot.Spec.Distance} 制空:{RangeString(planeFp.AirCombat)}" +
\r
200 (planeFp.IsInterceptor ? $" 防空:{RangeString(planeFp.Interception)}" : ""),
\r
201 Color = plane.Slot.Spec.Color
\r
207 _table = list.ToArray();
\r
210 private string RangeString(int[] fp) => fp[0] == fp[1] ? fp[0].ToString() : $"{fp[0]}~{fp[1]}";
\r
212 private int CutOverFlow(int value) => value > 999 ? 999 : value;
\r
214 private string GenEquipString(ItemStatus item)
\r
216 var name = item.Spec.Name;
\r
217 var attr = item.Level == 0 ? "" : "★" + item.Level;
\r
218 var proposed = new Size(int.MaxValue, int.MaxValue);
\r
219 var maxWidth = item.Spec.IsAircraft ? 132 : 180;
\r
220 var result = name + attr;
\r
221 if (TextRenderer.MeasureText(result, Font, proposed).Width <= maxWidth)
\r
223 var truncated = "";
\r
224 foreach (var ch in name)
\r
226 var tmp = truncated + ch;
\r
227 if (TextRenderer.MeasureText(tmp + attr, Font, proposed).Width > maxWidth)
\r
231 return truncated + attr;
\r
234 private void CreateLabels()
\r
236 for (var i = _labelList.Count; i < _table.Length; i++)
\r
240 private class FleetLabels : IEnumerable<ShipLabel>
\r
242 public ShipLabel Fleet { get; set; }
\r
243 public ShipLabel Name { get; set; }
\r
244 public ShipLabel Equip { get; set; }
\r
245 public ShipLabel EquipColor { get; set; }
\r
246 public ShipLabel Spec { get; set; }
\r
248 public IEnumerator<ShipLabel> GetEnumerator() =>
\r
249 ((IEnumerable<ShipLabel>)new[] {Fleet, Name, Equip, EquipColor, Spec}).GetEnumerator();
\r
251 IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
\r
254 private void CreateLabels(int i)
\r
256 var y = 1 + LineHeight * i;
\r
257 var lbp = new Panel
\r
259 Location = new Point(0, y),
\r
260 Size = new Size(ListForm.PanelWidth, LineHeight),
\r
261 BackColor = ShipLabel.ColumnColors[(i + 1) % 2],
\r
264 lbp.Scale(ShipLabel.ScaleFactor);
\r
265 lbp.Tag = lbp.Location.Y;
\r
266 var labels = new FleetLabels
\r
268 Fleet = new ShipLabel {Location = new Point(1, 2), AutoSize = true},
\r
269 Name = new ShipLabel {Location = new Point(10, 2), AutoSize = true},
\r
270 Equip = new ShipLabel {Location = new Point(38, 2), AutoSize = true},
\r
271 EquipColor = new ShipLabel {Location = new Point(35, 2), Size = new Size(4, LabelHeight - 2)},
\r
272 Spec = new ShipLabel {Location = new Point(217, 2), AutoSize = true, AnchorRight = true}
\r
274 _labelList.Add(labels);
\r
275 _panelList.Add(lbp);
\r
276 lbp.Controls.AddRange(labels.Cast<Control>().ToArray());
\r
278 foreach (var label in labels)
\r
281 label.PresetColor =
\r
282 label.BackColor = ShipLabel.ColumnColors[(i + 1) % 2];
\r
286 private void SetRecords()
\r
288 for (var i = 0; i < _table.Length; i++)
\r
290 for (var i = _table.Length; i < _labelList.Count; i++)
\r
291 _panelList[i].Visible = false;
\r
294 private void SetRecord(int i)
\r
296 var lbp = _panelList[i];
\r
298 lbp.Location = new Point(lbp.Left, (int)lbp.Tag + AutoScrollPosition.Y);
\r
300 var labels = _labelList[i];
\r
301 labels.Fleet.Text = e.Fleet;
\r
302 labels.Name.SetName(e.Ship);
\r
304 _toolTip.SetToolTip(labels.Name, e.Ship2);
\r
305 labels.Equip.Text = e.Equip;
\r
306 labels.EquipColor.Visible = e.Equip != "";
\r
307 labels.EquipColor.BackColor = e.Color;
\r
308 labels.Spec.Text = e.Spec;
\r
309 if (e.Fleet != "" && e.Fleet2 != "")
\r
310 _toolTip.SetToolTip(labels.Fleet, e.Fleet2);
\r
311 _toolTip.SetToolTip(labels.Equip, e.AircraftSpec != "" ? e.AircraftSpec : "");
\r
312 _toolTip.SetToolTip(labels.Spec, e.Spec2 != "" ? e.Spec2 : "");
\r
313 lbp.Visible = true;
\r
316 public void ShowShip(int id)
\r
318 var i = Array.FindIndex(_table, e => e.Id == id);
\r
321 var y = (int)Math.Round(ShipLabel.ScaleFactor.Height * LineHeight * i);
\r
322 AutoScrollPosition = new Point(0, y);
\r
325 public void ShowFleet(string fn)
\r
327 var i = Array.FindIndex(_table, e => e.Fleet.StartsWith(fn));
\r
330 var y = (int)Math.Round(ShipLabel.ScaleFactor.Height * LineHeight * i);
\r
331 AutoScrollPosition = new Point(0, y);
\r
334 protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
\r
336 base.ScaleControl(factor, specified);
\r
337 if (factor.Height > 1)
\r
338 _toolTip.Font = new Font(_toolTip.Font.FontFamily, _toolTip.Font.Size * factor.Height);
\r