33 lines
670 B
GDScript3
33 lines
670 B
GDScript3
|
@tool
|
||
|
extends Composer
|
||
|
class_name Command
|
||
|
|
||
|
signal clicked
|
||
|
|
||
|
@export var icon: Texture2D:
|
||
|
set(val):
|
||
|
if val is Texture2D:
|
||
|
icon = val
|
||
|
else:
|
||
|
icon = PlaceholderTexture2D.new()
|
||
|
_check_compose()
|
||
|
|
||
|
@export var code: String
|
||
|
|
||
|
func _compose():
|
||
|
$badge/icon.texture = icon
|
||
|
super._compose()
|
||
|
|
||
|
func _on_click_input_event(viewport, event, shape_idx):
|
||
|
if event is InputEventMouseButton:
|
||
|
if event.button_index == MOUSE_BUTTON_LEFT:
|
||
|
get_viewport().set_input_as_handled()
|
||
|
clicked.emit()
|
||
|
|
||
|
func apply(container: Node2D, pos: Vector2):
|
||
|
if get_parent() != container:
|
||
|
if get_parent():
|
||
|
get_parent().remove_child(self)
|
||
|
container.add_child(self)
|
||
|
position = pos
|