1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-13 01:03:07 +00:00

Fixed more than one swatch selected if there is the same color available in an earlier swatch

This commit is contained in:
Variable 2024-11-26 14:47:59 +05:00
parent adbeec12f8
commit b8c04e83c9
3 changed files with 8 additions and 4 deletions

View file

@ -296,13 +296,14 @@ func current_palette_select_color(mouse_button: int, index: int) -> void:
if color == null: if color == null:
return return
_select_color(mouse_button, index)
match mouse_button: match mouse_button:
MOUSE_BUTTON_LEFT: MOUSE_BUTTON_LEFT:
Tools.assign_color(color, mouse_button) Tools.assign_color(color, mouse_button)
MOUSE_BUTTON_RIGHT: MOUSE_BUTTON_RIGHT:
Tools.assign_color(color, mouse_button) Tools.assign_color(color, mouse_button)
_select_color(mouse_button, index)
func _select_color(mouse_button: int, index: int) -> void: func _select_color(mouse_button: int, index: int) -> void:

View file

@ -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]. ## 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. ## 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: func find_and_select_color(target_color: Color, mouse_button: int) -> void:
if not is_instance_valid(current_palette): if not is_instance_valid(current_palette):
return 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(): for color_ind in swatches.size():
if ( if (
target_color.is_equal_approx(swatches[color_ind].color) target_color.is_equal_approx(swatches[color_ind].color)
or target_color.to_html() == swatches[color_ind].color.to_html() or target_color.to_html() == swatches[color_ind].color.to_html()
): ):
var index := convert_grid_index_to_palette_index(color_ind) 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: match mouse_button:
MOUSE_BUTTON_LEFT: MOUSE_BUTTON_LEFT:
Palettes.left_selected_color = index Palettes.left_selected_color = index