add: Selectable Tile Map Layer/Mouse Controlled Camera

This commit is contained in:
h z
2025-02-26 20:17:37 +00:00
parent 92770d3425
commit 8df4ebb6d5
6 changed files with 145 additions and 8 deletions

View File

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