From 28af3e4c5b6f99f17b54b9316a1390401c196028 Mon Sep 17 00:00:00 2001 From: Greg Dreadpon Date: Fri, 3 May 2024 13:13:40 +0300 Subject: [PATCH] Implement Request #47 Add .res to open mesh dialog (and also .obj and .scn/.gltf to scene open dialog) --- .../input_fields/ui_if_thumbnail_base.gd | 27 ++++++++++++------- .../greenhouse/greenhouse.gd | 2 +- .../greenhouse/greenhouse_LOD_variant.gd | 5 ++-- .../greenhouse/greenhouse_plant.gd | 15 ++++++----- .../utility/globals.gd | 3 --- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/addons/dreadpon.spatial_gardener/controls/input_fields/ui_if_thumbnail_base.gd b/addons/dreadpon.spatial_gardener/controls/input_fields/ui_if_thumbnail_base.gd index d71f8a8..22b29ca 100644 --- a/addons/dreadpon.spatial_gardener/controls/input_fields/ui_if_thumbnail_base.gd +++ b/addons/dreadpon.spatial_gardener/controls/input_fields/ui_if_thumbnail_base.gd @@ -92,13 +92,22 @@ func _cleanup(): # Wish we could automatically infer extensions :/ func add_file_dialog_filter(): for accepted_class in accepted_classes: - var extension := "tres" - match accepted_class: - "ArrayMesh": - extension = "mesh" - "PackedScene": - extension = "tscn" - file_dialog.add_filter("*.*%s ; %s" % [extension, accepted_class]) + var extensions := "" + var ext_name := "" + var inst = accepted_class.new() + + if is_instance_of(inst, Mesh): + extensions = "*.tres, *.res, *.mesh, .*obj" + ext_name = "Mesh" + elif is_instance_of(inst, PackedScene): + extensions = "*.tscn, *.scn, *.gltf" + ext_name = "PackedScene" + elif is_instance_of(inst, Resource): + extensions = "*.tres, *.res" + ext_name = "Resource" + + if extensions != "": + file_dialog.add_filter("%s ; %s" % [extensions, ext_name]) @@ -222,8 +231,8 @@ func on_file_selected(path, thumb): var res = load(path) var found_example = false - for accepted_classe in accepted_classes: - if FunLib.obj_is_class_string(res, accepted_classe): + for accepted_class in accepted_classes: + if is_instance_of(res, accepted_class): found_example = true break diff --git a/addons/dreadpon.spatial_gardener/greenhouse/greenhouse.gd b/addons/dreadpon.spatial_gardener/greenhouse/greenhouse.gd index 0a392db..d788f5f 100644 --- a/addons/dreadpon.spatial_gardener/greenhouse/greenhouse.gd +++ b/addons/dreadpon.spatial_gardener/greenhouse/greenhouse.gd @@ -116,7 +116,7 @@ func _create_input_field(_base_control:Control, _resource_previewer, prop:String "plant_types/greenhouse_plant_states": var settings := { "add_create_inst_button": true, - "accepted_classes": ["Greenhouse_PlantState"], + "accepted_classes": [Greenhouse_PlantState], "element_display_size": 100 * FunLib.get_setting_safe("dreadpons_spatial_gardener/input_and_ui/greenhouse_thumbnail_scale", 1.0), "element_interaction_flags": UI_IF_ThumbnailArray.PRESET_PLANT_STATE, } diff --git a/addons/dreadpon.spatial_gardener/greenhouse/greenhouse_LOD_variant.gd b/addons/dreadpon.spatial_gardener/greenhouse/greenhouse_LOD_variant.gd index f215446..e74e945 100644 --- a/addons/dreadpon.spatial_gardener/greenhouse/greenhouse_LOD_variant.gd +++ b/addons/dreadpon.spatial_gardener/greenhouse/greenhouse_LOD_variant.gd @@ -37,15 +37,14 @@ func _create_input_field(_base_control:Control, _resource_previewer, prop:String match prop: "mesh": var settings := { - # Godot really needs a proper class check - "accepted_classes": Globals.MESH_CLASSES, + "accepted_classes": [Mesh], "element_display_size": 75 * FunLib.get_setting_safe("dreadpons_spatial_gardener/input_and_ui/greenhouse_thumbnail_scale", 1.0), "element_interaction_flags": UI_IF_ThumbnailArray.PRESET_RESOURCE, } input_field = UI_IF_ThumbnailObject.new(mesh, "Mesh", prop, settings) "spawned_spatial": var settings := { - "accepted_classes": ["PackedScene"], + "accepted_classes": [PackedScene], "element_display_size": 75 * FunLib.get_setting_safe("dreadpons_spatial_gardener/input_and_ui/greenhouse_thumbnail_scale", 1.0), "element_interaction_flags": UI_IF_ThumbnailArray.PRESET_RESOURCE, } diff --git a/addons/dreadpon.spatial_gardener/greenhouse/greenhouse_plant.gd b/addons/dreadpon.spatial_gardener/greenhouse/greenhouse_plant.gd index 4b02640..c2ab2db 100644 --- a/addons/dreadpon.spatial_gardener/greenhouse/greenhouse_plant.gd +++ b/addons/dreadpon.spatial_gardener/greenhouse/greenhouse_plant.gd @@ -132,8 +132,7 @@ func _create_input_field(_base_control:Control, _resource_previewer, prop:String var input_field:UI_InputField = null match prop: "mesh/mesh_LOD_variants": - var accepted_classes := ["Greenhouse_LODVariant", "PackedScene"] - accepted_classes.append_array(Globals.MESH_CLASSES) + var accepted_classes := [Greenhouse_LODVariant, PackedScene, Mesh] var settings := { "add_create_inst_button": true, "accepted_classes": accepted_classes, @@ -429,11 +428,13 @@ func request_prop_action(prop_action:PropAction): var new_prop_action = null if is_instance_of(prop_action.val, PackedScene): new_prop_action = PA_PropSet.new("spawned_spatial", prop_action.val) - else: - for mesh_class in Globals.MESH_CLASSES: - if FunLib.obj_is_class_string(prop_action.val, mesh_class): - new_prop_action = PA_PropSet.new("mesh", prop_action.val) - break + elif is_instance_of(prop_action.val, Mesh): + new_prop_action = PA_PropSet.new("mesh", prop_action.val) + # else: + # for mesh_class in Globals.MESH_CLASSES: + # if FunLib.obj_is_class_string(prop_action.val, mesh_class): + # new_prop_action = PA_PropSet.new("mesh", prop_action.val) + # break if new_prop_action != null: mesh_LOD_variants[prop_action.index].request_prop_action(new_prop_action) diff --git a/addons/dreadpon.spatial_gardener/utility/globals.gd b/addons/dreadpon.spatial_gardener/utility/globals.gd index 59bb9fd..691987a 100644 --- a/addons/dreadpon.spatial_gardener/utility/globals.gd +++ b/addons/dreadpon.spatial_gardener/utility/globals.gd @@ -29,9 +29,6 @@ static func get_err_message(err_code): -# All accepted mesh classes in string format -const MESH_CLASSES:Array = ["ArrayMesh", "CapsuleMesh", "BoxMesh", "CylinderMesh", "PlaneMesh", "PointMesh", "PrismMesh", "QuadMesh", "SphereMesh"] - # Controls per how many units is density calculated const PLANT_DENSITY_UNITS:int = 100