OSDN Git Service

6a2f36f6393e31f9fc41a1d92a8b0bf6f8209c0c
[kancollesniffer/KancolleSniffer.git] / KancolleSniffer / MainForm.cs
1 // Copyright (C) 2013, 2014, 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
2 // \r
3 // Licensed under the Apache License, Version 2.0 (the "License");\r
4 // you may not use this file except in compliance with the License.\r
5 // You may obtain a copy of the License at\r
6 //\r
7 //    http://www.apache.org/licenses/LICENSE-2.0\r
8 //\r
9 // Unless required by applicable law or agreed to in writing, software\r
10 // distributed under the License is distributed on an "AS IS" BASIS,\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12 // See the License for the specific language governing permissions and\r
13 // limitations under the License.\r
14 \r
15 using System;\r
16 using System.Collections.Generic;\r
17 using System.Diagnostics;\r
18 using System.Drawing;\r
19 using System.Globalization;\r
20 using System.IO;\r
21 using System.Linq;\r
22 using System.Net;\r
23 using System.Runtime.InteropServices;\r
24 using System.Text;\r
25 using System.Text.RegularExpressions;\r
26 using System.Threading.Tasks;\r
27 using System.Windows.Forms;\r
28 using Microsoft.CSharp.RuntimeBinder;\r
29 using static System.Math;\r
30 \r
31 namespace KancolleSniffer\r
32 {\r
33     public partial class MainForm : Form\r
34     {\r
35         private readonly Sniffer _sniffer = new Sniffer();\r
36         private readonly Config _config = new Config();\r
37         private readonly ConfigDialog _configDialog;\r
38         private readonly ProxyManager _proxyManager;\r
39         private readonly ToolTip _toolTipQuest = new ToolTip {ShowAlways = true, AutoPopDelay = 10000};\r
40         private readonly ToolTip _toolTipCount = new ToolTip {ShowAlways = true};\r
41         private readonly ToolTip _tooltipCopy = new ToolTip {AutomaticDelay = 0};\r
42         private int _currentFleet;\r
43         private bool _combinedFleet;\r
44         private readonly Label[] _labelCheckFleets;\r
45         private readonly MainFormLabels _mainLabels;\r
46         private readonly ListForm _listForm;\r
47         private readonly NotificationManager _notificationManager;\r
48         private bool _started;\r
49         private bool _timerEnabled;\r
50         private string _debugLogFile;\r
51         private IEnumerator<string> _playLog;\r
52         private DateTime _prev, _now;\r
53         private bool _inSortie;\r
54 \r
55         private readonly ErrorDialog _errorDialog = new ErrorDialog();\r
56         private readonly ErrorLog _errorLog;\r
57 \r
58         public MainForm()\r
59         {\r
60             InitializeComponent();\r
61             HttpProxy.AfterSessionComplete += HttpProxy_AfterSessionComplete;\r
62             _configDialog = new ConfigDialog(_config, this);\r
63             _labelCheckFleets = new[] {labelCheckFleet1, labelCheckFleet2, labelCheckFleet3, labelCheckFleet4};\r
64 \r
65             // この時点でAutoScaleDimensions == CurrentAutoScaleDimensionsなので、\r
66             // MainForm.Designer.csのAutoScaleDimensionsの6f,12fを使う。\r
67             ShipLabel.ScaleFactor = new SizeF(CurrentAutoScaleDimensions.Width / 6f,\r
68                 CurrentAutoScaleDimensions.Height / 12f);\r
69 \r
70             SetupFleetClick();\r
71             _mainLabels = new MainFormLabels();\r
72             _mainLabels.CreateAkashiTimers(panelShipInfo);\r
73             _mainLabels.CreateShipLabels(panelShipInfo, ShowShipOnShipList);\r
74             _mainLabels.CreateAkashiTimers7(panel7Ships);\r
75             _mainLabels.CreateShipLabels7(panel7Ships, ShowShipOnShipList);\r
76             _mainLabels.CreateCombinedShipLabels(panelCombinedFleet, ShowShipOnShipList);\r
77             _mainLabels.CreateNDockLabels(panelDock, labelNDock_Click);\r
78             panelRepairList.CreateLabels(panelRepairList_Click);\r
79             labelPresetAkashiTimer.BackColor = ShipLabel.ColumnColors[1];\r
80             _listForm = new ListForm(_sniffer, _config) {Owner = this};\r
81             _notificationManager = new NotificationManager(Alarm);\r
82             try\r
83             {\r
84                 _config.Load();\r
85             }\r
86             catch (Exception ex)\r
87             {\r
88                 throw new ConfigFileException("設定ファイルが壊れています。", ex);\r
89             }\r
90             _proxyManager = new ProxyManager(_config, this);\r
91             _errorLog = new ErrorLog(_sniffer);\r
92             _proxyManager.UpdatePacFile();\r
93             PerformZoom();\r
94             _mainLabels.AdjustAkashiTimers();\r
95             LoadData();\r
96             _sniffer.RepeatingTimerController = new RepeatingTimerController(_notificationManager, _config);\r
97         }\r
98 \r
99         /// <summary>\r
100         /// パネルのz-orderがくるうのを避ける\r
101         /// https://stackoverflow.com/a/5777090/1429506\r
102         /// </summary>\r
103         private void MainForm_Shown(object sender, EventArgs e)\r
104         {\r
105             // ReSharper disable once NotAccessedVariable\r
106             IntPtr handle;\r
107             foreach (var panel in new[] {panelShipInfo, panel7Ships, panelCombinedFleet})\r
108                 // ReSharper disable once RedundantAssignment\r
109                 handle = panel.Handle;\r
110         }\r
111 \r
112         private readonly FileSystemWatcher _watcher = new FileSystemWatcher\r
113         {\r
114             Path = AppDomain.CurrentDomain.BaseDirectory,\r
115             NotifyFilter = NotifyFilters.LastWrite\r
116         };\r
117 \r
118         private readonly Timer _watcherTimer = new Timer {Interval = 1000};\r
119 \r
120         private void LoadData()\r
121         {\r
122             var target = "";\r
123             _sniffer.LoadState();\r
124             DataLoader.LoadTpSpec();\r
125             _watcher.SynchronizingObject = this;\r
126             _watcherTimer.Tick += (sender, ev) =>\r
127             {\r
128                 _watcherTimer.Stop();\r
129                 switch (target)\r
130                 {\r
131                     case "status.xml":\r
132                         _sniffer.LoadState();\r
133                         break;\r
134                     case "TP.csv":\r
135                         DataLoader.LoadTpSpec();\r
136                         break;\r
137                 }\r
138             };\r
139             _watcher.Changed += (sender, ev) =>\r
140             {\r
141                 target = ev.Name;\r
142                 _watcherTimer.Stop();\r
143                 _watcherTimer.Start();\r
144             };\r
145             _watcher.EnableRaisingEvents = true;\r
146         }\r
147 \r
148         private class RepeatingTimerController : Sniffer.IRepeatingTimerController\r
149         {\r
150             private readonly NotificationManager _manager;\r
151             private readonly Config _config;\r
152 \r
153             public RepeatingTimerController(NotificationManager manager, Config config)\r
154             {\r
155                 _manager = manager;\r
156                 _config = config;\r
157             }\r
158 \r
159             public void Stop(string key)\r
160             {\r
161                 _manager.StopRepeat(key,\r
162                     (key == "入渠終了" || key == "遠征終了") &&\r
163                     (_config.Notifications[key].Flags & NotificationType.Cont) != 0);\r
164             }\r
165 \r
166             public void Stop(string key, int fleet) => _manager.StopRepeat(key, fleet);\r
167 \r
168             public void Suspend() => _manager.SuspendRepeat();\r
169 \r
170             public void Resume() => _manager.ResumeRepeat();\r
171         }\r
172 \r
173         public class ConfigFileException : Exception\r
174         {\r
175             public ConfigFileException(string message, Exception innerException) : base(message, innerException)\r
176             {\r
177             }\r
178         }\r
179 \r
180         private void HttpProxy_AfterSessionComplete(HttpProxy.Session session)\r
181         {\r
182             BeginInvoke(new Action<HttpProxy.Session>(ProcessRequest), session);\r
183         }\r
184 \r
185         private void ProcessRequest(HttpProxy.Session session)\r
186         {\r
187             var url = session.Request.PathAndQuery;\r
188             if (!url.Contains("kcsapi/"))\r
189                 return;\r
190             var request = session.Request.BodyAsString;\r
191             var response = session.Response.BodyAsString;\r
192             if (response == null || !response.StartsWith("svdata="))\r
193             {\r
194                 WriteDebugLog(url, request, response);\r
195                 return;\r
196             }\r
197             response = UnescapeString(response.Remove(0, "svdata=".Length));\r
198             WriteDebugLog(url, request, response);\r
199             ProcessRequestMain(url, request, response);\r
200         }\r
201 \r
202         private void ProcessRequestMain(string url, string request, string response)\r
203         {\r
204             try\r
205             {\r
206                 UpdateInfo(_sniffer.Sniff(url, request, JsonParser.Parse(response)));\r
207                 _errorLog.CheckBattleApi(url, request, response);\r
208             }\r
209 \r
210             catch (RuntimeBinderException e)\r
211             {\r
212                 if (_errorDialog.ShowDialog(this,\r
213                         "艦これに仕様変更があったか、受信内容が壊れています。",\r
214                         _errorLog.GenerateErrorLog(url, request, response, e.ToString())) == DialogResult.Abort)\r
215                     Exit();\r
216             }\r
217             catch (LogIOException e)\r
218             {\r
219                 // ReSharper disable once PossibleNullReferenceException\r
220                 if (_errorDialog.ShowDialog(this, e.Message, e.InnerException.ToString()) == DialogResult.Abort)\r
221                     Exit();\r
222             }\r
223             catch (BattleResultError)\r
224             {\r
225                 if (_errorDialog.ShowDialog(this, "戦闘結果の計算に誤りがあります。",\r
226                         _errorLog.GenerateBattleErrorLog()) == DialogResult.Abort)\r
227                     Exit();\r
228             }\r
229             catch (Exception e)\r
230             {\r
231                 if (_errorDialog.ShowDialog(this, "エラーが発生しました。",\r
232                         _errorLog.GenerateErrorLog(url, request, response, e.ToString())) == DialogResult.Abort)\r
233                     Exit();\r
234             }\r
235         }\r
236 \r
237         private void Exit()\r
238         {\r
239             _proxyManager.Shutdown();\r
240             Environment.Exit(1);\r
241         }\r
242 \r
243         private void WriteDebugLog(string url, string request, string response)\r
244         {\r
245             if (_debugLogFile != null)\r
246             {\r
247                 File.AppendAllText(_debugLogFile,\r
248                     $"date: {DateTime.Now:g}\nurl: {url}\nrequest: {request}\nresponse: {response ?? "(null)"}\n");\r
249             }\r
250         }\r
251 \r
252         private string UnescapeString(string s)\r
253         {\r
254             try\r
255             {\r
256                 var rx = new Regex(@"\\[uU]([0-9A-Fa-f]{4})");\r
257                 return rx.Replace(s,\r
258                     match => ((char)int.Parse(match.Value.Substring(2), NumberStyles.HexNumber)).ToString());\r
259             }\r
260             catch (ArgumentException)\r
261             {\r
262                 return s;\r
263             }\r
264         }\r
265 \r
266         private void UpdateInfo(Sniffer.Update update)\r
267         {\r
268             if (update == Sniffer.Update.Start)\r
269             {\r
270                 labelLogin.Visible = false;\r
271                 linkLabelGuide.Visible = false;\r
272                 _started = true;\r
273                 return;\r
274             }\r
275             if (!_started)\r
276                 return;\r
277             if (_now == DateTime.MinValue)\r
278                 _now = DateTime.Now;\r
279             if ((update & Sniffer.Update.Item) != 0)\r
280                 UpdateItemInfo();\r
281             if ((update & Sniffer.Update.Timer) != 0)\r
282                 UpdateTimers();\r
283             if ((update & Sniffer.Update.NDock) != 0)\r
284                 UpdateNDocLabels();\r
285             if ((update & Sniffer.Update.Mission) != 0)\r
286                 UpdateMissionLabels();\r
287             if ((update & Sniffer.Update.QuestList) != 0)\r
288                 UpdateQuestList();\r
289             if ((update & Sniffer.Update.Ship) != 0)\r
290                 UpdateShipInfo();\r
291             if ((update & Sniffer.Update.Battle) != 0)\r
292                 UpdateBattleInfo();\r
293         }\r
294 \r
295         private void MainForm_Load(object sender, EventArgs e)\r
296         {\r
297             RestoreLocation();\r
298             if (_config.HideOnMinimized && WindowState == FormWindowState.Minimized)\r
299                 ShowInTaskbar = false;\r
300             if (_config.ShowHpInPercent)\r
301                 _mainLabels.ToggleHpPercent();\r
302             if (_config.ShipList.Visible)\r
303                 _listForm.Show();\r
304             ApplyConfig();\r
305             ApplyDebugLogSetting();\r
306             ApplyLogSetting();\r
307             ApplyProxySetting();\r
308             CheckVersionUp((current, latest) =>\r
309             {\r
310                 if (double.Parse(latest) <= double.Parse(current))\r
311                     return;\r
312                 linkLabelGuide.Text = $"バージョン{latest}があります。";\r
313                 linkLabelGuide.LinkArea = new LinkArea(0, linkLabelGuide.Text.Length);\r
314                 linkLabelGuide.Click += (obj, ev) =>\r
315                 {\r
316                     Process.Start("https://ja.osdn.net/rel/kancollesniffer/" + latest);\r
317                 };\r
318             });\r
319         }\r
320 \r
321         public async void CheckVersionUp(Action<string, string> action)\r
322         {\r
323             var current = string.Join(".", Application.ProductVersion.Split('.').Take(2));\r
324             try\r
325             {\r
326                 var latest = (await new WebClient().DownloadStringTaskAsync("http://kancollesniffer.osdn.jp/version"))\r
327                     .TrimEnd();\r
328                 try\r
329                 {\r
330                     action(current, latest);\r
331                 }\r
332                 catch (InvalidOperationException)\r
333                 {\r
334                 }\r
335             }\r
336             catch (WebException)\r
337             {\r
338             }\r
339         }\r
340 \r
341         private void MainForm_FormClosing(object sender, FormClosingEventArgs e)\r
342         {\r
343             if (!_config.ExitSilently)\r
344             {\r
345                 using (var dialog = new ConfirmDialog())\r
346                 {\r
347                     if (dialog.ShowDialog(this) != DialogResult.Yes)\r
348                     {\r
349                         e.Cancel = true;\r
350                         return;\r
351                     }\r
352                 }\r
353             }\r
354             e.Cancel = false;\r
355             _sniffer.FlashLog();\r
356             _config.Location = (WindowState == FormWindowState.Normal ? Bounds : RestoreBounds).Location;\r
357             _config.ShowHpInPercent = _mainLabels.ShowHpInPercent;\r
358             _config.ShipList.Visible = _listForm.Visible && _listForm.WindowState == FormWindowState.Normal;\r
359             _config.Save();\r
360             _sniffer.SaveState();\r
361             _proxyManager.Shutdown();\r
362         }\r
363 \r
364         private void MainForm_Resize(object sender, EventArgs e)\r
365         {\r
366             ShowInTaskbar = !(_config.HideOnMinimized && WindowState == FormWindowState.Minimized);\r
367         }\r
368 \r
369         private void notifyIconMain_MouseDoubleClick(object sender, MouseEventArgs e)\r
370         {\r
371             NotifyIconOpenToolStripMenuItem_Click(sender, e);\r
372         }\r
373 \r
374         private void NotifyIconOpenToolStripMenuItem_Click(object sender, EventArgs e)\r
375         {\r
376             ShowInTaskbar = true;\r
377             WindowState = FormWindowState.Normal;\r
378             TopMost = _config.TopMost; // 最前面に表示されなくなることがあるのを回避する\r
379             Activate();\r
380         }\r
381 \r
382         private void ExitToolStripMenuItem_Click(object sender, EventArgs e)\r
383         {\r
384             Close();\r
385         }\r
386 \r
387         private void ConfigToolStripMenuItem_Click(object sender, EventArgs e)\r
388         {\r
389             if (_configDialog.ShowDialog(this) == DialogResult.OK)\r
390             {\r
391                 _config.Save();\r
392                 ApplyConfig();\r
393                 StopRepeatingTimer(_configDialog.RepeatSettingsChanged);\r
394             }\r
395         }\r
396 \r
397         private void StopRepeatingTimer(IEnumerable<string> names)\r
398         {\r
399             foreach (var name in names)\r
400                 _notificationManager.StopRepeat(name);\r
401         }\r
402 \r
403         private void PerformZoom()\r
404         {\r
405             if (_config.Zoom == 100)\r
406                 return;\r
407             var prev = CurrentAutoScaleDimensions;\r
408             foreach (var control in new Control[]\r
409             {\r
410                 this, _listForm, labelLogin, linkLabelGuide,\r
411                 _configDialog, _configDialog.NotificationConfigDialog,\r
412                 contextMenuStripMain, _errorDialog\r
413             })\r
414             {\r
415                 control.Font = new Font(control.Font.FontFamily, control.Font.Size * _config.Zoom / 100);\r
416             }\r
417             ShipLabel.LatinFont = new Font("Tahoma", 8f * _config.Zoom / 100);\r
418             var cur = CurrentAutoScaleDimensions;\r
419             ShipLabel.ScaleFactor = new SizeF(ShipLabel.ScaleFactor.Width * cur.Width / prev.Width,\r
420                 ShipLabel.ScaleFactor.Height * cur.Height / prev.Height);\r
421         }\r
422 \r
423         private void RestoreLocation()\r
424         {\r
425             if (_config.Location.X == int.MinValue)\r
426                 return;\r
427             if (IsTitleBarOnAnyScreen(_config.Location))\r
428                 Location = _config.Location;\r
429         }\r
430 \r
431         private void ApplyConfig()\r
432         {\r
433             _listForm.TopMost = TopMost = _config.TopMost;\r
434             _sniffer.Item.MarginShips = _config.MarginShips;\r
435             UpdateNumOfShips();\r
436             _sniffer.Item.MarginEquips = _config.MarginEquips;\r
437             UpdateNumOfEquips();\r
438             _sniffer.Achievement.ResetHours = _config.ResetHours;\r
439             labelAkashiRepair.Visible = labelAkashiRepairTimer.Visible =\r
440                 labelPresetAkashiTimer.Visible = _config.UsePresetAkashi;\r
441         }\r
442 \r
443         public void ApplyDebugLogSetting()\r
444         {\r
445             _debugLogFile = _config.DebugLogging ? _config.DebugLogFile : null;\r
446         }\r
447 \r
448         public bool ApplyProxySetting()\r
449         {\r
450             return _proxyManager.ApplyConfig();\r
451         }\r
452 \r
453         public void ApplyLogSetting()\r
454         {\r
455             LogServer.OutputDir = _config.Log.OutputDir;\r
456             LogServer.MaterialHistory = _sniffer.Material.MaterialHistory;\r
457             _sniffer.EnableLog(_config.Log.On ? LogType.All : LogType.None);\r
458             _sniffer.MaterialLogInterval = _config.Log.MaterialLogInterval;\r
459             _sniffer.LogOutputDir = _config.Log.OutputDir;\r
460         }\r
461 \r
462         public static bool IsTitleBarOnAnyScreen(Point location)\r
463         {\r
464             var rect = new Rectangle(\r
465                 new Point(location.X + SystemInformation.IconSize.Width + SystemInformation.HorizontalFocusThickness,\r
466                     location.Y + SystemInformation.CaptionHeight), new Size(60, 1));\r
467             return Screen.AllScreens.Any(screen => screen.WorkingArea.Contains(rect));\r
468         }\r
469 \r
470         private void timerMain_Tick(object sender, EventArgs e)\r
471         {\r
472             if (_timerEnabled)\r
473             {\r
474                 try\r
475                 {\r
476                     _now = DateTime.Now;\r
477                     UpdateTimers();\r
478                     NotifyTimers();\r
479                     _prev = _now;\r
480                 }\r
481                 catch (Exception ex)\r
482                 {\r
483                     if (_errorDialog.ShowDialog(this, "エラーが発生しました。", ex.ToString()) == DialogResult.Abort)\r
484                         Exit();\r
485                 }\r
486             }\r
487             if (_playLog == null || _configDialog.Visible)\r
488             {\r
489                 labelPlayLog.Visible = false;\r
490                 return;\r
491             }\r
492             PlayLog();\r
493         }\r
494 \r
495         public void SetPlayLog(string file)\r
496         {\r
497             _playLog = File.ReadLines(file).GetEnumerator();\r
498         }\r
499 \r
500         private void PlayLog()\r
501         {\r
502             var lines = new List<string>();\r
503             foreach (var s in new[] {"url: ", "request: ", "response: "})\r
504             {\r
505                 do\r
506                 {\r
507                     if (!_playLog.MoveNext() || _playLog.Current == null)\r
508                     {\r
509                         labelPlayLog.Visible = false;\r
510                         return;\r
511                     }\r
512                 } while (!_playLog.Current.StartsWith(s));\r
513                 lines.Add(_playLog.Current.Substring(s.Length));\r
514             }\r
515             labelPlayLog.Visible = !labelPlayLog.Visible;\r
516             ProcessRequestMain(lines[0], lines[1], lines[2]);\r
517         }\r
518 \r
519         private void ShowShipOnShipList(object sender, EventArgs ev)\r
520         {\r
521             if (!_listForm.Visible)\r
522                 return;\r
523             var idx = (int)((Control)sender).Tag;\r
524             var statuses = _sniffer.GetShipStatuses(_currentFleet);\r
525             if (statuses.Length <= idx)\r
526                 return;\r
527             _listForm.ShowShip(statuses[idx].Id);\r
528         }\r
529 \r
530         private void UpdateItemInfo()\r
531         {\r
532             UpdateNumOfShips();\r
533             UpdateNumOfEquips();\r
534             _notificationManager.Flash();\r
535             labelNumOfBuckets.Text = _sniffer.Material.MaterialHistory[(int)Material.Bucket].Now.ToString("D");\r
536             UpdateBucketHistory();\r
537             var ac = _sniffer.Achievement.Value;\r
538             if (ac >= 10000)\r
539                 ac = 9999;\r
540             labelAchievement.Text = ac >= 1000 ? ((int)ac).ToString("D") : ac.ToString("F1");\r
541             toolTipAchievement.SetToolTip(labelAchievement,\r
542                 "今月 " + _sniffer.Achievement.ValueOfMonth.ToString("F1") + "\n" +\r
543                 "EO " + _sniffer.ExMap.Achievement);\r
544             UpdateMaterialHistry();\r
545             if (_listForm.Visible)\r
546                 _listForm.UpdateList();\r
547         }\r
548 \r
549         private void UpdateNumOfShips()\r
550         {\r
551             var item = _sniffer.Item;\r
552             labelNumOfShips.Text = $"{item.NowShips:D}/{item.MaxShips:D}";\r
553             labelNumOfShips.ForeColor = item.TooManyShips ? CUDColor.Red : Color.Black;\r
554             if (item.AlarmShips)\r
555             {\r
556                 var message = $"残り{_sniffer.Item.MaxShips - _sniffer.Item.NowShips:D}隻";\r
557                 _notificationManager.Enqueue("艦娘数超過", message);\r
558                 item.AlarmShips = false;\r
559             }\r
560         }\r
561 \r
562         private void UpdateNumOfEquips()\r
563         {\r
564             var item = _sniffer.Item;\r
565             labelNumOfEquips.Text = $"{item.NowEquips:D}/{item.MaxEquips:D}";\r
566             labelNumOfEquips.ForeColor = item.TooManyEquips ? CUDColor.Red : Color.Black;\r
567             if (item.AlarmEquips)\r
568             {\r
569                 var message = $"残り{_sniffer.Item.MaxEquips - _sniffer.Item.NowEquips:D}個";\r
570                 _notificationManager.Enqueue("装備数超過", message);\r
571                 item.AlarmEquips = false;\r
572             }\r
573         }\r
574 \r
575         private void UpdateBucketHistory()\r
576         {\r
577             var count = _sniffer.Material.MaterialHistory[(int)Material.Bucket];\r
578             var day = CutOverflow(count.Now - count.BegOfDay, 999);\r
579             var week = CutOverflow(count.Now - count.BegOfWeek, 999);\r
580             labelBucketHistory.Text = $"{day:+#;-#;±0} 今日\n{week:+#;-#;±0} 今週";\r
581         }\r
582 \r
583         private void UpdateMaterialHistry()\r
584         {\r
585             var labels = new[] {labelFuelHistory, labelBulletHistory, labelSteelHistory, labelBouxiteHistory};\r
586             var text = new[] {"燃料", "弾薬", "鋼材", "ボーキ"};\r
587             for (var i = 0; i < labels.Length; i++)\r
588             {\r
589                 var count = _sniffer.Material.MaterialHistory[i];\r
590                 var port = CutOverflow(count.Now - _sniffer.Material.PrevPort[i], 99999);\r
591                 var day = CutOverflow(count.Now - count.BegOfDay, 99999);\r
592                 var week = CutOverflow(count.Now - count.BegOfWeek, 99999);\r
593                 labels[i].Text = $"{text[i]}\n{port:+#;-#;±0}\n{day:+#;-#;±0}\n{week:+#;-#;±0}";\r
594             }\r
595         }\r
596 \r
597         private int CutOverflow(int value, int limit)\r
598         {\r
599             if (value > limit)\r
600                 return limit;\r
601             if (value < -limit)\r
602                 return -limit;\r
603             return value;\r
604         }\r
605 \r
606         private void UpdateShipInfo()\r
607         {\r
608             SetCurrentFleet();\r
609             UpdatePanelShipInfo();\r
610             NotifyDamagedShip();\r
611             UpdateChargeInfo();\r
612             UpdateRepairList();\r
613             if (_listForm.Visible)\r
614                 _listForm.UpdateList();\r
615         }\r
616 \r
617         private void SetCurrentFleet()\r
618         {\r
619             var inSortie = _sniffer.InSortie;\r
620             if (_inSortie || !inSortie.Any(x => x))\r
621             {\r
622                 _inSortie = inSortie.Any(x => x);\r
623                 return;\r
624             }\r
625             _inSortie = true;\r
626             if (inSortie[0] && inSortie[1])\r
627             {\r
628                 _combinedFleet = true;\r
629                 _currentFleet = 0;\r
630             }\r
631             else\r
632             {\r
633                 _combinedFleet = false;\r
634                 _currentFleet = Array.FindIndex(inSortie, x => x);\r
635             }\r
636         }\r
637 \r
638         private void UpdatePanelShipInfo()\r
639         {\r
640             var statuses = _sniffer.GetShipStatuses(_currentFleet);\r
641             panel7Ships.Visible = statuses.Length == 7;\r
642             _mainLabels.SetShipLabels(statuses);\r
643             if (_sniffer.CombinedFleetType == 0)\r
644                 _combinedFleet = false;\r
645             labelFleet1.Text = _combinedFleet ? "連合" : "第一";\r
646             panelCombinedFleet.Visible = _combinedFleet;\r
647             if (_combinedFleet)\r
648                 _mainLabels.SetCombinedShipLabels(_sniffer.GetShipStatuses(0), _sniffer.GetShipStatuses(1));\r
649             for (var i = 0; i < _labelCheckFleets.Length; i++)\r
650                 _labelCheckFleets[i].Visible = _currentFleet == i;\r
651             UpdateAkashiTimer();\r
652             var battle = _sniffer.Battle;\r
653             UpdateFighterPower(_combinedFleet && (battle.BattleState == BattleState.None || battle.EnemyIsCombined));\r
654             UpdateLoS();\r
655             UpdateCondTimers();\r
656         }\r
657 \r
658         private void NotifyDamagedShip()\r
659         {\r
660             if (!_sniffer.BadlyDamagedShips.Any())\r
661                 return;\r
662             _notificationManager.Enqueue("大破警告", string.Join(" ", _sniffer.BadlyDamagedShips));\r
663             _notificationManager.Flash();\r
664         }\r
665 \r
666         public void UpdateFighterPower(bool combined)\r
667         {\r
668             var fp = combined\r
669                 ? _sniffer.GetFighterPower(0).Zip(_sniffer.GetFighterPower(1), (a, b) => a + b).ToArray()\r
670                 : _sniffer.GetFighterPower(_currentFleet);\r
671             labelFighterPower.Text = fp[0].ToString("D");\r
672             var cr = combined\r
673                 ? _sniffer.GetContactTriggerRate(0) + _sniffer.GetContactTriggerRate(1)\r
674                 : _sniffer.GetContactTriggerRate(_currentFleet);\r
675             var text = "制空: " + (fp[0] == fp[1] ? $"{fp[0]}" : $"{fp[0]}~{fp[1]}") +\r
676                        $" 触接: {cr * 100:f1}";\r
677             toolTipFighterPower.SetToolTip(labelFighterPower, text);\r
678             toolTipFighterPower.SetToolTip(labelFighterPowerCaption, text);\r
679         }\r
680 \r
681         private void UpdateLoS()\r
682         {\r
683             labelLoS.Text = RoundDown(_sniffer.GetFleetLineOfSights(_currentFleet, 1)).ToString("F1");\r
684             var text = $"係数3: {RoundDown(_sniffer.GetFleetLineOfSights(_currentFleet, 3)):F1}\r\n" +\r
685                        $"係数4: {RoundDown(_sniffer.GetFleetLineOfSights(_currentFleet, 4)):F1}";\r
686             toolTipLoS.SetToolTip(labelLoS, text);\r
687             toolTipLoS.SetToolTip(labelLoSCaption, text);\r
688         }\r
689 \r
690         private double RoundDown(double number)\r
691         {\r
692             return Floor(number * 10) / 10.0;\r
693         }\r
694 \r
695         private void UpdateBattleInfo()\r
696         {\r
697             ResetBattleInfo();\r
698             _listForm.UpdateBattleResult();\r
699             if (_sniffer.Battle.BattleState == BattleState.None)\r
700                 return;\r
701             panelBattleInfo.BringToFront();\r
702             var battle = _sniffer.Battle;\r
703             labelFormation.Text = new[] {"同航戦", "反航戦", "T字有利", "T字不利"}[battle.Formation[2] - 1];\r
704             UpdateBattleFighterPower();\r
705             if ((_config.Spoilers & Spoiler.ResultRank) != 0)\r
706                 ShowResultRank();\r
707             if (_sniffer.Battle.BattleState == BattleState.Day)\r
708                 _listForm.UpdateAirBattleResult();\r
709         }\r
710 \r
711         private void ResetBattleInfo()\r
712         {\r
713             labelFormation.Text = "";\r
714             labelEnemyFighterPower.Text = "";\r
715             labelFighterPower.ForeColor = DefaultForeColor;\r
716             labelResultRank.Text = "判定";\r
717             panelBattleInfo.Visible = _sniffer.Battle.BattleState != BattleState.None;\r
718         }\r
719 \r
720         private void UpdateBattleFighterPower()\r
721         {\r
722             var battle = _sniffer.Battle;\r
723             var power = battle.EnemyFighterPower;\r
724             labelEnemyFighterPower.Text = power.AirCombat + power.UnknownMark;\r
725             if (power.AirCombat != power.Interception)\r
726             {\r
727                 var text = "防空: " + power.Interception + power.UnknownMark;\r
728                 toolTipFighterPower.SetToolTip(labelEnemyFighterPower, text);\r
729                 toolTipFighterPower.SetToolTip(labelEnemyFighterPowerCaption, text);\r
730             }\r
731             UpdateFighterPower(_sniffer.CombinedFleetType > 0 && battle.EnemyIsCombined);\r
732             labelFighterPower.ForeColor = new[]\r
733                 {DefaultForeColor, DefaultForeColor, CUDColor.Blue, CUDColor.Green, CUDColor.Orange, CUDColor.Red}[\r
734                 battle.AirControlLevel + 1];\r
735         }\r
736 \r
737         private void ShowResultRank()\r
738         {\r
739             var result = new[] {"完全S", "勝利S", "勝利A", "勝利B", "敗北C", "敗北D", "敗北E"};\r
740             labelResultRank.Text = result[(int)_sniffer.Battle.ResultRank];\r
741         }\r
742 \r
743         private void labelResultRank_Click(object sender, EventArgs e)\r
744         {\r
745             ShowResultRank();\r
746         }\r
747 \r
748         private void UpdateChargeInfo()\r
749         {\r
750             var fuelSq = new[] {labelFuelSq1, labelFuelSq2, labelFuelSq3, labelFuelSq4};\r
751             var bullSq = new[] {labelBullSq1, labelBullSq2, labelBullSq3, labelBullSq4};\r
752 \r
753             for (var i = 0; i < fuelSq.Length; i++)\r
754             {\r
755                 var stat = _sniffer.ChargeStatuses[i];\r
756                 fuelSq[i].ImageIndex = stat.Fuel;\r
757                 bullSq[i].ImageIndex = stat.Bull;\r
758             }\r
759         }\r
760 \r
761         private void UpdateNDocLabels()\r
762         {\r
763             _mainLabels.SetNDockLabels(_sniffer.NDock);\r
764         }\r
765 \r
766 \r
767         private void labelNDock_Click(object sender, EventArgs e)\r
768         {\r
769             _config.ShowEndTime ^= TimerKind.NDock;\r
770             UpdateTimers();\r
771         }\r
772 \r
773         private void UpdateMissionLabels()\r
774         {\r
775             foreach (var entry in\r
776                 new[] {labelMissionName1, labelMissionName2, labelMissionName3}.Zip(_sniffer.Missions,\r
777                     (label, mission) => new {label, mission.Name}))\r
778                 entry.label.Text = entry.Name;\r
779         }\r
780 \r
781         private void labelMission_Click(object sender, EventArgs e)\r
782         {\r
783             _config.ShowEndTime ^= TimerKind.Mission;\r
784             UpdateTimers();\r
785         }\r
786 \r
787         private void UpdateTimers()\r
788         {\r
789             var mission = new[] {labelMission1, labelMission2, labelMission3};\r
790             for (var i = 0; i < mission.Length; i++)\r
791             {\r
792                 var entry = _sniffer.Missions[i];\r
793                 SetTimerColor(mission[i], entry.Timer, _now);\r
794                 mission[i].Text = entry.Timer.ToString(_now, (_config.ShowEndTime & TimerKind.Mission) != 0);\r
795             }\r
796             for (var i = 0; i < _sniffer.NDock.Length; i++)\r
797             {\r
798                 var entry = _sniffer.NDock[i];\r
799                 _mainLabels.SetNDockTimer(i, entry.Timer, _now, (_config.ShowEndTime & TimerKind.NDock) != 0);\r
800             }\r
801             var kdock = new[] {labelConstruct1, labelConstruct2, labelConstruct3, labelConstruct4};\r
802             for (var i = 0; i < kdock.Length; i++)\r
803             {\r
804                 var timer = _sniffer.KDock[i];\r
805                 SetTimerColor(kdock[i], timer, _now);\r
806                 kdock[i].Text = timer.ToString(_now);\r
807             }\r
808             UpdateCondTimers();\r
809             UpdateAkashiTimer();\r
810             _timerEnabled = true;\r
811         }\r
812 \r
813         private void NotifyTimers()\r
814         {\r
815             for (var i = 0; i < _sniffer.Missions.Length; i++)\r
816             {\r
817                 var entry = _sniffer.Missions[i];\r
818                 CheckAlarm("遠征終了", entry.Timer, i + 1, entry.Name);\r
819             }\r
820             for (var i = 0; i < _sniffer.NDock.Length; i++)\r
821             {\r
822                 var entry = _sniffer.NDock[i];\r
823                 CheckAlarm("入渠終了", entry.Timer, i, entry.Name);\r
824             }\r
825             for (var i = 0; i < _sniffer.KDock.Length; i++)\r
826             {\r
827                 var timer = _sniffer.KDock[i];\r
828                 CheckAlarm("建造完了", timer, 0, $"第{i + 1:D}ドック");\r
829             }\r
830             NotifyCondTimers();\r
831             NotifyAkashiTimer();\r
832             _notificationManager.Flash();\r
833         }\r
834 \r
835         private void CheckAlarm(string key, AlarmTimer timer, int fleet, string subject)\r
836         {\r
837             if (timer.CheckAlarm(_prev, _now))\r
838             {\r
839                 SetNotification(key, fleet, subject);\r
840                 return;\r
841             }\r
842             var pre = TimeSpan.FromSeconds(_config.Notifications[key].PreliminaryPeriod);\r
843             if (pre == TimeSpan.Zero)\r
844                 return;\r
845             if (timer.CheckAlarm(_prev + pre, _now + pre))\r
846                 SetPreNotification(key, fleet, subject);\r
847         }\r
848 \r
849         private void SetTimerColor(Label label, AlarmTimer timer, DateTime now)\r
850         {\r
851             label.ForeColor = timer.IsFinished(now) ? CUDColor.Red : Color.Black;\r
852         }\r
853 \r
854         private void UpdateCondTimers()\r
855         {\r
856             DateTime timer;\r
857             if (_combinedFleet)\r
858             {\r
859                 var timer1 = _sniffer.GetConditionTimer(0);\r
860                 var timer2 = _sniffer.GetConditionTimer(1);\r
861                 timer = timer2 > timer1 ? timer2 : timer1;\r
862             }\r
863             else\r
864             {\r
865                 timer = _sniffer.GetConditionTimer(_currentFleet);\r
866             }\r
867             if (timer == DateTime.MinValue)\r
868             {\r
869                 labelCondTimerTitle.Text = "";\r
870                 labelCondTimer.Text = "";\r
871                 return;\r
872             }\r
873             var span = TimeSpan.FromSeconds(Ceiling((timer - _now).TotalSeconds));\r
874             if (span >= TimeSpan.FromMinutes(9))\r
875             {\r
876                 labelCondTimerTitle.Text = "cond40まで";\r
877                 labelCondTimer.Text = (span - TimeSpan.FromMinutes(9)).ToString(@"mm\:ss");\r
878                 labelCondTimer.ForeColor = DefaultForeColor;\r
879             }\r
880             else\r
881             {\r
882                 labelCondTimerTitle.Text = "cond49まで";\r
883                 labelCondTimer.Text = (span >= TimeSpan.Zero ? span : TimeSpan.Zero).ToString(@"mm\:ss");\r
884                 labelCondTimer.ForeColor = span <= TimeSpan.Zero ? CUDColor.Red : DefaultForeColor;\r
885             }\r
886         }\r
887 \r
888         private void NotifyCondTimers()\r
889         {\r
890             var notice = _sniffer.GetConditionNotice(_prev, _now);\r
891             var pre = TimeSpan.FromSeconds(_config.Notifications["疲労回復"].PreliminaryPeriod);\r
892             var preNotice = pre == TimeSpan.Zero\r
893                 ? new int[ShipInfo.FleetCount]\r
894                 : _sniffer.GetConditionNotice(_prev + pre, _now + pre);\r
895             for (var i = 0; i < ShipInfo.FleetCount; i++)\r
896             {\r
897                 if (_config.NotifyConditions.Contains(notice[i]))\r
898                 {\r
899                     SetNotification("疲労回復" + notice[i], i, "cond" + notice[i]);\r
900                 }\r
901                 else if (_config.NotifyConditions.Contains(preNotice[i]))\r
902                 {\r
903                     SetPreNotification("疲労回復" + preNotice[i], i, "cond" + notice[i]);\r
904                 }\r
905             }\r
906         }\r
907 \r
908         private void UpdateAkashiTimer()\r
909         {\r
910             if (_config.UsePresetAkashi)\r
911                 UpdatePresetAkashiTimer();\r
912             var statuses = _sniffer.GetShipStatuses(_currentFleet);\r
913             _mainLabels.SetAkashiTimer(statuses,\r
914                 _sniffer.AkashiTimer.GetTimers(_currentFleet));\r
915         }\r
916 \r
917         private void UpdatePresetAkashiTimer()\r
918         {\r
919             var akashi = _sniffer.AkashiTimer;\r
920             var span = akashi.PresetDeckTimer;\r
921             var color = span == TimeSpan.Zero && akashi.CheckPresetRepairing() ? CUDColor.Red : DefaultForeColor;\r
922             var text = span == TimeSpan.MinValue ? "" : span.ToString(@"mm\:ss");\r
923             labelAkashiRepairTimer.ForeColor = color;\r
924             labelAkashiRepairTimer.Text = text;\r
925             if (akashi.CheckPresetRepairing() && !akashi.CheckRepairing(_currentFleet))\r
926             {\r
927                 labelPresetAkashiTimer.ForeColor = color;\r
928                 labelPresetAkashiTimer.Text = text;\r
929             }\r
930             else\r
931             {\r
932                 labelPresetAkashiTimer.ForeColor = DefaultForeColor;\r
933                 labelPresetAkashiTimer.Text = "";\r
934             }\r
935         }\r
936 \r
937         private void NotifyAkashiTimer()\r
938         {\r
939             var akashi = _sniffer.AkashiTimer;\r
940             var msgs = akashi.GetNotice(_prev, _now);\r
941             if (msgs.Length == 0)\r
942             {\r
943                 _notificationManager.StopRepeat("泊地修理");\r
944                 return;\r
945             }\r
946             if (!akashi.CheckRepairing() && !(akashi.CheckPresetRepairing() && _config.UsePresetAkashi))\r
947             {\r
948                 _notificationManager.StopRepeat("泊地修理");\r
949                 return;\r
950             }\r
951             var skipPreliminary = false;\r
952             if (msgs[0].Proceeded == "20分経過しました。")\r
953             {\r
954                 SetNotification("泊地修理20分経過", msgs[0].Proceeded);\r
955                 msgs[0].Proceeded = "";\r
956                 skipPreliminary = true;\r
957                 // 修理完了がいるかもしれないので続ける\r
958             }\r
959             for (var i = 0; i < ShipInfo.FleetCount; i++)\r
960             {\r
961                 if (msgs[i].Proceeded != "")\r
962                     SetNotification("泊地修理進行", i, msgs[i].Proceeded);\r
963                 if (msgs[i].Completed != "")\r
964                     SetNotification("泊地修理完了", i, msgs[i].Completed);\r
965             }\r
966             var pre = TimeSpan.FromSeconds(_config.Notifications["泊地修理20分経過"].PreliminaryPeriod);\r
967             if (skipPreliminary || pre == TimeSpan.Zero)\r
968                 return;\r
969             if ((msgs = akashi.GetNotice(_prev + pre, _now + pre))[0].Proceeded == "20分経過しました。")\r
970                 SetPreNotification("泊地修理20分経過", 0, msgs[0].Proceeded);\r
971         }\r
972 \r
973         private void SetNotification(string key, string subject)\r
974         {\r
975             SetNotification(key, 0, subject);\r
976         }\r
977 \r
978         private void SetNotification(string key, int fleet, string subject)\r
979         {\r
980             var spec = _config.Notifications[_notificationManager.KeyToName(key)];\r
981             _notificationManager.Enqueue(key, fleet, subject,\r
982                 (spec.Flags & _config.NotificationFlags & NotificationType.Repeat) == 0 ? 0 : spec.RepeatInterval);\r
983         }\r
984 \r
985         private void SetPreNotification(string key, int fleet, string subject)\r
986         {\r
987             var spec = _config.Notifications[_notificationManager.KeyToName(key)];\r
988             if ((spec.Flags & NotificationType.Preliminary) != 0)\r
989                 _notificationManager.Enqueue(key, fleet, subject, 0, true);\r
990         }\r
991 \r
992         private void UpdateRepairList()\r
993         {\r
994             panelRepairList.SetRepairList(_sniffer.RepairList);\r
995         }\r
996 \r
997         private void UpdateQuestList()\r
998         {\r
999             var category = new[]\r
1000             {\r
1001                 labelQuestColor1, labelQuestColor2, labelQuestColor3, labelQuestColor4, labelQuestColor5,\r
1002                 labelQuestColor6\r
1003             };\r
1004             var name = new[] {labelQuest1, labelQuest2, labelQuest3, labelQuest4, labelQuest5, labelQuest6};\r
1005             var count = new[]\r
1006             {\r
1007                 labelQuestCount1, labelQuestCount2, labelQuestCount3, labelQuestCount4, labelQuestCount5,\r
1008                 labelQuestCount6\r
1009             };\r
1010             var progress = new[]\r
1011                 {labelProgress1, labelProgress2, labelProgress3, labelProgress4, labelProgress5, labelProgress6};\r
1012             var quests = _sniffer.Quests;\r
1013             for (var i = 0; i < name.Length; i++)\r
1014             {\r
1015                 if (i < quests.Length)\r
1016                 {\r
1017                     category[i].BackColor = quests[i].Color;\r
1018                     name[i].Text = quests[i].Name;\r
1019                     progress[i].Text = $"{quests[i].Progress:D}%";\r
1020                     _toolTipQuest.SetToolTip(name[i], quests[i].ToToolTip());\r
1021                     var c = quests[i].Count;\r
1022                     if (c.Id == 0)\r
1023                     {\r
1024                         count[i].Text = "";\r
1025                         count[i].ForeColor = Color.Black;\r
1026                         _toolTipCount.SetToolTip(count[i], "");\r
1027                         continue;\r
1028                     }\r
1029                     count[i].Text = " " + c;\r
1030                     count[i].ForeColor = c.Cleared ? CUDColor.Green : Color.Black;\r
1031                     _toolTipCount.SetToolTip(count[i], c.ToToolTip());\r
1032                 }\r
1033                 else\r
1034                 {\r
1035                     category[i].BackColor = DefaultBackColor;\r
1036                     name[i].Text = count[i].Text = progress[i].Text = "";\r
1037                     _toolTipQuest.SetToolTip(name[i], "");\r
1038                     _toolTipCount.SetToolTip(count[i], "");\r
1039                 }\r
1040             }\r
1041         }\r
1042 \r
1043         private void Alarm(string balloonTitle, string balloonMessage, string name)\r
1044         {\r
1045             var flags = _config.Notifications[name].Flags;\r
1046             var effective = _config.NotificationFlags & _config.Notifications[name].Flags;\r
1047             if ((effective & NotificationType.FlashWindow) != 0)\r
1048                 Win32API.FlashWindow(Handle);\r
1049             if ((effective & NotificationType.ShowBaloonTip) != 0)\r
1050                 notifyIconMain.ShowBalloonTip(20000, balloonTitle, balloonMessage, ToolTipIcon.Info);\r
1051             if ((effective & NotificationType.PlaySound) != 0)\r
1052                 PlaySound(_config.Sounds[name], _config.Sounds.Volume);\r
1053             if (_config.Pushbullet.On && (flags & NotificationType.Push) != 0)\r
1054             {\r
1055                 Task.Run(() =>\r
1056                 {\r
1057                     PushNotification.PushToPushbullet(_config.Pushbullet.Token, balloonTitle, balloonMessage);\r
1058                 });\r
1059             }\r
1060             if (_config.Pushover.On && (flags & NotificationType.Push) != 0)\r
1061             {\r
1062                 Task.Run(() =>\r
1063                 {\r
1064                     PushNotification.PushToPushover(_config.Pushover.ApiKey, _config.Pushover.UserKey,\r
1065                         balloonTitle, balloonMessage);\r
1066                 });\r
1067             }\r
1068         }\r
1069 \r
1070         [DllImport("winmm.dll")]\r
1071         private static extern int mciSendString(String command,\r
1072             StringBuilder buffer, int bufferSize, IntPtr hwndCallback);\r
1073 \r
1074 // ReSharper disable InconsistentNaming\r
1075         private const int MM_MCINOTIFY = 0x3B9;\r
1076 \r
1077         private const int MCI_NOTIFY_SUCCESSFUL = 1;\r
1078 // ReSharper restore InconsistentNaming\r
1079 \r
1080         public void PlaySound(string file, int volume)\r
1081         {\r
1082             if (!File.Exists(file))\r
1083                 return;\r
1084             mciSendString("close sound", null, 0, IntPtr.Zero);\r
1085             if (mciSendString("open \"" + file + "\" type mpegvideo alias sound", null, 0, IntPtr.Zero) != 0)\r
1086                 return;\r
1087             mciSendString("setaudio sound volume to " + volume * 10, null, 0, IntPtr.Zero);\r
1088             mciSendString("play sound notify", null, 0, Handle);\r
1089         }\r
1090 \r
1091         protected override void WndProc(ref Message m)\r
1092         {\r
1093             if (m.Msg == MM_MCINOTIFY && (int)m.WParam == MCI_NOTIFY_SUCCESSFUL)\r
1094                 mciSendString("close sound", null, 0, IntPtr.Zero);\r
1095             base.WndProc(ref m);\r
1096         }\r
1097 \r
1098         private void SetupFleetClick()\r
1099         {\r
1100             var labels = new[]\r
1101             {\r
1102                 new[] {labelFleet1, labelFleet2, labelFleet3, labelFleet4},\r
1103                 new[] {labelFuelSq1, labelFuelSq2, labelFuelSq3, labelFuelSq4},\r
1104                 new[] {labelBullSq1, labelBullSq2, labelBullSq3, labelBullSq4}\r
1105             };\r
1106             foreach (var a in labels)\r
1107             {\r
1108                 for (var fleet = 0; fleet < labels[0].Length; fleet++)\r
1109                 {\r
1110                     a[fleet].Tag = fleet;\r
1111                     a[fleet].Click += labelFleet_Click;\r
1112                 }\r
1113             }\r
1114         }\r
1115 \r
1116         private void labelFleet_Click(object sender, EventArgs e)\r
1117         {\r
1118             if (!_started)\r
1119                 return;\r
1120             var fleet = (int)((Label)sender).Tag;\r
1121             if (_currentFleet == fleet)\r
1122             {\r
1123                 if (fleet > 0)\r
1124                     return;\r
1125                 _combinedFleet = _sniffer.CombinedFleetType > 0 && !_combinedFleet;\r
1126                 UpdatePanelShipInfo();\r
1127                 return;\r
1128             }\r
1129             _combinedFleet = false;\r
1130             _currentFleet = fleet;\r
1131             UpdatePanelShipInfo();\r
1132         }\r
1133 \r
1134         private void labelFleet1_MouseHover(object sender, EventArgs e)\r
1135         {\r
1136             labelFleet1.Text = _currentFleet == 0 && _sniffer.CombinedFleetType > 0 && !_combinedFleet ? "連合" : "第一";\r
1137         }\r
1138 \r
1139         private void labelFleet1_MouseLeave(object sender, EventArgs e)\r
1140         {\r
1141             labelFleet1.Text = _combinedFleet ? "連合" : "第一";\r
1142         }\r
1143 \r
1144         private readonly Color _activeButtonColor = Color.FromArgb(152, 179, 208);\r
1145 \r
1146         private void labelBucketHistoryButton_Click(object sender, EventArgs e)\r
1147         {\r
1148             if (labelBucketHistory.Visible)\r
1149             {\r
1150                 labelBucketHistory.Visible = false;\r
1151                 labelBucketHistoryButton.BackColor = DefaultBackColor;\r
1152             }\r
1153             else\r
1154             {\r
1155                 labelBucketHistory.Visible = true;\r
1156                 labelBucketHistory.BringToFront();\r
1157                 labelBucketHistoryButton.BackColor = _activeButtonColor;\r
1158             }\r
1159         }\r
1160 \r
1161         private void labelBucketHistory_Click(object sender, EventArgs e)\r
1162         {\r
1163             labelBucketHistory.Visible = false;\r
1164             labelBucketHistoryButton.BackColor = DefaultBackColor;\r
1165         }\r
1166 \r
1167         private void labelMaterialHistoryButton_Click(object sender, EventArgs e)\r
1168         {\r
1169             if (panelMaterialHistory.Visible)\r
1170             {\r
1171                 panelMaterialHistory.Visible = false;\r
1172                 labelMaterialHistoryButton.BackColor = DefaultBackColor;\r
1173             }\r
1174             else\r
1175             {\r
1176                 panelMaterialHistory.Visible = true;\r
1177                 panelMaterialHistory.BringToFront();\r
1178                 labelMaterialHistoryButton.BackColor = _activeButtonColor;\r
1179             }\r
1180         }\r
1181 \r
1182         private void panelMaterialHistory_Click(object sender, EventArgs e)\r
1183         {\r
1184             panelMaterialHistory.Visible = false;\r
1185             labelMaterialHistoryButton.BackColor = DefaultBackColor;\r
1186         }\r
1187 \r
1188         public void ResetAchievemnt()\r
1189         {\r
1190             _sniffer.Achievement.Reset();\r
1191             UpdateItemInfo();\r
1192         }\r
1193 \r
1194         private void labelRepairListButton_Click(object sender, EventArgs e)\r
1195         {\r
1196             if (panelRepairList.Visible)\r
1197             {\r
1198                 panelRepairList.Visible = false;\r
1199                 labelRepairListButton.BackColor = DefaultBackColor;\r
1200             }\r
1201             else\r
1202             {\r
1203                 panelRepairList.Visible = true;\r
1204                 panelRepairList.BringToFront();\r
1205                 labelRepairListButton.BackColor = _activeButtonColor;\r
1206             }\r
1207         }\r
1208 \r
1209         private void panelRepairList_Click(object sender, EventArgs e)\r
1210         {\r
1211             panelRepairList.Visible = false;\r
1212             labelRepairListButton.BackColor = DefaultBackColor;\r
1213         }\r
1214 \r
1215         private void ShipListToolStripMenuItem_Click(object sender, EventArgs e)\r
1216         {\r
1217             _listForm.UpdateList();\r
1218             _listForm.Show();\r
1219             if (_listForm.WindowState == FormWindowState.Minimized)\r
1220                 _listForm.WindowState = FormWindowState.Normal;\r
1221             _listForm.Activate();\r
1222         }\r
1223 \r
1224         private void LogToolStripMenuItem_Click(object sender, EventArgs e)\r
1225         {\r
1226             Process.Start("http://localhost:" + _config.Proxy.Listen + "/");\r
1227         }\r
1228 \r
1229         private void labelClearQuest_Click(object sender, EventArgs e)\r
1230         {\r
1231             _sniffer.ClearQuests();\r
1232             UpdateQuestList();\r
1233         }\r
1234 \r
1235         private void labelClearQuest_MouseDown(object sender, MouseEventArgs e)\r
1236         {\r
1237             labelClearQuest.BackColor = _activeButtonColor;\r
1238         }\r
1239 \r
1240         private void labelClearQuest_MouseUp(object sender, MouseEventArgs e)\r
1241         {\r
1242             labelClearQuest.BackColor = DefaultBackColor;\r
1243         }\r
1244 \r
1245         private void labelQuest_DoubleClick(object sender, EventArgs e)\r
1246         {\r
1247             var label = (Label)sender;\r
1248             Clipboard.SetText(label.Text);\r
1249             _tooltipCopy.Active = true;\r
1250             _tooltipCopy.Show("コピーしました。", label);\r
1251             Task.Run(async () =>\r
1252             {\r
1253                 await Task.Delay(1000);\r
1254                 _tooltipCopy.Active = false;\r
1255             });\r
1256         }\r
1257 \r
1258         private void CaptureToolStripMenuItem_Click(object sender, EventArgs e)\r
1259         {\r
1260             try\r
1261             {\r
1262                 var proc = new ProcessStartInfo("BurageSnap.exe") {WorkingDirectory = "Capture"};\r
1263                 Process.Start(proc);\r
1264             }\r
1265             catch (FileNotFoundException)\r
1266             {\r
1267             }\r
1268         }\r
1269     }\r
1270 }