Browse Source

Update main screen plugin tutorial (#3232)

Add get_plugin_icon, add a link to the 2.5D demo projects, and make scripts conform to style guide (two lines between functions)
Aaron Franke 5 years ago
parent
commit
d160dae635
1 changed files with 23 additions and 0 deletions
  1. 23 0
      tutorials/plugins/editor/making_main_screen_plugins.rst

+ 23 - 0
tutorials/plugins/editor/making_main_screen_plugins.rst

@@ -53,18 +53,26 @@ file. In our example, ``main_screen_plugin.gd``.
     func _enter_tree():
     func _enter_tree():
        pass
        pass
 
 
+
     func _exit_tree():
     func _exit_tree():
        pass
        pass
 
 
+
     func has_main_screen():
     func has_main_screen():
        return true
        return true
 
 
+
     func make_visible(visible):
     func make_visible(visible):
        pass
        pass
 
 
+
     func get_plugin_name():
     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")
+
 The important part in this script is the ``has_main_screen()`` function, which is
 The important part in this script is the ``has_main_screen()`` function, which is
 overloaded so it returns ``true``. This function is automatically called by the
 overloaded so it returns ``true``. This function is automatically called by the
 editor on plugin activation, to tell it that this plugin adds a new center view to
 editor on plugin activation, to tell it that this plugin adds a new center view to
@@ -172,6 +180,7 @@ Here is the script's full content:
     func _on_Button_pressed():
     func _on_Button_pressed():
        emit_signal("side_button_pressed", "Hello from side panel!")
        emit_signal("side_button_pressed", "Hello from side panel!")
 
 
+
     func _on_main_button_pressed(text_to_show):
     func _on_main_button_pressed(text_to_show):
        $Label.text = text_to_show
        $Label.text = text_to_show
 
 
@@ -207,26 +216,36 @@ Here is the full ``main.gd``:
        # Hide the main panel
        # Hide the main panel
        make_visible(false)
        make_visible(false)
 
 
+
     func _exit_tree():
     func _exit_tree():
        main_panel_instance.queue_free()
        main_panel_instance.queue_free()
        side_panel_instance.queue_free()
        side_panel_instance.queue_free()
 
 
+
     func _ready():
     func _ready():
        main_panel_instance.connect("main_button_pressed", side_panel_instance, "_on_main_button_pressed")
        main_panel_instance.connect("main_button_pressed", side_panel_instance, "_on_main_button_pressed")
        side_panel_instance.connect("side_button_pressed", main_panel_instance, "_on_side_button_pressed")
        side_panel_instance.connect("side_button_pressed", main_panel_instance, "_on_side_button_pressed")
 
 
+
     func has_main_screen():
     func has_main_screen():
        return true
        return true
 
 
+
     func make_visible(visible):
     func make_visible(visible):
        if visible:
        if visible:
           main_panel_instance.show()
           main_panel_instance.show()
        else:
        else:
           main_panel_instance.hide()
           main_panel_instance.hide()
 
 
+
     func get_plugin_name():
     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")
+
 A couple of specific lines were added. First, we defined the constants that
 A couple of specific lines were added. First, we defined the constants that
 contain our 2 GUI packed scenes (``MainPanel`` and ``SidePanel``). We will use
 contain our 2 GUI packed scenes (``MainPanel`` and ``SidePanel``). We will use
 these resources to instance both scenes.
 these resources to instance both scenes.
@@ -262,3 +281,7 @@ Activate the plugin in the Project Settings. You'll observe a new button next to
 2D, 3D, Script above the main viewport. You'll also notice a new tab in the left
 2D, 3D, Script above the main viewport. You'll also notice a new tab in the left
 dock. Try to click the buttons in both side and main panels: events are emitted
 dock. Try to click the buttons in both side and main panels: events are emitted
 and caught by the corresponding target scene to change the Label caption inside it.
 and caught by the corresponding target scene to change the Label caption inside it.
+
+If you would like to see a more complete example of what main screen plugins
+are capable of, check out the 2.5D demo projects here:
+https://github.com/godotengine/godot-demo-projects/tree/master/misc/2.5d