OSDN Git Service

艦隊ごとの装備一覧の艦娘名とLvの間に空白を入れる
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / EquipPanel.cs
1 // Copyright (C) 2015 Kazuhiro Fujieda <fujieda@users.sourceforge.jp>\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 \r
33         private class EquipColumn\r
34         {\r
35             public string Fleet { get; set; }\r
36             public string Ship { get; set; }\r
37             public int Id { get; set; }\r
38             public string Equip { get; set; }\r
39             public Color Color { get; set; }\r
40             public string Spec { get; set; }\r
41 \r
42             public EquipColumn()\r
43             {\r
44                 Fleet = Ship = Equip = "";\r
45                 Color = DefaultBackColor;\r
46             }\r
47         }\r
48 \r
49         public void UpdateEquip(Sniffer sniffer)\r
50         {\r
51             CreateEquipList(sniffer);\r
52             SuspendLayout();\r
53             CreateEquipLabels();\r
54             SetEquipLabels();\r
55             ResumeLayout();\r
56         }\r
57 \r
58         private void CreateEquipList(Sniffer sniffer)\r
59         {\r
60             var list = new List<EquipColumn>();\r
61             var fn = new[] {"第一艦隊", "第二艦隊", "第三艦隊", "第四艦隊"};\r
62             for (var f = 0; f < fn.Length; f++)\r
63             {\r
64                 var drumTotal = 0;\r
65                 var drumShips = 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 slot = s.Slot[i];\r
74                         var onslot = s.OnSlot[i];\r
75                         var max = s.Spec.MaxEq[i];\r
76                         if (slot == -1)\r
77                             continue;\r
78                         var item = sniffer.Item.ItemDict[slot];\r
79                         if (item.Spec.Name == "ドラム缶(輸送用)")\r
80                             drum++;\r
81                         equips.Add(new EquipColumn\r
82                         {\r
83                             Equip = item.Spec.Name + (item.Level == 0 ? "" : "★" + item.Level) +\r
84                                     (!item.Spec.IsAircraft ? "" : " " + onslot + "/" + max),\r
85                             Color = item.Spec.Color\r
86                         });\r
87                     }\r
88                     if (drum != 0)\r
89                         drumShips++;\r
90                     drumTotal += drum;\r
91                     var rfp = s.RealFirepower;\r
92                     var ras = s.RealAntiSubmarine;\r
93                     ships.Add(new EquipColumn\r
94                     {\r
95                         Ship = (s.Escaped ? "[避]" : "") + s.Name + " Lv" + s.Level,\r
96                         Id = s.Id,\r
97                         Spec = (rfp == 0 ? "" : "砲" + rfp) + (ras == 0 ? "" : " 潜" + ras)\r
98                     });\r
99                     ships.AddRange(equips);\r
100                 }\r
101                 list.Add(new EquipColumn\r
102                 {\r
103                     Fleet = fn[f] + (drumTotal == 0 ? "" : " ドラム缶" + drumTotal + "(" + drumShips + "隻)")\r
104                 });\r
105                 list.AddRange(ships);\r
106             }\r
107             _equipList = list.ToArray();\r
108         }\r
109 \r
110         private void CreateEquipLabels()\r
111         {\r
112             for (var i = _labelList.Count; i < _equipList.Length; i++)\r
113                 CreateEquipLabels(i);\r
114         }\r
115 \r
116         private void CreateEquipLabels(int i)\r
117         {\r
118             var y = 1 + LineHeight * i;\r
119             var lbp = new Panel\r
120             {\r
121                 Location = new Point(0, y),\r
122                 Size = new Size(ShipListForm.PanelWidth, LineHeight),\r
123                 BackColor = ShipLabels.ColumnColors[(i + 1) % 2],\r
124                 Visible = false\r
125             };\r
126             lbp.Scale(ShipLabel.ScaleFactor);\r
127             lbp.Tag = lbp.Location.Y;\r
128             var labels = new[]\r
129             {\r
130                 new ShipLabel {Location = new Point(1, 2), AutoSize = true},\r
131                 new ShipLabel {Location = new Point(10, 2), AutoSize = true},\r
132                 new ShipLabel {Location = new Point(40, 2), AutoSize = true},\r
133                 new ShipLabel {Location = new Point(37, 2), Size = new Size(4, LabelHeight - 2)},\r
134                 new ShipLabel {Location = new Point(217, 2), AutoSize = true, AnchorRight = true}\r
135             };\r
136             _labelList.Add(labels);\r
137             _panelList.Add(lbp);\r
138             // ReSharper disable once CoVariantArrayConversion\r
139             lbp.Controls.AddRange(labels);\r
140             Controls.Add(lbp);\r
141             foreach (var label in labels)\r
142             {\r
143                 label.Scale();\r
144                 label.PresetColor =\r
145                     label.BackColor = ShipLabels.ColumnColors[(i + 1) % 2];\r
146             }\r
147         }\r
148 \r
149         private void SetEquipLabels()\r
150         {\r
151             for (var i = 0; i < _equipList.Length; i++)\r
152                 SetEquip(i);\r
153             for (var i = _equipList.Length; i < _labelList.Count; i++)\r
154                 _panelList[i].Visible = false;\r
155         }\r
156 \r
157         private void SetEquip(int i)\r
158         {\r
159             var lbp = _panelList[i];\r
160             if (!lbp.Visible)\r
161                 lbp.Location = new Point(lbp.Left, (int)lbp.Tag + AutoScrollPosition.Y);\r
162             var e = _equipList[i];\r
163             var labels = _labelList[i];\r
164             labels[0].Text = e.Fleet;\r
165             labels[1].SetName(e.Ship);\r
166             labels[2].Text = e.Equip;\r
167             labels[3].Visible = e.Equip != "";\r
168             labels[3].BackColor = e.Color;\r
169             labels[4].Text = e.Spec;\r
170             lbp.Visible = true;\r
171         }\r
172 \r
173         public void ShowShip(int id)\r
174         {\r
175             var i = Array.FindIndex(_equipList, e => e.Id == id);\r
176             if (i == -1)\r
177                 return;\r
178             var y = (int)Math.Round(ShipLabel.ScaleFactor.Height * LineHeight * i);\r
179             AutoScrollPosition = new Point(0, y);\r
180         }\r
181     }\r
182 }