changes
This commit is contained in:
66
label.gd
66
label.gd
@@ -1,22 +1,12 @@
|
||||
extends Node2D
|
||||
|
||||
|
||||
var hovered_setpieces: Array[Dictionary] = []
|
||||
|
||||
@onready var label : Label = $"label"
|
||||
|
||||
func _ready():
|
||||
_connect_setpieces(get_parent())
|
||||
ActionState.hover_changed.connect(_on_hover_changed)
|
||||
|
||||
func _on_transitioned(s):
|
||||
hovered_setpieces.clear()
|
||||
func _on_transitioned(_s):
|
||||
$label.hide()
|
||||
_connect_setpieces(get_parent())
|
||||
|
||||
func _connect_setpieces(scene: Node) -> void:
|
||||
for n in scene.find_children("*", "SetPiece", true, false):
|
||||
print("LOOKING AT", n)
|
||||
n.connect("entered", Callable(self, "_on_setpiece_entered"))
|
||||
n.connect("exited", Callable(self, "_on_setpiece_exited"))
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
@@ -70,47 +60,11 @@ func _process(delta):
|
||||
global_position = mouse_pos
|
||||
|
||||
|
||||
func _on_setpiece_entered(lab: String) -> void:
|
||||
var piece = get_setpiece_by_label(lab)
|
||||
if piece:
|
||||
var entry = {"label": lab, "priority": piece.priority}
|
||||
if not _has_entry_with_label(lab):
|
||||
hovered_setpieces.append(entry)
|
||||
_update_label()
|
||||
|
||||
|
||||
func _on_setpiece_exited(lab: String) -> void:
|
||||
for i in range(hovered_setpieces.size()):
|
||||
if hovered_setpieces[i].label == lab:
|
||||
hovered_setpieces.remove_at(i)
|
||||
break
|
||||
_update_label()
|
||||
|
||||
|
||||
func _has_entry_with_label(lab: String) -> bool:
|
||||
for entry in hovered_setpieces:
|
||||
if entry.label == lab:
|
||||
return true
|
||||
return false
|
||||
|
||||
func get_setpiece_by_label(lab: String) -> SetPiece:
|
||||
var scene = get_parent()
|
||||
for child in scene.find_children("*", "SetPiece", true, false):
|
||||
if child is SetPiece and child.label == lab:
|
||||
return child
|
||||
return null
|
||||
|
||||
func _update_label() -> void:
|
||||
|
||||
if hovered_setpieces.is_empty():
|
||||
func _on_hover_changed(piece: SetPiece) -> void:
|
||||
if piece == null:
|
||||
$label.hide()
|
||||
return
|
||||
|
||||
hovered_setpieces.sort_custom(func(a, b): return b.priority < a.priority)
|
||||
var top_entry = hovered_setpieces[0]
|
||||
print(hovered_setpieces, top_entry, top_entry.label)
|
||||
$label.show()
|
||||
$label.text = top_entry.label
|
||||
|
||||
var size = label.label_settings.font.get_string_size(top_entry.label, HORIZONTAL_ALIGNMENT_LEFT, 200, 32)
|
||||
label.size = size
|
||||
else:
|
||||
$label.show()
|
||||
$label.text = piece.label
|
||||
var size = label.label_settings.font.get_string_size(piece.label, HORIZONTAL_ALIGNMENT_LEFT, 200, 32)
|
||||
label.size = size
|
||||
|
||||
Reference in New Issue
Block a user