|
@@ -31,28 +31,29 @@ Add five extra methods such that the script looks like this:
|
|
|
tool
|
|
|
extends EditorPlugin
|
|
|
|
|
|
+
|
|
|
func _enter_tree():
|
|
|
- pass
|
|
|
+ pass
|
|
|
|
|
|
|
|
|
func _exit_tree():
|
|
|
- pass
|
|
|
+ pass
|
|
|
|
|
|
|
|
|
func has_main_screen():
|
|
|
- return true
|
|
|
+ return true
|
|
|
|
|
|
|
|
|
func make_visible(visible):
|
|
|
- pass
|
|
|
+ pass
|
|
|
|
|
|
|
|
|
func get_plugin_name():
|
|
|
- return "Main Screen Plugin"
|
|
|
+ return "Main Screen Plugin"
|
|
|
|
|
|
|
|
|
func get_plugin_icon():
|
|
|
- return get_editor_interface().get_base_control().get_icon("Node", "EditorIcons")
|
|
|
+ return get_editor_interface().get_base_control().get_icon("Node", "EditorIcons")
|
|
|
|
|
|
The important part in this script is the ``has_main_screen()`` function,
|
|
|
which is overloaded so it returns ``true``. This function is automatically
|
|
@@ -79,11 +80,12 @@ Add a script to the button like this:
|
|
|
tool
|
|
|
extends Button
|
|
|
|
|
|
+
|
|
|
func _on_PrintHello_pressed():
|
|
|
- print("Hello from the main screen plugin!")
|
|
|
+ print("Hello from the main screen plugin!")
|
|
|
|
|
|
Then connect the "pressed" signal to itself. If you need help with signals,
|
|
|
-see the :ref:`Signals <doc_getting_started_step_by_step_signals>` article.
|
|
|
+see the :ref:`doc_signals` article.
|
|
|
|
|
|
We are done with the main screen panel. Save the scene as ``main_panel.tscn``.
|
|
|
|
|
@@ -99,39 +101,41 @@ Here is the full plugin script:
|
|
|
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)
|
|
|
+ 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()
|
|
|
+ if main_panel_instance:
|
|
|
+ main_panel_instance.queue_free()
|
|
|
|
|
|
|
|
|
func has_main_screen():
|
|
|
- return true
|
|
|
+ return true
|
|
|
|
|
|
|
|
|
func make_visible(visible):
|
|
|
- if main_panel_instance:
|
|
|
- main_panel_instance.visible = visible
|
|
|
+ if main_panel_instance:
|
|
|
+ main_panel_instance.visible = visible
|
|
|
|
|
|
|
|
|
func get_plugin_name():
|
|
|
- return "Main Screen Plugin"
|
|
|
+ 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")
|
|
|
+ # Must return some kind of Texture for the icon.
|
|
|
+ return get_editor_interface().get_base_control().get_icon("Node", "EditorIcons")
|
|
|
|
|
|
A couple of specific lines were added. ``MainPanel`` is a constant that holds
|
|
|
a reference to the scene, and we instance it into `main_panel_instance`.
|