diary/user_interface/topic_panel/topic_editable.gd
2022-05-21 14:56:02 +02:00

126 lines
3.1 KiB
GDScript

extends EditableTextBlock
class_name TopicEditable
const TYPE_CASUAL = 0
const TYPE_DAILY = 1
const TYPE_URGENT = 2
onready var parent = get_parent()
onready var type_label = get_node("VBoxContainer/HBoxContainer/TypeLabel")
var associated_topic
var type: int = TYPE_CASUAL
var color: Color
func _get_content_string() -> String: # Override.
return associated_topic.content
func _setup(): # Override.
_setup_content()
_setup_appearance()
func _setup_popup_menu_items(): # Override.
var is_selected = _is_part_of_multi_selection()
if not is_selected:
popup_menu.add_item("Insert New", 0)
popup_menu.add_item("Edit", 1)
popup_menu.add_separator("Change Type")
if type != TYPE_CASUAL or is_selected:
popup_menu.add_radio_check_item("Casual", 2)
if type != TYPE_DAILY or is_selected:
popup_menu.add_radio_check_item("Daily", 3)
if type != TYPE_URGENT or is_selected:
popup_menu.add_radio_check_item("Urgent", 4)
popup_menu.add_separator("")
popup_menu.add_item("Delete", 5)
func _adjust_appearance_to_user(): # Override.
match type:
TYPE_CASUAL:
if type_label:
type_label.text = "CASUAL"
color = Users.get_current().casual_topic_color
TYPE_DAILY:
if type_label:
type_label.text = "DAILY"
color = Users.get_current().daily_topic_color
TYPE_URGENT:
if type_label:
type_label.text = "URGENT"
color = Users.get_current().urgent_topic_color
_update_color()
func _update_color():
var addition
if _is_selected():
addition = Color(0.1, 0.12, 0.15)
else:
addition = Color.black
nine_patch.self_modulate = color + addition
func _is_selected() -> bool:
if get_parent().topic_feed:
return parent.topic_feed.selected_topics.has(parent)
else:
return false
func _is_part_of_multi_selection() -> bool:
if get_parent().topic_feed:
return _is_selected() and parent.topic_feed.selected_topics.size() > 1
else:
return false
func _delete():
if _is_part_of_multi_selection():
parent.topic_feed._delete_selected_topics()
else:
associated_topic.delete()
func _on_popup_menu_id_pressed(id):
match id:
0: # Insert new Topic.
Data.topics.add_topic(parent.get_index())
1: # Edit.
_enable_edit_mode()
text_edit.grab_focus()
yield(get_tree(), "idle_frame")
text_edit.select_all()
2: # Change type to CASUAL.
if _is_part_of_multi_selection():
parent.topic_feed._change_type_of_selected_topics(TYPE_CASUAL)
else:
associated_topic.change_type(TYPE_CASUAL)
_adjust_appearance_to_user()
3: # Change type to DAILY.
if _is_part_of_multi_selection():
parent.topic_feed._change_type_of_selected_topics(TYPE_DAILY)
else:
associated_topic.change_type(TYPE_DAILY)
_adjust_appearance_to_user()
4: # Change type to URGENT.
if _is_part_of_multi_selection():
parent.topic_feed._change_type_of_selected_topics(TYPE_URGENT)
else:
associated_topic.change_type(TYPE_URGENT)
_adjust_appearance_to_user()
5: # Delete.
_delete()
func _on_text_edit_confirmed(confirmed_content): # Override
associated_topic.content = confirmed_content
_disable_edit_mode()
Data.topics.dirty_flag = true