OSDN Git Service

ShipInfoPanelからBattleInfoPanelとFighterPowerを切り出す
authorKazuhiro Fujieda <fujieda@users.osdn.me>
Tue, 5 May 2020 09:20:55 +0000 (18:20 +0900)
committerKazuhiro Fujieda <fujieda@users.osdn.me>
Sun, 30 Aug 2020 05:58:22 +0000 (14:58 +0900)
KancolleSniffer/KancolleSniffer.csproj
KancolleSniffer/View/MainWindow/BattleInfoPanel.cs [new file with mode: 0644]
KancolleSniffer/View/MainWindow/FighterPower.cs [new file with mode: 0644]
KancolleSniffer/View/MainWindow/ShipInfoPanel.cs
KancolleSniffer/View/PanelWithToolTip.cs

index 6a9091c..fe17894 100644 (file)
@@ -87,6 +87,9 @@
     <Compile Include="Util\Clipboard.cs" />\r
     <Compile Include="Util\SoundPlayer.cs" />\r
     <Compile Include="Util\TimeStep.cs" />\r
+    <Compile Include="View\MainWindow\BattleInfoPanel.cs">\r
+      <SubType>Component</SubType>\r
+    </Compile>\r
     <Compile Include="View\MainWindow\ChargeStatus.cs">\r
       <SubType>Component</SubType>\r
     </Compile>\r
       <SubType>Component</SubType>\r
     </Compile>\r
     <Compile Include="View\IUpdateable.cs" />\r
+    <Compile Include="View\MainWindow\FighterPower.cs" />\r
     <Compile Include="View\MainWindow\MainFleetPanel.cs">\r
       <SubType>Component</SubType>\r
     </Compile>\r
