1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 09:09:47 +00:00

Ensure that the swatches get deleted when the user removes all palettes

This commit is contained in:
Emmanouil Papadeas 2024-11-23 17:54:28 +02:00
parent 01b55aca07
commit 8b1367494d
4 changed files with 39 additions and 31 deletions

View file

@ -36,9 +36,10 @@ func does_palette_exist(palette_name: String) -> bool:
func select_palette(palette_name: String) -> void: func select_palette(palette_name: String) -> void:
current_palette = palettes.get(palette_name) current_palette = palettes.get(palette_name, null)
_clear_selected_colors() _clear_selected_colors()
Global.config_cache.set_value("data", "last_palette", current_palette.name) if is_instance_valid(current_palette):
Global.config_cache.set_value("data", "last_palette", current_palette.name)
palette_selected.emit(palette_name) palette_selected.emit(palette_name)
@ -224,6 +225,7 @@ func current_palete_delete(permanent := true) -> void:
select_palette(palettes.keys()[0]) select_palette(palettes.keys()[0])
else: else:
current_palette = null current_palette = null
select_palette("")
func current_palette_add_color(mouse_button: int, start_index := 0) -> void: func current_palette_add_color(mouse_button: int, start_index := 0) -> void:

View file

@ -23,10 +23,6 @@ func _ready() -> void:
func set_palette(new_palette: Palette) -> void: func set_palette(new_palette: Palette) -> void:
# Only display valid palette objects
if not new_palette:
return
current_palette = new_palette current_palette = new_palette
grid_window_origin = Vector2.ZERO grid_window_origin = Vector2.ZERO
@ -117,6 +113,8 @@ func find_and_select_color(target_color: Color, mouse_button: int) -> void:
## Displays a left/right highlight over a swatch ## Displays a left/right highlight over a swatch
func select_swatch(mouse_button: int, palette_index: int, old_palette_index: int) -> void: func select_swatch(mouse_button: int, palette_index: int, old_palette_index: int) -> void:
if not is_instance_valid(current_palette):
return
var index := convert_palette_index_to_grid_index(palette_index) var index := convert_palette_index_to_grid_index(palette_index)
var old_index := convert_palette_index_to_grid_index(old_palette_index) var old_index := convert_palette_index_to_grid_index(old_palette_index)
if index >= 0 and index < swatches.size(): if index >= 0 and index < swatches.size():
@ -161,16 +159,17 @@ func convert_palette_index_to_grid_index(palette_index: int) -> int:
func resize_grid(new_rect_size: Vector2) -> void: func resize_grid(new_rect_size: Vector2) -> void:
if not is_instance_valid(current_palette):
return
var grid_x: int = ( var grid_x: int = (
new_rect_size.x / (swatch_size.x + get("theme_override_constants/h_separation")) new_rect_size.x / (swatch_size.x + get("theme_override_constants/h_separation"))
) )
var grid_y: int = ( var grid_y: int = (
new_rect_size.y / (swatch_size.y + get("theme_override_constants/v_separation")) new_rect_size.y / (swatch_size.y + get("theme_override_constants/v_separation"))
) )
grid_size.x = mini(grid_x, current_palette.width) if is_instance_valid(current_palette):
grid_size.y = mini(grid_y, current_palette.height) grid_size.x = mini(grid_x, current_palette.width)
grid_size.y = mini(grid_y, current_palette.height)
else:
grid_size = Vector2i.ZERO
setup_swatches() setup_swatches()
draw_palette() draw_palette()

View file

