2 using System.Collections.Generic;
\r
3 using System.Drawing;
\r
5 using System.Windows.Forms;
\r
7 namespace KancolleSniffer
\r
9 public partial class NotificationConfigDialog : Form
\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
15 public NotificationConfigDialog(Dictionary<string, NotificationSpec> notifications,
\r
16 Dictionary<NotificationType, CheckBox> checkBoxs)
\r
18 InitializeComponent();
\r
19 _notifications = notifications;
\r
20 _configCheckBoxs = checkBoxs;
\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
30 // ReSharper disable once CoVariantArrayConversion
\r
31 listBoxNotifications.Items.AddRange(Config.NotificationNames);
\r
34 private void listBoxNotifications_SelectedIndexChanged(object sender, EventArgs e)
\r
36 if (listBoxNotifications.SelectedItem == null)
\r
38 var notification = _notifications[(string)listBoxNotifications.SelectedItem];
\r
39 switch (notification.Name)
\r
43 textBoxPreliminary.Visible = labelPreliminary.Visible = checkBoxPreliminary.Visible =
\r
44 textBoxRepeat.Visible = labelRepeat.Visible = checkBoxRepeat.Visible =
\r
45 checkBoxCont.Visible = false;
\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
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
69 private void checkBox_CheckedChanged(object sender, EventArgs e)
\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
77 textBoxRepeat.Enabled = labelRepeat.Enabled = checkBoxCont.Enabled =
\r
78 _configCheckBoxs[NotificationType.Repeat].Checked && checkBox.Checked;
\r
80 if (type == NotificationType.Preliminary)
\r
81 textBoxPreliminary.Enabled = labelPreliminary.Enabled = checkBox.Checked;
\r
84 private bool IsContAvailable =>
\r
85 new[] {"遠征終了", "入渠終了"}.Contains((string)listBoxNotifications.SelectedItem);
\r
87 private bool IsPreliminaryAvailable =>
\r
88 new[] {"遠征終了", "入渠終了", "建造完了", "泊地修理20分経過", "疲労回復"}.Contains((string)listBoxNotifications.SelectedItem);
\r
90 private void textBoxRepeat_TextChanged(object sender, EventArgs e)
\r
92 _notifications[(string)listBoxNotifications.SelectedItem].RepeatInterval =
\r
93 int.TryParse(textBoxRepeat.Text, out var interval) && interval > 0 ? interval : 0;
\r
96 private void NotificationConfigDialog_Load(object sender, EventArgs e)
\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
106 var selected = listBoxNotifications.SelectedIndex;
\r
107 listBoxNotifications.SelectedIndex = -1;
\r
108 listBoxNotifications.SelectedIndex = selected == -1 ? 0 : selected;
\r
111 private void textBoxPreliminary_TextChanged(object sender, EventArgs e)
\r
113 _notifications[(string)listBoxNotifications.SelectedItem].PreliminaryPeriod =
\r
114 int.TryParse(textBoxPreliminary.Text, out var preliminary) && preliminary > 0 ? preliminary : 0;
\r
117 protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
\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