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:
parent
01b55aca07
commit
8b1367494d
|
@ -36,8 +36,9 @@ func does_palette_exist(palette_name: String) -> bool:
|
|||
|
||||
|
||||
func select_palette(palette_name: String) -> void:
|
||||
current_palette = palettes.get(palette_name)
|
||||
current_palette = palettes.get(palette_name, null)
|
||||
_clear_selected_colors()
|
||||
if is_instance_valid(current_palette):
|
||||
Global.config_cache.set_value("data", "last_palette", current_palette.name)
|
||||
palette_selected.emit(palette_name)
|
||||
|
||||
|
@ -224,6 +225,7 @@ func current_palete_delete(permanent := true) -> void:
|
|||
select_palette(palettes.keys()[0])
|
||||
else:
|
||||
current_palette = null
|
||||
select_palette("")
|
||||
|
||||
|
||||
func current_palette_add_color(mouse_button: int, start_index := 0) -> void:
|
||||
|
|
|
@ -23,10 +23,6 @@ func _ready() -> void:
|
|||
|
||||
|
||||
func set_palette(new_palette: Palette) -> void:
|
||||
# Only display valid palette objects
|
||||
if not new_palette:
|
||||
return
|
||||
|
||||
current_palette = new_palette
|
||||
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
|
||||
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 old_index := convert_palette_index_to_grid_index(old_palette_index)
|
||||
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:
|
||||
if not is_instance_valid(current_palette):
|
||||
return
|
||||
var grid_x: int = (
|
||||
new_rect_size.x / (swatch_size.x + get("theme_override_constants/h_separation"))
|
||||
)
|
||||
var grid_y: int = (
|
||||
new_rect_size.y / (swatch_size.y + get("theme_override_constants/v_separation"))
|
||||
)
|
||||
if is_instance_valid(current_palette):
|
||||
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()
|
||||
draw_palette()
|
||||
|
||||
|
|
|
@ -115,6 +115,8 @@ func redraw_current_palette() -> 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()
|
||||
if add_color_button.disabled:
|
||||
add_color_button.mouse_default_cursor_shape = CURSOR_FORBIDDEN
|
||||
|
|
|
@ -4,9 +4,9 @@ var scroll := Vector2i.ZERO
|
|||
var drag_started := false
|
||||
var drag_start_position := Vector2i.ZERO
|
||||
|
||||
@onready var h_slider := %HScrollBar
|
||||
@onready var v_slider := %VScrollBar
|
||||
@onready var palette_grid := %PaletteGrid
|
||||
@onready var h_slider := %HScrollBar as HScrollBar
|
||||
@onready var v_slider := %VScrollBar as VScrollBar
|
||||
@onready var palette_grid := %PaletteGrid as PaletteGrid
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
|
@ -17,16 +17,21 @@ func _input(event: InputEvent) -> void:
|
|||
|
||||
|
||||
func set_sliders(palette: Palette, origin: Vector2i) -> void:
|
||||
if not is_instance_valid(palette):
|
||||
return
|
||||
if is_instance_valid(palette):
|
||||
h_slider.value = origin.x
|
||||
h_slider.max_value = palette.width
|
||||
h_slider.page = palette_grid.grid_size.x
|
||||
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
|
||||
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
|
||||
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
|
||||
# Keeps position where the dragging started
|
||||
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:
|
||||
|
|
Loading…
Reference in a new issue