add: Selectable Tile Map Layer/Mouse Controlled Camera
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
|
||||
using Godot;
|
||||
using Polonium.Attributes;
|
||||
|
||||
// ReSharper disable once CheckNamespace
|
||||
namespace GlobalClasses;
|
||||
[ProxyNode]
|
||||
[GlobalClass]
|
||||
[Tool]
|
||||
public partial class MouseControlledCamera : Camera2D
|
||||
{
|
||||
private Vector2 DragStartPosition { get; set; }
|
||||
private bool IsDragging { get; set; }
|
||||
[Signal]
|
||||
public delegate void ZoomInEventHandler();
|
||||
[Signal]
|
||||
public delegate void ZoomOutEventHandler();
|
||||
|
||||
[Export]
|
||||
public MouseButton DragButton { get; set; } = MouseButton.Middle;
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
if (@event is InputEventMouseButton mouseButtonEvent)
|
||||
{
|
||||
if(mouseButtonEvent.ButtonIndex == MouseButton.WheelUp)
|
||||
EmitSignalZoomIn();
|
||||
else if(mouseButtonEvent.ButtonIndex == MouseButton.WheelDown)
|
||||
EmitSignalZoomOut();
|
||||
else if (mouseButtonEvent.ButtonIndex == DragButton)
|
||||
{
|
||||
IsDragging = mouseButtonEvent.Pressed;
|
||||
if(IsDragging)
|
||||
DragStartPosition = GetGlobalMousePosition();
|
||||
}
|
||||
}
|
||||
else if (@event is InputEventMouseMotion mouseMotionEvent && IsDragging)
|
||||
{
|
||||
Vector2 mousePos = GetGlobalMousePosition();
|
||||
Vector2 offset = DragStartPosition - mousePos;
|
||||
Position += offset;
|
||||
DragStartPosition = mousePos;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user