Skip to content

Commit

Permalink
Display of images in demo project
Browse files Browse the repository at this point in the history
Signed-off-by: Jacob Ibáñez Sánchez <jacobibanez@jacobibanez.com>
  • Loading branch information
Iakobs committed Dec 21, 2023
1 parent 448cb74 commit 2f32893
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 66 deletions.
21 changes: 21 additions & 0 deletions plugin/demo/scenes/achievements/AchievementDisplay.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
extends Control

@onready var icon_rect: TextureRect = %IconRect

@onready var id_label: Label = %IdLabel
@onready var name_label: Label = %NameLabel
@onready var description_label: Label = %DescriptionLabel
Expand Down Expand Up @@ -96,8 +98,27 @@ func _connect_signals() -> void:
_waiting = false
_set_up_display()
)
GodotPlayGameServices.image_stored.connect(func(file_path: String):
if file_path == achievement.revealed_image_uri\
or file_path == achievement.unlocked_image_uri:
_set_up_icon()
)

func _set_up_waiting() -> void:
_waiting = true
unlock_button.disabled = true
unlock_button.text = "Wait..."

func _set_up_icon() -> void:
var property: String
match achievement.state:
AchievementsClient.State.STATE_REVEALED:
property = achievement.revealed_image_uri
AchievementsClient.State.STATE_UNLOCKED:
property = achievement.unlocked_image_uri

if property and not property.is_empty():
GodotPlayGameServices.display_image_in_texture_rect(
icon_rect,
property
)
6 changes: 6 additions & 0 deletions plugin/demo/scenes/achievements/AchievementDisplay.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ theme_override_constants/margin_bottom = 25
layout_mode = 2
theme_override_constants/separation = 25

