OSDN Git Service

基本攻撃力の計算式を新しくして改修レベルも反映させる
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / EquipPanel.cs
1 // Copyright (C) 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
2 //\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
6 //\r
7 //    http://www.apache.org/licenses/LICENSE-2.0\r
8 //\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
14 \r
15 using System;\r
16 using System.Collections.Generic;\r
17 using System.Drawing;\r
18 using System.Windows.Forms;\r
19 \r
20 namespace KancolleSniffer\r
21 {\r
22     public class EquipPanel : Panel\r
23     {\r
24         private const int LineHeight = 14;\r
25         private const int LabelHeight = 12;\r
26         private EquipColumn[] _equipList;\r
27         private readonly List<ShipLabel[]> _labelList = new List<ShipLabel[]>();\r
28         private readonly List<Panel> _panelList = new List<Panel>();\r
29         private readonly ToolTip _toolTip = new ToolTip {ShowAlways = true};\r
30 \r
31         private class EquipColumn\r
32         {\r
33             public string Fleet { get; set; }\r
34             public string Ship { get; set; }\r
35             public int Id { get; set; }\r
36             public string Equip { get; set; }\r
37             public Color Color { get; set; }\r
38             public string Spec { get; set; }\r
39             public string AircraftSpec { get; set; }\r
40 \r
41             public EquipColumn()\r
42             {\r
43                 Fleet = Ship = Equip = AircraftSpec = "";\r
44                 Color = DefaultBackColor;\r
45             }\r
46         }\r
47 \r
48         public void UpdateEquip(Sniffer sniffer)\r
49         {\r
50             CreateEquipList(sniffer);\r
51             SuspendLayout();\r
52             CreateEquipLabels();\r
53             SetEquipLabels();\r
54             ResumeLayout();\r
55         }\r
56 \r
57         private void CreateEquipList(Sniffer sniffer)\r
58         {\r
59             var list = new List<EquipColumn>();\r
60             var fn = new[] {"第一艦隊", "第二艦隊", "第三艦隊", "第四艦隊"};\r
61             for (var f = 0; f < fn.Length; f++)\r
62             {\r
63                 var drumTotal = 0;\r
64                 var drumShips = 0;\r
65                 var levelTotal = 0;\r
66                 var ships = new List<EquipColumn>();\r
67                 foreach (var s in sniffer.GetShipStatuses(f))\r
68                 {\r
69                     var drum = 0;\r
70                     var equips = new List<EquipColumn>();\r
71                     for (var i = 0; i < s.Slot.Length; i++)\r
72                     {\r
73                         var item = s.Slot[i];\r
74                         var onslot = s.OnSlot[i];\r
75                         var max = s.Spec.MaxEq[i];\r
76                         if (item.Id == -1)\r
77                             continue;\r
78                         if (item.Spec.Name == "ドラム缶(輸送用)")\r
79                             drum++;\r
80                         var airspec = "";\r
81                         if (item.Spec.CanAirCombat)\r
82                         {\r
83                             if (item.Spec.Type == 7 || item.Spec.Type == 11) // 爆撃\r
84                             {\r
85                                 airspec = "航空戦 " + (25 + (int)(item.Spec.Bomber * Math.Sqrt(onslot)));\r
86                             }\r
87                             else if (item.Spec.Type == 8)\r
88                             {\r
89                                 var normal = 25 + item.Spec.Torpedo * Math.Sqrt(onslot);\r
90                                 airspec = "航空戦 " + (int)(normal * 0.8) + "/" + (int)(normal * 1.5);\r
91                             }\r
92                         }\r
93                         equips.Add(new EquipColumn\r
94                         {\r
95                             Equip = item.Spec.Name +\r
96                                     (item.Alv == 0 ? "" : "+" + item.Alv) +\r
97                                     (item.Level == 0 ? "" : "★" + item.Level) +\r
98                                     (!item.Spec.IsAircraft ? "" : " " + onslot + "/" + max),\r
99                             AircraftSpec = airspec,\r
100                             Color = item.Spec.Color\r
101                         });\r
102                     }\r
103                     if (s.SlotEx.Id > 0)\r
104                     {\r
105                         var item = s.SlotEx;\r
106                         equips.Add(new EquipColumn {Equip = item.Spec.Name, Color = item.Spec.Color});\r
107                     }\r
108                     if (drum != 0)\r
109                         drumShips++;\r
110                     drumTotal += drum;\r
111                     levelTotal += s.Level;\r
112                     var rfp = s.RealFirepower;\r
113                     var ras = s.RealAntiSubmarine;\r
114                     ships.Add(new EquipColumn\r
115                     {\r
116                         Ship = (s.Escaped ? "[避]" : "") + s.Name + " Lv" + s.Level,\r
117                         Id = s.Id,\r
118                         // ReSharper disable CompareOfFloatsByEqualityOperator\r
119                         Spec = (rfp == 0 ? "" : $"砲{rfp:f1}") + (ras == 0 ? "" : $" 潜{ras:f1}")\r
120                         // ReSharper restore CompareOfFloatsByEqualityOperator\r
121                     });\r
122                     ships.AddRange(equips);\r
123                 }\r
124                 list.Add(new EquipColumn\r
125                 {\r
126                     Fleet = fn[f] + (levelTotal == 0 ? "" : " 合計Lv" + levelTotal) +\r
127                             (drumTotal == 0 ? "" : " ドラム缶" + drumTotal + "(" + drumShips + "隻)")\r
128                 });\r
129                 list.AddRange(ships);\r
130             }\r
131             _equipList = list.ToArray();\r
132         }\r
133 \r
134         private void CreateEquipLabels()\r
135         {\r
136             for (var i = _labelList.Count; i < _equipList.Length; i++)\r
137                 CreateEquipLabels(i);\r
138         }\r
139 \r
140         private void CreateEquipLabels(int i)\r
141         {\r
142             var y = 1 + LineHeight * i;\r
143             var lbp = new Panel\r
144             {\r
145                 Location = new Point(0, y),\r
146                 Size = new Size(ShipListForm.PanelWidth, LineHeight),\r
147                 BackColor = ShipLabels.ColumnColors[(i + 1) % 2],\r
148                 Visible = false\r
149             };\r
150             lbp.Scale(ShipLabel.ScaleFactor);\r
151             lbp.Tag = lbp.Location.Y;\r
152             var labels = new[]\r
153             {\r
154                 new ShipLabel {Location = new Point(1, 2), AutoSize = true},\r
155                 new ShipLabel {Location = new Point(10, 2), AutoSize = true},\r
156                 new ShipLabel {Location = new Point(40, 2), AutoSize = true},\r
157                 new ShipLabel {Location = new Point(37, 2), Size = new Size(4, LabelHeight - 2)},\r
158                 new ShipLabel {Location = new Point(217, 2), AutoSize = true, AnchorRight = true}\r
159             };\r
160             _labelList.Add(labels);\r
161             _panelList.Add(lbp);\r
162             // ReSharper disable once CoVariantArrayConversion\r
163             lbp.Controls.AddRange(labels);\r
164             Controls.Add(lbp);\r
165             foreach (var label in labels)\r
166             {\r
167                 label.Scale();\r
168                 label.PresetColor =\r
169                     label.BackColor = ShipLabels.ColumnColors[(i + 1) % 2];\r
170             }\r
171         }\r
172 \r
173         private void SetEquipLabels()\r
174         {\r
175             for (var i = 0; i < _equipList.Length; i++)\r
176                 SetEquip(i);\r
177             for (var i = _equipList.Length; i < _labelList.Count; i++)\r
178                 _panelList[i].Visible = false;\r
179         }\r
180 \r
181         private void SetEquip(int i)\r
182         {\r
183             var lbp = _panelList[i];\r
184             if (!lbp.Visible)\r
185                 lbp.Location = new Point(lbp.Left, (int)lbp.Tag + AutoScrollPosition.Y);\r
186             var e = _equipList[i];\r
187             var labels = _labelList[i];\r
188             labels[0].Text = e.Fleet;\r
189             labels[1].SetName(e.Ship);\r
190             labels[2].Text = e.Equip;\r
191             labels[3].Visible = e.Equip != "";\r
192             labels[3].BackColor = e.Color;\r
193             labels[4].Text = e.Spec;\r
194             _toolTip.SetToolTip(labels[2], e.AircraftSpec != "" ? e.AircraftSpec : "");\r
195             lbp.Visible = true;\r
196         }\r
197 \r
198         public void ShowShip(int id)\r
199         {\r
200             var i = Array.FindIndex(_equipList, e => e.Id == id);\r
201             if (i == -1)\r
202                 return;\r
203             var y = (int)Math.Round(ShipLabel.ScaleFactor.Height * LineHeight * i);\r
204             AutoScrollPosition = new Point(0, y);\r
205         }\r
206     }\r
207 }