Added tile drag-move

This commit is contained in:
Ray 2026-05-09 22:01:19 +01:00
parent afa73a1ab0
commit 95ccefbb1b
3 changed files with 84 additions and 1 deletions

View File

@ -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<TilePanel>(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);
}
}
}

View File

@ -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<TilePanel>(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);
}
}
}

View File

@ -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);
}
}
}
}