umstyling + meetingresource
This commit is contained in:
84
MeetingPhysicsBox.cs
Normal file
84
MeetingPhysicsBox.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using Godot;
|
||||
using yourareanaiceo;
|
||||
|
||||
[SceneTree]
|
||||
public partial class MeetingPhysicsBox : RigidBody2D
|
||||
{
|
||||
[Export]
|
||||
public MeetingResource MeetingResource { get; set; } = new DummyMeetingResource();
|
||||
|
||||
private bool _mouseInside;
|
||||
private bool _isDragging;
|
||||
private Vector2 _dragTarget;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
FreezeMode = FreezeModeEnum.Kinematic;
|
||||
Modulate = MeetingResource.Color;
|
||||
|
||||
MeetingControlGfx.MeetingTitle.Text = MeetingResource.Title;
|
||||
|
||||
MouseEntered += () =>
|
||||
{
|
||||
_mouseInside = true;
|
||||
CanSleep = false;
|
||||
};
|
||||
MouseExited += () =>
|
||||
{
|
||||
_mouseInside = false;
|
||||
CanSleep = true;
|
||||
};
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
// TODO: probably memory problem
|
||||
if (@event is InputEventMouse mouseEvent)
|
||||
{
|
||||
if (_mouseInside)
|
||||
{
|
||||
if (mouseEvent.IsPressed() && mouseEvent.ButtonMask == MouseButtonMask.Left)
|
||||
{
|
||||
GD.Print("Start Dragging");
|
||||
StartDragging();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
_dragTarget = GetGlobalMousePosition();
|
||||
}
|
||||
|
||||
public override void _IntegrateForces(PhysicsDirectBodyState2D state)
|
||||
{
|
||||
if (!_isDragging)
|
||||
return;
|
||||
|
||||
var t = state.Transform;
|
||||
t.Origin = _dragTarget;
|
||||
|
||||
state.Transform = t;
|
||||
state.LinearVelocity = Vector2.Zero;
|
||||
state.AngularVelocity = 0;
|
||||
}
|
||||
|
||||
private void StartDragging()
|
||||
{
|
||||
LinearVelocity = Vector2.Zero;
|
||||
AngularVelocity = 0;
|
||||
RotationDegrees = 0;
|
||||
|
||||
var meetingControl = Instantiator.Instantiate<MeetingControl>();
|
||||
meetingControl.MeetingPhysicsBox = this;
|
||||
|
||||
GetParent().AddChild(meetingControl);
|
||||
meetingControl.StartDrag();
|
||||
|
||||
meetingControl.Position = new Vector2(-5000, -5000);
|
||||
|
||||
GetParent().RemoveChild(this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user