Guest User

Untitled

a guest
Jul 25th, 2016
58
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. # MBS - Event Text Display
  3. #------------------------------------------------------------------------------
  4. # por Masked
  5. #==============================================================================
  6. #==============================================================================
  7. # Instruções
  8. #------------------------------------------------------------------------------
  9. # Para mostrar o texto acima do personagem/event escreva nas notas/comentário
  10. # dele:
  11. # <TEXT "texto" #hex above/below>
  12. # Sendo o texto a mostrar entre aspas, o #hex a cor do texto em hexadecimal e
  13. # above para o texto acima do personagem e below para abaixo,
  14. # por exemplo:
  15. # <TEXT "maçã" #f00 above> = 'maçã' escrito em vermelho acima do personagem
  16. # Os dois últimos valores são opcionais
  17. # Você pode usar as tags \V, \N, \P e \G igual às mensagens no texto.
  18. #
  19. # Para adicionar/deletar textos por script call, use a propriedade .texts
  20. # do character;
  21. # Deleta o texto nº X:
  22. # character.texts.delete_at(x)
  23. # Insere o texto "texto" com a cor "cor" acima do personagem:
  24. # character.texts.insert(x, ["texto","cor",:above])
  25. # Muda o texto número X para "texto" com a cor "cor" abaixo do personagem:
  26. # character.texts[x] = ["texte","cor",:below]
  27. #
  28. # O character pode ser o jogador ou algum evento:
  29. # $game_player.texts.delete_at(x)
  30. # $game_map.events[id].texts.insert(x, ["texto","cor",:above])
  31. #
  32. # Também pode ser algum dos seguidores do jogador:
  33. # $game_player.followers[n].texts.delete_at(x)
  34. #==============================================================================
  35. #==============================================================================
  36. # ** MBS
  37. #==============================================================================
  38. module MBS
  39. #============================================================================
  40. # ** EventText
  41. #============================================================================
  42. module EventText
  43. #==========================================================================
  44. # * Configurações
  45. #==========================================================================
  46. # Tamanho da fonte do texto
  47. FONT_SIZE = 18
  48.  
  49. # Caso queira usar os textos das notas dos seguidores deixe como true,
  50. # se não mude para false
  51. USE_FOLLOWER_NOTE = true
  52. #==========================================================================
  53. # * Fim das configurações
  54. #==========================================================================
  55. REGEX = /<TEXT\s*"(.+)"\s*(#[a-f0-9]{3,})?\s*(above|below)?\s*>/i
  56. end
  57. end
  58. #==============================================================================
  59. # ** Game_Character
  60. #------------------------------------------------------------------------------
  61. # Modificações para guardar os textos pra cada character
  62. #==============================================================================
  63. class Game_Character < Game_CharacterBase
  64. #--------------------------------------------------------------------------
  65. # * Definição dos atributos
  66. #--------------------------------------------------------------------------
  67. attr_reader :texts
  68. #--------------------------------------------------------------------------
  69. # * Alias
  70. #--------------------------------------------------------------------------
  71. alias mbseventtext_initpublicmems init_public_members
  72. #--------------------------------------------------------------------------
  73. # * Inicialização de variáveis públicas
  74. #--------------------------------------------------------------------------
  75. def init_public_members(*a, &b)
  76. mbseventtext_initpublicmems(*a, &b)
  77. @texts = []
  78. end
  79. end
  80. #==============================================================================
  81. # ** Sprite_Character
  82. #------------------------------------------------------------------------------
  83. # Modificações para mostrar o texto no personagem
  84. #==============================================================================
  85. class Sprite_Character < Sprite_Base
  86. #--------------------------------------------------------------------------
  87. # * Alias
  88. #--------------------------------------------------------------------------
  89. alias mbseventtext_updatebitmap update_bitmap
  90. alias mbseventtext_updateposition update_position
  91. alias mbseventtext_dispose dispose
  92. #--------------------------------------------------------------------------
  93. # * Atualização do bitmap de origem
  94. #--------------------------------------------------------------------------
  95. def update_bitmap(*a,&b)
  96. mbseventtext_updatebitmap(*a,&b)
  97. update_texts if texts_changed?
  98. @spr_txt.update if @spr_txt
  99. end
  100. #--------------------------------------------------------------------------
  101. # * Atualização da posição do sprite
  102. #--------------------------------------------------------------------------
  103. def update_position
  104. mbseventtext_updateposition
  105. @spr_txt.x = self.x if @spr_txt
  106. @spr_txt.y = self.y if @spr_txt
  107. end
  108. #--------------------------------------------------------------------------
  109. # * Verificação de quando os textos mudaram
  110. #--------------------------------------------------------------------------
  111. def texts_changed?
  112. @texts != @character.texts
  113. end
  114. #--------------------------------------------------------------------------
  115. # * Aquisição de uma cor através de um hexadecimal
  116. #--------------------------------------------------------------------------
  117. def parse_color(hex)
  118. r = g = b = a = 255
  119. case hex.to_s.size
  120. when 3
  121. r, g, b = *hex.split('')
  122. r = (r*2).to_i(16)
  123. g = (g*2).to_i(16)
  124. b = (b*2).to_i(16)
  125. when 4
  126. r, g, b, a = *hex.split('')
  127. r = (r*2).to_i(16)
  128. g = (g*2).to_i(16)
  129. b = (b*2).to_i(16)
  130. a = (a*2).to_i(16)
  131. when 6
  132. r = hex[0..1].to_i(16)
  133. g = hex[2..3].to_i(16)
  134. b = hex[4..5].to_i(16)
  135. when 8
  136. r = hex[0..1].to_i(16)
  137. g = hex[2..3].to_i(16)
  138. b = hex[4..5].to_i(16)
  139. a = hex[6..7].to_i(16)
  140. end
  141. return Color.new(r,g,b,a)
  142. end
  143. private :parse_color
  144. #--------------------------------------------------------------------------
  145. # * Aquisição dos textos abaixo do char
  146. #--------------------------------------------------------------------------
  147. def below_texts
  148. @texts.select {|txt| txt[2] == :below}
  149. end
  150. #--------------------------------------------------------------------------
  151. # * Aquisição dos textos acima do char
  152. #--------------------------------------------------------------------------
  153. def above_texts
  154. @texts.select {|txt| txt[2] == :above}
  155. end
  156. #--------------------------------------------------------------------------
  157. # * Atualização dos textos
  158. #--------------------------------------------------------------------------
  159. def update_texts
  160. @spr_txt ||= Sprite.new
  161. @texts = @character.texts.dup
  162.  
  163. bigger = (@texts.sort {|a, b| a[0].size <=> b[0].size}.last || [])[0]
  164. bitmap.font.size &&= MBS::EventText::FONT_SIZE
  165. w = bitmap.text_size(bigger).width+8
  166. h = bitmap.text_size(bigger).height+2
  167. @spr_txt.bitmap = Bitmap.new([@cw, w].max,@ch+h*@texts.size)
  168. @spr_txt.bitmap.font.size &&= MBS::EventText::FONT_SIZE
  169. @spr_txt.ox = @spr_txt.width/2
  170. @spr_txt.oy = self.oy + above_texts.size*h
  171.  
  172. above_texts.compact.each_with_index do |text, i|
  173. @spr_txt.bitmap.font.color = parse_color(text[1])
  174. @spr_txt.bitmap.draw_text(0,i*h,w,h,convert_escape_characters(text[0]),1)
  175. end
  176.  
  177. below_texts.compact.each_with_index do |text, i|
  178. @spr_txt.bitmap.font.color = parse_color(text[1])
  179. @spr_txt.bitmap.draw_text(0,above_texts.size*h + @ch + i*h,w,h,convert_escape_characters(text[0]),1)
  180. end
  181. end
  182. #--------------------------------------------------------------------------
  183. # * Conversão dos caracteres de controle
  184. #--------------------------------------------------------------------------
  185. def convert_escape_characters(text)
  186. result = text.to_s.clone
  187. result.gsub!(/\\/) { "\e" }
  188. result.gsub!(/\e\e/) { "\\" }
  189. result.gsub!(/%var(\d+)%/i) { $game_variables[$1.to_i] }
  190. result.gsub!(/%actor(\d+)%/i) { $data_actors[$1.to_i].name }
  191. result.gsub!(/%party(\d+)%/i) { $game_party.members[$1.to_i].name }
  192. result.gsub!(/%currency%/i) { Vocab::currency_unit }
  193. result.gsub!(/%name%/i) do
  194. character.is_a?(Game_Player) || character.is_a?(Game_Follower) ? character.actor.name : character.event.name
  195. end
  196. result.gsub!(/%level%/i) do
  197.  
  198. end
  199. result
  200. end
  201. #--------------------------------------------------------------------------
  202. # * Disposição
  203. #--------------------------------------------------------------------------
  204. def dispose
  205. @spr_txt.dispose if @spr_txt
  206. mbseventtext_dispose
  207. end
  208. end
  209. #==============================================================================
  210. # ** Game_Event
  211. #------------------------------------------------------------------------------
  212. # Aqui são feitas as modificações para pegar os textos dos comentários do
  213. # evento
  214. #==============================================================================
  215. class Game_Event < Game_Character
  216. #--------------------------------------------------------------------------
  217. # * Definição dos atributos
  218. #--------------------------------------------------------------------------
  219. attr_reader :event
  220. #--------------------------------------------------------------------------
  221. # * Alias
  222. #--------------------------------------------------------------------------
  223. alias mbseventtext_setuppage setup_page_settings
  224. #--------------------------------------------------------------------------
  225. # * Aplicação das configurações da página
  226. #--------------------------------------------------------------------------
  227. def setup_page_settings(*a, &b)
  228. mbseventtext_setuppage(*a, &b)
  229. @list.select {|cmd| cmd.code == 108 || cmd.code == 408}.each do |comment|
  230. comment.parameters[0].scan(MBS::EventText::REGEX) do
  231. color = ($2 || '#fff')
  232. pos = ($3 || 'above').to_sym
  233. @texts << [$1, color[/[a-f0-9]+/], pos]
  234. end
  235. end
  236. end
  237. end
  238. #==============================================================================
  239. # ** Game_Player
  240. #------------------------------------------------------------------------------
  241. # Aqui são feitas as alterações para pegar os textos do jogador direto das
  242. # notas
  243. #==============================================================================
  244. class Game_Player < Game_Character
  245. #--------------------------------------------------------------------------
  246. # * Alias
  247. #--------------------------------------------------------------------------
  248. alias mbseventtext_refresh refresh
  249. #--------------------------------------------------------------------------
  250. # * Renovação
  251. #--------------------------------------------------------------------------
  252. def refresh(*a, &b)
  253. mbseventtext_refresh
  254. refresh_texts
  255. end
  256. #--------------------------------------------------------------------------
  257. # * Renovação dos textos
  258. #--------------------------------------------------------------------------
  259. def refresh_texts
  260. @texts.clear
  261. return unless actor
  262. $data_actors[actor.id].note.scan(MBS::EventText::REGEX) do
  263. color = ($2 || '#fff')
  264. pos = ($3 || 'above').to_sym
  265. @texts << [$1, color[/[a-f0-9]+/], pos]
  266. end
  267. end
  268. end
  269. #==============================================================================
  270. # ** Game_Follower
  271. #------------------------------------------------------------------------------
  272. # Aqui são feitas as alterações para pegar os textos dos seguidores direto
  273. # das notas
  274. #==============================================================================
  275. if MBS::EventText::USE_FOLLOWER_NOTE
  276. class Game_Follower < Game_Character
  277. #--------------------------------------------------------------------------
  278. # * Alias
  279. #--------------------------------------------------------------------------
  280. alias mbseventtext_refresh refresh
  281. #--------------------------------------------------------------------------
  282. # * Renovação
  283. #--------------------------------------------------------------------------
  284. def refresh(*a, &b)
  285. mbseventtext_refresh
  286. refresh_texts
  287. end
  288. #--------------------------------------------------------------------------
  289. # * Renovação dos textos
  290. #--------------------------------------------------------------------------
  291. def refresh_texts
  292. @texts.clear
  293. return unless actor
  294. $data_actors[actor.id].note.scan(MBS::EventText::REGEX) do
  295. color = ($2 || '#fff')
  296. pos = ($3 || 'above').to_sym
  297. @texts << [$1, color[/[a-f0-9]+/], pos]
  298. end
  299. end
  300. end
  301. end
RAW Paste Data