-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathLobbyUser.gd
59 lines (50 loc) · 1.92 KB
/
LobbyUser.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
extends Panel
signal challenge_pressed()
signal avatar_loaded()
#const MEMBER_MIN_SIZE = 30
#const OWNER_MIN_SIZE = 44
onready var owner_actions = $OwnerActions
var member
func _ready():
Steam.connect("avatar_loaded", self, "_loaded_Avatar")
$"%ChallengeButton".connect("pressed", self, "on_challenge_pressed")
func init(member):
# if $"%AvatarIcon".texture == null:
Steam.getPlayerAvatar(Steam.AVATAR_MEDIUM, member.steam_id)
$"%Username".text = member.steam_name
self.member = member
$"%OwnerIcon".visible = false
$"%ChallengeButton".hide()
if SteamHustle.STEAM_ID != member.steam_id:
$"%ChallengeButton".show()
if Steam.getLobbyOwner(SteamLobby.LOBBY_ID) == member.steam_id:
$"%OwnerIcon".visible = true
var status = Steam.getLobbyMemberData(SteamLobby.LOBBY_ID, member.steam_id, "status")
if status != "idle":
$"%ChallengeButton".disabled = true
$"%ChallengeButton".text = status
if status == "fighting":
$"%ChallengeButton".text = "fighting " + Steam.getFriendPersonaName(int(Steam.getLobbyMemberData(SteamLobby.LOBBY_ID, member.steam_id, "opponent_id")))
# var lobby_owner = SteamLobby.am_i_lobby_owner()
# rect_min_size.y = MEMBER_MIN_SIZE if !lobby_owner else OWNER_MIN_SIZE
# owner_actions.visible = lobby_owner
func update_avatar():
Steam.getPlayerAvatar(Steam.AVATAR_MEDIUM, member.steam_id)
func on_challenge_pressed():
if member:
emit_signal("challenge_pressed")
SteamLobby.challenge_user(member)
func _loaded_Avatar(id: int, size: int, buffer: PoolByteArray) -> void:
if id != member.steam_id:
return
print("Avatar for user: "+str(id))
print("Size: "+str(size))
# Create the image and texture for loading
var AVATAR = Image.new()
var AVATAR_TEXTURE: ImageTexture = ImageTexture.new()
AVATAR.create_from_data(size, size, false, Image.FORMAT_RGBA8, buffer)
# Apply it to the texture
AVATAR_TEXTURE.create_from_image(AVATAR)
# Set it
$"%AvatarIcon".set_texture(AVATAR_TEXTURE)
emit_signal("avatar_loaded")