daily pastebin goal
60%
SHARE
TWEET

ums

a guest Nov 11th, 2017 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.       # Resize the window to fit the contents?
  1187.       if $game_system.ums_mode == FIT_WINDOW_TO_TEXT
  1188.         width = 1
  1189.         text = @text.split("\n")
  1190.         height = 0
  1191.         i = 0
  1192.         for line in text
  1193.           # don't count this line's width if it has the ignr code
  1194.           if !line.include?("\023")
  1195.             width = [width, self.contents.text_size(line).width].max
  1196.             delta = self.contents.text_size(line).height
  1197.             height += delta + (delta * 0.2).to_i
  1198.           end
  1199.         end
  1200.  
  1201.        
  1202.         if $game_system.face_graphic != "" and ($game_system.face_graphic_position == CENTER or $game_system.face_graphic_position == BOTTOM)
  1203.           width += @face.bitmap.width
  1204.           if height < @face.bitmap.height
  1205.             height = @face.bitmap.height - 32
  1206.           end
  1207.         end
  1208.        
  1209.         if height == 0
  1210.           height = 1
  1211.         end
  1212.        
  1213.         self.width = width + 26
  1214.         self.height = height + 38
  1215.         self.contents = Bitmap.new(width + 16, height)
  1216.        
  1217.         if $game_system.font == ""
  1218.           self.contents.font.name = Font.default_name
  1219.         else
  1220.           self.contents.font.name = $game_system.font
  1221.         end
  1222.        
  1223.         if $game_system.font_color.nil?
  1224.           self.contents.font.color = normal_color
  1225.         else
  1226.           self.contents.font.color = $game_system.font_color
  1227.         end
  1228.       else # normal mode
  1229.         if self.width != $game_system.window_height or self.height != $game_system.window_width
  1230.           self.width = $game_system.window_width
  1231.           self.height = $game_system.window_height
  1232.          
  1233.           # check to see if overall text height is greater than window height
  1234.           text = @text.split("\n")
  1235.           height = 0
  1236.           i = 0
  1237.           for line in text
  1238.             # don't count this line's width if it has the ignr code
  1239.             if !line.include?("\023")
  1240.               delta = self.contents.text_size(line).height
  1241.               height += delta + (delta * 0.2).to_i
  1242.             end
  1243.           end
  1244.           height += 32
  1245.          
  1246.           if (height > self.height)
  1247.             self.contents = Bitmap.new(self.width - 32, height - 32)
  1248.           else
  1249.             self.contents = Bitmap.new(self.width - 32, self.height - 32)
  1250.           end
  1251.          
  1252.           if $game_system.font == ""
  1253.             self.contents.font.name = Font.default_name
  1254.           else
  1255.             self.contents.font.name = $game_system.font
  1256.           end
  1257.           if $game_system.font_color.nil?
  1258.             self.contents.font.color = normal_color
  1259.           else
  1260.             self.contents.font.color = $game_system.font_color
  1261.           end
  1262.         end
  1263.       end
  1264.      
  1265.       if $game_system.window_image != nil
  1266.         # figure out how we're going to resize this          
  1267.         @window_back.zoom_x = self.width.to_f / @window_back.bitmap.width
  1268.         @window_back.zoom_y = self.height.to_f / @window_back.bitmap.height
  1269.       end
  1270.      
  1271.       reset_window
  1272.      
  1273.       get_x_value
  1274.      
  1275.       @count = Graphics.frame_count
  1276.       @pause_time = 0
  1277.       @ignore = false
  1278.       @ascending = true
  1279.       @target_x = self.x + $game_system.shake
  1280.       @target_x2 = @shake_sprite.x + $game_system.text_shake
  1281.       @done = false
  1282.       @face_frame = 0
  1283.       @done = false
  1284.      
  1285.       self.oy = 0
  1286.     end
  1287.    
  1288.    
  1289.   end
  1290.  
  1291.   #--------------------------------------------------------------------------
  1292.   # * Set Window Position and Opacity Level
  1293.   #--------------------------------------------------------------------------
  1294.   def reset_window (change_opacity = true)
  1295.     # x-coordinate depends on justification
  1296.     if $game_system.message_event == -1 and $game_system.train_actor == -1
  1297.       if $game_system.window_justification == RIGHT
  1298.         self.x = 640 - $game_system.window_width
  1299.       elsif $game_system.window_justification == LEFT
  1300.         self.x = 0
  1301.       else # center
  1302.         self.x = (640 - self.width) / 2
  1303.       end
  1304.     elsif $game_system.train_actor >= 0
  1305.       if $game_system.train_actor == 0 or $game_system.train_actor > $game_party.actors.size - 1
  1306.         # center on player
  1307.         event_x = $game_player.screen_x
  1308.       else
  1309.         # center on train actor
  1310.         event_x = $game_train.actors[$game_system.train_actor - 1].screen_x
  1311.       end
  1312.       self.x = event_x - self.width / 2
  1313.       @comic.x = self.x + (self.width / 2) + 4
  1314.     else
  1315.       if $game_system.message_event == 0 or $game_map.events[$game_system.message_event] == nil
  1316.         # center on player
  1317.         event_x = $game_player.screen_x
  1318.       else
  1319.         # center on the event specified
  1320.         event_x = $game_map.events[$game_system.message_event].screen_x
  1321.       end
  1322.       self.x = event_x - self.width / 2
  1323.       @comic.x = self.x + (self.width / 2) + 4
  1324.     end
  1325.    
  1326.     if $game_temp.in_battle
  1327.       self.y = 16
  1328.     else
  1329.       if $game_system.message_event == -1 and $game_system.train_actor == -1
  1330.         case $game_system.message_position
  1331.           when 0  # up
  1332.             self.y = 16
  1333.           when 1  # middle
  1334.             self.y = (480 - $game_system.window_height) / 2
  1335.           when 2  # down
  1336.             self.y = 480 - $game_system.window_height - 24
  1337.         end
  1338.       elsif $game_system.train_actor >= 0
  1339.         if $game_system.train_actor == 0 or $game_system.train_actor > $game_party.actors.size - 1
  1340.           # center on player
  1341.           self.y = $game_player.screen_y - self.height - 48
  1342.         else
  1343.           # center on train actor
  1344.           self.y = $game_train.actors[$game_system.train_actor - 1].screen_y - self.height - 48
  1345.         end
  1346.         @comic.y = self.y + self.height - 2
  1347.         @comic.angle = 0
  1348.       else
  1349.         if $game_system.message_event == 0 or $game_map.events[$game_system.message_event] == nil
  1350.           # above player
  1351.           self.y = $game_player.screen_y - self.height - 48
  1352.         else
  1353.           # above event specified
  1354.           self.y = $game_map.events[$game_system.message_event].screen_y - self.height - 48
  1355.         end
  1356.         @comic.y = self.y + self.height - 2
  1357.         @comic.angle = 0
  1358.       end
  1359.     end
  1360.     if self.y < 0 + ($game_system.name == "" ? 0 : 16)
  1361.       if $game_system.comic_enabled
  1362.         if $game_system.message_event == 0 or $game_map.events[$game_system.message_event] == nil
  1363.           self.y = $game_player.screen_y - 16
  1364.         else
  1365.           self.y = $game_map.events[$game_system.message_event].screen_y - 16
  1366.         end
  1367.         @comic.angle = 180
  1368.         @comic.y = self.y + 2
  1369.         @comic.x = self.x + (self.width / 2) - 4
  1370.       else
  1371.         self.y = 0 + ($game_system.name == "" ? 0 : 16)
  1372.       end
  1373.     elsif self.y > 480 - self.height
  1374.       self.y = 480 - self.height
  1375.     end
  1376.     if self.x < 0
  1377.       self.x = 0
  1378.     elsif self.x > 680 - self.width - 48
  1379.       self.x = 640 - self.width
  1380.     end
  1381.    
  1382.     if change_opacity
  1383.       if $game_system.message_frame == 0 and $game_temp.message_text != ""
  1384.         self.opacity = $game_system.opacity
  1385.       else
  1386.         self.opacity = 0
  1387.       end
  1388.       self.back_opacity = $game_system.back_opacity
  1389.     end
  1390.    
  1391.     # window back stuff
  1392.     if $game_system.window_image != nil
  1393.       @window_back.bitmap = RPG::Cache.windowskin($game_system.window_image)
  1394.       @window_back.x = self.x
  1395.       @window_back.y = self.y
  1396.     end
  1397.    
  1398.       # face stuff
  1399.       if $game_system.face_graphic != ""  
  1400.         # the player has chosen to show a face graphic
  1401.         if @done and $game_system.resting_face != ""
  1402.           @face.bitmap = RPG::Cache.picture($game_system.face_graphic + $game_system.resting_face)
  1403.           if @face_frame * $game_system.face_frame_width >= @face.bitmap.width
  1404.             @face_frame = 0
  1405.           end
  1406.         else
  1407.           @face.bitmap = RPG::Cache.picture($game_system.face_graphic)
  1408.         end
  1409.        
  1410.         # picture y-coordinate
  1411.         if $game_system.face_graphic_position == ABOVE
  1412.           @face.y = self.y - @face.bitmap.height
  1413.           @face_offset = 0
  1414.         elsif $game_system.face_graphic_position == CENTER
  1415.           delta = (@face.bitmap.height - self.height) / 2
  1416.           @face.y = self.y - delta
  1417.           if $game_system.animated_faces
  1418.             @face_offset = $game_system.face_frame_width + 16
  1419.           else
  1420.             @face_offset = @face.bitmap.width + 16
  1421.           end
  1422.         elsif $game_system.face_graphic_position == BOTTOM
  1423.           @face.y = self.y + self.height - @face.bitmap.height
  1424.           if $game_system.animated_faces
  1425.             @face_offset = $game_system.face_frame_width + 16
  1426.           else
  1427.             @face_offset = @face.bitmap.width + 16
  1428.           end
  1429.         else # side
  1430.           delta = (@face.bitmap.height - self.height) / 2
  1431.           @face.y = self.y - delta
  1432.           @face_offset = 0
  1433.         end
  1434.        
  1435.         # picture x-coordinate
  1436.         if $game_system.face_graphic_justification == LEFT
  1437.           if $game_system.face_graphic_position == SIDE
  1438.             @face.x = self.x - @face.bitmap.width
  1439.           else
  1440.             @face.x = self.x + 10
  1441.           end
  1442.         else # right side
  1443.           if $game_system.animated_faces
  1444.             offset = @face.bitmap.width - $game_system.face_frame_width
  1445.           else
  1446.             offset = 0
  1447.           end
  1448.           if $game_system.face_graphic_position == SIDE
  1449.             @face.x = self.x + self.width + offset
  1450.           else
  1451.             @face.x = self.x + self.width - @face.bitmap.width - 10 + offset
  1452.             @face_offset = 0
  1453.           end
  1454.         end
  1455.        
  1456.         if $game_system.animated_faces
  1457.           @face.src_rect = Rect.new(@face_frame * $game_system.face_frame_width, 0, $game_system.face_frame_width, @face.bitmap.height)
  1458.           if @done and $game_system.resting_face != ""
  1459.             pause = $game_system.resting_animation_pause
  1460.           else
  1461.             pause = $game_system.animation_pause
  1462.           end
  1463.           if Graphics.frame_count % pause == 0
  1464.             @animate_face = true
  1465.           end
  1466.           if @animate_face
  1467.             if Graphics.frame_count % 3 == 0
  1468.               @face_frame += 1
  1469.               if @face_frame * $game_system.face_frame_width >= @face.bitmap.width
  1470.                 @face_frame = 0
  1471.                 @animate_face = false
  1472.               end
  1473.             end
  1474.           end
  1475.         end
  1476.       end
  1477.      
  1478.       # name window
  1479.       if $game_system.name != ""
  1480.         @name_window.x = self.x
  1481.         @name_window.y = self.y - 36
  1482.         @name_window.set_name($game_system.name)
  1483.       end
  1484.      
  1485.       # If choice
  1486.     if $game_temp.choice_max > 0
  1487.       @choice_window.set_choices($game_temp.choices)
  1488.       # determine x and y coords for choice window
  1489.       if $game_system.choice_justification == LEFT
  1490.         @choice_window.x = self.x
  1491.       else
  1492.         @choice_window.x = self.x + self.width - @choice_window.width
  1493.       end
  1494.       if $game_system.choice_position == ABOVE
  1495.         # check to make sure there is enough room above the textbox
  1496.         if self.y < @choice_window.height
  1497.           # not enough room above, place below
  1498.           @choice_window.y = self.y + self.height
  1499.         else
  1500.           # draw above
  1501.           @choice_window.y = self.y - @choice_window.height
  1502.         end
  1503.       elsif $game_system.choice_position == BOTTOM
  1504.         # check to make sure there is enough room below the textbox
  1505.         if (480 - self.y - self.height) < @choice_window.height
  1506.           # not enough room below, place above
  1507.           @choice_window.y = self.y - @choice_window.height
  1508.         else
  1509.           # draw below
  1510.           @choice_window.y = self.y + self.height
  1511.         end
  1512.       else # side
  1513.         if $game_system.choice_justification == LEFT
  1514.           # check to make sure there's room on the left side
  1515.           if self.y < @choice_window.width
  1516.             # not enough room on the side, check to make sure there's room below
  1517.             if (480 - self.y - self.height) < @choice_window.height
  1518.               # not enough room below, place above
  1519.               @choice_window.y = self.y - @choice_window.height
  1520.             else
  1521.               # draw below
  1522.               @choice_window.y = self.y + self.height
  1523.             end
  1524.           else
  1525.             # place on the left side
  1526.             @choice_window.y = self.y
  1527.             @choice_window.x = self.x - @choice_window.width
  1528.           end
  1529.         else # right
  1530.           # check to make sure there's room on the right side
  1531.           if (680 - (self.y + self.width)) < @choice_window.width
  1532.             # not enough room on the side, check to make sure there's room below
  1533.             if (480 - self.y - self.height) < @choice_window.height
  1534.               # not enough room below, place above
  1535.               @choice_window.y = self.y - @choice_window.height
  1536.             else
  1537.               # draw below
  1538.               @choice_window.y = self.y + self.height
  1539.             end
  1540.           else
  1541.             # place on the left side
  1542.             @choice_window.y = self.y
  1543.             @choice_window.x = self.x + self.width
  1544.           end
  1545.         end
  1546.       end
  1547.     end
  1548.    
  1549.     # If number input
  1550.     if $game_temp.num_input_variable_id > 0
  1551.       if @input_number_window == nil
  1552.         digits_max = $game_temp.num_input_digits_max
  1553.         number = $game_variables[$game_temp.num_input_variable_id]
  1554.         @input_number_window = Window_InputNumber.new(digits_max)
  1555.         @input_number_window.number = number
  1556.       end
  1557.       # determine x and y coords for number input window
  1558.       if $game_system.choice_justification == LEFT
  1559.         @input_number_window.x = self.x
  1560.       else
  1561.         @input_number_window.x = self.x + self.width - @input_number_window.width
  1562.       end
  1563.       if $game_system.choice_position == ABOVE
  1564.         # check to make sure there is enough room above the textbox
  1565.         if self.y < @input_number_window.height
  1566.           # not enough room above, place below
  1567.           @input_number_window.y = self.y + self.height
  1568.         else
  1569.           # draw above
  1570.           @input_number_window.y = self.y - @choice_window.height
  1571.         end
  1572.       elsif $game_system.choice_position == BOTTOM
  1573.         # check to make sure there is enough room below the textbox
  1574.         if (480 - self.y - self.height) < @input_number_window.height
  1575.           # not enough room below, place above
  1576.           @input_number_window.y = self.y - @input_number_window.height
  1577.         else
  1578.           # draw below
  1579.           @input_number_window.y = self.y + self.height
  1580.         end
  1581.       else # side
  1582.         if $game_system.choice_justification == LEFT
  1583.           # check to make sure there's room on the left side
  1584.           if self.y < @input_number_window.width
  1585.             # not enough room on the side, check to make sure there's room below
  1586.             if (480 - self.y - self.height) < @input_number_window.height
  1587.               # not enough room below, place above
  1588.               @input_number_window.y = self.y - @input_number_window.height
  1589.             else
  1590.               # draw below
  1591.               @input_number_window.y = self.y + self.height
  1592.             end
  1593.           else
  1594.             # place on the left side
  1595.             @input_number_window.y = self.y
  1596.             @input_number_window.x = self.x - @choice_window.width
  1597.           end
  1598.         else # right
  1599.           # check to make sure there's room on the right side
  1600.           if (680 - (self.y + self.width)) < @input_number_window.width
  1601.             # not enough room on the side, check to make sure there's room below
  1602.             if (480 - self.y - self.height) < @input_number_window.height
  1603.               # not enough room below, place above
  1604.               @input_number_window.y = self.y - @input_number_window.height
  1605.             else
  1606.               # draw below
  1607.               @input_number_window.y = self.y + self.height
  1608.             end
  1609.           else
  1610.             # place on the left side
  1611.             @input_number_window.y = self.y
  1612.             @input_number_window.x = self.x + self.width
  1613.           end
  1614.         end
  1615.       end
  1616.     end
  1617.   end
  1618.   #--------------------------------------------------------------------------
  1619.   # * Frame Update
  1620.   #--------------------------------------------------------------------------
  1621.   def update
  1622.     super
  1623.    
  1624.     if (@contents_showing and $game_system.message_event != -1 and $game_system.shake == 0) or $game_system.animated_faces
  1625.       reset_window(false)
  1626.     end
  1627.    
  1628.     if $game_system.shake != 0  # shake the window
  1629.       if @ascending
  1630.         if @target_x != self.x
  1631.           self.x += 1
  1632.         else
  1633.           @ascending = false
  1634.           @target_x = self.x - ($game_system.shake * 2)
  1635.         end
  1636.       else
  1637.         if @target_x != self.x
  1638.           self.x -= 1
  1639.         else
  1640.           @ascending = true
  1641.           @target_x = self.x + ($game_system.shake * 2)
  1642.         end
  1643.       end
  1644.     end
  1645.    
  1646.     if $game_system.text_shake != 0  # shake the text
  1647.       if @ascending
  1648.         if @target_x2 != @shake_sprite.x
  1649.           @shake_sprite.x += 1
  1650.         else
  1651.           @ascending = false
  1652.           @target_x2 = @shake_sprite.x - ($game_system.text_shake * 2)
  1653.         end
  1654.       else
  1655.         if @target_x2 != @shake_sprite.x
  1656.           @shake_sprite.x -= 1
  1657.         else
  1658.           @ascending = true
  1659.           @target_x2 = @shake_sprite.x + ($game_system.text_shake * 2)
  1660.         end
  1661.       end
  1662.     end
  1663.    
  1664.     @name_window.update
  1665.    
  1666.     if @wait > 0
  1667.       @wait -= 1
  1668.       if @wait == 0
  1669.         terminate_message
  1670.         return
  1671.       end
  1672.     end
  1673.    
  1674.     # If fade in
  1675.     if @fade_in
  1676.       if $game_temp.message_text == ""
  1677.         @fade_in = false
  1678.         return
  1679.       end
  1680.       self.contents_opacity += 24
  1681.       if $game_system.face_graphic != ""
  1682.         @face.opacity += 24
  1683.       end
  1684.       if $game_system.window_image != nil
  1685.         @window_back.opacity += 24
  1686.       end
  1687.       if $game_system.comic_enabled and $game_system.message_event != -1
  1688.         @comic.opacity = self.opacity
  1689.         @comic.visible = self.visible
  1690.       end
  1691.       @shake_sprite.visible = true
  1692.      
  1693.       if $game_system.name != "" and @show
  1694.         @name_window.visible = true
  1695.         if $game_system.name_window
  1696.           @name_window.dummy_window.visible = true
  1697.         end
  1698.       end
  1699.       if @input_number_window != nil
  1700.         @input_number_window.contents_opacity += 24
  1701.       end
  1702.       if self.contents_opacity == 255
  1703.         @fade_in = false
  1704.       end
  1705.       return
  1706.     end
  1707.    
  1708.     # write the text
  1709.     if @text != nil and @text != ""
  1710.       speed = $game_system.write_speed
  1711.       if $game_system.text_mode == ALL_AT_ONCE or $game_temp.in_battle
  1712.         while (c = @text.slice!(/./m)) != nil
  1713.           write_char(c)
  1714.         end
  1715.         $game_system.slave_windows.each_value { |window| window.write_all }
  1716.         return
  1717.       end
  1718.       if $game_system.text_skip
  1719.         if $game_system.skip_mode == WRITE_FASTER and Input.press?(Input::C)
  1720.           # the player is holding the action button, write faster
  1721.           speed /= 3
  1722.         elsif $game_system.skip_mode == WRITE_ALL and Input.trigger?(Input::C)
  1723.           # the player pressed the action button, write all the text
  1724.           while (c = @text.slice!(/./m)) != nil
  1725.             write_char(c)
  1726.           end
  1727.           $game_system.slave_windows.each_value { |window| window.write_all }
  1728.           return
  1729.         end
  1730.       end
  1731.       while @ignore
  1732.         c = @text.slice!(/./m)
  1733.         if c != nil
  1734.           write_char(c)
  1735.         end
  1736.       end
  1737.       if @pause_time > 0
  1738.         @pause_time -= 1
  1739.         return
  1740.       end
  1741.       if Graphics.frame_count - @count >= speed
  1742.         if $game_system.sound_effect != ""
  1743.           Audio.se_play("Audio/SE/" + $game_system.sound_effect, 60, 100)
  1744.         end
  1745.         @count = Graphics.frame_count
  1746.         c = @text.slice!(/./m)
  1747.         if c != nil
  1748.           write_char(c)
  1749.         end
  1750.       end
  1751.       return
  1752.     end
  1753.    
  1754.     if $game_system.animated_faces and $game_system.resting_face != ""
  1755.       @done = true
  1756.     end
  1757.    
  1758.     # If inputting number
  1759.     if @input_number_window != nil
  1760.       @input_number_window.update
  1761.       # Confirm
  1762.       if Input.trigger?(Input::C)
  1763.         $game_system.se_play($data_system.decision_se)
  1764.         $game_variables[$game_temp.num_input_variable_id] =
  1765.           @input_number_window.number
  1766.         $game_map.need_refresh = true
  1767.         # Dispose of number input window
  1768.         @input_number_window.dispose
  1769.         @input_number_window = nil
  1770.         terminate_message
  1771.       end
  1772.       return
  1773.     end
  1774.    
  1775.     if @wait != 0
  1776.       return
  1777.     end
  1778.    
  1779.     # If message is being displayed and contents are all written
  1780.     if @contents_showing
  1781.       # if choice
  1782.       if $game_temp.choice_max > 0
  1783.         if !@choice_window.active
  1784.           @choice_window.visible = true
  1785.           @choice_window.active = true
  1786.           @choice_window.index = 0
  1787.         end
  1788.         @choice_window.update
  1789.       else
  1790.         # If choice isn't being displayed, show pause sign
  1791.         self.pause = $game_system.show_pause
  1792.       end
  1793.         # Cancel
  1794.         if Input.trigger?(Input::B)
  1795.           if $game_temp.choice_max > 0 and $game_temp.choice_cancel_type > 0
  1796.             $game_system.se_play($data_system.cancel_se)
  1797.             $game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
  1798.             terminate_message
  1799.           end
  1800.         end
  1801.         # Confirm
  1802.         if Input.trigger?(Input::C) and !(@wait > 0)
  1803.           @done = true
  1804.           $game_system.slave_windows.each_value { |window|
  1805.             window.write_all
  1806.             if !window.done
  1807.               @done = false
  1808.             end
  1809.           }
  1810.           if @done
  1811.             if $game_temp.choice_max > 0
  1812.               $game_system.se_play($data_system.decision_se)
  1813.               $game_temp.choice_proc.call(@choice_window.index)
  1814.             end
  1815.             terminate_message
  1816.           else
  1817.             @finishing_up = true
  1818.           end
  1819.         end
  1820.         return
  1821.       end
  1822.      
  1823.     if @finishing_up
  1824.       $game_system.slave_windows.each_value { |window|
  1825.         if !window.done
  1826.           @done = true
  1827.           break
  1828.         end
  1829.       }
  1830.      
  1831.       if @done = false
  1832.         terminate_message
  1833.       end
  1834.     end
  1835.     # If display wait message or choice exists when not fading out
  1836.     if @fade_out == false and $game_temp.message_text != nil
  1837.       @contents_showing = true
  1838.       $game_temp.message_window_showing = true
  1839.      
  1840.       reset_window
  1841.       refresh
  1842.       Graphics.frame_reset
  1843.       if @show
  1844.         self.visible = true
  1845.       end
  1846.       self.contents_opacity = 0
  1847.       if @input_number_window != nil
  1848.         @input_number_window.contents_opacity = 0
  1849.       end
  1850.       @fade_in = true
  1851.       return
  1852.     end
  1853.     # If message which should be displayed is not shown, but window is visible
  1854.     if self.visible
  1855.       @fade_out = true
  1856.       self.opacity -= 48
  1857.       @name_window.opacity -= 48
  1858.       @shake_sprite.opacity -= 48
  1859.       @comic.opacity -= 48
  1860.       @face.opacity -= 48
  1861.       @window_back.opacity -= 48
  1862.       if self.opacity == 0
  1863.         self.visible = false
  1864.         @face.opacity = 0
  1865.         @window_back.opacity = 0
  1866.         @choice_window.visible = false
  1867.         @choice_window.active = false
  1868.         @comic.opacity = 0
  1869.         @name_window.visible = false
  1870.         @shake_sprite.bitmap.clear
  1871.         @shake_sprite.opacity = 255
  1872.         @name_window.dummy_window.visible = false
  1873.         @name_window.update
  1874.         @fade_out = false
  1875.         $game_temp.message_window_showing = false
  1876.       end
  1877.       return
  1878.     end
  1879.    
  1880.     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
  1881.      
  1882.         $game_system.indy_windows.each_pair {|name, window|
  1883.           if window.show == true
  1884.             window.dispose
  1885.             $game_system.indy_windows.delete(name)
  1886.           end
  1887.         }
  1888.     end
  1889.   end
  1890.  
  1891.   #--------------------------------------------------------------------------
  1892.   # * Process and write the given character
  1893.   #--------------------------------------------------------------------------
  1894.   def write_char(c)
  1895.     if c == "\000"
  1896.       # Return to original text
  1897.       c = "\\"
  1898.     end
  1899.     # If \C[n]
  1900.     if c == "\001"
  1901.     # Change text color
  1902.       @text.sub!(/\[([0-9]+)\]/, "")
  1903.       color = $1.to_i
  1904.       if color >= 0 and color <= 7
  1905.         self.contents.font.color = text_color(color)
  1906.       end
  1907.       # go to next text
  1908.       return
  1909.     end
  1910.     # If \G
  1911.     if c == "\002"
  1912.       # Make gold window
  1913.       if @gold_window == nil
  1914.         @gold_window = Window_Gold.new
  1915.         @gold_window.x = 560 - @gold_window.width
  1916.         if $game_temp.in_battle
  1917.           @gold_window.y = 192
  1918.         else
  1919.           @gold_window.y = self.y >= 128 ? 32 : 384
  1920.         end
  1921.         @gold_window.opacity = self.opacity
  1922.         @gold_window.back_opacity = self.back_opacity
  1923.       end
  1924.       # go to next text
  1925.       return
  1926.     end
  1927.     # If \skip
  1928.     if c == "\003"
  1929.       # toggle text skipping
  1930.       $game_system.text_skip = !$game_system.text_skip
  1931.       # go to next text
  1932.       return
  1933.     end
  1934.     # If \b
  1935.     if c == "\004"
  1936.       # toggle bold
  1937.       self.contents.font.bold = !self.contents.font.bold
  1938.       # go to next text
  1939.       return
  1940.     end
  1941.     # If \i
  1942.     if c == "\005"
  1943.       # toggle italics
  1944.       self.contents.font.italic = !self.contents.font.italic
  1945.       # go to next text
  1946.       return
  1947.     end
  1948.     # If \s
  1949.     if c == "\006"
  1950.       # toggle shadow
  1951.       $game_system.shadowed_text = !$game_system.shadowed_text
  1952.       # go to next text
  1953.       return
  1954.     end
  1955.     # If \font
  1956.     if c == "\007"
  1957.       # change font
  1958.       @text.sub!(/\[(.*?)\]/, "")
  1959.       font = $1.to_s
  1960.       $game_system.font = font
  1961.       if font == ""
  1962.         self.contents.font.name = Font.default_name
  1963.       else
  1964.         self.contents.font.name = font
  1965.       end
  1966.       # go to next text
  1967.       return
  1968.     end
  1969.     # If \p[n]
  1970.     if c == "\010"
  1971.       @text.sub!(/\[([0-9]+)\]/, "")
  1972.       @pause_time = $1.to_i
  1973.  
  1974.       # go to next text
  1975.       return
  1976.     end
  1977.    
  1978.     # If \w[n]
  1979.     if c == "\011"
  1980.       @text.sub!(/\[([0-9]+)\]/, "")
  1981.       @wait = $1.to_i
  1982.  
  1983.       # go to next text
  1984.       return
  1985.     end
  1986.    
  1987.     # If \ws[n]
  1988.     if c == "\013"
  1989.       @text.sub!(/\[([0-9]+)\]/, "")
  1990.       $game_system.write_speed = $1.to_i
  1991.  
  1992.       # go to next text
  1993.       return
  1994.     end
  1995.     # If \oa[n]
  1996.     if c == "\014"
  1997.       @text.sub!(/\[([0-9]+)\]/, "")
  1998.       index = $1.to_i
  1999.       @text.sub!("  ", "")
  2000.       item = $data_armors[index]
  2001.       # draw the icon
  2002.       icon = RPG::Cache.icon(item.icon_name)
  2003.       line = self.contents.text_size("dj").height
  2004.       self.contents.blt(@x + 4, (@y * line) + 4, icon, Rect.new(0, 0, 24, 24))
  2005.       @x += 24
  2006.  
  2007.       # go to next text
  2008.       return
  2009.     end
  2010.    
  2011.     # If \oi[n]
  2012.     if c == "\015"
  2013.       @text.sub!(/\[([0-9]+)\]/, "")
  2014.       index = $1.to_i
  2015.       @text.sub!("  ", "")
  2016.       item = $data_items[index]
  2017.       # draw the icon
  2018.       icon = RPG::Cache.icon(item.icon_name)
  2019.       line = self.contents.text_size("dj").height
  2020.       self.contents.blt(@x + 4, (@y * line) + 4, icon, Rect.new(0, 0, 24, 24))
  2021.       @x += 24
  2022.  
  2023.       # go to next text
  2024.       return
  2025.     end
  2026.    
  2027.     # If \ic[name]
  2028.     if c == "\027"
  2029.       @text.sub!(/\[(.*?)\]/, "")
  2030.       # draw the icon
  2031.       icon = RPG::Cache.icon($1.to_s)
  2032.       line = self.contents.text_size("dj").height
  2033.       self.contents.blt(@x + 4, (@y * line) + 4, icon, Rect.new(0, 0, 24, 24))
  2034.       @x += 24
  2035.  
  2036.       # go to next text
  2037.       return
  2038.     end
  2039.    
  2040.     # If \os[n]
  2041.     if c == "\016"
  2042.       @text.sub!(/\[([0-9]+)\]/, "")
  2043.       index = $1.to_i
  2044.       @text.sub!("  ", "")
  2045.       item = $data_skills[index]
  2046.       # draw the icon
  2047.       icon = RPG::Cache.icon(item.icon_name)
  2048.       line = self.contents.text_size("dj").height
  2049.       self.contents.blt(@x + 2, (@y * line) + 4, icon, Rect.new(0, 0, 24, 24))
  2050.       @x += 24
  2051.  
  2052.       # go to next text
  2053.       return
  2054.     end
  2055.    
  2056.     # If \ow[n]
  2057.     if c == "\017"
  2058.       @text.sub!(/\[([0-9]+)\]/, "")
  2059.       index = $1.to_i
  2060.       @text.sub!("  ", "")
  2061.       item = $data_weapons[index]
  2062.       # draw the icon
  2063.       icon = RPG::Cache.icon(item.icon_name)
  2064.       line = self.contents.text_size("dj").height
  2065.       self.contents.blt(@x + 2, (@y * line) + 4, icon, Rect.new(0, 0, 24, 24))
  2066.       @x += 24
  2067.      
  2068.       # go to next text
  2069.       return
  2070.     end
  2071.    
  2072.     # If \tc
  2073.     if c == "\020"
  2074.       # center justify
  2075.       $game_system.text_justification = CENTER
  2076.       get_x_value
  2077.       # go to next text
  2078.       return
  2079.     end
  2080.    
  2081.     # If \tl
  2082.     if c == "\021"
  2083.       # left justify
  2084.       $game_system.text_justification = LEFT
  2085.       get_x_value
  2086.       # go to next text
  2087.       return
  2088.     end
  2089.    
  2090.     # If \tr
  2091.     if c == "\022"
  2092.       # right justify
  2093.       $game_system.text_justification = RIGHT
  2094.       get_x_value
  2095.       # go to next text
  2096.       return
  2097.     end
  2098.    
  2099.     # If \ignr
  2100.     if c == "\023"
  2101.       # set ignore flage
  2102.       @ignore = true
  2103.       # go to next text
  2104.       return
  2105.     end
  2106.    
  2107.     # if \slv
  2108.     if c == "\024"
  2109.       # we need to show a slave window
  2110.       @text.sub!(/\[(.*?)\]/, "")
  2111.       name = $1.to_s
  2112.       $game_system.slave_windows[name].show = true
  2113.       return
  2114.     end
  2115.    
  2116.     # if \ind
  2117.     if c == "\025"
  2118.       # we need to show a independent window
  2119.       @text.sub!(/\[(.*?)\]/, "")
  2120.       name = $1.to_s
  2121.       if $game_system.indy_windows[name].show
  2122.         $game_system.indy_windows[name].dispose
  2123.         $game_system.indy_windows.delete(name)
  2124.       else
  2125.         $game_system.indy_windows[name].show = true
  2126.       end
  2127.       return
  2128.     end
  2129.    
  2130.     # if \c (hex color)
  2131.     if c == "\026"
  2132.       # convert hex color to RGB
  2133.       @text.sub!(/\[([0123456789abcdef]+)\]/, "")
  2134.       hex_code = $1.to_s
  2135.      
  2136.       red   = ("0x" + hex_code.slice(0..1)).hex
  2137.       blue  = ("0x" + hex_code.slice(2..3)).hex
  2138.       green = ("0x" + hex_code.slice(4..5)).hex
  2139.      
  2140.       self.contents.font.color = Color.new(red, blue, green)
  2141.       return
  2142.     end
  2143.    
  2144.     # if \sk[i] (begin shake)
  2145.     if c == "\030"
  2146.       @shake_text = true
  2147.       return
  2148.     end
  2149.     # if \sk (end shake)
  2150.     if c == "\031"
  2151.       @shake_text = false
  2152.       return
  2153.     end
  2154.    
  2155.     # If new line text
  2156.     if c == "\n"
  2157.       # Add 1 to y
  2158.       if !@ignore
  2159.         @y += 1
  2160.       end
  2161.       # check for scroll
  2162.       line = self.contents.text_size("dj").height
  2163.       if @y * line + 2 > self.height - 32 - line and @text.slice(/./m) != nil
  2164.         self.oy += line
  2165.       end
  2166.       if @text != ""
  2167.         get_x_value
  2168.       end
  2169.       @ignore = false
  2170.  
  2171.       # go to next text
  2172.       return
  2173.     end
  2174.     if @ignore
  2175.       return
  2176.     end
  2177.     # Draw text
  2178.     line = self.contents.text_size("dj").height
  2179.     if $game_system.shadowed_text
  2180.       old_color = self.contents.font.color.clone
  2181.       if @shake_text
  2182.         @shake_sprite.bitmap.font.color = $game_system.shadow_color    
  2183.         @shake_sprite.bitmap.draw_text(6 + @x, line * @y + 2, 40, 32, c)
  2184.         @shake_sprite.bitmap.font.color = old_color
  2185.       else
  2186.         self.contents.font.color = $game_system.shadow_color    
  2187.         self.contents.draw_text(6 + @x, line * @y + 2, 40, 32, c)
  2188.         self.contents.font.color = old_color
  2189.       end
  2190.     end
  2191.     if @shake_text
  2192.       @shake_sprite.bitmap.draw_text(4 + @x, line * @y, 40, 32, c)
  2193.     else
  2194.       self.contents.draw_text(4 + @x, line * @y, 40, 32, c)
  2195.     end
  2196.     # Add x to drawn text width
  2197.     @x += self.contents.text_size(c).width
  2198.   end
  2199.  
  2200.   def get_x_value
  2201.     # text justification - offset for first line
  2202.     if $game_system.text_justification == CENTER
  2203.       # get the length of the current line
  2204.       w = self.contents.text_size(@text.split("\n")[0]).width
  2205.       @x = (self.width - w - 48) / 2
  2206.     elsif $game_system.text_justification == RIGHT
  2207.       # get the length of the current line
  2208.       w = self.contents.text_size(@text.split("\n")[0]).width
  2209.       @x = self.width - w - 48
  2210.     else # left
  2211.       if $game_system.face_graphic == ""
  2212.         @x = 0
  2213.       else
  2214.         @x = @face_offset
  2215.       end
  2216.     end
  2217.   end
  2218.    
  2219. end
  2220.  
  2221. #==============================================================================
  2222. # ** Window_Choice
  2223. #------------------------------------------------------------------------------
  2224. #  This message window is used to display choices.
  2225. #==============================================================================
  2226. class Window_Choice < Window_Selectable
  2227.   def initialize (choices)
  2228.     super(0, 0, 32, choices.size * 32)
  2229.     self.visible = false
  2230.     self.active = false
  2231.     self.z = 9999
  2232.     @index = 0
  2233.     @item_max = choices.size
  2234.     @choices = choices
  2235.     self.contents = Bitmap.new(32, 32)
  2236.     self.opacity = $game_system.opacity
  2237.     self.back_opacity = $game_system.back_opacity
  2238.   end
  2239.  
  2240.   def refresh
  2241.     # determine necessary width
  2242.     width = 64
  2243.     for line in @choices
  2244.       width = [width, (self.contents.text_size(line).width + 48)].max
  2245.     end
  2246.     self.width = width
  2247.     self.height = @choices.size * 32 + 32
  2248.     self.contents = Bitmap.new(width - 32, height - 32)
  2249.     if $game_system.font == ""
  2250.       self.contents.font.name = Font.default_name
  2251.     else
  2252.       self.contents.font.name = $game_system.font
  2253.     end
  2254.     if $game_system.font_color.nil?
  2255.       self.contents.font.color = normal_color
  2256.     else
  2257.       self.contents.font.color = $game_system.font_color
  2258.     end
  2259.     if $game_system.windowskin != ""  
  2260.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin)
  2261.     else
  2262.       self.windowskin = RPG::Cache.windowskin($data_system.windowskin_name)
  2263.     end
  2264.    
  2265.     # draw choices
  2266.     @y = 0
  2267.     for line in @choices
  2268.       @x = 0
  2269.       @text = line
  2270.       while (c = line.slice!(/./m)) != nil
  2271.         write_char(c)
  2272.       end
  2273.       @y += 1
  2274.     end
  2275.   end
  2276.  
  2277.   def write_char(c)
  2278.    
  2279.     # If \oa[n]
  2280.     if c == "\014"
  2281.       @text.sub!(/\[([0-9]+)\]/, "")
  2282.       index = $1.to_i
  2283.       @text.sub!("  ", "")
  2284.       item = $data_armors[index]
  2285.       # draw the icon
  2286.       icon = RPG::Cache.icon(item.icon_name)
  2287.       self.contents.blt(@x + 4, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  2288.       @x += 24
  2289.     end
  2290.    
  2291.     # If \oi[n]
  2292.     if c == "\015"
  2293.       @text.sub!(/\[([0-9]+)\]/, "")
  2294.       index = $1.to_i
  2295.       @text.sub!("  ", "")
  2296.       item = $data_items[index]
  2297.       # draw the icon
  2298.       icon = RPG::Cache.icon(item.icon_name)
  2299.       self.contents.blt(@x + 4, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  2300.       @x += 24
  2301.  
  2302.       # go to next text
  2303.       return
  2304.     end
  2305.    
  2306.     # If \ic[name]
  2307.     if c == "\027"
  2308.       @text.sub!(/\[(.*?)\]/, "")
  2309.       # draw the icon
  2310.       icon = RPG::Cache.icon($1.to_s)
  2311.       self.contents.blt(@x + 4, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  2312.       @x += 24
  2313.  
  2314.       # go to next text
  2315.       return
  2316.     end
  2317.    
  2318.     # If \os[n]
  2319.     if c == "\016"
  2320.       @text.sub!(/\[([0-9]+)\]/, "")
  2321.       index = $1.to_i
  2322.       @text.sub!("  ", "")
  2323.       item = $data_skills[index]
  2324.       # draw the icon
  2325.       icon = RPG::Cache.icon(item.icon_name)
  2326.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  2327.       @x += 24
  2328.  
  2329.       # go to next text
  2330.       return
  2331.     end
  2332.    
  2333.     # If \ow[n]
  2334.     if c == "\017"
  2335.       @text.sub!(/\[([0-9]+)\]/, "")
  2336.       index = $1.to_i
  2337.       @text.sub!("  ", "")
  2338.       item = $data_weapons[index]
  2339.       # draw the icon
  2340.       icon = RPG::Cache.icon(item.icon_name)
  2341.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  2342.       @x += 24
  2343.      
  2344.       # go to next text
  2345.       return
  2346.     end
  2347.    
  2348.     # If \ic[name]
  2349.     if c == "\027"
  2350.       @text.sub!(/\[(.*?)\]/, "")
  2351.       # draw the icon
  2352.       icon = RPG::Cache.icon($1.to_s)
  2353.       self.contents.blt(@x + 4, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  2354.       @x += 24
  2355.  
  2356.       # go to next text
  2357.       return
  2358.     end
  2359.    
  2360.     # If \C[n]
  2361.     if c == "\001"
  2362.     # Change text color
  2363.       @text.sub!(/\[([0-9]+)\]/, "")
  2364.       color = $1.to_i
  2365.       if color >= 0 and color <= 7
  2366.         self.contents.font.color = text_color(color)
  2367.       end
  2368.       # go to next text
  2369.       return
  2370.     end
  2371.    
  2372.     # if \c (hex color)
  2373.     if c == "\026"
  2374.       # convert hex color to RGB
  2375.       @text.sub!(/\[([0123456789abcdef]+)\]/, "")
  2376.       hex_code = $1.to_s
  2377.      
  2378.       red   = ("0x" + hex_code.slice(0..1)).hex
  2379.       blue  = ("0x" + hex_code.slice(2..3)).hex
  2380.       green = ("0x" + hex_code.slice(4..5)).hex
  2381.      
  2382.       self.contents.font.color = Color.new(red, blue, green)
  2383.       return
  2384.     end
  2385.    
  2386.     # Draw text
  2387.     line = 32
  2388.     if $game_system.shadowed_text
  2389.       old_color = self.contents.font.color.clone
  2390.       self.contents.font.color = $game_system.shadow_color    
  2391.       self.contents.draw_text(6 + @x, line * @y + 2, 40, 32, c)
  2392.       self.contents.font.color = old_color
  2393.     end
  2394.     self.contents.draw_text(4 + @x, line * @y, 40, 32, c)
  2395.     # Add x to drawn text width
  2396.     @x += self.contents.text_size(c).width
  2397.   end
  2398.      
  2399.   def set_choices(choices)
  2400.     @choices = Array.new
  2401.     for choice in choices
  2402.       @choices.push(choice.clone)
  2403.     end
  2404.     @item_max = @choices.size
  2405.     for choice in choices
  2406.       # variables
  2407.       choice.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  2408.      
  2409.       # actor names
  2410.       choice.gsub!(/\\[Nn]\[([0-9]+)\]/) {
  2411.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  2412.       }
  2413.       choice.gsub!(/\\[Nn][Pp]\[([0-9]+)\]/) {
  2414.         $game_party.actors[$1.to_i] != nil ? $game_party.actors[$1.to_i].name : ""
  2415.       }
  2416.      
  2417.       # armor, items, skills, and weapons
  2418.       choice.gsub!(/\\[Oo][Aa]\[([0-9]+)\]/) {
  2419.         item = $data_armors[$1.to_i]
  2420.         "\014[#{$1}]" + "  " + item.name
  2421.       }
  2422.       choice.gsub!(/\\[Oo][Ii]\[([0-9]+)\]/) {
  2423.         item = $data_items[$1.to_i]
  2424.         "\015[#{$1}]" + "  " + item.name
  2425.       }
  2426.       choice.gsub!(/\\[Oo][Ss]\[([0-9]+)\]/) {
  2427.         item = $data_skills[$1.to_i]
  2428.         "\016[#{$1}]" + "  " + item.name
  2429.       }
  2430.       choice.gsub!(/\\[Oo][Ww]\[([0-9]+)\]/) {
  2431.         item = $data_weapons[$1.to_i]
  2432.         "\017[#{$1}]" + "  " + item.name
  2433.       }
  2434.       choice.gsub!(/\\[Ii][Cc]\[(.*?)\]/) {
  2435.         "\027[#{$1}]"
  2436.       }
  2437.      
  2438.       # color
  2439.       choice.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  2440.       choice.gsub!(/\\[Cc]\[0x([0123456789abcdef]+)\]/) { "\026[#{$1}]" }
  2441.      
  2442.     end
  2443.     refresh
  2444.   end
  2445. end
  2446.  
  2447. #==============================================================================
  2448. # ** Window_Name
  2449. #------------------------------------------------------------------------------
  2450. #  This window is used to display names above the message window.  Uncomment
  2451. #   and modify the various sections to customize.
  2452. #==============================================================================
  2453. class Window_Name < Window_Base
  2454.   attr_accessor :dummy_window
  2455.  
  2456.   def initialize
  2457.     super(0, 0, 32, 64)
  2458.     self.contents = Bitmap.new(32, 32)
  2459.     self.opacity = 0
  2460.    
  2461.    
  2462.     @dummy_window = Window_Dummy.new
  2463.    
  2464.     self.visible = false
  2465.   end
  2466.  
  2467.   def set_name(name)
  2468.     @name = name
  2469.     refresh
  2470.   end
  2471.  
  2472.   def refresh
  2473.     if @name == nil
  2474.       return
  2475.     end
  2476.     self.width = self.contents.text_size(@name).width + 48
  2477.     self.contents = Bitmap.new(width - 32, height - 32)
  2478.    
  2479.    
  2480.     if $game_system.name_window
  2481.       @dummy_window.x = self.x
  2482.       @dummy_window.y = self.y + 12
  2483.       @dummy_window.set(height - 24, width - 12)
  2484.     end
  2485.    
  2486.     if $game_system.font == ""
  2487.       self.contents.font.name = Font.default_name
  2488.     else
  2489.       self.contents.font.name = $game_system.font
  2490.     end
  2491.     # uncomment this and change the font to give the name window a fancy font
  2492.     self.contents.font.name = "NAZWA"
  2493.     self.contents.font.color = Color.new(101, 49, 49, 255)
  2494.     self.contents.draw_text(0, 0, self.width, 32, @name)
  2495.     self.contents.draw_text(0, 2, self.width, 32, @name)
  2496.     self.contents.draw_text(2, 0, self.width, 32, @name)
  2497.     self.contents.draw_text(2, 2, self.width, 32, @name)
  2498.     # change the color to give the name window a seperate color
  2499.     self.contents.font.color = Color.new(175, 86, 86, 255)
  2500.     self.contents.draw_text(1, 1, self.width, 32, @name)
  2501.   end
  2502.  
  2503.   def visible=(v)
  2504.     if $game_system.name_window
  2505.       @dummy_window.visible = v
  2506.     end
  2507.     super(v)
  2508.   end
  2509.  
  2510.  
  2511.  
  2512.   def update
  2513.     super
  2514.     if $game_system.name_window
  2515.       @dummy_window.x = self.x
  2516.       @dummy_window.y = self.y + 12
  2517.       @dummy_window.update
  2518.     end
  2519.   end
  2520.  
  2521.   def dispose
  2522.     @dummy_window.dispose
  2523.     super
  2524.   end
  2525. end
  2526.  
  2527. class Window_Dummy < Window_Base
  2528.   def initialize
  2529.     super(0, 0, 32, 64)
  2530.     self.z = 9999
  2531.     self.visible = false
  2532.    
  2533.   end
  2534.  
  2535.   def set(height, width)
  2536.     self.height = height
  2537.     self.width = width
  2538.   end
  2539.  
  2540.   def update
  2541.     super
  2542.     if $game_system.windowskin != ""  
  2543.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin)
  2544.     else
  2545.       self.windowskin = RPG::Cache.windowskin($data_system.windowskin_name)
  2546.     end
  2547. #    self.windowskin = RPG::Cache.windowskin('sandstone')
  2548.   end
  2549. end
  2550.  
  2551. #==============================================================================
  2552. # ** Window_Slave
  2553. #------------------------------------------------------------------------------
  2554. #  These are slave windows to the main message window.  They will close when
  2555. #   the user terminates them.  Initial settings are identical to the main
  2556. #   message window, with one exception.  When in normal mode, it will apear
  2557. #   above if the main message is below, below if it is above or centered.  Use
  2558. #   message codes to change the settings for this window.
  2559. #==============================================================================
  2560. class Window_Slave < Window_Base
  2561.   attr_accessor :show
  2562.   attr_reader :done
  2563.  
  2564.   def write_all
  2565.     @write_all = true
  2566.   end
  2567.  
  2568.   #--------------------------------------------------------------------------
  2569.   # * Object Initialization
  2570.   #--------------------------------------------------------------------------
  2571.   def initialize (text)
  2572.     super(0, 0, 33, 33)
  2573.     @text = text
  2574.    
  2575.     # x-coordinate depends on justification
  2576.     if @justification == RIGHT
  2577.       self.x = 640 - self.width
  2578.     elsif @justification == LEFT
  2579.       self.x = 0
  2580.     else # center
  2581.       self.x = (640 - self.width) / 2
  2582.     end
  2583.     # y-coordinate depends on height
  2584.     self.y = 480 - $game_system.window_height - 16
  2585.     self.contents = Bitmap.new(width - 32, height - 32)
  2586.     if $game_system.font == ""
  2587.       self.contents.font.name = Font.default_name
  2588.     else
  2589.       self.contents.font.name = $game_system.font
  2590.     end
  2591.     self.visible = false
  2592.     self.z = 9998
  2593.     @fade_in = false
  2594.     @fade_out = false
  2595.     @contents_showing = false
  2596.    
  2597.     # face graphic sprite
  2598.     @face = Sprite.new
  2599.     @face.opacity = 0
  2600.     @face.z = self.z + 1
  2601.     @face_offset = 0
  2602.    
  2603.     # choice window
  2604.     @choice_window = Window_Choice.new([])
  2605.     @choice_window.back_opacity = $game_system.back_opacity
  2606.    
  2607.     @comic_style = $game_system.comic_style
  2608.     @name = $game_system.name
  2609.    
  2610.     # comic sprite
  2611.     @comic = Sprite.new
  2612.     @comic.opacity = 0
  2613.     @comic.z = self.z + 1
  2614.     if @comic_style == TALK1
  2615.       @comic.bitmap = RPG::Cache.windowskin("talk1")
  2616.     elsif @comic_style == TALK2
  2617.       @comic.bitmap = RPG::Cache.windowskin("talk2")
  2618.     else # thought
  2619.       @comic.bitmap = RPG::Cache.windowskin("thought")
  2620.     end
  2621.    
  2622.     # shake bitmaps
  2623.     @shake_sprite = Sprite.new
  2624.     @shake_sprite.bitmap = Bitmap.new(width - 32, height - 32)
  2625.     @shake_sprite.x = self.x + 16
  2626.     @shake_sprite.y = self.y + 8
  2627.     @shake_sprite.z = self.z + 1
  2628.    
  2629.     @pause_time = 0
  2630.     @wait = 0
  2631.    
  2632.     @mode = $game_system.ums_mode
  2633.     self.height = $game_system.window_height
  2634.     self.width = $game_system.window_width
  2635.     @justification = $game_system.window_justification
  2636.     @face_graphic = $game_system.face_graphic
  2637.     @face_graphic_justification = $game_system.face_graphic_justification
  2638.     @message_event = $game_system.message_event
  2639.     if $game_system.message_position == 2 # down
  2640.       @message_position = 0
  2641.     else
  2642.       @message_postion = 2
  2643.     end
  2644.     @face_graphic_position = $game_system.face_graphic_position
  2645.     if $game_system.font == ""
  2646.       @font = Font.default_name
  2647.     else
  2648.       @font = $game_system.font
  2649.     end
  2650.     @text_justification = $game_system.text_justification
  2651.    
  2652.     @shake = $game_system.shake
  2653.    
  2654.     @face_frame = 0
  2655.    
  2656.     refresh
  2657.   end
  2658.   #--------------------------------------------------------------------------
  2659.   # * Dispose
  2660.   #--------------------------------------------------------------------------
  2661.   def dispose
  2662.     terminate_message
  2663.     $game_temp.message_window_showing = false
  2664.     if @input_number_window != nil
  2665.       @input_number_window.dispose
  2666.     end
  2667.     @face.dispose
  2668.     @choice_window.dispose
  2669.     @comic.dispose
  2670.     @shake_sprite.dispose
  2671.     if @name_window != nil
  2672.       @name_window.dispose
  2673.     end
  2674.     super
  2675.   end
  2676.   #--------------------------------------------------------------------------
  2677.   # * Terminate Message
  2678.   #--------------------------------------------------------------------------
  2679.   def terminate_message
  2680.     self.active = false
  2681.     self.pause = false
  2682.     self.contents.clear
  2683.     # Clear showing flag
  2684.     @contents_showing = false
  2685.     # Call message callback
  2686.     if $game_temp.message_proc != nil
  2687.       $game_temp.message_proc.call
  2688.     end
  2689.     # Clear variables related to text, choices, and number input
  2690.     $game_temp.message_text = nil
  2691.     $game_temp.message_proc = nil
  2692.     $game_temp.choice_start = 99
  2693.     $game_temp.choice_max = 0
  2694.     $game_temp.choice_cancel_type = 0
  2695.     $game_temp.choice_proc = nil
  2696.     $game_temp.num_input_start = 99
  2697.     $game_temp.num_input_variable_id = 0
  2698.     $game_temp.num_input_digits_max = 0
  2699.     # Open gold window
  2700.     if @gold_window != nil
  2701.       @gold_window.dispose
  2702.       @gold_window = nil
  2703.     end
  2704.     @choice_window.visible = false
  2705.     @choice_window.active = false
  2706.     @comic.opacity = 0
  2707.   end
  2708.   #--------------------------------------------------------------------------
  2709.   # * Refresh
  2710.   #--------------------------------------------------------------------------
  2711.   def refresh
  2712.    
  2713.     self.contents.clear
  2714.     if $game_system.font_color.nil?
  2715.       self.contents.font.color = normal_color
  2716.     else
  2717.       self.contents.font.color = $game_system.font_color
  2718.     end
  2719.     if $game_system.windowskin != ""  
  2720.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin)
  2721.     else
  2722.       self.windowskin = RPG::Cache.windowskin($data_system.windowskin_name)
  2723.     end
  2724.     @x = @y = 0
  2725.  
  2726.     # If waiting for a message to be displayed
  2727.     if @text != nil
  2728.       # replace shortcuts with original code
  2729.       $game_system.shortcuts.each { |shortcut, code|
  2730.         @text.gsub!(shortcut, code)
  2731.       }
  2732.      
  2733.       # Control text processing
  2734.       begin
  2735.         last_text = @text.clone
  2736.         @text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  2737.       end until @text == last_text
  2738.       @text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  2739.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  2740.       end
  2741.      
  2742.       # window mode
  2743.       if @text.index(/\\[Mm]/) != nil
  2744.         if $game_system.ums_mode == NORMAL_MODE
  2745.           @mode = FIT_WINDOW_TO_TEXT
  2746.         else
  2747.           @mode = NORMAL_MODE
  2748.         end
  2749.         @text.gsub!(/\\[Mm]/) { "" }
  2750.       end
  2751.      
  2752.       # window height
  2753.       @text.gsub!(/\\[Hh][Ee][Ii][Gg][Hh][Tt]\[([0-9]+)\]/) do
  2754.         self.height = $1.to_i
  2755.         ""
  2756.       end
  2757.      
  2758.       # window width
  2759.       @text.gsub!(/\\[Ww][Ii][Dd][Tt][Hh]\[([0-9]+)\]/) do
  2760.         self.width = $1.to_i
  2761.         ""
  2762.       end
  2763.      
  2764.       # justification
  2765.       @text.gsub!(/\\[Jj][Rr]/) do
  2766.         @justification = RIGHT
  2767.         reset_window
  2768.         ""
  2769.       end
  2770.       @text.gsub!(/\\[Jj][Cc]/) do
  2771.         @justification = CENTER
  2772.         reset_window
  2773.         ""
  2774.       end      
  2775.       @text.gsub!(/\\[Jj][Ll]/) do
  2776.         @justification = LEFT
  2777.         reset_window
  2778.         ""
  2779.       end
  2780.      
  2781.       # face graphics
  2782.       @text.gsub!(/\\[Ff][Aa][Cc][Ee]\[(.*?)\]/) do
  2783.         @face_graphic = $1.to_s
  2784.         if $1.to_s == ""
  2785.           @face.opacity = 0
  2786.         end
  2787.         ""
  2788.       end
  2789.       @text.gsub!(/\\[Ff][Ll]/) do
  2790.         @face_graphic_justification = LEFT
  2791.         ""
  2792.       end
  2793.       @text.gsub!(/\\[Ff][Rr]/) do
  2794.         @face_graphic_justification = RIGHT
  2795.         ""
  2796.       end
  2797.      
  2798.       # event centering
  2799.       @text.gsub!(/\\[Ee]\[([0-9]+)\]/) do
  2800.         @message_event = $1.to_i
  2801.         ""
  2802.       end
  2803.      
  2804.       # comic thingy
  2805.       @text.gsub!(/\\[Tt]1/) do
  2806.         @comic_style = TALK1
  2807.         @comic.bitmap = RPG::Cache.windowskin("talk1.png")
  2808.         ""
  2809.       end
  2810.       @text.gsub!(/\\[Tt]2/) do
  2811.         @comic_style = TALK2
  2812.         @comic.bitmap = RPG::Cache.windowskin("talk2.png")
  2813.         ""
  2814.       end
  2815.       @text.gsub!(/\\[Tt][Hh]/) do
  2816.         @comic_style = THOUGHT
  2817.         @comic.bitmap = RPG::Cache.windowskin("thought.png")
  2818.         ""
  2819.       end
  2820.      
  2821.       # name window
  2822.       @text.gsub!(/\\[Nn][Mm]\[(.*?)\]/) do
  2823.         @name = $1.to_s
  2824.         if $1.to_s == "" and @name_window != nil
  2825.           @name_window.visible = false
  2826.         end
  2827.         ""
  2828.       end
  2829.       if @name != ""
  2830.         # name window
  2831.         @name_window = Window_Name.new
  2832.         @name_window.z = self.z + 1
  2833.         @name_window.set_name(@name)
  2834.       end
  2835.      
  2836.       # shaking
  2837.       text.gsub!(/\\[Ss][Kk]\[([0-9]+)\]/) do
  2838.         $game_system.text_shake = $1.to_i
  2839.         "\030"
  2840.       end
  2841.       @text.gsub!(/\\[Ss][Kk]/) do
  2842.         "\031"
  2843.       end
  2844.       @text.gsub!(/\\[Ss][Hh][Kk]\[([0-9]+)\]/) do
  2845.         @shake = $1.to_i
  2846.         ""
  2847.       end
  2848.      
  2849.       # back opacity
  2850.       @text.gsub!(/\\[Bb][Oo][Pp][Cc]\[([0-9]+)\]/) do
  2851.         self.back_opacity = $1.to_i
  2852.         ""
  2853.       end
  2854.      
  2855.       # opacity
  2856.       @text.gsub!(/\\[Oo][Pp][Cc]\[([0-9]+)\]/) do
  2857.         self.opacity = $1.to_i
  2858.         ""
  2859.       end
  2860.      
  2861.       # Change "\\\\" to "\000" for convenience
  2862.       @text.gsub!(/\\\\/) { "\000" }
  2863.       # Change "\\C" to "\001" and "\\G" to "\002"
  2864.       @text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  2865.       @text.gsub!(/\\[Gg]/) { "\002" }
  2866.       @text.gsub!(/\\[Cc]\[0x([0123456789abcdef]+)\]/) { "\026[#{$1}]" }
  2867.      
  2868.       # text skip code
  2869.       @text.gsub!(/\\[Ss][Kk][Ii][Pp]/) { "\003" }
  2870.      
  2871.       # ignore code
  2872.       @text.gsub!(/\\[Ii][Gg][Nn][Rr]/) { "\023" }
  2873.      
  2874.       # bold and italics
  2875.       @text.gsub!(/\\[Bb]/) { "\004" }
  2876.       @text.gsub!(/\\[Ii]/) { "\005" }
  2877.      
  2878.       # shadow
  2879.       @text.gsub!(/\\[Ss]/) { "\006" }
  2880.      
  2881.       # font
  2882.       @text.gsub!(/\\[Ff][Oo][Nn][Tt]\[(.*?)\]/) { "\007[#{$1}]" }
  2883.      
  2884.       # pause and wait
  2885.       @text.gsub!(/\\[Pp]\[([0-9]+)\]/) { "\010[#{$1}]" }
  2886.       @text.gsub!(/\\[Ww]\[([0-9]+)\]/) { "\011[#{$1}]" }
  2887.      
  2888.       # write speed
  2889.       @text.gsub!(/\\[Ww][Ss]\[([0-9]+)\]/) { "\013[#{$1}]" }
  2890.            
  2891.       # armor, items, skills, and weapons
  2892.       @text.gsub!(/\\[Oo][Aa]\[([0-9]+)\]/) {
  2893.         item = $data_armors[$1.to_i]
  2894.         "\014[#{$1}]" + "  " + item.name
  2895.       }
  2896.       @text.gsub!(/\\[Oo][Ii]\[([0-9]+)\]/) {
  2897.         item = $data_items[$1.to_i]
  2898.         "\015[#{$1}]" + "  " + item.name
  2899.       }
  2900.       @text.gsub!(/\\[Oo][Ss]\[([0-9]+)\]/) {
  2901.         item = $data_skills[$1.to_i]
  2902.         "\016[#{$1}]" + "  " + item.name
  2903.       }
  2904.       @text.gsub!(/\\[Oo][Ww]\[([0-9]+)\]/) {
  2905.         item = $data_weapons[$1.to_i]
  2906.         "\017[#{$1}]" + "  " + item.name
  2907.       }
  2908.       @text.gsub!(/\\[Ii][Cc]\[(.*?)\]/) {
  2909.         "\027[#{$1}]"
  2910.       }
  2911.      
  2912.       # text justification
  2913.       @text.gsub!(/\\[Tt][Cc]/) { "\020" }
  2914.       @text.gsub!(/\\[Tt][Ll]/) { "\021" }
  2915.       @text.gsub!(/\\[Tt][Rr]/) { "\022" }
  2916.      
  2917.       # Resize the window to fit the contents?
  2918.       if @mode == FIT_WINDOW_TO_TEXT
  2919.         width = 1
  2920.         text = @text.split("\n")
  2921.         height = 0
  2922.         i = 0
  2923.         for line in text
  2924.           # don't count this line's width if it has the ignr code
  2925.           if !line.include?("\023")
  2926.             width = [width, self.contents.text_size(line).width].max
  2927.             delta = self.contents.text_size(line).height
  2928.             height += delta + (6 * i) + 3
  2929.             if i < 3
  2930.               i += 1
  2931.             end
  2932.           end
  2933.         end
  2934.        
  2935.         if @face_graphic != "" and ($game_system.face_graphic_position == CENTER or $game_system.face_graphic_position == BOTTOM)
  2936.           width += @face.bitmap.width
  2937.           if height < @face.bitmap.height
  2938.             height = @face.bitmap.height - 32
  2939.           end
  2940.         end
  2941.        
  2942.         if height == 0
  2943.           height = 1
  2944.         end
  2945.          
  2946.         self.width = width + 48
  2947.         self.height = height + 48
  2948.         self.contents = Bitmap.new(width + 16, height)
  2949.         if $game_system.font == ""
  2950.           self.contents.font.name = Font.default_name
  2951.         else
  2952.           self.contents.font.name = $game_system.font
  2953.         end
  2954.         if $game_system.font_color.nil?
  2955.           self.contents.font.color = normal_color
  2956.         else
  2957.           self.contents.font.color = $game_system.font_color
  2958.         end
  2959.  
  2960.       else
  2961.         if self.width != $game_system.window_height or self.height != $game_system.window_width
  2962.           self.width = $game_system.window_width
  2963.           self.height = $game_system.window_height
  2964.           self.contents = Bitmap.new(self.width - 32, self.height - 32)
  2965.           if $game_system.font == ""
  2966.             self.contents.font.name = Font.default_name
  2967.           else
  2968.             self.contents.font.name = $game_system.font
  2969.           end
  2970.           if $game_system.font_color.nil?
  2971.             self.contents.font.color = normal_color
  2972.           else
  2973.             self.contents.font.color = $game_system.font_color
  2974.           end
  2975.         end
  2976.       end
  2977.      
  2978.       reset_window
  2979.      
  2980.       get_x_value
  2981.      
  2982.       @count = Graphics.frame_count
  2983.       @pause_time = 0
  2984.       @ignore = false
  2985.       @done = false
  2986.       @face_frame = 0
  2987.     end
  2988.    
  2989.    
  2990.    
  2991.     # If number input
  2992.     if $game_temp.num_input_variable_id > 0
  2993.       digits_max = $game_temp.num_input_digits_max
  2994.       number = $game_variables[$game_temp.num_input_variable_id]
  2995.       @input_number_window = Window_InputNumber.new(digits_max)
  2996.       @input_number_window.number = number
  2997.       @input_number_window.x = self.x + 8
  2998.       @input_number_window.y = self.y + $game_temp.num_input_start * 32
  2999.     end
  3000.   end
  3001.   #--------------------------------------------------------------------------
  3002.   # * Set Window Position and Opacity Level
  3003.   #--------------------------------------------------------------------------
  3004.   def reset_window (change_opacity = true)
  3005.     # x-coordinate depends on justification
  3006.     if @message_event == -1
  3007.       if @justification == RIGHT
  3008.         self.x = 640 - self.width
  3009.       elsif @justification == LEFT
  3010.         self.x = 0
  3011.       else # center
  3012.         self.x = (640 - self.width) / 2
  3013.       end
  3014.     else
  3015.       if @message_event == 0 or $game_map.events[@message_event] == nil
  3016.         # center on player
  3017.         event_x = $game_player.screen_x
  3018.       else
  3019.         # center on the event specified
  3020.         event_x = $game_map.events[@message_event].screen_x
  3021.       end
  3022.       self.x = event_x - self.width / 2
  3023.       @comic.x = self.x + (self.width / 2) + 4
  3024.     end
  3025.    
  3026.     if $game_temp.in_battle
  3027.       self.y = 16
  3028.     else
  3029.       if @message_event == -1
  3030.         case @message_position
  3031.           when 0  # up
  3032.             self.y = 16
  3033.           when 1  # middle
  3034.             self.y = (480 - self.height) / 2
  3035.           when 2  # down
  3036.             self.y = 480 - self.height - 24
  3037.         end
  3038.       else
  3039.         if @message_event == 0 or $game_map.events[@message_event] == nil
  3040.           # above player
  3041.           self.y = $game_player.screen_y - self.height - 48
  3042.         else
  3043.           # above event specified
  3044.           self.y = $game_map.events[@message_event].screen_y - self.height - 48
  3045.         end
  3046.         @comic.y = self.y + self.height - 2
  3047.       end
  3048.     end
  3049.     if self.y < 0 + (@name == "" ? 0 : 16)
  3050.       self.y = 0 + (@name == "" ? 0 : 16)
  3051.     elsif self.y > 480 - self.height
  3052.       self.y = 480 - self.height
  3053.     end
  3054.     if self.x < 0
  3055.       self.x = 0
  3056.     elsif self.x > 680 - self.width - 48
  3057.       self.x = 640 - self.width
  3058.     end
  3059.    
  3060.     if change_opacity
  3061.       if $game_system.message_frame == 0
  3062.         self.opacity = 255
  3063.       else
  3064.         self.opacity = 0
  3065.       end
  3066.       self.back_opacity = $game_system.back_opacity
  3067.     end
  3068.    
  3069.     # face stuff
  3070.       if @face_graphic != ""  
  3071.         # the player has chosen to show a face graphic
  3072.         if @done and $game_system.resting_face != ""
  3073.           @face.bitmap = RPG::Cache.picture(@face_graphic + $game_system.resting_face)
  3074.           if @face_frame * $game_system.face_frame_width >= @face.bitmap.width
  3075.             @face_frame = 0
  3076.           end
  3077.         else
  3078.           @face.bitmap = RPG::Cache.picture(@face_graphic)
  3079.         end
  3080.        
  3081.         # picture y-coordinate
  3082.         if @face_graphic_position == ABOVE
  3083.           @face.y = self.y - @face.bitmap.height
  3084.           @face_offset = 0
  3085.         elsif @face_graphic_position == CENTER
  3086.           delta = (@face.bitmap.height - self.height) / 2
  3087.           @face.y = self.y - delta
  3088.           if $game_system.animated_faces
  3089.             @face_offset = $game_system.face_frame_width + 16
  3090.           else
  3091.             @face_offset = @face.bitmap.width + 16
  3092.           end
  3093.         elsif @face_graphic_position == BOTTOM
  3094.           @face.y = self.y + self.height - @face.bitmap.height
  3095.           if $game_system.animated_faces
  3096.             @face_offset = $game_system.face_frame_width + 16
  3097.           else
  3098.             @face_offset = @face.bitmap.width + 16
  3099.           end
  3100.         else # side
  3101.           delta = (@face.bitmap.height - self.height) / 2
  3102.           @face.y = self.y - delta
  3103.           @face_offset = 0
  3104.         end
  3105.        
  3106.         # picture x-coordinate
  3107.         if @face_graphic_justification == LEFT
  3108.           if @face_graphic_position == SIDE
  3109.             @face.x = self.x - @face.bitmap.width
  3110.           else
  3111.             @face.x = self.x + 10
  3112.           end
  3113.         else
  3114.           if $game_system.animated_faces
  3115.             offset = @face.bitmap.width - $game_system.face_frame_width
  3116.           else
  3117.             offset = 0
  3118.           end
  3119.           if @face_graphic_position == SIDE
  3120.             @face.x = self.x + self.width + offset
  3121.           else
  3122.             @face.x = self.x + self.width - @face.bitmap.width - 10 + offset
  3123.             @face_offset = 0
  3124.           end
  3125.         end
  3126.        
  3127.         if $game_system.animated_faces
  3128.           @face.src_rect = Rect.new(@face_frame * $game_system.face_frame_width, 0, $game_system.face_frame_width, @face.bitmap.height)
  3129.           if @done and $game_system.resting_face != ""
  3130.             pause = $game_system.resting_animation_pause
  3131.           else
  3132.             pause = $game_system.animation_pause
  3133.           end
  3134.           if Graphics.frame_count % pause == 0
  3135.             @animate_face = true
  3136.           end
  3137.           if @animate_face
  3138.             if Graphics.frame_count % 3 == 0
  3139.               @face_frame += 1
  3140.               if @face_frame * $game_system.face_frame_width >= @face.bitmap.width
  3141.                 @face_frame = 0
  3142.                 @animate_face = false
  3143.               end
  3144.             end
  3145.           end
  3146.         end
  3147.       end
  3148.      
  3149.       # name window
  3150.       if @name != "" and @name != nil
  3151.         @name_window.set_name(@name)
  3152.         @name_window.x = self.x
  3153.         @name_window.y = self.y - 36
  3154.       end
  3155.      
  3156.       # If choice
  3157.     if $game_temp.choice_max > 0
  3158.       @choice_window.set_choices($game_temp.choices)
  3159.       # determine x and y coords for choice window
  3160.       if $game_system.choice_justification == LEFT
  3161.         @choice_window.x = self.x
  3162.       else
  3163.         @choice_window.x = self.x + self.width - @choice_window.width
  3164.       end
  3165.       if $game_system.choice_position == ABOVE
  3166.         # check to make sure there is enough room above the textbox
  3167.         if self.y < @choice_window.height
  3168.           # not enough room above, place below
  3169.           @choice_window.y = self.y + self.height
  3170.         else
  3171.           # draw above
  3172.           @choice_window.y = self.y - @choice_window.height
  3173.         end
  3174.       elsif $game_system.choice_position == BOTTOM
  3175.         # check to make sure there is enough room below the textbox
  3176.         if (480 - self.y - self.height) < @choice_window.height
  3177.           # not enough room below, place above
  3178.           @choice_window.y = self.y - @choice_window.height
  3179.         else
  3180.           # draw below
  3181.           @choice_window.y = self.y + self.height
  3182.         end
  3183.       else # side
  3184.         if $game_system.choice_justification == LEFT
  3185.           # check to make sure there's room on the left side
  3186.           if self.y < @choice_window.width
  3187.             # not enough room on the side, check to make sure there's room below
  3188.             if (480 - self.y - self.height) < @choice_window.height
  3189.               # not enough room below, place above
  3190.               @choice_window.y = self.y - @choice_window.height
  3191.             else
  3192.               # draw below
  3193.               @choice_window.y = self.y + self.height
  3194.             end
  3195.           else
  3196.             # place on the left side
  3197.             @choice_window.y = self.y
  3198.             @choice_window.x = self.x - @choice_window.width
  3199.           end
  3200.         else # right
  3201.           # check to make sure there's room on the right side
  3202.           if (680 - (self.y + self.width)) < @choice_window.width
  3203.             # not enough room on the side, check to make sure there's room below
  3204.             if (480 - self.y - self.height) < @choice_window.height
  3205.               # not enough room below, place above
  3206.               @choice_window.y = self.y - @choice_window.height
  3207.             else
  3208.               # draw below
  3209.               @choice_window.y = self.y + self.height
  3210.             end
  3211.           else
  3212.             # place on the left side
  3213.             @choice_window.y = self.y
  3214.             @choice_window.x = self.x + self.width
  3215.           end
  3216.         end
  3217.       end
  3218.     end
  3219.   end
  3220.   #--------------------------------------------------------------------------
  3221.   # * Frame Update
  3222.   #--------------------------------------------------------------------------
  3223.   def update
  3224.     super
  3225.    
  3226.     if !@show
  3227.       return
  3228.     else
  3229.       self.visible = true
  3230.       if @face_graphic != ""
  3231.         @face.opacity = 255
  3232.       end
  3233.       if $game_system.comic_enabled and @message_event != -1
  3234.         @comic.opacity = 255
  3235.       end
  3236.       if @name != ""
  3237.         @name_window.visible = true
  3238.         if $game_system.name_window
  3239.           @name_window.dummy_window.visible = true
  3240.         end
  3241.       end
  3242.       if @input_number_window != nil
  3243.         @input_number_window.contents_opacity = 255
  3244.       end
  3245.       reset_window
  3246.     end
  3247.    
  3248.    
  3249.     if (@contents_showing and $game_system.message_event != -1 and @shake == 0) or $game_system.animated_faces
  3250.       reset_window(false)
  3251.     end
  3252.    
  3253.     if $game_system.shake != 0  # shake the window
  3254.       if @ascending
  3255.         if @target_x != self.x
  3256.           self.x += 1
  3257.         else
  3258.           @ascending = false
  3259.           @target_x = self.x - ($game_system.shake * 2)
  3260.         end
  3261.       else
  3262.         if @target_x != self.x
  3263.           self.x -= 1
  3264.         else
  3265.           @ascending = true
  3266.           @target_x = self.x + ($game_system.shake * 2)
  3267.         end
  3268.       end
  3269.     end
  3270.    
  3271.     if $game_system.text_shake != 0  # shake the text
  3272.       if @ascending
  3273.         if @target_x2 != @shake_sprite.x
  3274.           @shake_sprite.x += 1
  3275.         else
  3276.           @ascending = false
  3277.           @target_x2 = @shake_sprite.x - ($game_system.text_shake * 2)
  3278.         end
  3279.       else
  3280.         if @target_x2 != @shake_sprite.x
  3281.           @shake_sprite.x -= 1
  3282.         else
  3283.           @ascending = true
  3284.           @target_x2 = @shake_sprite.x + ($game_system.text_shake * 2)
  3285.         end
  3286.       end
  3287.     end
  3288.    
  3289.     if @wait > 0
  3290.       @wait -= 1
  3291.       if @wait == 0
  3292.         terminate_message
  3293.         return
  3294.       end
  3295.     end
  3296.    
  3297.     # If fade in
  3298.     if @fade_in
  3299.       self.contents_opacity += 24
  3300.       if @face_graphic != ""
  3301.         @face.opacity += 24
  3302.       end
  3303.       if $game_system.comic_enabled and @message_event != -1
  3304.         @comic.opacity += 24
  3305.       end
  3306.       if @name != ""
  3307.         @name_window.visible = true
  3308.       end
  3309.       if @input_number_window != nil
  3310.         @input_number_window.contents_opacity += 24
  3311.       end
  3312.       if self.contents_opacity == 255
  3313.         @fade_in = false
  3314.       end
  3315.       return
  3316.     end
  3317.    
  3318.     # write the text
  3319.     if @text != nil and @text != ""
  3320.       speed = $game_system.write_speed
  3321.       if $game_system.text_skip
  3322.         if $game_system.skip_mode == WRITE_FASTER and Input.press?(Input::C)
  3323.           # the player is holding the action button, write faster
  3324.           speed /= 3
  3325.         elsif $game_system.skip_mode == WRITE_ALL and @write_all
  3326.           # the player pressed the action button, write all the text
  3327.           while (c = @text.slice!(/./m)) != nil
  3328.             write_char(c)
  3329.           end
  3330.           return
  3331.         end
  3332.       end
  3333.       while @ignore
  3334.         c = @text.slice!(/./m)
  3335.         if c != nil
  3336.           write_char(c)
  3337.         end
  3338.       end
  3339.       if @pause_time > 0
  3340.         @pause_time -= 1
  3341.         return
  3342.       end
  3343.       if Graphics.frame_count - @count >= speed
  3344.         if $game_system.sound_effect != ""
  3345.           Audio.se_play("Audio/SE/" + $game_system.sound_effect, 60, 100)
  3346.         end
  3347.         @count = Graphics.frame_count
  3348.         c = @text.slice!(/./m)
  3349.         if c != nil
  3350.           write_char(c)
  3351.         end
  3352.       end
  3353.       return
  3354.     end
  3355.    
  3356.     @done = true
  3357.    
  3358.     # If inputting number
  3359.     if @input_number_window != nil
  3360.       @input_number_window.update
  3361.       # Confirm
  3362.       if Input.trigger?(Input::C)
  3363.         $game_system.se_play($data_system.decision_se)
  3364.         $game_variables[$game_temp.num_input_variable_id] =
  3365.           @input_number_window.number
  3366.         $game_map.need_refresh = true
  3367.         # Dispose of number input window
  3368.         @input_number_window.dispose
  3369.         @input_number_window = nil
  3370.         terminate_message
  3371.       end
  3372.       return
  3373.     end
  3374.    
  3375.     if @wait != 0
  3376.       return
  3377.     end
  3378.    
  3379.     # If message is being displayed and contents are all written
  3380.     if @contents_showing
  3381.       # if choice
  3382.       if $game_temp.choice_max > 0
  3383.         if !@choice_window.active
  3384.           @choice_window.visible = true
  3385.           @choice_window.active = true
  3386.           @choice_window.index = 0
  3387.         end
  3388.         @choice_window.update
  3389.       else
  3390.         # If choice isn't being displayed, show pause sign
  3391.         self.pause = true
  3392.       end
  3393.       return
  3394.     end
  3395.   end
  3396.  
  3397.   #--------------------------------------------------------------------------
  3398.   # * Process and write the given character
  3399.   #--------------------------------------------------------------------------
  3400.   def write_char(c)
  3401.     if c == "\000"
  3402.       # Return to original text
  3403.       c = "\\"
  3404.     end
  3405.     # If \C[n]
  3406.     if c == "\001"
  3407.     # Change text color
  3408.       @text.sub!(/\[([0-9]+)\]/, "")
  3409.       color = $1.to_i
  3410.       if color >= 0 and color <= 7
  3411.         self.contents.font.color = text_color(color)
  3412.       end
  3413.       # go to next text
  3414.       return
  3415.     end
  3416.     # If \G
  3417.     if c == "\002"
  3418.       # Make gold window
  3419.       if @gold_window == nil
  3420.         @gold_window = Window_Gold.new
  3421.         @gold_window.x = 560 - @gold_window.width
  3422.         if $game_temp.in_battle
  3423.           @gold_window.y = 192
  3424.         else
  3425.           @gold_window.y = self.y >= 128 ? 32 : 384
  3426.         end
  3427.         @gold_window.opacity = self.opacity
  3428.         @gold_window.back_opacity = self.back_opacity
  3429.       end
  3430.       # go to next text
  3431.       return
  3432.     end
  3433.     # If \skip
  3434.     if c == "\003"
  3435.       # toggle text skipping
  3436.       #$game_system.text_skip = !$game_system.text_skip
  3437.       # go to next text
  3438.       return
  3439.     end
  3440.     # If \b
  3441.     if c == "\004"
  3442.       # toggle bold
  3443.       self.contents.font.bold = !self.contents.font.bold
  3444.       # go to next text
  3445.       return
  3446.     end
  3447.     # If \i
  3448.     if c == "\005"
  3449.       # toggle italics
  3450.       self.contents.font.italic = !self.contents.font.italic
  3451.       # go to next text
  3452.       return
  3453.     end
  3454.     # If \s
  3455.     if c == "\006"
  3456.       # toggle shadow
  3457.       #$game_system.shadowed_text = !$game_system.shadowed_text
  3458.       # go to next text
  3459.       return
  3460.     end
  3461.     # If \font
  3462.     if c == "\007"
  3463.       # change font
  3464.       @text.sub!(/\[(.*?)\]/, "")
  3465.       font = $1.to_s
  3466.       @font = font
  3467.       if font == ""
  3468.         self.contents.font.name = Font.default_name
  3469.       else
  3470.         self.contents.font.name = font
  3471.       end
  3472.       # go to next text
  3473.       return
  3474.     end
  3475.     # If \p[n]
  3476.     if c == "\010"
  3477.       @text.sub!(/\[([0-9]+)\]/, "")
  3478.       @pause_time = $1.to_i
  3479.  
  3480.       # go to next text
  3481.       return
  3482.     end
  3483.    
  3484.     # If \w[n]
  3485.     if c == "\011"
  3486.       @text.sub!(/\[([0-9]+)\]/, "")
  3487.       @wait = $1.to_i
  3488.  
  3489.       # go to next text
  3490.       return
  3491.     end
  3492.    
  3493.     # If \ws[n]
  3494.     if c == "\013"
  3495.       @text.sub!(/\[([0-9]+)\]/, "")
  3496.       $game_system.write_speed = $1.to_i
  3497.  
  3498.       # go to next text
  3499.       return
  3500.     end
  3501.     # If \oa[n]
  3502.     if c == "\014"
  3503.       @text.sub!(/\[([0-9]+)\]/, "")
  3504.       index = $1.to_i
  3505.       @text.sub!("  ", "")
  3506.       item = $data_armors[index]
  3507.       # draw the icon
  3508.       icon = RPG::Cache.icon(item.icon_name)
  3509.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  3510.       @x += 24
  3511.  
  3512.       # go to next text
  3513.       return
  3514.     end
  3515.    
  3516.     # If \oi[n]
  3517.     if c == "\015"
  3518.       @text.sub!(/\[([0-9]+)\]/, "")
  3519.       index = $1.to_i
  3520.       @text.sub!("  ", "")
  3521.       item = $data_items[index]
  3522.       # draw the icon
  3523.       icon = RPG::Cache.icon(item.icon_name)
  3524.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  3525.       @x += 24
  3526.  
  3527.       # go to next text
  3528.       return
  3529.     end
  3530.    
  3531.     # If \os[n]
  3532.     if c == "\016"
  3533.       @text.sub!(/\[([0-9]+)\]/, "")
  3534.       index = $1.to_i
  3535.       @text.sub!("  ", "")
  3536.       item = $data_skills[index]
  3537.       # draw the icon
  3538.       icon = RPG::Cache.icon(item.icon_name)
  3539.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  3540.       @x += 24
  3541.  
  3542.       # go to next text
  3543.       return
  3544.     end
  3545.    
  3546.     # If \ow[n]
  3547.     if c == "\017"
  3548.       @text.sub!(/\[([0-9]+)\]/, "")
  3549.       index = $1.to_i
  3550.       @text.sub!("  ", "")
  3551.       item = $data_weapons[index]
  3552.       # draw the icon
  3553.       icon = RPG::Cache.icon(item.icon_name)
  3554.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  3555.       @x += 24
  3556.      
  3557.       # go to next text
  3558.       return
  3559.     end
  3560.     # If \ic[name]
  3561.     if c == "\027"
  3562.       @text.sub!(/\[(.*?)\]/, "")
  3563.       # draw the icon
  3564.       icon = RPG::Cache.icon($1.to_s)
  3565.       line = self.contents.text_size("dj").height
  3566.       self.contents.blt(@x + 4, (@y * line) + 4, icon, Rect.new(0, 0, 24, 24))
  3567.       @x += 24
  3568.  
  3569.       # go to next text
  3570.       return
  3571.     end
  3572.    
  3573.     # If \tc
  3574.     if c == "\020"
  3575.       # center justify
  3576.       @text_justification = CENTER
  3577.       get_x_value
  3578.       # go to next text
  3579.       return
  3580.     end
  3581.    
  3582.     # If \tl
  3583.     if c == "\021"
  3584.       # left justify
  3585.       @text_justification = LEFT
  3586.       get_x_value
  3587.       # go to next text
  3588.       return
  3589.     end
  3590.    
  3591.     # If \tr
  3592.     if c == "\022"
  3593.       # right justify
  3594.       @text_justification = RIGHT
  3595.       get_x_value
  3596.       # go to next text
  3597.       return
  3598.     end
  3599.    
  3600.     # If \ignr
  3601.     if c == "\023"
  3602.       # set ignore flage
  3603.       @ignore = true
  3604.       # go to next text
  3605.       return
  3606.     end
  3607.    
  3608.     # if \c (hex color)
  3609.     if c == "\026"
  3610.       # convert hex color to RGB
  3611.       @text.sub!(/\[([0123456789abcdef]+)\]/, "")
  3612.       hex_code = $1.to_s
  3613.      
  3614.       red   = ("0x" + hex_code.slice(0..1)).hex
  3615.       blue  = ("0x" + hex_code.slice(2..3)).hex
  3616.       green = ("0x" + hex_code.slice(4..5)).hex
  3617.      
  3618.       self.contents.font.color = Color.new(red, blue, green)
  3619.       return
  3620.     end
  3621.    
  3622.     # if \sk[i] (begin shake)
  3623.     if c == "\030"
  3624.       @shake_text = true
  3625.       return
  3626.     end
  3627.     # if \sk (end shake)
  3628.     if c == "\031"
  3629.       @shake_text = false
  3630.       return
  3631.     end
  3632.    
  3633.     # If new line text
  3634.     if c == "\n"
  3635.       # Add 1 to y
  3636.       if !@ignore
  3637.         @y += 1
  3638.       end
  3639.       if @text != ""
  3640.         get_x_value
  3641.       end
  3642.       @ignore = false
  3643.  
  3644.       # go to next text
  3645.       return
  3646.     end
  3647.     if @ignore
  3648.       return
  3649.     end
  3650.     # Draw text
  3651.     line = self.contents.text_size("dj").height
  3652.     if $game_system.shadowed_text
  3653.       old_color = self.contents.font.color.clone
  3654.       if @shake_text
  3655.         @shake_sprite.bitmap.font.color = $game_system.shadow_color    
  3656.         @shake_sprite.bitmap.draw_text(6 + @x, line * @y + 2, 40, 32, c)
  3657.         @shake_sprite.bitmap.font.color = old_color
  3658.       else
  3659.         self.contents.font.color = $game_system.shadow_color    
  3660.         self.contents.draw_text(6 + @x, line * @y + 2, 40, 32, c)
  3661.         self.contents.font.color = old_color
  3662.       end
  3663.     end
  3664.     if @shake_text
  3665.       @shake_sprite.bitmap.draw_text(4 + @x, line * @y, 40, 32, c)
  3666.     else
  3667.       self.contents.draw_text(4 + @x, line * @y, 40, 32, c)
  3668.     end
  3669.     # Add x to drawn text width
  3670.     @x += self.contents.text_size(c).width
  3671.   end
  3672.  
  3673.   def get_x_value
  3674.     # text justification - offset for first line
  3675.     if @text_justification == CENTER
  3676.       # get the length of the current line
  3677.       w = self.contents.text_size(@text.split("\n")[0]).width
  3678.       @x = (self.width - w - 48) / 2
  3679.     elsif @text_justification == RIGHT
  3680.       # get the length of the current line
  3681.       w = self.contents.text_size(@text.split("\n")[0]).width
  3682.       @x = self.width - w - 48
  3683.     else # left
  3684.       if @face_graphic == ""
  3685.         @x = 0
  3686.       else
  3687.         @x = @face_offset
  3688.       end
  3689.     end
  3690.   end
  3691. end
  3692.  
  3693. #==============================================================================
  3694. # ** Window_InputNumber
  3695. #------------------------------------------------------------------------------
  3696. #  This window is for inputting numbers, and is used within the
  3697. #  message window.
  3698. #==============================================================================
  3699.  
  3700. class Window_InputNumber < Window_Base
  3701.   #--------------------------------------------------------------------------
  3702.   # * Object Initialization
  3703.   #     digits_max : digit count
  3704.   #--------------------------------------------------------------------------
  3705.   def initialize(digits_max)
  3706.     @digits_max = digits_max
  3707.     @number = 0
  3708.     # Calculate cursor width from number width (0-9 equal width and postulate)
  3709.     dummy_bitmap = Bitmap.new(32, 32)
  3710.     @cursor_width = dummy_bitmap.text_size("0").width + 8
  3711.     dummy_bitmap.dispose
  3712.     super(0, 0, @cursor_width * @digits_max + 32, 64)
  3713.     self.contents = Bitmap.new(width - 32, height - 32)
  3714.     if $game_system.font == ""
  3715.       self.contents.font.name = Font.default_name
  3716.     else
  3717.       self.contents.font.name = $game_system.font
  3718.     end
  3719.     self.z += 9999
  3720.     self.opacity = $game_system.opacity
  3721.     self.back_opacity = $game_system.back_opacity
  3722.     @index = 0
  3723.     refresh
  3724.     update_cursor_rect
  3725.   end
  3726.  
  3727.   #--------------------------------------------------------------------------
  3728.   # * Refresh
  3729.   #--------------------------------------------------------------------------
  3730.   def refresh
  3731.     self.contents.clear
  3732.     if $game_system.font_color.nil?
  3733.       self.contents.font.color = normal_color
  3734.     else
  3735.       self.contents.font.color = $game_system.font_color
  3736.     end
  3737.     if $game_system.windowskin != ""  
  3738.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin)
  3739.     else
  3740.       self.windowskin = RPG::Cache.windowskin($data_system.windowskin_name)
  3741.     end
  3742.     s = sprintf("%0*d", @digits_max, @number)
  3743.     for i in 0...@digits_max
  3744.       # Draw text
  3745.       if $game_system.shadowed_text
  3746.         old_color = self.contents.font.color.clone
  3747.         self.contents.font.color = $game_system.shadow_color
  3748.         self.contents.draw_text(i * @cursor_width + 6, 2, 32, 32, s[i,1])
  3749.         self.contents.font.color = old_color
  3750.       end
  3751.       self.contents.draw_text(i * @cursor_width + 4, 0, 32, 32, s[i,1])
  3752.     end
  3753.   end
  3754. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top