Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve editor 2D/3D main screen auto-switching logic #104010

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aaronfranke
Copy link
Member

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

@aaronfranke aaronfranke added this to the 4.x milestone Mar 12, 2025
@aaronfranke aaronfranke requested a review from a team as a code owner March 12, 2025 06:04
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.

1 participant