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