OSDN Git Service

IUpdatableをIUpdateContextとIUpdateTimerに分離する
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / View / AntiAirPanel.cs
index b2e860e..45d627a 100644 (file)
@@ -16,16 +16,24 @@ using System.Collections.Generic;
 using System.Drawing;\r
 using System.Linq;\r
 using System.Windows.Forms;\r
+using KancolleSniffer.Model;\r
 \r
 namespace KancolleSniffer.View\r
 {\r
     public class AntiAirPanel : Panel\r
     {\r
         private const int LineHeight = 16;\r
-        private readonly List<ShipLabel[]> _labelList = new List<ShipLabel[]>();\r
-        private readonly List<Panel> _panelList = new List<Panel>();\r
+        private readonly List<AntiAirLabels> _labelList = new List<AntiAirLabels>();\r
         private readonly List<Record> _table = new List<Record>();\r
 \r
+        private class AntiAirLabels : ShipLabels\r
+        {\r
+            public Label Rate { get; set; }\r
+            public Label Diff { get; set; }\r
+\r
+            public override Control[] AddedControls => new Control[] {Rate, Diff};\r
+        }\r
+\r
         public void Update(Sniffer sniffer)\r
         {\r
             CreateTable(sniffer);\r
@@ -60,27 +68,57 @@ namespace KancolleSniffer.View
                 var forFleet = new[] {1.0, 1.2, 1.6}.Select(r => (int)(rawForFleet * r) * 2 / 1.3).ToArray();\r
                 _table.Add(new Record\r
                 {\r
-                    Fleet = fn[fleet.Number] + " " + string.Join("/", forFleet.Select(x => x.ToString("f1")))\r
+                    Fleet = fn[fleet.Number] + " 防空" + string.Join("/", forFleet.Select(x => x.ToString("f1")))\r
                 });\r
                 foreach (var ship in ships)\r
                 {\r
-                    var rate = ship.EffectiveAntiAirForShip / 4.0;\r
-                    var diff = forFleet.Select(x => (x + ship.EffectiveAntiAirForShip) / 10.0);\r
-                    _table.Add(new Record\r
-                    {\r
-                        Ship = ship.Name + " Lv" + ship.Level +\r
-                               " : " + ship.EffectiveAntiAirForShip.ToString("d"),\r
-                        Id = ship.Id\r
-                    });\r
-                    _table.Add(new Record\r
-                    {\r
-                        Rate = "割合: " + rate.ToString("f1") + "% ",\r
-                        Diff = "固定: " + string.Join("/", diff.Select(d => d.ToString("f1")))\r
-                    });\r
+                    _table.Add(CreateShipRecord(ship));\r
+                    _table.Add(CreateAntiAirRecord(forFleet, ship));\r
                 }\r
             }\r
         }\r
 \r
+        private Record CreateShipRecord(ShipStatus ship)\r
+        {\r
+            var param = " Lv" + ship.Level +\r
+                        " 加重" + ship.EffectiveAntiAirForShip.ToString("d") +\r
+                        AntiAirPropellantBarrageChance(ship);\r
+            var name = ship.Name;\r
+            var realWidth = Scaler.ScaleWidth(ListForm.PanelWidth - 10);\r
+            return new Record\r
+            {\r
+                Ship = StringTruncator.Truncate(name, param, realWidth, GetFont(name)) + param,\r
+                Id = ship.Id\r
+            };\r
+        }\r
+\r
+        private Record CreateAntiAirRecord(double[] forFleet, ShipStatus ship)\r
+        {\r
+            var rate = ship.EffectiveAntiAirForShip / 4.0;\r
+            var diff = forFleet.Select(x => (x + ship.EffectiveAntiAirForShip) / 10.0);\r
+            return new Record\r
+            {\r
+                Rate = "割合" + rate.ToString("f1") + "% ",\r
+                Diff = "固定" + string.Join("/", diff.Select(d => d.ToString("f1")))\r
+            };\r
+        }\r
+\r
+        private static Font GetFont(string name)\r
+        {\r
+            return ShipLabel.Name.StartWithLetter(name)\r
+                ? ShipLabel.Name.LatinFont\r
+                : ShipLabel.Name.BaseFont;\r
+        }\r
+\r
+        private static string AntiAirPropellantBarrageChance(ShipStatus ship)\r
+        {\r
+            // ReSharper disable once CompareOfFloatsByEqualityOperator\r
+            if (ship.AntiAirPropellantBarrageChance == 0)\r
+                return "";\r
+            var chance = ship.AntiAirPropellantBarrageChance;\r
+            return " 弾幕" + (chance < 100 ? chance.ToString("f1") : ((int)chance).ToString());\r
+        }\r
+\r
         private void CreateLabels()\r
         {\r
             for (var i = _labelList.Count; i < _table.Count; i++)\r
@@ -90,53 +128,40 @@ namespace KancolleSniffer.View
         private void CreateLabels(int i)\r
         {\r
             var y = 1 + LineHeight * i;\r
-            var lbp = new Panel\r
+            var labels = new AntiAirLabels\r
             {\r
-                Location = new Point(0, y),\r
-                Size = new Size(ListForm.PanelWidth, LineHeight),\r
-                BackColor = CustomColors.ColumnColors.BrightFirst(i),\r
-                Visible = false\r
-            };\r
-            Scaler.Scale(lbp);\r
-            lbp.Tag = lbp.Location.Y;\r
-            var labels = new[]\r
-            {\r
-                new ShipLabel {Location = new Point(1, 3), AutoSize = true},\r
-                new ShipLabel {Location = new Point(10, 3), AutoSize = true},\r
-                new ShipLabel {Location = new Point(35, 3), AutoSize = true},\r
-                new ShipLabel {Location = new Point(100, 3), AutoSize = true}\r
+                Fleet = new ShipLabel.Fleet(new Point(1, 3)),\r
+                Name = new ShipLabel.Name(new Point(10, 3), ShipNameWidth.Max),\r
+                Rate = new Label {Location = new Point(35, 3), AutoSize = true},\r
+                Diff = new Label {Location = new Point(100, 3), AutoSize = true},\r
+                BackPanel = new Panel\r
+                {\r
+                    Location = new Point(0, y),\r
+                    Size = new Size(ListForm.PanelWidth, LineHeight)\r
+                }\r
             };\r
             _labelList.Add(labels);\r
-            _panelList.Add(lbp);\r
-            // ReSharper disable once CoVariantArrayConversion\r
-            lbp.Controls.AddRange(labels);\r
-            Controls.Add(lbp);\r
-            foreach (var label in labels)\r
-            {\r
-                Scaler.Scale(label);\r
-                label.BackColor = CustomColors.ColumnColors.BrightFirst(i);\r
-            }\r
+            labels.Arrange(this, CustomColors.ColumnColors.BrightFirst(i));\r
+            labels.Move(AutoScrollPosition);\r
         }\r
 \r
         private void SetRecords()\r
         {\r
             for (var i = 0; i < _table.Count; i++)\r
                 SetRecord(i);\r
-            for (var i = _table.Count; i < _panelList.Count; i++)\r
-                _panelList[i].Visible = false;\r
+            for (var i = _table.Count; i < _labelList.Count; i++)\r
+                _labelList[i].BackPanel.Visible = false;\r
         }\r
 \r
         private void SetRecord(int i)\r
         {\r
-            var lbp = _panelList[i];\r
-            if (!lbp.Visible)\r
-                lbp.Location = new Point(lbp.Left, (int)lbp.Tag + AutoScrollPosition.Y);\r
+            var lbp = _labelList[i].BackPanel;\r
             var column = _table[i];\r
             var labels = _labelList[i];\r
-            labels[0].Text = column.Fleet;\r
-            labels[1].SetName(column.Ship);\r
-            labels[2].Text = column.Rate;\r
-            labels[3].Text = column.Diff;\r
+            labels.Fleet.Text = column.Fleet;\r
+            labels.Name.SetName(column.Ship);\r
+            labels.Rate.Text = column.Rate;\r
+            labels.Diff.Text = column.Diff;\r
             lbp.Visible = true;\r
         }\r
 \r