convert to Godot 3.5

This commit is contained in:
2023-03-10 00:26:57 +04:00
parent bf3a9a35ce
commit 66b25bae97
36 changed files with 733 additions and 1468 deletions

View File

@ -1,118 +0,0 @@
extends Control
@onready var time_label: Label = %TimeLabel
@onready var start_button: Button = %StartButton
@onready var task_name_line_edit: LineEdit = %TaskNameLineEdit
@onready var time_entries_items_tree: TimeEntriesItemsTree = %TimeEntriesItemsTree
@onready var timer: Timer = %Timer
@onready var tasks_button: Button = %TasksButton
@onready var settings_button: Button = %SettingsButton
@onready var previous_tasks_window: Window = %PreviousTasksWindow
@onready var settings_window: Window = %SettingsWindow
@onready var audio_stream_player: AudioStreamPlayer = %AudioStreamPlayer
var config: ConfigManager = preload("res://config_manager.tres")
func _ready() -> void:
config.file_changed.connect(set_initial_state)
config.theme_changed.connect(
func theme_changed() -> void:
theme = config.them
)
get_tree().set_auto_accept_quit(false)
previous_tasks_window.hide()
settings_window.hide()
timer.timeout.connect(
func on_timer_timeout() -> void:
config.timesheet.update()
time_label.text = config.timesheet.get_period()
var total_elapsed: int = config.timesheet.get_total_elapsed_seconds()
time_entries_items_tree.set_time_elapsed(total_elapsed)
)
start_button.tooltip_text = tr(Consts.START)
start_button.toggle_mode = true
start_button.toggled.connect(
func start(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)
set_button_as_started()
else:
config.timesheet.close_entry()
set_button_as_stopped()
)
task_name_line_edit.text = config.last_task_name
task_name_line_edit.text_changed.connect(
func(new_text: String) -> void:
config.last_task_name = new_text
)
time_entries_items_tree.item_selected.connect(
func item_selected() -> void:
task_name_line_edit.text = time_entries_items_tree.get_current_text()
)
tasks_button.toggle_mode = true
tasks_button.toggled.connect(
func tasks_toggled(is_on: bool) -> void:
previous_tasks_window.visible = is_on
)
previous_tasks_window.close_requested.connect(
func close() -> void:
tasks_button.set_pressed_no_signal(false)
previous_tasks_window.hide()
)
settings_button.toggle_mode = true
settings_button.toggled.connect(
func settings_toggled(is_on: bool) -> void:
settings_window.visible = is_on
)
settings_window.close_requested.connect(
func close() -> void:
settings_button.set_pressed_no_signal(false)
settings_window.hide()
)
func set_button_as_started() -> void:
time_entries_items_tree.set_current_item(config.timesheet.current_entry.name)
start_button.tooltip_text = tr(Consts.STOP)
start_button.theme_type_variation = Consts.THEME_OVERRIDE_STOP
timer.start()
func set_button_as_stopped() -> void:
start_button.tooltip_text = tr(Consts.START)
time_label.text = Consts.NO_TIME
start_button.theme_type_variation = Consts.THEME_OVERRIDE_START
timer.stop()
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()
func _notification(what: int) -> void:
if what == NOTIFICATION_WM_CLOSE_REQUEST:
get_tree().quit()
## Unused; if a manual quit button is added, this would be used
func quit() -> void:
get_tree().notification(NOTIFICATION_WM_CLOSE_REQUEST)

View File

