0 votes

Hi All,

I am trying to make something like a level editor that can be used in the editor. (I am making something for other developers). The idea is that you can select properties from the inspector and it will change the layout of a controller in real time.

I know You can use export variables + tool scripts to achieve something like this, but I want to be able to create additional properties depending on what the user/dev selected from those variables. For example, the user/dev selects "add button" from an export string var. I then want a new property to appear that will have a drop-down of (right, left, top, bottom) for the user to select the location of the button.

Any ideas on how to do this? Is a Tool script going to be enough, or is there more I need to do?

Godot version 3.2.4 beta 4
in Engine by (577 points)

1 Answer

+1 vote
Best answer

For what you're trying to do i'd recommend using Editor plugins for more control

You can create whole menu structures using User Interface nodes and simply hide/show the controls based on the user/dev selections.

by (4,644 points)
selected by

An example

Plugin Script

tool extends EditorPlugin

enum options {BOTTOM, LEFT, RIGHT, TOP}
var menu = preload("res://addons/Example/menu.tscn").instance()
var option_button = menu.get_node("OptionButton")
var add_button = menu.get_node("Button")

var last_position = CONTAINER_SPATIAL_EDITOR_BOTTOM

func _add_button_pressed():
    #add_button has Toggle mode enabled
    match add_button.pressed:
        true: 
            option_button.show()
            add_button.text = "Sub"
        false:
            option_button.hide()
            add_button.text = "Add"

func _option_button_pressed(index):
    remove_control_from_container(last_position, menu)
    match index:
        options.LEFT:
            last_position = CONTAINER_SPATIAL_EDITOR_SIDE_LEFT
        options.RIGHT:
            last_position = CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT
        options.TOP:
            last_position = CONTAINER_SPATIAL_EDITOR_MENU
        options.BOTTOM:
            last_position = CONTAINER_SPATIAL_EDITOR_BOTTOM
    add_control_to_container(last_position, menu)

func _enter_tree():
    #add control to editor CONTAINER_CANVAS_EDITOR for 2D SPATIAL for 3D
    add_control_to_container(CONTAINER_SPATIAL_EDITOR_BOTTOM, menu)

    add_button.connect("button_up", self, "_add_button_pressed")
    option_button.connect("item_selected", self,"_option_button_pressed")

    #poulate option node, can also be done through editor
    for item in options.keys():
        option_button.add_item(item)

func _exit_tree():
    remove_control_from_container(last_position, menu)

Menu.tscn
menu

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.