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.Forms;
\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<ShipLabels> _labelList = new List<ShipLabels>();
\r
32 public const int GroupCount = 4;
\r
33 public List<List<int>> GroupSettings { get; set; }
\r
34 public bool GroupUpdated { get; set; }
\r
36 public GroupConfigLabels(ShipListPanel shipListPanel)
\r
38 _shipListPanel = shipListPanel;
\r
41 public void CreateComponents(int i)
\r
43 var y = ShipListPanel.LineHeight * i + 1;
\r
44 var labels = new ShipLabels
\r
46 Fleet = new ShipLabel.Fleet(new Point(1, 2)),
\r
47 Name = new ShipLabel.Name(new Point(10, 2), ShipNameWidth.GroupConfig),
\r
48 Level = new ShipLabel.Level(new Point(90, 2), ShipListPanel.LabelHeight),
\r
49 BackPanel = new Panel
\r
51 Location = new Point(0, y),
\r
52 Size = new Size(ListForm.PanelWidth, ShipListPanel.LineHeight),
\r
53 Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top
\r
56 var cb = new CheckBox[GroupCount];
\r
57 for (var j = 0; j < cb.Length; j++)
\r
59 cb[j] = new CheckBox
\r
61 Location = new Point(125 + j * 24, 2),
\r
62 FlatStyle = FlatStyle.Flat,
\r
63 Size = new Size(12, 11),
\r
66 cb[j].CheckedChanged += checkboxGroup_CheckedChanged;
\r
68 SetAnchorRight(cb.Concat(new Control[] {labels.Level}).ToArray());
\r
69 _labelList.Add(labels);
\r
70 _checkBoxesList.Add(cb);
\r
71 labels.Arrange(_shipListPanel, CustomColors.ColumnColors.BrightFirst(i));
\r
72 labels.BackPanel.Controls.AddRange(cb);
\r
76 private void SetAnchorRight(params Control[] controls)
\r
78 foreach (var control in controls)
\r
79 control.Anchor = AnchorStyles.Top | AnchorStyles.Right;
\r
82 public void Resize(int i, int width)
\r
84 var labels = _labelList[i];
\r
85 labels.BackPanel.Width = width;
\r
86 labels.Name.AdjustWidth(Scaler.DownWidth(width) - ListForm.PanelWidth);
\r
89 private void checkboxGroup_CheckedChanged(object sender, EventArgs e)
\r
91 var cb = (CheckBox)sender;
\r
92 var group = (int)cb.Tag % 10;
\r
93 var idx = (int)cb.Tag / 10;
\r
94 GroupSettings[group].RemoveAll(id => id == _shipListPanel.GetShip(idx).Id);
\r
96 GroupSettings[group].Add(_shipListPanel.GetShip(idx).Id);
\r
97 GroupUpdated = true;
\r
100 public void SetGrouping(int i)
\r
102 var s = _shipListPanel.GetShip(i);
\r
103 var labels = _labelList[i];
\r
104 if (s.Level == 1000)
\r
106 _shipListPanel.SetShipType(i);
\r
110 var cb = _checkBoxesList[i];
\r
111 for (var j = 0; j < cb.Length; j++)
\r
112 cb[j].Checked = GroupSettings[j].Contains(s.Id);
\r
113 labels.BackPanel.Visible = true;
\r
116 public void HidePanel(int i)
\r
118 _labelList[i].BackPanel.Visible = false;
\r