@ -1,132 +0,0 @@
[gd_scene load_steps=8 format=3 uid="uid://bmlciwscreowf"]
[ext_resource type="Theme" uid="uid://bd8ancgbfsvmd" path="res://assets/default_theme.theme" id="1_2s8h2"]
[ext_resource type="Script" path="res://ui/Main.gd" id="2_sl5q6"]
[ext_resource type="Script" path="res://ui/time_entries_items_tree.gd" id="3_oxqux"]
[ext_resource type="PackedScene" uid="uid://b07v41toqw355" path="res://ui/settings.tscn" id="4_4fa2j"]
[ext_resource type="AudioStream" uid="uid://cdsbhoidgyx70" path="res://assets/pop.ogg" id="4_6ajaq"]
[sub_resource type="InputEventKey" id="InputEventKey_guuii"]
device = -1
pressed = true
keycode = 32
unicode = 32
[sub_resource type="Shortcut" id="Shortcut_irhvi"]
events = [SubResource("InputEventKey_guuii")]
[node name="PanelContainer" type="PanelContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("1_2s8h2")
theme_type_variation = &"background"
[node name="Main" type="MarginContainer" parent="."]
layout_mode = 2
theme_override_constants/margin_left = 5
theme_override_constants/margin_top = 5
theme_override_constants/margin_right = 5
theme_override_constants/margin_bottom = 5
script = ExtResource("2_sl5q6")
[node name="VBoxContainer" type="VBoxContainer" parent="Main"]
layout_mode = 2
size_flags_horizontal = 3
[node name="HBoxContainer2" type="HBoxContainer" parent="Main/VBoxContainer"]
layout_mode = 2
[node name="SettingsButton" type="Button" parent="Main/VBoxContainer/HBoxContainer2"]
unique_name_in_owner = true
layout_mode = 2
tooltip_text = "Settings"
theme_type_variation = &"settings_button"
icon_alignment = 1
[node name="TaskNameLineEdit" type="LineEdit" parent="Main/VBoxContainer/HBoxContainer2"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
placeholder_text = "Task Name. Use \"/\" to create subtasks"
caret_blink = true
caret_blink_interval = 0.5
[node name="TasksButton" type="Button" parent="Main/VBoxContainer/HBoxContainer2"]
unique_name_in_owner = true
layout_mode = 2
tooltip_text = "Tasks"
theme_type_variation = &"tasks_button"
icon_alignment = 1
[node name="HBoxContainer" type="HBoxContainer" parent="Main/VBoxContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="TimeLabel" type="Label" parent="Main/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 1
theme_type_variation = &"time_label"
text = "00:00:00"
horizontal_alignment = 1
vertical_alignment = 1
[node name="StartButton" type="Button" parent="Main/VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_type_variation = &"play_button"
shortcut = SubResource("Shortcut_irhvi")
[node name="Timer" type="Timer" parent="Main"]
unique_name_in_owner = true
[node name="PreviousTasksWindow" type="Window" parent="Main"]
unique_name_in_owner = true
title = "Tasks"
size = Vector2i(300, 300)
visible = false
always_on_top = true
[node name="PanelContainer" type="PanelContainer" parent="Main/PreviousTasksWindow"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_type_variation = &"background"
[node name="MarginContainer" type="MarginContainer" parent="Main/PreviousTasksWindow/PanelContainer"]
layout_mode = 2
size_flags_vertical = 3
theme_override_constants/margin_left = 20
theme_override_constants/margin_top = 20
theme_override_constants/margin_right = 20
theme_override_constants/margin_bottom = 20
[node name="TimeEntriesItemsTree" type="Tree" parent="Main/PreviousTasksWindow/PanelContainer/MarginContainer"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
columns = 2
script = ExtResource("3_oxqux")
[node name="SettingsWindow" type="Window" parent="Main"]
unique_name_in_owner = true
title = "Settings"
size = Vector2i(300, 300)
visible = false
always_on_top = true
[node name="Settings" parent="Main/SettingsWindow" instance=ExtResource("4_4fa2j")]
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
unique_name_in_owner = true
stream = ExtResource("4_6ajaq")

45
ui/main.tscn Normal file
View File

@ -0,0 +1,45 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://ui/time_counter.tscn" type="PackedScene" id=1]
[ext_resource path="res://ui/tasks_list.tscn" type="PackedScene" id=2]
[ext_resource path="res://ui/settings.tscn" type="PackedScene" id=3]
[node name="VBoxContainer" type="VBoxContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
[node name="TimeCounter" parent="." instance=ExtResource( 1 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 360.0
margin_bottom = 48.0
[node name="TabContainer" type="TabContainer" parent="."]
margin_top = 52.0
margin_right = 360.0
margin_bottom = 760.0
size_flags_vertical = 3
[node name="TasksList" parent="TabContainer" instance=ExtResource( 2 )]
margin_left = 4.0
margin_top = 32.0
margin_right = -4.0
margin_bottom = -4.0
size_flags_horizontal = 3
[node name="Settings" type="ScrollContainer" parent="TabContainer"]
visible = false
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 4.0
margin_top = 32.0
margin_right = -4.0
margin_bottom = -4.0
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="Settings" parent="TabContainer/Settings" instance=ExtResource( 3 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 352.0
margin_bottom = 672.0

View File

@ -1,59 +1,89 @@
extends PanelContainer
var config: ConfigManager = preload("res://config_manager.tres")
@onready var file_path_file_dialog: FileDialog = %FilePathFileDialog
@onready var file_path_line_edit: LineEdit = %FilePathLineEdit
@onready var file_path_button: Button = %FilePathButton
@onready var theme_path_file_dialog: FileDialog = %ThemePathFileDialog
@onready var theme_path_button: Button = %ThemePathButton
@onready var sound_check_box: CheckBox = %SoundCheckBox
@onready var attributions_rich_text_label: RichTextLabel = %AttributionsRichTextLabel
@onready var open_data_dir_button: Button = %OpenDataDirButton
onready var file_path_line_edit := $"%FilePathLineEdit" as LineEdit
onready var file_path_button := $"%FilePathButton" as Button
onready var theme_path_button := $"%ThemePathButton" as Button
onready var sound_check_box := $"%SoundCheckBox" as CheckBox
onready var open_data_dir_button := $"%OpenDataDirButton" as Button
onready var attributions_rich_text_label := $"%AttributionsRichTextLabel" as RichTextLabel
onready var file_path_file_dialog := $"%FilePathFileDialog" as FileDialog
onready var theme_path_file_dialog := $"%ThemePathFileDialog" as FileDialog
func _ready() -> void:
config.theme_changed.connect(
func set_current_theme() -> void:
theme = config.theme
)
# warning-ignore:return_value_discarded
config.connect("theme_changed", self, "_on_theme_changed")
config.file_changed.connect(
func set_current_file() -> void:
file_path_file_dialog.current_path = config.current_file
file_path_file_dialog.current_dir = config.current_file.get_base_dir()
file_path_line_edit.text = config.current_file
)
# warning-ignore:return_value_discarded
config.connect("file_changed", self, "_on_current_file_changed")
file_path_button.pressed.connect(
file_path_file_dialog.popup_centered
)
# warning-ignore:return_value_discarded
file_path_button.connect("pressed", self, "_on_file_path_button_pressed")
file_path_file_dialog.file_selected.connect(config.set_current_file)
file_path_line_edit.text_submitted.connect(config.set_current_file)
# warning-ignore:return_value_discarded
file_path_file_dialog.connect("file_selected", self, "_on_current_file_selected")
# warning-ignore:return_value_discarded
file_path_line_edit.connect("text_submitted", self, "_on_current_file_selected")
theme_path_button.pressed.connect(
theme_path_file_dialog.popup_centered
)
theme_path_file_dialog.file_selected.connect(config.set_theme_path)
theme_path_button.connected("pressed", self, "_on_theme_path_button_pressed")
theme_path_file_dialog.connected("file_selected", self, "_on_new_theme_selected")
theme_path_file_dialog.hide()
file_path_file_dialog.hide()
sound_check_box.button_pressed = config.sound_fx_on
sound_check_box.toggled.connect(
func sound_toggle(is_on: bool) -> void:
config.sound_fx_on = is_on
)
attributions_rich_text_label.meta_clicked.connect(OS.shell_open)
sound_check_box.pressed = config.sound_fx_on
open_data_dir_button.pressed.connect(
OS.shell_open.bind(OS.get_user_data_dir())
)
# warning-ignore:return_value_discarded
sound_check_box.connect("toggled", self, "_on_sound_toggle")
# warning-ignore:return_value_discarded
attributions_rich_text_label.connect("meta_clicked", self, "_on_attributions_rich_text_label_meta_clicked")
# warning-ignore:return_value_discarded
open_data_dir_button.connect("pressed", self, "_on_open_data_dir_button_pressed")
func _on_current_file_changed() -> void:
file_path_file_dialog.current_path = config.current_file
file_path_file_dialog.current_dir = config.current_file.get_base_dir()
file_path_line_edit.text = config.current_file
func _on_theme_changed() -> void:
theme = config.theme
func _on_file_path_button_pressed() -> void:
file_path_file_dialog.popup_centered()
func _on_current_file_selected(new_file: String) -> void:
config.set_current_file = new_file
func _on_sound_toggle(is_on: bool) -> void:
config.sound_fx_on = is_on
func _on_theme_path_button_pressed() -> void:
theme_path_file_dialog.popup_centered()
func _on_new_theme_selected(new_theme_path: String) -> void:
config.set_theme_path = new_theme_path
func _on_attributions_rich_text_label_meta_clicked(meta) -> void:
if meta is String:
# warning-ignore:return_value_discarded
OS.shell_open(meta)
func _on_open_data_dir_button_pressed() -> void:
# warning-ignore:return_value_discarded
OS.shell_open(OS.get_user_data_dir())

View File

@ -1,89 +1,110 @@
[gd_scene load_steps=2 format=3 uid="uid://b07v41toqw355"]
[gd_scene load_steps=2 format=2]
[ext_resource type="Script" path="res://ui/settings.gd" id="1_cmilf"]
[ext_resource path="res://ui/settings.gd" type="Script" id=1]
[node name="Settings" type="PanelContainer"]
anchors_preset = 15
[node name="Settings" type="MarginContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_type_variation = &"background"
script = ExtResource("1_cmilf")
script = ExtResource( 1 )
[node name="MarginContainer" type="MarginContainer" parent="."]
layout_mode = 2
[node name="VBoxContainer" type="VBoxContainer" parent="."]
margin_right = 360.0
margin_bottom = 760.0
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_constants/margin_left = 20
theme_override_constants/margin_top = 20
theme_override_constants/margin_right = 20
theme_override_constants/margin_bottom = 20
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
layout_mode = 2
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_right = 360.0
margin_bottom = 24.0
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_constants/separation = 10
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"]
margin_top = 5.0
margin_right = 55.0
margin_bottom = 19.0
text = "File Path"
[node name="FilePathLineEdit" type="LineEdit" parent="MarginContainer/VBoxContainer/HBoxContainer"]
[node name="FilePathLineEdit" type="LineEdit" parent="VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
margin_left = 59.0
margin_right = 332.0
margin_bottom = 24.0
size_flags_horizontal = 3
caret_blink = true
caret_blink_interval = 0.5
caret_blink_speed = 0.5
[node name="FilePathButton" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer"]
[node name="FilePathButton" type="Button" parent="VBoxContainer/HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
margin_left = 336.0
margin_right = 360.0
margin_bottom = 24.0
text = "..."
[node name="HBoxContainer2" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
[node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 28.0
margin_right = 360.0
margin_bottom = 48.0
size_flags_horizontal = 3
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer2"]
layout_mode = 2
text = "Alternative theme
"
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer2"]
margin_top = 3.0
margin_right = 118.0
margin_bottom = 17.0
text = "Alternative Theme"
[node name="ThemePathButton" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer2"]
[node name="ThemePathButton" type="Button" parent="VBoxContainer/HBoxContainer2"]
unique_name_in_owner = true
layout_mode = 2
margin_left = 122.0
margin_right = 161.0
margin_bottom = 20.0
text = "load"
[node name="HBoxContainer3" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2
[node name="HBoxContainer3" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 52.0
margin_right = 360.0
margin_bottom = 76.0
size_flags_horizontal = 3
[node name="SoundCheckBox" type="CheckBox" parent="MarginContainer/VBoxContainer/HBoxContainer3"]
[node name="SoundCheckBox" type="CheckBox" parent="VBoxContainer/HBoxContainer3"]
unique_name_in_owner = true
layout_mode = 2
button_pressed = true
text = "Sounds"
margin_right = 74.0
margin_bottom = 24.0
text = "sounds"
[node name="OpenDataDirButton" type="Button" parent="MarginContainer/VBoxContainer"]
[node name="OpenDataDirButton" type="Button" parent="VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
text = "open data dir"
margin_top = 80.0
margin_right = 360.0
margin_bottom = 100.0
text = "Open data dir"
[node name="AttributionsRichTextLabel" type="RichTextLabel" parent="MarginContainer/VBoxContainer"]
[node name="AttributionsRichTextLabel" type="RichTextLabel" parent="VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
margin_top = 104.0
margin_right = 360.0
margin_bottom = 760.0
size_flags_vertical = 3
theme_type_variation = &"small_text"
bbcode_enabled = true
text = "Font: Cairo, Designed by Mohamed Gaber, Accademia di Belle Arti di Urbino
bbcode_text = "Font: Cairo, Designed by Mohamed Gaber, Accademia di Belle Arti di Urbino
Sound: [url]https://opengameart.org/content/bubbles-pop[/url]
This game uses Godot Engine, available under the following license:
Copyright (c) 2014-present Godot Engine contributors. Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"
text = "Font: Cairo, Designed by Mohamed Gaber, Accademia di Belle Arti di Urbino
Sound: https://opengameart.org/content/bubbles-pop
This game uses Godot Engine, available under the following license:
Copyright (c) 2014-present Godot Engine contributors. Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.
@ -97,17 +118,17 @@ This game uses Godot Engine, available under the following license:
[node name="FilePathFileDialog" type="FileDialog" parent="."]
unique_name_in_owner = true
title = "Pick Tracker File"
size = Vector2i(800, 600)
ok_button_text = "Save"
margin_right = 442.0
margin_bottom = 760.0
window_title = "Pick a file"
access = 2
filters = PackedStringArray("*.csv ; Comma Separated Files")
filters = PoolStringArray( "*.csv ; Comma Separated Files" )
[node name="ThemePathFileDialog" type="FileDialog" parent="."]
unique_name_in_owner = true
title = "Open a File"
size = Vector2i(800, 600)
ok_button_text = "Open"
file_mode = 0
margin_right = 360.0
margin_bottom = 760.0
window_title = "Open a File"
mode = 0
access = 2
filters = PackedStringArray("*.theme ; Theme Files")
filters = PoolStringArray( "*.theme ; Theme Files" )

View File

@ -10,7 +10,8 @@ var config: ConfigManager = preload("res://config_manager.tres")
var current_item: TreeItem
func _ready() -> void:
config.file_changed.connect(populate_entries)
# warning-ignore:return_value_discarded
config.connect("file_changed", self, "populate_entries")
populate_entries()
@ -19,6 +20,7 @@ func populate_entries() -> void:
var _root := create_item()
var entries_names := config.timesheet.entries_names
for entry_name in entries_names:
# warning-ignore:return_value_discarded
append_name_to_tree(entry_name, entries_names[entry_name])
@ -56,13 +58,27 @@ func append_name_to_tree(task_name: String, total_elapsed := 0) -> TreeItem:
return item
## Unecessary in Godot 4, can bre replaced with get_children()
static func _get_tree_item_children(item: TreeItem):
var children = []
var child = item.get_children()
if child == null:
return children
children.append(child)
child = child.get_next()
while child != null:
children.append(child)
child = child.get_next()
return children
## Finds an item in the tree by text
func find_item(root: TreeItem, item_name: String, or_create: bool) -> TreeItem:
for child in root.get_children():
for child in _get_tree_item_children(root):
if child.get_text(COL.TEXT) == item_name:
return child
if or_create:
var child := root.create_child()
var child := create_item(root)
child.set_text(COL.TEXT, item_name)
child.set_text(COL.TIME, Consts.NO_TIME)
return child

9
ui/tasks_list.tscn Normal file
View File

@ -0,0 +1,9 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://ui/tasks_list.gd" type="Script" id=1]
[node name="TasksList" type="Tree"]
anchor_right = 1.0
anchor_bottom = 1.0
columns = 2
script = ExtResource( 1 )

78
ui/time_counter.gd Normal file
View File

@ -0,0 +1,78 @@
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.tooltip_text = 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.tooltip_text = 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.tooltip_text = 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()

39
ui/time_counter.tscn Normal file
View File

@ -0,0 +1,39 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://ui/time_counter.gd" type="Script" id=1]
[node name="TimeCounter" type="VBoxContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
[node name="TaskNameLineEdit" type="LineEdit" parent="."]
unique_name_in_owner = true
margin_right = 360.0
margin_bottom = 24.0
[node name="HBoxContainer" type="HBoxContainer" parent="."]
margin_top = 28.0
margin_right = 360.0
margin_bottom = 760.0
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="TimeLabel" type="Label" parent="HBoxContainer"]
unique_name_in_owner = true
margin_top = 359.0
margin_right = 344.0
margin_bottom = 373.0
size_flags_horizontal = 3
[node name="StartButton" type="Button" parent="HBoxContainer"]
unique_name_in_owner = true
margin_left = 348.0
margin_right = 360.0
margin_bottom = 732.0
[node name="Timer" type="Timer" parent="."]
unique_name_in_owner = true
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
unique_name_in_owner = true