save position
This commit is contained in:
		
							
								
								
									
										49
									
								
								ui/main.gd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								ui/main.gd
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,49 @@
 | 
			
		||||
extends VBoxContainer
 | 
			
		||||
 | 
			
		||||
var config: ConfigManager = preload("res://config_manager.tres")
 | 
			
		||||
 | 
			
		||||
onready var v_box_container_primary := $"%VBoxContainerPrimary" as VBoxContainer
 | 
			
		||||
onready var toggle_tab_container_button := $"%ToggleTabContainerButton" as Button
 | 
			
		||||
onready var tab_container := $"%TabContainer" as TabContainer
 | 
			
		||||
 | 
			
		||||
func _ready() -> void:
 | 
			
		||||
	toggle_tab_container_button.toggle_mode = true
 | 
			
		||||
	# warning-ignore:return_value_discarded
 | 
			
		||||
	toggle_tab_container_button.connect("toggled", self, "_on_toggle_tab_container_button_toggled")
 | 
			
		||||
	tab_container.visible = toggle_tab_container_button.pressed
 | 
			
		||||
	OS.window_position = config.last_window_position
 | 
			
		||||
	set_window_size()
 | 
			
		||||
	get_tree().get_root().set_transparent_background(true)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
func _on_toggle_tab_container_button_toggled(is_toggled: bool) -> void:
 | 
			
		||||
	tab_container.visible = is_toggled
 | 
			
		||||
	set_window_size()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
func set_window_size() -> void:
 | 
			
		||||
	OS.window_size = v_box_container_primary.rect_size
 | 
			
		||||
	if tab_container.visible:
 | 
			
		||||
		OS.window_size.y += tab_container.rect_size.y
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
var mouse_button_is_pressed := false
 | 
			
		||||
var dragging_start_position = Vector2()
 | 
			
		||||
 | 
			
		||||
func _gui_input(event: InputEvent) -> void:
 | 
			
		||||
	if event is InputEventMouseButton:
 | 
			
		||||
		if event.get_button_index() == 1:
 | 
			
		||||
			mouse_button_is_pressed = !mouse_button_is_pressed
 | 
			
		||||
			dragging_start_position = get_local_mouse_position()
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
func _process(_delta: float) -> void:
 | 
			
		||||
	if mouse_button_is_pressed:
 | 
			
		||||
		OS.set_window_position(OS.window_position + get_global_mouse_position() - dragging_start_position)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
func _notification(what: int) -> void:
 | 
			
		||||
	match what:
 | 
			
		||||
		MainLoop.NOTIFICATION_WM_QUIT_REQUEST:
 | 
			
		||||
			config.last_window_position = OS.window_position
 | 
			
		||||
			get_tree().quit()
 | 
			
		||||
							
								
								
									
										31
									
								
								ui/main.tscn
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								ui/main.tscn
									
									
									
									
									
								
							@@ -1,22 +1,43 @@
 | 
			
		||||
[gd_scene load_steps=4 format=2]
 | 
			
		||||
[gd_scene load_steps=5 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]
 | 
			
		||||
[ext_resource path="res://ui/main.gd" type="Script" id=4]
 | 
			
		||||
 | 
			
		||||
[node name="VBoxContainer" type="VBoxContainer"]
 | 
			
		||||
[node name="Main" type="VBoxContainer"]
 | 
			
		||||
anchor_right = 1.0
 | 
			
		||||
anchor_bottom = 1.0
 | 
			
		||||
script = ExtResource( 4 )
 | 
			
		||||
 | 
			
		||||
[node name="TimeCounter" parent="." instance=ExtResource( 1 )]
 | 
			
		||||
[node name="VBoxContainerPrimary" type="VBoxContainer" parent="."]
 | 
			
		||||
unique_name_in_owner = true
 | 
			
		||||
margin_right = 360.0
 | 
			
		||||
margin_bottom = 72.0
 | 
			
		||||
 | 
			
		||||
[node name="TimeCounter" parent="VBoxContainerPrimary" 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="."]
 | 
			
		||||
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainerPrimary"]
 | 
			
		||||
margin_top = 52.0
 | 
			
		||||
margin_right = 360.0
 | 
			
		||||
margin_bottom = 72.0
 | 
			
		||||
alignment = 2
 | 
			
		||||
 | 
			
		||||
[node name="ToggleTabContainerButton" type="Button" parent="VBoxContainerPrimary/HBoxContainer"]
 | 
			
		||||
unique_name_in_owner = true
 | 
			
		||||
margin_left = 348.0
 | 
			
		||||
margin_right = 360.0
 | 
			
		||||
margin_bottom = 20.0
 | 
			
		||||
toggle_mode = true
 | 
			
		||||
 | 
			
		||||
[node name="TabContainer" type="TabContainer" parent="."]
 | 
			
		||||
unique_name_in_owner = true
 | 
			
		||||
margin_top = 76.0
 | 
			
		||||
margin_right = 360.0
 | 
			
		||||
margin_bottom = 760.0
 | 
			
		||||
size_flags_vertical = 3
 | 
			
		||||
 | 
			
		||||
@@ -42,4 +63,4 @@ size_flags_vertical = 3
 | 
			
		||||
anchor_right = 0.0
 | 
			
		||||
anchor_bottom = 0.0
 | 
			
		||||
margin_right = 352.0
 | 
			
		||||
margin_bottom = 672.0
 | 
			
		||||
margin_bottom = 648.0
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user