1 // Copyright (C) 2013, 2014, 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>
\r
3 // This program is part of KancolleSniffer.
\r
5 // KancolleSniffer is free software: you can redistribute it and/or modify
\r
6 // it under the terms of the GNU General Public License as published by
\r
7 // the Free Software Foundation, either version 3 of the License, or
\r
8 // (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, see <http://www.gnu.org/licenses/>.
\r
19 using System.Collections.Generic;
\r
20 using System.Diagnostics;
\r
21 using System.Drawing;
\r
25 using System.Net.Sockets;
\r
26 using System.Runtime.InteropServices;
\r
28 using System.Threading;
\r
29 using System.Threading.Tasks;
\r
30 using System.Windows.Forms;
\r
32 using Codeplex.Data;
\r
33 using Microsoft.CSharp.RuntimeBinder;
\r
34 using Microsoft.Win32;
\r
36 using static System.Math;
\r
37 using Timer = System.Windows.Forms.Timer;
\r
39 namespace KancolleSniffer
\r
41 public partial class MainForm : Form
\r
43 private readonly Sniffer _sniffer = new Sniffer();
\r
44 private readonly Config _config = new Config();
\r
45 private readonly ConfigDialog _configDialog;
\r
46 private int _currentFleet;
\r
47 private readonly Label[] _labelCheckFleets;
\r
48 private readonly ShipLabels _shipLabels;
\r
49 private readonly ShipListForm _shipListForm;
\r
50 private readonly NoticeQueue _noticeQueue;
\r
51 private bool _started;
\r
52 private string _debugLogFile;
\r
53 private IEnumerator<string> _playLog;
\r
54 private LogServer _logServer;
\r
55 private int _prevProxyPort;
\r
56 private readonly SystemProxy _systemProxy = new SystemProxy();
\r
57 private readonly ErrorDialog _errorDialog = new ErrorDialog();
\r
61 InitializeComponent();
\r
62 HttpProxy.AfterSessionComplete += HttpProxy_AfterSessionComplete;
\r
63 _configDialog = new ConfigDialog(_config, this);
\r
64 _labelCheckFleets = new[] {labelCheckFleet1, labelCheckFleet2, labelCheckFleet3, labelCheckFleet4};
\r
66 // この時点でAutoScaleDimensions == CurrentAutoScaleDimensionsなので、
\r
67 // MainForm.Designer.csのAutoScaleDimensionsの6f,12fを使う。
\r
68 ShipLabel.ScaleFactor = new SizeF(CurrentAutoScaleDimensions.Width / 6f,
\r
69 CurrentAutoScaleDimensions.Height / 12f);
\r
72 _shipLabels = new ShipLabels();
\r
73 _shipLabels.CreateAkashiTimers(panelShipInfo);
\r
74 _shipLabels.CreateLabels(panelShipInfo, ShowShipOnShipList);
\r
75 _shipLabels.CreateDamagedShipList(panelDamagedShipList, panelDamagedShipList_Click);
\r
76 _shipLabels.CreateNDockLabels(panelDock);
\r
77 _shipListForm = new ShipListForm(_sniffer, _config) {Owner = this};
\r
78 _noticeQueue = new NoticeQueue(Ring);
\r
81 private void HttpProxy_AfterSessionComplete(Session session)
\r
83 Invoke(new Action<Session>(ProcessRequest), session);
\r
86 private void ProcessRequest(Session session)
\r
88 var url = session.Request.PathAndQuery;
\r
89 var request = session.Request.BodyAsString;
\r
90 var response = session.Response.BodyAsString;
\r
91 if (!url.Contains("kcsapi/"))
\r
93 if (response == null || !response.StartsWith("svdata="))
\r
95 WriteDebugLog(url, request, response);
\r
96 ShowServerError(url, request, response);
\r
99 response = response.Remove(0, "svdata=".Length);
\r
102 var json = DynamicJson.Parse(response);
\r
103 WriteDebugLog(url, request, json.ToString());
\r
104 var update = _sniffer.Sniff(url, request, json);
\r
105 if (update == Sniffer.Update.Error)
\r
107 ShowServerError(url, request, json);
\r
110 UpdateInfo(update);
\r
112 catch (XmlException)
\r
114 WriteDebugLog(url, request, response);
\r
115 ShowServerError(url, request, response);
\r
117 catch (RuntimeBinderException e)
\r
119 if (_errorDialog.ShowDialog(this,
\r
120 "このバージョンは現在の艦これに対応していません。\n新しいバージョンを利用してください。", e.ToString()) == DialogResult.Abort)
\r
121 Application.Exit();
\r
123 catch (LogIOException e)
\r
125 if (_errorDialog.ShowDialog(this, e.Message, e.InnerException.ToString()) == DialogResult.Abort)
\r
126 Application.Exit();
\r
130 private void WriteDebugLog(string url, string request, string response)
\r
132 if (_debugLogFile != null)
\r
134 File.AppendAllText(_debugLogFile, SessionString(url, request, response));
\r
138 private void ShowServerError(string url, string request, string response)
\r
140 if (_errorDialog.Visible)
\r
142 if (_errorDialog.ShowDialog(this, "サーバーからの応答が異常です。",
\r
143 SessionString(url, request, response)) == DialogResult.Abort)
\r
144 Application.Exit();
\r
147 private string SessionString(string url, string request, string response)
\r
148 => $"url: {url}\nrequest: {request}\nresponse: {(response ?? "(null)")}\n";
\r
150 private void UpdateInfo(Sniffer.Update update)
\r
152 if (update == Sniffer.Update.Start)
\r
154 labelLogin.Visible = false;
\r
160 if ((update & Sniffer.Update.Item) != 0)
\r
162 if ((update & Sniffer.Update.Timer) != 0)
\r
164 if ((update & Sniffer.Update.NDock) != 0)
\r
165 UpdateNDocLabels();
\r
166 if ((update & Sniffer.Update.Mission) != 0)
\r
167 UpdateMissionLabels();
\r
168 if ((update & Sniffer.Update.QuestList) != 0)
\r
170 if ((update & Sniffer.Update.Ship) != 0)
\r
172 if ((update & Sniffer.Update.Battle) != 0)
\r
173 UpdateBattleInfo();
\r
176 private void MainForm_Load(object sender, EventArgs e)
\r
180 if (_config.HideOnMinimized && WindowState == FormWindowState.Minimized)
\r
181 ShowInTaskbar = false;
\r
183 ApplyDebugLogSetting();
\r
185 _sniffer.LoadState();
\r
186 ApplyProxySetting();
\r
187 SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
\r
190 private void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
\r
192 if (e.Mode != PowerModes.Resume || !_config.Proxy.Auto)
\r
196 for (var i = 0; i < 5; Thread.Sleep(10000), i++)
\r
198 WebResponse res = null;
\r
199 SystemProxy.Refresh();
\r
200 var system = WebRequest.GetSystemWebProxy();
\r
201 if (!system.GetProxy(new Uri("http://125.6.184.16/")).IsLoopback)
\r
203 File.AppendAllText("wakeup.log",
\r
204 $"[{DateTime.Now.ToString("g")}] proxy settings doesn't work.\r\n");
\r
209 var req = WebRequest.Create("http://kancollesniffer.osdn.jp/version");
\r
210 res = req.GetResponse();
\r
215 File.AppendAllText("wakeup.log",
\r
216 $"[{DateTime.Now.ToString("g")}] failed to connect internet.\r\n");
\r
226 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
\r
229 _config.Location = (WindowState == FormWindowState.Normal ? Bounds : RestoreBounds).Location;
\r
231 Task.Run(() => ShutdownProxy());
\r
232 _logServer?.Stop();
\r
233 if (_config.Proxy.Auto)
\r
234 _systemProxy.RestoreSettings();
\r
235 SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
\r
238 private void ShutdownProxy()
\r
240 HttpProxy.Shutdown();
\r
243 private void MainForm_Resize(object sender, EventArgs e)
\r
245 ShowInTaskbar = !(_config.HideOnMinimized && WindowState == FormWindowState.Minimized);
\r
248 private void notifyIconMain_MouseDoubleClick(object sender, MouseEventArgs e)
\r
250 NotifyIconOpenToolStripMenuItem_Click(sender, e);
\r
253 private void NotifyIconOpenToolStripMenuItem_Click(object sender, EventArgs e)
\r
255 ShowInTaskbar = true;
\r
256 WindowState = FormWindowState.Normal;
\r
257 TopMost = _config.TopMost; // 最前面に表示されなくなることがあるのを回避する
\r
261 private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
\r
266 private void ConfigToolStripMenuItem_Click(object sender, EventArgs e)
\r
268 if (_configDialog.ShowDialog(this) == DialogResult.OK)
\r
272 private void RestoreLocation()
\r
274 if (_config.Location.X == int.MinValue)
\r
276 var newBounds = Bounds;
\r
277 newBounds.Location = _config.Location;
\r
278 if (IsVisibleOnAnyScreen(newBounds))
\r
279 Location = _config.Location;
\r
282 private void ApplyConfig()
\r
284 _shipListForm.TopMost = TopMost = _config.TopMost;
\r
285 _sniffer.Item.MarginShips = _config.MarginShips;
\r
286 _sniffer.Item.MarginEquips = _config.MarginEquips;
\r
287 _sniffer.Achievement.ResetHours = _config.ResetHours;
\r
290 public void ApplyDebugLogSetting()
\r
292 _debugLogFile = _config.DebugLogging ? _config.DebugLogFile : null;
\r
295 public bool ApplyProxySetting()
\r
297 if (!_config.Proxy.Auto)
\r
298 _systemProxy.RestoreSettings();
\r
299 if (_config.Proxy.UseUpstream)
\r
301 HttpProxy.UpstreamProxyHost = "127.0.0.1";
\r
302 HttpProxy.UpstreamProxyPort = _config.Proxy.UpstreamPort;
\r
304 HttpProxy.IsEnableUpstreamProxy = _config.Proxy.UseUpstream;
\r
306 if (!HttpProxy.IsInListening || _config.Proxy.Listen != _prevProxyPort)
\r
309 result = StartProxy();
\r
311 if (_config.Proxy.Auto && result)
\r
313 _systemProxy.SetAutoProxyUrl(HttpProxy.LocalPort == 8080
\r
314 ? ProxyConfig.AutoConfigUrl
\r
315 : ProxyConfig.AutoConfigUrlWithPort + HttpProxy.LocalPort);
\r
317 _prevProxyPort = _config.Proxy.Listen;
\r
321 private bool StartProxy()
\r
325 HttpProxy.Startup(_config.Proxy.Listen, false, false);
\r
327 catch (SocketException e)
\r
329 if (e.SocketErrorCode != SocketError.AddressAlreadyInUse)
\r
331 if (WarnConflictPortNumber("プロキシサーバー", _config.Proxy.Listen, _config.Proxy.Auto) == DialogResult.No ||
\r
332 !_config.Proxy.Auto)
\r
334 _systemProxy.RestoreSettings();
\r
337 HttpProxy.Startup(0, false, false);
\r
338 _config.Proxy.Listen = HttpProxy.LocalPort;
\r
343 private DialogResult WarnConflictPortNumber(string name, int port, bool auto)
\r
345 var msg = $"{name}のポート番号{port}は他のアプリケーションが使用中です。";
\r
346 var cap = "ポート番号の衝突";
\r
348 ? MessageBox.Show(this, msg + "自動的に別の番号を割り当てますか?", cap,
\r
349 MessageBoxButtons.YesNo, MessageBoxIcon.Question)
\r
350 : MessageBox.Show(this, msg + "設定ダイアログでポート番号を変更してください。", cap,
\r
351 MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
\r
354 public bool ApplyLogSetting()
\r
357 if (_config.Log.ServerOn)
\r
359 result = StartLogServer();
\r
363 _logServer?.Stop();
\r
366 _sniffer.EnableLog(_config.Log.On ? LogType.All : LogType.None);
\r
367 _sniffer.MaterialLogInterval = _config.Log.MaterialLogInterval;
\r
368 _sniffer.LogOutputDir = _config.Log.OutputDir;
\r
372 private bool StartLogServer()
\r
374 var port = _config.Log.Listen;
\r
375 if (_logServer?.Port == port)
\r
377 _logServer?.Stop();
\r
381 _logServer = new LogServer(port);
\r
382 _logServer.Start();
\r
384 catch (SocketException e) when (e.SocketErrorCode == SocketError.AddressAlreadyInUse)
\r
386 if (WarnConflictPortNumber("閲覧サーバー", port, true) == DialogResult.No)
\r
388 _logServer = new LogServer(0);
\r
389 _logServer.Start();
\r
390 _config.Log.Listen = _logServer.Port;
\r
392 _logServer.OutputDir = _config.Log.OutputDir;
\r
396 public static bool IsVisibleOnAnyScreen(Rectangle rect)
\r
398 return Screen.AllScreens.Any(screen => screen.WorkingArea.IntersectsWith(rect));
\r
401 private void timerMain_Tick(object sender, EventArgs e)
\r
405 if (_playLog == null || _configDialog.Visible)
\r
407 labelPlayLog.Visible = false;
\r
413 public void SetPlayLog(string file)
\r
415 _playLog = File.ReadLines(file).GetEnumerator();
\r
418 private void PlayLog()
\r
420 var lines = new List<string>();
\r
421 foreach (var s in new[] {"url: ", "request: ", "response: "})
\r
423 if (!_playLog.MoveNext() || !_playLog.Current.StartsWith(s))
\r
425 labelPlayLog.Visible = false;
\r
428 lines.Add(_playLog.Current.Substring(s.Length));
\r
430 labelPlayLog.Visible = !labelPlayLog.Visible;
\r
431 var json = DynamicJson.Parse(lines[2]);
\r
432 UpdateInfo(_sniffer.Sniff(lines[0], lines[1], json));
\r
435 private void ShowShipOnShipList(object sender, EventArgs ev)
\r
437 if (!_shipListForm.Visible)
\r
439 var idx = (int)((Control)sender).Tag;
\r
440 var statuses = _sniffer.GetShipStatuses(_currentFleet);
\r
441 if (statuses.Length <= idx)
\r
443 _shipListForm.ShowShip(statuses[idx].Id);
\r
446 private void UpdateItemInfo()
\r
448 UpdateNumOfShips();
\r
449 UpdateNumOfEquips();
\r
450 labelNumOfBuckets.Text = _sniffer.Material.MaterialHistory[(int)Material.Bucket].Now.ToString("D");
\r
451 UpdateBucketHistory();
\r
452 var ac = _sniffer.Achievement.Value;
\r
455 labelAchievement.Text = ac >= 1000 ? ((int)ac).ToString("D") : ac.ToString("F1");
\r
456 toolTipAchievement.SetToolTip(labelAchievement,
\r
457 "今月 " + _sniffer.Achievement.ValueOfMonth.ToString("F1") + "\n" +
\r
458 "EO " + _sniffer.ExMap.Achievement);
\r
459 UpdateMaterialHistry();
\r
460 if (_shipListForm.Visible)
\r
461 _shipListForm.UpdateList();
\r
464 private void UpdateNumOfShips()
\r
466 var item = _sniffer.Item;
\r
467 labelNumOfShips.Text = $"{item.NowShips:D}/{item.MaxShips:D}";
\r
468 labelNumOfShips.ForeColor = item.TooManyShips ? Color.Red : Color.Black;
\r
469 if (item.RingShips)
\r
471 var message = $"残り{_sniffer.Item.MaxShips - _sniffer.Item.NowShips:D}隻";
\r
472 _noticeQueue.Enqueue("艦娘が多すぎます", message, _config.MaxShipsSoundFile);
\r
473 item.RingShips = false;
\r
477 private void UpdateNumOfEquips()
\r
479 var item = _sniffer.Item;
\r
480 labelNumOfEquips.Text = $"{item.NowEquips:D}/{item.MaxEquips:D}";
\r
481 labelNumOfEquips.ForeColor = item.TooManyEquips ? Color.Red : Color.Black;
\r
482 if (item.RingEquips)
\r
484 var message = $"残り{_sniffer.Item.MaxEquips - _sniffer.Item.NowEquips:D}個";
\r
485 _noticeQueue.Enqueue("装備が多すぎます", message, _config.MaxEquipsSoundFile);
\r
486 item.RingEquips = false;
\r
490 private void UpdateBucketHistory()
\r
492 var count = _sniffer.Material.MaterialHistory[(int)Material.Bucket];
\r
493 var day = count.Now - count.BegOfDay;
\r
494 var week = count.Now - count.BegOfWeek;
\r
499 labelBucketHistory.Text = $"{day:+#;-#;±0} 今日\n{week:+#;-#;±0} 今週";
\r
502 private void UpdateMaterialHistry()
\r
504 var labels = new[] {labelFuelHistory, labelBulletHistory, labelSteelHistory, labelBouxiteHistory};
\r
505 var text = new[] {"燃料", "弾薬", "鋼材", "ボーキ"};
\r
506 for (var i = 0; i < labels.Length; i++)
\r
508 var count = _sniffer.Material.MaterialHistory[i];
\r
509 var port = count.Now - _sniffer.Material.PrevPort[i];
\r
510 if (port >= 100000)
\r
512 var day = count.Now - count.BegOfDay;
\r
515 var week = count.Now - count.BegOfWeek;
\r
516 if (week >= 100000)
\r
518 labels[i].Text = $"{text[i]}\n{port:+#;-#;±0}\n{day:+#;-#;±0}\n{week:+#;-#;±0}";
\r
522 private void UpdateShipInfo()
\r
524 UpdatePanelShipInfo();
\r
525 NotifyDamagedShip();
\r
526 UpdateChargeInfo();
\r
527 UpdateDamagedShipList();
\r
528 if (_shipListForm.Visible)
\r
529 _shipListForm.UpdateList();
\r
532 private void UpdatePanelShipInfo()
\r
534 var statuses = _sniffer.GetShipStatuses(_currentFleet);
\r
535 _shipLabels.SetShipInfo(statuses);
\r
536 UpdateAkashiTimer();
\r
537 UpdateFighterPower();
\r
539 UpdateCondTimers();
\r
542 private void NotifyDamagedShip()
\r
544 if (_sniffer.Battle.HasDamagedShip)
\r
545 _noticeQueue.Enqueue("大破した艦娘がいます", string.Join(" ", _sniffer.Battle.DamagedShipNames),
\r
546 _config.DamagedShipSoundFile);
\r
549 private void NotifyAkashiTimer()
\r
551 var msgs = _sniffer.GetAkashiTimerNotice();
\r
552 if (msgs.Length == 0)
\r
554 if (msgs[0].Proceeded == "20分経過しました。")
\r
556 _noticeQueue.Enqueue("泊地修理", msgs[0].Proceeded, _config.Akashi20MinSoundFile);
\r
557 msgs[0].Proceeded = "";
\r
558 // 修理完了がいるかもしれないので続ける
\r
560 var fn = new[] {"第一艦隊", "第二艦隊", "第三艦隊", "第四艦隊"};
\r
561 for (var i = 0; i < fn.Length; i++)
\r
563 if (msgs[i].Proceeded != "")
\r
564 _noticeQueue.Enqueue("泊地修理 " + fn[i], "修理進行:" + msgs[i].Proceeded, _config.AkashiProgressSoundFile);
\r
565 if (msgs[i].Completed != "")
\r
566 _noticeQueue.Enqueue("泊地修理 " + fn[i], "修理完了:" + msgs[i].Completed, _config.AkashiCompleteSoundFile);
\r
570 public void UpdateFighterPower()
\r
572 labelFighterPower.Text = _sniffer.GetFighterPower(_currentFleet, true).ToString("D");
\r
573 toolTipFigherPower.SetToolTip(labelFighterPower, "熟練度抜き " + _sniffer.GetFighterPower(_currentFleet, false));
\r
576 private void UpdateLoS()
\r
578 labelLoS.Text = _sniffer.GetFleetLineOfSights(_currentFleet).ToString("F1");
\r
581 private void UpdateBattleInfo()
\r
583 labelFormation.Text = "";
\r
584 labelEnemyFighterPower.Text = "";
\r
585 labelFighterPower.ForeColor = DefaultForeColor;
\r
586 labelResultRank.Text = "判定";
\r
587 panelBattleInfo.Visible = _sniffer.Battle.InBattle;
\r
588 if (!_sniffer.Battle.InBattle)
\r
590 panelBattleInfo.BringToFront();
\r
591 var battle = _sniffer.Battle;
\r
592 var color = new[] {DefaultForeColor, DefaultForeColor, Color.Blue, Color.Green, Color.Orange, Color.Red};
\r
593 labelFormation.Text = battle.Formation;
\r
594 var enemyFp = battle.EnemyFighterPower;
\r
595 labelEnemyFighterPower.Text = (enemyFp & BattleInfo.IncollectFighterPowerFlag) == 0
\r
596 ? enemyFp.ToString()
\r
597 : (enemyFp & ~BattleInfo.IncollectFighterPowerFlag) + "+";
\r
598 labelFighterPower.ForeColor = color[battle.AirControlLevel + 1];
\r
599 if (_config.AlwaysShowResultRank)
\r
603 private void ShowResultRank()
\r
605 var result = new[] {"完全S", "勝利S", "勝利A", "勝利B", "敗北C", "敗北D", "敗北E"};
\r
606 labelResultRank.Text = result[(int)_sniffer.Battle.ResultRank];
\r
609 private void labelResultRank_Click(object sender, EventArgs e)
\r
614 private void UpdateChargeInfo()
\r
616 var fuelSq = new[] {labelFuelSq1, labelFuelSq2, labelFuelSq3, labelFuelSq4};
\r
617 var bullSq = new[] {labelBullSq1, labelBullSq2, labelBullSq3, labelBullSq4};
\r
619 for (var i = 0; i < fuelSq.Length; i++)
\r
621 var stat = _sniffer.ChargeStatuses[i];
\r
622 fuelSq[i].ImageIndex = stat.Fuel;
\r
623 bullSq[i].ImageIndex = stat.Bull;
\r
627 private void UpdateNDocLabels()
\r
629 _shipLabels.SetNDockLabels(_sniffer.NDock);
\r
632 private void UpdateMissionLabels()
\r
634 foreach (var entry in
\r
635 new[] {labelMissionName1, labelMissionName2, labelMissionName3}.Zip(_sniffer.Missions,
\r
636 (label, mission) => new {label, mission.Name}))
\r
637 entry.label.Text = entry.Name;
\r
640 private void UpdateTimers()
\r
642 foreach (var entry in
\r
643 new[] {labelMission1, labelMission2, labelMission3}.Zip(_sniffer.Missions,
\r
644 (label, mission) => new {label, mission.Name, mission.Timer}))
\r
646 entry.Timer.Update();
\r
647 SetTimerColor(entry.label, entry.Timer);
\r
648 var rest = entry.Timer.Rest;
\r
649 entry.label.Text = rest.Days == 0 ? rest.ToString(@"hh\:mm\:ss") : rest.ToString(@"d\dhh\:mm");
\r
650 if (!entry.Timer.NeedRing)
\r
652 _noticeQueue.Enqueue("遠征が終わりました", entry.Name, _config.MissionSoundFile);
\r
653 entry.Timer.NeedRing = false;
\r
655 for (var i = 0; i < _sniffer.NDock.Length; i++)
\r
657 var entry = _sniffer.NDock[i];
\r
658 entry.Timer.Update();
\r
659 _shipLabels.SetNDockTimer(i, entry.Timer);
\r
660 if (!entry.Timer.NeedRing)
\r
662 _noticeQueue.Enqueue("入渠が終わりました", entry.Name, _config.NDockSoundFile);
\r
663 entry.Timer.NeedRing = false;
\r
665 var kdock = new[] {labelConstruct1, labelConstruct2, labelConstruct3, labelConstruct4};
\r
666 for (var i = 0; i < kdock.Length; i++)
\r
668 var timer = _sniffer.KDock[i];
\r
670 SetTimerColor(kdock[i], timer);
\r
671 kdock[i].Text = timer.Rest.ToString(@"hh\:mm\:ss");
\r
672 if (!timer.NeedRing)
\r
674 _noticeQueue.Enqueue("建造が終わりました", $"第{i + 1:D}ドック", _config.KDockSoundFile);
\r
675 timer.NeedRing = false;
\r
677 UpdateCondTimers();
\r
678 UpdateAkashiTimer();
\r
681 private void SetTimerColor(Label label, RingTimer timer)
\r
683 label.ForeColor = timer.IsFinished ? Color.Red : Color.Black;
\r
686 private void UpdateCondTimers()
\r
688 var timer = _sniffer.GetConditionTimer(_currentFleet);
\r
689 var now = DateTime.Now;
\r
690 if (timer == DateTime.MinValue)
\r
692 labelCondTimerTitle.Text = "";
\r
693 labelCondTimer.Text = "";
\r
696 var span = TimeSpan.FromSeconds(Ceiling((timer - now).TotalSeconds));
\r
697 if (span >= TimeSpan.FromMinutes(9))
\r
699 labelCondTimerTitle.Text = "cond40まで";
\r
700 labelCondTimer.Text = (span - TimeSpan.FromMinutes(9)).ToString(@"mm\:ss");
\r
704 labelCondTimerTitle.Text = "cond49まで";
\r
705 labelCondTimer.Text = (span >= TimeSpan.Zero ? span : TimeSpan.Zero).ToString(@"mm\:ss");
\r
707 var notice = _sniffer.GetConditionNotice();
\r
708 if (notice == null)
\r
710 var fn = new[] {"第一艦隊", "第二艦隊", "第三艦隊", "第四艦隊"};
\r
711 for (var i = 0; i < fn.Length; i++)
\r
713 if (!_config.NotifyConditions.Contains(notice[i]))
\r
715 _noticeQueue.Enqueue("疲労が回復しました", fn[i] + " cond" + notice[i].ToString("D"), _config.ConditionSoundFile);
\r
719 private void UpdateAkashiTimer()
\r
721 _shipLabels.SetAkashiTimer(_sniffer.GetShipStatuses(_currentFleet),
\r
722 _sniffer.GetAkashiTimers(_currentFleet));
\r
723 NotifyAkashiTimer();
\r
726 private void UpdateDamagedShipList()
\r
728 _shipLabels.SetDamagedShipList(_sniffer.DamagedShipList);
\r
731 private void UpdateQuestList()
\r
733 var category = new[]
\r
735 labelQuestColor1, labelQuestColor2, labelQuestColor3, labelQuestColor4, labelQuestColor5,
\r
738 var name = new[] {labelQuest1, labelQuest2, labelQuest3, labelQuest4, labelQuest5, labelQuest6};
\r
739 var progress = new[]
\r
740 {labelProgress1, labelProgress2, labelProgress3, labelProgress4, labelProgress5, labelProgress6};
\r
743 Color.FromArgb(60, 141, 76), Color.FromArgb(232, 57, 41), Color.FromArgb(136, 204, 120),
\r
744 Color.FromArgb(52, 147, 185), Color.FromArgb(220, 198, 126), Color.FromArgb(168, 111, 76),
\r
745 Color.FromArgb(200, 148, 231)
\r
748 var quests = _sniffer.Quests;
\r
749 for (var i = 0; i < name.Length; i++)
\r
751 if (i < quests.Length)
\r
753 category[i].BackColor = color[quests[i].Category - 1];
\r
754 name[i].Text = quests[i].Name;
\r
755 progress[i].Text = $"{quests[i].Progress:D}%";
\r
759 category[i].BackColor = DefaultBackColor;
\r
760 name[i].Text = progress[i].Text = "";
\r
765 private class NoticeQueue
\r
767 private readonly Action<string, string, string> _ring;
\r
768 private readonly Queue<Tuple<string, string, string>> _queue = new Queue<Tuple<string, string, string>>();
\r
769 private readonly Timer _timer = new Timer {Interval = 2000};
\r
771 public NoticeQueue(Action<string, string, string> ring)
\r
774 _timer.Tick += TimerOnTick;
\r
777 private void TimerOnTick(object obj, EventArgs e)
\r
779 if (_queue.Count == 0)
\r
784 var notice = _queue.Dequeue();
\r
785 _ring(notice.Item1, notice.Item2, notice.Item3);
\r
788 public void Enqueue(string title, string message, string soundFile)
\r
790 if (_timer.Enabled)
\r
792 _queue.Enqueue(new Tuple<string, string, string>(title, message, soundFile));
\r
796 _ring(title, message, soundFile);
\r
802 private void Ring(string baloonTitle, string baloonMessage, string soundFile)
\r
804 if (_config.FlashWindow)
\r
805 Win32API.FlashWindow(Handle);
\r
806 if (_config.ShowBaloonTip)
\r
807 notifyIconMain.ShowBalloonTip(20000, baloonTitle, baloonMessage, ToolTipIcon.Info);
\r
808 if (_config.PlaySound)
\r
809 PlaySound(soundFile, _config.SoundVolume);
\r
812 [DllImport("winmm.dll")]
\r
813 private static extern int mciSendString(String command,
\r
814 StringBuilder buffer, int bufferSize, IntPtr hwndCallback);
\r
816 // ReSharper disable InconsistentNaming
\r
817 private const int MM_MCINOTIFY = 0x3B9;
\r
818 private const int MCI_NOTIFY_SUCCESSFUL = 1;
\r
819 // ReSharper restore InconsistentNaming
\r
821 public void PlaySound(string file, int volume)
\r
823 if (!File.Exists(file))
\r
825 mciSendString("close sound", null, 0, IntPtr.Zero);
\r
826 if (mciSendString("open \"" + file + "\" type mpegvideo alias sound", null, 0, IntPtr.Zero) != 0)
\r
828 mciSendString("setaudio sound volume to " + volume * 10, null, 0, IntPtr.Zero);
\r
829 mciSendString("play sound notify", null, 0, Handle);
\r
832 protected override void WndProc(ref Message m)
\r
834 if (m.Msg == MM_MCINOTIFY && (int)m.WParam == MCI_NOTIFY_SUCCESSFUL)
\r
835 mciSendString("close sound", null, 0, IntPtr.Zero);
\r
836 base.WndProc(ref m);
\r
839 private void SetupFleetClick()
\r
843 new[] {labelFleet1, labelFleet2, labelFleet3, labelFleet4},
\r
844 new[] {labelFuelSq1, labelFuelSq2, labelFuelSq3, labelFuelSq4},
\r
845 new[] {labelBullSq1, labelBullSq2, labelBullSq3, labelBullSq4}
\r
847 foreach (var a in labels)
\r
849 for (var fleet = 0; fleet < labels[0].Length; fleet++)
\r
851 a[fleet].Tag = fleet;
\r
852 a[fleet].Click += labelFleet_Click;
\r
857 private void labelFleet_Click(object sender, EventArgs e)
\r
859 var fleet = (int)((Label)sender).Tag;
\r
860 if (_currentFleet == fleet)
\r
862 _currentFleet = fleet;
\r
863 foreach (var label in _labelCheckFleets)
\r
864 label.Visible = false;
\r
865 _labelCheckFleets[fleet].Visible = true;
\r
868 UpdatePanelShipInfo();
\r
871 private void labelBucketHistoryButton_Click(object sender, EventArgs e)
\r
873 if (labelBucketHistory.Visible)
\r
875 labelBucketHistory.Visible = false;
\r
876 labelBucketHistoryButton.BackColor = DefaultBackColor;
\r
880 labelBucketHistory.Visible = true;
\r
881 labelBucketHistory.BringToFront();
\r
882 labelBucketHistoryButton.BackColor = SystemColors.ActiveCaption;
\r
886 private void labelBucketHistory_Click(object sender, EventArgs e)
\r
888 labelBucketHistory.Visible = false;
\r
889 labelBucketHistoryButton.BackColor = DefaultBackColor;
\r
892 private void labelMaterialHistoryButton_Click(object sender, EventArgs e)
\r
894 if (panelMaterialHistory.Visible)
\r
896 panelMaterialHistory.Visible = false;
\r
897 labelMaterialHistoryButton.BackColor = DefaultBackColor;
\r
901 panelMaterialHistory.Visible = true;
\r
902 panelMaterialHistory.BringToFront();
\r
903 labelMaterialHistoryButton.BackColor = SystemColors.ActiveCaption;
\r
907 private void panelMaterialHistory_Click(object sender, EventArgs e)
\r
909 panelMaterialHistory.Visible = false;
\r
910 labelMaterialHistoryButton.BackColor = DefaultBackColor;
\r
913 public void ResetAchievemnt()
\r
915 _sniffer.Achievement.Reset();
\r
919 private void labelDamgedShipListButton_Click(object sender, EventArgs e)
\r
921 if (panelDamagedShipList.Visible)
\r
923 panelDamagedShipList.Visible = false;
\r
924 labelDamgedShipListButton.BackColor = DefaultBackColor;
\r
928 panelDamagedShipList.Visible = true;
\r
929 panelDamagedShipList.BringToFront();
\r
930 labelDamgedShipListButton.BackColor = SystemColors.ActiveCaption;
\r
934 private void panelDamagedShipList_Click(object sender, EventArgs e)
\r
936 panelDamagedShipList.Visible = false;
\r
937 labelDamgedShipListButton.BackColor = DefaultBackColor;
\r
940 private void ShipListToolStripMenuItem_Click(object sender, EventArgs e)
\r
942 _shipListForm.UpdateList();
\r
943 _shipListForm.Show();
\r
944 if (_shipListForm.WindowState == FormWindowState.Minimized)
\r
945 _shipListForm.WindowState = FormWindowState.Normal;
\r
946 _shipListForm.Activate();
\r
949 private void LogToolStripMenuItem_Click(object sender, EventArgs e)
\r
951 Process.Start("http://localhost:" + _config.Log.Listen + "/");
\r
954 private void CaptureToolStripMenuItem_Click(object sender, EventArgs e)
\r
958 var proc = new ProcessStartInfo("BurageSnap.exe") {WorkingDirectory = "Capture"};
\r
959 Process.Start(proc);
\r
961 catch (FileNotFoundException)
\r