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
24 using System.Net.Sockets;
\r
25 using System.Runtime.InteropServices;
\r
27 using System.Threading;
\r
28 using System.Threading.Tasks;
\r
29 using System.Windows.Forms;
\r
30 using Codeplex.Data;
\r
31 using Microsoft.CSharp.RuntimeBinder;
\r
32 using Microsoft.Win32;
\r
34 using static System.Math;
\r
35 using Timer = System.Windows.Forms.Timer;
\r
37 namespace KancolleSniffer
\r
39 public partial class MainForm : Form
\r
41 private readonly Sniffer _sniffer = new Sniffer();
\r
42 private readonly Config _config = new Config();
\r
43 private readonly ConfigDialog _configDialog;
\r
44 private int _currentFleet;
\r
45 private readonly Label[] _labelCheckFleets;
\r
46 private readonly ShipLabels _shipLabels;
\r
47 private readonly ShipListForm _shipListForm;
\r
48 private readonly NoticeQueue _noticeQueue;
\r
49 private bool _started;
\r
50 private string _debugLogFile;
\r
51 private IEnumerator<string> _playLog;
\r
52 private LogServer _logServer;
\r
53 private int _prevProxyPort;
\r
54 private readonly SystemProxy _systemProxy = new SystemProxy();
\r
58 InitializeComponent();
\r
59 HttpProxy.AfterSessionComplete += HttpProxy_AfterSessionComplete;
\r
60 _configDialog = new ConfigDialog(_config, this);
\r
61 _labelCheckFleets = new[] {labelCheckFleet1, labelCheckFleet2, labelCheckFleet3, labelCheckFleet4};
\r
63 // この時点でAutoScaleDimensions == CurrentAutoScaleDimensionsなので、
\r
64 // MainForm.Designer.csのAutoScaleDimensionsの6f,12fを使う。
\r
65 ShipLabel.ScaleFactor = new SizeF(CurrentAutoScaleDimensions.Width / 6f,
\r
66 CurrentAutoScaleDimensions.Height / 12f);
\r
69 _shipLabels = new ShipLabels();
\r
70 _shipLabels.CreateAkashiTimers(panelShipInfo);
\r
71 _shipLabels.CreateLabels(panelShipInfo, ShowShipOnShipList);
\r
72 _shipLabels.CreateDamagedShipList(panelDamagedShipList);
\r
73 _shipLabels.CreateNDockLabels(panelDock);
\r
74 _shipListForm = new ShipListForm(_sniffer, _config) {Owner = this};
\r
75 _noticeQueue = new NoticeQueue(Ring);
\r
78 private void HttpProxy_AfterSessionComplete(Session session)
\r
80 Invoke(new Action<Session>(ProcessRequest), session);
\r
83 private void ProcessRequest(Session session)
\r
85 var response = session.Response.BodyAsString;
\r
86 if (response == null || !response.StartsWith("svdata="))
\r
88 response = response.Remove(0, "svdata=".Length);
\r
89 var json = DynamicJson.Parse(response);
\r
90 var request = session.Request.BodyAsString;
\r
91 if (_debugLogFile != null)
\r
93 File.AppendAllText(_debugLogFile,
\r
94 string.Format("url: {0}\nrequest: {1}\nresponse: {2}\n", session.Request.PathAndQuery, request, json.ToString()));
\r
98 UpdateInfo(_sniffer.Sniff(session.Request.PathAndQuery, request, json));
\r
100 catch (RuntimeBinderException)
\r
102 labelLogin.Visible = true;
\r
103 labelLogin.Text = "現在の艦これに対応していません。\n新しいバージョンを利用してください。";
\r
107 private void UpdateInfo(Sniffer.Update update)
\r
109 if (update == Sniffer.Update.Start)
\r
111 labelLogin.Visible = false;
\r
117 if ((update & Sniffer.Update.Item) != 0)
\r
119 if ((update & Sniffer.Update.Timer) != 0)
\r
121 if ((update & Sniffer.Update.NDock) != 0)
\r
122 UpdateNDocLabels();
\r
123 if ((update & Sniffer.Update.Mission) != 0)
\r
124 UpdateMissionLabels();
\r
125 if ((update & Sniffer.Update.QuestList) != 0)
\r
127 if ((update & Sniffer.Update.Ship) != 0)
\r
129 if ((update & Sniffer.Update.Battle) != 0)
\r
130 UpdateBattleInfo();
\r
133 private void MainForm_Load(object sender, EventArgs e)
\r
137 if (_config.HideOnMinimized && WindowState == FormWindowState.Minimized)
\r
138 ShowInTaskbar = false;
\r
140 ApplyDebugLogSetting();
\r
142 _sniffer.LoadState();
\r
143 ApplyProxySetting();
\r
144 SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
\r
147 private void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
\r
149 if (e.Mode != PowerModes.Resume)
\r
151 Thread.Sleep(10000);
\r
152 SystemProxy.Refresh();
\r
155 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
\r
158 _config.Location = (WindowState == FormWindowState.Normal ? Bounds : RestoreBounds).Location;
\r
160 Task.Run(() => ShutdownProxy());
\r
161 _logServer?.Stop();
\r
162 if (_config.Proxy.Auto)
\r
163 _systemProxy.RestoreSettings();
\r
164 SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
\r
167 private void ShutdownProxy()
\r
169 HttpProxy.Shutdown();
\r
172 private void MainForm_Resize(object sender, EventArgs e)
\r
174 ShowInTaskbar = !(_config.HideOnMinimized && WindowState == FormWindowState.Minimized);
\r
177 private void notifyIconMain_MouseDoubleClick(object sender, MouseEventArgs e)
\r
179 NotifyIconOpenToolStripMenuItem_Click(sender, e);
\r
182 private void NotifyIconOpenToolStripMenuItem_Click(object sender, EventArgs e)
\r
184 ShowInTaskbar = true;
\r
185 WindowState = FormWindowState.Normal;
\r
186 TopMost = _config.TopMost; // 最前面に表示されなくなることがあるのを回避する
\r
190 private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
\r
195 private void ConfigToolStripMenuItem_Click(object sender, EventArgs e)
\r
197 if (_configDialog.ShowDialog(this) == DialogResult.OK)
\r
201 private void RestoreLocation()
\r
203 if (_config.Location.X == int.MinValue)
\r
205 var newBounds = Bounds;
\r
206 newBounds.Location = _config.Location;
\r
207 if (IsVisibleOnAnyScreen(newBounds))
\r
208 Location = _config.Location;
\r
211 private void ApplyConfig()
\r
213 _shipListForm.TopMost = TopMost = _config.TopMost;
\r
214 _sniffer.Item.MarginShips = _config.MarginShips;
\r
215 _sniffer.Item.MarginEquips = _config.MarginEquips;
\r
216 _sniffer.Achievement.ResetHours = _config.ResetHours;
\r
219 public void ApplyDebugLogSetting()
\r
221 _debugLogFile = _config.DebugLogging ? _config.DebugLogFile : null;
\r
224 public bool ApplyProxySetting()
\r
226 if (!_config.Proxy.Auto)
\r
227 _systemProxy.RestoreSettings();
\r
228 if (_config.Proxy.UseUpstream)
\r
230 HttpProxy.UpstreamProxyHost = "127.0.0.1";
\r
231 HttpProxy.UpstreamProxyPort = _config.Proxy.UpstreamPort;
\r
233 HttpProxy.IsEnableUpstreamProxy = _config.Proxy.UseUpstream;
\r
235 if (!HttpProxy.IsInListening || _config.Proxy.Listen != _prevProxyPort)
\r
238 result = StartProxy();
\r
240 if (_config.Proxy.Auto && result)
\r
242 _systemProxy.SetAutoProxyUrl(HttpProxy.LocalPort == 8080
\r
243 ? ProxyConfig.AutoConfigUrl
\r
244 : ProxyConfig.AutoConfigUrlWithPort + HttpProxy.LocalPort);
\r
246 _prevProxyPort = _config.Proxy.Listen;
\r
250 private bool StartProxy()
\r
254 HttpProxy.Startup(_config.Proxy.Listen, false, false);
\r
256 catch (SocketException e)
\r
258 if (e.SocketErrorCode != SocketError.AddressAlreadyInUse)
\r
260 if (WarnConflictPortNumber("プロキシサーバー", _config.Proxy.Listen, _config.Proxy.Auto) == DialogResult.No ||
\r
261 !_config.Proxy.Auto)
\r
263 _systemProxy.RestoreSettings();
\r
266 HttpProxy.Startup(0, false, false);
\r
267 _config.Proxy.Listen = HttpProxy.LocalPort;
\r
272 private DialogResult WarnConflictPortNumber(string name, int port, bool auto)
\r
274 var msg = $"{name}のポート番号{port}は他のアプリケーションが使用中です。";
\r
275 var cap = "ポート番号の衝突";
\r
277 ? MessageBox.Show(this, msg + "自動的に別の番号を割り当てますか?", cap,
\r
278 MessageBoxButtons.YesNo, MessageBoxIcon.Question)
\r
279 : MessageBox.Show(this, msg + "設定ダイアログでポート番号を変更してください。", cap,
\r
280 MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
\r
283 public bool ApplyLogSetting()
\r
286 if (_config.Log.ServerOn)
\r
288 result = StartLogServer();
\r
292 _logServer?.Stop();
\r
295 _sniffer.EnableLog(_config.Log.On ? LogType.All : LogType.None);
\r
296 _sniffer.MaterialLogInterval = _config.Log.MaterialLogInterval;
\r
297 _sniffer.LogOutputDir = _config.Log.OutputDir;
\r
301 private bool StartLogServer()
\r
303 var port = _config.Log.Listen;
\r
304 if (_logServer?.Port == port)
\r
306 _logServer?.Stop();
\r
310 _logServer = new LogServer(port);
\r
311 _logServer.Start();
\r
313 catch (SocketException e) when (e.SocketErrorCode == SocketError.AddressAlreadyInUse)
\r
315 if (WarnConflictPortNumber("閲覧サーバー", port, true) == DialogResult.No)
\r
317 _logServer = new LogServer(0);
\r
318 _logServer.Start();
\r
319 _config.Log.Listen = _logServer.Port;
\r
321 _logServer.OutputDir = _config.Log.OutputDir;
\r
325 public static bool IsVisibleOnAnyScreen(Rectangle rect)
\r
327 return Screen.AllScreens.Any(screen => screen.WorkingArea.IntersectsWith(rect));
\r
330 private void timerMain_Tick(object sender, EventArgs e)
\r
334 if (_playLog == null || _configDialog.Visible)
\r
336 labelPlayLog.Visible = false;
\r
342 public void SetPlayLog(string file)
\r
344 _playLog = File.ReadLines(file).GetEnumerator();
\r
347 private void PlayLog()
\r
349 var lines = new List<string>();
\r
350 foreach (var s in new[] {"url: ", "request: ", "response: "})
\r
352 if (!_playLog.MoveNext() || !_playLog.Current.StartsWith(s))
\r
354 labelPlayLog.Visible = false;
\r
357 lines.Add(_playLog.Current.Substring(s.Count()));
\r
359 labelPlayLog.Visible = !labelPlayLog.Visible;
\r
360 var json = DynamicJson.Parse(lines[2]);
\r
361 UpdateInfo(_sniffer.Sniff(lines[0], lines[1], json));
\r
364 private void ShowShipOnShipList(object sender, EventArgs ev)
\r
366 if (!_shipListForm.Visible)
\r
368 var idx = (int)((Control)sender).Tag;
\r
369 var statuses = _sniffer.GetShipStatuses(_currentFleet);
\r
370 if (statuses.Length <= idx)
\r
372 _shipListForm.ShowShip(statuses[idx].Id);
\r
375 private void UpdateItemInfo()
\r
377 UpdateNumOfShips();
\r
378 UpdateNumOfEquips();
\r
379 labelNumOfBuckets.Text = _sniffer.Item.MaterialHistory[(int)Material.Bucket].Now.ToString("D");
\r
380 UpdateBucketHistory();
\r
381 var ac = _sniffer.Achievement.Value;
\r
384 labelAchievement.Text = ac >= 1000 ? ((int)ac).ToString("D") : ac.ToString("F1");
\r
385 toolTipAchievement.SetToolTip(labelAchievement,
\r
386 "今月 " + _sniffer.Achievement.ValueOfMonth.ToString("F1") + "\n" +
\r
387 "EO " + _sniffer.ExMap.Achievement);
\r
388 UpdateMaterialHistry();
\r
389 if (_shipListForm.Visible)
\r
390 _shipListForm.UpdateList();
\r
393 private void UpdateNumOfShips()
\r
395 var item = _sniffer.Item;
\r
396 labelNumOfShips.Text = $"{item.NowShips:D}/{item.MaxShips:D}";
\r
397 labelNumOfShips.ForeColor = item.TooManyShips ? Color.Red : Color.Black;
\r
398 if (item.RingShips)
\r
400 var message = $"残り{_sniffer.Item.MaxShips - _sniffer.Item.NowShips:D}隻";
\r
401 _noticeQueue.Enqueue("艦娘が多すぎます", message, _config.MaxShipsSoundFile);
\r
402 item.RingShips = false;
\r
406 private void UpdateNumOfEquips()
\r
408 var item = _sniffer.Item;
\r
409 labelNumOfEquips.Text = $"{item.NowEquips:D}/{item.MaxEquips:D}";
\r
410 labelNumOfEquips.ForeColor = item.TooManyEquips ? Color.Red : Color.Black;
\r
411 if (item.RingEquips)
\r
413 var message = $"残り{_sniffer.Item.MaxEquips - _sniffer.Item.NowEquips:D}個";
\r
414 _noticeQueue.Enqueue("装備が多すぎます", message, _config.MaxEquipsSoundFile);
\r
415 item.RingEquips = false;
\r
419 private void UpdateBucketHistory()
\r
421 var count = _sniffer.Item.MaterialHistory[(int)Material.Bucket];
\r
422 var day = count.Now - count.BegOfDay;
\r
423 var week = count.Now - count.BegOfWeek;
\r
428 labelBucketHistory.Text = $"{day:+#;-#;±0} 今日\n{week:+#;-#;±0} 今週";
\r
431 private void UpdateMaterialHistry()
\r
433 var labels = new[] {labelFuelHistory, labelBulletHistory, labelSteelHistory, labelBouxiteHistory};
\r
434 var text = new[] {"燃料", "弾薬", "鋼材", "ボーキ"};
\r
435 for (var i = 0; i < labels.Length; i++)
\r
437 var count = _sniffer.Item.MaterialHistory[i];
\r
438 var port = count.Now - _sniffer.Item.PrevPort[i];
\r
439 if (port >= 100000)
\r
441 var day = count.Now - count.BegOfDay;
\r
444 var week = count.Now - count.BegOfWeek;
\r
445 if (week >= 100000)
\r
447 labels[i].Text = $"{text[i]}\n{port:+#;-#;±0}\n{day:+#;-#;±0}\n{week:+#;-#;±0}";
\r
451 private void UpdateShipInfo()
\r
453 UpdatePanelShipInfo();
\r
454 NotifyDamagedShip();
\r
455 UpdateChargeInfo();
\r
456 UpdateDamagedShipList();
\r
457 if (_shipListForm.Visible)
\r
458 _shipListForm.UpdateList();
\r
461 private void UpdatePanelShipInfo()
\r
463 var statuses = _sniffer.GetShipStatuses(_currentFleet);
\r
464 _shipLabels.SetShipInfo(statuses);
\r
465 UpdateAkashiTimer();
\r
466 UpdateFighterPower();
\r
468 UpdateCondTimers();
\r
471 private void NotifyDamagedShip()
\r
473 if (_sniffer.Battle.HasDamagedShip)
\r
474 _noticeQueue.Enqueue("大破した艦娘がいます", string.Join(" ", _sniffer.Battle.DamagedShipNames),
\r
475 _config.DamagedShipSoundFile);
\r
478 private void NotifyAkashiTimer()
\r
480 var msgs = _sniffer.GetAkashiTimerNotice();
\r
481 if (msgs.Length == 0)
\r
483 if (msgs[0].Proceeded == "20分経過しました。")
\r
485 _noticeQueue.Enqueue("泊地修理", msgs[0].Proceeded, _config.Akashi20MinSoundFile);
\r
486 msgs[0].Proceeded = "";
\r
487 // 修理完了がいるかもしれないので続ける
\r
489 var fn = new[] {"第一艦隊", "第二艦隊", "第三艦隊", "第四艦隊"};
\r
490 for (var i = 0; i < fn.Length; i++)
\r
492 if (msgs[i].Proceeded != "")
\r
493 _noticeQueue.Enqueue("泊地修理 " + fn[i], "修理進行:" + msgs[i].Proceeded, _config.AkashiProgressSoundFile);
\r
494 if (msgs[i].Completed != "")
\r
495 _noticeQueue.Enqueue("泊地修理 " + fn[i], "修理完了:" + msgs[i].Completed, _config.AkashiCompleteSoundFile);
\r
499 public void UpdateFighterPower()
\r
501 labelFighterPower.Text = _sniffer.GetFighterPower(_currentFleet, true).ToString("D");
\r
502 toolTipFigherPower.SetToolTip(labelFighterPower, "熟練度抜き " + _sniffer.GetFighterPower(_currentFleet, false));
\r
505 private void UpdateLoS()
\r
507 labelLoS.Text = _sniffer.GetFleetLineOfSights(_currentFleet).ToString("F1");
\r
510 private void UpdateBattleInfo()
\r
512 labelFormation.Text = "";
\r
513 labelEnemyFighterPower.Text = "";
\r
514 labelFighterPower.ForeColor = DefaultForeColor;
\r
515 labelResultRank.Text = "判定";
\r
516 panelBattleInfo.Visible = _sniffer.Battle.InBattle;
\r
517 if (!_sniffer.Battle.InBattle)
\r
519 panelBattleInfo.BringToFront();
\r
520 var battle = _sniffer.Battle;
\r
521 var color = new[] {DefaultForeColor, DefaultForeColor, Color.Blue, Color.Green, Color.Orange, Color.Red};
\r
522 labelFormation.Text = battle.Formation;
\r
523 var enemyFp = battle.EnemyFighterPower;
\r
524 labelEnemyFighterPower.Text = (enemyFp & BattleInfo.IncollectFighterPowerFlag) == 0
\r
525 ? enemyFp.ToString()
\r
526 : (enemyFp & ~BattleInfo.IncollectFighterPowerFlag) + "+";
\r
527 labelFighterPower.ForeColor = color[battle.AirControlLevel + 1];
\r
528 if (_config.AlwaysShowResultRank)
\r
532 private void ShowResultRank()
\r
534 var result = new[] {"完全S", "勝利S", "勝利A", "勝利B", "敗北C", "敗北D", "敗北E"};
\r
535 labelResultRank.Text = result[(int)_sniffer.Battle.ResultRank];
\r
538 private void labelResultRank_Click(object sender, EventArgs e)
\r
543 private void UpdateChargeInfo()
\r
545 var fuelSq = new[] {labelFuelSq1, labelFuelSq2, labelFuelSq3, labelFuelSq4};
\r
546 var bullSq = new[] {labelBullSq1, labelBullSq2, labelBullSq3, labelBullSq4};
\r
548 for (var i = 0; i < fuelSq.Length; i++)
\r
550 var stat = _sniffer.ChargeStatuses[i];
\r
551 fuelSq[i].ImageIndex = stat.Fuel;
\r
552 bullSq[i].ImageIndex = stat.Bull;
\r
556 private void UpdateNDocLabels()
\r
558 _shipLabels.SetNDockLabels(_sniffer.NDock);
\r
561 private void UpdateMissionLabels()
\r
563 foreach (var entry in
\r
564 new[] {labelMissionName1, labelMissionName2, labelMissionName3}.Zip(_sniffer.Missions,
\r
565 (label, mission) => new {label, mission.Name}))
\r
566 entry.label.Text = entry.Name;
\r
569 private void UpdateTimers()
\r
571 foreach (var entry in
\r
572 new[] {labelMission1, labelMission2, labelMission3}.Zip(_sniffer.Missions,
\r
573 (label, mission) => new {label, mission.Name, mission.Timer}))
\r
575 entry.Timer.Update();
\r
576 SetTimerColor(entry.label, entry.Timer);
\r
577 var rest = entry.Timer.Rest;
\r
578 entry.label.Text = rest.Days == 0 ? rest.ToString(@"hh\:mm\:ss") : rest.ToString(@"d\.hh\:mm");
\r
579 if (!entry.Timer.NeedRing)
\r
581 _noticeQueue.Enqueue("遠征が終わりました", entry.Name, _config.MissionSoundFile);
\r
582 entry.Timer.NeedRing = false;
\r
584 for (var i = 0; i < _sniffer.NDock.Length; i++)
\r
586 var entry = _sniffer.NDock[i];
\r
587 entry.Timer.Update();
\r
588 _shipLabels.SetNDockTimer(i, entry.Timer);
\r
589 if (!entry.Timer.NeedRing)
\r
591 _noticeQueue.Enqueue("入渠が終わりました", entry.Name, _config.NDockSoundFile);
\r
592 entry.Timer.NeedRing = false;
\r
594 var kdock = new[] {labelConstruct1, labelConstruct2, labelConstruct3, labelConstruct4};
\r
595 for (var i = 0; i < kdock.Length; i++)
\r
597 var timer = _sniffer.KDock[i];
\r
599 SetTimerColor(kdock[i], timer);
\r
600 kdock[i].Text = timer.Rest.ToString(@"hh\:mm\:ss");
\r
601 if (!timer.NeedRing)
\r
603 _noticeQueue.Enqueue("建造が終わりました", $"第{i + 1:D}ドック", _config.KDockSoundFile);
\r
604 timer.NeedRing = false;
\r
606 UpdateCondTimers();
\r
607 UpdateAkashiTimer();
\r
610 private void SetTimerColor(Label label, RingTimer timer)
\r
612 label.ForeColor = timer.IsFinished ? Color.Red : Color.Black;
\r
615 private void UpdateCondTimers()
\r
617 var timer = _sniffer.GetConditionTimer(_currentFleet);
\r
618 var now = DateTime.Now;
\r
619 if (timer == DateTime.MinValue)
\r
621 labelCondTimerTitle.Text = "";
\r
622 labelCondTimer.Text = "";
\r
625 var span = TimeSpan.FromSeconds(Ceiling((timer - now).TotalSeconds));
\r
626 if (span >= TimeSpan.FromMinutes(9))
\r
628 labelCondTimerTitle.Text = "cond40まで";
\r
629 labelCondTimer.Text = (span - TimeSpan.FromMinutes(9)).ToString(@"mm\:ss");
\r
633 labelCondTimerTitle.Text = "cond49まで";
\r
634 labelCondTimer.Text = (span >= TimeSpan.Zero ? span : TimeSpan.Zero).ToString(@"mm\:ss");
\r
636 var notice = _sniffer.GetConditionNotice();
\r
637 if (notice == null)
\r
639 var fn = new[] {"第一艦隊", "第二艦隊", "第三艦隊", "第四艦隊"};
\r
640 for (var i = 0; i < fn.Length; i++)
\r
642 if (!_config.NotifyConditions.Contains(notice[i]))
\r
644 _noticeQueue.Enqueue("疲労が回復しました", fn[i] + " cond" + notice[i].ToString("D"), _config.ConditionSoundFile);
\r
648 private void UpdateAkashiTimer()
\r
650 _shipLabels.SetAkashiTimer(_sniffer.GetShipStatuses(_currentFleet),
\r
651 _sniffer.GetAkashiTimers(_currentFleet));
\r
652 NotifyAkashiTimer();
\r
655 private void UpdateDamagedShipList()
\r
657 _shipLabels.SetDamagedShipList(_sniffer.DamagedShipList);
\r
660 private void UpdateQuestList()
\r
662 var category = new[]
\r
664 labelQuestColor1, labelQuestColor2, labelQuestColor3, labelQuestColor4, labelQuestColor5,
\r
667 var name = new[] {labelQuest1, labelQuest2, labelQuest3, labelQuest4, labelQuest5, labelQuest6};
\r
668 var progress = new[]
\r
669 {labelProgress1, labelProgress2, labelProgress3, labelProgress4, labelProgress5, labelProgress6};
\r
672 Color.FromArgb(60, 141, 76), Color.FromArgb(232, 57, 41), Color.FromArgb(136, 204, 120),
\r
673 Color.FromArgb(52, 147, 185), Color.FromArgb(220, 198, 126), Color.FromArgb(168, 111, 76),
\r
674 Color.FromArgb(200, 148, 231)
\r
677 var quests = _sniffer.Quests;
\r
678 for (var i = 0; i < name.Length; i++)
\r
680 if (i < quests.Length)
\r
682 category[i].BackColor = color[quests[i].Category - 1];
\r
683 name[i].Text = quests[i].Name;
\r
684 progress[i].Text = $"{quests[i].Progress:D}%";
\r
688 category[i].BackColor = DefaultBackColor;
\r
689 name[i].Text = progress[i].Text = "";
\r
694 private class NoticeQueue
\r
696 private readonly Action<string, string, string> _ring;
\r
697 private readonly Queue<Tuple<string, string, string>> _queue = new Queue<Tuple<string, string, string>>();
\r
698 private readonly Timer _timer = new Timer {Interval = 2000};
\r
700 public NoticeQueue(Action<string, string, string> ring)
\r
703 _timer.Tick += TimerOnTick;
\r
706 private void TimerOnTick(object obj, EventArgs e)
\r
708 if (_queue.Count == 0)
\r
713 var notice = _queue.Dequeue();
\r
714 _ring(notice.Item1, notice.Item2, notice.Item3);
\r
717 public void Enqueue(string title, string message, string soundFile)
\r
719 if (_timer.Enabled)
\r
721 _queue.Enqueue(new Tuple<string, string, string>(title, message, soundFile));
\r
725 _ring(title, message, soundFile);
\r
731 private void Ring(string baloonTitle, string baloonMessage, string soundFile)
\r
733 if (_config.FlashWindow)
\r
734 Win32API.FlashWindow(Handle);
\r
735 if (_config.ShowBaloonTip)
\r
736 notifyIconMain.ShowBalloonTip(20000, baloonTitle, baloonMessage, ToolTipIcon.Info);
\r
737 if (_config.PlaySound)
\r
738 PlaySound(soundFile, _config.SoundVolume);
\r
741 [DllImport("winmm.dll")]
\r
742 private static extern int mciSendString(String command,
\r
743 StringBuilder buffer, int bufferSize, IntPtr hwndCallback);
\r
745 // ReSharper disable InconsistentNaming
\r
746 private const int MM_MCINOTIFY = 0x3B9;
\r
747 private const int MCI_NOTIFY_SUCCESSFUL = 1;
\r
748 // ReSharper restore InconsistentNaming
\r
750 public void PlaySound(string file, int volume)
\r
752 if (!File.Exists(file))
\r
754 mciSendString("close sound", null, 0, IntPtr.Zero);
\r
755 if (mciSendString("open \"" + file + "\" type mpegvideo alias sound", null, 0, IntPtr.Zero) != 0)
\r
757 mciSendString("setaudio sound volume to " + volume * 10, null, 0, IntPtr.Zero);
\r
758 mciSendString("play sound notify", null, 0, Handle);
\r
761 protected override void WndProc(ref Message m)
\r
763 if (m.Msg == MM_MCINOTIFY && (int)m.WParam == MCI_NOTIFY_SUCCESSFUL)
\r
764 mciSendString("close sound", null, 0, IntPtr.Zero);
\r
765 base.WndProc(ref m);
\r
768 private void SetupFleetClick()
\r
772 new[] {labelFleet1, labelFleet2, labelFleet3, labelFleet4},
\r
773 new[] {labelFuelSq1, labelFuelSq2, labelFuelSq3, labelFuelSq4},
\r
774 new[] {labelBullSq1, labelBullSq2, labelBullSq3, labelBullSq4}
\r
776 foreach (var a in labels)
\r
778 for (var fleet = 0; fleet < labels[0].Length; fleet++)
\r
780 a[fleet].Tag = fleet;
\r
781 a[fleet].Click += labelFleet_Click;
\r
786 private void labelFleet_Click(object sender, EventArgs e)
\r
788 var fleet = (int)((Label)sender).Tag;
\r
789 if (_currentFleet == fleet)
\r
791 _currentFleet = fleet;
\r
792 foreach (var label in _labelCheckFleets)
\r
793 label.Visible = false;
\r
794 _labelCheckFleets[fleet].Visible = true;
\r
797 UpdatePanelShipInfo();
\r
800 private void labelBucketHistoryButton_Click(object sender, EventArgs e)
\r
802 if (labelBucketHistory.Visible)
\r
804 labelBucketHistory.Visible = false;
\r
805 labelBucketHistoryButton.BackColor = DefaultBackColor;
\r
809 labelBucketHistory.Visible = true;
\r
810 labelBucketHistory.BringToFront();
\r
811 labelBucketHistoryButton.BackColor = SystemColors.ActiveCaption;
\r
815 private void labelMaterialHistoryButton_Click(object sender, EventArgs e)
\r
817 if (panelMaterialHistory.Visible)
\r
819 panelMaterialHistory.Visible = false;
\r
820 labelMaterialHistoryButton.BackColor = DefaultBackColor;
\r
824 panelMaterialHistory.Visible = true;
\r
825 panelMaterialHistory.BringToFront();
\r
826 labelMaterialHistoryButton.BackColor = SystemColors.ActiveCaption;
\r
830 public void ResetAchievemnt()
\r
832 _sniffer.Achievement.Reset();
\r
836 private void labelDamgedShipListButton_Click(object sender, EventArgs e)
\r
838 if (panelDamagedShipList.Visible)
\r
840 panelDamagedShipList.Visible = false;
\r
841 labelDamgedShipListButton.BackColor = DefaultBackColor;
\r
845 panelDamagedShipList.Visible = true;
\r
846 panelDamagedShipList.BringToFront();
\r
847 labelDamgedShipListButton.BackColor = SystemColors.ActiveCaption;
\r
851 private void ShipListToolStripMenuItem_Click(object sender, EventArgs e)
\r
853 _shipListForm.UpdateList();
\r
854 _shipListForm.Show();
\r
855 if (_shipListForm.WindowState == FormWindowState.Minimized)
\r
856 _shipListForm.WindowState = FormWindowState.Normal;
\r
857 _shipListForm.Activate();
\r
860 private void LogToolStripMenuItem_Click(object sender, EventArgs e)
\r
862 Process.Start("http://localhost:" + _config.Log.Listen + "/");
\r