OSDN Git Service

遠征終了のサウンドの設定がキャンセルしても元に戻らないのを直す
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / ConfigDialog.cs
1 // Copyright (C) 2014, 2015 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.Diagnostics;\r
21 using System.IO;\r
22 using System.Linq;\r
23 using System.Net;\r
24 using System.Windows.Forms;\r
25 \r
26 namespace KancolleSniffer\r
27 {\r
28     public partial class ConfigDialog : Form\r
29     {\r
30         private readonly Config _config;\r
31         private readonly MainForm _main;\r
32         private DebugDialog _debugDialog;\r
33         private ProxyDialog _proxyDialog;\r
34         private LogDialog _logDialog;\r
35         private readonly Dictionary<string, string> _soundSetting = new Dictionary<string, string>();\r
36         private const string Home = "http://kancollesniffer.sourceforge.jp/";\r
37 \r
38         public ConfigDialog(Config config, MainForm main)\r
39         {\r
40             InitializeComponent();\r
41             _config = config;\r
42             _main = main;\r
43             listBoxSoundFile.Items.AddRange(new object[]\r
44             {\r
45                 "遠征終了", "入渠終了", "建造完了", "艦娘数超過", "装備数超過",\r
46                 "大破警告", "泊地修理20分経過", "泊地修理進行", "疲労回復"\r
47             });\r
48         }\r
49 \r
50         private void ConfigDialog_Load(object sender, EventArgs e)\r
51         {\r
52             var version = string.Join(".", Application.ProductVersion.Split('.').Take(2));\r
53             labelVersion.Text = "バージョン" + version;\r
54             SetLatestVersion(version);\r
55 \r
56             checkBoxTopMost.Checked = _config.TopMost;\r
57             checkBoxHideOnMinimized.Checked = _config.HideOnMinimized;\r
58             checkBoxFlash.Checked = _config.FlashWindow;\r
59             checkBoxBalloon.Checked = _config.ShowBaloonTip;\r
60             checkBoxSound.Checked = _config.PlaySound;\r
61             numericUpDownMarginShips.Value = _config.MarginShips;\r
62             numericUpDownMarginEquips.Value = _config.MarginEquips;\r
63             checkBoxCond40.Checked = _config.NotifyConditions.Contains(40);\r
64             checkBoxCond49.Checked = _config.NotifyConditions.Contains(49);\r
65             checkBoxReset02.Checked = _config.ResetHours.Contains(2);\r
66             checkBoxReset14.Checked = _config.ResetHours.Contains(14);\r
67 \r
68             numericUpDownSoundVolume.Value = _config.SoundVolume;\r
69 \r
70             _soundSetting["遠征終了"] = _config.MissionSoundFile;\r
71             _soundSetting["入渠終了"] = _config.NDockSoundFile;\r
72             _soundSetting["建造完了"] = _config.KDockSoundFile;\r
73             _soundSetting["艦娘数超過"] = _config.MaxShipsSoundFile;\r
74             _soundSetting["装備数超過"] = _config.MaxEquipsSoundFile;\r
75             _soundSetting["大破警告"] = _config.DamagedShipSoundFile;\r
76             _soundSetting["泊地修理20分経過"] = _config.Akashi20MinSoundFile;\r
77             _soundSetting["泊地修理進行"] = _config.AkashiProgressSoundFile;\r
78             _soundSetting["疲労回復"] = _config.ConditionSoundFile;\r
79 \r
80             listBoxSoundFile.SelectedIndex = -1;\r
81             listBoxSoundFile.SelectedIndex = 0;\r
82         }\r
83 \r
84         private async void SetLatestVersion(string version)\r
85         {\r
86             try\r
87             {\r
88                 var req = WebRequest.Create(Home + "version");\r
89                 var response = await req.GetResponseAsync();\r
90                 var stream = response.GetResponseStream();\r
91                 if (stream == null)\r
92                     return;\r
93                 using (var reader = new StreamReader(stream))\r
94                 {\r
95                     var str = await reader.ReadLineAsync();\r
96                     Invoke(new Action(() => { labelLatest.Text = version == str ? "最新です" : "最新は" + str + "です"; }));\r
97                 }\r
98             }\r
99             catch (WebException)\r
100             {\r
101             }\r
102         }\r
103 \r
104         private void buttonOk_Click(object sender, EventArgs e)\r
105         {\r
106             _config.TopMost = checkBoxTopMost.Checked;\r
107             _config.HideOnMinimized = checkBoxHideOnMinimized.Checked;\r
108             _config.FlashWindow = checkBoxFlash.Checked;\r
109             _config.ShowBaloonTip = checkBoxBalloon.Checked;\r
110             _config.PlaySound = checkBoxSound.Checked;\r
111             _config.MarginShips = (int)numericUpDownMarginShips.Value;\r
112             _config.MarginEquips = (int)numericUpDownMarginEquips.Value;\r
113 \r
114             _config.NotifyConditions.Clear();\r
115             if (checkBoxCond40.Checked)\r
116                 _config.NotifyConditions.Add(40);\r
117             if (checkBoxCond49.Checked)\r
118                 _config.NotifyConditions.Add(49);\r
119 \r
120             _config.ResetHours.Clear();\r
121             if (checkBoxReset02.Checked)\r
122                 _config.ResetHours.Add(2);\r
123             if (checkBoxReset14.Checked)\r
124                 _config.ResetHours.Add(14);\r
125 \r
126             _config.SoundVolume = (int)numericUpDownSoundVolume.Value;\r
127 \r
128             _config.MissionSoundFile = _soundSetting["遠征終了"];\r
129             _config.NDockSoundFile = _soundSetting["入渠終了"];\r
130             _config.KDockSoundFile = _soundSetting["建造完了"];\r
131             _config.MaxShipsSoundFile = _soundSetting["艦娘数超過"];\r
132             _config.MaxEquipsSoundFile = _soundSetting["装備数超過"];\r
133             _config.DamagedShipSoundFile = _soundSetting["大破警告"];\r
134             _config.Akashi20MinSoundFile = _soundSetting["泊地修理20分経過"];\r
135             _config.AkashiProgressSoundFile = _soundSetting["泊地修理進行"];\r
136             _config.ConditionSoundFile = _soundSetting["疲労回復"];\r
137         }\r
138 \r
139         private void textBoxSoundFile_TextChanged(object sender, EventArgs e)\r
140         {\r
141             _soundSetting[(string)listBoxSoundFile.SelectedItem] = textBoxSoundFile.Text;\r
142         }\r
143 \r
144         private void listBoxSoundFile_SelectedIndexChanged(object sender, EventArgs e)\r
145         {\r
146             if (listBoxSoundFile.SelectedItem == null)\r
147                 return;\r
148             textBoxSoundFile.Text = _soundSetting[(string)listBoxSoundFile.SelectedItem];\r
149             textBoxSoundFile.Select(textBoxSoundFile.Text.Length, 0);\r
150         }\r
151 \r
152         private void buttonOpenFile_Click(object sender, EventArgs e)\r
153         {\r
154             openFileDialog.FileName = textBoxSoundFile.Text;\r
155             openFileDialog.InitialDirectory = Path.GetDirectoryName(textBoxSoundFile.Text) ?? "";\r
156             if (openFileDialog.ShowDialog() != DialogResult.OK)\r
157                 return;\r
158             textBoxSoundFile.Text = openFileDialog.FileName;\r
159             textBoxSoundFile.Select(textBoxSoundFile.Text.Length, 0);\r
160         }\r
161 \r
162 \r
163         private void buttonPlay_Click(object sender, EventArgs e)\r
164         {\r
165             _main.PlaySound(_soundSetting[(string)listBoxSoundFile.SelectedItem], (int)numericUpDownSoundVolume.Value);\r
166         }\r
167 \r
168         private void DebugToolStripMenuItem_Click(object sender, EventArgs e)\r
169         {\r
170             if (_debugDialog == null)\r
171                 _debugDialog = new DebugDialog(_config, _main);\r
172             if (_debugDialog.ShowDialog(this) == DialogResult.Abort)\r
173                 DialogResult = DialogResult.Cancel;\r
174         }\r
175 \r
176         private void buttonResetAchievement_Click(object sender, EventArgs e)\r
177         {\r
178             _main.ResetAchievemnt();\r
179         }\r
180 \r
181         private void ProxyToolStripMenuItem_Click(object sender, EventArgs e)\r
182         {\r
183             if (_proxyDialog == null)\r
184                 _proxyDialog = new ProxyDialog(_config.Proxy, _main);\r
185             _proxyDialog.ShowDialog(this);\r
186         }\r
187 \r
188         private void ReportToolStripMenuItem_Click(object sender, EventArgs e)\r
189         {\r
190             if (_logDialog == null)\r
191                 _logDialog = new LogDialog(_config.Log, _main);\r
192             _logDialog.ShowDialog(this);\r
193         }\r
194 \r
195         private void linkLabelProductName_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)\r
196         {\r
197             linkLabelProductName.LinkVisited = true;\r
198             Process.Start(Home);\r
199         }\r
200     }\r
201 }