extends TextureButton
@onready var label = $"label"

var level_name


var bound_object = null
var bound_method = null

var focus_object = null
var focus_method = null


func _ready():
	var _error = self.connect("pressed", Callable(self, "_on_button_pressed"))
	self.label.set_message_translation(false)
	self.label.notification(NOTIFICATION_TRANSLATION_CHANGED)


func fill_data(fill_name):
	self.level_name = fill_name

	self.refresh_label()


func refresh_label():
	var new_text = self.level_name

	self.label.set_text(new_text)
	


func bind_method(new_object, new_method):
	self.bound_object = new_object
	self.bound_method = new_method


func bind_focus(new_object, new_method):
	self.focus_object = new_object
	self.focus_method = new_method


func _get_level_id():
	return self.level_name


func _on_button_pressed():
	if self.bound_object != null:
		self.bound_object.call_deferred(self.bound_method, self._get_level_id())


func _on_focus_entered():
	if self.focus_object != null:
		self.focus_object.call_deferred(self.focus_method, self._get_level_id())

func _on_mouse_entered():
	self._on_focus_entered()
