diff --git a/plugins/README.md b/plugins/README.md index 0e07ad8b..dff4fa3d 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -11,7 +11,7 @@ Renderer: GLES 2 # How does it work? -This project contains 3 plugins: +This project contains 4 plugins: * The custom node plugin shows how to create a custom node type using `add_custom_type`. [More info](addons/custom_node). @@ -22,6 +22,9 @@ This project contains 3 plugins: * The material creator plugin shows how to add a custom dock with some simple functionality. [More info](addons/material_creator). +* The main screen plugin is a minimal example of how to create a plugin + with a main screen. [More info](addons/main_screen). + To use these plugins in another project, copy any of these folders to the `addons/` folder in a Godot project, and then enable them in the project settings menu. diff --git a/plugins/addons/main_screen/README.md b/plugins/addons/main_screen/README.md new file mode 100644 index 00000000..453959f5 --- /dev/null +++ b/plugins/addons/main_screen/README.md @@ -0,0 +1,11 @@ +# Main Screen Plugin Demo + +This plugin demo shows how to make a main screen plugin. +The main screen appears as a button next to the "2D", "3D", "Script", and +"AssetLib" buttons. It also shows up when a Node it `handles` is selected. + +For more information, see this documentation article: +https://docs.godotengine.org/en/latest/tutorials/plugins/editor/making_main_screen_plugins.html + +If you would like to see a more complete example of what main screen plugins +are capable of, check out the [2.5D demo project](../../../misc/2.5d). diff --git a/plugins/addons/main_screen/handled_by_main_screen.gd b/plugins/addons/main_screen/handled_by_main_screen.gd new file mode 100644 index 00000000..61510e14 --- /dev/null +++ b/plugins/addons/main_screen/handled_by_main_screen.gd @@ -0,0 +1 @@ +extends Node diff --git a/plugins/addons/main_screen/main_panel.tscn b/plugins/addons/main_screen/main_panel.tscn new file mode 100644 index 00000000..b8693bea --- /dev/null +++ b/plugins/addons/main_screen/main_panel.tscn @@ -0,0 +1,20 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://addons/main_screen/print_hello.gd" type="Script" id=1] + +[node name="MainPanel" type="CenterContainer"] +anchor_right = 1.0 +anchor_bottom = 1.0 +size_flags_vertical = 3 + +[node name="PrintHello" type="Button" parent="."] +margin_left = 472.0 +margin_top = 290.0 +margin_right = 552.0 +margin_bottom = 310.0 +text = "Print Hello" +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} +[connection signal="pressed" from="PrintHello" to="PrintHello" method="_on_PrintHello_pressed"] diff --git a/plugins/addons/main_screen/main_screen_plugin.gd b/plugins/addons/main_screen/main_screen_plugin.gd new file mode 100644 index 00000000..b85aaa8b --- /dev/null +++ b/plugins/addons/main_screen/main_screen_plugin.gd @@ -0,0 +1,41 @@ +tool +extends EditorPlugin + +const MainPanel = preload("res://addons/main_screen/main_panel.tscn") + +var main_panel_instance + +func _enter_tree(): + main_panel_instance = MainPanel.instance() + # Add the main panel to the editor's main viewport. + get_editor_interface().get_editor_viewport().add_child(main_panel_instance) + # Hide the main panel. Very much required. + make_visible(false) + + +func _exit_tree(): + if main_panel_instance: + main_panel_instance.queue_free() + + +func has_main_screen(): + return true + + +func make_visible(visible): + if main_panel_instance: + main_panel_instance.visible = visible + + +# If your plugin doesn't handle any node types, you can remove this method. +func handles(obj): + return obj is preload("res://addons/main_screen/handled_by_main_screen.gd") + + +func get_plugin_name(): + return "Main Screen Plugin" + + +func get_plugin_icon(): + # Must return some kind of Texture for the icon. + return get_editor_interface().get_base_control().get_icon("Node", "EditorIcons") diff --git a/plugins/addons/main_screen/plugin.cfg b/plugins/addons/main_screen/plugin.cfg new file mode 100644 index 00000000..b38b73b7 --- /dev/null +++ b/plugins/addons/main_screen/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="Main Screen Plugin Demo" +description="Demonstrates how to make a main screen plugin." +author="Aaron Franke, Julian Murgia" +version="1.0" +script="main_screen_plugin.gd" diff --git a/plugins/addons/main_screen/print_hello.gd b/plugins/addons/main_screen/print_hello.gd new file mode 100644 index 00000000..aecd7e59 --- /dev/null +++ b/plugins/addons/main_screen/print_hello.gd @@ -0,0 +1,5 @@ +tool +extends Button + +func _on_PrintHello_pressed(): + print("Hello from the main screen plugin!") diff --git a/plugins/project.godot b/plugins/project.godot index 8ffa7ea0..1d5247e9 100644 --- a/plugins/project.godot +++ b/plugins/project.godot @@ -17,12 +17,12 @@ _global_script_class_icons={ config/name="Plugin Demos" config/description="This contains multiple plugin demos, all placed in a project for convenience." -run/main_scene="res://custom_node_test.tscn" +run/main_scene="res://test_scene.tscn" config/icon="res://icon.png" [editor_plugins] -enabled=PoolStringArray( "custom_node", "material_creator", "material_import_plugin" ) +enabled=PoolStringArray( "custom_node", "main_screen", "material_creator", "material_import_plugin" ) [rendering] diff --git a/plugins/custom_node_test.tscn b/plugins/test_scene.tscn similarity index 53% rename from plugins/custom_node_test.tscn rename to plugins/test_scene.tscn index 8684e02a..30a80ed5 100644 --- a/plugins/custom_node_test.tscn +++ b/plugins/test_scene.tscn @@ -1,15 +1,19 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=4 format=2] -[ext_resource path="res://addons/custom_node/heart.gd" type="Script" id=1] +[ext_resource path="res://addons/main_screen/handled_by_main_screen.gd" type="Script" id=1] +[ext_resource path="res://addons/custom_node/heart.gd" type="Script" id=2] [sub_resource type="CubeMesh" id=1] -[node name="CustomNodeTest" type="Node2D"] +[node name="TestScene" type="Node"] [node name="Heart" type="Node2D" parent="."] -script = ExtResource( 1 ) +script = ExtResource( 2 ) [node name="MeshInstance" type="MeshInstance" parent="."] mesh = SubResource( 1 ) skeleton = NodePath("") material/0 = null + +[node name="HandledByMainScreen" type="Node" parent="."] +script = ExtResource( 1 )