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 using KancolleSniffer.View;\r
7 \r
8 namespace KancolleSniffer\r
9 {\r
10     public partial class NotificationConfigDialog : Form\r
11     {\r
12         private readonly Dictionary<string, NotificationSpec> _notifications;\r
13         private readonly Dictionary<NotificationType, CheckBox> _configCheckBoxes;\r
14         private readonly ResizableToolTip _toolTip = new ResizableToolTip();\r
15 \r
16         public NotificationConfigDialog(Dictionary<string, NotificationSpec> notifications,\r
17             Dictionary<NotificationType, CheckBox> checkBoxes)\r
18         {\r
19             InitializeComponent();\r
20             _notifications = notifications;\r
21             _configCheckBoxes = checkBoxes;\r
22 \r
23             checkBoxFlashWindow.Tag = NotificationType.FlashWindow;\r
24             checkBoxShowBalloonTip.Tag = NotificationType.ShowBaloonTip;\r
25             checkBoxPlaySound.Tag = NotificationType.PlaySound;\r
26             checkBoxPush.Tag = NotificationType.Push;\r
27             checkBoxRepeat.Tag = NotificationType.Repeat;\r
28             checkBoxCont.Tag = NotificationType.Cont;\r
29             checkBoxPreliminary.Tag = NotificationType.Preliminary;\r
30 \r
31             // ReSharper disable once CoVariantArrayConversion\r
32             listBoxNotifications.Items.AddRange(Config.NotificationNames);\r
33         }\r
34 \r
35         private void listBoxNotifications_SelectedIndexChanged(object sender, EventArgs e)\r
36         {\r
37             if (listBoxNotifications.SelectedItem == null)\r
38                 return;\r
39             var notification = _notifications[(string)listBoxNotifications.SelectedItem];\r
40             switch (notification.Name)\r
41             {\r
42                 case "艦娘数超過":\r
43                 case "装備数超過":\r
44                     textBoxPreliminary.Visible = labelPreliminary.Visible = checkBoxPreliminary.Visible =\r
45                         textBoxRepeat.Visible = labelRepeat.Visible = checkBoxRepeat.Visible =\r
46                             checkBoxCont.Visible = false;\r
47                     break;\r
48                 default:\r
49                     textBoxRepeat.Visible = labelRepeat.Visible = checkBoxRepeat.Visible = true;\r
50                     checkBoxRepeat.Enabled = _configCheckBoxes[NotificationType.Repeat].Checked;\r
51                     textBoxRepeat.Text = notification.RepeatInterval.ToString();\r
52                     checkBoxCont.Visible = IsContAvailable;\r
53                     textBoxPreliminary.Visible =\r
54                         labelPreliminary.Visible = checkBoxPreliminary.Visible = IsPreliminaryAvailable;\r
55                     textBoxPreliminary.Text = notification.PreliminaryPeriod.ToString();\r
56                     break;\r
57             }\r
58             checkBoxFlashWindow.Checked = (notification.Flags & NotificationType.FlashWindow) != 0;\r
59             checkBoxShowBalloonTip.Checked = (notification.Flags & NotificationType.ShowBaloonTip) != 0;\r
60             checkBoxPlaySound.Checked = (notification.Flags & NotificationType.PlaySound) != 0;\r
61             checkBoxPush.Checked = (notification.Flags & NotificationType.Push) != 0;\r
62             checkBoxRepeat.Checked = (notification.Flags & NotificationType.Repeat) != 0;\r
63             _toolTip.SetToolTip(checkBoxCont,\r
64                 !IsContAvailable ? "" :\r
65                 notification.Name == "遠征終了" ? "再度遠征に出すまでリピートする。" : "再度入渠させるまでリピートする。");\r
66             checkBoxCont.Checked = (notification.Flags & NotificationType.Cont) != 0;\r
67             checkBoxPreliminary.Checked = (notification.Flags & NotificationType.Preliminary) != 0;\r
68         }\r
69 \r
70         private void checkBox_CheckedChanged(object sender, EventArgs e)\r
71         {\r
72             var checkBox = (CheckBox)sender;\r
73             var type = (NotificationType)checkBox.Tag;\r
74             var spec = _notifications[(string)listBoxNotifications.SelectedItem];\r
75             spec.Flags = checkBox.Checked ? spec.Flags | type : spec.Flags & ~type;\r
76             if (type == NotificationType.Repeat)\r
77             {\r
78                 textBoxRepeat.Enabled = labelRepeat.Enabled = checkBoxCont.Enabled =\r
79                     _configCheckBoxes[NotificationType.Repeat].Checked && checkBox.Checked;\r
80             }\r
81             if (type == NotificationType.Preliminary)\r
82                 textBoxPreliminary.Enabled = labelPreliminary.Enabled = checkBox.Checked;\r
83         }\r
84 \r
85         private bool IsContAvailable =>\r
86             new[] {"遠征終了", "入渠終了"}.Contains((string)listBoxNotifications.SelectedItem);\r
87 \r
88         private bool IsPreliminaryAvailable =>\r
89             new[] {"遠征終了", "入渠終了", "建造完了", "泊地修理20分経過", "疲労回復"}.Contains((string)listBoxNotifications.SelectedItem);\r
90 \r
91         private void textBoxRepeat_TextChanged(object sender, EventArgs e)\r
92         {\r
93             _notifications[(string)listBoxNotifications.SelectedItem].RepeatInterval =\r
94                 int.TryParse(textBoxRepeat.Text, out var interval) && interval > 0 ? interval : 0;\r
95         }\r
96 \r
97         private void NotificationConfigDialog_Load(object sender, EventArgs e)\r
98         {\r
99             checkBoxFlashWindow.Enabled = _configCheckBoxes[NotificationType.FlashWindow].Checked;\r
100             checkBoxShowBalloonTip.Enabled = _configCheckBoxes[NotificationType.ShowBaloonTip].Checked;\r
101             checkBoxPlaySound.Enabled = _configCheckBoxes[NotificationType.PlaySound].Checked;\r
102             checkBoxRepeat.Enabled = _configCheckBoxes[NotificationType.Repeat].Checked;\r
103             textBoxRepeat.Enabled = labelRepeat.Enabled = checkBoxCont.Enabled =\r
104                 checkBoxRepeat.Enabled && checkBoxRepeat.Checked;\r
105             textBoxPreliminary.Enabled = checkBoxPreliminary.Checked;\r
106 \r
107             var selected = listBoxNotifications.SelectedIndex;\r
108             listBoxNotifications.SelectedIndex = -1;\r
109             listBoxNotifications.SelectedIndex = selected == -1 ? 0 : selected;\r
110         }\r
111 \r
112         private void textBoxPreliminary_TextChanged(object sender, EventArgs e)\r
113         {\r
114             _notifications[(string)listBoxNotifications.SelectedItem].PreliminaryPeriod =\r
115                 int.TryParse(textBoxPreliminary.Text, out var preliminary) && preliminary > 0 ? preliminary : 0;\r
116         }\r
117 \r
118         protected override void ScaleControl(SizeF factor, BoundsSpecified specified)\r
119         {\r
120             base.ScaleControl(factor, specified);\r
121             if (factor.Height > 1)\r
122                 _toolTip.Font = new Font(_toolTip.Font.FontFamily, _toolTip.Font.Size * factor.Height);\r
123         }\r
124     }\r
125 }