1 // Copyright (C) 2013, 2014, 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>
\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
7 // http://www.apache.org/licenses/LICENSE-2.0
\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
16 using System.Collections.Generic;
\r
17 using System.Diagnostics;
\r
18 using System.Drawing;
\r
19 using System.Globalization;
\r
22 using System.Runtime.InteropServices;
\r
24 using System.Text.RegularExpressions;
\r
25 using System.Threading.Tasks;
\r
26 using System.Windows.Forms;
\r
27 using Microsoft.CSharp.RuntimeBinder;
\r
28 using static System.Math;
\r
30 namespace KancolleSniffer
\r
32 public partial class MainForm : Form
\r
34 private readonly Sniffer _sniffer = new Sniffer();
\r
35 private readonly Config _config = new Config();
\r
36 private readonly ConfigDialog _configDialog;
\r
37 private readonly ProxyManager _proxyManager;
\r
38 private int _currentFleet;
\r
39 private bool _combinedFleet;
\r
40 private readonly Label[] _labelCheckFleets;
\r
41 private readonly ShipLabels _shipLabels;
\r
42 private readonly ListForm _listForm;
\r
43 private readonly NotificationManager _notificationManager;
\r
44 private bool _started;
\r
45 private string _debugLogFile;
\r
46 private IEnumerator<string> _playLog;
\r
48 private readonly ErrorDialog _errorDialog = new ErrorDialog();
\r
49 private bool _missionFinishTimeMode;
\r
50 private bool _ndockFinishTimeMode;
\r
51 private readonly KancolleDb _kancolleDb = new KancolleDb();
\r
55 InitializeComponent();
\r
56 HttpProxy.AfterSessionComplete += HttpProxy_AfterSessionComplete;
\r
57 _configDialog = new ConfigDialog(_config, this);
\r
58 _labelCheckFleets = new[] {labelCheckFleet1, labelCheckFleet2, labelCheckFleet3, labelCheckFleet4};
\r
60 // この時点でAutoScaleDimensions == CurrentAutoScaleDimensionsなので、
\r
61 // MainForm.Designer.csのAutoScaleDimensionsの6f,12fを使う。
\r
62 ShipLabel.ScaleFactor = new SizeF(CurrentAutoScaleDimensions.Width / 6f,
\r
63 CurrentAutoScaleDimensions.Height / 12f);
\r
66 _shipLabels = new ShipLabels();
\r
67 _shipLabels.CreateAkashiTimers(panelShipInfo);
\r
68 _shipLabels.CreateShipLabels(panelShipInfo, ShowShipOnShipList);
\r
69 _shipLabels.CreateCombinedShipLabels(panelCombinedFleet, ShowShipOnShipList);
\r
70 _shipLabels.CreateNDockLabels(panelDock, labelNDock_Click);
\r
71 panelRepairList.CreateLabels(panelRepairList_Click);
\r
72 labelPresetAkashiTimer.BackColor = ShipLabels.ColumnColors[1];
\r
73 _listForm = new ListForm(_sniffer, _config) {Owner = this};
\r
74 _notificationManager = new NotificationManager(Ring);
\r
76 _proxyManager = new ProxyManager(_config, this);
\r
78 _shipLabels.AdjustAkashiTimers();
\r
79 _sniffer.LoadState();
\r
82 private void HttpProxy_AfterSessionComplete(HttpProxy.Session session)
\r
84 Invoke(new Action<HttpProxy.Session>(ProcessRequest), session);
\r
87 private void ProcessRequest(HttpProxy.Session session)
\r
89 var url = session.Request.PathAndQuery;
\r
90 if (!url.Contains("kcsapi/"))
\r
92 var request = session.Request.BodyAsString;
\r
93 var response = session.Response.BodyAsString;
\r
94 if (response == null || !response.StartsWith("svdata="))
\r
96 WriteDebugLog(url, request, response);
\r
99 if (_config.KancolleDb.On)
\r
100 _kancolleDb.Send(url, request, response);
\r
101 response = UnescapeString(response.Remove(0, "svdata=".Length));
\r
102 WriteDebugLog(url, request, response);
\r
103 ProcessRequestMain(url, request, response);
\r
106 private readonly List<string[]> _battleApiLog = new List<string[]>();
\r
108 private void ProcessRequestMain(string url, string request, string response)
\r
112 UpdateInfo(_sniffer.Sniff(url, request, JsonParser.Parse(response)));
\r
113 CheckBattleResult();
\r
114 SaveBattleApi(url, request, response);
\r
116 catch (RuntimeBinderException e)
\r
118 if (_errorDialog.ShowDialog(this,
\r
119 "艦これに仕様変更があったか、受信内容が壊れています。",
\r
120 GenerateErrorLog(url, request, response, e.ToString())) == DialogResult.Abort)
\r
121 Application.Exit();
\r
123 catch (LogIOException e)
\r
125 // ReSharper disable once PossibleNullReferenceException
\r
126 if (_errorDialog.ShowDialog(this, e.Message, e.InnerException.ToString()) == DialogResult.Abort)
\r
127 Application.Exit();
\r
129 catch (Exception e)
\r
131 if (_errorDialog.ShowDialog(this, "エラーが発生しました。",
\r
132 GenerateErrorLog(url, request, response, e.ToString())) == DialogResult.Abort)
\r
133 Application.Exit();
\r
137 private void CheckBattleResult()
\r
139 if (_sniffer.WrongBattleResult.Count > 0)
\r
141 if (_errorDialog.ShowDialog(this,
\r
142 "戦闘結果の計算に誤りがあります。",
\r
143 GenerateBattleErrorLog()) == DialogResult.Abort)
\r
144 Application.Exit();
\r
145 _sniffer.WrongBattleResult.Clear();
\r
149 private void SaveBattleApi(string url, string request, string response)
\r
151 if (_sniffer.Battle.BattleState != BattleState.None)
\r
153 _battleApiLog.Add(new[] {url, request, response});
\r
156 _battleApiLog.Clear();
\r
159 private string GenerateBattleErrorLog()
\r
161 foreach (var logs in _battleApiLog)
\r
162 RemoveSensitiveInformation(ref logs[1], ref logs[2]);
\r
163 var version = string.Join(".", Application.ProductVersion.Split('.').Take(2));
\r
164 var api = string.Join("\r\n", _battleApiLog.Select(logs => string.Join("\r\n", logs)));
\r
165 var status = string.Join(" ",
\r
166 from pair in _sniffer.WrongBattleResult
\r
167 let assumed = pair.Assumed
\r
168 let actual = pair.Actual
\r
169 select $"[{assumed.Fleet}-{assumed.DeckIndex}] {assumed.Id}: {assumed.NowHp}->{actual.NowHp}");
\r
170 return $"{DateTime.Now:g} {version}\r\n{api}\r\n{status}";
\r
173 private string GenerateErrorLog(string url, string request, string response, string exception)
\r
175 RemoveSensitiveInformation(ref request, ref response);
\r
176 var version = string.Join(".", Application.ProductVersion.Split('.').Take(2));
\r
177 return $"{DateTime.Now:g} {version}\r\n{exception}\r\n{url}\r\n{request}\r\n{response}\r\n";
\r
180 private void RemoveSensitiveInformation(ref string request, ref string response)
\r
182 var token = new Regex("&api%5Ftoken=[^&]*|api%5Ftoken=[^&]*&?");
\r
183 request = token.Replace(request, "");
\r
184 var id = new Regex(@"""api_member_id"":\d+,?|""api_nickname"":[^,]+,""api_nickname_id"":""d+"",?");
\r
185 response = id.Replace(response, "");
\r
188 private void WriteDebugLog(string url, string request, string response)
\r
190 if (_debugLogFile != null)
\r
192 File.AppendAllText(_debugLogFile,
\r
193 $"date: {DateTime.Now:g}\nurl: {url}\nrequest: {request}\nresponse: {response ?? "(null)"}\n");
\r
198 private string UnescapeString(string s)
\r
202 var rx = new Regex(@"\\[uU]([0-9A-Fa-f]{4})");
\r
203 return rx.Replace(s,
\r
204 match => ((char)int.Parse(match.Value.Substring(2), NumberStyles.HexNumber)).ToString());
\r
206 catch (ArgumentException)
\r
212 private void UpdateInfo(Sniffer.Update update)
\r
214 if (update == Sniffer.Update.Start)
\r
216 labelLogin.Visible = false;
\r
217 labelGuide.Visible = false;
\r
223 if ((update & Sniffer.Update.Item) != 0)
\r
225 if ((update & Sniffer.Update.Timer) != 0)
\r
227 if ((update & Sniffer.Update.NDock) != 0)
\r
228 UpdateNDocLabels();
\r
229 if ((update & Sniffer.Update.Mission) != 0)
\r
230 UpdateMissionLabels();
\r
231 if ((update & Sniffer.Update.QuestList) != 0)
\r
233 if ((update & Sniffer.Update.Ship) != 0)
\r
235 if ((update & Sniffer.Update.Battle) != 0)
\r
236 UpdateBattleInfo();
\r
239 private void MainForm_Load(object sender, EventArgs e)
\r
242 if (_config.HideOnMinimized && WindowState == FormWindowState.Minimized)
\r
243 ShowInTaskbar = false;
\r
245 ApplyDebugLogSetting();
\r
247 ApplyProxySetting();
\r
248 if (_config.KancolleDb.On)
\r
249 _kancolleDb.Start(_config.KancolleDb.Token);
\r
252 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
\r
254 if (!_config.ExitSilently)
\r
256 using (var dialog = new ConfirmDialog())
\r
258 if (dialog.ShowDialog(this) != DialogResult.Yes)
\r
266 _sniffer.FlashLog();
\r
267 _config.Location = (WindowState == FormWindowState.Normal ? Bounds : RestoreBounds).Location;
\r
269 _proxyManager.Shutdown();
\r
270 _kancolleDb.Stop();
\r
273 private void MainForm_Resize(object sender, EventArgs e)
\r
275 ShowInTaskbar = !(_config.HideOnMinimized && WindowState == FormWindowState.Minimized);
\r
278 private void notifyIconMain_MouseDoubleClick(object sender, MouseEventArgs e)
\r
280 NotifyIconOpenToolStripMenuItem_Click(sender, e);
\r
283 private void NotifyIconOpenToolStripMenuItem_Click(object sender, EventArgs e)
\r
285 ShowInTaskbar = true;
\r
286 WindowState = FormWindowState.Normal;
\r
287 TopMost = _config.TopMost; // 最前面に表示されなくなることがあるのを回避する
\r
291 private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
\r
296 private void ConfigToolStripMenuItem_Click(object sender, EventArgs e)
\r
298 if (_configDialog.ShowDialog(this) == DialogResult.OK)
\r
302 private void PerformZoom()
\r
304 if (_config.Zoom == 100)
\r
306 var prev = CurrentAutoScaleDimensions;
\r
307 foreach (var control in new Control[] {this, _listForm, labelLogin, labelGuide})
\r
308 control.Font = new Font(control.Font.FontFamily, control.Font.Size * _config.Zoom / 100);
\r
309 ShipLabel.LatinFont = new Font("Tahoma", 8f * _config.Zoom / 100);
\r
310 var cur = CurrentAutoScaleDimensions;
\r
311 ShipLabel.ScaleFactor = new SizeF(ShipLabel.ScaleFactor.Width * cur.Width / prev.Width,
\r
312 ShipLabel.ScaleFactor.Height * cur.Height / prev.Height);
\r
315 private void RestoreLocation()
\r
317 if (_config.Location.X == int.MinValue)
\r
319 if (IsTitleBarOnAnyScreen(_config.Location))
\r
320 Location = _config.Location;
\r
323 private void ApplyConfig()
\r
325 _listForm.TopMost = TopMost = _config.TopMost;
\r
326 _sniffer.Item.MarginShips = _config.MarginShips;
\r
327 _sniffer.Item.MarginEquips = _config.MarginEquips;
\r
328 _sniffer.Achievement.ResetHours = _config.ResetHours;
\r
329 labelAkashiRepair.Visible = labelAkashiRepairTimer.Visible =
\r
330 labelPresetAkashiTimer.Visible = _config.UsePresetAkashi;
\r
331 if (_config.KancolleDb.On)
\r
332 _kancolleDb.Start(_config.KancolleDb.Token);
\r
335 public void ApplyDebugLogSetting()
\r
337 _debugLogFile = _config.DebugLogging ? _config.DebugLogFile : null;
\r
340 public bool ApplyProxySetting()
\r
342 return _proxyManager.ApplyConfig();
\r
345 public void ApplyLogSetting()
\r
347 LogServer.OutputDir = _config.Log.OutputDir;
\r
348 LogServer.MaterialHistory = _sniffer.Material.MaterialHistory;
\r
349 _sniffer.EnableLog(_config.Log.On ? LogType.All : LogType.None);
\r
350 _sniffer.MaterialLogInterval = _config.Log.MaterialLogInterval;
\r
351 _sniffer.LogOutputDir = _config.Log.OutputDir;
\r
354 public static bool IsTitleBarOnAnyScreen(Point location)
\r
356 var rect = new Rectangle(
\r
357 new Point(location.X + SystemInformation.IconSize.Width + SystemInformation.HorizontalFocusThickness,
\r
358 location.Y + SystemInformation.CaptionHeight) , new Size(60, 1));
\r
359 return Screen.AllScreens.Any(screen => screen.WorkingArea.Contains(rect));
\r
362 private void timerMain_Tick(object sender, EventArgs e)
\r
370 catch (Exception ex)
\r
372 if (_errorDialog.ShowDialog(this, "エラーが発生しました。", ex.ToString()) == DialogResult.Abort)
\r
373 Application.Exit();
\r
376 if (_playLog == null || _configDialog.Visible)
\r
378 labelPlayLog.Visible = false;
\r
384 public void SetPlayLog(string file)
\r
386 _playLog = File.ReadLines(file).GetEnumerator();
\r
389 private void PlayLog()
\r
391 var lines = new List<string>();
\r
392 foreach (var s in new[] {"url: ", "request: ", "response: "})
\r
396 if (!_playLog.MoveNext() || _playLog.Current == null)
\r
398 labelPlayLog.Visible = false;
\r
401 } while (!_playLog.Current.StartsWith(s));
\r
402 lines.Add(_playLog.Current.Substring(s.Length));
\r
404 labelPlayLog.Visible = !labelPlayLog.Visible;
\r
405 ProcessRequestMain(lines[0], lines[1], lines[2]);
\r
408 private void ShowShipOnShipList(object sender, EventArgs ev)
\r
410 if (!_listForm.Visible)
\r
412 var idx = (int)((Control)sender).Tag;
\r
413 var statuses = _sniffer.GetShipStatuses(_currentFleet);
\r
414 if (statuses.Length <= idx)
\r
416 _listForm.ShowShip(statuses[idx].Id);
\r
419 private void UpdateItemInfo()
\r
421 UpdateNumOfShips();
\r
422 UpdateNumOfEquips();
\r
423 labelNumOfBuckets.Text = _sniffer.Material.MaterialHistory[(int)Material.Bucket].Now.ToString("D");
\r
424 UpdateBucketHistory();
\r
425 var ac = _sniffer.Achievement.Value;
\r
428 labelAchievement.Text = ac >= 1000 ? ((int)ac).ToString("D") : ac.ToString("F1");
\r
429 toolTipAchievement.SetToolTip(labelAchievement,
\r
430 "今月 " + _sniffer.Achievement.ValueOfMonth.ToString("F1") + "\n" +
\r
431 "EO " + _sniffer.ExMap.Achievement);
\r
432 UpdateMaterialHistry();
\r
433 if (_listForm.Visible)
\r
434 _listForm.UpdateList();
\r
437 private void UpdateNumOfShips()
\r
439 var item = _sniffer.Item;
\r
440 labelNumOfShips.Text = $"{item.NowShips:D}/{item.MaxShips:D}";
\r
441 labelNumOfShips.ForeColor = item.TooManyShips ? CUDColor.Red : Color.Black;
\r
442 if (item.RingShips)
\r
444 var message = $"残り{_sniffer.Item.MaxShips - _sniffer.Item.NowShips:D}隻";
\r
445 _notificationManager.Enqueue("艦娘数超過", message);
\r
446 item.RingShips = false;
\r
450 private void UpdateNumOfEquips()
\r
452 var item = _sniffer.Item;
\r
453 labelNumOfEquips.Text = $"{item.NowEquips:D}/{item.MaxEquips:D}";
\r
454 labelNumOfEquips.ForeColor = item.TooManyEquips ? CUDColor.Red : Color.Black;
\r
455 if (item.RingEquips)
\r
457 var message = $"残り{_sniffer.Item.MaxEquips - _sniffer.Item.NowEquips:D}個";
\r
458 _notificationManager.Enqueue("装備数超過", message);
\r
459 item.RingEquips = false;
\r
463 private void UpdateBucketHistory()
\r
465 var count = _sniffer.Material.MaterialHistory[(int)Material.Bucket];
\r
466 var day = CutOverflow(count.Now - count.BegOfDay, 999);
\r
467 var week = CutOverflow(count.Now - count.BegOfWeek, 999);
\r
468 labelBucketHistory.Text = $"{day:+#;-#;±0} 今日\n{week:+#;-#;±0} 今週";
\r
471 private void UpdateMaterialHistry()
\r
473 var labels = new[] {labelFuelHistory, labelBulletHistory, labelSteelHistory, labelBouxiteHistory};
\r
474 var text = new[] {"燃料", "弾薬", "鋼材", "ボーキ"};
\r
475 for (var i = 0; i < labels.Length; i++)
\r
477 var count = _sniffer.Material.MaterialHistory[i];
\r
478 var port = CutOverflow(count.Now - _sniffer.Material.PrevPort[i], 99999);
\r
479 var day = CutOverflow(count.Now - count.BegOfDay, 99999);
\r
480 var week = CutOverflow(count.Now - count.BegOfWeek, 99999);
\r
481 labels[i].Text = $"{text[i]}\n{port:+#;-#;±0}\n{day:+#;-#;±0}\n{week:+#;-#;±0}";
\r
485 private int CutOverflow(int value, int limit)
\r
489 if (value < -limit)
\r
494 private void UpdateShipInfo()
\r
496 UpdatePanelShipInfo();
\r
497 NotifyDamagedShip();
\r
498 UpdateChargeInfo();
\r
499 UpdateRepairList();
\r
500 if (_listForm.Visible)
\r
501 _listForm.UpdateList();
\r
504 private void UpdatePanelShipInfo()
\r
506 var statuses = _sniffer.GetShipStatuses(_currentFleet);
\r
507 _shipLabels.SetShipLabels(statuses);
\r
508 if (_sniffer.CombinedFleetType == 0)
\r
509 _combinedFleet = false;
\r
510 labelFleet1.Text = _combinedFleet ? "連合" : "第一";
\r
511 panelCombinedFleet.Visible = _combinedFleet;
\r
512 if (_combinedFleet)
\r
513 _shipLabels.SetCombinedShipLabels(_sniffer.GetShipStatuses(0), _sniffer.GetShipStatuses(1));
\r
514 UpdateAkashiTimer();
\r
515 UpdateFighterPower(_combinedFleet);
\r
517 UpdateCondTimers();
\r
520 private void NotifyDamagedShip()
\r
522 if (_sniffer.BadlyDamagedShips.Any())
\r
523 _notificationManager.Enqueue("大破警告", string.Join(" ", _sniffer.BadlyDamagedShips));
\r
526 private void NotifyAkashiTimer()
\r
528 var akashi = _sniffer.AkashiTimer;
\r
529 var msgs = akashi.GetNotice();
\r
530 if (msgs.Length == 0)
\r
532 if (!akashi.CheckReparing() && !(akashi.CheckPresetReparing() && _config.UsePresetAkashi))
\r
534 if (msgs[0].Proceeded == "20分経過しました。")
\r
536 _notificationManager.Enqueue("泊地修理20分経過", msgs[0].Proceeded);
\r
537 msgs[0].Proceeded = "";
\r
538 // 修理完了がいるかもしれないので続ける
\r
540 for (var i = 0; i < ShipInfo.FleetCount; i++)
\r
542 if (msgs[i].Proceeded != "")
\r
543 _notificationManager.Enqueue("泊地修理進行", i, msgs[i].Proceeded);
\r
544 if (msgs[i].Completed != "")
\r
545 _notificationManager.Enqueue("泊地修理完了", i, msgs[i].Completed);
\r
549 public void UpdateFighterPower(bool combined)
\r
552 ? _sniffer.GetFighterPower(0).Zip(_sniffer.GetFighterPower(1), (a, b) => a + b).ToArray()
\r
553 : _sniffer.GetFighterPower(_currentFleet);
\r
554 labelFighterPower.Text = fp[0].ToString("D");
\r
556 ? _sniffer.GetContactTriggerRate(0) + _sniffer.GetContactTriggerRate(1)
\r
557 : _sniffer.GetContactTriggerRate(_currentFleet);
\r
558 var text = "制空: " + (fp[0] == fp[1] ? $"{fp[0]}" : $"{fp[0]}~{fp[1]}") +
\r
559 $" 触接: {cr * 100:f1}";
\r
560 toolTipFighterPower.SetToolTip(labelFighterPower, text);
\r
561 toolTipFighterPower.SetToolTip(labelFighterPowerCaption, text);
\r
564 private void UpdateLoS()
\r
566 labelLoS.Text = RoundDown(_sniffer.GetFleetLineOfSights(_currentFleet, 1)).ToString("F1");
\r
567 var text = $"係数3: {RoundDown(_sniffer.GetFleetLineOfSights(_currentFleet, 3)):F1}\r\n" +
\r
568 $"係数4: {RoundDown(_sniffer.GetFleetLineOfSights(_currentFleet, 4)):F1}";
\r
569 toolTipLoS.SetToolTip(labelLoS, text);
\r
570 toolTipLoS.SetToolTip(labelLoSCaption, text);
\r
573 private double RoundDown(double number)
\r
575 return Floor(number * 10) / 10.0;
\r
578 private void UpdateBattleInfo()
\r
581 if (_sniffer.Battle.BattleState == BattleState.None)
\r
583 panelBattleInfo.BringToFront();
\r
584 var battle = _sniffer.Battle;
\r
585 labelFormation.Text = battle.Formation;
\r
586 UpdateBattleFighterPower();
\r
587 if (_config.AlwaysShowResultRank)
\r
589 if (_sniffer.Battle.BattleState == BattleState.Day)
\r
590 _listForm.UpdateAirBattleResult();
\r
593 private void ResetBattleInfo()
\r
595 labelFormation.Text = "";
\r
596 labelEnemyFighterPower.Text = "";
\r
597 labelFighterPower.ForeColor = DefaultForeColor;
\r
598 labelResultRank.Text = "判定";
\r
599 panelBattleInfo.Visible = _sniffer.Battle.BattleState != BattleState.None;
\r
602 private void UpdateBattleFighterPower()
\r
604 var battle = _sniffer.Battle;
\r
605 var power = battle.EnemyFighterPower;
\r
606 labelEnemyFighterPower.Text = power.AirCombat + power.UnknownMark;
\r
607 if (power.AirCombat != power.Interception)
\r
609 var text = "防空: " + power.Interception + power.UnknownMark;
\r
610 toolTipFighterPower.SetToolTip(labelEnemyFighterPower, text);
\r
611 toolTipFighterPower.SetToolTip(labelEnemyFighterPowerCaption, text);
\r
613 UpdateFighterPower(_sniffer.CombinedFleetType > 0 && battle.EnemyIsCombined);
\r
614 labelFighterPower.ForeColor = new[]
\r
615 {DefaultForeColor, DefaultForeColor, CUDColor.Blue, CUDColor.Green, CUDColor.Orange, CUDColor.Red}[
\r
616 battle.AirControlLevel + 1];
\r
619 private void ShowResultRank()
\r
621 var result = new[] {"完全S", "勝利S", "勝利A", "勝利B", "敗北C", "敗北D", "敗北E"};
\r
622 labelResultRank.Text = result[(int)_sniffer.Battle.ResultRank];
\r
625 private void labelResultRank_Click(object sender, EventArgs e)
\r
630 private void UpdateChargeInfo()
\r
632 var fuelSq = new[] {labelFuelSq1, labelFuelSq2, labelFuelSq3, labelFuelSq4};
\r
633 var bullSq = new[] {labelBullSq1, labelBullSq2, labelBullSq3, labelBullSq4};
\r
635 for (var i = 0; i < fuelSq.Length; i++)
\r
637 var stat = _sniffer.ChargeStatuses[i];
\r
638 fuelSq[i].ImageIndex = stat.Fuel;
\r
639 bullSq[i].ImageIndex = stat.Bull;
\r
643 private void UpdateNDocLabels()
\r
645 _shipLabels.SetNDockLabels(_sniffer.NDock);
\r
649 private void labelNDock_Click(object sender, EventArgs e)
\r
651 _ndockFinishTimeMode = !_ndockFinishTimeMode;
\r
655 private void UpdateMissionLabels()
\r
657 foreach (var entry in
\r
658 new[] {labelMissionName1, labelMissionName2, labelMissionName3}.Zip(_sniffer.Missions,
\r
659 (label, mission) => new {label, mission.Name}))
\r
660 entry.label.Text = entry.Name;
\r
663 private void labelMission_Click(object sender, EventArgs e)
\r
665 _missionFinishTimeMode = !_missionFinishTimeMode;
\r
669 private void UpdateTimers()
\r
671 foreach (var entry in
\r
672 new[] {labelMission1, labelMission2, labelMission3}.Zip(_sniffer.Missions,
\r
673 (label, mission) => new {label, mission.Name, mission.Timer}))
\r
675 entry.Timer.Update();
\r
676 SetTimerColor(entry.label, entry.Timer);
\r
677 entry.label.Text = entry.Timer.ToString(_missionFinishTimeMode);
\r
678 if (!entry.Timer.NeedRing)
\r
680 _notificationManager.Enqueue("遠征終了", entry.Name);
\r
681 entry.Timer.NeedRing = false;
\r
683 for (var i = 0; i < _sniffer.NDock.Length; i++)
\r
685 var entry = _sniffer.NDock[i];
\r
686 entry.Timer.Update();
\r
687 _shipLabels.SetNDockTimer(i, entry.Timer, _ndockFinishTimeMode);
\r
688 if (!entry.Timer.NeedRing)
\r
690 _notificationManager.Enqueue("入渠終了", entry.Name);
\r
691 entry.Timer.NeedRing = false;
\r
693 var kdock = new[] {labelConstruct1, labelConstruct2, labelConstruct3, labelConstruct4};
\r
694 for (var i = 0; i < kdock.Length; i++)
\r
696 var timer = _sniffer.KDock[i];
\r
698 SetTimerColor(kdock[i], timer);
\r
700 kdock[i].Text = timer.EndTime == DateTime.MinValue ? "" : timer.Rest.ToString(@"hh\:mm\:ss");
\r
701 if (!timer.NeedRing)
\r
703 _notificationManager.Enqueue("建造完了", $"第{i + 1:D}ドック");
\r
704 timer.NeedRing = false;
\r
706 UpdateCondTimers();
\r
707 UpdateAkashiTimer();
\r
710 private void SetTimerColor(Label label, RingTimer timer)
\r
712 label.ForeColor = timer.IsFinished ? CUDColor.Red : Color.Black;
\r
715 private void UpdateCondTimers()
\r
718 if (_combinedFleet)
\r
720 var timer1 = _sniffer.GetConditionTimer(0);
\r
721 var timer2 = _sniffer.GetConditionTimer(1);
\r
722 timer = timer2 > timer1 ? timer2 : timer1;
\r
726 timer = _sniffer.GetConditionTimer(_currentFleet);
\r
728 var now = DateTime.Now;
\r
729 if (timer == DateTime.MinValue)
\r
731 labelCondTimerTitle.Text = "";
\r
732 labelCondTimer.Text = "";
\r
735 var span = TimeSpan.FromSeconds(Ceiling((timer - now).TotalSeconds));
\r
736 if (span >= TimeSpan.FromMinutes(9))
\r
738 labelCondTimerTitle.Text = "cond40まで";
\r
739 labelCondTimer.Text = (span - TimeSpan.FromMinutes(9)).ToString(@"mm\:ss");
\r
740 labelCondTimer.ForeColor = DefaultForeColor;
\r
744 labelCondTimerTitle.Text = "cond49まで";
\r
745 labelCondTimer.Text = (span >= TimeSpan.Zero ? span : TimeSpan.Zero).ToString(@"mm\:ss");
\r
746 labelCondTimer.ForeColor = span <= TimeSpan.Zero ? CUDColor.Red : DefaultForeColor;
\r
748 var notice = _sniffer.GetConditionNotice();
\r
749 if (notice == null)
\r
751 for (var i = 0; i < ShipInfo.FleetCount; i++)
\r
753 if (!_config.NotifyConditions.Contains(notice[i]))
\r
755 _notificationManager.Enqueue("疲労回復" + notice[i], i, "cond" + notice[i]);
\r
759 private void UpdateAkashiTimer()
\r
761 if (_config.UsePresetAkashi)
\r
762 UpdatePresetAkashiTimer();
\r
763 _shipLabels.SetAkashiTimer(_sniffer.GetShipStatuses(_currentFleet),
\r
764 _sniffer.AkashiTimer.GetTimers(_currentFleet));
\r
765 NotifyAkashiTimer();
\r
768 private void UpdatePresetAkashiTimer()
\r
770 var akashi = _sniffer.AkashiTimer;
\r
771 var span = akashi.PresetDeckTimer;
\r
772 var color = span == TimeSpan.Zero && akashi.CheckPresetReparing() ? CUDColor.Red : DefaultForeColor;
\r
773 var text = span == TimeSpan.MinValue ? "" : span.ToString(@"mm\:ss");
\r
774 labelAkashiRepairTimer.ForeColor = color;
\r
775 labelAkashiRepairTimer.Text = text;
\r
776 if (akashi.CheckPresetReparing() && !akashi.CheckReparing(_currentFleet))
\r
778 labelPresetAkashiTimer.ForeColor = color;
\r
779 labelPresetAkashiTimer.Text = text;
\r
783 labelPresetAkashiTimer.ForeColor = DefaultForeColor;
\r
784 labelPresetAkashiTimer.Text = "";
\r
788 private void UpdateRepairList()
\r
790 panelRepairList.SetRepairList(_sniffer.RepairList);
\r
793 private void UpdateQuestList()
\r
795 var category = new[]
\r
797 labelQuestColor1, labelQuestColor2, labelQuestColor3, labelQuestColor4, labelQuestColor5,
\r
800 var name = new[] {labelQuest1, labelQuest2, labelQuest3, labelQuest4, labelQuest5, labelQuest6};
\r
801 var progress = new[]
\r
802 {labelProgress1, labelProgress2, labelProgress3, labelProgress4, labelProgress5, labelProgress6};
\r
803 var quests = _sniffer.Quests;
\r
804 for (var i = 0; i < name.Length; i++)
\r
806 if (i < quests.Length)
\r
808 category[i].BackColor = quests[i].Color;
\r
809 name[i].Text = quests[i].Name;
\r
810 progress[i].Text = $"{quests[i].Progress:D}%";
\r
814 category[i].BackColor = DefaultBackColor;
\r
815 name[i].Text = progress[i].Text = "";
\r
820 private void Ring(string balloonTitle, string balloonMessage, string name)
\r
822 if (_config.FlashWindow && (_config.Notifications[name] & NotificationType.FlashWindow) != 0)
\r
823 Win32API.FlashWindow(Handle);
\r
824 if (_config.ShowBaloonTip && (_config.Notifications[name] & NotificationType.ShowBaloonTip) != 0)
\r
825 notifyIconMain.ShowBalloonTip(20000, balloonTitle, balloonMessage, ToolTipIcon.Info);
\r
826 if (_config.PlaySound && (_config.Notifications[name] & NotificationType.PlaySound) != 0)
\r
827 PlaySound(_config.Sounds[name], _config.Sounds.Volume);
\r
828 if (_config.Pushbullet.On && (_config.Notifications[name] & NotificationType.Pushbullet) != 0)
\r
832 PushBullet.PushNote(_config.Pushbullet.Token, balloonTitle, balloonMessage);
\r
837 [DllImport("winmm.dll")]
\r
838 private static extern int mciSendString(String command,
\r
839 StringBuilder buffer, int bufferSize, IntPtr hwndCallback);
\r
841 // ReSharper disable InconsistentNaming
\r
842 private const int MM_MCINOTIFY = 0x3B9;
\r
844 private const int MCI_NOTIFY_SUCCESSFUL = 1;
\r
845 // ReSharper restore InconsistentNaming
\r
847 public void PlaySound(string file, int volume)
\r
849 if (!File.Exists(file))
\r
851 mciSendString("close sound", null, 0, IntPtr.Zero);
\r
852 if (mciSendString("open \"" + file + "\" type mpegvideo alias sound", null, 0, IntPtr.Zero) != 0)
\r
854 mciSendString("setaudio sound volume to " + volume * 10, null, 0, IntPtr.Zero);
\r
855 mciSendString("play sound notify", null, 0, Handle);
\r
858 protected override void WndProc(ref Message m)
\r
860 if (m.Msg == MM_MCINOTIFY && (int)m.WParam == MCI_NOTIFY_SUCCESSFUL)
\r
861 mciSendString("close sound", null, 0, IntPtr.Zero);
\r
862 base.WndProc(ref m);
\r
865 private void SetupFleetClick()
\r
869 new[] {labelFleet1, labelFleet2, labelFleet3, labelFleet4},
\r
870 new[] {labelFuelSq1, labelFuelSq2, labelFuelSq3, labelFuelSq4},
\r
871 new[] {labelBullSq1, labelBullSq2, labelBullSq3, labelBullSq4}
\r
873 foreach (var a in labels)
\r
875 for (var fleet = 0; fleet < labels[0].Length; fleet++)
\r
877 a[fleet].Tag = fleet;
\r
878 a[fleet].Click += labelFleet_Click;
\r
883 private void labelFleet_Click(object sender, EventArgs e)
\r
887 var fleet = (int)((Label)sender).Tag;
\r
888 if (_currentFleet == fleet)
\r
892 _combinedFleet = _sniffer.CombinedFleetType > 0 && !_combinedFleet;
\r
893 UpdatePanelShipInfo();
\r
896 _combinedFleet = false;
\r
897 _currentFleet = fleet;
\r
898 foreach (var label in _labelCheckFleets)
\r
899 label.Visible = false;
\r
900 _labelCheckFleets[fleet].Visible = true;
\r
901 UpdatePanelShipInfo();
\r
904 private void labelFleet1_MouseHover(object sender, EventArgs e)
\r
906 labelFleet1.Text = _currentFleet == 0 && _sniffer.CombinedFleetType > 0 && !_combinedFleet ? "連合" : "第一";
\r
909 private void labelFleet1_MouseLeave(object sender, EventArgs e)
\r
911 labelFleet1.Text = _combinedFleet ? "連合" : "第一";
\r
914 private void labelBucketHistoryButton_Click(object sender, EventArgs e)
\r
916 if (labelBucketHistory.Visible)
\r
918 labelBucketHistory.Visible = false;
\r
919 labelBucketHistoryButton.BackColor = DefaultBackColor;
\r
923 labelBucketHistory.Visible = true;
\r
924 labelBucketHistory.BringToFront();
\r
925 labelBucketHistoryButton.BackColor = SystemColors.ActiveCaption;
\r
929 private void labelBucketHistory_Click(object sender, EventArgs e)
\r
931 labelBucketHistory.Visible = false;
\r
932 labelBucketHistoryButton.BackColor = DefaultBackColor;
\r
935 private void labelMaterialHistoryButton_Click(object sender, EventArgs e)
\r
937 if (panelMaterialHistory.Visible)
\r
939 panelMaterialHistory.Visible = false;
\r
940 labelMaterialHistoryButton.BackColor = DefaultBackColor;
\r
944 panelMaterialHistory.Visible = true;
\r
945 panelMaterialHistory.BringToFront();
\r
946 labelMaterialHistoryButton.BackColor = SystemColors.ActiveCaption;
\r
950 private void panelMaterialHistory_Click(object sender, EventArgs e)
\r
952 panelMaterialHistory.Visible = false;
\r
953 labelMaterialHistoryButton.BackColor = DefaultBackColor;
\r
956 public void ResetAchievemnt()
\r
958 _sniffer.Achievement.Reset();
\r
962 private void labelRepairListButton_Click(object sender, EventArgs e)
\r
964 if (panelRepairList.Visible)
\r
966 panelRepairList.Visible = false;
\r
967 labelRepairListButton.BackColor = DefaultBackColor;
\r
971 panelRepairList.Visible = true;
\r
972 panelRepairList.BringToFront();
\r
973 labelRepairListButton.BackColor = SystemColors.ActiveCaption;
\r
977 private void panelRepairList_Click(object sender, EventArgs e)
\r
979 panelRepairList.Visible = false;
\r
980 labelRepairListButton.BackColor = DefaultBackColor;
\r
983 private void ShipListToolStripMenuItem_Click(object sender, EventArgs e)
\r
985 _listForm.UpdateList();
\r
987 if (_listForm.WindowState == FormWindowState.Minimized)
\r
988 _listForm.WindowState = FormWindowState.Normal;
\r
989 _listForm.Activate();
\r
992 private void LogToolStripMenuItem_Click(object sender, EventArgs e)
\r
994 Process.Start("http://localhost:" + _config.Proxy.Listen + "/");
\r
997 private void CaptureToolStripMenuItem_Click(object sender, EventArgs e)
\r
1001 var proc = new ProcessStartInfo("BurageSnap.exe") {WorkingDirectory = "Capture"};
\r
1002 Process.Start(proc);
\r
1004 catch (FileNotFoundException)
\r