From c64c3408e89d7d02f5593ee984a736187ec309f6 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Wed, 23 Oct 2019 02:54:29 +0300 Subject: [PATCH] Added two new tools, Paint all pixels of same color and lighten/darken - Paint all pixels of same color tool added. Does what it says. - Lighten/darken tool. It lightens by default, darkens when user is pressing Ctrl. - Removed tool variables from main - stored everything in an array instead. --- Main.tscn | 31 ++++++++++++++++++++++++++++--- Scripts/Canvas.gd | 24 ++++++++++++++++++++++++ Scripts/Main.gd | 44 +++++++++++++++----------------------------- project.godot | 20 ++++++++++++++++++++ 4 files changed, 87 insertions(+), 32 deletions(-) diff --git a/Main.tscn b/Main.tscn index 38e767db9..e773a9e72 100644 --- a/Main.tscn +++ b/Main.tscn @@ -34,7 +34,6 @@ size_flags_horizontal = 3 size_flags_vertical = 3 [node name="MenusAndTools" type="VBoxContainer" parent="UI/ToolPanel/Tools"] -editor/display_folded = true margin_right = 230.0 margin_bottom = 266.0 size_flags_vertical = 3 @@ -117,12 +116,38 @@ mouse_default_cursor_shape = 2 button_mask = 3 text = "Bucket" -[node name="SelectionToolsContainer" type="HBoxContainer" parent="UI/ToolPanel/Tools/MenusAndTools"] +[node name="ColorToolsContainer" type="HBoxContainer" parent="UI/ToolPanel/Tools/MenusAndTools"] margin_top = 48.0 margin_right = 230.0 margin_bottom = 68.0 -[node name="RectSelect" type="Button" parent="UI/ToolPanel/Tools/MenusAndTools/SelectionToolsContainer"] +[node name="PaintAllPixelsSameColor" type="Button" parent="UI/ToolPanel/Tools/MenusAndTools/ColorToolsContainer"] +margin_right = 112.0 +margin_bottom = 20.0 +hint_tooltip = "Paint all pixels of the same color +A for left mouse button +Alt + A for right mouse button" +mouse_default_cursor_shape = 2 +button_mask = 3 +text = "PaintSameColor" + +[node name="LightenDarken" type="Button" parent="UI/ToolPanel/Tools/MenusAndTools/ColorToolsContainer"] +margin_left = 116.0 +margin_right = 225.0 +margin_bottom = 20.0 +hint_tooltip = "U for left mouse button +Alt + U for right mouse button +Ctrl to Darken" +mouse_default_cursor_shape = 2 +button_mask = 3 +text = "Lighten/Darken" + +[node name="SelectionToolsContainer2" type="HBoxContainer" parent="UI/ToolPanel/Tools/MenusAndTools"] +margin_top = 72.0 +margin_right = 230.0 +margin_bottom = 92.0 + +[node name="RectSelect" type="Button" parent="UI/ToolPanel/Tools/MenusAndTools/SelectionToolsContainer2"] margin_right = 79.0 margin_bottom = 20.0 hint_tooltip = "R for left mouse button diff --git a/Scripts/Canvas.gd b/Scripts/Canvas.gd index 76ca7d29d..93e18a5cc 100644 --- a/Scripts/Canvas.gd +++ b/Scripts/Canvas.gd @@ -110,6 +110,30 @@ func _process(delta) -> void: elif current_mouse_button == "right_mouse": current_color = Global.right_color_picker.color flood_fill(mouse_pos, layers[current_layer_index][0].get_pixelv(mouse_pos), current_color) + "PaintAllPixelsSameColor": + if point_in_rectangle(mouse_pos, location, location + size): + var current_color : Color + if current_mouse_button == "left_mouse": + current_color = Global.left_color_picker.color + elif current_mouse_button == "right_mouse": + current_color = Global.right_color_picker.color + + var pixel_color : Color = layers[current_layer_index][0].get_pixelv(mouse_pos) + for xx in size.x: + for yy in size.y: + var c : Color = layers[current_layer_index][0].get_pixel(xx, yy) + if c == pixel_color: + layers[current_layer_index][0].set_pixel(xx, yy, current_color) + sprite_changed_this_frame = true + "LightenDarken": + if point_in_rectangle(mouse_pos, location, location + size): + var pixel_color : Color = layers[current_layer_index][0].get_pixelv(mouse_pos) + var amount := 0.05 + var color_changed := pixel_color.lightened(amount) + if Input.is_key_pressed(KEY_CONTROL): + color_changed = pixel_color.darkened(amount) + layers[current_layer_index][0].set_pixelv(mouse_pos, color_changed) + sprite_changed_this_frame = true "RectSelect": #Check SelectionRectangle.gd for more code on Rectangle Selection if Global.can_draw && Global.has_focus && Global.current_frame == frame: diff --git a/Scripts/Main.gd b/Scripts/Main.gd index e51722b00..fd6a7182f 100644 --- a/Scripts/Main.gd +++ b/Scripts/Main.gd @@ -4,10 +4,7 @@ var current_save_path := "" var current_export_path := "" var opensprite_file_selected := false var view_menu : PopupMenu -var pencil_tool -var eraser_tool -var fill_tool -var rectselect_tool +var tools := [] var import_as_new_frame : CheckBox var export_all_frames : CheckBox var export_as_single_file : CheckBox @@ -75,15 +72,16 @@ func _ready() -> void: help_menu.connect("id_pressed", self, "help_menu_id_pressed") var root = get_tree().get_root() - pencil_tool = Global.find_node_by_name(root, "Pencil") - eraser_tool = Global.find_node_by_name(root, "Eraser") - fill_tool = Global.find_node_by_name(root, "Fill") - rectselect_tool = Global.find_node_by_name(root, "RectSelect") + #Node, left mouse shortcut, right mouse shortcut + tools.append([Global.find_node_by_name(root, "Pencil"), "left_pencil_tool", "right_pencil_tool"]) + tools.append([Global.find_node_by_name(root, "Eraser"), "left_eraser_tool", "right_eraser_tool"]) + tools.append([Global.find_node_by_name(root, "Fill"), "left_fill_tool", "right_fill_tool"]) + tools.append([Global.find_node_by_name(root, "PaintAllPixelsSameColor"), "left_paint_all_tool", "right_paint_all_tool"]) + tools.append([Global.find_node_by_name(root, "LightenDarken"), "left_lightdark_tool", "right_lightdark_tool"]) + tools.append([Global.find_node_by_name(root, "RectSelect"), "left_rectangle_select_tool", "right_rectangle_select_tool"]) - pencil_tool.connect("pressed", self, "_on_Tool_pressed", [pencil_tool]) - eraser_tool.connect("pressed", self, "_on_Tool_pressed", [eraser_tool]) - fill_tool.connect("pressed", self, "_on_Tool_pressed", [fill_tool]) - rectselect_tool.connect("pressed", self, "_on_Tool_pressed", [rectselect_tool]) + for t in tools: + t[0].connect("pressed", self, "_on_Tool_pressed", [t[0]]) #Options for Import import_as_new_frame = CheckBox.new() @@ -103,23 +101,11 @@ func _ready() -> void: func _input(event): - #Handle tool shortcuts - if event.is_action_pressed("right_pencil_tool"): - _on_Tool_pressed(pencil_tool, false, false) - elif event.is_action_pressed("left_pencil_tool"): - _on_Tool_pressed(pencil_tool, false, true) - elif event.is_action_pressed("right_eraser_tool"): - _on_Tool_pressed(eraser_tool, false, false) - elif event.is_action_pressed("left_eraser_tool"): - _on_Tool_pressed(eraser_tool, false, true) - elif event.is_action_pressed("right_fill_tool"): - _on_Tool_pressed(fill_tool, false, false) - elif event.is_action_pressed("left_fill_tool"): - _on_Tool_pressed(fill_tool, false, true) - elif event.is_action_pressed("right_rectangle_select_tool"): - _on_Tool_pressed(rectselect_tool, false, false) - elif event.is_action_pressed("left_rectangle_select_tool"): - _on_Tool_pressed(rectselect_tool, false, true) + for t in tools: #Handle tool shortcuts + if event.is_action_pressed(t[2]): #Shortcut for right button (with Alt) + _on_Tool_pressed(t[0], false, false) + elif event.is_action_pressed(t[1]): #Shortcut for left button + _on_Tool_pressed(t[0], false, true) func file_menu_id_pressed(id : int) -> void: match id: diff --git a/project.godot b/project.godot index c2c4da199..e1f8e30c1 100644 --- a/project.godot +++ b/project.godot @@ -117,6 +117,26 @@ paste={ "events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":86,"unicode":0,"echo":false,"script":null) ] } +left_paint_all_tool={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null) + ] +} +right_paint_all_tool={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":true,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null) + ] +} +left_lightdark_tool={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":85,"unicode":0,"echo":false,"script":null) + ] +} +right_lightdark_tool={ +"deadzone": 0.5, +"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":true,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":85,"unicode":0,"echo":false,"script":null) + ] +} [rendering]