Window_Message centering

EDIT: OK, found it, doesn't matter :S (I always seem to work stuff out when I post) But another question, is there any easy way of centering text through Window_Message? I'm sure there must be a way of adding up the total character's length and displaying the text at that value, but I can't figure it out.

Thanks in advance.
For total length, I believe you can use
contents.text_size(your_text).width
The problem is: Window_Message draws the text one character at a time. (it parses out the control characters).

CCoa's Universal Message System has a text alignment feature.
OK, I'm using CCoa's system now, as I tried to put parts of her code into mine and it just didn't work. I've managed to pretty much recreate what I had using her system, but I have a problem. I've removed:

  1.    # If new line text
  2.     if c == "\n"
  3.       # Add 1 to y
  4.       if !@ignore
  5.         @y += 1
  6.       end
  7.       if @text != ""
  8.         get_x_value
  9.       end
  10.       @ignore = false
  11.  
  12.       # go to next text
  13.       return
  14.     end
  15.  
Expand to see the code.


from the code so the script doesn't create a new line, but carries on so you get more text in one box. However, this is what happens now:

Image

Obviously I want it in that small box down the bottom, as that's my message system, but the text isn't centered, instead, the 'first line' is centered, but as the second line is tacked on the end, the system doesn't recognise it as one line, and just prints it next to it, instead of centering the entire thing as a whole. Anybody got any ideas how I could get round that? Here my edit of CCoa's message system:

