drag and drop UI
This commit is contained in:
54
Main.tscn
54
Main.tscn
@@ -1,8 +1,7 @@
|
|||||||
[gd_scene format=3 uid="uid://b2rl7r8oav3hy"]
|
[gd_scene format=3 uid="uid://b2rl7r8oav3hy"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://dciugg77wsy6p" path="res://Meeting.tscn" id="1_glv2v"]
|
[ext_resource type="PackedScene" uid="uid://dciugg77wsy6p" path="res://Meeting.tscn" id="1_glv2v"]
|
||||||
[ext_resource type="Script" uid="uid://dldaxqajhnnva" path="res://TimeSlot.cs" id="2_r0du0"]
|
[ext_resource type="PackedScene" uid="uid://nnr6u0igggve" path="res://TimeSlot.tscn" id="1_uu6xs"]
|
||||||
[ext_resource type="PackedScene" uid="uid://do8ll0kylvrcn" path="res://MeetingControl.tscn" id="2_uu6xs"]
|
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_sko1m"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_sko1m"]
|
||||||
size = Vector2(575, 20)
|
size = Vector2(575, 20)
|
||||||
@@ -12,46 +11,49 @@ size = Vector2(21.5, 1920)
|
|||||||
|
|
||||||
[node name="Main" type="Node2D" unique_id=287617203]
|
[node name="Main" type="Node2D" unique_id=287617203]
|
||||||
|
|
||||||
[node name="MeetingControl" parent="." unique_id=11410047 instance=ExtResource("2_uu6xs")]
|
|
||||||
anchors_preset = 8
|
|
||||||
anchor_left = 0.5
|
|
||||||
anchor_top = 0.5
|
|
||||||
anchor_right = 0.5
|
|
||||||
anchor_bottom = 0.5
|
|
||||||
offset_left = 631.0
|
|
||||||
offset_top = 18.0
|
|
||||||
offset_right = 960.0
|
|
||||||
offset_bottom = 98.0
|
|
||||||
grow_horizontal = 2
|
|
||||||
grow_vertical = 2
|
|
||||||
mouse_default_cursor_shape = 2
|
|
||||||
metadata/_edit_use_anchors_ = true
|
|
||||||
|
|
||||||
[node name="Control" type="Control" parent="." unique_id=1593899]
|
[node name="Control" type="Control" parent="." unique_id=1593899]
|
||||||
layout_mode = 3
|
layout_mode = 3
|
||||||
anchors_preset = 0
|
anchors_preset = 0
|
||||||
offset_left = 114.0
|
offset_left = 125.0
|
||||||
offset_top = 34.0
|
offset_top = 43.0
|
||||||
offset_right = 514.0
|
offset_right = 455.0
|
||||||
offset_bottom = 603.0
|
offset_bottom = 602.0
|
||||||
|
mouse_filter = 2
|
||||||
|
|
||||||
[node name="PanelContainer" type="PanelContainer" parent="Control" unique_id=1636973054]
|
[node name="PanelContainer" type="PanelContainer" parent="Control" unique_id=1636973054]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
offset_left = -1.0
|
|
||||||
offset_right = -1.0
|
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
|
mouse_filter = 2
|
||||||
|
|
||||||
[node name="VBoxContainer" type="VBoxContainer" parent="Control/PanelContainer" unique_id=1658498861]
|
[node name="VBoxContainer" type="VBoxContainer" parent="Control/PanelContainer" unique_id=1658498861]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
mouse_filter = 2
|
||||||
|
alignment = 1
|
||||||
|
|
||||||
[node name="TimeSlot" type="PanelContainer" parent="Control/PanelContainer/VBoxContainer" unique_id=1554329623]
|
[node name="TimeSlot" parent="Control/PanelContainer/VBoxContainer" unique_id=979842204 instance=ExtResource("1_uu6xs")]
|
||||||
custom_minimum_size = Vector2(0, 74)
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="TimeSlot2" parent="Control/PanelContainer/VBoxContainer" unique_id=1532657435 instance=ExtResource("1_uu6xs")]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="TimeSlot3" parent="Control/PanelContainer/VBoxContainer" unique_id=1504478834 instance=ExtResource("1_uu6xs")]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="TimeSlot4" parent="Control/PanelContainer/VBoxContainer" unique_id=1891572413 instance=ExtResource("1_uu6xs")]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="TimeSlot5" parent="Control/PanelContainer/VBoxContainer" unique_id=464659559 instance=ExtResource("1_uu6xs")]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="TimeSlot6" parent="Control/PanelContainer/VBoxContainer" unique_id=1773919778 instance=ExtResource("1_uu6xs")]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="TimeSlot7" parent="Control/PanelContainer/VBoxContainer" unique_id=1476334804 instance=ExtResource("1_uu6xs")]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
script = ExtResource("2_r0du0")
|
|
||||||
|
|
||||||
[node name="Box" type="StaticBody2D" parent="." unique_id=56956355]
|
[node name="Box" type="StaticBody2D" parent="." unique_id=56956355]
|
||||||
|
|
||||||
|
|||||||
27
Meeting.cs
27
Meeting.cs
@@ -37,12 +37,6 @@ public partial class Meeting : RigidBody2D
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_isDragging && @event is InputEventMouseButton { Pressed: false })
|
|
||||||
{
|
|
||||||
GD.Print("Let me free");
|
|
||||||
StopDragging();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
@@ -65,15 +59,18 @@ public partial class Meeting : RigidBody2D
|
|||||||
|
|
||||||
private void StartDragging()
|
private void StartDragging()
|
||||||
{
|
{
|
||||||
Freeze = true;
|
LinearVelocity = Vector2.Zero;
|
||||||
_isDragging = true;
|
AngularVelocity = 0;
|
||||||
CollisionLayer = 0;
|
RotationDegrees = 0;
|
||||||
}
|
|
||||||
|
|
||||||
private void StopDragging()
|
var meetingControl = Instantiator.Instantiate<MeetingControl>();
|
||||||
{
|
meetingControl.Meeting = this;
|
||||||
Freeze = false;
|
|
||||||
_isDragging = false;
|
GetParent().AddChild(meetingControl);
|
||||||
CollisionLayer = 1;
|
meetingControl.StartDrag();
|
||||||
|
|
||||||
|
meetingControl.Position = new Vector2(-5000, -5000);
|
||||||
|
|
||||||
|
GetParent().RemoveChild(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
28
Meeting.tscn
28
Meeting.tscn
@@ -2,12 +2,13 @@
|
|||||||
|
|
||||||
[ext_resource type="Script" uid="uid://cit20jyhj41rs" path="res://Meeting.cs" id="1_1rolt"]
|
[ext_resource type="Script" uid="uid://cit20jyhj41rs" path="res://Meeting.cs" id="1_1rolt"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dyxftkkuf7h7w" path="res://icon.svg" id="1_2t4nr"]
|
[ext_resource type="Texture2D" uid="uid://dyxftkkuf7h7w" path="res://icon.svg" id="1_2t4nr"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://b2cpk0ef3rw87" path="res://MeetingControlGfx.tscn" id="2_h68fa"]
|
||||||
|
|
||||||
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_glv2v"]
|
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_glv2v"]
|
||||||
bounce = 0.1
|
bounce = 0.1
|
||||||
|
|
||||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_boq60"]
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_boq60"]
|
||||||
size = Vector2(294, 72)
|
size = Vector2(329, 80)
|
||||||
|
|
||||||
[node name="Meeting" type="RigidBody2D" unique_id=796440984]
|
[node name="Meeting" type="RigidBody2D" unique_id=796440984]
|
||||||
input_pickable = true
|
input_pickable = true
|
||||||
@@ -16,9 +17,26 @@ freeze_mode = 1
|
|||||||
continuous_cd = 2
|
continuous_cd = 2
|
||||||
script = ExtResource("1_1rolt")
|
script = ExtResource("1_1rolt")
|
||||||
|
|
||||||
[node name="Icon" type="Sprite2D" parent="." unique_id=1878852055]
|
|
||||||
scale = Vector2(2.3203125, 0.6015625)
|
|
||||||
texture = ExtResource("1_2t4nr")
|
|
||||||
|
|
||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=235269066]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=235269066]
|
||||||
|
position = Vector2(0.5, 0)
|
||||||
shape = SubResource("RectangleShape2D_boq60")
|
shape = SubResource("RectangleShape2D_boq60")
|
||||||
|
|
||||||
|
[node name="MeetingControlGFX" parent="." unique_id=1923695250 instance=ExtResource("2_h68fa")]
|
||||||
|
anchors_preset = 8
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_top = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
anchor_bottom = 0.5
|
||||||
|
offset_left = -164.5
|
||||||
|
offset_top = -40.0
|
||||||
|
offset_right = 164.5
|
||||||
|
offset_bottom = 40.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
mouse_filter = 2
|
||||||
|
|
||||||
|
[node name="Icon" type="Sprite2D" parent="." unique_id=816382870]
|
||||||
|
self_modulate = Color(0.649173, 0, 0.25909996, 1)
|
||||||
|
position = Vector2(153, -29.000004)
|
||||||
|
scale = Vector2(0.1171875, 0.1171875)
|
||||||
|
texture = ExtResource("1_2t4nr")
|
||||||
|
|||||||
@@ -1,15 +1,65 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
public sealed partial class MeetingControlDragData : GodotObject { }
|
public sealed partial class MeetingControlDragData(MeetingControl meetingControl) : GodotObject
|
||||||
|
|
||||||
public partial class MeetingControl : PanelContainer
|
|
||||||
{
|
{
|
||||||
|
public MeetingControl MeetingControl { get; set; } = meetingControl;
|
||||||
|
}
|
||||||
|
|
||||||
|
[SceneTree]
|
||||||
|
public partial class MeetingControl : Control
|
||||||
|
{
|
||||||
|
[Export]
|
||||||
|
public Meeting Meeting;
|
||||||
|
|
||||||
|
public bool InSlot { get; set; }
|
||||||
|
|
||||||
public override Variant _GetDragData(Vector2 atPosition)
|
public override Variant _GetDragData(Vector2 atPosition)
|
||||||
{
|
{
|
||||||
GD.Print("CONTROL DRAG");
|
var preview = CreatePreview();
|
||||||
var copy = Duplicate() as MeetingControl;
|
SetDragPreview(preview);
|
||||||
SetDragPreview(copy);
|
GD.Print("asdasdasdasd as dasd");
|
||||||
|
Visible = false;
|
||||||
|
|
||||||
return Variant.From(new MeetingControlDragData());
|
InSlot = false;
|
||||||
|
|
||||||
|
return Variant.From(new MeetingControlDragData(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StartDrag()
|
||||||
|
{
|
||||||
|
var preview = CreatePreview();
|
||||||
|
var data = Variant.From(new MeetingControlDragData(this));
|
||||||
|
|
||||||
|
ForceDrag(data, preview);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _Notification(int what)
|
||||||
|
{
|
||||||
|
if (what == NotificationDragEnd)
|
||||||
|
{
|
||||||
|
GD.Print("Drag End");
|
||||||
|
|
||||||
|
if (InSlot)
|
||||||
|
{
|
||||||
|
GD.Print("Dropped in Slot");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
GD.Print("Dropped somewhere");
|
||||||
|
|
||||||
|
FindParent("Main").AddChild(Meeting);
|
||||||
|
Meeting.Position = GetGlobalMousePosition();
|
||||||
|
QueueFree();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Control CreatePreview()
|
||||||
|
{
|
||||||
|
var copy = Duplicate() as MeetingControl;
|
||||||
|
var preview = new Control();
|
||||||
|
preview.AddChild(copy);
|
||||||
|
copy.Position = new Vector2(-Size.X / 2, -Size.Y / 2);
|
||||||
|
|
||||||
|
return preview;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
[gd_scene format=3 uid="uid://do8ll0kylvrcn"]
|
[gd_scene format=3 uid="uid://do8ll0kylvrcn"]
|
||||||
|
|
||||||
[ext_resource type="Script" uid="uid://ctl23v8cgy4k3" path="res://MeetingControl.cs" id="1_o5h3n"]
|
[ext_resource type="Script" uid="uid://ctl23v8cgy4k3" path="res://MeetingControl.cs" id="1_o5h3n"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dyxftkkuf7h7w" path="res://icon.svg" id="1_o8u20"]
|
[ext_resource type="PackedScene" uid="uid://b2cpk0ef3rw87" path="res://MeetingControlGfx.tscn" id="1_o8u20"]
|
||||||
|
|
||||||
[node name="MeetingControl" type="PanelContainer" unique_id=508053904]
|
[node name="MeetingControl" type="Control" unique_id=778678487]
|
||||||
custom_minimum_size = Vector2(10.74, 9.49)
|
layout_mode = 3
|
||||||
|
anchors_preset = 0
|
||||||
offset_right = 329.0
|
offset_right = 329.0
|
||||||
offset_bottom = 80.0
|
offset_bottom = 80.0
|
||||||
size_flags_horizontal = 3
|
|
||||||
script = ExtResource("1_o5h3n")
|
script = ExtResource("1_o5h3n")
|
||||||
|
|
||||||
[node name="Icon" type="Sprite2D" parent="." unique_id=1047834216]
|
[node name="MeetingControlGFX" parent="." unique_id=1923695250 instance=ExtResource("1_o8u20")]
|
||||||
position = Vector2(36.999996, 37)
|
layout_mode = 0
|
||||||
scale = Vector2(0.390625, 0.390625)
|
mouse_filter = 2
|
||||||
texture = ExtResource("1_o8u20")
|
|
||||||
|
|||||||
14
MeetingControlGfx.tscn
Normal file
14
MeetingControlGfx.tscn
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
[gd_scene format=3 uid="uid://b2cpk0ef3rw87"]
|
||||||
|
|
||||||
|
[ext_resource type="Texture2D" uid="uid://dyxftkkuf7h7w" path="res://icon.svg" id="1_vkyb6"]
|
||||||
|
|
||||||
|
[node name="MeetingControlGFX" type="PanelContainer" unique_id=1923695250]
|
||||||
|
custom_minimum_size = Vector2(10.74, 9.49)
|
||||||
|
offset_right = 330.0
|
||||||
|
offset_bottom = 80.0
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
|
||||||
|
[node name="Icon" type="Sprite2D" parent="." unique_id=527110079]
|
||||||
|
position = Vector2(36.999996, 37)
|
||||||
|
scale = Vector2(0.390625, 0.390625)
|
||||||
|
texture = ExtResource("1_vkyb6")
|
||||||
22
TimeSlot.cs
22
TimeSlot.cs
@@ -2,6 +2,8 @@ using Godot;
|
|||||||
|
|
||||||
public partial class TimeSlot : PanelContainer
|
public partial class TimeSlot : PanelContainer
|
||||||
{
|
{
|
||||||
|
public MeetingControl MeetingControl { get; set; }
|
||||||
|
|
||||||
public override bool _CanDropData(Vector2 atPosition, Variant data)
|
public override bool _CanDropData(Vector2 atPosition, Variant data)
|
||||||
{
|
{
|
||||||
GD.Print("DRAGGED OVERR!!!");
|
GD.Print("DRAGGED OVERR!!!");
|
||||||
@@ -11,6 +13,24 @@ public partial class TimeSlot : PanelContainer
|
|||||||
|
|
||||||
public override void _DropData(Vector2 atPosition, Variant data)
|
public override void _DropData(Vector2 atPosition, Variant data)
|
||||||
{
|
{
|
||||||
GD.Print("DROP");
|
var meetingData = (MeetingControlDragData)data;
|
||||||
|
|
||||||
|
MeetingControl = meetingData.MeetingControl;
|
||||||
|
meetingData.MeetingControl.InSlot = true;
|
||||||
|
MeetingControl.Reparent(this, false);
|
||||||
|
MeetingControl.Visible = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void _Notification(int what)
|
||||||
|
{
|
||||||
|
if (what == NotificationDragBegin)
|
||||||
|
{
|
||||||
|
MouseFilter = MouseFilterEnum.Pass;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (what == NotificationDragEnd)
|
||||||
|
{
|
||||||
|
MouseFilter = MouseFilterEnum.Ignore;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,4 +4,6 @@
|
|||||||
|
|
||||||
[node name="TimeSlot" type="PanelContainer" unique_id=979842204]
|
[node name="TimeSlot" type="PanelContainer" unique_id=979842204]
|
||||||
custom_minimum_size = Vector2(0, 74)
|
custom_minimum_size = Vector2(0, 74)
|
||||||
|
offset_bottom = 80.0
|
||||||
|
mouse_filter = 2
|
||||||
script = ExtResource("1_50jir")
|
script = ExtResource("1_50jir")
|
||||||
|
|||||||
@@ -5,4 +5,7 @@
|
|||||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||||
<RootNamespace>yourareanaiceo</RootNamespace>
|
<RootNamespace>yourareanaiceo</RootNamespace>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="GodotSharp.SourceGenerators" Version="2.7.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user