From 4918944e457a6b9b7674bacc20f8984956a24ef3 Mon Sep 17 00:00:00 2001 From: Kazuhiro Fujieda Date: Sat, 9 May 2020 14:50:51 +0900 Subject: [PATCH] =?utf8?q?=E4=B8=80=E8=A6=A7=E3=82=A6=E3=82=A3=E3=83=B3?= =?utf8?q?=E3=83=89=E3=82=A6=E3=81=AE=E6=A8=AA=E5=B9=85=E3=82=92=E5=8F=AF?= =?utf8?q?=E5=A4=89=E3=81=AB=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- KancolleSniffer.Test/FleetDataTest.cs | 12 ++-- KancolleSniffer/Forms/ListForm.Designer.cs | 75 +++++++++++----------- KancolleSniffer/Forms/ListForm.cs | 40 +++++++++--- KancolleSniffer/KancolleSniffer.csproj | 1 + KancolleSniffer/View/GrowLeftLabel.cs | 2 +- .../View/ListWindow/AirBattleResultPanel.cs | 8 ++- KancolleSniffer/View/ListWindow/AntiAirPanel.cs | 13 +++- .../View/ListWindow/BattleResultPanel.cs | 51 +++++++++++++-- KancolleSniffer/View/ListWindow/FleetData.cs | 44 ++++++++++--- KancolleSniffer/View/ListWindow/FleetDataPanel.cs | 25 ++++++-- KancolleSniffer/View/ListWindow/IPanelResize.cs | 8 +++ KancolleSniffer/View/Scaler.cs | 7 +- KancolleSniffer/View/ShipLabel.cs | 35 ++++++---- .../View/ShipListPanel/GroupConfigLabels.cs | 15 +++++ .../View/ShipListPanel/RepairListLabels.cs | 20 +++++- .../View/ShipListPanel/ShipListLabels.cs | 22 ++++++- .../View/ShipListPanel/ShipListPanel.cs | 19 +++++- 17 files changed, 299 insertions(+), 98 deletions(-) create mode 100644 KancolleSniffer/View/ListWindow/IPanelResize.cs diff --git a/KancolleSniffer.Test/FleetDataTest.cs b/KancolleSniffer.Test/FleetDataTest.cs index f55a6ad..ea83806 100644 --- a/KancolleSniffer.Test/FleetDataTest.cs +++ b/KancolleSniffer.Test/FleetDataTest.cs @@ -36,7 +36,7 @@ namespace KancolleSniffer.Test { AircraftSpec = "", Color = SystemColors.Control, - Equip = "", + Equip = new FleetData.EquipRecord(""), Fleet = "", Fleet2 = null, Id = 756, @@ -64,7 +64,7 @@ namespace KancolleSniffer.Test continue; return false; } - if (aVal.Equals(bVal)) + if (aVal.ToString() == bVal.ToString()) continue; return false; } @@ -91,9 +91,9 @@ namespace KancolleSniffer.Test Name = "大発動艇(八九式中戦車&陸戦隊)" } }; - Assert.AreEqual(item.Spec.Name, FleetData.Record.CreateItemRecord(item, 7, 7).Equip); + Assert.AreEqual(item.Spec.Name, FleetData.Record.CreateItemRecord(item, 7, 7).Equip.ToString(0)); item.Level = 10; - Assert.AreEqual("大発動艇(八九式中戦車&陸戦★10", FleetData.Record.CreateItemRecord(item, 7, 7).Equip); + Assert.AreEqual("大発動艇(八九式中戦車&陸戦★10", FleetData.Record.CreateItemRecord(item, 7, 7).Equip.ToString(0)); var aircraft = new ItemStatus { @@ -103,9 +103,9 @@ namespace KancolleSniffer.Test Type = 6 } }; - Assert.AreEqual(aircraft.Spec.Name, FleetData.Record.CreateItemRecord(aircraft, 7, 7).Equip); + Assert.AreEqual(aircraft.Spec.Name, FleetData.Record.CreateItemRecord(aircraft, 7, 7).Equip.ToString(0)); aircraft.Level = 10; - Assert.AreEqual("零式艦戦53型(岩本★10", FleetData.Record.CreateItemRecord(aircraft, 7, 7).Equip); + Assert.AreEqual("零式艦戦53型(岩本★10", FleetData.Record.CreateItemRecord(aircraft, 7, 7).Equip.ToString(0)); } } } \ No newline at end of file diff --git a/KancolleSniffer/Forms/ListForm.Designer.cs b/KancolleSniffer/Forms/ListForm.Designer.cs index 97d505f..fd1c412 100644 --- a/KancolleSniffer/Forms/ListForm.Designer.cs +++ b/KancolleSniffer/Forms/ListForm.Designer.cs @@ -91,15 +91,15 @@ namespace KancolleSniffer.Forms this.checkBoxSTypeHeavyCruiser = new System.Windows.Forms.CheckBox(); this.checkBoxSTypeAircraftCarrier = new System.Windows.Forms.CheckBox(); this.checkBoxSTypeBattleShip = new System.Windows.Forms.CheckBox(); - this.dropDownButtonSType = new KancolleSniffer.View.DropDownButton(); this.labelSType = new System.Windows.Forms.Label(); - this.airBattleResultPanel = new AirBattleResultPanel(); - this.battleResultPanel = new BattleResultPanel(); - this.antiAirPanel = new AntiAirPanel(); - this.fleetPanel = new FleetDataPanel(); - this.itemTreeView = new ItemTreeView(); - this.shipListPanel = new KancolleSniffer.View.ShipListPanel.ShipListPanel(); this.panelShipHeader = new System.Windows.Forms.Panel(); + this.airBattleResultPanel = new KancolleSniffer.View.ListWindow.AirBattleResultPanel(); + this.battleResultPanel = new KancolleSniffer.View.ListWindow.BattleResultPanel(); + this.antiAirPanel = new KancolleSniffer.View.ListWindow.AntiAirPanel(); + this.dropDownButtonSType = new KancolleSniffer.View.DropDownButton(); + this.fleetPanel = new KancolleSniffer.View.ListWindow.FleetDataPanel(); + this.itemTreeView = new KancolleSniffer.View.ListWindow.ItemTreeView(); + this.shipListPanel = new KancolleSniffer.View.ShipListPanel.ShipListPanel(); this.contextMenuStripShipList.SuspendLayout(); this.contextMenuStripItemList.SuspendLayout(); this.panelGroupHeader.SuspendLayout(); @@ -171,7 +171,7 @@ namespace KancolleSniffer.Forms // this.labelHeaderCond.AutoSize = true; this.labelHeaderCond.Cursor = System.Windows.Forms.Cursors.Hand; - this.labelHeaderCond.Location = new System.Drawing.Point(19, 5); + this.labelHeaderCond.Location = new System.Drawing.Point(20, 5); this.labelHeaderCond.Name = "labelHeaderCond"; this.labelHeaderCond.Size = new System.Drawing.Size(29, 12); this.labelHeaderCond.TabIndex = 13; @@ -182,7 +182,7 @@ namespace KancolleSniffer.Forms // this.labelHeaderExp.AutoSize = true; this.labelHeaderExp.Cursor = System.Windows.Forms.Cursors.Hand; - this.labelHeaderExp.Location = new System.Drawing.Point(88, 5); + this.labelHeaderExp.Location = new System.Drawing.Point(86, 5); this.labelHeaderExp.Name = "labelHeaderExp"; this.labelHeaderExp.Size = new System.Drawing.Size(24, 12); this.labelHeaderExp.TabIndex = 14; @@ -192,7 +192,7 @@ namespace KancolleSniffer.Forms // labelHeaderLv // this.labelHeaderLv.AutoSize = true; - this.labelHeaderLv.Location = new System.Drawing.Point(56, 5); + this.labelHeaderLv.Location = new System.Drawing.Point(55, 5); this.labelHeaderLv.Name = "labelHeaderLv"; this.labelHeaderLv.Size = new System.Drawing.Size(17, 12); this.labelHeaderLv.TabIndex = 13; @@ -200,14 +200,15 @@ namespace KancolleSniffer.Forms // // panelGroupHeader // + this.panelGroupHeader.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.panelGroupHeader.Controls.Add(this.label5); this.panelGroupHeader.Controls.Add(this.label9); this.panelGroupHeader.Controls.Add(this.label8); this.panelGroupHeader.Controls.Add(this.label7); this.panelGroupHeader.Controls.Add(this.label6); - this.panelGroupHeader.Location = new System.Drawing.Point(103, 3); + this.panelGroupHeader.Location = new System.Drawing.Point(101, 3); this.panelGroupHeader.Name = "panelGroupHeader"; - this.panelGroupHeader.Size = new System.Drawing.Size(125, 19); + this.panelGroupHeader.Size = new System.Drawing.Size(112, 19); this.panelGroupHeader.TabIndex = 16; // // label5 @@ -287,13 +288,14 @@ namespace KancolleSniffer.Forms // // panelRepairHeader // + this.panelRepairHeader.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.panelRepairHeader.Controls.Add(this.label10); this.panelRepairHeader.Controls.Add(this.label12); this.panelRepairHeader.Controls.Add(this.label13); this.panelRepairHeader.Controls.Add(this.label1RepairHp); this.panelRepairHeader.Location = new System.Drawing.Point(104, 3); this.panelRepairHeader.Name = "panelRepairHeader"; - this.panelRepairHeader.Size = new System.Drawing.Size(121, 19); + this.panelRepairHeader.Size = new System.Drawing.Size(118, 19); this.panelRepairHeader.TabIndex = 2; // // label10 @@ -318,8 +320,7 @@ namespace KancolleSniffer.Forms // // panelEmptyHeader // - this.panelEmptyHeader.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.panelEmptyHeader.Location = new System.Drawing.Point(58, 3); + this.panelEmptyHeader.Location = new System.Drawing.Point(56, 3); this.panelEmptyHeader.Name = "panelEmptyHeader"; this.panelEmptyHeader.Size = new System.Drawing.Size(167, 19); this.panelEmptyHeader.TabIndex = 0; @@ -332,7 +333,7 @@ namespace KancolleSniffer.Forms this.richTextBoxMiscText.Location = new System.Drawing.Point(6, 23); this.richTextBoxMiscText.Name = "richTextBoxMiscText"; this.richTextBoxMiscText.ReadOnly = true; - this.richTextBoxMiscText.Size = new System.Drawing.Size(238, 263); + this.richTextBoxMiscText.Size = new System.Drawing.Size(236, 263); this.richTextBoxMiscText.TabIndex = 0; this.richTextBoxMiscText.Text = ""; // @@ -360,11 +361,12 @@ namespace KancolleSniffer.Forms // // panelFleetHeader // + this.panelFleetHeader.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.panelFleetHeader.Controls.Add(this.labelFleet4); this.panelFleetHeader.Controls.Add(this.label1Fleet3); this.panelFleetHeader.Controls.Add(this.labelFleet2); this.panelFleetHeader.Controls.Add(this.labelFleet1); - this.panelFleetHeader.Location = new System.Drawing.Point(58, 3); + this.panelFleetHeader.Location = new System.Drawing.Point(56, 3); this.panelFleetHeader.Name = "panelFleetHeader"; this.panelFleetHeader.Size = new System.Drawing.Size(167, 19); this.panelFleetHeader.TabIndex = 0; @@ -549,6 +551,18 @@ namespace KancolleSniffer.Forms this.labelSType.Text = "艦種"; this.labelSType.Click += new System.EventHandler(this.labelSTypeButton_Click); // + // panelShipHeader + // + this.panelShipHeader.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); + this.panelShipHeader.Controls.Add(this.labelHeaderHp); + this.panelShipHeader.Controls.Add(this.labelHeaderCond); + this.panelShipHeader.Controls.Add(this.labelHeaderLv); + this.panelShipHeader.Controls.Add(this.labelHeaderExp); + this.panelShipHeader.Location = new System.Drawing.Point(113, 3); + this.panelShipHeader.Name = "panelShipHeader"; + this.panelShipHeader.Size = new System.Drawing.Size(113, 19); + this.panelShipHeader.TabIndex = 21; + // // airBattleResultPanel // this.airBattleResultPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) @@ -557,7 +571,7 @@ namespace KancolleSniffer.Forms this.airBattleResultPanel.Location = new System.Drawing.Point(6, 23); this.airBattleResultPanel.Name = "airBattleResultPanel"; this.airBattleResultPanel.ShowResultAutomatic = false; - this.airBattleResultPanel.Size = new System.Drawing.Size(238, 51); + this.airBattleResultPanel.Size = new System.Drawing.Size(236, 51); this.airBattleResultPanel.TabIndex = 18; // // battleResultPanel @@ -569,7 +583,7 @@ namespace KancolleSniffer.Forms this.battleResultPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.battleResultPanel.Location = new System.Drawing.Point(6, 73); this.battleResultPanel.Name = "battleResultPanel"; - this.battleResultPanel.Size = new System.Drawing.Size(238, 213); + this.battleResultPanel.Size = new System.Drawing.Size(236, 213); this.battleResultPanel.TabIndex = 0; // // antiAirPanel @@ -581,7 +595,7 @@ namespace KancolleSniffer.Forms this.antiAirPanel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.antiAirPanel.Location = new System.Drawing.Point(6, 23); this.antiAirPanel.Name = "antiAirPanel"; - this.antiAirPanel.Size = new System.Drawing.Size(238, 263); + this.antiAirPanel.Size = new System.Drawing.Size(236, 263); this.antiAirPanel.TabIndex = 17; // // dropDownButtonSType @@ -603,7 +617,7 @@ namespace KancolleSniffer.Forms this.fleetPanel.ContextMenuStrip = this.contextMenuStripFleetData; this.fleetPanel.Location = new System.Drawing.Point(6, 23); this.fleetPanel.Name = "fleetPanel"; - this.fleetPanel.Size = new System.Drawing.Size(238, 263); + this.fleetPanel.Size = new System.Drawing.Size(236, 263); this.fleetPanel.TabIndex = 1; // // itemTreeView @@ -614,7 +628,7 @@ namespace KancolleSniffer.Forms this.itemTreeView.ContextMenuStrip = this.contextMenuStripItemList; this.itemTreeView.Location = new System.Drawing.Point(6, 23); this.itemTreeView.Name = "itemTreeView"; - this.itemTreeView.Size = new System.Drawing.Size(238, 263); + this.itemTreeView.Size = new System.Drawing.Size(236, 263); this.itemTreeView.TabIndex = 0; // // shipListPanel @@ -627,26 +641,14 @@ namespace KancolleSniffer.Forms this.shipListPanel.GroupUpdated = false; this.shipListPanel.Location = new System.Drawing.Point(6, 23); this.shipListPanel.Name = "shipListPanel"; - this.shipListPanel.Size = new System.Drawing.Size(238, 263); + this.shipListPanel.Size = new System.Drawing.Size(236, 263); this.shipListPanel.TabIndex = 0; // - // panelShipHeader - // - this.panelShipHeader.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.panelShipHeader.Controls.Add(this.labelHeaderHp); - this.panelShipHeader.Controls.Add(this.labelHeaderCond); - this.panelShipHeader.Controls.Add(this.labelHeaderLv); - this.panelShipHeader.Controls.Add(this.labelHeaderExp); - this.panelShipHeader.Location = new System.Drawing.Point(114, 3); - this.panelShipHeader.Name = "panelShipHeader"; - this.panelShipHeader.Size = new System.Drawing.Size(113, 19); - this.panelShipHeader.TabIndex = 21; - // // ListForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(250, 292); + this.ClientSize = new System.Drawing.Size(248, 292); this.Controls.Add(this.panelSType); this.Controls.Add(this.panelFleetHeader); this.Controls.Add(this.airBattleResultPanel); @@ -671,6 +673,7 @@ namespace KancolleSniffer.Forms this.Activated += new System.EventHandler(this.ListForm_Activated); this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ListForm_FormClosing); this.Load += new System.EventHandler(this.ListForm_Load); + this.ResizeEnd += new System.EventHandler(this.ListForm_ResizeEnd); this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.ListForm_KeyPress); this.contextMenuStripShipList.ResumeLayout(false); this.contextMenuStripItemList.ResumeLayout(false); diff --git a/KancolleSniffer/Forms/ListForm.cs b/KancolleSniffer/Forms/ListForm.cs index 4fb8d2e..24c6987 100644 --- a/KancolleSniffer/Forms/ListForm.cs +++ b/KancolleSniffer/Forms/ListForm.cs @@ -19,6 +19,7 @@ using System.Linq; using System.Windows.Forms; using KancolleSniffer.Model; using KancolleSniffer.View; +using KancolleSniffer.View.ListWindow; using KancolleSniffer.View.ShipListPanel; using Clipboard = KancolleSniffer.Util.Clipboard; @@ -33,7 +34,7 @@ namespace KancolleSniffer.Forms private readonly CheckBox[] _shipTypeCheckBoxes; private bool _isMaster; private Settings _settings; - public const int PanelWidth = 217; + public const int PanelWidth = 215; public class Settings { @@ -273,12 +274,8 @@ namespace KancolleSniffer.Forms private void ListForm_Load(object sender, EventArgs e) { - /* DPIではなくズームしたときにパネルは大きくなるがScrollBarはそのままなので隙間ができる。 - そこでScrollBarの幅に合わせて全体の横幅を設定し直す。*/ - Width = Scaler.ScaleWidth(PanelWidth + 12 /* PanelとFrameの内側 */) + - SystemInformation.VerticalScrollBarWidth + 2 /* 縁の幅 */ + Width - ClientSize.Width; - MinimumSize = new Size(Width, 0); - MaximumSize = new Size(Width, int.MaxValue); + AdjustHeader(); + SetMinimumSize(); var config = GetConfig(); _settings = Settings.FromShipListConfig(config); if (_settings.ShowHpInPercent) @@ -294,7 +291,25 @@ namespace KancolleSniffer.Forms var bounds = new Rectangle(config.Location, config.Size); if (MainWindow.IsTitleBarOnAnyScreen(bounds.Location)) Location = bounds.Location; - Height = bounds.Height; + Size = bounds.Size; + } + + private void AdjustHeader() + { + if (_config.Zoom == 100) + return; + foreach (var header in new[] + { + panelShipHeader, panelGroupHeader, panelRepairHeader + }) + { + header.Left += SystemInformation.VerticalScrollBarWidth * (_config.Zoom - 100) / 100; + } + } + + private void SetMinimumSize() + { + MinimumSize = new Size(Width - Scaler.ScaleWidth(24) - SystemInformation.VerticalScrollBarWidth * (_config.Zoom - 100) / 100, 0); } private ShipListConfig GetConfig() @@ -608,5 +623,14 @@ namespace KancolleSniffer.Forms UpdateList(); SetActiveControl(); } + + private void ListForm_ResizeEnd(object sender, EventArgs e) + { + foreach (var panel in new IPanelResize[] {shipListPanel, antiAirPanel, airBattleResultPanel, battleResultPanel, fleetPanel}) + { + if (panel.Visible) + panel.ApplyResize(); + } + } } } \ No newline at end of file diff --git a/KancolleSniffer/KancolleSniffer.csproj b/KancolleSniffer/KancolleSniffer.csproj index 5bb8a36..6709467 100644 --- a/KancolleSniffer/KancolleSniffer.csproj +++ b/KancolleSniffer/KancolleSniffer.csproj @@ -93,6 +93,7 @@ + Component diff --git a/KancolleSniffer/View/GrowLeftLabel.cs b/KancolleSniffer/View/GrowLeftLabel.cs index fc23f7e..62a4e01 100644 --- a/KancolleSniffer/View/GrowLeftLabel.cs +++ b/KancolleSniffer/View/GrowLeftLabel.cs @@ -54,7 +54,7 @@ namespace KancolleSniffer.View AdjustLocation(); } - private void AdjustLocation() + public void AdjustLocation() { if (!GrowLeft) return; diff --git a/KancolleSniffer/View/ListWindow/AirBattleResultPanel.cs b/KancolleSniffer/View/ListWindow/AirBattleResultPanel.cs index 80d0e02..3bc533a 100644 --- a/KancolleSniffer/View/ListWindow/AirBattleResultPanel.cs +++ b/KancolleSniffer/View/ListWindow/AirBattleResultPanel.cs @@ -23,7 +23,7 @@ using KancolleSniffer.Model; namespace KancolleSniffer.View.ListWindow { [DesignerCategory("Code")] - public class AirBattleResultPanel : PanelWithToolTip + public class AirBattleResultPanel : PanelWithToolTip, IPanelResize { private readonly Label _phaseName; private readonly Label _stage1; @@ -32,6 +32,7 @@ namespace KancolleSniffer.View.ListWindow private int _resultIndex; private readonly ShipLabel.Name _ciShipName; private readonly Label _ciKind; + private const int InitWidth = 236; public bool ShowResultAutomatic { get; set; } @@ -98,6 +99,11 @@ namespace KancolleSniffer.View.ListWindow _phaseName.Click += PhaseNameOnClick; } + public void ApplyResize() + { + _ciShipName.AdjustWidth(Scaler.DownWidth(Width) - InitWidth, true); + } + public void SetResult(Sniffer sniffer) { var battleResult = sniffer.Battle.AirBattleResult; diff --git a/KancolleSniffer/View/ListWindow/AntiAirPanel.cs b/KancolleSniffer/View/ListWindow/AntiAirPanel.cs index 7429551..707e828 100644 --- a/KancolleSniffer/View/ListWindow/AntiAirPanel.cs +++ b/KancolleSniffer/View/ListWindow/AntiAirPanel.cs @@ -21,7 +21,7 @@ using KancolleSniffer.Model; namespace KancolleSniffer.View.ListWindow { - public class AntiAirPanel : Panel + public class AntiAirPanel : Panel, IPanelResize { private const int LineHeight = 16; private readonly List _labelList = new List(); @@ -138,7 +138,7 @@ namespace KancolleSniffer.View.ListWindow BackPanel = new Panel { Location = new Point(0, y), - Size = new Size(ListForm.PanelWidth, LineHeight) + Size = new Size(ListForm.PanelWidth, LineHeight), } }; _labelList.Add(labels); @@ -146,6 +146,15 @@ namespace KancolleSniffer.View.ListWindow labels.Move(AutoScrollPosition); } + public void ApplyResize() + { + var width = Width - SystemInformation.VerticalScrollBarWidth - 2; + SuspendLayout(); + foreach (var labels in _labelList) + labels.BackPanel.Width = width; + ResumeLayout(); + } + private void SetRecords() { for (var i = 0; i < _table.Count; i++) diff --git a/KancolleSniffer/View/ListWindow/BattleResultPanel.cs b/KancolleSniffer/View/ListWindow/BattleResultPanel.cs index 33304c6..08fe21c 100644 --- a/KancolleSniffer/View/ListWindow/BattleResultPanel.cs +++ b/KancolleSniffer/View/ListWindow/BattleResultPanel.cs @@ -23,7 +23,7 @@ using static System.Math; namespace KancolleSniffer.View.ListWindow { - public class BattleResultPanel : PanelWithToolTip + public class BattleResultPanel : PanelWithToolTip, IPanelResize { private readonly List _friendLabels = new List(); private readonly List _enemyLabels = new List(); @@ -238,7 +238,7 @@ namespace KancolleSniffer.View.ListWindow var lines = Max(Ships(result.Friend).Length, Ships(result.Enemy).Length); SetPanelVisible(lines); ResumeLayout(); // スクロールバーの有無を決定する - AdjustPanelWidth(lines); + AdjustPanelWidth(); } private void SetEachResult(IReadOnlyList labelsList, BattleInfo.BattleResult.Combined fleet) @@ -258,6 +258,7 @@ namespace KancolleSniffer.View.ListWindow { labels.Hp.Set(ship); labels.Name.SetName(ShortenName(ship.Name)); + labels.Name.Left = CalcEnemyNameLeft(labels.Hp.Width); } else { @@ -320,6 +321,9 @@ namespace KancolleSniffer.View.ListWindow private const int LabelHeight = 12; private const int LabelMargin = (LineHeight - LabelHeight) / 2; private const int TopMargin = 4; + private const int EnemyNameLeft = 164; + + private int _adjust; private void CreateLabels() { @@ -368,7 +372,7 @@ namespace KancolleSniffer.View.ListWindow friend.Hp.Click += HpLabelClickHandler; var enemy = new ShipLabels { - Name = new ShipLabel.Name(new Point(164, LabelMargin), ShipNameWidth.Max), + Name = new ShipLabel.Name(new Point(EnemyNameLeft, LabelMargin), ShipNameWidth.Max), Hp = new ShipLabel.Hp { Location = new Point(119, 0), @@ -388,12 +392,45 @@ namespace KancolleSniffer.View.ListWindow _friendLabels[i].BackPanel.Visible = i < showPanels; } - private void AdjustPanelWidth(int lines) + private int _gap; + + private void AdjustPanelWidth() { + var labelMax = _enemyLabels[0].Name.Location.X + _enemyLabels.Max(labels => labels.Name.Size.Width) - 1; var panelWidth = Max(ClientSize.Width, // スクロールバーの有無を反映した横幅 - _enemyLabels[0].Name.Location.X + _enemyLabels.Max(labels => labels.Name.Size.Width) - 1); // 敵の名前の右端 - for (var i = 0; i < lines; i++) - _friendLabels[i].BackPanel.Width = panelWidth; + labelMax); // 敵の名前の右端 + foreach (var panel in from labels in _friendLabels where labels.BackPanel.Visible select labels.BackPanel) + panel.Width = panelWidth; + _gap = (ClientSize.Width - labelMax) * 2 / 3; + } + + public void ApplyResize() + { + AdjustPanelWidth(); + var prev = _adjust; + _adjust = Max(0, Min(Scaler.ScaleWidth(24), _adjust + _gap)); + if (_adjust == prev) + return; + var diff = _adjust - prev; + foreach (var labels in _enemyLabels) + { + labels.Hp.Left += diff; + labels.Name.Left = CalcEnemyNameLeft(labels.Hp.Width); + } + foreach (var labels in _friendLabels) + { + labels.Hp.Left += diff; + labels.Hp.AdjustLocation(); + labels.Name.AdjustWidth(Scaler.DownWidth(_adjust), true); + } + } + + private int CalcEnemyNameLeft(int hpWidth) + { + var nameSpace = _adjust / 2; + var hpAdjust = Scaler.ScaleWidth(12); + var wideHp = hpWidth > Scaler.ScaleWidth(47); + return Scaler.ScaleWidth(EnemyNameLeft) + _adjust + (wideHp && nameSpace < hpAdjust ? hpAdjust : nameSpace); } protected override void OnMouseWheel(MouseEventArgs e) diff --git a/KancolleSniffer/View/ListWindow/FleetData.cs b/KancolleSniffer/View/ListWindow/FleetData.cs index 4797927..7f7a927 100644 --- a/KancolleSniffer/View/ListWindow/FleetData.cs +++ b/KancolleSniffer/View/ListWindow/FleetData.cs @@ -63,6 +63,35 @@ namespace KancolleSniffer.View.ListWindow return items.Concat(new[] {Record.CreateItemRecord(ship.SlotEx, 0, 0)}); } + public class EquipRecord + { + private readonly ItemStatus _item; + private readonly string _text; + + public EquipRecord(ItemStatus item) + { + _item = new ItemStatus{Alv = item.Alv, Level = item.Level, Spec = item.Spec}; + } + + public EquipRecord(string text = "") + { + _text = text; + } + + public string ToString(int adjust) + { + if (_text != null) + return _text; + var level = _item.Level == 0 ? "" : "★" + _item.Level; + return StringTruncator.Truncate(_item.Spec.Name, level, adjust + (_item.Spec.IsAircraft ? 132 : 180)) + level; + } + + public override string ToString() + { + return _text; + } + } + public class Record { public string Fleet { get; set; } @@ -70,7 +99,7 @@ namespace KancolleSniffer.View.ListWindow public string Ship { get; set; } public string Ship2 { get; set; } public int Id { get; set; } - public string Equip { get; set; } + public EquipRecord Equip { get; set; } public Color Color { get; set; } public string Spec { get; set; } public string Spec2 { get; set; } @@ -79,7 +108,8 @@ namespace KancolleSniffer.View.ListWindow public Record() { Color = Control.DefaultBackColor; - Fleet = Ship = Equip = AircraftSpec = ""; + Fleet = Ship = AircraftSpec = ""; + Equip = new EquipRecord(); } public static Record CreateShipRecord(ShipStatus ship) @@ -120,7 +150,7 @@ namespace KancolleSniffer.View.ListWindow { public ItemRecord(ItemStatus item, int onSlot, int maxEq) { - Equip = GenEquipString(item); + Equip = new EquipRecord(item); Spec = item.Spec.IsAircraft ? $"+{item.Alv} {onSlot}/{maxEq}" : ""; AircraftSpec = GetAircraftSpec(item, onSlot); Color = item.Spec.Color; @@ -142,12 +172,6 @@ namespace KancolleSniffer.View.ListWindow } } - private static string GenEquipString(ItemStatus item) - { - var level = item.Level == 0 ? "" : "★" + item.Level; - return StringTruncator.Truncate(item.Spec.Name, level, item.Spec.IsAircraft ? 132 : 180) + level; - } - public static Record CreateFleetRecord(IReadOnlyList fleets, int number) { return new FleetRecord(fleets, number); @@ -298,7 +322,7 @@ namespace KancolleSniffer.View.ListWindow public CorpsPlaneRecord(AirBase.PlaneInfo plane) { var planeFp = plane.FighterPower; - Equip = plane.State != 1 ? plane.StateName : GenEquipString(plane.Slot); + Equip = plane.State != 1 ? new EquipRecord(plane.StateName) : new EquipRecord(plane.Slot); Spec = plane.State != 1 ? "" : $"+{plane.Slot.Alv} {plane.Count}/{plane.MaxCount}"; AircraftSpec = $"距離:{plane.Slot.Spec.Distance} 制空:{RangeString(planeFp.AirCombat)}" + diff --git a/KancolleSniffer/View/ListWindow/FleetDataPanel.cs b/KancolleSniffer/View/ListWindow/FleetDataPanel.cs index 4099b8f..9957a77 100644 --- a/KancolleSniffer/View/ListWindow/FleetDataPanel.cs +++ b/KancolleSniffer/View/ListWindow/FleetDataPanel.cs @@ -21,7 +21,7 @@ using KancolleSniffer.Forms; namespace KancolleSniffer.View.ListWindow { - public class FleetDataPanel : PanelWithToolTip + public class FleetDataPanel : PanelWithToolTip, IPanelResize { private const int LineHeight = 14; private const int LabelHeight = 12; @@ -54,7 +54,7 @@ namespace KancolleSniffer.View.ListWindow public ShipLabel.Name Name { get; set; } public Label Equip { get; set; } public Label EquipColor { get; set; } - public Label Spec { get; set; } + public GrowLeftLabel Spec { get; set; } public override Control[] Controls => new Control[] {Fleet, Name, Equip, EquipColor, Spec}; } @@ -66,9 +66,9 @@ namespace KancolleSniffer.View.ListWindow { Fleet = new Label {Location = new Point(1, 2), AutoSize = true}, Name = new ShipLabel.Name(new Point(10, 2), ShipNameWidth.Max), - Equip = new Label {Location = new Point(38, 2), AutoSize = true}, + Equip = new Label {Location = new Point(38, 2), AutoSize = true, Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top}, EquipColor = new Label {Location = new Point(35, 2), Size = new Size(4, LabelHeight - 2)}, - Spec = new GrowLeftLabel {Location = new Point(217, 2), GrowLeft = true}, + Spec = new GrowLeftLabel {Location = new Point(217, 2), GrowLeft = true, Anchor = AnchorStyles.Right | AnchorStyles.Top}, BackPanel = new Panel { Location = new Point(0, y), @@ -82,6 +82,19 @@ namespace KancolleSniffer.View.ListWindow labels.Move(AutoScrollPosition); } + public void ApplyResize() + { + var width = Width - SystemInformation.VerticalScrollBarWidth - 2; + SuspendLayout(); + foreach (var labels in _labelList) + { + labels.BackPanel.Width = width; + labels.Spec.AdjustLocation(); + } + SetRecords(); + ResumeLayout(); + } + private void SetRecords() { for (var i = 0; i < _data.Length; i++) @@ -99,8 +112,8 @@ namespace KancolleSniffer.View.ListWindow labels.Name.SetName(e.Ship); if (e.Ship2 != "") ToolTip.SetToolTip(labels.Name, e.Ship2); - labels.Equip.Text = e.Equip; - labels.EquipColor.Visible = e.Equip != ""; + labels.Equip.Text = e.Equip.ToString(Scaler.DownWidth(labels.BackPanel.Width) - ListForm.PanelWidth); + labels.EquipColor.Visible = e.Equip.ToString() != ""; labels.EquipColor.BackColor = e.Color; labels.Spec.Text = e.Spec; if (e.Fleet != "" && e.Fleet2 != "") diff --git a/KancolleSniffer/View/ListWindow/IPanelResize.cs b/KancolleSniffer/View/ListWindow/IPanelResize.cs new file mode 100644 index 0000000..1ea82ac --- /dev/null +++ b/KancolleSniffer/View/ListWindow/IPanelResize.cs @@ -0,0 +1,8 @@ +namespace KancolleSniffer.View.ListWindow +{ + public interface IPanelResize + { + bool Visible { get; } + void ApplyResize(); + } +} \ No newline at end of file diff --git a/KancolleSniffer/View/Scaler.cs b/KancolleSniffer/View/Scaler.cs index bde4461..15658dd 100644 --- a/KancolleSniffer/View/Scaler.cs +++ b/KancolleSniffer/View/Scaler.cs @@ -20,7 +20,7 @@ namespace KancolleSniffer.View { public static class Scaler { - public static SizeF Factor { private get; set; } + public static SizeF Factor { private get; set; } = new SizeF(1, 1); public static void Scale(Control control) { @@ -61,5 +61,10 @@ namespace KancolleSniffer.View { return new Point(x + ScaleWidth(width), y + ScaleHeight(height)); } + + public static int DownWidth(int width) + { + return (int)(width / Factor.Width); + } } } \ No newline at end of file diff --git a/KancolleSniffer/View/ShipLabel.cs b/KancolleSniffer/View/ShipLabel.cs index f2dfdec..688fee1 100644 --- a/KancolleSniffer/View/ShipLabel.cs +++ b/KancolleSniffer/View/ShipLabel.cs @@ -51,14 +51,24 @@ namespace KancolleSniffer.View public new sealed class Name : ShipLabel { private SlotStatus _slotStatus, _prevSlotStatus; - private readonly ShipNameWidth _defaultWidth; + private ShipStatus _status; public static Font LatinFont { get; set; } public static Font BaseFont { get; set; } + private readonly ShipNameWidth _defaultWidth; + private int _nameWidth; + + public void AdjustWidth(int adjust, bool update = false) + { + _nameWidth = (int)_defaultWidth + Max(-24, adjust); + if (update && _status != null) + Set(_status); + } - public Name(Point location, ShipNameWidth defaultWidth) + public Name(Point location, ShipNameWidth nameWidth) { - _defaultWidth = defaultWidth; + _defaultWidth = nameWidth; + _nameWidth = (int)nameWidth; Location = location; AutoSize = true; } @@ -74,7 +84,7 @@ namespace KancolleSniffer.View public override void Set(ShipStatus status) { - SetName(status, _defaultWidth); + SetName(status, _nameWidth); } public override void Reset() @@ -84,6 +94,12 @@ namespace KancolleSniffer.View public void SetName(ShipStatus status, ShipNameWidth width) { + SetName(status, (int)width); + } + + private void SetName(ShipStatus status, int width) + { + _status = status; var slotStatus = GetSlotStatus(status); var dcName = DameConName(status); var sp = SpecialAttack(status); @@ -130,19 +146,14 @@ namespace KancolleSniffer.View public void SetName(string name) { - SetName(name, _defaultWidth); - } - - private void SetName(string name, ShipNameWidth width) - { - SetName("", name, SlotStatus.Equipped, width); + Set(new ShipStatus{Spec = new ShipSpec{Name = name}}); } - private void SetName(string prefix, string name, SlotStatus slotStatus, ShipNameWidth width) + private void SetName(string prefix, string name, SlotStatus slotStatus, int width) { _slotStatus = slotStatus; ChangeFont(name); - var realWidth = width == ShipNameWidth.Max ? (int)width : Scaler.ScaleWidth((int)width); + var realWidth = width == int.MaxValue ? width : Scaler.ScaleWidth(width); Text = prefix + StringTruncator.Truncate(name, "", realWidth, Font); if (_prevSlotStatus != _slotStatus) Invalidate(); // OnPaintを実行させるため diff --git a/KancolleSniffer/View/ShipListPanel/GroupConfigLabels.cs b/KancolleSniffer/View/ShipListPanel/GroupConfigLabels.cs index cd6540d..a135c6c 100644 --- a/KancolleSniffer/View/ShipListPanel/GroupConfigLabels.cs +++ b/KancolleSniffer/View/ShipListPanel/GroupConfigLabels.cs @@ -51,6 +51,7 @@ namespace KancolleSniffer.View.ShipListPanel { Location = new Point(0, y), Size = new Size(ListForm.PanelWidth, ShipListPanel.LineHeight), + Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top } }; var cb = new CheckBox[GroupCount]; @@ -66,12 +67,26 @@ namespace KancolleSniffer.View.ShipListPanel Scaler.Scale(cb[j]); cb[j].CheckedChanged += checkboxGroup_CheckedChanged; } + SetAnchorRight(cb.Concat(new Control[] {labels.Level}).ToArray()); _labelList.Add(labels); _checkBoxesList.Add(cb); labels.Arrange(_shipListPanel, CustomColors.ColumnColors.BrightFirst(i)); labels.BackPanel.Controls.AddRange(cb); } + private void SetAnchorRight(params Control[] controls) + { + foreach (var control in controls) + control.Anchor = AnchorStyles.Top | AnchorStyles.Right; + } + + public void Resize(int i, int width) + { + var labels = _labelList[i]; + labels.BackPanel.Width = width; + labels.Name.AdjustWidth(Scaler.DownWidth(width) - ListForm.PanelWidth); + } + private void checkboxGroup_CheckedChanged(object sender, EventArgs e) { var cb = (CheckBox)sender; diff --git a/KancolleSniffer/View/ShipListPanel/RepairListLabels.cs b/KancolleSniffer/View/ShipListPanel/RepairListLabels.cs index 9423eb1..810663a 100644 --- a/KancolleSniffer/View/ShipListPanel/RepairListLabels.cs +++ b/KancolleSniffer/View/ShipListPanel/RepairListLabels.cs @@ -55,18 +55,34 @@ namespace KancolleSniffer.View.ShipListPanel Hp = new ShipLabel.Hp(new Point(118, 0), ShipListPanel.LineHeight), Level = new ShipLabel.Level(new Point(116, 2), height), Time = new ShipLabel.RepairTime(new Point(141, 2)), - PerHp = new Label {Location = new Point(186, 2), AutoSize = true}, + PerHp = new Label {Location = new Point(185, 2), AutoSize = true}, BackPanel = new Panel { Location = new Point(0, y), - Size = new Size(ListForm.PanelWidth, ShipListPanel.LineHeight) + Size = new Size(ListForm.PanelWidth, ShipListPanel.LineHeight), + Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top } }; + SetAnchorRight(labels.Hp, labels.Level, labels.Time, labels.PerHp); _labelList.Add(labels); labels.Arrange(_shipListPanel, CustomColors.ColumnColors.BrightFirst(i)); _shipListPanel.SetHpPercent(labels.Hp); } + private void SetAnchorRight(params Control[] controls) + { + foreach (var control in controls) + control.Anchor = AnchorStyles.Top | AnchorStyles.Right; + } + + public void Resize(int i, int width) + { + var labels = _labelList[i]; + labels.BackPanel.Width = width; + labels.Hp.AdjustLocation(); + labels.Name.AdjustWidth(Scaler.DownWidth(width) - ListForm.PanelWidth); + } + public void SetRepairList(int i) { var s = _shipListPanel.GetShip(i); diff --git a/KancolleSniffer/View/ShipListPanel/ShipListLabels.cs b/KancolleSniffer/View/ShipListPanel/ShipListLabels.cs index 004ca62..9fbd66b 100644 --- a/KancolleSniffer/View/ShipListPanel/ShipListLabels.cs +++ b/KancolleSniffer/View/ShipListPanel/ShipListLabels.cs @@ -38,20 +38,36 @@ namespace KancolleSniffer.View.ShipListPanel Fleet = new ShipLabel.Fleet(new Point(1, 2)), Name = new ShipLabel.Name(new Point(10, 2), ShipNameWidth.ShipList), Hp = new ShipLabel.Hp(new Point(126, 0), ShipListPanel.LineHeight), - Cond = new ShipLabel.Cond(new Point(128, 0), ShipListPanel.LineHeight), - Level = new ShipLabel.Level(new Point(154, 2), height), - Exp = new ShipLabel.Exp(new Point(175, 2), height), + Cond = new ShipLabel.Cond(new Point(127, 0), ShipListPanel.LineHeight), + Level = new ShipLabel.Level(new Point(152, 2), height), + Exp = new ShipLabel.Exp(new Point(174, 2), height), BackPanel = new Panel { Location = new Point(0, y), Size = new Size(ListForm.PanelWidth, ShipListPanel.LineHeight), + Anchor = AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Top } }; + SetAnchorRight(labels.Hp, labels.Cond, labels.Level, labels.Exp); _labelList.Add(labels); labels.Arrange(_shipListPanel, CustomColors.ColumnColors.BrightFirst(i)); _shipListPanel.SetHpPercent(labels.Hp); } + private void SetAnchorRight(params Control[] controls) + { + foreach (var control in controls) + control.Anchor = AnchorStyles.Top | AnchorStyles.Right; + } + + public void Resize(int i, int width) + { + var labels = _labelList[i]; + labels.BackPanel.Width = width; + labels.Hp.AdjustLocation(); + labels.Name.AdjustWidth(Scaler.DownWidth(width) - ListForm.PanelWidth); + } + public void SetShipStatus(int i) { var s = _shipListPanel.GetShip(i); diff --git a/KancolleSniffer/View/ShipListPanel/ShipListPanel.cs b/KancolleSniffer/View/ShipListPanel/ShipListPanel.cs index 44eb4b7..c3ad995 100644 --- a/KancolleSniffer/View/ShipListPanel/ShipListPanel.cs +++ b/KancolleSniffer/View/ShipListPanel/ShipListPanel.cs @@ -19,11 +19,12 @@ using System.Runtime.InteropServices; using System.Windows.Forms; using KancolleSniffer.Forms; using KancolleSniffer.Model; +using KancolleSniffer.View.ListWindow; using static System.Math; namespace KancolleSniffer.View.ShipListPanel { - public class ShipListPanel : Panel + public class ShipListPanel : Panel, IPanelResize { public const int LabelHeight = 12; public const int LineHeight = 16; @@ -68,13 +69,13 @@ namespace KancolleSniffer.View.ShipListPanel ResumeDrawing(); } - protected override void OnResize(EventArgs ev) + public void ApplyResize() { - base.OnResize(ev); if (_shipList == null || _shipList.Length == 0 || !Visible) return; SuspendDrawing(); SetupLabels(); + ResizeLabels(); SetShipLabels(); ResumeDrawing(); } @@ -93,6 +94,7 @@ namespace KancolleSniffer.View.ShipListPanel CreateShipList(sniffer, settings); SuspendDrawing(); SetupLabels(); + ResizeLabels(); SetShipLabels(); ResumeDrawing(); } @@ -299,6 +301,17 @@ namespace KancolleSniffer.View.ShipListPanel ScrollBar.Value = Min(ScrollBar.Value, max); } + private void ResizeLabels() + { + var width = Width - SystemInformation.VerticalScrollBarWidth - 2; + for (var i = 0; i < _labelCount; i++) + { + _shipListLabels.Resize(i, width); + _groupConfigLabels.Resize(i, width); + _repairListLabels.Resize(i, width); + } + } + public void SetHpPercent(ShipLabel.Hp label) { if (_hpPercent) -- 2.11.0