Vlue

Text Wrap

Feb 13th, 2015
191
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Vlue's Rudimentary Text Wrap. Whee
  2.  
  3. $useTextWrap = true
  4.  
  5. class Window_Base
  6.   alias :draw_text_ex_wrap :draw_text_ex
  7.   def draw_text_ex(x, y, text)
  8.     if $useTextWrap
  9.       reset_font_settings
  10.       text = convert_escape_characters(text)
  11.       pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  12.       words = text.split
  13.       words.each {|word| process_word(text,word,pos)}
  14.     else
  15.       draw_text_ex_wrap(x, y, text)
  16.     end
  17.   end
  18.   def process_word(text, word, pos)
  19.     text_width = text_size(word).width
  20.     index = text.index(word) + word.size + 1
  21.     process_new_line(text, pos) if pos[:x] + text_width > contents.width
  22.     process_character(word.slice!(0,1), word, pos) until word.empty?
  23.     process_character(' ',' ',pos)
  24.   end
  25.   alias cec_tw convert_escape_characters
  26.   def convert_escape_characters(text)
  27.     result = cec_tw(text)
  28.     result.gsub!("\n") { "¶" }
  29.     result
  30.   end
  31.   alias pc_tw process_character
  32.   def process_character(c, text, pos)
  33.     c == "¶" ? process_new_line(text, pos) : pc_tw(c,text,pos)
  34.   end
  35. end
  36.  
  37. class Window_Message
  38.   alias :process_all_text_wrap :process_all_text
  39.   def process_all_text
  40.     if $useTextWrap
  41.       open_and_wait
  42.       text = convert_escape_characters($game_message.all_text)
  43.       pos = {}
  44.       new_page(text, pos)
  45.       words = text.split
  46.       words.each {|word| process_word(text, word, pos) }
  47.     else
  48.       process_all_text_wrap
  49.     end
  50.   end
  51. end
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×