2 using System.Drawing;
\r
4 using System.Windows.Forms;
\r
5 using KancolleSniffer.Model;
\r
7 namespace KancolleSniffer.View.MainWindow
\r
9 public class ShipInfoPanel : PanelWithToolTip, IUpdateTimers
\r
11 private readonly BattleInfoPanel _battleInfo = new BattleInfoPanel
\r
13 Location = new Point(59, 116),
\r
14 Size = new Size(157, 14),
\r
18 private readonly FighterPower _fighterPower;
\r
20 private readonly Label _presetAkashiTimer = new Label
\r
22 Location = new Point(2, 3),
\r
23 Size = new Size(32, 12),
\r
24 BackColor = CustomColors.ColumnColors.Bright
\r
27 public LinkLabel Guide { get; } = new LinkLabel
\r
30 Font = new Font("MS UI Gothic", 9.75F, FontStyle.Regular, GraphicsUnit.Point, 128),
\r
31 LinkArea = new LinkArea(0, 0),
\r
32 Location = new Point(31, 51),
\r
33 Text = "右クリックでメニューが出ます。"
\r
36 private readonly Label _lineOfSight = new Label
\r
38 Location = new Point(85, 117),
\r
39 Size = new Size(38, 12),
\r
41 TextAlign = ContentAlignment.MiddleRight
\r
44 private readonly Label _lineOfSightCaption = new Label
\r
47 Location = new Point(59, 117),
\r
51 private readonly Label _condTimerCaption = new Label
\r
53 Location = new Point(128, 117),
\r
54 Size = new Size(60, 12)
\r
57 private readonly Label _condTimer = new Label
\r
60 Location = new Point(186, 117)
\r
63 private readonly ShipListPanels _shipPanels;
\r
65 private UpdateContext _context;
\r
67 public UpdateContext Context
\r
70 set => _battleInfo.Context = _fighterPower.Context = _context = value;
\r
73 public int CurrentFleet { get; set; }
\r
75 public bool CombinedFleet { get; set; }
\r
77 public Action<int> ShowShipOnList { get; set; }
\r
79 public ShipInfoPanel()
\r
81 Controls.AddRange(new Control[] {Guide, _presetAkashiTimer});
\r
82 BorderStyle = BorderStyle.FixedSingle;
\r
83 _shipPanels = new ShipListPanels(this, ShipClickHandler);
\r
84 Controls.AddRange(new Control[]
\r
87 _lineOfSight, _lineOfSightCaption, _condTimer, _condTimerCaption
\r
89 _fighterPower = new FighterPower(this);
\r
92 private void ShipClickHandler(object sender, EventArgs e)
\r
94 var idx = (int)((Control)sender).Tag;
\r
95 var ship = (CombinedFleet
\r
96 ? Context.Sniffer.Fleets[0].Ships.Concat(Context.Sniffer.Fleets[1].Ships)
\r
97 : Context.Sniffer.Fleets[CurrentFleet].Ships).ElementAt(idx);
\r
99 ShowShipOnList(ship.Id);
\r
102 public void ToggleHpPercent()
\r
104 _shipPanels.ToggleHpPercent();
\r
107 public bool ShowHpInPercent => _shipPanels.ShowHpInPercent;
\r
109 private bool _inSortie;
\r
110 private bool _prevCombined;
\r
112 public void ChangeCurrentFleet()
\r
114 var inSortie = Context.Sniffer.InSortie;
\r
117 _inSortie = inSortie != -1;
\r
120 if (inSortie == -1)
\r
123 if (Context.Sniffer.IsCombinedFleet && !_prevCombined)
\r
125 CombinedFleet = true;
\r
128 _prevCombined = Context.Sniffer.IsCombinedFleet;
\r
133 if (inSortie == 10)
\r
135 CombinedFleet = true;
\r
140 CombinedFleet = false;
\r
141 CurrentFleet = inSortie;
\r
146 public new void Update()
\r
148 var ships = Context.Sniffer.Fleets[CurrentFleet].ActualShips;
\r
149 _shipPanels.SetShipLabels(ships);
\r
150 ShowCombinedFleet();
\r
151 _presetAkashiTimer.Visible = Context.Config.UsePresetAkashi;
\r
152 UpdateAkashiTimer();
\r
153 _fighterPower.UpdateFighterPower();
\r
155 UpdateCondTimers();
\r
158 private void ShowCombinedFleet()
\r
160 if (!Context.Sniffer.IsCombinedFleet)
\r
161 CombinedFleet = false;
\r
164 _shipPanels.SetCombinedShipLabels(Context.Sniffer.Fleets[0].ActualShips,
\r
165 Context.Sniffer.Fleets[1].ActualShips);
\r
169 private void UpdateLoS()
\r
171 var fleet = Context.Sniffer.Fleets[CurrentFleet];
\r
172 _lineOfSight.Text = RoundDown(fleet.GetLineOfSights(1)).ToString("F1");
\r
173 var text = $"係数2: {RoundDown(fleet.GetLineOfSights(2)):F1}\r\n" +
\r
174 $"係数3: {RoundDown(fleet.GetLineOfSights(3)):F1}\r\n" +
\r
175 $"係数4: {RoundDown(fleet.GetLineOfSights(4)):F1}";
\r
176 ToolTip.SetToolTip(_lineOfSight, text);
\r
177 ToolTip.SetToolTip(_lineOfSightCaption, text);
\r
180 private double RoundDown(double number)
\r
182 return Math.Floor(number * 10) / 10.0;
\r
185 public void UpdateBattleInfo()
\r
188 if (Context.Sniffer.Battle.BattleState == BattleState.None)
\r
190 _battleInfo.Update();
\r
191 _fighterPower.UpdateBattleFighterPower();
\r
194 private void ResetBattleInfo()
\r
196 _battleInfo.Reset();
\r
197 _fighterPower.Reset();
\r
200 private void UpdateCondTimers()
\r
205 var timer1 = Context.Sniffer.GetConditionTimer(0);
\r
206 var timer2 = Context.Sniffer.GetConditionTimer(1);
\r
207 timer = timer2 > timer1 ? timer2 : timer1;
\r
211 timer = Context.Sniffer.GetConditionTimer(CurrentFleet);
\r
213 if (timer == DateTime.MinValue)
\r
215 _condTimerCaption.Text = "";
\r
216 _condTimer.Text = "";
\r
219 var span = TimeSpan.FromSeconds(Math.Ceiling((timer - Context.GetStep().Now).TotalSeconds));
\r
220 if (span >= TimeSpan.FromMinutes(9) && Context.Config.NotifyConditions.Contains(40))
\r
222 _condTimerCaption.Text = "cond40まで";
\r
223 _condTimer.Text = (span - TimeSpan.FromMinutes(9)).ToString(@"mm\:ss");
\r
224 _condTimer.ForeColor = DefaultForeColor;
\r
228 _condTimerCaption.Text = "cond49まで";
\r
229 _condTimer.Text = (span >= TimeSpan.Zero ? span : TimeSpan.Zero).ToString(@"mm\:ss");
\r
230 _condTimer.ForeColor = span <= TimeSpan.Zero ? CUDColors.Red : DefaultForeColor;
\r
234 public Label AkashiRepairTimer { get; set; }
\r
236 public void UpdateTimers()
\r
238 UpdateCondTimers();
\r
239 UpdateAkashiTimer();
\r
240 UpdatePresetAkashiTimer();
\r
243 private void UpdateAkashiTimer()
\r
245 if (Context.Config.UsePresetAkashi)
\r
246 UpdatePresetAkashiTimer();
\r
247 _shipPanels.SetAkashiTimer(Context.Sniffer.Fleets[CurrentFleet].ActualShips,
\r
248 Context.Sniffer.AkashiTimer.GetTimers(CurrentFleet, Context.GetStep().Now));
\r
251 private void UpdatePresetAkashiTimer()
\r
253 var now = Context.GetStep().Now;
\r
254 var akashi = Context.Sniffer.AkashiTimer;
\r
255 var span = akashi.GetPresetDeckTimer(now);
\r
256 var color = span == TimeSpan.Zero && akashi.CheckPresetRepairing() ? CUDColors.Red : DefaultForeColor;
\r
257 var text = span == TimeSpan.MinValue ? "" : span.ToString(@"mm\:ss");
\r
258 AkashiRepairTimer.ForeColor = color;
\r
259 AkashiRepairTimer.Text = text;
\r
260 if (akashi.CheckPresetRepairing() && !akashi.CheckRepairing(CurrentFleet, now))
\r
262 _presetAkashiTimer.ForeColor = color;
\r
263 _presetAkashiTimer.Text = text;
\r
267 _presetAkashiTimer.ForeColor = DefaultForeColor;
\r
268 _presetAkashiTimer.Text = "";
\r