OSDN Git Service

再度の遠征や入渠までタイマーをリピートできるようにする
authorKazuhiro Fujieda <fujieda@users.osdn.me>
Mon, 11 Dec 2017 11:09:43 +0000 (20:09 +0900)
committerKazuhiro Fujieda <fujieda@users.osdn.me>
Sat, 27 Jan 2018 08:33:54 +0000 (17:33 +0900)
KancolleSniffer.Test/NotificationManagerTest.cs
KancolleSniffer/Config.cs
KancolleSniffer/ConfigDialog.cs
KancolleSniffer/MainForm.cs
KancolleSniffer/NotificationConfigDialog.Designer.cs
KancolleSniffer/NotificationConfigDialog.cs
KancolleSniffer/NotificationManager.cs
KancolleSniffer/Sniffer.cs

index 506d914..6cdf0f0 100644 (file)
@@ -337,5 +337,45 @@ namespace KancolleSniffer.Test
                 timer.ElapseTime(1000);\r
             }\r
         }\r
+\r
+        /// <summary>\r
+        /// リピート中の特定の通知を止める\r
+        /// </summary>\r
+        [TestMethod]\r
+        public void StopSpecificRepeatingNotification()\r
+        {\r
+            var timer = new MockTimer();\r
+            Message result = null;\r
+            var manager =\r
+                new NotificationManager((t, b, n) => { result = new Message {Title = t, Body = b, Name = n}; }, timer);\r
+            var expected1 = new Message {Title = "遠征が終わりました", Body = "防空射撃演習", Name = "遠征終了"};\r
+            var expected2 = new Message {Title = "遠征が終わりました", Body = "海上護衛任務", Name = "遠征終了"};\r
+            while (true)\r
+            {\r
+                switch (timer.Elapsed)\r
+                {\r
+                    case 0:\r
+                        manager.Enqueue("遠征終了", 1, "防空射撃演習", 10);\r
+                        manager.Enqueue("遠征終了", 2, "海上護衛任務", 10);\r
+                        PAssert.That(() => expected1.Equals(result));\r
+                        break;\r
+                    case 2000:\r
+                        PAssert.That(() => expected2.Equals(result));\r
+                        break;\r
+                    case 5000:\r
+                        manager.StopRepeat("遠征終了", 1);\r
+                        break;\r
+                    case 12000:\r
+                        PAssert.That(() => expected2.Equals(result));\r
+                        return;\r
+                    default:\r
+                        PAssert.That(() => result == null, timer.Elapsed.ToString());\r
+                        break;\r
+\r
+                }\r
+                result = null;\r
+                timer.ElapseTime(1000);\r
+            }\r
+        }\r
     }\r
 }
\ No newline at end of file
index bc883e9..1309d8e 100644 (file)
@@ -123,7 +123,8 @@ namespace KancolleSniffer
         All = (1 << 3) - 1,\r
         Pushbullet = 1 << 3,\r
         Push = 1 << 4,\r
-        Repeat = 1 << 5\r
+        Repeat = 1 << 5,\r
+        Cont = 1 << 6\r
     }\r
 \r
 \r
index a463628..e2a5368 100644 (file)
@@ -171,7 +171,8 @@ namespace KancolleSniffer
                 var old = _config.Notifications[name];\r
                 var cur = _notificationSettings[name];\r
                 if (repeatOff || old.RepeatInterval != cur.RepeatInterval ||\r
-                    (cur.Flags & NotificationType.Repeat) == 0)\r
+                    (cur.Flags & NotificationType.Repeat) == 0 ||\r
+                    (cur.Flags & NotificationType.Cont) == 0)\r
                 {\r
                     RepeatSettingsChanged.Add(name);\r
                 }\r
index 3dfb143..5d3e18f 100644 (file)
@@ -90,19 +90,27 @@ namespace KancolleSniffer
             PerformZoom();\r
             _shipLabels.AdjustAkashiTimers();\r
             _sniffer.LoadState();\r