@ -89,16 +89,16 @@ func select_palette(palette_name: String) -> void:
var palette_id = palettes_path_id.get(palette_name) var palette_id = palettes_path_id.get(palette_name)
if palette_id != null: if palette_id != null:
palette_select.selected = palette_id palette_select.selected = palette_id
palette_grid.set_palette(Palettes.current_palette) palette_grid.set_palette(Palettes.current_palette)
palette_scroll.resize_grid() palette_scroll.resize_grid()
palette_scroll.set_sliders(Palettes.current_palette, palette_grid.grid_window_origin) palette_scroll.set_sliders(Palettes.current_palette, palette_grid.grid_window_origin)
var left_selected := Palettes.current_palette_get_selected_color_index(MOUSE_BUTTON_LEFT) var left_selected := Palettes.current_palette_get_selected_color_index(MOUSE_BUTTON_LEFT)
var right_selected := Palettes.current_palette_get_selected_color_index(MOUSE_BUTTON_RIGHT) var right_selected := Palettes.current_palette_get_selected_color_index(MOUSE_BUTTON_RIGHT)
palette_grid.select_swatch(MOUSE_BUTTON_LEFT, left_selected, left_selected) palette_grid.select_swatch(MOUSE_BUTTON_LEFT, left_selected, left_selected)
palette_grid.select_swatch(MOUSE_BUTTON_RIGHT, right_selected, right_selected) palette_grid.select_swatch(MOUSE_BUTTON_RIGHT, right_selected, right_selected)
toggle_add_delete_buttons() toggle_add_delete_buttons()
## Select and display current palette ## Select and display current palette
@ -115,6 +115,8 @@ func redraw_current_palette() -> void:
func toggle_add_delete_buttons() -> void: func toggle_add_delete_buttons() -> void:
if not is_instance_valid(Palettes.current_palette):
return
add_color_button.disabled = Palettes.current_palette.is_full() add_color_button.disabled = Palettes.current_palette.is_full()
if add_color_button.disabled: if add_color_button.disabled:
add_color_button.mouse_default_cursor_shape = CURSOR_FORBIDDEN add_color_button.mouse_default_cursor_shape = CURSOR_FORBIDDEN

View file

@ -4,9 +4,9 @@ var scroll := Vector2i.ZERO
var drag_started := false var drag_started := false
var drag_start_position := Vector2i.ZERO var drag_start_position := Vector2i.ZERO
@onready var h_slider := %HScrollBar @onready var h_slider := %HScrollBar as HScrollBar
@onready var v_slider := %VScrollBar @onready var v_slider := %VScrollBar as VScrollBar
@onready var palette_grid := %PaletteGrid @onready var palette_grid := %PaletteGrid as PaletteGrid
func _input(event: InputEvent) -> void: func _input(event: InputEvent) -> void:
@ -17,16 +17,21 @@ func _input(event: InputEvent) -> void:
func set_sliders(palette: Palette, origin: Vector2i) -> void: func set_sliders(palette: Palette, origin: Vector2i) -> void:
if not is_instance_valid(palette): if is_instance_valid(palette):
return h_slider.value = origin.x
h_slider.value = origin.x h_slider.max_value = palette.width
h_slider.max_value = palette.width h_slider.page = palette_grid.grid_size.x
h_slider.page = palette_grid.grid_size.x v_slider.value = origin.y
v_slider.max_value = palette.height
v_slider.page = palette_grid.grid_size.y
else:
h_slider.value = 0
h_slider.max_value = 0
h_slider.page = 0
v_slider.value = 0
v_slider.max_value = 0
v_slider.page = 0
h_slider.visible = false if h_slider.max_value <= palette_grid.grid_size.x else true h_slider.visible = false if h_slider.max_value <= palette_grid.grid_size.x else true
v_slider.value = origin.y
v_slider.max_value = palette.height
v_slider.page = palette_grid.grid_size.y
v_slider.visible = false if v_slider.max_value <= palette_grid.grid_size.y else true v_slider.visible = false if v_slider.max_value <= palette_grid.grid_size.y else true
@ -58,7 +63,7 @@ func _on_PaletteGrid_gui_input(event: InputEvent) -> void:
drag_started = true drag_started = true
# Keeps position where the dragging started # Keeps position where the dragging started
drag_start_position = ( drag_start_position = (
event.position + Vector2i(h_slider.value, v_slider.value) * palette_grid.swatch_size event.position + Vector2(h_slider.value, v_slider.value) * palette_grid.swatch_size
) )
if event is InputEventMouseMotion and drag_started: if event is InputEventMouseMotion and drag_started: