From 83d23e60c650ce5a6bfb9ec440b3a18a9857c5b7 Mon Sep 17 00:00:00 2001 From: don-tnowe <67479453+don-tnowe@users.noreply.github.com> Date: Thu, 22 Sep 2022 19:28:34 +0300 Subject: [PATCH] Add sorting by resource and color --- addons/resources_speadsheet_view/editor_view.gd | 13 ++++++++++++- .../typed_editors/dock_color.gd | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/addons/resources_speadsheet_view/editor_view.gd b/addons/resources_speadsheet_view/editor_view.gd index e4b94e4..9008790 100644 --- a/addons/resources_speadsheet_view/editor_view.gd +++ b/addons/resources_speadsheet_view/editor_view.gd @@ -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 diff --git a/addons/resources_speadsheet_view/typed_editors/dock_color.gd b/addons/resources_speadsheet_view/typed_editors/dock_color.gd index d920528..5c1e6b3 100644 --- a/addons/resources_speadsheet_view/typed_editors/dock_color.gd +++ b/addons/resources_speadsheet_view/typed_editors/dock_color.gd @@ -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