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
21 namespace KancolleSniffer.View
\r
23 public class FleetPanel : PanelWithToolTip
\r
25 private const int LineHeight = 14;
\r
26 private const int LabelHeight = 12;
\r
27 private FleetSpec.Record[] _spec = new FleetSpec.Record[0];
\r
28 private readonly List<FleetLabels> _labelList = new List<FleetLabels>();
\r
32 ToolTip.AutoPopDelay = 10000;
\r
35 public void Update(Sniffer sniffer)
\r
37 _spec = FleetSpec.Create(sniffer);
\r
44 private void CreateLabels()
\r
46 for (var i = _labelList.Count; i < _spec.Length; i++)
\r
50 private class FleetLabels : ControlsArranger
\r
52 public Label Fleet { get; set; }
\r
53 public ShipLabel.Name Name { get; set; }
\r
54 public Label Equip { get; set; }
\r
55 public Label EquipColor { get; set; }
\r
56 public Label Spec { get; set; }
\r
58 public override Control[] Controls => new Control[] {Fleet, Name, Equip, EquipColor, Spec};
\r
61 private void CreateLabels(int i)
\r
63 var y = 1 + LineHeight * i;
\r
64 var labels = new FleetLabels
\r
66 Fleet = new Label {Location = new Point(1, 2), AutoSize = true},
\r
67 Name = new ShipLabel.Name(new Point(10, 2), ShipNameWidth.Max),
\r
68 Equip = new Label {Location = new Point(38, 2), AutoSize = true},
\r
69 EquipColor = new Label {Location = new Point(35, 2), Size = new Size(4, LabelHeight - 2)},
\r
70 Spec = new GrowLeftLabel {Location = new Point(217, 2), GrowLeft = true},
\r
71 BackPanel = new Panel
\r
73 Location = new Point(0, y),
\r
74 Size = new Size(ListForm.PanelWidth, LineHeight),
\r
75 BackColor = CustomColors.ColumnColors.BrightFirst(i)
\r
78 _labelList.Add(labels);
\r
79 labels.Fleet.DoubleClick += (obj, ev) => { Clipboard.SetText((string)labels.Fleet.Tag); };
\r
80 labels.Arrange(this, CustomColors.ColumnColors.BrightFirst(i));
\r
81 labels.Move(AutoScrollPosition);
\r
84 private void SetRecords()
\r
86 for (var i = 0; i < _spec.Length; i++)
\r
88 for (var i = _spec.Length; i < _labelList.Count; i++)
\r
89 _labelList[i].BackPanel.Visible = false;
\r
92 private void SetRecord(int i)
\r
95 var labels = _labelList[i];
\r
96 labels.Fleet.Text = e.Fleet;
\r
97 labels.Fleet.Tag = "";
\r
98 labels.Name.SetName(e.Ship);
\r
100 ToolTip.SetToolTip(labels.Name, e.Ship2);
\r
101 labels.Equip.Text = e.Equip;
\r
102 labels.EquipColor.Visible = e.Equip != "";
\r
103 labels.EquipColor.BackColor = e.Color;
\r
104 labels.Spec.Text = e.Spec;
\r
105 if (e.Fleet != "" && e.Fleet2 != "")
\r
107 ToolTip.SetToolTip(labels.Fleet, e.Fleet2);
\r
108 labels.Fleet.Tag = e.Fleet2;
\r
110 ToolTip.SetToolTip(labels.Equip, e.AircraftSpec != "" ? e.AircraftSpec : "");
\r
111 ToolTip.SetToolTip(labels.Spec, e.Spec2 != "" ? e.Spec2 : "");
\r
112 labels.BackPanel.Visible = true;
\r
115 public void ShowShip(int id)
\r
117 var i = Array.FindIndex(_spec, e => e.Id == id);
\r
120 var y = Scaler.ScaleHeight(LineHeight * i);
\r
121 AutoScrollPosition = new Point(0, y);
\r
124 public void ShowFleet(string fn)
\r
126 var i = Array.FindIndex(_spec, e => e.Fleet.StartsWith(fn));
\r
129 var y = Scaler.ScaleHeight(LineHeight * i);
\r
130 AutoScrollPosition = new Point(0, y);
\r