1 // Copyright (C) 2020 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.Drawing;
\r
18 using System.Windows.Forms;
\r
19 using KancolleSniffer.Model;
\r
21 namespace KancolleSniffer.View
\r
23 public class MissionPanel : PanelWithToolTip
\r
25 private const int TopMargin = 3;
\r
26 private const int LeftMargin = 2;
\r
27 private const int LabelHeight = 12;
\r
28 private const int LineHeight = 15;
\r
29 private const int Lines = 3;
\r
30 private readonly MissionLabels[] _labels = new MissionLabels[Lines];
\r
32 private class MissionLabels
\r
34 public Label Number { get; set; }
\r
35 public Label Name { get; set; }
\r
36 public Label Params { get; set; }
\r
37 public Label Timer { get; set; }
\r
40 public MissionPanel()
\r
42 BorderStyle = BorderStyle.FixedSingle;
\r
43 for (var i = 0; i < Lines; i++)
\r
45 var y = TopMargin + i * LineHeight;
\r
46 _labels[i] = new MissionLabels
\r
50 Location = new Point(LeftMargin, y),
\r
52 Text = "第" + new[] {"二", "三", "四"}[i]
\r
56 Location = new Point(LeftMargin + 54, y),
\r
57 Size = new Size(161, LabelHeight)
\r
61 Location = new Point(LeftMargin + 30, y),
\r
62 Size = new Size(135, LabelHeight)
\r
66 Location = new Point(LeftMargin + 165, y),
\r
67 Size = new Size(51, LabelHeight),
\r
68 TextAlign = ContentAlignment.MiddleRight
\r
72 Controls.AddRange(_labels.SelectMany(l => new Control[] {l.Number, l.Params, l.Name, l.Timer}).ToArray());
\r
76 private void SetCursor()
\r
78 Cursor = Cursors.Hand;
\r
79 foreach (Control control in Controls)
\r
80 control.Cursor = Cursors.Hand;
\r
83 public void SetClickHandler(EventHandler onClick)
\r
86 foreach (Control control in Controls)
\r
87 control.Click += onClick;
\r
90 public void Update(Sniffer sniffer)
\r
92 var names = sniffer.Missions.Select(mission => mission.Name).ToArray();
\r
93 for (var i = 0; i < Lines; i++)
\r
95 var fleetParams = sniffer.Fleets[i + 1].MissionParameter;
\r
96 var inPort = string.IsNullOrEmpty(names[i]);
\r
97 _labels[i].Params.Visible = inPort;
\r
98 _labels[i].Params.Text = fleetParams;
\r
99 _labels[i].Name.Text = names[i];
\r
100 ToolTip.SetToolTip(_labels[i].Name, inPort ? "" : fleetParams);
\r
104 public void UpdateTimers(Sniffer sniffer, DateTime now, bool showEndTime)
\r
106 for (var i = 0; i < Lines; i++)
\r
108 var entry = sniffer.Missions[i];
\r
109 SetTimerColor(_labels[i].Timer, entry.Timer, now);
\r
110 _labels[i].Timer.Text = entry.Timer.ToString(now, showEndTime);
\r
114 private void SetTimerColor(Label label, AlarmTimer timer, DateTime now)
\r
116 label.ForeColor = timer.IsFinished(now) ? CUDColors.Red : Color.Black;
\r