X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=KancolleSniffer%2FShipListPanel.cs;h=017c71c9849292a8b4805fffb066b1f0d73f83ae;hb=2239ef207d5559e76b4262eb4015cde28ea63ced;hp=c7f3666096d5c421bafdb11cbea5fa36958edfbe;hpb=9bcc2343d816d53fea906d2274e305e806dee30e;p=kancollesniffer%2FKancolleSniffer.git diff --git a/KancolleSniffer/ShipListPanel.cs b/KancolleSniffer/ShipListPanel.cs index c7f3666..017c71c 100644 --- a/KancolleSniffer/ShipListPanel.cs +++ b/KancolleSniffer/ShipListPanel.cs @@ -18,6 +18,7 @@ using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Windows.Forms; +using static System.Math; namespace KancolleSniffer { @@ -49,21 +50,27 @@ namespace KancolleSniffer private void ScrollBarOnValueChanged(object sender, EventArgs eventArgs) { + SuspendDrawing(); SetShipLabels(); + ResumeDrawing(); } protected override void OnResize(EventArgs ev) { base.OnResize(ev); - if (_shipList == null || _shipList.Length == 0) + if (_shipList == null || _shipList.Length == 0 || !Visible) return; + SuspendDrawing(); SetupLabels(); SetShipLabels(); + ResumeDrawing(); } protected override void OnMouseWheel(MouseEventArgs e) { - ScrollBar.Value = Math.Max(ScrollBar.Minimum, Math.Min(ScrollBar.Maximum - ScrollBar.LargeChange + 1, + if (!ScrollBar.Visible) + return; + ScrollBar.Value = Max(ScrollBar.Minimum, Min(ScrollBar.Maximum - ScrollBar.LargeChange + 1, ScrollBar.Value - e.Delta * SystemInformation.MouseWheelScrollLines / 120)); } @@ -71,10 +78,26 @@ namespace KancolleSniffer { _mode = mode; CreateShipList(sniffer, sortOrder, byShipType); - if (_shipList.Length == 0) - return; + SuspendDrawing(); SetupLabels(); SetShipLabels(); + ResumeDrawing(); + } + + [DllImport("user32.dll")] + public static extern int SendMessage(IntPtr hWnd, int wMsg, bool wParam, IntPtr lParam); + + private void SuspendDrawing() + { + SendMessage(Handle, 11, false, IntPtr.Zero); // WM_SETREDRAW = 11 + SuspendLayout(); + } + + public void ResumeDrawing() + { + ResumeLayout(); + SendMessage(Handle, 11, true, IntPtr.Zero); + Refresh(); } void CreateShipList(Sniffer sniffer, ListForm.SortOrder sortOrder, bool byShipType) @@ -124,26 +147,43 @@ namespace KancolleSniffer { if (a == null || b == null) throw new ArgumentNullException(); - if (_shipType && a.Spec.ShipType != b.Spec.ShipType) - return a.Spec.ShipType - b.Spec.ShipType; - switch (_order) + if (_shipType) { - case ListForm.SortOrder.None: - case ListForm.SortOrder.ExpToNext: - break; - case ListForm.SortOrder.Cond: - if (a.Cond != b.Cond) - return a.Cond - b.Cond; - break; - case ListForm.SortOrder.Repair: - if (a.RepairTime != b.RepairTime) - return (int)(b.RepairTime - a.RepairTime).TotalSeconds; - break; + if (a.Spec.ShipType != b.Spec.ShipType) + return a.Spec.ShipType - b.Spec.ShipType; + if (a.Level != b.Level) + { + if (a.Level == 1000) + return -1; + if (b.Level == 1000) + return 1; + } + } + if (_order == ListForm.SortOrder.Repair && a.RepairTime != b.RepairTime) + return (int)(b.RepairTime - a.RepairTime).TotalSeconds; + if (a.Cond != b.Cond) + { + if (_order == ListForm.SortOrder.CondAscend) + return a.Cond - b.Cond; + if (_order == ListForm.SortOrder.CondDescend) + return b.Cond - a.Cond; + } + if (a.Level != b.Level) + { + if (_order == ListForm.SortOrder.ExpToNextAscend) + return b.Level - a.Level; + if (_order == ListForm.SortOrder.ExpToNextDescend) + return a.Level - b.Level; + if (!_shipType) // Condが同じかSortOrder.Noneで艦種なし + return b.Level - a.Level; + } + if (a.ExpToNext != b.ExpToNext) + { + if (_order == ListForm.SortOrder.ExpToNextAscend) + return a.ExpToNext - b.ExpToNext; + if (_order == ListForm.SortOrder.ExpToNextDescend) + return b.ExpToNext - a.ExpToNext; } - if ((!_shipType || _order == ListForm.SortOrder.ExpToNext) && a.Level != b.Level) - return b.Level - a.Level; - if (_order == ListForm.SortOrder.ExpToNext && a.ExpToNext != b.ExpToNext) - return a.ExpToNext - b.ExpToNext; if (a.Spec.SortNo != b.Spec.SortNo) return a.Spec.SortNo - b.Spec.SortNo; return a.Id - b.Id; @@ -152,7 +192,6 @@ namespace KancolleSniffer private void SetupLabels() { - SuspendLayout(); for (var i = _labelList.Count; i * LineHeight < Height; i++) { CreateGroupingComponents(i); @@ -166,23 +205,25 @@ namespace KancolleSniffer _repairPanelList[i].Visible = _mode == "修復"; } SetupScrollBar(); - ResumeLayout(); } private void SetupScrollBar() { - ScrollBar.Visible = _shipList.Length * LineHeight > Height; - if (!ScrollBar.Visible) + var needBar = _shipList.Length * LineHeight * ShipLabel.ScaleFactor.Height > Height; + if (!needBar) { + ScrollBar.Visible = false; ScrollBar.Value = 0; return; } + ScrollBar.Visible = true; ScrollBar.Minimum = 0; - var max = _shipList.Length - Height / LineHeight; - ScrollBar.LargeChange = Math.Min(10, max); + var lines = Max(1, Height / (int)Round(LineHeight * ShipLabel.ScaleFactor.Height)); + var max = _shipList.Length - lines; + ScrollBar.LargeChange = Min(lines, max); ScrollBar.Maximum = - Math.Max(0, max + ScrollBar.LargeChange - 1); // ScrollBarを最大まで動かしてもmaxには届かない - ScrollBar.Value = Math.Min(ScrollBar.Value, max); + Max(0, max + ScrollBar.LargeChange - 1); // ScrollBarを最大まで動かしてもmaxには届かない + ScrollBar.Value = Min(ScrollBar.Value, max); } private void CreateGroupingComponents(int i) @@ -200,8 +241,8 @@ namespace KancolleSniffer { new ShipLabel { - Location = new Point(91, 2), - Size = new Size(23, LabelHeight), + Location = new Point(90, 2), + Size = new Size(24, LabelHeight), TextAlign = ContentAlignment.MiddleRight }, new ShipLabel {Location = new Point(10, 2), AutoSize = true}, @@ -269,8 +310,8 @@ namespace KancolleSniffer new ShipLabel {Location = new Point(118, 2), AutoSize = true, AnchorRight = true}, new ShipLabel { - Location = new Point(117, 2), - Size = new Size(23, height), + Location = new Point(116, 2), + Size = new Size(24, height), TextAlign = ContentAlignment.MiddleRight }, new ShipLabel {Location = new Point(141, 2), AutoSize = true}, @@ -307,20 +348,20 @@ namespace KancolleSniffer new ShipLabel {Location = new Point(126, 2), AutoSize = true, AnchorRight = true}, new ShipLabel { - Location = new Point(129, 2), - Size = new Size(23, height), + Location = new Point(128, 2), + Size = new Size(24, height), TextAlign = ContentAlignment.MiddleRight }, new ShipLabel { - Location = new Point(155, 2), - Size = new Size(23, height), + Location = new Point(154, 2), + Size = new Size(24, height), TextAlign = ContentAlignment.MiddleRight }, new ShipLabel { - Location = new Point(176, 2), - Size = new Size(41, height), + Location = new Point(175, 2), + Size = new Size(42, height), TextAlign = ContentAlignment.MiddleRight }, new ShipLabel {Location = new Point(10, 2), AutoSize = true}, @@ -341,8 +382,6 @@ namespace KancolleSniffer private void SetShipLabels() { - SuspendDrawing(); - SuspendLayout(); for (var i = 0; i < (Height + LineHeight - 1) / LineHeight; i++) { if (InShipStatus(_mode)) @@ -352,22 +391,6 @@ namespace KancolleSniffer if (_mode == "修復") SetRepairList(i); } - ResumeLayout(); - ResumeDrawing(); - } - - [DllImport("user32.dll")] - public static extern int SendMessage(IntPtr hWnd, int wMsg, bool wParam, IntPtr lParam); - - private void SuspendDrawing() - { - SendMessage(Handle, 11, false, IntPtr.Zero); // WM_SETREDRAW = 11 - } - - public void ResumeDrawing() - { - SendMessage(Handle, 11, true, IntPtr.Zero); - Refresh(); } private bool InShipStatus(string mode) => Array.Exists(new[] {"全員", "A", "B", "C", "D"}, x => mode == x); @@ -456,7 +479,7 @@ namespace KancolleSniffer rpl[0].SetHp(s); rpl[1].SetLevel(s); rpl[2].SetRepairTime(s); - rpl[3].Text = TimeSpan.FromSeconds(s.RepairSecPerHp).ToString(@"mm\:ss"); + rpl[3].Text = s.RepairTimePerHp.ToString(@"mm\:ss"); rpl[4].SetName(s, ShipNameWidth.RepairListFull); rpl[5].SetFleet(s); panel.Visible = true; @@ -467,7 +490,7 @@ namespace KancolleSniffer var i = Array.FindIndex(_shipList, s => s.Id == id); if (i == -1) return; - ScrollBar.Value = Math.Min(i, ScrollBar.Maximum + 1 - ScrollBar.LargeChange); + ScrollBar.Value = Min(i, ScrollBar.Maximum + 1 - ScrollBar.LargeChange); SetShipLabels(); } }