2018-07-25 07:36:19 +00:00
|
|
|
extends MarginContainer
|
|
|
|
|
|
|
|
export(bool) var is_movable = true
|
|
|
|
export(bool) var is_resizable = true
|
|
|
|
export(bool) var is_borderless = false
|
|
|
|
|
2018-08-15 11:00:30 +00:00
|
|
|
signal window_clicked( window )
|
2018-07-25 07:36:19 +00:00
|
|
|
|
|
|
|
var current_rect_size = Vector2( 0, 0 )
|
2018-07-30 12:56:17 +00:00
|
|
|
var current_rect_position = Vector2( -1, -1 )
|
2018-07-25 07:36:19 +00:00
|
|
|
var is_resizing = false
|
|
|
|
var is_moving = false
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2018-08-15 11:00:30 +00:00
|
|
|
func _input( event ):
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-25 07:36:19 +00:00
|
|
|
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
|
|
|
|
|
2018-08-15 11:00:30 +00:00
|
|
|
func _on_Header_gui_input( event ):
|
|
|
|
|
|
|
|
if not is_moving and event is InputEventMouseButton and event.is_pressed() and not event.is_echo() and event.button_index == 1 :
|
|
|
|
put_above_other()
|
|
|
|
|
|
|
|
|
2018-07-25 07:36:19 +00:00
|
|
|
if is_movable:
|
2018-08-15 11:00:30 +00:00
|
|
|
if is_moving and event is InputEventMouseButton and not event.pressed:
|
2018-07-25 07:36:19 +00:00
|
|
|
is_moving = false
|
2018-08-15 11:00:30 +00:00
|
|
|
elif not is_moving and event is InputEventMouseButton and event.pressed:
|
2018-07-25 07:36:19 +00:00
|
|
|
is_moving = true
|
2018-08-15 11:00:30 +00:00
|
|
|
if event is InputEventMouseMotion and is_moving:
|
|
|
|
var delta = event.relative
|
2018-07-25 07:36:19 +00:00
|
|
|
self.rect_position += delta
|
|
|
|
|
2018-08-15 11:00:30 +00:00
|
|
|
|
|
|
|
|
2018-07-25 07:36:19 +00:00
|
|
|
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 ):
|
2018-07-30 13:35:00 +00:00
|
|
|
|
|
|
|
var is_open = $VBoxContainer/Content.visible
|
|
|
|
|
2018-07-25 07:36:19 +00:00
|
|
|
config_file.set_value(self.name, "position", self.rect_position)
|
2018-07-30 12:56:17 +00:00
|
|
|
|
2018-07-30 13:35:00 +00:00
|
|
|
if not is_open:
|
2018-07-30 12:56:17 +00:00
|
|
|
config_file.set_value(self.name, "size", current_rect_size)
|
|
|
|
else:
|
|
|
|
config_file.set_value(self.name, "size", self.rect_size)
|
|
|
|
|
2018-07-30 13:35:00 +00:00
|
|
|
if is_open:
|
2018-07-25 07:36:19 +00:00
|
|
|
config_file.set_value(self.name, "opened", true)
|
|
|
|
else:
|
|
|
|
config_file.set_value(self.name, "opened", false)
|
2018-07-30 12:56:17 +00:00
|
|
|
|
2018-07-25 07:36:19 +00:00
|
|
|
config_file.set_value(self.name, "borderless", is_borderless)
|
2018-08-15 11:00:30 +00:00
|
|
|
|
|
|
|
func put_above_other():
|
|
|
|
# var index = 0
|
|
|
|
# for child in get_parent().get_children():
|
|
|
|
# get_parent().move_child(child, index)
|
|
|
|
# index += 1
|
|
|
|
# get_parent().move_child(self, index)
|
|
|
|
|
|
|
|
# var parent = self.get_parent()
|
|
|
|
# var last_child = parent.get_child( parent.get_child_count()-1 )
|
|
|
|
# if not self.is_greater_than( last_child ):
|
|
|
|
# parent.remove_child( self )
|
|
|
|
# parent.add_child_below_node( last_child, self )
|
|
|
|
|
|
|
|
# self.raise()
|
|
|
|
emit_signal( "window_clicked", self )
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|