diary/system/ping/ping.gd
2022-04-19 08:24:57 -04:00

196 lines
6.7 KiB
GDScript

extends Node
onready var main_input = get_node("../core/Panel/Margin/Structure/Body/ChatPanel/VBoxContainer/PanelContainer/HBoxContainer/InputContainer/MarginContainer/VBoxContainer/HBoxContainer/MarginContainer/TextEdit")
onready var msg_scroll = get_node("../core/Panel/Margin/Structure/Body/ChatPanel/VBoxContainer/MarginContainer/ScrollContainer")
onready var msg_cont = get_node("../core/Panel/Margin/Structure/Body/ChatPanel/VBoxContainer/MarginContainer/ScrollContainer/messageContainer")
onready var username_label = get_node("../core/Panel/Margin/Structure/Body/SidePanel/VBoxContainer/UserToolbox/Margin/Structure/Profile/UserTexts/Label")
onready var bg_texture1 = preload("res://assets/textures/bg1.png")
onready var bg_texture2 = preload("res://assets/textures/bg2.png")
onready var round_shader = preload("res://assets/textures/profilepicture/shape.shader")
onready var round_shape = preload("res://assets/textures/profilepicture/shape.png")
onready var username_font = preload("res://assets/fonts/username_label.tres")
onready var date_font = preload("res://assets/fonts/date_label.tres")
onready var first_user_data = preload("res://system/users/first_user.tres")
onready var second_user_data = preload("res://system/users/second_user.tres")
func _input(event):
if event is InputEventKey:
if Input.is_action_just_pressed("ui_accept"):
create_message()
elif Input.is_action_just_released("ui_accept"):
var test = msg_cont.get_size().y
var scroller = msg_scroll.get_child(2)
scroller.set("value", test)
main_input.set_text("")
func create_message():
var text_content = main_input.get_text()
var username = username_label.get_text()
var resource = Message.new()
resource.user = username
# Define date
var os_time = OS.get_datetime()
var storaged_today = OS.get_datetime().day
if storaged_today == os_time.day:
resource.date = "Today, at " + str(OS.get_datetime().hour) + ":" + str(OS.get_datetime().minute)
elif storaged_today == os_time.day +1:
resource.date = "yesterday"
resource.content = text_content
if username_label.get_text() == first_user_data.username:
resource.profile_picture = first_user_data.picture
elif username_label.get_text() == second_user_data.username:
resource.profile_picture = second_user_data.picture
var msg_min_h_size = 0
var msg_header_h_size = 0
if text_content.length() < 25:
msg_min_h_size = 50
msg_header_h_size = 25
else:
msg_min_h_size = 350
msg_header_h_size = 300
var datetime = OS.get_datetime()
var user = resource.user
var date = resource.date
var content = resource.content
var pfp = resource.profile_picture
# root is a HBoxContainer.
var root = HBoxContainer.new()
root.set_name("message0")
msg_cont.add_child(root)
# Icon is a texture_rect connected to the root.
# HBoxContainer/TextureRect
# Settings are...
# Texture: Should load texture from 'Resource.new()' once sent a message.
# Expand: On
# Stretch Mode: Keep Aspect
# Size Flags: Null
var profile_picture = TextureRect.new()
var core_shader = ShaderMaterial.new()
var real_shader = Shader.new()
core_shader.set_shader(real_shader)
var round_shader_txt = round_shader.get_code()
core_shader.set_shader_param("mask", round_shape)
real_shader.set_code(round_shader_txt)
profile_picture.set_texture(pfp)
profile_picture.set_custom_minimum_size(Vector2(65, 65))
profile_picture.expand = true
profile_picture.size_flags_horizontal = 0
profile_picture.size_flags_vertical = 0
profile_picture.set_name("profile_picture")
profile_picture.set_material(core_shader)
# Main node for message's Header and Body
# Separates sections of Header and Body
var GridStructure = VBoxContainer.new()
GridStructure.set_name("GridStructure")
if username_label.get_text() == first_user_data.username:
root.add_child(profile_picture)
root.add_child(GridStructure)
elif username_label.get_text() == second_user_data.username:
root.size_flags_horizontal = 8
root.add_child(GridStructure)
root.add_child(profile_picture)
# Header (Contains Name Label and Date Label)
var Header = HBoxContainer.new()
Header.set_name("Header")
Header.set_custom_minimum_size(Vector2(msg_header_h_size,0))
Header.size_flags_horizontal = 3
GridStructure.add_child(Header)
var NameLabel = Label.new()
NameLabel.set_name("NameLabel")
NameLabel.set_text(user)
NameLabel.add_font_override("font", username_font)
NameLabel.size_flags_horizontal = 3
Header.add_child(NameLabel)
var DateLabel = Label.new()
DateLabel.set_name("DateLabel")
DateLabel.set_text(str(date))
DateLabel.add_font_override("font", date_font)
DateLabel.size_flags_horizontal = 3
Header.add_child(DateLabel)
# Body (Contains NinePatchRect for Background and Margins that contain the RichTextLabel
var Body = MarginContainer.new()
Body.set_name("Body")
GridStructure.set_custom_minimum_size(Vector2(msg_min_h_size, 25))
GridStructure.add_child(Body)
# BGTexture uses NinePatchRect for Message Bubble
var BGTexture = NinePatchRect.new()
BGTexture.set_name("BGTexture")
if username_label.get_text() == first_user_data.username:
BGTexture.patch_margin_left = 21
BGTexture.patch_margin_top = 12
BGTexture.patch_margin_right = 12
BGTexture.patch_margin_bottom = 12
BGTexture.size_flags_horizontal = 3
BGTexture.size_flags_vertical = 3
BGTexture.set_texture(bg_texture1)
elif username_label.get_text() == second_user_data.username:
BGTexture.patch_margin_left = 12
BGTexture.patch_margin_top = 12
BGTexture.patch_margin_right = 21
BGTexture.patch_margin_bottom = 12
BGTexture.size_flags_horizontal = 3
BGTexture.size_flags_vertical = 3
BGTexture.set_texture(bg_texture2)
Body.add_child(BGTexture)
# Margin forces FILL_EXPAND into it's children.
var Margin = MarginContainer.new()
Margin.set_name("Margin")
if username_label.get_text() == first_user_data.username:
Margin.add_constant_override("margin_top", 5)
Margin.add_constant_override("margin_left", 16)
Margin.add_constant_override("margin_right", 5)
Margin.add_constant_override("margin_bottom", 5)
if username_label.get_text() == second_user_data.username:
Margin.add_constant_override("margin_top", 5)
Margin.add_constant_override("margin_left", 5)
Margin.add_constant_override("margin_right", 16)
Margin.add_constant_override("margin_bottom", 5)
Body.add_child(Margin)
# Stretch is what keeps the Message expanding as if it has an anchor for Full_Rect
# Body Content:
var TextLabel = RichTextLabel.new()
TextLabel.set_name("TextLabel")
TextLabel.bbcode_enabled = true
TextLabel.set_bbcode(content)
TextLabel.fit_content_height = true
TextLabel.scroll_active = false
TextLabel.size_flags_horizontal = 1
TextLabel.add_color_override("default_color", Color(0,0,0,1))
Margin.add_child(TextLabel)