diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index f938ce054..6f67f2d8f 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -211,27 +211,27 @@ func _ready() -> void: image_clipboard = Image.new() Input.set_custom_mouse_cursor(cursor_image, Input.CURSOR_CROSS, Vector2(15, 15)) - var root = get_tree().get_root() - control = find_node_by_name(root, "Control") + var root : Node = get_tree().get_root() + control = root.get_node("Control") - top_menu_container = find_node_by_name(control, "TopMenuContainer") - left_cursor = find_node_by_name(root, "LeftCursor") - right_cursor = find_node_by_name(root, "RightCursor") - canvas = find_node_by_name(root, "Canvas") + top_menu_container = control.find_node("TopMenuContainer") + left_cursor = control.find_node("LeftCursor") + right_cursor = control.find_node("RightCursor") + canvas = control.find_node("Canvas") - tabs = find_node_by_name(root, "Tabs") - main_viewport = find_node_by_name(root, "ViewportContainer") - second_viewport = find_node_by_name(root, "ViewportContainer2") - small_preview_viewport = find_node_by_name(root, "PreviewViewportContainer") - camera = find_node_by_name(main_viewport, "Camera2D") - camera2 = find_node_by_name(root, "Camera2D2") - camera_preview = find_node_by_name(root, "CameraPreview") - horizontal_ruler = find_node_by_name(root, "HorizontalRuler") - vertical_ruler = find_node_by_name(root, "VerticalRuler") - transparent_checker = find_node_by_name(root, "TransparentChecker") + tabs = control.find_node("Tabs") + main_viewport = control.find_node("ViewportContainer") + second_viewport = control.find_node("ViewportContainer2") + small_preview_viewport = control.find_node("PreviewViewportContainer") + camera = main_viewport.find_node("Camera2D") + camera2 = control.find_node("Camera2D2") + camera_preview = control.find_node("CameraPreview") + horizontal_ruler = control.find_node("HorizontalRuler") + vertical_ruler = control.find_node("VerticalRuler") + transparent_checker = control.find_node("TransparentChecker") - cursor_position_label = find_node_by_name(root, "CursorPosition") - zoom_level_label = find_node_by_name(root, "ZoomLevel") + cursor_position_label = control.find_node("CursorPosition") + zoom_level_label = control.find_node("ZoomLevel") tool_panel = control.find_node("ToolPanel") right_panel = control.find_node("RightPanel") @@ -273,72 +273,59 @@ func _ready() -> void: panel_layout_submenu.hide_on_checkable_item_selection = false panel_layout_submenu.set_item_checked(panel_layout, true) - new_image_dialog = find_node_by_name(root, "CreateNewImage") - open_sprites_dialog = find_node_by_name(root, "OpenSprite") - save_sprites_dialog = find_node_by_name(root, "SaveSprite") - save_sprites_html5_dialog = find_node_by_name(root, "SaveSpriteHTML5") - export_dialog = find_node_by_name(root, "ExportDialog") - preferences_dialog = find_node_by_name(root, "PreferencesDialog") - unsaved_changes_dialog = find_node_by_name(root, "UnsavedCanvasDialog") + new_image_dialog = control.find_node("CreateNewImage") + open_sprites_dialog = control.find_node("OpenSprite") + save_sprites_dialog = control.find_node("SaveSprite") + save_sprites_html5_dialog = control.find_node("SaveSpriteHTML5") + export_dialog = control.find_node("ExportDialog") + preferences_dialog = control.find_node("PreferencesDialog") + unsaved_changes_dialog = control.find_node("UnsavedCanvasDialog") - color_switch_button = find_node_by_name(root, "ColorSwitch") + color_switch_button = control.find_node("ColorSwitch") - brushes_popup = find_node_by_name(root, "BrushesPopup") - patterns_popup = find_node_by_name(root, "PatternsPopup") + brushes_popup = control.find_node("BrushesPopup") + patterns_popup = control.find_node("PatternsPopup") - animation_timeline = find_node_by_name(root, "AnimationTimeline") - frame_properties = find_node_by_name(root, "FrameProperties") + animation_timeline = control.find_node("AnimationTimeline") + frame_properties = control.find_node("FrameProperties") - layers_container = find_node_by_name(animation_timeline, "LayersContainer") - frames_container = find_node_by_name(animation_timeline, "FramesContainer") - animation_timer = find_node_by_name(animation_timeline, "AnimationTimer") - frame_ids = find_node_by_name(animation_timeline, "FrameIDs") - current_frame_mark_label = find_node_by_name(control, "CurrentFrameMark") - onion_skinning_button = find_node_by_name(animation_timeline, "OnionSkinning") - loop_animation_button = find_node_by_name(animation_timeline, "LoopAnim") - play_forward = find_node_by_name(animation_timeline, "PlayForward") - play_backwards = find_node_by_name(animation_timeline, "PlayBackwards") - tag_container = find_node_by_name(animation_timeline, "TagContainer") - tag_dialog = find_node_by_name(animation_timeline, "FrameTagDialog") + layers_container = animation_timeline.find_node("LayersContainer") + frames_container = animation_timeline.find_node("FramesContainer") + animation_timer = animation_timeline.find_node("AnimationTimer") + frame_ids = animation_timeline.find_node("FrameIDs") + current_frame_mark_label = control.find_node("CurrentFrameMark") + onion_skinning_button = animation_timeline.find_node("OnionSkinning") + loop_animation_button = animation_timeline.find_node("LoopAnim") + play_forward = animation_timeline.find_node("PlayForward") + play_backwards = animation_timeline.find_node("PlayBackwards") + tag_container = animation_timeline.find_node("TagContainer") + tag_dialog = animation_timeline.find_node("FrameTagDialog") - remove_frame_button = find_node_by_name(animation_timeline, "DeleteFrame") - move_left_frame_button = find_node_by_name(animation_timeline, "MoveLeft") - move_right_frame_button = find_node_by_name(animation_timeline, "MoveRight") + remove_frame_button = animation_timeline.find_node("DeleteFrame") + move_left_frame_button = animation_timeline.find_node("MoveLeft") + move_right_frame_button = animation_timeline.find_node("MoveRight") - remove_layer_button = find_node_by_name(animation_timeline, "RemoveLayer") - move_up_layer_button = find_node_by_name(animation_timeline, "MoveUpLayer") - move_down_layer_button = find_node_by_name(animation_timeline, "MoveDownLayer") - merge_down_layer_button = find_node_by_name(animation_timeline, "MergeDownLayer") + remove_layer_button = animation_timeline.find_node("RemoveLayer") + move_up_layer_button = animation_timeline.find_node("MoveUpLayer") + move_down_layer_button = animation_timeline.find_node("MoveDownLayer") + merge_down_layer_button = animation_timeline.find_node("MergeDownLayer") - layer_opacity_slider = find_node_by_name(animation_timeline, "OpacitySlider") - layer_opacity_spinbox = find_node_by_name(animation_timeline, "OpacitySpinBox") + layer_opacity_slider = animation_timeline.find_node("OpacitySlider") + layer_opacity_spinbox = animation_timeline.find_node("OpacitySpinBox") - preview_zoom_slider = find_node_by_name(root, "PreviewZoomSlider") + preview_zoom_slider = control.find_node("PreviewZoomSlider") - palette_panel = find_node_by_name(root, "PalettePanel") + palette_panel = control.find_node("PalettePanel") - error_dialog = find_node_by_name(root, "ErrorDialog") - quit_dialog = find_node_by_name(root, "QuitDialog") - quit_and_save_dialog = find_node_by_name(root, "QuitAndSaveDialog") + error_dialog = control.find_node("ErrorDialog") + quit_dialog = control.find_node("QuitDialog") + quit_and_save_dialog = control.find_node("QuitAndSaveDialog") projects.append(Project.new()) projects[0].layers.append(Layer.new()) current_project = projects[0] -# Thanks to https://godotengine.org/qa/17524/how-to-find-an-instanced-scene-by-its-name -func find_node_by_name(root : Node, node_name : String) -> Node: - if root.get_name() == node_name: - return root - for child in root.get_children(): - if child.get_name() == node_name: - return child - var found = find_node_by_name(child, node_name) - if found: - return found - return null - - func notification_label(text : String) -> void: var notification : Label = load("res://src/UI/NotificationLabel.tscn").instance() notification.text = tr(text) @@ -478,8 +465,7 @@ func change_button_texturerect(texture_button : TextureRect, new_file_name : Str func update_hint_tooltips() -> void: - var root = control - var tool_buttons = root.find_node("ToolButtons") + var tool_buttons = control.find_node("ToolButtons") var rect_select : BaseButton = tool_buttons.find_node("RectSelect") rect_select.hint_tooltip = tr("""Rectangular Selection @@ -529,26 +515,26 @@ func update_hint_tooltips() -> void: %s for right mouse button""") % [InputMap.get_action_list("left_move_tool")[0].as_text(), InputMap.get_action_list("right_move_tool")[0].as_text()] - var zoom_tool : BaseButton = find_node_by_name(root, "Zoom") + var zoom_tool : BaseButton = tool_buttons.find_node("Zoom") zoom_tool.hint_tooltip = tr("""Zoom %s for left mouse button %s for right mouse button""") % [InputMap.get_action_list("left_zoom_tool")[0].as_text(), InputMap.get_action_list("right_zoom_tool")[0].as_text()] - var pan_tool : BaseButton = find_node_by_name(root, "Pan") + var pan_tool : BaseButton = tool_buttons.find_node("Pan") pan_tool.hint_tooltip = tr("""Pan %s for left mouse button %s for right mouse button""") % [InputMap.get_action_list("left_pan_tool")[0].as_text(), InputMap.get_action_list("right_pan_tool")[0].as_text()] - var color_picker : BaseButton = find_node_by_name(root, "ColorPicker") + var color_picker : BaseButton = tool_buttons.find_node("ColorPicker") color_picker.hint_tooltip = tr("""Color Picker Select a color from a pixel of the sprite %s for left mouse button %s for right mouse button""") % [InputMap.get_action_list("left_colorpicker_tool")[0].as_text(), InputMap.get_action_list("right_colorpicker_tool")[0].as_text()] - var pencil : BaseButton = find_node_by_name(root, "Pencil") + var pencil : BaseButton = tool_buttons.find_node("Pencil") pencil.hint_tooltip = tr("""Pencil %s for left mouse button @@ -556,7 +542,7 @@ Select a color from a pixel of the sprite Hold %s to make a line""") % [InputMap.get_action_list("left_pencil_tool")[0].as_text(), InputMap.get_action_list("right_pencil_tool")[0].as_text(), "Shift"] - var eraser : BaseButton = find_node_by_name(root, "Eraser") + var eraser : BaseButton = tool_buttons.find_node("Eraser") eraser.hint_tooltip = tr("""Eraser %s for left mouse button @@ -564,19 +550,19 @@ Hold %s to make a line""") % [InputMap.get_action_list("left_pencil_tool")[0].as Hold %s to make a line""") % [InputMap.get_action_list("left_eraser_tool")[0].as_text(), InputMap.get_action_list("right_eraser_tool")[0].as_text(), "Shift"] - var bucket : BaseButton = find_node_by_name(root, "Bucket") + var bucket : BaseButton = tool_buttons.find_node("Bucket") bucket.hint_tooltip = tr("""Bucket %s for left mouse button %s for right mouse button""") % [InputMap.get_action_list("left_fill_tool")[0].as_text(), InputMap.get_action_list("right_fill_tool")[0].as_text()] - var ld : BaseButton = find_node_by_name(root, "Shading") + var ld : BaseButton = tool_buttons.find_node("Shading") ld.hint_tooltip = tr("""Shading Tool %s for left mouse button %s for right mouse button""") % [InputMap.get_action_list("left_shading_tool")[0].as_text(), InputMap.get_action_list("right_shading_tool")[0].as_text()] - var linetool : BaseButton = find_node_by_name(root, "LineTool") + var linetool : BaseButton = tool_buttons.find_node("LineTool") linetool.hint_tooltip = tr("""Line Tool %s for left mouse button @@ -586,7 +572,7 @@ Hold %s to snap the angle of the line Hold %s to center the shape on the click origin Hold %s to displace the shape's origin""") % [InputMap.get_action_list("left_linetool_tool")[0].as_text(), InputMap.get_action_list("right_linetool_tool")[0].as_text(), "Shift", "Ctrl", "Alt"] - var recttool : BaseButton = find_node_by_name(root, "RectangleTool") + var recttool : BaseButton = tool_buttons.find_node("RectangleTool") recttool.hint_tooltip = tr("""Rectangle Tool %s for left mouse button @@ -596,7 +582,7 @@ Hold %s to create a 1:1 shape Hold %s to center the shape on the click origin Hold %s to displace the shape's origin""") % [InputMap.get_action_list("left_rectangletool_tool")[0].as_text(), InputMap.get_action_list("right_rectangletool_tool")[0].as_text(), "Shift", "Ctrl", "Alt"] - var ellipsetool : BaseButton = find_node_by_name(root, "EllipseTool") + var ellipsetool : BaseButton = tool_buttons.find_node("EllipseTool") ellipsetool.hint_tooltip = tr("""Ellipse Tool %s for left mouse button @@ -606,15 +592,15 @@ Hold %s to create a 1:1 shape Hold %s to center the shape on the click origin Hold %s to displace the shape's origin""") % [InputMap.get_action_list("left_ellipsetool_tool")[0].as_text(), InputMap.get_action_list("right_ellipsetool_tool")[0].as_text(), "Shift", "Ctrl", "Alt"] - var color_switch : BaseButton = find_node_by_name(root, "ColorSwitch") + var color_switch : BaseButton = control.find_node("ColorSwitch") color_switch.hint_tooltip = tr("""Switch left and right colors (%s)""") % InputMap.get_action_list("switch_colors")[0].as_text() - var first_frame : BaseButton = find_node_by_name(root, "FirstFrame") + var first_frame : BaseButton = control.find_node("FirstFrame") first_frame.hint_tooltip = tr("""Jump to the first frame (%s)""") % InputMap.get_action_list("go_to_first_frame")[0].as_text() - var previous_frame : BaseButton = find_node_by_name(root, "PreviousFrame") + var previous_frame : BaseButton = control.find_node("PreviousFrame") previous_frame.hint_tooltip = tr("""Go to the previous frame (%s)""") % InputMap.get_action_list("go_to_previous_frame")[0].as_text() @@ -624,11 +610,11 @@ Hold %s to displace the shape's origin""") % [InputMap.get_action_list("left_ell play_forward.hint_tooltip = tr("""Play the animation forward (from beginning to end) (%s)""") % InputMap.get_action_list("play_forward")[0].as_text() - var next_frame : BaseButton = find_node_by_name(root, "NextFrame") + var next_frame : BaseButton = control.find_node("NextFrame") next_frame.hint_tooltip = tr("""Go to the next frame (%s)""") % InputMap.get_action_list("go_to_next_frame")[0].as_text() - var last_frame : BaseButton = find_node_by_name(root, "LastFrame") + var last_frame : BaseButton = control.find_node("LastFrame") last_frame.hint_tooltip = tr("""Jump to the last frame (%s)""") % InputMap.get_action_list("go_to_last_frame")[0].as_text() diff --git a/src/Autoload/Tools.gd b/src/Autoload/Tools.gd index 9201d7122..8ec12a12c 100644 --- a/src/Autoload/Tools.gd +++ b/src/Autoload/Tools.gd @@ -70,12 +70,12 @@ var alt := false func _ready() -> void: - _tool_buttons = Global.find_node_by_name(Global.control, "ToolButtons") + _tool_buttons = Global.control.find_node("ToolButtons") yield(get_tree(), "idle_frame") _slots[BUTTON_LEFT] = Slot.new("Left tool") _slots[BUTTON_RIGHT] = Slot.new("Right tool") - _panels[BUTTON_LEFT] = Global.find_node_by_name(Global.control, "LeftPanelContainer") - _panels[BUTTON_RIGHT] = Global.find_node_by_name(Global.control, "RightPanelContainer") + _panels[BUTTON_LEFT] = Global.control.find_node("LeftPanelContainer") + _panels[BUTTON_RIGHT] = Global.control.find_node("RightPanelContainer") var value = Global.config_cache.get_value(_slots[BUTTON_LEFT].kname, "tool", "Pencil") if not value in _tools: diff --git a/src/Main.gd b/src/Main.gd index 949399943..d4aeca4f5 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -35,7 +35,6 @@ func _ready() -> void: handle_resize() get_tree().get_root().connect("size_changed", self, "handle_resize") - Global.window_title = tr("untitled") + " - Pixelorama " + Global.current_version Global.current_project.layers[0].name = tr("Layer") + " 0" diff --git a/src/Preferences/HandleThemes.gd b/src/Preferences/HandleThemes.gd index 12c46fbce..13fcd7564 100644 --- a/src/Preferences/HandleThemes.gd +++ b/src/Preferences/HandleThemes.gd @@ -80,10 +80,10 @@ func change_theme(ID : int) -> void: VisualServer.set_default_clear_color(Color(Global.default_clear_color)) (Global.animation_timeline.get_stylebox("panel", "Panel") as StyleBoxFlat).bg_color = main_theme.get_stylebox("panel", "Panel").bg_color - var fake_vsplit_grabber : TextureRect = Global.find_node_by_name(Global.animation_timeline, "FakeVSplitContainerGrabber") + var fake_vsplit_grabber : TextureRect = Global.animation_timeline.find_node("FakeVSplitContainerGrabber") fake_vsplit_grabber.texture = main_theme.get_icon("grabber", "VSplitContainer") - var layer_button_panel_container : PanelContainer = Global.find_node_by_name(Global.animation_timeline, "LayerButtonPanelContainer") + var layer_button_panel_container : PanelContainer = Global.animation_timeline.find_node("LayerButtonPanelContainer") (layer_button_panel_container.get_stylebox("panel", "PanelContainer") as StyleBoxFlat).bg_color = Global.default_clear_color var top_menu_style = main_theme.get_stylebox("TopMenu", "Panel") diff --git a/src/UI/Canvas/Canvas.gd b/src/UI/Canvas/Canvas.gd index 28ee6ada0..0f8a44017 100644 --- a/src/UI/Canvas/Canvas.gd +++ b/src/UI/Canvas/Canvas.gd @@ -225,7 +225,7 @@ func update_texture(layer_index : int, frame_index := -1, project : Project = Gl if project == Global.current_project: var frame_texture_rect : TextureRect - frame_texture_rect = Global.find_node_by_name(project.layers[layer_index].frame_container.get_child(frame_index), "CelTexture") + frame_texture_rect = project.layers[layer_index].frame_container.get_child(frame_index).find_node("CelTexture") frame_texture_rect.texture = current_cel.image_texture @@ -239,7 +239,7 @@ func update_selected_cels_textures(project : Project = Global.current_project) - if project == Global.current_project: var frame_texture_rect : TextureRect - frame_texture_rect = Global.find_node_by_name(project.layers[layer_index].frame_container.get_child(frame_index), "CelTexture") + frame_texture_rect = project.layers[layer_index].frame_container.get_child(frame_index).find_node("CelTexture") frame_texture_rect.texture = current_cel.image_texture diff --git a/src/UI/Dialogs/SplashDialog.gd b/src/UI/Dialogs/SplashDialog.gd index 591ca101b..15e453adb 100644 --- a/src/UI/Dialogs/SplashDialog.gd +++ b/src/UI/Dialogs/SplashDialog.gd @@ -14,10 +14,10 @@ onready var cjk_font = preload("res://assets/fonts/CJK/DroidSansFallback-Small.t func _on_SplashDialog_about_to_show() -> void: - var splash_art_texturerect : TextureRect = Global.find_node_by_name(self, "SplashArt") - var art_by_label : Button = Global.find_node_by_name(self, "ArtistName") - var show_on_startup_button : CheckBox = Global.find_node_by_name(self, "ShowOnStartup") - var copyright_label : Label = Global.find_node_by_name(self, "CopyrightLabel") + var splash_art_texturerect : TextureRect = find_node("SplashArt") + var art_by_label : Button = find_node("ArtistName") + var show_on_startup_button : CheckBox = find_node("ShowOnStartup") + var copyright_label : Label = find_node("CopyrightLabel") if Global.config_cache.has_section_key("preferences", "startup"): show_on_startup_button.pressed = !Global.config_cache.get_value("preferences", "startup") diff --git a/src/UI/Timeline/AnimationTimeline.gd b/src/UI/Timeline/AnimationTimeline.gd index 85ded1201..08309e694 100644 --- a/src/UI/Timeline/AnimationTimeline.gd +++ b/src/UI/Timeline/AnimationTimeline.gd @@ -15,8 +15,8 @@ var fps_spinbox : SpinBox func _ready() -> void: - timeline_scroll = Global.find_node_by_name(self, "TimelineScroll") - tag_scroll_container = Global.find_node_by_name(self, "TagScroll") + timeline_scroll = find_node("TimelineScroll") + tag_scroll_container = find_node("TagScroll") fps_spinbox = find_node("FPSValue") timeline_scroll.get_h_scrollbar().connect("value_changed", self, "_h_scroll_changed") yield(get_tree(), "idle_frame")