Content Hidden Spoiler
  1. # *****************************************************************************
  2. # *    Universal Message System
  3. # *      v1.30
  4. # *      by Ccoa
  5. # *****************************************************************************
  6. # Usage:
  7. =begin
  8.  
  9. IN MESSAGE CODES
  10.   \b          - toggle bold on and off
  11.   \bopc[i]    - change the back opacity for this message to i (should be 0-255)
  12.   \c[i]       - change the text color
  13.   \c[#IIIIII] - change the text color to the hex code (temporary)
  14.   \e[i]       - place the text box over event i (0 = player, -1 no event)
  15.   \face[name] - changes the face graphic to name.png (leave empty [] for no face)
  16.   \fl         - change face justification to left
  17.   \font[name] - change the font to name, leave empty [] to return to the default font
  18.   \fr         - change face justification to right
  19.   \g          - display the gold window
  20.   \height     - height of the message window, works only in normal mode
  21.   \i          - toggle italics on and off
  22.   \ignr       - Do not write anything on this line, only process codes, must be the first thing on a line
  23.   \jc         - justify the window to the center, ignored if using \e
  24.   \jl         - justify the window to the left, ignored if using \e
  25.   \jr         - justify the window to the right, ignored if using \e
  26.   \m          - toggle mode between normal and fit window to text
  27.   \n[i]       - display the name of actor i
  28.   \nm[name]   - display the name in the name window, leave empty [] to remove the name window
  29.   \oa[i]      - display the icon and name of armor i
  30.   \oi[i]      - display the icon and name of item i
  31.   \opc[i]     - change the opacity for this message to i (should be 0-255)
  32.   \os[i]      - display the icon and name of skill i
  33.   \ow[i]      - display the icon and name of weapon i
  34.   \p[i]       - pause for i frames before writing the next character
  35.   \pt         - toggle pause display on and off
  36.   \s          - toggle shadowed text
  37.   \shk[i]     - set window shake to i, higher i is bigger shake, 0 is no shake
  38.   \skip       - toggle text skip on and off
  39.   \t1         - switch to the talk1 comic thingy
  40.   \t2         - switch to the talk2 comic thingy
  41.   \tc         - center the text, must be the first thing on a line
  42.   \th         - switch to the thought comic thingy
  43.   \tl         - left justify the text, must be the first thing on a line
  44.   \tr         - right justify the text, must be the first thing on a line
  45.   \v[i]       - display variable i
  46.   \width      - width of the message window, works only in normal mode
  47.   \w[i]       - wait for i frames after receiving this code, then close the window
  48.   \ws[i]      - change the write speed to i
  49.   \slv[name]  - set this window to be slave window name, or show slave window name
  50.   \inc        - include this window in the last
  51.  
  52. OUT OF MESSAGE CODES (use in a Script event command)
  53. $game_system.ums_mode = NORMAL_MODE - switch to normal mode
  54. $game_system.ums_mode = FIT_WINDOW_TO_TEXT - switch to fit window mode
  55. $game_system.text_skip = true - turn text skip on
  56. $game_system.text_skip = false
  57. true                           - turn text skip off (true is necessary)
  58. $game_system.text_mode = WRITE_FASTER - change skip mode to write faster
  59. $game_system.text_mode = WRITE_ALL - change skip mode to write all
  60. $game_system.write_speed = i - change the delay between letters to i frames
  61. $game_system.window_height = i - change the window height to i
  62. $game_system.window_width = i - change the window width to i
  63. $game_system.window_justification = RIGHT - make the window right justified
  64. $game_system.window_justification = LEFT - make the window left justified
  65. $game_system.window_justification = CENTER - make the window center justified
  66. $game_system.face_graphic = "filename" - change the face graphic to filename.png
  67. $game_system.face_graphic = "" - change the face graphic to none
  68. $game_system.face_graphic_justification = LEFT - the face graphic is on the left side
  69. $game_system.face_graphic_justification = RIGHT - the face graphic is on the right side
  70. $game_system.face_graphic_position = TOP - face graphic appears on top of window
  71. $game_system.face_graphic_position = CENTER - face graphic appears centered in window
  72. $game_system.face_graphic_position = BOTTOM - face graphic appears on the bottom of window
  73. $game_system.shadow_text = true - turn text shadowing on
  74. $game_system.shadow_text = false
  75. true                            - turn text shadowing off (true is necessary)
  76. $game_system.shadow_color = Color.new(red, blue, green, alpha) - change shadow color
  77. $game_system.message_event = what event to put the message over (0 = player, -1 = no event)
  78. $game_system.comic_enabled = false
  79. true                               - turn off comic thingy
  80. $game_system.comic_enabled = true  - turn on comic thingy (only works with message_event not -1)
  81. $game_system.comic_style = TALK1   - use the talk1.png comic thingy
  82. $game_system.comic_style = TALK2   - use the talk2.png comic thingy
  83. $game_system.comic_style = THOUGHT - use the thought.png comic thingy
  84. $game_system.name = "name" - change the text of the name window to name
  85. $game_system.name = "" - remove the name window
  86. $game_system.font = "name" - change the font to name
  87. $game_system.font = "" - return the font to the default
  88. $game_system.text_justification = CENTER - center justify the text
  89. $game_system.text_justification = LEFT - left justify the text
  90. $game_system.text_justification = RIGHT - right justify the text
  91. $game_system.show_pause = true - show pause icon when waiting for user input
  92. $game_system.show_pause = false - don't show pause icon when waiting for user input
  93. $game_system.shake = 0 - turn window shake off
  94. $game_system.shake = i - set shake to i, higher i is bigger shake
  95. $game_system.sound_effect = "" - turn off the letter-by-letter SE
  96. $game_system.sound_effect = "sename" - play the SE sename with each letter written
  97. $game_system.animated_faces = false - do not use animated faces
  98. $game_system.animated_faces = true - use animated faces
  99. $game_system.animation_pause = i - Wait i frames between each animation
  100. $game_system.face_frame_width = i - Each frame on the faceset is i pixels
  101. $game_system.resting_face = "" - Do not use a resting face
  102. $game_system.resting_face = "name" - Use a different animated face named facenamename when done talking
  103. $game_system.resting_animation_pause = i - Wait i frames between resting animations
  104. $game_system.text_mode = ONE_LETTER_AT_A_TIME - write text one letter at a time
  105. $game_system.text_mode = ALL_AT_ONCE - write text all at once
  106. $game_system.font_color = Color.new(R, G, B, A) - permanently change the font color to the RGBA color given here
  107. $game_system.font_color = nil - return the font color permanently to normal_color (white, by default)
  108. $game_system.windowskin = "windowskinname" - change the message box windowskin to windowskin
  109. $game_system.windowskin = "" - change the message box windowskin back to the one in the database
  110. $game_system.name_window = true - show the name window
  111. $game_system.name_window = false - hide the name window (just show the text)
  112. $game_system.opacity = i - change the message window back opacity to i (0-255)
  113.  
  114. =end
  115. # *****************************************************************************
  116. #  CONSTANTS
  117. # *****************************************************************************
  118.  
  119. # modes
  120. NORMAL_MODE        = 0
  121. FIT_WINDOW_TO_TEXT = 1
  122.  
  123. #text modes
  124. ONE_LETTER_AT_A_TIME = 0
  125. ALL_AT_ONCE          = 1
  126.  
  127. # skip modes
  128. WRITE_FASTER = 0
  129. WRITE_ALL    = 1
  130.  
  131. # justifications
  132. RIGHT  = 0
  133. CENTER = 1
  134. LEFT   = 2
  135.  
  136. # positions for extra objects (face graphics, choice box, etc)
  137. ABOVE  = 0  # place the object above the top of the message box
  138. CENTER = 1  # center the object vertically inside the message box
  139. BOTTOM = 2  # place the bottom of the object on the bottom of the message box
  140. SIDE   = 3  # to the side of the message box (which side depends on justification)
  141.  
  142. # comic type
  143. TALK1   = 0
  144. TALK2   = 1
  145. THOUGHT = 2
  146.  
  147.  
  148. # *****************************************************************************
  149. #  Changes to Game_System.  This allows any changes made to be saved when the
  150. #     game is saved.
  151. # *****************************************************************************
  152.  
  153. class Game_System
  154.   attr_accessor :ums_mode # what mode the UMS is in
  155.   attr_accessor :text_skip # whether or not text skip is activated
  156.   attr_accessor :skip_mode # write the text faster while C is pressed, or just skip to the end
  157.   attr_accessor :write_speed # frame delay between characters
  158.  
  159.   attr_accessor :text_mode # write one letter at a time, or all at once?
  160.  
  161.   attr_accessor :window_height # default height of message window
  162.   attr_accessor :window_width # default width of message window
  163.   attr_accessor :window_justification # default justification of window
  164.  
  165.   attr_accessor :face_graphic # current face graphic
  166.   attr_accessor :face_graphic_justification # justification of face graphic
  167.   attr_accessor :face_graphic_position # position of face graphic
  168.  
  169.   attr_accessor :shadowed_text # whether or not to draw a shadow behind the text
  170.   attr_accessor :shadow_color # the shadow color
  171.  
  172.   attr_accessor :choice_justification # where the choice window is located
  173.   attr_accessor :choice_position # prefered position of choice window
  174.  
  175.   attr_accessor :message_event # what event to center the text over (0 player, -1 to not)
  176.  
  177.   attr_accessor :comic_enabled # using "talk" icons?
  178.   attr_accessor :comic_style   # what type of comic image to use
  179.  
  180.   attr_accessor :name # the text for the name window
  181.   attr_accessor :name_window # should the name window be visible?
  182.  
  183.   attr_accessor :font # the name of the font
  184.   attr_accessor :font_color # the name of the (permanent) font color
  185.  
  186.   attr_accessor :text_justification # the justification of the window text
  187.  
  188.   attr_accessor :show_pause # whether or not to show the pause icon
  189.  
  190.   attr_accessor :shake # the amount of shake for the window
  191.  
  192.   attr_accessor :sound_effect # SE to play with each letter
  193.  
  194.   attr_accessor :slave_windows # hash of slave windows
  195.   attr_accessor :indy_windows  # hash of independent windows
  196.  
  197.   attr_accessor :animated_faces # are the faces animated?
  198.   attr_accessor :animation_pause # how long do I wait between animation loops?
  199.   attr_accessor :face_frame_width # how many pixels wide is each face frame
  200.   attr_accessor :resting_face  # postext for waiting face graphic
  201.   attr_accessor :resting_animation_pause # how long to wait for resting graphic
  202.  
  203.   attr_accessor :windowskin # what windowskin to use for messages
  204.   attr_accessor :back_opacity # back opacity of windowskin
  205.   attr_accessor :opacity # opacity of windowskin
  206.  
  207.   attr_reader :shortcuts  # user-defined shortcuts
  208.  
  209.   alias ums_initialize initialize
  210.   def initialize
  211.     ums_initialize
  212.     @ums_mode = NORMAL_MODE
  213.    
  214.     @skip_mode = WRITE_ALL
  215.     @text_skip = true
  216.     @write_speed = 2
  217.    
  218.     @text_mode = ONE_LETTER_AT_A_TIME
  219.    
  220.     @window_height = 60
  221.     @window_width = 620
  222.     @window_justification = CENTER
  223.    
  224.     @face_graphic = ""
  225.     @face_graphic_justification = LEFT
  226.     @face_graphic_position = CENTER
  227.    
  228.     @shadowed_text = false
  229.     @shadow_color = Color.new(0, 0, 0, 100)
  230.    
  231.     @choice_justification = RIGHT
  232.     @choice_position = SIDE
  233.    
  234.     @message_event = -1
  235.    
  236.     @comic_enabled = false
  237.     @comic_style = TALK1
  238.    
  239.     @name = ""
  240.     @name_window = false
  241.    
  242.     @font = "Basic Sans Heavy SF"
  243.     Font.default_size = 14
  244.     Font.default_bold = true    
  245.     @font_color = nil
  246.    
  247.     @text_justification = CENTER
  248.    
  249.     @show_pause = true
  250.    
  251.     @shake = 0
  252.    
  253.     @sound_effect = ""
  254.    
  255.     @slave_windows = {}
  256.     @indy_windows  = {}
  257.    
  258.     @animated_faces = false
  259.     @animation_pause = 80
  260.     @face_frame_width = 100
  261.     @resting_face = ""
  262.     @resting_animation_pause = 80
  263.    
  264.     @windowskin = ""
  265.     @opacity = 255
  266.     @back_opacity = 160
  267.    
  268.     @used_codes = ['\v', '\n', '\c', '\g', '\skip', '\m', '\height', '\width',
  269.                    '\jr', '\jc', '\jl', '\face', '\fl', '\fr', '\b', '\i', '\s',
  270.                    '\e', '\t1', '\t2', '\th', '\nm', '\font', '\p', '\w', '\ws',
  271.                    '\oa', '\oi', '\os', '\ow', '\tl', '\tr', '\tc', '\ignr',
  272.                    '\shk', '\slv', '\ind', '\inc']
  273.                    
  274.     @shortcuts = {}
  275.   end
  276.  
  277.   def add_shortcut(shortcut, code)
  278.     text = shortcut.downcase
  279.     if !@used_codes.include?(text)
  280.       @shortcuts[shortcut] = code
  281.     end
  282.   end
  283.  
  284.   def open_window(name)
  285.     if $game_system.indy_windows.has_key?(name)
  286.       $game_system.indy_windows[name].show = true
  287.     end
  288.   end
  289.  
  290.   def close_window(name)
  291.     if $game_system.indy_windows.has_key?(name)
  292.       $game_system.indy_windows[name].dispose
  293.       $game_system.indy_windows.delete(name)
  294.     end
  295.   end
  296. end
  297.  
  298.  
  299. #==============================================================================
  300. # ** Game_Temp
  301. #------------------------------------------------------------------------------
  302. #  This class handles temporary data that is not included with save data.
  303. #  Refer to "$game_temp" for the instance of this class.
  304. #==============================================================================
  305. class Game_Temp
  306.   attr_accessor :choices
  307. end
  308.  
  309. class Scene_Map
  310.   alias ums_update update
  311.   def update
  312.     $game_system.slave_windows.each_value { |window| window.update }
  313.     $game_system.indy_windows.each_value { |window| window.update }
  314.     ums_update
  315.   end
  316. end
  317.  
  318. class Interpreter
  319.   #--------------------------------------------------------------------------
  320.   # * Show Text
  321.   #--------------------------------------------------------------------------
  322.   def command_101
  323.     # If other text has been set to message_text
  324.     if $game_temp.message_text != nil
  325.       # End
  326.       return false
  327.     end
  328.     # Set message end waiting flag and callback
  329.     @message_waiting = true
  330.     $game_temp.message_proc = Proc.new { @message_waiting = false }
  331.     # Set message text on first line
  332.     $game_temp.message_text = @list[@index].parameters[0] + "\n"
  333.     line_count = 1
  334.     # Loop
  335.     loop do
  336.       # If next event command text is on the second line or after
  337.       if @list[@index + 1].code == 401
  338.         # Add the second line or after to message_text
  339.         $game_temp.message_text += @list[@index + 1].parameters[0] + "\n"
  340.         line_count += 1
  341.       # If the next event command is show text
  342.       elsif @list[@index + 1].code == 101
  343.         # If the text contains the \inc code
  344.         if @list[@index + 1].parameters[0].index(/\\[Ii][Nn][Cc]/) != nil
  345.           $game_temp.message_text += @list[@index + 1].parameters[0] + "\n"
  346.           $game_temp.message_text.sub!(/\\[Ii][Nn][Cc]/) { "" }
  347.         else
  348.           return true
  349.         end
  350.       # If event command is not on the second line or after
  351.       else
  352.         # If next event command is show choices
  353.         if @list[@index + 1].code == 102
  354.           # If choices fit on screen
  355.           #if @list[@index+1].parameters[0].size <= 4 - line_count
  356.             # Advance index
  357.             @index += 1
  358.             # Choices setup
  359.             $game_temp.choice_start = line_count
  360.             setup_choices(@list[@index].parameters)
  361.           #end
  362.         # If next event command is input number
  363.         elsif @list[@index + 1].code == 103
  364.           # If number input window fits on screen
  365.           if line_count < 4
  366.             # Advance index
  367.             @index += 1
  368.             # Number input setup
  369.             $game_temp.num_input_start = line_count
  370.             $game_temp.num_input_variable_id = @list[@index].parameters[0]
  371.             $game_temp.num_input_digits_max = @list[@index].parameters[1]
  372.           end
  373.         end
  374.         # Continue
  375.         return true
  376.       end
  377.       # Advance index
  378.       @index += 1
  379.     end
  380.   end
  381.   #--------------------------------------------------------------------------
  382.   # * Setup Choices
  383.   #--------------------------------------------------------------------------
  384.   def setup_choices(parameters)
  385.     # Set choice item count to choice_max
  386.     $game_temp.choice_max = parameters[0].size
  387.     # Set choice to message_text
  388.     $game_temp.choices = parameters[0]
  389.     # Set cancel processing
  390.     $game_temp.choice_cancel_type = parameters[1]
  391.    
  392.     # Set callback
  393.     current_indent = @list[@index].indent
  394.     $game_temp.choice_proc = Proc.new { |n| @branch[current_indent] = n }
  395.   end
  396.  
  397.   #--------------------------------------------------------------------------
  398.   # * Input Number
  399.   #--------------------------------------------------------------------------
  400.   def command_103
  401.     # If text has been set to message_text
  402.     if $game_temp.message_text != nil
  403.       # End
  404.       return false
  405.     end
  406.     # Set message end waiting flag and callback
  407.     @message_waiting = true
  408.     $game_temp.message_proc = Proc.new { @message_waiting = false }
  409.     # Number input setup
  410.     $game_temp.message_text = ""
  411.     $game_temp.num_input_start = 0
  412.     $game_temp.num_input_variable_id = @parameters[0]
  413.     $game_temp.num_input_digits_max = @parameters[1]
  414.     # Continue
  415.     return true
  416.   end
  417.  
  418.   #--------------------------------------------------------------------------
  419.   # * Script
  420.   #--------------------------------------------------------------------------
  421.   def command_355
  422.     # Set first line to script
  423.     script = @list[@index].parameters[0] + "\n"
  424.     # Loop
  425.     loop do
  426.       # If next event command is second line of script or after
  427.       if @list[@index + 1].code == 655
  428.         # Add second line or after to script
  429.         script += @list[@index + 1].parameters[0] + "\n"
  430.       # If event command is not second line or after
  431.       else
  432.         # Abort loop
  433.         break
  434.       end
  435.       # Advance index
  436.       @index += 1
  437.     end
  438.     # Evaluation
  439.     result = eval(script)
  440.  
  441.     # Continue
  442.     return true
  443.   end
  444. end
  445.  
  446. # *****************************************************************************
  447. #  Changes to Window_Message.  This is the bulk of the script
  448. # *****************************************************************************
  449. #==============================================================================
  450. # ** Window_Message
  451. #------------------------------------------------------------------------------
  452. #  This message window is used to display text.
  453. #==============================================================================
  454.  
  455. class Window_Message < Window_Base
  456.   #--------------------------------------------------------------------------
  457.   # * Object Initialization
  458.   #--------------------------------------------------------------------------
  459.   def initialize
  460.     # x-coordinate depends on justification
  461.     if $game_system.window_justification == RIGHT
  462.       x = 640 - self.width
  463.     elsif $game_system.window_justification == LEFT
  464.       x = 0
  465.     else # center
  466.       x = (640 - $game_system.window_width) / 2
  467.     end
  468.     # y-coordinate depends on height
  469.     y = 480 - $game_system.window_height - 16
  470.     super(x, y, $game_system.window_width, $game_system.window_height)
  471.     self.contents = Bitmap.new(width - 32, height - 32)
  472.     self.visible = false
  473.     self.z = 9998
  474.     @fade_in = false
  475.     @fade_out = false
  476.     @contents_showing = false
  477.    
  478.     # face graphic sprite
  479.     @face = Sprite.new
  480.     @face.opacity = 0
  481.     @face.z = self.z + 1
  482.     @face_offset = 0
  483.    
  484.     # choice window
  485.     @choice_window = Window_Choice.new([])
  486.     @choice_window.back_opacity = self.back_opacity
  487.    
  488.     # comic sprite
  489.     @comic = Sprite.new
  490.     @comic.opacity = 0
  491.     @comic.z = self.z + 1
  492.     if $game_system.comic_style == TALK1
  493.       @comic.bitmap = RPG::Cache.windowskin("talk1")
  494.     elsif $game_system.comic_style == TALK2
  495.       @comic.bitmap = RPG::Cache.windowskin("talk2")
  496.     else # thought
  497.       @comic.bitmap = RPG::Cache.windowskin("thought")
  498.     end
  499.    
  500.     # name window
  501.     @name_window = Window_Name.new
  502.     @name_window.z = self.z + 1
  503.    
  504.     @pause_time = 0
  505.     @wait = 0
  506.    
  507.     @show = false
  508.    
  509.     @face_frame = 0
  510.   end
  511.   #--------------------------------------------------------------------------
  512.   # * Dispose
  513.   #--------------------------------------------------------------------------
  514.   def dispose
  515.     terminate_message
  516.     $game_temp.message_window_showing = false
  517.     if @input_number_window != nil
  518.       @input_number_window.dispose
  519.     end
  520.     @face.dispose
  521.     @choice_window.dispose
  522.     @comic.dispose
  523.     @name_window.dispose
  524.     super
  525.   end
  526.   #--------------------------------------------------------------------------
  527.   # * Terminate Message
  528.   #--------------------------------------------------------------------------
  529.   def terminate_message
  530.     @show = false
  531.     self.active = false
  532.     self.pause = false
  533.     self.contents.clear
  534.     # Clear showing flag
  535.     @contents_showing = false
  536.     # Call message callback
  537.     if $game_temp.message_proc != nil
  538.       $game_temp.message_proc.call
  539.     end
  540.     # Clear variables related to text, choices, and number input
  541.     $game_temp.message_text = nil
  542.     $game_temp.message_proc = nil
  543.     $game_temp.choice_start = 99
  544.     $game_temp.choice_max = 0
  545.     $game_temp.choice_cancel_type = 0
  546.     $game_temp.choice_proc = nil
  547.     $game_temp.num_input_start = 99
  548.     $game_temp.num_input_variable_id = 0
  549.     $game_temp.num_input_digits_max = 0
  550.     # Open gold window
  551.     if @gold_window != nil
  552.       @gold_window.dispose
  553.       @gold_window = nil
  554.     end
  555.     @choice_window.visible = false
  556.     @choice_window.active = false
  557.     @comic.opacity = 0
  558.     $game_system.slave_windows.each_pair {|name, window|
  559.       if window.show == true
  560.         window.dispose
  561.         $game_system.slave_windows.delete(name)
  562.       end
  563.     }
  564.     @done = false
  565.   end
  566.   #--------------------------------------------------------------------------
  567.   # * Refresh
  568.   #--------------------------------------------------------------------------
  569.   def refresh
  570.     self.contents.clear
  571.     if $game_system.font_color.nil?
  572.       self.contents.font.color = normal_color
  573.     else
  574.       self.contents.font.color = $game_system.font_color
  575.     end
  576.     if $game_system.windowskin != ""  
  577.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin)
  578.     else
  579.       self.windowskin = RPG::Cache.windowskin($data_system.windowskin_name)
  580.     end
  581.     @show = true
  582.     @x = @y = 0
  583.  
  584.     # If waiting for a message to be displayed
  585.     if $game_temp.message_text != nil
  586.       @text = $game_temp.message_text
  587.      
  588.       # replace shortcuts with original code
  589.       $game_system.shortcuts.each { |shortcut, code|
  590.         @text.gsub!(shortcut, code)
  591.       }
  592.      
  593.       # VERY first thing.  Check to see if this is being set up as a slave
  594.       #  or independent window.
  595.       if @text.index(/\\[Ss][Ll][Vv]\[(.*?)\]/) != nil
  596.         # is this a new slave window, or a request to display it?
  597.         if !$game_system.slave_windows.has_key?($1.to_s)
  598.           # there is no such slave window yet.  Set it up.
  599.           @text.gsub!(/\\[Ss][Ll][Vv]\[(.*?)\]/, "")
  600.           $game_system.slave_windows[$1.to_s] = Window_Slave.new(@text)
  601.           @text = ""
  602.           @show = false
  603.           terminate_message
  604.           return
  605.         end
  606.       end
  607.       if @text.index(/\\[Ii][Nn][Dd]\[(.*?)\]/) != nil
  608.         # is this a new independent window, or a request to display it?
  609.         if !$game_system.indy_windows.has_key?($1.to_s)
  610.           # there is no such slave window yet.  Set it up.
  611.           @text.gsub!(/\\[Ii][Nn][Dd]\[(.*?)\]/, "")
  612.           $game_system.indy_windows[$1.to_s] = Window_Slave.new(@text)
  613.           @text = ""
  614.           @show = false
  615.           terminate_message
  616.           return
  617.         end
  618.       end
  619.      
  620.       # Control text processing
  621.       begin
  622.         last_text = @text.clone
  623.         @text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  624.       end until @text == last_text
  625.       @text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  626.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  627.       end
  628.      
  629.       # window mode
  630.       if @text.index(/\\[Mm]/) != nil
  631.         if $game_system.ums_mode == NORMAL_MODE
  632.           $game_system.ums_mode = FIT_WINDOW_TO_TEXT
  633.         else
  634.           $game_system.ums_mode = NORMAL_MODE
  635.         end
  636.         @text.gsub!(/\\[Mm]/) { "" }
  637.       end
  638.      
  639.       # window height
  640.       @text.gsub!(/\\[Hh][Ee][Ii][Gg][Hh][Tt]\[([0-9]+)\]/) do
  641.         $game_system.window_height = $1.to_i
  642.         ""
  643.       end
  644.      
  645.       # window width
  646.       @text.gsub!(/\\[Ww][Ii][Dd][Tt][Hh]\[([0-9]+)\]/) do
  647.         $game_system.window_width = $1.to_i
  648.         ""
  649.       end
  650.      
  651.       # justification
  652.       @text.gsub!(/\\[Jj][Rr]/) do
  653.         $game_system.window_justification = RIGHT
  654.         reset_window
  655.         ""
  656.       end
  657.       @text.gsub!(/\\[Jj][Cc]/) do
  658.         $game_system.window_justification = CENTER
  659.         reset_window
  660.         ""
  661.       end      
  662.       @text.gsub!(/\\[Jj][Ll]/) do
  663.         $game_system.window_justification = LEFT
  664.         reset_window
  665.         ""
  666.       end
  667.      
  668.       # face graphics
  669.       @text.gsub!(/\\[Ff][Aa][Cc][Ee]\[(.*?)\]/) do
  670.         $game_system.face_graphic = $1.to_s
  671.         if $1.to_s == ""
  672.           @face.opacity = 0
  673.         end
  674.         ""
  675.       end
  676.       @text.gsub!(/\\[Ff][Ll]/) do
  677.         $game_system.face_graphic_justification = LEFT
  678.         ""
  679.       end
  680.       @text.gsub!(/\\[Ff][Rr]/) do
  681.         $game_system.face_graphic_justification = RIGHT
  682.         ""
  683.       end
  684.      
  685.       # event centering
  686.       @text.gsub!(/\\[Ee]\[([0-9]+)\]/) do
  687.         $game_system.message_event = $1.to_i
  688.         ""
  689.       end
  690.      
  691.       # comic thingy
  692.       @text.gsub!(/\\[Tt]1/) do
  693.         $game_system.comic_style = TALK1
  694.         @comic.bitmap = RPG::Cache.windowskin("talk1.png")
  695.         ""
  696.       end
  697.       @text.gsub!(/\\[Tt]2/) do
  698.         $game_system.comic_style = TALK2
  699.         @comic.bitmap = RPG::Cache.windowskin("talk2.png")
  700.         ""
  701.       end
  702.       @text.gsub!(/\\[Tt][Hh]/) do
  703.         $game_system.comic_style = THOUGHT
  704.         @comic.bitmap = RPG::Cache.windowskin("thought.png")
  705.         ""
  706.       end
  707.      
  708.       # name window
  709.       @text.gsub!(/\\[Nn][Mm]\[(.*?)\]/) do
  710.         $game_system.name = $1.to_s
  711.         if $1.to_s == ""
  712.           @name_window.visible = false
  713.           @name_window.dummy_window.visible = false
  714.         end
  715.         ""
  716.       end
  717.      
  718.       # toggle pause
  719.       @text.gsub!(/\\[Pp][Tt]/) do
  720.         $game_system.show_pause = !$game_system.show_pause
  721.         ""
  722.       end
  723.      
  724.       # shaking
  725.       @text.gsub!(/\\[Ss][Hh][Kk]\[([0-9]+)\]/) do
  726.         $game_system.shake = $1.to_i
  727.         ""
  728.       end
  729.      
  730.       # back opacity
  731.       @text.gsub!(/\\[Bb][Oo][Pp][Cc]\[([0-9]+)\]/) do
  732.         $game_system.back_opacity = $1.to_i
  733.         self.back_opacity = $game_system.back_opacity
  734.         ""
  735.       end
  736.      
  737.       # opacity
  738.       @text.gsub!(/\\[Oo][Pp][Cc]\[([0-9]+)\]/) do
  739.         $game_system.opacity = $1.to_i
  740.         self.opacity = $game_system.opacity
  741.         ""
  742.       end
  743.      
  744.       # Change "\\\\" to "\000" for convenience
  745.       @text.gsub!(/\\\\/) { "\000" }
  746.       # Change "\\C" to "\001" and "\\G" to "\002"
  747.       @text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  748.       @text.gsub!(/\\[Gg]/) { "\002" }
  749.       @text.gsub!(/\\[Cc]\[0x([0123456789abcdef]+)\]/) { "\026[#{$1}]" }
  750.      
  751.       # text skip code
  752.       @text.gsub!(/\\[Ss][Kk][Ii][Pp]/) { "\003" }
  753.      
  754.       # ignore code
  755.       @text.gsub!(/\\[Ii][Gg][Nn][Rr]/) { "\023" }
  756.      
  757.       # slave and indy windows
  758.       @text.gsub!(/\\[Ss][Ll][Vv]\[(.*?)\]/) { "\024[#{$1}]" }
  759.       @text.gsub!(/\\[Ii][Nn][Dd]\[(.*?)\]/) { "\025[#{$1}]" }
  760.      
  761.       # bold and italics
  762.       @text.gsub!(/\\[Bb]/) { "\004" }
  763.       @text.gsub!(/\\[Ii]/) { "\005" }
  764.      
  765.       # shadow
  766.       @text.gsub!(/\\[Ss]/) { "\006" }
  767.      
  768.       # font
  769.       @text.gsub!(/\\[Ff][Oo][Nn][Tt]\[(.*?)\]/) { "\007[#{$1}]" }
  770.      
  771.       # pause and wait
  772.       @text.gsub!(/\\[Pp]\[([0-9]+)\]/) { "\010[#{$1}]" }
  773.       @text.gsub!(/\\[Ww]\[([0-9]+)\]/) { "\011[#{$1}]" }
  774.      
  775.       # write speed
  776.       @text.gsub!(/\\[Ww][Ss]\[([0-9]+)\]/) { "\013[#{$1}]" }
  777.            
  778.       # armor, items, skills, and weapons
  779.       @text.gsub!(/\\[Oo][Aa]\[([0-9]+)\]/) {
  780.         item = $data_armors[$1.to_i]
  781.         "\014[#{$1}]" + "  " + item.name
  782.       }
  783.       @text.gsub!(/\\[Oo][Ii]\[([0-9]+)\]/) {
  784.         item = $data_items[$1.to_i]
  785.         "\015[#{$1}]" + "  " + item.name
  786.       }
  787.       @text.gsub!(/\\[Oo][Ss]\[([0-9]+)\]/) {
  788.         item = $data_skills[$1.to_i]
  789.         "\016[#{$1}]" + "  " + item.name
  790.       }
  791.       @text.gsub!(/\\[Oo][Ww]\[([0-9]+)\]/) {
  792.         item = $data_weapons[$1.to_i]
  793.         "\017[#{$1}]" + "  " + item.name
  794.       }
  795.      
  796.       # text justification
  797.       @text.gsub!(/\\[Tt][Cc]/) { "\020" }
  798.       @text.gsub!(/\\[Tt][Ll]/) { "\021" }
  799.       @text.gsub!(/\\[Tt][Rr]/) { "\022" }
  800.      
  801.       # Resize the window to fit the contents?
  802.       if $game_system.ums_mode == FIT_WINDOW_TO_TEXT
  803.         width = 1
  804.         text = @text.split("\n")
  805.         height = 0
  806.         i = 0
  807.         for line in text
  808.           # don't count this line's width if it has the ignr code
  809.           if !line.include?("\023")
  810.             width = [width, self.contents.text_size(line).width].max
  811.             delta = self.contents.text_size(line).height
  812.             height += delta + (delta * 0.2).to_i
  813.           end
  814.         end
  815.        
  816.         if $game_system.face_graphic != "" and ($game_system.face_graphic_position == CENTER or $game_system.face_graphic_position == BOTTOM)
  817.           width += @face.bitmap.width
  818.           if height < @face.bitmap.height
  819.             height = @face.bitmap.height - 32
  820.           end
  821.         end
  822.        
  823.         if height == 0
  824.           height = 1
  825.         end
  826.        
  827.         self.width = width + 48
  828.         self.height = height + 48
  829.         self.contents = Bitmap.new(width + 16, height)
  830.         if $game_system.font_color.nil?
  831.           self.contents.font.color = normal_color
  832.         else
  833.           self.contents.font.color = $game_system.font_color
  834.         end
  835.       else
  836.         if self.width != $game_system.window_height or self.height != $game_system.window_width
  837.           self.width = $game_system.window_width
  838.           self.height = $game_system.window_height
  839.           self.contents = Bitmap.new(self.width - 32, self.height - 32)
  840.           if $game_system.font_color.nil?
  841.             self.contents.font.color = normal_color
  842.           else
  843.             self.contents.font.color = $game_system.font_color
  844.           end
  845.         end
  846.       end
  847.      
  848.       reset_window
  849.      
  850.       get_x_value
  851.      
  852.       @count = Graphics.frame_count
  853.       @pause_time = 0
  854.       @ignore = false
  855.       @ascending = true
  856.       @target_x = self.x + $game_system.shake
  857.       @done = false
  858.       @face_frame = 0
  859.       @done = false
  860.      
  861.       self.oy = 0
  862.     end
  863.    
  864.    
  865.   end
  866.  
  867.   #--------------------------------------------------------------------------
  868.   # * Set Window Position and Opacity Level
  869.   #--------------------------------------------------------------------------
  870.   def reset_window (change_opacity = true)
  871.     # x-coordinate depends on justification
  872.     if $game_system.message_event == -1
  873.       if $game_system.window_justification == RIGHT
  874.         self.x = 640 - $game_system.window_width
  875.       elsif $game_system.window_justification == LEFT
  876.         self.x = 0
  877.       else # center
  878.         self.x = (640 - self.width) / 2
  879.       end
  880.     else
  881.       if $game_system.message_event == 0 or $game_map.events[$game_system.message_event] == nil
  882.         # center on player
  883.         event_x = $game_player.screen_x
  884.       else
  885.         # center on the event specified
  886.         event_x = $game_map.events[$game_system.message_event].screen_x
  887.       end
  888.       self.x = event_x - self.width / 2
  889.       @comic.x = self.x + (self.width / 2) + 4
  890.     end
  891.    
  892.     if $game_temp.in_battle
  893.       self.y = 16
  894.     else
  895.       if $game_system.message_event == -1
  896.         case $game_system.message_position
  897.           when 0  # up
  898.             self.y = 16
  899.           when 1  # middle
  900.             self.y = (480 - $game_system.window_height) / 2
  901.           when 2  # down
  902.             self.y = 426
  903.         end
  904.       else
  905.         if $game_system.message_event == 0 or $game_map.events[$game_system.message_event] == nil
  906.           # above player
  907.           self.y = $game_player.screen_y - self.height - 48
  908.         else
  909.           # above event specified
  910.           self.y = $game_map.events[$game_system.message_event].screen_y - self.height - 48
  911.         end
  912.         @comic.y = self.y + self.height - 2
  913.         @comic.angle = 0
  914.       end
  915.     end
  916.     if self.y < 0 + ($game_system.name == "" ? 0 : 16)
  917.       if $game_system.comic_enabled
  918.         if $game_system.message_event == 0 or $game_map.events[$game_system.message_event] == nil
  919.           self.y = $game_player.screen_y - 16
  920.         else
  921.           self.y = $game_map.events[$game_system.message_event].screen_y - 16
  922.         end
  923.         @comic.angle = 180
  924.         @comic.y = self.y + 2
  925.         @comic.x = self.x + (self.width / 2) - 4
  926.       else
  927.         self.y = 0 + ($game_system.name == "" ? 0 : 16)
  928.       end
  929.     elsif self.y > 480 - self.height
  930.       self.y = 480 - self.height
  931.     end
  932.     if self.x < 0
  933.       self.x = 0
  934.     elsif self.x > 680 - self.width - 48
  935.       self.x = 640 - self.width
  936.     end
  937.    
  938.     if change_opacity
  939.       if $game_system.message_frame == 0 and $game_temp.message_text != ""
  940.         self.opacity = $game_system.opacity
  941.       else
  942.         self.opacity = 0
  943.       end
  944.       self.back_opacity = $game_system.back_opacity
  945.     end
  946.    
  947.       # face stuff
  948.       if $game_system.face_graphic != ""  
  949.         # the player has chosen to show a face graphic
  950.         if @done and $game_system.resting_face != ""
  951.           @face.bitmap = RPG::Cache.picture($game_system.face_graphic + $game_system.resting_face)
  952.           if @face_frame * $game_system.face_frame_width >= @face.bitmap.width
  953.             @face_frame = 0
  954.           end
  955.         else
  956.           @face.bitmap = RPG::Cache.picture($game_system.face_graphic)
  957.         end
  958.        
  959.         # picture y-coordinate
  960.         if $game_system.face_graphic_position == ABOVE
  961.           @face.y = self.y - @face.bitmap.height
  962.           @face_offset = 0
  963.         elsif $game_system.face_graphic_position == CENTER
  964.           delta = (@face.bitmap.height - self.height) / 2
  965.           @face.y = self.y - delta
  966.           if $game_system.animated_faces
  967.             @face_offset = $game_system.face_frame_width + 16
  968.           else
  969.             @face_offset = @face.bitmap.width + 16
  970.           end
  971.         elsif $game_system.face_graphic_position == BOTTOM
  972.           @face.y = self.y + self.height - @face.bitmap.height
  973.           if $game_system.animated_faces
  974.             @face_offset = $game_system.face_frame_width + 16
  975.           else
  976.             @face_offset = @face.bitmap.width + 16
  977.           end
  978.         else # side
  979.           delta = (@face.bitmap.height - self.height) / 2
  980.           @face.y = self.y - delta
  981.           @face_offset = 0
  982.         end
  983.        
  984.         # picture x-coordinate
  985.         if $game_system.face_graphic_justification == LEFT
  986.           if $game_system.face_graphic_position == SIDE
  987.             @face.x = self.x - @face.bitmap.width
  988.           else
  989.             @face.x = self.x + 10
  990.           end
  991.         else # right side
  992.           if $game_system.animated_faces
  993.             offset = @face.bitmap.width - $game_system.face_frame_width
  994.           else
  995.             offset = 0
  996.           end
  997.           if $game_system.face_graphic_position == SIDE
  998.             @face.x = self.x + self.width + offset
  999.           else
  1000.             @face.x = self.x + self.width - @face.bitmap.width - 10 + offset
  1001.             @face_offset = 0
  1002.           end
  1003.         end
  1004.        
  1005.         if $game_system.animated_faces
  1006.           @face.src_rect = Rect.new(@face_frame * $game_system.face_frame_width, 0, $game_system.face_frame_width, @face.bitmap.height)
  1007.           if @done and $game_system.resting_face != ""
  1008.             pause = $game_system.resting_animation_pause
  1009.           else
  1010.             pause = $game_system.animation_pause
  1011.           end
  1012.           if Graphics.frame_count % pause == 0
  1013.             @animate_face = true
  1014.           end
  1015.           if @animate_face
  1016.             if Graphics.frame_count % 3 == 0
  1017.               @face_frame += 1
  1018.               if @face_frame * $game_system.face_frame_width >= @face.bitmap.width
  1019.                 @face_frame = 0
  1020.                 @animate_face = false
  1021.               end
  1022.             end
  1023.           end
  1024.         end
  1025.       end
  1026.      
  1027.       # name window
  1028.       if $game_system.name != ""
  1029.         @name_window.x = self.x
  1030.         @name_window.y = self.y - 36
  1031.         @name_window.set_name($game_system.name)
  1032.       end
  1033.      
  1034.       # If choice
  1035.     if $game_temp.choice_max > 0
  1036.       @choice_window.set_choices($game_temp.choices)
  1037.       # determine x and y coords for choice window
  1038.       if $game_system.choice_justification == LEFT
  1039.         @choice_window.x = self.x
  1040.       else
  1041.         @choice_window.x = self.x + self.width - @choice_window.width
  1042.       end
  1043.       if $game_system.choice_position == ABOVE
  1044.         # check to make sure there is enough room above the textbox
  1045.         if self.y < @choice_window.height
  1046.           # not enough room above, place below
  1047.           @choice_window.y = self.y + self.height
  1048.         else
  1049.           # draw above
  1050.           @choice_window.y = self.y - @choice_window.height
  1051.         end
  1052.       elsif $game_system.choice_position == BOTTOM
  1053.         # check to make sure there is enough room below the textbox
  1054.         if (480 - self.y - self.height) < @choice_window.height
  1055.           # not enough room below, place above
  1056.           @choice_window.y = self.y - @choice_window.height
  1057.         else
  1058.           # draw below
  1059.           @choice_window.y = self.y + self.height
  1060.         end
  1061.       else # side
  1062.         if $game_system.choice_justification == LEFT
  1063.           # check to make sure there's room on the left side
  1064.           if self.y < @choice_window.width
  1065.             # not enough room on the side, check to make sure there's room below
  1066.             if (480 - self.y - self.height) < @choice_window.height
  1067.               # not enough room below, place above
  1068.               @choice_window.y = self.y - @choice_window.height
  1069.             else
  1070.               # draw below
  1071.               @choice_window.y = self.y + self.height
  1072.             end
  1073.           else
  1074.             # place on the left side
  1075.             @choice_window.y = self.y
  1076.             @choice_window.x = self.x - @choice_window.width
  1077.           end
  1078.         else # right
  1079.           # check to make sure there's room on the right side
  1080.           if (680 - (self.y + self.width)) < @choice_window.width
  1081.             # not enough room on the side, check to make sure there's room below
  1082.             if (480 - self.y - self.height) < @choice_window.height
  1083.               # not enough room below, place above
  1084.               @choice_window.y = self.y - @choice_window.height
  1085.             else
  1086.               # draw below
  1087.               @choice_window.y = self.y + self.height
  1088.             end
  1089.           else
  1090.             # place on the left side
  1091.             @choice_window.y = self.y
  1092.             @choice_window.x = self.x + self.width
  1093.           end
  1094.         end
  1095.       end
  1096.     end
  1097.    
  1098.     # If number input
  1099.     if $game_temp.num_input_variable_id > 0
  1100.       if @input_number_window == nil
  1101.         digits_max = $game_temp.num_input_digits_max
  1102.         number = $game_variables[$game_temp.num_input_variable_id]
  1103.         @input_number_window = Window_InputNumber.new(digits_max)
  1104.         @input_number_window.number = number
  1105.       end
  1106.       # determine x and y coords for number input window
  1107.       if $game_system.choice_justification == LEFT
  1108.         @input_number_window.x = self.x
  1109.       else
  1110.         @input_number_window.x = self.x + self.width - @input_number_window.width
  1111.       end
  1112.       if $game_system.choice_position == ABOVE
  1113.         # check to make sure there is enough room above the textbox
  1114.         if self.y < @input_number_window.height
  1115.           # not enough room above, place below
  1116.           @input_number_window.y = self.y + self.height
  1117.         else
  1118.           # draw above
  1119.           @input_number_window.y = self.y - @choice_window.height
  1120.         end
  1121.       elsif $game_system.choice_position == BOTTOM
  1122.         # check to make sure there is enough room below the textbox
  1123.         if (480 - self.y - self.height) < @input_number_window.height
  1124.           # not enough room below, place above
  1125.           @input_number_window.y = self.y - @input_number_window.height
  1126.         else
  1127.           # draw below
  1128.           @input_number_window.y = self.y + self.height
  1129.         end
  1130.       else # side
  1131.         if $game_system.choice_justification == LEFT
  1132.           # check to make sure there's room on the left side
  1133.           if self.y < @input_number_window.width
  1134.             # not enough room on the side, check to make sure there's room below
  1135.             if (480 - self.y - self.height) < @input_number_window.height
  1136.               # not enough room below, place above
  1137.               @input_number_window.y = self.y - @input_number_window.height
  1138.             else
  1139.               # draw below
  1140.               @input_number_window.y = self.y + self.height
  1141.             end
  1142.           else
  1143.             # place on the left side
  1144.             @input_number_window.y = self.y
  1145.             @input_number_window.x = self.x - @choice_window.width
  1146.           end
  1147.         else # right
  1148.           # check to make sure there's room on the right side
  1149.           if (680 - (self.y + self.width)) < @input_number_window.width
  1150.             # not enough room on the side, check to make sure there's room below
  1151.             if (480 - self.y - self.height) < @input_number_window.height
  1152.               # not enough room below, place above
  1153.               @input_number_window.y = self.y - @input_number_window.height
  1154.             else
  1155.               # draw below
  1156.               @input_number_window.y = self.y + self.height
  1157.             end
  1158.           else
  1159.             # place on the left side
  1160.             @input_number_window.y = self.y
  1161.             @input_number_window.x = self.x + self.width
  1162.           end
  1163.         end
  1164.       end
  1165.     end
  1166.   end
  1167.   #--------------------------------------------------------------------------
  1168.   # * Frame Update
  1169.   #--------------------------------------------------------------------------
  1170.   def update
  1171.     super
  1172.    
  1173.     if (@contents_showing and $game_system.message_event != -1 and $game_system.shake == 0) or $game_system.animated_faces
  1174.       reset_window(false)
  1175.     end
  1176.    
  1177.     if $game_system.shake != 0  # shake the window
  1178.       if @ascending
  1179.         if @target_x != self.x
  1180.           self.x += 1
  1181.         else
  1182.           @ascending = false
  1183.           @target_x = self.x - ($game_system.shake * 2)
  1184.         end
  1185.       else
  1186.         if @target_x != self.x
  1187.           self.x -= 1
  1188.         else
  1189.           @ascending = true
  1190.           @target_x = self.x + ($game_system.shake * 2)
  1191.         end
  1192.       end
  1193.     end
  1194.    
  1195.     @name_window.update
  1196.    
  1197.     if @wait > 0
  1198.       @wait -= 1
  1199.       if @wait == 0
  1200.         terminate_message
  1201.         return
  1202.       end
  1203.     end
  1204.    
  1205.     # If fade in
  1206.     if @fade_in
  1207.       if $game_temp.message_text == ""
  1208.         @fade_in = false
  1209.         return
  1210.       end
  1211.       self.contents_opacity += 24
  1212.       if $game_system.face_graphic != ""
  1213.         @face.opacity += 24
  1214.       end
  1215.       if $game_system.comic_enabled and $game_system.message_event != -1
  1216.         @comic.opacity = self.opacity
  1217.         @comic.visible = self.visible
  1218.       end
  1219.      
  1220.       if $game_system.name != ""
  1221.         @name_window.visible = true
  1222.         if $game_system.name_window
  1223.           @name_window.dummy_window.visible = true
  1224.         end
  1225.       end
  1226.       if @input_number_window != nil
  1227.         @input_number_window.contents_opacity += 24
  1228.       end
  1229.       if self.contents_opacity == 255
  1230.         @fade_in = false
  1231.       end
  1232.       return
  1233.     end
  1234.    
  1235.     # write the text
  1236.     if @text != nil and @text != ""
  1237.       speed = $game_system.write_speed
  1238.       if $game_system.text_mode == ALL_AT_ONCE or $game_temp.in_battle
  1239.         while (c = @text.slice!(/./m)) != nil
  1240.           write_char(c)
  1241.         end
  1242.         $game_system.slave_windows.each_value { |window| window.write_all }
  1243.         return
  1244.       end
  1245.       if $game_system.text_skip
  1246.         if $game_system.skip_mode == WRITE_FASTER and Input.press?(Input::C)
  1247.           # the player is holding the action button, write faster
  1248.           speed /= 3
  1249.         elsif $game_system.skip_mode == WRITE_ALL and Input.trigger?(Input::C)
  1250.           # the player pressed the action button, write all the text
  1251.           while (c = @text.slice!(/./m)) != nil
  1252.             write_char(c)
  1253.           end
  1254.           $game_system.slave_windows.each_value { |window| window.write_all }
  1255.           return
  1256.         end
  1257.       end
  1258.       while @ignore
  1259.         c = @text.slice!(/./m)
  1260.         if c != nil
  1261.           write_char(c)
  1262.         end
  1263.       end
  1264.       if @pause_time > 0
  1265.         @pause_time -= 1
  1266.         return
  1267.       end
  1268.       if Graphics.frame_count - @count >= speed
  1269.         if $game_system.sound_effect != ""
  1270.           Audio.se_play("Audio/SE/" + $game_system.sound_effect, 80, 100)
  1271.         end
  1272.         @count = Graphics.frame_count
  1273.         c = @text.slice!(/./m)
  1274.         if c != nil
  1275.           write_char(c)
  1276.         end
  1277.       end
  1278.       return
  1279.     end
  1280.    
  1281.     if $game_system.animated_faces and $game_system.resting_face != ""
  1282.       @done = true
  1283.     end
  1284.    
  1285.     # If inputting number
  1286.     if @input_number_window != nil
  1287.       @input_number_window.update
  1288.       # Confirm
  1289.       if Input.trigger?(Input::C)
  1290.         $game_system.se_play($data_system.decision_se)
  1291.         $game_variables[$game_temp.num_input_variable_id] =
  1292.           @input_number_window.number
  1293.         $game_map.need_refresh = true
  1294.         # Dispose of number input window
  1295.         @input_number_window.dispose
  1296.         @input_number_window = nil
  1297.         terminate_message
  1298.       end
  1299.       return
  1300.     end
  1301.    
  1302.     if @wait != 0
  1303.       return
  1304.     end
  1305.    
  1306.     # If message is being displayed and contents are all written
  1307.     if @contents_showing
  1308.       # if choice
  1309.       if $game_temp.choice_max > 0
  1310.         if !@choice_window.active
  1311.           @choice_window.visible = true
  1312.           @choice_window.active = true
  1313.           @choice_window.index = 0
  1314.         end
  1315.         @choice_window.update
  1316.       else
  1317.         # If choice isn't being displayed, show pause sign
  1318.         self.pause = $game_system.show_pause
  1319.       end
  1320.         # Cancel
  1321.         if Input.trigger?(Input::B)
  1322.           if $game_temp.choice_max > 0 and $game_temp.choice_cancel_type > 0
  1323.             $game_system.se_play($data_system.cancel_se)
  1324.             $game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
  1325.             terminate_message
  1326.           end
  1327.         end
  1328.         # Confirm
  1329.         if Input.trigger?(Input::C) and !(@wait > 0)
  1330.           @done = true
  1331.           $game_system.slave_windows.each_value { |window|
  1332.             window.write_all
  1333.             if !window.done
  1334.               @done = false
  1335.             end
  1336.           }
  1337.           if @done
  1338.             if $game_temp.choice_max > 0
  1339.               $game_system.se_play($data_system.decision_se)
  1340.               $game_temp.choice_proc.call(@choice_window.index)
  1341.             end
  1342.             terminate_message
  1343.           else
  1344.             @finishing_up = true
  1345.           end
  1346.         end
  1347.         return
  1348.       end
  1349.      
  1350.     if @finishing_up
  1351.       $game_system.slave_windows.each_value { |window|
  1352.         if !window.done
  1353.           @done = true
  1354.           break
  1355.         end
  1356.       }
  1357.      
  1358.       if @done = false
  1359.         terminate_message
  1360.       end
  1361.     end
  1362.     # If display wait message or choice exists when not fading out
  1363.     if @fade_out == false and $game_temp.message_text != nil
  1364.       @contents_showing = true
  1365.       $game_temp.message_window_showing = true
  1366.      
  1367.       reset_window
  1368.       refresh
  1369.       Graphics.frame_reset
  1370.       if @show
  1371.         self.visible = true
  1372.       end
  1373.       self.contents_opacity = 0
  1374.       if @input_number_window != nil
  1375.         @input_number_window.contents_opacity = 0
  1376.       end
  1377.       @fade_in = true
  1378.       return
  1379.     end
  1380.     # If message which should be displayed is not shown, but window is visible
  1381.     if self.visible
  1382.       @fade_out = true
  1383.       self.opacity -= 48
  1384.       @name_window.opacity -= 48
  1385.       @comic.opacity -= 48
  1386.       @face.opacity -= 48
  1387.       if self.opacity == 0
  1388.         self.visible = false
  1389.         @face.opacity = 0
  1390.         @choice_window.visible = false
  1391.         @choice_window.active = false
  1392.         @comic.opacity = 0
  1393.         @name_window.visible = false
  1394.         @name_window.dummy_window.visible = false
  1395.         @name_window.update
  1396.         @fade_out = false
  1397.         $game_temp.message_window_showing = false
  1398.       end
  1399.       return
  1400.     end
  1401.    
  1402.     if $game_temp.battle_calling or $game_temp.shop_calling or $game_temp.name_calling or $game_temp.menu_calling or $game_temp.save_calling or $game_temp.debug_calling
  1403.      
  1404.         $game_system.indy_windows.each_pair {|name, window|
  1405.           if window.show == true
  1406.             window.dispose
  1407.             $game_system.indy_windows.delete(name)
  1408.           end
  1409.         }
  1410.     end
  1411.   end
  1412.  
  1413.   #--------------------------------------------------------------------------
  1414.   # * Process and write the given character
  1415.   #--------------------------------------------------------------------------
  1416.   def write_char(c)
  1417.     if c == "\000"
  1418.       # Return to original text
  1419.       c = "\\"
  1420.     end
  1421.     # If \C[n]
  1422.     if c == "\001"
  1423.     # Change text color
  1424.       @text.sub!(/\[([0-9]+)\]/, "")
  1425.       color = $1.to_i
  1426.       if color >= 0 and color <= 7
  1427.         self.contents.font.color = text_color(color)
  1428.       end
  1429.       # go to next text
  1430.       return
  1431.     end
  1432.     # If \G
  1433.     if c == "\002"
  1434.       # Make gold window
  1435.       if @gold_window == nil
  1436.         @gold_window = Window_Gold.new
  1437.         @gold_window.x = 560 - @gold_window.width
  1438.         if $game_temp.in_battle
  1439.           @gold_window.y = 192
  1440.         else
  1441.           @gold_window.y = self.y >= 128 ? 32 : 384
  1442.         end
  1443.         @gold_window.opacity = self.opacity
  1444.         @gold_window.back_opacity = self.back_opacity
  1445.       end
  1446.       # go to next text
  1447.       return
  1448.     end
  1449.     # If \skip
  1450.     if c == "\003"
  1451.       # toggle text skipping
  1452.       $game_system.text_skip = !$game_system.text_skip
  1453.       # go to next text
  1454.       return
  1455.     end
  1456.     # If \b
  1457.     if c == "\004"
  1458.       # toggle bold
  1459.       self.contents.font.bold = !self.contents.font.bold
  1460.       # go to next text
  1461.       return
  1462.     end
  1463.     # If \i
  1464.     if c == "\005"
  1465.       # toggle italics
  1466.       self.contents.font.italic = !self.contents.font.italic
  1467.       # go to next text
  1468.       return
  1469.     end
  1470.     # If \s
  1471.     if c == "\006"
  1472.       # toggle shadow
  1473.       $game_system.shadowed_text = !$game_system.shadowed_text
  1474.       # go to next text
  1475.       return
  1476.     end
  1477.     # If \font
  1478.     if c == "\007"
  1479.       # change font
  1480.       @text.sub!(/\[(.*?)\]/, "")
  1481.       font = $1.to_s
  1482.       $game_system.font = font
  1483.       if font == ""
  1484.         self.contents.font.name = Font.default_name
  1485.       else
  1486.         self.contents.font.name = font
  1487.       end
  1488.       # go to next text
  1489.       return
  1490.     end
  1491.     # If \p[n]
  1492.     if c == "\010"
  1493.       @text.sub!(/\[([0-9]+)\]/, "")
  1494.       @pause_time = $1.to_i
  1495.  
  1496.       # go to next text
  1497.       return
  1498.     end
  1499.    
  1500.     # If \w[n]
  1501.     if c == "\011"
  1502.       @text.sub!(/\[([0-9]+)\]/, "")
  1503.       @wait = $1.to_i
  1504.  
  1505.       # go to next text
  1506.       return
  1507.     end
  1508.    
  1509.     # If \ws[n]
  1510.     if c == "\013"
  1511.       @text.sub!(/\[([0-9]+)\]/, "")
  1512.       $game_system.write_speed = $1.to_i
  1513.  
  1514.       # go to next text
  1515.       return
  1516.     end
  1517.     # If \oa[n]
  1518.     if c == "\014"
  1519.       @text.sub!(/\[([0-9]+)\]/, "")
  1520.       index = $1.to_i
  1521.       @text.sub!("  ", "")
  1522.       item = $data_armors[index]
  1523.       # draw the icon
  1524.       icon = RPG::Cache.icon(item.icon_name)
  1525.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  1526.       @x += 24
  1527.  
  1528.       # go to next text
  1529.       return
  1530.     end
  1531.    
  1532.     # If \oi[n]
  1533.     if c == "\015"
  1534.       @text.sub!(/\[([0-9]+)\]/, "")
  1535.       index = $1.to_i
  1536.       @text.sub!("  ", "")
  1537.       item = $data_items[index]
  1538.       # draw the icon
  1539.       icon = RPG::Cache.icon(item.icon_name)
  1540.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  1541.       @x += 24
  1542.  
  1543.       # go to next text
  1544.       return
  1545.     end
  1546.    
  1547.     # If \os[n]
  1548.     if c == "\016"
  1549.       @text.sub!(/\[([0-9]+)\]/, "")
  1550.       index = $1.to_i
  1551.       @text.sub!("  ", "")
  1552.       item = $data_skills[index]
  1553.       # draw the icon
  1554.       icon = RPG::Cache.icon(item.icon_name)
  1555.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  1556.       @x += 24
  1557.  
  1558.       # go to next text
  1559.       return
  1560.     end
  1561.    
  1562.     # If \ow[n]
  1563.     if c == "\017"
  1564.       @text.sub!(/\[([0-9]+)\]/, "")
  1565.       index = $1.to_i
  1566.       @text.sub!("  ", "")
  1567.       item = $data_weapons[index]
  1568.       # draw the icon
  1569.       icon = RPG::Cache.icon(item.icon_name)
  1570.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  1571.       @x += 24
  1572.      
  1573.       # go to next text
  1574.       return
  1575.     end
  1576.    
  1577.     # If \tc
  1578.     if c == "\020"
  1579.       # center justify
  1580.       $game_system.text_justification = CENTER
  1581.       get_x_value
  1582.       # go to next text
  1583.       return
  1584.     end
  1585.    
  1586.     # If \tl
  1587.     if c == "\021"
  1588.       # left justify
  1589.       $game_system.text_justification = LEFT
  1590.       get_x_value
  1591.       # go to next text
  1592.       return
  1593.     end
  1594.    
  1595.     # If \tr
  1596.     if c == "\022"
  1597.       # right justify
  1598.       $game_system.text_justification = RIGHT
  1599.       get_x_value
  1600.       # go to next text
  1601.       return
  1602.     end
  1603.    
  1604.     # If \ignr
  1605.     if c == "\023"
  1606.       # set ignore flage
  1607.       @ignore = true
  1608.       # go to next text
  1609.       return
  1610.     end
  1611.    
  1612.     # if \slv
  1613.     if c == "\024"
  1614.       # we need to show a slave window
  1615.       @text.sub!(/\[(.*?)\]/, "")
  1616.       name = $1.to_s
  1617.       $game_system.slave_windows[name].show = true
  1618.       return
  1619.     end
  1620.    
  1621.     # if \ind
  1622.     if c == "\025"
  1623.       # we need to show a independent window
  1624.       @text.sub!(/\[(.*?)\]/, "")
  1625.       name = $1.to_s
  1626.       if $game_system.indy_windows[name].show
  1627.         $game_system.indy_windows[name].dispose
  1628.         $game_system.indy_windows.delete(name)
  1629.       else
  1630.         $game_system.indy_windows[name].show = true
  1631.       end
  1632.       return
  1633.     end
  1634.    
  1635.     # if \c (hex color)
  1636.     if c == "\026"
  1637.       # convert hex color to RGB
  1638.       @text.sub!(/\[([0123456789abcdef]+)\]/, "")
  1639.       hex_code = $1.to_s
  1640.      
  1641.       red   = ("0x" + hex_code.slice(0..1)).hex
  1642.       blue  = ("0x" + hex_code.slice(2..3)).hex
  1643.       green = ("0x" + hex_code.slice(4..5)).hex
  1644.      
  1645.       self.contents.font.color = Color.new(red, blue, green)
  1646.       return
  1647.     end
  1648.    
  1649.     # If new line text
  1650.     if c == "\n"
  1651.       # Add 1 to y
  1652.       if !@ignore
  1653.         @y += 0
  1654.       end
  1655. #      if @text != ""
  1656. #        get_x_value
  1657. #      end
  1658.       @ignore = false
  1659.  
  1660.       # go to next text
  1661.       return
  1662.     end
  1663.     if @ignore
  1664.       return
  1665.     end
  1666.     # Draw text
  1667.     line = self.contents.text_size("j").height
  1668.     if $game_system.shadowed_text
  1669.       old_color = self.contents.font.color.clone
  1670.       self.contents.font.color = $game_system.shadow_color    
  1671.       self.contents.draw_text(6 + @x, line * @y + 2, 40, 32, c)
  1672.       self.contents.font.color = old_color
  1673.     end
  1674.     self.contents.draw_text(4 + @x, line * @y, 40, 32, c)
  1675.     # Add x to drawn text width
  1676.     @x += self.contents.text_size(c).width
  1677.   end
  1678.  
  1679.   def get_x_value
  1680.     # text justification - offset for first line
  1681.     if $game_system.text_justification == CENTER
  1682.       # get the length of the current line
  1683.       w = self.contents.text_size(@text.split("\n")[0]).width
  1684.       @x = (self.width - w - 0 - 48) / 2
  1685.     elsif $game_system.text_justification == RIGHT
  1686.       # get the length of the current line
  1687.       w = self.contents.text_size(@text.split("\n")[0]).width
  1688.       @x = self.width - w - 48
  1689.     else # left
  1690.       if $game_system.face_graphic == ""
  1691.         @x = 0
  1692.       else
  1693.         @x = @face_offset
  1694.       end
  1695.     end
  1696.   end
  1697.    
  1698. end
  1699.  
  1700. #==============================================================================
  1701. # ** Window_Choice
  1702. #------------------------------------------------------------------------------
  1703. #  This message window is used to display choices.
  1704. #==============================================================================
  1705. class Window_Choice < Window_Selectable
  1706.   def initialize (choices)
  1707.     super(0, 0, 32, choices.size * 32)
  1708.     self.visible = false
  1709.     self.active = false
  1710.     self.z = 9999
  1711.     @index = 0
  1712.     @item_max = choices.size
  1713.     @choices = choices
  1714.     self.contents = Bitmap.new(32, 32)
  1715.   end
  1716.  
  1717.   def refresh
  1718.     # determine necessary width
  1719.     width = 64
  1720.     for line in @choices
  1721.       width = [width, (self.contents.text_size(line).width + 48)].max
  1722.     end
  1723.     self.width = width
  1724.     self.height = @choices.size * 32 + 32
  1725.     self.contents = Bitmap.new(width - 32, height - 32)
  1726.     if $game_system.font_color.nil?
  1727.       self.contents.font.color = normal_color
  1728.     else
  1729.       self.contents.font.color = $game_system.font_color
  1730.     end
  1731.     if $game_system.windowskin != ""  
  1732.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin)
  1733.     else
  1734.       self.windowskin = RPG::Cache.windowskin($data_system.windowskin_name)
  1735.     end
  1736.    
  1737.     # draw choices
  1738.     y = 0
  1739.     for line in @choices
  1740.       # Draw text
  1741.       if $game_system.shadowed_text
  1742.         old_color = self.contents.font.color.clone
  1743.         self.contents.font.color = $game_system.shadow_color
  1744.         self.contents.draw_text(6, 32 * y + 2, width, 32, line)
  1745.         self.contents.font.color = old_color
  1746.       end
  1747.       self.contents.draw_text(4, y * 32, width, 32, line)
  1748.       y += 1
  1749.     end
  1750.   end
  1751.      
  1752.   def set_choices(choices)
  1753.     @choices = choices
  1754.     @item_max = @choices.size
  1755.     for choice in @choices
  1756.       choice.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  1757.       choice.gsub!(/\\[Nn]\[([0-9]+)\]/) {
  1758.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  1759.       }
  1760.     end
  1761.     refresh
  1762.   end
  1763. end
  1764.  
  1765. #==============================================================================
  1766. # ** Window_Name
  1767. #------------------------------------------------------------------------------
  1768. #  This window is used to display names above the message window.  Uncomment
  1769. #   and modify the various sections to customize.
  1770. #==============================================================================
  1771. class Window_Name < Window_Base
  1772.   attr_accessor :dummy_window
  1773.  
  1774.   def initialize
  1775.     super(0, 0, 32, 64)
  1776.     self.contents = Bitmap.new(32, 32)
  1777.     self.opacity = 0
  1778.    
  1779.     @dummy_window = Window_Dummy.new
  1780.    
  1781.     self.visible = false
  1782.   end
  1783.  
  1784.   def set_name(name)
  1785.     @name = name
  1786.     refresh
  1787.   end
  1788.  
  1789.   def refresh
  1790.     if @name == nil
  1791.       return
  1792.     end
  1793.     self.width = self.contents.text_size(@name).width + 48
  1794.     self.contents = Bitmap.new(width - 32, height - 32)
  1795.    
  1796.     if $game_system.name_window
  1797.       @dummy_window.x = self.x
  1798.       @dummy_window.y = self.y + 12
  1799.       @dummy_window.set(height - 24, width - 12)
  1800.     end
  1801.    
  1802.     # uncomment this and change the font to give the name window a fancy font
  1803.     #self.contents.font.name = "Ariel"
  1804.     self.contents.font.color = Color.new(0, 0, 0, 255)
  1805.     self.contents.draw_text(0, 0, self.width, 32, @name)
  1806.     self.contents.draw_text(0, 2, self.width, 32, @name)
  1807.     self.contents.draw_text(2, 0, self.width, 32, @name)
  1808.     self.contents.draw_text(2, 2, self.width, 32, @name)
  1809.     # change the color to give the name window a seperate color
  1810.     self.contents.font.color = normal_color
  1811.     self.contents.draw_text(1, 1, self.width, 32, @name)
  1812.   end
  1813.  
  1814.   def update
  1815.     super
  1816.     if $game_system.name_window
  1817.       @dummy_window.x = self.x
  1818.       @dummy_window.y = self.y + 12
  1819.       @dummy_window.update
  1820.     end
  1821.   end
  1822.  
  1823.   def dispose
  1824.     @dummy_window.dispose
  1825.     super
  1826.   end
  1827. end
  1828.  
  1829. class Window_Dummy < Window_Base
  1830.   def initialize
  1831.     super(0, 0, 32, 64)
  1832.     self.z = 9999
  1833.     self.visible = false
  1834.   end
  1835.  
  1836.   def set(height, width)
  1837.     self.height = height
  1838.     self.width = width
  1839.   end
  1840.  
  1841.   def update
  1842.     super
  1843.     if $game_system.windowskin != ""  
  1844.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin)
  1845.     else
  1846.       self.windowskin = RPG::Cache.windowskin($data_system.windowskin_name)
  1847.     end
  1848.   end
  1849. end
  1850.  
  1851. #==============================================================================
  1852. # ** Window_Slave
  1853. #------------------------------------------------------------------------------
  1854. #  These are slave windows to the main message window.  They will close when
  1855. #   the user terminates them.  Initial settings are identical to the main
  1856. #   message window, with one exception.  When in normal mode, it will apear
  1857. #   above if the main message is below, below if it is above or centered.  Use
  1858. #   message codes to change the settings for this window.
  1859. #==============================================================================
  1860. class Window_Slave < Window_Base
  1861.   attr_accessor :show
  1862.   attr_reader :done
  1863.  
  1864.   def write_all
  1865.     @write_all = true
  1866.   end
  1867.  
  1868.   #--------------------------------------------------------------------------
  1869.   # * Object Initialization
  1870.   #--------------------------------------------------------------------------
  1871.   def initialize (text)
  1872.     super(0, 0, 33, 33)
  1873.     @text = text
  1874.    
  1875.     # x-coordinate depends on justification
  1876.     if @justification == RIGHT
  1877.       self.x = 640 - self.width
  1878.     elsif @justification == LEFT
  1879.       self.x = 0
  1880.     else # center
  1881.       self.x = (640 - self.width) / 2
  1882.     end
  1883.     # y-coordinate depends on height
  1884.     self.y = 480 - $game_system.window_height - 16
  1885.     self.contents = Bitmap.new(width - 32, height - 32)
  1886.     self.visible = false
  1887.     self.z = 9998
  1888.     @fade_in = false
  1889.     @fade_out = false
  1890.     @contents_showing = false
  1891.    
  1892.     # face graphic sprite
  1893.     @face = Sprite.new
  1894.     @face.opacity = 0
  1895.     @face.z = self.z + 1
  1896.     @face_offset = 0
  1897.    
  1898.     # choice window
  1899.     @choice_window = Window_Choice.new([])
  1900.     @choice_window.back_opacity = $game_system.back_opacity
  1901.    
  1902.     @comic_style = $game_system.comic_style
  1903.     @name = $game_system.name
  1904.    
  1905.     # comic sprite
  1906.     @comic = Sprite.new
  1907.     @comic.opacity = 0
  1908.     @comic.z = self.z + 1
  1909.     if @comic_style == TALK1
  1910.       @comic.bitmap = RPG::Cache.windowskin("talk1")
  1911.     elsif @comic_style == TALK2
  1912.       @comic.bitmap = RPG::Cache.windowskin("talk2")
  1913.     else # thought
  1914.       @comic.bitmap = RPG::Cache.windowskin("thought")
  1915.     end
  1916.    
  1917.    
  1918.    
  1919.     @pause_time = 0
  1920.     @wait = 0
  1921.    
  1922.     @mode = $game_system.ums_mode
  1923.     self.height = $game_system.window_height
  1924.     self.width = $game_system.window_width
  1925.     @justification = $game_system.window_justification
  1926.     @face_graphic = $game_system.face_graphic
  1927.     @face_graphic_justification = $game_system.face_graphic_justification
  1928.     @message_event = $game_system.message_event
  1929.     if $game_system.message_position == 2 # down
  1930.       @message_position = 0
  1931.     else
  1932.       @message_postion = 2
  1933.     end
  1934.     @face_graphic_position = $game_system.face_graphic_position
  1935.     if $game_system.font == ""
  1936.       @font = Font.default_name
  1937.     else
  1938.       @font = $game_system.font
  1939.     end
  1940.     @text_justification = $game_system.text_justification
  1941.    
  1942.     @shake = $game_system.shake
  1943.    
  1944.     @face_frame = 0
  1945.    
  1946.     refresh
  1947.   end
  1948.   #--------------------------------------------------------------------------
  1949.   # * Dispose
  1950.   #--------------------------------------------------------------------------
  1951.   def dispose
  1952.     terminate_message
  1953.     $game_temp.message_window_showing = false
  1954.     if @input_number_window != nil
  1955.       @input_number_window.dispose
  1956.     end
  1957.     @face.dispose
  1958.     @choice_window.dispose
  1959.     @comic.dispose
  1960.     if @name_window != nil
  1961.       @name_window.dispose
  1962.     end
  1963.     super
  1964.   end
  1965.   #--------------------------------------------------------------------------
  1966.   # * Terminate Message
  1967.   #--------------------------------------------------------------------------
  1968.   def terminate_message
  1969.     self.active = false
  1970.     self.pause = false
  1971.     self.contents.clear
  1972.     # Clear showing flag
  1973.     @contents_showing = false
  1974.     # Call message callback
  1975.     if $game_temp.message_proc != nil
  1976.       $game_temp.message_proc.call
  1977.     end
  1978.     # Clear variables related to text, choices, and number input
  1979.     $game_temp.message_text = nil
  1980.     $game_temp.message_proc = nil
  1981.     $game_temp.choice_start = 99
  1982.     $game_temp.choice_max = 0
  1983.     $game_temp.choice_cancel_type = 0
  1984.     $game_temp.choice_proc = nil
  1985.     $game_temp.num_input_start = 99
  1986.     $game_temp.num_input_variable_id = 0
  1987.     $game_temp.num_input_digits_max = 0
  1988.     # Open gold window
  1989.     if @gold_window != nil
  1990.       @gold_window.dispose
  1991.       @gold_window = nil
  1992.     end
  1993.     @choice_window.visible = false
  1994.     @choice_window.active = false
  1995.     @comic.opacity = 0
  1996.   end
  1997.   #--------------------------------------------------------------------------
  1998.   # * Refresh
  1999.   #--------------------------------------------------------------------------
  2000.   def refresh
  2001.    
  2002.     self.contents.clear
  2003.     if $game_system.font_color.nil?
  2004.       self.contents.font.color = normal_color
  2005.     else
  2006.       self.contents.font.color = $game_system.font_color
  2007.     end
  2008.     if $game_system.windowskin != ""  
  2009.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin)
  2010.     else
  2011.       self.windowskin = RPG::Cache.windowskin($data_system.windowskin_name)
  2012.     end
  2013.     @x = @y = 0
  2014.  
  2015.     # If waiting for a message to be displayed
  2016.     if @text != nil
  2017.       # replace shortcuts with original code
  2018.       $game_system.shortcuts.each { |shortcut, code|
  2019.         @text.gsub!(shortcut, code)
  2020.       }
  2021.      
  2022.       # Control text processing
  2023.       begin
  2024.         last_text = @text.clone
  2025.         @text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  2026.       end until @text == last_text
  2027.       @text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  2028.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  2029.       end
  2030.      
  2031.       # window mode
  2032.       if @text.index(/\\[Mm]/) != nil
  2033.         if $game_system.ums_mode == NORMAL_MODE
  2034.           @mode = FIT_WINDOW_TO_TEXT
  2035.         else
  2036.           @mode = NORMAL_MODE
  2037.         end
  2038.         @text.gsub!(/\\[Mm]/) { "" }
  2039.       end
  2040.      
  2041.       # window height
  2042.       @text.gsub!(/\\[Hh][Ee][Ii][Gg][Hh][Tt]\[([0-9]+)\]/) do
  2043.         self.height = $1.to_i
  2044.         ""
  2045.       end
  2046.      
  2047.       # window width
  2048.       @text.gsub!(/\\[Ww][Ii][Dd][Tt][Hh]\[([0-9]+)\]/) do
  2049.         self.width = $1.to_i
  2050.         ""
  2051.       end
  2052.      
  2053.       # justification
  2054.       @text.gsub!(/\\[Jj][Rr]/) do
  2055.         @justification = RIGHT
  2056.         reset_window
  2057.         ""
  2058.       end
  2059.       @text.gsub!(/\\[Jj][Cc]/) do
  2060.         @justification = CENTER
  2061.         reset_window
  2062.         ""
  2063.       end      
  2064.       @text.gsub!(/\\[Jj][Ll]/) do
  2065.         @justification = LEFT
  2066.         reset_window
  2067.         ""
  2068.       end
  2069.      
  2070.       # face graphics
  2071.       @text.gsub!(/\\[Ff][Aa][Cc][Ee]\[(.*?)\]/) do
  2072.         @face_graphic = $1.to_s
  2073.         if $1.to_s == ""
  2074.           @face.opacity = 0
  2075.         end
  2076.         ""
  2077.       end
  2078.       @text.gsub!(/\\[Ff][Ll]/) do
  2079.         @face_graphic_justification = LEFT
  2080.         ""
  2081.       end
  2082.       @text.gsub!(/\\[Ff][Rr]/) do
  2083.         @face_graphic_justification = RIGHT
  2084.         ""
  2085.       end
  2086.      
  2087.       # event centering
  2088.       @text.gsub!(/\\[Ee]\[([0-9]+)\]/) do
  2089.         @message_event = $1.to_i
  2090.         ""
  2091.       end
  2092.      
  2093.       # comic thingy
  2094.       @text.gsub!(/\\[Tt]1/) do
  2095.         @comic_style = TALK1
  2096.         @comic.bitmap = RPG::Cache.windowskin("talk1.png")
  2097.         ""
  2098.       end
  2099.       @text.gsub!(/\\[Tt]2/) do
  2100.         @comic_style = TALK2
  2101.         @comic.bitmap = RPG::Cache.windowskin("talk2.png")
  2102.         ""
  2103.       end
  2104.       @text.gsub!(/\\[Tt][Hh]/) do
  2105.         @comic_style = THOUGHT
  2106.         @comic.bitmap = RPG::Cache.windowskin("thought.png")
  2107.         ""
  2108.       end
  2109.      
  2110.       # name window
  2111.       @text.gsub!(/\\[Nn][Mm]\[(.*?)\]/) do
  2112.         @name = $1.to_s
  2113.         if $1.to_s == "" and @name_window != nil
  2114.           @name_window.visible = false
  2115.         end
  2116.         ""
  2117.       end
  2118.       if @name != ""
  2119.         # name window
  2120.         @name_window = Window_Name.new
  2121.         @name_window.z = self.z + 1
  2122.         @name_window.set_name(@name)
  2123.       end
  2124.      
  2125.       # shaking
  2126.       @text.gsub!(/\\[Ss][Hh][Kk]\[([0-9]+)\]/) do
  2127.         @shake = $1.to_i
  2128.         ""
  2129.       end
  2130.      
  2131.       # back opacity
  2132.       @text.gsub!(/\\[Bb][Oo][Pp][Cc]\[([0-9]+)\]/) do
  2133.         self.back_opacity = $1.to_i
  2134.         ""
  2135.       end
  2136.      
  2137.       # opacity
  2138.       @text.gsub!(/\\[Oo][Pp][Cc]\[([0-9]+)\]/) do
  2139.         self.opacity = $1.to_i
  2140.         ""
  2141.       end
  2142.      
  2143.       # Change "\\\\" to "\000" for convenience
  2144.       @text.gsub!(/\\\\/) { "\000" }
  2145.       # Change "\\C" to "\001" and "\\G" to "\002"
  2146.       @text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  2147.       @text.gsub!(/\\[Gg]/) { "\002" }
  2148.       @text.gsub!(/\\[Cc]\[0x([0123456789abcdef]+)\]/) { "\026[#{$1}]" }
  2149.      
  2150.       # text skip code
  2151.       @text.gsub!(/\\[Ss][Kk][Ii][Pp]/) { "\003" }
  2152.      
  2153.       # ignore code
  2154.       @text.gsub!(/\\[Ii][Gg][Nn][Rr]/) { "\023" }
  2155.      
  2156.       # bold and italics
  2157.       @text.gsub!(/\\[Bb]/) { "\004" }
  2158.       @text.gsub!(/\\[Ii]/) { "\005" }
  2159.      
  2160.       # shadow
  2161.       @text.gsub!(/\\[Ss]/) { "\006" }
  2162.      
  2163.       # font
  2164.       @text.gsub!(/\\[Ff][Oo][Nn][Tt]\[(.*?)\]/) { "\007[#{$1}]" }
  2165.      
  2166.       # pause and wait
  2167.       @text.gsub!(/\\[Pp]\[([0-9]+)\]/) { "\010[#{$1}]" }
  2168.       @text.gsub!(/\\[Ww]\[([0-9]+)\]/) { "\011[#{$1}]" }
  2169.      
  2170.       # write speed
  2171.       @text.gsub!(/\\[Ww][Ss]\[([0-9]+)\]/) { "\013[#{$1}]" }
  2172.            
  2173.       # armor, items, skills, and weapons
  2174.       @text.gsub!(/\\[Oo][Aa]\[([0-9]+)\]/) {
  2175.         item = $data_armors[$1.to_i]
  2176.         "\014[#{$1}]" + "  " + item.name
  2177.       }
  2178.       @text.gsub!(/\\[Oo][Ii]\[([0-9]+)\]/) {
  2179.         item = $data_items[$1.to_i]
  2180.         "\015[#{$1}]" + "  " + item.name
  2181.       }
  2182.       @text.gsub!(/\\[Oo][Ss]\[([0-9]+)\]/) {
  2183.         item = $data_skills[$1.to_i]
  2184.         "\016[#{$1}]" + "  " + item.name
  2185.       }
  2186.       @text.gsub!(/\\[Oo][Ww]\[([0-9]+)\]/) {
  2187.         item = $data_weapons[$1.to_i]
  2188.         "\017[#{$1}]" + "  " + item.name
  2189.       }
  2190.      
  2191.       # text justification
  2192.       @text.gsub!(/\\[Tt][Cc]/) { "\020" }
  2193.       @text.gsub!(/\\[Tt][Ll]/) { "\021" }
  2194.       @text.gsub!(/\\[Tt][Rr]/) { "\022" }
  2195.      
  2196.       # Resize the window to fit the contents?
  2197.       if @mode == FIT_WINDOW_TO_TEXT
  2198.         width = 1
  2199.         text = @text.split("\n")
  2200.         height = 0
  2201.         i = 0
  2202.         for line in text
  2203.           # don't count this line's width if it has the ignr code
  2204.           if !line.include?("\023")
  2205.             width = [width, self.contents.text_size(line).width].max
  2206.             delta = self.contents.text_size(line).height
  2207.             height += delta + (6 * i) + 3
  2208.             if i < 3
  2209.               i += 1
  2210.             end
  2211.           end
  2212.         end
  2213.        
  2214.         if @face_graphic != "" and ($game_system.face_graphic_position == CENTER or $game_system.face_graphic_position == BOTTOM)
  2215.           width += @face.bitmap.width
  2216.           if height < @face.bitmap.height
  2217.             height = @face.bitmap.height - 32
  2218.           end
  2219.         end
  2220.        
  2221.         if height == 0
  2222.           height = 1
  2223.         end
  2224.          
  2225.         self.width = width + 48
  2226.         self.height = height + 48
  2227.         self.contents = Bitmap.new(width + 16, height)
  2228.         if $game_system.font_color.nil?
  2229.           self.contents.font.color = normal_color
  2230.         else
  2231.           self.contents.font.color = $game_system.font_color
  2232.         end
  2233.  
  2234.       else
  2235.         if self.width != $game_system.window_height or self.height != $game_system.window_width
  2236.           self.width = $game_system.window_width
  2237.           self.height = $game_system.window_height
  2238.           self.contents = Bitmap.new(self.width - 32, self.height - 32)
  2239.           if $game_system.font_color.nil?
  2240.             self.contents.font.color = normal_color
  2241.           else
  2242.             self.contents.font.color = $game_system.font_color
  2243.           end
  2244.         end
  2245.       end
  2246.      
  2247.       reset_window
  2248.      
  2249.       get_x_value
  2250.      
  2251.       @count = Graphics.frame_count
  2252.       @pause_time = 0
  2253.       @ignore = false
  2254.       @done = false
  2255.       @face_frame = 0
  2256.     end
  2257.    
  2258.    
  2259.    
  2260.     # If number input
  2261.     if $game_temp.num_input_variable_id > 0
  2262.       digits_max = $game_temp.num_input_digits_max
  2263.       number = $game_variables[$game_temp.num_input_variable_id]
  2264.       @input_number_window = Window_InputNumber.new(digits_max)
  2265.       @input_number_window.number = number
  2266.       @input_number_window.x = self.x + 8
  2267.       @input_number_window.y = self.y + $game_temp.num_input_start * 32
  2268.     end
  2269.   end
  2270.   #--------------------------------------------------------------------------
  2271.   # * Set Window Position and Opacity Level
  2272.   #--------------------------------------------------------------------------
  2273.   def reset_window (change_opacity = true)
  2274.     # x-coordinate depends on justification
  2275.     if @message_event == -1
  2276.       if @justification == RIGHT
  2277.         self.x = 640 - self.width
  2278.       elsif @justification == LEFT
  2279.         self.x = 0
  2280.       else # center
  2281.         self.x = (640 - self.width) / 2
  2282.       end
  2283.     else
  2284.       if @message_event == 0 or $game_map.events[@message_event] == nil
  2285.         # center on player
  2286.         event_x = $game_player.screen_x
  2287.       else
  2288.         # center on the event specified
  2289.         event_x = $game_map.events[@message_event].screen_x
  2290.       end
  2291.       self.x = event_x - self.width / 2
  2292.       @comic.x = self.x + (self.width / 2) + 4
  2293.     end
  2294.    
  2295.     if $game_temp.in_battle
  2296.       self.y = 16
  2297.     else
  2298.       if @message_event == -1
  2299.         case @message_position
  2300.           when 0  # up
  2301.             self.y = 16
  2302.           when 1  # middle
  2303.             self.y = (480 - self.height) / 2
  2304.           when 2  # down
  2305.             self.y = 480 - self.height - 24
  2306.         end
  2307.       else
  2308.         if @message_event == 0 or $game_map.events[@message_event] == nil
  2309.           # above player
  2310.           self.y = $game_player.screen_y - self.height - 48
  2311.         else
  2312.           # above event specified
  2313.           self.y = $game_map.events[@message_event].screen_y - self.height - 48
  2314.         end
  2315.         @comic.y = self.y + self.height - 2
  2316.       end
  2317.     end
  2318.     if self.y < 0 + (@name == "" ? 0 : 16)
  2319.       self.y = 0 + (@name == "" ? 0 : 16)
  2320.     elsif self.y > 480 - self.height
  2321.       self.y = 480 - self.height
  2322.     end
  2323.     if self.x < 0
  2324.       self.x = 0
  2325.     elsif self.x > 680 - self.width - 48
  2326.       self.x = 640 - self.width
  2327.     end
  2328.    
  2329.     if change_opacity
  2330.       if $game_system.message_frame == 0
  2331.         self.opacity = 255
  2332.       else
  2333.         self.opacity = 0
  2334.       end
  2335.       self.back_opacity = $game_system.back_opacity
  2336.     end
  2337.    
  2338.     # face stuff
  2339.       if @face_graphic != ""  
  2340.         # the player has chosen to show a face graphic
  2341.         if @done and $game_system.resting_face != ""
  2342.           @face.bitmap = RPG::Cache.picture(@face_graphic + $game_system.resting_face)
  2343.           if @face_frame * $game_system.face_frame_width >= @face.bitmap.width
  2344.             @face_frame = 0
  2345.           end
  2346.         else
  2347.           @face.bitmap = RPG::Cache.picture(@face_graphic)
  2348.         end
  2349.        
  2350.         # picture y-coordinate
  2351.         if @face_graphic_position == ABOVE
  2352.           @face.y = self.y - @face.bitmap.height
  2353.           @face_offset = 0
  2354.         elsif @face_graphic_position == CENTER
  2355.           delta = (@face.bitmap.height - self.height) / 2
  2356.           @face.y = self.y - delta
  2357.           if $game_system.animated_faces
  2358.             @face_offset = $game_system.face_frame_width + 16
  2359.           else
  2360.             @face_offset = @face.bitmap.width + 16
  2361.           end
  2362.         elsif @face_graphic_position == BOTTOM
  2363.           @face.y = self.y + self.height - @face.bitmap.height
  2364.           if $game_system.animated_faces
  2365.             @face_offset = $game_system.face_frame_width + 16
  2366.           else
  2367.             @face_offset = @face.bitmap.width + 16
  2368.           end
  2369.         else # side
  2370.           delta = (@face.bitmap.height - self.height) / 2
  2371.           @face.y = self.y - delta
  2372.           @face_offset = 0
  2373.         end
  2374.        
  2375.         # picture x-coordinate
  2376.         if @face_graphic_justification == LEFT
  2377.           if @face_graphic_position == SIDE
  2378.             @face.x = self.x - @face.bitmap.width
  2379.           else
  2380.             @face.x = self.x + 10
  2381.           end
  2382.         else
  2383.           if $game_system.animated_faces
  2384.             offset = @face.bitmap.width - $game_system.face_frame_width
  2385.           else
  2386.             offset = 0
  2387.           end
  2388.           if @face_graphic_position == SIDE
  2389.             @face.x = self.x + self.width + offset
  2390.           else
  2391.             @face.x = self.x + self.width - @face.bitmap.width - 10 + offset
  2392.             @face_offset = 0
  2393.           end
  2394.         end
  2395.        
  2396.         if $game_system.animated_faces
  2397.           @face.src_rect = Rect.new(@face_frame * $game_system.face_frame_width, 0, $game_system.face_frame_width, @face.bitmap.height)
  2398.           if @done and $game_system.resting_face != ""
  2399.             pause = $game_system.resting_animation_pause
  2400.           else
  2401.             pause = $game_system.animation_pause
  2402.           end
  2403.           if Graphics.frame_count % pause == 0
  2404.             @animate_face = true
  2405.           end
  2406.           if @animate_face
  2407.             if Graphics.frame_count % 3 == 0
  2408.               @face_frame += 1
  2409.               if @face_frame * $game_system.face_frame_width >= @face.bitmap.width
  2410.                 @face_frame = 0
  2411.                 @animate_face = false
  2412.               end
  2413.             end
  2414.           end
  2415.         end
  2416.       end
  2417.      
  2418.       # name window
  2419.       if @name != "" and @name != nil
  2420.         @name_window.set_name(@name)
  2421.         @name_window.x = self.x
  2422.         @name_window.y = self.y - 36
  2423.       end
  2424.      
  2425.       # If choice
  2426.     if $game_temp.choice_max > 0
  2427.       @choice_window.set_choices($game_temp.choices)
  2428.       # determine x and y coords for choice window
  2429.       if $game_system.choice_justification == LEFT
  2430.         @choice_window.x = self.x
  2431.       else
  2432.         @choice_window.x = self.x + self.width - @choice_window.width
  2433.       end
  2434.       if $game_system.choice_position == ABOVE
  2435.         # check to make sure there is enough room above the textbox
  2436.         if self.y < @choice_window.height
  2437.           # not enough room above, place below
  2438.           @choice_window.y = self.y + self.height
  2439.         else
  2440.           # draw above
  2441.           @choice_window.y = self.y - @choice_window.height
  2442.         end
  2443.       elsif $game_system.choice_position == BOTTOM
  2444.         # check to make sure there is enough room below the textbox
  2445.         if (480 - self.y - self.height) < @choice_window.height
  2446.           # not enough room below, place above
  2447.           @choice_window.y = self.y - @choice_window.height
  2448.         else
  2449.           # draw below
  2450.           @choice_window.y = self.y + self.height
  2451.         end
  2452.       else # side
  2453.         if $game_system.choice_justification == LEFT
  2454.           # check to make sure there's room on the left side
  2455.           if self.y < @choice_window.width
  2456.             # not enough room on the side, check to make sure there's room below
  2457.             if (480 - self.y - self.height) < @choice_window.height
  2458.               # not enough room below, place above
  2459.               @choice_window.y = self.y - @choice_window.height
  2460.             else
  2461.               # draw below
  2462.               @choice_window.y = self.y + self.height
  2463.             end
  2464.           else
  2465.             # place on the left side
  2466.             @choice_window.y = self.y
  2467.             @choice_window.x = self.x - @choice_window.width
  2468.           end
  2469.         else # right
  2470.           # check to make sure there's room on the right side
  2471.           if (680 - (self.y + self.width)) < @choice_window.width
  2472.             # not enough room on the side, check to make sure there's room below
  2473.             if (480 - self.y - self.height) < @choice_window.height
  2474.               # not enough room below, place above
  2475.               @choice_window.y = self.y - @choice_window.height
  2476.             else
  2477.               # draw below
  2478.               @choice_window.y = self.y + self.height
  2479.             end
  2480.           else
  2481.             # place on the left side
  2482.             @choice_window.y = self.y
  2483.             @choice_window.x = self.x + self.width
  2484.           end
  2485.         end
  2486.       end
  2487.     end
  2488.   end
  2489.   #--------------------------------------------------------------------------
  2490.   # * Frame Update
  2491.   #--------------------------------------------------------------------------
  2492.   def update
  2493.     super
  2494.    
  2495.     if !@show
  2496.       return
  2497.     else
  2498.       self.visible = true
  2499.       if @face_graphic != ""
  2500.         @face.opacity = 255
  2501.       end
  2502.       if $game_system.comic_enabled and @message_event != -1
  2503.         @comic.opacity = 255
  2504.       end
  2505.       if @name != ""
  2506.         @name_window.visible = true
  2507.       end
  2508.       if @input_number_window != nil
  2509.         @input_number_window.contents_opacity = 255
  2510.       end
  2511.       reset_window
  2512.     end
  2513.    
  2514.    
  2515.     if (@contents_showing and $game_system.message_event != -1 and @shake == 0) or $game_system.animated_faces
  2516.       reset_window(false)
  2517.     end
  2518.    
  2519.     if $game_system.shake != 0  # shake the window
  2520.       if @ascending
  2521.         if @target_x != self.x
  2522.           self.x += 1
  2523.         else
  2524.           @ascending = false
  2525.           @target_x = self.x - ($game_system.shake * 2)
  2526.         end
  2527.       else
  2528.         if @target_x != self.x
  2529.           self.x -= 1
  2530.         else
  2531.           @ascending = true
  2532.           @target_x = self.x + ($game_system.shake * 2)
  2533.         end
  2534.       end
  2535.     end
  2536.    
  2537.     if @wait > 0
  2538.       @wait -= 1
  2539.       if @wait == 0
  2540.         terminate_message
  2541.         return
  2542.       end
  2543.     end
  2544.    
  2545.     # If fade in
  2546.     if @fade_in
  2547.       self.contents_opacity += 24
  2548.       if @face_graphic != ""
  2549.         @face.opacity += 24
  2550.       end
  2551.       if $game_system.comic_enabled and @message_event != -1
  2552.         @comic.opacity += 24
  2553.       end
  2554.       if @name != ""
  2555.         @name_window.visible = true
  2556.       end
  2557.       if @input_number_window != nil
  2558.         @input_number_window.contents_opacity += 24
  2559.       end
  2560.       if self.contents_opacity == 255
  2561.         @fade_in = false
  2562.       end
  2563.       return
  2564.     end
  2565.    
  2566.     # write the text
  2567.     if @text != nil and @text != ""
  2568.       speed = $game_system.write_speed
  2569.       if $game_system.text_skip
  2570.         if $game_system.skip_mode == WRITE_FASTER and Input.press?(Input::C)
  2571.           # the player is holding the action button, write faster
  2572.           speed /= 3
  2573.         elsif $game_system.skip_mode == WRITE_ALL and @write_all
  2574.           # the player pressed the action button, write all the text
  2575.           while (c = @text.slice!(/./m)) != nil
  2576.             write_char(c)
  2577.           end
  2578.           return
  2579.         end
  2580.       end
  2581.       while @ignore
  2582.         c = @text.slice!(/./m)
  2583.         if c != nil
  2584.           write_char(c)
  2585.         end
  2586.       end
  2587.       if @pause_time > 0
  2588.         @pause_time -= 1
  2589.         return
  2590.       end
  2591.       if Graphics.frame_count - @count >= speed
  2592.         if $game_system.sound_effect != ""
  2593.           Audio.se_play("Audio/SE/" + $game_system.sound_effect, 80, 100)
  2594.         end
  2595.         @count = Graphics.frame_count
  2596.         c = @text.slice!(/./m)
  2597.         if c != nil
  2598.           write_char(c)
  2599.         end
  2600.       end
  2601.       return
  2602.     end
  2603.    
  2604.     @done = true
  2605.    
  2606.     # If inputting number
  2607.     if @input_number_window != nil
  2608.       @input_number_window.update
  2609.       # Confirm
  2610.       if Input.trigger?(Input::C)
  2611.         $game_system.se_play($data_system.decision_se)
  2612.         $game_variables[$game_temp.num_input_variable_id] =
  2613.           @input_number_window.number
  2614.         $game_map.need_refresh = true
  2615.         # Dispose of number input window
  2616.         @input_number_window.dispose
  2617.         @input_number_window = nil
  2618.         terminate_message
  2619.       end
  2620.       return
  2621.     end
  2622.    
  2623.     if @wait != 0
  2624.       return
  2625.     end
  2626.    
  2627.     # If message is being displayed and contents are all written
  2628.     if @contents_showing
  2629.       # if choice
  2630.       if $game_temp.choice_max > 0
  2631.         if !@choice_window.active
  2632.           @choice_window.visible = true
  2633.           @choice_window.active = true
  2634.           @choice_window.index = 0
  2635.         end
  2636.         @choice_window.update
  2637.       else
  2638.         # If choice isn't being displayed, show pause sign
  2639.         self.pause = true
  2640.       end
  2641.       return
  2642.     end
  2643.   end
  2644.  
  2645.   #--------------------------------------------------------------------------
  2646.   # * Process and write the given character
  2647.   #--------------------------------------------------------------------------
  2648.   def write_char(c)
  2649.     if c == "\000"
  2650.       # Return to original text
  2651.       c = "\\"
  2652.     end
  2653.     # If \C[n]
  2654.     if c == "\001"
  2655.     # Change text color
  2656.       @text.sub!(/\[([0-9]+)\]/, "")
  2657.       color = $1.to_i
  2658.       if color >= 0 and color <= 7
  2659.         self.contents.font.color = text_color(color)
  2660.       end
  2661.       # go to next text
  2662.       return
  2663.     end
  2664.     # If \G
  2665.     if c == "\002"
  2666.       # Make gold window
  2667.       if @gold_window == nil
  2668.         @gold_window = Window_Gold.new
  2669.         @gold_window.x = 560 - @gold_window.width
  2670.         if $game_temp.in_battle
  2671.           @gold_window.y = 192
  2672.         else
  2673.           @gold_window.y = self.y >= 128 ? 32 : 384
  2674.         end
  2675.         @gold_window.opacity = self.opacity
  2676.         @gold_window.back_opacity = self.back_opacity
  2677.       end
  2678.       # go to next text
  2679.       return
  2680.     end
  2681.     # If \skip
  2682.     if c == "\003"
  2683.       # toggle text skipping
  2684.       #$game_system.text_skip = !$game_system.text_skip
  2685.       # go to next text
  2686.       return
  2687.     end
  2688.     # If \b
  2689.     if c == "\004"
  2690.       # toggle bold
  2691.       self.contents.font.bold = !self.contents.font.bold
  2692.       # go to next text
  2693.       return
  2694.     end
  2695.     # If \i
  2696.     if c == "\005"
  2697.       # toggle italics
  2698.       self.contents.font.italic = !self.contents.font.italic
  2699.       # go to next text
  2700.       return
  2701.     end
  2702.     # If \s
  2703.     if c == "\006"
  2704.       # toggle shadow
  2705.       #$game_system.shadowed_text = !$game_system.shadowed_text
  2706.       # go to next text
  2707.       return
  2708.     end
  2709.     # If \font
  2710.     if c == "\007"
  2711.       # change font
  2712.       @text.sub!(/\[(.*?)\]/, "")
  2713.       font = $1.to_s
  2714.       @font = font
  2715.       if font == ""
  2716.         self.contents.font.name = Font.default_name
  2717.       else
  2718.         self.contents.font.name = font
  2719.       end
  2720.       # go to next text
  2721.       return
  2722.     end
  2723.     # If \p[n]
  2724.     if c == "\010"
  2725.       @text.sub!(/\[([0-9]+)\]/, "")
  2726.       @pause_time = $1.to_i
  2727.  
  2728.       # go to next text
  2729.       return
  2730.     end
  2731.    
  2732.     # If \w[n]
  2733.     if c == "\011"
  2734.       @text.sub!(/\[([0-9]+)\]/, "")
  2735.       @wait = $1.to_i
  2736.  
  2737.       # go to next text
  2738.       return
  2739.     end
  2740.    
  2741.     # If \ws[n]
  2742.     if c == "\013"
  2743.       @text.sub!(/\[([0-9]+)\]/, "")
  2744.       $game_system.write_speed = $1.to_i
  2745.  
  2746.       # go to next text
  2747.       return
  2748.     end
  2749.     # If \oa[n]
  2750.     if c == "\014"
  2751.       @text.sub!(/\[([0-9]+)\]/, "")
  2752.       index = $1.to_i
  2753.       @text.sub!("  ", "")
  2754.       item = $data_armors[index]
  2755.       # draw the icon
  2756.       icon = RPG::Cache.icon(item.icon_name)
  2757.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  2758.       @x += 24
  2759.  
  2760.       # go to next text
  2761.       return
  2762.     end
  2763.    
  2764.     # If \oi[n]
  2765.     if c == "\015"
  2766.       @text.sub!(/\[([0-9]+)\]/, "")
  2767.       index = $1.to_i
  2768.       @text.sub!("  ", "")
  2769.       item = $data_items[index]
  2770.       # draw the icon
  2771.       icon = RPG::Cache.icon(item.icon_name)
  2772.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  2773.       @x += 24
  2774.  
  2775.       # go to next text
  2776.       return
  2777.     end
  2778.    
  2779.     # If \os[n]
  2780.     if c == "\016"
  2781.       @text.sub!(/\[([0-9]+)\]/, "")
  2782.       index = $1.to_i
  2783.       @text.sub!("  ", "")
  2784.       item = $data_skills[index]
  2785.       # draw the icon
  2786.       icon = RPG::Cache.icon(item.icon_name)
  2787.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  2788.       @x += 24
  2789.  
  2790.       # go to next text
  2791.       return
  2792.     end
  2793.    
  2794.     # If \ow[n]
  2795.     if c == "\017"
  2796.       @text.sub!(/\[([0-9]+)\]/, "")
  2797.       index = $1.to_i
  2798.       @text.sub!("  ", "")
  2799.       item = $data_weapons[index]
  2800.       # draw the icon
  2801.       icon = RPG::Cache.icon(item.icon_name)
  2802.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  2803.       @x += 24
  2804.      
  2805.       # go to next text
  2806.       return
  2807.     end
  2808.    
  2809.     # If \tc
  2810.     if c == "\020"
  2811.       # center justify
  2812.       @text_justification = CENTER
  2813.       get_x_value
  2814.       # go to next text
  2815.       return
  2816.     end
  2817.    
  2818.     # If \tl
  2819.     if c == "\021"
  2820.       # left justify
  2821.       @text_justification = LEFT
  2822.       get_x_value
  2823.       # go to next text
  2824.       return
  2825.     end
  2826.    
  2827.     # If \tr
  2828.     if c == "\022"
  2829.       # right justify
  2830.       @text_justification = RIGHT
  2831.       get_x_value
  2832.       # go to next text
  2833.       return
  2834.     end
  2835.    
  2836.     # If \ignr
  2837.     if c == "\023"
  2838.       # set ignore flage
  2839.       @ignore = true
  2840.       # go to next text
  2841.       return
  2842.     end
  2843.    
  2844.     # if \c (hex color)
  2845.     if c == "\026"
  2846.       # convert hex color to RGB
  2847.       @text.sub!(/\[([0123456789abcdef]+)\]/, "")
  2848.       hex_code = $1.to_s
  2849.      
  2850.       red   = ("0x" + hex_code.slice(0..1)).hex
  2851.       blue  = ("0x" + hex_code.slice(2..3)).hex
  2852.       green = ("0x" + hex_code.slice(4..5)).hex
  2853.      
  2854.       self.contents.font.color = Color.new(red, blue, green)
  2855.       return
  2856.     end
  2857.    
  2858.     # If new line text
  2859.     if c == "\n"
  2860.       # Add 1 to y
  2861.       if !@ignore
  2862.         @y += 0
  2863.       end
  2864. #      if @text != ""
  2865. #        get_x_value
  2866. #      end
  2867.       @ignore = false
  2868.  
  2869.       # go to next text
  2870.       return
  2871.     end
  2872.     if @ignore
  2873.       return
  2874.     end
  2875.     # Draw text
  2876.     line = self.contents.text_size("dj").height
  2877.     if $game_system.shadowed_text
  2878.       old_color = self.contents.font.color.clone
  2879.       self.contents.font.color = $game_system.shadow_color
  2880.       self.contents.draw_text(6 + @x, line * @y + 2, 40, 32, c)
  2881.       self.contents.font.color = old_color
  2882.     end
  2883.     self.contents.draw_text(4 + @x, line * @y, 40, 32, c)
  2884.     # Add x to drawn text width
  2885.     @x += self.contents.text_size(c).width
  2886.   end
  2887.  
  2888.   def get_x_value
  2889.     # text justification - offset for first line
  2890.     if @text_justification == CENTER
  2891.       # get the length of the current line
  2892.       w = self.contents.text_size(@text.split("\n")[0]).width
  2893.       @x = (self.width - w - 0 - 48) / 2
  2894.     elsif @text_justification == RIGHT
  2895.       # get the length of the current line
  2896.       w = self.contents.text_size(@text.split("\n")[0]).width
  2897.       @x = self.width - w - 48
  2898.     else # left
  2899.       if @face_graphic == ""
  2900.         @x = 0
  2901.       else
  2902.         @x = @face_offset
  2903.       end
  2904.     end
  2905.   end
  2906. end
  2907.  
  2908. #==============================================================================
  2909. # ** Window_InputNumber
  2910. #------------------------------------------------------------------------------
  2911. #  This window is for inputting numbers, and is used within the
  2912. #  message window.
  2913. #==============================================================================
  2914.  
  2915. class Window_InputNumber < Window_Base
  2916.   #--------------------------------------------------------------------------
  2917.   # * Object Initialization
  2918.   #     digits_max : digit count
  2919.   #--------------------------------------------------------------------------
  2920.   def initialize(digits_max)
  2921.     @digits_max = digits_max
  2922.     @number = 0
  2923.     # Calculate cursor width from number width (0-9 equal width and postulate)
  2924.     dummy_bitmap = Bitmap.new(32, 32)
  2925.     @cursor_width = dummy_bitmap.text_size("0").width + 8
  2926.     dummy_bitmap.dispose
  2927.     super(0, 0, @cursor_width * @digits_max + 32, 64)
  2928.     self.contents = Bitmap.new(width - 32, height - 32)
  2929.     self.z += 9999
  2930.     self.opacity = $game_system.opacity
  2931.     self.back_opacity = $game_system.back_opacity
  2932.     @index = 0
  2933.     refresh
  2934.     update_cursor_rect
  2935.   end
  2936.  
  2937.   #--------------------------------------------------------------------------
  2938.   # * Refresh
  2939.   #--------------------------------------------------------------------------
  2940.   def refresh
  2941.     self.contents.clear
  2942.     if $game_system.font_color.nil?
  2943.       self.contents.font.color = normal_color
  2944.     else
  2945.       self.contents.font.color = $game_system.font_color
  2946.     end
  2947.     if $game_system.windowskin != ""  
  2948.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin)
  2949.     else
  2950.       self.windowskin = RPG::Cache.windowskin($data_system.windowskin_name)
  2951.     end
  2952.     s = sprintf("%0*d", @digits_max, @number)
  2953.     for i in 0...@digits_max
  2954.       # Draw text
  2955.       if $game_system.shadowed_text
  2956.         old_color = self.contents.font.color.clone
  2957.         self.contents.font.color = $game_system.shadow_color
  2958.         self.contents.draw_text(i * @cursor_width + 6, 2, 32, 32, s[i,1])
  2959.         self.contents.font.color = old_color
  2960.       end
  2961.       self.contents.draw_text(i * @cursor_width + 4, 0, 32, 32, s[i,1])
  2962.     end
  2963.   end
  2964. end
