1 // Copyright (C) 2014, 2015 Kazuhiro Fujieda <fujieda@users.sourceforge.jp>
\r
3 // This program is part of KancolleSniffer.
\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
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
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
19 using System.Collections.Generic;
\r
20 using System.Diagnostics;
\r
24 using System.Windows.Forms;
\r
26 namespace KancolleSniffer
\r
28 public partial class ConfigDialog : Form
\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
38 public ConfigDialog(Config config, MainForm main)
\r
40 InitializeComponent();
\r
43 listBoxSoundFile.Items.AddRange(new object[]
\r
45 "遠征終了", "入渠終了", "建造完了", "艦娘数超過", "装備数超過",
\r
46 "大破警告", "泊地修理20分経過", "泊地修理進行", "疲労回復"
\r
50 private void ConfigDialog_Load(object sender, EventArgs e)
\r
52 var version = string.Join(".", Application.ProductVersion.Split('.').Take(2));
\r
53 labelVersion.Text = "バージョン" + version;
\r
54 SetLatestVersion(version);
\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
68 numericUpDownSoundVolume.Value = _config.SoundVolume;
\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
80 listBoxSoundFile.SelectedIndex = -1;
\r
81 listBoxSoundFile.SelectedIndex = 0;
\r
84 private async void SetLatestVersion(string version)
\r
88 var req = WebRequest.Create(Home + "version");
\r
89 var response = await req.GetResponseAsync();
\r
90 var stream = response.GetResponseStream();
\r
93 using (var reader = new StreamReader(stream))
\r
95 var str = await reader.ReadLineAsync();
\r
96 Invoke(new Action(() => { labelLatest.Text = version == str ? "最新です" : "最新は" + str + "です"; }));
\r
99 catch (WebException)
\r
104 private void buttonOk_Click(object sender, EventArgs e)
\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
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
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
126 _config.SoundVolume = (int)numericUpDownSoundVolume.Value;
\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
139 private void textBoxSoundFile_TextChanged(object sender, EventArgs e)
\r
141 _soundSetting[(string)listBoxSoundFile.SelectedItem] = textBoxSoundFile.Text;
\r
144 private void listBoxSoundFile_SelectedIndexChanged(object sender, EventArgs e)
\r
146 if (listBoxSoundFile.SelectedItem == null)
\r
148 textBoxSoundFile.Text = _soundSetting[(string)listBoxSoundFile.SelectedItem];
\r
149 textBoxSoundFile.Select(textBoxSoundFile.Text.Length, 0);
\r
152 private void buttonOpenFile_Click(object sender, EventArgs e)
\r
154 openFileDialog.FileName = textBoxSoundFile.Text;
\r
155 openFileDialog.InitialDirectory = Path.GetDirectoryName(textBoxSoundFile.Text) ?? "";
\r
156 if (openFileDialog.ShowDialog() != DialogResult.OK)
\r
158 textBoxSoundFile.Text = openFileDialog.FileName;
\r
159 textBoxSoundFile.Select(textBoxSoundFile.Text.Length, 0);
\r
163 private void buttonPlay_Click(object sender, EventArgs e)
\r
165 _main.PlaySound(_soundSetting[(string)listBoxSoundFile.SelectedItem], (int)numericUpDownSoundVolume.Value);
\r
168 private void DebugToolStripMenuItem_Click(object sender, EventArgs e)
\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
176 private void buttonResetAchievement_Click(object sender, EventArgs e)
\r
178 _main.ResetAchievemnt();
\r
181 private void ProxyToolStripMenuItem_Click(object sender, EventArgs e)
\r
183 if (_proxyDialog == null)
\r
184 _proxyDialog = new ProxyDialog(_config.Proxy, _main);
\r
185 _proxyDialog.ShowDialog(this);
\r
188 private void ReportToolStripMenuItem_Click(object sender, EventArgs e)
\r
190 if (_logDialog == null)
\r
191 _logDialog = new LogDialog(_config.Log, _main);
\r
192 _logDialog.ShowDialog(this);
\r
195 private void linkLabelProductName_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
\r
197 linkLabelProductName.LinkVisited = true;
\r
198 Process.Start(Home);
\r