Skip to content

Commit

Permalink
When dragging an instance over UI, reset its position
Browse files Browse the repository at this point in the history
  • Loading branch information
rainlizard committed Apr 19, 2024
1 parent 654d6e1 commit cdbcc9b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Scenes/Selector.gd
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ func _process(delta):
mouse_button_anywhere()
if oUi.mouseOnUi == false:
mouse_button_on_field()
else:
# Dragging an instance over UI, so reset its drag positon to original.
if draggingInstance == true and is_instance_valid(holdClickOnInstance) and Input.is_action_just_released("mouse_left"):
holdClickOnInstance.global_position = subtile2world(Vector2(holdClickOnInstance.locationX, holdClickOnInstance.locationY))
holdClickOnInstance = null
draggingInstance = false

func mouse_button_anywhere():
if Input.is_action_pressed("mouse_left") == false:
Expand Down Expand Up @@ -172,7 +178,6 @@ func mouse_button_on_field():
draggingInstance = false
var snapToPos = world2subtile(get_global_mouse_position())
var originalPosition = Vector2(holdClickOnInstance.locationX, holdClickOnInstance.locationY)

holdClickOnInstance.locationX = snapToPos.x + 0.5
holdClickOnInstance.locationY = snapToPos.y + 0.5

Expand Down Expand Up @@ -335,6 +340,9 @@ func world2tile(pos):
func world2subtile(pos):
return Vector2(floor(pos.x/SUBTILE_SIZE),floor(pos.y/SUBTILE_SIZE))

func subtile2world(subtilePos):
return Vector2(subtilePos.x * SUBTILE_SIZE,subtilePos.y * SUBTILE_SIZE)

func instance_position(checkPos, checkGroup):
var space = get_world_2d().direct_space_state
for i in space.intersect_point(oInstances.global_transform.translated(checkPos).get_origin(), 32, [], 0x7FFFFFFF, true, true):
Expand Down

0 comments on commit cdbcc9b

Please sign in to comment.