Completed the support for plugins! It is not possible to add plugins.

Not all APIs are provided yet, please request whathever you are missing.
Some example plugins are provided in demos/plugins. Just copy them to a folder in your project named addons/ and then enable them from the project settings.
Have fun!
This commit is contained in:
Juan Linietsky
2016-02-27 23:10:44 -03:00
parent 9fc6eaa11f
commit b9155df063
15 changed files with 390 additions and 0 deletions

Binary file not shown.

View File

@@ -0,0 +1,23 @@
tool
extends EditorPlugin
var dock = null
func _enter_tree():
# When this plugin node enters tree, add the custom type
dock = preload("res://addons/custom_dock/custom_dock.scn").instance()
add_control_to_dock( DOCK_SLOT_LEFT_UL, dock )
func _exit_tree():
# Remove from docks (must be called so layout is updated and saved)
remove_control_from_docks(dock)
# Remove the node
dock.free()

View File

@@ -0,0 +1,14 @@
[plugin]
name="Custom Dock"
description="Adds a new Customizable Dock"
author="Juan Linietsky"
version="1.0"
script="dock_plugin.gd"

View File

@@ -0,0 +1,81 @@
tool
extends EditorImportPlugin
# Simple plugin that imports a text file with extension .mtxt
# which contains 3 integers in format R,G,B (0-255)
# (see example .mtxt in this folder)
# Imported file is converted to a material
var dialog = null
func get_name():
return "silly_material"
func get_visible_name():
return "Silly Material"
func import_dialog(path):
var md = null
if (path!=""):
md = ResourceLoader.load_import_metadata(path)
dialog.configure(self,path,md)
dialog.popup_centered()
func import(path,metadata):
assert(metadata.get_source_count() == 1)
var source = metadata.get_source_path(0)
var use_red_anyway = metadata.get_option("use_red_anyway")
var f = File.new()
var err = f.open(source,File.READ)
if (err!=OK):
return ERR_CANT_OPEN
var l = f.get_line()
f.close()
var channels = l.split(",")
if (channels.size()!=3):
return ERR_PARSE_ERROR
var color = Color8(int(channels[0]),int(channels[1]),int(channels[2]))
var material
if (ResourceLoader.has(path)):
# Material is in use, update it
material = ResourceLoader.load(path)
else:
# Material not in use, create
material = FixedMaterial.new()
if (use_red_anyway):
color=Color8(255,0,0)
material.set_parameter(FixedMaterial.PARAM_DIFFUSE,color)
# Make sure import metadata links to this plugin
metadata.set_editor("silly_material")
# Update the import metadata
material.set_import_metadata(metadata)
# Save
err = ResourceSaver.save(path,material)
return err
func config(base_control):
dialog = preload("res://addons/custom_import_plugin/material_dialog.tscn").instance()
base_control.add_child(dialog)

View File

@@ -0,0 +1,67 @@
tool
extends ConfirmationDialog
var src_fs
var dst_fs
var import_plugin
func configure(p_import_plugin,path,metadata):
import_plugin=p_import_plugin
if (metadata):
# metadata from previous import exists, fill in fields
assert( metadata.get_source_count() > 0 )
# Always expand the source paths
var src_path = import_plugin.expand_source_path( metadata.get_source_path(0) )
get_node("src_file").set_text(src_path)
get_node("dst_file").set_text(path)
# Fill in from metadata options
get_node("use_red_anyway").set_pressed( metadata.get_option("use_red_anyway") )
func _ready():
src_fs = FileDialog.new()
src_fs.set_mode(FileDialog.MODE_OPEN_FILE)
src_fs.set_access(FileDialog.ACCESS_FILESYSTEM) #access all filesystem, not only res://
src_fs.add_filter("*.mtxt")
src_fs.connect("file_selected",self,"_on_src_selected")
add_child(src_fs)
dst_fs = EditorFileDialog.new()
dst_fs.set_mode(EditorFileDialog.MODE_SAVE_FILE)
dst_fs.add_filter("*.mtl") # Use binary extension always, text can't save metadata
dst_fs.connect("file_selected",self,"_on_dst_selected")
add_child(dst_fs)
set_hide_on_ok(true)
get_ok().set_text("Import!")
func _on_src_browse_pressed():
src_fs.popup_centered_ratio()
func _on_dst_browse_pressed():
dst_fs.popup_centered_ratio()
func _on_src_selected(path):
get_node("src_file").set_text(path)
func _on_dst_selected(path):
get_node("dst_file").set_text(path)
func _on_MaterialImport_confirmed():
# Create an import metadata
var imd = ResourceImportMetadata.new()
# Add the source files, always validate the source path
imd.add_source( import_plugin.validate_source_path( get_node("src_file").get_text() ))
# Add the options
imd.set_option( "use_red_anyway", get_node("use_red_anyway").is_pressed() )
# Perform regular import
var err = import_plugin.import( get_node("dst_file").get_text(), imd )
# Warn if error
if (err!=OK):
get_node("error").set_text("Error Importing!")
get_node("error").popup_centered_minsize()

