2020-07-09 12:22:17 +00:00
|
|
|
class_name Patterns
|
2021-11-25 12:48:30 +00:00
|
|
|
extends PopupPanel
|
2020-07-09 12:22:17 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
signal pattern_selected(pattern)
|
2020-07-09 12:22:17 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
var default_pattern: Pattern = null
|
2020-07-09 12:22:17 +00:00
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
class Pattern:
|
|
|
|
var image: Image
|
|
|
|
var index: int
|
2020-07-09 12:22:17 +00:00
|
|
|
|
|
|
|
|
2021-12-05 16:37:15 +00:00
|
|
|
func _ready() -> void:
|
|
|
|
add(Image.new(), "Clipboard")
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func select_pattern(pattern: Pattern) -> void:
|
2020-07-09 12:22:17 +00:00
|
|
|
emit_signal("pattern_selected", pattern)
|
|
|
|
hide()
|
|
|
|
|
|
|
|
|
2021-12-05 16:37:15 +00:00
|
|
|
func create_button(image: Image) -> Node:
|
2023-01-05 15:54:22 +00:00
|
|
|
var button: BaseButton = preload("res://src/UI/Buttons/PatternButton.tscn").instance()
|
2020-07-09 12:22:17 +00:00
|
|
|
var tex := ImageTexture.new()
|
2021-12-05 16:37:15 +00:00
|
|
|
if !image.is_empty():
|
|
|
|
tex.create_from_image(image, 0)
|
2020-07-09 12:22:17 +00:00
|
|
|
button.get_child(0).texture = tex
|
|
|
|
button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
|
|
|
return button
|
|
|
|
|
|
|
|
|
2021-12-05 16:37:15 +00:00
|
|
|
func add(image: Image, hint := "") -> void:
|
2020-07-09 12:22:17 +00:00
|
|
|
var button = create_button(image)
|
|
|
|
button.pattern.image = image
|
|
|
|
button.hint_tooltip = hint
|
2021-12-05 16:37:15 +00:00
|
|
|
var container = get_node("ScrollContainer/PatternContainer")
|
2020-07-09 12:22:17 +00:00
|
|
|
container.add_child(button)
|
|
|
|
button.pattern.index = button.get_index()
|
|
|
|
|
|
|
|
if Global.patterns_popup.default_pattern == null:
|
|
|
|
Global.patterns_popup.default_pattern = button.pattern
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func get_pattern(index: int) -> Pattern:
|
2020-07-09 12:22:17 +00:00
|
|
|
var container = Global.patterns_popup.get_node("ScrollContainer/PatternContainer")
|
|
|
|
var pattern = default_pattern
|
|
|
|
if index < container.get_child_count():
|
|
|
|
pattern = container.get_child(index).pattern
|
|
|
|
return pattern
|