console.gd 822 B

123456789101112131415161718192021222324252627
  1. extends Window
  2. # Called when the node enters the scene tree for the first time.
  3. func _ready() -> void:
  4. pass # Replace with function body.
  5. func _on_console_output_gui_input(event: InputEvent) -> void:
  6. #check if right click on console and if so open context menu
  7. if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_RIGHT and event.pressed:
  8. var local_pos = DisplayServer.mouse_get_position()
  9. $ConsoleRightClick.position = local_pos
  10. $ConsoleRightClick.popup()
  11. func _on_console_right_click_index_pressed(index: int) -> void:
  12. match index:
  13. 0:
  14. #select all text in the console
  15. $ConsoleOutput.select_all()
  16. 1:
  17. #copy selected text in the console to the clipboard
  18. var selection = $ConsoleOutput.get_selected_text()
  19. if selection != "":
  20. DisplayServer.clipboard_set(selection)