136 lines
No EOL
4.4 KiB
GDScript
136 lines
No EOL
4.4 KiB
GDScript
extends MarginContainer
|
|
|
|
export(bool) var is_movable = true
|
|
export(bool) var is_resizable = true
|
|
export(bool) var is_borderless = false
|
|
|
|
|
|
var current_rect_size = Vector2( 0, 0 )
|
|
var current_rect_position = Vector2( -1, -1 )
|
|
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
|
|
|
|
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 _on_Header_gui_input(ev):
|
|
if is_movable:
|
|
if is_moving and ev is InputEventMouseButton and not ev.pressed:
|
|
is_moving = false
|
|
elif not is_moving and ev is InputEventMouseButton and ev.pressed:
|
|
is_moving = true
|
|
if ev is InputEventMouseMotion and is_moving:
|
|
var delta = ev.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)
|
|
|