diff --git a/KancolleSniffer/View/MainWindow/BattleInfoPanel.cs b/KancolleSniffer/View/MainWindow/BattleInfoPanel.cs
new file mode 100644 (file)
index 0000000..3d0737c
--- /dev/null
@@ -0,0 +1,99 @@
+// Copyright (C) 2020 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.Drawing;\r
+using System.Windows.Forms;\r
+using KancolleSniffer.Model;\r
+\r
+namespace KancolleSniffer.View.MainWindow\r
+{\r
+    public class BattleInfoPanel : Panel\r
+    {\r
+        private readonly Label _enemyFighterPower = new Label\r
+        {\r
+            Location = new Point(129, 1),\r
+            Size = new Size(29, 12),\r
+            TextAlign = ContentAlignment.MiddleRight\r
+        };\r
+\r
+        private readonly Label _enemyFighterPowerCaption = new Label\r
+        {\r
+            AutoSize = true,\r
+            Location = new Point(90, 1),\r
+            Text = "敵制空"\r
+        };\r
+\r
+        private readonly Label _formation = new Label\r
+        {\r
+            Location = new Point(40, 1),\r
+            Size = new Size(48, 12)\r
+        };\r
+\r
+        private readonly Label _resultRank = new Label\r
+        {\r
+            Location = new Point(1, 1),\r
+            Size = new Size(42, 12),\r
+            TabIndex = 0,\r
+            Text = "判定"\r
+        };\r
+\r
+        public UpdateContext Context { private get; set; }\r
+\r
+        private ToolTip ToolTip => ((PanelWithToolTip)Parent).ToolTip;\r
+\r
+        public BattleInfoPanel()\r
+        {\r
+            Controls.AddRange(new Control[] {_enemyFighterPower, _enemyFighterPowerCaption, _formation, _resultRank});\r
+            _resultRank.Click += (sender, e) => ShowResultRank();\r
+        }\r
+\r
+        public new void Update()\r
+        {\r
+            BringToFront();\r
+            var battle = Context.Sniffer.Battle;\r
+            _formation.Text = new[] {"同航戦", "反航戦", "T字有利", "T字不利"}[battle.Formation[2] - 1];\r
+            UpdateBattleFighterPower();\r
+            if ((Context.Config.Spoilers & Spoiler.ResultRank) != 0)\r
+                ShowResultRank();\r
+        }\r
+\r
+        public void Reset()\r
+        {\r
+            _formation.Text = "";\r
+            _enemyFighterPower.Text = "";\r
+            _resultRank.Text = "判定";\r
+            Visible = Context.Sniffer.Battle.BattleState != BattleState.None;\r
+        }\r
+\r
+        private void UpdateBattleFighterPower()\r
+        {\r
+            UpdateEnemyFighterPower();\r
+        }\r
+\r
+        private void UpdateEnemyFighterPower()\r
+        {\r
+            var fp = Context.Sniffer.Battle.EnemyFighterPower;\r
+            _enemyFighterPower.Text = fp.AirCombat + fp.UnknownMark;\r
+            var toolTip = fp.AirCombat == fp.Interception ? "" : "防空: " + fp.Interception + fp.UnknownMark;\r
+            ToolTip.SetToolTip(_enemyFighterPower, toolTip);\r
+            ToolTip.SetToolTip(_enemyFighterPowerCaption, toolTip);\r
+        }\r
+\r
+        private void ShowResultRank()\r
+        {\r
+            var result = new[] {"完全S", "勝利S", "勝利A", "勝利B", "敗北C", "敗北D", "敗北E"};\r
+            _resultRank.Text = result[(int)Context.Sniffer.Battle.ResultRank];\r
+        }\r
+    }\r
+}
\ No newline at end of file
diff --git a/KancolleSniffer/View/MainWindow/FighterPower.cs b/KancolleSniffer/View/MainWindow/FighterPower.cs
new file mode 100644 (file)
index 0000000..d49e08b
--- /dev/null
@@ -0,0 +1,119 @@
+// Copyright (C) 2020 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.Drawing;\r
+using System.Windows.Forms;\r
+using KancolleSniffer.Model;\r
+\r
+namespace KancolleSniffer.View.MainWindow\r
+{\r
+    public class FighterPower\r
+    {\r
+        private readonly Label _fighterPower = new Label\r
+        {\r
+            Location = new Point(28, 117),\r
+            Size = new Size(29, 12),\r
+            Text = "0",\r
+            TextAlign = ContentAlignment.MiddleRight\r
+        };\r
+\r
+        private readonly Label _fighterPowerCaption = new Label\r
+        {\r
+            AutoSize = true,\r
+            Location = new Point(2, 117),\r
+            Text = "制空"\r
+        };\r
+\r
+        private readonly ShipInfoPanel _parent;\r
+\r
+        public UpdateContext Context { private get; set; }\r
+\r
+        public FighterPower(ShipInfoPanel parent)\r
+        {\r
+            _parent = parent;\r
+            parent.Controls.AddRange(new Control[] {_fighterPowerCaption, _fighterPower});\r
+        }\r
+\r
+        public void Reset()\r
+        {\r
+            _fighterPower.ForeColor = Control.DefaultForeColor;\r
+            _fighterPowerCaption.Text = "制空";\r
+        }\r
+\r
+        public void UpdateFighterPower()\r
+        {\r
+            UpdateFighterPower(IsCombinedFighterPower);\r
+        }\r
+\r
+        private bool IsCombinedFighterPower => _parent.CombinedFleet &&\r
+                                               (Context.Sniffer.Battle.BattleState == BattleState.None ||\r
+                                                Context.Sniffer.Battle.EnemyIsCombined);\r
+\r
+        private void UpdateFighterPower(bool combined)\r
+        {\r
+            var fleets = Context.Sniffer.Fleets;\r
+            var fp = combined\r
+                ? fleets[0].FighterPower + fleets[1].FighterPower\r
+                : fleets[_parent.CurrentFleet].FighterPower;\r
+            _fighterPower.Text = fp.Min.ToString("D");\r
+            var cr = combined\r
+                ? fleets[0].ContactTriggerRate + fleets[1].ContactTriggerRate\r
+                : fleets[_parent.CurrentFleet].ContactTriggerRate;\r
+            var text = "制空: " + (fp.Diff ? fp.RangeString : fp.Min.ToString()) +\r
+                       $" 触接: {cr * 100:f1}";\r
+            _parent.ToolTip.SetToolTip(_fighterPower, text);\r
+            _parent.ToolTip.SetToolTip(_fighterPowerCaption, text);\r
+        }\r
+\r
+        public void UpdateBattleFighterPower()\r
+        {\r
+            var battle = Context.Sniffer.Battle;\r
+            _fighterPower.ForeColor = AirControlLevelColor(battle);\r
+            _fighterPowerCaption.Text = AirControlLevelString(battle);\r
+            if (battle.BattleState == BattleState.AirRaid)\r
+            {\r
+                UpdateAirRaidFighterPower();\r
+            }\r
+            else\r
+            {\r
+                UpdateFighterPower(Context.Sniffer.IsCombinedFleet && battle.EnemyIsCombined);\r
+            }\r
+        }\r
+\r
+        private void UpdateAirRaidFighterPower()\r
+        {\r
+            var fp = Context.Sniffer.Battle.FighterPower;\r
+            _fighterPower.Text = fp.Min.ToString();\r
+            var toolTop = fp.Diff ? fp.RangeString : "";\r
+            _parent.ToolTip.SetToolTip(_fighterPower, toolTop);\r
+            _parent.ToolTip.SetToolTip(_fighterPowerCaption, toolTop);\r
+        }\r
+\r
+        private static Color AirControlLevelColor(BattleInfo battle)\r
+        {\r
+            return new[]\r
+            {\r
+                Control.DefaultForeColor, Control.DefaultForeColor, CUDColors.Blue, CUDColors.Green, CUDColors.Orange,\r
+                CUDColors.Red\r
+            }[\r
+                battle.BattleState == BattleState.Night ? 0 : battle.AirControlLevel + 1];\r
+        }\r
+\r
+        private static string AirControlLevelString(BattleInfo battle)\r
+        {\r
+            return new[] {"制空", "拮抗", "確保", "優勢", "劣勢", "喪失"}[\r
+                battle.BattleState == BattleState.Night ? 0 : battle.AirControlLevel + 1];\r
+        }\r
+    }\r
+}
\ No newline at end of file
index a39a563..251a8fb 100644 (file)
@@ -22,13 +22,15 @@ namespace KancolleSniffer.View.MainWindow
             Visible = false\r
         };\r
 \r
