OSDN Git Service

基地空襲戦の制空値がメインウィンドウに表示されないのを直す
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / View / FleetPanel.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.View\r
21 {\r
22     public class FleetPanel : PanelWithToolTip\r
23     {\r
24         private const int LineHeight = 14;\r
25         private const int LabelHeight = 12;\r
26         private FleetSpec.Record[] _spec = new FleetSpec.Record[0];\r
27         private readonly List<FleetLabels> _labelList = new List<FleetLabels>();\r
28 \r
29         public FleetPanel()\r
30         {\r
31             ToolTip.AutoPopDelay = 10000;\r
32         }\r
33 \r
34         public void Update(Sniffer sniffer)\r
35         {\r
36             _spec = FleetSpec.Create(sniffer);\r
37             SuspendLayout();\r
38             CreateLabels();\r
39             SetRecords();\r
40             ResumeLayout();\r
41         }\r
42 \r
43         private void CreateLabels()\r
44         {\r
45             for (var i = _labelList.Count; i < _spec.Length; i++)\r
46                 CreateLabels(i);\r
47         }\r
48 \r
49         private class FleetLabels : ControlsArranger\r
50         {\r
51             public Label Fleet { get; set; }\r
52             public ShipLabel.Name Name { get; set; }\r
53             public Label Equip { get; set; }\r
54             public Label EquipColor { get; set; }\r
55             public Label Spec { get; set; }\r
56 \r
57             public override Control[] Controls => new Control[] {Fleet, Name, Equip, EquipColor, Spec};\r
58         }\r
59 \r
60         private void CreateLabels(int i)\r
61         {\r
62             var y = 1 + LineHeight * i;\r
63             var labels = new FleetLabels\r
64             {\r
65                 Fleet = new Label {Location = new Point(1, 2), AutoSize = true},\r
66                 Name = new ShipLabel.Name(new Point(10, 2), ShipNameWidth.Max),\r
67                 Equip = new Label {Location = new Point(38, 2), AutoSize = true},\r
68                 EquipColor = new Label {Location = new Point(35, 2), Size = new Size(4, LabelHeight - 2)},\r
69                 Spec = new GrowLeftLabel {Location = new Point(217, 2), GrowLeft = true},\r
70                 BackPanel = new Panel\r
71                 {\r
72                     Location = new Point(0, y),\r
73                     Size = new Size(ListForm.PanelWidth, LineHeight),\r
74                     BackColor = CustomColors.ColumnColors.BrightFirst(i)\r
75                 }\r
76             };\r
77             _labelList.Add(labels);\r
78             labels.Arrange(this, CustomColors.ColumnColors.BrightFirst(i));\r
79             labels.Move(AutoScrollPosition);\r
80         }\r
81 \r
82         private void SetRecords()\r
83         {\r
84             for (var i = 0; i < _spec.Length; i++)\r
85                 SetRecord(i);\r
86             for (var i = _spec.Length; i < _labelList.Count; i++)\r
87                 _labelList[i].BackPanel.Visible = false;\r
88         }\r
89 \r
90         private void SetRecord(int i)\r
91         {\r
92             var e = _spec[i];\r
93             var labels = _labelList[i];\r
94             labels.Fleet.Text = e.Fleet;\r
95             labels.Name.SetName(e.Ship);\r
96             if (e.Ship2 != "")\r
97                 ToolTip.SetToolTip(labels.Name, e.Ship2);\r
98             labels.Equip.Text = e.Equip;\r
99             labels.EquipColor.Visible = e.Equip != "";\r
100             labels.EquipColor.BackColor = e.Color;\r
101             labels.Spec.Text = e.Spec;\r
102             if (e.Fleet != "" && e.Fleet2 != "")\r
103                 ToolTip.SetToolTip(labels.Fleet, e.Fleet2);\r
104             ToolTip.SetToolTip(labels.Equip, e.AircraftSpec != "" ? e.AircraftSpec : "");\r
105             ToolTip.SetToolTip(labels.Spec, e.Spec2 != "" ? e.Spec2 : "");\r
106             labels.BackPanel.Visible = true;\r
107         }\r
108 \r
109         public void ShowShip(int id)\r
110         {\r
111             var i = Array.FindIndex(_spec, e => e.Id == id);\r
112             if (i == -1)\r
113                 return;\r
114             var y = Scaler.ScaleHeight(LineHeight * i);\r
115             AutoScrollPosition = new Point(0, y);\r
116         }\r
117 \r
118         public void ShowFleet(string fn)\r
119         {\r
120             var i = Array.FindIndex(_spec, e => e.Fleet.StartsWith(fn));\r
121             if (i == -1)\r
122                 return;\r
123             var y = Scaler.ScaleHeight(LineHeight * i);\r
124             AutoScrollPosition = new Point(0, y);\r
125         }\r
126     }\r
127 }