#Unable to Click the little hammer Button on Selected Tile

1 messages · Page 1 of 1 (latest)

modern cedar
#

extends Node2D

@onready var highlight_TileMap: TileMapLayer = $"../Highlight"
@onready var build_button: TextureButton = $"../Control/CanvasLayer/MarginContainer/BuildButton"
@onready var build_ui: Panel = $"../BuildAnything"

var source_highlight_id = 0

Color Atlas

var White_Highlight : Vector2i = Vector2i(0,0)

var isBtnEnabled : bool
var CurrentSelectedTile : Vector2i

func _ready() -> void:
isBtnEnabled = false
build_ui.visible = false

func _process(delta: float) -> void:
pass

func get_target_tile_pos() -> Vector2i:
var mousePos = get_global_mouse_position()
return highlight_TileMap.local_to_map(mousePos)

func get_tile_world_Position(tile_pos : Vector2i) -> Vector2:
return highlight_TileMap.map_to_local(tile_pos)

func _input(event):
if event.is_action_pressed("click") and isBtnEnabled:

    var target_tile = get_target_tile_pos()
    
    # Remove Previous Tile Highlight
    highlight_TileMap.set_cell(CurrentSelectedTile,-1)
    
    CurrentSelectedTile = target_tile
    highlight_TileMap.set_cell(CurrentSelectedTile,source_highlight_id,White_Highlight)
    
    # Show the UI Panel
    var world_Position = get_tile_world_Position(CurrentSelectedTile)
    build_ui.global_position = world_Position + Vector2(-8, -32)
    build_ui.visible = true

func _on_build_button_toggled(toggled_on: bool) -> void:
isBtnEnabled = toggled_on
if not toggled_on:
build_ui.visible = false
highlight_TileMap.set_cell(CurrentSelectedTile,-1)

func _on_build_pressed() -> void:
print("hi")

I am unable to Print hi

#

This is the Structure

mental grove
#

You need to disable the code that spawns the hammer button while one is already present.
Or use _unhandled_input() as to allow the button to block inputs.