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 public class AirBattleResult
\r
27 public class StageResult
\r
29 public int FriendCount { get; set; }
\r
30 public int FriendLost { get; set; }
\r
31 public int EnemyCount { get; set; }
\r
32 public int EnemyLost { get; set; }
\r
35 public class AirFireResult
\r
37 public string ShipName { get; set; }
\r
38 public int Kind { get; set; }
\r
39 public string[] Items { get; set; }
\r
42 public string PhaseName { get; set; }
\r
43 public int AirControlLevel { get; set; }
\r
44 public StageResult Stage1 { get; set; }
\r
45 public StageResult Stage2 { get; set; }
\r
46 public AirFireResult AirFire { get; set; }
\r
49 [DesignerCategory("Code")]
\r
50 public class AirBattleResultPanel : PanelWithToolTip
\r
52 private readonly Label _phaseName;
\r
53 private readonly Label _stage1;
\r
54 private readonly Label[][][] _resultLabels = new Label[2][][];
\r
55 private AirBattleResult[] _resultList;
\r
56 private int _resultIndex;
\r
57 private readonly ShipLabel _ciShipName;
\r
58 private readonly Label _ciKind;
\r
60 public bool ShowResultAutomatic { get; set; }
\r
62 private bool ResultRemained
\r
64 set => _phaseName.BorderStyle = value ? BorderStyle.FixedSingle : BorderStyle.None;
\r
67 public AirBattleResultPanel()
\r
77 Location = new Point(4, 4),
\r
78 Size = new Size(49, 12),
\r
79 TextAlign = ContentAlignment.TopCenter
\r
81 _stage1 = new Label {Text = "stage1", Location = new Point(8, top), AutoSize = true},
\r
82 new Label {Text = "stage2", Location = new Point(8, top + 14), AutoSize = true},
\r
83 new Label {Text = "自軍", Location = new Point(67, 6), AutoSize = true},
\r
84 new Label {Text = "敵軍", Location = new Point(122, 6), AutoSize = true},
\r
85 new Label {Text = "CI", Location = new Point(ci, 4), AutoSize = true}
\r
87 Controls.AddRange(labels);
\r
88 const int left = 53;
\r
89 const int space = 55;
\r
90 for (var stage = 0; stage < 2; stage++)
\r
92 _resultLabels[stage] = new Label[2][];
\r
93 for (var fe = 0; fe < 2; fe++)
\r
95 _resultLabels[stage][fe] = new Label[2];
\r
96 Controls.Add(_resultLabels[stage][fe][1] = new Label
\r
98 Location = new Point(left + 34 + space * fe, top + 14 * stage),
\r
99 Size = new Size(24, 12),
\r
100 TextAlign = ContentAlignment.TopLeft
\r
102 Controls.Add(new Label
\r
104 Location = new Point(left + 21 + space * fe, top + 14 * stage),
\r
108 Controls.Add(_resultLabels[stage][fe][0] = new Label
\r
110 Location = new Point(left + space * fe, top + 14 * stage),
\r
111 Size = new Size(24, 12),
\r
112 TextAlign = ContentAlignment.TopRight
\r
116 Controls.Add(_ciShipName = new ShipLabel
\r
118 Location = new Point(ci, top),
\r
119 Size = new Size((int)ShipNameWidth.CiShipName, 12)
\r
121 Controls.Add(_ciKind = new Label
\r
123 Location = new Point(ci, top + 14),
\r
124 Size = new Size(24, 12)
\r
126 _phaseName.Click += PhaseNameOnClick;
\r
129 public void SetResult(Sniffer sniffer)
\r
131 var state = sniffer.Battle.BattleState;
\r
132 if (state != BattleState.Day && state != BattleState.SpNight)
\r
134 _resultList = sniffer.Battle.AirBattleResults.ToArray();
\r
135 if (_resultList.Length == 0)
\r
137 ResultRemained = false;
\r
141 _resultIndex = _resultList.Length - 1;
\r
142 if (!ShowResultAutomatic)
\r
144 ResultRemained = true;
\r
149 ResultRemained = _resultList.Length > 1;
\r
153 private void PhaseNameOnClick(object sender, EventArgs eventArgs)
\r
155 if (_resultList == null || _resultList.Length == 0)
\r
158 if (_resultList.Length == 1)
\r
159 ResultRemained = false;
\r
160 _resultIndex = (_resultIndex + 1) % _resultList.Length;
\r
163 private void ShowResult()
\r
165 if (_resultIndex >= _resultList.Length)
\r
167 var result = _resultList[_resultIndex];
\r
168 _phaseName.Text = result.PhaseName;
\r
169 var color = new[] {DefaultForeColor, CUDColors.Blue, CUDColors.Green, CUDColors.Orange, CUDColors.Red};
\r
170 _stage1.ForeColor = color[result.AirControlLevel];
\r
171 var stages = new[] {result.Stage1, result.Stage2};
\r
172 for (var i = 0; i < 2; i++)
\r
174 var stage = stages[i];
\r
175 var labels = _resultLabels[i];
\r
176 labels[0][0].Text = $"{stage.FriendCount}";
\r
177 labels[0][1].Text = $"{stage.FriendCount - stage.FriendLost}";
\r
178 labels[1][0].Text = $"{stage.EnemyCount}";
\r
179 labels[1][1].Text = $"{stage.EnemyCount - stage.EnemyLost}";
\r
181 ShowAirFireResult();
\r
184 private void ShowAirFireResult()
\r
186 var result = _resultList[_resultIndex];
\r
187 if (result.AirFire == null)
\r
189 _ciShipName.SetName(null);
\r
191 ToolTip.SetToolTip(_ciKind, "");
\r
195 _ciShipName.SetName(result.AirFire.ShipName, ShipNameWidth.CiShipName);
\r
196 _ciKind.Text = result.AirFire.Kind.ToString();
\r
197 ToolTip.SetToolTip(_ciKind, string.Join("\r\n", result.AirFire.Items));
\r
201 private void ClearResult()
\r
203 _phaseName.Text = "航空戦";
\r
204 _stage1.ForeColor = DefaultForeColor;
\r
205 for (var st = 0; st < 2; st++)
\r
207 for (var fe = 0; fe < 2; fe++)
\r
209 for (var ba = 0; ba < 2; ba++)
\r
211 _resultLabels[st][fe][ba].Text = "";
\r
215 _ciShipName.SetName(null);
\r
217 ToolTip.SetToolTip(_ciKind, "");
\r