1 // Copyright (C) 2017 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
20 using static System.Math;
\r
22 // ReSharper disable CoVariantArrayConversion
\r
24 namespace KancolleSniffer.View.MainWindow
\r
26 public class RepairListPanel : Panel
\r
28 private const int PanelPadding = 5;
\r
29 private const int LineHeight = 15;
\r
30 private RepairLabels[] _repairLabels;
\r
31 private ShipStatus[] _repairList = new ShipStatus[0];
\r
32 private ListScroller _listScroller;
\r
34 private class RepairLabels : ShipLabels
\r
36 public ShipLabel.RepairTime Time { private get; set; }
\r
37 public ShipLabel.Hp Damage { get; set; }
\r
39 protected override Control[] AddedControls => new Control[] {Time, Damage};
\r
41 public override void Set(ShipStatus status)
\r
47 public override void Reset()
\r
55 public void CreateLabels(EventHandler onClick)
\r
57 _repairLabels = new RepairLabels[Lines];
\r
59 for (var i = 0; i < _repairLabels.Length; i++)
\r
61 var y = PanelPadding + 1 + i * LineHeight;
\r
62 const int height = 12;
\r
63 _repairLabels[i] = new RepairLabels
\r
65 Fleet = new ShipLabel.Fleet(new Point(0, y)),
\r
66 Name = new ShipLabel.Name(new Point(9, y), ShipNameWidth.RepairList),
\r
67 Damage = new ShipLabel.Hp {Location = new Point(119, y), Size = new Size(5, height - 1)},
\r
68 Time = new ShipLabel.RepairTime(new Point(75, y)),
\r
69 BackGround = new Label
\r
71 Location = new Point(0, y - 1),
\r
72 Size = new Size(Width, height + 2)
\r
75 _repairLabels[i].Arrange(this, CustomColors.ColumnColors.BrightFirst(i));
\r
76 _repairLabels[i].Scale();
\r
77 _repairLabels[i].SetClickHandler(onClick);
\r
80 SetupListScroller();
\r
87 var baseHeight = Parent.ClientRectangle.Height - Location.Y + 2;
\r
88 return (int)Floor((baseHeight - Scaler.ScaleHeight((float)PanelPadding) * 2) /
\r
89 Scaler.ScaleHeight((float)LineHeight));
\r
93 private void SetupListScroller()
\r
95 _listScroller = new ListScroller(this, _repairLabels[0].Controls, _repairLabels.Last().Controls)
\r
97 Lines = _repairLabels.Length,
\r
98 Padding = PanelPadding
\r
100 _listScroller.Update += ShowRepairList;
\r
103 public void SetRepairList(ShipStatus[] list)
\r
105 _repairList = list;
\r
106 _listScroller.DataCount = list.Length;
\r
108 if (list.Length == 0)
\r
113 _repairLabels[0].Name.SetName("なし");
\r
116 _listScroller.Position = Min(_listScroller.Position, Max(0, _repairList.Length - _repairLabels.Length));
\r
120 private void SetPanelHeight()
\r
122 var lines = Min(Max(1, _repairList.Length), _repairLabels.Length);
\r
123 Size = new Size(Width, Scaler.ScaleHeight(lines * LineHeight + PanelPadding * 2));
\r
126 private void ShowRepairList()
\r
128 for (var i = 0; i < Min(_repairList.Length, _repairLabels.Length); i++)
\r
130 var s = _repairList[i + _listScroller.Position];
\r
131 var labels = _repairLabels[i];
\r
133 labels.Damage.SetColor(s);
\r
135 if (_repairList.Length < _repairLabels.Length)
\r
136 ClearLabels(_repairList.Length);
\r
137 _listScroller.DrawMark();
\r
140 private void ClearLabels(int i)
\r
142 var labels = _repairLabels[i];
\r