small racing game im working on
Diffstat (limited to 'ui/editor/brush.gd')
-rw-r--r--ui/editor/brush.gd39
1 files changed, 39 insertions, 0 deletions
diff --git a/ui/editor/brush.gd b/ui/editor/brush.gd
new file mode 100644
index 0000000..0270b38
--- /dev/null
+++ b/ui/editor/brush.gd
@@ -0,0 +1,39 @@
+extends MultiButton
+class_name Brush
+
+@onready var brush: TextureRect = $brush
+@onready var outline: TextureRect = $outline
+@export var cursor: Texture
+
+func set_c(c: Color) -> void:
+ if disabled:
+ brush.modulate = c
+ if not button_pressed:
+ secondary.modulate = c
+ outline.visible = button_pressed
+
+var mat: int = 0
+
+func _can_drop_data(_at_position: Vector2, data: Variant) -> bool:
+ return data is WeakLink and data.type == WeakLink.Type.Material
+
+func _drop_data(_at_position: Vector2, data: Variant) -> void:
+ mat = data.material
+ brush.modulate = data.material_color
+ disabled = false
+
+func _gui_input(event: InputEvent) -> void:
+ if event is InputEventMouseButton and event.is_pressed() and event.button_index == MOUSE_BUTTON_RIGHT:
+ mat = 0
+ reset()
+
+func reset() -> void:
+ button_pressed = false
+ disabled = true
+
+func _toggled(on: bool) -> void:
+ Input.set_custom_mouse_cursor(cursor if on else null, Input.CURSOR_ARROW)
+
+func _on_mousecast_hit(colls: Array) -> void:
+ if colls.is_empty():
+ button_pressed = false