From 5613c3d7efc8c773a0b649766c3f41f95fe34776 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Fri, 6 Dec 2019 01:48:29 +0200 Subject: [PATCH] Overall code re-organizing & layer renaming changes - When renaming a layer, the line edit grabs the focus. If enter is pressed, it gets invisible. Also fixed positioning and size - Re-organized the variables in Global, now they are less messy and randomly placed - Layer, frame & brush textures stretch mode has been changed to Keep Aspect Centered --- Main.tscn | 2 + Prefabs/BrushButton.tscn | 1 + Prefabs/FrameButton.tscn | 1 + Prefabs/LayerContainer.tscn | 35 ++++--- Scripts/CameraMovement.gd | 2 +- Scripts/Canvas.gd | 4 +- Scripts/Global.gd | 176 ++++++++++++++++++---------------- Scripts/Guides.gd | 2 +- Scripts/HorizontalRuler.gd | 2 +- Scripts/LayerContainer.gd | 39 +++++--- Scripts/Main.gd | 4 +- Scripts/SelectionRectangle.gd | 2 +- Scripts/TimelineSeconds.gd | 2 +- Scripts/VerticalRuler.gd | 2 +- 14 files changed, 158 insertions(+), 116 deletions(-) diff --git a/Main.tscn b/Main.tscn index 357e9dfd6..d399cba97 100644 --- a/Main.tscn +++ b/Main.tscn @@ -905,6 +905,7 @@ margin_bottom = 138.0 size_flags_horizontal = 3 [node name="AnimationButtons" type="HBoxContainer" parent="MenuAndUI/UI/CanvasAndTimeline/AnimationTimeline/AnimationContainer/TimelineContainer"] +editor/display_folded = true margin_right = 562.0 margin_bottom = 25.0 rect_min_size = Vector2( 0, 24 ) @@ -972,6 +973,7 @@ mouse_default_cursor_shape = 2 texture_normal = ExtResource( 25 ) [node name="LoopButtons" type="HBoxContainer" parent="MenuAndUI/UI/CanvasAndTimeline/AnimationTimeline/AnimationContainer/TimelineContainer/AnimationButtons"] +editor/display_folded = true margin_left = 476.0 margin_right = 562.0 margin_bottom = 25.0 diff --git a/Prefabs/BrushButton.tscn b/Prefabs/BrushButton.tscn index 985a86aab..ff1de7654 100644 --- a/Prefabs/BrushButton.tscn +++ b/Prefabs/BrushButton.tscn @@ -22,6 +22,7 @@ margin_bottom = 32.0 rect_min_size = Vector2( 3, 0 ) button_mask = 3 texture_normal = ExtResource( 1 ) +stretch_mode = 5 script = ExtResource( 2 ) [node name="BrushTexture" type="TextureRect" parent="."] diff --git a/Prefabs/FrameButton.tscn b/Prefabs/FrameButton.tscn index 10ec74759..bcdb6a745 100644 --- a/Prefabs/FrameButton.tscn +++ b/Prefabs/FrameButton.tscn @@ -26,6 +26,7 @@ rect_min_size = Vector2( 32, 32 ) size_flags_horizontal = 0 size_flags_vertical = 0 expand = true +stretch_mode = 6 [node name="PopupMenu" type="PopupMenu" parent="FrameButton"] margin_right = 20.0 diff --git a/Prefabs/LayerContainer.tscn b/Prefabs/LayerContainer.tscn index be14508f8..586f7eead 100644 --- a/Prefabs/LayerContainer.tscn +++ b/Prefabs/LayerContainer.tscn @@ -3,7 +3,6 @@ [ext_resource path="res://Scripts/LayerContainer.gd" type="Script" id=1] [ext_resource path="res://Assets/Graphics/Layers/layer_visible.png" type="Texture" id=2] - [node name="LayerContainer" type="Button"] margin_left = -0.540344 margin_right = 11.4597 @@ -11,19 +10,25 @@ margin_bottom = 42.0 rect_min_size = Vector2( 160, 42 ) toggle_mode = true script = ExtResource( 1 ) +__meta__ = { +"_edit_horizontal_guides_": [ ] +} [node name="HBoxContainer" type="HBoxContainer" parent="."] +anchor_left = 0.5 anchor_top = 0.5 -anchor_right = 1.0 +anchor_right = 0.5 anchor_bottom = 0.5 -margin_left = 4.0 -margin_top = -16.0 -margin_bottom = 16.0 +margin_left = -80.0 +margin_top = -21.0 +margin_right = 80.0 +margin_bottom = 21.0 mouse_default_cursor_shape = 2 [node name="VisibilityButton" type="TextureButton" parent="HBoxContainer"] +margin_top = 5.0 margin_right = 32.0 -margin_bottom = 32.0 +margin_bottom = 37.0 hint_tooltip = "Toggle layer's visibility" mouse_default_cursor_shape = 2 size_flags_horizontal = 0 @@ -32,24 +37,30 @@ texture_normal = ExtResource( 2 ) [node name="TextureRect" type="TextureRect" parent="HBoxContainer"] margin_left = 36.0 +margin_top = 5.0 margin_right = 68.0 -margin_bottom = 32.0 +margin_bottom = 37.0 rect_min_size = Vector2( 32, 32 ) +size_flags_vertical = 4 expand = true +stretch_mode = 6 [node name="Label" type="Label" parent="HBoxContainer"] margin_left = 72.0 -margin_top = 9.0 +margin_top = 14.0 margin_right = 118.0 -margin_bottom = 23.0 +margin_bottom = 28.0 text = "Layer 0" align = 1 [node name="LineEdit" type="LineEdit" parent="HBoxContainer"] visible = false -margin_left = 110.0 -margin_right = 168.0 -margin_bottom = 32.0 +margin_left = 122.0 +margin_top = 5.0 +margin_right = 202.0 +margin_bottom = 37.0 +rect_min_size = Vector2( 80, 32 ) +size_flags_vertical = 4 text = "Layer 0" editable = false caret_blink = true diff --git a/Scripts/CameraMovement.gd b/Scripts/CameraMovement.gd index 1a7339e21..28795736a 100644 --- a/Scripts/CameraMovement.gd +++ b/Scripts/CameraMovement.gd @@ -8,7 +8,7 @@ var drag := false func _ready() -> void: viewport_container = get_parent().get_parent() -func _input(event) -> void: +func _input(event : InputEvent) -> void: var mouse_pos := viewport_container.get_local_mouse_position() var viewport_size := viewport_container.rect_size if event.is_action_pressed("camera_drag"): diff --git a/Scripts/Canvas.gd b/Scripts/Canvas.gd index 5cfc31ab9..4d503bd52 100644 --- a/Scripts/Canvas.gd +++ b/Scripts/Canvas.gd @@ -75,7 +75,7 @@ func camera_zoom() -> void: Global.camera_preview.offset = size / 2 # warning-ignore:unused_argument -func _process(delta) -> void: +func _process(delta : float) -> void: sprite_changed_this_frame = false update() current_pixel = get_local_mouse_position() - location @@ -438,10 +438,10 @@ func generate_layer_panels() -> void: if !layers[i][2]: layers[i][2] = "Layer %s" % i layer_container.i = i + layer_container.get_child(0).get_child(1).texture = layers[i][1] layer_container.get_child(0).get_child(2).text = layers[i][2] layer_container.get_child(0).get_child(3).text = layers[i][2] layers[i][3] = true #set visible - layer_container.get_child(0).get_child(1).texture = layers[i][1] Global.vbox_layer_container.add_child(layer_container) func pencil_and_eraser(mouse_pos : Vector2, color : Color, current_mouse_button : String, current_action := "None") -> void: diff --git a/Scripts/Global.gd b/Scripts/Global.gd index c750411af..75d88ba85 100644 --- a/Scripts/Global.gd +++ b/Scripts/Global.gd @@ -2,17 +2,55 @@ extends Node var undo_redo : UndoRedo var undos := 0 #The number of times we added undo properties + +#Canvas related stuff var current_frame := 0 setget frame_changed # warning-ignore:unused_class_variable var can_draw := false # warning-ignore:unused_class_variable var has_focus := false +var canvases := [] # warning-ignore:unused_class_variable -var onion_skinning_past_rate := 0 +var hidden_canvases := [] # warning-ignore:unused_class_variable -var onion_skinning_future_rate := 0 +var selected_pixels := [] +var image_clipboard : Image + +#Tools & options # warning-ignore:unused_class_variable -var onion_skinning_blue_red := false +var current_left_tool := "Pencil" +# warning-ignore:unused_class_variable +var current_right_tool := "Eraser" +# warning-ignore:unused_class_variable +var left_square_indicator_visible := true +# warning-ignore:unused_class_variable +var right_square_indicator_visible := false +#0 for area of same color, 1 for all pixels of the same color +# warning-ignore:unused_class_variable +var left_fill_area := 0 +# warning-ignore:unused_class_variable +var right_fill_area := 0 + +#0 for lighten, 1 for darken +# warning-ignore:unused_class_variable +var left_ld := 0 +# warning-ignore:unused_class_variable +var right_ld := 0 +# warning-ignore:unused_class_variable +var left_ld_amount := 0.1 +# warning-ignore:unused_class_variable +var right_ld_amount := 0.1 + +# warning-ignore:unused_class_variable +var left_horizontal_mirror := false +# warning-ignore:unused_class_variable +var left_vertical_mirror := false +# warning-ignore:unused_class_variable +var right_horizontal_mirror := false +# warning-ignore:unused_class_variable +var right_vertical_mirror := false + +#View menu options # warning-ignore:unused_class_variable var tile_mode := false # warning-ignore:unused_class_variable @@ -21,9 +59,43 @@ var draw_grid := false var show_rulers := true # warning-ignore:unused_class_variable var show_guides := true -var canvases := [] + +#Onion skinning options # warning-ignore:unused_class_variable -var hidden_canvases := [] +var onion_skinning_past_rate := 0 +# warning-ignore:unused_class_variable +var onion_skinning_future_rate := 0 +# warning-ignore:unused_class_variable +var onion_skinning_blue_red := false + +#Brushes +enum BRUSH_TYPES {PIXEL, FILE, CUSTOM} +# warning-ignore:unused_class_variable +var left_brush_size := 1 +# warning-ignore:unused_class_variable +var right_brush_size := 1 +# warning-ignore:unused_class_variable +var current_left_brush_type = BRUSH_TYPES.PIXEL +# warning-ignore:unused_class_variable +var current_right_brush_type = BRUSH_TYPES.PIXEL + +var brushes_from_files := 0 +# warning-ignore:unused_class_variable +var custom_brushes := [] +# warning-ignore:unused_class_variable +var custom_left_brush_index := -1 +# warning-ignore:unused_class_variable +var custom_right_brush_index := -1 +# warning-ignore:unused_class_variable +var custom_left_brush_image : Image +# warning-ignore:unused_class_variable +var custom_right_brush_image : Image +# warning-ignore:unused_class_variable +var custom_left_brush_texture := ImageTexture.new() +# warning-ignore:unused_class_variable +var custom_right_brush_texture := ImageTexture.new() + +#Nodes var control : Node var canvas : Canvas var canvas_parent : Node @@ -31,24 +103,19 @@ var main_viewport : ViewportContainer var second_viewport : ViewportContainer var viewport_separator : VSeparator var split_screen_button : BaseButton -# warning-ignore:unused_class_variable -var left_square_indicator_visible := true -# warning-ignore:unused_class_variable -var right_square_indicator_visible := false var camera : Camera2D var camera2 : Camera2D var camera_preview : Camera2D var selection_rectangle : Polygon2D var horizontal_ruler : BaseButton var vertical_ruler : BaseButton -# warning-ignore:unused_class_variable -var selected_pixels := [] -var image_clipboard : Image var file_menu : MenuButton var edit_menu : MenuButton var view_menu : MenuButton var help_menu : MenuButton +var cursor_position_label : Label +var zoom_level_label : Label var left_color_picker : ColorPickerButton var right_color_picker : ColorPickerButton @@ -62,6 +129,9 @@ var left_brush_type_button : BaseButton var right_brush_type_button : BaseButton var left_brush_type_label : Label var right_brush_type_label : Label +var brushes_popup : Popup +var file_brush_container : GridContainer +var project_brush_container : GridContainer var left_brush_size_container : Container var right_brush_size_container : Container @@ -82,77 +152,24 @@ var right_ld_container : Container var left_mirror_container : Container var right_mirror_container : Container +var animation_timer : Timer + +var current_frame_label : Label var loop_animation_button : BaseButton var play_forward : BaseButton var play_backwards : BaseButton var frame_container : HBoxContainer + var vbox_layer_container : VBoxContainer var remove_layer_button : BaseButton var move_up_layer_button : BaseButton var move_down_layer_button : BaseButton var merge_down_layer_button : BaseButton -var animation_timer : Timer -var cursor_position_label : Label -var zoom_level_label : Label -var current_frame_label : Label -# warning-ignore:unused_class_variable -var current_left_tool := "Pencil" -# warning-ignore:unused_class_variable -var current_right_tool := "Eraser" - -#Brushes -enum BRUSH_TYPES {PIXEL, FILE, CUSTOM} -# warning-ignore:unused_class_variable -var left_brush_size := 1 -# warning-ignore:unused_class_variable -var right_brush_size := 1 -# warning-ignore:unused_class_variable -var current_left_brush_type = BRUSH_TYPES.PIXEL -# warning-ignore:unused_class_variable -var current_right_brush_type = BRUSH_TYPES.PIXEL -var brushes_popup : Popup -var file_brush_container : GridContainer -var project_brush_container : GridContainer - -#0 for area of same color, 1 for all pixels of the same color -var left_fill_area := 0 -var right_fill_area := 0 - -#0 for lighten, 1 for darken -var left_ld := 0 -var right_ld := 0 -# warning-ignore:unused_class_variable -var left_ld_amount := 0.1 -# warning-ignore:unused_class_variable -var right_ld_amount := 0.1 - -# warning-ignore:unused_class_variable -var left_horizontal_mirror := false -# warning-ignore:unused_class_variable -var left_vertical_mirror := false -# warning-ignore:unused_class_variable -var right_horizontal_mirror := false -# warning-ignore:unused_class_variable -var right_vertical_mirror := false - -var brushes_from_files := 0 -# warning-ignore:unused_class_variable -var custom_brushes := [] -# warning-ignore:unused_class_variable -var custom_left_brush_index := -1 -# warning-ignore:unused_class_variable -var custom_right_brush_index := -1 -# warning-ignore:unused_class_variable -var custom_left_brush_image : Image -# warning-ignore:unused_class_variable -var custom_right_brush_image : Image -# warning-ignore:unused_class_variable -var custom_left_brush_texture := ImageTexture.new() -# warning-ignore:unused_class_variable -var custom_right_brush_texture := ImageTexture.new() func _ready() -> void: undo_redo = UndoRedo.new() + image_clipboard = Image.new() + var root = get_tree().get_root() control = find_node_by_name(root, "Control") canvas = find_node_by_name(root, "Canvas") @@ -168,12 +185,13 @@ func _ready() -> void: selection_rectangle = find_node_by_name(root, "SelectionRectangle") horizontal_ruler = find_node_by_name(root, "HorizontalRuler") vertical_ruler = find_node_by_name(root, "VerticalRuler") - image_clipboard = Image.new() file_menu = find_node_by_name(root, "FileMenu") edit_menu = find_node_by_name(root, "EditMenu") view_menu = find_node_by_name(root, "ViewMenu") help_menu = find_node_by_name(root, "HelpMenu") + cursor_position_label = find_node_by_name(root, "CursorPosition") + zoom_level_label = find_node_by_name(root, "ZoomLevel") left_tool_options_container = find_node_by_name(root, "LeftToolOptions") right_tool_options_container = find_node_by_name(root, "RightToolOptions") @@ -187,6 +205,9 @@ func _ready() -> void: right_brush_type_button = find_node_by_name(right_brush_type_container, "RightBrushTypeButton") left_brush_type_label = find_node_by_name(left_brush_type_container, "LeftBrushTypeLabel") right_brush_type_label = find_node_by_name(right_brush_type_container, "RightBrushTypeLabel") + brushes_popup = find_node_by_name(root, "BrushesPopup") + file_brush_container = find_node_by_name(brushes_popup, "FileBrushContainer") + project_brush_container = find_node_by_name(brushes_popup, "ProjectBrushContainer") left_brush_size_container = find_node_by_name(left_tool_options_container, "LeftBrushSize") right_brush_size_container = find_node_by_name(right_tool_options_container, "RightBrushSize") @@ -207,6 +228,9 @@ func _ready() -> void: left_mirror_container = find_node_by_name(left_tool_options_container, "LeftMirroring") right_mirror_container = find_node_by_name(right_tool_options_container, "RightMirroring") + animation_timer = find_node_by_name(root, "AnimationTimer") + + current_frame_label = find_node_by_name(root, "CurrentFrame") loop_animation_button = find_node_by_name(root, "LoopAnim") play_forward = find_node_by_name(root, "PlayForward") play_backwards = find_node_by_name(root, "PlayBackwards") @@ -217,14 +241,6 @@ func _ready() -> void: move_up_layer_button = find_node_by_name(root, "MoveUpLayer") move_down_layer_button = find_node_by_name(root, "MoveDownLayer") merge_down_layer_button = find_node_by_name(root, "MergeDownLayer") - animation_timer = find_node_by_name(root, "AnimationTimer") - cursor_position_label = find_node_by_name(root, "CursorPosition") - zoom_level_label = find_node_by_name(root, "ZoomLevel") - current_frame_label = find_node_by_name(root, "CurrentFrame") - - brushes_popup = find_node_by_name(root, "BrushesPopup") - file_brush_container = find_node_by_name(brushes_popup, "FileBrushContainer") - project_brush_container = find_node_by_name(brushes_popup, "ProjectBrushContainer") #Thanks to https://godotengine.org/qa/17524/how-to-find-an-instanced-scene-by-its-name func find_node_by_name(root, node_name) -> Node: diff --git a/Scripts/Guides.gd b/Scripts/Guides.gd index 5384524cf..4d4e2d603 100644 --- a/Scripts/Guides.gd +++ b/Scripts/Guides.gd @@ -13,7 +13,7 @@ func _ready() -> void: width = 0.1 # warning-ignore:unused_argument -func _process(delta) -> void: +func _process(delta : float) -> void: width = Global.camera.zoom.x mouse_pos = get_local_mouse_position() var point0 := points[0] diff --git a/Scripts/HorizontalRuler.gd b/Scripts/HorizontalRuler.gd index 7845731a4..7b5481b92 100644 --- a/Scripts/HorizontalRuler.gd +++ b/Scripts/HorizontalRuler.gd @@ -10,7 +10,7 @@ var first : Vector2 var last : Vector2 # warning-ignore:unused_argument -func _process(delta) -> void: +func _process(delta : float) -> void: update() #Code taken and modified from Godot's source code diff --git a/Scripts/LayerContainer.gd b/Scripts/LayerContainer.gd index c8e1f43e2..01fff5af5 100644 --- a/Scripts/LayerContainer.gd +++ b/Scripts/LayerContainer.gd @@ -5,31 +5,42 @@ var i # warning-ignore:unused_class_variable var currently_selected := false +onready var visibility_button := $HBoxContainer/VisibilityButton +onready var label := $HBoxContainer/Label +onready var line_edit := $HBoxContainer/LineEdit + func _ready() -> void: changed_selection() +func _input(event : InputEvent): + if event.is_action_released("ui_accept") && line_edit.visible: + label.visible = true + line_edit.visible = false + line_edit.editable = false + func _on_LayerContainer_pressed() -> void: var initially_pressed := pressed - var label_initially_visible : bool = $HBoxContainer/Label.visible + var label_initially_visible : bool = label.visible Global.canvas.current_layer_index = i changed_selection() if !initially_pressed: if label_initially_visible: - $HBoxContainer/Label.visible = false - $HBoxContainer/LineEdit.visible = true - $HBoxContainer/LineEdit.editable = true + label.visible = false + line_edit.visible = true + line_edit.editable = true + line_edit.grab_focus() else: - $HBoxContainer/Label.visible = true - $HBoxContainer/LineEdit.visible = false - $HBoxContainer/LineEdit.editable = false + label.visible = true + line_edit.visible = false + line_edit.editable = false func changed_selection() -> void: - var parent = get_parent() + var parent := get_parent() for child in parent.get_children(): if child is Button: - child.get_node("HBoxContainer/Label").visible = true - child.get_node("HBoxContainer/LineEdit").visible = false - child.get_node("HBoxContainer/LineEdit").editable = false + child.label.visible = true + child.line_edit.visible = false + child.line_edit.editable = false if Global.canvas.current_layer_index == child.i: child.currently_selected = true child.pressed = true @@ -58,11 +69,11 @@ func changed_selection() -> void: func _on_VisibilityButton_pressed() -> void: if Global.canvas.layers[i][3]: Global.canvas.layers[i][3] = false - get_child(0).get_child(0).texture_normal = preload("res://Assets/Graphics/Layers/layer_invisible.png") + visibility_button.texture_normal = preload("res://Assets/Graphics/Layers/layer_invisible.png") else: Global.canvas.layers[i][3] = true - get_child(0).get_child(0).texture_normal = preload("res://Assets/Graphics/Layers/layer_visible.png") + visibility_button.texture_normal = preload("res://Assets/Graphics/Layers/layer_visible.png") func _on_LineEdit_text_changed(new_text : String) -> void: Global.canvas.layers[i][2] = new_text - $HBoxContainer/Label.text = new_text + label.text = new_text \ No newline at end of file diff --git a/Scripts/Main.gd b/Scripts/Main.gd index dc6d33a83..d24b754fc 100644 --- a/Scripts/Main.gd +++ b/Scripts/Main.gd @@ -142,7 +142,7 @@ func _ready() -> void: brushes_dir.list_dir_end() Global.brushes_from_files = Global.custom_brushes.size() -func _input(event) -> void: +func _input(event : InputEvent) -> void: if event.is_action_pressed("toggle_fullscreen"): OS.window_fullscreen = !OS.window_fullscreen @@ -153,7 +153,7 @@ func _input(event) -> void: elif event.is_action_pressed(t[1]): #Shortcut for left button _on_Tool_pressed(t[0], false, true) -func _notification(what) -> void: +func _notification(what : int) -> void: if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST: #Handle exit $QuitDialog.popup_centered() Global.can_draw = false diff --git a/Scripts/SelectionRectangle.gd b/Scripts/SelectionRectangle.gd index 03858fb9c..58c225ecc 100644 --- a/Scripts/SelectionRectangle.gd +++ b/Scripts/SelectionRectangle.gd @@ -18,7 +18,7 @@ func _ready() -> void: tex.create_from_image(img, 0) # warning-ignore:unused_argument -func _process(delta) -> void: +func _process(delta : float) -> void: var mouse_pos := get_local_mouse_position() - Global.canvas.location var mouse_pos_floored := mouse_pos.floor() var start_pos := polygon[0] diff --git a/Scripts/TimelineSeconds.gd b/Scripts/TimelineSeconds.gd index 49151e735..3f1066d8f 100644 --- a/Scripts/TimelineSeconds.gd +++ b/Scripts/TimelineSeconds.gd @@ -10,7 +10,7 @@ var first : Vector2 var last : Vector2 # warning-ignore:unused_argument -func _process(delta) -> void: +func _process(delta : float) -> void: update() #Code taken and modified from Godot's source code diff --git a/Scripts/VerticalRuler.gd b/Scripts/VerticalRuler.gd index 5077cffd6..4757c4ff9 100644 --- a/Scripts/VerticalRuler.gd +++ b/Scripts/VerticalRuler.gd @@ -10,7 +10,7 @@ var first : Vector2 var last : Vector2 # warning-ignore:unused_argument -func _process(delta) -> void: +func _process(delta : float) -> void: update() #Code taken and modified from Godot's source code