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.ComponentModel;
\r
17 using System.Drawing;
\r
18 using System.Windows.Forms;
\r
19 using KancolleSniffer.Model;
\r
21 // ReSharper disable CoVariantArrayConversion
\r
23 namespace KancolleSniffer.View
\r
25 [DesignerCategory("Code")]
\r
26 public class AirBattleResultPanel : PanelWithToolTip
\r
28 private readonly Label _phaseName;
\r
29 private readonly Label _stage1;
\r
30 private readonly Label[][][] _resultLabels = new Label[2][][];
\r
31 private AirBattleResult.AirBattleRecord[] _resultList;
\r
32 private int _resultIndex;
\r
33 private readonly ShipLabel.Name _ciShipName;
\r
34 private readonly Label _ciKind;
\r
36 public bool ShowResultAutomatic { get; set; }
\r
38 private bool ResultRemained
\r
40 set => _phaseName.BorderStyle = value ? BorderStyle.FixedSingle : BorderStyle.None;
\r
43 public AirBattleResultPanel()
\r
53 Location = new Point(4, 4),
\r
54 Size = new Size(49, 12),
\r
55 TextAlign = ContentAlignment.TopCenter
\r
57 _stage1 = new Label {Text = "stage1", Location = new Point(8, top), AutoSize = true},
\r
58 new Label {Text = "stage2", Location = new Point(8, top + 14), AutoSize = true},
\r
59 new Label {Text = "自軍", Location = new Point(67, 6), AutoSize = true},
\r
60 new Label {Text = "敵軍", Location = new Point(122, 6), AutoSize = true},
\r
61 new Label {Text = "CI", Location = new Point(ci, 4), AutoSize = true}
\r
63 Controls.AddRange(labels);
\r
64 const int left = 53;
\r
65 const int space = 55;
\r
66 for (var stage = 0; stage < 2; stage++)
\r
68 _resultLabels[stage] = new Label[2][];
\r
69 for (var fe = 0; fe < 2; fe++)
\r
71 _resultLabels[stage][fe] = new Label[2];
\r
72 Controls.Add(_resultLabels[stage][fe][1] = new Label
\r
74 Location = new Point(left + 34 + space * fe, top + 14 * stage),
\r
75 Size = new Size(24, 12),
\r
76 TextAlign = ContentAlignment.TopLeft
\r
78 Controls.Add(new Label
\r
80 Location = new Point(left + 21 + space * fe, top + 14 * stage),
\r
84 Controls.Add(_resultLabels[stage][fe][0] = new Label
\r
86 Location = new Point(left + space * fe, top + 14 * stage),
\r
87 Size = new Size(24, 12),
\r
88 TextAlign = ContentAlignment.TopRight
\r
92 Controls.Add(_ciShipName = new ShipLabel.Name(new Point(ci, top), ShipNameWidth.CiShipName));
\r
93 Controls.Add(_ciKind = new Label
\r
95 Location = new Point(ci, top + 14),
\r
96 Size = new Size(24, 12)
\r
98 _phaseName.Click += PhaseNameOnClick;
\r
101 public void SetResult(Sniffer sniffer)
\r
103 var battleResult = sniffer.Battle.AirBattleResult;
\r
104 if (!battleResult.CheckUpdate())
\r
106 _resultList = battleResult.Result.ToArray();
\r
107 if (_resultList.Length == 0)
\r
109 ResultRemained = false;
\r
113 _resultIndex = _resultList.Length - 1;
\r
114 if (!ShowResultAutomatic)
\r
116 ResultRemained = true;
\r
121 ResultRemained = _resultList.Length > 1;
\r
125 private void PhaseNameOnClick(object sender, EventArgs eventArgs)
\r
127 if (_resultList == null || _resultList.Length == 0)
\r
130 if (_resultList.Length == 1)
\r
131 ResultRemained = false;
\r
132 _resultIndex = (_resultIndex + 1) % _resultList.Length;
\r
135 private void ShowResult()
\r
137 if (_resultIndex >= _resultList.Length)
\r
139 var result = _resultList[_resultIndex];
\r
140 _phaseName.Text = result.PhaseName;
\r
141 var color = new[] {DefaultForeColor, CUDColors.Blue, CUDColors.Green, CUDColors.Orange, CUDColors.Red};
\r
142 _stage1.ForeColor = color[result.AirControlLevel];
\r
143 var stages = new[] {result.Stage1, result.Stage2};
\r
144 for (var i = 0; i < 2; i++)
\r
146 var stage = stages[i];
\r
147 var labels = _resultLabels[i];
\r
148 labels[0][0].Text = $"{stage.FriendCount}";
\r
149 labels[0][1].Text = $"{stage.FriendCount - stage.FriendLost}";
\r
150 labels[1][0].Text = $"{stage.EnemyCount}";
\r
151 labels[1][1].Text = $"{stage.EnemyCount - stage.EnemyLost}";
\r
153 ShowAirFireResult();
\r
156 private void ShowAirFireResult()
\r
158 var result = _resultList[_resultIndex];
\r
159 if (result.AirFire == null)
\r
161 _ciShipName.Reset();
\r
163 ToolTip.SetToolTip(_ciKind, "");
\r
167 _ciShipName.SetName(result.AirFire.ShipName);
\r
168 _ciKind.Text = result.AirFire.Kind.ToString();
\r
169 ToolTip.SetToolTip(_ciKind, string.Join("\r\n", result.AirFire.Items));
\r
173 private void ClearResult()
\r
175 _phaseName.Text = "航空戦";
\r
176 _stage1.ForeColor = DefaultForeColor;
\r
177 for (var st = 0; st < 2; st++)
\r
179 for (var fe = 0; fe < 2; fe++)
\r
181 for (var ba = 0; ba < 2; ba++)
\r
183 _resultLabels[st][fe][ba].Text = "";
\r
187 _ciShipName.Reset();
\r
189 ToolTip.SetToolTip(_ciKind, "");
\r