OSDN Git Service

艦隊情報で艦載機の攻撃力を表示する
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / EquipPanel.cs
1 // Copyright (C) 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
2 //\r
3 // This program is part of KancolleSniffer.\r
4 //\r
5 // KancolleSniffer is free software: you can redistribute it and/or modify\r
6 // it under the terms of the GNU General Public License as published by\r
7 // the Free Software Foundation, either version 3 of the License, or\r
8 // (at your option) any later version.\r
9 //\r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 //\r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, see <http://www.gnu.org/licenses/>.\r
17 \r
18 using System;\r
19 using System.Collections.Generic;\r
20 using System.Drawing;\r
21 using System.Windows.Forms;\r
22 \r
23 namespace KancolleSniffer\r
24 {\r
25     public class EquipPanel : Panel\r
26     {\r
27         private const int LineHeight = 14;\r
28         private const int LabelHeight = 12;\r
29         private EquipColumn[] _equipList;\r
30         private readonly List<ShipLabel[]> _labelList = new List<ShipLabel[]>();\r
31         private readonly List<Panel> _panelList = new List<Panel>();\r
32         private readonly ToolTip _toolTip = new ToolTip();\r
33 \r
34         private class EquipColumn\r
35         {\r
36             public string Fleet { get; set; }\r
37             public string Ship { get; set; }\r
38             public int Id { get; set; }\r
39             public string Equip { get; set; }\r
40             public Color Color { get; set; }\r
41             public string Spec { get; set; }\r
42             public string AircraftSpec { get; set; }\r
43 \r
44             public EquipColumn()\r
45             {\r
46                 Fleet = Ship = Equip = AircraftSpec = "";\r
47                 Color = DefaultBackColor;\r
48             }\r
49         }\r
50 \r
51         public void UpdateEquip(Sniffer sniffer)\r
52         {\r
53             CreateEquipList(sniffer);\r
54             SuspendLayout();\r
55             CreateEquipLabels();\r
56             SetEquipLabels();\r
57             ResumeLayout();\r
58         }\r
59 \r
60         private void CreateEquipList(Sniffer sniffer)\r
61         {\r
62             var list = new List<EquipColumn>();\r
63             var fn = new[] {"第一艦隊", "第二艦隊", "第三艦隊", "第四艦隊"};\r
64             for (var f = 0; f < fn.Length; f++)\r
65             {\r
66                 var drumTotal = 0;\r
67                 var drumShips = 0;\r
68                 var levelTotal = 0;\r
69                 var ships = new List<EquipColumn>();\r
70                 foreach (var s in sniffer.GetShipStatuses(f))\r
71                 {\r
72                     var drum = 0;\r
73                     var equips = new List<EquipColumn>();\r
74                     for (var i = 0; i < s.Slot.Length; i++)\r
75                     {\r
76                         var slot = s.Slot[i];\r
77                         var onslot = s.OnSlot[i];\r
78                         var max = s.Spec.MaxEq[i];\r
79                         if (slot == -1)\r
80                             continue;\r
81                         var item = sniffer.Item.ItemDict[slot];\r
82                         if (item.Spec.Name == "ドラム缶(輸送用)")\r
83                             drum++;\r
84                         var airspec = "";\r
85                         if (item.Spec.CanAirCombat)\r
86                         {\r
87                             if (item.Spec.Type == 7 || item.Spec.Type == 11) // 爆撃\r
88                             {\r
89                                 airspec = "航空戦 " + (25 + (int)(item.Spec.Bomber * Math.Sqrt(onslot)));\r
90                             }\r
91                             else if (item.Spec.Type == 8)\r
92                             {\r
93                                 var normal = 25 + item.Spec.Torpedo * Math.Sqrt(onslot);\r
94                                 airspec = "航空戦 " + (int)(normal * 0.8) + "/" + (int)(normal * 1.5);\r
95                             }\r
96                         }\r
97                         equips.Add(new EquipColumn\r
98                         {\r
99                             Equip = item.Spec.Name +\r
100                                     (item.Alv == 0 ? "" : "+" + item.Alv) +\r
101                                     (item.Level == 0 ? "" : "★" + item.Level) +\r
102                                     (!item.Spec.IsAircraft ? "" : " " + onslot + "/" + max),\r
103                             AircraftSpec = airspec,\r
104                             Color = item.Spec.Color\r
105                         });\r
106                     }\r
107                     if (s.SlotEx > 0)\r
108                     {\r
109                         var item = sniffer.Item.ItemDict[s.SlotEx];\r
110                         equips.Add(new EquipColumn {Equip = item.Spec.Name, Color = item.Spec.Color});\r
111                     }\r
112                     if (drum != 0)\r
113                         drumShips++;\r
114                     drumTotal += drum;\r
115                     levelTotal += s.Level;\r
116                     var rfp = s.RealFirepower;\r
117                     var ras = s.RealAntiSubmarine;\r
118                     ships.Add(new EquipColumn\r
119                     {\r
120                         Ship = (s.Escaped ? "[避]" : "") + s.Name + " Lv" + s.Level,\r
121                         Id = s.Id,\r
122                         Spec = (rfp == 0 ? "" : "砲" + rfp) + (ras == 0 ? "" : " 潜" + ras)\r
123                     });\r
124                     ships.AddRange(equips);\r
125                 }\r
126                 list.Add(new EquipColumn\r
127                 {\r
128                     Fleet = fn[f] + (levelTotal == 0 ? "" : " 合計Lv" + levelTotal) +\r
129                             (drumTotal == 0 ? "" : " ドラム缶" + drumTotal + "(" + drumShips + "隻)")\r
130                 });\r
131                 list.AddRange(ships);\r
132             }\r
133             _equipList = list.ToArray();\r
134         }\r
135 \r
136         private void CreateEquipLabels()\r
137         {\r
138             for (var i = _labelList.Count; i < _equipList.Length; i++)\r
139                 CreateEquipLabels(i);\r
140         }\r
141 \r
142         private void CreateEquipLabels(int i)\r
143         {\r
144             var y = 1 + LineHeight * i;\r
145             var lbp = new Panel\r
146             {\r
147                 Location = new Point(0, y),\r
148                 Size = new Size(ShipListForm.PanelWidth, LineHeight),\r
149                 BackColor = ShipLabels.ColumnColors[(i + 1) % 2],\r
150                 Visible = false\r
151             };\r
152             lbp.Scale(ShipLabel.ScaleFactor);\r
153             lbp.Tag = lbp.Location.Y;\r
154             var labels = new[]\r
155             {\r
156                 new ShipLabel {Location = new Point(1, 2), AutoSize = true},\r
157                 new ShipLabel {Location = new Point(10, 2), AutoSize = true},\r
158                 new ShipLabel {Location = new Point(40, 2), AutoSize = true},\r
159                 new ShipLabel {Location = new Point(37, 2), Size = new Size(4, LabelHeight - 2)},\r
160                 new ShipLabel {Location = new Point(217, 2), AutoSize = true, AnchorRight = true}\r
161             };\r
162             _labelList.Add(labels);\r
163             _panelList.Add(lbp);\r
164             // ReSharper disable once CoVariantArrayConversion\r
165             lbp.Controls.AddRange(labels);\r
166             Controls.Add(lbp);\r
167             foreach (var label in labels)\r
168             {\r
169                 label.Scale();\r
170                 label.PresetColor =\r
171                     label.BackColor = ShipLabels.ColumnColors[(i + 1) % 2];\r
172             }\r
173         }\r
174 \r
175         private void SetEquipLabels()\r
176         {\r
177             for (var i = 0; i < _equipList.Length; i++)\r
178                 SetEquip(i);\r
179             for (var i = _equipList.Length; i < _labelList.Count; i++)\r
180                 _panelList[i].Visible = false;\r
181         }\r
182 \r
183         private void SetEquip(int i)\r
184         {\r
185             var lbp = _panelList[i];\r
186             if (!lbp.Visible)\r
187                 lbp.Location = new Point(lbp.Left, (int)lbp.Tag + AutoScrollPosition.Y);\r
188             var e = _equipList[i];\r
189             var labels = _labelList[i];\r
190             labels[0].Text = e.Fleet;\r
191             labels[1].SetName(e.Ship);\r
192             labels[2].Text = e.Equip;\r
193             labels[3].Visible = e.Equip != "";\r
194             labels[3].BackColor = e.Color;\r
195             labels[4].Text = e.Spec;\r
196             _toolTip.SetToolTip(labels[2], e.AircraftSpec != "" ? e.AircraftSpec : "");\r
197             lbp.Visible = true;\r
198         }\r
199 \r
200         public void ShowShip(int id)\r
201         {\r
202             var i = Array.FindIndex(_equipList, e => e.Id == id);\r
203             if (i == -1)\r
204                 return;\r
205             var y = (int)Math.Round(ShipLabel.ScaleFactor.Height * LineHeight * i);\r
206             AutoScrollPosition = new Point(0, y);\r
207         }\r
208     }\r
209 }