diff --git a/plugin/demo/scenes/players/Players.gd b/plugin/demo/scenes/players/Players.gd index b003364..416f265 100644 --- a/plugin/demo/scenes/players/Players.gd +++ b/plugin/demo/scenes/players/Players.gd @@ -5,12 +5,22 @@ extends Control @onready var search_button: Button = %SearchButton @onready var search_display: VBoxContainer = %SearchDisplay +@onready var current_player_display: VBoxContainer = %CurrentPlayerDisplay + @onready var friends_display: VBoxContainer = %FriendsDisplay +var _current_player: PlayersClient.Player var _friends_cache: Array[PlayersClient.Player] = [] var _player_display := preload("res://scenes/players/PlayerDisplay.tscn") func _ready() -> void: + if not _current_player: + PlayersClient.load_current_player(true) + PlayersClient.current_player_loaded.connect(func(current_player: PlayersClient.Player): + var container := _player_display.instantiate() as Control + container.player = current_player + current_player_display.add_child(container) + ) if _friends_cache.is_empty(): PlayersClient.load_friends(10, true, true) PlayersClient.friends_loaded.connect( diff --git a/plugin/demo/scenes/players/Players.tscn b/plugin/demo/scenes/players/Players.tscn index b1e4ec8..f48bbf5 100644 --- a/plugin/demo/scenes/players/Players.tscn +++ b/plugin/demo/scenes/players/Players.tscn @@ -67,6 +67,23 @@ layout_mode = 2 [node name="HSeparator" type="HSeparator" parent="MarginContainer/VBoxContainer/ScrollContainer/ScrollChild"] layout_mode = 2 +[node name="CurrentPlayer" type="VBoxContainer" parent="MarginContainer/VBoxContainer/ScrollContainer/ScrollChild"] +layout_mode = 2 +theme_override_constants/separation = 25 + +[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/ScrollContainer/ScrollChild/CurrentPlayer"] +layout_mode = 2 +text = "Current Player" +horizontal_alignment = 1 + +[node name="CurrentPlayerDisplay" type="VBoxContainer" parent="MarginContainer/VBoxContainer/ScrollContainer/ScrollChild/CurrentPlayer"] +unique_name_in_owner = true +layout_mode = 2 +theme_override_constants/separation = 25 + +[node name="HSeparator2" type="HSeparator" parent="MarginContainer/VBoxContainer/ScrollContainer/ScrollChild"] +layout_mode = 2 + [node name="Friends" type="VBoxContainer" parent="MarginContainer/VBoxContainer/ScrollContainer/ScrollChild"] layout_mode = 2 theme_override_constants/separation = 25 diff --git a/plugin/export_scripts_template/autoloads/players_client.gd b/plugin/export_scripts_template/autoloads/players_client.gd index 29aa073..bfd4618 100644 --- a/plugin/export_scripts_template/autoloads/players_client.gd +++ b/plugin/export_scripts_template/autoloads/players_client.gd @@ -16,6 +16,12 @@ signal friends_loaded(friends: Array[Player]) ## [param player]: The selected player. signal player_searched(player: Player) +## Signal emitted after calling the [method load_current_player] method.[br] +## [br] +## [param current_player]: The currently signed-in player, or null if there where +## any errors loading the player. +signal current_player_loaded(current_player: Player) + ## Friends list visibility statuses. enum FriendsListVisibilityStatus { FEATURE_UNAVAILABLE = 3, ## The friends list is currently unavailable for the game. @@ -48,6 +54,10 @@ func _connect_signals() -> void: var safe_dictionary := GodotPlayGameServices.json_marshaller.safe_parse_dictionary(friend_json) player_searched.emit(Player.new(safe_dictionary)) ) + GodotPlayGameServices.android_plugin.currentPlayerLoaded.connect(func(friend_json: String): + var safe_dictionary := GodotPlayGameServices.json_marshaller.safe_parse_dictionary(friend_json) + current_player_loaded.emit(Player.new(safe_dictionary)) + ) ## Use this method and subscribe to the emitted signal to receive the list of friends ## for the current player.[br] @@ -109,6 +119,19 @@ func search_player() -> void: if GodotPlayGameServices.android_plugin: GodotPlayGameServices.android_plugin.searchPlayer() +## Use this method and subscribe to the emitted signal to receive the currently +## signed in player.[br] +## [br] +## The method emits the [signal current_player_loaded] signal.[br] +## [br] +## [param force_reload]: If true, this call will clear any locally cached +## data and attempt to fetch the latest data from the server. Send it set to [code]true[/code] +## the first time, and [code]false[/code] in subsequent calls, or when you want +## to clear the cache. +func load_current_player(force_reload: bool) -> void: + if GodotPlayGameServices.android_plugin: + GodotPlayGameServices.android_plugin.loadCurrentPlayer(force_reload) + ## Player information. class Player: var banner_image_landscape_uri: String ## Banner image of the player in landscape.