Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # MBS - Event Text Display
- #------------------------------------------------------------------------------
- # por Masked
- #==============================================================================
- #==============================================================================
- # Instruções
- #------------------------------------------------------------------------------
- # Para mostrar o texto acima do personagem/event escreva nas notas/comentário
- # dele:
- # <TEXT "texto" #hex above/below>
- # Sendo o texto a mostrar entre aspas, o #hex a cor do texto em hexadecimal e
- # above para o texto acima do personagem e below para abaixo,
- # por exemplo:
- # <TEXT "maçã" #f00 above> = 'maçã' escrito em vermelho acima do personagem
- # Os dois últimos valores são opcionais
- # Você pode usar as tags \V, \N, \P e \G igual às mensagens no texto.
- #
- # Para adicionar/deletar textos por script call, use a propriedade .texts
- # do character;
- # Deleta o texto nº X:
- # character.texts.delete_at(x)
- # Insere o texto "texto" com a cor "cor" acima do personagem:
- # character.texts.insert(x, ["texto","cor",:above])
- # Muda o texto número X para "texto" com a cor "cor" abaixo do personagem:
- # character.texts[x] = ["texte","cor",:below]
- #
- # O character pode ser o jogador ou algum evento:
- # $game_player.texts.delete_at(x)
- # $game_map.events[id].texts.insert(x, ["texto","cor",:above])
- #
- # Também pode ser algum dos seguidores do jogador:
- # $game_player.followers[n].texts.delete_at(x)
- #==============================================================================
- #==============================================================================
- # ** MBS
- #==============================================================================
- module MBS
- #============================================================================
- # ** EventText
- #============================================================================
- module EventText
- #==========================================================================
- # * Configurações
- #==========================================================================
- # Tamanho da fonte do texto
- FONT_SIZE = 18
- # Caso queira usar os textos das notas dos seguidores deixe como true,
- # se não mude para false
- USE_FOLLOWER_NOTE = true
- #==========================================================================
- # * Fim das configurações
- #==========================================================================
- REGEX = /<TEXT\s*"(.+)"\s*(#[a-f0-9]{3,})?\s*(above|below)?\s*>/i
- end
- end
- #==============================================================================
- # ** Game_Character
- #------------------------------------------------------------------------------
- # Modificações para guardar os textos pra cada character
- #==============================================================================
- class Game_Character < Game_CharacterBase
- #--------------------------------------------------------------------------
- # * Definição dos atributos
- #--------------------------------------------------------------------------
- attr_reader :texts
- #--------------------------------------------------------------------------
- # * Alias
- #--------------------------------------------------------------------------
- alias mbseventtext_initpublicmems init_public_members
- #--------------------------------------------------------------------------
- # * Inicialização de variáveis públicas
- #--------------------------------------------------------------------------
- def init_public_members(*a, &b)
- mbseventtext_initpublicmems(*a, &b)
- @texts = []
- end
- end
- #==============================================================================
- # ** Sprite_Character
- #------------------------------------------------------------------------------
- # Modificações para mostrar o texto no personagem
- #==============================================================================
- class Sprite_Character < Sprite_Base
- #--------------------------------------------------------------------------
- # * Alias
- #--------------------------------------------------------------------------
- alias mbseventtext_updatebitmap update_bitmap
- alias mbseventtext_updateposition update_position
- alias mbseventtext_dispose dispose
- #--------------------------------------------------------------------------
- # * Atualização do bitmap de origem
- #--------------------------------------------------------------------------
- def update_bitmap(*a,&b)
- mbseventtext_updatebitmap(*a,&b)
- update_texts if texts_changed?
- @spr_txt.update if @spr_txt
- end
- #--------------------------------------------------------------------------
- # * Atualização da posição do sprite
- #--------------------------------------------------------------------------
- def update_position
- mbseventtext_updateposition
- @spr_txt.x = self.x if @spr_txt
- @spr_txt.y = self.y if @spr_txt
- end
- #--------------------------------------------------------------------------
- # * Verificação de quando os textos mudaram
- #--------------------------------------------------------------------------
- def texts_changed?
- @texts != @character.texts
- end
- #--------------------------------------------------------------------------
- # * Aquisição de uma cor através de um hexadecimal
- #--------------------------------------------------------------------------
- def parse_color(hex)
- r = g = b = a = 255
- case hex.to_s.size
- when 3
- r, g, b = *hex.split('')
- r = (r*2).to_i(16)
- g = (g*2).to_i(16)
- b = (b*2).to_i(16)
- when 4
- r, g, b, a = *hex.split('')
- r = (r*2).to_i(16)
- g = (g*2).to_i(16)
- b = (b*2).to_i(16)
- a = (a*2).to_i(16)
- when 6
- r = hex[0..1].to_i(16)
- g = hex[2..3].to_i(16)
- b = hex[4..5].to_i(16)
- when 8
- r = hex[0..1].to_i(16)
- g = hex[2..3].to_i(16)
- b = hex[4..5].to_i(16)
- a = hex[6..7].to_i(16)
- end
- return Color.new(r,g,b,a)
- end
- private :parse_color
- #--------------------------------------------------------------------------
- # * Aquisição dos textos abaixo do char
- #--------------------------------------------------------------------------
- def below_texts
- @texts.select {|txt| txt[2] == :below}
- end
- #--------------------------------------------------------------------------
- # * Aquisição dos textos acima do char
- #--------------------------------------------------------------------------
- def above_texts
- @texts.select {|txt| txt[2] == :above}
- end
- #--------------------------------------------------------------------------
- # * Atualização dos textos
- #--------------------------------------------------------------------------
- def update_texts
- @spr_txt ||= Sprite.new
- @texts = @character.texts.dup
- bigger = (@texts.sort {|a, b| a[0].size <=> b[0].size}.last || [])[0]
- bitmap.font.size &&= MBS::EventText::FONT_SIZE
- w = bitmap.text_size(bigger).width+8
- h = bitmap.text_size(bigger).height+2
- @spr_txt.bitmap = Bitmap.new([@cw, w].max,@ch+h*@texts.size)
- @spr_txt.bitmap.font.size &&= MBS::EventText::FONT_SIZE
- @spr_txt.ox = @spr_txt.width/2
- @spr_txt.oy = self.oy + above_texts.size*h
- above_texts.compact.each_with_index do |text, i|
- @spr_txt.bitmap.font.color = parse_color(text[1])
- @spr_txt.bitmap.draw_text(0,i*h,w,h,convert_escape_characters(text[0]),1)
- end
- below_texts.compact.each_with_index do |text, i|
- @spr_txt.bitmap.font.color = parse_color(text[1])
- @spr_txt.bitmap.draw_text(0,above_texts.size*h + @ch + i*h,w,h,convert_escape_characters(text[0]),1)
- end
- end
- #--------------------------------------------------------------------------
- # * Conversão dos caracteres de controle
- #--------------------------------------------------------------------------
- def convert_escape_characters(text)
- result = text.to_s.clone
- result.gsub!(/\\/) { "\e" }
- result.gsub!(/\e\e/) { "\\" }
- result.gsub!(/%var(\d+)%/i) { $game_variables[$1.to_i] }
- result.gsub!(/%actor(\d+)%/i) { $data_actors[$1.to_i].name }
- result.gsub!(/%party(\d+)%/i) { $game_party.members[$1.to_i].name }
- result.gsub!(/%currency%/i) { Vocab::currency_unit }
- result.gsub!(/%name%/i) do
- character.is_a?(Game_Player) || character.is_a?(Game_Follower) ? character.actor.name : character.event.name
- end
- result.gsub!(/%level%/i) do
- end
- result
- end
- #--------------------------------------------------------------------------
- # * Disposição
- #--------------------------------------------------------------------------
- def dispose
- @spr_txt.dispose if @spr_txt
- mbseventtext_dispose
- end
- end
- #==============================================================================
- # ** Game_Event
- #------------------------------------------------------------------------------
- # Aqui são feitas as modificações para pegar os textos dos comentários do
- # evento
- #==============================================================================
- class Game_Event < Game_Character
- #--------------------------------------------------------------------------
- # * Definição dos atributos
- #--------------------------------------------------------------------------
- attr_reader :event
- #--------------------------------------------------------------------------
- # * Alias
- #--------------------------------------------------------------------------
- alias mbseventtext_setuppage setup_page_settings
- #--------------------------------------------------------------------------
- # * Aplicação das configurações da página
- #--------------------------------------------------------------------------
- def setup_page_settings(*a, &b)
- mbseventtext_setuppage(*a, &b)
- @list.select {|cmd| cmd.code == 108 || cmd.code == 408}.each do |comment|
- comment.parameters[0].scan(MBS::EventText::REGEX) do
- color = ($2 || '#fff')
- pos = ($3 || 'above').to_sym
- @texts << [$1, color[/[a-f0-9]+/], pos]
- end
- end
- end
- end
- #==============================================================================
- # ** Game_Player
- #------------------------------------------------------------------------------
- # Aqui são feitas as alterações para pegar os textos do jogador direto das
- # notas
- #==============================================================================
- class Game_Player < Game_Character
- #--------------------------------------------------------------------------
- # * Alias
- #--------------------------------------------------------------------------
- alias mbseventtext_refresh refresh
- #--------------------------------------------------------------------------
- # * Renovação
- #--------------------------------------------------------------------------
- def refresh(*a, &b)
- mbseventtext_refresh
- refresh_texts
- end
- #--------------------------------------------------------------------------
- # * Renovação dos textos
- #--------------------------------------------------------------------------
- def refresh_texts
- @texts.clear
- return unless actor
- $data_actors[actor.id].note.scan(MBS::EventText::REGEX) do
- color = ($2 || '#fff')
- pos = ($3 || 'above').to_sym
- @texts << [$1, color[/[a-f0-9]+/], pos]
- end
- end
- end
- #==============================================================================
- # ** Game_Follower
- #------------------------------------------------------------------------------
- # Aqui são feitas as alterações para pegar os textos dos seguidores direto
- # das notas
- #==============================================================================
- if MBS::EventText::USE_FOLLOWER_NOTE
- class Game_Follower < Game_Character
- #--------------------------------------------------------------------------
- # * Alias
- #--------------------------------------------------------------------------
- alias mbseventtext_refresh refresh
- #--------------------------------------------------------------------------
- # * Renovação
- #--------------------------------------------------------------------------
- def refresh(*a, &b)
- mbseventtext_refresh
- refresh_texts
- end
- #--------------------------------------------------------------------------
- # * Renovação dos textos
- #--------------------------------------------------------------------------
- def refresh_texts
- @texts.clear
- return unless actor
- $data_actors[actor.id].note.scan(MBS::EventText::REGEX) do
- color = ($2 || '#fff')
- pos = ($3 || 'above').to_sym
- @texts << [$1, color[/[a-f0-9]+/], pos]
- end
- end
- end
- end
RAW Paste Data