Upgrade UI Help

I’m still in godot 4.3, (Upgrading soon I hope lol) and I’m working on an expanding Upgrade system. (Reference Extension/Pit -Indentation Upgrade system help for my full idea) And the idea is that when you place one of the UI Textures on down, It pops up others around it that you can use later. Idk how it would work, I thought an AstarGrid2D might do it, but after looking at the documentation, I didn’t think it’d work. If you could help, I’d be great!

/// Heres the code I have rn.
extends TextureRect

var original_texture : Texture2D = null
signal UpgradeDropConfirmed

func _ready():
	await get_parent() != null
	UpgradeDropConfirmed.connect(get_parent()._on_drag_and_drop_upgrade_drop_confirmed)

func _get_drag_data(at_position: Vector2) -> Variant:
	original_texture = texture
	
	var preview_texture = TextureRect.new()
	preview_texture.texture = texture
	preview_texture.expand_mode = TextureRect.EXPAND_FIT_WIDTH
	preview_texture.size = Vector2(30, 30)

	var preview = Control.new()
	preview.add_child(preview_texture)
	
	set_drag_preview(preview)

	texture = null
	
	return { "texture": preview_texture.texture, "source": self }


func _can_drop_data(at_position: Vector2, data: Variant) -> bool:
	return typeof(data) == TYPE_DICTIONARY and data.has("texture") and data["texture"] is Texture2D and texture == null


func _drop_data(at_position: Vector2, data: Variant) -> void:
	if texture == null:
		texture = data["texture"]
		data["source"]._confirm_drop()


func _confirm_drop():
	original_texture = null
	UpgradeDropConfirmed.emit()


func _notification(what):
	if what == NOTIFICATION_DRAG_END:
		if original_texture != null:
			texture = original_texture
			original_texture = null
1 Like

Can you draw a sketch for it.For better understanding : )

1 Like


I placed these by hand to demonstrate but I’d like to get this done with code


Also the icon dosen’t need to duplicate or anything I did that cuz it was quick to show you. but it should check up down left and right for avaiable positions and then spawn the scenes/texture rects there instead of doing it manually (What I did) also I found a bug with the camera where if the cam is active (And zoomed in to make it easier to see) and you pick one of the textures up to move it it’s WAY displaced.

1 Like

If my big brain get it right then I think its easy you can use area2d for checking that is a DragandDrop is active(what ever you want) or not you can see some docs about
Area2d.you can use 2 area2d for left and right or you can use 1. If the area2d checks that the DragandDrop is unactive then you can active them / transfer textures/ powerups and more
I hope i get it right : D

1 Like

Big brain :OOO :exploding_head:

1 Like

Yeahhhh get it

1 Like

var Frozen_Fried.Smorts : BigBrain = 999

1 Like

Hahahaha btw your DragandDrop should atleast have an another area2d to detect it .

1 Like