Expand to see the code.


Thanks in advance again.
Bump, really need help plz...
You could pre-process the line of text to remove the newlines. Looks like the centering code happens before the newline replacement.
As far as I'm aware, raw message data consists of a generic string, seperated with special \n characters. Splitting the string via aString.split!('\n') should give you an array which contents you can draw with align=1 to get each line centered. As a neat side effect, you could easily determine the height of your message window by checking for your anArray.size
Right... you lost me there sry. I'm a fairly novice scripter. I have no idea what you mean by that.
Well, what I meant is that the raw data (data output that's saved when you use the Message event command to input text to be displayed) should be saved in a format that's simply like this:
  1. "this is the first line\nsecond line\nthis would be the third line, regardless if it's getting\ncut off because of the window size"
Expand to see the code.
In other words, you get a perfect string, ready to be split.
Let's say that string is saved in the variable @message_string (I never worked with the message system really, so I dunno how it actually is saved... but it should be easy to figure out), then just split it like so:
  1. @message_array = @message_string.split("\n")
Expand to see the code.

This will get you the following array to work with:
  1. p @message_string # => ["this is the first line", "second line", "this would be the third line, regardless if it's getting", "cut off because of the window size"]
Expand to see the code.

Now what you do to display them below each other is this:
  1. for i in 0...@message_array.size
  2.   self.contents.draw_text(4, 32 * i, self.width-40, 32, @message_array[i], 1)
  3. end
Expand to see the code.

As this is script support, I let you figure out the meaning of all this yourself (ask if you need elaborations), however, I'm gonna tell you that the 1 at the very end is the align flag, which aligns your text left if you put 0 (or don't put anything), centers it if you put 1 or aligns it right if you put 2.

