Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Adds texture2d stub property #174

Open
wants to merge 1 commit into
base: godot-4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/pandora/icons/Texture2D.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions addons/pandora/icons/Texture2D.svg.import
Original file line number Diff line number Diff line change
@@ -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
62 changes: 62 additions & 0 deletions addons/pandora/model/types/texture2d.gd
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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"
11 changes: 10 additions & 1 deletion addons/pandora/ui/components/property_bar/property_bar.tscn
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Loading