-            _sniffer.RepeatingTimerController = new RepeatingTimerController(_notificationManager);\r
+            _sniffer.RepeatingTimerController = new RepeatingTimerController(_notificationManager, _config);\r
         }\r
 \r
         private class RepeatingTimerController : Sniffer.IRepeatingTimerController\r
         {\r
             private readonly NotificationManager _manager;\r
+            private readonly Config _config;\r
 \r
-            public RepeatingTimerController(NotificationManager manager)\r
+            public RepeatingTimerController(NotificationManager manager, Config config)\r
             {\r
                 _manager = manager;\r
+                _config = config;\r
             }\r
 \r
-            public void Stop(string key) => _manager.StopRepeat(key);\r
+            public void Stop(string key)\r
+            {\r
+                if ((_config.Notifications[key].Flags & NotificationType.Cont) == 0)\r
+                    _manager.StopRepeat(key);\r
+            }\r
+\r
+            public void Stop(string key, int fleet) => _manager.StopRepeat(key, fleet);\r
 \r
             public void Suspend() => _manager.SuspendRepeat();\r
 \r
@@ -718,16 +726,16 @@ namespace KancolleSniffer
 \r
         private void UpdateTimers()\r
         {\r
-            foreach (var entry in\r
-                new[] {labelMission1, labelMission2, labelMission3}.Zip(_sniffer.Missions,\r
-                    (label, mission) => new {label, mission.Name, mission.Timer}))\r
+            var mission = new[] {labelMission1, labelMission2, labelMission3};\r
+            for (var i = 0; i < mission.Length; i++)\r
             {\r
+                var entry = _sniffer.Missions[i];\r
                 entry.Timer.Update();\r
-                SetTimerColor(entry.label, entry.Timer);\r
-                entry.label.Text = entry.Timer.ToString(_missionFinishTimeMode);\r
+                SetTimerColor(mission[i], entry.Timer);\r
+                mission[i].Text = entry.Timer.ToString(_missionFinishTimeMode);\r
                 if (!entry.Timer.NeedRing)\r
                     continue;\r
-                SetNotification("遠征終了", entry.Name);\r
+                SetNotification("遠征終了", i + 1, entry.Name);\r
                 entry.Timer.NeedRing = false;\r
             }\r
             for (var i = 0; i < _sniffer.NDock.Length; i++)\r
@@ -737,7 +745,7 @@ namespace KancolleSniffer
                 _shipLabels.SetNDockTimer(i, entry.Timer, _ndockFinishTimeMode);\r
                 if (!entry.Timer.NeedRing)\r
                     continue;\r
-                SetNotification("入渠終了", entry.Name);\r
+                SetNotification("入渠終了", i, entry.Name);\r
                 entry.Timer.NeedRing = false;\r
             }\r
             var kdock = new[] {labelConstruct1, labelConstruct2, labelConstruct3, labelConstruct4};\r
index 27a6a1f..aafa16d 100644 (file)
             this.checkBoxRepeat = new System.Windows.Forms.CheckBox();\r
             this.textBoxRepeat = new System.Windows.Forms.TextBox();\r
             this.labelRepeat = new System.Windows.Forms.Label();\r
+            this.checkBoxCont = new System.Windows.Forms.CheckBox();\r
             this.SuspendLayout();\r
             // \r
             // listBoxNotifications\r
             // \r
+            this.listBoxNotifications.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) \r
+            | System.Windows.Forms.AnchorStyles.Right)));\r
             this.listBoxNotifications.FormattingEnabled = true;\r
             this.listBoxNotifications.ItemHeight = 12;\r
             this.listBoxNotifications.Location = new System.Drawing.Point(12, 12);\r
             this.listBoxNotifications.Name = "listBoxNotifications";\r
-            this.listBoxNotifications.Size = new System.Drawing.Size(204, 88);\r
+            this.listBoxNotifications.Size = new System.Drawing.Size(264, 88);\r
             this.listBoxNotifications.TabIndex = 0;\r
             this.listBoxNotifications.SelectedIndexChanged += new System.EventHandler(this.listBoxNotifications_SelectedIndexChanged);\r
             // \r
@@ -84,9 +87,9 @@
             // \r
             // buttonClose\r
             // \r
