// Copyright (C) 2013, 2014, 2015 Kazuhiro Fujieda <fujieda@users.osdn.me>\r
// \r
-// This program is part of KancolleSniffer.\r
+// Licensed under the Apache License, Version 2.0 (the "License");\r
+// you may not use this file except in compliance with the License.\r
+// You may obtain a copy of the License at\r
//\r
-// KancolleSniffer is free software: you can redistribute it and/or modify\r
-// it under the terms of the GNU General Public License as published by\r
-// the Free Software Foundation, either version 3 of the License, or\r
-// (at your option) any later version.\r
+// http://www.apache.org/licenses/LICENSE-2.0\r
//\r
-// This program is distributed in the hope that it will be useful,\r
-// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
-// GNU General Public License for more details.\r
-//\r
-// You should have received a copy of the GNU General Public License\r
-// along with this program; if not, see <http://www.gnu.org/licenses/>.\r
+// Unless required by applicable law or agreed to in writing, software\r
+// distributed under the License is distributed on an "AS IS" BASIS,\r
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+// See the License for the specific language governing permissions and\r
+// limitations under the License.\r
\r
using System;\r
using System.Collections.Generic;\r
using System.Diagnostics;\r
using System.Drawing;\r
+using System.Globalization;\r
using System.IO;\r
using System.Linq;\r
-using System.Net;\r
-using System.Net.Sockets;\r
using System.Runtime.InteropServices;\r
using System.Text;\r
-using System.Threading;\r
+using System.Text.RegularExpressions;\r
using System.Threading.Tasks;\r
using System.Windows.Forms;\r
-using System.Xml;\r
-using Codeplex.Data;\r
using Microsoft.CSharp.RuntimeBinder;\r
-using Microsoft.Win32;\r
-using Nekoxy;\r
using static System.Math;\r
-using Timer = System.Windows.Forms.Timer;\r
\r
namespace KancolleSniffer\r
{\r
private readonly Sniffer _sniffer = new Sniffer();\r
private readonly Config _config = new Config();\r
private readonly ConfigDialog _configDialog;\r
+ private readonly ProxyManager _proxyManager;\r
private int _currentFleet;\r
+ private bool _combinedFleet;\r
private readonly Label[] _labelCheckFleets;\r
private readonly ShipLabels _shipLabels;\r
- private readonly ShipListForm _shipListForm;\r
- private readonly NoticeQueue _noticeQueue;\r
+ private readonly ListForm _listForm;\r
+ private readonly NotificationManager _notificationManager;\r
private bool _started;\r
private string _debugLogFile;\r
private IEnumerator<string> _playLog;\r
- private LogServer _logServer;\r
- private int _prevProxyPort;\r
- private readonly SystemProxy _systemProxy = new SystemProxy();\r
+\r
private readonly ErrorDialog _errorDialog = new ErrorDialog();\r
private bool _missionFinishTimeMode;\r
private bool _ndockFinishTimeMode;\r
+ private readonly KancolleDb _kancolleDb = new KancolleDb();\r
\r
public MainForm()\r
{\r
SetupFleetClick();\r
_shipLabels = new ShipLabels();\r
_shipLabels.CreateAkashiTimers(panelShipInfo);\r
- _shipLabels.CreateLabels(panelShipInfo, ShowShipOnShipList);\r
- _shipLabels.CreateDamagedShipList(panelDamagedShipList, panelDamagedShipList_Click);\r
- _shipLabels.CreateNDockLabels(panelDock, (obj, args) =>\r
- {\r
- _ndockFinishTimeMode = !_ndockFinishTimeMode;\r
- UpdateTimers();\r
- });\r
- labelPresetDeckTimer.BackColor = ShipLabels.ColumnColors[1];\r
- _shipListForm = new ShipListForm(_sniffer, _config) {Owner = this};\r
- _noticeQueue = new NoticeQueue(Ring);\r
+ _shipLabels.CreateShipLabels(panelShipInfo, ShowShipOnShipList);\r
+ _shipLabels.CreateCombinedShipLabels(panelCombinedFleet, ShowShipOnShipList);\r
+ _shipLabels.CreateNDockLabels(panelDock, labelNDock_Click);\r
+ panelRepairList.CreateLabels(panelRepairList_Click);\r
+ labelPresetAkashiTimer.BackColor = ShipLabels.ColumnColors[1];\r
+ _listForm = new ListForm(_sniffer, _config) {Owner = this};\r
+ _notificationManager = new NotificationManager(Ring);\r
+ _config.Load();\r
+ _proxyManager = new ProxyManager(_config, this);\r
+ PerformZoom();\r
+ _shipLabels.AdjustAkashiTimers();\r
+ _sniffer.LoadState();\r
}\r
\r
- private void HttpProxy_AfterSessionComplete(Session session)\r
+ private void HttpProxy_AfterSessionComplete(HttpProxy.Session session)\r
{\r
- Invoke(new Action<Session>(ProcessRequest), session);\r
+ Invoke(new Action<HttpProxy.Session>(ProcessRequest), session);\r
}\r
\r
- private void ProcessRequest(Session session)\r
+ private void ProcessRequest(HttpProxy.Session session)\r
{\r
var url = session.Request.PathAndQuery;\r
- var request = session.Request.BodyAsString;\r
- var response = session.Response.BodyAsString;\r
if (!url.Contains("kcsapi/"))\r
return;\r
+ var request = session.Request.BodyAsString;\r
+ var response = session.Response.BodyAsString;\r
if (response == null || !response.StartsWith("svdata="))\r
{\r
WriteDebugLog(url, request, response);\r
- ShowServerError(url, request, response);\r
return;\r
}\r
- response = response.Remove(0, "svdata=".Length);\r
+ if (_config.KancolleDb.On)\r
+ _kancolleDb.Send(url, request, response);\r
+ response = UnescapeString(response.Remove(0, "svdata=".Length));\r
+ WriteDebugLog(url, request, response);\r
try\r
{\r
- var json = DynamicJson.Parse(response);\r
- WriteDebugLog(url, request, json.ToString());\r
- var update = _sniffer.Sniff(url, request, json);\r
- if (update == Sniffer.Update.Error)\r
- {\r
- ShowServerError(url, request, json);\r
- return;\r
- }\r
- UpdateInfo(update);\r
- }\r
- catch (XmlException)\r
- {\r
- WriteDebugLog(url, request, response);\r
- ShowServerError(url, request, response);\r
+ UpdateInfo(_sniffer.Sniff(url, request, JsonParser.Parse(response)));\r
}\r
catch (RuntimeBinderException e)\r
{\r
if (_errorDialog.ShowDialog(this,\r
- "このバージョンは現在の艦これに対応していません。\n新しいバージョンを利用してください。", e.ToString()) == DialogResult.Abort)\r
+ "このバージョンは現在の艦これに対応していません。\r\n新しいバージョンを利用してください。", e.ToString()) == DialogResult.Abort)\r
Application.Exit();\r
}\r
catch (LogIOException e)\r
{\r
+ // ReSharper disable once PossibleNullReferenceException\r
if (_errorDialog.ShowDialog(this, e.Message, e.InnerException.ToString()) == DialogResult.Abort)\r
Application.Exit();\r
}\r
+ catch (Exception e)\r
+ {\r
+ if (_errorDialog.ShowDialog(this, "エラーが発生しました。", e.ToString()) == DialogResult.Abort)\r
+ Application.Exit();\r
+ }\r
}\r
\r
private void WriteDebugLog(string url, string request, string response)\r
{\r
if (_debugLogFile != null)\r
{\r
- File.AppendAllText(_debugLogFile, SessionString(url, request, response));\r
+ File.AppendAllText(_debugLogFile,\r
+ $"url: {url}\nrequest: {request}\nresponse: {response ?? "(null)"}\n");\r
}\r
}\r
\r
- private void ShowServerError(string url, string request, string response)\r
+ private string UnescapeString(string s)\r
{\r
- if (_errorDialog.Visible)\r
- return;\r
- if (_errorDialog.ShowDialog(this, "サーバーからの応答が異常です。",\r
- SessionString(url, request, response)) == DialogResult.Abort)\r
- Application.Exit();\r
+ try\r
+ {\r
+ var rx = new Regex(@"\\[uU]([0-9A-Fa-f]{4})");\r
+ return rx.Replace(s,\r
+ match => ((char)int.Parse(match.Value.Substring(2), NumberStyles.HexNumber)).ToString());\r
+ }\r
+ catch (ArgumentException)\r
+ {\r
+ return s;\r
+ }\r
}\r
\r
- private string SessionString(string url, string request, string response)\r
- => $"url: {url}\nrequest: {request}\nresponse: {(response ?? "(null)")}\n";\r
-\r
private void UpdateInfo(Sniffer.Update update)\r
{\r
if (update == Sniffer.Update.Start)\r
{\r
labelLogin.Visible = false;\r
+ labelGuide.Visible = false;\r
_started = true;\r
return;\r
}\r
\r
private void MainForm_Load(object sender, EventArgs e)\r
{\r
- _config.Load();\r
RestoreLocation();\r
if (_config.HideOnMinimized && WindowState == FormWindowState.Minimized)\r
ShowInTaskbar = false;\r
ApplyConfig();\r
ApplyDebugLogSetting();\r
ApplyLogSetting();\r
- _sniffer.LoadState();\r
ApplyProxySetting();\r
- SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;\r
+ if (_config.KancolleDb.On)\r
+ _kancolleDb.Start(_config.KancolleDb.Token);\r
}\r
\r
- private void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)\r
+ private void MainForm_FormClosing(object sender, FormClosingEventArgs e)\r
{\r
- if (e.Mode != PowerModes.Resume || !_config.Proxy.Auto)\r
- return;\r
- Task.Run(() =>\r
+ using (var dialog = new ConfirmDialog())\r
{\r
- for (var i = 0; i < 5; Thread.Sleep(10000), i++)\r
+ if (dialog.ShowDialog(this) != DialogResult.Yes)\r
{\r
- WebResponse res = null;\r
- SystemProxy.Refresh();\r
- var system = WebRequest.GetSystemWebProxy();\r
- if (!system.GetProxy(new Uri("http://125.6.184.16/")).IsLoopback)\r
- {\r
- File.AppendAllText("wakeup.log",\r
- $"[{DateTime.Now.ToString("g")}] proxy settings doesn't work.\r\n");\r
- continue;\r
- }\r
- try\r
- {\r
- var req = WebRequest.Create("http://kancollesniffer.osdn.jp/version");\r
- res = req.GetResponse();\r
- break;\r
- }\r
- catch\r
- {\r
- File.AppendAllText("wakeup.log",\r
- $"[{DateTime.Now.ToString("g")}] failed to connect internet.\r\n");\r
- }\r
- finally\r
- {\r
- res?.Close();\r
- }\r
+ e.Cancel = true;\r
+ return;\r
}\r
- });\r
- }\r
-\r
- private void MainForm_FormClosing(object sender, FormClosingEventArgs e)\r
- {\r
+ }\r
e.Cancel = false;\r
+ _sniffer.FlashLog();\r
_config.Location = (WindowState == FormWindowState.Normal ? Bounds : RestoreBounds).Location;\r
_config.Save();\r
- Task.Run(() => ShutdownProxy());\r
- _logServer?.Stop();\r
- if (_config.Proxy.Auto)\r
- _systemProxy.RestoreSettings();\r
- SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;\r
- }\r
-\r
- private void ShutdownProxy()\r
- {\r
- HttpProxy.Shutdown();\r
+ _proxyManager.Shutdown();\r
+ _kancolleDb.Stop();\r
}\r
\r
private void MainForm_Resize(object sender, EventArgs e)\r
ApplyConfig();\r
}\r
\r
+ private void PerformZoom()\r
+ {\r
+ if (_config.Zoom == 100)\r
+ return;\r
+ var prev = CurrentAutoScaleDimensions;\r
+ foreach (var control in new Control[] {this, _listForm, labelLogin, labelGuide})\r
+ control.Font = new Font(control.Font.FontFamily, control.Font.Size * _config.Zoom / 100);\r
+ ShipLabel.LatinFont = new Font("Tahoma", 8f * _config.Zoom / 100);\r
+ var cur = CurrentAutoScaleDimensions;\r
+ ShipLabel.ScaleFactor = new SizeF(ShipLabel.ScaleFactor.Width * cur.Width / prev.Width,\r
+ ShipLabel.ScaleFactor.Height * cur.Height / prev.Height);\r
+ }\r
+\r
private void RestoreLocation()\r
{\r
if (_config.Location.X == int.MinValue)\r
\r
private void ApplyConfig()\r
{\r
- _shipListForm.TopMost = TopMost = _config.TopMost;\r
+ _listForm.TopMost = TopMost = _config.TopMost;\r
_sniffer.Item.MarginShips = _config.MarginShips;\r
_sniffer.Item.MarginEquips = _config.MarginEquips;\r
_sniffer.Achievement.ResetHours = _config.ResetHours;\r
+ labelAkashiRepair.Visible = labelAkashiRepairTimer.Visible =\r
+ labelPresetAkashiTimer.Visible = _config.UsePresetAkashi;\r
+ if (_config.KancolleDb.On)\r
+ _kancolleDb.Start(_config.KancolleDb.Token);\r
}\r
\r
public void ApplyDebugLogSetting()\r
\r
public bool ApplyProxySetting()\r
{\r
- if (!_config.Proxy.Auto)\r
- _systemProxy.RestoreSettings();\r
- if (_config.Proxy.UseUpstream)\r
- {\r
- HttpProxy.UpstreamProxyHost = "127.0.0.1";\r
- HttpProxy.UpstreamProxyPort = _config.Proxy.UpstreamPort;\r
- }\r
- HttpProxy.IsEnableUpstreamProxy = _config.Proxy.UseUpstream;\r
- var result = true;\r
- if (!HttpProxy.IsInListening || _config.Proxy.Listen != _prevProxyPort)\r
- {\r
- ShutdownProxy();\r
- result = StartProxy();\r
- }\r
- if (_config.Proxy.Auto && result)\r
- {\r
- _systemProxy.SetAutoProxyUrl(HttpProxy.LocalPort == 8080\r
- ? ProxyConfig.AutoConfigUrl\r
- : ProxyConfig.AutoConfigUrlWithPort + HttpProxy.LocalPort);\r
- }\r
- _prevProxyPort = _config.Proxy.Listen;\r
- return result;\r
- }\r
-\r
- private bool StartProxy()\r
- {\r
- try\r
- {\r
- HttpProxy.Startup(_config.Proxy.Listen, false, false);\r
- }\r
- catch (SocketException e)\r
- {\r
- if (e.SocketErrorCode != SocketError.AddressAlreadyInUse)\r
- throw;\r
- if (WarnConflictPortNumber("プロキシサーバー", _config.Proxy.Listen, _config.Proxy.Auto) == DialogResult.No ||\r
- !_config.Proxy.Auto)\r
- {\r
- _systemProxy.RestoreSettings();\r
- return false;\r
- }\r
- HttpProxy.Startup(0, false, false);\r
- _config.Proxy.Listen = HttpProxy.LocalPort;\r
- }\r
- return true;\r
- }\r
-\r
- private DialogResult WarnConflictPortNumber(string name, int port, bool auto)\r
- {\r
- var msg = $"{name}のポート番号{port}は他のアプリケーションが使用中です。";\r
- var cap = "ポート番号の衝突";\r
- return auto\r
- ? MessageBox.Show(this, msg + "自動的に別の番号を割り当てますか?", cap,\r
- MessageBoxButtons.YesNo, MessageBoxIcon.Question)\r
- : MessageBox.Show(this, msg + "設定ダイアログでポート番号を変更してください。", cap,\r
- MessageBoxButtons.OK, MessageBoxIcon.Exclamation);\r
+ return _proxyManager.ApplyConfig();\r
}\r
\r
- public bool ApplyLogSetting()\r
+ public void ApplyLogSetting()\r
{\r
- var result = true;\r
- if (_config.Log.ServerOn)\r
- {\r
- result = StartLogServer();\r
- }\r
- else\r
- {\r
- _logServer?.Stop();\r
- _logServer = null;\r
- }\r
+ LogServer.OutputDir = _config.Log.OutputDir;\r
_sniffer.EnableLog(_config.Log.On ? LogType.All : LogType.None);\r
_sniffer.MaterialLogInterval = _config.Log.MaterialLogInterval;\r
_sniffer.LogOutputDir = _config.Log.OutputDir;\r
- return result;\r
- }\r
-\r
- private bool StartLogServer()\r
- {\r
- var port = _config.Log.Listen;\r
- if (_logServer?.Port == port)\r
- return true;\r
- _logServer?.Stop();\r
- _logServer = null;\r
- try\r
- {\r
- _logServer = new LogServer(port);\r
- _logServer.Start();\r
- }\r
- catch (SocketException e) when (e.SocketErrorCode == SocketError.AddressAlreadyInUse)\r
- {\r
- if (WarnConflictPortNumber("閲覧サーバー", port, true) == DialogResult.No)\r
- return false;\r
- _logServer = new LogServer(0);\r
- _logServer.Start();\r
- _config.Log.Listen = _logServer.Port;\r
- }\r
- _logServer.OutputDir = _config.Log.OutputDir;\r
- return true;\r
}\r
\r
public static bool IsVisibleOnAnyScreen(Rectangle rect)\r
private void timerMain_Tick(object sender, EventArgs e)\r
{\r
if (_started)\r
- UpdateTimers();\r
+ {\r
+ try\r
+ {\r
+ UpdateTimers();\r
+ }\r
+ catch (Exception ex)\r
+ {\r
+ if (_errorDialog.ShowDialog(this, "エラーが発生しました。", ex.ToString()) == DialogResult.Abort)\r
+ Application.Exit();\r
+ }\r
+ }\r
if (_playLog == null || _configDialog.Visible)\r
{\r
labelPlayLog.Visible = false;\r
lines.Add(_playLog.Current.Substring(s.Length));\r
}\r
labelPlayLog.Visible = !labelPlayLog.Visible;\r
- var json = DynamicJson.Parse(lines[2]);\r
+ var json = JsonParser.Parse(lines[2]);\r
UpdateInfo(_sniffer.Sniff(lines[0], lines[1], json));\r
}\r
\r
private void ShowShipOnShipList(object sender, EventArgs ev)\r
{\r
- if (!_shipListForm.Visible)\r
+ if (!_listForm.Visible)\r
return;\r
var idx = (int)((Control)sender).Tag;\r
var statuses = _sniffer.GetShipStatuses(_currentFleet);\r
if (statuses.Length <= idx)\r
return;\r
- _shipListForm.ShowShip(statuses[idx].Id);\r
+ _listForm.ShowShip(statuses[idx].Id);\r
}\r
\r
private void UpdateItemInfo()\r
"今月 " + _sniffer.Achievement.ValueOfMonth.ToString("F1") + "\n" +\r
"EO " + _sniffer.ExMap.Achievement);\r
UpdateMaterialHistry();\r
- if (_shipListForm.Visible)\r
- _shipListForm.UpdateList();\r
+ if (_listForm.Visible)\r
+ _listForm.UpdateList();\r
}\r
\r
private void UpdateNumOfShips()\r
{\r
var item = _sniffer.Item;\r
labelNumOfShips.Text = $"{item.NowShips:D}/{item.MaxShips:D}";\r
- labelNumOfShips.ForeColor = item.TooManyShips ? Color.Red : Color.Black;\r
+ labelNumOfShips.ForeColor = item.TooManyShips ? CUDColor.Red : Color.Black;\r
if (item.RingShips)\r
{\r
var message = $"残り{_sniffer.Item.MaxShips - _sniffer.Item.NowShips:D}隻";\r
- _noticeQueue.Enqueue("艦娘が多すぎます", message, _config.MaxShipsSoundFile);\r
+ _notificationManager.Enqueue("艦娘数超過", message);\r
item.RingShips = false;\r
}\r
}\r
{\r
var item = _sniffer.Item;\r
labelNumOfEquips.Text = $"{item.NowEquips:D}/{item.MaxEquips:D}";\r
- labelNumOfEquips.ForeColor = item.TooManyEquips ? Color.Red : Color.Black;\r
+ labelNumOfEquips.ForeColor = item.TooManyEquips ? CUDColor.Red : Color.Black;\r
if (item.RingEquips)\r
{\r
var message = $"残り{_sniffer.Item.MaxEquips - _sniffer.Item.NowEquips:D}個";\r
- _noticeQueue.Enqueue("装備が多すぎます", message, _config.MaxEquipsSoundFile);\r
+ _notificationManager.Enqueue("装備数超過", message);\r
item.RingEquips = false;\r
}\r
}\r
private void UpdateBucketHistory()\r
{\r
var count = _sniffer.Material.MaterialHistory[(int)Material.Bucket];\r
- var day = count.Now - count.BegOfDay;\r
- var week = count.Now - count.BegOfWeek;\r
- if (day >= 1000)\r
- day = 999;\r
- if (week >= 1000)\r
- week = 999;\r
+ var day = CutOverflow(count.Now - count.BegOfDay, 999);\r
+ var week = CutOverflow(count.Now - count.BegOfWeek, 999);\r
labelBucketHistory.Text = $"{day:+#;-#;±0} 今日\n{week:+#;-#;±0} 今週";\r
}\r
\r
for (var i = 0; i < labels.Length; i++)\r
{\r
var count = _sniffer.Material.MaterialHistory[i];\r
- var port = count.Now - _sniffer.Material.PrevPort[i];\r
- if (port >= 100000)\r
- port = 99999;\r
- var day = count.Now - count.BegOfDay;\r
- if (day >= 100000)\r
- day = 99999;\r
- var week = count.Now - count.BegOfWeek;\r
- if (week >= 100000)\r
- week = 99999;\r
+ var port = CutOverflow(count.Now - _sniffer.Material.PrevPort[i], 99999);\r
+ var day = CutOverflow(count.Now - count.BegOfDay, 99999);\r
+ var week = CutOverflow(count.Now - count.BegOfWeek, 99999);\r
labels[i].Text = $"{text[i]}\n{port:+#;-#;±0}\n{day:+#;-#;±0}\n{week:+#;-#;±0}";\r
}\r
}\r
\r
+ private int CutOverflow(int value, int limit)\r
+ {\r
+ if (value > limit)\r
+ return limit;\r
+ if (value < -limit)\r
+ return -limit;\r
+ return value;\r
+ }\r
+\r
private void UpdateShipInfo()\r
{\r
UpdatePanelShipInfo();\r
NotifyDamagedShip();\r
UpdateChargeInfo();\r
- UpdateDamagedShipList();\r
- if (_shipListForm.Visible)\r
- _shipListForm.UpdateList();\r
+ UpdateRepairList();\r
+ if (_listForm.Visible)\r
+ _listForm.UpdateList();\r
}\r
\r
private void UpdatePanelShipInfo()\r
{\r
var statuses = _sniffer.GetShipStatuses(_currentFleet);\r
- _shipLabels.SetShipInfo(statuses);\r
+ _shipLabels.SetShipLabels(statuses);\r
+ if (_sniffer.CombinedFleetType == 0)\r
+ _combinedFleet = false;\r
+ labelFleet1.Text = _combinedFleet ? "連合" : "第一";\r
+ panelCombinedFleet.Visible = _combinedFleet;\r
+ if (_combinedFleet)\r
+ _shipLabels.SetCombinedShipLabels(_sniffer.GetShipStatuses(0), _sniffer.GetShipStatuses(1));\r
UpdateAkashiTimer();\r
- UpdateFighterPower();\r
+ UpdateFighterPower(_combinedFleet);\r
UpdateLoS();\r
UpdateCondTimers();\r
}\r
\r
private void NotifyDamagedShip()\r
{\r
- if (_sniffer.Battle.HasDamagedShip)\r
- _noticeQueue.Enqueue("大破した艦娘がいます", string.Join(" ", _sniffer.Battle.DamagedShipNames),\r
- _config.DamagedShipSoundFile);\r
+ if (_sniffer.BadlyDamagedShips.Any())\r
+ _notificationManager.Enqueue("大破警告", string.Join(" ", _sniffer.BadlyDamagedShips));\r
}\r
\r
private void NotifyAkashiTimer()\r
{\r
- var msgs = _sniffer.GetAkashiTimerNotice();\r
+ var akashi = _sniffer.AkashiTimer;\r
+ var msgs = akashi.GetNotice();\r
if (msgs.Length == 0)\r
return;\r
+ if (!akashi.CheckReparing() && !(akashi.CheckPresetReparing() && _config.UsePresetAkashi))\r
+ return;\r
if (msgs[0].Proceeded == "20分経過しました。")\r
{\r
- _noticeQueue.Enqueue("泊地修理", msgs[0].Proceeded, _config.Akashi20MinSoundFile);\r
+ _notificationManager.Enqueue("泊地修理20分経過", msgs[0].Proceeded);\r
msgs[0].Proceeded = "";\r
// 修理完了がいるかもしれないので続ける\r
}\r
- var fn = new[] {"第一艦隊", "第二艦隊", "第三艦隊", "第四艦隊"};\r
- for (var i = 0; i < fn.Length; i++)\r
+ for (var i = 0; i < ShipInfo.FleetCount; i++)\r
{\r
if (msgs[i].Proceeded != "")\r
- _noticeQueue.Enqueue("泊地修理 " + fn[i], "修理進行:" + msgs[i].Proceeded, _config.AkashiProgressSoundFile);\r
+ _notificationManager.Enqueue("泊地修理進行", i, msgs[i].Proceeded);\r
if (msgs[i].Completed != "")\r
- _noticeQueue.Enqueue("泊地修理 " + fn[i], "修理完了:" + msgs[i].Completed, _config.AkashiCompleteSoundFile);\r
+ _notificationManager.Enqueue("泊地修理完了", i, msgs[i].Completed);\r
}\r
}\r
\r
- public void UpdateFighterPower()\r
+ public void UpdateFighterPower(bool combined)\r
{\r
- labelFighterPower.Text = _sniffer.GetFighterPower(_currentFleet, true).ToString("D");\r
- toolTipFigherPower.SetToolTip(labelFighterPower, "熟練度抜き " + _sniffer.GetFighterPower(_currentFleet, false));\r
+ var fp = combined\r
+ ? _sniffer.GetFighterPower(0).Zip(_sniffer.GetFighterPower(1), (a, b) => a + b).ToArray()\r
+ : _sniffer.GetFighterPower(_currentFleet);\r
+ labelFighterPower.Text = fp[0].ToString("D");\r
+ var cr = combined\r
+ ? _sniffer.GetContactTriggerRate(0) + _sniffer.GetContactTriggerRate(1)\r
+ : _sniffer.GetContactTriggerRate(_currentFleet);\r
+ var text = "制空: " + (fp[0] == fp[1] ? $"{fp[0]}" : $"{fp[0]}~{fp[1]}") +\r
+ $" 触接: {cr * 100:f1}";\r
+ toolTipFighterPower.SetToolTip(labelFighterPower, text);\r
+ toolTipFighterPower.SetToolTip(labelFighterPowerCaption, text);\r
}\r
\r
private void UpdateLoS()\r
{\r
- labelLoS.Text = _sniffer.GetFleetLineOfSights(_currentFleet).ToString("F1");\r
+ labelLoS.Text = RoundDown(_sniffer.GetFleetLineOfSights(_currentFleet, 1)).ToString("F1");\r
+ var text = $"係数3: {RoundDown(_sniffer.GetFleetLineOfSights(_currentFleet, 3)):F1}\r\n" +\r
+ $"係数4: {RoundDown(_sniffer.GetFleetLineOfSights(_currentFleet, 4)):F1}";\r
+ toolTipLoS.SetToolTip(labelLoS, text);\r
+ toolTipLoS.SetToolTip(labelLoSCaption, text);\r
+ }\r
+\r
+ private double RoundDown(double number)\r
+ {\r
+ return Floor(number * 10) / 10.0;\r
}\r
\r
private void UpdateBattleInfo()\r
{\r
- labelFormation.Text = "";\r
- labelEnemyFighterPower.Text = "";\r
- labelFighterPower.ForeColor = DefaultForeColor;\r
- labelResultRank.Text = "判定";\r
- panelBattleInfo.Visible = _sniffer.Battle.InBattle;\r
- if (!_sniffer.Battle.InBattle)\r
+ ResetBattleInfo();\r
+ if (_sniffer.Battle.BattleState == BattleState.None)\r
return;\r
panelBattleInfo.BringToFront();\r
var battle = _sniffer.Battle;\r
- var color = new[] {DefaultForeColor, DefaultForeColor, Color.Blue, Color.Green, Color.Orange, Color.Red};\r
labelFormation.Text = battle.Formation;\r
- var enemyFp = battle.EnemyFighterPower;\r
- labelEnemyFighterPower.Text = (enemyFp & BattleInfo.IncollectFighterPowerFlag) == 0\r
- ? enemyFp.ToString()\r
- : (enemyFp & ~BattleInfo.IncollectFighterPowerFlag) + "+";\r
- labelFighterPower.ForeColor = color[battle.AirControlLevel + 1];\r
+ UpdateBattleFighterPower();\r
if (_config.AlwaysShowResultRank)\r
ShowResultRank();\r
+ if (_sniffer.Battle.BattleState == BattleState.Day)\r
+ _listForm.UpdateAirBattleResult();\r
+ }\r
+\r
+ private void ResetBattleInfo()\r
+ {\r
+ labelFormation.Text = "";\r
+ labelEnemyFighterPower.Text = "";\r
+ labelFighterPower.ForeColor = DefaultForeColor;\r
+ labelResultRank.Text = "判定";\r
+ panelBattleInfo.Visible = _sniffer.Battle.BattleState != BattleState.None;\r
+ }\r
+\r
+ private void UpdateBattleFighterPower()\r
+ {\r
+ var battle = _sniffer.Battle;\r
+ var power = battle.EnemyFighterPower;\r
+ labelEnemyFighterPower.Text = power.AirCombat + power.UnknownMark;\r
+ if (power.AirCombat != power.Interception)\r
+ {\r
+ var text = "防空: " + power.Interception + power.UnknownMark;\r
+ toolTipFighterPower.SetToolTip(labelEnemyFighterPower, text);\r
+ toolTipFighterPower.SetToolTip(labelEnemyFighterPowerCaption, text);\r
+ }\r
+ UpdateFighterPower(_sniffer.CombinedFleetType > 0 && battle.EnemyIsCombined);\r
+ labelFighterPower.ForeColor = new[]\r
+ {DefaultForeColor, DefaultForeColor, CUDColor.Blue, CUDColor.Green, CUDColor.Orange, CUDColor.Red}[\r
+ battle.AirControlLevel + 1];\r
}\r
\r
private void ShowResultRank()\r
_shipLabels.SetNDockLabels(_sniffer.NDock);\r
}\r
\r
+\r
+ private void labelNDock_Click(object sender, EventArgs e)\r
+ {\r
+ _ndockFinishTimeMode = !_ndockFinishTimeMode;\r
+ UpdateTimers();\r
+ }\r
+\r
private void UpdateMissionLabels()\r
{\r
foreach (var entry in\r
{\r
entry.Timer.Update();\r
SetTimerColor(entry.label, entry.Timer);\r
- var rest = entry.Timer.Rest;\r
- entry.label.Text = _missionFinishTimeMode\r
- ? entry.Timer.EndTime == DateTime.MinValue\r
- ? "-------"\r
- : entry.Timer.EndTime.ToString(@"dd\ HH\:mm")\r
- : rest.ToString(@"hh\:mm\:ss");\r
+ entry.label.Text = entry.Timer.ToString(_missionFinishTimeMode);\r
if (!entry.Timer.NeedRing)\r
continue;\r
- _noticeQueue.Enqueue("遠征が終わりました", entry.Name, _config.MissionSoundFile);\r
+ _notificationManager.Enqueue("遠征終了", entry.Name);\r
entry.Timer.NeedRing = false;\r
}\r
for (var i = 0; i < _sniffer.NDock.Length; i++)\r
_shipLabels.SetNDockTimer(i, entry.Timer, _ndockFinishTimeMode);\r
if (!entry.Timer.NeedRing)\r
continue;\r
- _noticeQueue.Enqueue("入渠が終わりました", entry.Name, _config.NDockSoundFile);\r
+ _notificationManager.Enqueue("入渠終了", entry.Name);\r
entry.Timer.NeedRing = false;\r
}\r
var kdock = new[] {labelConstruct1, labelConstruct2, labelConstruct3, labelConstruct4};\r
var timer = _sniffer.KDock[i];\r
timer.Update();\r
SetTimerColor(kdock[i], timer);\r
- kdock[i].Text = timer.Rest.ToString(@"hh\:mm\:ss");\r
+\r
+ kdock[i].Text = timer.EndTime == DateTime.MinValue ? "" : timer.Rest.ToString(@"hh\:mm\:ss");\r
if (!timer.NeedRing)\r
continue;\r
- _noticeQueue.Enqueue("建造が終わりました", $"第{i + 1:D}ドック", _config.KDockSoundFile);\r
+ _notificationManager.Enqueue("建造完了", $"第{i + 1:D}ドック");\r
timer.NeedRing = false;\r
}\r
UpdateCondTimers();\r
\r
private void SetTimerColor(Label label, RingTimer timer)\r
{\r
- label.ForeColor = timer.IsFinished ? Color.Red : Color.Black;\r
+ label.ForeColor = timer.IsFinished ? CUDColor.Red : Color.Black;\r
}\r
\r
private void UpdateCondTimers()\r
{\r
- var timer = _sniffer.GetConditionTimer(_currentFleet);\r
+ DateTime timer;\r
+ if (_combinedFleet)\r
+ {\r
+ var timer1 = _sniffer.GetConditionTimer(0);\r
+ var timer2 = _sniffer.GetConditionTimer(1);\r
+ timer = timer2 > timer1 ? timer2 : timer1;\r
+ }\r
+ else\r
+ {\r
+ timer = _sniffer.GetConditionTimer(_currentFleet);\r
+ }\r
var now = DateTime.Now;\r
if (timer == DateTime.MinValue)\r
{\r
var notice = _sniffer.GetConditionNotice();\r
if (notice == null)\r
return;\r
- var fn = new[] {"第一艦隊", "第二艦隊", "第三艦隊", "第四艦隊"};\r
- for (var i = 0; i < fn.Length; i++)\r
+ for (var i = 0; i < ShipInfo.FleetCount; i++)\r
{\r
if (!_config.NotifyConditions.Contains(notice[i]))\r
return;\r
- _noticeQueue.Enqueue("疲労が回復しました", fn[i] + " cond" + notice[i].ToString("D"), _config.ConditionSoundFile);\r
+ _notificationManager.Enqueue("疲労回復" + notice[i], i, "cond" + notice[i]);\r
}\r
}\r
\r
private void UpdateAkashiTimer()\r
{\r
- var span = _sniffer.AkashiPresetDeckTimer;\r
- var timer = _sniffer.GetAkashiTimers(_currentFleet);\r
- var reparing = timer.Any(t => t.Span != TimeSpan.MinValue);\r
- labelPresetDeckTimer.Text = span == TimeSpan.MinValue || reparing ? "" : span.ToString(@"mm\:ss");\r
+ if (_config.UsePresetAkashi)\r
+ UpdatePresetAkashiTimer();\r
_shipLabels.SetAkashiTimer(_sniffer.GetShipStatuses(_currentFleet),\r
- _sniffer.GetAkashiTimers(_currentFleet));\r
+ _sniffer.AkashiTimer.GetTimers(_currentFleet));\r
NotifyAkashiTimer();\r
}\r
\r
- private void UpdateDamagedShipList()\r
+ private void UpdatePresetAkashiTimer()\r
+ {\r
+ var akashi = _sniffer.AkashiTimer;\r
+ var span = akashi.PresetDeckTimer;\r
+ var color = span == TimeSpan.Zero && akashi.CheckPresetReparing() ? CUDColor.Red : DefaultForeColor;\r
+ var text = span == TimeSpan.MinValue ? "" : span.ToString(@"mm\:ss");\r
+ labelAkashiRepairTimer.ForeColor = color;\r
+ labelAkashiRepairTimer.Text = text;\r
+ if (akashi.CheckPresetReparing() && !akashi.CheckReparing(_currentFleet))\r
+ {\r
+ labelPresetAkashiTimer.ForeColor = color;\r
+ labelPresetAkashiTimer.Text = text;\r
+ }\r
+ else\r
+ {\r
+ labelPresetAkashiTimer.ForeColor = DefaultForeColor;\r
+ labelPresetAkashiTimer.Text = "";\r
+ }\r
+ }\r
+\r
+ private void UpdateRepairList()\r
{\r
- _shipLabels.SetDamagedShipList(_sniffer.DamagedShipList);\r
+ panelRepairList.SetRepairList(_sniffer.RepairList);\r
}\r
\r
private void UpdateQuestList()\r
};\r
var name = new[] {labelQuest1, labelQuest2, labelQuest3, labelQuest4, labelQuest5, labelQuest6};\r
var progress = new[]\r
- {labelProgress1, labelProgress2, labelProgress3, labelProgress4, labelProgress5, labelProgress6};\r
- var color = new[]\r
- {\r
- Color.FromArgb(60, 141, 76), Color.FromArgb(232, 57, 41), Color.FromArgb(136, 204, 120),\r
- Color.FromArgb(52, 147, 185), Color.FromArgb(220, 198, 126), Color.FromArgb(168, 111, 76),\r
- Color.FromArgb(200, 148, 231)\r
- };\r
-\r
+ {labelProgress1, labelProgress2, labelProgress3, labelProgress4, labelProgress5, labelProgress6};\r
var quests = _sniffer.Quests;\r
for (var i = 0; i < name.Length; i++)\r
{\r
if (i < quests.Length)\r
{\r
- category[i].BackColor = color[quests[i].Category - 1];\r
+ category[i].BackColor = quests[i].Color;\r
name[i].Text = quests[i].Name;\r
progress[i].Text = $"{quests[i].Progress:D}%";\r
}\r
}\r
}\r
\r
- private class NoticeQueue\r
+ private void Ring(string balloonTitle, string balloonMessage, string name)\r
{\r
- private readonly Action<string, string, string> _ring;\r
- private readonly Queue<Tuple<string, string, string>> _queue = new Queue<Tuple<string, string, string>>();\r
- private readonly Timer _timer = new Timer {Interval = 2000};\r
-\r
- public NoticeQueue(Action<string, string, string> ring)\r
- {\r
- _ring = ring;\r
- _timer.Tick += TimerOnTick;\r
- }\r
-\r
- private void TimerOnTick(object obj, EventArgs e)\r
- {\r
- if (_queue.Count == 0)\r
- {\r
- _timer.Stop();\r
- return;\r
- }\r
- var notice = _queue.Dequeue();\r
- _ring(notice.Item1, notice.Item2, notice.Item3);\r
- }\r
-\r
- public void Enqueue(string title, string message, string soundFile)\r
+ if (_config.FlashWindow && (_config.Notifications[name] & NotificationType.FlashWindow) != 0)\r
+ Win32API.FlashWindow(Handle);\r
+ if (_config.ShowBaloonTip && (_config.Notifications[name] & NotificationType.ShowBaloonTip) != 0)\r
+ notifyIconMain.ShowBalloonTip(20000, balloonTitle, balloonMessage, ToolTipIcon.Info);\r
+ if (_config.PlaySound && (_config.Notifications[name] & NotificationType.PlaySound) != 0)\r
+ PlaySound(_config.Sounds[name], _config.Sounds.Volume);\r
+ if (_config.Pushbullet.On && (_config.Notifications[name] & NotificationType.Pushbullet) != 0)\r
{\r
- if (_timer.Enabled)\r
- {\r
- _queue.Enqueue(new Tuple<string, string, string>(title, message, soundFile));\r
- }\r
- else\r
+ Task.Run(() =>\r
{\r
- _ring(title, message, soundFile);\r
- _timer.Start();\r
- }\r
+ PushBullet.PushNote(_config.Pushbullet.Token, balloonTitle, balloonMessage);\r
+ });\r
}\r
}\r
\r
- private void Ring(string baloonTitle, string baloonMessage, string soundFile)\r
- {\r
- if (_config.FlashWindow)\r
- Win32API.FlashWindow(Handle);\r
- if (_config.ShowBaloonTip)\r
- notifyIconMain.ShowBalloonTip(20000, baloonTitle, baloonMessage, ToolTipIcon.Info);\r
- if (_config.PlaySound)\r
- PlaySound(soundFile, _config.SoundVolume);\r
- }\r
-\r
[DllImport("winmm.dll")]\r
private static extern int mciSendString(String command,\r
StringBuilder buffer, int bufferSize, IntPtr hwndCallback);\r
\r
// ReSharper disable InconsistentNaming\r
private const int MM_MCINOTIFY = 0x3B9;\r
+\r
private const int MCI_NOTIFY_SUCCESSFUL = 1;\r
// ReSharper restore InconsistentNaming\r
\r
\r
private void labelFleet_Click(object sender, EventArgs e)\r
{\r
+ if (!_started)\r
+ return;\r
var fleet = (int)((Label)sender).Tag;\r
if (_currentFleet == fleet)\r
+ {\r
+ if (fleet > 0)\r
+ return;\r
+ _combinedFleet = _sniffer.CombinedFleetType > 0 && !_combinedFleet;\r
+ UpdatePanelShipInfo();\r
return;\r
+ }\r
+ _combinedFleet = false;\r
_currentFleet = fleet;\r
foreach (var label in _labelCheckFleets)\r
label.Visible = false;\r
_labelCheckFleets[fleet].Visible = true;\r
- if (!_started)\r
- return;\r
UpdatePanelShipInfo();\r
}\r
\r
+ private void labelFleet1_MouseHover(object sender, EventArgs e)\r
+ {\r
+ labelFleet1.Text = _currentFleet == 0 && _sniffer.CombinedFleetType > 0 && !_combinedFleet ? "連合" : "第一";\r
+ }\r
+\r
+ private void labelFleet1_MouseLeave(object sender, EventArgs e)\r
+ {\r
+ labelFleet1.Text = _combinedFleet ? "連合" : "第一";\r
+ }\r
+\r
private void labelBucketHistoryButton_Click(object sender, EventArgs e)\r
{\r
if (labelBucketHistory.Visible)\r
UpdateItemInfo();\r
}\r
\r
- private void labelDamgedShipListButton_Click(object sender, EventArgs e)\r
+ private void labelRepairListButton_Click(object sender, EventArgs e)\r
{\r
- if (panelDamagedShipList.Visible)\r
+ if (panelRepairList.Visible)\r
{\r
- panelDamagedShipList.Visible = false;\r
- labelDamgedShipListButton.BackColor = DefaultBackColor;\r
+ panelRepairList.Visible = false;\r
+ labelRepairListButton.BackColor = DefaultBackColor;\r
}\r
else\r
{\r
- panelDamagedShipList.Visible = true;\r
- panelDamagedShipList.BringToFront();\r
- labelDamgedShipListButton.BackColor = SystemColors.ActiveCaption;\r
+ panelRepairList.Visible = true;\r
+ panelRepairList.BringToFront();\r
+ labelRepairListButton.BackColor = SystemColors.ActiveCaption;\r
}\r
}\r
\r
- private void panelDamagedShipList_Click(object sender, EventArgs e)\r
+ private void panelRepairList_Click(object sender, EventArgs e)\r
{\r
- panelDamagedShipList.Visible = false;\r
- labelDamgedShipListButton.BackColor = DefaultBackColor;\r
+ panelRepairList.Visible = false;\r
+ labelRepairListButton.BackColor = DefaultBackColor;\r
}\r
\r
private void ShipListToolStripMenuItem_Click(object sender, EventArgs e)\r
{\r
- _shipListForm.UpdateList();\r
- _shipListForm.Show();\r
- if (_shipListForm.WindowState == FormWindowState.Minimized)\r
- _shipListForm.WindowState = FormWindowState.Normal;\r
- _shipListForm.Activate();\r
+ _listForm.UpdateList();\r
+ _listForm.Show();\r
+ if (_listForm.WindowState == FormWindowState.Minimized)\r
+ _listForm.WindowState = FormWindowState.Normal;\r
+ _listForm.Activate();\r
}\r
\r
private void LogToolStripMenuItem_Click(object sender, EventArgs e)\r
{\r
- Process.Start("http://localhost:" + _config.Log.Listen + "/");\r
+ Process.Start("http://localhost:" + _config.Proxy.Listen + "/");\r
}\r
\r
private void CaptureToolStripMenuItem_Click(object sender, EventArgs e)\r