OSDN Git Service

通知の予告の有無をチェックボックスで設定できるようにする
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / NotificationConfigDialog.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Linq;\r
4 using System.Windows.Forms;\r
5 \r
6 namespace KancolleSniffer\r
7 {\r
8     public partial class NotificationConfigDialog : Form\r
9     {\r
10         private readonly Dictionary<string, NotificationSpec> _notifications;\r
11         private readonly Dictionary<NotificationType, CheckBox> _configCheckBoxs;\r
12         private readonly ToolTip _tooltip = new ToolTip();\r
13 \r
14         public NotificationConfigDialog(Dictionary<string, NotificationSpec> notifications,\r
15             Dictionary<NotificationType, CheckBox> checkBoxs)\r
16         {\r
17             InitializeComponent();\r
18             _notifications = notifications;\r
19             _configCheckBoxs = checkBoxs;\r
20 \r
21             checkBoxFlashWindow.Tag = NotificationType.FlashWindow;\r
22             checkBoxShowBaloonTip.Tag = NotificationType.ShowBaloonTip;\r
23             checkBoxPlaySound.Tag = NotificationType.PlaySound;\r
24             checkBoxPush.Tag = NotificationType.Push;\r
25             checkBoxRepeat.Tag = NotificationType.Repeat;\r
26             checkBoxCont.Tag = NotificationType.Cont;\r
27             checkBoxPreliminary.Tag = NotificationType.Preliminary;\r
28 \r
29             // ReSharper disable once CoVariantArrayConversion\r
30             listBoxNotifications.Items.AddRange(Config.NotificationNames);\r
31         }\r
32 \r
33         private void listBoxNotifications_SelectedIndexChanged(object sender, EventArgs e)\r
34         {\r
35             if (listBoxNotifications.SelectedItem == null)\r
36                 return;\r
37             var notification = _notifications[(string)listBoxNotifications.SelectedItem];\r
38             switch (notification.Name)\r
39             {\r
40                 case "艦娘数超過":\r
41                 case "装備数超過":\r
42                 case "大破警告":\r
43                     textBoxPreliminary.Visible = labelPreliminary.Visible = checkBoxPreliminary.Visible =\r
44                         textBoxRepeat.Visible = labelRepeat.Visible = checkBoxRepeat.Visible =\r
45                             checkBoxCont.Visible = false;\r
46                     break;\r
47                 default:\r
48                     textBoxRepeat.Visible = labelRepeat.Visible = checkBoxRepeat.Visible = true;\r
49                     checkBoxRepeat.Enabled = _configCheckBoxs[NotificationType.Repeat].Checked;\r
50                     textBoxRepeat.Text = notification.RepeatInterval.ToString();\r
51                     checkBoxCont.Visible = IsContAvailable;\r
52                     textBoxPreliminary.Visible =\r
53                         labelPreliminary.Visible = checkBoxPreliminary.Visible = IspreliminaryAvailable;\r
54                     textBoxPreliminary.Text = notification.PreliminaryPeriod.ToString();\r
55                     break;\r
56             }\r
57             checkBoxFlashWindow.Checked = (notification.Flags & NotificationType.FlashWindow) != 0;\r
58             checkBoxShowBaloonTip.Checked = (notification.Flags & NotificationType.ShowBaloonTip) != 0;\r
59             checkBoxPlaySound.Checked = (notification.Flags & NotificationType.PlaySound) != 0;\r
60             checkBoxPush.Checked = (notification.Flags & NotificationType.Push) != 0;\r
61             checkBoxRepeat.Checked = (notification.Flags & NotificationType.Repeat) != 0;\r
62             _tooltip.SetToolTip(checkBoxCont,\r
63                 !IsContAvailable ? "" :\r
64                 notification.Name == "遠征終了" ? "再度遠征に出すまでリピートする。" : "再度入渠させるまでリピートする。");\r
65             checkBoxCont.Checked = (notification.Flags & NotificationType.Cont) != 0;\r
66             checkBoxPreliminary.Checked = (notification.Flags & NotificationType.Preliminary) != 0;\r
67         }\r
68 \r
69         private void checkBox_CheckedChanged(object sender, EventArgs e)\r
70         {\r
71             var checkBox = (CheckBox)sender;\r
72             var type = (NotificationType)checkBox.Tag;\r
73             var spec = _notifications[(string)listBoxNotifications.SelectedItem];\r
74             spec.Flags = checkBox.Checked ? spec.Flags | type : spec.Flags & ~type;\r
75             if (type == NotificationType.Repeat)\r
76             {\r
77                 textBoxRepeat.Enabled = labelRepeat.Enabled = checkBoxCont.Enabled =\r
78                     _configCheckBoxs[NotificationType.Repeat].Checked && checkBox.Checked;\r
79             }\r
80             if (type == NotificationType.Preliminary)\r
81                 textBoxPreliminary.Enabled = labelPreliminary.Enabled = checkBox.Checked;\r
82         }\r
83 \r
84         private bool IsContAvailable =>\r
85             new[] {"遠征終了", "入渠終了"}.Contains((string)listBoxNotifications.SelectedItem);\r
86 \r
87         private bool IspreliminaryAvailable =>\r
88             new[] {"遠征終了", "入渠終了", "建造完了", "泊地修理20分経過", "疲労回復"}.Contains((string)listBoxNotifications.SelectedItem);\r
89 \r
90         private void textBoxRepeat_TextChanged(object sender, EventArgs e)\r
91         {\r
92             _notifications[(string)listBoxNotifications.SelectedItem].RepeatInterval =\r
93                 int.TryParse(textBoxRepeat.Text, out int interval) ? interval : 0;\r
94         }\r
95 \r
96         private void NotificationConfigDialog_Load(object sender, EventArgs e)\r
97         {\r
98             checkBoxFlashWindow.Enabled = _configCheckBoxs[NotificationType.FlashWindow].Checked;\r
99             checkBoxShowBaloonTip.Enabled = _configCheckBoxs[NotificationType.ShowBaloonTip].Checked;\r
100             checkBoxPlaySound.Enabled = _configCheckBoxs[NotificationType.PlaySound].Checked;\r
101             checkBoxRepeat.Enabled = _configCheckBoxs[NotificationType.Repeat].Checked;\r
102             textBoxRepeat.Enabled = labelRepeat.Enabled = checkBoxCont.Enabled =\r
103                 checkBoxRepeat.Enabled && checkBoxRepeat.Checked;\r
104             textBoxPreliminary.Enabled = checkBoxPreliminary.Checked;\r
105 \r
106             if (listBoxNotifications.SelectedIndex == -1)\r
107                 listBoxNotifications.SelectedIndex = 0;\r
108         }\r
109 \r
110         private void textBoxpreliminary_TextChanged(object sender, EventArgs e)\r
111         {\r
112             _notifications[(string)listBoxNotifications.SelectedItem].PreliminaryPeriod =\r
113                 int.TryParse(textBoxPreliminary.Text, out int preliminary) ? preliminary : 0;\r
114         }\r
115     }\r
116 }