1 // Copyright (C) 2015 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.Generic;
\r
17 using System.Drawing;
\r
18 using System.Windows.Forms;
\r
20 namespace KancolleSniffer.View
\r
22 public class FleetPanel : PanelWithToolTip
\r
24 private const int LineHeight = 14;
\r
25 private const int LabelHeight = 12;
\r
26 private FleetSpec.Record[] _spec = new FleetSpec.Record[0];
\r
27 private readonly List<FleetLabels> _labelList = new List<FleetLabels>();
\r
31 ToolTip.AutoPopDelay = 10000;
\r
34 public void Update(Sniffer sniffer)
\r
36 _spec = FleetSpec.Create(sniffer);
\r
43 private void CreateLabels()
\r
45 for (var i = _labelList.Count; i < _spec.Length; i++)
\r
49 private class FleetLabels : ControlsArranger
\r
51 public Label Fleet { get; set; }
\r
52 public ShipLabel.Name Name { get; set; }
\r
53 public Label Equip { get; set; }
\r
54 public Label EquipColor { get; set; }
\r
55 public Label Spec { get; set; }
\r
57 public override Control[] Controls => new Control[] {Fleet, Name, Equip, EquipColor, Spec};
\r
60 private void CreateLabels(int i)
\r
62 var y = 1 + LineHeight * i;
\r
63 var labels = new FleetLabels
\r
65 Fleet = new Label {Location = new Point(1, 2), AutoSize = true},
\r
66 Name = new ShipLabel.Name(new Point(10, 2), ShipNameWidth.Max),
\r
67 Equip = new Label {Location = new Point(38, 2), AutoSize = true},
\r
68 EquipColor = new Label {Location = new Point(35, 2), Size = new Size(4, LabelHeight - 2)},
\r
69 Spec = new GrowLeftLabel {Location = new Point(217, 2), GrowLeft = true},
\r
70 BackPanel = new Panel
\r
72 Location = new Point(0, y),
\r
73 Size = new Size(ListForm.PanelWidth, LineHeight),
\r
74 BackColor = CustomColors.ColumnColors.BrightFirst(i)
\r
77 _labelList.Add(labels);
\r
78 labels.Arrange(this, CustomColors.ColumnColors.BrightFirst(i));
\r
79 labels.Move(AutoScrollPosition);
\r
82 private void SetRecords()
\r
84 for (var i = 0; i < _spec.Length; i++)
\r
86 for (var i = _spec.Length; i < _labelList.Count; i++)
\r
87 _labelList[i].BackPanel.Visible = false;
\r
90 private void SetRecord(int i)
\r
93 var labels = _labelList[i];
\r
94 labels.Fleet.Text = e.Fleet;
\r
95 labels.Name.SetName(e.Ship);
\r
97 ToolTip.SetToolTip(labels.Name, e.Ship2);
\r
98 labels.Equip.Text = e.Equip;
\r
99 labels.EquipColor.Visible = e.Equip != "";
\r
100 labels.EquipColor.BackColor = e.Color;
\r
101 labels.Spec.Text = e.Spec;
\r
102 if (e.Fleet != "" && e.Fleet2 != "")
\r
103 ToolTip.SetToolTip(labels.Fleet, e.Fleet2);
\r
104 ToolTip.SetToolTip(labels.Equip, e.AircraftSpec != "" ? e.AircraftSpec : "");
\r
105 ToolTip.SetToolTip(labels.Spec, e.Spec2 != "" ? e.Spec2 : "");
\r
106 labels.BackPanel.Visible = true;
\r
109 public void ShowShip(int id)
\r
111 var i = Array.FindIndex(_spec, e => e.Id == id);
\r
114 var y = Scaler.ScaleHeight(LineHeight * i);
\r
115 AutoScrollPosition = new Point(0, y);
\r
118 public void ShowFleet(string fn)
\r
120 var i = Array.FindIndex(_spec, e => e.Fleet.StartsWith(fn));
\r
123 var y = Scaler.ScaleHeight(LineHeight * i);
\r
124 AutoScrollPosition = new Point(0, y);
\r