hello,
Iam making this plugIn were the user draws on screen... Problem here is i cant keep the node selected. Once i press the node the plugIn the menu showsUp / when i press the editor screen the node gets deselected ?!?
Is there a way to keep the node selected like in the original tileMap node ?
I cant find anything in the manual, or the original tileMap code, that explains a simple node selection like this... Everything is scattered.
The original tileMap node is keeping the node selected on the screen someHow, and the user is able to press the main editor at any time, without deselecting the node... Its just such a simple thing to do, and yet so neglected, that its driving me crazy, to the point of just be done and leave this engine... If it was a complicated thing..ok.. fine... but such a simple thing causing such a mess, like having an ant on the middle of a free way and the A.I. cars are forced to stop... it just seems stupid...

`
@tool
extends EditorPlugin

const editorAddon = preload("res://addons/tiletest/tilePlugTest.tscn");
const tileDrawNode = preload("res://addons/tiletest/tileDrawNode.gd");
const tileDrawIcon = preload("res://addons/tiletest/icon.png");

var dockedCanvas;

var dockedScene;
var subVcont;
var subVport;
var label1;
var label2;
var camTl;

var img;
var Mimg: int = 0;
var MouseOnImage;
var blk;
var blk2;

func _enter_tree():
add_custom_type("TileDraw", "Node2D", tileDrawNode, tileDrawIcon );
dockedScene = editorAddon.instantiate();
add_control_to_container(CONTAINER_CANVAS_EDITOR_SIDE_RIGHT, dockedScene );
dockedScene.custom_minimum_size = Vector2(10,0);


if not is_instance_valid(dockedScene):
	return;

subVcont = dockedScene.get_node("SubViewportContainer");
subVport = dockedScene.get_node("SubViewportContainer/SubViewport");

label1 = dockedScene.get_node("Label");
label2 = dockedScene.get_node("Label2");
img = dockedScene.get_node("SubViewportContainer/SubViewport/Icon");
camTl = dockedScene.get_node("SubViewportContainer/SubViewport/Camera2D");
blk = dockedScene.get_node("Blk");
blk2 = dockedScene.get_node("Blk2");

var editorSel = get_editor_interface().get_selection().get_selected_nodes()

if ( editorSel.has('TileDraw') ):
	dockedScene.visible = false;
else:
	dockedScene.visible = true;

func _handles(object: Object) -> bool:
return object is tileDrawNode

func _make_visible(visible: bool) -> void:
dockedScene.visible = visible
`

[ edit ] In the function description _make_visible. the manual states:

This function will be called when the editor is requested to become visible. It is used for plugins that edit a specific object type.
Remember that you have to manage the visibility of all your editor controls manually.

There isnt any info about managing the visibility of all your editor controls manually...

  • xyz replied to this.

    xyz I rebember trying something simillar, when i frist started making the plugIn. But i had no way of getting the node.
    this line -> var editorSel = get_editor_interface().get_selection().get_selected_nodes()... returns something ?!? a list or an array of all clicked / or selected nodes, but whenever i try to get a specific node from that thing everything returns an error, i dont want to use a for loop ( array has ) should work there.
    But even if it worked i dont see how it would change anything the node would still be deselected once the user presses the main screen...
    Iam sure theres a simple way or function hidden out there somewere, that would make such a simple thing work. I just cant find it nor can i understand the manual thats what makes it so frustrating... Any search on this topic will take you to the wrong places.

    • xyz replied to this.

      jonSS Um, the thing I suggested has nothing to do with getting nodes. It just intercepts viewport events. If your plugin consumes the mousedown event, the event should not be processed further to cause deselection. I haven't tried it but it looks like it should do the job. Just try to override EditorPlugin::_forward_canvas_gui_input() and return true from it if the event is mousedown to tell the engine to stop forwarding the event.

        xyz okay... but iam not sure how to use it.

        func _forward_canvas_gui_input(event):
        	print(event);

        it returns mouse movement:

        204.2426)), pressure=0.00, tilt=((0, 0)), pen_inverted=(false)
        InputEventMouseMotion: button_mask=0, position=((374, 321)), relative=((5, -10)), velocity=((508.3884,

        and it only works on the editor main screen, when the mouse is on the editor tree it stops printing
        when i mouse click on the editor main screen

        InputEventMouseButton: button_index=1, mods=none, pressed=true, canceled=false, position=((363, 246)), button_mask=1, double_click=false

        the node gets deselected due to this function

        func _make_visible(visible: bool) -> void:
        	dockedScene.visible = visible
        	#print( get_editor_interface().get_selection().get_selected_nodes() )

        if i could get "func _forward_canvas_gui_input(event)" to work on the node tree and get the node name, from the list above get_editor_interface().get_selection().get_selected_nodes() , i might set visible true/false from there...
        _forward_canvas_gui_input() only shows values when the mouse is on the editor main screen, the place were i click and the node gets deselected...

        [edit]

        func _make_visible(visible: bool) -> void:
        	dockedScene.visible = visible
        	print( get_editor_interface().get_selection().get_selected_nodes() )

        func _make_visible prints this:
        [Node2D:<Node2D#1682100514617>]
        [TileDraw:<Node2D#1682117291834>]

        I dont know how to get this values... this returns an error

        	var editorSel = get_editor_interface().get_selection().get_selected_nodes()
        	
        	if ( editorSel.has('TileDraw') ):
        		dockedScene.visible = false;
        	else:
        		dockedScene.visible = true;

        something about type string into array type:

        Attempted to use 'has' a variable of type 'String' into a TypedArray of type 'Object'.
        core/variant/array.cpp:400 - Condition "!_p->typed.validate(value, "use 'has'")" is true. Returning: false

        it looks like an array from the "print( get_editor_interface().get_selection().get_selected_nodes() )"... but now its telling me of type object of type string of type variable i cant understand... it looks like a dictionary to me, with an array key, that can have string, int, etc..... i dont know how to check the value...

        [edit]
        func _forward_canvas_gui_input(event): worked after all !!!

        i was trying to get the input from the tree, and could not understand how to make this 2 functions work together "make_visible" and "forward_canvas_gui_input"
        but everything seems to be working now, like in the original tileMap node... the plugIN menu gets hidden when pressing a diferent node on the tree. And it shows the menu when y select the "tileDraw" node or selected it the frist time and then select multiple nodes ... the user can keep pressing the main editor window and the "tileDraw"node doesnt get deselected...

        func _enter_tree():
        	add_custom_type("TileDraw", "Node2D", tileDrawNode, tileDrawIcon );
        
        func _handles(object: Object) -> bool:
        	return object is tileDrawNode
        
        func _make_visible(visible: bool) -> void:
        	dockedScene.visible = visible
        
        func _forward_canvas_gui_input(event):
        	if (event is InputEventMouseButton ):
        		dockedScene.visible = true;
        		return true
        	print(event);

        thanks

        • xyz replied to this.

          jonSS func _forward_canvas_gui_input(event): worked after all !!!

          See. I told you it would 😃
          👍