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.Collections;
\r
17 using System.Collections.Generic;
\r
18 using System.Drawing;
\r
20 using System.Windows.Forms;
\r
21 using KancolleSniffer.Model;
\r
23 namespace KancolleSniffer.View.MainWindow
\r
25 public class NDockPanel : Panel, IUpdateTimers
\r
27 private const int TopMargin = 3;
\r
28 private const int LeftMargin = 2;
\r
29 private const int LineHeight = 15;
\r
30 private readonly NDockLabels[] _labels = new NDockLabels[DockInfo.DockCount];
\r
31 private Label _caption;
\r
33 private class NDockLabels
\r
35 public Label Number { get; set; }
\r
36 public ShipLabel.Name Name { get; set; }
\r
37 public Label Timer { get; set; }
\r
40 public UpdateContext Context { private get; set; }
\r
44 BorderStyle = BorderStyle.FixedSingle;
\r
45 for (var i = 0; i < _labels.Length; i++)
\r
47 var y = TopMargin + i * LineHeight;
\r
48 _labels[i] = new NDockLabels
\r
52 Location = new Point(LeftMargin, y),
\r
54 Text = "第" + new[] {"一", "二", "三", "四"}[i]
\r
56 Name = new ShipLabel.Name(new Point(LeftMargin + 27, y), ShipNameWidth.NDock),
\r
57 Timer = new GrowLeftLabel
\r
59 Location = new Point(LeftMargin + 136, y - 1),
\r
61 MinimumSize = new Size(0, LineHeight),
\r
62 TextAlign = ContentAlignment.MiddleLeft,
\r
63 Cursor = Cursors.Hand
\r
67 Controls.AddRange(_labels.SelectMany(l => new Control[] {l.Number, l.Name, l.Timer}).ToArray());
\r
68 var timers = _labels.Select(l => l.Timer).ToArray();
\r
70 SetClickHandler(timers);
\r
73 public void SetClickHandler(Label caption)
\r
75 caption.Click += ClickHandler;
\r
79 private void SetCursor(IEnumerable<Control> controls)
\r
81 foreach (var control in controls)
\r
82 control.Cursor = Cursors.Hand;
\r
85 private void SetClickHandler(IEnumerable<Control> controls)
\r
87 foreach (var control in controls)
\r
88 control.Click += ClickHandler;
\r
91 private void ClickHandler(object sender, EventArgs e)
\r
93 Context.Config.ShowEndTime ^= TimerKind.NDock;
\r
98 public new void Update()
\r
100 for (var i = 0; i < _labels.Length; i++)
\r
101 _labels[i].Name.SetName(Context.Sniffer.NDock[i].Name);
\r
105 private void SetCaption()
\r
107 _caption.Text = (Context.Config.ShowEndTime & TimerKind.NDock) != 0 ? "入渠終了" : "入渠";
\r
110 public void UpdateTimers()
\r
112 var now = Context.GetStep().Now;
\r
113 var showEndTime = (Context.Config.ShowEndTime & TimerKind.NDock) != 0;
\r
114 foreach (var entry in _labels.Zip(Context.Sniffer.NDock,
\r
115 (label, ndock) => new {label = label.Timer, timer = ndock.Timer}))
\r
117 entry.label.ForeColor = entry.timer.IsFinished(now) ? CUDColors.Red : Color.Black;
\r
118 entry.label.Text = entry.timer.ToString(now, showEndTime);
\r