Polish title online and save slot interfaces

This commit is contained in:
Alexander Sellite 2026-08-23 23:04:15 -04:00
parent a3aea98982
commit 867fd431af
8 changed files with 463 additions and 86 deletions

View file

@ -32,6 +32,10 @@ const DIRECT_WORKFLOW_HELP: String = (
@onready var _direct_content: Control = %DirectContent
@onready var _list_content: Control = %ListContent
@onready var _list_title: Label = %ListTitle
@onready var _online_controls: Control = %OnlineControls
@onready var _presence_button: Button = %PresenceButton
@onready var _room_open_button: Button = %RoomOpenButton
@onready var _room_listing_button: Button = %RoomListingButton
@onready var _details_panel: PanelContainer = %DetailsPanel
@onready var _address: LineEdit = %Address
@onready var _address_label: Label = %AddressLabel
@ -89,6 +93,9 @@ func _ready() -> void:
_direct_button.pressed.connect(_set_mode.bind(Mode.DIRECT))
_saved_button.pressed.connect(_set_mode.bind(Mode.SAVED))
_recent_button.pressed.connect(_set_mode.bind(Mode.RECENT))
_presence_button.pressed.connect(_on_presence_pressed)
_room_open_button.pressed.connect(_on_room_open_pressed)
_room_listing_button.pressed.connect(_on_room_listing_pressed)
_refresh_button.pressed.connect(_request_discovery_refresh)
_join_button.pressed.connect(_request_join)
_save_button.pressed.connect(_on_save_pressed)
@ -238,6 +245,10 @@ func setup(
_on_peer_count_changed
):
_network_session.peer_count_changed.connect(_on_peer_count_changed)
if not _network_session.host_openness_changed.is_connected(
_on_host_openness_changed
):
_network_session.host_openness_changed.connect(_on_host_openness_changed)
if (
_saved_servers != null
and not _saved_servers.data_changed.is_connected(_on_store_changed)
@ -278,6 +289,22 @@ func setup(
_discovery.social_status_changed.connect(
_on_social_status_changed
)
if not _discovery.host_settings_changed.is_connected(
_on_host_settings_changed
):
_discovery.host_settings_changed.connect(
_on_host_settings_changed
)
if not _discovery.host_status_changed.is_connected(
_on_host_status_changed
):
_discovery.host_status_changed.connect(_on_host_status_changed)
if not _discovery.presence_sharing_changed.is_connected(
_on_presence_sharing_changed
):
_discovery.presence_sharing_changed.connect(
_on_presence_sharing_changed
)
_friend_entries = _discovery.get_friend_presence()
_refresh()
@ -792,6 +819,7 @@ func _refresh() -> void:
_direct_content.visible = direct_content_visible
_list_content.visible = list_content_visible
_list_title.text = _current_list_title()
_refresh_online_controls(discovery_mode, friends_mode, connecting)
_address.visible = direct or _name_entry_active
_address_label.visible = _address.visible
_address_helper.visible = _address.visible
@ -916,6 +944,66 @@ func _current_list_title() -> String:
return "public rooms"
func _refresh_online_controls(
discovery_mode: bool,
friends_mode: bool,
connecting: bool,
) -> void:
_online_controls.visible = discovery_mode and not _name_entry_active
_presence_button.visible = friends_mode and not _name_entry_active
var presence_enabled: bool = (
_discovery != null and _discovery.is_presence_sharing()
)
_presence_button.text = (
"friends: online" if presence_enabled else "friends: offline"
)
_presence_button.disabled = (
connecting or _discovery == null or not _discovery.is_configured()
)
_presence_button.tooltip_text = (
"Stay visible to friends until you switch this off. "
+ "Your current room is shared only while it is publicly joinable."
if presence_enabled
else "Show as online to friends until you switch this off."
)
if not _online_controls.visible:
return
var local_host: bool = _network_session.is_host()
_room_open_button.visible = local_host
_room_listing_button.visible = local_host
if not local_host:
return
var room_open: bool = _network_session.is_open_host()
var room_listed: bool = (
_discovery != null and _discovery.is_discoverable()
)
_room_open_button.text = "room: open" if room_open else "room: closed"
_room_open_button.disabled = connecting
_room_open_button.tooltip_text = (
"Close this room to new connections."
if room_open
else "Open this room so other players can connect."
)
_room_listing_button.text = (
"listing: on" if room_listed else "listing: off"
)
_room_listing_button.disabled = (
connecting
or _discovery == null
or not _discovery.is_configured()
or not room_open
)
_room_listing_button.tooltip_text = (
"Remove this room from the public room browser."
if room_listed
else "List this open room in the public room browser."
if room_open and _discovery != null and _discovery.is_configured()
else "Open the room before enabling its public listing."
if _discovery != null and _discovery.is_configured()
else "Room discovery is not configured in this build."
)
func _configure_controller_navigation() -> void:
var mode_buttons: Array[Control] = [
_discover_button,
@ -924,12 +1012,24 @@ func _configure_controller_navigation() -> void:
_saved_button,
_recent_button,
]
var online_controls: Array[Control] = []
for control: Control in [
_room_open_button,
_room_listing_button,
]:
if _controller_focus_eligible(control):
online_controls.append(control)
var content_controls: Array[Control] = []
for control: Control in [_address, _name_edit, _server_list]:
for control: Control in [
_address,
_name_edit,
_server_list,
]:
if _controller_focus_eligible(control):
content_controls.append(control)
var action_controls: Array[Control] = []
for control: Control in [
_presence_button,
_refresh_button,
_join_button,
_save_button,
@ -942,12 +1042,16 @@ func _configure_controller_navigation() -> void:
action_controls.append(control)
var all_controls: Array[Control] = []
all_controls.append_array(mode_buttons)
all_controls.append_array(online_controls)
all_controls.append_array(content_controls)
all_controls.append_array(action_controls)
all_controls.append(_back_button)
for control: Control in all_controls:
control.focus_mode = Control.FOCUS_ALL
for control: Control in [
_presence_button,
_room_open_button,
_room_listing_button,
_address,
_name_edit,
_server_list,
@ -963,7 +1067,9 @@ func _configure_controller_navigation() -> void:
control.focus_mode = Control.FOCUS_NONE
_back_button.focus_mode = Control.FOCUS_ALL
var primary_content: Control = (
content_controls.front()
online_controls.front()
if not online_controls.is_empty()
else content_controls.front()
if not content_controls.is_empty()
else action_controls.front()
if not action_controls.is_empty()
@ -978,11 +1084,29 @@ func _configure_controller_navigation() -> void:
mode_button,
primary_content,
)
for index: int in online_controls.size():
var online_control: Control = online_controls[index]
var below: Control = (
content_controls.front()
if not content_controls.is_empty()
else action_controls.front()
if not action_controls.is_empty()
else _back_button
)
_set_controller_neighbors(
online_control,
online_controls[maxi(index - 1, 0)],
online_controls[mini(index + 1, online_controls.size() - 1)],
mode_buttons[int(_mode)],
below,
)
for index: int in content_controls.size():
var content: Control = content_controls[index]
var above: Control = (
content_controls[index - 1]
if index > 0
else online_controls.front()
if not online_controls.is_empty()
else mode_buttons[int(_mode)]
)
var below: Control = (
@ -1001,6 +1125,8 @@ func _configure_controller_navigation() -> void:
action_controls[mini(index + 1, action_controls.size() - 1)],
content_controls.back()
if not content_controls.is_empty()
else online_controls.back()
if not online_controls.is_empty()
else mode_buttons[int(_mode)],
_back_button,
)
@ -1009,6 +1135,8 @@ func _configure_controller_navigation() -> void:
if not action_controls.is_empty()
else content_controls.back()
if not content_controls.is_empty()
else online_controls.back()
if not online_controls.is_empty()
else mode_buttons[int(_mode)]
)
_set_controller_neighbors(
@ -1270,6 +1398,76 @@ func _on_social_status_changed(message: String, is_error: bool) -> void:
_set_status(message, is_error)
func _on_presence_pressed() -> void:
if _discovery == null:
_set_status("Friend presence is not available.", true)
return
var enabling: bool = not _discovery.is_presence_sharing()
if not _discovery.set_presence_sharing(enabling):
return
_set_status(
"You will remain online to friends until you switch this off."
if enabling
else "You now appear offline to friends."
)
_refresh()
func _on_room_open_pressed() -> void:
if _network_session == null or not _network_session.is_host():
return
var opening: bool = not _network_session.is_open_host()
if not _network_session.set_host_open(opening):
_set_status("The room could not be updated.", true)
return
_set_status(
"The room is open to new connections."
if opening
else "The room is closed to new connections."
)
_refresh()
func _on_room_listing_pressed() -> void:
if _discovery == null:
return
var enabling: bool = not _discovery.is_discoverable()
if not _discovery.set_discoverable(enabling):
return
_set_status(
"The room is being listed publicly."
if enabling
else "The room is no longer listed publicly."
)
_refresh()
func _on_host_openness_changed(_is_open: bool) -> void:
_refresh()
func _on_host_settings_changed(
_room_name: String,
_discoverable: bool,
) -> void:
_refresh()
func _on_host_status_changed(message: String, is_error: bool) -> void:
if (
_mode == Mode.DISCOVER
and is_visible_in_tree()
and _network_session != null
and _network_session.is_host()
):
_set_status(message, is_error)
_refresh()
func _on_presence_sharing_changed(_enabled: bool) -> void:
_refresh()
func _format_result_code(result_code: String) -> String:
match result_code.strip_edges().to_upper():
"SUCCESS":

View file

@ -138,9 +138,35 @@ layout_mode = 2
theme_override_font_sizes/font_size = 20
text = "public rooms"
[node name="OnlineControls" type="HBoxContainer" parent="MainPanel/OuterMargin/Layout/ContentPanel/ContentMargin/ContentLayout/PageStack/ListContent"]
unique_name_in_owner = true
custom_minimum_size = Vector2(0, 42)
layout_mode = 2
theme_override_constants/separation = 10
[node name="OnlineControlsSpacer" type="Control" parent="MainPanel/OuterMargin/Layout/ContentPanel/ContentMargin/ContentLayout/PageStack/ListContent/OnlineControls"]
layout_mode = 2
size_flags_horizontal = 3
[node name="RoomOpenButton" type="Button" parent="MainPanel/OuterMargin/Layout/ContentPanel/ContentMargin/ContentLayout/PageStack/ListContent/OnlineControls"]
unique_name_in_owner = true
visible = false
custom_minimum_size = Vector2(160, 42)
layout_mode = 2
focus_mode = 2
text = "room: closed"
[node name="RoomListingButton" type="Button" parent="MainPanel/OuterMargin/Layout/ContentPanel/ContentMargin/ContentLayout/PageStack/ListContent/OnlineControls"]
unique_name_in_owner = true
visible = false
custom_minimum_size = Vector2(180, 42)
layout_mode = 2
focus_mode = 2
text = "listing: off"
[node name="ServerList" type="ItemList" parent="MainPanel/OuterMargin/Layout/ContentPanel/ContentMargin/ContentLayout/PageStack/ListContent"]
unique_name_in_owner = true
custom_minimum_size = Vector2(0, 180)
custom_minimum_size = Vector2(0, 140)
layout_mode = 2
size_flags_vertical = 3
theme_override_font_sizes/font_size = 17
@ -235,7 +261,18 @@ unique_name_in_owner = true
custom_minimum_size = Vector2(0, 46)
layout_mode = 2
theme_override_constants/separation = 10
alignment = 1
[node name="PresenceButton" type="Button" parent="MainPanel/OuterMargin/Layout/ContentPanel/ContentMargin/ContentLayout/Actions"]
unique_name_in_owner = true
visible = false
custom_minimum_size = Vector2(210, 46)
layout_mode = 2
focus_mode = 2
text = "friends: offline"
[node name="ActionsSpacer" type="Control" parent="MainPanel/OuterMargin/Layout/ContentPanel/ContentMargin/ContentLayout/Actions"]
layout_mode = 2
size_flags_horizontal = 3
[node name="RefreshButton" type="Button" parent="MainPanel/OuterMargin/Layout/ContentPanel/ContentMargin/ContentLayout/Actions"]
unique_name_in_owner = true