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
30 private class NDockLabels
\r
32 public Label Number { get; set; }
\r
33 public ShipLabel.Name Name { get; set; }
\r
34 public Label Timer { get; set; }
\r
37 public UpdateContext Context { private get; set; }
\r
41 BorderStyle = BorderStyle.FixedSingle;
\r
42 for (var i = 0; i < _labels.Length; i++)
\r
44 var y = TopMargin + i * LineHeight;
\r
45 _labels[i] = new NDockLabels
\r
49 Location = new Point(LeftMargin, y),
\r
51 Text = "第" + new[] {"一", "二", "三", "四"}[i]
\r
53 Name = new ShipLabel.Name(new Point(LeftMargin + 27, y), ShipNameWidth.NDock),
\r
54 Timer = new GrowLeftLabel
\r
56 Location = new Point(LeftMargin + 136, y - 1),
\r
58 MinimumSize = new Size(0, LineHeight),
\r
59 TextAlign = ContentAlignment.MiddleLeft,
\r
60 Cursor = Cursors.Hand
\r
64 Controls.AddRange(_labels.SelectMany(l => new Control[] {l.Number, l.Name, l.Timer}).ToArray());
\r
68 private void SetCursor()
\r
70 Cursor = Cursors.Hand;
\r
71 foreach (Control control in Controls)
\r
72 control.Cursor = Cursors.Hand;
\r
75 public void SetClickHandler(EventHandler onClick)
\r
78 foreach (Control control in Controls)
\r
79 control.Click += onClick;
\r
82 public new void Update()
\r
84 for (var i = 0; i < _labels.Length; i++)
\r
85 _labels[i].Name.SetName(Context.Sniffer.NDock[i].Name);
\r
88 public void UpdateTimers()
\r
90 var now = Context.GetNow();
\r
91 var showEndTime = (Context.Config.ShowEndTime & TimerKind.NDock) != 0;
\r
92 foreach (var entry in _labels.Zip(Context.Sniffer.NDock,
\r
93 (label, ndock) => new {label = label.Timer, timer = ndock.Timer}))
\r
95 entry.label.ForeColor = entry.timer.IsFinished(now) ? CUDColors.Red : Color.Black;
\r
96 entry.label.Text = entry.timer.ToString(now, showEndTime);
\r