Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # EZ Text Pop
- # FenixFyreX (Thank you man! ..)
- #
- # To create a pop above a character, use a script call like so:
- #
- # pop_char_text(text, id, color, size)
- #
- # text - the text to be displayed
- # id - determines what character pops the text.
- # -1 for player
- # 0 for current event
- # 1+ for any event on the map
- # color - the color of the text to be displayed
- # size - the size of the text to be displayed
- # you can leave id, color, and size out, they all have defaults.
- # To create a global pop, use a script call like so:
- #
- # pop_global_text(text, color, size)
- #
- # text - the text to be displayed
- # color - the color of the text to be displayed
- # size - the size of the text to be displayed
- # you can leave color, and size out, they all have defaults.
- module EzTextPop
- # Determines how long the text pops last before fading out.
- PopLength = 80
- # Default color of text.
- PopColor = Color.new(255,255,255)
- # Default size of text.
- PopSize = 18
- end
- class Game_Interpreter
- def pop_char_text(text, id = 0, color = EzTextPop::PopColor, size = EzTextPop::PopSize)
- id = id.to_i
- text = text.to_s
- case id
- when -1
- $game_player.pop_text(text, color, size)
- when 0
- $game_map.events[@event_id].pop_text(text, color, size)
- else
- $game_map.events[id].pop_text(text, color, size)
- end
- return true
- end
- def pop_global_text(text, color = EzTextPop::PopColor, size = EzTextPop::PopSize)
- $game_system.pop_global_text(text, color, size)
- end
- end
- class Game_Character
- attr_accessor :textpops
- alias initialize_pop_text_stuffz initialize unless $@
- def initialize(*args)
- @textpops = []
- initialize_pop_text_stuffz(*args)
- end
- def pop_text(text, color, size)
- sprite = TextPopSprite.new(text, color, size, self)
- @textpops << sprite
- end
- alias update_txtpopspritz update unless $@
- def update
- update_txtpopspritz
- update_textpops
- end
- def update_textpops
- @textpops.compact!
- @textpops.each {|s| s.update unless s.nil? or s.disposed? }
- end
- end
- class Game_System
- attr_accessor :textpops
- alias initialize_pop_textz initialize unless $@
- def initialize
- @textpops = []
- initialize_pop_textz
- end
- def pop_global_text(text, color, size)
- sprite = TextPopSprite.new(text, color, size, self)
- @textpops << sprite
- end
- alias update_textpopz update unless $@
- def update
- update_textpopz
- @textpops.compact!
- @textpops.each {|s| s.update unless s.nil? or s.disposed? }
- end
- end
- class Scene_Base
- alias update_textpopz_charz update unless $@
- def update(*args,&block)
- update_textpopz_charz(*args,&block)
- if !popup_scene && !$game_map.events.nil?
- update_char_textpops
- end
- end
- def popup_scene
- return true if $scene.is_a?(Scene_Map)
- return false
- end
- def update_char_textpops
- $game_map.events.each do |id,event|
- event.update_textpops
- end
- end
- end
- class TextPopSprite < Sprite_Base
- def initialize(text, color, size, char)
- super()
- self.opacity = 255
- @count = EzTextPop::PopLength
- @char = char
- @size = size
- @index = @char.textpops.size
- w = text.size*size
- self.bitmap = Bitmap.new(w+10,size+6)
- self.bitmap.font.size = size
- self.bitmap.font.color = color
- self.bitmap.draw_text(5,3,w+2,size,text,1)
- if @char.is_a?(Game_Character)
- @char_bitmap_height = get_char_height
- self.x = @char.screen_x-(self.bitmap.width/2)
- self.y = (@char.screen_y-@char_bitmap_height)-(@index*size)-32
- self.z = @char.screen_z
- else
- self.x = 0
- self.y = (Graphics.height-self.bitmap.height)-(@index*size)
- self.z = 99999
- end
- end
- def get_char_height
- nam = @char.character_name
- if FileTest.exist?("Graphics/Characters/#{nam}.png")
- bit = Cache.character(nam)
- h = nam.include?('$') ? 4 : 8
- height = bit.height / h
- return height
- end
- return 24
- end
- def update
- super
- if !$scene.popup_scene
- @count = 0
- end
- if @char.is_a?(Game_Character)
- self.x = @char.screen_x-(self.bitmap.width/2)
- self.y = (@char.screen_y-@char_bitmap_height)-(@index*@size)-32
- self.z = @char.screen_z
- else
- self.x = 0
- self.y = (Graphics.height-self.bitmap.height)-(@index*@size)
- self.z = 99999
- end
- @count -= 1
- if @count <= 0
- self.opacity -= 2
- end
- if self.opacity <= 0 or !$scene.is_a?(Scene_Map)
- dispose
- @char.textpops[@char.textpops.index(self)] = nil
- return
- end
- end
- end
Add Comment
Please, Sign In to add comment