164 lines
5.2 KiB
GDScript
164 lines
5.2 KiB
GDScript
extends MarginContainer
|
|
|
|
export(bool) var is_movable = true
|
|
export(bool) var is_resizable = true
|
|
export(bool) var is_borderless = false
|
|
|
|
signal window_clicked( window )
|
|
|
|
var current_rect_size = Vector2( 0, 0 )
|
|
var current_rect_position = Vector2( -1, -1 )
|
|
var is_resizing = false
|
|
var is_moving = false
|
|
|
|
|
|
|
|
func add_child(node):
|
|
$VBoxContainer/Content/scroll_container/v_box_container.add_child(node)
|
|
prints(self.get_name()+" just fathered", node.get_name())
|
|
|
|
|
|
func set_mouse_pass_to_children( node ):
|
|
for child in node.get_children():
|
|
set_mouse_pass_to_children( child )
|
|
if node is Control:
|
|
node.mouse_filter = MOUSE_FILTER_PASS
|
|
|
|
func _ready():
|
|
current_rect_size = self.rect_min_size
|
|
|
|
if is_borderless:
|
|
$Background.region_rect = Rect2( 3, 28+3, 512-6, 512-28-6 )
|
|
$VBoxContainer/Header/HBoxContainer/Close.visible = false
|
|
$VBoxContainer/Header/HBoxContainer/Open.visible = false
|
|
$VBoxContainer/Header/HBoxContainer/Quit.visible = false
|
|
$VBoxContainer/Header/HBoxContainer/Label.visible = false
|
|
# else:
|
|
# $Background.region_rect = Rect2( 0, 0, 512, 512 )
|
|
# $VBoxContainer/Header/HBoxContainer/Close.visible = true
|
|
# $VBoxContainer/Header/HBoxContainer/Open.visible = false
|
|
# $VBoxContainer/Header/HBoxContainer/Quit.visible = true
|
|
# $VBoxContainer/Header/HBoxContainer/Label.visible = true
|
|
if not is_resizable:
|
|
$VBoxContainer/Footer/HBoxContainer/Resize.visible = false
|
|
|
|
set_mouse_pass_to_children( self )
|
|
|
|
|
|
func _on_Window_mouse_entered():
|
|
print("mouse_entered")
|
|
|
|
|
|
func _on_Window_focus_entered():
|
|
print("focus_entered")
|
|
|
|
|
|
func _on_Quit_pressed():
|
|
self.visible = false
|
|
|
|
func get_content():
|
|
return $VBoxContainer/Content
|
|
|
|
|
|
|
|
func close():
|
|
if not is_borderless:
|
|
$VBoxContainer/Header/HBoxContainer/Close.visible = false
|
|
$VBoxContainer/Header/HBoxContainer/Open.visible = true
|
|
$VBoxContainer/Content.visible = false
|
|
$VBoxContainer/Footer.visible = false
|
|
current_rect_size = self.rect_size
|
|
self.rect_size = Vector2( 0, 0 )
|
|
else:
|
|
$VBoxContainer/Header/HBoxContainer/Close.visible = false
|
|
$VBoxContainer/Header/HBoxContainer/Open.visible = false
|
|
$VBoxContainer/Content.visible = false
|
|
$VBoxContainer/Footer.visible = false
|
|
current_rect_size = self.rect_size
|
|
self.rect_size = Vector2( 0, 0 )
|
|
|
|
|
|
func _on_Close_pressed():
|
|
close()
|
|
|
|
func open():
|
|
if not is_borderless:
|
|
$VBoxContainer/Header/HBoxContainer/Close.visible = true
|
|
$VBoxContainer/Header/HBoxContainer/Open.visible = false
|
|
$VBoxContainer/Content.visible = true
|
|
$VBoxContainer/Footer.visible = true
|
|
self.rect_size = current_rect_size
|
|
else:
|
|
$VBoxContainer/Header/HBoxContainer/Close.visible = false
|
|
$VBoxContainer/Header/HBoxContainer/Open.visible = false
|
|
$VBoxContainer/Content.visible = true
|
|
$VBoxContainer/Footer.visible = true
|
|
self.rect_size = current_rect_size
|
|
|
|
func _on_Open_pressed():
|
|
open()
|
|
|
|
func _on_Resize_pressed():
|
|
is_resizing = true
|
|
|
|
func _input( event ):
|
|
if is_resizable:
|
|
if is_resizing and event is InputEventMouseButton and not event.pressed:
|
|
is_resizing = false
|
|
if event is InputEventMouseMotion and is_resizing:
|
|
var delta = event.relative
|
|
self.rect_size += delta
|
|
|
|
|
|
func check_if_clicked( event ):
|
|
if not is_moving and event is InputEventMouseButton and event.is_pressed() and not event.is_echo() and event.button_index == 1 :
|
|
emit_signal( "window_clicked", self )
|
|
|
|
func _on_Header_gui_input( event ):
|
|
|
|
check_if_clicked( event )
|
|
|
|
if is_movable:
|
|
if is_moving and event is InputEventMouseButton and not event.pressed:
|
|
is_moving = false
|
|
elif not is_moving and event is InputEventMouseButton and event.pressed:
|
|
is_moving = true
|
|
if event is InputEventMouseMotion and is_moving:
|
|
var delta = event.relative
|
|
self.rect_position += delta
|
|
|
|
|
|
|
|
func load_from_file( config_file ):
|
|
if config_file.has_section( self.name ):
|
|
self.rect_position = config_file.get_value( self.name, "position" )
|
|
self.rect_size = config_file.get_value( self.name, "size" )
|
|
self.is_borderless = config_file.get_value( self.name, "borderless" )
|
|
current_rect_position = self.rect_position
|
|
current_rect_size = self.rect_size
|
|
if config_file.get_value( self.name, "opened" ):
|
|
open()
|
|
else:
|
|
close()
|
|
|
|
|
|
func save_to_file( config_file ):
|
|
|
|
var is_open = $VBoxContainer/Content.visible
|
|
|
|
config_file.set_value(self.name, "position", self.rect_position)
|
|
|
|
if not is_open:
|
|
config_file.set_value(self.name, "size", current_rect_size)
|
|
else:
|
|
config_file.set_value(self.name, "size", self.rect_size)
|
|
|
|
if is_open:
|
|
config_file.set_value(self.name, "opened", true)
|
|
else:
|
|
config_file.set_value(self.name, "opened", false)
|
|
|
|
config_file.set_value(self.name, "borderless", is_borderless)
|
|
|
|
func _on_window_gui_input( event ):
|
|
check_if_clicked( event )
|