2023-04-19 16:53:24 +00:00
|
|
|
@tool
|
|
|
|
|
|
2023-06-28 10:18:00 +00:00
|
|
|
extends Area2D
|
2023-04-19 16:53:24 +00:00
|
|
|
class_name PostIt
|
2023-05-28 13:21:19 +00:00
|
|
|
var sibling
|
2023-06-28 13:27:05 +00:00
|
|
|
var shift_tween
|
|
|
|
|
var modulate_tween
|
2023-04-19 16:53:24 +00:00
|
|
|
|
2023-09-23 14:19:58 +00:00
|
|
|
signal transform_tween_finished
|
|
|
|
|
|
2023-04-19 16:53:24 +00:00
|
|
|
@export var text: String = "" :
|
|
|
|
|
set (value):
|
|
|
|
|
if is_inside_tree() or Engine.is_editor_hint():
|
2023-06-28 13:27:05 +00:00
|
|
|
$Content/Label.text = value
|
|
|
|
|
$Content/BackgroundSprite.frame = text.hash() % $Content/BackgroundSprite.sprite_frames.get_frame_count($Content/BackgroundSprite.animation)
|
2023-04-19 16:53:24 +00:00
|
|
|
text = value
|
2023-06-29 15:34:02 +00:00
|
|
|
|
2023-06-28 13:27:05 +00:00
|
|
|
|
|
|
|
|
@export var shift_by: Vector2 = Vector2(-32, 0)
|
|
|
|
|
@export_color_no_alpha var highlight_color: Color = Color(1.5, 1.5, 1.5)
|
|
|
|
|
@export var highlighted: bool = false:
|
|
|
|
|
set(highlight):
|
|
|
|
|
if highlight != highlighted:
|
|
|
|
|
highlighted = highlight
|
|
|
|
|
|
|
|
|
|
if is_inside_tree() and is_node_ready():
|
|
|
|
|
if modulate_tween: modulate_tween.kill()
|
|
|
|
|
if shift_tween: shift_tween.kill()
|
|
|
|
|
if highlighted:
|
|
|
|
|
modulate_tween = get_tree().create_tween()
|
|
|
|
|
modulate_tween.tween_property(self, "modulate", highlight_color, 0.1)
|
|
|
|
|
shift_tween = get_tree().create_tween()
|
|
|
|
|
shift_tween.tween_property($Content, "position", shift_by, 0.2)
|
|
|
|
|
else:
|
|
|
|
|
modulate_tween = get_tree().create_tween()
|
|
|
|
|
modulate_tween.tween_property(self, "modulate", Color(1, 1, 1), 0.3)
|
|
|
|
|
shift_tween = get_tree().create_tween()
|
|
|
|
|
shift_tween.tween_property($Content, "position", Vector2.ZERO, 0.5)
|
|
|
|
|
else:
|
|
|
|
|
if highlighted:
|
|
|
|
|
modulate = Color(1, 1, 1)
|
|
|
|
|
else:
|
|
|
|
|
modulate = Color(1, 1, 1)
|
|
|
|
|
|
2023-04-19 16:53:24 +00:00
|
|
|
@export var voice_line: AudioStream = null
|
2023-06-29 20:19:58 +00:00
|
|
|
@export var is_dragable: bool = false
|
2023-07-03 18:27:09 +00:00
|
|
|
@onready var base_rotation = rotation
|
|
|
|
|
@onready var base_scale = scale
|
2023-07-14 19:36:20 +00:00
|
|
|
var is_dragged: bool = false:
|
|
|
|
|
set(dragged):
|
|
|
|
|
is_dragged = dragged
|
|
|
|
|
z_index = int(dragged)
|
|
|
|
|
|
|
|
|
|
var mouse_offset: Vector2
|
2023-04-19 16:53:24 +00:00
|
|
|
|
2023-07-18 13:54:34 +00:00
|
|
|
@onready var diameter = $CollisionShape2D.shape.height
|
|
|
|
|
@export_range(1.0, 10.0) var bounce_speed: float = 8
|
2023-09-24 10:23:26 +00:00
|
|
|
var on_board: bool = false
|
|
|
|
|
var attatched_to: Node = null
|
2023-07-18 13:54:34 +00:00
|
|
|
|
2023-04-19 16:53:24 +00:00
|
|
|
func _ready() -> void:
|
2023-07-01 14:03:22 +00:00
|
|
|
|
2023-06-28 13:27:05 +00:00
|
|
|
$Content/Label.text = self.text
|
|
|
|
|
$Content/BackgroundSprite.frame = text.hash() % $Content/BackgroundSprite.sprite_frames.get_frame_count($Content/BackgroundSprite.animation)
|
|
|
|
|
|
2023-04-19 16:53:24 +00:00
|
|
|
|
2023-05-28 13:21:19 +00:00
|
|
|
func replace_with(postit: PostIt):
|
|
|
|
|
self.text = postit.text
|
|
|
|
|
self.voice_line = postit.voice_line
|
|
|
|
|
self.sibling = postit.sibling
|
2023-07-17 22:13:33 +00:00
|
|
|
self.name = postit.name
|
|
|
|
|
for group in self.get_groups():
|
|
|
|
|
self.remove_from_group(group)
|
|
|
|
|
for group in postit.get_groups():
|
|
|
|
|
self.add_to_group(group)
|
2023-05-28 13:21:19 +00:00
|
|
|
|
2023-07-18 13:54:34 +00:00
|
|
|
func _process(delta: float) -> void:
|
|
|
|
|
if get_overlapping_areas().size() > 0 and is_dragable and on_board:
|
|
|
|
|
for area in get_overlapping_areas():
|
|
|
|
|
if area is Card or area is CardCollider:
|
|
|
|
|
if area is CardCollider:
|
|
|
|
|
position += area.direction * delta
|
|
|
|
|
elif not area.highlighted or self.highlighted:
|
|
|
|
|
var diff:Vector2 = position - area.position
|
|
|
|
|
position -= diff.normalized() * ((diff.length()-diameter)/diameter) * bounce_speed * (delta/(1.0/60))
|
|
|
|
|
|
2023-07-14 17:15:15 +00:00
|
|
|
_move_post_it()
|
|
|
|
|
|
2023-04-19 16:53:24 +00:00
|
|
|
|
|
|
|
|
func _on_focus_entered():
|
|
|
|
|
print(self, "is focused")
|
|
|
|
|
|
|
|
|
|
func _on_focus_exited():
|
|
|
|
|
print(self, "is not focused")
|
2023-06-29 20:19:58 +00:00
|
|
|
|
|
|
|
|
func _on_mouse_entered():
|
2023-07-14 17:15:15 +00:00
|
|
|
if not Input.is_action_pressed("mouse_left"):
|
2023-06-29 22:53:16 +00:00
|
|
|
highlighted = true
|
|
|
|
|
if "handle_hover" in owner:
|
|
|
|
|
owner.handle_hover(self)
|
2023-06-29 20:19:58 +00:00
|
|
|
|
|
|
|
|
func _on_mouse_exited():
|
|
|
|
|
highlighted = false
|
2023-07-14 20:03:09 +00:00
|
|
|
if is_postit_attached() and "check_hover" in get_parent():
|
|
|
|
|
get_parent().check_hover()
|
2023-06-29 20:19:58 +00:00
|
|
|
|
|
|
|
|
func _on_input_event(viewport, event, shape_idx):
|
2023-07-14 17:15:15 +00:00
|
|
|
if event is InputEventMouseMotion:
|
|
|
|
|
_move_post_it()
|
|
|
|
|
|
|
|
|
|
if event is InputEventMouseButton:
|
2023-08-12 11:02:00 +00:00
|
|
|
if event.button_index == MOUSE_BUTTON_LEFT or event.button_index == MOUSE_BUTTON_RIGHT:
|
2023-07-18 12:58:06 +00:00
|
|
|
if "handle_mouse_button" in owner:
|
2023-07-14 19:36:20 +00:00
|
|
|
mouse_offset = (get_viewport().get_mouse_position() - global_position)
|
2023-07-14 17:15:15 +00:00
|
|
|
owner.handle_mouse_button(self, event)
|
2023-07-01 11:43:27 +00:00
|
|
|
|
2023-07-02 08:42:58 +00:00
|
|
|
func _move_post_it():
|
|
|
|
|
if is_dragged:
|
2023-07-14 19:36:20 +00:00
|
|
|
position += (get_viewport().get_mouse_position() - position) - mouse_offset
|
2023-07-02 08:42:58 +00:00
|
|
|
|
2023-07-02 13:10:33 +00:00
|
|
|
func is_postit_attached() -> bool:
|
2023-08-12 10:20:05 +00:00
|
|
|
# there is probably a nicer way to do this
|
|
|
|
|
return self.get_parent().get_parent() is Card
|
2023-07-02 13:10:33 +00:00
|
|
|
|
2023-07-15 13:59:22 +00:00
|
|
|
func tween_transform_to(target: Vector2):
|
2023-09-23 14:19:58 +00:00
|
|
|
var transform_tween: Tween = create_tween()
|
2023-07-15 13:59:22 +00:00
|
|
|
transform_tween.tween_property(self, "position", target, 0.25)
|
2023-09-23 14:19:58 +00:00
|
|
|
await transform_tween.finished
|
|
|
|
|
emit_signal("transform_tween_finished")
|