79 lines
2.6 KiB
GDScript
79 lines
2.6 KiB
GDScript
extends VBoxContainer
|
|
|
|
|
|
var config: ConfigManager = preload("res://config_manager.tres")
|
|
|
|
|
|
onready var task_name_line_edit := $"%TaskNameLineEdit" as LineEdit
|
|
onready var time_label := $"%TimeLabel" as Label
|
|
onready var start_button := $"%StartButton" as Button
|
|
onready var timer := $"%Timer" as Timer
|
|
onready var audio_stream_player := $"%AudioStreamPlayer" as AudioStreamPlayer
|
|
|
|
|
|
func _ready() -> void:
|
|
# warning-ignore:return_value_discarded
|
|
timer.connect("timeout", self, "_on_timer_timeout")
|
|
start_button.hint_tooltip = tr(Consts.START)
|
|
start_button.toggle_mode = true
|
|
# warning-ignore:return_value_discarded
|
|
start_button.connect("toggled", self, "_on_start_button_toggled")
|
|
task_name_line_edit.text = config.last_task_name
|
|
# warning-ignore:return_value_discarded
|
|
task_name_line_edit.connect("text_changed", self, "_on_task_name_line_edit_text_changed")
|
|
# warning-ignore:return_value_discarded
|
|
config.connect("entry_started", self, "set_button_as_started")
|
|
# warning-ignore:return_value_discarded
|
|
config.connect("entry_stopped", self, "set_button_as_stopped")
|
|
# TODO: connect this:
|
|
#time_entries_items_tree.item_selected.connect(
|
|
# func item_selected() -> void:
|
|
# task_name_line_edit.text = time_entries_items_tree.get_current_text()
|
|
#)
|
|
|
|
|
|
func _on_timer_timeout() -> void:
|
|
config.timesheet.update()
|
|
|
|
time_label.text = config.timesheet.get_period()
|
|
|
|
## TODO: change this
|
|
# var total_elapsed: int = config.timesheet.get_total_elapsed_seconds()
|
|
# time_entries_items_tree.set_time_elapsed(total_elapsed)
|
|
|
|
|
|
func _on_start_button_toggled(is_on: bool) -> void:
|
|
if config.sound_fx_on:
|
|
audio_stream_player.play()
|
|
if is_on:
|
|
config.timesheet.start_entry(task_name_line_edit.text)
|
|
else:
|
|
config.timesheet.close_entry()
|
|
|
|
|
|
func _on_task_name_line_edit_text_changed(new_text: String) -> void:
|
|
config.last_task_name = new_text
|
|
|
|
|
|
func set_button_as_stopped() -> void:
|
|
start_button.set_pressed_no_signal(false)
|
|
start_button.hint_tooltip = tr(Consts.START)
|
|
time_label.text = Consts.NO_TIME
|
|
start_button.theme_type_variation = Consts.THEME_OVERRIDE_START
|
|
timer.stop()
|
|
|
|
|
|
func set_button_as_started() -> void:
|
|
## TODO: make this independent
|
|
# time_entries_items_tree.set_current_item(config.timesheet.current_entry.name)
|
|
start_button.set_pressed_no_signal(true)
|
|
start_button.hint_tooltip = tr(Consts.STOP)
|
|
start_button.theme_type_variation = Consts.THEME_OVERRIDE_STOP
|
|
timer.start()
|
|
|
|
|
|
func set_initial_state() -> void:
|
|
if config.timesheet.current_entry != null and config.timesheet.current_entry.closed == false:
|
|
start_button.set_pressed_no_signal(true)
|
|
set_button_as_started()
|