[node name="IconRect" type="TextureRect" parent="MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
stretch_mode = 3

[node name="Id" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
visible = false
layout_mode = 2

[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/Id"]
Expand Down
31 changes: 20 additions & 11 deletions plugin/demo/scenes/leaderboards/LeaderboardDisplay.gd
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
extends Control

@onready var leaderboard_id_label: Label = %LeaderboardId
@onready var leaderboard_name_label: Label = %LeaderboardName
@onready var icon_rect: TextureRect = %IconRect

@onready var player_rank_label: Label = %PlayerRank
@onready var player_score_label: Label = %PlayerScore
@onready var id_label: Label = %IdLabel
@onready var name_label: Label = %NameLabel

@onready var new_score_line_edit: LineEdit = %NewScore
@onready var submit_score_button: Button = %SubmitScore
@onready var player_rank_label: Label = %PlayerRankLabel
@onready var player_score_label: Label = %PlayerScoreLabel

@onready var time_span_option: OptionButton = %TimeSpan
@onready var collection_option: OptionButton = %Collection
@onready var show_variant_button: Button = %ShowVariant
@onready var new_score_line_edit: LineEdit = %NewScoreLineEdit
@onready var submit_score_button: Button = %SubmitScoreButton

@onready var time_span_option: OptionButton = %TimeSpanOption
@onready var collection_option: OptionButton = %CollectionOption
@onready var show_variant_button: Button = %ShowVariantButton

var leaderboard: LeaderboardsClient.Leaderboard

Expand All @@ -24,8 +26,15 @@ var _selected_collection: LeaderboardsClient.Collection

func _ready() -> void:
if leaderboard:
leaderboard_id_label.text = leaderboard.leaderboard_id
leaderboard_name_label.text = leaderboard.display_name
GodotPlayGameServices.image_stored.connect(func(file_path: String):
if file_path == leaderboard.icon_image_uri:
GodotPlayGameServices.display_image_in_texture_rect(
icon_rect,
file_path
)
)
id_label.text = leaderboard.leaderboard_id
name_label.text = leaderboard.display_name
_set_up_display_score()
_set_up_submit_score()
_set_up_variants()
Expand Down
36 changes: 21 additions & 15 deletions plugin/demo/scenes/leaderboards/LeaderboardDisplay.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,33 @@ theme_override_constants/margin_bottom = 25
layout_mode = 2
theme_override_constants/separation = 25

[node name="LeaderboardId" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
[node name="IconRect" type="TextureRect" parent="MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
stretch_mode = 3

[node name="Id" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
visible = false
layout_mode = 2

[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/LeaderboardId"]
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/Id"]
layout_mode = 2
text = "Leaderboard ID:"
text = "ID:"

[node name="LeaderboardId" type="Label" parent="MarginContainer/VBoxContainer/LeaderboardId"]
[node name="IdLabel" type="Label" parent="MarginContainer/VBoxContainer/Id"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
text_overrun_behavior = 3

[node name="LeaderboardName" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
[node name="Name" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
layout_mode = 2

[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/LeaderboardName"]
[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/Name"]
layout_mode = 2
text = "Leaderboard Name:"
text = "Name:"

[node name="LeaderboardName" type="Label" parent="MarginContainer/VBoxContainer/LeaderboardName"]
[node name="NameLabel" type="Label" parent="MarginContainer/VBoxContainer/Name"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3
Expand All @@ -57,7 +63,7 @@ layout_mode = 2
layout_mode = 2
text = "Player Rank:"

[node name="PlayerRank" type="Label" parent="MarginContainer/VBoxContainer/PlayerRank"]
[node name="PlayerRankLabel" type="Label" parent="MarginContainer/VBoxContainer/PlayerRank"]
unique_name_in_owner = true
layout_mode = 2

Expand All @@ -68,7 +74,7 @@ layout_mode = 2
layout_mode = 2
text = "Player Score:"

[node name="PlayerScore" type="Label" parent="MarginContainer/VBoxContainer/PlayerScore"]
[node name="PlayerScoreLabel" type="Label" parent="MarginContainer/VBoxContainer/PlayerScore"]
unique_name_in_owner = true
layout_mode = 2

Expand All @@ -87,14 +93,14 @@ layout_mode = 2
text = "New score:"
horizontal_alignment = 1

[node name="NewScore" type="LineEdit" parent="MarginContainer/VBoxContainer/SubmitScore/NewScore"]
[node name="NewScoreLineEdit" type="LineEdit" parent="MarginContainer/VBoxContainer/SubmitScore/NewScore"]
unique_name_in_owner = true
layout_mode = 2
alignment = 1
virtual_keyboard_type = 2
clear_button_enabled = true

[node name="SubmitScore" type="Button" parent="MarginContainer/VBoxContainer/SubmitScore"]
[node name="SubmitScoreButton" type="Button" parent="MarginContainer/VBoxContainer/SubmitScore"]
unique_name_in_owner = true
layout_mode = 2
theme = ExtResource("1_oo2te")
Expand All @@ -116,7 +122,7 @@ layout_mode = 2
layout_mode = 2
text = "Time Span"

[node name="TimeSpan" type="OptionButton" parent="MarginContainer/VBoxContainer/Variants/TimeSpan"]
[node name="TimeSpanOption" type="OptionButton" parent="MarginContainer/VBoxContainer/Variants/TimeSpan"]
unique_name_in_owner = true
layout_mode = 2

Expand All @@ -127,11 +133,11 @@ layout_mode = 2
layout_mode = 2
text = "Collection"

[node name="Collection" type="OptionButton" parent="MarginContainer/VBoxContainer/Variants/Collection"]
[node name="CollectionOption" type="OptionButton" parent="MarginContainer/VBoxContainer/Variants/Collection"]
unique_name_in_owner = true
layout_mode = 2

[node name="ShowVariant" type="Button" parent="MarginContainer/VBoxContainer/Variants"]
[node name="ShowVariantButton" type="Button" parent="MarginContainer/VBoxContainer/Variants"]
unique_name_in_owner = true
layout_mode = 2
theme = ExtResource("1_oo2te")
Expand Down
25 changes: 24 additions & 1 deletion plugin/demo/scenes/players/PlayerDisplay.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
extends Control

@onready var avatar_rect: TextureRect = %AvatarRect

@onready var id_label: Label = %IdLabel
@onready var name_label: Label = %NameLabel
@onready var title_label: Label = %TitleLabel
Expand All @@ -13,15 +15,36 @@ var player: PlayersClient.Player

func _ready() -> void:
if player:
_set_up_display()
_set_up_display.call_deferred()
compare_button.pressed.connect(func():
PlayersClient.compare_profile(player.player_id)
)

func _set_up_display() -> void:
GodotPlayGameServices.image_stored.connect(func(file_path: String):
if file_path == player.hi_res_image_uri:
GodotPlayGameServices.display_image_in_texture_rect(
avatar_rect,
file_path
)
)
id_label.text = player.player_id
name_label.text = player.display_name
title_label.text = player.title
status_label.text = PlayersClient.PlayerFriendStatus.find_key(player.friend_status)
level_label.text = str(player.level_info.current_level.level_number)
xp_label.text = str(player.level_info.current_xp_total)

func _load_and_retry(image_uri: String) -> Image:
var image = Image.new()
var retries := 3
var error := ERR_FILE_NOT_FOUND
while retries > 0 or error == ERR_FILE_NOT_FOUND:
if retries != 3:
await get_tree().create_timer(1.0).timeout
error = image.load_png_from_buffer(Image.load_from_file(image_uri).get_data())
retries -= 1
if retries == 0:
print("Error loading file!!")
image = null
return image
45 changes: 6 additions & 39 deletions plugin/demo/scenes/players/PlayerDisplay.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ theme_override_constants/margin_bottom = 25
layout_mode = 2
theme_override_constants/separation = 25

[node name="AvatarRect" type="TextureRect" parent="MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
stretch_mode = 3

[node name="Id" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
visible = false
layout_mode = 2

[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/Id"]
Expand Down Expand Up @@ -107,42 +113,3 @@ layout_mode = 2
theme = ExtResource("1_uv4o5")
text = "Compare"
text_overrun_behavior = 3

[node name="HSeparator2" type="HSeparator" parent="MarginContainer/VBoxContainer"]
visible = false
layout_mode = 2

[node name="Variants" type="VBoxContainer" parent="MarginContainer/VBoxContainer"]
visible = false
layout_mode = 2
theme_override_constants/separation = 25

[node name="TimeSpan" type="VBoxContainer" parent="MarginContainer/VBoxContainer/Variants"]
layout_mode = 2

[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/Variants/TimeSpan"]
layout_mode = 2
text = "Time Span"

[node name="TimeSpan" type="OptionButton" parent="MarginContainer/VBoxContainer/Variants/TimeSpan"]
unique_name_in_owner = true
layout_mode = 2

[node name="Collection" type="VBoxContainer" parent="MarginContainer/VBoxContainer/Variants"]
layout_mode = 2

[node name="Label" type="Label" parent="MarginContainer/VBoxContainer/Variants/Collection"]
layout_mode = 2
text = "Collection"

[node name="Collection" type="OptionButton" parent="MarginContainer/VBoxContainer/Variants/Collection"]
unique_name_in_owner = true
layout_mode = 2

[node name="ShowVariant" type="Button" parent="MarginContainer/VBoxContainer/Variants"]
unique_name_in_owner = true
layout_mode = 2
theme = ExtResource("1_uv4o5")
disabled = true
text = "Show Leaderboard Variant"
text_overrun_behavior = 3
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ extends Node
## This Autoload also calls the [code]initialize()[/code] method of the plugin,
## checking if the user is authenticated.

## Signal emitted after an image is downloaded and saved to the device.[br]
## [br]
## [param file_path]: The path to the stored file.
signal image_stored(file_path: String)

## Main entry point to the android plugin. With this object, you can call the
## kotlin methods directly.
var android_plugin: Object
Expand All @@ -26,3 +31,16 @@ func _ready() -> void:
android_plugin.initialize()
else:
printerr("No plugin found!")

if android_plugin:
android_plugin.imageStored.connect(func(file_path: String):
image_stored.emit(file_path)
)

## Displays the given image in the given texture rectangle.[br]
## [br]
## [param texture_rect]: The texture rectangle control to display the image.[br]
## [param file_path]: The file path of the image, for example user://image.png.
func display_image_in_texture_rect(texture_rect: TextureRect, file_path: String) -> void:
var image := Image.load_from_file(file_path)
texture_rect.texture = ImageTexture.create_from_image(image)

0 comments on commit 2f32893

Please sign in to comment.