Guest User

Untitled

a guest
Apr 23rd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.70 KB | None | 0 0
  1. # EZ Text Pop
  2. # FenixFyreX (Thank you man! ..)
  3. #
  4. # To create a pop above a character, use a script call like so:
  5. #
  6. # pop_char_text(text, id, color, size)
  7. #
  8. # text - the text to be displayed
  9. # id - determines what character pops the text.
  10. # -1 for player
  11. # 0 for current event
  12. # 1+ for any event on the map
  13. # color - the color of the text to be displayed
  14. # size - the size of the text to be displayed
  15. # you can leave id, color, and size out, they all have defaults.
  16.  
  17. # To create a global pop, use a script call like so:
  18. #
  19. # pop_global_text(text, color, size)
  20. #
  21. # text - the text to be displayed
  22. # color - the color of the text to be displayed
  23. # size - the size of the text to be displayed
  24. # you can leave color, and size out, they all have defaults.
  25.  
  26. module EzTextPop
  27.  
  28. # Determines how long the text pops last before fading out.
  29. PopLength = 80
  30.  
  31. # Default color of text.
  32. PopColor = Color.new(255,255,255)
  33.  
  34. # Default size of text.
  35. PopSize = 18
  36. end
  37.  
  38. class Game_Interpreter
  39.  
  40. def pop_char_text(text, id = 0, color = EzTextPop::PopColor, size = EzTextPop::PopSize)
  41. id = id.to_i
  42. text = text.to_s
  43. case id
  44. when -1
  45. $game_player.pop_text(text, color, size)
  46. when 0
  47. $game_map.events[@event_id].pop_text(text, color, size)
  48. else
  49. $game_map.events[id].pop_text(text, color, size)
  50. end
  51. return true
  52. end
  53.  
  54. def pop_global_text(text, color = EzTextPop::PopColor, size = EzTextPop::PopSize)
  55. $game_system.pop_global_text(text, color, size)
  56. end
  57. end
  58.  
  59. class Game_Character
  60.  
  61. attr_accessor :textpops
  62.  
  63. alias initialize_pop_text_stuffz initialize unless $@
  64. def initialize(*args)
  65. @textpops = []
  66. initialize_pop_text_stuffz(*args)
  67. end
  68.  
  69. def pop_text(text, color, size)
  70. sprite = TextPopSprite.new(text, color, size, self)
  71. @textpops << sprite
  72. end
  73.  
  74. alias update_txtpopspritz update unless $@
  75. def update
  76. update_txtpopspritz
  77. update_textpops
  78. end
  79.  
  80. def update_textpops
  81. @textpops.compact!
  82. @textpops.each {|s| s.update unless s.nil? or s.disposed? }
  83. end
  84. end
  85.  
  86. class Game_System
  87.  
  88. attr_accessor :textpops
  89.  
  90. alias initialize_pop_textz initialize unless $@
  91. def initialize
  92. @textpops = []
  93. initialize_pop_textz
  94. end
  95.  
  96. def pop_global_text(text, color, size)
  97. sprite = TextPopSprite.new(text, color, size, self)
  98. @textpops << sprite
  99. end
  100.  
  101. alias update_textpopz update unless $@
  102. def update
  103. update_textpopz
  104. @textpops.compact!
  105. @textpops.each {|s| s.update unless s.nil? or s.disposed? }
  106. end
  107. end
  108. class Scene_Base
  109.  
  110. alias update_textpopz_charz update unless $@
  111. def update(*args,&block)
  112. update_textpopz_charz(*args,&block)
  113. if !popup_scene && !$game_map.events.nil?
  114. update_char_textpops
  115. end
  116. end
  117.  
  118. def popup_scene
  119. return true if $scene.is_a?(Scene_Map)
  120. return false
  121. end
  122.  
  123. def update_char_textpops
  124. $game_map.events.each do |id,event|
  125. event.update_textpops
  126. end
  127. end
  128. end
  129.  
  130. class TextPopSprite < Sprite_Base
  131.  
  132. def initialize(text, color, size, char)
  133. super()
  134. self.opacity = 255
  135. @count = EzTextPop::PopLength
  136. @char = char
  137. @size = size
  138. @index = @char.textpops.size
  139. w = text.size*size
  140. self.bitmap = Bitmap.new(w+10,size+6)
  141. self.bitmap.font.size = size
  142. self.bitmap.font.color = color
  143. self.bitmap.draw_text(5,3,w+2,size,text,1)
  144. if @char.is_a?(Game_Character)
  145. @char_bitmap_height = get_char_height
  146. self.x = @char.screen_x-(self.bitmap.width/2)
  147. self.y = (@char.screen_y-@char_bitmap_height)-(@index*size)-32
  148. self.z = @char.screen_z
  149. else
  150. self.x = 0
  151. self.y = (Graphics.height-self.bitmap.height)-(@index*size)
  152. self.z = 99999
  153. end
  154. end
  155.  
  156. def get_char_height
  157. nam = @char.character_name
  158. if FileTest.exist?("Graphics/Characters/#{nam}.png")
  159. bit = Cache.character(nam)
  160. h = nam.include?('$') ? 4 : 8
  161. height = bit.height / h
  162. return height
  163. end
  164. return 24
  165. end
  166.  
  167. def update
  168. super
  169. if !$scene.popup_scene
  170. @count = 0
  171. end
  172. if @char.is_a?(Game_Character)
  173. self.x = @char.screen_x-(self.bitmap.width/2)
  174. self.y = (@char.screen_y-@char_bitmap_height)-(@index*@size)-32
  175. self.z = @char.screen_z
  176. else
  177. self.x = 0
  178. self.y = (Graphics.height-self.bitmap.height)-(@index*@size)
  179. self.z = 99999
  180. end
  181. @count -= 1
  182. if @count <= 0
  183. self.opacity -= 2
  184. end
  185. if self.opacity <= 0 or !$scene.is_a?(Scene_Map)
  186. dispose
  187. @char.textpops[@char.textpops.index(self)] = nil
  188. return
  189. end
  190. end
  191. end
Add Comment
Please, Sign In to add comment