Advertisement
KK20

CCOA UMS FIT_WINDOW fix

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