vindaca510

V's Auto Message Formatting v0.4

Mar 17th, 2014
548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.18 KB | None | 0 0
  1. #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
  2. #                                                                              #
  3. #                         V's  Auto Message Formatting                         #
  4. #                                 Version  0.4                                 #
  5. #                                                                              #
  6. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  7. #                                Written By:  V                                #
  8. #                         Last Edited:  March 20, 2014                         #
  9. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  10. #                                                                              #
  11. #<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>#
  12. #==============================================================================#
  13. #------------------------------------------------------------------------------#
  14. # ** Disclaimer                                                                #
  15. #------------------------------------------------------------------------------#
  16. #                                                                              #
  17. # This script was intended for Non-Commercial use only, if you wish to use     #
  18. # this script in a commercial game please PM me at which ever site you found   #
  19. # this script. Either way please give me credit in your game script as the     #
  20. # writer of this script, and send me a PM abuot the release of the game/demo.  #
  21. #                                                                              #
  22. #------------------------------------------------------------------------------#
  23. # ** How To Use                                                                #
  24. #------------------------------------------------------------------------------#
  25. #                                                                              #
  26. #  * This script is Plug & Play.                                               #
  27. #                                                                              #
  28. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
  29. #                                                                              #
  30. #  * Additional Control/Escape Characters                                      #
  31. #                                                                              #
  32. #    \~                             ~ Quick Indent                             #
  33. #    \M                             ~ Current Map Display Name                 #
  34. #    \L                             ~ Current Group Leader                     #
  35. #    \CG                            ~ Current Amount of Gold                   #
  36. #    \K[x]                          ~ Party Member x Nickname                  #
  37. #    \E[x]                          ~ Enemy x Name                             #
  38. #    \ET[x]                         ~ Enemy Troop x Name                       #
  39. #    \IT[x]                         ~ Item x Name                              #
  40. #    \W[x]                          ~ Weapon Troop x Name                      #
  41. #    \A[x]                          ~ Armor Troop x Name                       #
  42. #    \Y[x]                          ~ Change Message Window Y to x             #
  43. #                                                                              #
  44. #------------------------------------------------------------------------------#
  45. # ** Description                                                               #
  46. #------------------------------------------------------------------------------#
  47. #                                                                              #
  48. #  v0.1                                                                        #
  49. # ~=~=~=~                                                                      #
  50. #                                                                              #
  51. # In v0.1, this script automatically formats the games messages for you.       #
  52. # This enables you to type everything on one line when writing out messages    #
  53. # while also allowing you to still use the enter key and \n to start a new     #
  54. # line if wanted.                                                              #
  55. #                                                                              #
  56. #  v0.2                                                                        #
  57. # ~=~=~=~                                                                      #
  58. #                                                                              #
  59. # In v0.2, I added a few additional control/escape characters.                 #
  60. #                                                                              #
  61. #  v0.3                                                                        #
  62. # ~=~=~=~                                                                      #
  63. #                                                                              #
  64. # In v0.3, I added a few more additional control/escape characters.            #
  65. #                                                                              #
  66. #  v0.4                                                                        #
  67. # ~=~=~=~                                                                      #
  68. #                                                                              #
  69. # In v0.4, I added a control/escape character to change the windows y position.#
  70. #                                                                              #
  71. #------------------------------------------------------------------------------#
  72. #==============================================================================#
  73. #==============================================================================
  74. # ** Window_Message
  75. #------------------------------------------------------------------------------
  76. #  This message window is used to display text.
  77. #==============================================================================
  78.  
  79. class Window_Message < Window_Base
  80.  
  81.   #--------------------------------------------------------------------------
  82.   # * Process All Text
  83.   #--------------------------------------------------------------------------
  84.   def process_all_text
  85.     pos = {}
  86.     text = format_text($game_message.all_text)
  87.     open_and_wait
  88.     new_page(text, pos)
  89.     process_character(text.slice!(0, 1), text, pos) until text.empty?
  90.   end
  91.  
  92.   #--------------------------------------------------------------------------
  93.   # * Aliased Method: Control Character Processing
  94.   #--------------------------------------------------------------------------
  95.   alias :wmpec1002654654200456 :convert_escape_characters
  96.  
  97.   #--------------------------------------------------------------------------
  98.   # * Preconvert Control Characters
  99.   #    As a rule, replace only what will be changed into text strings before
  100.   #    starting actual drawing. The character "\" is replaced with the escape
  101.   #    character (\e).
  102.   #--------------------------------------------------------------------------
  103.   def convert_escape_characters(text)
  104.     wmpec1002654654200456(text)
  105.     result = text.to_s.clone
  106.     result.gsub!(/\\/)             { "\e" }
  107.     result.gsub!(/\e\e/)           { "\\" }
  108.     result.gsub!(/\eV\[(\d+)\]/i)  { $game_variables[$1.to_i] }
  109.     result.gsub!(/\eN\[(\d+)\]/i)  { actor_name($1.to_i) }
  110.     result.gsub!(/\eP\[(\d+)\]/i)  { party_member_name($1.to_i) }
  111.     result.gsub!(/\eG/i)           { Vocab::currency_unit }
  112.     result.gsub!(/\eM/i)           { $game_map.display_name }
  113.     result.gsub!(/\e~/i)           { "    " }
  114.     result.gsub!(/\eL/i)           { $game_party.battle_members[0].name }
  115.     result.gsub!(/\eCG/i)          { $game_party.gold.to_s }
  116.     result.gsub!(/\eK\[(\d+)\]/i)  { $game_party.members[$1.to_i].nickname }
  117.     result.gsub!(/\eE\[(\d+)\]/i)  { $data_enemies[$1.to_i].name }
  118.     result.gsub!(/\eET\[(\d+)\]/i) { $data_troops[$1.to_i].name }
  119.     result.gsub!(/\eIT\[(\d+)\]/i) { $data_items[$1.to_i].name }
  120.     result.gsub!(/\eW\[(\d+)\]/i)  { $data_weapons[$1.to_i].name }
  121.     result.gsub!(/\eA\[(\d+)\]/i)  { $data_armors[$1.to_i].name }
  122.     self.y = $1.to_i if result.scan(/\eY\[(\d+)\]/i) != []
  123.     result.gsub!(/\eY\[(\d+)\]/i)  { "" }
  124.     result
  125.   end
  126.  
  127.   #--------------------------------------------------------------------------
  128.   # * Format(Text)
  129.   #--------------------------------------------------------------------------
  130.   def format_text(text)
  131.     x_pos = 0
  132.     temp_text = convert_escape_characters(text)
  133.     temp_text.size.times { |i|
  134.       element = i
  135.       case
  136.       when temp_text[element] == "\e" && temp_text[element + 1] == "n"
  137.         temp_text[element + 2] = "\n"
  138.         x_pos = 0
  139.         next
  140.       end
  141.       if x_pos >= (self.width - ($game_message.face_name.empty? ? 28 : 168 ))
  142.         while(temp_text[element] != " ")
  143.           break if element == 0
  144.           element -= 1
  145.         end
  146.         temp_text[element] = "\n"
  147.         i = element
  148.         x_pos = 0
  149.       else
  150.         x_pos += text_size(temp_text[i]).width
  151.       end
  152.     }
  153.     return temp_text
  154.   end
  155.  
  156. end
Advertisement
Add Comment
Please, Sign In to add comment