From b9f0f0a64766769c72e7d4ea1ee0cda1c6f9024a Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Wed, 24 Aug 2022 14:22:40 +0300 Subject: [PATCH] Move left and right cursor sprite nodes to Main.gd --- src/Autoload/Global.gd | 4 +--- src/Autoload/Tools.gd | 7 +++---- src/Main.gd | 10 ++++++---- src/UI/ViewportContainer.gd | 8 ++++---- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index fabe337c6..adf0cf2d8 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -143,10 +143,8 @@ var palettes := {} # Nodes var notification_label_node: PackedScene = preload("res://src/UI/NotificationLabel.tscn") -onready var control: Node = get_tree().get_root().get_node("Control") +onready var control: Node = get_tree().current_scene -onready var left_cursor: Sprite = control.find_node("LeftCursor") -onready var right_cursor: Sprite = control.find_node("RightCursor") onready var canvas: Canvas = control.find_node("Canvas") onready var tabs: Tabs = control.find_node("Tabs") onready var main_viewport: ViewportContainer = control.find_node("ViewportContainer") diff --git a/src/Autoload/Tools.gd b/src/Autoload/Tools.gd index 39983ad15..aecc9025c 100644 --- a/src/Autoload/Tools.gd +++ b/src/Autoload/Tools.gd @@ -232,9 +232,7 @@ func _ready() -> void: if not tool_name in tools: tool_name = "Eraser" set_tool(tool_name, BUTTON_RIGHT) - update_tool_buttons() - update_tool_cursors() horizontal_mirror = Global.config_cache.get_value("preferences", "horizontal_mirror", false) vertical_mirror = Global.config_cache.get_value("preferences", "vertical_mirror", false) @@ -248,6 +246,7 @@ func _ready() -> void: assign_color(color_value, BUTTON_LEFT, false) color_value = Global.config_cache.get_value(_slots[BUTTON_RIGHT].kname, "color", Color.white) assign_color(color_value, BUTTON_RIGHT, false) + update_tool_cursors() func add_tool_button(t: Tool) -> void: @@ -351,9 +350,9 @@ func update_hint_tooltips() -> void: func update_tool_cursors() -> void: var left_tool: Tool = tools[_slots[BUTTON_LEFT].tool_node.name] - Global.left_cursor.texture = left_tool.cursor_icon + Global.control.left_cursor.texture = left_tool.cursor_icon var right_tool: Tool = tools[_slots[BUTTON_RIGHT].tool_node.name] - Global.right_cursor.texture = right_tool.cursor_icon + Global.control.right_cursor.texture = right_tool.cursor_icon func draw_indicator() -> void: diff --git a/src/Main.gd b/src/Main.gd index ff11613f6..573808bd7 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -7,8 +7,10 @@ var cursor_image: Texture = preload("res://assets/graphics/cursor.png") onready var ui := $MenuAndUI/UI/DockableContainer onready var backup_confirmation: ConfirmationDialog = $Dialogs/BackupConfirmation -onready var quit_dialog: ConfirmationDialog = find_node("QuitDialog") -onready var quit_and_save_dialog: ConfirmationDialog = find_node("QuitAndSaveDialog") +onready var quit_dialog: ConfirmationDialog = $Dialogs/QuitDialog +onready var quit_and_save_dialog: ConfirmationDialog = $Dialogs/QuitAndSaveDialog +onready var left_cursor: Sprite = $LeftCursor +onready var right_cursor: Sprite = $RightCursor func _init() -> void: @@ -78,8 +80,8 @@ func _ready() -> void: func _input(event: InputEvent) -> void: - Global.left_cursor.position = get_global_mouse_position() + Vector2(-32, 32) - Global.right_cursor.position = get_global_mouse_position() + Vector2(32, 32) + left_cursor.position = get_global_mouse_position() + Vector2(-32, 32) + right_cursor.position = get_global_mouse_position() + Vector2(32, 32) if event is InputEventKey and (event.scancode == KEY_ENTER or event.scancode == KEY_KP_ENTER): if get_focus_owner() is LineEdit: diff --git a/src/UI/ViewportContainer.gd b/src/UI/ViewportContainer.gd index d14cdb048..565fe4e4b 100644 --- a/src/UI/ViewportContainer.gd +++ b/src/UI/ViewportContainer.gd @@ -8,11 +8,11 @@ func _ready() -> void: func _on_ViewportContainer_mouse_entered() -> void: Global.has_focus = true - Global.left_cursor.visible = Global.show_left_tool_icon - Global.right_cursor.visible = Global.show_right_tool_icon + Global.control.left_cursor.visible = Global.show_left_tool_icon + Global.control.right_cursor.visible = Global.show_right_tool_icon func _on_ViewportContainer_mouse_exited() -> void: Global.has_focus = false - Global.left_cursor.visible = false - Global.right_cursor.visible = false + Global.control.left_cursor.visible = false + Global.control.right_cursor.visible = false