OSDN Git Service

一行分のラベルの保持に配列ではなくオブジェクトを使う
authorKazuhiro Fujieda <fujieda@users.osdn.me>
Sat, 24 Jun 2017 20:33:49 +0000 (05:33 +0900)
committerKazuhiro Fujieda <fujieda@users.osdn.me>
Wed, 28 Jun 2017 09:23:36 +0000 (18:23 +0900)
KancolleSniffer/FleetPanel.cs

index e9142a7..363888a 100644 (file)
@@ -13,6 +13,7 @@
 // limitations under the License.\r
 \r
 using System;\r
+using System.Collections;\r
 using System.Collections.Generic;\r
 using System.Drawing;\r
 using System.Linq;\r
@@ -25,7 +26,7 @@ namespace KancolleSniffer
         private const int LineHeight = 14;\r
         private const int LabelHeight = 12;\r
         private Record[] _table;\r
-        private readonly List<ShipLabel[]> _labelList = new List<ShipLabel[]>();\r
+        private readonly List<FleetLabels> _labelList = new List<FleetLabels>();\r
         private readonly List<Panel> _panelList = new List<Panel>();\r
         private readonly ToolTip _toolTip = new ToolTip {ShowAlways = true};\r
 \r
@@ -197,6 +198,20 @@ namespace KancolleSniffer
                 CreateLabels(i);\r
         }\r
 \r
+        private class FleetLabels : IEnumerable<ShipLabel>\r
+        {\r
+            public ShipLabel Fleet { get; set; }\r
+            public ShipLabel Name { get; set; }\r
+            public ShipLabel Equip { get; set; }\r
+            public ShipLabel EquipColor { get; set; }\r
+            public ShipLabel Spec { get; set; }\r
+\r
+            public IEnumerator<ShipLabel> GetEnumerator() =>\r
+                ((IEnumerable<ShipLabel>)new[] {Fleet, Name, Equip, EquipColor, Spec}).GetEnumerator();\r
+\r
+            IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();\r
+        }\r
+\r
         private void CreateLabels(int i)\r
         {\r
             var y = 1 + LineHeight * i;\r
@@ -209,18 +224,17 @@ namespace KancolleSniffer
             };\r
             lbp.Scale(ShipLabel.ScaleFactor);\r
             lbp.Tag = lbp.Location.Y;\r
-            var labels = new[]\r
+            var labels = new FleetLabels\r
             {\r
-                new ShipLabel {Location = new Point(1, 2), AutoSize = true},\r
-                new ShipLabel {Location = new Point(10, 2), AutoSize = true},\r
-                new ShipLabel {Location = new Point(38, 2), AutoSize = true},\r
-                new ShipLabel {Location = new Point(35, 2), Size = new Size(4, LabelHeight - 2)},\r
-                new ShipLabel {Location = new Point(217, 2), AutoSize = true, AnchorRight = true}\r
+                Fleet = new ShipLabel {Location = new Point(1, 2), AutoSize = true},\r
+                Name = new ShipLabel {Location = new Point(10, 2), AutoSize = true},\r
+                Equip = new ShipLabel {Location = new Point(38, 2), AutoSize = true},\r
+                EquipColor = new ShipLabel {Location = new Point(35, 2), Size = new Size(4, LabelHeight - 2)},\r
+                Spec = new ShipLabel {Location = new Point(217, 2), AutoSize = true, AnchorRight = true}\r
             };\r
             _labelList.Add(labels);\r
             _panelList.Add(lbp);\r
-            // ReSharper disable once CoVariantArrayConversion\r
-            lbp.Controls.AddRange(labels);\r
+            lbp.Controls.AddRange(labels.Cast<Control>().ToArray());\r
             Controls.Add(lbp);\r
             foreach (var label in labels)\r
             {\r
@@ -245,16 +259,16 @@ namespace KancolleSniffer
                 lbp.Location = new Point(lbp.Left, (int)lbp.Tag + AutoScrollPosition.Y);\r
             var e = _table[i];\r
             var labels = _labelList[i];\r
-            labels[0].Text = e.Fleet;\r
-            labels[1].SetName(e.Ship);\r
-            labels[2].Text = e.Equip;\r
-            labels[3].Visible = e.Equip != "";\r
-            labels[3].BackColor = e.Color;\r
-            labels[4].Text = e.Spec;\r
+            labels.Fleet.Text = e.Fleet;\r
+            labels.Name.SetName(e.Ship);\r
+            labels.Equip.Text = e.Equip;\r
+            labels.EquipColor.Visible = e.Equip != "";\r
+            labels.EquipColor.BackColor = e.Color;\r
+            labels.Spec.Text = e.Spec;\r
             if (e.Fleet != "" && e.Fleet2 != "")\r
-                _toolTip.SetToolTip(labels[0], e.Fleet2);\r
-            _toolTip.SetToolTip(labels[2], e.AircraftSpec != "" ? e.AircraftSpec : "");\r
-            _toolTip.SetToolTip(labels[4], e.Spec2 != "" ? e.Spec2 : "");\r
+                _toolTip.SetToolTip(labels.Fleet, e.Fleet2);\r
+            _toolTip.SetToolTip(labels.Equip, e.AircraftSpec != "" ? e.AircraftSpec : "");\r
+            _toolTip.SetToolTip(labels.Spec, e.Spec2 != "" ? e.Spec2 : "");\r
             lbp.Visible = true;\r
         }\r
 \r