OSDN Git Service

大破警告をリピート可能にする
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / NotificationConfigDialog.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Drawing;\r
4 using System.Linq;\r
5 using System.Windows.Forms;\r
6 \r
7 namespace KancolleSniffer\r
8 {\r
9     public partial class NotificationConfigDialog : Form\r
10     {\r
11         private readonly Dictionary<string, NotificationSpec> _notifications;\r
12         private readonly Dictionary<NotificationType, CheckBox> _configCheckBoxs;\r
13         private readonly ResizableToolTip _toolTip = new ResizableToolTip();\r
14 \r
15         public NotificationConfigDialog(Dictionary<string, NotificationSpec> notifications,\r
16             Dictionary<NotificationType, CheckBox> checkBoxs)\r
17         {\r
18             InitializeComponent();\r
19             _notifications = notifications;\r
20             _configCheckBoxs = checkBoxs;\r
21 \r
22             checkBoxFlashWindow.Tag = NotificationType.FlashWindow;\r
23             checkBoxShowBaloonTip.Tag = NotificationType.ShowBaloonTip;\r
24             checkBoxPlaySound.Tag = NotificationType.PlaySound;\r
25             checkBoxPush.Tag = NotificationType.Push;\r
26             checkBoxRepeat.Tag = NotificationType.Repeat;\r
27             checkBoxCont.Tag = NotificationType.Cont;\r
28             checkBoxPreliminary.Tag = NotificationType.Preliminary;\r
29 \r
30             // ReSharper disable once CoVariantArrayConversion\r
31             listBoxNotifications.Items.AddRange(Config.NotificationNames);\r
32         }\r
33 \r
34         private void listBoxNotifications_SelectedIndexChanged(object sender, EventArgs e)\r
35         {\r
36             if (listBoxNotifications.SelectedItem == null)\r
37                 return;\r
38             var notification = _notifications[(string)listBoxNotifications.SelectedItem];\r
39             switch (notification.Name)\r
40             {\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 var interval) && interval > 0 ? 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             var selected = listBoxNotifications.SelectedIndex;\r
107             listBoxNotifications.SelectedIndex = -1;\r
108             listBoxNotifications.SelectedIndex = selected == -1 ? 0 : selected;\r
109         }\r
110 \r
111         private void textBoxPreliminary_TextChanged(object sender, EventArgs e)\r
112         {\r
113             _notifications[(string)listBoxNotifications.SelectedItem].PreliminaryPeriod =\r
114                 int.TryParse(textBoxPreliminary.Text, out var preliminary) && preliminary > 0 ? preliminary : 0;\r
115         }\r
116 \r
117         protected override void ScaleControl(SizeF factor, BoundsSpecified specified)\r
118         {\r
119             base.ScaleControl(factor, specified);\r
120             if (factor.Height > 1)\r
121                 _toolTip.Font = new Font(_toolTip.Font.FontFamily, _toolTip.Font.Size * factor.Height);\r
122         }\r
123     }\r
124 }