Added save and load functionality.

This commit is contained in:
mono 2022-06-04 13:33:00 +02:00
parent f3c726329d
commit 7123b47938
24 changed files with 201 additions and 80 deletions

@ -29,7 +29,7 @@ _global_script_classes=[ {
"language": "GDScript", "language": "GDScript",
"path": "res://system/data/message_data/message.gd" "path": "res://system/data/message_data/message.gd"
}, { }, {
"base": "Node", "base": "Object",
"class": "MessageData", "class": "MessageData",
"language": "GDScript", "language": "GDScript",
"path": "res://system/data/message_data/message_data_singleton.gd" "path": "res://system/data/message_data/message_data_singleton.gd"
@ -54,7 +54,7 @@ _global_script_classes=[ {
"language": "GDScript", "language": "GDScript",
"path": "res://system/data/topic_data/topic.gd" "path": "res://system/data/topic_data/topic.gd"
}, { }, {
"base": "Node", "base": "Object",
"class": "TopicData", "class": "TopicData",
"language": "GDScript", "language": "GDScript",
"path": "res://system/data/topic_data/topic_data_singleton.gd" "path": "res://system/data/topic_data/topic_data_singleton.gd"

@ -1,21 +1,19 @@
extends Node extends Node
signal loaded()
var messages: MessageData var messages: MessageData
var topics: TopicData var topics: TopicData
func _ready(): func _ready():
messages = MessageData.new()
topics = TopicData.new()
var autosave_timer = Timer.new() var autosave_timer = Timer.new()
autosave_timer.wait_time = 600.0 # Every ten minutes. autosave_timer.wait_time = 600.0 # Every ten minutes.
autosave_timer.autostart = true autosave_timer.autostart = true
autosave_timer.connect("timeout", self, "_save_data") autosave_timer.connect("timeout", self, "_save_data")
add_child(autosave_timer) add_child(autosave_timer)
yield(get_tree(), "idle_frame")
_load_data()
func _notification(what): func _notification(what):
@ -23,14 +21,17 @@ func _notification(what):
_save_data() _save_data()
func _exit_tree(): func setup():
messages.free() messages = MessageData.new()
topics.free() topics = TopicData.new()
yield(get_tree(), "idle_frame")
_load_data()
func _load_data(): func _load_data():
messages.load_data() messages.load_data()
topics.load_data() topics.load_data()
emit_signal("loaded")
func _save_data(): func _save_data():

@ -4,25 +4,32 @@ class_name Message
const MESSAGE_NODE = preload("res://user_interface/chat_panel/message_node.tscn") const MESSAGE_NODE = preload("res://user_interface/chat_panel/message_node.tscn")
var associated_node: Control var associated_node: Control
var associated_message_group: MessageGroup var associated_message_group: WeakRef
var content: String var content: String
var time_stamp: int var time_stamp: int
func get_user() -> User: func get_user() -> User:
return associated_message_group.associated_user return associated_message_group.get_ref().associated_user
func delete(): func delete():
associated_message_group.delete(self) associated_message_group.get_ref().delete(self)
Data.messages.dirty_flag = true
func edit(new_content: String):
content = new_content
Data.messages.dirty_flag = true
# Used by the MessageFeed, to spawn message nodes. # Used by the MessageFeed, to spawn message nodes.
func create_node() -> Control: func create_node() -> Control:
var message_node = MESSAGE_NODE.instance() var message_node = MESSAGE_NODE.instance()
associated_node = message_node associated_node = message_node
message_node.associated_message = self message_node.associated_message = weakref(self)
if associated_message_group.messages.size() > 1: if associated_message_group:
message_node.follow_up = true if associated_message_group.get_ref().messages.size() > 1:
message_node.follow_up = true
return message_node return message_node

@ -1,4 +1,4 @@
extends Node extends Object
class_name MessageData class_name MessageData
@ -32,20 +32,43 @@ func add_message(content, time_stamp, user):
message_group.add(message) message_group.add(message)
emit_signal("message_added", message) emit_signal("message_added", message)
# var node = message.create_node() dirty_flag = true
# message_group.associated_container.add(node)
func load_data(): func load_data():
# TODO: load data. var file = File.new()
pass file.open("user://message_history.dat", File.READ)
var json_string = file.get_as_text()
if validate_json(json_string):
printerr("\"message_history.dat\" was found, but is corrupted.")
return
var message_data_list = parse_json(json_string)
for message_data in message_data_list:
var user = Users.get_primary() if message_data["user"] else Users.get_helper()
add_message(
message_data["content"],
message_data["time_stamp"],
user
)
func save_data(): func save_data():
if dirty_flag: if dirty_flag:
# TODO: Save data. var message_data_list = []
pass for message_group in loaded_message_groups:
var user = message_group.associated_user.is_primary()
for message in message_group.messages:
var message_data = {
"user" : user,
"time_stamp" : message.time_stamp,
"content" : message.content
}
message_data_list.append(message_data)
var json_string = to_json(message_data_list)
var file = File.new()
file.open("user://message_history.dat", File.WRITE)
file.store_string(json_string)
file.close()
# dirty_flag needs to be set to false after successful save! # dirty_flag needs to be set to false after successful save!
dirty_flag = false dirty_flag = false

@ -13,7 +13,7 @@ var messages := []
func add(message): func add(message):
messages.append(message) messages.append(message)
message.associated_message_group = self message.associated_message_group = weakref(self)
func delete(message): func delete(message):
@ -32,5 +32,5 @@ func delete(message):
func create_container() -> Control: func create_container() -> Control:
var container = MESSAGE_GROUP_CONTAINER.instance() var container = MESSAGE_GROUP_CONTAINER.instance()
associated_container = container associated_container = container
container.associated_message_group = self container.associated_message_group = weakref(self)
return container return container

@ -31,7 +31,7 @@ func create_node() -> Control:
var topic_node = TOPIC_NODE.instance() var topic_node = TOPIC_NODE.instance()
var editable = topic_node.get_node("TopicEditable") var editable = topic_node.get_node("TopicEditable")
associated_node = editable associated_node = editable
editable.associated_topic = self editable.associated_topic = weakref(self)
editable.type = type editable.type = type
return topic_node return topic_node

@ -1,19 +1,29 @@
extends Node extends Object
class_name TopicData class_name TopicData
signal topic_added(topic, position) signal topic_added(topic)
signal topic_inserted(topic, position)
var dirty_flag = false var dirty_flag = false
var loaded_topics = [] var loaded_topics = []
func add_topic(position: int): func add_topic(content, type): # On start-up.
var topic = Topic.new()
topic.content = content
topic.type = type
loaded_topics.append(topic)
emit_signal("topic_added", topic)
func insert_topic(position: int):
var topic = Topic.new() var topic = Topic.new()
loaded_topics.append(topic) loaded_topics.append(topic)
dirty_flag = true dirty_flag = true
emit_signal("topic_added", topic, position) emit_signal("topic_inserted", topic, position)
func sort_topics(): func sort_topics():
@ -25,15 +35,34 @@ func _compare_topic_index(a, b):
func load_data(): func load_data():
# TODO: Load data. var file = File.new()
pass file.open("user://topic_list.dat", File.READ)
var json_string = file.get_as_text()
if validate_json(json_string):
printerr("\"topic_list.dat\" was found, but is corrupted.")
return
var topic_data_list = parse_json(json_string)
for topic_data in topic_data_list:
add_topic(
topic_data["content"],
int(topic_data["type"])
)
func save_data(): func save_data():
if dirty_flag: if dirty_flag:
sort_topics() # Important before saving, to remain the order. sort_topics() # Important before saving, to remain the order.
# TODO: Save data. var topic_data_list = []
pass for topic in loaded_topics:
var topic_data = {
"content" : topic.content,
"type" : topic.type
}
topic_data_list.append(topic_data)
var json_string = to_json(topic_data_list)
var file = File.new()
file.open("user://topic_list.dat", File.WRITE)
file.store_string(json_string)
file.close()
# dirty_flag needs to be set to false after successful save! # dirty_flag needs to be set to false after successful save!
dirty_flag = false dirty_flag = false

@ -21,8 +21,6 @@ func _input(event):
func send_ping(): func send_ping():
if unhandled_ping_count < 15: if unhandled_ping_count < 15:
Data.messages.add_message("", Time.get_current_time(), Users.get_helper()) Data.messages.add_message("", Time.get_current_time(), Users.get_helper())
unhandled_ping_count += 1
total_ping_count += 1
ping_sound.play() ping_sound.play()
OS.request_attention() OS.request_attention()

@ -4,6 +4,7 @@ onready var animation_player = get_node("AnimationPlayer")
func _ready(): func _ready():
# warning-ignore:return_value_discarded
Call.connect("requested", self, "_on_call_requested") Call.connect("requested", self, "_on_call_requested")

@ -70,7 +70,7 @@ tracks/0/keys = {
"times": PoolRealArray( 0 ), "times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ), "transitions": PoolRealArray( 1 ),
"update": 0, "update": 0,
"values": [ true ] "values": [ false ]
} }
tracks/1/type = "value" tracks/1/type = "value"
tracks/1/path = NodePath(".:rect_min_size") tracks/1/path = NodePath(".:rect_min_size")

@ -11,7 +11,7 @@ const FOLLOW_UP_BUBBLE_BY_INACTIVE = preload("res://user_interface/chat_panel/fo
onready var message_inserted_sound = get_node("MessageInsertedSound") onready var message_inserted_sound = get_node("MessageInsertedSound")
var associated_message var associated_message: WeakRef
var follow_up: bool = false var follow_up: bool = false
# If the node was spawned by PingSystem. # If the node was spawned by PingSystem.
@ -20,11 +20,11 @@ var ping_id: int = -1
func get_user() -> User: func get_user() -> User:
return associated_message.get_user() return associated_message.get_ref().get_user()
func _get_content_string() -> String: # Override. func _get_content_string() -> String: # Override.
return associated_message.content return associated_message.get_ref().content
func _setup(): # Override. func _setup(): # Override.
@ -40,6 +40,8 @@ func _setup_insert_mode():
# warning-ignore:return_value_discarded # warning-ignore:return_value_discarded
PingSystem.connect("ping_handled", self, "_on_ping_handled") PingSystem.connect("ping_handled", self, "_on_ping_handled")
ping_id = PingSystem.total_ping_count ping_id = PingSystem.total_ping_count
PingSystem.unhandled_ping_count += 1
PingSystem.total_ping_count += 1
# warning-ignore:return_value_discarded # warning-ignore:return_value_discarded
_check_if_next_ping() _check_if_next_ping()
@ -58,7 +60,7 @@ func _setup_insert_mode():
func _setup_popup_menu_items(): # Override. func _setup_popup_menu_items(): # Override.
if associated_message.get_user() == Users.get_current(): if associated_message.get_ref().get_user() == Users.get_current():
popup_menu.add_item("Edit", 0) popup_menu.add_item("Edit", 0)
popup_menu.add_item("Copy", 1) popup_menu.add_item("Copy", 1)
popup_menu.add_item("Delete", 2) popup_menu.add_item("Delete", 2)
@ -130,7 +132,7 @@ func _disable_insert_mode():
func _delete(): func _delete():
associated_message.delete() associated_message.get_ref().delete()
func _on_popup_menu_id_pressed(id): func _on_popup_menu_id_pressed(id):
@ -138,7 +140,7 @@ func _on_popup_menu_id_pressed(id):
0: # Edit. 0: # Edit.
_enable_edit_mode() _enable_edit_mode()
1: # Copy. 1: # Copy.
OS.clipboard = associated_message.content OS.clipboard = associated_message.get_ref().content
2: # Delete. 2: # Delete.
_delete() _delete()
@ -149,7 +151,7 @@ func _on_text_edit_confirmed(confirmed_content): # Override
if not insert_mode: if not insert_mode:
_delete() _delete()
else: else:
associated_message.content = confirmed_content associated_message.get_ref().edit(confirmed_content)
_disable_edit_mode() _disable_edit_mode()

@ -31,7 +31,7 @@ func _on_message_box_confirmed(content):
func _on_data_message_added(message): func _on_data_message_added(message):
var node = message.create_node() var node = message.create_node()
message.associated_message_group.associated_container.add(node) message.associated_message_group.get_ref().associated_container.add(node)
scroll_to_newest() scroll_to_newest()

@ -8,7 +8,7 @@ onready var username = get_node("VBoxContainer/Header/Username")
onready var date = get_node("VBoxContainer/Header/Date") onready var date = get_node("VBoxContainer/Header/Date")
onready var message_container = get_node("VBoxContainer/MessageContainer") onready var message_container = get_node("VBoxContainer/MessageContainer")
var associated_message_group var associated_message_group: WeakRef
func _ready(): func _ready():
@ -18,7 +18,7 @@ func _ready():
func get_user() -> User: func get_user() -> User:
return associated_message_group.associated_user return associated_message_group.get_ref().associated_user
func add(message): func add(message):
@ -34,18 +34,47 @@ func _setup():
username.text = get_user().username username.text = get_user().username
# Define date. # Define date.
var time_stamp = associated_message_group.time_stamp var time_stamp = associated_message_group.get_ref().time_stamp
var storaged_date = OS.get_datetime_from_unix_time(time_stamp) var storaged_date = OS.get_datetime_from_unix_time(time_stamp)
var os_time = OS.get_datetime() var os_time = OS.get_datetime()
if storaged_date.day == os_time.day: if storaged_date.day == os_time.day:
date.text = "today, at " + str(os_time.hour) + ":" + "%02d" % os_time.minute date.text = "Today at " + _get_time_string(storaged_date)
elif storaged_date.day == os_time.day + 1: elif storaged_date.day == os_time.day - 1:
date.text = "yesterday" date.text = "Yesterday at " + _get_time_string(storaged_date)
else:
date.text = _get_date_string(storaged_date)
_adjust_layout_to_user() _adjust_layout_to_user()
func _get_time_string(datetime: Dictionary) -> String:
var hour = datetime.hour
var minute = datetime.minute
var am_pm
var offset_wrapped_hour = wrapi(hour - 1, 0, 24)
var processed_hour = offset_wrapped_hour
if offset_wrapped_hour >= 12:
am_pm = " PM"
processed_hour -= 12
else:
am_pm = " AM"
processed_hour += 1
var hour_string = str(processed_hour)
var minute_string = "%02d" % minute
return hour_string + ":" + minute_string + am_pm
func _get_date_string(datetime: Dictionary) -> String:
var month_string = "%02d" % datetime.month
var day_string = "%02d" % datetime.day
var year_string = str(datetime.year)
return month_string + "/" + day_string + "/" + year_string
func _adjust_layout_to_user(): func _adjust_layout_to_user():
if get_user().is_current(): if get_user().is_current():
move_child(profile_image_rect, 1) move_child(profile_image_rect, 1)

@ -30,6 +30,7 @@ custom_fonts/font = ExtResource( 4 )
text = "[Username]" text = "[Username]"
[node name="Date" type="Label" parent="VBoxContainer/Header"] [node name="Date" type="Label" parent="VBoxContainer/Header"]
self_modulate = Color( 1, 1, 1, 0.501961 )
margin_left = 461.0 margin_left = 461.0
margin_right = 488.0 margin_right = 488.0
margin_bottom = 12.0 margin_bottom = 12.0

@ -12,6 +12,16 @@ func _ready():
Users.emit_signal("switched") Users.emit_signal("switched")
func _enter_tree():
Data.setup()
func _exit_tree():
Data._save_data()
Data.messages.free()
Data.topics.free()
func _on_user_switched(): func _on_user_switched():
theme.get_stylebox("panel", "Panel").bg_color = Users.get_current().background_color theme.get_stylebox("panel", "Panel").bg_color = Users.get_current().background_color
theme.get_stylebox("panel", "PanelContainer").bg_color = Users.get_current().panel_color theme.get_stylebox("panel", "PanelContainer").bg_color = Users.get_current().panel_color

@ -42,11 +42,11 @@ margin_bottom = 568.0
visible = false visible = false
[node name="CallPanel" parent="Panel/MarginContainer/VBoxContainer" instance=ExtResource( 5 )] [node name="CallPanel" parent="Panel/MarginContainer/VBoxContainer" instance=ExtResource( 5 )]
visible = false
margin_top = 0.0 margin_top = 0.0
margin_bottom = 0.0 margin_bottom = 0.0
[node name="HBoxContainer" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer"] [node name="HBoxContainer" type="HBoxContainer" parent="Panel/MarginContainer/VBoxContainer"]
margin_top = 8.0
margin_right = 1008.0 margin_right = 1008.0
margin_bottom = 560.0 margin_bottom = 560.0
size_flags_vertical = 3 size_flags_vertical = 3
@ -56,17 +56,17 @@ __meta__ = {
[node name="SidePanel" type="VBoxContainer" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer"] [node name="SidePanel" type="VBoxContainer" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer"]
margin_right = 328.0 margin_right = 328.0
margin_bottom = 552.0 margin_bottom = 560.0
rect_min_size = Vector2( 328, 0 ) rect_min_size = Vector2( 328, 0 )
[node name="TopicPanel" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer/SidePanel" instance=ExtResource( 3 )] [node name="TopicPanel" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer/SidePanel" instance=ExtResource( 3 )]
margin_bottom = 482.0 margin_bottom = 490.0
[node name="ToolBar" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer/SidePanel" instance=ExtResource( 2 )] [node name="ToolBar" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer/SidePanel" instance=ExtResource( 2 )]
margin_top = 490.0 margin_top = 498.0
margin_bottom = 552.0 margin_bottom = 560.0
[node name="ChatPanel" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer" instance=ExtResource( 1 )] [node name="ChatPanel" parent="Panel/MarginContainer/VBoxContainer/HBoxContainer" instance=ExtResource( 1 )]
margin_bottom = 552.0 margin_bottom = 560.0
[connection signal="resized" from="." to="." method="_on_resized"] [connection signal="resized" from="." to="." method="_on_resized"]

@ -1,5 +1,5 @@
extends TextureButton extends TextureButton
func _on_toggled(button_pressed): func _on_toggled(_button_pressed):
Call.request_call() Call.request_call()

@ -0,0 +1,6 @@
extends TextureButton
# settings_button.gd
func _on_pressed():
# warning-ignore:return_value_discarded
get_tree().reload_current_scene()

@ -1,4 +1,4 @@
[gd_scene load_steps=21 format=2] [gd_scene load_steps=22 format=2]
[ext_resource path="res://user_interface/main.theme" type="Theme" id=1] [ext_resource path="res://user_interface/main.theme" type="Theme" id=1]
[ext_resource path="res://user_interface/utility_controls/profile_image_rect_mask.png" type="Texture" id=2] [ext_resource path="res://user_interface/utility_controls/profile_image_rect_mask.png" type="Texture" id=2]
@ -17,6 +17,7 @@
[ext_resource path="res://user_interface/tool_bar/icons/settings_pressed.png" type="Texture" id=15] [ext_resource path="res://user_interface/tool_bar/icons/settings_pressed.png" type="Texture" id=15]
[ext_resource path="res://user_interface/tool_bar/icons/start_call_pressed.png" type="Texture" id=16] [ext_resource path="res://user_interface/tool_bar/icons/start_call_pressed.png" type="Texture" id=16]
[ext_resource path="res://user_interface/tool_bar/icons/mute_pressed.png" type="Texture" id=17] [ext_resource path="res://user_interface/tool_bar/icons/mute_pressed.png" type="Texture" id=17]
[ext_resource path="res://user_interface/tool_bar/settings_button.gd" type="Script" id=18]
[sub_resource type="Shader" id=1] [sub_resource type="Shader" id=1]
code = "shader_type canvas_item; code = "shader_type canvas_item;
@ -146,7 +147,9 @@ size_flags_vertical = 4
texture_normal = ExtResource( 8 ) texture_normal = ExtResource( 8 )
texture_pressed = ExtResource( 15 ) texture_pressed = ExtResource( 15 )
texture_hover = ExtResource( 14 ) texture_hover = ExtResource( 14 )
script = ExtResource( 18 )
[connection signal="toggled" from="Margin/Structure/CallButton" to="Margin/Structure/CallButton" method="_on_toggled"] [connection signal="toggled" from="Margin/Structure/CallButton" to="Margin/Structure/CallButton" method="_on_toggled"]
[connection signal="pressed" from="Margin/Structure/MuteButton" to="Margin/Structure/MuteButton" method="_on_pressed"] [connection signal="pressed" from="Margin/Structure/MuteButton" to="Margin/Structure/MuteButton" method="_on_pressed"]
[connection signal="toggled" from="Margin/Structure/MuteButton" to="Margin/Structure/MuteButton" method="_on_toggled"] [connection signal="toggled" from="Margin/Structure/MuteButton" to="Margin/Structure/MuteButton" method="_on_toggled"]
[connection signal="pressed" from="Margin/Structure/SettingsButton" to="Margin/Structure/SettingsButton" method="_on_pressed"]

@ -14,6 +14,6 @@ func _on_user_switched():
func _on_pressed(): func _on_pressed():
Data.topics.add_topic(get_index()) Data.topics.insert_topic(get_index())
yield(get_tree(), "idle_frame") yield(get_tree(), "idle_frame")
scroll_container.scroll_vertical += 64 scroll_container.scroll_vertical += 64

@ -8,13 +8,13 @@ const TYPE_URGENT = 2
onready var parent = get_parent() onready var parent = get_parent()
onready var type_label = get_node("VBoxContainer/HBoxContainer/TypeLabel") onready var type_label = get_node("VBoxContainer/HBoxContainer/TypeLabel")
var associated_topic var associated_topic: WeakRef
var type: int = TYPE_CASUAL var type: int = TYPE_CASUAL
var color: Color var color: Color
func _get_content_string() -> String: # Override. func _get_content_string() -> String: # Override.
return associated_topic.content return associated_topic.get_ref().content
func _setup(): # Override. func _setup(): # Override.
@ -85,13 +85,13 @@ func _delete():
if _is_part_of_multi_selection(): if _is_part_of_multi_selection():
parent.topic_feed._delete_selected_topics() parent.topic_feed._delete_selected_topics()
else: else:
associated_topic.delete() associated_topic.get_ref().delete()
func _on_popup_menu_id_pressed(id): func _on_popup_menu_id_pressed(id):
match id: match id:
0: # Insert new Topic. 0: # Insert new Topic.
Data.topics.add_topic(parent.get_index()) Data.topics.insert_topic(parent.get_index())
1: # Edit. 1: # Edit.
_enable_edit_mode() _enable_edit_mode()
text_edit.grab_focus() text_edit.grab_focus()
@ -101,25 +101,25 @@ func _on_popup_menu_id_pressed(id):
if _is_part_of_multi_selection(): if _is_part_of_multi_selection():
parent.topic_feed._change_type_of_selected_topics(TYPE_CASUAL) parent.topic_feed._change_type_of_selected_topics(TYPE_CASUAL)
else: else:
associated_topic.change_type(TYPE_CASUAL) associated_topic.get_ref().change_type(TYPE_CASUAL)
_adjust_appearance_to_user() _adjust_appearance_to_user()
3: # Change type to DAILY. 3: # Change type to DAILY.
if _is_part_of_multi_selection(): if _is_part_of_multi_selection():
parent.topic_feed._change_type_of_selected_topics(TYPE_DAILY) parent.topic_feed._change_type_of_selected_topics(TYPE_DAILY)
else: else:
associated_topic.change_type(TYPE_DAILY) associated_topic.get_ref().change_type(TYPE_DAILY)
_adjust_appearance_to_user() _adjust_appearance_to_user()
4: # Change type to URGENT. 4: # Change type to URGENT.
if _is_part_of_multi_selection(): if _is_part_of_multi_selection():
parent.topic_feed._change_type_of_selected_topics(TYPE_URGENT) parent.topic_feed._change_type_of_selected_topics(TYPE_URGENT)
else: else:
associated_topic.change_type(TYPE_URGENT) associated_topic.get_ref().change_type(TYPE_URGENT)
_adjust_appearance_to_user() _adjust_appearance_to_user()
5: # Delete. 5: # Delete.
_delete() _delete()
func _on_text_edit_confirmed(confirmed_content): # Override func _on_text_edit_confirmed(confirmed_content): # Override
associated_topic.content = confirmed_content associated_topic.get_ref().content = confirmed_content
_disable_edit_mode() _disable_edit_mode()
Data.topics.dirty_flag = true Data.topics.dirty_flag = true

@ -4,6 +4,9 @@ extends VBoxContainer
signal topic_node_added(topic_node) signal topic_node_added(topic_node)
const ADD_BUTTON = preload("res://user_interface/topic_panel/add_button.tscn")
var currently_grabbed_topic = null var currently_grabbed_topic = null
var selected_topics = [] var selected_topics = []
@ -15,6 +18,10 @@ var _toggle_selection_result
func _ready(): func _ready():
# warning-ignore:return_value_discarded # warning-ignore:return_value_discarded
Data.topics.connect("topic_added", self, "_on_data_topic_added") Data.topics.connect("topic_added", self, "_on_data_topic_added")
# warning-ignore:return_value_discarded
Data.topics.connect("topic_inserted", self, "_on_data_topic_inserted")
# warning-ignore:return_value_discarded
Data.connect("loaded", self, "_on_data_loaded")
func _input(event): func _input(event):
@ -62,21 +69,30 @@ func update_all_colors():
func _delete_selected_topics(): func _delete_selected_topics():
for topic in selected_topics: for topic in selected_topics:
topic.editable.associated_topic.delete() topic.editable.associated_topic.get_ref().delete()
selected_topics.clear() selected_topics.clear()
func _change_type_of_selected_topics(type: int): func _change_type_of_selected_topics(type: int):
for topic in selected_topics: for topic in selected_topics:
topic.editable.associated_topic.change_type(type) topic.editable.associated_topic.get_ref().change_type(type)
topic.editable._adjust_appearance_to_user() topic.editable._adjust_appearance_to_user()
selected_topics.clear() selected_topics.clear()
update_all_colors() update_all_colors()
func _on_data_topic_added(topic, position): func _on_data_topic_added(topic):
var topic_node = topic.create_node()
add_child(topic_node)
topic_node.editable._adjust_appearance_to_user()
func _on_data_topic_inserted(topic, position):
var topic_node = topic.create_node() var topic_node = topic.create_node()
add_child(topic_node) add_child(topic_node)
move_child(topic_node, position) move_child(topic_node, position)
topic_node.editable._adjust_appearance_to_user() topic_node.editable._adjust_appearance_to_user()
func _on_data_loaded():
add_child(ADD_BUTTON.instance())

@ -1,7 +1,6 @@
[gd_scene load_steps=4 format=2] [gd_scene load_steps=3 format=2]
[ext_resource path="res://user_interface/main.theme" type="Theme" id=1] [ext_resource path="res://user_interface/main.theme" type="Theme" id=1]
[ext_resource path="res://user_interface/topic_panel/add_button.tscn" type="PackedScene" id=2]
[ext_resource path="res://user_interface/topic_panel/topic_feed.gd" type="Script" id=3] [ext_resource path="res://user_interface/topic_panel/topic_feed.gd" type="Script" id=3]
[node name="TopicPanel" type="PanelContainer"] [node name="TopicPanel" type="PanelContainer"]
@ -26,10 +25,5 @@ scroll_horizontal_enabled = false
[node name="TopicFeed" type="VBoxContainer" parent="MarginContainer/ScrollContainer"] [node name="TopicFeed" type="VBoxContainer" parent="MarginContainer/ScrollContainer"]
margin_right = 312.0 margin_right = 312.0
margin_bottom = 56.0
size_flags_horizontal = 3 size_flags_horizontal = 3
script = ExtResource( 3 ) script = ExtResource( 3 )
[node name="AddButton" parent="MarginContainer/ScrollContainer/TopicFeed" instance=ExtResource( 2 )]
margin_right = 312.0
margin_bottom = 56.0

@ -19,6 +19,7 @@ var edit_mode: bool = false
func _ready(): func _ready():
margin_container.remove_child(text_edit) margin_container.remove_child(text_edit)
popup_menu.rect_size.x = 64 popup_menu.rect_size.x = 64
content.text = _get_content_string()
# warning-ignore:return_value_discarded # warning-ignore:return_value_discarded
Users.connect("switched", self, "_on_user_switched") Users.connect("switched", self, "_on_user_switched")
_setup() _setup()