OSDN Git Service

分類でグループから艦娘を外せないことがあるのを直す
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / View / ShipListPanel / GroupConfigLabels.cs
1 // Copyright (C) 2019 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
2 //\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
6 //\r
7 //    http://www.apache.org/licenses/LICENSE-2.0\r
8 //\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
14 \r
15 using System;\r
16 using System.Collections.Generic;\r
17 using System.Drawing;\r
18 using System.Linq;\r
19 using System.Windows.Forms;\r
20 using KancolleSniffer.Forms;\r
21 \r
22 // ReSharper disable CoVariantArrayConversion\r
23 \r
24 namespace KancolleSniffer.View.ShipListPanel\r
25 {\r
26     public class GroupConfigLabels\r
27     {\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
31 \r
32         public const int GroupCount = 4;\r
33         public List<List<int>> GroupSettings { get; set; }\r
34         public bool GroupUpdated { get; set; }\r
35 \r
36         public GroupConfigLabels(ShipListPanel shipListPanel)\r
37         {\r
38             _shipListPanel = shipListPanel;\r
39         }\r
40 \r
41         public void CreateComponents(int i)\r
42         {\r
43             var y = ShipListPanel.LineHeight * i + 1;\r
44             var labels = new ShipLabels\r
45             {\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
50                 {\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
54                 }\r
55             };\r
56             var cb = new CheckBox[GroupCount];\r
57             for (var j = 0; j < cb.Length; j++)\r
58             {\r
59                 cb[j] = new CheckBox\r
60                 {\r
61                     Location = new Point(125 + j * 24, 2),\r
62                     FlatStyle = FlatStyle.Flat,\r
63                     Size = new Size(12, 11),\r
64                     Tag = i * 10 + j\r
65                 };\r
66                 cb[j].CheckedChanged += checkboxGroup_CheckedChanged;\r
67             }\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
73             labels.Scale();\r
74         }\r
75 \r
76         private void SetAnchorRight(params Control[] controls)\r
77         {\r
78             foreach (var control in controls)\r
79                 control.Anchor = AnchorStyles.Top | AnchorStyles.Right;\r
80         }\r
81 \r
82         public void Resize(int i, int width)\r
83         {\r
84             var labels = _labelList[i];\r
85             labels.BackPanel.Width = width;\r
86             labels.Name.AdjustWidth(Scaler.DownWidth(width) - ListForm.PanelWidth);\r
87         }\r
88 \r
89         private void checkboxGroup_CheckedChanged(object sender, EventArgs e)\r
90         {\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
95             if (cb.Checked)\r
96                 GroupSettings[group].Add(_shipListPanel.GetShip(idx).Id);\r
97             GroupUpdated = true;\r
98         }\r
99 \r
100         public void SetGrouping(int i)\r
101         {\r
102             var s = _shipListPanel.GetShip(i);\r
103             var labels = _labelList[i];\r
104             if (s.Level == 1000)\r
105             {\r
106                 _shipListPanel.SetShipType(i);\r
107                 return;\r
108             }\r
109             labels.Set(s);\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
114         }\r
115 \r
116         public void HidePanel(int i)\r
117         {\r
118             _labelList[i].BackPanel.Visible = false;\r
119         }\r
120     }\r
121 }