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 _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( 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() 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 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