1 // Copyright (C) 2019 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 NDockPanel : Panel, IUpdateTimers
\r
25 private const int TopMargin = 3;
\r
26 private const int LeftMargin = 2;
\r
27 private const int LineHeight = 15;
\r
28 private readonly NDockLabels[] _labels = new NDockLabels[DockInfo.DockCount];
\r
29 private Label _caption;
\r
31 private class NDockLabels
\r
33 public Label Number { get; set; }
\r
34 public ShipLabel.Name Name { get; set; }
\r
35 public Label Timer { get; set; }
\r
38 public UpdateContext Context { private get; set; }
\r
42 BorderStyle = BorderStyle.FixedSingle;
\r
43 for (var i = 0; i < _labels.Length; i++)
\r
45 var y = TopMargin + i * LineHeight;
\r
46 _labels[i] = new NDockLabels
\r
50 Location = new Point(LeftMargin, y),
\r
52 Text = "第" + new[] {"一", "二", "三", "四"}[i]
\r
54 Name = new ShipLabel.Name(new Point(LeftMargin + 27, y), ShipNameWidth.NDock),
\r
55 Timer = new GrowLeftLabel
\r
57 Location = new Point(LeftMargin + 136, y - 1),
\r
59 MinimumSize = new Size(0, LineHeight),
\r
60 TextAlign = ContentAlignment.MiddleLeft,
\r
61 Cursor = Cursors.Hand
\r
65 Controls.AddRange(_labels.SelectMany(l => new Control[] {l.Number, l.Name, l.Timer}).ToArray());
\r
70 public void SetClickHandler(Label caption)
\r
72 caption.Click += ClickHandler;
\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 private void SetClickHandler()
\r
85 Click += ClickHandler;
\r
86 foreach (Control control in Controls)
\r
87 control.Click += ClickHandler;
\r
90 private void ClickHandler(object sender, EventArgs e)
\r
92 Context.Config.ShowEndTime ^= TimerKind.NDock;
\r
97 public new void Update()
\r
99 for (var i = 0; i < _labels.Length; i++)
\r
100 _labels[i].Name.SetName(Context.Sniffer.NDock[i].Name);
\r
104 private void SetCaption()
\r
106 _caption.Text = (Context.Config.ShowEndTime & TimerKind.NDock) != 0 ? "入渠終了" : "入渠";
\r
109 public void UpdateTimers()
\r
111 var now = Context.GetNow();
\r
112 var showEndTime = (Context.Config.ShowEndTime & TimerKind.NDock) != 0;
\r
113 foreach (var entry in _labels.Zip(Context.Sniffer.NDock,
\r
114 (label, ndock) => new {label = label.Timer, timer = ndock.Timer}))
\r
116 entry.label.ForeColor = entry.timer.IsFinished(now) ? CUDColors.Red : Color.Black;
\r
117 entry.label.Text = entry.timer.ToString(now, showEndTime);
\r