OSDN Git Service

最小化時にタスクバーに表示しないオプションを実装する
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / ConfigDialog.cs
1 // Copyright (C) 2014 Kazuhiro Fujieda <fujieda@users.sourceforge.jp>\r
2 // \r
3 // This program is part of KancolleSniffer.\r
4 //\r
5 // KancolleSniffer is free software: you can redistribute it and/or modify\r
6 // it under the terms of the GNU General Public License as published by\r
7 // the Free Software Foundation, either version 3 of the License, or\r
8 // (at your option) any later version.\r
9 //\r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 //\r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, see <http://www.gnu.org/licenses/>.\r
17 \r
18 using System;\r
19 using System.Collections.Generic;\r
20 using System.IO;\r
21 using System.Linq;\r
22 using System.Windows.Forms;\r
23 \r
24 namespace KancolleSniffer\r
25 {\r
26     public partial class ConfigDialog : Form\r
27     {\r
28         private readonly Config _config;\r
29         private readonly MainForm _main;\r
30         private DebugDialog _debugDialog;\r
31         private ProxyDialog _proxyDialog;\r
32         private readonly Dictionary<string, string> _soundSetting = new Dictionary<string, string>();\r
33 \r
34         public ConfigDialog(Config config, MainForm main)\r
35         {\r
36             InitializeComponent();\r
37             _config = config;\r
38             _main = main;\r
39             listBoxSoundFile.Items.AddRange(new object[] {"遠征終了", "入渠終了", "建造完了", "艦娘数超過", "大破警告", "泊地修理20分経過", "泊地修理進行"});\r
40         }\r
41 \r
42         private void ConfigDialog_Load(object sender, EventArgs e)\r
43         {\r
44             checkBoxTopMost.Checked = _config.TopMost;\r
45             checkBoxHideOnMinimized.Checked = _config.HideOnMinimized;\r
46             checkBoxFlash.Checked = _config.FlashWindow;\r
47             checkBoxBalloon.Checked = _config.ShowBaloonTip;\r
48             groupBoxSound.Enabled = checkBoxSound.Checked = _config.PlaySound;\r
49             numericUpDownMarginShips.Value = _config.MarginShips;\r
50 \r
51             checkBoxReset02.Checked = _config.ResetHours.Any(x => x == 2);\r
52             checkBoxReset14.Checked = _config.ResetHours.Any(x => x == 14);\r
53 \r
54             numericUpDownSoundVolume.Value = _config.SoundVolume;\r
55 \r
56             _soundSetting["遠征終了"] = _config.MissionSoundFile;\r
57             _soundSetting["入渠終了"] = _config.NDockSoundFile;\r
58             _soundSetting["建造完了"] = _config.KDockSoundFile;\r
59             _soundSetting["艦娘数超過"] = _config.MaxShipsSoundFile;\r
60             _soundSetting["大破警告"] = _config.DamagedShipSoundFile;\r
61             _soundSetting["泊地修理20分経過"] = _config.Akashi20MinSoundFile;\r
62             _soundSetting["泊地修理進行"] = _config.AkashiProgressSoundFile;\r
63             listBoxSoundFile.SelectedIndex = 0;\r
64         }\r
65 \r
66         private void buttonOk_Click(object sender, EventArgs e)\r
67         {\r
68             _config.TopMost = checkBoxTopMost.Checked;\r
69             _config.HideOnMinimized = checkBoxHideOnMinimized.Checked;\r
70             _config.FlashWindow = checkBoxFlash.Checked;\r
71             _config.ShowBaloonTip = checkBoxBalloon.Checked;\r
72             _config.PlaySound = checkBoxSound.Checked;\r
73             _config.MarginShips = (int)numericUpDownMarginShips.Value;\r
74 \r
75             _config.ResetHours.Clear();\r
76             if (checkBoxReset02.Checked)\r
77                 _config.ResetHours.Add(2);\r
78             if (checkBoxReset14.Checked)\r
79                 _config.ResetHours.Add(14);\r
80 \r
81             _config.SoundVolume = (int)numericUpDownSoundVolume.Value;\r
82 \r
83             _config.MissionSoundFile = _soundSetting["遠征終了"];\r
84             _config.NDockSoundFile = _soundSetting["入渠終了"];\r
85             _config.KDockSoundFile = _soundSetting["建造完了"];\r
86             _config.MaxShipsSoundFile = _soundSetting["艦娘数超過"];\r
87             _config.DamagedShipSoundFile = _soundSetting["大破警告"];\r
88             _config.Akashi20MinSoundFile = _soundSetting["泊地修理20分経過"];\r
89             _config.AkashiProgressSoundFile = _soundSetting["泊地修理進行"];\r
90         }\r
91 \r
92         private void checkBoxSound_CheckedChanged(object sender, EventArgs e)\r
93         {\r
94             groupBoxSound.Enabled = checkBoxSound.Checked;\r
95         }\r
96 \r
97         private void textBoxSoundFile_TextChanged(object sender, EventArgs e)\r
98         {\r
99             _soundSetting[(string)listBoxSoundFile.SelectedItem] = textBoxSoundFile.Text;\r
100         }\r
101 \r
102         private void listBoxSoundFile_SelectedIndexChanged(object sender, EventArgs e)\r
103         {\r
104             textBoxSoundFile.Text = _soundSetting[(string)listBoxSoundFile.SelectedItem];\r
105             textBoxSoundFile.Select(textBoxSoundFile.Text.Length, 0);\r
106         }\r
107 \r
108         private void buttonOpenFile_Click(object sender, EventArgs e)\r
109         {\r
110             openFileDialog.FileName = textBoxSoundFile.Text;\r
111             openFileDialog.InitialDirectory = Path.GetDirectoryName(textBoxSoundFile.Text) ?? "";\r
112             if (openFileDialog.ShowDialog() != DialogResult.OK)\r
113                 return;\r
114             textBoxSoundFile.Text = openFileDialog.FileName;\r
115             textBoxSoundFile.Select(textBoxSoundFile.Text.Length, 0);\r
116         }\r
117 \r
118 \r
119         private void buttonPlay_Click(object sender, EventArgs e)\r
120         {\r
121             _main.PlaySound(_soundSetting[(string)listBoxSoundFile.SelectedItem], (int)numericUpDownSoundVolume.Value);\r
122         }\r
123 \r
124         private void DebugToolStripMenuItem_Click(object sender, EventArgs e)\r
125         {\r
126             if (_debugDialog == null)\r
127                 _debugDialog = new DebugDialog(_config, _main);\r
128             _debugDialog.ShowDialog(this);\r
129         }\r
130 \r
131         private void buttonResetAchievement_Click(object sender, EventArgs e)\r
132         {\r
133             _main.ResetAchievemnt();\r
134         }\r
135 \r
136         private void ProxyToolStripMenuItem_Click(object sender, EventArgs e)\r
137         {\r
138             if (_proxyDialog == null)\r
139                 _proxyDialog = new ProxyDialog(_config.Proxy, _main);\r
140             _proxyDialog.ShowDialog(this);\r
141         }\r
142     }\r
143 }