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
19 using Clipboard = KancolleSniffer.Util.Clipboard;
\r
20 using KancolleSniffer.Forms;
\r
22 namespace KancolleSniffer.View.ListWindow
\r
24 public class FleetDataPanel : PanelWithToolTip, IPanelResize
\r
26 private const int LineHeight = 14;
\r
27 private const int LabelHeight = 12;
\r
28 private FleetData.Record[] _data = new FleetData.Record[0];
\r
29 private readonly List<FleetLabels> _labelList = new List<FleetLabels>();
\r
31 public FleetDataPanel()
\r
33 ToolTip.AutoPopDelay = 10000;
\r
36 public void Update(Sniffer sniffer)
\r
38 _data = FleetData.Create(sniffer);
\r
45 private void CreateLabels()
\r
47 for (var i = _labelList.Count; i < _data.Length; i++)
\r
51 private class FleetLabels : ControlsArranger
\r
53 public Label Fleet { get; set; }
\r
54 public ShipLabel.Name Name { get; set; }
\r
55 public Label Equip { get; set; }
\r
56 public Label EquipColor { get; set; }
\r
57 public GrowLeftLabel Spec { get; set; }
\r
59 public override Control[] Controls => new Control[] {Fleet, Name, Equip, EquipColor, Spec};
\r
62 private void CreateLabels(int i)
\r
64 var y = 1 + LineHeight * i;
\r
65 var labels = new FleetLabels
\r
67 Fleet = new Label {Location = new Point(1, 2), AutoSize = true},
\r
68 Name = new ShipLabel.Name(new Point(10, 2), ShipNameWidth.Max),
\r
69 Equip = new Label {Location = new Point(38, 2), AutoSize = true, Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top},
\r
70 EquipColor = new Label {Location = new Point(35, 2), Size = new Size(4, LabelHeight - 2)},
\r
71 Spec = new GrowLeftLabel {Location = new Point(217, 2), GrowLeft = true, Anchor = AnchorStyles.Right | AnchorStyles.Top},
\r
72 BackPanel = new Panel
\r
74 Location = new Point(0, y),
\r
75 Size = new Size(ListForm.PanelWidth, LineHeight),
\r
76 BackColor = CustomColors.ColumnColors.BrightFirst(i)
\r
79 _labelList.Add(labels);
\r
80 labels.Fleet.DoubleClick += (obj, ev) => { Clipboard.SetText((string)labels.Fleet.Tag); };
\r
81 labels.Arrange(this, CustomColors.ColumnColors.BrightFirst(i));
\r
82 labels.Move(AutoScrollPosition);
\r
85 public void ApplyResize()
\r
87 var width = Width - SystemInformation.VerticalScrollBarWidth - 2;
\r
89 foreach (var labels in _labelList)
\r
91 labels.BackPanel.Width = width;
\r
92 labels.Spec.AdjustLocation();
\r
98 private void SetRecords()
\r
100 for (var i = 0; i < _data.Length; i++)
\r
102 for (var i = _data.Length; i < _labelList.Count; i++)
\r
103 _labelList[i].BackPanel.Visible = false;
\r
106 private void SetRecord(int i)
\r
109 var labels = _labelList[i];
\r
110 labels.Fleet.Text = e.Fleet;
\r
111 labels.Fleet.Tag = "";
\r
112 labels.Name.SetName(e.Ship);
\r
114 ToolTip.SetToolTip(labels.Name, e.Ship2);
\r
115 labels.Equip.Text = e.Equip.ToString(Scaler.DownWidth(labels.BackPanel.Width) - ListForm.PanelWidth);
\r
116 labels.EquipColor.Visible = e.Equip.ToString() != "";
\r
117 labels.EquipColor.BackColor = e.Color;
\r
118 labels.Spec.Text = e.Spec;
\r
119 if (e.Fleet != "" && e.Fleet2 != "")
\r
121 ToolTip.SetToolTip(labels.Fleet, e.Fleet2);
\r
122 labels.Fleet.Tag = e.Fleet2;
\r
124 ToolTip.SetToolTip(labels.Equip, e.AircraftSpec != "" ? e.AircraftSpec : "");
\r
125 ToolTip.SetToolTip(labels.Spec, e.Spec2 != "" ? e.Spec2 : "");
\r
126 labels.BackPanel.Visible = true;
\r
129 public void ShowShip(int id)
\r
131 var i = Array.FindIndex(_data, e => e.Id == id);
\r
134 var y = Scaler.ScaleHeight(LineHeight * i);
\r
135 AutoScrollPosition = new Point(0, y);
\r
138 public void ShowFleet(string fn)
\r
140 var i = Array.FindIndex(_data, e => e.Fleet.Contains(fn));
\r
143 var y = fn == "基地" ? int.MaxValue : Scaler.ScaleHeight(LineHeight * i);
\r
144 AutoScrollPosition = new Point(0, y);
\r