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.MainWindow
\r
23 public class MissionPanel : PanelWithToolTip, IUpdateTimers
\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
31 private Label _caption;
\r
33 private class MissionLabels
\r
35 public Label Number { get; set; }
\r
36 public Label Name { get; set; }
\r
37 public Label Params { get; set; }
\r
38 public Label Timer { get; set; }
\r
41 public UpdateContext Context { private get; set; }
\r
43 public MissionPanel()
\r
45 BorderStyle = BorderStyle.FixedSingle;
\r
46 for (var i = 0; i < Lines; i++)
\r
48 var y = TopMargin + i * LineHeight;
\r
49 _labels[i] = new MissionLabels
\r
53 Location = new Point(LeftMargin, y),
\r
55 Text = "第" + new[] {"二", "三", "四"}[i]
\r
59 Location = new Point(LeftMargin + 54, y),
\r
60 Size = new Size(161, LabelHeight)
\r
64 Location = new Point(LeftMargin + 30, y),
\r
65 Size = new Size(135, LabelHeight)
\r
67 Timer = new GrowLeftLabel()
\r
69 Location = new Point(LeftMargin + 216, y),
\r
74 Controls.AddRange(_labels.SelectMany(l => new Control[] {l.Number, l.Params, l.Timer, l.Name}).ToArray());
\r
79 public void SetClickHandler(Label caption)
\r
81 caption.Click += ClickHandler;
\r
85 private void SetCursor()
\r
87 Cursor = Cursors.Hand;
\r
88 foreach (Control control in Controls)
\r
89 control.Cursor = Cursors.Hand;
\r
92 private void SetClickHandler()
\r
94 Click += ClickHandler;
\r
95 foreach (Control control in Controls)
\r
96 control.Click += ClickHandler;
\r
99 private void ClickHandler(Object sender, EventArgs e)
\r
101 Context.Config.ShowEndTime ^= TimerKind.Mission;
\r
106 public new void Update()
\r
108 var names = Context.Sniffer.Missions.Select(mission => mission.Name).ToArray();
\r
109 for (var i = 0; i < Lines; i++)
\r
111 var fleetParams = Context.Sniffer.Fleets[i + 1].MissionParameter;
\r
112 var inPort = string.IsNullOrEmpty(names[i]);
\r
113 _labels[i].Params.Visible = inPort;
\r
114 _labels[i].Params.Text = fleetParams;
\r
115 _labels[i].Name.Text = names[i];
\r
116 ToolTip.SetToolTip(_labels[i].Name, inPort ? "" : fleetParams);
\r
121 private void SetCaption()
\r
123 _caption.Text = (Context.Config.ShowEndTime & TimerKind.Mission) != 0 ? "遠征終了" : "遠征";
\r
126 public void UpdateTimers()
\r
128 var now = Context.GetStep().Now;
\r
129 var showEndTime = (Context.Config.ShowEndTime & TimerKind.Mission) != 0;
\r
130 for (var i = 0; i < Lines; i++)
\r
132 var entry = Context.Sniffer.Missions[i];
\r
133 SetTimerColor(_labels[i].Timer, entry.Timer, now);
\r
134 _labels[i].Timer.Text = entry.Timer.ToString(now, showEndTime);
\r
138 private void SetTimerColor(Label label, AlarmTimer timer, DateTime now)
\r
140 label.ForeColor = timer.IsFinished(now) ? CUDColors.Red : Color.Black;
\r