109 lines
3.1 KiB
GDScript
109 lines
3.1 KiB
GDScript
extends Control
|
|
|
|
const Brand := preload("res://scripts/ui/medmind_style.gd")
|
|
const NotesEditor := preload("res://scripts/ui/notes_editor.gd")
|
|
|
|
signal closed
|
|
|
|
var panel: PanelContainer
|
|
var notes_editor: VBoxContainer
|
|
var theme_service: Node
|
|
var block_session_service: Node
|
|
|
|
|
|
func _ready() -> void:
|
|
theme_service = get_node("/root/UIThemeService")
|
|
block_session_service = get_node("/root/BlockSessionService")
|
|
visible = false
|
|
top_level = true
|
|
mouse_filter = Control.MOUSE_FILTER_STOP
|
|
set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
|
|
var dim := ColorRect.new()
|
|
dim.color = Color(0, 0, 0, 0.72)
|
|
dim.set_anchors_preset(Control.PRESET_FULL_RECT)
|
|
dim.gui_input.connect(_on_dim_input)
|
|
add_child(dim)
|
|
var center := CenterContainer.new()
|
|
center.set_anchors_preset(Control.PRESET_FULL_RECT)
|
|
add_child(center)
|
|
panel = PanelContainer.new()
|
|
panel.custom_minimum_size = Vector2(760, 650)
|
|
center.add_child(panel)
|
|
var content := VBoxContainer.new()
|
|
content.add_theme_constant_override("separation", 12)
|
|
panel.add_child(content)
|
|
var header := HBoxContainer.new()
|
|
content.add_child(header)
|
|
var title := Label.new()
|
|
title.text = "Notes"
|
|
title.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
|
title.add_theme_font_override("font", Brand.font)
|
|
title.add_theme_font_size_override("font_size", 26)
|
|
header.add_child(title)
|
|
var close_button := Button.new()
|
|
close_button.icon = preload("res://assets/icons/lucide/x.svg")
|
|
close_button.tooltip_text = "Close notes"
|
|
close_button.custom_minimum_size = Vector2(42, 42)
|
|
close_button.add_theme_constant_override("icon_max_width", 20)
|
|
close_button.pressed.connect(hide_dialog)
|
|
header.add_child(close_button)
|
|
notes_editor = NotesEditor.new()
|
|
content.add_child(notes_editor)
|
|
theme_service.theme_changed.connect(_on_theme_changed)
|
|
resized.connect(_fit_panel)
|
|
_apply_theme()
|
|
_fit_panel()
|
|
|
|
|
|
func show_dialog() -> void:
|
|
notes_editor.activate()
|
|
visible = true
|
|
move_to_front()
|
|
block_session_service.pause_current_question_timer()
|
|
call_deferred("_focus_editor")
|
|
|
|
|
|
func hide_dialog() -> void:
|
|
if not visible:
|
|
return
|
|
visible = false
|
|
get_node("/root/NotesService").flush()
|
|
block_session_service.resume_current_question_timer()
|
|
closed.emit()
|
|
|
|
|
|
func _focus_editor() -> void:
|
|
notes_editor.focus_editor()
|
|
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if visible and event.is_action_pressed("ui_cancel"):
|
|
hide_dialog()
|
|
get_viewport().set_input_as_handled()
|
|
|
|
|
|
func _on_dim_input(event: InputEvent) -> void:
|
|
var mouse_event := event as InputEventMouseButton
|
|
if mouse_event != null and mouse_event.pressed and mouse_event.button_index == MOUSE_BUTTON_LEFT:
|
|
hide_dialog()
|
|
get_viewport().set_input_as_handled()
|
|
|
|
|
|
func _on_theme_changed(_dark: bool) -> void:
|
|
_apply_theme()
|
|
|
|
|
|
func _apply_theme() -> void:
|
|
panel.add_theme_stylebox_override("panel", Brand.panel_box(theme_service.is_dark_mode()))
|
|
|
|
|
|
func _fit_panel() -> void:
|
|
if panel == null:
|
|
return
|
|
var available := get_viewport_rect().size - Vector2(32, 32)
|
|
var target_size := Vector2(
|
|
minf(760.0, maxf(300.0, available.x)),
|
|
minf(650.0, maxf(420.0, available.y)))
|
|
if panel.custom_minimum_size != target_size:
|
|
panel.custom_minimum_size = target_size
|