1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 15:39:49 +00:00
Pixelorama/src/UI/PatternsPopup.gd
Manolis Papadeas c6b9a1fb82
Format code and add static checks (#599)
* gdformat .

* Lint code - Part 1

* Format code - Part 2

* Lint code - Part 2

Trying to fix the max allowed line length errors

* Add normal_map_invert_y to the image .import files

Because of Godot 3.4

* Do not call private methods outside of the script's scope

Lint code - Part 3

* Format code - Part 3

* Fixed more line length exceeded errors - Lint code Part 3

* Export array of licenses - Lint code part 4

* Clean hint_tooltip code from Global

Removes a lot of lines of code

* Create static-checks.yml

* Fix FreeType's license
2021-11-25 14:48:30 +02:00

46 lines
1.2 KiB
GDScript

class_name Patterns
extends PopupPanel
signal pattern_selected(pattern)
var default_pattern: Pattern = null
class Pattern:
var image: Image
var index: int
func select_pattern(pattern: Pattern) -> void:
emit_signal("pattern_selected", pattern)
hide()
static func create_button(image: Image) -> Node:
var button: BaseButton = preload("res://src/UI/PatternButton.tscn").instance()
var tex := ImageTexture.new()
tex.create_from_image(image, 0)
button.get_child(0).texture = tex
button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
return button
static func add(image: Image, hint := "") -> void:
var button = create_button(image)
button.pattern.image = image
button.hint_tooltip = hint
var container = Global.patterns_popup.get_node("ScrollContainer/PatternContainer")
container.add_child(button)
button.pattern.index = button.get_index()
if Global.patterns_popup.default_pattern == null:
Global.patterns_popup.default_pattern = button.pattern
func get_pattern(index: int) -> Pattern:
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