Advertisement
Guest User

Habbo Hotel Draw Friend Class v0.4

a guest
Jun 20th, 2024
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.21 KB | Source Code | 0 0
  1. --Draw
  2. --Friend
  3. --v 0.4
  4.  
  5.  
  6. --| Public:
  7. --| construct
  8. --| define
  9. --| update
  10. --| select
  11. --| unselect
  12. --| render
  13.  
  14.  
  15. -- Buddy data:
  16.  
  17. property pData
  18. property pID
  19. property pName
  20. --property pSex
  21. property pCustomText
  22. property pOnline
  23. property pLocation
  24. property pLastTime
  25. property pMsgCount
  26.  
  27. -- Layout data:
  28.  
  29. property pTopMarg
  30. property pLeftMarg
  31. property pWidth
  32. property pHeight
  33. property pLineHeight
  34. property pMsgLinkRect
  35. property pSelected
  36. property pNeedUpdate
  37.  
  38. -- Cached images and update requests:
  39.  
  40. property pCacheImage
  41. property pDotLineImg
  42. property pCacheOnlineImg
  43.  
  44. property pCacheNameImg
  45. property pCacheMsgsImg
  46. property pCacheUnitImg
  47. property pCacheLastTimeImg
  48. property pCacheMissionImg
  49.  
  50. property pNameNeedUpdate
  51. property pMsgsNeedUpdate
  52. property pLocationNeedUpdate
  53. property pLastNeedUpdate
  54. property pMissNeedUpdate
  55.  
  56. -- Direct pointers to writer objects:
  57.  
  58. property pWriterName
  59. property pWriterMsgs
  60. property pWriterLast
  61. property pWriterText
  62.  
  63. --additional offsets defined in the patch file
  64.  
  65. property pFriendNameOffset
  66. property pFriendLastOffset
  67. property pFriendPerMsgOffset
  68.  
  69. on construct(me)
  70.  
  71. pData = [:]
  72. pID = EMPTY
  73. pCustomText = EMPTY
  74. pOnline = FALSE
  75. pLocation = EMPTY
  76. pLastTime = EMPTY
  77. pMsgCount = "0"
  78. pTopMarg = 3
  79. pLeftMarg = 29
  80. pLineHeight = 10
  81. pMsgLinkRect = rect(0, 0, 0, 0)
  82. pSelected = FALSE
  83. pDotLineImg = member(getMemNum("meswhitedottedline")).image
  84. pCacheOnlineImg = member(getMemNum("mes_smallbuddy_head")).image
  85. pNameNeedUpdate = TRUE
  86. pMsgsNeedUpdate = TRUE
  87. pLocationNeedUpdate = TRUE
  88. pLastNeedUpdate = TRUE
  89. pMissNeedUpdate = TRUE
  90.  
  91. -- Check if offsets are set
  92.  
  93. pFriendNameOffset = 0
  94. if (variableExists("messenger_friend_name_offset")) then pFriendNameOffset = getVariable("messenger_friend_name_offset")
  95.  
  96. pFriendLastOffset = 0
  97. if (variableExists("messenger_friend_last_offset")) then pFriendLastOffset = getVariable("messenger_friend_last_offset")
  98.  
  99. pFriendPerMsgOffset = 0
  100. if (variableExists("messenger_friend_permsg_offset")) then pFriendPerMsgOffset = getVariable("messenger_friend_permsg_offset")
  101.  
  102.  
  103. return(TRUE)
  104.  
  105. end
  106.  
  107.  
  108. on define(me, tData, tProps)
  109.  
  110. pData = tData
  111. pID = tData.id
  112. pName = tData.name
  113. pOnline = tData.online
  114. --pSex = tData.sex
  115. pWidth = tProps.width
  116. pHeight = tProps.height
  117. pCacheImage = image(pWidth, pHeight, 8)
  118. pWriterName = getWriter(tProps.writer_name)
  119. pWriterMsgs = getWriter(tProps.writer_msgs)
  120. pWriterLast = getWriter(tProps.writer_last)
  121. pWriterText = getWriter(tProps.writer_text)
  122. pNeedUpdate = TRUE
  123. me.update()
  124.  
  125. end
  126.  
  127.  
  128. on update(me)
  129.  
  130. pOnline = pData.online
  131.  
  132. -- Mission...
  133.  
  134. if(pData.customText <> pCustomText) then
  135. pCustomText = pData.customText
  136. pMissNeedUpdate = TRUE
  137. pNeedUpdate = TRUE
  138. end if
  139.  
  140. if(pOnline) then
  141. -- Unit...
  142.  
  143. if(pData.location <> pLocation) then
  144. pLocation = pData.location
  145. pLocationNeedUpdate = TRUE
  146. pNeedUpdate = TRUE
  147. end if
  148.  
  149. else
  150. -- Last visit...
  151.  
  152. if(pData.lastAccess <> pLastTime) then
  153. pLastTime = pData.lastAccess
  154. pLastNeedUpdate = TRUE
  155. pNeedUpdate = TRUE
  156. end if
  157. end if
  158.  
  159. -- Message count...
  160.  
  161. if(pData.msgs <> pMsgCount) then
  162. pMsgCount = string(pData.msgs)
  163. pMsgsNeedUpdate = TRUE
  164. pNeedUpdate = TRUE
  165. end if
  166.  
  167. end
  168.  
  169.  
  170. on select(me, tClickPoint, tBuffer, tPosition)
  171.  
  172. if(integer(pMsgCount.word[1]) > 0 and inside(tClickPoint, pMsgLinkRect)) then
  173. tMsgStruct = getThread(#messenger).getComponent().getMessageBySenderID(pID)
  174. getThread(#messenger).getInterface().renderMessage(tMsgStruct)
  175. else
  176. tPos = tPosition * pHeight
  177. tRect = pCacheImage.rect + rect(0, 1,-4,-2) + [0, tPos, 0, tPos]
  178. if(pSelected) then
  179. pSelected = FALSE
  180. tBuffer.draw(tRect, [#shapeType:#rect, #lineSize:1, #color:rgb("#FFFFFF")])
  181. else
  182. pSelected = TRUE
  183. tBuffer.draw(tRect, [#shapeType:#rect, #lineSize:1, #color:rgb("#EEEEEE")])
  184. end if
  185. getThread(#messenger).getInterface().buddySelectOrNot(pName, pID, pSelected)
  186. end if
  187.  
  188. end
  189.  
  190.  
  191. on unselect(me)
  192.  
  193. pSelected = FALSE
  194.  
  195. end
  196.  
  197.  
  198. on render(me, tBuffer, tPosition)
  199.  
  200. tPosition = tPosition - 1
  201. if(pData.update) then pNeedUpdate = TRUE
  202.  
  203. if(not pNeedUpdate) then
  204.  
  205. -- Render cached image...
  206.  
  207. tDstRect = pCacheImage.rect + rect(0, tPosition * pHeight, 0, tPosition * pHeight)
  208. tBuffer.copyPixels(pCacheImage, tDstRect, pCacheImage.rect)
  209.  
  210. else
  211.  
  212. pNeedUpdate = FALSE
  213. --tt = the milliseconds
  214.  
  215. -- Create and render cached name image...
  216.  
  217. if(pNameNeedUpdate) then
  218.  
  219. tText = pName && "-"
  220.  
  221. pCacheNameImg = pWriterName.render(tText).duplicate()
  222. pNameNeedUpdate = FALSE
  223.  
  224. tX1 = pLeftMarg
  225. tX2 = tX1 + pCacheNameImg.width
  226. tY1 = pTopMarg + pFriendNameOffset
  227. tY2 = tY1 + pCacheNameImg.height
  228. tDstRect = rect(tX1, tY1, tX2, tY2)
  229. pCacheImage.copyPixels(pCacheNameImg, tDstRect, pCacheNameImg.rect)
  230.  
  231. end if
  232.  
  233. -- Create messages count image...
  234.  
  235. if(pMsgsNeedUpdate) then
  236.  
  237. tMsgsImg = pWriterMsgs.render(pMsgCount)
  238.  
  239. tX1 = pLeftMarg + pCacheNameImg.width + 5
  240. tX2 = tX1 + tMsgsImg.width
  241. tY1 = pTopMarg + pFriendNameOffset
  242. tY2 = tY1 + tMsgsImg.height
  243. tDstRect = rect(tX1, tY1, tX2, tY2)
  244. pCacheImage.fill(tDstRect, rgb(255, 255, 255))
  245. pCacheImage.copyPixels(tMsgsImg, tDstRect, tMsgsImg.rect)
  246. pMsgLinkRect = tDstRect
  247. pMsgNeedUpdate = FALSE
  248.  
  249. end if
  250.  
  251. -- Create last visit image...
  252.  
  253. if(pLastNeedUpdate OR pLocationNeedUpdate) then -- T�ss� varmaan pit�� olla location my�s -Antti
  254.  
  255. if(not(pOnline)) then
  256. tText = getText("console_lastvisit") && pLastTime
  257. else
  258. tLocation = pLocation
  259. -- Begin legacy code, can be removed in r9 b3 and on
  260. if(tLocation contains "Floor1") then tLocation = getText("console_inprivateroom")
  261. if(tLocation = "") then tLocation = getText("console_onfrontpage") -- This was 'ENTERPRISESERVER'
  262. -- /Legacy
  263. -- Tuota ei voinut viel� poistaa kommentista huolimatta (R9 b12) -Antti
  264. tText = getText("console_online") && tLocation
  265. end if
  266.  
  267. tLastTimeImg = pWriterLast.render(tText)
  268.  
  269. tX1 = pLeftMarg
  270. tX2 = tX1 + tLastTimeImg.width
  271. tY1 = pLineHeight + pTopMarg + pFriendLastOffset
  272. tY2 = tY1 + tLastTimeImg.height
  273. tDstRect = rect(tX1, tY1, tX2, tY2)
  274. pCacheImage.fill(rect(tX1, tY1, pCacheImage.width, tY2), rgb(255, 255, 255))
  275. pCacheImage.copyPixels(tLastTimeImg, tDstRect, tLastTimeImg.rect)
  276. pLastNeedUpdate = FALSE
  277.  
  278. end if
  279.  
  280. -- Render online-head image...
  281.  
  282. tX1 = 6
  283. tX2 = tX1 + pCacheOnlineImg.width
  284. tY1 = 4
  285. tY2 = tY1 + pCacheOnlineImg.height
  286. tDstRect = rect(tX1, tY1, tX2, tY2)
  287.  
  288. if(pOnline) then
  289. pCacheImage.copyPixels(pCacheOnlineImg, tDstRect, pCacheOnlineImg.rect)
  290. else
  291. pCacheImage.fill(tDstRect, rgb(255, 255, 255))
  292. end if
  293.  
  294. -- Create mission image...
  295.  
  296. if(pMissNeedUpdate) then
  297.  
  298. tMissionImg = pWriterText.render(QUOTE & pCustomText & QUOTE)
  299. tX1 = pLeftMarg
  300. tX2 = tX1 + tMissionImg.width
  301. tY1 = pLineHeight * 2 + pTopMarg + pFriendPerMsgOffset
  302. tY2 = tY1 + tMissionImg.height
  303. tDstRect = rect(tX1, tY1, tX2, tY2)
  304. pCacheImage.fill(rect(tX1, tY1, tX1 + pWidth, tY2), rgb(255, 255, 255))
  305. pCacheImage.copyPixels(tMissionImg, tDstRect, tMissionImg.rect)
  306. pMissNeedUpdate = FALSE
  307.  
  308. end if
  309.  
  310. -- Render dotline...
  311.  
  312. tX1 = 0
  313. tX2 = pDotLineImg.width
  314. tY1 = pCacheImage.height - 1
  315. tY2 = tY1 + 1
  316. tDstRect = rect(tX1, tY1, tX2, tY2)
  317. pCacheImage.copyPixels(pDotLineImg, tDstRect, pDotLineImg.rect)
  318.  
  319. -- Update BufferImage...
  320.  
  321. tDstRect = pCacheImage.rect + rect(0, tPosition * pHeight, 0, tPosition * pHeight)
  322. tBuffer.copyPixels(pCacheImage, tDstRect, pCacheImage.rect)
  323. pData.update = FALSE
  324.  
  325. --tt = (the milliseconds - tt)
  326. --put "buddy image took:" && tt
  327.  
  328. end if
  329.  
  330. end
  331.  
  332. --Draw Friend Class
  333. --Antti Kaseva
  334.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement