Advertisement
Rolpege

UMS custom resolution by Rolpege

Nov 8th, 2011
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 116.40 KB | None | 0 0
  1. # *****************************************************************************
  2. # *    Universal Message System
  3. # *      v1.8.0
  4. # *      by Ccoa
  5. # *    If you're seeing this script anywhere other than RPG Revolution, RMVXP
  6. # *    Universe, SponGen, or RPG Manager, then please contact me.  I have not
  7. # *    given permission for this to be distributed anywhere else.
  8. # *****************************************************************************
  9. # Usage:
  10. =begin
  11.  
  12. IN MESSAGE CODES
  13.   \b          - toggle bold on and off
  14.   \bopc[i]    - change the back opacity for this message to i (should be 0-255)
  15.   \c[i]       - change the text color
  16.   \c[#IIIIII] - change the text color to the hex code (temporary)
  17.   \e[i]       - place the text box over event i (0 = player, -1 no event)
  18.   \face[name] - changes the face graphic to name.png (leave empty [] for no face)
  19.   \fl         - change face justification to left
  20.   \font[name] - change the font to name, leave empty [] to return to the default font
  21.   \fr         - change face justification to right
  22.   \g          - display the gold window
  23.   \height     - height of the message window, works only in normal mode
  24.   \i          - toggle italics on and off
  25.   \ic[name]   - draw icon name in the window
  26.   \ignr       - Do not write anything on this line, only process codes, must be the first thing on a line
  27.   \jc         - justify the window to the center, ignored if using \e
  28.   \jl         - justify the window to the left, ignored if using \e
  29.   \jr         - justify the window to the right, ignored if using \e
  30.   \m          - toggle mode between normal and fit window to text
  31.   \n[i]       - display the name of actor i
  32.   \nm[name]   - display the name in the name window, leave empty [] to remove the name window
  33.   \oa[i]      - display the icon and name of armor i
  34.   \oi[i]      - display the icon and name of item i
  35.   \opc[i]     - change the opacity for this message to i (should be 0-255)
  36.   \os[i]      - display the icon and name of skill i
  37.   \ow[i]      - display the icon and name of weapon i
  38.   \p[i]       - pause for i frames before writing the next character
  39.   \pt         - toggle pause display on and off
  40.   \s          - toggle shadowed text
  41.   \shk[i]     - set window shake to i, higher i is bigger shake, 0 is no shake
  42.   \sk[i]      - begin text to be shaken, i is begger shake
  43.   \sk         - end text to be shaken
  44.   \skip       - toggle text skip on and off
  45.   \ta[i]      - center the window over train actor 1
  46.   \t1         - switch to the talk1 comic thingy
  47.   \t2         - switch to the talk2 comic thingy
  48.   \tc         - center the text, must be the first thing on a line
  49.   \th         - switch to the thought comic thingy
  50.   \tl         - left justify the text, must be the first thing on a line
  51.   \tr         - right justify the text, must be the first thing on a line
  52.   \v[i]       - display variable i
  53.   \width      - width of the message window, works only in normal mode
  54.   \w[i]       - wait for i frames after receiving this code, then close the window
  55.   \ws[i]      - change the write speed to i
  56.   \slv[name]  - set this window to be slave window name, or show slave window name
  57.   \inc        - include this window in the last
  58.  
  59. OUT OF MESSAGE CODES (use in a Script event command)
  60. $game_system.ums_mode = NORMAL_MODE - switch to normal mode
  61. $game_system.ums_mode = FIT_WINDOW_TO_TEXT - switch to fit window mode
  62. $game_system.text_skip = true - turn text skip on
  63. $game_system.text_skip = false
  64. true                           - turn text skip off (true is necessary)
  65. $game_system.text_mode = WRITE_FASTER - change skip mode to write faster
  66. $game_system.text_mode = WRITE_ALL - change skip mode to write all
  67. $game_system.write_speed = i - change the delay between letters to i frames
  68. $game_system.window_height = i - change the window height to i
  69. $game_system.window_width = i - change the window width to i
  70. $game_system.window_justification = RIGHT - make the window right justified
  71. $game_system.window_justification = LEFT - make the window left justified
  72. $game_system.window_justification = CENTER - make the window center justified
  73. $game_system.face_graphic = "filename" - change the face graphic to filename.png
  74. $game_system.face_graphic = "" - change the face graphic to none
  75. $game_system.face_graphic_justification = LEFT - the face graphic is on the left side
  76. $game_system.face_graphic_justification = RIGHT - the face graphic is on the right side
  77. $game_system.face_graphic_position = TOP - face graphic appears on top of window
  78. $game_system.face_graphic_position = CENTER - face graphic appears centered in window
  79. $game_system.face_graphic_position = BOTTOM - face graphic appears on the bottom of window
  80. $game_system.shadow_text = true - turn text shadowing on
  81. $game_system.shadow_text = false
  82. true                            - turn text shadowing off (true is necessary)
  83. $game_system.shadow_color = Color.new(red, blue, green, alpha) - change shadow color
  84. $game_system.message_event = what event to put the message over (0 = player, -1 = no event)
  85. $game_system.comic_enabled = false
  86. true                               - turn off comic thingy
  87. $game_system.comic_enabled = true  - turn on comic thingy (only works with message_event not -1)
  88. $game_system.comic_style = TALK1   - use the talk1.png comic thingy
  89. $game_system.comic_style = TALK2   - use the talk2.png comic thingy
  90. $game_system.comic_style = THOUGHT - use the thought.png comic thingy
  91. $game_system.name = "name" - change the text of the name window to name
  92. $game_system.name = "" - remove the name window
  93. $game_system.font = "name" - change the font to name
  94. $game_system.font = "" - return the font to the default
  95. $game_system.text_justification = CENTER - center justify the text
  96. $game_system.text_justification = LEFT - left justify the text
  97. $game_system.text_justification = RIGHT - right justify the text
  98. $game_system.show_pause = true - show pause icon when waiting for user input
  99. $game_system.show_pause = false - don't show pause icon when waiting for user input
  100. $game_system.shake = 0 - turn window shake off
  101. $game_system.shake = i - set shake to i, higher i is bigger shake
  102. $game_system.sound_effect = "" - turn off the letter-by-letter SE
  103. $game_system.sound_effect = "sename" - play the SE sename with each letter written
  104. $game_system.animated_faces = false - do not use animated faces
  105. $game_system.animated_faces = true - use animated faces
  106. $game_system.animation_pause = i - Wait i frames between each animation
  107. $game_system.face_frame_width = i - Each frame on the faceset is i pixels
  108. $game_system.resting_face = "" - Do not use a resting face
  109. $game_system.resting_face = "name" - Use a different animated face named facenamename when done talking
  110. $game_system.resting_animation_pause = i - Wait i frames between resting animations
  111. $game_system.text_mode = ONE_LETTER_AT_A_TIME - write text one letter at a time
  112. $game_system.text_mode = ALL_AT_ONCE - write text all at once
  113. $game_system.font_color = Color.new(R, G, B, A) - permanently change the font color to the RGBA color given here
  114. $game_system.font_color = nil - return the font color permanently to normal_color (white, by default)
  115. $game_system.windowskin = "windowskinname" - change the message box windowskin to windowskin
  116. $game_system.windowskin = "" - change the message box windowskin back to the one in the database
  117. $game_system.name_window = true - show the name window
  118. $game_system.name_window = false - hide the name window (just show the text)
  119. $game_system.opacity = i - change the message window back opacity to i (0-255)
  120. $game_system.window_image = "imagename" - the name of the image to show behind the window
  121. $game_system.window_image = nil - stop showing an image behind the window
  122. $game_system.train_actor = i - center the message over train actor i
  123.  
  124. =end
  125. # *****************************************************************************
  126. #  CONSTANTS
  127. # *****************************************************************************
  128.  
  129. # Rolpege: Custom resolution
  130. SCREEN = [1024, 576]
  131.  
  132. # modes
  133. NORMAL_MODE        = 0
  134. FIT_WINDOW_TO_TEXT = 1
  135.  
  136. #text modes
  137. ONE_LETTER_AT_A_TIME = 0
  138. ALL_AT_ONCE          = 1
  139.  
  140. # skip modes
  141. WRITE_FASTER = 0
  142. WRITE_ALL    = 1
  143.  
  144. # justifications
  145. RIGHT  = 4
  146. CENTER = 1
  147. LEFT   = 6
  148.  
  149. # positions for extra objects (face graphics, choice box, etc)
  150. ABOVE  = 0  # place the object above the top of the message box
  151. CENTER = 1  # center the object vertically inside the message box
  152. BOTTOM = 2  # place the bottom of the object on the bottom of the message box
  153. SIDE   = 3  # to the side of the message box (which side depends on justification)
  154.  
  155. # comic type
  156. TALK1   = 0
  157. TALK2   = 1
  158. THOUGHT = 2
  159.  
  160. # *****************************************************************************
  161. #  Changes to Game_System.  This allows any changes made to be saved when the
  162. #     game is saved.
  163. # *****************************************************************************
  164.  
  165. class Game_System
  166.   attr_accessor :ums_mode # what mode the UMS is in
  167.   attr_accessor :text_skip # whether or not text skip is activated
  168.   attr_accessor :skip_mode # write the text faster while C is pressed, or just skip to the end
  169.   attr_accessor :write_speed # frame delay between characters
  170.  
  171.   attr_accessor :text_mode # write one letter at a time, or all at once?
  172.  
  173.   attr_accessor :window_height # default height of message window
  174.   attr_accessor :window_width # default width of message window
  175.   attr_accessor :window_justification # default justification of window
  176.  
  177.   attr_accessor :face_graphic # current face graphic
  178.   attr_accessor :face_graphic_justification # justification of face graphic
  179.   attr_accessor :face_graphic_position # position of face graphic
  180.  
  181.   attr_accessor :shadowed_text # whether or not to draw a shadow behind the text
  182.   attr_accessor :shadow_color # the shadow color
  183.  
  184.   attr_accessor :choice_justification # where the choice window is located
  185.   attr_accessor :choice_position # prefered position of choice window
  186.  
  187.   attr_accessor :message_event # what event to center the text over (0 player, -1 to not)
  188.   attr_accessor :train_actor   # what train actor to center the text over (0 player, -1 to not)
  189.  
  190.   attr_accessor :comic_enabled # using "talk" icons?
  191.   attr_accessor :comic_style   # what type of comic image to use
  192.  
  193.   attr_accessor :name # the text for the name window
  194.   attr_accessor :name_window # should the name window be visible?
  195.  
  196.   attr_accessor :font # the name of the font
  197.   attr_accessor :font_color # the name of the (permanent) font color
  198.  
  199.   attr_accessor :text_justification # the justification of the window text
  200.  
  201.   attr_accessor :show_pause # whether or not to show the pause icon
  202.  
  203.   attr_accessor :shake # the amount of shake for the window
  204.   attr_accessor :text_shake # shake amount for text
  205.  
  206.   attr_accessor :sound_effect # SE to play with each letter
  207.  
  208.   attr_accessor :slave_windows # hash of slave windows
  209.   attr_accessor :indy_windows  # hash of independent windows
  210.  
  211.   attr_accessor :animated_faces # are the faces animated?
  212.   attr_accessor :animation_pause # how long do I wait between animation loops?
  213.   attr_accessor :face_frame_width # how many pixels wide is each face frame
  214.   attr_accessor :resting_face  # postext for waiting face graphic
  215.   attr_accessor :resting_animation_pause # how long to wait for resting graphic
  216.  
  217.   attr_accessor :windowskin # what windowskin to use for messages
  218.   attr_accessor :back_opacity # back opacity of windowskin
  219.   attr_accessor :opacity # opacity of windowskin
  220.  
  221.   attr_accessor :window_image # image used behind window
  222.  
  223.   attr_reader :shortcuts  # user-defined shortcuts
  224.  
  225.   alias ums_initialize initialize
  226.   def initialize
  227.     ums_initialize
  228.     @ums_mode = NORMAL_MODE
  229.    
  230.     @skip_mode = WRITE_ALL
  231.     @text_skip = true
  232.     @write_speed = 2
  233.    
  234.     @text_mode = ONE_LETTER_AT_A_TIME
  235.    
  236.     @window_height = 128
  237.     @window_width = 480
  238.     @window_justification = CENTER
  239.    
  240.     @face_graphic = ""
  241.     @face_graphic_justification = LEFT
  242.     @face_graphic_position = CENTER
  243.    
  244.     @shadowed_text = false
  245.     @shadow_color = Color.new(0, 0, 0, 100)
  246.    
  247.     @choice_justification = RIGHT
  248.     @choice_position = SIDE
  249.    
  250.     @message_event = -1
  251.     @train_actor   = -1
  252.    
  253.     @comic_enabled = false
  254.     @comic_style = TALK1
  255.    
  256.     @name = ""
  257.     @name_window = true
  258.    
  259.     @font = "Verdana"
  260.     @font_color = nil
  261.    
  262.     @text_justification = LEFT
  263.    
  264.     @show_pause = true
  265.    
  266.     @shake = 0
  267.     @text_shake = 0
  268.    
  269.     @sound_effect = ""
  270.    
  271.     @slave_windows = {}
  272.     @indy_windows  = {}
  273.    
  274.     @animated_faces = false
  275.     @animation_pause = 80
  276.     @face_frame_width = 100
  277.     @resting_face = ""
  278.     @resting_animation_pause = 80
  279.    
  280.     @windowskin = ""
  281.     @opacity = 255
  282.     @back_opacity = 160
  283.    
  284.     @window_image = nil
  285.    
  286.     @used_codes = ['\v', '\n', '\c', '\g', '\skip', '\m', '\height', '\width',
  287.                    '\jr', '\jc', '\jl', '\face', '\fl', '\fr', '\b', '\i', '\s',
  288.                    '\e', '\t1', '\t2', '\th', '\nm', '\font', '\p', '\w', '\ws',
  289.                    '\oa', '\oi', '\os', '\ow', '\tl', '\tr', '\tc', '\ignr',
  290.                    '\shk', '\slv', '\ind', '\inc']
  291.                    
  292.     @shortcuts = {}
  293.   end
  294.  
  295.   def add_shortcut(shortcut, code)
  296.     text = shortcut.downcase
  297.     if !@used_codes.include?(text)
  298.       @shortcuts[shortcut] = code
  299.     end
  300.   end
  301.  
  302.   def open_window(name)
  303.     if $game_system.indy_windows.has_key?(name)
  304.       $game_system.indy_windows[name].show = true
  305.     end
  306.   end
  307.  
  308.   def close_window(name)
  309.     if $game_system.indy_windows.has_key?(name)
  310.       $game_system.indy_windows[name].dispose
  311.       $game_system.indy_windows.delete(name)
  312.     end
  313.   end
  314. end
  315.  
  316. #==============================================================================
  317. # ** Game_Temp
  318. #------------------------------------------------------------------------------
  319. #  This class handles temporary data that is not included with save data.
  320. #  Refer to "$game_temp" for the instance of this class.
  321. #==============================================================================
  322. class Game_Temp
  323.   attr_accessor :choices
  324.   attr_accessor :num_choices
  325.   attr_accessor :skip_next_choices
  326.  
  327.   alias old_init initialize
  328.   def initialize
  329.     old_init
  330.     @skip_next_choices = 0
  331.     @num_choices = 1
  332.   end
  333. end
  334.  
  335. class Scene_Map
  336.   alias ums_update update
  337.   def update
  338.     $game_system.slave_windows.each_value { |window| window.update }
  339.     $game_system.indy_windows.each_value { |window| window.update }
  340.     ums_update
  341.   end
  342. end
  343.  
  344. class Interpreter
  345.   #--------------------------------------------------------------------------
  346.   # * Event Command Execution
  347.   #--------------------------------------------------------------------------
  348.   def execute_command
  349.     # If last to arrive for list of event commands
  350.     if @index >= @list.size - 1
  351.       # End event
  352.       command_end
  353.       # Continue
  354.       return true
  355.     end
  356.     # Make event command parameters available for reference via @parameters
  357.     if !(@list[@index].code == 102 and $game_temp.skip_next_choices > 0)
  358.       @parameters = @list[@index].parameters.clone
  359.       if @list[@index].code == 402
  360.         @parameters[0] += @offset
  361.       end
  362.     end
  363.     # Branch by command code
  364.     case @list[@index].code
  365.     when 101  # Show Text
  366.       return command_101
  367.     when 102  # Show Choices
  368.       return command_102
  369.     when 402  # When [**]
  370.       return command_402
  371.     when 403  # When Cancel
  372.       return command_403
  373.     when 103  # Input Number
  374.       return command_103
  375.     when 104  # Change Text Options
  376.       return command_104
  377.     when 105  # Button Input Processing
  378.       return command_105
  379.     when 106  # Wait
  380.       return command_106
  381.     when 111  # Conditional Branch
  382.       return command_111
  383.     when 411  # Else
  384.       return command_411
  385.     when 112  # Loop
  386.       return command_112
  387.     when 413  # Repeat Above
  388.       return command_413
  389.     when 113  # Break Loop
  390.       return command_113
  391.     when 115  # Exit Event Processing
  392.       return command_115
  393.     when 116  # Erase Event
  394.       return command_116
  395.     when 117  # Call Common Event
  396.       return command_117
  397.     when 118  # Label
  398.       return command_118
  399.     when 119  # Jump to Label
  400.       return command_119
  401.     when 121  # Control Switches
  402.       return command_121
  403.     when 122  # Control Variables
  404.       return command_122
  405.     when 123  # Control Self Switch
  406.       return command_123
  407.     when 124  # Control Timer
  408.       return command_124
  409.     when 125  # Change Gold
  410.       return command_125
  411.     when 126  # Change Items
  412.       return command_126
  413.     when 127  # Change Weapons
  414.       return command_127
  415.     when 128  # Change Armor
  416.       return command_128
  417.     when 129  # Change Party Member
  418.       return command_129
  419.     when 131  # Change Windowskin
  420.       return command_131
  421.     when 132  # Change Battle BGM
  422.       return command_132
  423.     when 133  # Change Battle End ME
  424.       return command_133
  425.     when 134  # Change Save Access
  426.       return command_134
  427.     when 135  # Change Menu Access
  428.       return command_135
  429.     when 136  # Change Encounter
  430.       return command_136
  431.     when 201  # Transfer Player
  432.       return command_201
  433.     when 202  # Set Event Location
  434.       return command_202
  435.     when 203  # Scroll Map
  436.       return command_203
  437.     when 204  # Change Map Settings
  438.       return command_204
  439.     when 205  # Change Fog Color Tone
  440.       return command_205
  441.     when 206  # Change Fog Opacity
  442.       return command_206
  443.     when 207  # Show Animation
  444.       return command_207
  445.     when 208  # Change Transparent Flag
  446.       return command_208
  447.     when 209  # Set Move Route
  448.       return command_209
  449.     when 210  # Wait for Move's Completion
  450.       return command_210
  451.     when 221  # Prepare for Transition
  452.       return command_221
  453.     when 222  # Execute Transition
  454.       return command_222
  455.     when 223  # Change Screen Color Tone
  456.       return command_223
  457.     when 224  # Screen Flash
  458.       return command_224
  459.     when 225  # Screen Shake
  460.       return command_225
  461.     when 231  # Show Picture
  462.       return command_231
  463.     when 232  # Move Picture
  464.       return command_232
  465.     when 233  # Rotate Picture
  466.       return command_233
  467.     when 234  # Change Picture Color Tone
  468.       return command_234
  469.     when 235  # Erase Picture
  470.       return command_235
  471.     when 236  # Set Weather Effects
  472.       return command_236
  473.     when 241  # Play BGM
  474.       return command_241
  475.     when 242  # Fade Out BGM
  476.       return command_242
  477.     when 245  # Play BGS
  478.       return command_245
  479.     when 246  # Fade Out BGS
  480.       return command_246
  481.     when 247  # Memorize BGM/BGS
  482.       return command_247
  483.     when 248  # Restore BGM/BGS
  484.       return command_248
  485.     when 249  # Play ME
  486.       return command_249
  487.     when 250  # Play SE
  488.       return command_250
  489.     when 251  # Stop SE
  490.       return command_251
  491.     when 301  # Battle Processing
  492.       return command_301
  493.     when 601  # If Win
  494.       return command_601
  495.     when 602  # If Escape
  496.       return command_602
  497.     when 603  # If Lose
  498.       return command_603
  499.     when 302  # Shop Processing
  500.       return command_302
  501.     when 303  # Name Input Processing
  502.       return command_303
  503.     when 311  # Change HP
  504.       return command_311
  505.     when 312  # Change SP
  506.       return command_312
  507.     when 313  # Change State
  508.       return command_313
  509.     when 314  # Recover All
  510.       return command_314
  511.     when 315  # Change EXP
  512.       return command_315
  513.     when 316  # Change Level
  514.       return command_316
  515.     when 317  # Change Parameters
  516.       return command_317
  517.     when 318  # Change Skills
  518.       return command_318
  519.     when 319  # Change Equipment
  520.       return command_319
  521.     when 320  # Change Actor Name
  522.       return command_320
  523.     when 321  # Change Actor Class
  524.       return command_321
  525.     when 322  # Change Actor Graphic
  526.       return command_322
  527.     when 331  # Change Enemy HP
  528.       return command_331
  529.     when 332  # Change Enemy SP
  530.       return command_332
  531.     when 333  # Change Enemy State
  532.       return command_333
  533.     when 334  # Enemy Recover All
  534.       return command_334
  535.     when 335  # Enemy Appearance
  536.       return command_335
  537.     when 336  # Enemy Transform
  538.       return command_336
  539.     when 337  # Show Battle Animation
  540.       return command_337
  541.     when 338  # Deal Damage
  542.       return command_338
  543.     when 339  # Force Action
  544.       return command_339
  545.     when 340  # Abort Battle
  546.       return command_340
  547.     when 351  # Call Menu Screen
  548.       return command_351
  549.     when 352  # Call Save Screen
  550.       return command_352
  551.     when 353  # Game Over
  552.       return command_353
  553.     when 354  # Return to Title Screen
  554.       return command_354
  555.     when 355  # Script
  556.       return command_355
  557.     else      # Other
  558.       return true
  559.     end
  560.   end
  561.  
  562.   #--------------------------------------------------------------------------
  563.   # * Show Text
  564.   #--------------------------------------------------------------------------
  565.   def command_101
  566.     # If other text has been set to message_text
  567.     if $game_temp.message_text != nil
  568.       # End
  569.       return false
  570.     end
  571.     # Set message end waiting flag and callback
  572.     @message_waiting = true
  573.     $game_temp.message_proc = Proc.new { @message_waiting = false }
  574.     # Set message text on first line
  575.     $game_temp.message_text = @list[@index].parameters[0] + "\n"
  576.     line_count = 1
  577.     # Loop
  578.     loop do
  579.       # If next event command text is on the second line or after
  580.       if @list[@index + 1].code == 401
  581.         # Add the second line or after to message_text
  582.         $game_temp.message_text += @list[@index + 1].parameters[0] + "\n"
  583.         line_count += 1
  584.       # If the next event command is show text
  585.       elsif @list[@index + 1].code == 101
  586.         # If the text contains the \inc code
  587.         if @list[@index + 1].parameters[0].index(/\\[Ii][Nn][Cc]/) != nil
  588.           $game_temp.message_text += @list[@index + 1].parameters[0] + "\n"
  589.           $game_temp.message_text.sub!(/\\[Ii][Nn][Cc]/) { "" }
  590.         else
  591.           return true
  592.         end
  593.       # If event command is not on the second line or after
  594.       else
  595.         # If next event command is show choices
  596.         if @list[@index + 1].code == 102
  597.           # Advance index
  598.           @index += 1
  599.          
  600.           # skip this one, it was already shown?
  601.           if $game_temp.skip_next_choices > 0
  602.             $game_temp.skip_next_choices -= 1
  603.           else
  604.             # Choices setup
  605.             $game_temp.choice_start = line_count
  606.             setup_choices(@list[@index].parameters)
  607.           end
  608.         # If next event command is input number
  609.         elsif @list[@index + 1].code == 103
  610.           # If number input window fits on screen
  611.           if line_count < 4
  612.             # Advance index
  613.             @index += 1
  614.             # Number input setup
  615.             $game_temp.num_input_start = line_count
  616.             $game_temp.num_input_variable_id = @list[@index].parameters[0]
  617.             $game_temp.num_input_digits_max = @list[@index].parameters[1]
  618.           end
  619.         end
  620.         # Continue
  621.         return true
  622.       end
  623.       # Advance index
  624.       @index += 1
  625.     end
  626.   end
  627.   #--------------------------------------------------------------------------
  628.   # * Show Choices
  629.   #--------------------------------------------------------------------------
  630.   def command_102
  631.     # If text has been set to message_text
  632.     if $game_temp.message_text != nil
  633.       # End
  634.       return false
  635.     end
  636.    
  637.     if $game_temp.skip_next_choices > 0
  638.       # skip this one, it is part of another
  639.       $game_temp.skip_next_choices -= 1
  640.       @offset += 4
  641.       @index += 1
  642.       return false
  643.     else
  644.       @offset = 0
  645.     end
  646.     # Set message end waiting flag and callback
  647.     @message_waiting = true
  648.     $game_temp.message_proc = Proc.new { @message_waiting = false }
  649.     # Choices setup
  650.     $game_temp.message_text = ""
  651.     $game_temp.choice_start = 0
  652.     setup_choices(@parameters)
  653.     # Continue
  654.     return true
  655.   end
  656.   #--------------------------------------------------------------------------
  657.   # * Setup Choices
  658.   #--------------------------------------------------------------------------
  659.   def setup_choices(parameters)
  660.     params = parameters.clone
  661.     @offset = 0
  662.     i = @index
  663.     curr = 1
  664.     while curr < $game_temp.num_choices
  665.       i += 1
  666.       if @list[i].code == 102
  667.         params[0] += @list[i].parameters[0]
  668.         if @list[i].parameters[1] == 5
  669.           @cancel_flag = true
  670.         else
  671.           @cancel_flag = false
  672.         end
  673.         params[1] = @list[i].parameters[1] + (curr * 4)
  674.         curr += 1
  675.       end
  676.     end
  677.    
  678.     # Set choice item count to choice_max
  679.     $game_temp.choice_max = params[0].size
  680.     # Set choice to message_text
  681.     $game_temp.choices = params[0]
  682.     # Set cancel processing
  683.     $game_temp.choice_cancel_type = params[1]
  684.    
  685.     if $game_temp.num_choices != 1
  686.       $game_temp.skip_next_choices = $game_temp.num_choices - 1
  687.       $game_temp.num_choices = 1
  688.     end
  689.    
  690.     # Set callback
  691.     current_indent = @list[@index].indent
  692.     $game_temp.choice_proc = Proc.new { |n| @branch[current_indent] = n }
  693.   end
  694.  
  695.   #--------------------------------------------------------------------------
  696.   # * When [**]
  697.   #--------------------------------------------------------------------------
  698.   def command_402
  699.     # If fitting choices are selected
  700.     if @branch[@list[@index].indent] == @parameters[0]
  701.       # Delete branch data
  702.       @branch.delete(@list[@index].indent)
  703.       # Continue
  704.       return true
  705.     end
  706.     # If it doesn't meet the condition: command skip
  707.     return command_skip
  708.   end
  709.  
  710.   #--------------------------------------------------------------------------
  711.   # * When Cancel
  712.   #--------------------------------------------------------------------------
  713.   def command_403
  714.     # If choices are cancelled
  715.     if @cancel_flag
  716.       # Delete branch data
  717.       @branch.delete(@list[@index].indent)
  718.       # Continue
  719.       return true
  720.     end
  721.     # If it doen't meet the condition: command skip
  722.     return command_skip
  723.   end
  724.  
  725.   #--------------------------------------------------------------------------
  726.   # * Input Number
  727.   #--------------------------------------------------------------------------
  728.   def command_103
  729.     # If text has been set to message_text
  730.     if $game_temp.message_text != nil
  731.       # End
  732.       return false
  733.     end
  734.     # Set message end waiting flag and callback
  735.     @message_waiting = true
  736.     $game_temp.message_proc = Proc.new { @message_waiting = false }
  737.     # Number input setup
  738.     $game_temp.message_text = ""
  739.     $game_temp.num_input_start = 0
  740.     $game_temp.num_input_variable_id = @parameters[0]
  741.     $game_temp.num_input_digits_max = @parameters[1]
  742.     # Continue
  743.     return true
  744.   end
  745.  
  746.   #--------------------------------------------------------------------------
  747.   # * Script
  748.   #--------------------------------------------------------------------------
  749.   def command_355
  750.     # Set first line to script
  751.     script = @list[@index].parameters[0] + "\n"
  752.     # Loop
  753.     loop do
  754.       # If next event command is second line of script or after
  755.       if @list[@index + 1].code == 655
  756.         # Add second line or after to script
  757.         script += @list[@index + 1].parameters[0] + "\n"
  758.       # If event command is not second line or after
  759.       else
  760.         # Abort loop
  761.         break
  762.       end
  763.       # Advance index
  764.       @index += 1
  765.     end
  766.     # Evaluation
  767.     result = eval(script)
  768.  
  769.     # Continue
  770.     return true
  771.   end
  772. end
  773.  
  774. # *****************************************************************************
  775. #  Changes to Window_Message.  This is the bulk of the script
  776. # *****************************************************************************
  777. #==============================================================================
  778. # ** Window_Message
  779. #------------------------------------------------------------------------------
  780. #  This message window is used to display text.
  781. #==============================================================================
  782.  
  783. class Window_Message < Window_Selectable
  784.   #--------------------------------------------------------------------------
  785.   # * Object Initialization
  786.   #--------------------------------------------------------------------------
  787.   def initialize
  788.     # x-coordinate depends on justification
  789.     if $game_system.window_justification == RIGHT
  790.       x = SCREEN[0] - self.width
  791.     elsif $game_system.window_justification == LEFT
  792.       x = 0
  793.     else # center
  794.       x = (SCREEN[0] - $game_system.window_width) / 2
  795.     end
  796.     # y-coordinate depends on height
  797.     y = SCREEN[1] - $game_system.window_height - 16
  798.     super(x, y, $game_system.window_width, $game_system.window_height)
  799.     self.contents = Bitmap.new(width - 32, height - 32)
  800.     if $game_system.font == ""
  801.       self.contents.font.name = Font.default_name
  802.     else
  803.       self.contents.font.name = $game_system.font
  804.     end
  805.     self.visible = false
  806.     self.z = 9998
  807.     @fade_in = false
  808.     @fade_out = false
  809.     @contents_showing = false
  810.    
  811.     # face graphic sprite
  812.     @face = Sprite.new
  813.     @face.opacity = 0
  814.     @face.z = self.z + 1
  815.     @face_offset = 0
  816.    
  817.     # choice window
  818.     @choice_window = Window_Choice.new([])
  819.     @choice_window.back_opacity = $game_system.back_opacity
  820.    
  821.     # comic sprite
  822.     @comic = Sprite.new
  823.     @comic.opacity = 0
  824.     @comic.z = self.z + 1
  825.     if $game_system.comic_style == TALK1
  826.       @comic.bitmap = RPG::Cache.windowskin("talk1")
  827.     elsif $game_system.comic_style == TALK2
  828.       @comic.bitmap = RPG::Cache.windowskin("talk2")
  829.     else # thought
  830.       @comic.bitmap = RPG::Cache.windowskin("thought")
  831.     end
  832.    
  833.     # window image sprite
  834.     @window_back = Sprite.new
  835.     @window_back.opacity = 0
  836.     @window_back.z = self.z - 1
  837.     if $game_system.window_image != nil
  838.       @window_back.bitmap = RPG::Cache.windowskin($game_system.window_image)
  839.     end
  840.    
  841.     # name window
  842.     @name_window = Window_Name.new
  843.     @name_window.z = self.z + 1
  844.    
  845.     # shake bitmaps
  846.     @shake_sprite = Sprite.new
  847.     @shake_sprite.bitmap = Bitmap.new(width - 32, height - 32)
  848.     @shake_sprite.x = self.x + 16
  849.     @shake_sprite.y = self.y + 8
  850.     @shake_sprite.z = self.z + 1
  851.    
  852.     @pause_time = 0
  853.     @wait = 0
  854.    
  855.     @show = false
  856.    
  857.     @face_frame = 0
  858.   end
  859.   #--------------------------------------------------------------------------
  860.   # * Dispose
  861.   #--------------------------------------------------------------------------
  862.   def dispose
  863.     terminate_message
  864.     $game_temp.message_window_showing = false
  865.     if @input_number_window != nil
  866.       @input_number_window.dispose
  867.     end
  868.     @face.dispose
  869.     @choice_window.dispose
  870.     @comic.dispose
  871.     @name_window.dispose
  872.     @shake_sprite.dispose
  873.     super
  874.   end
  875.   #--------------------------------------------------------------------------
  876.   # * Terminate Message
  877.   #--------------------------------------------------------------------------
  878.   def terminate_message
  879.     @show = false
  880.     self.active = false
  881.     self.pause = false
  882.     self.contents.clear
  883.     # Clear showing flag
  884.     @contents_showing = false
  885.     # Call message callback
  886.     if $game_temp.message_proc != nil
  887.       $game_temp.message_proc.call
  888.     end
  889.     # Clear variables related to text, choices, and number input
  890.     $game_temp.message_text = nil
  891.     $game_temp.message_proc = nil
  892.     $game_temp.choice_start = 99
  893.     $game_temp.choice_max = 0
  894.     $game_temp.choice_cancel_type = 0
  895.     $game_temp.choice_proc = nil
  896.     $game_temp.num_input_start = 99
  897.     $game_temp.num_input_variable_id = 0
  898.     $game_temp.num_input_digits_max = 0
  899.     # Open gold window
  900.     if @gold_window != nil
  901.       @gold_window.dispose
  902.       @gold_window = nil
  903.     end
  904.     @choice_window.visible = false
  905.     @choice_window.active = false
  906.     @comic.opacity = 0
  907.     $game_system.slave_windows.each_pair {|name, window|
  908.       if window.show == true
  909.         window.dispose
  910.         $game_system.slave_windows.delete(name)
  911.       end
  912.     }
  913.     @done = false
  914.   end
  915.   #--------------------------------------------------------------------------
  916.   # * Refresh
  917.   #--------------------------------------------------------------------------
  918.   def refresh
  919.     self.contents.clear
  920.     if $game_system.font_color.nil?
  921.       self.contents.font.color = normal_color
  922.     else
  923.       self.contents.font.color = $game_system.font_color
  924.     end
  925.     if $game_system.windowskin != ""  
  926.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin)
  927.     else
  928.       self.windowskin = RPG::Cache.windowskin($data_system.windowskin_name)
  929.     end
  930.     if $game_system.comic_style == TALK1
  931.       @comic.bitmap = RPG::Cache.windowskin("talk1")
  932.     elsif $game_system.comic_style == TALK2
  933.       @comic.bitmap = RPG::Cache.windowskin("talk2")
  934.     else # thought
  935.       @comic.bitmap = RPG::Cache.windowskin("thought")
  936.     end
  937.     @show = true
  938.     @x = @y = 0
  939.  
  940.     # If waiting for a message to be displayed
  941.     if $game_temp.message_text != nil
  942.       @text = $game_temp.message_text
  943.      
  944.       # replace shortcuts with original code
  945.       $game_system.shortcuts.each { |shortcut, code|
  946.         @text.gsub!(shortcut, code)
  947.       }
  948.      
  949.       # VERY first thing.  Check to see if this is being set up as a slave
  950.       #  or independent window.
  951.       if @text.index(/\\[Ss][Ll][Vv]\[(.*?)\]/) != nil
  952.         # is this a new slave window, or a request to display it?
  953.         if !$game_system.slave_windows.has_key?($1.to_s)
  954.           # there is no such slave window yet.  Set it up.
  955.           @text.gsub!(/\\[Ss][Ll][Vv]\[(.*?)\]/, "")
  956.           $game_system.slave_windows[$1.to_s] = Window_Slave.new(@text)
  957.           @text = ""
  958.           @show = false
  959.           terminate_message
  960.           return
  961.         end
  962.       end
  963.       if @text.index(/\\[Ii][Nn][Dd]\[(.*?)\]/) != nil
  964.         # is this a new independent window, or a request to display it?
  965.         if !$game_system.indy_windows.has_key?($1.to_s)
  966.           # there is no such slave window yet.  Set it up.
  967.           @text.gsub!(/\\[Ii][Nn][Dd]\[(.*?)\]/, "")
  968.           $game_system.indy_windows[$1.to_s] = Window_Slave.new(@text)
  969.           @text = ""
  970.           @show = false
  971.           terminate_message
  972.           return
  973.         end
  974.       end
  975.      
  976.       # Control text processing
  977.       begin
  978.         last_text = @text.clone
  979.         @text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  980.       end until @text == last_text
  981.       @text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  982.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  983.       end
  984.      
  985.       # window mode
  986.       if @text.index(/\\[Mm]/) != nil
  987.         if $game_system.ums_mode == NORMAL_MODE
  988.           $game_system.ums_mode = FIT_WINDOW_TO_TEXT
  989.         else
  990.           $game_system.ums_mode = NORMAL_MODE
  991.         end
  992.         @text.gsub!(/\\[Mm]/) { "" }
  993.       end
  994.      
  995.       # window height
  996.       @text.gsub!(/\\[Hh][Ee][Ii][Gg][Hh][Tt]\[([0-9]+)\]/) do
  997.         $game_system.window_height = $1.to_i
  998.         ""
  999.       end
  1000.      
  1001.       # window width
  1002.       @text.gsub!(/\\[Ww][Ii][Dd][Tt][Hh]\[([0-9]+)\]/) do
  1003.         $game_system.window_width = $1.to_i
  1004.         ""
  1005.       end
  1006.      
  1007.       # justification
  1008.       @text.gsub!(/\\[Jj][Rr]/) do
  1009.         $game_system.window_justification = RIGHT
  1010.         reset_window
  1011.         ""
  1012.       end
  1013.       @text.gsub!(/\\[Jj][Cc]/) do
  1014.         $game_system.window_justification = CENTER
  1015.         reset_window
  1016.         ""
  1017.       end      
  1018.       @text.gsub!(/\\[Jj][Ll]/) do
  1019.         $game_system.window_justification = LEFT
  1020.         reset_window
  1021.         ""
  1022.       end
  1023.      
  1024.       # face graphics
  1025.       @text.gsub!(/\\[Ff][Aa][Cc][Ee]\[(.*?)\]/) do
  1026.         $game_system.face_graphic = $1.to_s
  1027.         if $1.to_s == ""
  1028.           @face.opacity = 0
  1029.         end
  1030.         ""
  1031.       end
  1032.       @text.gsub!(/\\[Ff][Ll]/) do
  1033.         $game_system.face_graphic_justification = LEFT
  1034.         ""
  1035.       end
  1036.       @text.gsub!(/\\[Ff][Rr]/) do
  1037.         $game_system.face_graphic_justification = RIGHT
  1038.         ""
  1039.       end
  1040.      
  1041.       # event centering
  1042.       @text.gsub!(/\\[Ee]\[([0-9]+)\]/) do
  1043.         $game_system.message_event = $1.to_i
  1044.         ""
  1045.       end
  1046.      
  1047.       # train actor centering
  1048.       @text.gsub!(/\\[Tt][Aa]\[([0-9]+)\]/) do
  1049.         $game_system.train_actor = $1.to_i
  1050.         ""
  1051.       end
  1052.      
  1053.       # comic thingy
  1054.       @text.gsub!(/\\[Tt]1/) do
  1055.         $game_system.comic_style = TALK1
  1056.         @comic.bitmap = RPG::Cache.windowskin("talk1.png")
  1057.         ""
  1058.       end
  1059.       @text.gsub!(/\\[Tt]2/) do
  1060.         $game_system.comic_style = TALK2
  1061.         @comic.bitmap = RPG::Cache.windowskin("talk2.png")
  1062.         ""
  1063.       end
  1064.       @text.gsub!(/\\[Tt][Hh]/) do
  1065.         $game_system.comic_style = THOUGHT
  1066.         @comic.bitmap = RPG::Cache.windowskin("thought.png")
  1067.         ""
  1068.       end
  1069.      
  1070.       # name window
  1071.       @text.gsub!(/\\[Nn][Mm]\[(.*?)\]/) do
  1072.         $game_system.name = $1.to_s
  1073.         if $1.to_s == ""
  1074.           @name_window.visible = false
  1075.           @name_window.dummy_window.visible = false
  1076.         end
  1077.         ""
  1078.       end
  1079.       # name party window
  1080.       @text.gsub!(/\\[Nn][Pp]\[([0-9]+)\]/) do
  1081.         actor = $game_party.actors[$1.to_i]
  1082.         if actor != nil
  1083.           actor.name
  1084.         else
  1085.           ""
  1086.         end
  1087.       end
  1088.      
  1089.       if $game_system.name == ""
  1090.         @name_window.visible = false
  1091.         @name_window.dummy_window.visible = false
  1092.       end
  1093.      
  1094.      
  1095.       # toggle pause
  1096.       @text.gsub!(/\\[Pp][Tt]/) do
  1097.         $game_system.show_pause = !$game_system.show_pause
  1098.         ""
  1099.       end
  1100.      
  1101.       # shaking
  1102.       @text.gsub!(/\\[Ss][Kk]\[([0-9]+)\]/) do
  1103.         $game_system.text_shake = $1.to_i
  1104.         "\030"
  1105.       end
  1106.       @text.gsub!(/\\[Ss][Kk]/) do
  1107.         "\031"
  1108.       end
  1109.       @text.gsub!(/\\[Ss][Hh][Kk]\[([0-9]+)\]/) do
  1110.         $game_system.shake = $1.to_i
  1111.         ""
  1112.       end
  1113.      
  1114.      
  1115.       # back opacity
  1116.       @text.gsub!(/\\[Bb][Oo][Pp][Cc]\[([0-9]+)\]/) do
  1117.         $game_system.back_opacity = $1.to_i
  1118.         self.back_opacity = $game_system.back_opacity
  1119.         ""
  1120.       end
  1121.      
  1122.       # opacity
  1123.       @text.gsub!(/\\[Oo][Pp][Cc]\[([0-9]+)\]/) do
  1124.         $game_system.opacity = $1.to_i
  1125.         self.opacity = $game_system.opacity
  1126.         ""
  1127.       end
  1128.      
  1129.       # Change "\\\\" to "\000" for convenience
  1130.       @text.gsub!(/\\\\/) { "\000" }
  1131.       # Change "\\C" to "\001" and "\\G" to "\002"
  1132.       @text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  1133.       @text.gsub!(/\\[Gg]/) { "\002" }
  1134.       @text.gsub!(/\\[Cc]\[0x([0123456789abcdef]+)\]/) { "\026[#{$1}]" }
  1135.      
  1136.       # text skip code
  1137.       @text.gsub!(/\\[Ss][Kk][Ii][Pp]/) { "\003" }
  1138.      
  1139.       # ignore code
  1140.       @text.gsub!(/\\[Ii][Gg][Nn][Rr]/) { "\023" }
  1141.      
  1142.       # slave and indy windows
  1143.       @text.gsub!(/\\[Ss][Ll][Vv]\[(.*?)\]/) { "\024[#{$1}]" }
  1144.       @text.gsub!(/\\[Ii][Nn][Dd]\[(.*?)\]/) { "\025[#{$1}]" }
  1145.      
  1146.       # bold and italics
  1147.       @text.gsub!(/\\[Bb]/) { "\004" }
  1148.       @text.gsub!(/\\[Ii]/) { "\005" }
  1149.      
  1150.       # shadow
  1151.       @text.gsub!(/\\[Ss]/) { "\006" }
  1152.      
  1153.       # font
  1154.       @text.gsub!(/\\[Ff][Oo][Nn][Tt]\[(.*?)\]/) { "\007[#{$1}]" }
  1155.      
  1156.       # pause and wait
  1157.       @text.gsub!(/\\[Pp]\[([0-9]+)\]/) { "\010[#{$1}]" }
  1158.       @text.gsub!(/\\[Ww]\[([0-9]+)\]/) { "\011[#{$1}]" }
  1159.      
  1160.       # write speed
  1161.       @text.gsub!(/\\[Ww][Ss]\[([0-9]+)\]/) { "\013[#{$1}]" }
  1162.            
  1163.       # armor, items, skills, and weapons
  1164.       @text.gsub!(/\\[Oo][Aa]\[([0-9]+)\]/) {
  1165.         item = $data_armors[$1.to_i]
  1166.         "\014[#{$1}]" + "  " + item.name
  1167.       }
  1168.       @text.gsub!(/\\[Oo][Ii]\[([0-9]+)\]/) {
  1169.         item = $data_items[$1.to_i]
  1170.         "\015[#{$1}]" + "  " + item.name
  1171.       }
  1172.       @text.gsub!(/\\[Oo][Ss]\[([0-9]+)\]/) {
  1173.         item = $data_skills[$1.to_i]
  1174.         "\016[#{$1}]" + "  " + item.name
  1175.       }
  1176.       @text.gsub!(/\\[Oo][Ww]\[([0-9]+)\]/) {
  1177.         item = $data_weapons[$1.to_i]
  1178.         "\017[#{$1}]" + "  " + item.name
  1179.       }
  1180.       @text.gsub!(/\\[Ii][Cc]\[(.*?)\]/) {
  1181.         "\027[#{$1}]"
  1182.       }
  1183.      
  1184.       # text justification
  1185.       @text.gsub!(/\\[Tt][Cc]/) { "\020" }
  1186.       @text.gsub!(/\\[Tt][Ll]/) { "\021" }
  1187.       @text.gsub!(/\\[Tt][Rr]/) { "\022" }
  1188.      
  1189.       # Resize the window to fit the contents?
  1190.       if $game_system.ums_mode == FIT_WINDOW_TO_TEXT
  1191.         width = 1
  1192.         text = @text.split("\n")
  1193.         height = 0
  1194.         i = 0
  1195.         for line in text
  1196.           # don't count this line's width if it has the ignr code
  1197.           if !line.include?("\023")
  1198.             width = [width, self.contents.text_size(line).width].max
  1199.             delta = self.contents.text_size(line).height
  1200.             height += delta + (delta * 0.2).to_i
  1201.           end
  1202.         end
  1203.        
  1204.         if $game_system.face_graphic != "" and ($game_system.face_graphic_position == CENTER or $game_system.face_graphic_position == BOTTOM)
  1205.           width += @face.bitmap.width
  1206.           if height < @face.bitmap.height
  1207.             height = @face.bitmap.height - 32
  1208.           end
  1209.         end
  1210.        
  1211.         if height == 0
  1212.           height = 1
  1213.         end
  1214.        
  1215.         self.width = width + 48
  1216.         self.height = height + 48
  1217.         self.contents = Bitmap.new(width + 16, height)
  1218.        
  1219.         if $game_system.font == ""
  1220.           self.contents.font.name = Font.default_name
  1221.         else
  1222.           self.contents.font.name = $game_system.font
  1223.         end
  1224.        
  1225.         if $game_system.font_color.nil?
  1226.           self.contents.font.color = normal_color
  1227.         else
  1228.           self.contents.font.color = $game_system.font_color
  1229.         end
  1230.       else # normal mode
  1231.         if self.width != $game_system.window_height or self.height != $game_system.window_width
  1232.           self.width = $game_system.window_width
  1233.           self.height = $game_system.window_height
  1234.          
  1235.           # check to see if overall text height is greater than window height
  1236.           text = @text.split("\n")
  1237.           height = 0
  1238.           i = 0
  1239.           for line in text
  1240.             # don't count this line's width if it has the ignr code
  1241.             if !line.include?("\023")
  1242.               delta = self.contents.text_size(line).height
  1243.               height += delta + (delta * 0.2).to_i
  1244.             end
  1245.           end
  1246.           height += 32
  1247.          
  1248.           if (height > self.height)
  1249.             self.contents = Bitmap.new(self.width - 32, height - 32)
  1250.           else
  1251.             self.contents = Bitmap.new(self.width - 32, self.height - 32)
  1252.           end
  1253.          
  1254.           if $game_system.font == ""
  1255.             self.contents.font.name = Font.default_name
  1256.           else
  1257.             self.contents.font.name = $game_system.font
  1258.           end
  1259.           if $game_system.font_color.nil?
  1260.             self.contents.font.color = normal_color
  1261.           else
  1262.             self.contents.font.color = $game_system.font_color
  1263.           end
  1264.         end
  1265.       end
  1266.      
  1267.       if $game_system.window_image != nil
  1268.         # figure out how we're going to resize this          
  1269.         @window_back.zoom_x = self.width.to_f / @window_back.bitmap.width
  1270.         @window_back.zoom_y = self.height.to_f / @window_back.bitmap.height
  1271.       end
  1272.      
  1273.       reset_window
  1274.      
  1275.       get_x_value
  1276.      
  1277.       @count = Graphics.frame_count
  1278.       @pause_time = 0
  1279.       @ignore = false
  1280.       @ascending = true
  1281.       @target_x = self.x + $game_system.shake
  1282.       @target_x2 = @shake_sprite.x + $game_system.text_shake
  1283.       @done = false
  1284.       @face_frame = 0
  1285.       @done = false
  1286.      
  1287.       self.oy = 0
  1288.     end
  1289.    
  1290.    
  1291.   end
  1292.  
  1293.   #--------------------------------------------------------------------------
  1294.   # * Set Window Position and Opacity Level
  1295.   #--------------------------------------------------------------------------
  1296.   def reset_window (change_opacity = true)
  1297.     # x-coordinate depends on justification
  1298.     if $game_system.message_event == -1 and $game_system.train_actor == -1
  1299.       if $game_system.window_justification == RIGHT
  1300.         self.x = SCREEN[0] - $game_system.window_width
  1301.       elsif $game_system.window_justification == LEFT
  1302.         self.x = 0
  1303.       else # center
  1304.         self.x = (SCREEN[0] - self.width) / 2
  1305.       end
  1306.     elsif $game_system.train_actor >= 0
  1307.       if $game_system.train_actor == 0 or $game_system.train_actor > $game_party.actors.size - 1
  1308.         # center on player
  1309.         event_x = $game_player.screen_x
  1310.       else
  1311.         # center on train actor
  1312.         event_x = $game_train.actors[$game_system.train_actor - 1].screen_x
  1313.       end
  1314.       self.x = event_x - self.width / 2
  1315.       @comic.x = self.x + (self.width / 2) + 4
  1316.     else
  1317.       if $game_system.message_event == 0 or $game_map.events[$game_system.message_event] == nil
  1318.         # center on player
  1319.         event_x = $game_player.screen_x
  1320.       else
  1321.         # center on the event specified
  1322.         event_x = $game_map.events[$game_system.message_event].screen_x
  1323.       end
  1324.       self.x = event_x - self.width / 2
  1325.       @comic.x = self.x + (self.width / 2) + 4
  1326.     end
  1327.    
  1328.     if $game_temp.in_battle
  1329.       self.y = 16
  1330.     else
  1331.       if $game_system.message_event == -1 and $game_system.train_actor == -1
  1332.         case $game_system.message_position
  1333.           when 0  # up
  1334.             self.y = 16
  1335.           when 1  # middle
  1336.             self.y = (SCREEN[1] - $game_system.window_height) / 2
  1337.           when 2  # down
  1338.             self.y = SCREEN[1] - $game_system.window_height - 24
  1339.         end
  1340.       elsif $game_system.train_actor >= 0
  1341.         if $game_system.train_actor == 0 or $game_system.train_actor > $game_party.actors.size - 1
  1342.           # center on player
  1343.           self.y = $game_player.screen_y - self.height - 48
  1344.         else
  1345.           # center on train actor
  1346.           self.y = $game_train.actors[$game_system.train_actor - 1].screen_y - self.height - 48
  1347.         end
  1348.         @comic.y = self.y + self.height - 2
  1349.         @comic.angle = 0
  1350.       else
  1351.         if $game_system.message_event == 0 or $game_map.events[$game_system.message_event] == nil
  1352.           # above player
  1353.           self.y = $game_player.screen_y - self.height - 48
  1354.         else
  1355.           # above event specified
  1356.           self.y = $game_map.events[$game_system.message_event].screen_y - self.height - 48
  1357.         end
  1358.         @comic.y = self.y + self.height - 2
  1359.         @comic.angle = 0
  1360.       end
  1361.     end
  1362.     if self.y < 0 + ($game_system.name == "" ? 0 : 16)
  1363.       if $game_system.comic_enabled
  1364.         if $game_system.message_event == 0 or $game_map.events[$game_system.message_event] == nil
  1365.           self.y = $game_player.screen_y - 16
  1366.         else
  1367.           self.y = $game_map.events[$game_system.message_event].screen_y - 16
  1368.         end
  1369.         @comic.angle = 180
  1370.         @comic.y = self.y + 2
  1371.         @comic.x = self.x + (self.width / 2) - 4
  1372.       else
  1373.         self.y = 0 + ($game_system.name == "" ? 0 : 16)
  1374.       end
  1375.     elsif self.y > SCREEN[1] - self.height
  1376.       self.y = SCREEN[1] - self.height
  1377.     end
  1378.     if self.x < 0
  1379.       self.x = 0
  1380.     elsif self.x > (SCREEN[0] + 40) - self.width - 48
  1381.       self.x = SCREEN[0] - self.width
  1382.     end
  1383.    
  1384.     if change_opacity
  1385.       if $game_system.message_frame == 0 and $game_temp.message_text != ""
  1386.         self.opacity = $game_system.opacity
  1387.       else
  1388.         self.opacity = 0
  1389.       end
  1390.       self.back_opacity = $game_system.back_opacity
  1391.     end
  1392.    
  1393.     # window back stuff
  1394.     if $game_system.window_image != nil
  1395.       @window_back.bitmap = RPG::Cache.windowskin($game_system.window_image)
  1396.       @window_back.x = self.x
  1397.       @window_back.y = self.y
  1398.     end
  1399.    
  1400.       # face stuff
  1401.       if $game_system.face_graphic != ""  
  1402.         # the player has chosen to show a face graphic
  1403.         if @done and $game_system.resting_face != ""
  1404.           @face.bitmap = RPG::Cache.picture($game_system.face_graphic + $game_system.resting_face)
  1405.           if @face_frame * $game_system.face_frame_width >= @face.bitmap.width
  1406.             @face_frame = 0
  1407.           end
  1408.         else
  1409.           @face.bitmap = RPG::Cache.picture($game_system.face_graphic)
  1410.         end
  1411.        
  1412.         # picture y-coordinate
  1413.         if $game_system.face_graphic_position == ABOVE
  1414.           @face.y = self.y - @face.bitmap.height
  1415.           @face_offset = 0
  1416.         elsif $game_system.face_graphic_position == CENTER
  1417.           delta = (@face.bitmap.height - self.height) / 2
  1418.           @face.y = self.y - delta
  1419.           if $game_system.animated_faces
  1420.             @face_offset = $game_system.face_frame_width + 16
  1421.           else
  1422.             @face_offset = @face.bitmap.width + 16
  1423.           end
  1424.         elsif $game_system.face_graphic_position == BOTTOM
  1425.           @face.y = self.y + self.height - @face.bitmap.height
  1426.           if $game_system.animated_faces
  1427.             @face_offset = $game_system.face_frame_width + 16
  1428.           else
  1429.             @face_offset = @face.bitmap.width + 16
  1430.           end
  1431.         else # side
  1432.           delta = (@face.bitmap.height - self.height) / 2
  1433.           @face.y = self.y - delta
  1434.           @face_offset = 0
  1435.         end
  1436.        
  1437.         # picture x-coordinate
  1438.         if $game_system.face_graphic_justification == LEFT
  1439.           if $game_system.face_graphic_position == SIDE
  1440.             @face.x = self.x - @face.bitmap.width
  1441.           else
  1442.             @face.x = self.x + 10
  1443.           end
  1444.         else # right side
  1445.           if $game_system.animated_faces
  1446.             offset = @face.bitmap.width - $game_system.face_frame_width
  1447.           else
  1448.             offset = 0
  1449.           end
  1450.           if $game_system.face_graphic_position == SIDE
  1451.             @face.x = self.x + self.width + offset
  1452.           else
  1453.             @face.x = self.x + self.width - @face.bitmap.width - 10 + offset
  1454.             @face_offset = 0
  1455.           end
  1456.         end
  1457.        
  1458.         if $game_system.animated_faces
  1459.           @face.src_rect = Rect.new(@face_frame * $game_system.face_frame_width, 0, $game_system.face_frame_width, @face.bitmap.height)
  1460.           if @done and $game_system.resting_face != ""
  1461.             pause = $game_system.resting_animation_pause
  1462.           else
  1463.             pause = $game_system.animation_pause
  1464.           end
  1465.           if Graphics.frame_count % pause == 0
  1466.             @animate_face = true
  1467.           end
  1468.           if @animate_face
  1469.             if Graphics.frame_count % 3 == 0
  1470.               @face_frame += 1
  1471.               if @face_frame * $game_system.face_frame_width >= @face.bitmap.width
  1472.                 @face_frame = 0
  1473.                 @animate_face = false
  1474.               end
  1475.             end
  1476.           end
  1477.         end
  1478.       end
  1479.      
  1480.       # name window
  1481.       if $game_system.name != ""
  1482.         @name_window.x = self.x
  1483.         @name_window.y = self.y - 36
  1484.         @name_window.set_name($game_system.name)
  1485.       end
  1486.      
  1487.       # If choice
  1488.     if $game_temp.choice_max > 0
  1489.       @choice_window.set_choices($game_temp.choices)
  1490.       # determine x and y coords for choice window
  1491.       if $game_system.choice_justification == LEFT
  1492.         @choice_window.x = self.x
  1493.       else
  1494.         @choice_window.x = self.x + self.width - @choice_window.width
  1495.       end
  1496.       if $game_system.choice_position == ABOVE
  1497.         # check to make sure there is enough room above the textbox
  1498.         if self.y < @choice_window.height
  1499.           # not enough room above, place below
  1500.           @choice_window.y = self.y + self.height
  1501.         else
  1502.           # draw above
  1503.           @choice_window.y = self.y - @choice_window.height
  1504.         end
  1505.       elsif $game_system.choice_position == BOTTOM
  1506.         # check to make sure there is enough room below the textbox
  1507.         if (SCREEN[1] - self.y - self.height) < @choice_window.height
  1508.           # not enough room below, place above
  1509.           @choice_window.y = self.y - @choice_window.height
  1510.         else
  1511.           # draw below
  1512.           @choice_window.y = self.y + self.height
  1513.         end
  1514.       else # side
  1515.         if $game_system.choice_justification == LEFT
  1516.           # check to make sure there's room on the left side
  1517.           if self.y < @choice_window.width
  1518.             # not enough room on the side, check to make sure there's room below
  1519.             if (SCREEN[1] - self.y - self.height) < @choice_window.height
  1520.               # not enough room below, place above
  1521.               @choice_window.y = self.y - @choice_window.height
  1522.             else
  1523.               # draw below
  1524.               @choice_window.y = self.y + self.height
  1525.             end
  1526.           else
  1527.             # place on the left side
  1528.             @choice_window.y = self.y
  1529.             @choice_window.x = self.x - @choice_window.width
  1530.           end
  1531.         else # right
  1532.           # check to make sure there's room on the right side
  1533.           if (680 - (self.y + self.width)) < @choice_window.width
  1534.             # not enough room on the side, check to make sure there's room below
  1535.             if (SCREEN[1] - self.y - self.height) < @choice_window.height
  1536.               # not enough room below, place above
  1537.               @choice_window.y = self.y - @choice_window.height
  1538.             else
  1539.               # draw below
  1540.               @choice_window.y = self.y + self.height
  1541.             end
  1542.           else
  1543.             # place on the left side
  1544.             @choice_window.y = self.y
  1545.             @choice_window.x = self.x + self.width
  1546.           end
  1547.         end
  1548.       end
  1549.     end
  1550.    
  1551.     # If number input
  1552.     if $game_temp.num_input_variable_id > 0
  1553.       if @input_number_window == nil
  1554.         digits_max = $game_temp.num_input_digits_max
  1555.         number = $game_variables[$game_temp.num_input_variable_id]
  1556.         @input_number_window = Window_InputNumber.new(digits_max)
  1557.         @input_number_window.number = number
  1558.       end
  1559.       # determine x and y coords for number input window
  1560.       if $game_system.choice_justification == LEFT
  1561.         @input_number_window.x = self.x
  1562.       else
  1563.         @input_number_window.x = self.x + self.width - @input_number_window.width
  1564.       end
  1565.       if $game_system.choice_position == ABOVE
  1566.         # check to make sure there is enough room above the textbox
  1567.         if self.y < @input_number_window.height
  1568.           # not enough room above, place below
  1569.           @input_number_window.y = self.y + self.height
  1570.         else
  1571.           # draw above
  1572.           @input_number_window.y = self.y - @choice_window.height
  1573.         end
  1574.       elsif $game_system.choice_position == BOTTOM
  1575.         # check to make sure there is enough room below the textbox
  1576.         if (SCREEN[1] - self.y - self.height) < @input_number_window.height
  1577.           # not enough room below, place above
  1578.           @input_number_window.y = self.y - @input_number_window.height
  1579.         else
  1580.           # draw below
  1581.           @input_number_window.y = self.y + self.height
  1582.         end
  1583.       else # side
  1584.         if $game_system.choice_justification == LEFT
  1585.           # check to make sure there's room on the left side
  1586.           if self.y < @input_number_window.width
  1587.             # not enough room on the side, check to make sure there's room below
  1588.             if (SCREEN[1] - self.y - self.height) < @input_number_window.height
  1589.               # not enough room below, place above
  1590.               @input_number_window.y = self.y - @input_number_window.height
  1591.             else
  1592.               # draw below
  1593.               @input_number_window.y = self.y + self.height
  1594.             end
  1595.           else
  1596.             # place on the left side
  1597.             @input_number_window.y = self.y
  1598.             @input_number_window.x = self.x - @choice_window.width
  1599.           end
  1600.         else # right
  1601.           # check to make sure there's room on the right side
  1602.           if (680 - (self.y + self.width)) < @input_number_window.width
  1603.             # not enough room on the side, check to make sure there's room below
  1604.             if (SCREEN[1] - self.y - self.height) < @input_number_window.height
  1605.               # not enough room below, place above
  1606.               @input_number_window.y = self.y - @input_number_window.height
  1607.             else
  1608.               # draw below
  1609.               @input_number_window.y = self.y + self.height
  1610.             end
  1611.           else
  1612.             # place on the left side
  1613.             @input_number_window.y = self.y
  1614.             @input_number_window.x = self.x + self.width
  1615.           end
  1616.         end
  1617.       end
  1618.     end
  1619.   end
  1620.   #--------------------------------------------------------------------------
  1621.   # * Frame Update
  1622.   #--------------------------------------------------------------------------
  1623.   def update
  1624.     super
  1625.    
  1626.     if (@contents_showing and $game_system.message_event != -1 and $game_system.shake == 0) or $game_system.animated_faces
  1627.       reset_window(false)
  1628.     end
  1629.    
  1630.     if $game_system.shake != 0  # shake the window
  1631.       if @ascending
  1632.         if @target_x != self.x
  1633.           self.x += 1
  1634.         else
  1635.           @ascending = false
  1636.           @target_x = self.x - ($game_system.shake * 2)
  1637.         end
  1638.       else
  1639.         if @target_x != self.x
  1640.           self.x -= 1
  1641.         else
  1642.           @ascending = true
  1643.           @target_x = self.x + ($game_system.shake * 2)
  1644.         end
  1645.       end
  1646.     end
  1647.    
  1648.     if $game_system.text_shake != 0  # shake the text
  1649.       if @ascending
  1650.         if @target_x2 != @shake_sprite.x
  1651.           @shake_sprite.x += 1
  1652.         else
  1653.           @ascending = false
  1654.           @target_x2 = @shake_sprite.x - ($game_system.text_shake * 2)
  1655.         end
  1656.       else
  1657.         if @target_x2 != @shake_sprite.x
  1658.           @shake_sprite.x -= 1
  1659.         else
  1660.           @ascending = true
  1661.           @target_x2 = @shake_sprite.x + ($game_system.text_shake * 2)
  1662.         end
  1663.       end
  1664.     end
  1665.    
  1666.     @name_window.update
  1667.    
  1668.     if @wait > 0
  1669.       @wait -= 1
  1670.       if @wait == 0
  1671.         terminate_message
  1672.         return
  1673.       end
  1674.     end
  1675.    
  1676.     # If fade in
  1677.     if @fade_in
  1678.       if $game_temp.message_text == ""
  1679.         @fade_in = false
  1680.         return
  1681.       end
  1682.       self.contents_opacity += 24
  1683.       if $game_system.face_graphic != ""
  1684.         @face.opacity += 24
  1685.       end
  1686.       if $game_system.window_image != nil
  1687.         @window_back.opacity += 24
  1688.       end
  1689.       if $game_system.comic_enabled and $game_system.message_event != -1
  1690.         @comic.opacity = self.opacity
  1691.         @comic.visible = self.visible
  1692.       end
  1693.       @shake_sprite.visible = true
  1694.      
  1695.       if $game_system.name != "" and @show
  1696.         @name_window.visible = true
  1697.         if $game_system.name_window
  1698.           @name_window.dummy_window.visible = true
  1699.         end
  1700.       end
  1701.       if @input_number_window != nil
  1702.         @input_number_window.contents_opacity += 24
  1703.       end
  1704.       if self.contents_opacity == 255
  1705.         @fade_in = false
  1706.       end
  1707.       return
  1708.     end
  1709.    
  1710.     # write the text
  1711.     if @text != nil and @text != ""
  1712.       speed = $game_system.write_speed
  1713.       if $game_system.text_mode == ALL_AT_ONCE or $game_temp.in_battle
  1714.         while (c = @text.slice!(/./m)) != nil
  1715.           write_char(c)
  1716.         end
  1717.         $game_system.slave_windows.each_value { |window| window.write_all }
  1718.         return
  1719.       end
  1720.       if $game_system.text_skip
  1721.         if $game_system.skip_mode == WRITE_FASTER and Input.press?(Input::C)
  1722.           # the player is holding the action button, write faster
  1723.           speed /= 3
  1724.         elsif $game_system.skip_mode == WRITE_ALL and Input.trigger?(Input::C)
  1725.           # the player pressed the action button, write all the text
  1726.           while (c = @text.slice!(/./m)) != nil
  1727.             write_char(c)
  1728.           end
  1729.           $game_system.slave_windows.each_value { |window| window.write_all }
  1730.           return
  1731.         end
  1732.       end
  1733.       while @ignore
  1734.         c = @text.slice!(/./m)
  1735.         if c != nil
  1736.           write_char(c)
  1737.         end
  1738.       end
  1739.       if @pause_time > 0
  1740.         @pause_time -= 1
  1741.         return
  1742.       end
  1743.       if Graphics.frame_count - @count >= speed
  1744.         if $game_system.sound_effect != ""
  1745.           Audio.se_play("Audio/SE/" + $game_system.sound_effect, 80, 100)
  1746.         end
  1747.         @count = Graphics.frame_count
  1748.         c = @text.slice!(/./m)
  1749.         if c != nil
  1750.           write_char(c)
  1751.         end
  1752.       end
  1753.       return
  1754.     end
  1755.    
  1756.     if $game_system.animated_faces and $game_system.resting_face != ""
  1757.       @done = true
  1758.     end
  1759.    
  1760.     # If inputting number
  1761.     if @input_number_window != nil
  1762.       @input_number_window.update
  1763.       # Confirm
  1764.       if Input.trigger?(Input::C)
  1765.         $game_system.se_play($data_system.decision_se)
  1766.         $game_variables[$game_temp.num_input_variable_id] =
  1767.           @input_number_window.number
  1768.         $game_map.need_refresh = true
  1769.         # Dispose of number input window
  1770.         @input_number_window.dispose
  1771.         @input_number_window = nil
  1772.         terminate_message
  1773.       end
  1774.       return
  1775.     end
  1776.    
  1777.     if @wait != 0
  1778.       return
  1779.     end
  1780.    
  1781.     # If message is being displayed and contents are all written
  1782.     if @contents_showing
  1783.       # if choice
  1784.       if $game_temp.choice_max > 0
  1785.         if !@choice_window.active
  1786.           @choice_window.visible = true
  1787.           @choice_window.active = true
  1788.           @choice_window.index = 0
  1789.         end
  1790.         @choice_window.update
  1791.       else
  1792.         # If choice isn't being displayed, show pause sign
  1793.         self.pause = $game_system.show_pause
  1794.       end
  1795.         # Cancel
  1796.         if Input.trigger?(Input::B)
  1797.           if $game_temp.choice_max > 0 and $game_temp.choice_cancel_type > 0
  1798.             $game_system.se_play($data_system.cancel_se)
  1799.             $game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
  1800.             terminate_message
  1801.           end
  1802.         end
  1803.         # Confirm
  1804.         if Input.trigger?(Input::C) and !(@wait > 0)
  1805.           @done = true
  1806.           $game_system.slave_windows.each_value { |window|
  1807.             window.write_all
  1808.             if !window.done
  1809.               @done = false
  1810.             end
  1811.           }
  1812.           if @done
  1813.             if $game_temp.choice_max > 0
  1814.               $game_system.se_play($data_system.decision_se)
  1815.               $game_temp.choice_proc.call(@choice_window.index)
  1816.             end
  1817.             terminate_message
  1818.           else
  1819.             @finishing_up = true
  1820.           end
  1821.         end
  1822.         return
  1823.       end
  1824.      
  1825.     if @finishing_up
  1826.       $game_system.slave_windows.each_value { |window|
  1827.         if !window.done
  1828.           @done = true
  1829.           break
  1830.         end
  1831.       }
  1832.      
  1833.       if @done = false
  1834.         terminate_message
  1835.       end
  1836.     end
  1837.     # If display wait message or choice exists when not fading out
  1838.     if @fade_out == false and $game_temp.message_text != nil
  1839.       @contents_showing = true
  1840.       $game_temp.message_window_showing = true
  1841.      
  1842.       reset_window
  1843.       refresh
  1844.       Graphics.frame_reset
  1845.       if @show
  1846.         self.visible = true
  1847.       end
  1848.       self.contents_opacity = 0
  1849.       if @input_number_window != nil
  1850.         @input_number_window.contents_opacity = 0
  1851.       end
  1852.       @fade_in = true
  1853.       return
  1854.     end
  1855.     # If message which should be displayed is not shown, but window is visible
  1856.     if self.visible
  1857.       @fade_out = true
  1858.       self.opacity -= 48
  1859.       @name_window.opacity -= 48
  1860.       @shake_sprite.opacity -= 48
  1861.       @comic.opacity -= 48
  1862.       @face.opacity -= 48
  1863.       @window_back.opacity -= 48
  1864.       if self.opacity == 0
  1865.         self.visible = false
  1866.         @face.opacity = 0
  1867.         @window_back.opacity = 0
  1868.         @choice_window.visible = false
  1869.         @choice_window.active = false
  1870.         @comic.opacity = 0
  1871.         @name_window.visible = false
  1872.         @shake_sprite.bitmap.clear
  1873.         @shake_sprite.opacity = 255
  1874.         @name_window.dummy_window.visible = false
  1875.         @name_window.update
  1876.         @fade_out = false
  1877.         $game_temp.message_window_showing = false
  1878.       end
  1879.       return
  1880.     end
  1881.    
  1882.     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
  1883.      
  1884.         $game_system.indy_windows.each_pair {|name, window|
  1885.           if window.show == true
  1886.             window.dispose
  1887.             $game_system.indy_windows.delete(name)
  1888.           end
  1889.         }
  1890.     end
  1891.   end
  1892.  
  1893.   #--------------------------------------------------------------------------
  1894.   # * Process and write the given character
  1895.   #--------------------------------------------------------------------------
  1896.   def write_char(c)
  1897.     if c == "\000"
  1898.       # Return to original text
  1899.       c = "\\"
  1900.     end
  1901.     # If \C[n]
  1902.     if c == "\001"
  1903.     # Change text color
  1904.       @text.sub!(/\[([0-9]+)\]/, "")
  1905.       color = $1.to_i
  1906.       if color >= 0 and color <= 7
  1907.         self.contents.font.color = text_color(color)
  1908.       end
  1909.       # go to next text
  1910.       return
  1911.     end
  1912.     # If \G
  1913.     if c == "\002"
  1914.       # Make gold window
  1915.       if @gold_window == nil
  1916.         @gold_window = Window_Gold.new
  1917.         @gold_window.x = 560 - @gold_window.width
  1918.         if $game_temp.in_battle
  1919.           @gold_window.y = 192
  1920.         else
  1921.           @gold_window.y = self.y >= 128 ? 32 : 384
  1922.         end
  1923.         @gold_window.opacity = self.opacity
  1924.         @gold_window.back_opacity = self.back_opacity
  1925.       end
  1926.       # go to next text
  1927.       return
  1928.     end
  1929.     # If \skip
  1930.     if c == "\003"
  1931.       # toggle text skipping
  1932.       $game_system.text_skip = !$game_system.text_skip
  1933.       # go to next text
  1934.       return
  1935.     end
  1936.     # If \b
  1937.     if c == "\004"
  1938.       # toggle bold
  1939.       self.contents.font.bold = !self.contents.font.bold
  1940.       # go to next text
  1941.       return
  1942.     end
  1943.     # If \i
  1944.     if c == "\005"
  1945.       # toggle italics
  1946.       self.contents.font.italic = !self.contents.font.italic
  1947.       # go to next text
  1948.       return
  1949.     end
  1950.     # If \s
  1951.     if c == "\006"
  1952.       # toggle shadow
  1953.       $game_system.shadowed_text = !$game_system.shadowed_text
  1954.       # go to next text
  1955.       return
  1956.     end
  1957.     # If \font
  1958.     if c == "\007"
  1959.       # change font
  1960.       @text.sub!(/\[(.*?)\]/, "")
  1961.       font = $1.to_s
  1962.       $game_system.font = font
  1963.       if font == ""
  1964.         self.contents.font.name = Font.default_name
  1965.       else
  1966.         self.contents.font.name = font
  1967.       end
  1968.       # go to next text
  1969.       return
  1970.     end
  1971.     # If \p[n]
  1972.     if c == "\010"
  1973.       @text.sub!(/\[([0-9]+)\]/, "")
  1974.       @pause_time = $1.to_i
  1975.  
  1976.       # go to next text
  1977.       return
  1978.     end
  1979.    
  1980.     # If \w[n]
  1981.     if c == "\011"
  1982.       @text.sub!(/\[([0-9]+)\]/, "")
  1983.       @wait = $1.to_i
  1984.  
  1985.       # go to next text
  1986.       return
  1987.     end
  1988.    
  1989.     # If \ws[n]
  1990.     if c == "\013"
  1991.       @text.sub!(/\[([0-9]+)\]/, "")
  1992.       $game_system.write_speed = $1.to_i
  1993.  
  1994.       # go to next text
  1995.       return
  1996.     end
  1997.     # If \oa[n]
  1998.     if c == "\014"
  1999.       @text.sub!(/\[([0-9]+)\]/, "")
  2000.       index = $1.to_i
  2001.       @text.sub!("  ", "")
  2002.       item = $data_armors[index]
  2003.       # draw the icon
  2004.       icon = RPG::Cache.icon(item.icon_name)
  2005.       line = self.contents.text_size("dj").height
  2006.       self.contents.blt(@x + 4, (@y * line) + 4, icon, Rect.new(0, 0, 24, 24))
  2007.       @x += 24
  2008.  
  2009.       # go to next text
  2010.       return
  2011.     end
  2012.    
  2013.     # If \oi[n]
  2014.     if c == "\015"
  2015.       @text.sub!(/\[([0-9]+)\]/, "")
  2016.       index = $1.to_i
  2017.       @text.sub!("  ", "")
  2018.       item = $data_items[index]
  2019.       # draw the icon
  2020.       icon = RPG::Cache.icon(item.icon_name)
  2021.       line = self.contents.text_size("dj").height
  2022.       self.contents.blt(@x + 4, (@y * line) + 4, icon, Rect.new(0, 0, 24, 24))
  2023.       @x += 24
  2024.  
  2025.       # go to next text
  2026.       return
  2027.     end
  2028.    
  2029.     # If \ic[name]
  2030.     if c == "\027"
  2031.       @text.sub!(/\[(.*?)\]/, "")
  2032.       # draw the icon
  2033.       icon = RPG::Cache.icon($1.to_s)
  2034.       line = self.contents.text_size("dj").height
  2035.       self.contents.blt(@x + 4, (@y * line) + 4, icon, Rect.new(0, 0, 24, 24))
  2036.       @x += 24
  2037.  
  2038.       # go to next text
  2039.       return
  2040.     end
  2041.    
  2042.     # If \os[n]
  2043.     if c == "\016"
  2044.       @text.sub!(/\[([0-9]+)\]/, "")
  2045.       index = $1.to_i
  2046.       @text.sub!("  ", "")
  2047.       item = $data_skills[index]
  2048.       # draw the icon
  2049.       icon = RPG::Cache.icon(item.icon_name)
  2050.       line = self.contents.text_size("dj").height
  2051.       self.contents.blt(@x + 2, (@y * line) + 4, icon, Rect.new(0, 0, 24, 24))
  2052.       @x += 24
  2053.  
  2054.       # go to next text
  2055.       return
  2056.     end
  2057.    
  2058.     # If \ow[n]
  2059.     if c == "\017"
  2060.       @text.sub!(/\[([0-9]+)\]/, "")
  2061.       index = $1.to_i
  2062.       @text.sub!("  ", "")
  2063.       item = $data_weapons[index]
  2064.       # draw the icon
  2065.       icon = RPG::Cache.icon(item.icon_name)
  2066.       line = self.contents.text_size("dj").height
  2067.       self.contents.blt(@x + 2, (@y * line) + 4, icon, Rect.new(0, 0, 24, 24))
  2068.       @x += 24
  2069.      
  2070.       # go to next text
  2071.       return
  2072.     end
  2073.    
  2074.     # If \tc
  2075.     if c == "\020"
  2076.       # center justify
  2077.       $game_system.text_justification = CENTER
  2078.       get_x_value
  2079.       # go to next text
  2080.       return
  2081.     end
  2082.    
  2083.     # If \tl
  2084.     if c == "\021"
  2085.       # left justify
  2086.       $game_system.text_justification = LEFT
  2087.       get_x_value
  2088.       # go to next text
  2089.       return
  2090.     end
  2091.    
  2092.     # If \tr
  2093.     if c == "\022"
  2094.       # right justify
  2095.       $game_system.text_justification = RIGHT
  2096.       get_x_value
  2097.       # go to next text
  2098.       return
  2099.     end
  2100.    
  2101.     # If \ignr
  2102.     if c == "\023"
  2103.       # set ignore flage
  2104.       @ignore = true
  2105.       # go to next text
  2106.       return
  2107.     end
  2108.    
  2109.     # if \slv
  2110.     if c == "\024"
  2111.       # we need to show a slave window
  2112.       @text.sub!(/\[(.*?)\]/, "")
  2113.       name = $1.to_s
  2114.       $game_system.slave_windows[name].show = true
  2115.       return
  2116.     end
  2117.    
  2118.     # if \ind
  2119.     if c == "\025"
  2120.       # we need to show a independent window
  2121.       @text.sub!(/\[(.*?)\]/, "")
  2122.       name = $1.to_s
  2123.       if $game_system.indy_windows[name].show
  2124.         $game_system.indy_windows[name].dispose
  2125.         $game_system.indy_windows.delete(name)
  2126.       else
  2127.         $game_system.indy_windows[name].show = true
  2128.       end
  2129.       return
  2130.     end
  2131.    
  2132.     # if \c (hex color)
  2133.     if c == "\026"
  2134.       # convert hex color to RGB
  2135.       @text.sub!(/\[([0123456789abcdef]+)\]/, "")
  2136.       hex_code = $1.to_s
  2137.      
  2138.       red   = ("0x" + hex_code.slice(0..1)).hex
  2139.       blue  = ("0x" + hex_code.slice(2..3)).hex
  2140.       green = ("0x" + hex_code.slice(4..5)).hex
  2141.      
  2142.       self.contents.font.color = Color.new(red, blue, green)
  2143.       return
  2144.     end
  2145.    
  2146.     # if \sk[i] (begin shake)
  2147.     if c == "\030"
  2148.       @shake_text = true
  2149.       return
  2150.     end
  2151.     # if \sk (end shake)
  2152.     if c == "\031"
  2153.       @shake_text = false
  2154.       return
  2155.     end
  2156.    
  2157.     # If new line text
  2158.     if c == "\n"
  2159.       # Add 1 to y
  2160.       if !@ignore
  2161.         @y += 1
  2162.       end
  2163.       # check for scroll
  2164.       line = self.contents.text_size("dj").height
  2165.       if @y * line + 2 > self.height - 32 - line and @text.slice(/./m) != nil
  2166.         self.oy += line
  2167.       end
  2168.       if @text != ""
  2169.         get_x_value
  2170.       end
  2171.       @ignore = false
  2172.  
  2173.       # go to next text
  2174.       return
  2175.     end
  2176.     if @ignore
  2177.       return
  2178.     end
  2179.     # Draw text
  2180.     line = self.contents.text_size("dj").height
  2181.     if $game_system.shadowed_text
  2182.       old_color = self.contents.font.color.clone
  2183.       if @shake_text
  2184.         @shake_sprite.bitmap.font.color = $game_system.shadow_color    
  2185.         @shake_sprite.bitmap.draw_text(6 + @x, line * @y + 2, 40, 32, c)
  2186.         @shake_sprite.bitmap.font.color = old_color
  2187.       else
  2188.         self.contents.font.color = $game_system.shadow_color    
  2189.         self.contents.draw_text(6 + @x, line * @y + 2, 40, 32, c)
  2190.         self.contents.font.color = old_color
  2191.       end
  2192.     end
  2193.     if @shake_text
  2194.       @shake_sprite.bitmap.draw_text(4 + @x, line * @y, 40, 32, c)
  2195.     else
  2196.       self.contents.draw_text(4 + @x, line * @y, 40, 32, c)
  2197.     end
  2198.     # Add x to drawn text width
  2199.     @x += self.contents.text_size(c).width
  2200.   end
  2201.  
  2202.   def get_x_value
  2203.     # text justification - offset for first line
  2204.     if $game_system.text_justification == CENTER
  2205.       # get the length of the current line
  2206.       w = self.contents.text_size(@text.split("\n")[0]).width
  2207.       @x = (self.width - w - 48) / 2
  2208.     elsif $game_system.text_justification == RIGHT
  2209.       # get the length of the current line
  2210.       w = self.contents.text_size(@text.split("\n")[0]).width
  2211.       @x = self.width - w - 48
  2212.     else # left
  2213.       if $game_system.face_graphic == ""
  2214.         @x = 0
  2215.       else
  2216.         @x = @face_offset
  2217.       end
  2218.     end
  2219.   end
  2220.    
  2221. end
  2222.  
  2223. #==============================================================================
  2224. # ** Window_Choice
  2225. #------------------------------------------------------------------------------
  2226. #  This message window is used to display choices.
  2227. #==============================================================================
  2228. class Window_Choice < Window_Selectable
  2229.   def initialize (choices)
  2230.     super(0, 0, 32, choices.size * 32)
  2231.     self.visible = false
  2232.     self.active = false
  2233.     self.z = 9999
  2234.     @index = 0
  2235.     @item_max = choices.size
  2236.     @choices = choices
  2237.     self.contents = Bitmap.new(32, 32)
  2238.     self.opacity = $game_system.opacity
  2239.     self.back_opacity = $game_system.back_opacity
  2240.   end
  2241.  
  2242.   def refresh
  2243.     # determine necessary width
  2244.     width = 64
  2245.     for line in @choices
  2246.       width = [width, (self.contents.text_size(line).width + 48)].max
  2247.     end
  2248.     self.width = width
  2249.     self.height = @choices.size * 32 + 32
  2250.     self.contents = Bitmap.new(width - 32, height - 32)
  2251.     if $game_system.font == ""
  2252.       self.contents.font.name = Font.default_name
  2253.     else
  2254.       self.contents.font.name = $game_system.font
  2255.     end
  2256.     if $game_system.font_color.nil?
  2257.       self.contents.font.color = normal_color
  2258.     else
  2259.       self.contents.font.color = $game_system.font_color
  2260.     end
  2261.     if $game_system.windowskin != ""  
  2262.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin)
  2263.     else
  2264.       self.windowskin = RPG::Cache.windowskin($data_system.windowskin_name)
  2265.     end
  2266.    
  2267.     # draw choices
  2268.     @y = 0
  2269.     for line in @choices
  2270.       @x = 0
  2271.       @text = line
  2272.       while (c = line.slice!(/./m)) != nil
  2273.         write_char(c)
  2274.       end
  2275.       @y += 1
  2276.     end
  2277.   end
  2278.  
  2279.   def write_char(c)
  2280.    
  2281.     # If \oa[n]
  2282.     if c == "\014"
  2283.       @text.sub!(/\[([0-9]+)\]/, "")
  2284.       index = $1.to_i
  2285.       @text.sub!("  ", "")
  2286.       item = $data_armors[index]
  2287.       # draw the icon
  2288.       icon = RPG::Cache.icon(item.icon_name)
  2289.       self.contents.blt(@x + 4, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  2290.       @x += 24
  2291.     end
  2292.    
  2293.     # If \oi[n]
  2294.     if c == "\015"
  2295.       @text.sub!(/\[([0-9]+)\]/, "")
  2296.       index = $1.to_i
  2297.       @text.sub!("  ", "")
  2298.       item = $data_items[index]
  2299.       # draw the icon
  2300.       icon = RPG::Cache.icon(item.icon_name)
  2301.       self.contents.blt(@x + 4, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  2302.       @x += 24
  2303.  
  2304.       # go to next text
  2305.       return
  2306.     end
  2307.    
  2308.     # If \ic[name]
  2309.     if c == "\027"
  2310.       @text.sub!(/\[(.*?)\]/, "")
  2311.       # draw the icon
  2312.       icon = RPG::Cache.icon($1.to_s)
  2313.       self.contents.blt(@x + 4, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  2314.       @x += 24
  2315.  
  2316.       # go to next text
  2317.       return
  2318.     end
  2319.    
  2320.     # If \os[n]
  2321.     if c == "\016"
  2322.       @text.sub!(/\[([0-9]+)\]/, "")
  2323.       index = $1.to_i
  2324.       @text.sub!("  ", "")
  2325.       item = $data_skills[index]
  2326.       # draw the icon
  2327.       icon = RPG::Cache.icon(item.icon_name)
  2328.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  2329.       @x += 24
  2330.  
  2331.       # go to next text
  2332.       return
  2333.     end
  2334.    
  2335.     # If \ow[n]
  2336.     if c == "\017"
  2337.       @text.sub!(/\[([0-9]+)\]/, "")
  2338.       index = $1.to_i
  2339.       @text.sub!("  ", "")
  2340.       item = $data_weapons[index]
  2341.       # draw the icon
  2342.       icon = RPG::Cache.icon(item.icon_name)
  2343.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  2344.       @x += 24
  2345.      
  2346.       # go to next text
  2347.       return
  2348.     end
  2349.    
  2350.     # If \ic[name]
  2351.     if c == "\027"
  2352.       @text.sub!(/\[(.*?)\]/, "")
  2353.       # draw the icon
  2354.       icon = RPG::Cache.icon($1.to_s)
  2355.       self.contents.blt(@x + 4, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  2356.       @x += 24
  2357.  
  2358.       # go to next text
  2359.       return
  2360.     end
  2361.    
  2362.     # If \C[n]
  2363.     if c == "\001"
  2364.     # Change text color
  2365.       @text.sub!(/\[([0-9]+)\]/, "")
  2366.       color = $1.to_i
  2367.       if color >= 0 and color <= 7
  2368.         self.contents.font.color = text_color(color)
  2369.       end
  2370.       # go to next text
  2371.       return
  2372.     end
  2373.    
  2374.     # if \c (hex color)
  2375.     if c == "\026"
  2376.       # convert hex color to RGB
  2377.       @text.sub!(/\[([0123456789abcdef]+)\]/, "")
  2378.       hex_code = $1.to_s
  2379.      
  2380.       red   = ("0x" + hex_code.slice(0..1)).hex
  2381.       blue  = ("0x" + hex_code.slice(2..3)).hex
  2382.       green = ("0x" + hex_code.slice(4..5)).hex
  2383.      
  2384.       self.contents.font.color = Color.new(red, blue, green)
  2385.       return
  2386.     end
  2387.    
  2388.     # Draw text
  2389.     line = 32
  2390.     if $game_system.shadowed_text
  2391.       old_color = self.contents.font.color.clone
  2392.       self.contents.font.color = $game_system.shadow_color    
  2393.       self.contents.draw_text(6 + @x, line * @y + 2, 40, 32, c)
  2394.       self.contents.font.color = old_color
  2395.     end
  2396.     self.contents.draw_text(4 + @x, line * @y, 40, 32, c)
  2397.     # Add x to drawn text width
  2398.     @x += self.contents.text_size(c).width
  2399.   end
  2400.      
  2401.   def set_choices(choices)
  2402.     @choices = Array.new
  2403.     for choice in choices
  2404.       @choices.push(choice.clone)
  2405.     end
  2406.     @item_max = @choices.size
  2407.     for choice in choices
  2408.       # variables
  2409.       choice.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  2410.      
  2411.       # actor names
  2412.       choice.gsub!(/\\[Nn]\[([0-9]+)\]/) {
  2413.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  2414.       }
  2415.       choice.gsub!(/\\[Nn][Pp]\[([0-9]+)\]/) {
  2416.         $game_party.actors[$1.to_i] != nil ? $game_party.actors[$1.to_i].name : ""
  2417.       }
  2418.      
  2419.       # armor, items, skills, and weapons
  2420.       choice.gsub!(/\\[Oo][Aa]\[([0-9]+)\]/) {
  2421.         item = $data_armors[$1.to_i]
  2422.         "\014[#{$1}]" + "  " + item.name
  2423.       }
  2424.       choice.gsub!(/\\[Oo][Ii]\[([0-9]+)\]/) {
  2425.         item = $data_items[$1.to_i]
  2426.         "\015[#{$1}]" + "  " + item.name
  2427.       }
  2428.       choice.gsub!(/\\[Oo][Ss]\[([0-9]+)\]/) {
  2429.         item = $data_skills[$1.to_i]
  2430.         "\016[#{$1}]" + "  " + item.name
  2431.       }
  2432.       choice.gsub!(/\\[Oo][Ww]\[([0-9]+)\]/) {
  2433.         item = $data_weapons[$1.to_i]
  2434.         "\017[#{$1}]" + "  " + item.name
  2435.       }
  2436.       choice.gsub!(/\\[Ii][Cc]\[(.*?)\]/) {
  2437.         "\027[#{$1}]"
  2438.       }
  2439.      
  2440.       # color
  2441.       choice.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  2442.       choice.gsub!(/\\[Cc]\[0x([0123456789abcdef]+)\]/) { "\026[#{$1}]" }
  2443.      
  2444.     end
  2445.     refresh
  2446.   end
  2447. end
  2448.  
  2449. #==============================================================================
  2450. # ** Window_Name
  2451. #------------------------------------------------------------------------------
  2452. #  This window is used to display names above the message window.  Uncomment
  2453. #   and modify the various sections to customize.
  2454. #==============================================================================
  2455. class Window_Name < Window_Base
  2456.   attr_accessor :dummy_window
  2457.  
  2458.   def initialize
  2459.     super(0, 0, 32, 64)
  2460.     self.contents = Bitmap.new(32, 32)
  2461.     self.opacity = 0
  2462.    
  2463.    
  2464.     @dummy_window = Window_Dummy.new
  2465.    
  2466.     self.visible = false
  2467.   end
  2468.  
  2469.   def set_name(name)
  2470.     @name = name
  2471.     refresh
  2472.   end
  2473.  
  2474.   def refresh
  2475.     if @name == nil
  2476.       return
  2477.     end
  2478.     self.width = self.contents.text_size(@name).width + 48
  2479.     self.contents = Bitmap.new(width - 32, height - 32)
  2480.    
  2481.    
  2482.     if $game_system.name_window
  2483.       @dummy_window.x = self.x
  2484.       @dummy_window.y = self.y + 12
  2485.       @dummy_window.set(height - 24, width - 12)
  2486.     end
  2487.    
  2488.     if $game_system.font == ""
  2489.       self.contents.font.name = Font.default_name
  2490.     else
  2491.       self.contents.font.name = $game_system.font
  2492.     end
  2493.     # uncomment this and change the font to give the name window a fancy font
  2494.     #self.contents.font.name = "Ariel"
  2495.     self.contents.font.color = Color.new(0, 0, 0, 255)
  2496.     self.contents.draw_text(0, 0, self.width, 32, @name)
  2497.     self.contents.draw_text(0, 2, self.width, 32, @name)
  2498.     self.contents.draw_text(2, 0, self.width, 32, @name)
  2499.     self.contents.draw_text(2, 2, self.width, 32, @name)
  2500.     # change the color to give the name window a seperate color
  2501.     self.contents.font.color = normal_color
  2502.     self.contents.draw_text(1, 1, self.width, 32, @name)
  2503.   end
  2504.  
  2505.   def visible=(v)
  2506.     if $game_system.name_window
  2507.       @dummy_window.visible = v
  2508.     end
  2509.     super(v)
  2510.   end
  2511.  
  2512.  
  2513.  
  2514.   def update
  2515.     super
  2516.     if $game_system.name_window
  2517.       @dummy_window.x = self.x
  2518.       @dummy_window.y = self.y + 12
  2519.       @dummy_window.update
  2520.     end
  2521.   end
  2522.  
  2523.   def dispose
  2524.     @dummy_window.dispose
  2525.     super
  2526.   end
  2527. end
  2528.  
  2529. class Window_Dummy < Window_Base
  2530.   def initialize
  2531.     super(0, 0, 32, 64)
  2532.     self.z = 9999
  2533.     self.visible = false
  2534.    
  2535.   end
  2536.  
  2537.   def set(height, width)
  2538.     self.height = height
  2539.     self.width = width
  2540.   end
  2541.  
  2542.   def update
  2543.     super
  2544.     if $game_system.windowskin != ""  
  2545.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin)
  2546.     else
  2547.       self.windowskin = RPG::Cache.windowskin($data_system.windowskin_name)
  2548.     end
  2549. #    self.windowskin = RPG::Cache.windowskin('sandstone')
  2550.   end
  2551. end
  2552.  
  2553. #==============================================================================
  2554. # ** Window_Slave
  2555. #------------------------------------------------------------------------------
  2556. #  These are slave windows to the main message window.  They will close when
  2557. #   the user terminates them.  Initial settings are identical to the main
  2558. #   message window, with one exception.  When in normal mode, it will apear
  2559. #   above if the main message is below, below if it is above or centered.  Use
  2560. #   message codes to change the settings for this window.
  2561. #==============================================================================
  2562. class Window_Slave < Window_Base
  2563.   attr_accessor :show
  2564.   attr_reader :done
  2565.  
  2566.   def write_all
  2567.     @write_all = true
  2568.   end
  2569.  
  2570.   #--------------------------------------------------------------------------
  2571.   # * Object Initialization
  2572.   #--------------------------------------------------------------------------
  2573.   def initialize (text)
  2574.     super(0, 0, 33, 33)
  2575.     @text = text
  2576.    
  2577.     # x-coordinate depends on justification
  2578.     if @justification == RIGHT
  2579.       self.x = SCREEN[0] - self.width
  2580.     elsif @justification == LEFT
  2581.       self.x = 0
  2582.     else # center
  2583.       self.x = (SCREEN[0] - self.width) / 2
  2584.     end
  2585.     # y-coordinate depends on height
  2586.     self.y = SCREEN[1] - $game_system.window_height - 16
  2587.     self.contents = Bitmap.new(width - 32, height - 32)
  2588.     if $game_system.font == ""
  2589.       self.contents.font.name = Font.default_name
  2590.     else
  2591.       self.contents.font.name = $game_system.font
  2592.     end
  2593.     self.visible = false
  2594.     self.z = 9998
  2595.     @fade_in = false
  2596.     @fade_out = false
  2597.     @contents_showing = false
  2598.    
  2599.     # face graphic sprite
  2600.     @face = Sprite.new
  2601.     @face.opacity = 0
  2602.     @face.z = self.z + 1
  2603.     @face_offset = 0
  2604.    
  2605.     # choice window
  2606.     @choice_window = Window_Choice.new([])
  2607.     @choice_window.back_opacity = $game_system.back_opacity
  2608.    
  2609.     @comic_style = $game_system.comic_style
  2610.     @name = $game_system.name
  2611.    
  2612.     # comic sprite
  2613.     @comic = Sprite.new
  2614.     @comic.opacity = 0
  2615.     @comic.z = self.z + 1
  2616.     if @comic_style == TALK1
  2617.       @comic.bitmap = RPG::Cache.windowskin("talk1")
  2618.     elsif @comic_style == TALK2
  2619.       @comic.bitmap = RPG::Cache.windowskin("talk2")
  2620.     else # thought
  2621.       @comic.bitmap = RPG::Cache.windowskin("thought")
  2622.     end
  2623.    
  2624.     # shake bitmaps
  2625.     @shake_sprite = Sprite.new
  2626.     @shake_sprite.bitmap = Bitmap.new(width - 32, height - 32)
  2627.     @shake_sprite.x = self.x + 16
  2628.     @shake_sprite.y = self.y + 8
  2629.     @shake_sprite.z = self.z + 1
  2630.    
  2631.     @pause_time = 0
  2632.     @wait = 0
  2633.    
  2634.     @mode = $game_system.ums_mode
  2635.     self.height = $game_system.window_height
  2636.     self.width = $game_system.window_width
  2637.     @justification = $game_system.window_justification
  2638.     @face_graphic = $game_system.face_graphic
  2639.     @face_graphic_justification = $game_system.face_graphic_justification
  2640.     @message_event = $game_system.message_event
  2641.     if $game_system.message_position == 2 # down
  2642.       @message_position = 0
  2643.     else
  2644.       @message_postion = 2
  2645.     end
  2646.     @face_graphic_position = $game_system.face_graphic_position
  2647.     if $game_system.font == ""
  2648.       @font = Font.default_name
  2649.     else
  2650.       @font = $game_system.font
  2651.     end
  2652.     @text_justification = $game_system.text_justification
  2653.    
  2654.     @shake = $game_system.shake
  2655.    
  2656.     @face_frame = 0
  2657.    
  2658.     refresh
  2659.   end
  2660.   #--------------------------------------------------------------------------
  2661.   # * Dispose
  2662.   #--------------------------------------------------------------------------
  2663.   def dispose
  2664.     terminate_message
  2665.     $game_temp.message_window_showing = false
  2666.     if @input_number_window != nil
  2667.       @input_number_window.dispose
  2668.     end
  2669.     @face.dispose
  2670.     @choice_window.dispose
  2671.     @comic.dispose
  2672.     @shake_sprite.dispose
  2673.     if @name_window != nil
  2674.       @name_window.dispose
  2675.     end
  2676.     super
  2677.   end
  2678.   #--------------------------------------------------------------------------
  2679.   # * Terminate Message
  2680.   #--------------------------------------------------------------------------
  2681.   def terminate_message
  2682.     self.active = false
  2683.     self.pause = false
  2684.     self.contents.clear
  2685.     # Clear showing flag
  2686.     @contents_showing = false
  2687.     # Call message callback
  2688.     if $game_temp.message_proc != nil
  2689.       $game_temp.message_proc.call
  2690.     end
  2691.     # Clear variables related to text, choices, and number input
  2692.     $game_temp.message_text = nil
  2693.     $game_temp.message_proc = nil
  2694.     $game_temp.choice_start = 99
  2695.     $game_temp.choice_max = 0
  2696.     $game_temp.choice_cancel_type = 0
  2697.     $game_temp.choice_proc = nil
  2698.     $game_temp.num_input_start = 99
  2699.     $game_temp.num_input_variable_id = 0
  2700.     $game_temp.num_input_digits_max = 0
  2701.     # Open gold window
  2702.     if @gold_window != nil
  2703.       @gold_window.dispose
  2704.       @gold_window = nil
  2705.     end
  2706.     @choice_window.visible = false
  2707.     @choice_window.active = false
  2708.     @comic.opacity = 0
  2709.   end
  2710.   #--------------------------------------------------------------------------
  2711.   # * Refresh
  2712.   #--------------------------------------------------------------------------
  2713.   def refresh
  2714.    
  2715.     self.contents.clear
  2716.     if $game_system.font_color.nil?
  2717.       self.contents.font.color = normal_color
  2718.     else
  2719.       self.contents.font.color = $game_system.font_color
  2720.     end
  2721.     if $game_system.windowskin != ""  
  2722.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin)
  2723.     else
  2724.       self.windowskin = RPG::Cache.windowskin($data_system.windowskin_name)
  2725.     end
  2726.     @x = @y = 0
  2727.  
  2728.     # If waiting for a message to be displayed
  2729.     if @text != nil
  2730.       # replace shortcuts with original code
  2731.       $game_system.shortcuts.each { |shortcut, code|
  2732.         @text.gsub!(shortcut, code)
  2733.       }
  2734.      
  2735.       # Control text processing
  2736.       begin
  2737.         last_text = @text.clone
  2738.         @text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  2739.       end until @text == last_text
  2740.       @text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  2741.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  2742.       end
  2743.      
  2744.       # window mode
  2745.       if @text.index(/\\[Mm]/) != nil
  2746.         if $game_system.ums_mode == NORMAL_MODE
  2747.           @mode = FIT_WINDOW_TO_TEXT
  2748.         else
  2749.           @mode = NORMAL_MODE
  2750.         end
  2751.         @text.gsub!(/\\[Mm]/) { "" }
  2752.       end
  2753.      
  2754.       # window height
  2755.       @text.gsub!(/\\[Hh][Ee][Ii][Gg][Hh][Tt]\[([0-9]+)\]/) do
  2756.         self.height = $1.to_i
  2757.         ""
  2758.       end
  2759.      
  2760.       # window width
  2761.       @text.gsub!(/\\[Ww][Ii][Dd][Tt][Hh]\[([0-9]+)\]/) do
  2762.         self.width = $1.to_i
  2763.         ""
  2764.       end
  2765.      
  2766.       # justification
  2767.       @text.gsub!(/\\[Jj][Rr]/) do
  2768.         @justification = RIGHT
  2769.         reset_window
  2770.         ""
  2771.       end
  2772.       @text.gsub!(/\\[Jj][Cc]/) do
  2773.         @justification = CENTER
  2774.         reset_window
  2775.         ""
  2776.       end      
  2777.       @text.gsub!(/\\[Jj][Ll]/) do
  2778.         @justification = LEFT
  2779.         reset_window
  2780.         ""
  2781.       end
  2782.      
  2783.       # face graphics
  2784.       @text.gsub!(/\\[Ff][Aa][Cc][Ee]\[(.*?)\]/) do
  2785.         @face_graphic = $1.to_s
  2786.         if $1.to_s == ""
  2787.           @face.opacity = 0
  2788.         end
  2789.         ""
  2790.       end
  2791.       @text.gsub!(/\\[Ff][Ll]/) do
  2792.         @face_graphic_justification = LEFT
  2793.         ""
  2794.       end
  2795.       @text.gsub!(/\\[Ff][Rr]/) do
  2796.         @face_graphic_justification = RIGHT
  2797.         ""
  2798.       end
  2799.      
  2800.       # event centering
  2801.       @text.gsub!(/\\[Ee]\[([0-9]+)\]/) do
  2802.         @message_event = $1.to_i
  2803.         ""
  2804.       end
  2805.      
  2806.       # comic thingy
  2807.       @text.gsub!(/\\[Tt]1/) do
  2808.         @comic_style = TALK1
  2809.         @comic.bitmap = RPG::Cache.windowskin("talk1.png")
  2810.         ""
  2811.       end
  2812.       @text.gsub!(/\\[Tt]2/) do
  2813.         @comic_style = TALK2
  2814.         @comic.bitmap = RPG::Cache.windowskin("talk2.png")
  2815.         ""
  2816.       end
  2817.       @text.gsub!(/\\[Tt][Hh]/) do
  2818.         @comic_style = THOUGHT
  2819.         @comic.bitmap = RPG::Cache.windowskin("thought.png")
  2820.         ""
  2821.       end
  2822.      
  2823.       # name window
  2824.       @text.gsub!(/\\[Nn][Mm]\[(.*?)\]/) do
  2825.         @name = $1.to_s
  2826.         if $1.to_s == "" and @name_window != nil
  2827.           @name_window.visible = false
  2828.         end
  2829.         ""
  2830.       end
  2831.       if @name != ""
  2832.         # name window
  2833.         @name_window = Window_Name.new
  2834.         @name_window.z = self.z + 1
  2835.         @name_window.set_name(@name)
  2836.       end
  2837.      
  2838.       # shaking
  2839.       text.gsub!(/\\[Ss][Kk]\[([0-9]+)\]/) do
  2840.         $game_system.text_shake = $1.to_i
  2841.         "\030"
  2842.       end
  2843.       @text.gsub!(/\\[Ss][Kk]/) do
  2844.         "\031"
  2845.       end
  2846.       @text.gsub!(/\\[Ss][Hh][Kk]\[([0-9]+)\]/) do
  2847.         @shake = $1.to_i
  2848.         ""
  2849.       end
  2850.      
  2851.       # back opacity
  2852.       @text.gsub!(/\\[Bb][Oo][Pp][Cc]\[([0-9]+)\]/) do
  2853.         self.back_opacity = $1.to_i
  2854.         ""
  2855.       end
  2856.      
  2857.       # opacity
  2858.       @text.gsub!(/\\[Oo][Pp][Cc]\[([0-9]+)\]/) do
  2859.         self.opacity = $1.to_i
  2860.         ""
  2861.       end
  2862.      
  2863.       # Change "\\\\" to "\000" for convenience
  2864.       @text.gsub!(/\\\\/) { "\000" }
  2865.       # Change "\\C" to "\001" and "\\G" to "\002"
  2866.       @text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  2867.       @text.gsub!(/\\[Gg]/) { "\002" }
  2868.       @text.gsub!(/\\[Cc]\[0x([0123456789abcdef]+)\]/) { "\026[#{$1}]" }
  2869.      
  2870.       # text skip code
  2871.       @text.gsub!(/\\[Ss][Kk][Ii][Pp]/) { "\003" }
  2872.      
  2873.       # ignore code
  2874.       @text.gsub!(/\\[Ii][Gg][Nn][Rr]/) { "\023" }
  2875.      
  2876.       # bold and italics
  2877.       @text.gsub!(/\\[Bb]/) { "\004" }
  2878.       @text.gsub!(/\\[Ii]/) { "\005" }
  2879.      
  2880.       # shadow
  2881.       @text.gsub!(/\\[Ss]/) { "\006" }
  2882.      
  2883.       # font
  2884.       @text.gsub!(/\\[Ff][Oo][Nn][Tt]\[(.*?)\]/) { "\007[#{$1}]" }
  2885.      
  2886.       # pause and wait
  2887.       @text.gsub!(/\\[Pp]\[([0-9]+)\]/) { "\010[#{$1}]" }
  2888.       @text.gsub!(/\\[Ww]\[([0-9]+)\]/) { "\011[#{$1}]" }
  2889.      
  2890.       # write speed
  2891.       @text.gsub!(/\\[Ww][Ss]\[([0-9]+)\]/) { "\013[#{$1}]" }
  2892.            
  2893.       # armor, items, skills, and weapons
  2894.       @text.gsub!(/\\[Oo][Aa]\[([0-9]+)\]/) {
  2895.         item = $data_armors[$1.to_i]
  2896.         "\014[#{$1}]" + "  " + item.name
  2897.       }
  2898.       @text.gsub!(/\\[Oo][Ii]\[([0-9]+)\]/) {
  2899.         item = $data_items[$1.to_i]
  2900.         "\015[#{$1}]" + "  " + item.name
  2901.       }
  2902.       @text.gsub!(/\\[Oo][Ss]\[([0-9]+)\]/) {
  2903.         item = $data_skills[$1.to_i]
  2904.         "\016[#{$1}]" + "  " + item.name
  2905.       }
  2906.       @text.gsub!(/\\[Oo][Ww]\[([0-9]+)\]/) {
  2907.         item = $data_weapons[$1.to_i]
  2908.         "\017[#{$1}]" + "  " + item.name
  2909.       }
  2910.       @text.gsub!(/\\[Ii][Cc]\[(.*?)\]/) {
  2911.         "\027[#{$1}]"
  2912.       }
  2913.      
  2914.       # text justification
  2915.       @text.gsub!(/\\[Tt][Cc]/) { "\020" }
  2916.       @text.gsub!(/\\[Tt][Ll]/) { "\021" }
  2917.       @text.gsub!(/\\[Tt][Rr]/) { "\022" }
  2918.      
  2919.       # Resize the window to fit the contents?
  2920.       if @mode == FIT_WINDOW_TO_TEXT
  2921.         width = 1
  2922.         text = @text.split("\n")
  2923.         height = 0
  2924.         i = 0
  2925.         for line in text
  2926.           # don't count this line's width if it has the ignr code
  2927.           if !line.include?("\023")
  2928.             width = [width, self.contents.text_size(line).width].max
  2929.             delta = self.contents.text_size(line).height
  2930.             height += delta + (6 * i) + 3
  2931.             if i < 3
  2932.               i += 1
  2933.             end
  2934.           end
  2935.         end
  2936.        
  2937.         if @face_graphic != "" and ($game_system.face_graphic_position == CENTER or $game_system.face_graphic_position == BOTTOM)
  2938.           width += @face.bitmap.width
  2939.           if height < @face.bitmap.height
  2940.             height = @face.bitmap.height - 32
  2941.           end
  2942.         end
  2943.        
  2944.         if height == 0
  2945.           height = 1
  2946.         end
  2947.          
  2948.         self.width = width + 48
  2949.         self.height = height + 48
  2950.         self.contents = Bitmap.new(width + 16, height)
  2951.         if $game_system.font == ""
  2952.           self.contents.font.name = Font.default_name
  2953.         else
  2954.           self.contents.font.name = $game_system.font
  2955.         end
  2956.         if $game_system.font_color.nil?
  2957.           self.contents.font.color = normal_color
  2958.         else
  2959.           self.contents.font.color = $game_system.font_color
  2960.         end
  2961.  
  2962.       else
  2963.         if self.width != $game_system.window_height or self.height != $game_system.window_width
  2964.           self.width = $game_system.window_width
  2965.           self.height = $game_system.window_height
  2966.           self.contents = Bitmap.new(self.width - 32, self.height - 32)
  2967.           if $game_system.font == ""
  2968.             self.contents.font.name = Font.default_name
  2969.           else
  2970.             self.contents.font.name = $game_system.font
  2971.           end
  2972.           if $game_system.font_color.nil?
  2973.             self.contents.font.color = normal_color
  2974.           else
  2975.             self.contents.font.color = $game_system.font_color
  2976.           end
  2977.         end
  2978.       end
  2979.      
  2980.       reset_window
  2981.      
  2982.       get_x_value
  2983.      
  2984.       @count = Graphics.frame_count
  2985.       @pause_time = 0
  2986.       @ignore = false
  2987.       @done = false
  2988.       @face_frame = 0
  2989.     end
  2990.    
  2991.    
  2992.    
  2993.     # If number input
  2994.     if $game_temp.num_input_variable_id > 0
  2995.       digits_max = $game_temp.num_input_digits_max
  2996.       number = $game_variables[$game_temp.num_input_variable_id]
  2997.       @input_number_window = Window_InputNumber.new(digits_max)
  2998.       @input_number_window.number = number
  2999.       @input_number_window.x = self.x + 8
  3000.       @input_number_window.y = self.y + $game_temp.num_input_start * 32
  3001.     end
  3002.   end
  3003.   #--------------------------------------------------------------------------
  3004.   # * Set Window Position and Opacity Level
  3005.   #--------------------------------------------------------------------------
  3006.   def reset_window (change_opacity = true)
  3007.     # x-coordinate depends on justification
  3008.     if @message_event == -1
  3009.       if @justification == RIGHT
  3010.         self.x = SCREEN[0] - self.width
  3011.       elsif @justification == LEFT
  3012.         self.x = 0
  3013.       else # center
  3014.         self.x = (SCREEN[0] - self.width) / 2
  3015.       end
  3016.     else
  3017.       if @message_event == 0 or $game_map.events[@message_event] == nil
  3018.         # center on player
  3019.         event_x = $game_player.screen_x
  3020.       else
  3021.         # center on the event specified
  3022.         event_x = $game_map.events[@message_event].screen_x
  3023.       end
  3024.       self.x = event_x - self.width / 2
  3025.       @comic.x = self.x + (self.width / 2) + 4
  3026.     end
  3027.    
  3028.     if $game_temp.in_battle
  3029.       self.y = 16
  3030.     else
  3031.       if @message_event == -1
  3032.         case @message_position
  3033.           when 0  # up
  3034.             self.y = 16
  3035.           when 1  # middle
  3036.             self.y = (SCREEN[1] - self.height) / 2
  3037.           when 2  # down
  3038.             self.y = SCREEN[1] - self.height - 24
  3039.         end
  3040.       else
  3041.         if @message_event == 0 or $game_map.events[@message_event] == nil
  3042.           # above player
  3043.           self.y = $game_player.screen_y - self.height - 48
  3044.         else
  3045.           # above event specified
  3046.           self.y = $game_map.events[@message_event].screen_y - self.height - 48
  3047.         end
  3048.         @comic.y = self.y + self.height - 2
  3049.       end
  3050.     end
  3051.     if self.y < 0 + (@name == "" ? 0 : 16)
  3052.       self.y = 0 + (@name == "" ? 0 : 16)
  3053.     elsif self.y > SCREEN[1] - self.height
  3054.       self.y = SCREEN[1] - self.height
  3055.     end
  3056.     if self.x < 0
  3057.       self.x = 0
  3058.     elsif self.x > (SCREEN[0] + 40) - self.width - 48
  3059.       self.x = SCREEN[0] - self.width
  3060.     end
  3061.    
  3062.     if change_opacity
  3063.       if $game_system.message_frame == 0
  3064.         self.opacity = 255
  3065.       else
  3066.         self.opacity = 0
  3067.       end
  3068.       self.back_opacity = $game_system.back_opacity
  3069.     end
  3070.    
  3071.     # face stuff
  3072.       if @face_graphic != ""  
  3073.         # the player has chosen to show a face graphic
  3074.         if @done and $game_system.resting_face != ""
  3075.           @face.bitmap = RPG::Cache.picture(@face_graphic + $game_system.resting_face)
  3076.           if @face_frame * $game_system.face_frame_width >= @face.bitmap.width
  3077.             @face_frame = 0
  3078.           end
  3079.         else
  3080.           @face.bitmap = RPG::Cache.picture(@face_graphic)
  3081.         end
  3082.        
  3083.         # picture y-coordinate
  3084.         if @face_graphic_position == ABOVE
  3085.           @face.y = self.y - @face.bitmap.height
  3086.           @face_offset = 0
  3087.         elsif @face_graphic_position == CENTER
  3088.           delta = (@face.bitmap.height - self.height) / 2
  3089.           @face.y = self.y - delta
  3090.           if $game_system.animated_faces
  3091.             @face_offset = $game_system.face_frame_width + 16
  3092.           else
  3093.             @face_offset = @face.bitmap.width + 16
  3094.           end
  3095.         elsif @face_graphic_position == BOTTOM
  3096.           @face.y = self.y + self.height - @face.bitmap.height
  3097.           if $game_system.animated_faces
  3098.             @face_offset = $game_system.face_frame_width + 16
  3099.           else
  3100.             @face_offset = @face.bitmap.width + 16
  3101.           end
  3102.         else # side
  3103.           delta = (@face.bitmap.height - self.height) / 2
  3104.           @face.y = self.y - delta
  3105.           @face_offset = 0
  3106.         end
  3107.        
  3108.         # picture x-coordinate
  3109.         if @face_graphic_justification == LEFT
  3110.           if @face_graphic_position == SIDE
  3111.             @face.x = self.x - @face.bitmap.width
  3112.           else
  3113.             @face.x = self.x + 10
  3114.           end
  3115.         else
  3116.           if $game_system.animated_faces
  3117.             offset = @face.bitmap.width - $game_system.face_frame_width
  3118.           else
  3119.             offset = 0
  3120.           end
  3121.           if @face_graphic_position == SIDE
  3122.             @face.x = self.x + self.width + offset
  3123.           else
  3124.             @face.x = self.x + self.width - @face.bitmap.width - 10 + offset
  3125.             @face_offset = 0
  3126.           end
  3127.         end
  3128.        
  3129.         if $game_system.animated_faces
  3130.           @face.src_rect = Rect.new(@face_frame * $game_system.face_frame_width, 0, $game_system.face_frame_width, @face.bitmap.height)
  3131.           if @done and $game_system.resting_face != ""
  3132.             pause = $game_system.resting_animation_pause
  3133.           else
  3134.             pause = $game_system.animation_pause
  3135.           end
  3136.           if Graphics.frame_count % pause == 0
  3137.             @animate_face = true
  3138.           end
  3139.           if @animate_face
  3140.             if Graphics.frame_count % 3 == 0
  3141.               @face_frame += 1
  3142.               if @face_frame * $game_system.face_frame_width >= @face.bitmap.width
  3143.                 @face_frame = 0
  3144.                 @animate_face = false
  3145.               end
  3146.             end
  3147.           end
  3148.         end
  3149.       end
  3150.      
  3151.       # name window
  3152.       if @name != "" and @name != nil
  3153.         @name_window.set_name(@name)
  3154.         @name_window.x = self.x
  3155.         @name_window.y = self.y - 36
  3156.       end
  3157.      
  3158.       # If choice
  3159.     if $game_temp.choice_max > 0
  3160.       @choice_window.set_choices($game_temp.choices)
  3161.       # determine x and y coords for choice window
  3162.       if $game_system.choice_justification == LEFT
  3163.         @choice_window.x = self.x
  3164.       else
  3165.         @choice_window.x = self.x + self.width - @choice_window.width
  3166.       end
  3167.       if $game_system.choice_position == ABOVE
  3168.         # check to make sure there is enough room above the textbox
  3169.         if self.y < @choice_window.height
  3170.           # not enough room above, place below
  3171.           @choice_window.y = self.y + self.height
  3172.         else
  3173.           # draw above
  3174.           @choice_window.y = self.y - @choice_window.height
  3175.         end
  3176.       elsif $game_system.choice_position == BOTTOM
  3177.         # check to make sure there is enough room below the textbox
  3178.         if (SCREEN[1] - self.y - self.height) < @choice_window.height
  3179.           # not enough room below, place above
  3180.           @choice_window.y = self.y - @choice_window.height
  3181.         else
  3182.           # draw below
  3183.           @choice_window.y = self.y + self.height
  3184.         end
  3185.       else # side
  3186.         if $game_system.choice_justification == LEFT
  3187.           # check to make sure there's room on the left side
  3188.           if self.y < @choice_window.width
  3189.             # not enough room on the side, check to make sure there's room below
  3190.             if (SCREEN[1] - self.y - self.height) < @choice_window.height
  3191.               # not enough room below, place above
  3192.               @choice_window.y = self.y - @choice_window.height
  3193.             else
  3194.               # draw below
  3195.               @choice_window.y = self.y + self.height
  3196.             end
  3197.           else
  3198.             # place on the left side
  3199.             @choice_window.y = self.y
  3200.             @choice_window.x = self.x - @choice_window.width
  3201.           end
  3202.         else # right
  3203.           # check to make sure there's room on the right side
  3204.           if (680 - (self.y + self.width)) < @choice_window.width
  3205.             # not enough room on the side, check to make sure there's room below
  3206.             if (SCREEN[1] - self.y - self.height) < @choice_window.height
  3207.               # not enough room below, place above
  3208.               @choice_window.y = self.y - @choice_window.height
  3209.             else
  3210.               # draw below
  3211.               @choice_window.y = self.y + self.height
  3212.             end
  3213.           else
  3214.             # place on the left side
  3215.             @choice_window.y = self.y
  3216.             @choice_window.x = self.x + self.width
  3217.           end
  3218.         end
  3219.       end
  3220.     end
  3221.   end
  3222.   #--------------------------------------------------------------------------
  3223.   # * Frame Update
  3224.   #--------------------------------------------------------------------------
  3225.   def update
  3226.     super
  3227.    
  3228.     if !@show
  3229.       return
  3230.     else
  3231.       self.visible = true
  3232.       if @face_graphic != ""
  3233.         @face.opacity = 255
  3234.       end
  3235.       if $game_system.comic_enabled and @message_event != -1
  3236.         @comic.opacity = 255
  3237.       end
  3238.       if @name != ""
  3239.         @name_window.visible = true
  3240.         if $game_system.name_window
  3241.           @name_window.dummy_window.visible = true
  3242.         end
  3243.       end
  3244.       if @input_number_window != nil
  3245.         @input_number_window.contents_opacity = 255
  3246.       end
  3247.       reset_window
  3248.     end
  3249.    
  3250.    
  3251.     if (@contents_showing and $game_system.message_event != -1 and @shake == 0) or $game_system.animated_faces
  3252.       reset_window(false)
  3253.     end
  3254.    
  3255.     if $game_system.shake != 0  # shake the window
  3256.       if @ascending
  3257.         if @target_x != self.x
  3258.           self.x += 1
  3259.         else
  3260.           @ascending = false
  3261.           @target_x = self.x - ($game_system.shake * 2)
  3262.         end
  3263.       else
  3264.         if @target_x != self.x
  3265.           self.x -= 1
  3266.         else
  3267.           @ascending = true
  3268.           @target_x = self.x + ($game_system.shake * 2)
  3269.         end
  3270.       end
  3271.     end
  3272.    
  3273.     if $game_system.text_shake != 0  # shake the text
  3274.       if @ascending
  3275.         if @target_x2 != @shake_sprite.x
  3276.           @shake_sprite.x += 1
  3277.         else
  3278.           @ascending = false
  3279.           @target_x2 = @shake_sprite.x - ($game_system.text_shake * 2)
  3280.         end
  3281.       else
  3282.         if @target_x2 != @shake_sprite.x
  3283.           @shake_sprite.x -= 1
  3284.         else
  3285.           @ascending = true
  3286.           @target_x2 = @shake_sprite.x + ($game_system.text_shake * 2)
  3287.         end
  3288.       end
  3289.     end
  3290.    
  3291.     if @wait > 0
  3292.       @wait -= 1
  3293.       if @wait == 0
  3294.         terminate_message
  3295.         return
  3296.       end
  3297.     end
  3298.    
  3299.     # If fade in
  3300.     if @fade_in
  3301.       self.contents_opacity += 24
  3302.       if @face_graphic != ""
  3303.         @face.opacity += 24
  3304.       end
  3305.       if $game_system.comic_enabled and @message_event != -1
  3306.         @comic.opacity += 24
  3307.       end
  3308.       if @name != ""
  3309.         @name_window.visible = true
  3310.       end
  3311.       if @input_number_window != nil
  3312.         @input_number_window.contents_opacity += 24
  3313.       end
  3314.       if self.contents_opacity == 255
  3315.         @fade_in = false
  3316.       end
  3317.       return
  3318.     end
  3319.    
  3320.     # write the text
  3321.     if @text != nil and @text != ""
  3322.       speed = $game_system.write_speed
  3323.       if $game_system.text_skip
  3324.         if $game_system.skip_mode == WRITE_FASTER and Input.press?(Input::C)
  3325.           # the player is holding the action button, write faster
  3326.           speed /= 3
  3327.         elsif $game_system.skip_mode == WRITE_ALL and @write_all
  3328.           # the player pressed the action button, write all the text
  3329.           while (c = @text.slice!(/./m)) != nil
  3330.             write_char(c)
  3331.           end
  3332.           return
  3333.         end
  3334.       end
  3335.       while @ignore
  3336.         c = @text.slice!(/./m)
  3337.         if c != nil
  3338.           write_char(c)
  3339.         end
  3340.       end
  3341.       if @pause_time > 0
  3342.         @pause_time -= 1
  3343.         return
  3344.       end
  3345.       if Graphics.frame_count - @count >= speed
  3346.         if $game_system.sound_effect != ""
  3347.           Audio.se_play("Audio/SE/" + $game_system.sound_effect, 80, 100)
  3348.         end
  3349.         @count = Graphics.frame_count
  3350.         c = @text.slice!(/./m)
  3351.         if c != nil
  3352.           write_char(c)
  3353.         end
  3354.       end
  3355.       return
  3356.     end
  3357.    
  3358.     @done = true
  3359.    
  3360.     # If inputting number
  3361.     if @input_number_window != nil
  3362.       @input_number_window.update
  3363.       # Confirm
  3364.       if Input.trigger?(Input::C)
  3365.         $game_system.se_play($data_system.decision_se)
  3366.         $game_variables[$game_temp.num_input_variable_id] =
  3367.           @input_number_window.number
  3368.         $game_map.need_refresh = true
  3369.         # Dispose of number input window
  3370.         @input_number_window.dispose
  3371.         @input_number_window = nil
  3372.         terminate_message
  3373.       end
  3374.       return
  3375.     end
  3376.    
  3377.     if @wait != 0
  3378.       return
  3379.     end
  3380.    
  3381.     # If message is being displayed and contents are all written
  3382.     if @contents_showing
  3383.       # if choice
  3384.       if $game_temp.choice_max > 0
  3385.         if !@choice_window.active
  3386.           @choice_window.visible = true
  3387.           @choice_window.active = true
  3388.           @choice_window.index = 0
  3389.         end
  3390.         @choice_window.update
  3391.       else
  3392.         # If choice isn't being displayed, show pause sign
  3393.         self.pause = true
  3394.       end
  3395.       return
  3396.     end
  3397.   end
  3398.  
  3399.   #--------------------------------------------------------------------------
  3400.   # * Process and write the given character
  3401.   #--------------------------------------------------------------------------
  3402.   def write_char(c)
  3403.     if c == "\000"
  3404.       # Return to original text
  3405.       c = "\\"
  3406.     end
  3407.     # If \C[n]
  3408.     if c == "\001"
  3409.     # Change text color
  3410.       @text.sub!(/\[([0-9]+)\]/, "")
  3411.       color = $1.to_i
  3412.       if color >= 0 and color <= 7
  3413.         self.contents.font.color = text_color(color)
  3414.       end
  3415.       # go to next text
  3416.       return
  3417.     end
  3418.     # If \G
  3419.     if c == "\002"
  3420.       # Make gold window
  3421.       if @gold_window == nil
  3422.         @gold_window = Window_Gold.new
  3423.         @gold_window.x = 560 - @gold_window.width
  3424.         if $game_temp.in_battle
  3425.           @gold_window.y = 192
  3426.         else
  3427.           @gold_window.y = self.y >= 128 ? 32 : 384
  3428.         end
  3429.         @gold_window.opacity = self.opacity
  3430.         @gold_window.back_opacity = self.back_opacity
  3431.       end
  3432.       # go to next text
  3433.       return
  3434.     end
  3435.     # If \skip
  3436.     if c == "\003"
  3437.       # toggle text skipping
  3438.       #$game_system.text_skip = !$game_system.text_skip
  3439.       # go to next text
  3440.       return
  3441.     end
  3442.     # If \b
  3443.     if c == "\004"
  3444.       # toggle bold
  3445.       self.contents.font.bold = !self.contents.font.bold
  3446.       # go to next text
  3447.       return
  3448.     end
  3449.     # If \i
  3450.     if c == "\005"
  3451.       # toggle italics
  3452.       self.contents.font.italic = !self.contents.font.italic
  3453.       # go to next text
  3454.       return
  3455.     end
  3456.     # If \s
  3457.     if c == "\006"
  3458.       # toggle shadow
  3459.       #$game_system.shadowed_text = !$game_system.shadowed_text
  3460.       # go to next text
  3461.       return
  3462.     end
  3463.     # If \font
  3464.     if c == "\007"
  3465.       # change font
  3466.       @text.sub!(/\[(.*?)\]/, "")
  3467.       font = $1.to_s
  3468.       @font = font
  3469.       if font == ""
  3470.         self.contents.font.name = Font.default_name
  3471.       else
  3472.         self.contents.font.name = font
  3473.       end
  3474.       # go to next text
  3475.       return
  3476.     end
  3477.     # If \p[n]
  3478.     if c == "\010"
  3479.       @text.sub!(/\[([0-9]+)\]/, "")
  3480.       @pause_time = $1.to_i
  3481.  
  3482.       # go to next text
  3483.       return
  3484.     end
  3485.    
  3486.     # If \w[n]
  3487.     if c == "\011"
  3488.       @text.sub!(/\[([0-9]+)\]/, "")
  3489.       @wait = $1.to_i
  3490.  
  3491.       # go to next text
  3492.       return
  3493.     end
  3494.    
  3495.     # If \ws[n]
  3496.     if c == "\013"
  3497.       @text.sub!(/\[([0-9]+)\]/, "")
  3498.       $game_system.write_speed = $1.to_i
  3499.  
  3500.       # go to next text
  3501.       return
  3502.     end
  3503.     # If \oa[n]
  3504.     if c == "\014"
  3505.       @text.sub!(/\[([0-9]+)\]/, "")
  3506.       index = $1.to_i
  3507.       @text.sub!("  ", "")
  3508.       item = $data_armors[index]
  3509.       # draw the icon
  3510.       icon = RPG::Cache.icon(item.icon_name)
  3511.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  3512.       @x += 24
  3513.  
  3514.       # go to next text
  3515.       return
  3516.     end
  3517.    
  3518.     # If \oi[n]
  3519.     if c == "\015"
  3520.       @text.sub!(/\[([0-9]+)\]/, "")
  3521.       index = $1.to_i
  3522.       @text.sub!("  ", "")
  3523.       item = $data_items[index]
  3524.       # draw the icon
  3525.       icon = RPG::Cache.icon(item.icon_name)
  3526.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  3527.       @x += 24
  3528.  
  3529.       # go to next text
  3530.       return
  3531.     end
  3532.    
  3533.     # If \os[n]
  3534.     if c == "\016"
  3535.       @text.sub!(/\[([0-9]+)\]/, "")
  3536.       index = $1.to_i
  3537.       @text.sub!("  ", "")
  3538.       item = $data_skills[index]
  3539.       # draw the icon
  3540.       icon = RPG::Cache.icon(item.icon_name)
  3541.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  3542.       @x += 24
  3543.  
  3544.       # go to next text
  3545.       return
  3546.     end
  3547.    
  3548.     # If \ow[n]
  3549.     if c == "\017"
  3550.       @text.sub!(/\[([0-9]+)\]/, "")
  3551.       index = $1.to_i
  3552.       @text.sub!("  ", "")
  3553.       item = $data_weapons[index]
  3554.       # draw the icon
  3555.       icon = RPG::Cache.icon(item.icon_name)
  3556.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  3557.       @x += 24
  3558.      
  3559.       # go to next text
  3560.       return
  3561.     end
  3562.     # If \ic[name]
  3563.     if c == "\027"
  3564.       @text.sub!(/\[(.*?)\]/, "")
  3565.       # draw the icon
  3566.       icon = RPG::Cache.icon($1.to_s)
  3567.       line = self.contents.text_size("dj").height
  3568.       self.contents.blt(@x + 4, (@y * line) + 4, icon, Rect.new(0, 0, 24, 24))
  3569.       @x += 24
  3570.  
  3571.       # go to next text
  3572.       return
  3573.     end
  3574.    
  3575.     # If \tc
  3576.     if c == "\020"
  3577.       # center justify
  3578.       @text_justification = CENTER
  3579.       get_x_value
  3580.       # go to next text
  3581.       return
  3582.     end
  3583.    
  3584.     # If \tl
  3585.     if c == "\021"
  3586.       # left justify
  3587.       @text_justification = LEFT
  3588.       get_x_value
  3589.       # go to next text
  3590.       return
  3591.     end
  3592.    
  3593.     # If \tr
  3594.     if c == "\022"
  3595.       # right justify
  3596.       @text_justification = RIGHT
  3597.       get_x_value
  3598.       # go to next text
  3599.       return
  3600.     end
  3601.    
  3602.     # If \ignr
  3603.     if c == "\023"
  3604.       # set ignore flage
  3605.       @ignore = true
  3606.       # go to next text
  3607.       return
  3608.     end
  3609.    
  3610.     # if \c (hex color)
  3611.     if c == "\026"
  3612.       # convert hex color to RGB
  3613.       @text.sub!(/\[([0123456789abcdef]+)\]/, "")
  3614.       hex_code = $1.to_s
  3615.      
  3616.       red   = ("0x" + hex_code.slice(0..1)).hex
  3617.       blue  = ("0x" + hex_code.slice(2..3)).hex
  3618.       green = ("0x" + hex_code.slice(4..5)).hex
  3619.      
  3620.       self.contents.font.color = Color.new(red, blue, green)
  3621.       return
  3622.     end
  3623.    
  3624.     # if \sk[i] (begin shake)
  3625.     if c == "\030"
  3626.       @shake_text = true
  3627.       return
  3628.     end
  3629.     # if \sk (end shake)
  3630.     if c == "\031"
  3631.       @shake_text = false
  3632.       return
  3633.     end
  3634.    
  3635.     # If new line text
  3636.     if c == "\n"
  3637.       # Add 1 to y
  3638.       if !@ignore
  3639.         @y += 1
  3640.       end
  3641.       if @text != ""
  3642.         get_x_value
  3643.       end
  3644.       @ignore = false
  3645.  
  3646.       # go to next text
  3647.       return
  3648.     end
  3649.     if @ignore
  3650.       return
  3651.     end
  3652.     # Draw text
  3653.     line = self.contents.text_size("dj").height
  3654.     if $game_system.shadowed_text
  3655.       old_color = self.contents.font.color.clone
  3656.       if @shake_text
  3657.         @shake_sprite.bitmap.font.color = $game_system.shadow_color    
  3658.         @shake_sprite.bitmap.draw_text(6 + @x, line * @y + 2, 40, 32, c)
  3659.         @shake_sprite.bitmap.font.color = old_color
  3660.       else
  3661.         self.contents.font.color = $game_system.shadow_color    
  3662.         self.contents.draw_text(6 + @x, line * @y + 2, 40, 32, c)
  3663.         self.contents.font.color = old_color
  3664.       end
  3665.     end
  3666.     if @shake_text
  3667.       @shake_sprite.bitmap.draw_text(4 + @x, line * @y, 40, 32, c)
  3668.     else
  3669.       self.contents.draw_text(4 + @x, line * @y, 40, 32, c)
  3670.     end
  3671.     # Add x to drawn text width
  3672.     @x += self.contents.text_size(c).width
  3673.   end
  3674.  
  3675.   def get_x_value
  3676.     # text justification - offset for first line
  3677.     if @text_justification == CENTER
  3678.       # get the length of the current line
  3679.       w = self.contents.text_size(@text.split("\n")[0]).width
  3680.       @x = (self.width - w - 48) / 2
  3681.     elsif @text_justification == RIGHT
  3682.       # get the length of the current line
  3683.       w = self.contents.text_size(@text.split("\n")[0]).width
  3684.       @x = self.width - w - 48
  3685.     else # left
  3686.       if @face_graphic == ""
  3687.         @x = 0
  3688.       else
  3689.         @x = @face_offset
  3690.       end
  3691.     end
  3692.   end
  3693. end
  3694.  
  3695. #==============================================================================
  3696. # ** Window_InputNumber
  3697. #------------------------------------------------------------------------------
  3698. #  This window is for inputting numbers, and is used within the
  3699. #  message window.
  3700. #==============================================================================
  3701.  
  3702. class Window_InputNumber < Window_Base
  3703.   #--------------------------------------------------------------------------
  3704.   # * Object Initialization
  3705.   #     digits_max : digit count
  3706.   #--------------------------------------------------------------------------
  3707.   def initialize(digits_max)
  3708.     @digits_max = digits_max
  3709.     @number = 0
  3710.     # Calculate cursor width from number width (0-9 equal width and postulate)
  3711.     dummy_bitmap = Bitmap.new(32, 32)
  3712.     @cursor_width = dummy_bitmap.text_size("0").width + 8
  3713.     dummy_bitmap.dispose
  3714.     super(0, 0, @cursor_width * @digits_max + 32, 64)
  3715.     self.contents = Bitmap.new(width - 32, height - 32)
  3716.     if $game_system.font == ""
  3717.       self.contents.font.name = Font.default_name
  3718.     else
  3719.       self.contents.font.name = $game_system.font
  3720.     end
  3721.     self.z += 9999
  3722.     self.opacity = $game_system.opacity
  3723.     self.back_opacity = $game_system.back_opacity
  3724.     @index = 0
  3725.     refresh
  3726.     update_cursor_rect
  3727.   end
  3728.  
  3729.   #--------------------------------------------------------------------------
  3730.   # * Refresh
  3731.   #--------------------------------------------------------------------------
  3732.   def refresh
  3733.     self.contents.clear
  3734.     if $game_system.font_color.nil?
  3735.       self.contents.font.color = normal_color
  3736.     else
  3737.       self.contents.font.color = $game_system.font_color
  3738.     end
  3739.     if $game_system.windowskin != ""  
  3740.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin)
  3741.     else
  3742.       self.windowskin = RPG::Cache.windowskin($data_system.windowskin_name)
  3743.     end
  3744.     s = sprintf("%0*d", @digits_max, @number)
  3745.     for i in 0...@digits_max
  3746.       # Draw text
  3747.       if $game_system.shadowed_text
  3748.         old_color = self.contents.font.color.clone
  3749.         self.contents.font.color = $game_system.shadow_color
  3750.         self.contents.draw_text(i * @cursor_width + 6, 2, 32, 32, s[i,1])
  3751.         self.contents.font.color = old_color
  3752.       end
  3753.       self.contents.draw_text(i * @cursor_width + 4, 0, 32, 32, s[i,1])
  3754.     end
  3755.   end
  3756. end
  3757.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement