private readonly ResizableToolTip _tooltipCopy = new ResizableToolTip {ShowAlways = false, AutomaticDelay = 0};\r
private readonly ListFormGroup _listFormGroup;\r
\r
- private readonly Scheduler _notificationScheduler;\r
+ private readonly Notifier _notifier;\r
private bool _started;\r
private bool _timerEnabled;\r
private string _debugLogFile;\r
public Sniffer Sniffer { get; } = new Sniffer();\r
public Config Config { get; } = new Config();\r
\r
- public interface INotifySubmitter\r
- {\r
- void Flash();\r
- void Enqueue(string key, string subject);\r
- }\r
-\r
public MainForm()\r
{\r
InitializeComponent();\r
Config.Load();\r
_configDialog = new ConfigDialog(this);\r
_listFormGroup = new ListFormGroup(this);\r
- _notificationScheduler = new Scheduler(Alarm);\r
+ _notifier = new Notifier(FlashWindow, ShowTaster, PlaySound);\r
SetupView();\r
_proxyManager = new ProxyManager(this);\r
_proxyManager.UpdatePacFile();\r
_errorLog = new ErrorLog(Sniffer);\r
LoadData();\r
- Sniffer.RepeatingTimerController = new RepeatingTimerController(this);\r
+ Sniffer.RepeatingTimerController = _notifier;\r
}\r
\r
private void SetupView()\r
_updateable = new IUpdateContext[]\r
{\r
hqPanel, missionPanel, kdockPanel, ndockPanel, materialHistoryPanel, shipInfoPanel, chargeStatus1,\r
- chargeStatus2, chargeStatus3, chargeStatus4\r
+ chargeStatus2, chargeStatus3, chargeStatus4, _notifier\r
};\r
- var context = new UpdateContext(Sniffer, Config, new NotifySubmitter(_notificationScheduler), () => _now);\r
+ var context = new UpdateContext(Sniffer, Config, () => _now, () => _prev);\r
foreach (var updateable in _updateable)\r
updateable.Context = context;\r
_timers = new IUpdateTimers[] {missionPanel, kdockPanel, ndockPanel, shipInfoPanel};\r
Height += questPanel.Height - prevHeight;\r
}\r
\r
- private class NotifySubmitter : INotifySubmitter\r
- {\r
- private readonly Scheduler _manager;\r
-\r
- public NotifySubmitter(Scheduler manager)\r
- {\r
- _manager = manager;\r
- }\r
-\r
- public void Flash()\r
- {\r
- _manager.Flush();\r
- }\r
-\r
- public void Enqueue(string key, string subject)\r
- {\r
- _manager.Enqueue(key, subject);\r
- }\r
- }\r
-\r
private readonly FileSystemWatcher _watcher = new FileSystemWatcher\r
{\r
Path = AppDomain.CurrentDomain.BaseDirectory,\r
_watcher.EnableRaisingEvents = true;\r
}\r
\r
- private class RepeatingTimerController : Sniffer.IRepeatingTimerController\r
- {\r
- private readonly Scheduler _manager;\r
- private readonly Config _config;\r
-\r
- public RepeatingTimerController(MainForm main)\r
- {\r
- _manager = main._notificationScheduler;\r
- _config = main.Config;\r
- }\r
-\r
- public void Stop(string key)\r
- {\r
- _manager.StopRepeat(key,\r
- (key == "入渠終了" || key == "遠征終了") &&\r
- (_config.Notifications[key].Flags & NotificationType.Cont) != 0);\r
- }\r
-\r
- public void Stop(string key, int fleet) => _manager.StopRepeat(key, fleet);\r
-\r
- public void Suspend(string exception = null) => _manager.SuspendRepeat(exception);\r
-\r
- public void Resume() => _manager.ResumeRepeat();\r
- }\r
-\r
private void HttpProxy_AfterSessionComplete(HttpProxy.Session session)\r
{\r
BeginInvoke(new Action<HttpProxy.Session>(ProcessRequest), session);\r
hqPanel.Login.Visible = false;\r
shipInfoPanel.Guide.Visible = false;\r
_started = true;\r
- _notificationScheduler.StopAllRepeat();\r
+ _notifier.StopAllRepeat();\r
return;\r
}\r
if (!_started)\r
{\r
Config.Save();\r
ApplyConfig();\r
- StopRepeatingTimer(_configDialog.RepeatSettingsChanged);\r
+ _notifier.StopRepeatingTimer(_configDialog.RepeatSettingsChanged);\r
}\r
}\r
\r
- private void StopRepeatingTimer(IEnumerable<string> names)\r
- {\r
- foreach (var name in names)\r
- _notificationScheduler.StopRepeat(name);\r
- }\r
-\r
private void PerformZoom()\r
{\r
if (Config.Zoom == 100)\r
Sniffer.ShipCounter.Margin = Config.MarginShips;\r
Sniffer.ItemCounter.Margin = Config.MarginEquips;\r
hqPanel.Update();\r
+ _notifier.NotifyShipItemCount();\r
Sniffer.Achievement.ResetHours = Config.ResetHours;\r
labelAkashiRepair.Visible = labelAkashiRepairTimer.Visible = Config.UsePresetAkashi;\r
Sniffer.WarnBadDamageWithDameCon = Config.WarnBadDamageWithDameCon;\r
{\r
_now = DateTime.Now;\r
UpdateTimers();\r
- NotifyTimers();\r
+ _notifier.NotifyTimers();\r
_prev = _now;\r
}\r
catch (Exception ex)\r
private void UpdateItemInfo()\r
{\r
hqPanel.Update();\r
+ _notifier.NotifyShipItemCount();\r
materialHistoryPanel.Update();\r
if (_listFormGroup.Visible)\r
_listFormGroup.UpdateList();\r
{\r
shipInfoPanel.SetCurrentFleet();\r
shipInfoPanel.Update();\r
- NotifyDamagedShip();\r
+ _notifier.NotifyDamagedShip();\r
UpdateChargeInfo();\r
UpdateRepairList();\r
UpdateMissionLabels();\r
}\r
}\r
\r
- private void NotifyDamagedShip()\r
- {\r
- _notificationScheduler.StopRepeat("大破警告");\r
- if (!Sniffer.BadlyDamagedShips.Any())\r
- return;\r
- SetNotification("大破警告", string.Join(" ", Sniffer.BadlyDamagedShips));\r
- _notificationScheduler.Flush();\r
- }\r
-\r
private void UpdateBattleInfo()\r
{\r
_listFormGroup.UpdateBattleResult();\r
_timerEnabled = true;\r
}\r
\r
- private void NotifyTimers()\r
- {\r
- for (var i = 0; i < Sniffer.Missions.Length; i++)\r
- {\r
- var entry = Sniffer.Missions[i];\r
- if (entry.Name == "前衛支援任務" || entry.Name == "艦隊決戦支援任務")\r
- continue;\r
- CheckAlarm("遠征終了", entry.Timer, i + 1, entry.Name);\r
- }\r
- for (var i = 0; i < Sniffer.NDock.Length; i++)\r
- {\r
- var entry = Sniffer.NDock[i];\r
- CheckAlarm("入渠終了", entry.Timer, i, entry.Name);\r
- }\r
- for (var i = 0; i < Sniffer.KDock.Length; i++)\r
- {\r
- var timer = Sniffer.KDock[i];\r
- CheckAlarm("建造完了", timer, i, "");\r
- }\r
- NotifyCondTimers();\r
- NotifyAkashiTimer();\r
- _notificationScheduler.Flush();\r
- }\r
-\r
- private void CheckAlarm(string key, AlarmTimer timer, int fleet, string subject)\r
- {\r
- if (timer.CheckAlarm(_prev, _now))\r
- {\r
- SetNotification(key, fleet, subject);\r
- return;\r
- }\r
- var pre = TimeSpan.FromSeconds(Config.Notifications[key].PreliminaryPeriod);\r
- if (pre == TimeSpan.Zero)\r
- return;\r
- if (timer.CheckAlarm(_prev + pre, _now + pre))\r
- SetPreNotification(key, fleet, subject);\r
- }\r
-\r
- private void NotifyCondTimers()\r
- {\r
- var notice = Sniffer.GetConditionNotice(_prev, _now);\r
- var pre = TimeSpan.FromSeconds(Config.Notifications["疲労回復"].PreliminaryPeriod);\r
- var preNotice = pre == TimeSpan.Zero\r
- ? new int[ShipInfo.FleetCount]\r
- : Sniffer.GetConditionNotice(_prev + pre, _now + pre);\r
- for (var i = 0; i < ShipInfo.FleetCount; i++)\r
- {\r
- if (Config.NotifyConditions.Contains(notice[i]))\r
- {\r
- SetNotification("疲労回復" + notice[i], i, "cond" + notice[i]);\r
- }\r
- else if (Config.NotifyConditions.Contains(preNotice[i]))\r
- {\r
- SetPreNotification("疲労回復" + preNotice[i], i, "cond" + notice[i]);\r
- }\r
- }\r
- }\r
-\r
- private void NotifyAkashiTimer()\r
- {\r
- var akashi = Sniffer.AkashiTimer;\r
- var msgs = akashi.GetNotice(_prev, _now);\r
- if (msgs.Length == 0)\r
- {\r
- _notificationScheduler.StopRepeat("泊地修理");\r
- return;\r
- }\r
- if (!akashi.CheckRepairing(_now) && !(akashi.CheckPresetRepairing() && Config.UsePresetAkashi))\r
- {\r
- _notificationScheduler.StopRepeat("泊地修理");\r
- return;\r
- }\r
- var skipPreliminary = false;\r
- if (msgs[0].Proceeded == "20分経過しました。")\r
- {\r
- SetNotification("泊地修理20分経過", msgs[0].Proceeded);\r
- msgs[0].Proceeded = "";\r
- skipPreliminary = true;\r
- // 修理完了がいるかもしれないので続ける\r
- }\r
- for (var i = 0; i < ShipInfo.FleetCount; i++)\r
- {\r
- if (msgs[i].Proceeded != "")\r
- SetNotification("泊地修理進行", i, msgs[i].Proceeded);\r
- if (msgs[i].Completed != "")\r
- SetNotification("泊地修理完了", i, msgs[i].Completed);\r
- }\r
- var pre = TimeSpan.FromSeconds(Config.Notifications["泊地修理20分経過"].PreliminaryPeriod);\r
- if (skipPreliminary || pre == TimeSpan.Zero)\r
- return;\r
- if ((msgs = akashi.GetNotice(_prev + pre, _now + pre))[0].Proceeded == "20分経過しました。")\r
- SetPreNotification("泊地修理20分経過", 0, msgs[0].Proceeded);\r
- }\r
-\r
- private void SetNotification(string key, string subject)\r
- {\r
- SetNotification(key, 0, subject);\r
- }\r
-\r
- private void SetNotification(string key, int fleet, string subject)\r
- {\r
- var spec = Config.Notifications[_notificationScheduler.KeyToName(key)];\r
- _notificationScheduler.Enqueue(key, fleet, subject,\r
- (spec.Flags & Config.NotificationFlags & NotificationType.Repeat) == 0 ? 0 : spec.RepeatInterval);\r
- }\r
-\r
- private void SetPreNotification(string key, int fleet, string subject)\r
- {\r
- var spec = Config.Notifications[_notificationScheduler.KeyToName(key)];\r
- if ((spec.Flags & NotificationType.Preliminary) != 0)\r
- _notificationScheduler.Enqueue(key, fleet, subject, 0, true);\r
- }\r
-\r
private void UpdateRepairList()\r
{\r
panelRepairList.SetRepairList(Sniffer.RepairList);\r
{\r
questPanel.Update(Sniffer.Quests);\r
labelQuestCount.Text = Sniffer.Quests.Length.ToString();\r
- SetQuestNotification();\r
+ _notifier.NotifyQuestComplete();\r
}\r
\r
- private void SetQuestNotification()\r
+ private void FlashWindow()\r
{\r
- Sniffer.GetQuestNotifications(out var notify, out var stop);\r
- foreach (var questName in notify)\r
- SetNotification("任務達成", 0, questName);\r
- foreach (var questName in stop)\r
- _notificationScheduler.StopRepeat("任務達成", questName);\r
- _notificationScheduler.Flush();\r
+ Win32API.FlashWindow(Handle);\r
}\r
\r
- private void Alarm(string balloonTitle, string balloonMessage, string name)\r
+ private void ShowTaster(string title, string message)\r
{\r
- var flags = Config.Notifications[name].Flags;\r
- var effective = Config.NotificationFlags & Config.Notifications[name].Flags;\r
- if ((effective & NotificationType.FlashWindow) != 0)\r
- Win32API.FlashWindow(Handle);\r
- if ((effective & NotificationType.ShowBaloonTip) != 0)\r
- notifyIconMain.ShowBalloonTip(20000, balloonTitle, balloonMessage, ToolTipIcon.Info);\r
- if ((effective & NotificationType.PlaySound) != 0)\r
- PlaySound(Config.Sounds[name], Config.Sounds.Volume);\r
- if (Config.Pushbullet.On && (flags & NotificationType.Push) != 0)\r
- {\r
- Task.Run(() =>\r
- {\r
- PushNotification.PushToPushbullet(Config.Pushbullet.Token, balloonTitle, balloonMessage);\r
- });\r
- }\r
- if (Config.Pushover.On && (flags & NotificationType.Push) != 0)\r
- {\r
- Task.Run(() =>\r
- {\r
- PushNotification.PushToPushover(Config.Pushover.ApiKey, Config.Pushover.UserKey,\r
- balloonTitle, balloonMessage);\r
- });\r
- }\r
+ notifyIconMain.ShowBalloonTip(20000, title, message, ToolTipIcon.Info);\r
}\r
\r
[DllImport("winmm.dll")]\r