Skip to content

Commit 2ecf9c3

Browse files
committed
up 游戏实例移动
1 parent 70eb5b6 commit 2ecf9c3

14 files changed

Lines changed: 312 additions & 38 deletions

src/ColorMC.Gui/UI/Controls/Count/CountControl.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</UserControl.Styles>
3636

3737
<ScrollViewer>
38-
<StackPanel Margin="10">
38+
<StackPanel Margin="30">
3939

4040
<!-- 第一部分:启动统计 (使用 Grid 均分列) -->
4141
<Border Margin="0,0,0,10" Classes="t2">

src/ColorMC.Gui/UI/Controls/Items/GameControl.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
d:DesignWidth="80"
1313
x:DataType="model:GameItemModel"
1414
IsVisible="{Binding IsDisplay}"
15+
Opacity="{Binding Opa}"
1516
ToolTip.Tip="{Binding Tips}"
1617
mc:Ignorable="d">
1718
<Panel Background="Transparent">

src/ColorMC.Gui/UI/Controls/Items/GameControl.axaml.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ public GameControl()
4444
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
4545
{
4646
base.OnApplyTemplate(e);
47+
48+
if (DataContext is GameItemModel model)
49+
{
50+
if (model.Opa != 1.0)
51+
{
52+
return;
53+
}
54+
}
55+
4756
if (GuiConfigUtils.Config.Style.EnableAm)
4857
{
4958
Dispatcher.UIThread.Post(() =>
@@ -104,12 +113,12 @@ private void GameControl_PointerMoved(object? sender, PointerEventArgs e)
104113
if (pro.Properties.IsLeftButtonPressed && DataContext is GameItemModel model && !model.IsNew)
105114
{
106115
var pos = pro.Position;
107-
if (Math.Sqrt(Math.Pow(Math.Abs(pos.X - point.X), 2) + Math.Pow(Math.Abs(pos.Y - point.Y), 2)) > 30)
116+
if (Math.Sqrt(Math.Pow(Math.Abs(pos.X - point.X), 2) + Math.Pow(Math.Abs(pos.Y - point.Y), 2)) > 40)
108117
{
109118
var top = TopLevel.GetTopLevel(this);
110119
if (top != null)
111120
{
112-
model.Move(top, e, model.Pic);
121+
model.Move(top, e);
113122
}
114123

115124
e.Handled = true;

src/ColorMC.Gui/UI/Controls/Main/GameGroupControl.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
</ItemsControl.ItemsPanel>
6161
<ItemsControl.ItemTemplate>
6262
<DataTemplate>
63-
<views1:GameControl Margin="0,0,1,1" DataContext="{Binding}" />
63+
<views1:GameControl DataContext="{Binding}" />
6464
</DataTemplate>
6565
</ItemsControl.ItemTemplate>
6666
</ItemsControl>

src/ColorMC.Gui/UI/Controls/Main/GameGroupControl.axaml.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
using Avalonia.Controls;
33
using Avalonia.Input;
44
using Avalonia.Media.Imaging;
5+
using Avalonia.VisualTree;
56
using ColorMC.Core.LaunchPath;
67
using ColorMC.Gui.Manager;
8+
using ColorMC.Gui.UI.Controls.Items;
79
using ColorMC.Gui.UI.Flyouts;
10+
using ColorMC.Gui.UI.Model.Items;
811
using ColorMC.Gui.UI.Model.Main;
912
using ColorMC.Gui.UIBinding;
1013

@@ -27,9 +30,43 @@ public GameGroupControl()
2730

2831
AddHandler(DragDrop.DragEnterEvent, DragEnter);
2932
AddHandler(DragDrop.DragLeaveEvent, DragLeave);
33+
AddHandler(DragDrop.DragOverEvent, OnDragOver);
3034
AddHandler(DragDrop.DropEvent, Drop);
3135
}
3236

37+
public void OnDragOver(object? sender, DragEventArgs e)
38+
{
39+
var draggedItem = e.DataTransfer.TryGetValue(BaseBinding.DrapType);
40+
41+
if (draggedItem == null)
42+
{
43+
return;
44+
}
45+
46+
var vm = DataContext as GameGroupModel;
47+
48+
var visualTarget = e.Source as Visual;
49+
var targetBorder = visualTarget?.FindAncestorOfType<GameControl>();
50+
51+
if (targetBorder != null && targetBorder?.DataContext is GameItemModel targetItem)
52+
{
53+
var pos = e.GetPosition(targetBorder);
54+
55+
if (pos.X > targetBorder.Bounds.Width / 2)
56+
{
57+
vm?.PutPla(targetItem, false);
58+
}
59+
else
60+
{
61+
vm?.PutPla(targetItem, true);
62+
}
63+
}
64+
else
65+
{
66+
vm?.PutPla();
67+
}
68+
}
69+
3370
private void GameGroupControl_PointerPressed(object? sender, PointerPressedEventArgs e)
3471
{
3572
var temp = e.GetCurrentPoint(this).Properties;
@@ -107,5 +144,35 @@ private void Drop(object? sender, DragEventArgs e)
107144
{
108145
model.Drop(e.DataTransfer);
109146
}
147+
148+
var draggedItem = e.DataTransfer.TryGetValue(BaseBinding.DrapType);
149+
150+
if (draggedItem == null)
151+
{
152+
return;
153+
}
154+
155+
var vm = DataContext as GameGroupModel;
156+
157+
var visualTarget = e.Source as Visual;
158+
var targetBorder = visualTarget?.FindAncestorOfType<GameControl>();
159+
160+
if (targetBorder != null && targetBorder?.DataContext is GameItemModel targetItem)
161+
{
162+
var pos = e.GetPosition(targetBorder);
163+
164+
if (pos.X > targetBorder.Bounds.Width / 2)
165+
{
166+
vm?.PutDrap(targetItem, false);
167+
}
168+
else
169+
{
170+
vm?.PutDrap(targetItem, true);
171+
}
172+
}
173+
else
174+
{
175+
vm?.PutDrap();
176+
}
110177
}
111178
}

src/ColorMC.Gui/UI/Controls/Main/MainControl.axaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@
164164
<cards:LastControl Margin="0,20,0,0" IsVisible="{Binding HaveLast}" />
165165
</StackPanel>
166166
</ScrollViewer>
167-
<ScrollViewer Margin="0,0,0,0">
168-
<DockPanel Name="ContentOut" Margin="0,0,20,0">
167+
<ScrollViewer Margin="0,0,10,0">
168+
<DockPanel Name="ContentOut" Margin="0,0,10,0">
169169
<views:ServerMotdControl
170170
Margin="30,20,0,0"
171171
DockPanel.Dock="Top"

src/ColorMC.Gui/UI/Controls/Main/MainControl.axaml.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ private async Task DropAsync(object? sender, DragEventArgs e)
132132
{
133133
if (e.DataTransfer.Contains(BaseBinding.DrapType))
134134
{
135+
if (Content1.Child is MainGamesControl games)
136+
{
137+
games.OnDrop(sender, e);
138+
}
135139
return;
136140
}
137141
Grid2.IsVisible = false;

src/ColorMC.Gui/UI/Controls/Main/MainGamesControl.axaml.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using System;
2+
using System.Diagnostics;
13
using Avalonia;
24
using Avalonia.Controls;
35
using Avalonia.Input;
@@ -19,12 +21,40 @@ public MainGamesControl()
1921
AddHandler(DragDrop.DragOverEvent, OnDragOver);
2022
}
2123

22-
private void OnDragOver(object? sender, DragEventArgs e)
24+
public void OnDragOver(object? sender, DragEventArgs e)
2325
{
26+
var draggedItem = e.DataTransfer.TryGetValue(BaseBinding.DrapType);
2427

28+
if (draggedItem == null)
29+
{
30+
return;
31+
}
32+
33+
var vm = DataContext as MainModel;
34+
35+
var visualTarget = e.Source as Visual;
36+
var targetBorder = visualTarget?.FindAncestorOfType<GameControl>();
37+
38+
if (targetBorder != null && targetBorder?.DataContext is GameItemModel targetItem)
39+
{
40+
var pos = e.GetPosition(targetBorder);
41+
42+
if (pos.X > targetBorder.Bounds.Width / 2)
43+
{
44+
vm?.PutPla(targetItem, false);
45+
}
46+
else
47+
{
48+
vm?.PutPla(targetItem, true);
49+
}
50+
}
51+
else
52+
{
53+
vm?.PutPla();
54+
}
2555
}
2656

27-
private void OnDrop(object? sender, DragEventArgs e)
57+
public void OnDrop(object? sender, DragEventArgs e)
2858
{
2959
var draggedItem = e.DataTransfer.TryGetValue(BaseBinding.DrapType);
3060

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using ColorMC.Gui.UI.Model.Items;
5+
6+
namespace ColorMC.Gui.UI.Model;
7+
8+
public interface IDragTop
9+
{
10+
/// <summary>
11+
/// 开始拖拽
12+
/// </summary>
13+
/// <param name="item">游戏实例</param>
14+
void Drag(GameItemModel item);
15+
}

src/ColorMC.Gui/UI/Model/IMainTop.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,4 @@ public interface IMainTop
5555
/// </summary>
5656
/// <param name="obj">游戏实例</param>
5757
void ExportCmd(GameSettingObj obj);
58-
/// <summary>
59-
/// 开始拖拽
60-
/// </summary>
61-
/// <param name="item">游戏实例</param>
62-
void Drag(GameItemModel item);
6358
}

0 commit comments

Comments
 (0)