Skip to content

Commit

Permalink
Merge pull request #49491 from pycbouh/editor-expose-resource-picker-3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
akien-mga authored Jun 11, 2021
2 parents fed44e3 + b622dfa commit 72ae4ca
Show file tree
Hide file tree
Showing 9 changed files with 1,275 additions and 709 deletions.
115 changes: 115 additions & 0 deletions doc/classes/EditorResourcePicker.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="EditorResourcePicker" inherits="HBoxContainer" version="3.4">
<brief_description>
Godot editor's control for selecting [Resource] type properties.
</brief_description>
<description>
This [Control] node is used in the editor's Inspector dock to allow editing of [Resource] type properties. It provides options for creating, loading, saving and converting resources. Can be used with [EditorInspectorPlugin] to recreate the same behavior.
[b]Note:[/b] This [Control] does not include any editor for the resource, as editing is controlled by the Inspector dock itself or sub-Inspectors.
</description>
<tutorials>
</tutorials>
<methods>
<method name="can_drop_data_fw" qualifiers="const">
<return type="bool">
</return>
<argument index="0" name="position" type="Vector2">
</argument>
<argument index="1" name="data" type="Variant">
</argument>
<argument index="2" name="from" type="Control">
</argument>
<description>
</description>
</method>
<method name="drop_data_fw">
<return type="void">
</return>
<argument index="0" name="position" type="Vector2">
</argument>
<argument index="1" name="data" type="Variant">
</argument>
<argument index="2" name="from" type="Control">
</argument>
<description>
</description>
</method>
<method name="get_allowed_types" qualifiers="const">
<return type="PoolStringArray">
</return>
<description>
Returns a list of all allowed types and subtypes corresponding to the [member base_type]. If the [member base_type] is empty, an empty list is returned.
</description>
</method>
<method name="get_drag_data_fw">
<return type="Variant">
</return>
<argument index="0" name="position" type="Vector2">
</argument>
<argument index="1" name="from" type="Control">
</argument>
<description>
</description>
</method>
<method name="handle_menu_selected" qualifiers="virtual">
<return type="void">
</return>
<argument index="0" name="id" type="int">
</argument>
<description>
This virtual method can be implemented to handle context menu items not handled by default. See [method set_create_options].
</description>
</method>
<method name="set_create_options" qualifiers="virtual">
<return type="void">
</return>
<argument index="0" name="menu_node" type="Object">
</argument>
<description>
This virtual method is called when updating the context menu of [EditorResourcePicker]. Implement this method to override the "New ..." items with your own options. [code]menu_node[/code] is a reference to the [PopupMenu] node.
[b]Note:[/b] Implement [method handle_menu_selected] to handle these custom items.
</description>
</method>
<method name="set_toggle_pressed">
<return type="void">
</return>
<argument index="0" name="pressed" type="bool">
</argument>
<description>
Sets the toggle mode state for the main button. Works only if [member toggle_mode] is set to [code]true[/code].
</description>
</method>
</methods>
<members>
<member name="base_type" type="String" setter="set_base_type" getter="get_base_type" default="&quot;&quot;">
The base type of allowed resource types. Can be a comma-separated list of several options.
</member>
<member name="editable" type="bool" setter="set_editable" getter="is_editable" default="true">
If [code]true[/code], the value can be selected and edited.
</member>
<member name="edited_resource" type="Resource" setter="set_edited_resource" getter="get_edited_resource">
The edited resource value.
</member>
<member name="toggle_mode" type="bool" setter="set_toggle_mode" getter="is_toggle_mode" default="false">
If [code]true[/code], the main button with the resource preview works in the toggle mode. Use [method set_toggle_pressed] to manually set the state.
</member>
</members>
<signals>
<signal name="resource_changed">
<argument index="0" name="resource" type="Resource">
</argument>
<description>
Emitted when the value of the edited resource was changed.
</description>
</signal>
<signal name="resource_selected">
<argument index="0" name="resource" type="Resource">
</argument>
<description>
Emitted when the resource value was set and user clicked to edit it.
</description>
</signal>
</signals>
<constants>
</constants>
</class>
21 changes: 21 additions & 0 deletions doc/classes/EditorScriptPicker.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="EditorScriptPicker" inherits="EditorResourcePicker" version="3.4">
<brief_description>
Godot editor's control for selecting the [code]script[/code] property of a [Node].
</brief_description>
<description>
Similar to [EditorResourcePicker] this [Control] node is used in the editor's Inspector dock, but only to edit the [code]script[/code] property of a [Node]. Default options for creating new resources of all possible subtypes are replaced with dedicated buttons that open the "Attach Node Script" dialog. Can be used with [EditorInspectorPlugin] to recreate the same behavior.
[b]Note:[/b] You must set the [member script_owner] for the custom context menu items to work.
</description>
<tutorials>
</tutorials>
<methods>
</methods>
<members>
<member name="script_owner" type="Node" setter="set_script_owner" getter="get_script_owner">
The owner [Node] of the script property that holds the edited resource.
</member>
</members>
<constants>
</constants>
</class>
2 changes: 2 additions & 0 deletions doc/classes/EditorSpinSlider.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="EditorSpinSlider" inherits="Range" version="3.4">
<brief_description>
Godot editor's control for editing numeric values.
</brief_description>
<description>
This [Control] node is used in the editor's Inspector dock to allow editing of numeric values. Can be used with [EditorInspectorPlugin] to recreate the same behavior.
</description>
<tutorials>
</tutorials>
Expand Down
3 changes: 3 additions & 0 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
#include "editor/editor_log.h"
#include "editor/editor_plugin.h"
#include "editor/editor_properties.h"
#include "editor/editor_resource_picker.h"
#include "editor/editor_resource_preview.h"
#include "editor/editor_run_native.h"
#include "editor/editor_run_script.h"
Expand Down Expand Up @@ -3799,6 +3800,8 @@ void EditorNode::register_editor_types() {
ClassDB::register_class<ScriptCreateDialog>();
ClassDB::register_class<EditorFeatureProfile>();
ClassDB::register_class<EditorSpinSlider>();
ClassDB::register_class<EditorResourcePicker>();
ClassDB::register_class<EditorScriptPicker>();
ClassDB::register_virtual_class<FileSystemDock>();

// FIXME: Is this stuff obsolete, or should it be ported to new APIs?
Expand Down
Loading

0 comments on commit 72ae4ca

Please sign in to comment.