-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
153 additions
and
1 deletion.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
31 changes: 31 additions & 0 deletions
31
addons/pandora/ui/components/properties/texture2d/texture2d_property.gd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
12 changes: 12 additions & 0 deletions
12
addons/pandora/ui/components/properties/texture2d/texture2d_property.tscn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters