OSDN Git Service

設定でダメコン装備でも大破警告を出せるようにする
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / Config.cs
index 2a1d1b0..aa5ca31 100644 (file)
@@ -38,13 +38,32 @@ namespace KancolleSniffer
         }\r
     }\r
 \r
+    [Flags]\r
+    public enum ShipCategory\r
+    {\r
+        None = 0,\r
+        // ReSharper disable UnusedMember.Global\r
+        BattleShip = 1 << 0,\r
+\r
+        AircraftCarrier = 1 << 1,\r
+        HeavyCruiser = 1 << 2,\r
+        LightCruiser = 1 << 3,\r
+        Destroyer = 1 << 4,\r
+        Escort = 1 << 5,\r
+        Submarine = 1 << 6,\r
+        Assistant = 1 << 7,\r
+        // ReSharper restore UnusedMember.Global\r
+        All = (1 << 8) - 1\r
+    }\r
+\r
     public class ShipListConfig\r
     {\r
         public bool Visible { get; set; }\r
         public Point Location { get; set; }\r
         public Size Size { get; set; }\r
         public string Mode { get; set; }\r
-        public bool ShipType { get; set; }\r
+        public ShipCategory ShipCategories { get; set; } = ShipCategory.All;\r
+        public bool ShipType;\r
         public bool ShowHpInPercent { get; set; }\r
         public ListForm.SortOrder SortOrder { get; set; } = ListForm.SortOrder.ExpToNext;\r
         public List<List<int>> ShipGroup { get; set; }\r
@@ -87,7 +106,7 @@ namespace KancolleSniffer
     {\r
         public int Volume { get; set; } = 100;\r
 \r
-        public string[] Files { get; set; } =\r
+        public string[] Files =\r
         {\r
             "ensei.mp3",\r
             "nyuukyo.mp3",\r
@@ -98,7 +117,8 @@ namespace KancolleSniffer
             "20min.mp3",\r
             "syuuri.mp3",\r
             "syuuri2.mp3",\r
-            "hirou.mp3"\r
+            "hirou.mp3",\r
+            "ninmu.mp3"\r
         };\r
 \r
         public string this[string name]\r
@@ -106,12 +126,22 @@ namespace KancolleSniffer
             get => Files[Config.NotificationIndex[name]];\r
             set => Files[Config.NotificationIndex[name]] = value;\r
         }\r
+\r
+        public void Upgrade()\r
+        {\r
+            var expected = Config.NotificationNames.Length;\r
+            if (Files.Length == expected)\r
+                return;\r
+            Array.Resize(ref Files, expected);\r
+            Files[expected - 1] = "ninmu.mp3";\r
+        }\r
     }\r
 \r
     [Flags]\r
     public enum NotificationType\r
     {\r
         FlashWindow = 1,\r
+        // ReSharper disable once IdentifierTypo\r
         ShowBaloonTip = 1 << 1,\r
         PlaySound = 1 << 2,\r
         All = (1 << 3) - 1,\r
@@ -158,6 +188,37 @@ namespace KancolleSniffer
                 PreliminaryPeriods[Config.NotificationIndex[name]] = value.PreliminaryPeriod;\r
             }\r
         }\r
+\r
+        public void Upgrade()\r
+        {\r
+            UpgradeSettings(ref Settings);\r
+            UpgradeParameterArray(ref RepeatIntervals);\r
+            UpgradeParameterArray(ref PreliminaryPeriods);\r
+        }\r
+\r
+        private void UpgradeSettings(ref NotificationType[] settings)\r
+        {\r
+            for (var i = 0; i < settings.Length; i++)\r
+            {\r
+                if ((settings[i] & NotificationType.Pushbullet) != 0)\r
+                    settings[i] = settings[i] ^ NotificationType.Pushbullet | NotificationType.Push;\r
+            }\r
+            var expected = Config.NotificationNames.Length;\r
+            if (expected == settings.Length)\r
+                return;\r
+            Array.Resize(ref settings, expected);\r
+            settings[expected - 1] = NotificationType.All;\r
+        }\r
+\r
+        private void UpgradeParameterArray(ref int[] array)\r
+        {\r
+            Array.Resize(ref array, Config.NotificationNames.Length);\r
+            for (var i = 0; i < array.Length; i++)\r
+            {\r
+                if (array[i] < 0)\r
+                    array[i] = 0;\r
+            }\r
+        }\r
     }\r
 \r
     public class LocationPerMachine\r