-        private readonly Panel _battleInfo = new Panel\r
+        private readonly BattleInfoPanel _battleInfo = new BattleInfoPanel\r
         {\r
             Location = new Point(59, 116),\r
             Size = new Size(157, 14),\r
             Visible = false\r
         };\r
 \r
+        private readonly FighterPower _fighterPower;\r
+\r
         private readonly Label _presetAkashiTimer = new Label\r
         {\r
             Location = new Point(2, 3),\r
@@ -45,34 +47,6 @@ namespace KancolleSniffer.View.MainWindow
             Text = "右クリックでメニューが出ます。"\r
         };\r
 \r
-        private readonly Label _enemyFighterPower = new Label\r
-        {\r
-            Location = new Point(129, 1),\r
-            Size = new Size(29, 12),\r
-            TextAlign = ContentAlignment.MiddleRight\r
-        };\r
-\r
-        private readonly Label _enemyFighterPowerCaption = new Label\r
-        {\r
-            AutoSize = true,\r
-            Location = new Point(90, 1),\r
-            Text = "敵制空"\r
-        };\r
-\r
-        private readonly Label _formation = new Label\r
-        {\r
-            Location = new Point(40, 1),\r
-            Size = new Size(48, 12)\r
-        };\r
-\r
-        private readonly Label _resultRank = new Label\r
-        {\r
-            Location = new Point(1, 1),\r
-            Size = new Size(42, 12),\r
-            TabIndex = 0,\r
-            Text = "判定"\r
-        };\r
-\r
         private readonly Label _lineOfSight = new Label\r
         {\r
             Location = new Point(85, 117),\r
@@ -88,21 +62,6 @@ namespace KancolleSniffer.View.MainWindow
             Text = "索敵"\r
         };\r
 \r