-            this.buttonClose.Anchor = System.Windows.Forms.AnchorStyles.Bottom;\r
+            this.buttonClose.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));\r
             this.buttonClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;\r
-            this.buttonClose.Location = new System.Drawing.Point(141, 157);\r
+            this.buttonClose.Location = new System.Drawing.Point(201, 151);\r
             this.buttonClose.Name = "buttonClose";\r
             this.buttonClose.Size = new System.Drawing.Size(75, 23);\r
             this.buttonClose.TabIndex = 6;\r
             // checkBoxPush\r
             // \r
             this.checkBoxPush.AutoSize = true;\r
-            this.checkBoxPush.Location = new System.Drawing.Point(12, 128);\r
+            this.checkBoxPush.Location = new System.Drawing.Point(218, 106);\r
             this.checkBoxPush.Name = "checkBoxPush";\r
-            this.checkBoxPush.Size = new System.Drawing.Size(82, 16);\r
+            this.checkBoxPush.Size = new System.Drawing.Size(58, 16);\r
             this.checkBoxPush.TabIndex = 7;\r
-            this.checkBoxPush.Text = "プッシュ通知";\r
+            this.checkBoxPush.Text = "プッシュ";\r
             this.checkBoxPush.UseVisualStyleBackColor = true;\r
             this.checkBoxPush.CheckedChanged += new System.EventHandler(this.checkBox_CheckedChanged);\r
             // \r
             // checkBoxRepeat\r
             // \r
             this.checkBoxRepeat.AutoSize = true;\r
-            this.checkBoxRepeat.Location = new System.Drawing.Point(100, 128);\r
+            this.checkBoxRepeat.Location = new System.Drawing.Point(12, 134);\r
             this.checkBoxRepeat.Name = "checkBoxRepeat";\r
             this.checkBoxRepeat.Size = new System.Drawing.Size(58, 16);\r
             this.checkBoxRepeat.TabIndex = 8;\r
             // \r
             // textBoxRepeat\r
             // \r
-            this.textBoxRepeat.Location = new System.Drawing.Point(155, 126);\r
+            this.textBoxRepeat.Location = new System.Drawing.Point(67, 132);\r
             this.textBoxRepeat.Name = "textBoxRepeat";\r
             this.textBoxRepeat.Size = new System.Drawing.Size(26, 19);\r
             this.textBoxRepeat.TabIndex = 9;\r
             // labelRepeat\r
             // \r
             this.labelRepeat.AutoSize = true;\r
-            this.labelRepeat.Location = new System.Drawing.Point(183, 129);\r
+            this.labelRepeat.Location = new System.Drawing.Point(95, 135);\r
             this.labelRepeat.Name = "labelRepeat";\r
             this.labelRepeat.Size = new System.Drawing.Size(17, 12);\r
             this.labelRepeat.TabIndex = 10;\r
             this.labelRepeat.Text = "秒";\r
             // \r
+            // checkBoxCont\r
+            // \r
+            this.checkBoxCont.AutoSize = true;\r
+            this.checkBoxCont.Location = new System.Drawing.Point(112, 134);\r
+            this.checkBoxCont.Name = "checkBoxCont";\r
+            this.checkBoxCont.Size = new System.Drawing.Size(48, 16);\r
+            this.checkBoxCont.TabIndex = 11;\r
+            this.checkBoxCont.Text = "継続";\r
+            this.checkBoxCont.UseVisualStyleBackColor = true;\r
+            this.checkBoxCont.CheckedChanged += new System.EventHandler(this.checkBox_CheckedChanged);\r
+            // \r
             // NotificationConfigDialog\r
             // \r
             this.AcceptButton = this.buttonClose;\r
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);\r
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;\r
             this.CancelButton = this.buttonClose;\r
-            this.ClientSize = new System.Drawing.Size(228, 188);\r
+            this.ClientSize = new System.Drawing.Size(288, 185);\r
+            this.Controls.Add(this.checkBoxCont);\r
             this.Controls.Add(this.labelRepeat);\r
             this.Controls.Add(this.textBoxRepeat);\r
             this.Controls.Add(this.checkBoxRepeat);\r
             this.Controls.Add(this.checkBoxShowBaloonTip);\r
             this.Controls.Add(this.checkBoxFlashWindow);\r
             this.Controls.Add(this.listBoxNotifications);\r