@@ -175,7 +236,8 @@ namespace KancolleSniffer
         ResultRank = 1,\r
         AirBattleResult = 1 << 1,\r
         BattleResult = 1 << 2,\r
-        All = (1 << 3) - 1\r
+        NextCell = 1 << 3,\r
+        All = (1 << 4) - 1\r
     }\r
 \r
     [Flags]\r
@@ -192,22 +254,25 @@ namespace KancolleSniffer
         public bool HideOnMinimized { get; set; }\r
         public bool ExitSilently { get; set; }\r
         public int Zoom { get; set; } = 100;\r
+        public int QuestLines { get; set; } = 6;\r
         public bool SaveLocationPerMachine { get; set; }\r
         public List<LocationPerMachine> LocationList { get; set; } = new List<LocationPerMachine>();\r
         public bool ShowHpInPercent { get; set; }\r
         public TimerKind ShowEndTime { get; set; }\r
         public bool FlashWindow { get; set; } = true;\r
+        // ReSharper disable once IdentifierTypo\r
         public bool ShowBaloonTip { get; set; } = true;\r
         public bool PlaySound { get; set; } = true;\r
         public NotificationType NotificationFlags { get; set; } = NotificationType.All;\r
         public NotificationConfig Notifications { get; set; } = new NotificationConfig();\r
-        public int MarginShips { get; set; } = 4;\r
-        public int MarginEquips { get; set; } = 10;\r
+        public int MarginShips { get; set; } = 5;\r
+        public int MarginEquips { get; set; } = 5;\r
         public List<int> NotifyConditions { get; set; }\r
         public List<int> ResetHours { get; set; }\r
         public bool AlwaysShowResultRank { get; set; }\r
         public Spoiler Spoilers { get; set; }\r
         public bool UsePresetAkashi { get; set; }\r
+        public bool WarnBadDamageWithDameCon { get; set; }\r
         public SoundConfig Sounds { get; set; } = new SoundConfig();\r
         public bool DebugLogging { get; set; }\r
         public string DebugLogFile { get; set; } = "log.txt";\r
@@ -220,7 +285,7 @@ namespace KancolleSniffer
         public static readonly string[] NotificationNames =\r
         {\r
             "遠征終了", "入渠終了", "建造完了", "艦娘数超過", "装備数超過",\r
-            "大破警告", "泊地修理20分経過", "泊地修理進行", "泊地修理完了", "疲労回復"\r
+            "大破警告", "泊地修理20分経過", "泊地修理進行", "泊地修理完了", "疲労回復", "任務達成"\r
         };\r
 \r
         public static readonly Dictionary<string, int> NotificationIndex =\r
@@ -231,6 +296,11 @@ namespace KancolleSniffer
         public static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory;\r
         private static readonly string ConfigFile = Path.Combine(BaseDir, FileName);\r
 \r
+        public Config()\r
+        {\r
+            ConvertPath(PrependBaseDir);\r
+        }\r
+\r
         public void InitializeValues()\r
         {\r
             NotifyConditions = new List<int>(new[] {40, 49});\r
@@ -247,13 +317,9 @@ 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.Upgrade();\r
                 ComposeNotificationFlags();\r
+                Sounds.Upgrade();\r
                 if (AlwaysShowResultRank)\r
                 {\r
                     Spoilers = Spoiler.All;\r
@@ -281,6 +347,7 @@ namespace KancolleSniffer
             {\r
                 throw new Exception(FileName + "が壊れています。", ex);\r
             }\r
+            ConvertPath(PrependBaseDir);\r
         }\r
 \r
         private void ComposeNotificationFlags()\r
@@ -316,6 +383,7 @@ namespace KancolleSniffer
                 serializer.Serialize(file, this);\r
             File.Copy(ConfigFile + ".tmp", ConfigFile, true);\r
             File.Delete(ConfigFile + ".tmp");\r
+            ConvertPath(PrependBaseDir);\r
         }\r
 \r
         private void DecomposeNotificationFlags()\r
@@ -340,5 +408,7 @@ namespace KancolleSniffer
             path = path.Substring(BaseDir.Length);\r
             return path.TrimStart(Path.DirectorySeparatorChar);\r
         }\r
+\r
+        private string PrependBaseDir(string path) => Path.IsPathRooted(path) ? path : Path.Combine(BaseDir, path);\r
     }\r
 }
\ No newline at end of file