-        private readonly Label _fighterPower = new Label\r
-        {\r
-            Location = new Point(28, 117),\r
-            Size = new Size(29, 12),\r
-            Text = "0",\r
-            TextAlign = ContentAlignment.MiddleRight\r
-        };\r
-\r
-        private readonly Label _fighterPowerCaption = new Label\r
-        {\r
-            AutoSize = true,\r
-            Location = new Point(2, 117),\r
-            Text = "制空"\r
-        };\r
-\r
         private readonly Label _condTimerCaption = new Label\r
         {\r
             Location = new Point(128, 117),\r
@@ -117,7 +76,13 @@ namespace KancolleSniffer.View.MainWindow
 \r
         private readonly MainShipLabels _mainLabels = new MainShipLabels();\r
 \r
-        public UpdateContext Context { get; set; }\r
+        private UpdateContext _context;\r
+\r
+        public UpdateContext Context\r
+        {\r
+            get => _context;\r
+            set => _battleInfo.Context = _fighterPower.Context = _context = value;\r
+        }\r
 \r
         public int CurrentFleet { get; set; }\r
 \r
@@ -135,17 +100,12 @@ namespace KancolleSniffer.View.MainWindow
                 Panel7Ships = _7Ships,\r
                 PanelCombinedFleet = _combinedFleet\r
             }, ShipClickHandler);\r
-            _battleInfo.Controls.AddRange(new Control[]\r
-            {\r
-                _enemyFighterPower, _enemyFighterPowerCaption, _formation, _resultRank\r
-            });\r
             Controls.AddRange(new Control[]\r
             {\r
                 _battleInfo,\r
-                _lineOfSight, _lineOfSightCaption, _fighterPower, _fighterPowerCaption, _condTimer, _condTimerCaption\r
+                _lineOfSight, _lineOfSightCaption, _condTimer, _condTimerCaption\r
             });\r
-            _resultRank.Click += ResultRankClick;\r
-            Size = new Size(220, 134);\r
+            _fighterPower = new FighterPower(this);\r
         }\r
 \r
         private void ShipClickHandler(object sender, EventArgs e)\r
@@ -209,7 +169,7 @@ namespace KancolleSniffer.View.MainWindow
             ShowCombinedFleet();\r
             _presetAkashiTimer.Visible = Context.Config.UsePresetAkashi;\r
             UpdateAkashiTimer();\r
-            UpdateFighterPower(IsCombinedFighterPower);\r
+            _fighterPower.UpdateFighterPower();\r
             UpdateLoS();\r
             UpdateCondTimers();\r
         }\r
@@ -226,26 +186,6 @@ namespace KancolleSniffer.View.MainWindow
             }\r
         }\r
 \r
