extends Control var pixel_x var pixel_y var ui_scale var minsize var restore_minimize var module var category = "character" var item = "Grondir" var origin = null var distance = null var dragPoint = null var dragPoint_move = null var minimized = false var window_size var window_position var resizer func _enter_tree() -> void: module = load("res://01 - Menus/03 - Sheets/sheet.tscn").instantiate() module.category = category module.item = item %window.position = Vector2(600,400) %category.text = category %item.text = item %window.add_child(module) ui_scale = 1 if get_viewport_rect().size[0] + get_viewport_rect().size[1] < 3000: ui_scale = 0.7 pixel_x = get_viewport_rect().size[0] / ui_scale pixel_y = get_viewport_rect().size[1] / ui_scale module_fit_window() set_bar_items() await get_tree().create_timer(0.0001).timeout %size_right.position.x = %ui_bar.position.x + %ui_bar.size.x - 32 module.redraw() func _process(_delta: float) -> void: if pixel_x != get_viewport_rect().size[0] or pixel_y != get_viewport_rect().size[1]: pixel_x = get_viewport_rect().size[0] pixel_y = get_viewport_rect().size[1] if pixel_x + pixel_y > 3000: ui_scale = 1 else: ui_scale = 0.7 module_fit_window() func module_fit_window(): if get_viewport_rect().size[0] > get_viewport_rect().size[1]: module.get_child(0).size = %ui_background.size - Vector2(64,64) module.get_child(0).position = %ui_background.position + Vector2(32,32) for i in [%size_right,%size_left,%size_bottom]: i.visible = true else: %window.position = Vector2(0,0) %ui_background.size = get_viewport_rect().size / ui_scale module.get_child(0).size = %ui_background.size - Vector2(64,64) module.get_child(0).position = Vector2(32,96) %ui_bar.size.x = %ui_background.size.x %item.position.x = 64 %close.position.x = %ui_bar.size.x - 92 %minimize.position.x = %close.position.x - 92 for i in [%size_right,%size_left,%size_bottom]: i.visible = false move_child(module,1) module.redraw() func _on_ui_bar_gui_input(ev: InputEvent) -> void: if ev is InputEventMouseButton: if ev.button_index == MOUSE_BUTTON_LEFT: if ev.pressed: dragPoint = get_global_mouse_position() - %window.get_position() get_parent().move_child(self,get_parent().get_child_count()) else: dragPoint = null if ev is InputEventMouseMotion and dragPoint != null: %window.position = get_global_mouse_position()/ui_scale - dragPoint/ui_scale func _on_minimize_button_up() -> void: if minimized: for i in [%ui_background,module]: i.visible = true minimized = false %minimize.text = "-" for i in [%size_left,%size_right]: i.size.y = %ui_bar.size.y + %ui_background.size.y %size_bottom.visible = true else: for i in [%ui_background,module]: i.visible = false module.visible = false minimized = true %minimize.text = "+" for i in [%size_left,%size_right]: i.size.y = %ui_bar.size.y %size_bottom.visible = false func _on_close_button_up() -> void: queue_free() func _on_size_gui_input(ev: InputEvent) -> void: match resizer: "right": resizer = %size_right "left": resizer = %size_left "bottom": resizer = %size_bottom if ev is InputEventMouseButton: if ev.button_index == MOUSE_BUTTON_LEFT: if ev.pressed: dragPoint = get_global_mouse_position() * ui_scale origin = resizer.position else: var reset_right = %size_right.position.x - %size_left.position.x - 32 dragPoint = null distance = null origin = null for i in [%size_left,%size_right]: i.size.y = %ui_background.size.y + 32 i.position.y = 0 %size_bottom.size.x = %ui_bar.size.x %size_bottom.position.x = %ui_bar.position.x %window.set_position(%ui_bar.global_position) %size_left.position = Vector2(-32,0) %size_right.position.x = reset_right if ev is InputEventMouseMotion and dragPoint : distance = get_global_mouse_position() - dragPoint * ui_scale resizer.position = origin + distance for i in [%ui_background,%ui_bar]: i.size.x = %size_right.position.x - %size_left.position.x if %ui_background.size.x >= 700: i.position.x = %size_left.position.x + 32 %ui_background.size.y = %size_bottom.position.y - %ui_bar.position.y - 32 set_bar_items() module_fit_window() func set_bar_items(): if %ui_background.size.y < 500: %ui_background.size.y = 500 for i in [%size_left,%size_right]: i.size.y = 500 %size_bottom.position.y = 532 minsize = true else: minsize = false if %ui_bar.size.x < 700: for i in [%ui_bar,%ui_background]: i.size.x = 700 %size_left.position.x = %ui_bar.position.x - 32 elif %ui_bar.size.x < 1200: %category.visible = false %item.visible = true %item.position.x = (%ui_bar.size.x - 256) / 6 minsize = false else: %category.visible = true %item.visible = true %category.position.x = %ui_bar.size.x /6 %item.position.x = %category.position.x + %category.size.x + 64 minsize = false %close.position.x = %ui_bar.size.x - 96 %minimize.position.x = %ui_bar.size.x - 192 %size_right.position.x = %ui_bar.position.x + %ui_bar.size.x - 32 func _on_size_mouse_entered() -> void: #print("in") Input.set_default_cursor_shape(Input.CURSOR_HSIZE) func _on_size_mouse_exited() -> void: #print("out") Input.set_default_cursor_shape(Input.CURSOR_ARROW) func _on_size_right_mouse_entered() -> void: _on_size_mouse_entered() resizer = "right" func _on_size_right_mouse_exited() -> void: _on_size_mouse_exited() dragPoint = null func _on_size_left_mouse_entered() -> void: _on_size_mouse_entered() resizer = "left" func _on_size_left_mouse_exited() -> void: _on_size_mouse_exited() dragPoint = null func _on_size_bottom_mouse_entered() -> void: _on_size_mouse_entered() resizer = "bottom" func _on_size_bottom_mouse_exited() -> void: _on_size_mouse_exited() dragPoint = null