1 // Copyright (C) 2016 Kazuhiro Fujieda <fujieda@users.osdn.me>
\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
7 // http://www.apache.org/licenses/LICENSE-2.0
\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
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
22 // ReSharper disable CoVariantArrayConversion
\r
24 namespace KancolleSniffer.View
\r
26 public class AirBattleResult
\r
28 public class StageResult
\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
36 public class AirFireResult
\r
38 public string ShipName { get; set; }
\r
39 public int Kind { get; set; }
\r
40 public string[] Items { get; set; }
\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
50 [DesignerCategory("Code")]
\r
51 public class AirBattleResultPanel : Panel
\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
62 public bool ShowResultAutomatic { get; set; }
\r
64 private bool ResultRemained
\r
66 set => _phaseName.BorderStyle = value ? BorderStyle.FixedSingle : BorderStyle.None;
\r
69 public AirBattleResultPanel()
\r
79 Location = new Point(4, 4),
\r
80 Size = new Size(49, 12),
\r
81 TextAlign = ContentAlignment.TopCenter
\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
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
94 _resultLabels[stage] = new Label[2][];
\r
95 for (var fe = 0; fe < 2; fe++)
\r
97 _resultLabels[stage][fe] = new Label[2];
\r
98 Controls.Add(_resultLabels[stage][fe][1] = new Label
\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
104 Controls.Add(new Label
\r
106 Location = new Point(left + 21 + space * fe, top + 14 * stage),
\r
110 Controls.Add(_resultLabels[stage][fe][0] = new Label
\r
112 Location = new Point(left + space * fe, top + 14 * stage),
\r
113 Size = new Size(24, 12),
\r
114 TextAlign = ContentAlignment.TopRight
\r
118 Controls.Add(_ciShipName = new ShipLabel
\r
120 Location = new Point(ci, top),
\r
121 Size = new Size((int)ShipNameWidth.CiShipName, 12)
\r
123 Controls.Add(_ciKind = new Label
\r
125 Location = new Point(ci, top + 14),
\r
126 Size = new Size(24, 12)
\r
128 _phaseName.Click += PhaseNameOnClick;
\r
131 public void SetResult(List<AirBattleResult> resultList)
\r
133 _resultList = resultList.ToArray();
\r
134 if (_resultList.Length == 0)
\r
136 ResultRemained = false;
\r
140 _resultIndex = _resultList.Length - 1;
\r
141 if (!ShowResultAutomatic)
\r
143 ResultRemained = true;
\r
148 ResultRemained = _resultList.Length > 1;
\r
152 private void PhaseNameOnClick(object sender, EventArgs eventArgs)
\r
154 if (_resultList == null || _resultList.Length == 0)
\r
157 if (_resultList.Length == 1)
\r
158 ResultRemained = false;
\r
159 _resultIndex = (_resultIndex + 1) % _resultList.Length;
\r
162 private void ShowResult()
\r
164 if (_resultIndex >= _resultList.Length)
\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
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
180 ShowAirFireResult();
\r
183 private void ShowAirFireResult()
\r
185 var result = _resultList[_resultIndex];
\r
186 if (result.AirFire == null)
\r
188 _ciShipName.SetName(null);
\r
190 _toolTip.SetToolTip(_ciKind, "");
\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
200 private void ClearResult()
\r
202 _phaseName.Text = "航空戦";
\r
203 _stage1.ForeColor = DefaultForeColor;
\r
204 for (var st = 0; st < 2; st++)
\r
206 for (var fe = 0; fe < 2; fe++)
\r
208 for (var ba = 0; ba < 2; ba++)
\r
210 _resultLabels[st][fe][ba].Text = "";
\r
214 _ciShipName.SetName(null);
\r
216 _toolTip.SetToolTip(_ciKind, "");
\r
219 protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
\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