From 9b73e4f66111f7ba23f3a85a9fc83ac5e494dea0 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Thu, 26 Dec 2019 02:01:04 +0200 Subject: [PATCH] Edit palette fixes - If the palette has colors, automatically select the first one - When adding a new color button, take the color currently selected on the picker instead of white - Fixes issues with drag&dropping color buttons. The color that was dragged remains selected. --- Main.tscn | 2 ++ Prefabs/EditPalettePopup.tscn | 1 - Prefabs/PaletteButton.tscn | 2 +- Scripts/Palette/EditPalettePopup.gd | 16 +++++++++++----- Scripts/Palette/Palette.gd | 7 +++---- Scripts/Palette/PaletteButton.gd | 1 - Scripts/Palette/PaletteContainer.gd | 8 ++------ Scripts/{ => Rulers}/Guides.gd | 0 project.godot | 2 +- 9 files changed, 20 insertions(+), 19 deletions(-) rename Scripts/{ => Rulers}/Guides.gd (100%) diff --git a/Main.tscn b/Main.tscn index efd021958..24e08c3d2 100644 --- a/Main.tscn +++ b/Main.tscn @@ -250,6 +250,7 @@ text = "[64×64]" align = 2 [node name="UI" type="HBoxContainer" parent="MenuAndUI"] +editor/display_folded = true margin_top = 28.0 margin_right = 1152.0 margin_bottom = 648.0 @@ -580,6 +581,7 @@ text = "Brush color from" margin_left = 94.0 margin_right = 149.0 margin_bottom = 17.0 +hint_tooltip = "COLORFROM_HT" size_flags_horizontal = 3 size_flags_vertical = 1 value = 100.0 diff --git a/Prefabs/EditPalettePopup.tscn b/Prefabs/EditPalettePopup.tscn index 275a33d18..cdfd654ca 100644 --- a/Prefabs/EditPalettePopup.tscn +++ b/Prefabs/EditPalettePopup.tscn @@ -6,7 +6,6 @@ [ext_resource path="res://Assets/Graphics/Palette/remove_swatch_button.png" type="Texture" id=4] [ext_resource path="res://Assets/Graphics/Palette/remove_swatch_button_hover.png" type="Texture" id=5] - [node name="EditPalettePopup" type="WindowDialog"] visible = true margin_right = 600.0 diff --git a/Prefabs/PaletteButton.tscn b/Prefabs/PaletteButton.tscn index ea268349c..f009d8e90 100644 --- a/Prefabs/PaletteButton.tscn +++ b/Prefabs/PaletteButton.tscn @@ -7,7 +7,6 @@ [ext_resource path="res://Scripts/Palette/PaletteButton.gd" type="Script" id=5] [ext_resource path="res://Assets/Graphics/Palette/palette_button_fill.png" type="Texture" id=6] - [sub_resource type="ImageTexture" id=1] [node name="PaletteButton" type="Button"] @@ -19,6 +18,7 @@ custom_styles/hover = ExtResource( 1 ) custom_styles/pressed = ExtResource( 2 ) custom_styles/focus = ExtResource( 3 ) custom_styles/normal = ExtResource( 4 ) +action_mode = 0 button_mask = 3 icon = SubResource( 1 ) script = ExtResource( 5 ) diff --git a/Scripts/Palette/EditPalettePopup.gd b/Scripts/Palette/EditPalettePopup.gd index c78750245..86f5485a7 100644 --- a/Scripts/Palette/EditPalettePopup.gd +++ b/Scripts/Palette/EditPalettePopup.gd @@ -33,26 +33,32 @@ func _display_palette() -> void: new_button.draggable = true new_button.index = index new_button.connect("on_drop_data", self, "on_move_swatch") - new_button.connect("pressed", self, "on_swatch_select", [index]) + new_button.connect("pressed", self, "on_swatch_select", [new_button]) palette_grid.add_child(new_button) index += 1 + if index > 0: # If there are colors, select the first + current_swatch = 0 + color_name_edit.text = working_palette.get_color_name(0) + color_picker.color = working_palette.get_color(0) + func _clear_swatches() -> void: for child in palette_grid.get_children(): if child is BaseButton: child.disconnect("on_drop_data", self, "on_move_swatch") child.queue_free() -func on_swatch_select(index : int) -> void: +func on_swatch_select(new_button) -> void: + var index : int = new_button.index current_swatch = index color_name_edit.text = working_palette.get_color_name(index) color_picker.color = working_palette.get_color(index) func on_move_swatch(from : int, to : int) -> void: working_palette.move_color(from, to) - palette_grid.move_child(palette_grid.get_child(from), to) + current_swatch = to # Re-index swatches with new order var index := 0 @@ -61,7 +67,7 @@ func on_move_swatch(from : int, to : int) -> void: index += 1 func _on_AddSwatchButton_pressed() -> void: - var color = Color.white + var color : Color = color_picker.color var new_index : int = working_palette.colors.size() working_palette.add_color(color) @@ -96,7 +102,7 @@ func _on_EditPaletteColorNameLineEdit_text_changed(new_text) -> void: working_palette.set_color_name(current_swatch, new_text) _refresh_hint_tooltip(current_swatch) -func _on_EditPaletteColorPicker_color_changed(color) -> void: +func _on_EditPaletteColorPicker_color_changed(color : Color) -> void: if current_swatch >= 0 && current_swatch < working_palette.colors.size(): palette_grid.get_child(current_swatch).get_child(0).modulate = color working_palette.set_color(current_swatch, color) diff --git a/Scripts/Palette/Palette.gd b/Scripts/Palette/Palette.gd index 9fb0bc2f0..62fcaf08a 100644 --- a/Scripts/Palette/Palette.gd +++ b/Scripts/Palette/Palette.gd @@ -12,13 +12,12 @@ var comments : String = "" var editable : bool = true func insert_color(index : int, new_color : Color, _name : String = "no name") -> void: - if index < colors.size(): + if index <= colors.size(): var c := PaletteColor.new(new_color, _name) colors.insert(index, c) func add_color(new_color : Color, _name : String = "no name") -> void: var c := PaletteColor.new(new_color, _name) - colors.push_back(c) func remove_color(index : int) -> void: @@ -101,7 +100,7 @@ func deserialize(input_string : String) -> Palette: var result = get_script().new() var result_json = JSON.parse(input_string) -# + if result_json.error != OK: # If parse has errors print("Error: ", result_json.error) print("Error Line: ", result_json.error_line) @@ -109,7 +108,7 @@ func deserialize(input_string : String) -> Palette: result = null else: # If parse OK var data = result_json.result - if data.has("name"): #If data is 'valid' palette file + if data.has("name"): # If data is 'valid' palette file result = get_script().new() result.name = data.name if data.has("comments"): diff --git a/Scripts/Palette/PaletteButton.gd b/Scripts/Palette/PaletteButton.gd index 72e9b8525..eaf176dab 100644 --- a/Scripts/Palette/PaletteButton.gd +++ b/Scripts/Palette/PaletteButton.gd @@ -23,4 +23,3 @@ func can_drop_data(position, data): func drop_data(position, data): emit_signal("on_drop_data", data.source_index, index); - pass; diff --git a/Scripts/Palette/PaletteContainer.gd b/Scripts/Palette/PaletteContainer.gd index 036e9d397..5b7ac2d39 100644 --- a/Scripts/Palette/PaletteContainer.gd +++ b/Scripts/Palette/PaletteContainer.gd @@ -38,11 +38,9 @@ func on_new_empty_palette() -> void: Global.new_palette_name_line_edit.text = "Custom_Palette" from_palette = null Global.new_palette_dialog.popup_centered() - pass func on_import_palette() -> void: Global.palette_import_file_dialog.popup_centered() - pass func on_palette_import_file_selected(path) -> void: var file := File.new() @@ -67,7 +65,6 @@ func on_palette_import_file_selected(path) -> void: else: Global.error_dialog.set_text("Invalid Palette file!") Global.error_dialog.popup_centered() - pass func on_edit_palette() -> void: var palette : Dictionary = Global.palettes[current_palette] @@ -138,10 +135,10 @@ func _display_palette(palette : Palette) -> void: func on_color_select(index : int) -> void: var color : Color = Global.palettes[current_palette].get_color(index) - if Input.is_action_just_released("left_mouse"): + if Input.is_action_just_pressed("left_mouse"): Global.left_color_picker.color = color Global.update_left_custom_brush() - elif Input.is_action_just_released("right_mouse"): + elif Input.is_action_just_pressed("right_mouse"): Global.right_color_picker.color = color Global.update_right_custom_brush() @@ -208,7 +205,6 @@ func remove_current_palette() -> void: if(selected_index - 1 >= 0): Global.palette_option_button.select(selected_index - 1) on_palette_select(Global.palette_option_button.get_item_metadata(selected_index - 1)) - pass func _delete_palette_file(file_name : String) -> void: var dir = Directory.new() diff --git a/Scripts/Guides.gd b/Scripts/Rulers/Guides.gd similarity index 100% rename from Scripts/Guides.gd rename to Scripts/Rulers/Guides.gd diff --git a/project.godot b/project.godot index 4fc4d2860..130a7319b 100644 --- a/project.godot +++ b/project.godot @@ -17,7 +17,7 @@ _global_script_classes=[ { "base": "Line2D", "class": "Guide", "language": "GDScript", -"path": "res://Scripts/Guides.gd" +"path": "res://Scripts/Rulers/Guides.gd" }, { "base": "Button", "class": "LayerContainer",