X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=KancolleSniffer%2FMainForm.cs;h=810d826b6784f312eeecd58638348b8099ac7826;hb=383d4a0e79f45ab2d3ac428d6cbdc27c68163ee8;hp=869df77e69627a7f0a99b8e83cff23f82b23cc97;hpb=e0dc4c955ec5bd2bdd22dc0fbc65194859ac1b8b;p=kancollesniffer%2FKancolleSniffer.git diff --git a/KancolleSniffer/MainForm.cs b/KancolleSniffer/MainForm.cs index 869df77..810d826 100644 --- a/KancolleSniffer/MainForm.cs +++ b/KancolleSniffer/MainForm.cs @@ -14,6 +14,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Globalization; @@ -23,9 +24,16 @@ using System.Net; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; +using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using KancolleSniffer.Log; +using KancolleSniffer.Model; +using KancolleSniffer.Net; +using KancolleSniffer.Util; +using KancolleSniffer.View; using Microsoft.CSharp.RuntimeBinder; +using Timer = System.Windows.Forms.Timer; using static System.Math; namespace KancolleSniffer @@ -36,20 +44,22 @@ namespace KancolleSniffer private readonly Config _config = new Config(); private readonly ConfigDialog _configDialog; private readonly ProxyManager _proxyManager; + private readonly ResizableToolTip _toolTip = new ResizableToolTip {ShowAlways = true}; + private readonly ResizableToolTip _toolTipQuest = new ResizableToolTip {ShowAlways = true, AutoPopDelay = 10000}; + private readonly ResizableToolTip _tooltipCopy = new ResizableToolTip {AutomaticDelay = 0}; private int _currentFleet; private bool _combinedFleet; private readonly Label[] _labelCheckFleets; - private readonly ShipLabels _shipLabels; + private readonly MainFormLabels _mainLabels; private readonly ListForm _listForm; private readonly NotificationManager _notificationManager; private bool _started; + private bool _timerEnabled; private string _debugLogFile; private IEnumerator _playLog; + private DateTime _prev, _now; private readonly ErrorDialog _errorDialog = new ErrorDialog(); - private bool _missionFinishTimeMode; - private bool _ndockFinishTimeMode; - private readonly KancolleDb _kancolleDb = new KancolleDb(); private readonly ErrorLog _errorLog; public MainForm() @@ -65,34 +75,75 @@ namespace KancolleSniffer CurrentAutoScaleDimensions.Height / 12f); SetupFleetClick(); - _shipLabels = new ShipLabels(); - _shipLabels.CreateAkashiTimers(panelShipInfo); - _shipLabels.CreateShipLabels(panelShipInfo, ShowShipOnShipList); - _shipLabels.CreateAkashiTimers7(panel7Ships); - _shipLabels.CreateShipLabels7(panel7Ships, ShowShipOnShipList); - _shipLabels.CreateCombinedShipLabels(panelCombinedFleet, ShowShipOnShipList); - _shipLabels.CreateNDockLabels(panelDock, labelNDock_Click); + _mainLabels = new MainFormLabels(); + _mainLabels.CreateAkashiTimers(panelShipInfo); + _mainLabels.CreateShipLabels(panelShipInfo, ShowShipOnShipList); + _mainLabels.CreateAkashiTimers7(panel7Ships); + _mainLabels.CreateShipLabels7(panel7Ships, ShowShipOnShipList); + _mainLabels.CreateCombinedShipLabels(panelCombinedFleet, ShowShipOnShipList); + _mainLabels.CreateNDockLabels(panelDock, labelNDock_Click); panelRepairList.CreateLabels(panelRepairList_Click); - labelPresetAkashiTimer.BackColor = ShipLabels.ColumnColors[1]; + labelPresetAkashiTimer.BackColor = ShipLabel.ColumnColors[1]; _listForm = new ListForm(_sniffer, _config) {Owner = this}; - _notificationManager = new NotificationManager(Ring); - try - { - _config.Load(); - } - catch (Exception ex) - { - throw new ConfigFileException("設定ファイルが壊れています。", ex); - } + _notificationManager = new NotificationManager(Alarm); + _config.Load(); _proxyManager = new ProxyManager(_config, this); _errorLog = new ErrorLog(_sniffer); _proxyManager.UpdatePacFile(); PerformZoom(); - _shipLabels.AdjustAkashiTimers(); - _sniffer.LoadState(); + _mainLabels.AdjustAkashiTimers(); + LoadData(); _sniffer.RepeatingTimerController = new RepeatingTimerController(_notificationManager, _config); } + /// + /// パネルのz-orderがくるうのを避ける + /// https://stackoverflow.com/a/5777090/1429506 + /// + private void MainForm_Shown(object sender, EventArgs e) + { + // ReSharper disable once NotAccessedVariable + IntPtr handle; + foreach (var panel in new[] {panelShipInfo, panel7Ships, panelCombinedFleet}) + // ReSharper disable once RedundantAssignment + handle = panel.Handle; + } + + private readonly FileSystemWatcher _watcher = new FileSystemWatcher + { + Path = AppDomain.CurrentDomain.BaseDirectory, + NotifyFilter = NotifyFilters.LastWrite + }; + + private readonly Timer _watcherTimer = new Timer {Interval = 1000}; + + private void LoadData() + { + var target = ""; + _sniffer.LoadState(); + _watcher.SynchronizingObject = this; + _watcherTimer.Tick += (sender, ev) => + { + _watcherTimer.Stop(); + switch (target) + { + case "status.xml": + _sniffer.LoadState(); + break; + case "TP.csv": + _sniffer.AdditionalData.LoadTpSpec(); + break; + } + }; + _watcher.Changed += (sender, ev) => + { + target = ev.Name; + _watcherTimer.Stop(); + _watcherTimer.Start(); + }; + _watcher.EnableRaisingEvents = true; + } + private class RepeatingTimerController : Sniffer.IRepeatingTimerController { private readonly NotificationManager _manager; @@ -113,21 +164,14 @@ namespace KancolleSniffer public void Stop(string key, int fleet) => _manager.StopRepeat(key, fleet); - public void Suspend() => _manager.SuspendRepeat(); + public void Suspend(string exception = null) => _manager.SuspendRepeat(exception); public void Resume() => _manager.ResumeRepeat(); } - public class ConfigFileException : Exception - { - public ConfigFileException(string message, Exception innerException) : base(message, innerException) - { - } - } - private void HttpProxy_AfterSessionComplete(HttpProxy.Session session) { - Invoke(new Action(ProcessRequest), session); + BeginInvoke(new Action(ProcessRequest), session); } private void ProcessRequest(HttpProxy.Session session) @@ -137,14 +181,13 @@ namespace KancolleSniffer return; var request = session.Request.BodyAsString; var response = session.Response.BodyAsString; + Privacy.Remove(ref url, ref request, ref response); if (response == null || !response.StartsWith("svdata=")) { WriteDebugLog(url, request, response); return; } - if (_config.KancolleDb.On) - _kancolleDb.Send(url, request, response); - response = UnescapeString(response.Remove(0, "svdata=".Length)); + response = UnEscapeString(response.Remove(0, "svdata=".Length)); WriteDebugLog(url, request, response); ProcessRequestMain(url, request, response); } @@ -162,28 +205,34 @@ namespace KancolleSniffer if (_errorDialog.ShowDialog(this, "艦これに仕様変更があったか、受信内容が壊れています。", _errorLog.GenerateErrorLog(url, request, response, e.ToString())) == DialogResult.Abort) - Application.Exit(); + Exit(); } catch (LogIOException e) { // ReSharper disable once PossibleNullReferenceException if (_errorDialog.ShowDialog(this, e.Message, e.InnerException.ToString()) == DialogResult.Abort) - Application.Exit(); + Exit(); } catch (BattleResultError) { if (_errorDialog.ShowDialog(this, "戦闘結果の計算に誤りがあります。", _errorLog.GenerateBattleErrorLog()) == DialogResult.Abort) - Application.Exit(); + Exit(); } catch (Exception e) { if (_errorDialog.ShowDialog(this, "エラーが発生しました。", _errorLog.GenerateErrorLog(url, request, response, e.ToString())) == DialogResult.Abort) - Application.Exit(); + Exit(); } } + private void Exit() + { + _proxyManager.Shutdown(); + Environment.Exit(1); + } + private void WriteDebugLog(string url, string request, string response) { if (_debugLogFile != null) @@ -193,7 +242,7 @@ namespace KancolleSniffer } } - private string UnescapeString(string s) + private string UnEscapeString(string s) { try { @@ -218,6 +267,8 @@ namespace KancolleSniffer } if (!_started) return; + if (_now == DateTime.MinValue) + _now = DateTime.Now; if ((update & Sniffer.Update.Item) != 0) UpdateItemInfo(); if ((update & Sniffer.Update.Timer) != 0) @@ -232,6 +283,8 @@ namespace KancolleSniffer UpdateShipInfo(); if ((update & Sniffer.Update.Battle) != 0) UpdateBattleInfo(); + if ((update & Sniffer.Update.Cell) != 0) + UpdateCellInfo(); } private void MainForm_Load(object sender, EventArgs e) @@ -240,18 +293,16 @@ namespace KancolleSniffer if (_config.HideOnMinimized && WindowState == FormWindowState.Minimized) ShowInTaskbar = false; if (_config.ShowHpInPercent) - _shipLabels.ToggleHpPercent(); + _mainLabels.ToggleHpPercent(); if (_config.ShipList.Visible) _listForm.Show(); ApplyConfig(); ApplyDebugLogSetting(); ApplyLogSetting(); ApplyProxySetting(); - if (_config.KancolleDb.On) - _kancolleDb.Start(_config.KancolleDb.Token); CheckVersionUp((current, latest) => { - if (double.Parse(latest) <= double.Parse(current)) + if (latest == current) return; linkLabelGuide.Text = $"バージョン{latest}があります。"; linkLabelGuide.LinkArea = new LinkArea(0, linkLabelGuide.Text.Length); @@ -298,11 +349,11 @@ namespace KancolleSniffer e.Cancel = false; _sniffer.FlashLog(); _config.Location = (WindowState == FormWindowState.Normal ? Bounds : RestoreBounds).Location; - _config.ShowHpInPercent = _shipLabels.ShowHpInPercent; + _config.ShowHpInPercent = _mainLabels.ShowHpInPercent; _config.ShipList.Visible = _listForm.Visible && _listForm.WindowState == FormWindowState.Normal; _config.Save(); + _sniffer.SaveState(); _proxyManager.Shutdown(); - _kancolleDb.Stop(); } private void MainForm_Resize(object sender, EventArgs e) @@ -332,6 +383,7 @@ namespace KancolleSniffer { if (_configDialog.ShowDialog(this) == DialogResult.OK) { + _config.Save(); ApplyConfig(); StopRepeatingTimer(_configDialog.RepeatSettingsChanged); } @@ -351,11 +403,16 @@ namespace KancolleSniffer foreach (var control in new Control[] { this, _listForm, labelLogin, linkLabelGuide, - _configDialog, contextMenuStripMain, _errorDialog + _configDialog, _configDialog.NotificationConfigDialog, + contextMenuStripMain, _errorDialog }) { control.Font = new Font(control.Font.FontFamily, control.Font.Size * _config.Zoom / 100); } + foreach (var toolTip in new[]{_toolTip, _toolTipQuest, _tooltipCopy}) + { + toolTip.Font = new Font(toolTip.Font.FontFamily, toolTip.Font.Size * _config.Zoom / 100); + } ShipLabel.LatinFont = new Font("Tahoma", 8f * _config.Zoom / 100); var cur = CurrentAutoScaleDimensions; ShipLabel.ScaleFactor = new SizeF(ShipLabel.ScaleFactor.Width * cur.Width / prev.Width, @@ -373,15 +430,13 @@ namespace KancolleSniffer private void ApplyConfig() { _listForm.TopMost = TopMost = _config.TopMost; - _sniffer.Item.MarginShips = _config.MarginShips; + _sniffer.ShipCounter.Margin = _config.MarginShips; UpdateNumOfShips(); - _sniffer.Item.MarginEquips = _config.MarginEquips; + _sniffer.ItemCounter.Margin = _config.MarginEquips; UpdateNumOfEquips(); _sniffer.Achievement.ResetHours = _config.ResetHours; labelAkashiRepair.Visible = labelAkashiRepairTimer.Visible = labelPresetAkashiTimer.Visible = _config.UsePresetAkashi; - if (_config.KancolleDb.On) - _kancolleDb.Start(_config.KancolleDb.Token); } public void ApplyDebugLogSetting() @@ -397,7 +452,7 @@ namespace KancolleSniffer public void ApplyLogSetting() { LogServer.OutputDir = _config.Log.OutputDir; - LogServer.MaterialHistory = _sniffer.Material.MaterialHistory; + LogServer.LogProcessor = new LogProcessor(_sniffer.Material.MaterialHistory, _sniffer.MapDictionary); _sniffer.EnableLog(_config.Log.On ? LogType.All : LogType.None); _sniffer.MaterialLogInterval = _config.Log.MaterialLogInterval; _sniffer.LogOutputDir = _config.Log.OutputDir; @@ -413,16 +468,19 @@ namespace KancolleSniffer private void timerMain_Tick(object sender, EventArgs e) { - if (_started) + if (_timerEnabled) { try { + _now = DateTime.Now; UpdateTimers(); + NotifyTimers(); + _prev = _now; } catch (Exception ex) { if (_errorDialog.ShowDialog(this, "エラーが発生しました。", ex.ToString()) == DialogResult.Abort) - Application.Exit(); + Exit(); } } if (_playLog == null || _configDialog.Visible) @@ -462,53 +520,55 @@ namespace KancolleSniffer if (!_listForm.Visible) return; var idx = (int)((Control)sender).Tag; - var statuses = _sniffer.GetShipStatuses(_currentFleet); - if (statuses.Length <= idx) - return; - _listForm.ShowShip(statuses[idx].Id); + var ship = (_combinedFleet + ? _sniffer.Fleets[0].Ships.Concat(_sniffer.Fleets[1].Ships).ToArray() + : _sniffer.Fleets[_currentFleet].Ships)[idx]; + if (!ship.Empty) + _listForm.ShowShip(ship.Id); } private void UpdateItemInfo() { UpdateNumOfShips(); UpdateNumOfEquips(); + _notificationManager.Flash(); labelNumOfBuckets.Text = _sniffer.Material.MaterialHistory[(int)Material.Bucket].Now.ToString("D"); UpdateBucketHistory(); var ac = _sniffer.Achievement.Value; if (ac >= 10000) ac = 9999; labelAchievement.Text = ac >= 1000 ? ((int)ac).ToString("D") : ac.ToString("F1"); - toolTipAchievement.SetToolTip(labelAchievement, + _toolTip.SetToolTip(labelAchievement, "今月 " + _sniffer.Achievement.ValueOfMonth.ToString("F1") + "\n" + "EO " + _sniffer.ExMap.Achievement); - UpdateMaterialHistry(); + UpdateMaterialHistory(); if (_listForm.Visible) _listForm.UpdateList(); } private void UpdateNumOfShips() { - var item = _sniffer.Item; - labelNumOfShips.Text = $"{item.NowShips:D}/{item.MaxShips:D}"; - labelNumOfShips.ForeColor = item.TooManyShips ? CUDColor.Red : Color.Black; - if (item.RingShips) + var ship = _sniffer.ShipCounter; + labelNumOfShips.Text = $"{ship.Now:D}/{ship.Max:D}"; + labelNumOfShips.ForeColor = ship.TooMany ? CUDColors.Red : Color.Black; + if (ship.Alarm) { - var message = $"残り{_sniffer.Item.MaxShips - _sniffer.Item.NowShips:D}隻"; + var message = $"残り{ship.Rest:D}隻"; _notificationManager.Enqueue("艦娘数超過", message); - item.RingShips = false; + ship.Alarm = false; } } private void UpdateNumOfEquips() { - var item = _sniffer.Item; - labelNumOfEquips.Text = $"{item.NowEquips:D}/{item.MaxEquips:D}"; - labelNumOfEquips.ForeColor = item.TooManyEquips ? CUDColor.Red : Color.Black; - if (item.RingEquips) + var item = _sniffer.ItemCounter; + labelNumOfEquips.Text = $"{item.Now:D}/{item.Max:D}"; + labelNumOfEquips.ForeColor = item.TooMany ? CUDColors.Red : Color.Black; + if (item.Alarm) { - var message = $"残り{_sniffer.Item.MaxEquips - _sniffer.Item.NowEquips:D}個"; + var message = $"残り{item.Rest:D}個"; _notificationManager.Enqueue("装備数超過", message); - item.RingEquips = false; + item.Alarm = false; } } @@ -520,7 +580,7 @@ namespace KancolleSniffer labelBucketHistory.Text = $"{day:+#;-#;±0} 今日\n{week:+#;-#;±0} 今週"; } - private void UpdateMaterialHistry() + private void UpdateMaterialHistory() { var labels = new[] {labelFuelHistory, labelBulletHistory, labelSteelHistory, labelBouxiteHistory}; var text = new[] {"燃料", "弾薬", "鋼材", "ボーキ"}; @@ -545,59 +605,125 @@ namespace KancolleSniffer private void UpdateShipInfo() { + SetCurrentFleet(); + SetCombined(); UpdatePanelShipInfo(); NotifyDamagedShip(); UpdateChargeInfo(); UpdateRepairList(); + UpdateMissionLabels(); if (_listForm.Visible) _listForm.UpdateList(); } + private bool _inSortie; + + private void SetCurrentFleet() + { + var states = _sniffer.Fleets.Select(fleet => fleet.State).ToArray(); + var inSortie = states.Any(state => state >= FleetState.Sortie); + if (_inSortie || !inSortie) + { + _inSortie = inSortie; + return; + } + _inSortie = true; + if (states[0] == FleetState.Sortie && states[1] == FleetState.Sortie) + { + _combinedFleet = true; + _currentFleet = 0; + } + else + { + _combinedFleet = false; + _currentFleet = Array.FindIndex(states, state => state >= FleetState.Sortie); + } + } + + private bool _prevCombined; + + private void SetCombined() + { + if (_sniffer.IsCombinedFleet && !_prevCombined) + { + _combinedFleet = true; + _currentFleet = 0; + } + _prevCombined = _sniffer.IsCombinedFleet; + } + private void UpdatePanelShipInfo() { - var statuses = _sniffer.GetShipStatuses(_currentFleet); - panel7Ships.Visible = statuses.Length == 7; - _shipLabels.SetShipLabels(statuses); - if (_sniffer.CombinedFleetType == 0) + var fleets = _sniffer.Fleets; + var ships = fleets[_currentFleet].ActualShips; + panel7Ships.Visible = ships.Count == 7; + _mainLabels.SetShipLabels(ships); + if (!_sniffer.IsCombinedFleet) _combinedFleet = false; - labelFleet1.Text = _combinedFleet ? "連合" : "第一"; + labelFleet1.Text = _combinedFleet ? CombinedName : "第一"; panelCombinedFleet.Visible = _combinedFleet; if (_combinedFleet) - _shipLabels.SetCombinedShipLabels(_sniffer.GetShipStatuses(0), _sniffer.GetShipStatuses(1)); + _mainLabels.SetCombinedShipLabels(fleets[0].ActualShips, fleets[1].ActualShips); + for (var i = 0; i < _labelCheckFleets.Length; i++) + _labelCheckFleets[i].Visible = _currentFleet == i; UpdateAkashiTimer(); - UpdateFighterPower(_combinedFleet); + var battle = _sniffer.Battle; + UpdateFighterPower(_combinedFleet && (battle.BattleState == BattleState.None || battle.EnemyIsCombined)); UpdateLoS(); UpdateCondTimers(); } + private string CombinedName + { + get + { + switch (_sniffer.Fleets[0].CombinedType) + { + case CombinedType.Carrier: + return "機動"; + case CombinedType.Surface: + return "水上"; + case CombinedType.Transport: + return "輸送"; + default: + return "連合"; + } + } + } + private void NotifyDamagedShip() { - if (_sniffer.BadlyDamagedShips.Any()) - _notificationManager.Enqueue("大破警告", string.Join(" ", _sniffer.BadlyDamagedShips)); + if (!_sniffer.BadlyDamagedShips.Any()) + return; + _notificationManager.StopRepeat("大破警告"); + SetNotification("大破警告", string.Join(" ", _sniffer.BadlyDamagedShips)); + _notificationManager.Flash(); } public void UpdateFighterPower(bool combined) { + var fleets = _sniffer.Fleets; var fp = combined - ? _sniffer.GetFighterPower(0).Zip(_sniffer.GetFighterPower(1), (a, b) => a + b).ToArray() - : _sniffer.GetFighterPower(_currentFleet); + ? fleets[0].FighterPower.Zip(fleets[1].FighterPower, (a, b) => a + b).ToArray() + : fleets[_currentFleet].FighterPower; labelFighterPower.Text = fp[0].ToString("D"); var cr = combined - ? _sniffer.GetContactTriggerRate(0) + _sniffer.GetContactTriggerRate(1) - : _sniffer.GetContactTriggerRate(_currentFleet); + ? fleets[0].ContactTriggerRate + fleets[1].ContactTriggerRate + : fleets[_currentFleet].ContactTriggerRate; var text = "制空: " + (fp[0] == fp[1] ? $"{fp[0]}" : $"{fp[0]}~{fp[1]}") + $" 触接: {cr * 100:f1}"; - toolTipFighterPower.SetToolTip(labelFighterPower, text); - toolTipFighterPower.SetToolTip(labelFighterPowerCaption, text); + _toolTip.SetToolTip(labelFighterPower, text); + _toolTip.SetToolTip(labelFighterPowerCaption, text); } private void UpdateLoS() { - labelLoS.Text = RoundDown(_sniffer.GetFleetLineOfSights(_currentFleet, 1)).ToString("F1"); - var text = $"係数3: {RoundDown(_sniffer.GetFleetLineOfSights(_currentFleet, 3)):F1}\r\n" + - $"係数4: {RoundDown(_sniffer.GetFleetLineOfSights(_currentFleet, 4)):F1}"; - toolTipLoS.SetToolTip(labelLoS, text); - toolTipLoS.SetToolTip(labelLoSCaption, text); + var fleet = _sniffer.Fleets[_currentFleet]; + labelLoS.Text = RoundDown(fleet.GetLineOfSights(1)).ToString("F1"); + var text = $"係数3: {RoundDown(fleet.GetLineOfSights(3)):F1}\r\n" + + $"係数4: {RoundDown(fleet.GetLineOfSights(4)):F1}"; + _toolTip.SetToolTip(labelLoS, text); + _toolTip.SetToolTip(labelLoSCaption, text); } private double RoundDown(double number) @@ -608,16 +734,21 @@ namespace KancolleSniffer private void UpdateBattleInfo() { ResetBattleInfo(); + _listForm.UpdateBattleResult(); + _listForm.UpdateAirBattleResult(); if (_sniffer.Battle.BattleState == BattleState.None) return; panelBattleInfo.BringToFront(); var battle = _sniffer.Battle; - labelFormation.Text = battle.Formation; + labelFormation.Text = new[] {"同航戦", "反航戦", "T字有利", "T字不利"}[battle.Formation[2] - 1]; UpdateBattleFighterPower(); - if (_config.AlwaysShowResultRank) + if ((_config.Spoilers & Spoiler.ResultRank) != 0) ShowResultRank(); - if (_sniffer.Battle.BattleState == BattleState.Day) - _listForm.UpdateAirBattleResult(); + } + + private void UpdateCellInfo() + { + _listForm.UpdateCellInfo(); } private void ResetBattleInfo() @@ -637,12 +768,17 @@ namespace KancolleSniffer if (power.AirCombat != power.Interception) { var text = "防空: " + power.Interception + power.UnknownMark; - toolTipFighterPower.SetToolTip(labelEnemyFighterPower, text); - toolTipFighterPower.SetToolTip(labelEnemyFighterPowerCaption, text); + _toolTip.SetToolTip(labelEnemyFighterPower, text); + _toolTip.SetToolTip(labelEnemyFighterPowerCaption, text); + } + else + { + _toolTip.SetToolTip(labelEnemyFighterPower, ""); + _toolTip.SetToolTip(labelEnemyFighterPowerCaption, ""); } - UpdateFighterPower(_sniffer.CombinedFleetType > 0 && battle.EnemyIsCombined); + UpdateFighterPower(_sniffer.IsCombinedFleet && battle.EnemyIsCombined); labelFighterPower.ForeColor = new[] - {DefaultForeColor, DefaultForeColor, CUDColor.Blue, CUDColor.Green, CUDColor.Orange, CUDColor.Red}[ + {DefaultForeColor, DefaultForeColor, CUDColors.Blue, CUDColors.Green, CUDColors.Orange, CUDColors.Red}[ battle.AirControlLevel + 1]; } @@ -664,7 +800,7 @@ namespace KancolleSniffer for (var i = 0; i < fuelSq.Length; i++) { - var stat = _sniffer.ChargeStatuses[i]; + var stat = _sniffer.Fleets[i].ChargeStatus; fuelSq[i].ImageIndex = stat.Fuel; bullSq[i].ImageIndex = stat.Bull; } @@ -672,51 +808,82 @@ namespace KancolleSniffer private void UpdateNDocLabels() { - _shipLabels.SetNDockLabels(_sniffer.NDock); + _mainLabels.SetNDockLabels(_sniffer.NDock); + SetNDockLabel(); } + private void SetNDockLabel() + { + labelNDock.Text = (_config.ShowEndTime & TimerKind.NDock) != 0 ? "入渠終了" : "入渠"; + } private void labelNDock_Click(object sender, EventArgs e) { - _ndockFinishTimeMode = !_ndockFinishTimeMode; + _config.ShowEndTime ^= TimerKind.NDock; + SetNDockLabel(); UpdateTimers(); } private void UpdateMissionLabels() { - foreach (var entry in - new[] {labelMissionName1, labelMissionName2, labelMissionName3}.Zip(_sniffer.Missions, - (label, mission) => new {label, mission.Name})) - entry.label.Text = entry.Name; + var nameLabels = new[] {labelMissionName1, labelMissionName2, labelMissionName3}; + var paramsLabels = new[] {labelMissionParams1, labelMissionParams2, labelMissionParams3}; + var names = _sniffer.Missions.Select(mission => mission.Name).ToArray(); + for (var i = 0; i < ShipInfo.FleetCount - 1; i++) + { + paramsLabels[i].Visible = false; + if (string.IsNullOrEmpty(names[i])) + { + paramsLabels[i].Text = GenerateFleetParamsForMission(i + 1); + paramsLabels[i].Visible = true; + } + nameLabels[i].Text = names[i]; + } + SetMissionLabel(); + } + + private void SetMissionLabel() + { + labelMission.Text = (_config.ShowEndTime & TimerKind.Mission) != 0 ? "遠征終了" : "遠征"; + } + + private string GenerateFleetParamsForMission(int fleetNumber) + { + var result = new List(); + var fleet = _sniffer.Fleets[fleetNumber]; + var kira = fleet.Ships.Count(ship => ship.Cond > 49); + var plus = fleet.Ships[0].Cond > 49; + if (kira > 0) + result.Add($"キラ{kira}{(plus ? "+" : "")}"); + var drums = fleet.Ships.SelectMany(ship => ship.Slot).Count(item => item.Spec.IsDrum); + var drumShips = fleet.Ships.Count(ship => ship.Slot.Any(item => item.Spec.IsDrum)); + if (drums > 0) + result.Add($"ド{drums}({drumShips}隻)"); + if (fleet.DaihatsuBonus > 0) + result.Add($"ダ{fleet.DaihatsuBonus * 100:f1}%"); + return string.Join(" ", result); } private void labelMission_Click(object sender, EventArgs e) { - _missionFinishTimeMode = !_missionFinishTimeMode; + _config.ShowEndTime ^= TimerKind.Mission; + SetMissionLabel(); UpdateTimers(); } - private DateTime _prev, _now; - private void UpdateTimers() { - _prev = _now; - _now = DateTime.Now; var mission = new[] {labelMission1, labelMission2, labelMission3}; for (var i = 0; i < mission.Length; i++) { var entry = _sniffer.Missions[i]; SetTimerColor(mission[i], entry.Timer, _now); - mission[i].Text = entry.Timer.ToString(_now, _missionFinishTimeMode); - if (entry.Timer.CheckRing(_prev, _now)) - SetNotification("遠征終了", i + 1, entry.Name); + mission[i].Text = entry.Timer.ToString(_now, (_config.ShowEndTime & TimerKind.Mission) != 0); } for (var i = 0; i < _sniffer.NDock.Length; i++) { var entry = _sniffer.NDock[i]; - _shipLabels.SetNDockTimer(i, entry.Timer, _now, _ndockFinishTimeMode); - if (entry.Timer.CheckRing(_prev, _now)) - SetNotification("入渠終了", i, entry.Name); + _mainLabels.SetNDockTimer(i, entry.Timer, _now, (_config.ShowEndTime & TimerKind.NDock) != 0); } var kdock = new[] {labelConstruct1, labelConstruct2, labelConstruct3, labelConstruct4}; for (var i = 0; i < kdock.Length; i++) @@ -724,16 +891,53 @@ namespace KancolleSniffer var timer = _sniffer.KDock[i]; SetTimerColor(kdock[i], timer, _now); kdock[i].Text = timer.ToString(_now); - if (timer.CheckRing(_prev, _now)) - SetNotification("建造完了", $"第{i + 1:D}ドック"); } UpdateCondTimers(); UpdateAkashiTimer(); + _timerEnabled = true; } - private void SetTimerColor(Label label, RingTimer timer, DateTime now) + private void NotifyTimers() { - label.ForeColor = timer.IsFinished(now) ? CUDColor.Red : Color.Black; + for (var i = 0; i < _sniffer.Missions.Length; i++) + { + var entry = _sniffer.Missions[i]; + if (entry.Name == "前衛支援任務" || entry.Name == "艦隊決戦支援任務") + continue; + CheckAlarm("遠征終了", entry.Timer, i + 1, entry.Name); + } + for (var i = 0; i < _sniffer.NDock.Length; i++) + { + var entry = _sniffer.NDock[i]; + CheckAlarm("入渠終了", entry.Timer, i, entry.Name); + } + for (var i = 0; i < _sniffer.KDock.Length; i++) + { + var timer = _sniffer.KDock[i]; + CheckAlarm("建造完了", timer, i, ""); + } + NotifyCondTimers(); + NotifyAkashiTimer(); + _notificationManager.Flash(); + } + + private void CheckAlarm(string key, AlarmTimer timer, int fleet, string subject) + { + if (timer.CheckAlarm(_prev, _now)) + { + SetNotification(key, fleet, subject); + return; + } + var pre = TimeSpan.FromSeconds(_config.Notifications[key].PreliminaryPeriod); + if (pre == TimeSpan.Zero) + return; + if (timer.CheckAlarm(_prev + pre, _now + pre)) + SetPreNotification(key, fleet, subject); + } + + private void SetTimerColor(Label label, AlarmTimer timer, DateTime now) + { + label.ForeColor = timer.IsFinished(now) ? CUDColors.Red : Color.Black; } private void UpdateCondTimers() @@ -766,50 +970,47 @@ namespace KancolleSniffer { labelCondTimerTitle.Text = "cond49まで"; labelCondTimer.Text = (span >= TimeSpan.Zero ? span : TimeSpan.Zero).ToString(@"mm\:ss"); - labelCondTimer.ForeColor = span <= TimeSpan.Zero ? CUDColor.Red : DefaultForeColor; + labelCondTimer.ForeColor = span <= TimeSpan.Zero ? CUDColors.Red : DefaultForeColor; } + } + + private void NotifyCondTimers() + { var notice = _sniffer.GetConditionNotice(_prev, _now); - if (notice == null) - return; + var pre = TimeSpan.FromSeconds(_config.Notifications["疲労回復"].PreliminaryPeriod); + var preNotice = pre == TimeSpan.Zero + ? new int[ShipInfo.FleetCount] + : _sniffer.GetConditionNotice(_prev + pre, _now + pre); for (var i = 0; i < ShipInfo.FleetCount; i++) { - if (!_config.NotifyConditions.Contains(notice[i])) - return; - SetNotification("疲労回復" + notice[i], i, "cond" + notice[i]); + if (_config.NotifyConditions.Contains(notice[i])) + { + SetNotification("疲労回復" + notice[i], i, "cond" + notice[i]); + } + else if (_config.NotifyConditions.Contains(preNotice[i])) + { + SetPreNotification("疲労回復" + preNotice[i], i, "cond" + notice[i]); + } } } - private void SetNotification(string key, string subject) - { - SetNotification(key, 0, subject); - } - - private void SetNotification(string key, int fleet, string subject) - { - var spec = _config.Notifications[_notificationManager.KeyToName(key)]; - _notificationManager.Enqueue(key, fleet, subject, - (spec.Flags & _config.NotificationFlags & NotificationType.Repeat) == 0 ? 0 : spec.RepeatInterval); - } - private void UpdateAkashiTimer() { if (_config.UsePresetAkashi) UpdatePresetAkashiTimer(); - var statuses = _sniffer.GetShipStatuses(_currentFleet); - _shipLabels.SetAkashiTimer(statuses, - _sniffer.AkashiTimer.GetTimers(_currentFleet)); - NotifyAkashiTimer(); + _mainLabels.SetAkashiTimer(_sniffer.Fleets[_currentFleet].ActualShips, + _sniffer.AkashiTimer.GetTimers(_currentFleet, _now)); } private void UpdatePresetAkashiTimer() { var akashi = _sniffer.AkashiTimer; - var span = akashi.PresetDeckTimer; - var color = span == TimeSpan.Zero && akashi.CheckPresetReparing() ? CUDColor.Red : DefaultForeColor; + var span = akashi.GetPresetDeckTimer(_now); + var color = span == TimeSpan.Zero && akashi.CheckPresetRepairing() ? CUDColors.Red : DefaultForeColor; var text = span == TimeSpan.MinValue ? "" : span.ToString(@"mm\:ss"); labelAkashiRepairTimer.ForeColor = color; labelAkashiRepairTimer.Text = text; - if (akashi.CheckPresetReparing() && !akashi.CheckReparing(_currentFleet)) + if (akashi.CheckPresetRepairing() && !akashi.CheckRepairing(_currentFleet, _now)) { labelPresetAkashiTimer.ForeColor = color; labelPresetAkashiTimer.Text = text; @@ -830,15 +1031,17 @@ namespace KancolleSniffer _notificationManager.StopRepeat("泊地修理"); return; } - if (!akashi.CheckReparing() && !(akashi.CheckPresetReparing() && _config.UsePresetAkashi)) + if (!akashi.CheckRepairing(_now) && !(akashi.CheckPresetRepairing() && _config.UsePresetAkashi)) { _notificationManager.StopRepeat("泊地修理"); return; } + var skipPreliminary = false; if (msgs[0].Proceeded == "20分経過しました。") { SetNotification("泊地修理20分経過", msgs[0].Proceeded); msgs[0].Proceeded = ""; + skipPreliminary = true; // 修理完了がいるかもしれないので続ける } for (var i = 0; i < ShipInfo.FleetCount; i++) @@ -848,6 +1051,30 @@ namespace KancolleSniffer if (msgs[i].Completed != "") SetNotification("泊地修理完了", i, msgs[i].Completed); } + var pre = TimeSpan.FromSeconds(_config.Notifications["泊地修理20分経過"].PreliminaryPeriod); + if (skipPreliminary || pre == TimeSpan.Zero) + return; + if ((msgs = akashi.GetNotice(_prev + pre, _now + pre))[0].Proceeded == "20分経過しました。") + SetPreNotification("泊地修理20分経過", 0, msgs[0].Proceeded); + } + + private void SetNotification(string key, string subject) + { + SetNotification(key, 0, subject); + } + + private void SetNotification(string key, int fleet, string subject) + { + var spec = _config.Notifications[_notificationManager.KeyToName(key)]; + _notificationManager.Enqueue(key, fleet, subject, + (spec.Flags & _config.NotificationFlags & NotificationType.Repeat) == 0 ? 0 : spec.RepeatInterval); + } + + private void SetPreNotification(string key, int fleet, string subject) + { + var spec = _config.Notifications[_notificationManager.KeyToName(key)]; + if ((spec.Flags & NotificationType.Preliminary) != 0) + _notificationManager.Enqueue(key, fleet, subject, 0, true); } private void UpdateRepairList() @@ -863,6 +1090,11 @@ namespace KancolleSniffer labelQuestColor6 }; var name = new[] {labelQuest1, labelQuest2, labelQuest3, labelQuest4, labelQuest5, labelQuest6}; + var count = new[] + { + labelQuestCount1, labelQuestCount2, labelQuestCount3, labelQuestCount4, labelQuestCount5, + labelQuestCount6 + }; var progress = new[] {labelProgress1, labelProgress2, labelProgress3, labelProgress4, labelProgress5, labelProgress6}; var quests = _sniffer.Quests; @@ -873,16 +1105,30 @@ namespace KancolleSniffer category[i].BackColor = quests[i].Color; name[i].Text = quests[i].Name; progress[i].Text = $"{quests[i].Progress:D}%"; + _toolTipQuest.SetToolTip(name[i], quests[i].ToToolTip()); + var c = quests[i].Count; + if (c.Id == 0) + { + count[i].Text = ""; + count[i].ForeColor = Color.Black; + _toolTip.SetToolTip(count[i], ""); + continue; + } + count[i].Text = " " + c; + count[i].ForeColor = c.Cleared ? CUDColors.Green : Color.Black; + _toolTip.SetToolTip(count[i], c.ToToolTip()); } else { category[i].BackColor = DefaultBackColor; - name[i].Text = progress[i].Text = ""; + name[i].Text = count[i].Text = progress[i].Text = ""; + _toolTipQuest.SetToolTip(name[i], ""); + _toolTip.SetToolTip(count[i], ""); } } } - private void Ring(string balloonTitle, string balloonMessage, string name) + private void Alarm(string balloonTitle, string balloonMessage, string name) { var flags = _config.Notifications[name].Flags; var effective = _config.NotificationFlags & _config.Notifications[name].Flags; @@ -911,9 +1157,10 @@ namespace KancolleSniffer [DllImport("winmm.dll")] private static extern int mciSendString(String command, - StringBuilder buffer, int bufferSize, IntPtr hwndCallback); + StringBuilder buffer, int bufferSize, IntPtr hWndCallback); // ReSharper disable InconsistentNaming + // ReSharper disable once IdentifierTypo private const int MM_MCINOTIFY = 0x3B9; private const int MCI_NOTIFY_SUCCESSFUL = 1; @@ -947,10 +1194,14 @@ namespace KancolleSniffer }; foreach (var a in labels) { - for (var fleet = 0; fleet < labels[0].Length; fleet++) + a[0].Tag = 0; + a[0].Click += labelFleet1_Click; + a[0].DoubleClick += labelFleet1_DoubleClick; + for (var fleet = 1; fleet < labels[0].Length; fleet++) { a[fleet].Tag = fleet; a[fleet].Click += labelFleet_Click; + a[fleet].DoubleClick += labelFleet_DoubleClick; } } } @@ -961,32 +1212,82 @@ namespace KancolleSniffer return; var fleet = (int)((Label)sender).Tag; if (_currentFleet == fleet) - { - if (fleet > 0) - return; - _combinedFleet = _sniffer.CombinedFleetType > 0 && !_combinedFleet; - UpdatePanelShipInfo(); return; - } _combinedFleet = false; _currentFleet = fleet; - foreach (var label in _labelCheckFleets) - label.Visible = false; - _labelCheckFleets[fleet].Visible = true; + UpdatePanelShipInfo(); + } + + private readonly SemaphoreSlim _clickSemaphore = new SemaphoreSlim(1); + private readonly SemaphoreSlim _doubleClickSemaphore = new SemaphoreSlim(0); + + private async void labelFleet1_Click(object sender, EventArgs e) + { + if (!_started) + return; + if (_currentFleet != 0) + { + labelFleet_Click(sender, e); + return; + } + if (!_clickSemaphore.Wait(0)) + return; + try + { + if (await _doubleClickSemaphore.WaitAsync(SystemInformation.DoubleClickTime)) + return; + } + finally + { + _clickSemaphore.Release(); + } + _combinedFleet = _sniffer.IsCombinedFleet && !_combinedFleet; UpdatePanelShipInfo(); } private void labelFleet1_MouseHover(object sender, EventArgs e) { - labelFleet1.Text = _currentFleet == 0 && _sniffer.CombinedFleetType > 0 && !_combinedFleet ? "連合" : "第一"; + labelFleet1.Text = _currentFleet == 0 && _sniffer.IsCombinedFleet && !_combinedFleet ? "連合" : "第一"; } private void labelFleet1_MouseLeave(object sender, EventArgs e) { - labelFleet1.Text = _combinedFleet ? "連合" : "第一"; + labelFleet1.Text = _combinedFleet ? CombinedName : "第一"; + } + + private void labelFleet_DoubleClick(object sender, EventArgs e) + { + if (!_started) + return; + var fleet = (int)((Label)sender).Tag; + var text = TextGenerator.GenerateFleetData(_sniffer, fleet); + CopyFleetText(text, (Label)sender); + } + + private void labelFleet1_DoubleClick(object sender, EventArgs e) + { + if (!_started) + return; + _doubleClickSemaphore.Release(); + var text = TextGenerator.GenerateFleetData(_sniffer, 0); + if (_combinedFleet) + text += TextGenerator.GenerateFleetData(_sniffer, 1); + CopyFleetText(text, (Label)sender); } - private readonly Color _activeButtonColor = Color.FromArgb(152, 179, 208); + private void CopyFleetText(string text, Label fleetButton) + { + if (string.IsNullOrEmpty(text)) + return; + Clipboard.SetText(text); + _tooltipCopy.Active = true; + _tooltipCopy.Show("コピーしました。", fleetButton); + Task.Run(async () => + { + await Task.Delay(1000); + _tooltipCopy.Active = false; + }); + } private void labelBucketHistoryButton_Click(object sender, EventArgs e) { @@ -999,7 +1300,7 @@ namespace KancolleSniffer { labelBucketHistory.Visible = true; labelBucketHistory.BringToFront(); - labelBucketHistoryButton.BackColor = _activeButtonColor; + labelBucketHistoryButton.BackColor = CustomColors.ActiveButtonColor; } } @@ -1020,7 +1321,7 @@ namespace KancolleSniffer { panelMaterialHistory.Visible = true; panelMaterialHistory.BringToFront(); - labelMaterialHistoryButton.BackColor = _activeButtonColor; + labelMaterialHistoryButton.BackColor = CustomColors.ActiveButtonColor; } } @@ -1030,7 +1331,7 @@ namespace KancolleSniffer labelMaterialHistoryButton.BackColor = DefaultBackColor; } - public void ResetAchievemnt() + public void ResetAchievement() { _sniffer.Achievement.Reset(); UpdateItemInfo(); @@ -1047,7 +1348,7 @@ namespace KancolleSniffer { panelRepairList.Visible = true; panelRepairList.BringToFront(); - labelRepairListButton.BackColor = _activeButtonColor; + labelRepairListButton.BackColor = CustomColors.ActiveButtonColor; } } @@ -1071,6 +1372,37 @@ namespace KancolleSniffer Process.Start("http://localhost:" + _config.Proxy.Listen + "/"); } + private void labelClearQuest_Click(object sender, EventArgs e) + { + _sniffer.ClearQuests(); + UpdateQuestList(); + } + + private void labelClearQuest_MouseDown(object sender, MouseEventArgs e) + { + labelClearQuest.BackColor = CustomColors.ActiveButtonColor; + } + + private void labelClearQuest_MouseUp(object sender, MouseEventArgs e) + { + labelClearQuest.BackColor = DefaultBackColor; + } + + private void labelQuest_DoubleClick(object sender, EventArgs e) + { + var label = (Label)sender; + if (string.IsNullOrEmpty(label.Text)) + return; + Clipboard.SetText(label.Text); + _tooltipCopy.Active = true; + _tooltipCopy.Show("コピーしました。", label); + Task.Run(async () => + { + await Task.Delay(1000); + _tooltipCopy.Active = false; + }); + } + private void CaptureToolStripMenuItem_Click(object sender, EventArgs e) { try @@ -1081,6 +1413,9 @@ namespace KancolleSniffer catch (FileNotFoundException) { } + catch (Win32Exception) + { + } } } } \ No newline at end of file