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.Net.Sockets;
\r
23 using System.Runtime.InteropServices;
\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 Microsoft.Win32;
\r
30 using static System.Math;
\r
32 namespace KancolleSniffer
\r
34 public partial class MainForm : Form
\r
36 private readonly Sniffer _sniffer = new Sniffer();
\r
37 private readonly Config _config = new Config();
\r
38 private readonly ConfigDialog _configDialog;
\r
39 private int _currentFleet;
\r
40 private bool _combinedFleet;
\r
41 private readonly Label[] _labelCheckFleets;
\r
42 private readonly ShipLabels _shipLabels;
\r
43 private readonly ListForm _listForm;
\r
44 private readonly NotificationManager _notificationManager;
\r
45 private bool _started;
\r
46 private string _debugLogFile;
\r
47 private IEnumerator<string> _playLog;
\r
48 private int _prevProxyPort;
\r
49 private readonly SystemProxy _systemProxy = new SystemProxy();
\r
50 private readonly ErrorDialog _errorDialog = new ErrorDialog();
\r
51 private bool _missionFinishTimeMode;
\r
52 private bool _ndockFinishTimeMode;
\r
53 private readonly KancolleDb _kancolleDb = new KancolleDb();
\r
57 InitializeComponent();
\r
58 HttpProxy.AfterSessionComplete += HttpProxy_AfterSessionComplete;
\r
59 _configDialog = new ConfigDialog(_config, this);
\r
60 _labelCheckFleets = new[] {labelCheckFleet1, labelCheckFleet2, labelCheckFleet3, labelCheckFleet4};
\r
62 // この時点でAutoScaleDimensions == CurrentAutoScaleDimensionsなので、
\r
63 // MainForm.Designer.csのAutoScaleDimensionsの6f,12fを使う。
\r
64 ShipLabel.ScaleFactor = new SizeF(CurrentAutoScaleDimensions.Width / 6f,
\r
65 CurrentAutoScaleDimensions.Height / 12f);
\r
68 _shipLabels = new ShipLabels();
\r
69 _shipLabels.CreateAkashiTimers(panelShipInfo);
\r
70 _shipLabels.CreateShipLabels(panelShipInfo, ShowShipOnShipList);
\r
71 _shipLabels.CreateCombinedShipLabels(panelCombinedFleet, ShowShipOnShipList);
\r
72 _shipLabels.CreateNDockLabels(panelDock, labelNDock_Click);
\r
73 panelRepairList.CreateLabels(panelRepairList_Click);
\r
74 labelPresetAkashiTimer.BackColor = ShipLabels.ColumnColors[1];
\r
75 _listForm = new ListForm(_sniffer, _config) {Owner = this};
\r
76 _notificationManager = new NotificationManager(Ring);
\r
79 _shipLabels.AdjustAkashiTimers();
\r
80 _sniffer.LoadState();
\r
83 private void HttpProxy_AfterSessionComplete(HttpProxy.Session session)
\r
85 Invoke(new Action<HttpProxy.Session>(ProcessRequest), session);
\r
88 private void ProcessRequest(HttpProxy.Session session)
\r
90 var url = session.Request.PathAndQuery;
\r
91 if (!url.Contains("kcsapi/"))
\r
93 var request = session.Request.BodyAsString;
\r
94 var response = session.Response.BodyAsString;
\r
95 if (response == null || !response.StartsWith("svdata="))
\r
97 WriteDebugLog(url, request, response);
\r
100 if (_config.KancolleDb.On)
\r
101 _kancolleDb.Send(url, request, response);
\r
102 response = UnescapeString(response.Remove(0, "svdata=".Length));
\r
103 WriteDebugLog(url, request, response);
\r
106 UpdateInfo(_sniffer.Sniff(url, request, JsonParser.Parse(response)));
\r
108 catch (RuntimeBinderException e)
\r
110 if (_errorDialog.ShowDialog(this,
\r
111 "このバージョンは現在の艦これに対応していません。\r\n新しいバージョンを利用してください。", e.ToString()) == DialogResult.Abort)
\r
112 Application.Exit();
\r
114 catch (LogIOException e)
\r
116 // ReSharper disable once PossibleNullReferenceException
\r
117 if (_errorDialog.ShowDialog(this, e.Message, e.InnerException.ToString()) == DialogResult.Abort)
\r
118 Application.Exit();
\r
120 catch (Exception e)
\r
122 if (_errorDialog.ShowDialog(this, "エラーが発生しました。", e.ToString()) == DialogResult.Abort)
\r
123 Application.Exit();
\r
127 private void WriteDebugLog(string url, string request, string response)
\r
129 if (_debugLogFile != null)
\r
131 File.AppendAllText(_debugLogFile,
\r
132 $"url: {url}\nrequest: {request}\nresponse: {response ?? "(null)"}\n");
\r
136 private string UnescapeString(string s)
\r
140 var rx = new Regex(@"\\[uU]([0-9A-Fa-f]{4})");
\r
141 return rx.Replace(s,
\r
142 match => ((char)int.Parse(match.Value.Substring(2), NumberStyles.HexNumber)).ToString());
\r
144 catch (ArgumentException)
\r
150 private void UpdateInfo(Sniffer.Update update)
\r
152 if (update == Sniffer.Update.Start)
\r
154 labelLogin.Visible = false;
\r
155 labelGuide.Visible = false;
\r
161 if ((update & Sniffer.Update.Item) != 0)
\r
163 if ((update & Sniffer.Update.Timer) != 0)
\r
165 if ((update & Sniffer.Update.NDock) != 0)
\r
166 UpdateNDocLabels();
\r
167 if ((update & Sniffer.Update.Mission) != 0)
\r
168 UpdateMissionLabels();
\r
169 if ((update & Sniffer.Update.QuestList) != 0)
\r
171 if ((update & Sniffer.Update.Ship) != 0)
\r
173 if ((update & Sniffer.Update.Battle) != 0)
\r
174 UpdateBattleInfo();
\r
177 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 ApplyProxySetting();
\r
186 SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;
\r
187 if (_config.KancolleDb.On)
\r
188 _kancolleDb.Start(_config.KancolleDb.Token);
\r
191 private void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
\r
193 if (e.Mode != PowerModes.Resume || !_config.Proxy.Auto)
\r
195 SystemProxy.Refresh();
\r
198 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
\r
201 _sniffer.FlashLog();
\r
202 _config.Location = (WindowState == FormWindowState.Normal ? Bounds : RestoreBounds).Location;
\r
204 Task.Run(() => ShutdownProxy());
\r
205 if (_config.Proxy.Auto)
\r
206 _systemProxy.RestoreSettings();
\r
207 SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;
\r
208 _kancolleDb.Stop();
\r
211 private void ShutdownProxy()
\r
213 HttpProxy.Shutdown();
\r
216 private void MainForm_Resize(object sender, EventArgs e)
\r
218 ShowInTaskbar = !(_config.HideOnMinimized && WindowState == FormWindowState.Minimized);
\r
221 private void notifyIconMain_MouseDoubleClick(object sender, MouseEventArgs e)
\r
223 NotifyIconOpenToolStripMenuItem_Click(sender, e);
\r
226 private void NotifyIconOpenToolStripMenuItem_Click(object sender, EventArgs e)
\r
228 ShowInTaskbar = true;
\r
229 WindowState = FormWindowState.Normal;
\r
230 TopMost = _config.TopMost; // 最前面に表示されなくなることがあるのを回避する
\r
234 private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
\r
239 private void ConfigToolStripMenuItem_Click(object sender, EventArgs e)
\r
241 if (_configDialog.ShowDialog(this) == DialogResult.OK)
\r
245 private void PerformZoom()
\r
247 if (_config.Zoom == 100)
\r
249 var prev = CurrentAutoScaleDimensions;
\r
250 foreach (var control in new Control[] {this, _listForm, labelLogin, labelGuide})
\r
251 control.Font = new Font(control.Font.FontFamily, control.Font.Size * _config.Zoom / 100);
\r
252 ShipLabel.LatinFont = new Font("Tahoma", 8f * _config.Zoom / 100);
\r
253 var cur = CurrentAutoScaleDimensions;
\r
254 ShipLabel.ScaleFactor = new SizeF(ShipLabel.ScaleFactor.Width * cur.Width / prev.Width,
\r
255 ShipLabel.ScaleFactor.Height * cur.Height / prev.Height);
\r
258 private void RestoreLocation()
\r
260 if (_config.Location.X == int.MinValue)
\r
262 var newBounds = Bounds;
\r
263 newBounds.Location = _config.Location;
\r
264 if (IsVisibleOnAnyScreen(newBounds))
\r
265 Location = _config.Location;
\r
268 private void ApplyConfig()
\r
270 _listForm.TopMost = TopMost = _config.TopMost;
\r
271 _sniffer.Item.MarginShips = _config.MarginShips;
\r
272 _sniffer.Item.MarginEquips = _config.MarginEquips;
\r
273 _sniffer.Achievement.ResetHours = _config.ResetHours;
\r
274 labelAkashiRepair.Visible = labelAkashiRepairTimer.Visible =
\r
275 labelPresetAkashiTimer.Visible = _config.UsePresetAkashi;
\r
276 if (_config.KancolleDb.On)
\r
277 _kancolleDb.Start(_config.KancolleDb.Token);
\r
280 public void ApplyDebugLogSetting()
\r
282 _debugLogFile = _config.DebugLogging ? _config.DebugLogFile : null;
\r
285 public bool ApplyProxySetting()
\r
287 if (!_config.Proxy.Auto)
\r
288 _systemProxy.RestoreSettings();
\r
289 if (_config.Proxy.UseUpstream)
\r
291 HttpProxy.UpstreamProxyHost = "127.0.0.1";
\r
292 HttpProxy.UpstreamProxyPort = _config.Proxy.UpstreamPort;
\r
294 HttpProxy.IsEnableUpstreamProxy = _config.Proxy.UseUpstream;
\r
296 if (!HttpProxy.IsInListening || _config.Proxy.Listen != _prevProxyPort)
\r
299 result = StartProxy();
\r
301 if (_config.Proxy.Auto && result)
\r
303 _systemProxy.SetAutoProxyUrl($"http://localhost:{_config.Proxy.Listen}/proxy.pac");
\r
305 _prevProxyPort = _config.Proxy.Listen;
\r
309 private bool StartProxy()
\r
313 HttpProxy.Startup(_config.Proxy.Listen, false, false);
\r
315 catch (SocketException e)
\r
317 if (e.SocketErrorCode != SocketError.AddressAlreadyInUse)
\r
319 if (WarnConflictPortNumber("プロキシサーバー", _config.Proxy.Listen, _config.Proxy.Auto) == DialogResult.No ||
\r
320 !_config.Proxy.Auto)
\r
322 _systemProxy.RestoreSettings();
\r
325 HttpProxy.Startup(0, false, false);
\r
326 _config.Proxy.Listen = HttpProxy.LocalPort;
\r
331 private DialogResult WarnConflictPortNumber(string name, int port, bool auto)
\r
333 var msg = $"{name}のポート番号{port}は他のアプリケーションが使用中です。";
\r
334 var cap = "ポート番号の衝突";
\r
336 ? MessageBox.Show(this, msg + "自動的に別の番号を割り当てますか?", cap,
\r
337 MessageBoxButtons.YesNo, MessageBoxIcon.Question)
\r
338 : MessageBox.Show(this, msg + "設定ダイアログでポート番号を変更してください。", cap,
\r
339 MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
\r
342 public void ApplyLogSetting()
\r
344 LogServer.OutputDir = _config.Log.OutputDir;
\r
345 _sniffer.EnableLog(_config.Log.On ? LogType.All : LogType.None);
\r
346 _sniffer.MaterialLogInterval = _config.Log.MaterialLogInterval;
\r
347 _sniffer.LogOutputDir = _config.Log.OutputDir;
\r
350 public static bool IsVisibleOnAnyScreen(Rectangle rect)
\r
352 return Screen.AllScreens.Any(screen => screen.WorkingArea.IntersectsWith(rect));
\r
355 private void timerMain_Tick(object sender, EventArgs e)
\r
363 catch (Exception ex)
\r
365 if (_errorDialog.ShowDialog(this, "エラーが発生しました。", ex.ToString()) == DialogResult.Abort)
\r
366 Application.Exit();
\r
369 if (_playLog == null || _configDialog.Visible)
\r
371 labelPlayLog.Visible = false;
\r
377 public void SetPlayLog(string file)
\r
379 _playLog = File.ReadLines(file).GetEnumerator();
\r
382 private void PlayLog()
\r
384 var lines = new List<string>();
\r
385 foreach (var s in new[] {"url: ", "request: ", "response: "})
\r
387 if (!_playLog.MoveNext() || !_playLog.Current.StartsWith(s))
\r
389 labelPlayLog.Visible = false;
\r
392 lines.Add(_playLog.Current.Substring(s.Length));
\r
394 labelPlayLog.Visible = !labelPlayLog.Visible;
\r
395 var json = JsonParser.Parse(lines[2]);
\r
396 UpdateInfo(_sniffer.Sniff(lines[0], lines[1], json));
\r
399 private void ShowShipOnShipList(object sender, EventArgs ev)
\r
401 if (!_listForm.Visible)
\r
403 var idx = (int)((Control)sender).Tag;
\r
404 var statuses = _sniffer.GetShipStatuses(_currentFleet);
\r
405 if (statuses.Length <= idx)
\r
407 _listForm.ShowShip(statuses[idx].Id);
\r
410 private void UpdateItemInfo()
\r
412 UpdateNumOfShips();
\r
413 UpdateNumOfEquips();
\r
414 labelNumOfBuckets.Text = _sniffer.Material.MaterialHistory[(int)Material.Bucket].Now.ToString("D");
\r
415 UpdateBucketHistory();
\r
416 var ac = _sniffer.Achievement.Value;
\r
419 labelAchievement.Text = ac >= 1000 ? ((int)ac).ToString("D") : ac.ToString("F1");
\r
420 toolTipAchievement.SetToolTip(labelAchievement,
\r
421 "今月 " + _sniffer.Achievement.ValueOfMonth.ToString("F1") + "\n" +
\r
422 "EO " + _sniffer.ExMap.Achievement);
\r
423 UpdateMaterialHistry();
\r
424 if (_listForm.Visible)
\r
425 _listForm.UpdateList();
\r
428 private void UpdateNumOfShips()
\r
430 var item = _sniffer.Item;
\r
431 labelNumOfShips.Text = $"{item.NowShips:D}/{item.MaxShips:D}";
\r
432 labelNumOfShips.ForeColor = item.TooManyShips ? CUDColor.Red : Color.Black;
\r
433 if (item.RingShips)
\r
435 var message = $"残り{_sniffer.Item.MaxShips - _sniffer.Item.NowShips:D}隻";
\r
436 _notificationManager.Enqueue("艦娘数超過", message);
\r
437 item.RingShips = false;
\r
441 private void UpdateNumOfEquips()
\r
443 var item = _sniffer.Item;
\r
444 labelNumOfEquips.Text = $"{item.NowEquips:D}/{item.MaxEquips:D}";
\r
445 labelNumOfEquips.ForeColor = item.TooManyEquips ? CUDColor.Red : Color.Black;
\r
446 if (item.RingEquips)
\r
448 var message = $"残り{_sniffer.Item.MaxEquips - _sniffer.Item.NowEquips:D}個";
\r
449 _notificationManager.Enqueue("装備数超過", message);
\r
450 item.RingEquips = false;
\r
454 private void UpdateBucketHistory()
\r
456 var count = _sniffer.Material.MaterialHistory[(int)Material.Bucket];
\r
457 var day = CutOverflow(count.Now - count.BegOfDay, 999);
\r
458 var week = CutOverflow(count.Now - count.BegOfWeek, 999);
\r
459 labelBucketHistory.Text = $"{day:+#;-#;±0} 今日\n{week:+#;-#;±0} 今週";
\r
462 private void UpdateMaterialHistry()
\r
464 var labels = new[] {labelFuelHistory, labelBulletHistory, labelSteelHistory, labelBouxiteHistory};
\r
465 var text = new[] {"燃料", "弾薬", "鋼材", "ボーキ"};
\r
466 for (var i = 0; i < labels.Length; i++)
\r
468 var count = _sniffer.Material.MaterialHistory[i];
\r
469 var port = CutOverflow(count.Now - _sniffer.Material.PrevPort[i], 99999);
\r
470 var day = CutOverflow(count.Now - count.BegOfDay, 99999);
\r
471 var week = CutOverflow(count.Now - count.BegOfWeek, 99999);
\r
472 labels[i].Text = $"{text[i]}\n{port:+#;-#;±0}\n{day:+#;-#;±0}\n{week:+#;-#;±0}";
\r
476 private int CutOverflow(int value, int limit)
\r
480 if (value < -limit)
\r
485 private void UpdateShipInfo()
\r
487 UpdatePanelShipInfo();
\r
488 NotifyDamagedShip();
\r
489 UpdateChargeInfo();
\r
490 UpdateRepairList();
\r
491 if (_listForm.Visible)
\r
492 _listForm.UpdateList();
\r
495 private void UpdatePanelShipInfo()
\r
497 var statuses = _sniffer.GetShipStatuses(_currentFleet);
\r
498 _shipLabels.SetShipLabels(statuses);
\r
499 if (_sniffer.CombinedFleetType == 0)
\r
500 _combinedFleet = false;
\r
501 labelFleet1.Text = _combinedFleet ? "連合" : "第一";
\r
502 panelCombinedFleet.Visible = _combinedFleet;
\r
503 if (_combinedFleet)
\r
504 _shipLabels.SetCombinedShipLabels(_sniffer.GetShipStatuses(0), _sniffer.GetShipStatuses(1));
\r
505 UpdateAkashiTimer();
\r
506 UpdateFighterPower(_combinedFleet);
\r
508 UpdateCondTimers();
\r
511 private void NotifyDamagedShip()
\r
513 if (_sniffer.BadlyDamagedShips.Any())
\r
514 _notificationManager.Enqueue("大破警告", string.Join(" ", _sniffer.BadlyDamagedShips));
\r
517 private void NotifyAkashiTimer()
\r
519 var akashi = _sniffer.AkashiTimer;
\r
520 var msgs = akashi.GetNotice();
\r
521 if (msgs.Length == 0)
\r
523 if (!akashi.CheckReparing() && !(akashi.CheckPresetReparing() && _config.UsePresetAkashi))
\r
525 if (msgs[0].Proceeded == "20分経過しました。")
\r
527 _notificationManager.Enqueue("泊地修理20分経過", msgs[0].Proceeded);
\r
528 msgs[0].Proceeded = "";
\r
529 // 修理完了がいるかもしれないので続ける
\r
531 for (var i = 0; i < ShipInfo.FleetCount; i++)
\r
533 if (msgs[i].Proceeded != "")
\r
534 _notificationManager.Enqueue("泊地修理進行", i, msgs[i].Proceeded);
\r
535 if (msgs[i].Completed != "")
\r
536 _notificationManager.Enqueue("泊地修理完了", i, msgs[i].Completed);
\r
540 public void UpdateFighterPower(bool combined)
\r
543 ? _sniffer.GetFighterPower(0).Zip(_sniffer.GetFighterPower(1), (a, b) => a + b).ToArray()
\r
544 : _sniffer.GetFighterPower(_currentFleet);
\r
545 labelFighterPower.Text = fp[0].ToString("D");
\r
547 ? _sniffer.GetContactTriggerRate(0) + _sniffer.GetContactTriggerRate(1)
\r
548 : _sniffer.GetContactTriggerRate(_currentFleet);
\r
549 var text = "制空: " + (fp[0] == fp[1] ? $"{fp[0]}" : $"{fp[0]}~{fp[1]}") +
\r
550 $" 触接: {cr * 100:f1}";
\r
551 toolTipFighterPower.SetToolTip(labelFighterPower, text);
\r
552 toolTipFighterPower.SetToolTip(labelFighterPowerCaption, text);
\r
555 private void UpdateLoS()
\r
557 labelLoS.Text = RoundDown(_sniffer.GetFleetLineOfSights(_currentFleet, 1)).ToString("F1");
\r
558 var text = $"係数3: {RoundDown(_sniffer.GetFleetLineOfSights(_currentFleet, 3)):F1}\r\n" +
\r
559 $"係数4: {RoundDown(_sniffer.GetFleetLineOfSights(_currentFleet, 4)):F1}";
\r
560 toolTipLoS.SetToolTip(labelLoS, text);
\r
561 toolTipLoS.SetToolTip(labelLoSCaption, text);
\r
564 private double RoundDown(double number)
\r
566 return Floor(number * 10) / 10.0;
\r
569 private void UpdateBattleInfo()
\r
572 if (_sniffer.Battle.BattleState == BattleState.None)
\r
574 panelBattleInfo.BringToFront();
\r
575 var battle = _sniffer.Battle;
\r
576 labelFormation.Text = battle.Formation;
\r
577 UpdateBattleFighterPower();
\r
578 if (_config.AlwaysShowResultRank)
\r
580 if (_sniffer.Battle.BattleState == BattleState.Day)
\r
581 _listForm.UpdateAirBattleResult();
\r
584 private void ResetBattleInfo()
\r
586 labelFormation.Text = "";
\r
587 labelEnemyFighterPower.Text = "";
\r
588 labelFighterPower.ForeColor = DefaultForeColor;
\r
589 labelResultRank.Text = "判定";
\r
590 panelBattleInfo.Visible = _sniffer.Battle.BattleState != BattleState.None;
\r
593 private void UpdateBattleFighterPower()
\r
595 var battle = _sniffer.Battle;
\r
596 var power = battle.EnemyFighterPower;
\r
597 labelEnemyFighterPower.Text = power.AirCombat + power.UnknownMark;
\r
598 if (power.AirCombat != power.Interception)
\r
600 var text = "防空: " + power.Interception + power.UnknownMark;
\r
601 toolTipFighterPower.SetToolTip(labelEnemyFighterPower, text);
\r
602 toolTipFighterPower.SetToolTip(labelEnemyFighterPowerCaption, text);
\r
604 UpdateFighterPower(_sniffer.CombinedFleetType > 0 && battle.EnemyIsCombined);
\r
605 labelFighterPower.ForeColor = new[]
\r
606 {DefaultForeColor, DefaultForeColor, CUDColor.Blue, CUDColor.Green, CUDColor.Orange, CUDColor.Red}[
\r
607 battle.AirControlLevel + 1];
\r
610 private void ShowResultRank()
\r
612 var result = new[] {"完全S", "勝利S", "勝利A", "勝利B", "敗北C", "敗北D", "敗北E"};
\r
613 labelResultRank.Text = result[(int)_sniffer.Battle.ResultRank];
\r
616 private void labelResultRank_Click(object sender, EventArgs e)
\r
621 private void UpdateChargeInfo()
\r
623 var fuelSq = new[] {labelFuelSq1, labelFuelSq2, labelFuelSq3, labelFuelSq4};
\r
624 var bullSq = new[] {labelBullSq1, labelBullSq2, labelBullSq3, labelBullSq4};
\r
626 for (var i = 0; i < fuelSq.Length; i++)
\r
628 var stat = _sniffer.ChargeStatuses[i];
\r
629 fuelSq[i].ImageIndex = stat.Fuel;
\r
630 bullSq[i].ImageIndex = stat.Bull;
\r
634 private void UpdateNDocLabels()
\r
636 _shipLabels.SetNDockLabels(_sniffer.NDock);
\r
640 private void labelNDock_Click(object sender, EventArgs e)
\r
642 _ndockFinishTimeMode = !_ndockFinishTimeMode;
\r
646 private void UpdateMissionLabels()
\r
648 foreach (var entry in
\r
649 new[] {labelMissionName1, labelMissionName2, labelMissionName3}.Zip(_sniffer.Missions,
\r
650 (label, mission) => new {label, mission.Name}))
\r
651 entry.label.Text = entry.Name;
\r
654 private void labelMission_Click(object sender, EventArgs e)
\r
656 _missionFinishTimeMode = !_missionFinishTimeMode;
\r
660 private void UpdateTimers()
\r
662 foreach (var entry in
\r
663 new[] {labelMission1, labelMission2, labelMission3}.Zip(_sniffer.Missions,
\r
664 (label, mission) => new {label, mission.Name, mission.Timer}))
\r
666 entry.Timer.Update();
\r
667 SetTimerColor(entry.label, entry.Timer);
\r
668 entry.label.Text = entry.Timer.ToString(_missionFinishTimeMode);
\r
669 if (!entry.Timer.NeedRing)
\r
671 _notificationManager.Enqueue("遠征終了", entry.Name);
\r
672 entry.Timer.NeedRing = false;
\r
674 for (var i = 0; i < _sniffer.NDock.Length; i++)
\r
676 var entry = _sniffer.NDock[i];
\r
677 entry.Timer.Update();
\r
678 _shipLabels.SetNDockTimer(i, entry.Timer, _ndockFinishTimeMode);
\r
679 if (!entry.Timer.NeedRing)
\r
681 _notificationManager.Enqueue("入渠終了", entry.Name);
\r
682 entry.Timer.NeedRing = false;
\r
684 var kdock = new[] {labelConstruct1, labelConstruct2, labelConstruct3, labelConstruct4};
\r
685 for (var i = 0; i < kdock.Length; i++)
\r
687 var timer = _sniffer.KDock[i];
\r
689 SetTimerColor(kdock[i], timer);
\r
691 kdock[i].Text = timer.EndTime == DateTime.MinValue ? "" : timer.Rest.ToString(@"hh\:mm\:ss");
\r
692 if (!timer.NeedRing)
\r
694 _notificationManager.Enqueue("建造完了", $"第{i + 1:D}ドック");
\r
695 timer.NeedRing = false;
\r
697 UpdateCondTimers();
\r
698 UpdateAkashiTimer();
\r
701 private void SetTimerColor(Label label, RingTimer timer)
\r
703 label.ForeColor = timer.IsFinished ? CUDColor.Red : Color.Black;
\r
706 private void UpdateCondTimers()
\r
709 if (_combinedFleet)
\r
711 var timer1 = _sniffer.GetConditionTimer(0);
\r
712 var timer2 = _sniffer.GetConditionTimer(1);
\r
713 timer = timer2 > timer1 ? timer2 : timer1;
\r
717 timer = _sniffer.GetConditionTimer(_currentFleet);
\r
719 var now = DateTime.Now;
\r
720 if (timer == DateTime.MinValue)
\r
722 labelCondTimerTitle.Text = "";
\r
723 labelCondTimer.Text = "";
\r
726 var span = TimeSpan.FromSeconds(Ceiling((timer - now).TotalSeconds));
\r
727 if (span >= TimeSpan.FromMinutes(9))
\r
729 labelCondTimerTitle.Text = "cond40まで";
\r
730 labelCondTimer.Text = (span - TimeSpan.FromMinutes(9)).ToString(@"mm\:ss");
\r
734 labelCondTimerTitle.Text = "cond49まで";
\r
735 labelCondTimer.Text = (span >= TimeSpan.Zero ? span : TimeSpan.Zero).ToString(@"mm\:ss");
\r
737 var notice = _sniffer.GetConditionNotice();
\r
738 if (notice == null)
\r
740 for (var i = 0; i < ShipInfo.FleetCount; i++)
\r
742 if (!_config.NotifyConditions.Contains(notice[i]))
\r
744 _notificationManager.Enqueue("疲労回復" + notice[i], i, "cond" + notice[i]);
\r
748 private void UpdateAkashiTimer()
\r
750 if (_config.UsePresetAkashi)
\r
751 UpdatePresetAkashiTimer();
\r
752 _shipLabels.SetAkashiTimer(_sniffer.GetShipStatuses(_currentFleet),
\r
753 _sniffer.AkashiTimer.GetTimers(_currentFleet));
\r
754 NotifyAkashiTimer();
\r
757 private void UpdatePresetAkashiTimer()
\r
759 var akashi = _sniffer.AkashiTimer;
\r
760 var span = akashi.PresetDeckTimer;
\r
761 var color = span == TimeSpan.Zero && akashi.CheckPresetReparing() ? CUDColor.Red : DefaultForeColor;
\r
762 var text = span == TimeSpan.MinValue ? "" : span.ToString(@"mm\:ss");
\r
763 labelAkashiRepairTimer.ForeColor = color;
\r
764 labelAkashiRepairTimer.Text = text;
\r
765 if (akashi.CheckPresetReparing() && !akashi.CheckReparing(_currentFleet))
\r
767 labelPresetAkashiTimer.ForeColor = color;
\r
768 labelPresetAkashiTimer.Text = text;
\r
772 labelPresetAkashiTimer.ForeColor = DefaultForeColor;
\r
773 labelPresetAkashiTimer.Text = "";
\r
777 private void UpdateRepairList()
\r
779 panelRepairList.SetRepairList(_sniffer.RepairList);
\r
782 private void UpdateQuestList()
\r
784 var category = new[]
\r
786 labelQuestColor1, labelQuestColor2, labelQuestColor3, labelQuestColor4, labelQuestColor5,
\r
789 var name = new[] {labelQuest1, labelQuest2, labelQuest3, labelQuest4, labelQuest5, labelQuest6};
\r
790 var progress = new[]
\r
791 {labelProgress1, labelProgress2, labelProgress3, labelProgress4, labelProgress5, labelProgress6};
\r
792 var quests = _sniffer.Quests;
\r
793 for (var i = 0; i < name.Length; i++)
\r
795 if (i < quests.Length)
\r
797 category[i].BackColor = quests[i].Color;
\r
798 name[i].Text = quests[i].Name;
\r
799 progress[i].Text = $"{quests[i].Progress:D}%";
\r
803 category[i].BackColor = DefaultBackColor;
\r
804 name[i].Text = progress[i].Text = "";
\r
809 private void Ring(string balloonTitle, string balloonMessage, string name)
\r
811 if (_config.FlashWindow && (_config.Notifications[name] & NotificationType.FlashWindow) != 0)
\r
812 Win32API.FlashWindow(Handle);
\r
813 if (_config.ShowBaloonTip && (_config.Notifications[name] & NotificationType.ShowBaloonTip) != 0)
\r
814 notifyIconMain.ShowBalloonTip(20000, balloonTitle, balloonMessage, ToolTipIcon.Info);
\r
815 if (_config.PlaySound && (_config.Notifications[name] & NotificationType.PlaySound) != 0)
\r
816 PlaySound(_config.Sounds[name], _config.Sounds.Volume);
\r
817 if (_config.Pushbullet.On && (_config.Notifications[name] & NotificationType.Pushbullet) != 0)
\r
821 PushBullet.PushNote(_config.Pushbullet.Token, balloonTitle, balloonMessage);
\r
826 [DllImport("winmm.dll")]
\r
827 private static extern int mciSendString(String command,
\r
828 StringBuilder buffer, int bufferSize, IntPtr hwndCallback);
\r
830 // ReSharper disable InconsistentNaming
\r
831 private const int MM_MCINOTIFY = 0x3B9;
\r
833 private const int MCI_NOTIFY_SUCCESSFUL = 1;
\r
834 // ReSharper restore InconsistentNaming
\r
836 public void PlaySound(string file, int volume)
\r
838 if (!File.Exists(file))
\r
840 mciSendString("close sound", null, 0, IntPtr.Zero);
\r
841 if (mciSendString("open \"" + file + "\" type mpegvideo alias sound", null, 0, IntPtr.Zero) != 0)
\r
843 mciSendString("setaudio sound volume to " + volume * 10, null, 0, IntPtr.Zero);
\r
844 mciSendString("play sound notify", null, 0, Handle);
\r
847 protected override void WndProc(ref Message m)
\r
849 if (m.Msg == MM_MCINOTIFY && (int)m.WParam == MCI_NOTIFY_SUCCESSFUL)
\r
850 mciSendString("close sound", null, 0, IntPtr.Zero);
\r
851 base.WndProc(ref m);
\r
854 private void SetupFleetClick()
\r
858 new[] {labelFleet1, labelFleet2, labelFleet3, labelFleet4},
\r
859 new[] {labelFuelSq1, labelFuelSq2, labelFuelSq3, labelFuelSq4},
\r
860 new[] {labelBullSq1, labelBullSq2, labelBullSq3, labelBullSq4}
\r
862 foreach (var a in labels)
\r
864 for (var fleet = 0; fleet < labels[0].Length; fleet++)
\r
866 a[fleet].Tag = fleet;
\r
867 a[fleet].Click += labelFleet_Click;
\r
872 private void labelFleet_Click(object sender, EventArgs e)
\r
876 var fleet = (int)((Label)sender).Tag;
\r
877 if (_currentFleet == fleet)
\r
881 _combinedFleet = _sniffer.CombinedFleetType > 0 && !_combinedFleet;
\r
882 UpdatePanelShipInfo();
\r
885 _combinedFleet = false;
\r
886 _currentFleet = fleet;
\r
887 foreach (var label in _labelCheckFleets)
\r
888 label.Visible = false;
\r
889 _labelCheckFleets[fleet].Visible = true;
\r
890 UpdatePanelShipInfo();
\r
893 private void labelFleet1_MouseHover(object sender, EventArgs e)
\r
895 labelFleet1.Text = _currentFleet == 0 && _sniffer.CombinedFleetType > 0 && !_combinedFleet ? "連合" : "第一";
\r
898 private void labelFleet1_MouseLeave(object sender, EventArgs e)
\r
900 labelFleet1.Text = _combinedFleet ? "連合" : "第一";
\r
903 private void labelBucketHistoryButton_Click(object sender, EventArgs e)
\r
905 if (labelBucketHistory.Visible)
\r
907 labelBucketHistory.Visible = false;
\r
908 labelBucketHistoryButton.BackColor = DefaultBackColor;
\r
912 labelBucketHistory.Visible = true;
\r
913 labelBucketHistory.BringToFront();
\r
914 labelBucketHistoryButton.BackColor = SystemColors.ActiveCaption;
\r
918 private void labelBucketHistory_Click(object sender, EventArgs e)
\r
920 labelBucketHistory.Visible = false;
\r
921 labelBucketHistoryButton.BackColor = DefaultBackColor;
\r
924 private void labelMaterialHistoryButton_Click(object sender, EventArgs e)
\r
926 if (panelMaterialHistory.Visible)
\r
928 panelMaterialHistory.Visible = false;
\r
929 labelMaterialHistoryButton.BackColor = DefaultBackColor;
\r
933 panelMaterialHistory.Visible = true;
\r
934 panelMaterialHistory.BringToFront();
\r
935 labelMaterialHistoryButton.BackColor = SystemColors.ActiveCaption;
\r
939 private void panelMaterialHistory_Click(object sender, EventArgs e)
\r
941 panelMaterialHistory.Visible = false;
\r
942 labelMaterialHistoryButton.BackColor = DefaultBackColor;
\r
945 public void ResetAchievemnt()
\r
947 _sniffer.Achievement.Reset();
\r
951 private void labelRepairListButton_Click(object sender, EventArgs e)
\r
953 if (panelRepairList.Visible)
\r
955 panelRepairList.Visible = false;
\r
956 labelRepairListButton.BackColor = DefaultBackColor;
\r
960 panelRepairList.Visible = true;
\r
961 panelRepairList.BringToFront();
\r
962 labelRepairListButton.BackColor = SystemColors.ActiveCaption;
\r
966 private void panelRepairList_Click(object sender, EventArgs e)
\r
968 panelRepairList.Visible = false;
\r
969 labelRepairListButton.BackColor = DefaultBackColor;
\r
972 private void ShipListToolStripMenuItem_Click(object sender, EventArgs e)
\r
974 _listForm.UpdateList();
\r
976 if (_listForm.WindowState == FormWindowState.Minimized)
\r
977 _listForm.WindowState = FormWindowState.Normal;
\r
978 _listForm.Activate();
\r
981 private void LogToolStripMenuItem_Click(object sender, EventArgs e)
\r
983 Process.Start("http://localhost:" + _config.Proxy.Listen + "/");
\r
986 private void CaptureToolStripMenuItem_Click(object sender, EventArgs e)
\r
990 var proc = new ProcessStartInfo("BurageSnap.exe") {WorkingDirectory = "Capture"};
\r
991 Process.Start(proc);
\r
993 catch (FileNotFoundException)
\r