OSDN Git Service

PresetColorを廃止する
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / View / ShipListPanel / ShipListLabels.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.Windows.Forms;\r
18 \r
19 namespace KancolleSniffer.View.ShipListPanel\r
20 {\r
21     public class ShipListLabels\r
22     {\r
23         private readonly ShipListPanel _shipListPanel;\r
24         private readonly List<ShipLabel[]> _labelList = new List<ShipLabel[]>();\r
25         private readonly List<Panel> _panelList = new List<Panel>();\r
26 \r
27         public ShipListLabels(ShipListPanel shipListPanel)\r
28         {\r
29             _shipListPanel = shipListPanel;\r
30         }\r
31 \r
32         public void CreateShipLabels(int i)\r
33         {\r
34             var y = ShipListPanel.LineHeight * i + 1;\r
35             const int height = ShipListPanel.LabelHeight;\r
36             var panel = new Panel\r
37             {\r
38                 Location = new Point(0, y),\r
39                 Size = new Size(ListForm.PanelWidth, ShipListPanel.LineHeight),\r
40                 BackColor = ShipLabel.ColumnColors[(i + 1) % 2]\r
41             };\r
42             Scaler.Scale(panel);\r
43             var labels = new[]\r
44             {\r
45                 new ShipLabel\r
46                 {\r
47                     Location = new Point(126, 0),\r
48                     AutoSize = true,\r
49                     AnchorRight = true,\r
50                     MinimumSize = new Size(0, ShipListPanel.LineHeight),\r
51                     TextAlign = ContentAlignment.MiddleLeft,\r
52                     Cursor = Cursors.Hand\r
53                 },\r
54                 new ShipLabel\r
55                 {\r
56                     Location = new Point(128, 0),\r
57                     Size = new Size(24, ShipListPanel.LineHeight),\r
58                     TextAlign = ContentAlignment.MiddleRight\r
59                 },\r
60                 new ShipLabel\r
61                 {\r
62                     Location = new Point(154, 2),\r
63                     Size = new Size(24, height),\r
64                     TextAlign = ContentAlignment.MiddleRight\r
65                 },\r
66                 new ShipLabel\r
67                 {\r
68                     Location = new Point(175, 2),\r
69                     Size = new Size(42, height),\r
70                     TextAlign = ContentAlignment.MiddleRight\r
71                 },\r
72                 new ShipLabel {Location = new Point(10, 2), AutoSize = true},\r
73                 new ShipLabel {Location = new Point(1, 2), AutoSize = true}\r
74             };\r
75             _labelList.Add(labels);\r
76             _panelList.Add(panel);\r
77             // ReSharper disable once CoVariantArrayConversion\r
78             panel.Controls.AddRange(labels);\r
79             _shipListPanel.Controls.Add(panel);\r
80             var unused = panel.Handle; // create handle\r
81             foreach (var label in labels)\r
82             {\r
83                 Scaler.Scale(label);\r
84                 label.BackColor = ShipLabel.ColumnColors[(i + 1) % 2];\r
85             }\r
86             _shipListPanel.SetHpPercent(labels[0]);\r
87         }\r
88 \r
89         public void SetShipStatus(int i)\r
90         {\r
91             var s = _shipListPanel.GetShip(i);\r
92             var labels = _labelList[i];\r
93             if (s.Level == 1000) // 艦種の表示\r
94             {\r
95                 SetShipType(i);\r
96                 return;\r
97             }\r
98             labels[0].SetHp(s);\r
99             labels[1].SetCond(s);\r
100             labels[2].SetLevel(s);\r
101             labels[3].SetExpToNext(s);\r
102             labels[4].SetName(s, ShipNameWidth.ShipList);\r
103             labels[5].SetFleet(s);\r
104             _panelList[i].Visible = true;\r
105         }\r
106 \r
107         public void SetShipType(int i)\r
108         {\r
109             var s = _shipListPanel.GetShip(i);\r
110             var labels = _labelList[i];\r
111             labels[0].SetHp(null);\r
112             labels[1].SetCond(null);\r
113             labels[2].SetLevel(null);\r
114             labels[3].SetExpToNext(null);\r
115             labels[4].SetName(null);\r
116             labels[5].SetFleet(null);\r
117             labels[5].Text = s.Name;\r
118             _panelList[i].Visible = true;\r
119         }\r
120 \r
121         public void HidePanel(int i)\r
122         {\r
123             _panelList[i].Visible = false;\r
124         }\r
125     }\r
126 }