Add sorting by resource and color

This commit is contained in:
don-tnowe 2022-09-22 19:28:34 +03:00
parent 1ffa77166a
commit 83d23e60c6
2 changed files with 13 additions and 2 deletions

View File

@ -134,13 +134,24 @@ func _load_resources_from_folder(folderpath : String, sort_by : String, sort_rev
func _insert_row_sorted(res : Resource, rows : Array, sort_by : String, sort_reverse : bool):
for i in rows.size():
if sort_reverse != (res.get(sort_by) < rows[i].get(sort_by)):
if sort_reverse == _compare_values(res.get(sort_by), rows[i].get(sort_by)):
rows.insert(i, res)
return
rows.append(res)
func _compare_values(a, b) -> bool:
if a == null or b == null: return b == null
if a is Color:
return a.h > b.h if a.h != b.h else a.v > b.v
if a is Resource:
return a.resource_path > b.resource_path
return a > b
func _set_sorting(sort_by):
var sort_reverse : bool = !(sorting_by != sort_by or sorting_reverse)
sorting_reverse = sort_reverse

View File

@ -80,7 +80,7 @@ func _increment_values(by : float, property : int):
func _increment_values_custom(multiplier : float, property : int):
if property == 4 || property == 5:
if property == 4 or property == 5:
# Numbered buttons increment by 5 for Sat and Value, so hue is x0.5 effect. Negate it here
multiplier *= 2.0