mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-10 16:04:04 +00:00
fix(ui): keep menu content reachable at any window size
The main menu clipped its own title and bottom button in debug builds. The project lays out in a hard-fixed 1920x1080 logical viewport (window/stretch/mode="viewport"), and the only overflow strategy in the scene was a CenterContainer, which centres its child rather than clipping and scrolling. With DevSection visible the content measures 1133px against 1080, so roughly 53px spilled off both ends with no way to reach it — and main_menu.gd grabs focus on a button that may itself be off-screen. Worth recording because it is counter-intuitive: this is not resolution-dependent. Because the viewport is fixed, a 4K display magnifies the same clipped 1080p frame rather than giving the menu more room, so the fix has to make the layout scroll, not scale. Each menu is now MarginContainer > ScrollContainer > CenterContainer > VBoxContainer. ScrollContainer sizes its child to max(own size, child minimum), so an expanding CenterContainer keeps today's centred look when the content is short and grows past the viewport when it is tall — which is exactly when scrolling should start. follow_focus is on so keyboard and controller navigation cannot strand focus off-screen. Lobby and matchmaking share the same shape and get the same treatment before they hit the same wall; settings gained its wrapper alongside the Controls tab. Also stops the dev bot dropdowns widening the whole menu: they are filled from res://bots filenames and expand horizontally, so a long checkpoint name dragged the layout past its 420px minimum. test_menu_layout asserts each screen's bottom-most control really sits inside a ScrollContainer. That is a structural guard against the wrapper being removed or a new section being added outside it — not proof that nothing visually clips, which was checked by hand at 1000x600, 1280x720 and 1920x1080.
This commit is contained in:
@@ -52,7 +52,7 @@ func _ready() -> void:
|
||||
_populate_dropdown(bot_b_dropdown, bots, GameSettings.spectate_bot_b_path)
|
||||
NetworkManager.connected_to_server.connect(_on_connected_to_server)
|
||||
NetworkManager.connection_failed.connect(_on_connection_failed)
|
||||
$CenterContainer/VBoxContainer/FreePlayButton.grab_focus()
|
||||
%FreePlayButton.grab_focus()
|
||||
|
||||
|
||||
# main_menu.gd's first async flow (task 1.7): Host is synchronous
|
||||
@@ -120,6 +120,11 @@ func _list_bots() -> Array[String]:
|
||||
# disk, else the newest (last) bot.
|
||||
func _populate_dropdown(dropdown: OptionButton, bots: Array[String], preferred_path: String, include_none: bool = false) -> void:
|
||||
dropdown.clear()
|
||||
# These are filled from whatever checkpoints happen to be in res://bots, so
|
||||
# a long filename would otherwise widen the OptionButton (size_flags_h =
|
||||
# EXPAND_FILL) and drag the whole menu past its 420px minimum width.
|
||||
dropdown.clip_text = true
|
||||
dropdown.fit_to_longest_item = false
|
||||
if include_none:
|
||||
dropdown.add_item("(Use difficulty)")
|
||||
dropdown.set_item_metadata(0, "")
|
||||
@@ -173,7 +178,7 @@ func _on_match_pressed() -> void:
|
||||
|
||||
|
||||
func _on_settings_pressed() -> void:
|
||||
get_tree().change_scene_to_file("res://scenes/settings.tscn")
|
||||
get_tree().change_scene_to_file(ScenePaths.SETTINGS)
|
||||
|
||||
|
||||
func _on_spectate_pressed() -> void:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class_name ScenePaths
|
||||
|
||||
const MAIN_MENU := "res://scenes/main_menu.tscn"
|
||||
const SETTINGS := "res://scenes/settings.tscn"
|
||||
# §6.2 step 10: after RESULTS both peers return HERE, not to the main menu —
|
||||
# a community server whose players are all dumped back to their own menus
|
||||
# every 2.5 minutes has no way to keep a lobby together.
|
||||
|
||||
Reference in New Issue
Block a user