Guest User

Simple Paragrapher by Balrogic

a guest
Mar 3rd, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.14 KB | None | 0 0
  1. =begin
  2. Simple Paragrapher by Balrogic
  3.  
  4. This script is really simple. It does all the work on it's own.
  5. There is only one thing you need to configure, the width of the
  6. text drawing area in your message box. The default value of 520
  7. is perfect with the default font settings and message box size.
  8. If you change your font or window and notice that text gets cut
  9. off at the right side of your message window then uncomment puts
  10. statement at line 32, activate your console window if inactive
  11. and make a test event with a line of text that fills the entire
  12. message line without getting cut off. Change the TEXT_WIDTH to
  13. that number.
  14.  
  15. This script is free to use in both commercial and non-commercial
  16. games. Donations are optional but not discouraged. Private message
  17. me at http://forums.rpgmakerweb.com/index.php?/user/52841-balrogic/
  18. and offer me some pizza money if you just can't help yourself.
  19. =end
  20.  
  21. class Window_Message < Window_Base
  22.  
  23.   # CONFIGURATION  # Changing this changes how much text
  24.   TEXT_WIDTH = 520 # to draw before making a new line.
  25.  
  26.   def process_all_text
  27.     open_and_wait
  28.     text = convert_escape_characters($game_message.all_text)
  29.     pos = {}
  30.     new_page(text, pos)
  31.     text = new_text_thingy(text)
  32.     #puts contents.text_size(text).width
  33.     process_character(text.slice!(0, 1), text, pos) until text.empty?
  34.   end
  35.   def new_text_thingy(text)
  36.     @texty = []
  37.     @lengthy = 0
  38.     allowable = TEXT_WIDTH - new_line_x
  39.     text = text.split("\n")
  40.     text.each_with_index {|value, index| text[index] = value.split(" ")}
  41.     text.each_with_index {|value, index|
  42.       if contents.text_size(value.join(" ")).width <= allowable
  43.         @texty[index] = value.join(" ")
  44.       else
  45.         @texty[index] = ""
  46.         value.each {|final|
  47.           if contents.text_size(@texty[index] + final).width - @lengthy <= allowable
  48.             @texty[index] += final + " "
  49.           else
  50.             @texty[index] += "\n"
  51.             @lengthy = contents.text_size(@texty[index]).width
  52.             @texty[index] += final + " "
  53.           end
  54.         } # value.each
  55.       end
  56.     } # text.each_with_index
  57.     @texty.join("\n")
  58.   end
  59. end
Advertisement
Add Comment
Please, Sign In to add comment