Add public room discovery
This commit is contained in:
parent
59ef173ea7
commit
e204279b09
16 changed files with 857 additions and 22 deletions
|
|
@ -277,6 +277,7 @@ func setup(
|
|||
reservations: PlayerAssetReservationService,
|
||||
network_profile_service: NetworkProfileService,
|
||||
network_player_list: NetworkPlayerListService,
|
||||
discovery: DiscoveryClient,
|
||||
settings_manager: PlayerSettingsManagerType,
|
||||
surface_drawing: NetworkSurfaceDrawingService,
|
||||
art_unlocks: PlayerArtUnlocks,
|
||||
|
|
@ -372,6 +373,7 @@ func setup(
|
|||
reservations,
|
||||
network_profile_service,
|
||||
network_player_list,
|
||||
discovery,
|
||||
player_jobs,
|
||||
world_time,
|
||||
world_environment,
|
||||
|
|
|
|||
|
|
@ -5,11 +5,14 @@ signal join_requested(endpoint: String)
|
|||
signal back_requested
|
||||
|
||||
enum Mode {
|
||||
DISCOVER,
|
||||
DIRECT,
|
||||
SAVED,
|
||||
RECENT,
|
||||
}
|
||||
|
||||
const DISCOVERY_REFRESH_SECONDS: float = 8.0
|
||||
|
||||
const ADDRESS_FORMAT_HELP: String = (
|
||||
"Hostname, IPv4, or [IPv6]. Port 7777 is used when omitted; "
|
||||
+ "include the port shown by a host when it differs."
|
||||
|
|
@ -27,10 +30,12 @@ const DIRECT_WORKFLOW_HELP: String = (
|
|||
@onready var _name_helper: Label = %NameHelper
|
||||
@onready var _server_list: ItemList = %ServerList
|
||||
@onready var _details: Label = %Details
|
||||
@onready var _discover_button: Button = %DiscoverButton
|
||||
@onready var _direct_button: Button = %DirectButton
|
||||
@onready var _saved_button: Button = %SavedButton
|
||||
@onready var _recent_button: Button = %RecentButton
|
||||
@onready var _join_button: Button = %JoinButton
|
||||
@onready var _refresh_button: Button = %RefreshButton
|
||||
@onready var _save_button: Button = %SaveButton
|
||||
@onready var _edit_button: Button = %EditButton
|
||||
@onready var _favorite_button: Button = %FavoriteButton
|
||||
|
|
@ -47,10 +52,14 @@ const DIRECT_WORKFLOW_HELP: String = (
|
|||
var _network_session: NetworkSession
|
||||
var _saved_servers: SavedServerStore
|
||||
var _server_trust: ServerTrustStore
|
||||
var _discovery: DiscoveryClient
|
||||
var _gameplay_context: bool = false
|
||||
var _mode: Mode = Mode.DIRECT
|
||||
var _mode: Mode = Mode.DISCOVER
|
||||
var _visible_entries: Array[SavedServerEntry] = []
|
||||
var _selected_entry: SavedServerEntry
|
||||
var _discovery_rooms: Array[Dictionary] = []
|
||||
var _selected_discovery_index: int = -1
|
||||
var _discovery_refresh_timer: Timer
|
||||
var _editing_entry_id: String = ""
|
||||
var _name_entry_active: bool = false
|
||||
var _delete_armed: bool = false
|
||||
|
|
@ -63,16 +72,19 @@ func _ready() -> void:
|
|||
"panel", UtilityPageStyle.panel_style()
|
||||
)
|
||||
for button: BaseButton in [
|
||||
_direct_button, _saved_button, _recent_button, _join_button,
|
||||
_discover_button, _direct_button, _saved_button, _recent_button,
|
||||
_refresh_button, _join_button,
|
||||
_save_button, _edit_button, _favorite_button, _delete_button,
|
||||
_cancel_button, _back_button, _open_close_button,
|
||||
]:
|
||||
UtilityPageStyle.apply_ocean_button(button)
|
||||
UtilityPageStyle.apply_ocean_line_edit(_address)
|
||||
UtilityPageStyle.apply_ocean_line_edit(_name_edit)
|
||||
_discover_button.pressed.connect(_set_mode.bind(Mode.DISCOVER))
|
||||
_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))
|
||||
_refresh_button.pressed.connect(_request_discovery_refresh)
|
||||
_join_button.pressed.connect(_request_join)
|
||||
_save_button.pressed.connect(_on_save_pressed)
|
||||
_edit_button.pressed.connect(_on_edit_pressed)
|
||||
|
|
@ -97,6 +109,11 @@ func _ready() -> void:
|
|||
)
|
||||
_delete_confirmation.confirmed.connect(_confirm_delete)
|
||||
_delete_confirmation.cancelled.connect(_cancel_delete)
|
||||
_discovery_refresh_timer = Timer.new()
|
||||
_discovery_refresh_timer.wait_time = DISCOVERY_REFRESH_SECONDS
|
||||
_discovery_refresh_timer.one_shot = false
|
||||
_discovery_refresh_timer.timeout.connect(_request_discovery_refresh)
|
||||
add_child(_discovery_refresh_timer)
|
||||
hide()
|
||||
|
||||
|
||||
|
|
@ -105,11 +122,13 @@ func setup(
|
|||
saved_servers: SavedServerStore,
|
||||
gameplay_context: bool,
|
||||
server_trust: ServerTrustStore = null,
|
||||
discovery: DiscoveryClient = null,
|
||||
) -> void:
|
||||
_network_session = network_session
|
||||
_saved_servers = saved_servers
|
||||
_gameplay_context = gameplay_context
|
||||
_server_trust = server_trust
|
||||
_discovery = discovery
|
||||
if not _network_session.state_changed.is_connected(_on_state_changed):
|
||||
_network_session.state_changed.connect(_on_state_changed)
|
||||
if not _network_session.status_message_changed.is_connected(
|
||||
|
|
@ -131,6 +150,17 @@ func setup(
|
|||
and not _saved_servers.data_changed.is_connected(_on_store_changed)
|
||||
):
|
||||
_saved_servers.data_changed.connect(_on_store_changed)
|
||||
if _discovery != null:
|
||||
if not _discovery.rooms_updated.is_connected(
|
||||
_on_discovery_rooms_updated
|
||||
):
|
||||
_discovery.rooms_updated.connect(_on_discovery_rooms_updated)
|
||||
if not _discovery.browse_status_changed.is_connected(
|
||||
_on_discovery_status_changed
|
||||
):
|
||||
_discovery.browse_status_changed.connect(
|
||||
_on_discovery_status_changed
|
||||
)
|
||||
_refresh()
|
||||
|
||||
|
||||
|
|
@ -149,6 +179,7 @@ func open_page(preserved_endpoint: String = "") -> void:
|
|||
|
||||
func close_page() -> void:
|
||||
_clear_edit_state()
|
||||
_discovery_refresh_timer.stop()
|
||||
hide()
|
||||
var current_viewport: Viewport = get_viewport()
|
||||
if current_viewport != null:
|
||||
|
|
@ -166,9 +197,15 @@ func set_status(message: String) -> void:
|
|||
func _set_mode(mode: Mode) -> void:
|
||||
_mode = mode
|
||||
_selected_entry = null
|
||||
_selected_discovery_index = -1
|
||||
_clear_edit_state()
|
||||
_refresh_entries()
|
||||
_refresh()
|
||||
if mode == Mode.DISCOVER:
|
||||
_discovery_refresh_timer.start()
|
||||
_request_discovery_refresh()
|
||||
else:
|
||||
_discovery_refresh_timer.stop()
|
||||
if not is_visible_in_tree():
|
||||
return
|
||||
if mode == Mode.DIRECT:
|
||||
|
|
@ -183,11 +220,15 @@ func _request_join() -> void:
|
|||
NetworkSession.State.SERVER_LOST,
|
||||
]:
|
||||
_network_session.reset_failure()
|
||||
var endpoint_text: String = (
|
||||
_selected_entry.normalized_endpoint
|
||||
if _mode != Mode.DIRECT and _selected_entry != null
|
||||
else _address.text
|
||||
)
|
||||
var endpoint_text: String = _address.text
|
||||
if _mode == Mode.DISCOVER:
|
||||
var room: Dictionary = _selected_discovery_room()
|
||||
if _discovery_room_is_full(room):
|
||||
_set_status("That room is full.", true)
|
||||
return
|
||||
endpoint_text = _discovery.room_endpoint(room) if _discovery != null else ""
|
||||
elif _mode != Mode.DIRECT and _selected_entry != null:
|
||||
endpoint_text = _selected_entry.normalized_endpoint
|
||||
var endpoint: ConnectionEndpoint = EndpointParser.parse(endpoint_text)
|
||||
if not endpoint.is_valid():
|
||||
_set_status(endpoint.error_message, true)
|
||||
|
|
@ -339,6 +380,13 @@ func _cancel_delete() -> void:
|
|||
|
||||
|
||||
func _on_list_item_selected(index: int) -> void:
|
||||
if _mode == Mode.DISCOVER:
|
||||
if index < 0 or index >= _discovery_rooms.size():
|
||||
return
|
||||
_selected_discovery_index = index
|
||||
_selected_entry = null
|
||||
_refresh()
|
||||
return
|
||||
if index < 0 or index >= _visible_entries.size():
|
||||
return
|
||||
_selected_entry = _visible_entries[index]
|
||||
|
|
@ -357,6 +405,19 @@ func _select_entry_id(entry_id: String) -> void:
|
|||
func _refresh_entries() -> void:
|
||||
_visible_entries.clear()
|
||||
_server_list.clear()
|
||||
if _mode == Mode.DISCOVER:
|
||||
for room: Dictionary in _discovery_rooms:
|
||||
var player_count: int = int(room.get("current_players", 0))
|
||||
var maximum: int = int(room.get("max_players", 0))
|
||||
_server_list.add_item(
|
||||
"%s — %d / %d players%s" % [
|
||||
str(room.get("room_name", "Public room")),
|
||||
player_count,
|
||||
maximum,
|
||||
" — full" if player_count >= maximum else "",
|
||||
]
|
||||
)
|
||||
return
|
||||
if _saved_servers == null or _mode == Mode.DIRECT:
|
||||
return
|
||||
_visible_entries = (
|
||||
|
|
@ -394,7 +455,16 @@ func _refresh() -> void:
|
|||
NetworkSession.State.AUTHENTICATING,
|
||||
]
|
||||
var direct: bool = _mode == Mode.DIRECT
|
||||
var selected: bool = _selected_entry != null
|
||||
var discovery_mode: bool = _mode == Mode.DISCOVER
|
||||
var selected: bool = (
|
||||
_selected_discovery_index >= 0
|
||||
if discovery_mode
|
||||
else _selected_entry != null
|
||||
)
|
||||
_discover_button.button_pressed = discovery_mode
|
||||
_direct_button.button_pressed = direct
|
||||
_saved_button.button_pressed = _mode == Mode.SAVED
|
||||
_recent_button.button_pressed = _mode == Mode.RECENT
|
||||
_address.visible = direct or _name_entry_active
|
||||
_address_label.visible = _address.visible
|
||||
_address_helper.visible = _address.visible
|
||||
|
|
@ -407,9 +477,20 @@ func _refresh() -> void:
|
|||
_name_helper.visible = _name_entry_active
|
||||
_server_list.visible = not direct and not _name_entry_active
|
||||
_details.visible = not direct and not _name_entry_active
|
||||
_join_button.disabled = connecting or (not direct and not selected)
|
||||
_join_button.disabled = (
|
||||
connecting
|
||||
or (not direct and not selected)
|
||||
or (
|
||||
discovery_mode
|
||||
and selected
|
||||
and _discovery_room_is_full(_selected_discovery_room())
|
||||
)
|
||||
)
|
||||
_join_button.text = "join\nnow" if direct else "join"
|
||||
_save_button.visible = direct or _mode == Mode.RECENT or _name_entry_active
|
||||
_refresh_button.visible = discovery_mode and not _name_entry_active
|
||||
_save_button.visible = (
|
||||
direct or _mode == Mode.RECENT or _name_entry_active
|
||||
)
|
||||
_save_button.disabled = connecting or (
|
||||
_mode == Mode.RECENT and not selected and not _name_entry_active
|
||||
)
|
||||
|
|
@ -418,10 +499,14 @@ func _refresh() -> void:
|
|||
_favorite_button.visible = _mode == Mode.SAVED and selected
|
||||
_favorite_button.text = (
|
||||
"unfavorite"
|
||||
if selected and _selected_entry.favorite
|
||||
if _mode == Mode.SAVED
|
||||
and _selected_entry != null
|
||||
and _selected_entry.favorite
|
||||
else "favorite"
|
||||
)
|
||||
_delete_button.visible = not direct and selected
|
||||
_delete_button.visible = (
|
||||
_mode in [Mode.SAVED, Mode.RECENT] and selected
|
||||
)
|
||||
_delete_button.text = "remove" if _mode == Mode.RECENT else "delete"
|
||||
_cancel_button.visible = connecting
|
||||
_open_close_button.visible = (
|
||||
|
|
@ -453,10 +538,20 @@ func _refresh() -> void:
|
|||
)
|
||||
if not direct:
|
||||
if selected:
|
||||
_details.text = _format_entry_details(_selected_entry)
|
||||
elif _visible_entries.is_empty():
|
||||
_details.text = (
|
||||
"No saved servers yet."
|
||||
_format_discovery_details(_selected_discovery_room())
|
||||
if discovery_mode
|
||||
else _format_entry_details(_selected_entry)
|
||||
)
|
||||
elif (
|
||||
_discovery_rooms.is_empty()
|
||||
if discovery_mode
|
||||
else _visible_entries.is_empty()
|
||||
):
|
||||
_details.text = (
|
||||
"No public rooms are available."
|
||||
if discovery_mode
|
||||
else "No saved servers yet."
|
||||
if _mode == Mode.SAVED
|
||||
else "No recent connections yet."
|
||||
)
|
||||
|
|
@ -464,7 +559,7 @@ func _refresh() -> void:
|
|||
_details.text = "Select a server."
|
||||
var warning: String = (
|
||||
_saved_servers.get_recovery_warning()
|
||||
if _saved_servers != null
|
||||
if _saved_servers != null and not discovery_mode
|
||||
else ""
|
||||
)
|
||||
if not warning.is_empty() and _status.text.is_empty():
|
||||
|
|
@ -517,6 +612,69 @@ func _format_entry_details(entry: SavedServerEntry) -> String:
|
|||
return "\n".join(parts)
|
||||
|
||||
|
||||
func _format_discovery_details(room: Dictionary) -> String:
|
||||
if room.is_empty():
|
||||
return "Select a public room."
|
||||
return "\n".join([
|
||||
"Room: %s" % str(room.get("room_name", "Public room")),
|
||||
"Players: %d / %d" % [
|
||||
int(room.get("current_players", 0)),
|
||||
int(room.get("max_players", 0)),
|
||||
],
|
||||
"Connection: %s" % (
|
||||
_discovery.room_endpoint(room) if _discovery != null else "—"
|
||||
),
|
||||
"Direct UDP connection • ping is measured after joining",
|
||||
])
|
||||
|
||||
|
||||
func _selected_discovery_room() -> Dictionary:
|
||||
if (
|
||||
_selected_discovery_index < 0
|
||||
or _selected_discovery_index >= _discovery_rooms.size()
|
||||
):
|
||||
return {}
|
||||
return _discovery_rooms[_selected_discovery_index]
|
||||
|
||||
|
||||
func _discovery_room_is_full(room: Dictionary) -> bool:
|
||||
if room.is_empty():
|
||||
return false
|
||||
return int(room.get("current_players", 0)) >= int(room.get("max_players", 0))
|
||||
|
||||
|
||||
func _request_discovery_refresh() -> void:
|
||||
if (
|
||||
_discovery == null
|
||||
or _mode != Mode.DISCOVER
|
||||
or not is_visible_in_tree()
|
||||
):
|
||||
return
|
||||
_discovery.request_rooms()
|
||||
|
||||
|
||||
func _on_discovery_rooms_updated(rooms: Array[Dictionary]) -> void:
|
||||
var selected_id: String = str(
|
||||
_selected_discovery_room().get("room_id", "")
|
||||
)
|
||||
_discovery_rooms = rooms.duplicate(true)
|
||||
_selected_discovery_index = -1
|
||||
if _mode == Mode.DISCOVER:
|
||||
_refresh_entries()
|
||||
if not selected_id.is_empty():
|
||||
for index: int in _discovery_rooms.size():
|
||||
if str(_discovery_rooms[index].get("room_id", "")) == selected_id:
|
||||
_selected_discovery_index = index
|
||||
_server_list.select(index)
|
||||
break
|
||||
_refresh()
|
||||
|
||||
|
||||
func _on_discovery_status_changed(message: String, is_error: bool) -> void:
|
||||
if _mode == Mode.DISCOVER and is_visible_in_tree():
|
||||
_set_status(message, is_error)
|
||||
|
||||
|
||||
func _format_result_code(result_code: String) -> String:
|
||||
match result_code.strip_edges().to_upper():
|
||||
"SUCCESS":
|
||||
|
|
|
|||
|
|
@ -114,22 +114,32 @@ layout_mode = 2
|
|||
theme_override_constants/separation = 14
|
||||
alignment = 1
|
||||
|
||||
[node name="DiscoverButton" type="Button" parent="Paper/Margin/Layout/Modes"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(100, 72)
|
||||
layout_mode = 2
|
||||
toggle_mode = true
|
||||
text = "discover"
|
||||
|
||||
[node name="DirectButton" type="Button" parent="Paper/Margin/Layout/Modes"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(100, 72)
|
||||
layout_mode = 2
|
||||
toggle_mode = true
|
||||
text = "direct"
|
||||
|
||||
[node name="SavedButton" type="Button" parent="Paper/Margin/Layout/Modes"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(100, 72)
|
||||
layout_mode = 2
|
||||
toggle_mode = true
|
||||
text = "saved"
|
||||
|
||||
[node name="RecentButton" type="Button" parent="Paper/Margin/Layout/Modes"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(100, 72)
|
||||
layout_mode = 2
|
||||
toggle_mode = true
|
||||
text = "recent"
|
||||
|
||||
[node name="AddressLabel" type="Label" parent="Paper/Margin/Layout"]
|
||||
|
|
@ -258,6 +268,13 @@ layout_mode = 2
|
|||
theme_override_constants/separation = 7
|
||||
alignment = 1
|
||||
|
||||
[node name="RefreshButton" type="Button" parent="Paper/Margin/Layout/Actions"]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
custom_minimum_size = Vector2(82, 72)
|
||||
layout_mode = 2
|
||||
text = "refresh"
|
||||
|
||||
[node name="JoinButton" type="Button" parent="Paper/Margin/Layout/Actions"]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(82, 72)
|
||||
|
|
|
|||
|
|
@ -107,6 +107,7 @@ func setup(
|
|||
network_session: NetworkSessionType,
|
||||
saved_servers: SavedServerStoreType,
|
||||
server_trust: ServerTrustStore,
|
||||
discovery: DiscoveryClient,
|
||||
) -> void:
|
||||
_player = player
|
||||
_save_manager = save_manager
|
||||
|
|
@ -114,7 +115,9 @@ func setup(
|
|||
_fishing_spot = fishing_spot
|
||||
_network_session = network_session
|
||||
_saved_servers = saved_servers
|
||||
_join_game_page.setup(network_session, saved_servers, true, server_trust)
|
||||
_join_game_page.setup(
|
||||
network_session, saved_servers, true, server_trust, discovery
|
||||
)
|
||||
if not _fishing_spot.bite_activated.is_connected(_on_bite_activated):
|
||||
_fishing_spot.bite_activated.connect(_on_bite_activated)
|
||||
|
||||
|
|
|
|||
|
|
@ -526,6 +526,7 @@ func setup(
|
|||
reservations: PlayerAssetReservationService,
|
||||
network_profile_service: NetworkProfileService,
|
||||
network_player_list: NetworkPlayerListService,
|
||||
discovery: DiscoveryClient,
|
||||
player_jobs: PlayerJobService,
|
||||
world_time: WorldTimeService,
|
||||
world_environment: WorldEnvironment,
|
||||
|
|
@ -558,7 +559,7 @@ func setup(
|
|||
world_environment,
|
||||
world_sun,
|
||||
)
|
||||
_players_page.setup(network_player_list)
|
||||
_players_page.setup(network_player_list, discovery)
|
||||
_catalog_logbook.setup(collection_log, inventory, catalog)
|
||||
_the_net_page.setup(player_jobs, world_time)
|
||||
_network_mail_service.unread_count_changed.connect(
|
||||
|
|
|
|||
|
|
@ -2,10 +2,15 @@ class_name PlayersPage
|
|||
extends Control
|
||||
|
||||
var _service: NetworkPlayerListService
|
||||
var _discovery: DiscoveryClient
|
||||
var _count_label: Label
|
||||
var _tabs: HBoxContainer
|
||||
var _list: VBoxContainer
|
||||
var _status: Label
|
||||
var _host_settings_panel: PanelContainer
|
||||
var _room_name_edit: LineEdit
|
||||
var _discoverable_toggle: CheckButton
|
||||
var _host_discovery_status: Label
|
||||
var _current_tab := 0
|
||||
|
||||
|
||||
|
|
@ -15,13 +20,22 @@ func _ready() -> void:
|
|||
_build()
|
||||
|
||||
|
||||
func setup(service: NetworkPlayerListService) -> void:
|
||||
func setup(
|
||||
service: NetworkPlayerListService,
|
||||
discovery: DiscoveryClient,
|
||||
) -> void:
|
||||
_service = service
|
||||
_discovery = discovery
|
||||
_service.entries_changed.connect(_refresh)
|
||||
_service.moderation_finished.connect(func(_ok: bool, message: String) -> void:
|
||||
_status.text = message
|
||||
_refresh()
|
||||
)
|
||||
if _discovery != null:
|
||||
_discovery.host_settings_changed.connect(
|
||||
_on_host_settings_changed
|
||||
)
|
||||
_discovery.host_status_changed.connect(_on_host_status_changed)
|
||||
_refresh()
|
||||
|
||||
|
||||
|
|
@ -61,6 +75,7 @@ func _build() -> void:
|
|||
)
|
||||
_count_label.vertical_alignment = VERTICAL_ALIGNMENT_CENTER
|
||||
tab_row.add_child(_count_label)
|
||||
_build_host_settings(root)
|
||||
var scroll := ScrollContainer.new()
|
||||
scroll.custom_minimum_size = Vector2(0, 310)
|
||||
scroll.size_flags_vertical = Control.SIZE_EXPAND_FILL
|
||||
|
|
@ -77,6 +92,47 @@ func _build() -> void:
|
|||
root.add_child(_status)
|
||||
|
||||
|
||||
func _build_host_settings(root: VBoxContainer) -> void:
|
||||
_host_settings_panel = PanelContainer.new()
|
||||
_host_settings_panel.add_theme_stylebox_override(
|
||||
"panel", UtilityPageStyle.row_style(false)
|
||||
)
|
||||
root.add_child(_host_settings_panel)
|
||||
var row := HBoxContainer.new()
|
||||
row.custom_minimum_size.y = 58.0
|
||||
row.add_theme_constant_override("separation", 10)
|
||||
_host_settings_panel.add_child(row)
|
||||
var label := Label.new()
|
||||
label.text = "room name"
|
||||
label.add_theme_color_override(
|
||||
"font_color", UtilityPageStyle.OCEAN_TEXT_SECONDARY
|
||||
)
|
||||
row.add_child(label)
|
||||
_room_name_edit = LineEdit.new()
|
||||
_room_name_edit.custom_minimum_size = Vector2(300.0, 42.0)
|
||||
_room_name_edit.max_length = DiscoveryClient.MAX_ROOM_NAME_LENGTH
|
||||
_room_name_edit.placeholder_text = DiscoveryClient.DEFAULT_ROOM_NAME
|
||||
UtilityPageStyle.apply_ocean_line_edit(_room_name_edit)
|
||||
_room_name_edit.text_submitted.connect(
|
||||
func(_value: String) -> void: _commit_room_name()
|
||||
)
|
||||
_room_name_edit.focus_exited.connect(_commit_room_name)
|
||||
row.add_child(_room_name_edit)
|
||||
_discoverable_toggle = CheckButton.new()
|
||||
_discoverable_toggle.text = "list publicly"
|
||||
_discoverable_toggle.toggled.connect(_on_discoverable_toggled)
|
||||
UtilityPageStyle.apply_ocean_button(_discoverable_toggle)
|
||||
row.add_child(_discoverable_toggle)
|
||||
_host_discovery_status = Label.new()
|
||||
_host_discovery_status.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
_host_discovery_status.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
|
||||
_host_discovery_status.add_theme_font_size_override("font_size", 14)
|
||||
_host_discovery_status.add_theme_color_override(
|
||||
"font_color", UtilityPageStyle.OCEAN_TEXT_SECONDARY
|
||||
)
|
||||
row.add_child(_host_discovery_status)
|
||||
|
||||
|
||||
func _select_tab(index: int) -> void:
|
||||
if index == 2 and (_service == null or not _service.is_local_host()):
|
||||
return
|
||||
|
|
@ -95,6 +151,7 @@ func _refresh() -> void:
|
|||
var button := _tabs.get_child(index) as Button
|
||||
button.button_pressed = index == _current_tab
|
||||
button.visible = index != 2 or _service.is_local_host()
|
||||
_refresh_host_settings()
|
||||
for child: Node in _list.get_children():
|
||||
child.queue_free()
|
||||
match _current_tab:
|
||||
|
|
@ -106,6 +163,76 @@ func _refresh() -> void:
|
|||
_build_ban_rows()
|
||||
|
||||
|
||||
func _refresh_host_settings() -> void:
|
||||
if _host_settings_panel == null:
|
||||
return
|
||||
var host_visible: bool = _service.is_local_host() and _current_tab == 0
|
||||
_host_settings_panel.visible = host_visible
|
||||
if not host_visible or _discovery == null:
|
||||
return
|
||||
if not _room_name_edit.has_focus():
|
||||
_room_name_edit.text = _discovery.get_room_name()
|
||||
_discoverable_toggle.set_pressed_no_signal(_discovery.is_discoverable())
|
||||
var can_publish: bool = (
|
||||
_service.is_local_host()
|
||||
and _discovery.is_configured()
|
||||
and _service.is_open_host()
|
||||
)
|
||||
_discoverable_toggle.disabled = not can_publish
|
||||
_discoverable_toggle.tooltip_text = (
|
||||
"Advertise this open game in the public room browser."
|
||||
if can_publish
|
||||
else "Open the game before listing it publicly."
|
||||
if _discovery.is_configured()
|
||||
else "Room discovery is not configured in this build."
|
||||
)
|
||||
_on_host_status_changed(
|
||||
_discovery.get_host_status_message(),
|
||||
_discovery.host_status_is_error(),
|
||||
)
|
||||
|
||||
|
||||
func _commit_room_name() -> void:
|
||||
if _discovery == null:
|
||||
return
|
||||
if not _discovery.set_room_name(_room_name_edit.text):
|
||||
_room_name_edit.text = _discovery.get_room_name()
|
||||
else:
|
||||
_room_name_edit.text = _discovery.get_room_name()
|
||||
|
||||
|
||||
func _on_discoverable_toggled(enabled: bool) -> void:
|
||||
if _discovery == null:
|
||||
return
|
||||
if not _discovery.set_discoverable(enabled):
|
||||
_discoverable_toggle.set_pressed_no_signal(
|
||||
_discovery.is_discoverable()
|
||||
)
|
||||
|
||||
|
||||
func _on_host_settings_changed(
|
||||
room_name: String,
|
||||
discoverable: bool,
|
||||
) -> void:
|
||||
if _room_name_edit != null and not _room_name_edit.has_focus():
|
||||
_room_name_edit.text = room_name
|
||||
if _discoverable_toggle != null:
|
||||
_discoverable_toggle.set_pressed_no_signal(discoverable)
|
||||
_refresh_host_settings()
|
||||
|
||||
|
||||
func _on_host_status_changed(message: String, is_error: bool) -> void:
|
||||
if _host_discovery_status == null:
|
||||
return
|
||||
_host_discovery_status.text = message
|
||||
_host_discovery_status.add_theme_color_override(
|
||||
"font_color",
|
||||
UtilityPageStyle.OCEAN_DANGER
|
||||
if is_error
|
||||
else UtilityPageStyle.OCEAN_TEXT_SECONDARY,
|
||||
)
|
||||
|
||||
|
||||
func _build_active_rows() -> void:
|
||||
if _service.is_local_host():
|
||||
_build_session_artwork_controls()
|
||||
|
|
|
|||
|
|
@ -236,10 +236,13 @@ func setup(
|
|||
network_session: NetworkSessionType,
|
||||
saved_servers: SavedServerStoreType,
|
||||
server_trust: ServerTrustStore,
|
||||
discovery: DiscoveryClient,
|
||||
) -> void:
|
||||
_save_manager = save_manager
|
||||
_settings_manager = settings_manager
|
||||
_join_game_page.setup(network_session, saved_servers, false, server_trust)
|
||||
_join_game_page.setup(
|
||||
network_session, saved_servers, false, server_trust, discovery
|
||||
)
|
||||
_join_game_page.join_requested.connect(join_game_requested.emit)
|
||||
_join_game_page.back_requested.connect(_close_join_game)
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue