From: Eduardo Date: Thu, 28 Sep 2023 16:22:51 +0000 (+0200) Subject: added project time tracker plugin X-Git-Url: http://git.edufdez.es/?a=commitdiff_plain;h=cb50f84b21f1540044c44dbac7c38555ac408416;p=The%20Cutests%20To-Do%20List.git added project time tracker plugin --- diff --git a/addons/project_time_tracker/icon.png b/addons/project_time_tracker/icon.png new file mode 100644 index 0000000..ff4b75c Binary files /dev/null and b/addons/project_time_tracker/icon.png differ diff --git a/addons/project_time_tracker/icon.png.import b/addons/project_time_tracker/icon.png.import new file mode 100644 index 0000000..33c737c --- /dev/null +++ b/addons/project_time_tracker/icon.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bcbfcmhwy2rkl" +path="res://.godot/imported/icon.png-fc3fbdc4c342e4465b7ecfb6bc59cf69.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/project_time_tracker/icon.png" +dest_files=["res://.godot/imported/icon.png-fc3fbdc4c342e4465b7ecfb6bc59cf69.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/addons/project_time_tracker/plugin.cfg b/addons/project_time_tracker/plugin.cfg new file mode 100644 index 0000000..9728cae --- /dev/null +++ b/addons/project_time_tracker/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="Project Timer" +description="Tracks how long you've spent in this project." +author="Ccencceth" +version="0.1" +script="plugin.gd" diff --git a/addons/project_time_tracker/plugin.gd b/addons/project_time_tracker/plugin.gd new file mode 100644 index 0000000..6dca2ef --- /dev/null +++ b/addons/project_time_tracker/plugin.gd @@ -0,0 +1,15 @@ +@tool +extends EditorPlugin + + +var dock + + +func _enter_tree() -> void: + dock = preload("res://addons/project_time_tracker/project_timer.tscn").instantiate() + add_control_to_dock(DOCK_SLOT_RIGHT_BL, dock) + + +func _exit_tree() -> void: + remove_control_from_docks(dock) + dock.free() diff --git a/addons/project_time_tracker/project_timer.gd b/addons/project_time_tracker/project_timer.gd new file mode 100644 index 0000000..e59906b --- /dev/null +++ b/addons/project_time_tracker/project_timer.gd @@ -0,0 +1,89 @@ +@tool +extends Control + + +var session_time = 0.0 +var total_time = 0.0 +const PATH_TO_SAVE_FILE = "user://time_in_project.save" +@onready var total_time_label : Label = get_node("VBoxContainer/TimeInProject") +@onready var session_time_label : Label = get_node("VBoxContainer/TimeThisSession") +@onready var settings_window : Window = get_node("SettingsWindow") + + +func _enter_tree() -> void: + read_file() + + +func _exit_tree() -> void: + save_file() + + +func _process(delta: float) -> void: + session_time += delta + total_time += delta + + set_time() + + +func set_time() -> void: + total_time_label.text = "Time in project: " + get_time_string_from_unix(total_time) + session_time_label.text = "Time this session: " + get_time_string_from_unix(session_time) + + +func get_time_string_from_unix(unix_time): + var time_string = "" + var unix_time_int = int(unix_time) + + var hours = floor(unix_time_int / 3600) + if hours < 10: + time_string += "0" + time_string += str(hours) + ":" + unix_time_int -= hours * 3600 + + var minutes = floor(unix_time_int / 60) + if minutes < 10: + time_string += "0" + time_string += str(minutes) + ":" + unix_time_int -= minutes * 60 + + var seconds = unix_time_int + if seconds < 10: + time_string += "0" + time_string += str(seconds) + + return time_string + + +func read_file() -> void: + if not FileAccess.file_exists(PATH_TO_SAVE_FILE): + return + + var save = FileAccess.open(PATH_TO_SAVE_FILE, FileAccess.READ) + + var json_string := "" + while save.get_position() < save.get_length(): + json_string += save.get_line() + + var parsed_result = JSON.parse_string(json_string) + + total_time = float(parsed_result['time']) + + + +func save_file() -> void: + var save = FileAccess.open(PATH_TO_SAVE_FILE, FileAccess.WRITE) + save.store_line(JSON.stringify({'time': roundf(total_time)}, "\t")) + + +func _on_settings_button_pressed() -> void: + settings_window.show() + + +func _on_settings_window_close_requested() -> void: + settings_window.hide() + + +func _on_settings_window_set_new_time(hours, minutes, seconds) -> void: + var unix_time = hours * 3600 + minutes * 60 + seconds + total_time = unix_time + print("Set Time in project to: " + get_time_string_from_unix(total_time)) diff --git a/addons/project_time_tracker/project_timer.tscn b/addons/project_time_tracker/project_timer.tscn new file mode 100644 index 0000000..933e8cd --- /dev/null +++ b/addons/project_time_tracker/project_timer.tscn @@ -0,0 +1,90 @@ +[gd_scene load_steps=3 format=3 uid="uid://dsb6vxpbduj7f"] + +[ext_resource type="Script" path="res://addons/project_time_tracker/project_timer.gd" id="1_1r5vr"] +[ext_resource type="Script" path="res://addons/project_time_tracker/settings_window.gd" id="2_p44mt"] + +[node name="Project Timer" type="Control"] +custom_minimum_size = Vector2(200, 91) +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_1r5vr") + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="TimeInProject" type="Label" parent="VBoxContainer"] +layout_mode = 2 +text = "Time in project: 00:00:00" +autowrap_mode = 3 + +[node name="TimeThisSession" type="Label" parent="VBoxContainer"] +layout_mode = 2 +text = "Time this session: 00:00:00" +autowrap_mode = 3 + +[node name="SettingsButton" type="Button" parent="VBoxContainer"] +layout_mode = 2 +text = "Settings" + +[node name="SettingsWindow" type="Window" parent="."] +title = "Timer Settings" +initial_position = 2 +size = Vector2i(195, 100) +visible = false +popup_window = true +script = ExtResource("2_p44mt") + +[node name="Control" type="Control" parent="SettingsWindow"] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="SettingsWindow/Control"] +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 40.0 + +[node name="Label" type="Label" parent="SettingsWindow/Control/VBoxContainer"] +layout_mode = 2 +text = "Manually Set Time To" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="HBoxContainer" type="HBoxContainer" parent="SettingsWindow/Control/VBoxContainer"] +layout_mode = 2 + +[node name="InputHours" type="LineEdit" parent="SettingsWindow/Control/VBoxContainer/HBoxContainer"] +layout_mode = 2 +placeholder_text = "h" + +[node name="InputMinutes" type="LineEdit" parent="SettingsWindow/Control/VBoxContainer/HBoxContainer"] +layout_mode = 2 +placeholder_text = "m" + +[node name="InputSeconds" type="LineEdit" parent="SettingsWindow/Control/VBoxContainer/HBoxContainer"] +layout_mode = 2 +placeholder_text = "s" + +[node name="SetTimeButton" type="Button" parent="SettingsWindow/Control/VBoxContainer"] +layout_mode = 2 +text = "Set" + +[connection signal="pressed" from="VBoxContainer/SettingsButton" to="." method="_on_settings_button_pressed"] +[connection signal="close_requested" from="SettingsWindow" to="." method="_on_settings_window_close_requested"] +[connection signal="set_new_time" from="SettingsWindow" to="." method="_on_settings_window_set_new_time"] +[connection signal="text_changed" from="SettingsWindow/Control/VBoxContainer/HBoxContainer/InputHours" to="SettingsWindow" method="_on_input_hours_text_changed"] +[connection signal="text_changed" from="SettingsWindow/Control/VBoxContainer/HBoxContainer/InputMinutes" to="SettingsWindow" method="_on_input_minutes_text_changed"] +[connection signal="text_changed" from="SettingsWindow/Control/VBoxContainer/HBoxContainer/InputSeconds" to="SettingsWindow" method="_on_input_seconds_text_changed"] +[connection signal="pressed" from="SettingsWindow/Control/VBoxContainer/SetTimeButton" to="SettingsWindow" method="_on_set_time_button_pressed"] diff --git a/addons/project_time_tracker/settings_window.gd b/addons/project_time_tracker/settings_window.gd new file mode 100644 index 0000000..7253648 --- /dev/null +++ b/addons/project_time_tracker/settings_window.gd @@ -0,0 +1,28 @@ +@tool +extends Window + + +signal set_new_time(hours, minutes, seconds) + +@onready var hours_line_edit = $Control/VBoxContainer/HBoxContainer/InputHours +@onready var minutes_line_edit = $Control/VBoxContainer/HBoxContainer/InputMinutes +@onready var seconds_line_edit = $Control/VBoxContainer/HBoxContainer/InputSeconds +var hours = 0.0 +var minutes = 0.0 +var seconds = 0.0 + + +func _on_input_hours_text_changed(new_text: String) -> void: + hours = maxf(float(new_text), 0.0) + + +func _on_input_minutes_text_changed(new_text: String) -> void: + minutes = maxf(float(new_text), 0.0) + + +func _on_input_seconds_text_changed(new_text: String) -> void: + seconds = maxf(float(new_text), 0.0) + + +func _on_set_time_button_pressed() -> void: + emit_signal("set_new_time", hours, minutes, seconds)