Advertisement
Ancurio

UMS

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