|
34 | 34 |
|
35 | 35 | sub currentUserChanged() |
36 | 36 | m.user.text = m.top.currentUser |
| 37 | + m.userImage = m.top.findNode("userImage") |
| 38 | + if not isValid(m.userPoster) |
| 39 | + m.userPoster = createUserPoster() ' save node to memory for faster load time |
| 40 | + end if |
37 | 41 |
|
38 | 42 | if m.top.currentUser = "" |
39 | | - ' remove the user image node if it exists |
40 | | - userImage = m.userGroup.findNode("userImage") |
41 | | - if isValid(userImage) |
42 | | - m.userGroup.removeChild(userImage) |
| 43 | + ' no user logged in, remove image if it exists |
| 44 | + if isValid(m.userImage) |
| 45 | + m.userGroup.removeChild(m.userImage) |
| 46 | + m.userImage = invalid |
43 | 47 | end if |
44 | | - ' remove cached user image if it exists |
45 | | - m.userImage = invalid |
46 | | - else |
47 | | - ' cache the user image node if needed |
48 | | - if not isValid(m.userImage) |
49 | | - m.userImage = createUserImage() |
| 48 | + else if not isValid(m.userImage) |
| 49 | + ' user logged in but no image, add it |
| 50 | + m.userImage = m.userPoster |
| 51 | + if m.userImage.tag = "" |
| 52 | + m.userGroup.itemSpacings = 9 ' default image is padded |
| 53 | + else |
| 54 | + m.userGroup.itemSpacings = 15 |
50 | 55 | end if |
51 | | - ' add the user image node to the overhang |
| 56 | + |
52 | 57 | m.userGroup.insertChild(m.userImage, 0) |
53 | 58 | end if |
54 | 59 | end sub |
55 | 60 |
|
56 | | -function createUserImage() as object |
| 61 | +function createUserPoster() as object |
| 62 | + userImage = createObject("roSGNode", "Poster") |
| 63 | + |
57 | 64 | imgParams = { |
58 | 65 | maxHeight: 36, |
59 | 66 | maxWidth: 36, |
|
62 | 69 | imgTag = m.global.session.user.primaryImageTag |
63 | 70 | if isValid(imgTag) and imgTag <> "" |
64 | 71 | imgParams.tag = imgTag |
| 72 | + userImage.tag = imgTag |
65 | 73 | end if |
66 | 74 |
|
67 | | - userImage = createObject("roSGNode", "Poster") |
68 | 75 | userImage.id = "userImage" |
69 | 76 | userImage.width = "36" |
70 | 77 | userImage.height = "36" |
71 | 78 |
|
72 | | - if isValid(imgTag) and imgTag <> "" |
| 79 | + if isValid(imgTag) |
73 | 80 | ' reset defaults |
74 | | - m.userGroup.itemSpacings = 15 |
75 | 81 | userImage.blendColor = "0xFFFFFFFF" |
76 | 82 |
|
77 | 83 | if m.global.session.server.url <> "" |
78 | 84 | userImage.uri = buildURL(Substitute("/Users/{0}/Images/Primary", m.global.session.user.id), imgParams) |
79 | 85 | else |
80 | 86 | print "ERROR: No server URL set, cannot load user image" |
81 | 87 | end if |
82 | | - |
83 | 88 | else |
84 | | - m.userGroup.itemSpacings = 9 ' account for default image padding |
85 | 89 | userImage.blendColor = m.global.constants.colors.text_secondary |
86 | | - |
87 | 90 | userImage.uri = "pkg:/images/icons/person_36px.png" |
88 | 91 | end if |
89 | 92 |
|
|
0 commit comments