start command line setup
This commit is contained in:
176
ui/Main.gd
Normal file
176
ui/Main.gd
Normal file
@ -0,0 +1,176 @@
|
||||
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 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 audio_stream_player: AudioStreamPlayer = %AudioStreamPlayer
|
||||
@onready var open_data_dir_button: Button = %OpenDataDirButton
|
||||
|
||||
|
||||
var timesheet: TimeSheet
|
||||
var config: ConfigManager = preload("res://config_manager.tres")
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
|
||||
if config.theme_path:
|
||||
var new_theme: Theme = ResourceLoader.load(config.theme_path, "Theme")
|
||||
if new_theme != null:
|
||||
theme = new_theme
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
|
||||
get_tree().set_auto_accept_quit(false)
|
||||
var _root := time_entries_items_tree.create_item()
|
||||
|
||||
file_path_button.pressed.connect(
|
||||
file_path_file_dialog.popup_centered
|
||||
)
|
||||
|
||||
file_path_file_dialog.file_selected.connect(set_current_file)
|
||||
file_path_line_edit.text_submitted.connect(set_current_file)
|
||||
|
||||
theme_path_button.pressed.connect(
|
||||
theme_path_file_dialog.popup_centered
|
||||
)
|
||||
theme_path_file_dialog.file_selected.connect(
|
||||
func theme_selected(theme_path: String) -> void:
|
||||
var new_theme: Theme = ResourceLoader.load(theme_path, "Theme")
|
||||
if new_theme != null:
|
||||
theme = new_theme
|
||||
config.theme_path = theme_path
|
||||
)
|
||||
|
||||
theme_path_file_dialog.hide()
|
||||
file_path_file_dialog.hide()
|
||||
previous_tasks_window.hide()
|
||||
settings_window.hide()
|
||||
|
||||
timer.timeout.connect(
|
||||
func on_timer_timeout() -> void:
|
||||
timesheet.update()
|
||||
|
||||
time_label.text = timesheet.get_period()
|
||||
|
||||
var total_elapsed: int = 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 sound_check_box.button_pressed:
|
||||
audio_stream_player.play()
|
||||
if is_on:
|
||||
timesheet.start_entry(task_name_line_edit.text)
|
||||
set_button_as_started()
|
||||
else:
|
||||
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()
|
||||
)
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
open_data_dir_button.pressed.connect(
|
||||
OS.shell_open.bind(OS.get_user_data_dir())
|
||||
)
|
||||
|
||||
attributions_rich_text_label.meta_clicked.connect(OS.shell_open)
|
||||
|
||||
set_current_file(config.current_file)
|
||||
|
||||
|
||||
func set_button_as_started() -> void:
|
||||
time_entries_items_tree.set_current_item(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()
|
||||
|
||||
|
||||
## Changes the data file path, and loads the new path
|
||||
func set_current_file(new_current_file: String) -> void:
|
||||
timesheet = TimeSheet.restore(new_current_file)
|
||||
if timesheet == null:
|
||||
return
|
||||
config.current_file = new_current_file
|
||||
|
||||
for entry_name in timesheet.entries_names:
|
||||
time_entries_items_tree.append_name_to_tree(entry_name, timesheet.entries_names[entry_name])
|
||||
|
||||
if timesheet.current_entry != null and timesheet.current_entry.closed == false:
|
||||
start_button.set_pressed_no_signal(true)
|
||||
set_button_as_started()
|
||||
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 _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)
|
238
ui/Main.tscn
Normal file
238
ui/Main.tscn
Normal file
@ -0,0 +1,238 @@
|
||||
[gd_scene load_steps=7 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="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="FilePathFileDialog" type="FileDialog" parent="Main"]
|
||||
unique_name_in_owner = true
|
||||
title = "Pick Tracker File"
|
||||
size = Vector2i(800, 600)
|
||||
ok_button_text = "Save"
|
||||
access = 2
|
||||
filters = PackedStringArray("*.csv ; Comma Separated Files")
|
||||
|
||||
[node name="ThemePathFileDialog" type="FileDialog" parent="Main"]
|
||||
unique_name_in_owner = true
|
||||
title = "Open a File"
|
||||
size = Vector2i(800, 600)
|
||||
ok_button_text = "Open"
|
||||
file_mode = 0
|
||||
access = 2
|
||||
filters = PackedStringArray("*.theme ; Theme Files")
|
||||
|
||||
[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="PanelContainer" type="PanelContainer" parent="Main/SettingsWindow"]
|
||||
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/SettingsWindow/PanelContainer"]
|
||||
layout_mode = 2
|
||||
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="Main/SettingsWindow/PanelContainer/MarginContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
theme_override_constants/separation = 10
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="Main/SettingsWindow/PanelContainer/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="Main/SettingsWindow/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "File Path"
|
||||
|
||||
[node name="FilePathLineEdit" type="LineEdit" parent="Main/SettingsWindow/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
caret_blink = true
|
||||
caret_blink_interval = 0.5
|
||||
|
||||
[node name="FilePathButton" type="Button" parent="Main/SettingsWindow/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "..."
|
||||
|
||||
[node name="HBoxContainer2" type="HBoxContainer" parent="Main/SettingsWindow/PanelContainer/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="Main/SettingsWindow/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer2"]
|
||||
layout_mode = 2
|
||||
text = "Alternative theme
|
||||
"
|
||||
|
||||
[node name="ThemePathButton" type="Button" parent="Main/SettingsWindow/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer2"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "load"
|
||||
|
||||
[node name="HBoxContainer3" type="HBoxContainer" parent="Main/SettingsWindow/PanelContainer/MarginContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="SoundCheckBox" type="CheckBox" parent="Main/SettingsWindow/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer3"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
button_pressed = true
|
||||
text = "Sounds"
|
||||
|
||||
[node name="OpenDataDirButton" type="Button" parent="Main/SettingsWindow/PanelContainer/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "open data dir"
|
||||
|
||||
[node name="AttributionsRichTextLabel" type="RichTextLabel" parent="Main/SettingsWindow/PanelContainer/MarginContainer/VBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
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
|
||||
|
||||
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.
|
||||
"
|
||||
|
||||
[node name="AudioStreamPlayer" type="AudioStreamPlayer" parent="."]
|
||||
unique_name_in_owner = true
|
||||
stream = ExtResource("4_6ajaq")
|
Reference in New Issue
Block a user