-        private bool IsCombinedFighterPower => CombinedFleet &&\r
-                                               (Context.Sniffer.Battle.BattleState == BattleState.None ||\r
-                                                Context.Sniffer.Battle.EnemyIsCombined);\r
-\r
-        private void UpdateFighterPower(bool combined)\r
-        {\r
-            var fleets = Context.Sniffer.Fleets;\r
-            var fp = combined\r
-                ? fleets[0].FighterPower + fleets[1].FighterPower\r
-                : fleets[CurrentFleet].FighterPower;\r
-            _fighterPower.Text = fp.Min.ToString("D");\r
-            var cr = combined\r
-                ? fleets[0].ContactTriggerRate + fleets[1].ContactTriggerRate\r
-                : fleets[CurrentFleet].ContactTriggerRate;\r
-            var text = "制空: " + (fp.Diff ? fp.RangeString : fp.Min.ToString()) +\r
-                       $" 触接: {cr * 100:f1}";\r
-            ToolTip.SetToolTip(_fighterPower, text);\r
-            ToolTip.SetToolTip(_fighterPowerCaption, text);\r
-        }\r
-\r
         private void UpdateLoS()\r
         {\r
             var fleet = Context.Sniffer.Fleets[CurrentFleet];\r
@@ -267,80 +207,14 @@ namespace KancolleSniffer.View.MainWindow
             ResetBattleInfo();\r
             if (Context.Sniffer.Battle.BattleState == BattleState.None)\r
                 return;\r
-            _battleInfo.BringToFront();\r
-            var battle = Context.Sniffer.Battle;\r
-            _formation.Text = new[] {"同航戦", "反航戦", "T字有利", "T字不利"}[battle.Formation[2] - 1];\r
-            UpdateBattleFighterPower();\r
-            if ((Context.Config.Spoilers & Spoiler.ResultRank) != 0)\r
-                ShowResultRank();\r
+            _battleInfo.Update();\r
+            _fighterPower.UpdateBattleFighterPower();\r
         }\r
 \r
         private void ResetBattleInfo()\r
         {\r
-            _formation.Text = "";\r
-            _enemyFighterPower.Text = "";\r
-            _fighterPower.ForeColor = DefaultForeColor;\r
-            _fighterPowerCaption.Text = "制空";\r
-            _resultRank.Text = "判定";\r
-            _battleInfo.Visible = Context.Sniffer.Battle.BattleState != BattleState.None;\r
-        }\r
-\r
-        private void UpdateBattleFighterPower()\r
-        {\r
-            UpdateEnemyFighterPower();\r
-            var battle = Context.Sniffer.Battle;\r
-            _fighterPower.ForeColor = AirControlLevelColor(battle);\r
-            _fighterPowerCaption.Text = AirControlLevelString(battle);\r
-            if (battle.BattleState == BattleState.AirRaid)\r
-            {\r
-                UpdateAirRaidFighterPower();\r
-            }\r
-            else\r
-            {\r
-                UpdateFighterPower(Context.Sniffer.IsCombinedFleet && battle.EnemyIsCombined);\r
-            }\r
-        }\r
-\r
-        private void UpdateEnemyFighterPower()\r
-        {\r
-            var fp = Context.Sniffer.Battle.EnemyFighterPower;\r
-            _enemyFighterPower.Text = fp.AirCombat + fp.UnknownMark;\r
-            var toolTip = fp.AirCombat == fp.Interception ? "" : "防空: " + fp.Interception + fp.UnknownMark;\r
-            ToolTip.SetToolTip(_enemyFighterPower, toolTip);\r
-            ToolTip.SetToolTip(_enemyFighterPowerCaption, toolTip);\r
-        }\r
-\r
-        private void UpdateAirRaidFighterPower()\r
-        {\r
-            var fp = Context.Sniffer.Battle.FighterPower;\r
-            _fighterPower.Text = fp.Min.ToString();\r
-            var toolTop = fp.Diff ? fp.RangeString : "";\r
-            ToolTip.SetToolTip(_fighterPower, toolTop);\r
-            ToolTip.SetToolTip(_fighterPowerCaption, toolTop);\r
-        }\r
-\r
-        private static Color AirControlLevelColor(BattleInfo battle)\r
-        {\r
-            return new[]\r
-                {DefaultForeColor, DefaultForeColor, CUDColors.Blue, CUDColors.Green, CUDColors.Orange, CUDColors.Red}[\r
-                battle.BattleState == BattleState.Night ? 0 : battle.AirControlLevel + 1];\r
-        }\r
-\r
-        private static string AirControlLevelString(BattleInfo battle)\r
-        {\r
-            return new[] {"制空", "拮抗", "確保", "優勢", "劣勢", "喪失"}[\r
-                battle.BattleState == BattleState.Night ? 0 : battle.AirControlLevel + 1];\r
-        }\r
-\r
-        private void ShowResultRank()\r
-        {\r
-            var result = new[] {"完全S", "勝利S", "勝利A", "勝利B", "敗北C", "敗北D", "敗北E"};\r
-            _resultRank.Text = result[(int)Context.Sniffer.Battle.ResultRank];\r
-        }\r
-\r
-        private void ResultRankClick(object sender, EventArgs e)\r
-        {\r
-            ShowResultRank();\r
+            _battleInfo.Reset();\r
+            _fighterPower.Reset();\r
         }\r
 \r
         private void UpdateCondTimers()\r
index 68e9cbe..925fc7a 100644 (file)
@@ -19,7 +19,7 @@ namespace KancolleSniffer.View
 {\r
     public class PanelWithToolTip : Panel\r
     {\r
-        protected ResizableToolTip ToolTip { get; } = new ResizableToolTip();\r
+        public ResizableToolTip ToolTip { get; } = new ResizableToolTip();\r
 \r
         protected sealed override void ScaleControl(SizeF factor, BoundsSpecified specified)\r
         {\r