From 95ccefbb1b4d73313001a1690150816a5cb08500 Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 9 May 2026 22:01:19 +0100 Subject: [PATCH] Added tile drag-move --- MainForm.cs | 44 +++++++++++++++++++++++++++++++- Windows/Forms/TileLayoutPanel.cs | 31 ++++++++++++++++++++++ Windows/Forms/TilePanel.cs | 10 ++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) diff --git a/MainForm.cs b/MainForm.cs index ed29e5d..fb96d3c 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -1009,6 +1009,8 @@ namespace RokettoLaunch var tableLayout = (TileLayoutPanel)headers[n].ToggleControl; tableLayout.AddTilePanel(newTilePanel, newTileInfo.Position.X, newTileInfo.Position.Y); tableLayout.SetGridSize(this.CurrentSession.Groups[n].GridSize); + + } } @@ -1058,6 +1060,7 @@ namespace RokettoLaunch private void AddGroup(App4Options.Group groupInfo) { var tableLayout = CreateTable(groupInfo.GridSize); + tableLayout.GroupId = groupInfo.Id; var header = CreateHeader(groupInfo); header.ToggleControlId = groupInfo.Id; @@ -1104,6 +1107,7 @@ namespace RokettoLaunch private TileLayoutPanel CreateTable(Size gridSize) { var layoutPanel = new TileLayoutPanel(); + layoutPanel.DragDrop += LayoutPanel_DragDrop; layoutPanel.SetGridSize(gridSize); return layoutPanel; @@ -1217,6 +1221,45 @@ namespace RokettoLaunch return contextMenu; } + private async void LayoutPanel_DragDrop(object sender, DragEventArgs e) + { + if (!e.Data.TryGetData(out var tilePanel)) + { + return; + } + + var tableLayout = (sender as TileLayoutPanel); + + var point = tableLayout.PointToClient(new Point(e.X, e.Y)); + var newPosition = tableLayout.GetCellFromPoint(new Point(point.X, point.Y)); + + var groupInfo = this.CurrentSession.Groups.Where(x => x.Id == tableLayout.GroupId).FirstOrDefault(); + if (groupInfo == null) + { + return; + } + + var newGridPosition = new Point(newPosition.X, newPosition.Y); + if (groupInfo.Items.Where(x => x.Position == newGridPosition).Any()) + { + // Position already occupied + return; + } + + await Task.Run(() => + { + var foundTileInfo = this.CurrentSession.FindById(tilePanel.TileId); + foundTileInfo.Position = newGridPosition; + + this.Controls.Remove(tilePanel); + + tableLayout.AddTilePanel(tilePanel, newPosition.X, newPosition.Y); + }); + + _fileSessionManager.HasChanged = true; + } + + private void TilePanel_MouseClick(object sender, MouseEventArgs e) { var tilePanel = (sender as TilePanel); @@ -1345,6 +1388,5 @@ namespace RokettoLaunch RyzStudio.Diagnostics.Process.Execute(model.ResolvedTargetPath, model.ResolvedStartPath, model.ResolvedArgument, model.WindowStyle, model.RunAsAdmin); } - } } \ No newline at end of file diff --git a/Windows/Forms/TileLayoutPanel.cs b/Windows/Forms/TileLayoutPanel.cs index a0226b3..b1b4c84 100644 --- a/Windows/Forms/TileLayoutPanel.cs +++ b/Windows/Forms/TileLayoutPanel.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using System.Drawing; using System.Windows.Forms; using RyzStudio.Windows.Forms; @@ -14,12 +15,28 @@ namespace RokettoLaunch.Windows.Forms public TileLayoutPanel() : base() { + this.AllowDrop = true; this.Margin = new Padding(0); this.Padding = new Padding(0); this.ColumnCount = 0; this.RowCount = 0; } + protected override void OnDragEnter(DragEventArgs e) + { + base.OnDragEnter(e); + + if (e.Data.TryGetData(out var data)) + { + e.Effect = DragDropEffects.Move; + } + } + + + [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + public Guid GroupId { get; set; } = Guid.Empty; + + public void AddTilePanel(TilePanel tilePanel, int x, int y) { UIControl.Add(this, tilePanel, x, y); @@ -111,5 +128,19 @@ namespace RokettoLaunch.Windows.Forms }); } + public Point GetCellFromPoint(Point point) + { + var width = this.ClientSize.Width; + var height = this.ClientSize.Height; + + var x = (int)((float)point.X / width * this.ColumnCount); + var y = (int)((float)point.Y / height * this.RowCount); + + x = Math.Max(0, Math.Min(this.ColumnCount - 1, x)); + y = Math.Max(0, Math.Min(this.RowCount - 1, y)); + + return new Point(x, y); + } + } } diff --git a/Windows/Forms/TilePanel.cs b/Windows/Forms/TilePanel.cs index 969b5c7..239075b 100644 --- a/Windows/Forms/TilePanel.cs +++ b/Windows/Forms/TilePanel.cs @@ -64,5 +64,15 @@ namespace RokettoLaunch.Windows.Forms } } + protected override void OnMouseDown(MouseEventArgs e) + { + base.OnMouseDown(e); + + if (e.Button == MouseButtons.Right) + { + this.DoDragDrop(this, DragDropEffects.Move); + } + } + } } \ No newline at end of file