From b8c04e83c95050330a1ea917074524132896f987 Mon Sep 17 00:00:00 2001 From: Variable Date: Tue, 26 Nov 2024 14:47:59 +0500 Subject: [PATCH] Fixed more than one swatch selected if there is the same color available in an earlier swatch --- src/Autoload/Global.gd | 2 +- src/Autoload/Palettes.gd | 3 ++- src/Palette/PaletteGrid.gd | 7 +++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index bae48c0bc..fbdb41f9a 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -756,7 +756,7 @@ func _ready() -> void: Global.use_native_file_dialogs = true await get_tree().process_frame project_switched.emit() - canvas.color_index.enabled = show_pixel_indices # Initialize color index preview + canvas.color_index.enabled = show_pixel_indices # Initialize color index preview func update_grids(grids_data: Dictionary): diff --git a/src/Autoload/Palettes.gd b/src/Autoload/Palettes.gd index eef4abab6..a472e30db 100644 --- a/src/Autoload/Palettes.gd +++ b/src/Autoload/Palettes.gd @@ -296,13 +296,14 @@ func current_palette_select_color(mouse_button: int, index: int) -> void: if color == null: return + _select_color(mouse_button, index) + match mouse_button: MOUSE_BUTTON_LEFT: Tools.assign_color(color, mouse_button) MOUSE_BUTTON_RIGHT: Tools.assign_color(color, mouse_button) - _select_color(mouse_button, index) func _select_color(mouse_button: int, index: int) -> void: diff --git a/src/Palette/PaletteGrid.gd b/src/Palette/PaletteGrid.gd index 66bb92c46..abe894482 100644 --- a/src/Palette/PaletteGrid.gd +++ b/src/Palette/PaletteGrid.gd @@ -82,17 +82,20 @@ func scroll_palette(origin: Vector2i) -> void: ## Called when the color changes, either the left or the right, determined by [param mouse_button]. ## If current palette has [param target_color] as a [Color], then select it. +## This is helpful when we select color indirectly (e.g through colorpicker) func find_and_select_color(target_color: Color, mouse_button: int) -> void: if not is_instance_valid(current_palette): return - var old_index := Palettes.current_palette_get_selected_color_index(mouse_button) + var selected_index := Palettes.current_palette_get_selected_color_index(mouse_button) + if get_swatch_color(selected_index) == target_color: # Color already selected + return for color_ind in swatches.size(): if ( target_color.is_equal_approx(swatches[color_ind].color) or target_color.to_html() == swatches[color_ind].color.to_html() ): var index := convert_grid_index_to_palette_index(color_ind) - select_swatch(mouse_button, index, old_index) + select_swatch(mouse_button, index, selected_index) match mouse_button: MOUSE_BUTTON_LEFT: Palettes.left_selected_color = index