OSDN Git Service

ShipListPanelで一列分のラベルを配列で持つのをやめる
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / View / ShipListPanel / RepairListLabels.cs
1 // Copyright (C) 2019 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.Collections.Generic;\r
16 using System.Drawing;\r
17 using System.Linq;\r
18 using System.Windows.Forms;\r
19 \r
20 namespace KancolleSniffer.View.ShipListPanel\r
21 {\r
22     public class RepairListLabels\r
23     {\r
24         private readonly ShipListPanel _shipListPanel;\r
25         private readonly List<RepairLabels> _labelList = new List<RepairLabels>();\r
26 \r
27         private class RepairLabels : ShipLabels\r
28         {\r
29             public ShipLabel Time { get; set; }\r
30             public ShipLabel PerHp { get; set; }\r
31 \r
32             public override Control[] Controls => base.Controls.Concat(new[] {Time, PerHp}).ToArray();\r
33         }\r
34 \r
35         public RepairListLabels(ShipListPanel shipListPanel)\r
36         {\r
37             _shipListPanel = shipListPanel;\r
38         }\r
39 \r
40         public void CreateLabels(int i)\r
41         {\r
42             var y = ShipListPanel.LineHeight * i + 1;\r
43             const int height = ShipListPanel.LabelHeight;\r
44             var labels = new RepairLabels\r
45             {\r
46                 Fleet = new ShipLabel {Location = new Point(1, 2), AutoSize = true},\r
47                 Name = new ShipLabel {Location = new Point(10, 2), AutoSize = true},\r
48                 Hp = new ShipLabel\r
49                 {\r
50                     Location = new Point(118, 0),\r
51                     AutoSize = true,\r
52                     AnchorRight = true,\r
53                     MinimumSize = new Size(0, ShipListPanel.LineHeight),\r
54                     TextAlign = ContentAlignment.MiddleLeft,\r
55                     Cursor = Cursors.Hand\r
56                 },\r
57                 Level = new ShipLabel\r
58                 {\r
59                     Location = new Point(116, 2),\r
60                     Size = new Size(24, height),\r
61                     TextAlign = ContentAlignment.MiddleRight\r
62                 },\r
63                 Time = new ShipLabel {Location = new Point(141, 2), AutoSize = true},\r
64                 PerHp = new ShipLabel {Location = new Point(186, 2), AutoSize = true},\r
65                 BackPanel = new Panel\r
66                 {\r
67                     Location = new Point(0, y),\r
68                     Size = new Size(ListForm.PanelWidth, ShipListPanel.LineHeight)\r
69                 }\r
70             };\r
71             _labelList.Add(labels);\r
72             labels.Arrange(_shipListPanel, CustomColors.ColumnColors.BrightFirst(i));\r
73             _shipListPanel.SetHpPercent(labels.Hp);\r
74         }\r
75 \r
76         public void SetRepairList(int i)\r
77         {\r
78             var s = _shipListPanel.GetShip(i);\r
79             if (s.Level == 1000)\r
80             {\r
81                 _shipListPanel.SetShipType(i);\r
82                 return;\r
83             }\r
84             var labels = _labelList[i];\r
85             labels.Fleet.SetFleet(s);\r
86             labels.Name.SetName(s, ShipNameWidth.RepairListFull);\r
87             labels.Hp.SetHp(s);\r
88             labels.Level.SetLevel(s);\r
89             labels.Time.SetRepairTime(s);\r
90             labels.PerHp.Text = s.RepairTimePerHp.ToString(@"mm\:ss");\r
91             labels.BackPanel.Visible = true;\r
92         }\r
93 \r
94         public void HidePanel(int i)\r
95         {\r
96             _labelList[i].BackPanel.Visible = false;\r
97         }\r
98     }\r
99 }