1 // Copyright (C) 2019 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
19 using System.Windows.Forms;
\r
20 using KancolleSniffer.Model;
\r
22 // ReSharper disable CoVariantArrayConversion
\r
24 namespace KancolleSniffer.View.ShipListPanel
\r
26 public class GroupConfigLabels
\r
28 private readonly ShipListPanel _shipListPanel;
\r
29 private readonly List<CheckBox[]> _checkBoxesList = new List<CheckBox[]>();
\r
30 private readonly List<ShipLabel[]> _labelList = new List<ShipLabel[]>();
\r
31 private readonly List<Panel> _panelList = new List<Panel>();
\r
33 public const int GroupCount = 4;
\r
34 public HashSet<int>[] GroupSettings { get; } = new HashSet<int>[GroupCount];
\r
35 public bool GroupUpdated { get; set; }
\r
37 public GroupConfigLabels(ShipListPanel shipListPanel)
\r
39 _shipListPanel = shipListPanel;
\r
42 public void CreateComponents(int i)
\r
44 var y = ShipListPanel.LineHeight * i + 1;
\r
45 var panel = new Panel
\r
47 Location = new Point(0, y),
\r
48 Size = new Size(ListForm.PanelWidth, ShipListPanel.LineHeight),
\r
49 BackColor = ShipLabel.ColumnColors[(i + 1) % 2]
\r
51 Scaler.Scale(panel);
\r
52 panel.Tag = panel.Location.Y;
\r
57 Location = new Point(90, 2),
\r
58 Size = new Size(24, ShipListPanel.LabelHeight),
\r
59 TextAlign = ContentAlignment.MiddleRight
\r
61 new ShipLabel {Location = new Point(10, 2), AutoSize = true},
\r
62 new ShipLabel {Location = new Point(1, 2), AutoSize = true}
\r
65 var cb = new CheckBox[GroupCount];
\r
66 for (var j = 0; j < cb.Length; j++)
\r
68 cb[j] = new CheckBox
\r
70 Location = new Point(125 + j * 24, 2),
\r
71 FlatStyle = FlatStyle.Flat,
\r
72 Size = new Size(12, 11),
\r
75 Scaler.Scale(cb[j]);
\r
76 cb[j].CheckedChanged += checkboxGroup_CheckedChanged;
\r
78 _labelList.Add(labels);
\r
79 _checkBoxesList.Add(cb);
\r
80 _panelList.Add(panel);
\r
81 panel.Controls.AddRange(labels);
\r
82 panel.Controls.AddRange(cb);
\r
83 _shipListPanel.Controls.Add(panel);
\r
84 var unused = panel.Handle; // create handle
\r
85 foreach (var label in labels)
\r
87 Scaler.Scale(label);
\r
89 label.BackColor = ShipLabel.ColumnColors[(i + 1) % 2];
\r
93 private void checkboxGroup_CheckedChanged(object sender, EventArgs e)
\r
95 var cb = (CheckBox)sender;
\r
96 var group = (int)cb.Tag % 10;
\r
97 var idx = (int)cb.Tag / 10;
\r
100 GroupSettings[group].Add(_shipListPanel.GetShip(idx).Id);
\r
104 GroupSettings[group].Remove(_shipListPanel.GetShip(idx).Id);
\r
106 GroupUpdated = true;
\r
109 public void SetGrouping(int i)
\r
111 var s = _shipListPanel.GetShip(i);
\r
112 var labels = _labelList[i];
\r
113 if (s.Level == 1000)
\r
115 _shipListPanel.SetShipType(i);
\r
118 labels[0].SetLevel(s);
\r
119 labels[1].SetName(s, ShipNameWidth.GroupConfig);
\r
120 labels[2].SetFleet(s);
\r
121 var cb = _checkBoxesList[i];
\r
122 for (var j = 0; j < cb.Length; j++)
\r
123 cb[j].Checked = GroupSettings[j].Contains(s.Id);
\r
124 _panelList[i].Visible = true;
\r
127 public void HidePanel(int i)
\r
129 _panelList[i].Visible = false;
\r
132 public IEnumerable<ShipStatus> FilterByGroup(IEnumerable<ShipStatus> ships, string group)
\r
134 var g = Array.FindIndex(new[] {"A", "B", "C", "D"}, x => x == group);
\r
137 return from s in ships where GroupSettings[g].Contains(s.Id) select s;
\r