frame-of-mind/src/logic-scenes/board/empty_sticky_note_panel.gd

55 lines
2.0 KiB
GDScript3
Raw Normal View History

2023-09-23 14:19:58 +00:00
class_name PostItPanel
extends Panel
@export var minimum_size:Vector2 = Vector2(400, 100)
2023-11-01 22:19:47 +00:00
var attached_sticky_note: StickyNote
2023-10-12 16:25:21 +00:00
@onready var ancor = $"sticky-note_anchor"
2023-09-23 14:19:58 +00:00
func _ready():
ancor.position = Vector2(ancor.position.x, 0)
custom_minimum_size = Vector2(custom_minimum_size.x, 0)
2023-10-12 16:25:21 +00:00
func attatch_sticky_note(attatchment: StickyNote, tween:bool = true):
2023-09-23 14:19:58 +00:00
attatchment.on_board = false
if tween:
var height_tween: Tween = create_tween()
height_tween.tween_property(self, "custom_minimum_size", minimum_size, 0.3)
height_tween.tween_property(ancor, "position", Vector2(ancor.position.x, minimum_size.y/2), 0.3)
2023-09-23 14:19:58 +00:00
attatchment.tween_transform_to(ancor.global_position)
await attatchment.transform_tween_finished
2023-10-12 16:25:21 +00:00
else:
custom_minimum_size = minimum_size
ancor.position = Vector2(ancor.position.x, minimum_size.y/2)
2023-09-23 14:19:58 +00:00
attatchment.reparent(self)
2023-11-01 22:19:47 +00:00
attached_sticky_note = attatchment
2023-09-23 14:19:58 +00:00
attatchment.owner = self.owner
2023-11-01 22:19:47 +00:00
attatchment.attached_to = self
2023-10-12 16:25:21 +00:00
attatchment.transform = ancor.transform
2023-09-23 14:19:58 +00:00
2023-10-12 16:25:21 +00:00
func reclaim_sticky_note():
print("meep")
var is_emoty = is_empty()
print("meep")
2023-11-01 22:19:47 +00:00
if is_empty() and attached_sticky_note.on_board == true:
attached_sticky_note.on_board = false
attached_sticky_note.tween_transform_to(ancor.global_transform)
await attached_sticky_note.transform_tween_finished
attached_sticky_note.reparent(self)
attached_sticky_note.owner = self.owner
2023-10-12 16:25:21 +00:00
func clear_if_empty():
if !is_empty(): return
2023-11-01 22:19:47 +00:00
if attached_sticky_note.attached_to == self: attached_sticky_note.attached_to = null
2023-09-23 14:19:58 +00:00
var height_tween: Tween = create_tween()
height_tween.tween_property(self, "custom_minimum_size", Vector2.ZERO, 0.3)
await height_tween.finished
2023-11-01 22:19:47 +00:00
owner.on_sticky_panel_cleared()
2023-09-23 14:19:58 +00:00
self.free()
2023-10-12 16:25:21 +00:00
func replace_sticky_note_with(new_sticky_note: StickyNote):
if is_empty():
2023-11-01 22:19:47 +00:00
attached_sticky_note = new_sticky_note
2023-10-12 16:25:21 +00:00
func is_empty() -> bool:
2023-11-01 22:19:47 +00:00
return get_child_count() == 1