Skip to content

Commit 48f9499

Browse files
authoredJul 18, 2024
Merge pull request #2 from CollinViz/master
Select scene tab if in 2D or 3D or othere
2 parents d2b2f84 + 64bf5dd commit 48f9499

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed
 

‎addons/script-dock/plugin.gd

+32-12
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ extends EditorPlugin
33

44
var control := MarginContainer.new()
55
var panel: Control
6-
var default_parent: Control
6+
var default_parent: Control
7+
var script_editor :ScriptEditor = null
8+
var last_screen:=''
79

10+
811

9-
var script_editor :ScriptEditor = null
10-
func _enter_tree():
12+
func _enter_tree()->void:
13+
#print(" current screen " ,get_main_screen())
1114
script_editor = EditorInterface.get_script_editor()
1215
script_editor.editor_script_changed.connect(script_visibility_changed)
1316
script_editor.visibility_changed.connect(script_visibility_changed)
@@ -16,25 +19,42 @@ func _enter_tree():
1619
panel = default_parent.get_child(0)
1720
panel.reparent(control)
1821

19-
2022
control.size_flags_horizontal = Control.SIZE_EXPAND_FILL
2123
control.size_flags_vertical = Control.SIZE_EXPAND_FILL
2224
control.name = "Scripts"
2325
add_control_to_dock(EditorPlugin.DOCK_SLOT_LEFT_BR, control)
24-
26+
27+
## connect to what screen is active
28+
main_screen_changed.connect(screen_changed)
29+
30+
31+
32+
func screen_changed(screen)->void:
33+
last_screen = screen
34+
if !script_editor && !script_editor.is_visible_in_tree():
35+
return
2536
var parent: TabContainer = control.get_parent()
26-
parent.print_tree()
27-
2837

38+
match screen:
39+
"Script":
40+
parent.current_tab = control.get_index()
41+
_:
42+
parent.current_tab = 0
43+
2944

30-
func script_visibility_changed(a = null):
31-
if !script_editor.is_visible_in_tree():
45+
func script_visibility_changed(a = null)->void:
46+
if !script_editor && !script_editor.is_visible_in_tree():
3247
return
33-
var parent: TabContainer = control.get_parent()
34-
parent.current_tab = control.get_index()
48+
49+
if last_screen=="":
50+
return
51+
52+
if last_screen=="Script":
53+
var parent: TabContainer = control.get_parent()
54+
parent.current_tab = control.get_index()
3555

3656
func _exit_tree():
3757
panel.reparent(default_parent)
3858
default_parent.move_child(panel, 0)
3959
remove_control_from_docks(control)
40-
60+

0 commit comments

Comments
 (0)
Please sign in to comment.