+            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;\r
             this.MaximizeBox = false;\r
             this.MinimizeBox = false;\r
             this.Name = "NotificationConfigDialog";\r
         private System.Windows.Forms.CheckBox checkBoxRepeat;\r
         private System.Windows.Forms.TextBox textBoxRepeat;\r
         private System.Windows.Forms.Label labelRepeat;\r
+        private System.Windows.Forms.CheckBox checkBoxCont;\r
     }\r
 }
\ No newline at end of file
index 1712bcd..9f6c9ed 100644 (file)
@@ -8,6 +8,7 @@ namespace KancolleSniffer
     {\r
         private readonly Dictionary<string, NotificationSpec> _notifications;\r
         private readonly Dictionary<NotificationType, CheckBox> _configCheckBoxs;\r
+        private readonly ToolTip _tooltip = new ToolTip();\r
 \r
         public NotificationConfigDialog(Dictionary<string, NotificationSpec> notifications,\r
             Dictionary<NotificationType, CheckBox> checkBoxs)\r
@@ -21,6 +22,7 @@ namespace KancolleSniffer
             checkBoxPlaySound.Tag = NotificationType.PlaySound;\r
             checkBoxPush.Tag = NotificationType.Push;\r
             checkBoxRepeat.Tag = NotificationType.Repeat;\r
+            checkBoxCont.Tag = NotificationType.Cont;\r
 \r
             // ReSharper disable once CoVariantArrayConversion\r
             listBoxNotifications.Items.AddRange(Config.NotificationNames);\r
@@ -36,12 +38,13 @@ namespace KancolleSniffer
                 case "艦娘数超過":\r
                 case "装備数超過":\r
                 case "大破警告":\r
-                    checkBoxRepeat.Enabled = checkBoxRepeat.Checked = false;\r
-                    textBoxRepeat.Text = "";\r
+                    textBoxRepeat.Visible = labelRepeat.Visible = checkBoxRepeat.Visible = checkBoxCont.Visible = false;\r
                     break;\r
                 default:\r
+                    textBoxRepeat.Visible = labelRepeat.Visible = checkBoxRepeat.Visible = true;\r
                     checkBoxRepeat.Enabled = _configCheckBoxs[NotificationType.Repeat].Checked;\r
                     textBoxRepeat.Text = notification.RepeatInterval.ToString();\r
+                    checkBoxCont.Visible = IsContAvailable;\r
                     break;\r
             }\r
             checkBoxFlashWindow.Checked = (notification.Flags & NotificationType.FlashWindow) != 0;\r
@@ -49,6 +52,9 @@ namespace KancolleSniffer
             checkBoxPlaySound.Checked = (notification.Flags & NotificationType.PlaySound) != 0;\r
             checkBoxPush.Checked = (notification.Flags & NotificationType.Push) != 0;\r
             checkBoxRepeat.Checked = (notification.Flags & NotificationType.Repeat) != 0;\r
+            _tooltip.SetToolTip(checkBoxCont,\r
+                !IsContAvailable ? "" : notification.Name == "遠征終了" ? "再度遠征に出すまでリピートする。" : "再度入渠させるまでリピートする。");\r
+            checkBoxCont.Checked = (notification.Flags & NotificationType.Cont) != 0;\r
         }\r
 \r
         private void checkBox_CheckedChanged(object sender, EventArgs e)\r
@@ -59,11 +65,20 @@ namespace KancolleSniffer
             spec.Flags = checkBox.Checked ? spec.Flags | type : spec.Flags & ~type;\r
             if (type == NotificationType.Repeat)\r
             {\r
-                textBoxRepeat.Enabled = labelRepeat.Enabled =\r
+                textBoxRepeat.Enabled = labelRepeat.Enabled = checkBoxCont.Enabled =\r
                     _configCheckBoxs[NotificationType.Repeat].Checked && checkBox.Checked;\r
             }\r
         }\r
 \r
