using System.Linq;\r
using System.Runtime.InteropServices;\r
using System.Windows.Forms;\r
+using static System.Math;\r
\r
namespace KancolleSniffer\r
{\r
\r
public ScrollBar ScrollBar { get; }\r
\r
- private class FastWheelScrollBar : VScrollBar\r
- {\r
- protected override void OnMouseWheel(MouseEventArgs ev)\r
- {\r
- Value = Math.Max(Minimum, Math.Min(Maximum - LargeChange + 1,\r
- Value - ev.Delta * SystemInformation.MouseWheelScrollLines / 120));\r
- }\r
- }\r
-\r
public ShipListPanel()\r
{\r
- ScrollBar = new FastWheelScrollBar {Dock = DockStyle.Right, Visible = false};\r
+ ScrollBar = new VScrollBar {Dock = DockStyle.Right, Visible = false};\r
ScrollBar.ValueChanged += ScrollBarOnValueChanged;\r
Controls.Add(ScrollBar);\r
}\r
\r
private void ScrollBarOnValueChanged(object sender, EventArgs eventArgs)\r
{\r
+ SuspendDrawing();\r
SetShipLabels();\r
+ ResumeDrawing();\r
}\r
\r
protected override void OnResize(EventArgs ev)\r
{\r
base.OnResize(ev);\r
- if (_shipList == null || _shipList.Length == 0)\r
+ if (_shipList == null || _shipList.Length == 0 || !Visible)\r
return;\r
+ SuspendDrawing();\r
SetupLabels();\r
SetShipLabels();\r
+ ResumeDrawing();\r
+ }\r
+\r
+ protected override void OnMouseWheel(MouseEventArgs e)\r
+ {\r
+ if (!ScrollBar.Visible)\r
+ return;\r
+ ScrollBar.Value = Max(ScrollBar.Minimum, Min(ScrollBar.Maximum - ScrollBar.LargeChange + 1,\r
+ ScrollBar.Value - e.Delta * SystemInformation.MouseWheelScrollLines / 120));\r
}\r
\r
public void Update(Sniffer sniffer, string mode, ListForm.SortOrder sortOrder, bool byShipType)\r
{\r
_mode = mode;\r
CreateShipList(sniffer, sortOrder, byShipType);\r
- if (_shipList.Length == 0)\r
- return;\r
+ SuspendDrawing();\r
SetupLabels();\r
SetShipLabels();\r
+ ResumeDrawing();\r
+ }\r
+\r
+ [DllImport("user32.dll")]\r
+ public static extern int SendMessage(IntPtr hWnd, int wMsg, bool wParam, IntPtr lParam);\r
+\r
+ private void SuspendDrawing()\r
+ {\r
+ SendMessage(Handle, 11, false, IntPtr.Zero); // WM_SETREDRAW = 11\r
+ SuspendLayout();\r
+ }\r
+\r
+ public void ResumeDrawing()\r
+ {\r
+ ResumeLayout();\r
+ SendMessage(Handle, 11, true, IntPtr.Zero);\r
+ Refresh();\r
}\r
\r
void CreateShipList(Sniffer sniffer, ListForm.SortOrder sortOrder, bool byShipType)\r
{\r
if (a == null || b == null)\r
throw new ArgumentNullException();\r
- if (_shipType && a.Spec.ShipType != b.Spec.ShipType)\r
- return a.Spec.ShipType - b.Spec.ShipType;\r
- switch (_order)\r
+ if (_shipType)\r
+ {\r
+ if (a.Spec.ShipType != b.Spec.ShipType)\r
+ return a.Spec.ShipType - b.Spec.ShipType;\r
+ if (a.Level != b.Level)\r
+ {\r
+ if (a.Level == 1000)\r
+ return -1;\r
+ if (b.Level == 1000)\r
+ return 1;\r
+ }\r
+ }\r
+ if (_order == ListForm.SortOrder.Repair && a.RepairTime != b.RepairTime)\r
+ return (int)(b.RepairTime - a.RepairTime).TotalSeconds;\r
+ if (a.Cond != b.Cond)\r
+ {\r
+ if (_order == ListForm.SortOrder.CondAscend)\r
+ return a.Cond - b.Cond;\r
+ if (_order == ListForm.SortOrder.CondDescend)\r
+ return b.Cond - a.Cond;\r
+ }\r
+ if (a.Level != b.Level)\r
{\r
- case ListForm.SortOrder.None:\r
- case ListForm.SortOrder.ExpToNext:\r
- break;\r
- case ListForm.SortOrder.Cond:\r
- if (a.Cond != b.Cond)\r
- return a.Cond - b.Cond;\r
- break;\r
- case ListForm.SortOrder.Repair:\r
- if (a.RepairTime != b.RepairTime)\r
- return (int)(b.RepairTime - a.RepairTime).TotalSeconds;\r
- break;\r
+ if (_order == ListForm.SortOrder.ExpToNextAscend)\r
+ return b.Level - a.Level;\r
+ if (_order == ListForm.SortOrder.ExpToNextDescend)\r
+ return a.Level - b.Level;\r
+ if (!_shipType) // Condが同じかSortOrder.Noneで艦種なし\r
+ return b.Level - a.Level;\r
+ }\r
+ if (a.ExpToNext != b.ExpToNext)\r
+ {\r
+ if (_order == ListForm.SortOrder.ExpToNextAscend)\r
+ return a.ExpToNext - b.ExpToNext;\r
+ if (_order == ListForm.SortOrder.ExpToNextDescend)\r
+ return b.ExpToNext - a.ExpToNext;\r
}\r
- if ((!_shipType || _order == ListForm.SortOrder.ExpToNext) && a.Level != b.Level)\r
- return b.Level - a.Level;\r
- if (_order == ListForm.SortOrder.ExpToNext && a.ExpToNext != b.ExpToNext)\r
- return a.ExpToNext - b.ExpToNext;\r
if (a.Spec.SortNo != b.Spec.SortNo)\r
return a.Spec.SortNo - b.Spec.SortNo;\r
return a.Id - b.Id;\r
\r
private void SetupLabels()\r
{\r
- SuspendLayout();\r
for (var i = _labelList.Count; i * LineHeight < Height; i++)\r
{\r
CreateGroupingComponents(i);\r
_repairPanelList[i].Visible = _mode == "修復";\r
}\r
SetupScrollBar();\r
- ResumeLayout();\r
}\r
\r
private void SetupScrollBar()\r
{\r
- ScrollBar.Visible = _shipList.Length * LineHeight > Height;\r
- if (!ScrollBar.Visible)\r
+ var needBar = _shipList.Length * LineHeight * ShipLabel.ScaleFactor.Height > Height;\r
+ if (!needBar)\r
{\r
+ ScrollBar.Visible = false;\r
ScrollBar.Value = 0;\r
return;\r
}\r
+ ScrollBar.Visible = true;\r
ScrollBar.Minimum = 0;\r
- var max = _shipList.Length - Height / LineHeight;\r
- ScrollBar.LargeChange = Math.Min(10, max);\r
+ var lines = Max(1, Height / (int)Round(LineHeight * ShipLabel.ScaleFactor.Height));\r
+ var max = _shipList.Length - lines;\r
+ ScrollBar.LargeChange = Min(lines, max);\r
ScrollBar.Maximum =\r
- Math.Max(0, max + ScrollBar.LargeChange - 1); // ScrollBarを最大まで動かしてもmaxには届かない\r
- ScrollBar.Value = Math.Min(ScrollBar.Value, max);\r
+ Max(0, max + ScrollBar.LargeChange - 1); // ScrollBarを最大まで動かしてもmaxには届かない\r
+ ScrollBar.Value = Min(ScrollBar.Value, max);\r
}\r
\r
private void CreateGroupingComponents(int i)\r
{\r
new ShipLabel\r
{\r
- Location = new Point(91, 2),\r
- Size = new Size(23, LabelHeight),\r
+ Location = new Point(90, 2),\r
+ Size = new Size(24, LabelHeight),\r
TextAlign = ContentAlignment.MiddleRight\r
},\r
new ShipLabel {Location = new Point(10, 2), AutoSize = true},\r
new ShipLabel {Location = new Point(118, 2), AutoSize = true, AnchorRight = true},\r
new ShipLabel\r
{\r
- Location = new Point(117, 2),\r
- Size = new Size(23, height),\r
+ Location = new Point(116, 2),\r
+ Size = new Size(24, height),\r
TextAlign = ContentAlignment.MiddleRight\r
},\r
new ShipLabel {Location = new Point(141, 2), AutoSize = true},\r
new ShipLabel {Location = new Point(126, 2), AutoSize = true, AnchorRight = true},\r
new ShipLabel\r
{\r
- Location = new Point(129, 2),\r
- Size = new Size(23, height),\r
+ Location = new Point(128, 2),\r
+ Size = new Size(24, height),\r
TextAlign = ContentAlignment.MiddleRight\r
},\r
new ShipLabel\r
{\r
- Location = new Point(155, 2),\r
- Size = new Size(23, height),\r
+ Location = new Point(154, 2),\r
+ Size = new Size(24, height),\r
TextAlign = ContentAlignment.MiddleRight\r
},\r
new ShipLabel\r
{\r
- Location = new Point(176, 2),\r
- Size = new Size(41, height),\r
+ Location = new Point(175, 2),\r
+ Size = new Size(42, height),\r
TextAlign = ContentAlignment.MiddleRight\r
},\r
new ShipLabel {Location = new Point(10, 2), AutoSize = true},\r
\r
private void SetShipLabels()\r
{\r
- SuspendDrawing();\r
- SuspendLayout();\r
for (var i = 0; i < (Height + LineHeight - 1) / LineHeight; i++)\r
{\r
if (InShipStatus(_mode))\r
if (_mode == "修復")\r
SetRepairList(i);\r
}\r
- ResumeLayout();\r
- ResumeDrawing();\r
- }\r
-\r
- [DllImport("user32.dll")]\r
- public static extern int SendMessage(IntPtr hWnd, int wMsg, bool wParam, IntPtr lParam);\r
-\r
- private void SuspendDrawing()\r
- {\r
- SendMessage(Handle, 11, false, IntPtr.Zero); // WM_SETREDRAW = 11\r
- }\r
-\r
- public void ResumeDrawing()\r
- {\r
- SendMessage(Handle, 11, true, IntPtr.Zero);\r
- Refresh();\r
}\r
\r
private bool InShipStatus(string mode) => Array.Exists(new[] {"全員", "A", "B", "C", "D"}, x => mode == x);\r
rpl[0].SetHp(s);\r
rpl[1].SetLevel(s);\r
rpl[2].SetRepairTime(s);\r
- rpl[3].Text = TimeSpan.FromSeconds(s.RepairSecPerHp).ToString(@"mm\:ss");\r
+ rpl[3].Text = s.RepairTimePerHp.ToString(@"mm\:ss");\r
rpl[4].SetName(s, ShipNameWidth.RepairListFull);\r
rpl[5].SetFleet(s);\r
panel.Visible = true;\r
var i = Array.FindIndex(_shipList, s => s.Id == id);\r
if (i == -1)\r
return;\r
- ScrollBar.Value = Math.Min(i, ScrollBar.Maximum + 1 - ScrollBar.LargeChange);\r
+ ScrollBar.Value = Min(i, ScrollBar.Maximum + 1 - ScrollBar.LargeChange);\r
SetShipLabels();\r
}\r
}\r