OSDN Git Service

一覧のグループ分けに関する処理をGroupConfigLabelsに分離する
authorKazuhiro Fujieda <fujieda@users.osdn.me>
Thu, 9 May 2019 13:33:49 +0000 (22:33 +0900)
committerKazuhiro Fujieda <fujieda@users.osdn.me>
Fri, 17 May 2019 06:47:16 +0000 (15:47 +0900)
KancolleSniffer/KancolleSniffer.csproj
KancolleSniffer/ListForm.cs
KancolleSniffer/View/GroupConfigLabels.cs [new file with mode: 0644]
KancolleSniffer/View/ShipListPanel.cs

index 581890a..2ea5801 100644 (file)
     </Compile>\r
     <Compile Include="Net\HttpProxy.cs" />\r
     <Compile Include="Util\HttpUtility.cs" />\r
+    <Compile Include="View\GroupConfigLabels.cs" />\r
     <Compile Include="View\ListScroller.cs" />\r
     <Compile Include="View\NumberAndHistory.cs" />\r
     <Compile Include="View\ItemTreeView.cs">\r
index 8642e03..c74c281 100644 (file)
@@ -238,7 +238,7 @@ namespace KancolleSniffer
         private void LoadShipGroupFromConfig()\r
         {\r
             var group = _config.ShipList.ShipGroup;\r
-            for (var i = 0; i < ShipListPanel.GroupCount; i++)\r
+            for (var i = 0; i < GroupConfigLabels.GroupCount; i++)\r
                 shipListPanel.GroupSettings[i] = i < group.Count ? new HashSet<int>(group[i]) : new HashSet<int>();\r
         }\r
 \r
@@ -309,7 +309,7 @@ namespace KancolleSniffer
             var all = _sniffer.ShipList.Select(s => s.Id).ToArray();\r
             var group = _config.ShipList.ShipGroup;\r
             group.Clear();\r
