OSDN Git Service

Settingsクラスを廃止する
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / View / ShipListPanel / ShipListPanel.cs
index c261418..bf590c4 100644 (file)
@@ -17,17 +17,19 @@ using System.Collections.Generic;
 using System.Linq;\r
 using System.Runtime.InteropServices;\r
 using System.Windows.Forms;\r
+using KancolleSniffer.Forms;\r
 using KancolleSniffer.Model;\r
+using KancolleSniffer.View.ListWindow;\r
 using static System.Math;\r
 \r
 namespace KancolleSniffer.View.ShipListPanel\r
 {\r
-    public class ShipListPanel : Panel\r
+    public class ShipListPanel : Panel, IPanelResize\r
     {\r
         public const int LabelHeight = 12;\r
         public const int LineHeight = 16;\r
         private ShipStatus[] _shipList;\r
-        private readonly List<ShipLabel> _hpLabels = new List<ShipLabel>();\r
+        private readonly List<ShipLabel.Hp> _hpLabels = new List<ShipLabel.Hp>();\r
         private readonly ShipListLabels _shipListLabels;\r
         private readonly GroupConfigLabels _groupConfigLabels;\r
         private readonly RepairListLabels _repairListLabels;\r
@@ -67,13 +69,13 @@ namespace KancolleSniffer.View.ShipListPanel
             ResumeDrawing();\r
         }\r
 \r
-        protected override void OnResize(EventArgs ev)\r
+        public void ApplyResize()\r
         {\r
-            base.OnResize(ev);\r
             if (_shipList == null || _shipList.Length == 0 || !Visible)\r
                 return;\r
             SuspendDrawing();\r
             SetupLabels();\r
+            ResizeLabels();\r
             SetShipLabels();\r
             ResumeDrawing();\r
         }\r
@@ -86,18 +88,19 @@ namespace KancolleSniffer.View.ShipListPanel
                 ScrollBar.Value - e.Delta * SystemInformation.MouseWheelScrollLines / 120));\r
         }\r
 \r
-        public void Update(Sniffer sniffer, string mode, ShipListConfig config)\r
+        public void Update(Sniffer sniffer, string mode, ShipListConfig settings)\r
         {\r
             _mode = mode;\r
-            CreateShipList(sniffer, config);\r
+            CreateShipList(sniffer, settings);\r
             SuspendDrawing();\r
             SetupLabels();\r
+            ResizeLabels();\r
             SetShipLabels();\r
             ResumeDrawing();\r
         }\r
 \r
         [DllImport("user32.dll")]\r
-        public static extern int SendMessage(IntPtr hWnd, int wMsg, bool wParam, IntPtr lParam);\r
+        private static extern int SendMessage(IntPtr hWnd, int wMsg, bool wParam, IntPtr lParam);\r
 \r
         private void SuspendDrawing()\r
         {\r
@@ -105,20 +108,20 @@ namespace KancolleSniffer.View.ShipListPanel
             SuspendLayout();\r
         }\r
 \r
-        public void ResumeDrawing()\r
+        private void ResumeDrawing()\r
         {\r
             ResumeLayout();\r
             SendMessage(Handle, 11, true, IntPtr.Zero);\r
             Refresh();\r
         }\r
 \r
-        private void CreateShipList(Sniffer sniffer, ShipListConfig config)\r
+        private void CreateShipList(Sniffer sniffer, ShipListConfig settings)\r
         {\r
             var ships = FilterByShipTypes(\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
+                settings.ShipCategories).ToArray();\r
+            var order = _mode == "修復" ? ListForm.SortOrder.Repair : settings.SortOrder;\r
+            if (!settings.ShipType)\r
             {\r
                 _shipList = ships.OrderBy(s => s, new CompareShip(false, order)).ToArray();\r
                 return;\r
@@ -190,7 +193,7 @@ namespace KancolleSniffer.View.ShipListPanel
             return res;\r
         }\r
 \r
-        private IEnumerable<ShipStatus> FilterByShipTypes(IEnumerable<ShipStatus> ships, ShipCategory shipTypes)\r
+        private static IEnumerable<ShipStatus> FilterByShipTypes(IEnumerable<ShipStatus> ships, ShipCategory shipTypes)\r
         {\r
             var ids = Enumerable.Range(0, ShipTypeIds.Length)\r
                 .Where(type => ((int)shipTypes & (1 << type)) != 0)\r
@@ -298,7 +301,18 @@ namespace KancolleSniffer.View.ShipListPanel
             ScrollBar.Value = Min(ScrollBar.Value, max);\r
         }\r
 \r
-        public void SetHpPercent(ShipLabel label)\r
+        private void ResizeLabels()\r
+        {\r
+            var width = Width - SystemInformation.VerticalScrollBarWidth - 2;\r
+            for (var i = 0; i < _labelCount; i++)\r
+            {\r
+                _shipListLabels.Resize(i, width);\r
+                _groupConfigLabels.Resize(i, width);\r
+                _repairListLabels.Resize(i, width);\r
+            }\r
+        }\r
+\r
+        public void SetHpPercent(ShipLabel.Hp label)\r
         {\r
             if (_hpPercent)\r
                 label.ToggleHpPercent();\r