Skip to content

Conversation

@aaronfranke
Copy link
Member

@aaronfranke aaronfranke commented Mar 12, 2025

In master, Godot has a feature where the main screen tabs may auto-switch depending on the node type being edited.

  • When editing a 2D scene or selecting a 2D node, and the 3D tab is selected, switch to 2D.
  • When editing a 3D scene or selecting a 3D node, and the 2D tab is selected, switch to 3D.
  • When creating a new 2D or 3D scene, and the tab isn't the script editor (2D/3D/Game/AssetLib/custom), switch.

Seems simple enough. However, the code currently has the following problems:

  • There is a hard-coded assumption that the script editor is at index 2.
  • Instead of using func _handles on each plugin, there is hard-coded logic to check for CanvasItem and Node3D.
  • The logic does not behave the same when creating scenes as it does when editing scenes or nodes.
  • There is some dead code in the script editor for deciding when to switch (it always returns true, but never happens).
main_screen_switch_current_master.mp4

This PR makes the following changes:

  • New function bool EditorMainScreen::can_auto_switch_screens() const.
    • This is used both when editing nodes/scenes and when creating new ones, so now the logic is unified.
    • Instead of hard-coding an index for Script, check what position it's at. The new logic is that any tab to the left of Script is considered auto-switch-away-able, and auto-switch-to-able is determined by func _handles.
    • For the built-in tabs, this does change behavior in one case: creating a new scene when either the Game or AssetLib tabs are active will keep you on those tabs, just like editing a scene already does.
  • Set a human-readable unique name for the EditorMainScreenButtons HBoxContainer.
  • Remove the dead can_take_away_focus and can_lose_focus_on_node_selection functions.

This now works correctly for custom node types and main screen tabs placed to the left of Script:

main_screen_switch_with_pr.mp4

Implements and closes godotengine/godot-proposals#12154

@aaronfranke
Copy link
Member Author

@kitbdev You may be interested in reviewing this, since you've worked on the EditorMainScreen class before.

Copy link
Contributor

@kitbdev kitbdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually started a review but forgot to finish it, thanks for reminding me.

I don't think moving buttons around is properly supported, but I don't see a problem with the changes supporting it. The next and previous shortcuts don't use button order for example.
The other switching logic changes make sense too.

Also you can mention in the OP that this fixes godotengine/godot-proposals#12154

@aaronfranke aaronfranke force-pushed the main-screen-auto-switch branch from aff433e to acd050b Compare April 9, 2025 15:55
@aaronfranke aaronfranke force-pushed the main-screen-auto-switch branch from acd050b to c13d4e7 Compare April 9, 2025 16:14
@aaronfranke aaronfranke force-pushed the main-screen-auto-switch branch from 19a3e9f to db6a212 Compare April 9, 2025 16:33
Co-authored-by: Kit Bishop <kitbdev@gmail.com>
@aaronfranke aaronfranke force-pushed the main-screen-auto-switch branch from db6a212 to d9e1f5d Compare April 9, 2025 16:35
Copy link
Member

@Calinou Calinou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, it works as expected. Code looks good to me.

@kitbdev kitbdev modified the milestones: 4.x, 4.5 May 9, 2025
@Repiteo Repiteo merged commit 67b3db8 into godotengine:master May 14, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented May 14, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stopping The Changing of Workspace from Game to (3D or 2D) when selecting node in Scene Tree at *Runtime*

5 participants