X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=KancolleSniffer%2FMainForm.cs;h=817bdbf48e0ec8d4cf9ac0fc015c89cb9331a845;hb=f005e6c43866d5cefeeead66e559b460f6fc0cea;hp=153cea962ad6fac01ab3ae7ae994ff41d0f37996;hpb=9f8afeb856d63f85ef9e763d1b0d5b5fc820116b;p=kancollesniffer%2FKancolleSniffer.git diff --git a/KancolleSniffer/MainForm.cs b/KancolleSniffer/MainForm.cs index 153cea9..817bdbf 100644 --- a/KancolleSniffer/MainForm.cs +++ b/KancolleSniffer/MainForm.cs @@ -27,6 +27,7 @@ using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; +using DynaJson; using KancolleSniffer.Log; using KancolleSniffer.Model; using KancolleSniffer.Net; @@ -34,6 +35,7 @@ using KancolleSniffer.Util; using KancolleSniffer.View; using Microsoft.CSharp.RuntimeBinder; using static System.Math; +using Clipboard = KancolleSniffer.Util.Clipboard; using Timer = System.Windows.Forms.Timer; namespace KancolleSniffer @@ -46,9 +48,10 @@ namespace KancolleSniffer private readonly ResizableToolTip _tooltipCopy = new ResizableToolTip {ShowAlways = false, AutomaticDelay = 0}; private int _currentFleet; private bool _combinedFleet; - private MainFormLabels _mainLabels; + private readonly MainShipLabels _mainLabels = new MainShipLabels(); private NumberAndHistory _numberAndHistory; - private readonly ListForm _listForm; + private readonly ListFormGroup _listFormGroup; + private readonly NotificationManager _notificationManager; private bool _started; private bool _timerEnabled; @@ -68,7 +71,7 @@ namespace KancolleSniffer HttpProxy.AfterSessionComplete += HttpProxy_AfterSessionComplete; Config.Load(); _configDialog = new ConfigDialog(this); - _listForm = new ListForm(this); + _listFormGroup = new ListFormGroup(this); _notificationManager = new NotificationManager(Alarm); SetupView(_notificationManager); _proxyManager = new ProxyManager(this); @@ -84,31 +87,36 @@ namespace KancolleSniffer SetupFleetClick(); CreateMainLabels(); CreateNumberAndHistory(manager); - labelPresetAkashiTimer.BackColor = ShipLabel.ColumnColors[1]; + labelPresetAkashiTimer.BackColor = CustomColors.ColumnColors.Bright; + SetupQuestPanel(); panelRepairList.CreateLabels(panelRepairList_Click); - questPanel.NameLabelDoubleClick += labelQuest_DoubleClick; + ndockPanel.SetClickHandler(labelNDock_Click); + missionPanel.SetClickHandler(labelMission_Click); PerformZoom(); - _mainLabels.AdjustAkashiTimers(); } private void SetScaleFactorOfDpiScaling() { var autoScaleDimensions = new SizeF(6f, 12f); // AutoScaleDimensionの初期値 - ShipLabel.ScaleFactor = new SizeF(CurrentAutoScaleDimensions.Width / autoScaleDimensions.Width, + Scaler.Factor = new SizeF(CurrentAutoScaleDimensions.Width / autoScaleDimensions.Width, CurrentAutoScaleDimensions.Height / autoScaleDimensions.Height); } + private void SetupQuestPanel() + { + int prevHeight = questPanel.Height; + questPanel.CreateLabels(Config.QuestLines, labelQuest_DoubleClick); + Height += questPanel.Height - prevHeight; + } + private void CreateMainLabels() { - _mainLabels = new MainFormLabels(new MainFormPanels + _mainLabels.CreateAllShipLabels(new MainShipPanels { PanelShipInfo = panelShipInfo, Panel7Ships = panel7Ships, - PanelCombinedFleet = panelCombinedFleet, - PanelNDock = panelDock - }); - _mainLabels.CreateAllShipLabels(ShowShipOnShipList); - _mainLabels.CreateNDockLabels(labelNDock_Click); + PanelCombinedFleet = panelCombinedFleet + }, ShowShipOnShipList); } private void CreateNumberAndHistory(NotificationManager manager) @@ -248,7 +256,7 @@ namespace KancolleSniffer { try { - UpdateInfo(Sniffer.Sniff(url, request, JsonParser.Parse(response))); + UpdateInfo(Sniffer.Sniff(url, request, JsonObject.Parse(response))); _errorLog.CheckBattleApi(url, request, response); } @@ -349,7 +357,7 @@ namespace KancolleSniffer if (Config.ShowHpInPercent) _mainLabels.ToggleHpPercent(); if (Config.ShipList.Visible) - _listForm.Show(); + _listFormGroup.Show(); ApplyConfig(); ApplyDebugLogSetting(); ApplyLogSetting(); @@ -391,16 +399,14 @@ namespace KancolleSniffer { if (!Config.ExitSilently) { - using (var dialog = new ConfirmDialog()) + using var dialog = new ConfirmDialog(); + if (dialog.ShowDialog(this) != DialogResult.Yes) { - if (dialog.ShowDialog(this) != DialogResult.Yes) - { - e.Cancel = true; - return; - } + e.Cancel = true; + return; } } - _listForm.Close(); + _listFormGroup.Close(); Sniffer.FlashLog(); Config.Location = (WindowState == FormWindowState.Normal ? Bounds : RestoreBounds).Location; Config.ShowHpInPercent = _mainLabels.ShowHpInPercent; @@ -411,26 +417,15 @@ namespace KancolleSniffer private void MainForm_Resize(object sender, EventArgs e) { - if (_listForm == null) // DPIが100%でないときにInitializeComponentから呼ばれるので + if (_listFormGroup == null) // DPIが100%でないときにInitializeComponentから呼ばれるので return; SuppressActivate.Start(); if (WindowState == FormWindowState.Minimized) { - _listForm.WindowState = FormWindowState.Minimized; if (Config.HideOnMinimized) - _listForm.ShowInTaskbar = ShowInTaskbar = false; - } - else if (_listForm.WindowState == FormWindowState.Minimized) - { - DoPaint(); - _listForm.ShowInTaskbar = true; - _listForm.WindowState = FormWindowState.Normal; + ShowInTaskbar = false; } - } - - private void DoPaint() - { - Application.DoEvents(); + _listFormGroup.Main.ChangeWindowState(WindowState); } public TimeOutChecker SuppressActivate = new TimeOutChecker(); @@ -439,10 +434,16 @@ namespace KancolleSniffer { if (SuppressActivate.Check()) return; - if (WindowState == FormWindowState.Minimized) - return; - _listForm.Owner = null; - Owner = _listForm; + if (NeedRaise) + RaiseBothWindows(); + } + + private bool NeedRaise => _listFormGroup.Visible && WindowState != FormWindowState.Minimized; + + private void RaiseBothWindows() + { + _listFormGroup.Main.Owner = null; + Owner = _listFormGroup.Main; BringToFront(); Owner = null; } @@ -475,7 +476,7 @@ namespace KancolleSniffer { ShowInTaskbar = true; WindowState = FormWindowState.Normal; - TopMost = _listForm.TopMost = Config.TopMost; // 最前面に表示されなくなることがあるのを回避する + TopMost = _listFormGroup.TopMost = Config.TopMost; // 最前面に表示されなくなることがあるのを回避する } private void ExitToolStripMenuItem_Click(object sender, EventArgs e) @@ -502,25 +503,40 @@ namespace KancolleSniffer private void PerformZoom() { if (Config.Zoom == 100) + { + ShipLabel.Name.BaseFont = Font; + ShipLabel.Name.LatinFont = LatinFont(); return; + } var prev = CurrentAutoScaleDimensions; foreach (var control in new Control[] { - this, _listForm, labelLogin, linkLabelGuide, + this, labelLogin, linkLabelGuide, _configDialog, _configDialog.NotificationConfigDialog, contextMenuStripMain, _errorDialog }) { - control.Font = new Font(control.Font.FontFamily, control.Font.Size * Config.Zoom / 100); + control.Font = ZoomFont(control.Font); } + _listFormGroup.Font = ZoomFont(_listFormGroup.Font); foreach (var toolTip in new[] {_toolTip, _tooltipCopy}) { - toolTip.Font = new Font(toolTip.Font.FontFamily, toolTip.Font.Size * Config.Zoom / 100); + toolTip.Font = ZoomFont(toolTip.Font); } - ShipLabel.LatinFont = new Font("Tahoma", 8f * Config.Zoom / 100); + ShipLabel.Name.BaseFont = Font; + ShipLabel.Name.LatinFont = LatinFont(); var cur = CurrentAutoScaleDimensions; - ShipLabel.ScaleFactor = new SizeF(ShipLabel.ScaleFactor.Width * cur.Width / prev.Width, - ShipLabel.ScaleFactor.Height * cur.Height / prev.Height); + Scaler.Factor = Scaler.Scale(cur.Width / prev.Width, cur.Height / prev.Height); + } + + private Font ZoomFont(Font font) + { + return new Font(font.FontFamily, font.Size * Config.Zoom / 100); + } + + private Font LatinFont() + { + return new Font("Tahoma", 8f * Config.Zoom / 100); } private void RestoreLocation() @@ -534,7 +550,7 @@ namespace KancolleSniffer private void ApplyConfig() { if (TopMost != Config.TopMost) - TopMost = _listForm.TopMost = Config.TopMost; + TopMost = _listFormGroup.TopMost = Config.TopMost; Sniffer.ShipCounter.Margin = Config.MarginShips; _numberAndHistory.UpdateNumOfShips(); Sniffer.ItemCounter.Margin = Config.MarginEquips; @@ -542,6 +558,7 @@ namespace KancolleSniffer Sniffer.Achievement.ResetHours = Config.ResetHours; labelAkashiRepair.Visible = labelAkashiRepairTimer.Visible = labelPresetAkashiTimer.Visible = Config.UsePresetAkashi; + Sniffer.WarnBadDamageWithDameCon = Config.WarnBadDamageWithDameCon; } public void ApplyDebugLogSetting() @@ -622,22 +639,22 @@ namespace KancolleSniffer private void ShowShipOnShipList(object sender, EventArgs ev) { - if (!_listForm.Visible) + if (!_listFormGroup.Visible) return; var idx = (int)((Control)sender).Tag; 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); + _listFormGroup.ShowShip(ship.Id); } private void UpdateItemInfo() { _numberAndHistory.Update(); - if (_listForm.Visible) - _listForm.UpdateList(); + if (_listFormGroup.Visible) + _listFormGroup.UpdateList(); } private void UpdateShipInfo() @@ -649,23 +666,22 @@ namespace KancolleSniffer UpdateChargeInfo(); UpdateRepairList(); UpdateMissionLabels(); - if (_listForm.Visible) - _listForm.UpdateList(); + if (_listFormGroup.Visible) + _listFormGroup.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) + var inSortie = Sniffer.InSortie; + if (_inSortie || inSortie == -1) { - _inSortie = inSortie; + _inSortie = inSortie != -1; return; } _inSortie = true; - if (states[0] == FleetState.Sortie && states[1] == FleetState.Sortie) + if (inSortie == 10) { _combinedFleet = true; _currentFleet = 0; @@ -673,7 +689,7 @@ namespace KancolleSniffer else { _combinedFleet = false; - _currentFleet = Array.FindIndex(states, state => state >= FleetState.Sortie); + _currentFleet = inSortie; } } @@ -743,24 +759,24 @@ namespace KancolleSniffer private void NotifyDamagedShip() { + _notificationManager.StopRepeat("大破警告"); if (!Sniffer.BadlyDamagedShips.Any()) return; - _notificationManager.StopRepeat("大破警告"); SetNotification("大破警告", string.Join(" ", Sniffer.BadlyDamagedShips)); _notificationManager.Flash(); } - public void UpdateFighterPower(bool combined) + private void UpdateFighterPower(bool combined) { var fleets = Sniffer.Fleets; var fp = combined - ? fleets[0].FighterPower.Zip(fleets[1].FighterPower, (a, b) => a + b).ToArray() + ? fleets[0].FighterPower + fleets[1].FighterPower : fleets[_currentFleet].FighterPower; - labelFighterPower.Text = fp[0].ToString("D"); + labelFighterPower.Text = fp.Min.ToString("D"); var cr = combined ? fleets[0].ContactTriggerRate + fleets[1].ContactTriggerRate : fleets[_currentFleet].ContactTriggerRate; - var text = "制空: " + (fp[0] == fp[1] ? $"{fp[0]}" : $"{fp[0]}~{fp[1]}") + + var text = "制空: " + (fp.Diff ? fp.RangeString : fp.Min.ToString()) + $" 触接: {cr * 100:f1}"; _toolTip.SetToolTip(labelFighterPower, text); _toolTip.SetToolTip(labelFighterPowerCaption, text); @@ -785,8 +801,8 @@ namespace KancolleSniffer private void UpdateBattleInfo() { ResetBattleInfo(); - _listForm.UpdateBattleResult(); - _listForm.UpdateAirBattleResult(); + _listFormGroup.UpdateBattleResult(); + _listFormGroup.UpdateAirBattleResult(); if (Sniffer.Battle.BattleState == BattleState.None) return; panelBattleInfo.BringToFront(); @@ -799,7 +815,7 @@ namespace KancolleSniffer private void UpdateCellInfo() { - _listForm.UpdateCellInfo(); + _listFormGroup.UpdateCellInfo(); } private void ResetBattleInfo() @@ -807,30 +823,56 @@ namespace KancolleSniffer labelFormation.Text = ""; labelEnemyFighterPower.Text = ""; labelFighterPower.ForeColor = DefaultForeColor; + labelFighterPowerCaption.Text = "制空"; labelResultRank.Text = "判定"; panelBattleInfo.Visible = Sniffer.Battle.BattleState != BattleState.None; } private void UpdateBattleFighterPower() { + UpdateEnemyFighterPower(); var battle = Sniffer.Battle; - var power = battle.EnemyFighterPower; - labelEnemyFighterPower.Text = power.AirCombat + power.UnknownMark; - if (power.AirCombat != power.Interception) + labelFighterPower.ForeColor = AirControlLevelColor(battle); + labelFighterPowerCaption.Text = AirControlLevelString(battle); + if (battle.BattleState == BattleState.AirRaid) { - var text = "防空: " + power.Interception + power.UnknownMark; - _toolTip.SetToolTip(labelEnemyFighterPower, text); - _toolTip.SetToolTip(labelEnemyFighterPowerCaption, text); + UpdateAirRaidFighterPower(); } else { - _toolTip.SetToolTip(labelEnemyFighterPower, ""); - _toolTip.SetToolTip(labelEnemyFighterPowerCaption, ""); + UpdateFighterPower(Sniffer.IsCombinedFleet && battle.EnemyIsCombined); } - UpdateFighterPower(Sniffer.IsCombinedFleet && battle.EnemyIsCombined); - labelFighterPower.ForeColor = new[] + } + + private void UpdateEnemyFighterPower() + { + var fp = Sniffer.Battle.EnemyFighterPower; + labelEnemyFighterPower.Text = fp.AirCombat + fp.UnknownMark; + var toolTip = fp.AirCombat == fp.Interception ? "" : "防空: " + fp.Interception + fp.UnknownMark; + _toolTip.SetToolTip(labelEnemyFighterPower, toolTip); + _toolTip.SetToolTip(labelEnemyFighterPowerCaption, toolTip); + } + + private void UpdateAirRaidFighterPower() + { + var fp = Sniffer.Battle.FighterPower; + labelFighterPower.Text = fp.Min.ToString(); + var toolTop = fp.Diff ? fp.RangeString : ""; + _toolTip.SetToolTip(labelFighterPower, toolTop); + _toolTip.SetToolTip(labelFighterPowerCaption, toolTop); + } + + private static Color AirControlLevelColor(BattleInfo battle) + { + return new[] {DefaultForeColor, DefaultForeColor, CUDColors.Blue, CUDColors.Green, CUDColors.Orange, CUDColors.Red}[ - battle.AirControlLevel + 1]; + battle.BattleState == BattleState.Night ? 0 : battle.AirControlLevel + 1]; + } + + private static string AirControlLevelString(BattleInfo battle) + { + return new[] {"制空", "拮抗", "確保", "優勢", "劣勢", "喪失"}[ + battle.BattleState == BattleState.Night ? 0 : battle.AirControlLevel + 1]; } private void ShowResultRank() @@ -854,12 +896,15 @@ namespace KancolleSniffer var stat = Sniffer.Fleets[i].ChargeStatus; fuelSq[i].ImageIndex = stat.Fuel; bullSq[i].ImageIndex = stat.Bull; + var text = stat.Empty ? "" : $"燃{stat.FuelRatio * 100:f1}% 弾{stat.BullRatio * 100:f1}%"; + _toolTip.SetToolTip(fuelSq[i], text); + _toolTip.SetToolTip(bullSq[i], text); } } private void UpdateNDocLabels() { - _mainLabels.SetNDockLabels(Sniffer.NDock); + ndockPanel.SetName(Sniffer.NDock); SetNDockLabel(); } @@ -877,19 +922,7 @@ namespace KancolleSniffer private void UpdateMissionLabels() { - 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]; - } + missionPanel.Update(Sniffer); SetMissionLabel(); } @@ -898,23 +931,6 @@ namespace KancolleSniffer 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) { Config.ShowEndTime ^= TimerKind.Mission; @@ -924,25 +940,9 @@ namespace KancolleSniffer private void UpdateTimers() { - 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, (Config.ShowEndTime & TimerKind.Mission) != 0); - } - for (var i = 0; i < Sniffer.NDock.Length; i++) - { - var entry = Sniffer.NDock[i]; - _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++) - { - var timer = Sniffer.KDock[i]; - SetTimerColor(kdock[i], timer, _now); - kdock[i].Text = timer.ToString(_now); - } + missionPanel.UpdateTimers(Sniffer, _now, (Config.ShowEndTime & TimerKind.Mission) != 0); + ndockPanel.UpdateTimers(Sniffer, _now, (Config.ShowEndTime & TimerKind.NDock) != 0); + kdockPanel.UpdateTimers(Sniffer, _now); UpdateCondTimers(); UpdateAkashiTimer(); _timerEnabled = true; @@ -1011,7 +1011,7 @@ namespace KancolleSniffer return; } var span = TimeSpan.FromSeconds(Ceiling((timer - _now).TotalSeconds)); - if (span >= TimeSpan.FromMinutes(9)) + if (span >= TimeSpan.FromMinutes(9) && Config.NotifyConditions.Contains(40)) { labelCondTimerTitle.Text = "cond40まで"; labelCondTimer.Text = (span - TimeSpan.FromMinutes(9)).ToString(@"mm\:ss"); @@ -1137,6 +1137,12 @@ namespace KancolleSniffer private void UpdateQuestList() { questPanel.Update(Sniffer.Quests); + labelQuestCount.Text = Sniffer.Quests.Length.ToString(); + SetQuestNotification(); + } + + private void SetQuestNotification() + { Sniffer.GetQuestNotifications(out var notify, out var stop); foreach (var questName in notify) SetNotification("任務達成", 0, questName); @@ -1377,11 +1383,14 @@ namespace KancolleSniffer private void ShipListToolStripMenuItem_Click(object sender, EventArgs e) { + _listFormGroup.ShowOrCreate(); + /* _listForm.UpdateList(); _listForm.Show(); if (_listForm.WindowState == FormWindowState.Minimized) _listForm.WindowState = FormWindowState.Normal; _listForm.Activate(); + */ } private void LogToolStripMenuItem_Click(object sender, EventArgs e)