2022-05-14 20:51:48 +02:00
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 ( )
2022-05-21 14:56:02 +02:00
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 )
2022-05-14 20:51:48 +02:00
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 ( ) :
2022-05-21 14:56:02 +02:00
var addition
if _is_selected ( ) :
addition = Color ( 0.1 , 0.12 , 0.15 )
else :
addition = Color . black
2022-05-14 20:51:48 +02:00
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
2022-05-21 14:56:02 +02:00
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
2022-05-14 20:51:48 +02:00
func _delete ( ) :
2022-05-21 14:56:02 +02:00
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 ( )
2022-05-14 20:51:48 +02:00
func _on_text_edit_confirmed ( confirmed_content ) : # Override
associated_topic . content = confirmed_content
_disable_edit_mode ( )
2022-05-21 14:56:02 +02:00
Data . topics . dirty_flag = true