From f4c903771dcbf2697eecbe002a8f0ed99e1bd1e0 Mon Sep 17 00:00:00 2001 From: Manolis Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Wed, 17 Nov 2021 19:59:14 +0200 Subject: [PATCH] Remove some unneeded yield() calls And minor changes to make the code a tiny bit more clean. I tested this PR, but it still might be a bit risky. --- src/Autoload/Tools.gd | 27 ++++++++++++++------------- src/Main.gd | 17 ++++++++++------- src/Tools/BaseTool.gd | 1 - src/UI/Canvas/Canvas.gd | 2 +- src/UI/Canvas/Rulers/Guide.gd | 4 +--- src/UI/Canvas/Rulers/SymmetryGuide.gd | 3 --- src/UI/ColorAndToolOptions.tscn | 4 +--- src/UI/Timeline/AnimationTimeline.gd | 1 - 8 files changed, 27 insertions(+), 32 deletions(-) diff --git a/src/Autoload/Tools.gd b/src/Autoload/Tools.gd index 156b2ab32..cedffcfc4 100644 --- a/src/Autoload/Tools.gd +++ b/src/Autoload/Tools.gd @@ -71,28 +71,29 @@ var alt := false func _ready() -> void: _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.control.find_node("LeftPanelContainer", true, false) _panels[BUTTON_RIGHT] = Global.control.find_node("RightPanelContainer", true, false) - var value = Global.config_cache.get_value(_slots[BUTTON_LEFT].kname, "tool", "Pencil") - if not value in _tools: - value = "Pencil" - set_tool(value, BUTTON_LEFT) - value = Global.config_cache.get_value(_slots[BUTTON_RIGHT].kname, "tool", "Eraser") - if not value in _tools: - value = "Eraser" - set_tool(value, BUTTON_RIGHT) - value = Global.config_cache.get_value(_slots[BUTTON_LEFT].kname, "color", Color.black) - assign_color(value, BUTTON_LEFT, false) - value = Global.config_cache.get_value(_slots[BUTTON_RIGHT].kname, "color", Color.white) - assign_color(value, BUTTON_RIGHT, false) + var tool_name : String = Global.config_cache.get_value(_slots[BUTTON_LEFT].kname, "tool", "Pencil") + if not tool_name in _tools: + tool_name = "Pencil" + set_tool(tool_name, BUTTON_LEFT) + tool_name = Global.config_cache.get_value(_slots[BUTTON_RIGHT].kname, "tool", "Eraser") + if not tool_name in _tools: + tool_name = "Eraser" + set_tool(tool_name, BUTTON_RIGHT) update_tool_buttons() update_tool_cursors() + yield(get_tree(), "idle_frame") # Necessary for the color picker nodes to update their color values + var color_value : Color = Global.config_cache.get_value(_slots[BUTTON_LEFT].kname, "color", Color.black) + 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) + func set_tool(name : String, button : int) -> void: var slot = _slots[button] diff --git a/src/Main.gd b/src/Main.gd index 9b2626ef4..89ab5cd0c 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -21,7 +21,7 @@ onready var scroll_container := $MenuAndUI/UI/RightPanel/MarginContainer/Preview # Called when the node enters the scene tree for the first time. func _ready() -> void: - var alternate_transparent_background = ColorRect.new() + var alternate_transparent_background := ColorRect.new() add_child(alternate_transparent_background) move_child(alternate_transparent_background,0) alternate_transparent_background.visible = false @@ -66,10 +66,6 @@ func _ready() -> void: zstd_checkbox.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND Global.save_sprites_dialog.get_vbox().add_child(zstd_checkbox) - if not Global.config_cache.has_section_key("preferences", "startup"): - Global.config_cache.set_value("preferences", "startup", true) - show_splash_screen() - handle_backup() # If the user wants to run Pixelorama with arguments in terminal mode @@ -81,6 +77,8 @@ func _ready() -> void: if OS.get_name() == "Android": OS.request_permissions() + show_splash_screen() + func handle_resize() -> void: var aspect_ratio = get_viewport_rect().size.x/(0.00001 if get_viewport_rect().size.y == 0 else get_viewport_rect().size.y) @@ -240,9 +238,14 @@ func setup_application_window_size() -> void: func show_splash_screen() -> void: - # Wait for the window to adjust itself, so the popup is correctly centered - yield(get_tree().create_timer(0.2), "timeout") + if not Global.config_cache.has_section_key("preferences", "startup"): + Global.config_cache.set_value("preferences", "startup", true) + if Global.config_cache.get_value("preferences", "startup"): + if OS.window_size != Vector2(1280, 720): + # Wait for the window to adjust itself, so the popup is correctly centered + yield(get_tree(), "screen_resized") + $Dialogs/SplashDialog.popup_centered() # Splash screen modulate = Color(0.5, 0.5, 0.5) else: diff --git a/src/Tools/BaseTool.gd b/src/Tools/BaseTool.gd index 17d009763..beabf03f6 100644 --- a/src/Tools/BaseTool.gd +++ b/src/Tools/BaseTool.gd @@ -12,7 +12,6 @@ func _ready() -> void: kname = name.replace(" ", "_").to_lower() $Label.text = tool_slot.name - yield(get_tree(), "idle_frame") load_config() $PixelPerfect.pressed = tool_slot.pixel_perfect $Mirror/Horizontal.pressed = tool_slot.horizontal_mirror diff --git a/src/UI/Canvas/Canvas.gd b/src/UI/Canvas/Canvas.gd index 89d8a144d..a4d5b3b82 100644 --- a/src/UI/Canvas/Canvas.gd +++ b/src/UI/Canvas/Canvas.gd @@ -23,7 +23,7 @@ onready var previews = $Previews func _ready() -> void: var frame : Frame = new_empty_frame(true) Global.current_project.frames.append(frame) - yield(get_tree().create_timer(0.2), "timeout") + yield(get_tree(), "idle_frame") camera_zoom() diff --git a/src/UI/Canvas/Rulers/Guide.gd b/src/UI/Canvas/Rulers/Guide.gd index f98c33534..99cbf1cba 100644 --- a/src/UI/Canvas/Rulers/Guide.gd +++ b/src/UI/Canvas/Rulers/Guide.gd @@ -17,13 +17,11 @@ func _ready() -> void: modulate.a = 0.5 -func _input(_event : InputEvent): +func _input(_event : InputEvent) -> void: var tmp_transform = get_canvas_transform().affine_inverse() var tmp_position = Global.main_viewport.get_local_mouse_position() mouse_pos = tmp_transform.basis_xform(tmp_position) + tmp_transform.origin - if points.size() < 2: - return var point0 := points[0] var point1 := points[1] if type == Types.HORIZONTAL: diff --git a/src/UI/Canvas/Rulers/SymmetryGuide.gd b/src/UI/Canvas/Rulers/SymmetryGuide.gd index d7e3ede54..dcd030a68 100644 --- a/src/UI/Canvas/Rulers/SymmetryGuide.gd +++ b/src/UI/Canvas/Rulers/SymmetryGuide.gd @@ -10,7 +10,6 @@ func _ready() -> void: texture = _texture texture_mode = Line2D.LINE_TEXTURE_TILE width = Global.camera.zoom.x * 4 - yield(get_tree().create_timer(0.01), "timeout") # Add a subtle difference to the normal guide color by mixing in some blue default_color = Global.guide_color.linear_interpolate(Color(0.2 , 0.2, .65), .6) @@ -26,8 +25,6 @@ func _input(_event : InputEvent) -> void: points[1].x = clamp(points[1].x, 0, Global.current_project.size.x) project.x_symmetry_point = points[0].x * 2 - 1 - yield(get_tree().create_timer(0.01), "timeout") - func outside_canvas() -> bool: return false diff --git a/src/UI/ColorAndToolOptions.tscn b/src/UI/ColorAndToolOptions.tscn index bce3918df..c2e9efe0e 100644 --- a/src/UI/ColorAndToolOptions.tscn +++ b/src/UI/ColorAndToolOptions.tscn @@ -45,9 +45,7 @@ margin_top = 6.0 margin_right = 25.0 margin_bottom = 13.0 -[node name="ColorSwitch" type="TextureButton" parent="ColorPickersHorizontal/ColorButtonsVertical/ColorSwitchCenter" groups=[ -"UIButtons", -]] +[node name="ColorSwitch" type="TextureButton" parent="ColorPickersHorizontal/ColorButtonsVertical/ColorSwitchCenter" groups=["UIButtons"]] margin_right = 25.0 margin_bottom = 7.0 mouse_default_cursor_shape = 2 diff --git a/src/UI/Timeline/AnimationTimeline.gd b/src/UI/Timeline/AnimationTimeline.gd index 0ecf96263..1bbfc185d 100644 --- a/src/UI/Timeline/AnimationTimeline.gd +++ b/src/UI/Timeline/AnimationTimeline.gd @@ -20,7 +20,6 @@ func _ready() -> void: 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") Global.animation_timer.wait_time = 1 / Global.current_project.fps fps_spinbox.value = Global.current_project.fps