#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ #_/ ◆ Special Text Formatting - KGC_DrawFormatText ◆ VX ◆ #_/ ◇ Last Update : 2007/12/19 #_/ ◆ Written by TOMY #_/ ◆ Translation by Mr. Anonymous #_/ ◆ KGC Site: #_/ ◆ http://ytomy.sakura.ne.jp/ #_/ ◆ Translator's Blog: #_/ ◆ http://mraprojects.wordpress.com #_/---------------------------------------------------------------------------- #_/ Installation: Insert this script above main. #_/============================================================================ #_/ Specialized text display. #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ $imported = {} if $imported == nil $imported["DrawFormatText"] = true #------------------------------------------------------------------------------# class Bitmap @@__dummy_window = Window_Base.new(-64, -64, 64, 64) @@__dummy_window.visible = false #-------------------------------------------------------------------------- # ● Format specification character drawing #-------------------------------------------------------------------------- def draw_format_text(x, y, width, height, text, align = 0) str = convert_special_characters(text) dx = 0 buf = Bitmap.new(Graphics.width * 2, Window_Base::WLH) buf.font = self.font.clone loop { c = str.slice!(/./m) # following letter the acquisition case c when nil case c when nil # When no character present where it should draw break when "\x01" # \C[n] (Character color change) str.sub!(/\[([0-9]+)\]/, "") buf.font.color = @@__dummy_window.text_color($1.to_i) next else # Else draw usual character buf.draw_text(dx, 0, 40, Window_Base::WLH, c) c_width = buf.text_size(c).width dx += c_width end } self.font = buf.font.clone # The buffer is transmitted in the window. dest = Rect.new(x, y, [width, dx].min, height) src = Rect.new(0, 0, dx, Window_Base::WLH) offset = width - dx case align when 1 # Center justification dest.x += offset / 2 when 2 # Right justification dest.x += offset end stretch_blt(dest, buf, src) buf.dispose end #-------------------------------------------------------------------------- # ● Conversion of special characters #-------------------------------------------------------------------------- def convert_special_characters(str) text = str.dup text.gsub!(/\\V\[([0-9]+)\]/i) { $game_variables[$1.to_i] } text.gsub!(/\\N\[([0-9]+)\]/i) { $game_actors[$1.to_i].name } text.gsub!(/\\C\[([0-9]+)\]/i) { "\x01[#{$1}]" } text.gsub!(/\\G/) { $game_party.gold } text.gsub!(/\\\\/) { "\\" } return text end end