OSDN Git Service

タイマーと終了時刻の切り替えをわかりやすくする
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / ConfigDialog.cs
index e2a5368..f9c8194 100644 (file)
@@ -18,6 +18,8 @@ using System.Diagnostics;
 using System.Drawing;\r
 using System.IO;\r
 using System.Windows.Forms;\r
+using KancolleSniffer.Net;\r
+using KancolleSniffer.View;\r
 \r
 namespace KancolleSniffer\r
 {\r
@@ -25,7 +27,6 @@ namespace KancolleSniffer
     {\r
         private readonly Config _config;\r
         private readonly MainForm _main;\r
-        private readonly NotificationConfigDialog _notificationConfigDialog;\r
 \r
         private readonly Dictionary<string, NotificationSpec> _notificationSettings =\r
             new Dictionary<string, NotificationSpec>();\r
@@ -35,6 +36,7 @@ namespace KancolleSniffer
         private Point _prevPosition = new Point(int.MinValue, int.MinValue);\r
 \r
         public List<string> RepeatSettingsChanged { get; } = new List<string>();\r
+        public NotificationConfigDialog NotificationConfigDialog { get; }\r
 \r
         public ConfigDialog(Config config, MainForm main)\r
         {\r
@@ -45,7 +47,7 @@ namespace KancolleSniffer
             listBoxSoundFile.Items.AddRange(Config.NotificationNames);\r
             numericUpDownMaterialLogInterval.Maximum = 1440;\r
 \r
-            _notificationConfigDialog = new NotificationConfigDialog(_notificationSettings,\r
+            NotificationConfigDialog = new NotificationConfigDialog(_notificationSettings,\r
                 new Dictionary<NotificationType, CheckBox>\r
                 {\r
                     {NotificationType.FlashWindow, checkBoxFlash},\r
@@ -62,7 +64,7 @@ namespace KancolleSniffer
             _main.CheckVersionUp((current, latest) =>\r
             {\r
                 labelVersion.Text = "バージョン" + current;\r
-                labelLatest.Text = double.Parse(current) >= double.Parse(latest) ? "最新です" : "最新は" + latest + "です";\r
+                labelLatest.Text = current == latest ? "最新です" : "最新は" + latest + "です";\r
             });\r
             labelCopyright.Text = FileVersionInfo.GetVersionInfo(Application.ExecutablePath).LegalCopyright;\r
 \r
@@ -85,8 +87,10 @@ namespace KancolleSniffer
 \r
             checkBoxReset02.Checked = _config.ResetHours.Contains(2);\r
             checkBoxReset14.Checked = _config.ResetHours.Contains(14);\r
-            radioButtonResultRankAlways.Checked = _config.AlwaysShowResultRank;\r
-            radioButtonResultRankWhenClick.Checked = !_config.AlwaysShowResultRank;\r
+            checkBoxResultRank.Checked = (_config.Spoilers & Spoiler.ResultRank) != 0;\r
+            checkBoxAirBattleResult.Checked = (_config.Spoilers & Spoiler.AirBattleResult) != 0;\r
+            checkBoxBattleResult.Checked = (_config.Spoilers & Spoiler.BattleResult) != 0;\r
+            checkBoxNextCell.Checked = (_config.Spoilers & Spoiler.NextCell) != 0;\r
             checkBoxPresetAkashi.Checked = _config.UsePresetAkashi;\r
 \r
             numericUpDownSoundVolume.Value = _config.Sounds.Volume;\r
@@ -99,8 +103,6 @@ namespace KancolleSniffer
             LoadLogSettings();\r
             LoadDebugSettings();\r
 \r
-            checkBoxKancolleDbOn.Checked = _config.KancolleDb.On;\r
-            textBoxKancolleDbToken.Text = _config.KancolleDb.Token;\r
             checkBoxPushbulletOn.Checked = _config.Pushbullet.On;\r
             textBoxPushbulletToken.Text = _config.Pushbullet.Token;\r
             checkBoxPushoverOn.Checked = _config.Pushover.On;\r
@@ -144,8 +146,6 @@ namespace KancolleSniffer
             ApplyLogSettings();\r
             ApplyDebugSettings();\r
 \r
-            _config.KancolleDb.On = checkBoxKancolleDbOn.Checked;\r
-            _config.KancolleDb.Token = textBoxKancolleDbToken.Text;\r
             _config.Pushbullet.On = checkBoxPushbulletOn.Checked;\r
             _config.Pushbullet.Token = textBoxPushbulletToken.Text;\r
             _config.Pushover.On = checkBoxPushoverOn.Checked;\r
@@ -191,12 +191,15 @@ namespace KancolleSniffer
             if (checkBoxReset14.Checked)\r
                 _config.ResetHours.Add(14);\r
 \r
-            _config.AlwaysShowResultRank = radioButtonResultRankAlways.Checked;\r
+            _config.Spoilers = (checkBoxResultRank.Checked ? Spoiler.ResultRank : 0) |\r
+                               (checkBoxAirBattleResult.Checked ? Spoiler.AirBattleResult : 0) |\r
+                               (checkBoxBattleResult.Checked ? Spoiler.BattleResult : 0) |\r
+                               (checkBoxNextCell.Checked ? Spoiler.NextCell : 0);\r
             _config.UsePresetAkashi = checkBoxPresetAkashi.Checked;\r
 \r
             _config.Sounds.Volume = (int)numericUpDownSoundVolume.Value;\r
             foreach (var name in Config.NotificationNames)\r
-                _config.Sounds[name] = _soundSettings[name];\r
+                _config.Sounds[name] = MakePathRooted(_soundSettings[name]);\r
         }\r
 \r
         private bool ValidatePorts(out int listen, out int outbound, out int server)\r
@@ -232,17 +235,33 @@ namespace KancolleSniffer
         {\r
             _config.Log.On = checkBoxOutput.Checked;\r
             _config.Log.MaterialLogInterval = (int)numericUpDownMaterialLogInterval.Value;\r
-            _config.Log.OutputDir = textBoxOutput.Text;\r
+            _config.Log.OutputDir = MakePathRooted(textBoxOutput.Text);\r
             _main.ApplyLogSetting();\r
         }\r
 \r
         private void ApplyDebugSettings()\r
         {\r
             _config.DebugLogging = checkBoxDebugLog.Checked;\r
-            _config.DebugLogFile = textBoxDebugLog.Text;\r
+            _config.DebugLogFile = MakePathRooted(textBoxDebugLog.Text);\r
             _main.ApplyDebugLogSetting();\r
         }\r
 \r
+        private string MakePathRooted(string path)\r
+        {\r
+            try\r
+            {\r
+                return string.IsNullOrWhiteSpace(path)\r
+                    ? ""\r
+                    : Path.IsPathRooted(path)\r
+                        ? path\r
+                        : Path.Combine(Config.BaseDir, path);\r
+            }\r
+            catch (ArgumentException)\r
+            {\r
+                return "";\r
+            }\r
+        }\r
+\r
         private void textBoxSoundFile_TextChanged(object sender, EventArgs e)\r
         {\r
             _soundSettings[(string)listBoxSoundFile.SelectedItem] = textBoxSoundFile.Text;\r
@@ -258,8 +277,7 @@ namespace KancolleSniffer
 \r
         private void buttonOpenFile_Click(object sender, EventArgs e)\r
         {\r
-            openSoundFileDialog.FileName = textBoxSoundFile.Text;\r
-            openSoundFileDialog.InitialDirectory = Path.GetDirectoryName(textBoxSoundFile.Text) ?? "";\r
+            SetInitialPath(openSoundFileDialog, textBoxSoundFile.Text);\r
             if (openSoundFileDialog.ShowDialog() != DialogResult.OK)\r
                 return;\r
             textBoxSoundFile.Text = openSoundFileDialog.FileName;\r
@@ -273,7 +291,7 @@ namespace KancolleSniffer
 \r
         private void buttonResetAchievement_Click(object sender, EventArgs e)\r
         {\r
-            _main.ResetAchievemnt();\r
+            _main.ResetAchievement();\r
         }\r
 \r
         private void linkLabelProductName_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)\r
@@ -308,29 +326,61 @@ namespace KancolleSniffer
                 ShowToolTip("0より大きい数字を入力してください。", textBox);\r
                 return false;\r
             }\r
+            if (result > 65535)\r
+            {\r
+                ShowToolTip("65535以下の数字を入力してください。", textBox);\r
+                return false;\r
+            }\r
             return true;\r
         }\r
 \r
+        private readonly ResizableToolTip _toolTip =\r
+            new ResizableToolTip {AutomaticDelay = 0, ToolTipIcon = ToolTipIcon.Error};\r
+\r
         private void ShowToolTip(string message, Control control)\r
         {\r
             tabControl.SelectedTab = (TabPage)control.Parent.Parent;\r
-            toolTipError.Show(message, control, 0, control.Height, 3000);\r
+            _toolTip.Show(message, control, 0, control.Height, 3000);\r
         }\r
 \r
         private void textBox_Enter(object sender, EventArgs e)\r
         {\r
-            toolTipError.Hide((Control)sender);\r
+            _toolTip.Hide((Control)sender);\r
         }\r
 \r
         private void buttonDebugLogOpenFile_Click(object sender, EventArgs e)\r
         {\r
-            openDebugLogDialog.FileName = textBoxDebugLog.Text;\r
-            openDebugLogDialog.InitialDirectory = Path.GetDirectoryName(textBoxDebugLog.Text);\r
+            SetInitialPath(openDebugLogDialog, textBoxDebugLog.Text);\r
             if (openDebugLogDialog.ShowDialog(this) == DialogResult.OK)\r
                 textBoxDebugLog.Text = openDebugLogDialog.FileName;\r
             textBoxDebugLog.Select(textBoxDebugLog.Text.Length, 0);\r
         }\r
 \r
+        private void SetInitialPath(OpenFileDialog dialog, string path)\r
+        {\r
+            var dir = Config.BaseDir;\r
+            var file = "";\r
+            if (!string.IsNullOrWhiteSpace(path))\r
+            {\r
+                var res = Path.GetDirectoryName(path);\r
+                if (res == null) // root\r
+                {\r
+                    dir = path;\r
+                }\r
+                else if (res != "") // contain directory\r
+                {\r
+                    dir = res;\r
+                    file = Path.GetFileName(path);\r
+                }\r
+                else\r
+                {\r
+                    file = path;\r
+                }\r
+            }\r
+            dialog.InitialDirectory = dir;\r
+            dialog.FileName = file;\r
+        }\r
+\r
         private void buttonPlayDebugLog_Click(object sender, EventArgs e)\r
         {\r
             _main.SetPlayLog(textBoxDebugLog.Text);\r
@@ -339,7 +389,7 @@ namespace KancolleSniffer
 \r
         private void buttonDetailedSettings_Click(object sender, EventArgs e)\r
         {\r
-            _notificationConfigDialog.ShowDialog(this);\r
+            NotificationConfigDialog.ShowDialog(this);\r
         }\r
 \r
         private void ConfigDialog_FormClosing(object sender, FormClosingEventArgs e)\r
@@ -371,5 +421,12 @@ namespace KancolleSniffer
                 MessageBox.Show(this, ex.Message, "Pushoverエラー", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
             }\r
         }\r
+\r
+        protected override void ScaleControl(SizeF factor, BoundsSpecified specified)\r
+        {\r
+            base.ScaleControl(factor, specified);\r
+            if (factor.Height > 1)\r
+                _toolTip.Font = new Font(_toolTip.Font.FontFamily, _toolTip.Font.Size * factor.Height);\r
+        }\r
     }\r
 }
\ No newline at end of file