diary/user_interface/chat_panel/message_group_container.gd

58 lines
1.5 KiB
GDScript3
Raw Normal View History

extends HBoxContainer
class_name MessageGroupContainer
onready var profile_image_rect = get_node("ProfileImageRect")
onready var header = get_node("VBoxContainer/Header")
onready var username = get_node("VBoxContainer/Header/Username")
onready var date = get_node("VBoxContainer/Header/Date")
onready var message_container = get_node("VBoxContainer/MessageContainer")
var associated_message_group
func _ready():
# warning-ignore:return_value_discarded
Users.connect("switched", self, "_on_user_switched")
_setup()
func get_user() -> User:
return associated_message_group.associated_user
func add(message):
message_container.add_child(message)
func _on_user_switched():
_adjust_layout_to_user()
func _setup():
profile_image_rect.texture = get_user().profile_image
username.text = get_user().username
# Define date.
var time_stamp = associated_message_group.time_stamp
var storaged_date = OS.get_datetime_from_unix_time(time_stamp)
var os_time = OS.get_datetime()
if storaged_date.day == os_time.day:
date.text = "today, at " + str(os_time.hour) + ":" + "%02d" % os_time.minute
elif storaged_date.day == os_time.day + 1:
date.text = "yesterday"
_adjust_layout_to_user()
func _adjust_layout_to_user():
if get_user().is_current():
move_child(profile_image_rect, 1)
header.alignment = BoxContainer.ALIGN_END
size_flags_horizontal = SIZE_SHRINK_END
else:
move_child(profile_image_rect, 0)
header.alignment = BoxContainer.ALIGN_BEGIN
size_flags_horizontal = 0