diff --git a/addons/pandora/icons/Texture2D.svg b/addons/pandora/icons/Texture2D.svg new file mode 100644 index 0000000..71d2233 --- /dev/null +++ b/addons/pandora/icons/Texture2D.svg @@ -0,0 +1 @@ + diff --git a/addons/pandora/icons/Texture2D.svg.import b/addons/pandora/icons/Texture2D.svg.import new file mode 100644 index 0000000..422f119 --- /dev/null +++ b/addons/pandora/icons/Texture2D.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cb105f78rcfaa" +path="res://.godot/imported/Texture2D.svg-73d3f0de486ac9c46265c9ea609c96c1.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://addons/pandora/icons/Texture2D.svg" +dest_files=["res://.godot/imported/Texture2D.svg-73d3f0de486ac9c46265c9ea609c96c1.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/addons/pandora/model/types/texture2d.gd b/addons/pandora/model/types/texture2d.gd new file mode 100644 index 0000000..aa40418 --- /dev/null +++ b/addons/pandora/model/types/texture2d.gd @@ -0,0 +1,62 @@ +extends PandoraPropertyType + +const ICON_PATH = "res://addons/pandora/icons/Texture2d.svg" + +const SETTINGS = {} + + +func _init() -> void: + super("texture2d", SETTINGS, null, ICON_PATH) + + +func parse_value(variant: Variant, settings: Dictionary = {}) -> Variant: + if variant is String: + if variant == "": + return null + + var deserialized = JSON.parse_string(variant) + if deserialized["type"] == "AtlasTexture": + var t = AtlasTexture.new() + t.atlas = load(deserialized["path"]) + t.region = Rect2( + deserialized["region"][0], + deserialized["region"][1], + deserialized["region"][2], + deserialized["region"][3], + ) + return t + + # Defaults to loading a texture2d + var t = Texture2D.new() + t.load(deserialized["path"]) + return t + + return variant + + +func write_value(variant: Variant) -> Variant: + if variant == null: + return "" + + var texture2d = variant as Texture2D + var serialized = { + "path": texture2d.resource_path, + "type": texture2d.get_class(), + } + if texture2d is AtlasTexture: + if texture2d.atlas == null: + return "" + + serialized["path"] = texture2d.atlas.resource_path + serialized["region"] = [ + texture2d.region.position.x, + texture2d.region.position.y, + texture2d.region.size.x, + texture2d.region.size.y, + ] + + return JSON.stringify(serialized) + + +func is_valid(variant: Variant) -> bool: + return variant is Texture2D diff --git a/addons/pandora/ui/components/properties/texture2d/texture2d_property.gd b/addons/pandora/ui/components/properties/texture2d/texture2d_property.gd new file mode 100644 index 0000000..e3cc2cc --- /dev/null +++ b/addons/pandora/ui/components/properties/texture2d/texture2d_property.gd @@ -0,0 +1,31 @@ +@tool +extends PandoraPropertyControl + +var picker = EditorResourcePicker.new() + + +func _ready(): + picker.base_type = "Texture2D" + picker.size = Vector2(470, 45) + picker.resource_changed.connect(_on_resource_changed) + picker.resource_selected.connect(_on_resource_selected) + add_child(picker) + refresh() + + +func _on_resource_changed(resource: Resource): + var new_resource = resource.duplicate() + _property.set_default_value(new_resource) + property_value_changed.emit(new_resource) + + +func _on_resource_selected(resource: Resource, _inspect: bool): + var new_resource = resource.duplicate() + _property.set_default_value(new_resource) + property_value_changed.emit(new_resource) + + +func refresh() -> void: + if _property != null: + var value = _property.get_default_value() + picker.edited_resource = value diff --git a/addons/pandora/ui/components/properties/texture2d/texture2d_property.tscn b/addons/pandora/ui/components/properties/texture2d/texture2d_property.tscn new file mode 100644 index 0000000..05f15b3 --- /dev/null +++ b/addons/pandora/ui/components/properties/texture2d/texture2d_property.tscn @@ -0,0 +1,12 @@ +[gd_scene load_steps=2 format=3 uid="uid://bm1l2gcyxt3aa"] + +[ext_resource type="Script" path="res://addons/pandora/ui/components/properties/texture2d/texture2d_property.gd" id="1_o4vlm"] + +[node name="Texture2dProperty" type="MarginContainer"] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_o4vlm") +type = "texture2d" diff --git a/addons/pandora/ui/components/property_bar/property_bar.tscn b/addons/pandora/ui/components/property_bar/property_bar.tscn index fe2a94e..39997d6 100644 --- a/addons/pandora/ui/components/property_bar/property_bar.tscn +++ b/addons/pandora/ui/components/property_bar/property_bar.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=27 format=3 uid="uid://8namx0kxhw0"] +[gd_scene load_steps=29 format=3 uid="uid://8namx0kxhw0"] [ext_resource type="Script" path="res://addons/pandora/ui/components/property_bar/property_bar.gd" id="1_0r2cp"] [ext_resource type="Texture2D" uid="uid://do5tkodyvid10" path="res://addons/pandora/icons/String.svg" id="1_4esni"] @@ -26,6 +26,8 @@ [ext_resource type="Texture2D" uid="uid://66qnm42libnj" path="res://addons/pandora/icons/Array.svg" id="17_ebxvo"] [ext_resource type="PackedScene" uid="uid://cckh8r5sngw1m" path="res://addons/pandora/ui/components/properties/vector/vector3/vector3_property.tscn" id="18_oxp4m"] [ext_resource type="PackedScene" uid="uid://ckdfcxfes51ia" path="res://addons/pandora/ui/components/properties/array/array_property.tscn" id="18_sjnhs"] +[ext_resource type="Texture2D" uid="uid://cb105f78rcfaa" path="res://addons/pandora/icons/Texture2D.svg" id="27_86nf1"] +[ext_resource type="PackedScene" uid="uid://bm1l2gcyxt3aa" path="res://addons/pandora/ui/components/properties/texture2d/texture2d_property.tscn" id="28_0sht3"] [node name="PropertyBar" type="HBoxContainer"] offset_right = 35.0 @@ -122,3 +124,10 @@ tooltip_text = "Array property" icon = ExtResource("17_ebxvo") script = ExtResource("3_kwfh5") scene = ExtResource("18_sjnhs") + +[node name="PandoraPropertyButton" type="Button" parent="."] +layout_mode = 2 +tooltip_text = "Texture2D Property" +icon = ExtResource("27_86nf1") +script = ExtResource("3_kwfh5") +scene = ExtResource("28_0sht3")