-            for (var i = 0; i < ShipListPanel.GroupCount; i++)\r
+            for (var i = 0; i < GroupConfigLabels.GroupCount; i++)\r
             {\r
                 if (all.Length > 0)\r
                     shipListPanel.GroupSettings[i].IntersectWith(all);\r
diff --git a/KancolleSniffer/View/GroupConfigLabels.cs b/KancolleSniffer/View/GroupConfigLabels.cs
new file mode 100644 (file)
index 0000000..50c3f1b
--- /dev/null
@@ -0,0 +1,139 @@
+// Copyright (C) 2019 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
+//\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
+//\r
+//    http://www.apache.org/licenses/LICENSE-2.0\r
+//\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
+\r
+using System;\r
+using System.Collections.Generic;\r
+using System.Drawing;\r
+using System.Linq;\r
+using System.Windows.Forms;\r
+using KancolleSniffer.Model;\r
+// ReSharper disable CoVariantArrayConversion\r
+\r
+namespace KancolleSniffer.View\r
+{\r
+    public class GroupConfigLabels\r
+    {\r
+        private readonly ShipListPanel _shipListPanel;\r
+        private readonly List<CheckBox[]> _checkBoxesList = new List<CheckBox[]>();\r
+        private readonly List<ShipLabel[]> _labelList = new List<ShipLabel[]>();\r
+        private readonly List<Panel> _panelList = new List<Panel>();\r
+\r
+        public const int GroupCount = 4;\r
+        public HashSet<int>[] GroupSettings { get; } = new HashSet<int>[GroupCount];\r
+        public bool GroupUpdated { get; set; }\r
+\r
+        public GroupConfigLabels(ShipListPanel shipListPanel)\r
+        {\r
+            _shipListPanel = shipListPanel;\r
+        }\r
+\r
+        public void CreateComponents(int i)\r
+        {\r
+            var y = ShipListPanel.LineHeight * i + 1;\r
+            var panel = new Panel\r
+            {\r
+                Location = new Point(0, y),\r
+                Size = new Size(ListForm.PanelWidth, ShipListPanel.LineHeight),\r
+                BackColor = ShipLabel.ColumnColors[(i + 1) % 2]\r
+            };\r
+            Scaler.Scale(panel);\r
+            panel.Tag = panel.Location.Y;\r
+            var labels = new[]\r
+            {\r
+                new ShipLabel\r
+                {\r
+                    Location = new Point(90, 2),\r
+                    Size = new Size(24, ShipListPanel.LabelHeight),\r
+                    TextAlign = ContentAlignment.MiddleRight\r
+                },\r
+                new ShipLabel {Location = new Point(10, 2), AutoSize = true},\r
+                new ShipLabel {Location = new Point(1, 2), AutoSize = true}\r
+            };\r
+\r
+            var cb = new CheckBox[GroupCount];\r
+            for (var j = 0; j < cb.Length; j++)\r
+            {\r
+                cb[j] = new CheckBox\r
+                {\r
+                    Location = new Point(125 + j * 24, 2),\r
+                    FlatStyle = FlatStyle.Flat,\r
+                    Size = new Size(12, 11),\r
+                    Tag = i * 10 + j\r
+                };\r
+                Scaler.Scale(cb[j]);\r
+                cb[j].CheckedChanged += checkboxGroup_CheckedChanged;\r
+            }\r
+            _labelList.Add(labels);\r
+            _checkBoxesList.Add(cb);\r
+            _panelList.Add(panel);\r
+            panel.Controls.AddRange(labels);\r
+            panel.Controls.AddRange(cb);\r
+            _shipListPanel.Controls.Add(panel);\r
+            var unused = panel.Handle; // create handle\r
+            foreach (var label in labels)\r
+            {\r
+                Scaler.Scale(label);\r
+                label.PresetColor =\r
+                    label.BackColor = ShipLabel.ColumnColors[(i + 1) % 2];\r
+            }\r
+        }\r
+\r
+        private void checkboxGroup_CheckedChanged(object sender, EventArgs e)\r
+        {\r
+            var cb = (CheckBox)sender;\r
+            var group = (int)cb.Tag % 10;\r
+            var idx = (int)cb.Tag / 10;\r
+            if (cb.Checked)\r
+            {\r
+                GroupSettings[group].Add(_shipListPanel.GetShip(idx).Id);\r
+            }\r
+            else\r
+            {\r
+                GroupSettings[group].Remove(_shipListPanel.GetShip(idx).Id);\r
+            }\r
+            GroupUpdated = true;\r
+        }\r
+\r
+        public void SetGrouping(int i)\r
+        {\r
+            var s = _shipListPanel.GetShip(i);\r
+            var labels = _labelList[i];\r
+            if (s.Level == 1000)\r
+            {\r
+                _shipListPanel.SetShipType(i);\r
+                return;\r
+            }\r
+            labels[0].SetLevel(s);\r
+            labels[1].SetName(s, ShipNameWidth.GroupConfig);\r
+            labels[2].SetFleet(s);\r
+            var cb = _checkBoxesList[i];\r
+            for (var j = 0; j < cb.Length; j++)\r
+                cb[j].Checked = GroupSettings[j].Contains(s.Id);\r
+            _panelList[i].Visible = true;\r
+        }\r
+\r
+        public void HidePanel(int i)\r
+        {\r
+            _panelList[i].Visible = false;\r
+        }\r
+\r
+        public IEnumerable<ShipStatus> FilterByGroup(IEnumerable<ShipStatus> ships, string group)\r
+        {\r
+            var g = Array.FindIndex(new[] {"A", "B", "C", "D"}, x => x == group);\r
+            if (g == -1)\r
+                return ships;\r
+            return from s in ships where GroupSettings[g].Contains(s.Id) select s;\r
+        }\r
+    }\r
+}
\ No newline at end of file
index c99414d..3b6f7cb 100644 (file)
@@ -25,31 +25,39 @@ namespace KancolleSniffer.View
 {\r
     public class ShipListPanel : Panel\r
     {\r
-        private const int LabelHeight = 12;\r
+        public const int LabelHeight = 12;\r
         public const int LineHeight = 16;\r
         private ShipStatus[] _shipList;\r
         private readonly List<ShipLabel[]> _labelList = new List<ShipLabel[]>();\r
         private readonly List<Panel> _labelPanelList = new List<Panel>();\r
-        private readonly List<CheckBox[]> _checkBoxesList = new List<CheckBox[]>();\r
-        private readonly List<ShipLabel[]> _groupingLabelList = new List<ShipLabel[]>();\r
-        private readonly List<Panel> _groupingPanelList = new List<Panel>();\r
         private readonly List<ShipLabel[]> _repairLabelList = new List<ShipLabel[]>();\r
         private readonly List<Panel> _repairPanelList = new List<Panel>();\r
         private readonly List<ShipLabel> _hpLabels = new List<ShipLabel>();\r
+        private readonly GroupConfigLabels _groupConfigLabels;\r
         private string _mode;\r
         private bool _hpPercent;\r
 \r
-        public const int GroupCount = 4;\r
-        public HashSet<int>[] GroupSettings { get; } = new HashSet<int>[GroupCount];\r
-        public bool GroupUpdated { get; set; }\r
+        public HashSet<int>[] GroupSettings => _groupConfigLabels.GroupSettings;\r
+\r
+        public bool GroupUpdated\r
+        {\r
+            get => _groupConfigLabels.GroupUpdated;\r
+            set => _groupConfigLabels.GroupUpdated = value;\r
+        }\r
 \r
         public ScrollBar ScrollBar { get; }\r
 \r
+        public ShipStatus GetShip(int i)\r
+        {\r
+            return _shipList[i + ScrollBar.Value];\r
+        }\r
+\r
         public ShipListPanel()\r
         {\r
             ScrollBar = new VScrollBar {Dock = DockStyle.Right, Visible = false};\r
             ScrollBar.ValueChanged += ScrollBarOnValueChanged;\r
             Controls.Add(ScrollBar);\r
+            _groupConfigLabels = new GroupConfigLabels(this);\r
         }\r
 \r
         private void ScrollBarOnValueChanged(object sender, EventArgs eventArgs)\r
@@ -107,7 +115,7 @@ namespace KancolleSniffer.View
         private void CreateShipList(Sniffer sniffer, ShipListConfig config)\r
         {\r
             var ships = FilterByShipTypes(\r
-                _mode == "修復" ? sniffer.RepairList : FilterByGroup(sniffer.ShipList, _mode),\r
+                _mode == "修復" ? sniffer.RepairList : _groupConfigLabels.FilterByGroup(sniffer.ShipList, _mode),\r
                 config.ShipCategories).ToArray();\r
             var order = _mode == "修復" ? ListForm.SortOrder.Repair : config.SortOrder;\r
             if (!config.ShipType)\r
@@ -123,14 +131,6 @@ namespace KancolleSniffer.View
                 }).Concat(ships).OrderBy(ship => ship, new CompareShip(true, order)).ToArray();\r
         }\r
 \r
-        private IEnumerable<ShipStatus> FilterByGroup(IEnumerable<ShipStatus> ships, string group)\r
-        {\r
-            var g = Array.FindIndex(new[] {"A", "B", "C", "D"}, x => x == group);\r
-            if (g == -1)\r
-                return ships;\r
-            return from s in ships where GroupSettings[g].Contains(s.Id) select s;\r
-        }\r
-\r
         private static readonly int[][] ShipTypeIds =\r
         {\r
             new[] // 戦艦\r
@@ -272,7 +272,7 @@ namespace KancolleSniffer.View
         {\r
             for (var i = _labelList.Count; i * LineHeight < Height; i++)\r
             {\r
-                CreateGroupingComponents(i);\r
+                _groupConfigLabels.CreateComponents(i);\r
                 CreateRepairLabels(i);\r
                 CreateShipLabels(i);\r
             }\r
@@ -298,75 +298,6 @@ namespace KancolleSniffer.View
             ScrollBar.Value = Min(ScrollBar.Value, max);\r
         }\r
 \r
-        private void CreateGroupingComponents(int i)\r
-        {\r
-            var y = LineHeight * i + 1;\r
-            var panel = new Panel\r
-            {\r
-                Location = new Point(0, y),\r
-                Size = new Size(ListForm.PanelWidth, LineHeight),\r
-                BackColor = ShipLabel.ColumnColors[(i + 1) % 2]\r
-            };\r
-            Scaler.Scale(panel);\r
-            panel.Tag = panel.Location.Y;\r
-            var labels = new[]\r
-            {\r
-                new ShipLabel\r
-                {\r
-                    Location = new Point(90, 2),\r
-                    Size = new Size(24, LabelHeight),\r
-                    TextAlign = ContentAlignment.MiddleRight\r
-                },\r
-                new ShipLabel {Location = new Point(10, 2), AutoSize = true},\r
-                new ShipLabel {Location = new Point(1, 2), AutoSize = true}\r
-            };\r
-\r
-            var cb = new CheckBox[GroupCount];\r
-            for (var j = 0; j < cb.Length; j++)\r
-            {\r
-                cb[j] = new CheckBox\r
-                {\r
-                    Location = new Point(125 + j * 24, 2),\r
-                    FlatStyle = FlatStyle.Flat,\r
-                    Size = new Size(12, 11),\r
-                    Tag = i * 10 + j\r
-                };\r
-                Scaler.Scale(cb[j]);\r
-                cb[j].CheckedChanged += checkboxGroup_CheckedChanged;\r
-            }\r
-            _groupingLabelList.Add(labels);\r
-            _checkBoxesList.Add(cb);\r
-            _groupingPanelList.Add(panel);\r
-            // ReSharper disable CoVariantArrayConversion\r
-            panel.Controls.AddRange(labels);\r
-            panel.Controls.AddRange(cb);\r
-            // ReSharper restore CoVariantArrayConversion\r
-            Controls.Add(panel);\r
-            var unused = panel.Handle; // create handle\r
-            foreach (var label in labels)\r
-            {\r
-                Scaler.Scale(label);\r
-                label.PresetColor =\r
-                    label.BackColor = ShipLabel.ColumnColors[(i + 1) % 2];\r
-            }\r
-        }\r
-\r
-        private void checkboxGroup_CheckedChanged(object sender, EventArgs e)\r
-        {\r
-            var cb = (CheckBox)sender;\r
-            var group = (int)cb.Tag % 10;\r
-            var idx = (int)cb.Tag / 10;\r
-            if (cb.Checked)\r
-            {\r
-                GroupSettings[group].Add(_shipList[idx + ScrollBar.Value].Id);\r
-            }\r
-            else\r
-            {\r
-                GroupSettings[group].Remove(_shipList[idx + ScrollBar.Value].Id);\r
-            }\r
-            GroupUpdated = true;\r
-        }\r
-\r
         private void CreateRepairLabels(int i)\r
         {\r
             var y = LineHeight * i + 1;\r
@@ -490,7 +421,7 @@ namespace KancolleSniffer.View
                 if (InShipStatus(_mode))\r
                     SetShipStatus(i);\r
                 if (_mode == "分類")\r
-                    SetGrouping(i);\r
+                    _groupConfigLabels.SetGrouping(i);\r
                 if (_mode == "修復")\r
                     SetRepairList(i);\r
             }\r
@@ -498,7 +429,8 @@ namespace KancolleSniffer.View
 \r
         private void HidePanels(int i)\r
         {\r
-            _labelPanelList[i].Visible = _groupingPanelList[i].Visible = _repairPanelList[i].Visible = false;\r
+            _labelPanelList[i].Visible = _repairPanelList[i].Visible = false;\r
+            _groupConfigLabels.HidePanel(i);\r
         }\r
 \r
         private bool InShipStatus(string mode) => Array.Exists(new[] {"全艦", "A", "B", "C", "D"}, x => mode == x);\r
@@ -521,7 +453,7 @@ namespace KancolleSniffer.View
             _labelPanelList[i].Visible = true;\r
         }\r
 \r
-        private void SetShipType(int i)\r
+        public void SetShipType(int i)\r
         {\r
             var s = _shipList[i + ScrollBar.Value];\r
             var labels = _labelList[i];\r
@@ -535,24 +467,6 @@ namespace KancolleSniffer.View
             _labelPanelList[i].Visible = true;\r
         }\r
 \r
-        private void SetGrouping(int i)\r
-        {\r
-            var s = _shipList[i + ScrollBar.Value];\r
-            var labels = _groupingLabelList[i];\r
-            if (s.Level == 1000)\r
-            {\r
-                SetShipType(i);\r
-                return;\r
-            }\r
-            labels[0].SetLevel(s);\r
-            labels[1].SetName(s, ShipNameWidth.GroupConfig);\r
-            labels[2].SetFleet(s);\r
-            var cb = _checkBoxesList[i];\r
-            for (var j = 0; j < cb.Length; j++)\r
-                cb[j].Checked = GroupSettings[j].Contains(s.Id);\r
-            _groupingPanelList[i].Visible = true;\r
-        }\r
-\r
         private void SetRepairList(int i)\r
         {\r
             var s = _shipList[i + ScrollBar.Value];\r