Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.34 KB | None | 0 0
  1. #===============================================================================
  2. # * Simple HUD Optimized - by FL (Credits will be apreciated)
  3. #===============================================================================
  4. #
  5. # This script is for Pokémon Essentials. It displays a simple HUD with the
  6. # party icons, HP Bars and some small text.
  7. #
  8. #===============================================================================
  9. #
  10. # To this script works, put it above main.
  11. #
  12. #===============================================================================
  13. class Spriteset_Map
  14. class HUD
  15. # If you wish to use a background picture, put the image path below, like
  16. # BGPATH="Graphics/Pictures/battleMessage". I recommend a 512x64 picture
  17. BGPATH="Graphics/Pictures/Hud Suicune"
  18.  
  19. # Make as 'false' to don't show the blue bar
  20. USEBAR=false
  21.  
  22. # Make as 'true' to draw the HUD at bottom
  23. DRAWATBOTTOM=false
  24.  
  25. # Make as 'true' to only show HUD in the pause menu
  26. DRAWONLYINMENU=false
  27.  
  28. # Make as 'false' to don't show the hp bars
  29. SHOWHPBARS=false
  30.  
  31. # When above 0, only displays HUD when this switch is on.
  32. SWITCHNUMBER = 0
  33.  
  34. # Lower this number = more lag.
  35. FRAMESPERUPDATE=2
  36.  
  37. # The size of drawable content.
  38. BARHEIGHT = 64
  39.  
  40. def initialize(viewport1)
  41. @viewport1 = viewport1
  42. @sprites = {}
  43. @yposition = DRAWATBOTTOM ? Graphics.height-64 : 0
  44. end
  45.  
  46. def showHUD?
  47. return (
  48. $Trainer &&
  49. (SWITCHNUMBER<=0 || $game_switches[SWITCHNUMBER]) &&
  50. (!DRAWONLYINMENU || $game_temp.in_menu)
  51. )
  52. end
  53.  
  54. def create
  55. @sprites.clear
  56.  
  57. @partySpecies = Array.new(6, 0)
  58. @partyForm = Array.new(6, 0)
  59. @partyIsEgg = Array.new(6, false)
  60. @partyHP = Array.new(6, 0)
  61. @partyTotalHP = Array.new(6, 0)
  62.  
  63. if USEBAR
  64. @sprites["bar"]=IconSprite.new(0,@yposition,@viewport1)
  65. barBitmap = Bitmap.new(Graphics.width,BARHEIGHT)
  66. barRect = Rect.new(0,0,barBitmap.width,barBitmap.height)
  67. barBitmap.fill_rect(barRect,Color.new(128,128,192))
  68. @sprites["bar"].bitmap = barBitmap
  69. end
  70.  
  71. drawBarFromPath = BGPATH != ""
  72. if drawBarFromPath
  73. @sprites["bgbar"]=IconSprite.new(0,@yposition,@viewport1)
  74. @sprites["bgbar"].setBitmap(BGPATH)
  75. end
  76.  
  77. @currentTexts = textsDefined
  78. drawText
  79.  
  80. for i in 0...6
  81. x = 16+64*i
  82. y = @yposition-8
  83. y-=8 if SHOWHPBARS
  84. @sprites["pokeicon#{i}"]=IconSprite.new(x,y,@viewport1)
  85. end
  86. refreshPartyIcons
  87.  
  88. if SHOWHPBARS
  89. borderWidth = 36
  90. borderHeight = 10
  91. fillWidth = 32
  92. fillHeight = 6
  93. for i in 0...6
  94. x=64*i+48
  95. y=@yposition+55
  96.  
  97. @sprites["hpbarborder#{i}"] = BitmapSprite.new(
  98. borderWidth,borderHeight,@viewport1
  99. )
  100. @sprites["hpbarborder#{i}"].x = x-borderWidth/2
  101. @sprites["hpbarborder#{i}"].y = y-borderHeight/2
  102. @sprites["hpbarborder#{i}"].bitmap.fill_rect(
  103. Rect.new(0,0,borderWidth,borderHeight),
  104. Color.new(32,32,32)
  105. )
  106. @sprites["hpbarborder#{i}"].bitmap.fill_rect(
  107. (borderWidth-fillWidth)/2,
  108. (borderHeight-fillHeight)/2,
  109. fillWidth,
  110. fillHeight,
  111. Color.new(96,96,96)
  112. )
  113. @sprites["hpbarborder#{i}"].visible = true
  114.  
  115. @sprites["hpbarfill#{i}"] = BitmapSprite.new(
  116. fillWidth,fillHeight,@viewport1
  117. )
  118. @sprites["hpbarfill#{i}"].x = x-fillWidth/2
  119. @sprites["hpbarfill#{i}"].y = y-fillHeight/2
  120. end
  121. refreshHPBars
  122. end
  123.  
  124. for sprite in @sprites.values
  125. sprite.z+=600
  126. end
  127. end
  128.  
  129. def drawText
  130. baseColor=Color.new(232,255,255)
  131. shadowColor=Color.new(124,159,255)
  132.  
  133. if @sprites.include?("overlay")
  134. @sprites["overlay"].bitmap.clear
  135. else
  136. width = Graphics.width
  137. @sprites["overlay"] = BitmapSprite.new(width,BARHEIGHT,@viewport1)
  138. @sprites["overlay"].y = @yposition
  139. end
  140.  
  141. xposition = Graphics.width-64
  142. textPositions=[
  143. [@currentTexts[0],xposition,0,2,baseColor,shadowColor],
  144. [@currentTexts[1],xposition,32,2,baseColor,shadowColor]
  145. ]
  146.  
  147. pbSetSystemFont(@sprites["overlay"].bitmap)
  148. pbDrawTextPositions(@sprites["overlay"].bitmap,textPositions)
  149. end
  150.  
  151. # Note that this method is called on each refresh, but the texts
  152. # only will be redrawed if any character change.
  153. def textsDefined
  154. time = Time.now
  155. ret=[]
  156. ret[0] = _INTL("#{time.hour}")
  157. ret[1] = _INTL("#{time.min}")
  158. return ret
  159. end
  160.  
  161. def refreshPartyIcons
  162. for i in 0...6
  163. partyMemberExists = $Trainer.party.size > i
  164. partySpecie = 0
  165. partyForm = 0
  166. partyIsEgg = false
  167. if partyMemberExists
  168. partySpecie = $Trainer.party[i].species
  169. partyForm = $Trainer.party[i].form
  170. partyIsEgg = $Trainer.party[i].egg?
  171. end
  172. refresh = (
  173. @partySpecies[i]!=partySpecie ||
  174. @partyForm[i]!=partyForm ||
  175. @partyIsEgg[i]!=partyIsEgg
  176. )
  177. if refresh
  178. @partySpecies[i] = partySpecie
  179. @partyForm[i] = partyForm
  180. @partyIsEgg[i] = partyIsEgg
  181. if partyMemberExists
  182. pokemonIconFile = pbPokemonIconFile($Trainer.party[i])
  183. @sprites["pokeicon#{i}"].setBitmap(pokemonIconFile)
  184. @sprites["pokeicon#{i}"].src_rect=Rect.new(0,0,64,64)
  185. end
  186. @sprites["pokeicon#{i}"].visible = partyMemberExists
  187. end
  188. end
  189. end
  190.  
  191. def refreshHPBars
  192. for i in 0...6
  193. hp = 0
  194. totalhp = 0
  195. hasHP = i<$Trainer.party.size && !$Trainer.party[i].egg?
  196. if hasHP
  197. hp = $Trainer.party[i].hp
  198. totalhp = $Trainer.party[i].totalhp
  199. end
  200.  
  201. lastTimeWasHP = @partyTotalHP[i] != 0
  202. @sprites["hpbarborder#{i}"].visible = hasHP if lastTimeWasHP != hasHP
  203.  
  204. redrawFill = hp != @partyHP[i] || totalhp != @partyTotalHP[i]
  205. if redrawFill
  206. @partyHP[i] = hp
  207. @partyTotalHP[i] = totalhp
  208. @sprites["hpbarfill#{i}"].bitmap.clear
  209.  
  210. width = @sprites["hpbarfill#{i}"].bitmap.width
  211. height = @sprites["hpbarfill#{i}"].bitmap.height
  212. fillAmount = (hp==0 || totalhp==0) ? 0 : hp*width/totalhp
  213. # Always show a bit of HP when alive
  214. fillAmount = 1 if fillAmount==0 && hp>0
  215. if fillAmount > 0
  216. hpColors=nil
  217. if hp<=(totalhp/4).floor
  218. hpColors = [Color.new(240,80,32),Color.new(168,48,56)] # Red
  219. elsif hp<=(totalhp/2).floor
  220. hpColors = [Color.new(248,184,0),Color.new(184,112,0)] # Orange
  221. else
  222. hpColors = [Color.new(24,192,32),Color.new(0,144,0)] # Green
  223. end
  224. shadowHeight = 2
  225. rect = Rect.new(0,0,fillAmount,shadowHeight)
  226. @sprites["hpbarfill#{i}"].bitmap.fill_rect(rect, hpColors[1])
  227. rect = Rect.new(0,shadowHeight,fillAmount,height-shadowHeight)
  228. @sprites["hpbarfill#{i}"].bitmap.fill_rect(rect, hpColors[0])
  229. end
  230. end
  231. end
  232. end
  233.  
  234. def update
  235. if showHUD?
  236. if @sprites.empty?
  237. create
  238. else
  239. updateHUDContent = (
  240. FRAMESPERUPDATE<=1 || Graphics.frame_count%FRAMESPERUPDATE==0
  241. )
  242. if updateHUDContent
  243. newTexts = textsDefined
  244. if @currentTexts != newTexts
  245. @currentTexts = newTexts
  246. drawText
  247. end
  248. refreshPartyIcons
  249. refreshHPBars if SHOWHPBARS
  250. end
  251. end
  252. pbUpdateSpriteHash(@sprites)
  253. else
  254. dispose if !@sprites.empty?
  255. end
  256. end
  257.  
  258. def dispose
  259. pbDisposeSpriteHash(@sprites)
  260. end
  261. end
  262.  
  263. alias :initializeOldFL :initialize
  264. alias :disposeOldFL :dispose
  265. alias :updateOldFL :update
  266.  
  267. def initialize(map=nil)
  268. initializeOldFL(map)
  269. end
  270.  
  271. def dispose
  272. @hud.dispose if @hud
  273. disposeOldFL
  274. end
  275.  
  276. def update
  277. updateOldFL
  278. @hud = HUD.new(@viewport1) if !@hud
  279. @hud.update
  280. end
  281. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement