diff --git a/half-earth/nodes/grid_cursor.tscn b/half-earth/nodes/grid_cursor.tscn new file mode 100644 index 0000000..fd9f0f9 --- /dev/null +++ b/half-earth/nodes/grid_cursor.tscn @@ -0,0 +1,9 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://textures/icon.png" type="Texture" id=1] +[ext_resource path="res://scripts/GridCursor.cs" type="Script" id=2] + +[node name="Grid Cursor" type="Sprite"] +modulate = Color( 0, 1, 1, 0.533333 ) +texture = ExtResource( 1 ) +script = ExtResource( 2 ) diff --git a/half-earth/scripts/GridCursor.cs b/half-earth/scripts/GridCursor.cs new file mode 100644 index 0000000..9037ee6 --- /dev/null +++ b/half-earth/scripts/GridCursor.cs @@ -0,0 +1,33 @@ +using Godot; +using System; + +public class GridCursor : Sprite +{ + [Export] + public NodePath Grid { get; set; } + private WorldGrid _grid; + + public override void _Ready() + { + _grid = GetNode(Grid); + } + + public override void _Input(InputEvent @event) + { + base._Input(@event); + + if (@event is InputEventMouseMotion mouseMoveEvent) + { + var pos = mouseMoveEvent.Position; + _grid.GetGridPos(pos, out var x, out var y); + var position = new Vector2(x + .5f, y + .5f) * _grid.CellSize; + this.Position = position; + } + else if (@event is InputEventMouseButton mouseButtonEvent) + { + var pos = mouseButtonEvent.Position; + _grid.GetGridPos(pos, out var x, out var y); + GD.Print($"({x}, {y})"); + } + } +}