View File

@@ -0,0 +1,111 @@
[gd_scene load_steps=2 format=1]
[ext_resource path="res://addons/custom_import_plugin/material_dialog.gd" type="Script" id=1]
[node name="MaterialImport" type="ConfirmationDialog"]
margin/right = 276.0
margin/bottom = 154.0
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
popup/exclusive = false
window/title = "Silly Material Import"
dialog/hide_on_ok = true
script/script = ExtResource( 1 )
__meta__ = { "__editor_plugin_screen__":"Script" }
[node name="src_file" type="LineEdit" parent="."]
margin/left = 19.0
margin/top = 6.0
margin/right = 190.0
margin/bottom = 29.0
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
text = ""
max_length = 0
editable = true
secret = false
[node name="src_browse" type="Button" parent="."]
margin/left = 195.0
margin/top = 7.0
margin/right = 249.0
margin/bottom = 29.0
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
toggle_mode = false
text = "browse"
flat = false
[node name="dst_browse" type="Button" parent="."]
margin/left = 195.0
margin/top = 47.0
margin/right = 249.0
margin/bottom = 69.0
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
toggle_mode = false
text = "browse"
flat = false
[node name="dst_file" type="LineEdit" parent="."]
margin/left = 19.0
margin/top = 46.0
margin/right = 190.0
margin/bottom = 69.0
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
text = ""
max_length = 0
editable = true
secret = false
[node name="use_red_anyway" type="CheckBox" parent="."]
margin/left = 20.0
margin/top = 84.0
margin/right = 144.0
margin/bottom = 106.0
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
toggle_mode = true
text = "Use Red Anyway"
flat = false
align = 0
[node name="error" type="AcceptDialog" parent="."]
visibility/visible = false
margin/right = 40.0
margin/bottom = 40.0
focus/ignore_mouse = false
focus/stop_mouse = true
size_flags/horizontal = 2
size_flags/vertical = 2
popup/exclusive = false
window/title = "Alert!"
dialog/hide_on_ok = true
[connection signal="confirmed" from="." to="." method="_on_MaterialImport_confirmed"]
[connection signal="pressed" from="src_browse" to="." method="_on_src_browse_pressed"]
[connection signal="pressed" from="dst_browse" to="." method="_on_dst_browse_pressed"]

View File

@@ -0,0 +1,22 @@
tool
extends EditorPlugin
var import_plugin
func _enter_tree():
import_plugin = preload("res://addons/custom_import_plugin/import_plugin.gd").new()
# pass the GUI base control, so the dialog has a parent node
import_plugin.config( get_base_control() )
add_import_plugin( import_plugin)
func _exit_tree():
remove_import_plugin( import_plugin )

View File

@@ -0,0 +1,14 @@
[plugin]
name="Silly Material Importer"
description="Imports a 3D Material from an external text file"
author="Juan Linietsky"
version="1.0"
script="material_import.gd"

View File

@@ -0,0 +1 @@
0,0,255

View File

@@ -0,0 +1,12 @@
tool
extends Node2D
var heart = preload("res://addons/custom_node/heart.png")
func _draw():
draw_texture(heart,-heart.get_size()/2)
func _get_item_rect():
#override
return Rect2(-heart.get_size()/2,heart.get_size())

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

View File

@@ -0,0 +1,18 @@
tool
extends EditorPlugin
func _enter_tree():
# When this plugin node enters tree, add the custom type
add_custom_type("Heart","Node2D",preload("res://addons/custom_node/heart.gd"),preload("res://addons/custom_node/heart_icon.png"))
func _exit_tree():
# When the plugin node exits the tree, remove the custom type
remove_custom_type("Heart")

View File

@@ -0,0 +1,14 @@
[plugin]
name="Heart"
description="Adds a new Heart node in 2D"
author="Juan Linietsky"
version="1.0"
script="heart_plugin.gd"

13
plugins/readme.txt Normal file
View File

@@ -0,0 +1,13 @@
To install these, copy each of these folders to a folder:
addons/
inside your projects, example:
addons/custom_node
To distribute and install from UI, make a zip that contains the folder,
example:
zip -r custom_node.zip custom_node/*