2 using System.Collections.Generic;
\r
3 using System.Drawing;
\r
5 using System.Windows.Forms;
\r
6 using KancolleSniffer.View;
\r
8 namespace KancolleSniffer
\r
10 public partial class NotificationConfigDialog : Form
\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
16 public NotificationConfigDialog(Dictionary<string, NotificationSpec> notifications,
\r
17 Dictionary<NotificationType, CheckBox> checkBoxes)
\r
19 InitializeComponent();
\r
20 _notifications = notifications;
\r
21 _configCheckBoxes = checkBoxes;
\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
31 // ReSharper disable once CoVariantArrayConversion
\r
32 listBoxNotifications.Items.AddRange(Config.NotificationNames);
\r
35 private void listBoxNotifications_SelectedIndexChanged(object sender, EventArgs e)
\r
37 if (listBoxNotifications.SelectedItem == null)
\r
39 var notification = _notifications[(string)listBoxNotifications.SelectedItem];
\r
40 switch (notification.Name)
\r
44 textBoxPreliminary.Visible = labelPreliminary.Visible = checkBoxPreliminary.Visible =
\r
45 textBoxRepeat.Visible = labelRepeat.Visible = checkBoxRepeat.Visible =
\r
46 checkBoxCont.Visible = false;
\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
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
70 private void checkBox_CheckedChanged(object sender, EventArgs e)
\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
78 textBoxRepeat.Enabled = labelRepeat.Enabled = checkBoxCont.Enabled =
\r
79 _configCheckBoxes[NotificationType.Repeat].Checked && checkBox.Checked;
\r
81 if (type == NotificationType.Preliminary)
\r
82 textBoxPreliminary.Enabled = labelPreliminary.Enabled = checkBox.Checked;
\r
85 private bool IsContAvailable =>
\r
86 new[] {"遠征終了", "入渠終了"}.Contains((string)listBoxNotifications.SelectedItem);
\r
88 private bool IsPreliminaryAvailable =>
\r
89 new[] {"遠征終了", "入渠終了", "建造完了", "泊地修理20分経過", "疲労回復"}.Contains((string)listBoxNotifications.SelectedItem);
\r
91 private void textBoxRepeat_TextChanged(object sender, EventArgs e)
\r
93 _notifications[(string)listBoxNotifications.SelectedItem].RepeatInterval =
\r
94 int.TryParse(textBoxRepeat.Text, out var interval) && interval > 0 ? interval : 0;
\r
97 private void NotificationConfigDialog_Load(object sender, EventArgs e)
\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
107 var selected = listBoxNotifications.SelectedIndex;
\r
108 listBoxNotifications.SelectedIndex = -1;
\r
109 listBoxNotifications.SelectedIndex = selected == -1 ? 0 : selected;
\r
112 private void textBoxPreliminary_TextChanged(object sender, EventArgs e)
\r
114 _notifications[(string)listBoxNotifications.SelectedItem].PreliminaryPeriod =
\r
115 int.TryParse(textBoxPreliminary.Text, out var preliminary) && preliminary > 0 ? preliminary : 0;
\r
118 protected override void ScaleControl(SizeF factor, BoundsSpecified specified)
\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