diff --git a/units/base_unit.gd b/units/base_unit.gd index e8fc9ff..8d80523 100644 --- a/units/base_unit.gd +++ b/units/base_unit.gd @@ -12,13 +12,13 @@ export var base_hull_points = 0 setget set_base_hull_points export var base_shield_points = 0 setget set_base_shield_points export var base_damage_points = 0 setget set_base_damage_points -var dragged = false -var base_position var selected_anchor +var dragged func _ready(): + $move_hint.visible = false + set_sprite(sprite) - base_position = rect_position set_base_damage_points(base_damage_points) set_base_move_points(base_move_points) @@ -66,8 +66,8 @@ func can_be_used_on_anchor(anchor): return anchor is Anchor and anchor.is_connected_to(get_parent()) and (anchor.is_empty() or can_target(anchor.get_content())) func update_anchors(): - var position = rect_global_position + rect_size / 2 if dragged else null - selected_anchor = BattleHelper.update_anchors(get_tree(), position, funcref(self, "can_be_used_on_anchor")) + var cursor = rect_global_position + dragged if dragged else null + selected_anchor = BattleHelper.update_anchors(get_tree(), cursor, funcref(self, "can_be_used_on_anchor")) func play(anchor): if anchor.is_empty(): @@ -85,7 +85,6 @@ func play(anchor): func move_to(anchor): anchor.set_content(self) - rect_position = base_position func get_points() -> UnitPoints: if $points is UnitPoints: @@ -121,23 +120,27 @@ func attack(other) -> bool: return selfpoints.hull > 0 && otherpoints.hull == 0 func return_to_base(): - AnimHelper.linear_goto(self, base_position, 0.3) + dragged = null + $move_hint.visible = false + $move_hint.set_point_position(1, Vector2(0, 0)) func _gui_input(event): if event is InputEventMouseButton and event.button_index == 1: if event.pressed: - dragged = true - modulate = Color(1, 1, 1, 0.5) + dragged = event.position + $move_hint.visible = true elif dragged: - dragged = false - modulate = Color(1, 1, 1, 1) + dragged = null + $move_hint.visible = false if selected_anchor: play(selected_anchor) else: return_to_base() - if event is InputEventMouseMotion: - if event.button_mask == BUTTON_LEFT: - set_position(rect_position + event.relative) + if event is InputEventMouseMotion and event.button_mask == BUTTON_LEFT: + dragged = event.position update_anchors() + + if dragged: + $move_hint.set_point_position(1, selected_anchor.global_position - rect_global_position if selected_anchor else dragged) diff --git a/units/base_unit.tscn b/units/base_unit.tscn index fef12f3..a2a9fa4 100644 --- a/units/base_unit.tscn +++ b/units/base_unit.tscn @@ -29,3 +29,7 @@ anchor_right = 0.5 anchor_bottom = 0.5 margin_top = 70.0 margin_bottom = 115.0 + +[node name="move_hint" type="Line2D" parent="."] +points = PoolVector2Array( 50, 50, 0, 0 ) +antialiased = true