+// Copyright (C) 2019 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+\r
+using System;\r
+using System.Drawing;\r
+using System.Linq;\r
+using System.Windows.Forms;\r
+using KancolleSniffer.Model;\r
+\r
+namespace KancolleSniffer.View\r
+{\r
+ public class NDockPanel : Panel\r
+ {\r
+ private const int TopMargin = 3;\r
+ private const int LeftMargin = 2;\r
+ private const int LineHeight = 15;\r
+ private readonly NDockLabels[] _labels = new NDockLabels[DockInfo.DockCount];\r
+\r
+ private class NDockLabels\r
+ {\r
+ public Label Number { get; set; }\r
+ public ShipLabel.Name Name { get; set; }\r
+ public Label Timer { get; set; }\r
+ }\r
+\r
+ public NDockPanel()\r
+ {\r
+ BorderStyle = BorderStyle.FixedSingle;\r
+ for (var i = 0; i < _labels.Length; i++)\r
+ {\r
+ var y = TopMargin + i * LineHeight;\r
+ _labels[i] = new NDockLabels\r
+ {\r
+ Number = new Label\r
+ {\r
+ Location = new Point(LeftMargin, y),\r
+ AutoSize = true,\r
+ Text = "第" + new[] {"一", "二", "三", "四"}[i]\r
+ },\r
+ Name = new ShipLabel.Name(new Point(LeftMargin + 27, y), ShipNameWidth.NDock),\r
+ Timer = new GrowLeftLabel\r
+ {\r
+ Location = new Point(LeftMargin + 136, y - 1),\r
+ GrowLeft = true,\r
+ MinimumSize = new Size(0, LineHeight),\r
+ TextAlign = ContentAlignment.MiddleLeft,\r
+ Cursor = Cursors.Hand\r
+ }\r
+ };\r
+ }\r
+ Controls.AddRange(_labels.SelectMany(l => new Control[] {l.Number, l.Name, l.Timer}).ToArray());\r
+ SetCursor();\r
+ }\r
+\r
+ private void SetCursor()\r
+ {\r
+ Cursor = Cursors.Hand;\r
+ foreach (Control control in Controls)\r
+ control.Cursor = Cursors.Hand;\r
+ }\r
+\r
+ public void SetClickHandler(EventHandler onClick)\r
+ {\r
+ Click += onClick;\r
+ foreach (Control control in Controls)\r
+ control.Click += onClick;\r
+ }\r
+\r
+ public void SetName(NameAndTimer[] ndock)\r
+ {\r
+ for (var i = 0; i < _labels.Length; i++)\r
+ _labels[i].Name.SetName(ndock[i].Name);\r
+ }\r
+\r
+ public void UpdateTimers(Sniffer sniffer, DateTime now, bool showEndTime)\r
+ {\r
+ foreach (var entry in _labels.Zip(sniffer.NDock,\r
+ (label, ndock) => new {label = label.Timer, timer = ndock.Timer}))\r
+ {\r
+ entry.label.ForeColor = entry.timer.IsFinished(now) ? CUDColors.Red : Color.Black;\r
+ entry.label.Text = entry.timer.ToString(now, showEndTime);\r
+ }\r
+ }\r
+ }\r
+}
\ No newline at end of file