BY the way, all of this should go directly above the default draw_text methods, if I'm not mistaken...
If this was the default message (not ccoa ums):
  1. class Window_Message < Window_Selectable
  2. def refresh
  3.     self.contents.clear
  4.     self.contents.font.color = normal_color
  5.     x = y = 0
  6.     @cursor_width = 0
  7.     # Indent if choice
  8.     if $game_temp.choice_start == 0
  9.       x = 8
  10.     end
  11.     # If waiting for a message to be displayed
  12.     if $game_temp.message_text != nil
  13.       text = $game_temp.message_text
  14.       # ----------------- edit ---------------------------------#
  15.        original_text = text.clone
  16.       # ----------------- edit ---------------------------------#
  17.       # Control text processing
  18.       begin
  19.         last_text = text.clone
  20.         text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  21.       end until text == last_text
  22.       text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  23.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  24.       end
  25.       # Change "\\\\" to "\000" for convenience
  26.       text.gsub!(/\\\\/) { "\000" }
  27.       # Change "\\C" to "\001" and "\\G" to "\002"
  28.       text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  29.       text.gsub!(/\\[Gg]/) { "\002" }
  30.       # Get 1 text character in c (loop until unable to get text)
  31.       while ((c = text.slice!(/./m)) != nil)
  32.         # If \\
  33.         if c == "\000"
  34.           # Return to original text
  35.           c = "\\"
  36.         end
  37.         # If \C[n]
  38.         if c == "\001"
  39.           # Change text color
  40.           text.sub!(/\[([0-9]+)\]/, "")
  41.           color = $1.to_i
  42.           if color >= 0 and color <= 7
  43.             self.contents.font.color = text_color(color)
  44.           end
  45.           # go to next text
  46.           next
  47.         end
  48.         # If \G
  49.         if c == "\002"
  50.           # Make gold window
  51.           if @gold_window == nil
  52.             @gold_window = Window_Gold.new
  53.             @gold_window.x = 560 - @gold_window.width
  54.             if $game_temp.in_battle
  55.               @gold_window.y = 192
  56.             else
  57.               @gold_window.y = self.y >= 128 ? 32 : 384
  58.             end
  59.             @gold_window.opacity = self.opacity
  60.             @gold_window.back_opacity = self.back_opacity
  61.           end
  62.           # go to next text
  63.           next
  64.         end
  65.         # If new line text
  66.         if c == "\n"
  67.           # Update cursor width if choice
  68.           if y >= $game_temp.choice_start
  69.             @cursor_width = [@cursor_width, x].max
  70.           end
  71.           # Add 1 to y
  72.           y += 1
  73.           x = 0
  74.           # Indent if choice
  75.           if y >= $game_temp.choice_start
  76.             x = 8
  77.           end
  78.           # go to next text
  79.           next
  80.         end
  81.         # Draw text
  82.         # ----------------- edit ---------------------------------#
  83.         #self.contents.draw_text(4 + x, 32 * y, 40, 32, c)
  84.         # ----------------- edit ---------------------------------#
  85.         # Add x to drawn text width
  86.         x += self.contents.text_size(c).width
  87.       end
  88.     end
  89.     # ----------------- edit ---------------------------------#
  90.     @message_array  = original_text.split("\n")
  91.     for i in 0...@message_array.size
  92.       self.contents.draw_text(4, 32 * i, self.width-40, 32, @message_array[i], 1)
  93.     end
  94.     # ----------------- edit ---------------------------------#
  95.     # If choice
  96.     if $game_temp.choice_max > 0
  97.       @item_max = $game_temp.choice_max
  98.       self.active = true
  99.       self.index = 0
  100.     end
  101.     # If number input
  102.     if $game_temp.num_input_variable_id > 0
  103.       digits_max = $game_temp.num_input_digits_max
  104.       number = $game_variables[$game_temp.num_input_variable_id]
  105.       @input_number_window = Window_InputNumber.new(digits_max)
  106.       @input_number_window.number = number
  107.       @input_number_window.x = self.x + 8
  108.       @input_number_window.y = self.y + $game_temp.num_input_start * 32
  109.     end
  110.   end
  111. end
Expand to see the code.

Otherwise, you must find every 'self.contents.draw_text' in the script, and replace it with:
  1. @message_array  = original_text.split("\n")
  2.     for i in 0...@message_array.size
  3.       self.contents.draw_text(4, 32 * i, self.width-40, 32, @message_array[i], 1)
  4.     end
Expand to see the code.

If it's inside the loop that draws every character, delete it and add this code after the loop.
Remember you must set original_text to $game_temp.message_text first.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=70901