+        private bool IsContAvailable\r
+        {\r
+            get\r
+            {\r
+                var notification = _notifications[(string)listBoxNotifications.SelectedItem];\r
+                return notification.Name == "遠征終了" || notification.Name == "入渠終了";\r
+            }\r
+        }\r
+\r
         private void textBoxRepeat_TextChanged(object sender, EventArgs e)\r
         {\r
             _notifications[(string)listBoxNotifications.SelectedItem].RepeatInterval =\r
@@ -76,7 +91,8 @@ namespace KancolleSniffer
             checkBoxShowBaloonTip.Enabled = _configCheckBoxs[NotificationType.ShowBaloonTip].Checked;\r
             checkBoxPlaySound.Enabled = _configCheckBoxs[NotificationType.PlaySound].Checked;\r
             checkBoxRepeat.Enabled = _configCheckBoxs[NotificationType.Repeat].Checked;\r
-            textBoxRepeat.Enabled = labelRepeat.Enabled = checkBoxRepeat.Enabled && checkBoxRepeat.Checked;\r
+            textBoxRepeat.Enabled = labelRepeat.Enabled = checkBoxCont.Enabled =\r
+                checkBoxRepeat.Enabled && checkBoxRepeat.Checked;\r
 \r
             if (listBoxNotifications.SelectedIndex == -1)\r
                 listBoxNotifications.SelectedIndex = 0;\r
index ee1431d..79e13c0 100644 (file)
@@ -59,6 +59,11 @@ namespace KancolleSniffer
             _notificationQueue.StopRepeat(key);\r
         }\r
 \r
+        public void StopRepeat(string key, int fleet)\r
+        {\r
+            _notificationQueue.StopRepeat(key, fleet);\r
+        }\r
+\r
         public void SuspendRepeat()\r
         {\r
             _notificationQueue.SuspendRepeat();\r
@@ -327,6 +332,12 @@ namespace KancolleSniffer
                 _queue.RemoveAll(n => n.Key.Substring(0, 4) == key.Substring(0, 4) && n.Schedule != default);\r
             }\r
 \r
+            public void StopRepeat(string key, int fleet)\r
+            {\r
+                _queue.RemoveAll(n =>\r
+                    n.Key.Substring(0, 4) == key.Substring(0, 4) && n.Fleet == fleet && n.Schedule != default);\r
+            }\r
+\r
             public void SuspendRepeat()\r
             {\r
                 _suspend = true;\r
index 3302f15..795fc27 100644 (file)
@@ -44,6 +44,7 @@ namespace KancolleSniffer
         public interface IRepeatingTimerController\r
         {\r
             void Stop(string key);\r
+            void Stop(string key, int fleet);\r
             void Suspend();\r
             void Resume();\r
         }\r
@@ -439,6 +440,9 @@ namespace KancolleSniffer
                 _dockInfo.InspectNyukyo(request);\r
                 _conditionTimer.CheckCond();\r
                 _akashiTimer.CheckFleet();\r
+                var ndock = HttpUtility.ParseQueryString(request)["api_ndock_id"];\r
+                if (ndock != null && int.TryParse(ndock, out int id))\r
+                    RepeatingTimerController?.Stop("入渠終了", id - 1);\r
                 return Update.Item | Update.Ship;\r
             }\r
             if (url.EndsWith("api_req_nyukyo/speedchange"))\r
@@ -465,6 +469,13 @@ namespace KancolleSniffer
                 _logger.InspectMapNext(data);\r
                 return Update.None;\r
             }\r
+            if (url.EndsWith("api_req_mission/start"))\r
+            {\r
+                var deck = HttpUtility.ParseQueryString(request)["api_deck_id"];\r
+                if (deck != null && int.TryParse(deck, out int id))\r
+                    RepeatingTimerController?.Stop("遠征終了", id - 1);\r
+                return Update.None;\r
+            }\r
             if (url.EndsWith("api_req_mission/result"))\r
             {\r
                 _materialInfo.InspectMissionResult(data);\r