diary/system/Message.gd

121 lines
3.5 KiB
GDScript3
Raw Normal View History

2022-04-19 14:24:57 +02:00
tool
extends HBoxContainer
onready var bg_texture = preload("res://assets/textures/bg.png")
func create_message():
# Creates Data
var resource = Message.new()
resource.user = 1
resource.date = "today"
resource.content = "hello"
resource.profile_picture = null
var user = resource.user
var date = resource.date
var content = resource.content
var pfp = resource.profile_picture
print("Resource: ", resource, "\nUser: ", user, "\nDate: ", date, "\nContent: ", content, "\nProfile Picture: ", pfp)
# root is a HBoxContainer.
var root = HBoxContainer.new()
# 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()
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")
self.add_child(profile_picture)
# Main node for message's Header and Body
# Separates sections of Header and Body
var GridStructure = VBoxContainer.new()
GridStructure.set_name("GridStructure")
self.add_child(GridStructure)
# Header (Contains Name Label and Date Label)
var Header = HBoxContainer.new()
Header.set_name("Header")
GridStructure.add_child(Header)
var NameLabel = Label.new()
NameLabel.set_name("NameLabel")
NameLabel.set_text(name)
Header.add_child(NameLabel)
var DateLabel = Label.new()
DateLabel.set_name("DateLabel")
DateLabel.set_text(date)
Header.add_child(DateLabel)
# Body (Contains NinePatchRect for Background and Margins that contain the RichTextLabel
var Body = MarginContainer.new()
Body.set_name("Body")
GridStructure.add_child(Body)
# BGTexture uses NinePatchRect for Message Bubble
var BGTexture = NinePatchRect.new()
BGTexture.set_name("BGTexture")
BGTexture.set_texture(bg_texture)
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
Body.add_child(BGTexture)
# Margin forces FILL_EXPAND into it's children.
var Margin = MarginContainer.new()
Margin.set_name("Margin")
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)
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)
func build_time():
var time
var all_time = false
var os_time = OS.get_datetime()
var storaged_today = OS.get_datetime().day
var storaged_yesterday = OS.get_datetime().day +1
if storaged_today == os_time.day:
time = "today"
if storaged_yesterday == os_time.day +1:
storaged_yesterday = "yesterday"
if os_time.day > 1:
print("Before Yesterday: ",os_time.day, "/", os_time.month, "/", os_time.year)
print("if Today: ", time, "\nif Yesterday: ", storaged_yesterday)
func _ready():
build_time()