OSDN Git Service

リピートと予告の秒数にマイナスを指定できるのを直す
authorKazuhiro Fujieda <fujieda@users.osdn.me>
Sun, 20 May 2018 05:16:32 +0000 (14:16 +0900)
committerKazuhiro Fujieda <fujieda@users.osdn.me>
Sun, 20 May 2018 05:16:32 +0000 (14:16 +0900)
KancolleSniffer/Config.cs
KancolleSniffer/NotificationConfigDialog.Designer.cs
KancolleSniffer/NotificationConfigDialog.cs

index 2a1d1b0..cc17ea1 100644 (file)
@@ -158,6 +158,17 @@ namespace KancolleSniffer
                 PreliminaryPeriods[Config.NotificationIndex[name]] = value.PreliminaryPeriod;\r
             }\r
         }\r
+\r
+        public void Normalization()\r
+        {\r
+            Settings = Settings.Select(s =>\r
+                    (s & NotificationType.Pushbullet) != 0\r
+                        ? s ^ NotificationType.Pushbullet | NotificationType.Push\r
+                        : s)\r
+                .ToArray();\r
+            RepeatIntervals = RepeatIntervals.Select(v => v < 0 ? 0 : v).ToArray();\r
+            PreliminaryPeriods = RepeatIntervals.Select(v => v < 0 ? 0 : v).ToArray();\r
+        }\r
     }\r
 \r
     public class LocationPerMachine\r
@@ -247,12 +258,7 @@ namespace KancolleSniffer
                     config = (Config)serializer.Deserialize(file);\r
                 foreach (var property in GetType().GetProperties())\r
                     property.SetValue(this, property.GetValue(config, null), null);\r
-                var ns = Notifications.Settings;\r
-                for (var i = 0; i < ns.Length; i++)\r
-                {\r
-                    if ((ns[i] & NotificationType.Pushbullet) != 0)\r
-                        ns[i] = ns[i] ^ NotificationType.Pushbullet | NotificationType.Push;\r
-                }\r
+                Notifications.Normalization();\r
                 ComposeNotificationFlags();\r
                 if (AlwaysShowResultRank)\r
                 {\r
index 070bf07..d877155 100644 (file)
             this.textBoxPreliminary.Size = new System.Drawing.Size(36, 19);\r
             this.textBoxPreliminary.TabIndex = 12;\r
             this.textBoxPreliminary.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;\r
-            this.textBoxPreliminary.TextChanged += new System.EventHandler(this.textBoxpreliminary_TextChanged);\r
+            this.textBoxPreliminary.TextChanged += new System.EventHandler(this.textBoxPreliminary_TextChanged);\r
             // \r
             // labelPreliminary\r
             // \r
index dc8e9bd..8b20b12 100644 (file)
@@ -51,7 +51,7 @@ namespace KancolleSniffer
                     textBoxRepeat.Text = notification.RepeatInterval.ToString();\r
                     checkBoxCont.Visible = IsContAvailable;\r
                     textBoxPreliminary.Visible =\r
-                        labelPreliminary.Visible = checkBoxPreliminary.Visible = IspreliminaryAvailable;\r
+                        labelPreliminary.Visible = checkBoxPreliminary.Visible = IsPreliminaryAvailable;\r
                     textBoxPreliminary.Text = notification.PreliminaryPeriod.ToString();\r
                     break;\r
             }\r
@@ -85,13 +85,13 @@ namespace KancolleSniffer
         private bool IsContAvailable =>\r
             new[] {"遠征終了", "入渠終了"}.Contains((string)listBoxNotifications.SelectedItem);\r
 \r
-        private bool IspreliminaryAvailable =>\r
+        private bool IsPreliminaryAvailable =>\r
             new[] {"遠征終了", "入渠終了", "建造完了", "泊地修理20分経過", "疲労回復"}.Contains((string)listBoxNotifications.SelectedItem);\r
 \r
         private void textBoxRepeat_TextChanged(object sender, EventArgs e)\r
         {\r
             _notifications[(string)listBoxNotifications.SelectedItem].RepeatInterval =\r
-                int.TryParse(textBoxRepeat.Text, out int interval) ? interval : 0;\r
+                int.TryParse(textBoxRepeat.Text, out var interval) && interval > 0 ? interval : 0;\r
         }\r
 \r
         private void NotificationConfigDialog_Load(object sender, EventArgs e)\r
@@ -104,14 +104,15 @@ namespace KancolleSniffer
                 checkBoxRepeat.Enabled && checkBoxRepeat.Checked;\r
             textBoxPreliminary.Enabled = checkBoxPreliminary.Checked;\r
 \r
-            if (listBoxNotifications.SelectedIndex == -1)\r
-                listBoxNotifications.SelectedIndex = 0;\r
+            var selected = listBoxNotifications.SelectedIndex;\r
+            listBoxNotifications.SelectedIndex = -1;\r
+            listBoxNotifications.SelectedIndex = selected == -1 ? 0 : selected;\r
         }\r
 \r
-        private void textBoxpreliminary_TextChanged(object sender, EventArgs e)\r
+        private void textBoxPreliminary_TextChanged(object sender, EventArgs e)\r
         {\r
             _notifications[(string)listBoxNotifications.SelectedItem].PreliminaryPeriod =\r
-                int.TryParse(textBoxPreliminary.Text, out int preliminary) ? preliminary : 0;\r
+                int.TryParse(textBoxPreliminary.Text, out var preliminary) && preliminary > 0 ? preliminary : 0;\r
         }\r
 \r
         protected override void ScaleControl(SizeF factor, BoundsSpecified specified)\r