OSDN Git Service

IUpdatableを導入して処理を簡略化する
authorKazuhiro Fujieda <fujieda@users.osdn.me>
Sat, 4 Apr 2020 08:52:21 +0000 (17:52 +0900)
committerKazuhiro Fujieda <fujieda@users.osdn.me>
Sun, 30 Aug 2020 05:58:21 +0000 (14:58 +0900)
KancolleSniffer/KancolleSniffer.csproj
KancolleSniffer/MainForm.cs
KancolleSniffer/View/HqPanel.cs
KancolleSniffer/View/IUpdateable.cs [new file with mode: 0644]
KancolleSniffer/View/KDockPanel.cs
KancolleSniffer/View/MissionPanel.cs
KancolleSniffer/View/NDockPanel.cs

index 8c15d51..f447478 100644 (file)
@@ -83,6 +83,7 @@
     <Compile Include="Log\BattleLogProcessor.cs" />\r
     <Compile Include="Model\Range.cs" />\r
     <Compile Include="Util\Clipboard.cs" />\r
+    <Compile Include="View\IUpdateable.cs" />\r
     <Compile Include="View\UpdateContext.cs" />\r
     <Compile Include="View\AntiAirPanel.cs">\r
       <SubType>Component</SubType>\r
index ac98745..e16d5dc 100644 (file)
@@ -58,6 +58,7 @@ namespace KancolleSniffer
         private string _debugLogFile;\r
         private IEnumerator<string> _playLog;\r
         private DateTime _prev, _now;\r
+        private IEnumerable<IUpdateable> _updatables;\r
 \r
         private readonly ErrorDialog _errorDialog = new ErrorDialog();\r
         private readonly ErrorLog _errorLog;\r
@@ -98,17 +99,16 @@ namespace KancolleSniffer
             panelRepairList.CreateLabels(panelRepairList_Click);\r
             ndockPanel.SetClickHandler(labelNDock_Click);\r
             missionPanel.SetClickHandler(labelMission_Click);\r
-            SetUpdateContextToView();\r
+            SetupUpdateable();\r
             PerformZoom();\r
         }\r
 \r
-        private void SetUpdateContextToView()\r
+        private void SetupUpdateable()\r
         {\r
+            _updatables = new IUpdateable[] {hqPanel, missionPanel, kdockPanel, ndockPanel};\r
             var context = new UpdateContext(Sniffer, Config, new NotifySubmitter(_notificationManager), () => _now);\r
-            hqPanel.Context = context;\r
-            missionPanel.Context = context;\r
-            kdockPanel.Context = context;\r
-            ndockPanel.Context = context;\r
+            foreach (var updateable in _updatables)\r
+                updateable.Context = context;\r
         }\r
 \r
         private void SetScaleFactorOfDpiScaling()\r
@@ -951,9 +951,8 @@ namespace KancolleSniffer
 \r
         private void UpdateTimers()\r
         {\r
-            missionPanel.UpdateTimers();\r
-            ndockPanel.UpdateTimers();\r
-            kdockPanel.UpdateTimers();\r
+            foreach (var updateable in _updatables)\r
+                updateable.UpdateTimers();\r
             UpdateCondTimers();\r
             UpdateAkashiTimer();\r
             _timerEnabled = true;\r
index f16b14a..1e14e65 100644 (file)
@@ -6,7 +6,7 @@ using KancolleSniffer.Properties;
 \r
 namespace KancolleSniffer.View\r
 {\r
-    public class HqPanel : PanelWithToolTip\r
+    public class HqPanel : PanelWithToolTip, IUpdateable\r
     {\r
         public Label Login { get; } = new Label\r
         {\r
@@ -133,6 +133,10 @@ namespace KancolleSniffer.View
             UpdateAchievement();\r
         }\r
 \r
+        public void UpdateTimers()\r
+        {\r
+        }\r
+\r
         private void UpdateNumOfBuckets()\r
         {\r
             _numOfBuckets.Text = Context.Sniffer.Material.MaterialHistory[(int)Material.Bucket].Now.ToString("D");\r
diff --git a/KancolleSniffer/View/IUpdateable.cs b/KancolleSniffer/View/IUpdateable.cs
new file mode 100644 (file)
index 0000000..632ec2d
--- /dev/null
@@ -0,0 +1,8 @@
+namespace KancolleSniffer.View\r
+{\r
+    public interface IUpdateable\r
+    {\r
+        UpdateContext Context { set; }\r
+        void UpdateTimers();\r
+    }\r
+}
\ No newline at end of file
index 4e342d0..f71054e 100644 (file)
@@ -20,7 +20,7 @@ using KancolleSniffer.Model;
 \r
 namespace KancolleSniffer.View\r
 {\r
-    public class KDockPanel : Panel\r
+    public class KDockPanel : Panel, IUpdateable\r
     {\r
         private const int TopMargin = 3;\r
         private const int LeftMargin = 2;\r
index a0f027c..d41ff07 100644 (file)
@@ -20,7 +20,7 @@ using KancolleSniffer.Model;
 \r
 namespace KancolleSniffer.View\r
 {\r
-    public class MissionPanel : PanelWithToolTip\r
+    public class MissionPanel : PanelWithToolTip, IUpdateable\r
     {\r
         private const int TopMargin = 3;\r
         private const int LeftMargin = 2;\r
index 98ee614..1ef3446 100644 (file)
@@ -20,7 +20,7 @@ using KancolleSniffer.Model;
 \r
 namespace KancolleSniffer.View\r
 {\r
-    public class NDockPanel : Panel\r
+    public class NDockPanel : Panel, IUpdateable\r
     {\r
         private const int TopMargin = 3;\r
         private const int LeftMargin = 2;\r