OSDN Git Service

連合艦隊表示でも艦娘名のクリックで一覧をジャンプできるようにする
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / View / AirBattleResultPanel.cs
1 // Copyright (C) 2016 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.ComponentModel;\r
18 using System.Drawing;\r
19 using System.Windows.Forms;\r
20 using KancolleSniffer.Util;\r
21 \r
22 // ReSharper disable CoVariantArrayConversion\r
23 \r
24 namespace KancolleSniffer.View\r
25 {\r
26     public class AirBattleResult\r
27     {\r
28         public class StageResult\r
29         {\r
30             public int FriendCount { get; set; }\r
31             public int FriendLost { get; set; }\r
32             public int EnemyCount { get; set; }\r
33             public int EnemyLost { get; set; }\r
34         }\r
35 \r
36         public class AirFireResult\r
37         {\r
38             public string ShipName { get; set; }\r
39             public int Kind { get; set; }\r
40             public string[] Items { get; set; }\r
41         }\r
42 \r
43         public string PhaseName { get; set; }\r
44         public int AirControlLevel { get; set; }\r
45         public StageResult Stage1 { get; set;  }\r
46         public StageResult Stage2 { get; set;  }\r
47         public AirFireResult AirFire { get; set; }\r
48     }\r
49 \r
50     [DesignerCategory("Code")]\r
51     public class AirBattleResultPanel : Panel\r
52     {\r
53         private readonly Label _phaseName;\r
54         private readonly Label _stage1;\r
55         private readonly Label[][][] _resultLabels = new Label[2][][];\r
56         private AirBattleResult[] _resultList;\r
57         private int _resultIndex;\r
58         private readonly ShipLabel _ciShipName;\r
59         private readonly Label _ciKind;\r
60         private readonly ResizableToolTip _toolTip = new ResizableToolTip{ShowAlways = true};\r
61 \r
62         public bool ShowResultAutomatic { get; set; }\r
63 \r
64         private bool ResultRemained\r
65         {\r
66             set => _phaseName.BorderStyle = value ? BorderStyle.FixedSingle : BorderStyle.None;\r
67         }\r
68 \r
69         public AirBattleResultPanel()\r
70         {\r
71             const int top = 20;\r
72             const int ci = 168;\r
73             var labels = new[]\r
74             {\r
75                 _phaseName =\r
76                     new Label\r
77                     {\r
78                         Text = "航空戦",\r
79                         Location = new Point(4, 4),\r
80                         Size = new Size(49, 12),\r
81                         TextAlign = ContentAlignment.TopCenter\r
82                     },\r
83                 _stage1 = new Label {Text = "stage1", Location = new Point(8, top), AutoSize = true},\r
84                 new Label {Text = "stage2", Location = new Point(8, top + 14), AutoSize = true},\r
85                 new Label {Text = "自軍", Location = new Point(67, 6), AutoSize = true},\r
86                 new Label {Text = "敵軍", Location = new Point(122, 6), AutoSize = true},\r
87                 new Label {Text = "CI", Location = new Point(ci, 4), AutoSize = true}\r
88             };\r
89             Controls.AddRange(labels);\r
90             const int left = 53;\r
91             const int space = 55;\r
92             for (var stage = 0; stage < 2; stage++)\r
93             {\r
94                 _resultLabels[stage] = new Label[2][];\r
95                 for (var fe = 0; fe < 2; fe++)\r
96                 {\r
97                     _resultLabels[stage][fe] = new Label[2];\r
98                     Controls.Add(_resultLabels[stage][fe][1] = new Label\r
99                     {\r
100                         Location = new Point(left + 34 + space * fe, top + 14 * stage),\r
101                         Size = new Size(24, 12),\r
102                         TextAlign = ContentAlignment.TopLeft\r
103                     });\r
104                     Controls.Add(new Label\r
105                     {\r
106                         Location = new Point(left + 21 + space * fe, top + 14 * stage),\r
107                         Text = "→",\r
108                         AutoSize = true\r
109                     });\r
110                     Controls.Add(_resultLabels[stage][fe][0] = new Label\r
111                     {\r
112                         Location = new Point(left + space * fe, top + 14 * stage),\r
113                         Size = new Size(24, 12),\r
114                         TextAlign = ContentAlignment.TopRight\r
115                     });\r
116                 }\r
117             }\r
118             Controls.Add(_ciShipName = new ShipLabel\r
119             {\r
120                 Location = new Point(ci, top),\r
121                 Size = new Size((int)ShipNameWidth.CiShipName, 12)\r
122             });\r
123             Controls.Add(_ciKind = new Label\r
124             {\r
125                 Location = new Point(ci, top + 14),\r
126                 Size = new Size(24, 12)\r
127             });\r
128             _phaseName.Click += PhaseNameOnClick;\r
129         }\r
130 \r
131         public void SetResult(List<AirBattleResult> resultList)\r
132         {\r
133             _resultList = resultList.ToArray();\r
134             if (_resultList.Length == 0)\r
135             {\r
136                 ResultRemained = false;\r
137                 ClearResult();\r
138                 return;\r
139             }\r
140             _resultIndex = _resultList.Length - 1;\r
141             if (!ShowResultAutomatic)\r
142             {\r
143                 ResultRemained = true;\r
144                 ClearResult();\r
145                 return;\r
146             }\r
147             ShowResult();\r
148             ResultRemained = _resultList.Length > 1;\r
149             _resultIndex = 0;\r
150         }\r
151 \r
152         private void PhaseNameOnClick(object sender, EventArgs eventArgs)\r
153         {\r
154             if (_resultList == null || _resultList.Length == 0)\r
155                 return;\r
156             ShowResult();\r
157             if (_resultList.Length == 1)\r
158                 ResultRemained = false;\r
159             _resultIndex = (_resultIndex + 1) % _resultList.Length;\r
160         }\r
161 \r
162         private void ShowResult()\r
163         {\r
164             if (_resultIndex >= _resultList.Length)\r
165                 return;\r
166             var result = _resultList[_resultIndex];\r
167             _phaseName.Text = result.PhaseName;\r
168             var color = new[] {DefaultForeColor, CUDColors.Blue, CUDColors.Green, CUDColors.Orange, CUDColors.Red};\r
169             _stage1.ForeColor = color[result.AirControlLevel];\r
170             var stages = new[] {result.Stage1, result.Stage2};\r
171             for (var i = 0; i < 2; i++)\r
172             {\r
173                 var stage = stages[i];\r
174                 var labels = _resultLabels[i];\r
175                 labels[0][0].Text = $"{stage.FriendCount}";\r
176                 labels[0][1].Text = $"{stage.FriendCount - stage.FriendLost}";\r
177                 labels[1][0].Text = $"{stage.EnemyCount}";\r
178                 labels[1][1].Text = $"{stage.EnemyCount - stage.EnemyLost}";\r
179             }\r
180             ShowAirFireResult();\r
181         }\r
182 \r
183         private void ShowAirFireResult()\r
184         {\r
185             var result = _resultList[_resultIndex];\r
186             if (result.AirFire == null)\r
187             {\r
188                 _ciShipName.SetName(null);\r
189                 _ciKind.Text = "";\r
190                 _toolTip.SetToolTip(_ciKind, "");\r
191             }\r
192             else\r
193             {\r
194                 _ciShipName.SetName(result.AirFire.ShipName, ShipNameWidth.CiShipName);\r
195                 _ciKind.Text = result.AirFire.Kind.ToString();\r
196                 _toolTip.SetToolTip(_ciKind, string.Join("\r\n", result.AirFire.Items));\r
197             }\r
198         }\r
199 \r
200         private void ClearResult()\r
201         {\r
202             _phaseName.Text = "航空戦";\r
203             _stage1.ForeColor = DefaultForeColor;\r
204             for (var st = 0; st < 2; st++)\r
205             {\r
206                 for (var fe = 0; fe < 2; fe++)\r
207                 {\r
208                     for (var ba = 0; ba < 2; ba++)\r
209                     {\r
210                         _resultLabels[st][fe][ba].Text = "";\r
211                     }\r
212                 }\r
213             }\r
214             _ciShipName.SetName(null);\r
215             _ciKind.Text = "";\r
216             _toolTip.SetToolTip(_ciKind, "");\r
217         }\r
218 \r
219         protected override void ScaleControl(SizeF factor, BoundsSpecified specified)\r
220         {\r
221             base.ScaleControl(factor, specified);\r
222             if (factor.Height > 1)\r
223                 _toolTip.Font = new Font(_toolTip.Font.FontFamily, _toolTip.Font.Size * factor.Height);\r
224         }\r
225     }\r
226 }