Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # =============================================================================
- # TheoAllen - Anywhere Texts On Screen
- # Version : 1.0
- # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
- # (English Documentation)
- # Ported to XP by LiTTleDRAgo
- # =============================================================================
- ($imported ||= {})[:Theo_AnywhereText] = true
- # =============================================================================
- # CHANGE LOGS:
- # -----------------------------------------------------------------------------
- # 2013.08.26 - Finished script
- # 2013.08.25 - Started script
- # =============================================================================
- =begin
- ----------------------------------------------------------------------------
- Introduction :
- This script allow you to have many texts written on screen.
- ----------------------------------------------------------------------------
- How to use :
- Simply put this script below material but above main
- Read the manual
- LiTTleDRAgo's note :
- Require Drago Core Engine to work in RMXP
- ----------------------------------------------------------------------------
- Script calls :
- Write this following line to script call to add text on your screen
- text(key,x,y,text,z,show,width,height,color1,color2)
- Paramaters that must be filled:
- - key >> Is a hash key. You may fill it with numeric or string. It's used to
- delete your on screen text later
- - x >> X coordinate from top-left
- - y >> Y coordinate from top-left
- - text >> Is the text you want to display on screen. It's support escape
- characters such as \N[1] in show text message. But, you have to use
- double slash to activate. For example \\N[1]
- Parameters that can be ommited :
- - z >> Z coordinate on screen. The larger number means the closer to
- player text will be displayed. If it's ommited, the default value
- is 0.
- - show >> show duration in frame. If you want to text stay on screen until
- you delete it manualy, use -1. The default value is -1
- - width >> width of a rectangle that will be used to draw a box
- - height >> height of a rectangle that will be used to draw a box
- - color1 >> Color of the rectangle. Must be filled by
- Color.new(red,green,blue,alpha)
- - color2 >> Second Color of the rectangle. The default value is same as
- color1
- To delete a certain text. Use this script call
- del_text(key)
- Key is a hash key. Same as above
- To clear entire screen, use
- clear_texts
- ----------------------------------------------------------------------------
- Terms of use :
- Credit me, TheoAllen. You are free to edit this script by your own. As long
- as you don't claim it yours. For commercial purpose, don't forget to give me
- a free copy of the game.
- LiTTleDRAgo:
- Optional to credit me.
- =end
- # =============================================================================
- # No configuration is avalaible
- # Do not touch anything pass this line
- # =============================================================================
- class Interpreter
- TextDTStruct = Struct.new(:key,:x,:y,:z,:width,:height,
- :text,:show,:color1,:color2)
- def text(key,x,y,text,z = 0,show = -1, width = 0, height = 0,
- color1 = Color.new(255,255,255), color2 = color1)
- return if $game_system.anytexts.include?(key)
- txt = TextDTStruct.new(key,x,y,z,width,height,text,show,color1,color2)
- $game_system.anytexts[key] = txt
- $game_temp.text_to_add.push(key)
- end
- def del_text(key)
- return unless $game_system.anytexts.include?(key)
- $game_temp.text_to_delete.push(key)
- end
- def clear_texts
- $game_system.anytexts.keys.each { |key| del_text(key) }
- end
- end
- class Game_Temp
- define_method(:text_to_add) { @text_to_add ||= [] }
- define_method(:text_to_delete) { @text_to_delete ||= [] }
- end
- class Game_System
- define_method(:anytexts) { @anytexts ||= {} }
- end
- class Anywhere_Text < Window_Base
- attr_reader :key
- attr_writer :viewport unless method_defined?(:viewport=)
- def initialize(key, viewport)
- pad = standard_padding
- super(-pad, -pad, window_wh.at(0)+pad, window_wh.at(1)+pad)
- self.viewport = viewport
- self.opacity = 0
- self.contents = Bitmap.new(width - 32, height - 32)
- contents.fill_rect(contents.rect,Color.new(0,0,0,0))
- load_data(key)
- draw_contents
- end
- unless method_defined?(:standard_padding)
- define_method(:standard_padding) { 12 }
- end
- unless method_defined?(:draw_text_ex)
- raise("You need Drago Core Engine to use this script in RPG Maker XP")
- end
- def window_wh
- return [Graphics.width, Graphics.height] if Graphics.respond_to?(:width)
- return [640,480]
- end
- def load_data(key)
- @data = $game_system.anytexts[@key = key]
- @text = @data.text
- @xpos = @data.x
- @ypos = @data.y
- @w = @data.width
- @h = @data.height
- @color1 = @data.color1
- @color2 = @data.color2
- self.z = @data.z
- end
- def draw_contents
- rect = Rect.new(@xpos,@ypos,@w,@h)
- contents.gradient_fill_rect(rect,@color1,@color2)
- draw_text_ex(@xpos,@ypos,@text)
- end
- def update
- super
- update_dispose
- end
- def update_dispose
- @data.show = [@data.show - 1, -1].max
- self.dispose if @data.show == 0
- end
- end
- class Text_Hash
- def initialize(viewport = nil)
- @viewport, @data = viewport, {}
- init_used_text
- end
- def init_used_text
- $game_system.anytexts.keys.each { |key| add(key) }
- end
- def update
- update_disposed
- update_change
- update_text
- end
- def update_disposed
- @data.values.each { |text| text.disposed? && delete(text.key) }
- end
- def update_change
- delete($game_temp.text_to_delete.shift)
- add($game_temp.text_to_add.shift)
- end
- def update_text
- @data.values.each{|text| text.disposed? ? delete(text.key) : text.update }
- end
- def delete(key)
- return if key.nil?
- $game_system.anytexts.delete(key)
- (text = @data.delete(key)) && !text.disposed? && text.dispose
- end
- def add(key)
- return if key.nil?
- @data[key] && !@data[key].disposed? && @data[key].dispose
- @data[key] = Anywhere_Text.new(key,@viewport)
- end
- def dispose
- @data.values.each {|text| text.disposed? || text.dispose}
- end
- end
- class Spriteset_Map
- unless method_defined?(:theo_update_anytexts)
- alias_method(:theo_update_anytexts, :update)
- alias_method(:theo_dispose_anytexts, :dispose)
- end
- def update
- theo_update_anytexts
- update_anytexts
- end
- def dispose
- theo_dispose_anytexts
- @anytexts.dispose
- end
- def update_anytexts
- @anytexts ||= Text_Hash.new(@viewport2)
- @anytexts.update
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement