设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 1763|回复: 2
打印 上一主题 下一主题

[已经过期] 阿月历险记 消息框、对话框脚本

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
42 小时
注册时间
2010-11-20
帖子
11
跳转到指定楼层
1
 楼主| 发表于 2013-2-1 13:25:58 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 adsp 于 2013-2-1 13:32 编辑

是否有办法修改一下供一般游戏使用?
共6个脚本:
UMS 0 - Documents
RUBY 代码复制
  1. # *****************************************************************************
  2. # *    Universal Message System
  3. # *      v1.5.0
  4. # *      by Ccoa
  5. # *****************************************************************************
  6. # Usage:
  7. =begin
  8.  
  9. IN MESSAGE CODES
  10.   \b          - toggle bold on and off
  11.   \bopc[i]    - change the back opacity for this message to i (should be 0-255)
  12.   \c[i]       - change the text color
  13.   \c[#IIIIII] - change the text color to the hex code (temporary)
  14.   \e[i]       - place the text box over event i (0 = player, -1 no event)
  15.   \face[name] - changes the face graphic to name.png (leave empty [] for no face)
  16.   \fl         - change face justification to left
  17.   \font[name] - change the font to name, leave empty [] to return to the default font
  18.   \fr         - change face justification to right
  19.   \g          - display the gold window
  20.   \height     - height of the message window, works only in normal mode
  21.   \i          - toggle italics on and off
  22.   \ignr       - Do not write anything on this line, only process codes, must be the first thing on a line
  23.   \jc         - justify the window to the center, ignored if using \e
  24.   \jl         - justify the window to the left, ignored if using \e
  25.   \jr         - justify the window to the right, ignored if using \e
  26.   \m          - toggle mode between normal and fit window to text
  27.   \n[i]       - display the name of actor i
  28.   \nm[name]   - display the name in the name window, leave empty [] to remove the name window
  29.   \oa[i]      - display the icon and name of armor i
  30.   \oi[i]      - display the icon and name of item i
  31.   \opc[i]     - change the opacity for this message to i (should be 0-255)
  32.   \os[i]      - display the icon and name of skill i
  33.   \ow[i]      - display the icon and name of weapon i
  34.   \p[i]       - pause for i frames before writing the next character
  35.   \pt         - toggle pause display on and off
  36.   \s          - toggle shadowed text
  37.   \shk[i]     - set window shake to i, higher i is bigger shake, 0 is no shake
  38.   \skip       - toggle text skip on and off
  39.   \t1         - switch to the talk1 comic thingy
  40.   \t2         - switch to the talk2 comic thingy
  41.   \tc         - center the text, must be the first thing on a line
  42.   \th         - switch to the thought comic thingy
  43.   \tl         - left justify the text, must be the first thing on a line
  44.   \tr         - right justify the text, must be the first thing on a line
  45.   \v[i]       - display variable i
  46.   \width      - width of the message window, works only in normal mode
  47.   \w[i]       - wait for i frames after receiving this code, then close the window
  48.   \ws[i]      - change the write speed to i
  49.   \slv[name]  - set this window to be slave window name, or show slave window name
  50.   \inc        - include this window in the last
  51.  
  52. OUT OF MESSAGE CODES (use in a Script event command)
  53. $game_system.ums_mode = NORMAL_MODE - switch to normal mode
  54. $game_system.ums_mode = FIT_WINDOW_TO_TEXT - switch to fit window mode
  55. $game_system.text_skip = true - turn text skip on
  56. $game_system.text_skip = false
  57. true                           - turn text skip off (true is necessary)
  58. $game_system.text_mode = WRITE_FASTER - change skip mode to write faster
  59. $game_system.text_mode = WRITE_ALL - change skip mode to write all
  60. $game_system.write_speed = i - change the delay between letters to i frames
  61. $game_system.window_height = i - change the window height to i
  62. $game_system.window_width = i - change the window width to i
  63. $game_system.window_justification = RIGHT - make the window right justified
  64. $game_system.window_justification = LEFT - make the window left justified
  65. $game_system.window_justification = CENTER - make the window center justified
  66. $game_system.face_graphic = "filename" - change the face graphic to filename.png
  67. $game_system.face_graphic = "" - change the face graphic to none
  68. $game_system.face_graphic_justification = LEFT - the face graphic is on the left side
  69. $game_system.face_graphic_justification = RIGHT - the face graphic is on the right side
  70. $game_system.face_graphic_position = TOP - face graphic appears on top of window
  71. $game_system.face_graphic_position = CENTER - face graphic appears centered in window
  72. $game_system.face_graphic_position = BOTTOM - face graphic appears on the bottom of window
  73. $game_system.shadow_text = true - turn text shadowing on
  74. $game_system.shadow_text = false
  75. true                            - turn text shadowing off (true is necessary)
  76. $game_system.shadow_color = Color.new(red, blue, green, alpha) - change shadow color
  77. $game_system.message_event = what event to put the message over (0 = player, -1 = no event)
  78. $game_system.comic_enabled = false
  79. true                               - turn off comic thingy
  80. $game_system.comic_enabled = true  - turn on comic thingy (only works with message_event not -1)
  81. $game_system.comic_style = TALK1   - use the talk1.png comic thingy
  82. $game_system.comic_style = TALK2   - use the talk2.png comic thingy
  83. $game_system.comic_style = THOUGHT - use the thought.png comic thingy
  84. $game_system.name = "name" - change the text of the name window to name
  85. $game_system.name = "" - remove the name window
  86. $game_system.font = "name" - change the font to name
  87. $game_system.font = "" - return the font to the default
  88. $game_system.text_justification = CENTER - center justify the text
  89. $game_system.text_justification = LEFT - left justify the text
  90. $game_system.text_justification = RIGHT - right justify the text
  91. $game_system.show_pause = true - show pause icon when waiting for user input
  92. $game_system.show_pause = false - don't show pause icon when waiting for user input
  93. $game_system.shake = 0 - turn window shake off
  94. $game_system.shake = i - set shake to i, higher i is bigger shake
  95. $game_system.sound_effect = "" - turn off the letter-by-letter SE
  96. $game_system.sound_effect = "sename" - play the SE sename with each letter written
  97. $game_system.animated_faces = false - do not use animated faces
  98. $game_system.animated_faces = true - use animated faces
  99. $game_system.animation_pause = i - Wait i frames between each animation
  100. $game_system.face_frame_width = i - Each frame on the faceset is i pixels
  101. $game_system.resting_face = "" - Do not use a resting face
  102. $game_system.resting_face = "name" - Use a different animated face named facenamename when done talking
  103. $game_system.resting_animation_pause = i - Wait i frames between resting animations
  104. $game_system.text_mode = ONE_LETTER_AT_A_TIME - write text one letter at a time
  105. $game_system.text_mode = ALL_AT_ONCE - write text all at once
  106. $game_system.font_color = Color.new(R, G, B, A) - permanently change the font color to the RGBA color given here
  107. $game_system.font_color = nil - return the font color permanently to normal_color (white, by default)
  108. $game_system.windowskin = "windowskinname" - change the message box windowskin to windowskin
  109. $game_system.windowskin = "" - change the message box windowskin back to the one in the database
  110. $game_system.name_window = true - show the name window
  111. $game_system.name_window = false - hide the name window (just show the text)
  112. $game_system.opacity = i - change the message window back opacity to i (0-255)
  113. $game_system.window_image = "imagename" - the name of the image to show behind the window
  114. $game_system.window_image = nil - stop showing an image behind the window
  115.  
  116. =end


UMS 1 - Game
RUBY 代码复制
  1. # *****************************************************************************
  2. #  CONSTANTS
  3. # *****************************************************************************
  4.  
  5. # modes
  6. NORMAL_MODE        = 0
  7. FIT_WINDOW_TO_TEXT = 1
  8.  
  9. #text modes
  10. ONE_LETTER_AT_A_TIME = 0
  11. ALL_AT_ONCE          = 1
  12.  
  13. # skip modes
  14. WRITE_FASTER = 0
  15. WRITE_ALL    = 1
  16.  
  17. # justifications
  18. RIGHT  = 0
  19. CENTER = 1
  20. LEFT   = 2
  21.  
  22. # positions for extra objects (face graphics, choice box, etc)
  23. ABOVE  = 0  # place the object above the top of the message box
  24. CENTER = 1  # center the object vertically inside the message box
  25. BOTTOM = 2  # place the bottom of the object on the bottom of the message box
  26. SIDE   = 3  # to the side of the message box (which side depends on justification)
  27.  
  28. # comic type
  29. TALK1   = 0
  30. TALK2   = 1
  31. THOUGHT = 2
  32.  
  33. # *****************************************************************************
  34. #  Changes to Game_System.  This allows any changes made to be saved when the
  35. #     game is saved.
  36. # *****************************************************************************
  37.  
  38. class Game_System
  39.   attr_accessor :ums_mode # what mode the UMS is in
  40.   attr_accessor :text_skip # whether or not text skip is activated
  41.   attr_accessor :skip_mode # write the text faster while C is pressed, or just skip to the end
  42.   attr_accessor :write_speed # frame delay between characters
  43.  
  44.   attr_accessor :text_mode # write one letter at a time, or all at once?
  45.  
  46.   attr_accessor :window_height # default height of message window
  47.   attr_accessor :window_width # default width of message window
  48.   attr_accessor :window_justification # default justification of window
  49.  
  50.   attr_accessor :face_graphic # current face graphic
  51.   attr_accessor :face_graphic_justification # justification of face graphic
  52.   attr_accessor :face_graphic_position # position of face graphic
  53.  
  54.   attr_accessor :shadowed_text # whether or not to draw a shadow behind the text
  55.   attr_accessor :shadow_color # the shadow color
  56.  
  57.   attr_accessor :choice_justification # where the choice window is located
  58.   attr_accessor :choice_position # prefered position of choice window
  59.  
  60.   attr_accessor :message_event # what event to center the text over (0 player, -1 to not)
  61.  
  62.   attr_accessor :comic_enabled # using "talk" icons?
  63.   attr_accessor :comic_style   # what type of comic image to use
  64.  
  65.   attr_accessor :name # the text for the name window
  66.   attr_accessor :name_window # should the name window be visible?
  67.  
  68.   attr_accessor :font # the name of the font
  69.   attr_accessor :font_color # the name of the (permanent) font color
  70.  
  71.   attr_accessor :text_justification # the justification of the window text
  72.  
  73.   attr_accessor :show_pause # whether or not to show the pause icon
  74.  
  75.   attr_accessor :shake # the amount of shake for the window
  76.  
  77.   attr_accessor :sound_effect # SE to play with each letter
  78.  
  79.   attr_accessor :slave_windows # hash of slave windows
  80.   attr_accessor :indy_windows  # hash of independent windows
  81.  
  82.   attr_accessor :animated_faces # are the faces animated?
  83.   attr_accessor :animation_pause # how long do I wait between animation loops?
  84.   attr_accessor :face_frame_width # how many pixels wide is each face frame
  85.   attr_accessor :resting_face  # postext for waiting face graphic
  86.   attr_accessor :resting_animation_pause # how long to wait for resting graphic
  87.  
  88.   attr_accessor :windowskin # what windowskin to use for messages
  89.   attr_accessor :back_opacity # back opacity of windowskin
  90.   attr_accessor :opacity # opacity of windowskin
  91.  
  92.   attr_accessor :window_image # image used behind window
  93.  
  94.   attr_reader :shortcuts  # user-defined shortcuts
  95.  
  96.   alias ums_initialize initialize
  97.   def initialize
  98.     ums_initialize
  99.     @ums_mode = FIT_WINDOW_TO_TEXT #NORMAL_MODE
  100.  
  101.     @skip_mode = WRITE_ALL
  102.     @text_skip = true
  103.     @write_speed = 1
  104.  
  105.     @text_mode = ONE_LETTER_AT_A_TIME
  106.  
  107.     @window_height = 128
  108.     @window_width = 480
  109.     @window_justification = CENTER
  110.  
  111.     @face_graphic = "mea"
  112.     @face_graphic_justification = LEFT
  113.     @face_graphic_position = CENTER
  114.  
  115.     @shadowed_text = true
  116.     @shadow_color = Color.new(0, 0, 0, 100)
  117.  
  118.     @choice_justification = RIGHT
  119.     @choice_position = SIDE
  120.  
  121.     @message_event = -1
  122.  
  123.     @comic_enabled = true
  124.     @comic_style = TALK1
  125.  
  126.     @name = ""
  127.     @name_window = true
  128.  
  129.     @font = "Verdana"
  130.     @font_color = nil
  131.  
  132.     @text_justification = LEFT
  133.  
  134.     @show_pause = true
  135.  
  136.     @shake = 0
  137.  
  138.     @sound_effect = ""
  139.  
  140.     @slave_windows = {}
  141.     @indy_windows  = {}
  142.  
  143.     @animated_faces = false
  144.     @animation_pause = 80
  145.     @face_frame_width = 100
  146.     @resting_face = ""
  147.     @resting_animation_pause = 80
  148.  
  149.     @windowskin = ""
  150.     [url=home.php?mod=space&uid=316553]@opacity[/url] = 255
  151.     @back_opacity = 160
  152.  
  153.     @window_image = nil
  154.  
  155.     @used_codes = ['\v', '\n', '\c', '\g', '\skip', '\m', '\height', '\width',
  156.                    '\jr', '\jc', '\jl', '\face', '\fl', '\fr', '\b', '\i', '\s',
  157.                    '\e', '\t1', '\t2', '\th', '\nm', '\font', '\p', '\w', '\ws',
  158.                    '\oa', '\oi', '\os', '\ow', '\tl', '\tr', '\tc', '\ignr',
  159.                    '\shk', '\slv', '\ind', '\inc']
  160.  
  161.     @shortcuts = {}
  162.  
  163.   end
  164.  
  165.   def add_shortcut(shortcut, code)
  166.     text = shortcut.downcase
  167.     if !@used_codes.include?(text)
  168.       @shortcuts[shortcut] = code
  169.     end
  170.   end
  171.  
  172.   def open_window(name)
  173.     if $game_system.indy_windows.has_key?(name)
  174.       $game_system.indy_windows[name].show = true
  175.     end
  176.   end
  177.  
  178.   def close_window(name)
  179.     if $game_system.indy_windows.has_key?(name)
  180.       $game_system.indy_windows[name].dispose
  181.       $game_system.indy_windows.delete(name)
  182.     end
  183.   end
  184. end
  185.  
  186. #==============================================================================
  187. # ** Game_Temp
  188. #------------------------------------------------------------------------------
  189. #  This class handles temporary data that is not included with save data.
  190. #  Refer to "$game_temp" for the instance of this class.
  191. #==============================================================================
  192. class Game_Temp
  193.   attr_accessor :choices
  194.   attr_accessor :num_choices
  195.   attr_accessor :skip_next_choices
  196.  
  197.   alias old_init initialize
  198.   def initialize
  199.     old_init
  200.     @skip_next_choices = 0
  201.     @num_choices = 1
  202.   end
  203. end
  204.  
  205. class Scene_Map
  206.   alias ums_update update
  207.   def update
  208.     $game_system.slave_windows.each_value { |window| window.update }
  209.     $game_system.indy_windows.each_value { |window| window.update }
  210.     ums_update
  211.   end
  212. end



UMS 2 - Interpreter
RUBY 代码复制
  1. class Interpreter
  2.   #--------------------------------------------------------------------------
  3.   # * Show Text
  4.   #--------------------------------------------------------------------------
  5.   def command_101
  6.     # If other text has been set to message_text
  7.     if $game_temp.message_text != nil
  8.       # End
  9.       return false
  10.     end
  11.  
  12.     # Set message end waiting flag and callback
  13.     @message_waiting = true
  14.     $game_temp.message_proc = Proc.new { @message_waiting = false }
  15.     # Set message text on first line
  16.     $game_temp.message_text = @list[@index].parameters[0] + "\n"
  17.     line_count = 1
  18.     # Loop
  19.     loop do
  20.       # If next event command text is on the second line or after
  21.       if @list[@index + 1].code == 401
  22.         # Add the second line or after to message_text
  23.         $game_temp.message_text += @list[@index + 1].parameters[0] + "\n"
  24.         line_count += 1
  25.       # If the next event command is show text
  26.       elsif @list[@index + 1].code == 101
  27.         # If the text contains the \inc code
  28.         if @list[@index + 1].parameters[0].index(/\\[Ii][Nn][Cc]/) != nil
  29.           $game_temp.message_text += @list[@index + 1].parameters[0] + "\n"
  30.           $game_temp.message_text.sub!(/\\[Ii][Nn][Cc]/) { "" }
  31.         else
  32.           return true
  33.         end
  34.       # If event command is not on the second line or after
  35.       else
  36.         # If next event command is show choices
  37.         if @list[@index + 1].code == 102
  38.           # Advance index
  39.           @index += 1
  40.  
  41.           # skip this one, it was already shown?
  42.           if $game_temp.skip_next_choices > 0
  43.             $game_temp.skip_next_choices -= 1
  44.           else
  45.             # Choices setup
  46.             $game_temp.choice_start = line_count
  47.             setup_choices(@list[@index].parameters)
  48.           end
  49.         # If next event command is input number
  50.         elsif @list[@index + 1].code == 103
  51.           # If number input window fits on screen
  52.           if line_count < 4
  53.             # Advance index
  54.             @index += 1
  55.             # Number input setup
  56.             $game_temp.num_input_start = line_count
  57.             $game_temp.num_input_variable_id = @list[@index].parameters[0]
  58.             $game_temp.num_input_digits_max = @list[@index].parameters[1]
  59.           end
  60.         end
  61.         # Continue
  62.         return true
  63.       end
  64.       # Advance index
  65.       @index += 1
  66.     end
  67.   end
  68.   #--------------------------------------------------------------------------
  69.   # * Show Choices
  70.   #--------------------------------------------------------------------------
  71.   def command_102
  72.     # If text has been set to message_text
  73.     if $game_temp.message_text != nil
  74.       # End
  75.       return false
  76.     end
  77.  
  78.     if $game_temp.skip_next_choices > 0
  79.       # skip this one, it is part of another
  80.       $game_temp.skip_next_choices -= 1
  81.       @offset += 4
  82.       @index += 1
  83.       return false
  84.     else
  85.       @offset = 0
  86.     end
  87.     # Set message end waiting flag and callback
  88.     @message_waiting = true
  89.     $game_temp.message_proc = Proc.new { @message_waiting = false }
  90.     # Choices setup
  91.     $game_temp.message_text = ""
  92.     $game_temp.choice_start = 0
  93.     setup_choices(@parameters)
  94.     # Continue
  95.     return true   
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # * Setup Choices
  99.   #--------------------------------------------------------------------------
  100.   def setup_choices(parameters)
  101.     params = parameters.clone
  102.     @offset = 0
  103.     i = @index
  104.     curr = 1
  105.     while curr < $game_temp.num_choices
  106.       i += 1
  107.       if @list[i].code == 102
  108.         params[0] += @list[i].parameters[0]
  109.         if @list[i].parameters[1] == 5
  110.           @cancel_flag = true
  111.         else
  112.           @cancel_flag = false
  113.         end
  114.         params[1] = @list[i].parameters[1] + (curr * 4)
  115.         curr += 1
  116.       end
  117.     end
  118.  
  119.     # Set choice item count to choice_max
  120.     $game_temp.choice_max = params[0].size
  121.     # Set choice to message_text
  122.     $game_temp.choices = params[0]
  123.     # Set cancel processing
  124.     $game_temp.choice_cancel_type = params[1]
  125.  
  126.     if $game_temp.num_choices != 1
  127.       $game_temp.skip_next_choices = $game_temp.num_choices - 1
  128.       $game_temp.num_choices = 1
  129.     end
  130.  
  131.     # Set callback
  132.     current_indent = @list[@index].indent
  133.     $game_temp.choice_proc = Proc.new { |n| @branch[current_indent] = n }
  134.   end
  135.  
  136.   #--------------------------------------------------------------------------
  137.   # * When [**]
  138.   #--------------------------------------------------------------------------
  139.   def command_402
  140.     # If fitting choices are selected
  141.     if @branch[@list[@index].indent] == @parameters[0]
  142.       # Delete branch data
  143.       @branch.delete(@list[@index].indent)
  144.       # Continue
  145.       return true
  146.     end
  147.     # If it doesn't meet the condition: command skip
  148.     return command_skip
  149.   end
  150.  
  151.   #--------------------------------------------------------------------------
  152.   # * When Cancel
  153.   #--------------------------------------------------------------------------
  154.   def command_403
  155.     # If choices are cancelled
  156.     if @cancel_flag
  157.       # Delete branch data
  158.       @branch.delete(@list[@index].indent)
  159.       # Continue
  160.       return true
  161.     end
  162.     # If it doen't meet the condition: command skip
  163.     return command_skip
  164.   end
  165.  
  166.   #--------------------------------------------------------------------------
  167.   # * Input Number
  168.   #--------------------------------------------------------------------------
  169.   def command_103
  170.     # If text has been set to message_text
  171.     if $game_temp.message_text != nil
  172.       # End
  173.       return false
  174.     end
  175.     # Set message end waiting flag and callback
  176.     @message_waiting = true
  177.     $game_temp.message_proc = Proc.new { @message_waiting = false }
  178.     # Number input setup
  179.     $game_temp.message_text = ""
  180.     $game_temp.num_input_start = 0
  181.     $game_temp.num_input_variable_id = @parameters[0]
  182.     $game_temp.num_input_digits_max = @parameters[1]
  183.     # Continue
  184.     return true
  185.   end
  186.  
  187.   #--------------------------------------------------------------------------
  188.   # * Script
  189.   #--------------------------------------------------------------------------
  190.   def command_355
  191.     # Set first line to script
  192.     script = @list[@index].parameters[0] + "\n"
  193.     # Loop
  194.     loop do
  195.       # If next event command is second line of script or after
  196.       if @list[@index + 1].code == 655
  197.         # Add second line or after to script
  198.         script += @list[@index + 1].parameters[0] + "\n"
  199.       # If event command is not second line or after
  200.       else
  201.         # Abort loop
  202.         break
  203.       end
  204.       # Advance index
  205.       @index += 1
  206.     end
  207.     # Evaluation
  208.     result = eval(script)
  209.  
  210.     # Continue
  211.     return true
  212.   end
  213. end


UMS 3 - Windows_Select
RUBY 代码复制
  1. # *****************************************************************************
  2. #  Changes to Window_Message.  This is the bulk of the script
  3. # *****************************************************************************
  4. #==============================================================================
  5. # ** Window_Message
  6. #------------------------------------------------------------------------------
  7. #  This message window is used to display text.
  8. #==============================================================================
  9.  
  10. class Window_Message < Window_Selectable
  11.   #--------------------------------------------------------------------------
  12.   # * Object Initialization
  13.   #--------------------------------------------------------------------------
  14.   def initialize
  15.     # x-coordinate depends on justification
  16.     if $game_system.window_justification == RIGHT
  17.       x = 640 - self.width
  18.     elsif $game_system.window_justification == LEFT
  19.       x = 0
  20.     else # center
  21.       x = (640 - $game_system.window_width) / 2
  22.     end
  23.     # y-coordinate depends on height
  24.     y = 480 - $game_system.window_height - 16
  25.     super(x, y, $game_system.window_width, $game_system.window_height)
  26.     self.contents = Bitmap.new(width - 32, height - 32)
  27.     self.visible = false
  28.     self.z = 9998
  29.     @fade_in = false
  30.     @fade_out = false
  31.     @contents_showing = false
  32.  
  33.     # face graphic sprite
  34.     [url=home.php?mod=space&uid=84331]@face[/url] = Sprite.new
  35.     @face.opacity = 0
  36.     @face.z = self.z + 1
  37.     @face_offset = 0
  38.  
  39.     # choice window
  40.     @choice_window = Window_Choice.new([])
  41.     @choice_window.back_opacity = $game_system.back_opacity
  42.  
  43.     # comic sprite
  44.     [url=home.php?mod=space&uid=97554]@comic[/url] = Sprite.new
  45.     @comic.opacity = 0
  46.     @comic.z = self.z + 1
  47.     if $game_system.comic_style == TALK1
  48.       @comic.bitmap = RPG::Cache.windowskin("talk1")
  49.     elsif $game_system.comic_style == TALK2
  50.       @comic.bitmap = RPG::Cache.windowskin("talk2")
  51.     else # thought
  52.       @comic.bitmap = RPG::Cache.windowskin("thought")
  53.     end
  54.  
  55.     # window image sprite
  56.     @window_back = Sprite.new
  57.     @window_back.opacity = 0
  58.     @window_back.z = self.z - 1
  59.     if $game_system.window_image != nil
  60.       @window_back.bitmap = RPG::Cache.windowskin($game_system.window_image)
  61.     end
  62.  
  63.     # name window
  64.     @name_window = Window_Name.new
  65.     @name_window.z = self.z + 1
  66.  
  67.     @pause_time = 0
  68.     [url=home.php?mod=space&uid=36110]@Wait[/url] = 0
  69.  
  70.     [url=home.php?mod=space&uid=32215]@show[/url] = false
  71.  
  72.     @face_frame = 0
  73.   end
  74.   #--------------------------------------------------------------------------
  75.   # * Dispose
  76.   #--------------------------------------------------------------------------
  77.   def dispose
  78.     terminate_message
  79.     $game_temp.message_window_showing = false
  80.     if @input_number_window != nil
  81.       @input_number_window.dispose
  82.     end
  83.     @face.dispose
  84.     @choice_window.dispose
  85.     @comic.dispose
  86.     @name_window.dispose
  87.     super
  88.   end
  89.   #--------------------------------------------------------------------------
  90.   # * Terminate Message
  91.   #--------------------------------------------------------------------------
  92.   def terminate_message
  93.     [url=home.php?mod=space&uid=32215]@show[/url] = false
  94.     self.active = false
  95.     self.pause = false
  96.     self.contents.clear
  97.     # Clear showing flag
  98.     @contents_showing = false
  99.     # Call message callback
  100.     if $game_temp.message_proc != nil
  101.       $game_temp.message_proc.call
  102.     end
  103.     # Clear variables related to text, choices, and number input
  104.     $game_temp.message_text = nil
  105.     $game_temp.message_proc = nil
  106.     $game_temp.choice_start = 99
  107.     $game_temp.choice_max = 0
  108.     $game_temp.choice_cancel_type = 0
  109.     $game_temp.choice_proc = nil
  110.     $game_temp.num_input_start = 99
  111.     $game_temp.num_input_variable_id = 0
  112.     $game_temp.num_input_digits_max = 0
  113.     # Open gold window
  114.     if @gold_window != nil
  115.       @gold_window.dispose
  116.       @gold_window = nil
  117.     end
  118.     @choice_window.visible = false
  119.     @choice_window.active = false
  120.     @comic.opacity = 0
  121.     $game_system.slave_windows.each_pair {|name, window|
  122.       if window.show == true
  123.         window.dispose
  124.         $game_system.slave_windows.delete(name)
  125.       end
  126.     }
  127.     @done = false
  128.   end
  129.   #--------------------------------------------------------------------------
  130.   # * Refresh
  131.   #--------------------------------------------------------------------------
  132.   def refresh
  133.     self.contents.clear
  134.     if $game_system.font_color.nil?
  135.       self.contents.font.color = normal_color
  136.     else
  137.       self.contents.font.color = $game_system.font_color
  138.     end
  139.     if $game_system.windowskin != ""  
  140.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin)
  141.     else
  142.       self.windowskin = RPG::Cache.windowskin($data_system.windowskin_name)
  143.     end
  144.     if $game_system.comic_style == TALK1
  145.       @comic.bitmap = RPG::Cache.windowskin("talk1")
  146.     elsif $game_system.comic_style == TALK2
  147.       @comic.bitmap = RPG::Cache.windowskin("talk2")
  148.     else # thought
  149.       @comic.bitmap = RPG::Cache.windowskin("thought")
  150.     end
  151.     [url=home.php?mod=space&uid=32215]@show[/url] = true
  152.     @x = @y = 0
  153.  
  154.     # If waiting for a message to be displayed
  155.     # Shaz - added $game_temp.message_text != "" to stop choice boxes
  156.     #        with no message being off-center
  157.     if $game_temp.message_text != nil and $game_temp.message_text != ""
  158.       @text = $game_temp.message_text
  159.  
  160.       # agf: problem. when pass code through here, it sometimes puts the number
  161.       # in the wrong place     
  162.  
  163.       # replace shortcuts with original code
  164.       $game_system.shortcuts.each {
  165.         |shortcut, code|        
  166.         @text.gsub!(shortcut, code)
  167.       }
  168.  
  169.       # VERY first thing.  Check to see if this is being set up as a slave
  170.       #  or independent window.
  171.       if @text.index(/\\[Ss][Ll][Vv]\[(.*?)\]/) != nil
  172.         # is this a new slave window, or a request to display it?
  173.         if !$game_system.slave_windows.has_key?($1.to_s)
  174.           # there is no such slave window yet.  Set it up.
  175.           @text.gsub!(/\\[Ss][Ll][Vv]\[(.*?)\]/, "")
  176.           $game_system.slave_windows[$1.to_s] = Window_Slave.new(@text)
  177.           @text = ""
  178.           @show = false
  179.           terminate_message
  180.           return
  181.         end
  182.       end
  183.  
  184.       if @text.index(/\\[Ii][Nn][Dd]\[(.*?)\]/) != nil
  185.         # is this a new independent window, or a request to display it?
  186.         if !$game_system.indy_windows.has_key?($1.to_s)
  187.           # there is no such slave window yet.  Set it up.
  188.           @text.gsub!(/\\[Ii][Nn][Dd]\[(.*?)\]/, "")
  189.           $game_system.indy_windows[$1.to_s] = Window_Slave.new(@text)
  190.           @text = ""
  191.           @show = false
  192.           terminate_message
  193.           return
  194.         end
  195.       end
  196.  
  197.       # Control text processing
  198.       begin
  199.         last_text = @text.clone
  200.         @text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  201.       end until @text == last_text
  202.       @text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  203.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  204.       end
  205.  
  206.       # window mode
  207.       if @text.index(/\\[Mm]/) != nil
  208.         if $game_system.ums_mode == NORMAL_MODE
  209.           $game_system.ums_mode = FIT_WINDOW_TO_TEXT
  210.         else
  211.           $game_system.ums_mode = NORMAL_MODE
  212.         end
  213.         @text.gsub!(/\\[Mm]/) { "" }
  214.       end
  215.  
  216.       # window height
  217.       @text.gsub!(/\\[Hh][Ee][Ii][Gg][Hh][Tt]\[([0-9]+)\]/) do
  218.         $game_system.window_height = $1.to_i
  219.         ""
  220.       end
  221.  
  222.       # window width
  223.       @text.gsub!(/\\[Ww][Ii][Dd][Tt][Hh]\[([0-9]+)\]/) do
  224.         $game_system.window_width = $1.to_i
  225.         ""
  226.       end
  227.  
  228.       # justification
  229.       @text.gsub!(/\\[Jj][Rr]/) do
  230.         $game_system.window_justification = RIGHT
  231.         reset_window
  232.         ""
  233.       end
  234.       @text.gsub!(/\\[Jj][Cc]/) do
  235.         $game_system.window_justification = CENTER
  236.         reset_window
  237.         ""
  238.       end      
  239.       @text.gsub!(/\\[Jj][Ll]/) do
  240.         $game_system.window_justification = LEFT
  241.         reset_window
  242.         ""
  243.       end
  244.  
  245.       # face graphics #agf
  246.       @text.gsub!(/\\[Ff][Aa][Cc][Ee]\[(.*?)\]/) do
  247.         $game_system.face_graphic = $1.to_s #agf
  248.         if $1.to_s == ""
  249.           @face.opacity = 0
  250.         end
  251.         ""
  252.       end
  253.       @text.gsub!(/\\[Ff][Ll]/) do
  254.         $game_system.face_graphic_justification = LEFT
  255.         ""
  256.       end
  257.       @text.gsub!(/\\[Ff][Rr]/) do
  258.         $game_system.face_graphic_justification = RIGHT
  259.         ""
  260.       end
  261.  
  262.       # event centering
  263.       @text.gsub!(/\\[Ee]\[([0-9]+)\]/) do
  264.         $game_system.message_event = $1.to_i
  265.         ""
  266.       end
  267.  
  268.       # comic thingy
  269.       @text.gsub!(/\\[Tt]1/) do
  270.         $game_system.comic_style = TALK1
  271.         @comic.bitmap = RPG::Cache.windowskin("talk1.png")
  272.         ""
  273.       end
  274.       @text.gsub!(/\\[Tt]2/) do
  275.         $game_system.comic_style = TALK2
  276.         @comic.bitmap = RPG::Cache.windowskin("talk2.png")
  277.         ""
  278.       end
  279.       @text.gsub!(/\\[Tt][Hh]/) do
  280.         $game_system.comic_style = THOUGHT
  281.         @comic.bitmap = RPG::Cache.windowskin("thought.png")
  282.         ""
  283.       end
  284.  
  285.       # name window
  286.       @text.gsub!(/\\[Nn][Mm]\[(.*?)\]/) do
  287.         $game_system.name = $1.to_s
  288.         if $1.to_s == ""
  289.           @name_window.visible = false
  290.           @name_window.dummy_window.visible = false
  291.         end
  292.         ""
  293.       end
  294.  
  295.       # toggle pause
  296.       @text.gsub!(/\\[Pp][Tt]/) do
  297.         $game_system.show_pause = !$game_system.show_pause
  298.         ""
  299.       end
  300.  
  301.       # shaking
  302.       @text.gsub!(/\\[Ss][Hh][Kk]\[([0-9]+)\]/) do
  303.         $game_system.shake = $1.to_i
  304.         ""
  305.       end
  306.  
  307.       # back opacity
  308.       @text.gsub!(/\\[Bb][Oo][Pp][Cc]\[([0-9]+)\]/) do
  309.         $game_system.back_opacity = $1.to_i
  310.         self.back_opacity = $game_system.back_opacity
  311.         ""
  312.       end
  313.  
  314.       # opacity
  315.       @text.gsub!(/\\[Oo][Pp][Cc]\[([0-9]+)\]/) do
  316.         $game_system.opacity = $1.to_i
  317.         self.opacity = $game_system.opacity
  318.         ""
  319.       end
  320.  
  321.       # Change "\\\\" to "\000" for convenience
  322.       @text.gsub!(/\\\\/) { "\000" }
  323.       # Change "\\C" to "\001" and "\\G" to "\002"
  324.       @text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  325.       @text.gsub!(/\\[Gg]/) { "\002" }
  326.       @text.gsub!(/\\[Cc]\[0x([0123456789abcdef]+)\]/) { "\026[#{$1}]" }
  327.  
  328.       # text skip code
  329.       @text.gsub!(/\\[Ss][Kk][Ii][Pp]/) { "\003" }
  330.  
  331.       # ignore code
  332.       @text.gsub!(/\\[Ii][Gg][Nn][Rr]/) { "\023" }
  333.  
  334.       # slave and indy windows
  335.       @text.gsub!(/\\[Ss][Ll][Vv]\[(.*?)\]/) { "\024[#{$1}]" }
  336.       @text.gsub!(/\\[Ii][Nn][Dd]\[(.*?)\]/) { "\025[#{$1}]" }
  337.  
  338.       # bold and italics
  339.       @text.gsub!(/\\[Bb]/) { "\004" }
  340.       @text.gsub!(/\\[Ii]/) { "\005" }
  341.  
  342.       # shadow
  343.       @text.gsub!(/\\[Ss]/) { "\006" }
  344.  
  345.       # font
  346.       @text.gsub!(/\\[Ff][Oo][Nn][Tt]\[(.*?)\]/) { "\007[#{$1}]" }
  347.  
  348.       # pause and wait
  349.       @text.gsub!(/\\[Pp]\[([0-9]+)\]/) { "\010[#{$1}]" }
  350.       @text.gsub!(/\\[Ww]\[([0-9]+)\]/) { "\011[#{$1}]" }
  351.  
  352.       # write speed
  353.       @text.gsub!(/\\[Ww][Ss]\[([0-9]+)\]/) { "\013[#{$1}]" }
  354.  
  355.       # armor, items, skills, and weapons
  356.       @text.gsub!(/\\[Oo][Aa]\[([0-9]+)\]/) {
  357.         item = $data_armors[$1.to_i]
  358.         "\014[#{$1}]" + "  " + item.name
  359.       }
  360.       @text.gsub!(/\\[Oo][Ii]\[([0-9]+)\]/) {
  361.         item = $data_items[$1.to_i]
  362.         "\015[#{$1}]" + "  " + item.name
  363.       }
  364.       @text.gsub!(/\\[Oo][Ss]\[([0-9]+)\]/) {
  365.         item = $data_skills[$1.to_i]
  366.         "\016[#{$1}]" + "  " + item.name
  367.       }
  368.       @text.gsub!(/\\[Oo][Ww]\[([0-9]+)\]/) {
  369.         item = $data_weapons[$1.to_i]
  370.         "\017[#{$1}]" + "  " + item.name
  371.       }
  372.  
  373.       # text justification
  374.       @text.gsub!(/\\[Tt][Cc]/) { "\020" }
  375.       @text.gsub!(/\\[Tt][Ll]/) { "\021" }
  376.       @text.gsub!(/\\[Tt][Rr]/) { "\022" }
  377.  
  378.       # Resize the window to fit the contents?
  379.       if $game_system.ums_mode == FIT_WINDOW_TO_TEXT
  380.         width = 1
  381.         text = @text.split("\n")
  382.         height = 0
  383.         i = 0
  384.         for line in text
  385.           # don't count this line's width if it has the ignr code
  386.           if !line.include?("\023")
  387.             width = [width, self.contents.text_size(line).width].max
  388.             delta = self.contents.text_size(line).height
  389.             height += delta + (delta * 0.2).to_i
  390.           end
  391.         end
  392.  
  393.         if $game_system.face_graphic != "" and ($game_system.face_graphic_position == CENTER or $game_system.face_graphic_position == BOTTOM)         
  394.             width += @face.bitmap.width + 10
  395.             if height < @face.bitmap.height
  396.               height = @face.bitmap.height - 22
  397.             end            
  398.         end
  399.  
  400.         if height == 0
  401.           height = 1
  402.         end
  403.  
  404.         self.width = width + 48
  405.         self.height = height + 48
  406.         self.contents = Bitmap.new(width + 16, height + 5)
  407.  
  408.         if $game_system.font_color.nil?
  409.           self.contents.font.color = normal_color
  410.         else
  411.           self.contents.font.color = $game_system.font_color
  412.         end
  413.       else
  414.         if self.width != $game_system.window_height or self.height != $game_system.window_width
  415.           self.width = $game_system.window_width
  416.           self.height = $game_system.window_height
  417.           self.contents = Bitmap.new(self.width - 32, self.height - 32)
  418.           if $game_system.font_color.nil?
  419.             self.contents.font.color = normal_color
  420.           else
  421.             self.contents.font.color = $game_system.font_color
  422.           end
  423.         end
  424.       end
  425.  
  426.       if $game_system.window_image != nil
  427.         # figure out how we're going to resize this         
  428.         @window_back.zoom_x = self.width.to_f / @window_back.bitmap.width
  429.         @window_back.zoom_y = self.height.to_f / @window_back.bitmap.height
  430.       end
  431.  
  432.       reset_window
  433.  
  434.  
  435.       # show correct sprite
  436.       party = ["123abc", "Mel", "June", "Edward", "Ulf", "Yvette", "Spook"]
  437.       if $game_system.message_event == 0 && party.include?($game_system.name)
  438.         $game_player.show_character(party.index($game_system.name))
  439.       end
  440.  
  441.  
  442.       get_x_value
  443.  
  444.       @count = Graphics.frame_count
  445.       @pause_time = 0
  446.       @ignore = false
  447.       @ascending = true
  448.       @target_x = self.x + $game_system.shake
  449.       @done = false
  450.       @face_frame = 0
  451.       @done = false
  452.  
  453.       self.oy = 0
  454.     end
  455.  
  456.  
  457.   end
  458.  
  459.   #--------------------------------------------------------------------------
  460.   # * Set Window Position and Opacity Level
  461.   #--------------------------------------------------------------------------
  462.   def reset_window (change_opacity = true)
  463.  
  464.     # x-coordinate depends on justification
  465.     if $game_system.message_event == -1
  466.       if $game_system.window_justification == RIGHT
  467.         self.x = 640 - $game_system.window_width
  468.       elsif $game_system.window_justification == LEFT
  469.         self.x = 0
  470.       else # center
  471.         self.x = (640 - self.width) / 2
  472.       end
  473.     else
  474.       if $game_system.message_event == 0 or $game_map.events[$game_system.message_event] == nil
  475.         # center on player
  476.         event_x = $game_player.screen_x
  477.       else
  478.         # center on the event specified
  479.         event_x = $game_map.events[$game_system.message_event].screen_x
  480.       end
  481.       self.x = event_x - self.width / 2
  482.       @comic.x = self.x + (self.width / 2) + 4
  483.     end
  484.  
  485.     if $game_temp.in_battle
  486.       self.y = 16
  487.     else
  488.       if $game_system.message_event == -1
  489.         case $game_system.message_position
  490.           when 0  # up
  491.             self.y = 16
  492.           when 1  # middle
  493.             self.y = (480 - $game_system.window_height) / 2
  494.           when 2  # down
  495.             self.y = 480 - $game_system.window_height - 24
  496.         end
  497.       else
  498.         if $game_system.message_event == 0 or $game_map.events[$game_system.message_event] == nil
  499.           # above player
  500.           self.y = $game_player.screen_y - self.height - 48
  501.         else
  502.           # above event specified
  503.           self.y = $game_map.events[$game_system.message_event].screen_y - self.height - 48
  504.         end
  505.         # Shaz - adjust for higher character sprites
  506.         self.y -= 8
  507.         @comic.y = self.y + self.height - 2
  508.         @comic.angle = 0
  509.       end
  510.     end
  511.     if self.y < 0 + ($game_system.name == "" ? 0 : 16)
  512.       if $game_system.comic_enabled
  513.         if $game_system.message_event == 0 or $game_map.events[$game_system.message_event] == nil
  514.           self.y = $game_player.screen_y - 16
  515.         else
  516.           self.y = $game_map.events[$game_system.message_event].screen_y - 16
  517.         end
  518.         @comic.angle = 180
  519.         @comic.y = self.y + 2
  520.         @comic.x = self.x + (self.width / 2) - 4
  521.       else
  522.         self.y = 16 # self.y = 0 + ($game_system.name == "" ? 0 : 16)
  523.       end
  524.     elsif self.y > 480 - self.height
  525.       self.y = 480 - self.height
  526.     end
  527.  
  528.     if self.x < 0
  529.       self.x = 0
  530.     elsif self.x > 680 - self.width - 48
  531.       self.x = 640 - self.width
  532.     end
  533.  
  534.     if change_opacity
  535.       if $game_system.message_frame == 0 and $game_temp.message_text != ""
  536.         self.opacity = $game_system.opacity
  537.       else
  538.         self.opacity = 0
  539.       end
  540.       self.back_opacity = $game_system.back_opacity
  541.     end
  542.  
  543.     # window back stuff
  544.     if $game_system.window_image != nil
  545.       @window_back.bitmap = RPG::Cache.windowskin($game_system.window_image)
  546.       @window_back.x = self.x
  547.       @window_back.y = self.y
  548.     end
  549.  
  550.       # face stuff
  551.       if $game_system.face_graphic != ""  
  552.         # the player has chosen to show a face graphic
  553.         if @done and $game_system.resting_face != ""
  554.           @face.bitmap = RPG::Cache.picture($game_system.face_graphic + $game_system.resting_face)
  555.           if @face_frame * $game_system.face_frame_width >= @face.bitmap.width
  556.             @face_frame = 0
  557.           end
  558.         else
  559.           @face.bitmap = RPG::Cache.picture($game_system.face_graphic)
  560.         end
  561.  
  562.         # picture y-coordinate
  563.         if $game_system.face_graphic_position == ABOVE
  564.           @face.y = self.y - @face.bitmap.height
  565.           @face_offset = 0
  566.         elsif $game_system.face_graphic_position == CENTER
  567.           delta = (@face.bitmap.height - self.height) / 2
  568.           @face.y = self.y - delta
  569.           if $game_system.animated_faces
  570.             @face_offset = $game_system.face_frame_width + 16
  571.           else
  572.             @face_offset = @face.bitmap.width + 16
  573.           end
  574.         elsif $game_system.face_graphic_position == BOTTOM
  575.           @face.y = self.y + self.height - @face.bitmap.height
  576.           if $game_system.animated_faces
  577.             @face_offset = $game_system.face_frame_width + 16
  578.           else
  579.             @face_offset = @face.bitmap.width + 16
  580.           end
  581.         else # side
  582.           delta = (@face.bitmap.height - self.height) / 2
  583.           @face.y = self.y - delta
  584.           @face_offset = 0
  585.         end
  586.  
  587.         # picture x-coordinate
  588.         if $game_system.face_graphic_justification == LEFT
  589.           if $game_system.face_graphic_position == SIDE
  590.             @face.x = self.x - @face.bitmap.width
  591.           else
  592.             @face.x = self.x + 10
  593.           end
  594.         else # right side
  595.           if $game_system.animated_faces
  596.             offset = @face.bitmap.width - $game_system.face_frame_width
  597.           else
  598.             offset = 0
  599.           end
  600.           if $game_system.face_graphic_position == SIDE
  601.             @face.x = self.x + self.width + offset
  602.           else
  603.             @face.x = self.x + self.width - @face.bitmap.width - 10 + offset
  604.             @face_offset = 0
  605.           end
  606.         end
  607.  
  608.         if $game_system.animated_faces
  609.           @face.src_rect = Rect.new(@face_frame * $game_system.face_frame_width, 0, $game_system.face_frame_width, @face.bitmap.height)
  610.           if @done and $game_system.resting_face != ""
  611.             pause = $game_system.resting_animation_pause
  612.           else
  613.             pause = $game_system.animation_pause
  614.           end
  615.           if Graphics.frame_count % pause == 0
  616.             @animate_face = true
  617.           end
  618.           if @animate_face
  619.             if Graphics.frame_count % 3 == 0
  620.               @face_frame += 1
  621.               if @face_frame * $game_system.face_frame_width >= @face.bitmap.width
  622.                 @face_frame = 0
  623.                 @animate_face = false
  624.               end
  625.             end
  626.           end
  627.         end
  628.       end
  629.  
  630.       # name window
  631.       if $game_system.name != ""
  632.         @name_window.x = self.x
  633.         @name_window.y = self.y - 36
  634.         @name_window.set_name($game_system.name)
  635.       end
  636.  
  637.       # show correct sprite
  638.       #party = ["123abc", "Mel", "June", "Edward", "Ulf", "Yvette", "Spook"]
  639.       #if $game_system.message_event == 0 && party.include?($game_system.name)
  640.       #  $game_player.show_character(party.index($game_system.name))
  641.       #end
  642.  
  643.       # If choice
  644.       if $game_temp.choice_max > 0
  645.         @choice_window.set_choices($game_temp.choices)
  646.         @choice_window.x = self.x + self.width - @choice_window.width
  647.         if self.y > @choice_window.height
  648.           # draw above
  649.           @choice_window.y = self.y - @choice_window.height
  650.         else
  651.           # draw below
  652.           @choice_window.y = self.y + self.height
  653.         end
  654.       end
  655.  
  656.     # If number input
  657.     if $game_temp.num_input_variable_id > 0
  658.       if @input_number_window == nil
  659.         digits_max = $game_temp.num_input_digits_max
  660.         number = $game_variables[$game_temp.num_input_variable_id]
  661.         @input_number_window = Window_InputNumber.new(digits_max)
  662.         @input_number_window.number = number
  663.       end
  664.       # determine x and y coords for number input window
  665.       if $game_system.choice_justification == LEFT
  666.         @input_number_window.x = self.x
  667.       else
  668.         @input_number_window.x = self.x + self.width - @input_number_window.width
  669.       end
  670.       if $game_system.choice_position == ABOVE
  671.         # check to make sure there is enough room above the textbox
  672.         if self.y < @input_number_window.height
  673.           # not enough room above, place below
  674.           @input_number_window.y = self.y + self.height
  675.         else
  676.           # draw above
  677.           @input_number_window.y = self.y - @choice_window.height
  678.         end
  679.       elsif $game_system.choice_position == BOTTOM
  680.         # check to make sure there is enough room below the textbox
  681.         if (480 - self.y - self.height) < @input_number_window.height
  682.           # not enough room below, place above
  683.           @input_number_window.y = self.y - @input_number_window.height
  684.         else
  685.           # draw below
  686.           @input_number_window.y = self.y + self.height
  687.         end
  688.       else # side
  689.         if $game_system.choice_justification == LEFT
  690.           # check to make sure there's room on the left side
  691.           if self.y < @input_number_window.width
  692.             # not enough room on the side, check to make sure there's room below
  693.             if (480 - self.y - self.height) < @input_number_window.height
  694.               # not enough room below, place above
  695.               @input_number_window.y = self.y - @input_number_window.height
  696.             else
  697.               # draw below
  698.               @input_number_window.y = self.y + self.height
  699.             end
  700.           else
  701.             # place on the left side
  702.             @input_number_window.y = self.y
  703.             @input_number_window.x = self.x - @choice_window.width
  704.           end
  705.         else # right
  706.           # check to make sure there's room on the right side
  707.           if (680 - (self.y + self.width)) < @input_number_window.width
  708.             # not enough room on the side, check to make sure there's room below
  709.             if (480 - self.y - self.height) < @input_number_window.height
  710.               # not enough room below, place above
  711.               @input_number_window.y = self.y - @input_number_window.height
  712.             else
  713.               # draw below
  714.               @input_number_window.y = self.y + self.height
  715.             end
  716.           else
  717.             # place on the left side
  718.             @input_number_window.y = self.y
  719.             @input_number_window.x = self.x + self.width
  720.           end
  721.         end
  722.       end
  723.     end
  724.   end
  725.   #--------------------------------------------------------------------------
  726.   # * Frame Update
  727.   #--------------------------------------------------------------------------
  728.   def update
  729.     super
  730.  
  731.     if (@contents_showing and $game_system.message_event != -1 and $game_system.shake == 0) or $game_system.animated_faces
  732.       reset_window(false)
  733.     end
  734.  
  735.     if $game_system.shake != 0  # shake the window
  736.       if @ascending
  737.         if @target_x != self.x
  738.           self.x += 1
  739.         else
  740.           @ascending = false
  741.           @target_x = self.x - ($game_system.shake * 2)
  742.         end
  743.       else
  744.         if @target_x != self.x
  745.           self.x -= 1
  746.         else
  747.           @ascending = true
  748.           @target_x = self.x + ($game_system.shake * 2)
  749.         end
  750.       end
  751.     end
  752.  
  753.     @name_window.update
  754.  
  755.     if @wait > 0
  756.       @wait -= 1
  757.       if @wait == 0
  758.         terminate_message
  759.         return
  760.       end
  761.     end
  762.  
  763.     # If fade in
  764.     if @fade_in
  765.       if $game_temp.message_text == ""
  766.         @fade_in = false
  767.         return
  768.       end
  769.       self.contents_opacity += 24
  770.       if $game_system.face_graphic != ""
  771.         @face.opacity += 24
  772.       end
  773.       if $game_system.window_image != nil
  774.         @window_back.opacity += 24
  775.       end
  776.       if $game_system.comic_enabled and $game_system.message_event != -1
  777.         @comic.opacity = self.opacity
  778.         @comic.visible = self.visible
  779.       end
  780.  
  781.       if $game_system.name != ""
  782.         @name_window.visible = true
  783.         if $game_system.name_window
  784.           @name_window.dummy_window.visible = true
  785.         end
  786.       end
  787.       if @input_number_window != nil
  788.         @input_number_window.contents_opacity += 24
  789.       end
  790.       if self.contents_opacity == 255
  791.         @fade_in = false
  792.       end
  793.       return
  794.     end
  795.  
  796.     # write the text
  797.     if @text != nil and @text != ""
  798.       speed = $game_system.write_speed
  799.       if $game_system.text_mode == ALL_AT_ONCE or $game_temp.in_battle
  800.         while (c = @text.slice!(/./m)) != nil
  801.           write_char(c)
  802.         end
  803.         $game_system.slave_windows.each_value { |window| window.write_all }
  804.         return
  805.       end
  806.       if $game_system.text_skip
  807.         if $game_system.skip_mode == WRITE_FASTER and Input.press?(Input::C)
  808.           # the player is holding the action button, write faster
  809.           speed /= 3
  810.         elsif $game_system.skip_mode == WRITE_ALL and Input.trigger?(Input::C)
  811.           # the player pressed the action button, write all the text
  812.           while (c = @text.slice!(/./m)) != nil
  813.             write_char(c)
  814.           end
  815.           $game_system.slave_windows.each_value { |window| window.write_all }
  816.           return
  817.         end
  818.       end
  819.       while @ignore
  820.         c = @text.slice!(/./m)
  821.         if c != nil
  822.           write_char(c)
  823.         end
  824.       end
  825.       if @pause_time > 0
  826.         @pause_time -= 1
  827.         return
  828.       end
  829.       if Graphics.frame_count - @count >= speed
  830.         if $game_system.sound_effect != ""
  831.           Audio.se_play("Audio/SE/" + $game_system.sound_effect, 10, 100)
  832.         end
  833.         @count = Graphics.frame_count
  834.         c = @text.slice!(/./m)
  835.         if c != nil
  836.           write_char(c)
  837.         end
  838.       end
  839.       return
  840.     end
  841.  
  842.     if $game_system.animated_faces and $game_system.resting_face != ""
  843.       @done = true
  844.     end
  845.  
  846.     # If inputting number
  847.     if @input_number_window != nil
  848.       @input_number_window.update
  849.       # Confirm
  850.       if Input.trigger?(Input::C)
  851.         $game_system.se_play($data_system.decision_se)
  852.         $game_variables[$game_temp.num_input_variable_id] =
  853.           @input_number_window.number
  854.         $game_map.need_refresh = true
  855.         # Dispose of number input window
  856.         @input_number_window.dispose
  857.         @input_number_window = nil
  858.         terminate_message
  859.       end
  860.       return
  861.     end
  862.  
  863.     if @wait != 0
  864.       return
  865.     end
  866.  
  867.     # If message is being displayed and contents are all written
  868.     if @contents_showing
  869.       # if choice
  870.       if $game_temp.choice_max > 0
  871.         if !@choice_window.active
  872.           @choice_window.visible = true
  873.           @choice_window.active = true
  874.           @choice_window.index = 0
  875.         end
  876.         @choice_window.update
  877.       else
  878.         # If choice isn't being displayed, show pause sign
  879.         self.pause = $game_system.show_pause
  880.       end
  881.         # Cancel
  882.         if Input.trigger?(Input::B)
  883.           if $game_temp.choice_max > 0 and $game_temp.choice_cancel_type > 0
  884.             $game_system.se_play($data_system.cancel_se)
  885.             $game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
  886.             terminate_message
  887.           end
  888.         end
  889.         # Confirm
  890.         if Input.trigger?(Input::C) and !(@wait > 0)
  891.           @done = true
  892.           $game_system.slave_windows.each_value { |window|
  893.             window.write_all
  894.             if !window.done
  895.               @done = false
  896.             end
  897.           }
  898.           if @done
  899.             if $game_temp.choice_max > 0
  900.               $game_system.se_play($data_system.decision_se)
  901.               $game_temp.choice_proc.call(@choice_window.index)
  902.             end
  903.             terminate_message
  904.           else
  905.             @finishing_up = true
  906.           end
  907.         end
  908.         return
  909.       end
  910.  
  911.     if @finishing_up
  912.       $game_system.slave_windows.each_value { |window|
  913.         if !window.done
  914.           @done = true
  915.           break
  916.         end
  917.       }
  918.  
  919.       if @done = false
  920.         terminate_message
  921.       end
  922.     end
  923.     # If display wait message or choice exists when not fading out
  924.     if @fade_out == false and $game_temp.message_text != nil
  925.       @contents_showing = true
  926.       $game_temp.message_window_showing = true
  927.  
  928.       reset_window
  929.       refresh
  930.       Graphics.frame_reset
  931.       if @show
  932.         self.visible = true
  933.       end
  934.       self.contents_opacity = 0
  935.       if @input_number_window != nil
  936.         @input_number_window.contents_opacity = 0
  937.       end
  938.       @fade_in = true
  939.       return
  940.     end
  941.     # If message which should be displayed is not shown, but window is visible
  942.     if self.visible
  943.       @fade_out = true
  944.       self.opacity -= 48
  945.       @name_window.opacity -= 48
  946.       @comic.opacity -= 48
  947.       @face.opacity -= 48
  948.       @window_back.opacity -= 48
  949.       if self.opacity == 0
  950.         self.visible = false
  951.         @face.opacity = 0
  952.         @window_back.opacity = 0
  953.         @choice_window.visible = false
  954.         @choice_window.active = false
  955.         @comic.opacity = 0
  956.         @name_window.visible = false
  957.         @name_window.dummy_window.visible = false
  958.         @name_window.update
  959.         @fade_out = false
  960.         $game_temp.message_window_showing = false
  961.       end
  962.       return
  963.     end
  964.  
  965.     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
  966.  
  967.         $game_system.indy_windows.each_pair {|name, window|
  968.           if window.show == true
  969.             window.dispose
  970.             $game_system.indy_windows.delete(name)
  971.           end
  972.         }
  973.     end
  974.   end
  975.  
  976.   #--------------------------------------------------------------------------
  977.   # * Process and write the given character
  978.   #--------------------------------------------------------------------------
  979.   def write_char(c)
  980.     if c == "\000"
  981.       # Return to original text
  982.       c = "\\"
  983.     end
  984.     # If \C[n]
  985.     if c == "\001"
  986.     # Change text color
  987.       @text.sub!(/\[([0-9]+)\]/, "")
  988.       color = $1.to_i
  989.       if color >= 0 and color <= 7
  990.         self.contents.font.color = text_color(color)
  991.       end
  992.       # go to next text
  993.       return
  994.     end
  995.     # If \G
  996.     if c == "\002"
  997.       # Make gold window
  998.       if @gold_window == nil
  999.         @gold_window = Window_Gold.new
  1000.         @gold_window.x = 560 - @gold_window.width
  1001.         if $game_temp.in_battle
  1002.           @gold_window.y = 192
  1003.         else
  1004.           @gold_window.y = self.y >= 128 ? 32 : 384
  1005.         end
  1006.         @gold_window.opacity = self.opacity
  1007.         @gold_window.back_opacity = self.back_opacity
  1008.       end
  1009.       # go to next text
  1010.       return
  1011.     end
  1012.     # If \skip
  1013.     if c == "\003"
  1014.       # toggle text skipping
  1015.       $game_system.text_skip = !$game_system.text_skip
  1016.       # go to next text
  1017.       return
  1018.     end
  1019.     # If \b
  1020.     if c == "\004"
  1021.       # toggle bold
  1022.       self.contents.font.bold = !self.contents.font.bold
  1023.       # go to next text
  1024.       return
  1025.     end
  1026.     # If \i
  1027.     if c == "\005"
  1028.       # toggle italics
  1029.       self.contents.font.italic = !self.contents.font.italic
  1030.       # go to next text
  1031.       return
  1032.     end
  1033.     # If \s
  1034.     if c == "\006"
  1035.       # toggle shadow
  1036.       $game_system.shadowed_text = !$game_system.shadowed_text
  1037.       # go to next text
  1038.       return
  1039.     end
  1040.     # If \font
  1041.     if c == "\007"
  1042.       # change font
  1043.       @text.sub!(/\[(.*?)\]/, "")
  1044.       font = $1.to_s
  1045.       $game_system.font = font
  1046.       if font == ""
  1047.         self.contents.font.name = Font.default_name
  1048.       else
  1049.         self.contents.font.name = font
  1050.       end
  1051.       # go to next text
  1052.       return
  1053.     end
  1054.     # If \p[n]
  1055.     if c == "\010"
  1056.       @text.sub!(/\[([0-9]+)\]/, "")
  1057.       @pause_time = $1.to_i
  1058.  
  1059.       # go to next text
  1060.       return
  1061.     end
  1062.  
  1063.     # If \w[n]
  1064.     if c == "\011"
  1065.       @text.sub!(/\[([0-9]+)\]/, "")
  1066.       @wait = $1.to_i
  1067.  
  1068.       # go to next text
  1069.       return
  1070.     end
  1071.  
  1072.     # If \ws[n]
  1073.     if c == "\013"
  1074.       @text.sub!(/\[([0-9]+)\]/, "")
  1075.       $game_system.write_speed = $1.to_i
  1076.  
  1077.       # go to next text
  1078.       return
  1079.     end
  1080.     # If \oa[n]
  1081.     if c == "\014"
  1082.       @text.sub!(/\[([0-9]+)\]/, "")
  1083.       index = $1.to_i
  1084.       @text.sub!("  ", "")
  1085.       item = $data_armors[index]
  1086.       # draw the icon
  1087.       icon = RPG::Cache.icon(item.icon_name)
  1088.       line = self.contents.text_size("dj").height
  1089.       self.contents.blt(@x + 4, (@y * line) + 4, icon, Rect.new(0, 0, 24, 24))
  1090.       @x += 24
  1091.  
  1092.       # go to next text
  1093.       return
  1094.     end
  1095.  
  1096.     # If \oi[n]
  1097.     if c == "\015"
  1098.       @text.sub!(/\[([0-9]+)\]/, "")
  1099.       index = $1.to_i
  1100.       @text.sub!("  ", "")
  1101.       item = $data_items[index]
  1102.       # draw the icon
  1103.       icon = RPG::Cache.icon(item.icon_name)
  1104.       line = self.contents.text_size("dj").height
  1105.       self.contents.blt(@x + 4, (@y * line) + 4, icon, Rect.new(0, 0, 24, 24))
  1106.       @x += 24
  1107.  
  1108.       # go to next text
  1109.       return
  1110.     end
  1111.  
  1112.     # If \os[n]
  1113.     if c == "\016"
  1114.       @text.sub!(/\[([0-9]+)\]/, "")
  1115.       index = $1.to_i
  1116.       @text.sub!("  ", "")
  1117.       item = $data_skills[index]
  1118.       # draw the icon
  1119.       icon = RPG::Cache.icon(item.icon_name)
  1120.       line = self.contents.text_size("dj").height
  1121.       self.contents.blt(@x + 2, (@y * line) + 4, icon, Rect.new(0, 0, 24, 24))
  1122.       @x += 24
  1123.  
  1124.       # go to next text
  1125.       return
  1126.     end
  1127.  
  1128.     # If \ow[n]
  1129.     if c == "\017"
  1130.       @text.sub!(/\[([0-9]+)\]/, "")
  1131.       index = $1.to_i
  1132.       @text.sub!("  ", "")
  1133.       item = $data_weapons[index]
  1134.       # draw the icon
  1135.       icon = RPG::Cache.icon(item.icon_name)
  1136.       line = self.contents.text_size("dj").height
  1137.       self.contents.blt(@x + 2, (@y * line) + 4, icon, Rect.new(0, 0, 24, 24))
  1138.       @x += 24
  1139.  
  1140.       # go to next text
  1141.       return
  1142.     end
  1143.  
  1144.     # If \tc
  1145.     if c == "\020"
  1146.       # center justify
  1147.       $game_system.text_justification = CENTER
  1148.       get_x_value
  1149.       # go to next text
  1150.       return
  1151.     end
  1152.  
  1153.     # If \tl
  1154.     if c == "\021"
  1155.       # left justify
  1156.       $game_system.text_justification = LEFT
  1157.       get_x_value
  1158.       # go to next text
  1159.       return
  1160.     end
  1161.  
  1162.     # If \tr
  1163.     if c == "\022"
  1164.       # right justify
  1165.       $game_system.text_justification = RIGHT
  1166.       get_x_value
  1167.       # go to next text
  1168.       return
  1169.     end
  1170.  
  1171.     # If \ignr
  1172.     if c == "\023"
  1173.       # set ignore flage
  1174.       @ignore = true
  1175.       # go to next text
  1176.       return
  1177.     end
  1178.  
  1179.     # if \slv
  1180.     if c == "\024"
  1181.       # we need to show a slave window
  1182.       @text.sub!(/\[(.*?)\]/, "")
  1183.       name = $1.to_s
  1184.       $game_system.slave_windows[name].show = true
  1185.       return
  1186.     end
  1187.  
  1188.     # if \ind
  1189.     if c == "\025"
  1190.       # we need to show a independent window
  1191.       @text.sub!(/\[(.*?)\]/, "")
  1192.       name = $1.to_s
  1193.       if $game_system.indy_windows[name].show
  1194.         $game_system.indy_windows[name].dispose
  1195.         $game_system.indy_windows.delete(name)
  1196.       else
  1197.         $game_system.indy_windows[name].show = true
  1198.       end
  1199.       return
  1200.     end
  1201.  
  1202.     # if \c (hex color)
  1203.     if c == "\026"
  1204.       # convert hex color to RGB
  1205.       @text.sub!(/\[([0123456789abcdef]+)\]/, "")
  1206.       hex_code = $1.to_s
  1207.  
  1208.       red   = ("0x" + hex_code.slice(0..1)).hex
  1209.       blue  = ("0x" + hex_code.slice(2..3)).hex
  1210.       green = ("0x" + hex_code.slice(4..5)).hex
  1211.  
  1212.       self.contents.font.color = Color.new(red, blue, green)
  1213.       return
  1214.     end
  1215.  
  1216.     # If new line text
  1217.     if c == "\n"
  1218.       # Add 1 to y
  1219.       if !@ignore
  1220.         @y += 1
  1221.       end
  1222.       if @text != ""
  1223.         get_x_value
  1224.       end
  1225.       @ignore = false
  1226.  
  1227.       # go to next text
  1228.       return
  1229.     end
  1230.     if @ignore
  1231.       return
  1232.     end
  1233.     # Draw text
  1234.     line = self.contents.text_size("dj").height
  1235.     if $game_system.shadowed_text
  1236.       old_color = self.contents.font.color.clone
  1237.       self.contents.font.color = $game_system.shadow_color     
  1238.       self.contents.draw_text(6 + @x, line * @y + 2, 40, 32, c) # Shaz: 26 was 32
  1239.       self.contents.font.color = old_color
  1240.     end
  1241.     self.contents.draw_text(4 + @x, line * @y, 40, 32, c) # Shaz: 26 was 32
  1242.     # Add x to drawn text width
  1243.     @x += self.contents.text_size(c).width
  1244.   end
  1245.  
  1246.   def get_x_value
  1247.     # text justification - offset for first line
  1248.     if $game_system.text_justification == CENTER
  1249.       # get the length of the current line
  1250.       w = self.contents.text_size(@text.split("\n")[0]).width
  1251.       @x = (self.width - w - 48) / 2
  1252.     elsif $game_system.text_justification == RIGHT
  1253.       # get the length of the current line
  1254.       w = self.contents.text_size(@text.split("\n")[0]).width
  1255.       @x = self.width - w - 48
  1256.     else # left
  1257.       if $game_system.face_graphic == ""
  1258.         @x = 0
  1259.       else
  1260.         @x = @face_offset
  1261.       end
  1262.     end
  1263.   end
  1264.  
  1265. end

UMS 4 - Win_Choice & Name
RUBY 代码复制
  1. #==============================================================================
  2. # ** Window_Choice
  3. #------------------------------------------------------------------------------
  4. #  This message window is used to display choices.
  5. #==============================================================================
  6. class Window_Choice < Window_Selectable
  7.   def initialize (choices)
  8.     super(0, 0, 32, choices.size * 32)
  9.     self.visible = false
  10.     self.active = false
  11.     self.z = 9999
  12.     @index = 0
  13.     @item_max = choices.size
  14.     @choices = choices
  15.     self.contents = Bitmap.new(32, 32)
  16.     self.opacity = $game_system.opacity
  17.     self.back_opacity = $game_system.back_opacity
  18.   end
  19.  
  20.   def refresh
  21.     # determine necessary width
  22.     width = 64
  23.     for line in @choices
  24.       width = [width, (self.contents.text_size(line).width + 48)].max
  25.     end
  26.     self.width = width
  27.     self.height = @choices.size * 32 + 32
  28.     self.contents = Bitmap.new(width - 32, height - 32)
  29.     if $game_system.font_color.nil?
  30.       self.contents.font.color = normal_color
  31.     else
  32.       self.contents.font.color = $game_system.font_color
  33.     end
  34.     if $game_system.windowskin != ""  
  35.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin)
  36.     else
  37.       self.windowskin = RPG::Cache.windowskin($data_system.windowskin_name)
  38.     end
  39.  
  40.     # draw choices
  41.     y = 0
  42.     for line in @choices
  43.       # Draw text
  44.       if $game_system.shadowed_text
  45.         old_color = self.contents.font.color.clone
  46.         self.contents.font.color = $game_system.shadow_color
  47.         self.contents.draw_text(6, 32 * y + 2, width, 32, line)
  48.         self.contents.font.color = old_color
  49.       end
  50.       self.contents.draw_text(4, y * 32, width, 32, line)
  51.       y += 1
  52.     end
  53.   end
  54.  
  55.   def set_choices(choices)
  56.     @choices = choices
  57.     @item_max = @choices.size
  58.     for choice in @choices
  59.       choice.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  60.       choice.gsub!(/\\[Nn]\[([0-9]+)\]/) {
  61.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  62.       }
  63.     end
  64.     refresh
  65.   end
  66. end
  67.  
  68. #==============================================================================
  69. # ** Window_Name
  70. #------------------------------------------------------------------------------
  71. #  This window is used to display names above the message window.  Uncomment
  72. #   and modify the various sections to customize.
  73. #==============================================================================
  74. class Window_Name < Window_Base
  75.   attr_accessor :dummy_window
  76.  
  77.   def initialize
  78.     super(0, 0, 32, 64)
  79.     self.contents = Bitmap.new(32, 32)
  80.     self.opacity = 0
  81.     @dummy_window = Window_Dummy.new
  82.     self.visible = false
  83.     @same_name = ""
  84.     @name = ""
  85.   end
  86.  
  87.   def set_name(name)
  88.     @name = name
  89.     refresh if @name != @same_name
  90.     @same_name = @name
  91.   end
  92.  
  93.   def refresh  
  94.     if @name == nil
  95.       return
  96.     end
  97.     self.width = self.contents.text_size(@name).width + 48
  98.  
  99.     self.contents = Bitmap.new(width - 32, height - 32)
  100.  
  101.     if $game_system.name_window
  102.       @dummy_window.x = self.x
  103.       @dummy_window.y = self.y + 12
  104.       @dummy_window.set(height - 24, width - 12)
  105.     end
  106.  
  107.     # uncomment this and change the font to give the name window a fancy font
  108.     self.contents.font.name = $fontface
  109.     self.contents.font.color = Color.new(0, 0, 0, 255)
  110.     self.contents.draw_text(0, 0, self.width, 32, @name)
  111.     self.contents.draw_text(0, 2, self.width, 32, @name)
  112.     self.contents.draw_text(2, 0, self.width, 32, @name)
  113.     self.contents.draw_text(2, 2, self.width, 32, @name)
  114.     # change the color to give the name window a seperate color
  115.     self.contents.font.color = normal_color
  116.     self.contents.draw_text(1, 1, self.width, 32, @name)
  117.   end
  118.  
  119.   def update
  120.     super
  121.     if $game_system.name_window
  122.       @dummy_window.x = self.x
  123.       @dummy_window.y = self.y + 12
  124.       @dummy_window.update
  125.     end
  126.   end
  127.  
  128.   def dispose
  129.     @dummy_window.dispose
  130.     super
  131.   end
  132. end
  133.  
  134. class Window_Dummy < Window_Base
  135.   def initialize
  136.     super(0, 0, 32, 64)
  137.     self.z = 9999
  138.     self.visible = false
  139.   end
  140.  
  141.   def set(height, width)
  142.     self.height = height
  143.     self.width = width
  144.   end
  145.  
  146.   def update
  147.     super
  148.     if $game_system.windowskin != ""  
  149.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin)
  150.     else
  151.       self.windowskin = RPG::Cache.windowskin($data_system.windowskin_name)
  152.     end
  153.   end
  154. end
  155.  
  156. #==============================================================================
  157. # ** Window_Slave
  158. #------------------------------------------------------------------------------
  159. #  These are slave windows to the main message window.  They will close when
  160. #   the user terminates them.  Initial settings are identical to the main
  161. #   message window, with one exception.  When in normal mode, it will apear
  162. #   above if the main message is below, below if it is above or centered.  Use
  163. #   message codes to change the settings for this window.
  164. #==============================================================================
  165. class Window_Slave < Window_Base
  166.   attr_accessor :show
  167.   attr_reader :done
  168.  
  169.   def write_all
  170.     @write_all = true
  171.   end
  172.  
  173.   #--------------------------------------------------------------------------
  174.   # * Object Initialization
  175.   #--------------------------------------------------------------------------
  176.   def initialize (text)
  177.     super(0, 0, 33, 33)
  178.     @text = text
  179.  
  180.     # x-coordinate depends on justification
  181.     if @justification == RIGHT
  182.       self.x = 640 - self.width
  183.     elsif @justification == LEFT
  184.       self.x = 0
  185.     else # center
  186.       self.x = (640 - self.width) / 2
  187.     end
  188.     # y-coordinate depends on height
  189.     self.y = 480 - $game_system.window_height - 16
  190.     self.contents = Bitmap.new(width - 32, height - 32)
  191.     self.visible = false
  192.     self.z = 9998
  193.     @fade_in = false
  194.     @fade_out = false
  195.     @contents_showing = false
  196.  
  197.     # face graphic sprite
  198.     @face = Sprite.new
  199.     @face.opacity = 0
  200.     @face.z = self.z + 1
  201.     @face_offset = 0
  202.  
  203.     # choice window
  204.     @choice_window = Window_Choice.new([])
  205.     @choice_window.back_opacity = $game_system.back_opacity
  206.  
  207.     @comic_style = $game_system.comic_style
  208.     @name = $game_system.name
  209.  
  210.     # comic sprite
  211.     @comic = Sprite.new
  212.     @comic.opacity = 0
  213.     @comic.z = self.z + 1
  214.     if @comic_style == TALK1
  215.       @comic.bitmap = RPG::Cache.windowskin("talk1")
  216.     elsif @comic_style == TALK2
  217.       @comic.bitmap = RPG::Cache.windowskin("talk2")
  218.     else # thought
  219.       @comic.bitmap = RPG::Cache.windowskin("thought")
  220.     end
  221.  
  222.     @pause_time = 0
  223.     @wait = 0
  224.  
  225.     @mode = $game_system.ums_mode
  226.     self.height = $game_system.window_height
  227.     self.width = $game_system.window_width
  228.     @justification = $game_system.window_justification
  229.     @face_graphic = $game_system.face_graphic
  230.     @face_graphic_justification = $game_system.face_graphic_justification
  231.     @message_event = $game_system.message_event
  232.     if $game_system.message_position == 2 # down
  233.       @message_position = 0
  234.     else
  235.       @message_postion = 2
  236.     end
  237.     @face_graphic_position = $game_system.face_graphic_position
  238.     if $game_system.font == ""
  239.       @font = Font.default_name
  240.     else
  241.       @font = $game_system.font
  242.     end
  243.     @text_justification = $game_system.text_justification
  244.  
  245.     @shake = $game_system.shake
  246.  
  247.     @face_frame = 0
  248.  
  249.     refresh
  250.   end
  251.   #--------------------------------------------------------------------------
  252.   # * Dispose
  253.   #--------------------------------------------------------------------------
  254.   def dispose
  255.     terminate_message
  256.     $game_temp.message_window_showing = false
  257.     if @input_number_window != nil
  258.       @input_number_window.dispose
  259.     end
  260.     @face.dispose
  261.     @choice_window.dispose
  262.     @comic.dispose
  263.     if @name_window != nil
  264.       @name_window.dispose
  265.     end
  266.     super
  267.   end
  268.   #--------------------------------------------------------------------------
  269.   # * Terminate Message
  270.   #--------------------------------------------------------------------------
  271.   def terminate_message
  272.     self.active = false
  273.     self.pause = false
  274.     self.contents.clear
  275.     # Clear showing flag
  276.     @contents_showing = false
  277.     # Call message callback
  278.     if $game_temp.message_proc != nil
  279.       $game_temp.message_proc.call
  280.     end
  281.     # Clear variables related to text, choices, and number input
  282.     $game_temp.message_text = nil
  283.     $game_temp.message_proc = nil
  284.     $game_temp.choice_start = 99
  285.     $game_temp.choice_max = 0
  286.     $game_temp.choice_cancel_type = 0
  287.     $game_temp.choice_proc = nil
  288.     $game_temp.num_input_start = 99
  289.     $game_temp.num_input_variable_id = 0
  290.     $game_temp.num_input_digits_max = 0
  291.     # Open gold window
  292.     if @gold_window != nil
  293.       @gold_window.dispose
  294.       @gold_window = nil
  295.     end
  296.     @choice_window.visible = false
  297.     @choice_window.active = false
  298.     @comic.opacity = 0
  299.   end
  300.   #--------------------------------------------------------------------------
  301.   # * Refresh
  302.   #--------------------------------------------------------------------------
  303.   def refresh
  304.  
  305.     self.contents.clear
  306.     if $game_system.font_color.nil?
  307.       self.contents.font.color = normal_color
  308.     else
  309.       self.contents.font.color = $game_system.font_color
  310.     end
  311.     if $game_system.windowskin != ""  
  312.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin)
  313.     else
  314.       self.windowskin = RPG::Cache.windowskin($data_system.windowskin_name)
  315.     end
  316.     @x = @y = 0
  317.  
  318.     # If waiting for a message to be displayed
  319.     if @text != nil
  320.       # replace shortcuts with original code
  321.       $game_system.shortcuts.each { |shortcut, code|
  322.         @text.gsub!(shortcut, code)
  323.       }
  324.  
  325.       # Control text processing
  326.       begin
  327.         last_text = @text.clone
  328.         @text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  329.       end until @text == last_text
  330.       @text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  331.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  332.       end
  333.  
  334.       # window mode
  335.       if @text.index(/\\[Mm]/) != nil
  336.         if $game_system.ums_mode == NORMAL_MODE
  337.           @mode = FIT_WINDOW_TO_TEXT
  338.         else
  339.           @mode = NORMAL_MODE
  340.         end
  341.         @text.gsub!(/\\[Mm]/) { "" }
  342.       end
  343.  
  344.       # window height
  345.       @text.gsub!(/\\[Hh][Ee][Ii][Gg][Hh][Tt]\[([0-9]+)\]/) do
  346.         self.height = $1.to_i
  347.         ""
  348.       end
  349.  
  350.       # window width
  351.       @text.gsub!(/\\[Ww][Ii][Dd][Tt][Hh]\[([0-9]+)\]/) do
  352.         self.width = $1.to_i
  353.         ""
  354.       end
  355.  
  356.       # justification
  357.       @text.gsub!(/\\[Jj][Rr]/) do
  358.         @justification = RIGHT
  359.         reset_window
  360.         ""
  361.       end
  362.       @text.gsub!(/\\[Jj][Cc]/) do
  363.         @justification = CENTER
  364.         reset_window
  365.         ""
  366.       end      
  367.       @text.gsub!(/\\[Jj][Ll]/) do
  368.         @justification = LEFT
  369.         reset_window
  370.         ""
  371.       end
  372.  
  373.       # face graphics
  374.       @text.gsub!(/\\[Ff][Aa][Cc][Ee]\[(.*?)\]/) do
  375.         @face_graphic = $1.to_s
  376.         if $1.to_s == ""
  377.           @face.opacity = 0
  378.         end
  379.         ""
  380.       end
  381.       @text.gsub!(/\\[Ff][Ll]/) do
  382.         @face_graphic_justification = LEFT
  383.         ""
  384.       end
  385.       @text.gsub!(/\\[Ff][Rr]/) do
  386.         @face_graphic_justification = RIGHT
  387.         ""
  388.       end
  389.  
  390.       # event centering
  391.       @text.gsub!(/\\[Ee]\[([0-9]+)\]/) do
  392.         @message_event = $1.to_i
  393.         ""
  394.       end
  395.  
  396.       # comic thingy
  397.       @text.gsub!(/\\[Tt]1/) do
  398.         @comic_style = TALK1
  399.         @comic.bitmap = RPG::Cache.windowskin("talk1.png")
  400.         ""
  401.       end
  402.       @text.gsub!(/\\[Tt]2/) do
  403.         @comic_style = TALK2
  404.         @comic.bitmap = RPG::Cache.windowskin("talk2.png")
  405.         ""
  406.       end
  407.       @text.gsub!(/\\[Tt][Hh]/) do
  408.         @comic_style = THOUGHT
  409.         @comic.bitmap = RPG::Cache.windowskin("thought.png")
  410.         ""
  411.       end
  412.  
  413.       # name window
  414.       @text.gsub!(/\\[Nn][Mm]\[(.*?)\]/) do
  415.         @name = $1.to_s
  416.         if $1.to_s == "" and @name_window != nil
  417.           @name_window.visible = false
  418.         end
  419.         ""
  420.       end
  421.       if @name != ""
  422.         # name window
  423.         @name_window = Window_Name.new
  424.         @name_window.z = self.z + 1
  425.         @name_window.set_name(@name)
  426.       end
  427.  
  428.       # shaking
  429.       @text.gsub!(/\\[Ss][Hh][Kk]\[([0-9]+)\]/) do
  430.         @shake = $1.to_i
  431.         ""
  432.       end
  433.  
  434.       # back opacity
  435.       @text.gsub!(/\\[Bb][Oo][Pp][Cc]\[([0-9]+)\]/) do
  436.         self.back_opacity = $1.to_i
  437.         ""
  438.       end
  439.  
  440.       # opacity
  441.       @text.gsub!(/\\[Oo][Pp][Cc]\[([0-9]+)\]/) do
  442.         self.opacity = $1.to_i
  443.         ""
  444.       end
  445.  
  446.       # Change "\\\\" to "\000" for convenience
  447.       @text.gsub!(/\\\\/) { "\000" }
  448.       # Change "\\C" to "\001" and "\\G" to "\002"
  449.       @text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  450.       @text.gsub!(/\\[Gg]/) { "\002" }
  451.       @text.gsub!(/\\[Cc]\[0x([0123456789abcdef]+)\]/) { "\026[#{$1}]" }
  452.  
  453.       # text skip code
  454.       @text.gsub!(/\\[Ss][Kk][Ii][Pp]/) { "\003" }
  455.  
  456.       # ignore code
  457.       @text.gsub!(/\\[Ii][Gg][Nn][Rr]/) { "\023" }
  458.  
  459.       # bold and italics
  460.       @text.gsub!(/\\[Bb]/) { "\004" }
  461.       @text.gsub!(/\\[Ii]/) { "\005" }
  462.  
  463.       # shadow
  464.       @text.gsub!(/\\[Ss]/) { "\006" }
  465.  
  466.       # font
  467.       @text.gsub!(/\\[Ff][Oo][Nn][Tt]\[(.*?)\]/) { "\007[#{$1}]" }
  468.  
  469.       # pause and wait
  470.       @text.gsub!(/\\[Pp]\[([0-9]+)\]/) { "\010[#{$1}]" }
  471.       @text.gsub!(/\\[Ww]\[([0-9]+)\]/) { "\011[#{$1}]" }
  472.  
  473.       # write speed
  474.       @text.gsub!(/\\[Ww][Ss]\[([0-9]+)\]/) { "\013[#{$1}]" }
  475.  
  476.       # armor, items, skills, and weapons
  477.       @text.gsub!(/\\[Oo][Aa]\[([0-9]+)\]/) {
  478.         item = $data_armors[$1.to_i]
  479.         "\014[#{$1}]" + "  " + item.name
  480.       }
  481.       @text.gsub!(/\\[Oo][Ii]\[([0-9]+)\]/) {
  482.         item = $data_items[$1.to_i]
  483.         "\015[#{$1}]" + "  " + item.name
  484.       }
  485.       @text.gsub!(/\\[Oo][Ss]\[([0-9]+)\]/) {
  486.         item = $data_skills[$1.to_i]
  487.         "\016[#{$1}]" + "  " + item.name
  488.       }
  489.       @text.gsub!(/\\[Oo][Ww]\[([0-9]+)\]/) {
  490.         item = $data_weapons[$1.to_i]
  491.         "\017[#{$1}]" + "  " + item.name
  492.       }
  493.  
  494.       # text justification
  495.       @text.gsub!(/\\[Tt][Cc]/) { "\020" }
  496.       @text.gsub!(/\\[Tt][Ll]/) { "\021" }
  497.       @text.gsub!(/\\[Tt][Rr]/) { "\022" }
  498.  
  499.       # Resize the window to fit the contents?
  500.       if @mode == FIT_WINDOW_TO_TEXT
  501.         width = 1
  502.         text = @text.split("\n")
  503.         height = 0
  504.         i = 0
  505.         for line in text
  506.           # don't count this line's width if it has the ignr code
  507.           if !line.include?("\023")
  508.             width = [width, self.contents.text_size(line).width].max
  509.             delta = self.contents.text_size(line).height
  510.             height += delta + (6 * i) + 3
  511.             if i < 3
  512.               i += 1
  513.             end
  514.           end
  515.         end
  516.  
  517.         if @face_graphic != "" and ($game_system.face_graphic_position == CENTER or $game_system.face_graphic_position == BOTTOM)
  518.           width += @face.bitmap.width
  519.           if height < @face.bitmap.height
  520.             height = @face.bitmap.height - 32
  521.           end
  522.         end
  523.  
  524.         if height == 0
  525.           height = 1
  526.         end
  527.  
  528.         self.width = width + 48
  529.         self.height = height + 48
  530.         self.contents = Bitmap.new(width + 16, height)
  531.         if $game_system.font_color.nil?
  532.           self.contents.font.color = normal_color
  533.         else
  534.           self.contents.font.color = $game_system.font_color
  535.         end
  536.  
  537.       else
  538.  
  539.         if self.width != $game_system.window_height or self.height != $game_system.window_width
  540.           self.width = $game_system.window_width
  541.           self.height = $game_system.window_height
  542.           self.contents = Bitmap.new(self.width - 32, self.height - 32)
  543.           if $game_system.font_color.nil?
  544.             self.contents.font.color = normal_color
  545.           else
  546.             self.contents.font.color = $game_system.font_color
  547.           end
  548.         end
  549.       end
  550.  
  551.       reset_window
  552.  
  553.       get_x_value
  554.  
  555.       @count = Graphics.frame_count
  556.       @pause_time = 0
  557.       @ignore = false
  558.       @done = false
  559.       @face_frame = 0
  560.     end
  561.  
  562.  
  563.  
  564.     # If number input
  565.     if $game_temp.num_input_variable_id > 0
  566.       digits_max = $game_temp.num_input_digits_max
  567.       number = $game_variables[$game_temp.num_input_variable_id]
  568.       @input_number_window = Window_InputNumber.new(digits_max)
  569.       @input_number_window.number = number
  570.       @input_number_window.x = self.x + 8
  571.       @input_number_window.y = self.y + $game_temp.num_input_start * 32
  572.     end
  573.   end
  574.   #--------------------------------------------------------------------------
  575.   # * Set Window Position and Opacity Level
  576.   #--------------------------------------------------------------------------
  577.   def reset_window (change_opacity = true)
  578.     # x-coordinate depends on justification
  579.     if @message_event == -1
  580.       if @justification == RIGHT
  581.         self.x = 640 - self.width
  582.       elsif @justification == LEFT
  583.         self.x = 0
  584.       else # center
  585.         self.x = (640 - self.width) / 2
  586.       end
  587.     else
  588.       if @message_event == 0 or $game_map.events[@message_event] == nil
  589.         # center on player
  590.         event_x = $game_player.screen_x
  591.       else
  592.         # center on the event specified
  593.         event_x = $game_map.events[@message_event].screen_x
  594.       end
  595.       self.x = event_x - self.width / 2
  596.       @comic.x = self.x + (self.width / 2) + 4
  597.     end
  598.  
  599.     if $game_temp.in_battle
  600.       self.y = 16
  601.     else
  602.       if @message_event == -1
  603.         case @message_position
  604.           when 0  # up
  605.             self.y = 16
  606.           when 1  # middle
  607.             self.y = (480 - self.height) / 2
  608.           when 2  # down
  609.             self.y = 480 - self.height - 24
  610.         end
  611.       else
  612.         if @message_event == 0 or $game_map.events[@message_event] == nil
  613.           # above player
  614.           self.y = $game_player.screen_y - self.height - 48
  615.         else
  616.           # above event specified
  617.           self.y = $game_map.events[@message_event].screen_y - self.height - 48
  618.         end
  619.         @comic.y = self.y + self.height - 2
  620.       end
  621.     end
  622.     if self.y < 0 + (@name == "" ? 0 : 16)
  623.       self.y = 0 + (@name == "" ? 0 : 16)
  624.     elsif self.y > 480 - self.height
  625.       self.y = 480 - self.height
  626.     end
  627.     if self.x < 0
  628.       self.x = 0
  629.     elsif self.x > 680 - self.width - 48
  630.       self.x = 640 - self.width
  631.     end
  632.  
  633.     if change_opacity
  634.       if $game_system.message_frame == 0
  635.         self.opacity = 255
  636.       else
  637.         self.opacity = 0
  638.       end
  639.       self.back_opacity = $game_system.back_opacity
  640.     end
  641.  
  642.     # face stuff
  643.       if @face_graphic != ""  
  644.         # the player has chosen to show a face graphic
  645.         if @done and $game_system.resting_face != ""
  646.           @face.bitmap = RPG::Cache.picture(@face_graphic + $game_system.resting_face)
  647.           if @face_frame * $game_system.face_frame_width >= @face.bitmap.width
  648.             @face_frame = 0
  649.           end
  650.         else
  651.           @face.bitmap = RPG::Cache.picture(@face_graphic)
  652.         end
  653.  
  654.         # picture y-coordinate
  655.         if @face_graphic_position == ABOVE
  656.           @face.y = self.y - @face.bitmap.height
  657.           @face_offset = 0
  658.         elsif @face_graphic_position == CENTER
  659.           delta = (@face.bitmap.height - self.height) / 2
  660.           @face.y = self.y - delta
  661.           if $game_system.animated_faces
  662.             @face_offset = $game_system.face_frame_width + 16
  663.           else
  664.             @face_offset = @face.bitmap.width + 16
  665.           end
  666.         elsif @face_graphic_position == BOTTOM
  667.           @face.y = self.y + self.height - @face.bitmap.height
  668.           if $game_system.animated_faces
  669.             @face_offset = $game_system.face_frame_width + 16
  670.           else
  671.             @face_offset = @face.bitmap.width + 16
  672.           end
  673.         else # side
  674.           delta = (@face.bitmap.height - self.height) / 2
  675.           @face.y = self.y - delta
  676.           @face_offset = 0
  677.         end
  678.  
  679.         # picture x-coordinate
  680.         if @face_graphic_justification == LEFT
  681.           if @face_graphic_position == SIDE
  682.             @face.x = self.x - @face.bitmap.width
  683.           else
  684.             @face.x = self.x + 10
  685.           end
  686.         else
  687.           if $game_system.animated_faces
  688.             offset = @face.bitmap.width - $game_system.face_frame_width
  689.           else
  690.             offset = 0
  691.           end
  692.           if @face_graphic_position == SIDE
  693.             @face.x = self.x + self.width + offset
  694.           else
  695.             @face.x = self.x + self.width - @face.bitmap.width - 10 + offset
  696.             @face_offset = 0
  697.           end
  698.         end
  699.  
  700.         if $game_system.animated_faces
  701.           @face.src_rect = Rect.new(@face_frame * $game_system.face_frame_width, 0, $game_system.face_frame_width, @face.bitmap.height)
  702.           if @done and $game_system.resting_face != ""
  703.             pause = $game_system.resting_animation_pause
  704.           else
  705.             pause = $game_system.animation_pause
  706.           end
  707.           if Graphics.frame_count % pause == 0
  708.             @animate_face = true
  709.           end
  710.           if @animate_face
  711.             if Graphics.frame_count % 3 == 0
  712.               @face_frame += 1
  713.               if @face_frame * $game_system.face_frame_width >= @face.bitmap.width
  714.                 @face_frame = 0
  715.                 @animate_face = false
  716.               end
  717.             end
  718.           end
  719.         end
  720.       end
  721.  
  722.       # name window
  723.       if @name != "" and @name != nil
  724.         @name_window.set_name(@name)
  725.         @name_window.x = self.x
  726.         @name_window.y = self.y - 36
  727.       end
  728.  
  729.       # If choice
  730.     if $game_temp.choice_max > 0
  731.       @choice_window.set_choices($game_temp.choices)
  732.       # determine x and y coords for choice window
  733.       if $game_system.choice_justification == LEFT
  734.         @choice_window.x = self.x
  735.       else
  736.         @choice_window.x = self.x + self.width - @choice_window.width
  737.       end
  738.       if $game_system.choice_position == ABOVE
  739.         # check to make sure there is enough room above the textbox
  740.         if self.y < @choice_window.height
  741.           # not enough room above, place below
  742.           @choice_window.y = self.y + self.height
  743.         else
  744.           # draw above
  745.           @choice_window.y = self.y - @choice_window.height
  746.         end
  747.       elsif $game_system.choice_position == BOTTOM
  748.         # check to make sure there is enough room below the textbox
  749.         if (480 - self.y - self.height) < @choice_window.height
  750.           # not enough room below, place above
  751.           @choice_window.y = self.y - @choice_window.height
  752.         else
  753.           # draw below
  754.           @choice_window.y = self.y + self.height
  755.         end
  756.       else # side
  757.         if $game_system.choice_justification == LEFT
  758.           # check to make sure there's room on the left side
  759.           if self.y < @choice_window.width
  760.             # not enough room on the side, check to make sure there's room below
  761.             if (480 - self.y - self.height) < @choice_window.height
  762.               # not enough room below, place above
  763.               @choice_window.y = self.y - @choice_window.height
  764.             else
  765.               # draw below
  766.               @choice_window.y = self.y + self.height
  767.             end
  768.           else
  769.             # place on the left side
  770.             @choice_window.y = self.y
  771.             @choice_window.x = self.x - @choice_window.width
  772.           end
  773.         else # right
  774.           # check to make sure there's room on the right side
  775.           if (680 - (self.y + self.width)) < @choice_window.width
  776.             # not enough room on the side, check to make sure there's room below
  777.             if (480 - self.y - self.height) < @choice_window.height
  778.               # not enough room below, place above
  779.               @choice_window.y = self.y - @choice_window.height
  780.             else
  781.               # draw below
  782.               @choice_window.y = self.y + self.height
  783.             end
  784.           else
  785.             # place on the left side
  786.             @choice_window.y = self.y
  787.             @choice_window.x = self.x + self.width
  788.           end
  789.         end
  790.       end
  791.     end
  792.   end
  793.   #--------------------------------------------------------------------------
  794.   # * Frame Update
  795.   #--------------------------------------------------------------------------
  796.   def update
  797.     super
  798.  
  799.     if !@show
  800.       return
  801.     else
  802.       self.visible = true
  803.       if @face_graphic != ""
  804.         @face.opacity = 255
  805.       end
  806.       if $game_system.comic_enabled and @message_event != -1
  807.         @comic.opacity = 255
  808.       end
  809.       if @name != ""
  810.         @name_window.visible = true
  811.       end
  812.       if @input_number_window != nil
  813.         @input_number_window.contents_opacity = 255
  814.       end
  815.       reset_window
  816.     end
  817.  
  818.  
  819.     if (@contents_showing and $game_system.message_event != -1 and @shake == 0) or $game_system.animated_faces
  820.       reset_window(false)
  821.     end
  822.  
  823.     if $game_system.shake != 0  # shake the window
  824.       if @ascending
  825.         if @target_x != self.x
  826.           self.x += 1
  827.         else
  828.           @ascending = false
  829.           @target_x = self.x - ($game_system.shake * 2)
  830.         end
  831.       else
  832.         if @target_x != self.x
  833.           self.x -= 1
  834.         else
  835.           @ascending = true
  836.           @target_x = self.x + ($game_system.shake * 2)
  837.         end
  838.       end
  839.     end
  840.  
  841.     if @wait > 0
  842.       @wait -= 1
  843.       if @wait == 0
  844.         terminate_message
  845.         return
  846.       end
  847.     end
  848.  
  849.     # If fade in
  850.     if @fade_in
  851.       self.contents_opacity += 24
  852.       if @face_graphic != ""
  853.         @face.opacity += 24
  854.       end
  855.       if $game_system.comic_enabled and @message_event != -1
  856.         @comic.opacity += 24
  857.       end
  858.       if @name != ""
  859.         @name_window.visible = true
  860.       end
  861.       if @input_number_window != nil
  862.         @input_number_window.contents_opacity += 24
  863.       end
  864.       if self.contents_opacity == 255
  865.         @fade_in = false
  866.       end
  867.       return
  868.     end
  869.  
  870.     # write the text
  871.     if @text != nil and @text != ""
  872.       speed = $game_system.write_speed
  873.       if $game_system.text_skip
  874.         if $game_system.skip_mode == WRITE_FASTER and Input.press?(Input::C)
  875.           # the player is holding the action button, write faster
  876.           speed /= 3
  877.         elsif $game_system.skip_mode == WRITE_ALL and @write_all
  878.           # the player pressed the action button, write all the text
  879.           while (c = @text.slice!(/./m)) != nil
  880.             write_char(c)
  881.           end
  882.           return
  883.         end
  884.       end
  885.       while @ignore
  886.         c = @text.slice!(/./m)
  887.         if c != nil
  888.           write_char(c)
  889.         end
  890.       end
  891.       if @pause_time > 0
  892.         @pause_time -= 1
  893.         return
  894.       end
  895.       if Graphics.frame_count - @count >= speed
  896.         if $game_system.sound_effect != ""
  897.           Audio.se_play("Audio/SE/" + $game_system.sound_effect, 80, 100)
  898.         end
  899.         @count = Graphics.frame_count
  900.         c = @text.slice!(/./m)
  901.         if c != nil
  902.           write_char(c)
  903.         end
  904.       end
  905.       return
  906.     end
  907.  
  908.     @done = true
  909.  
  910.     # If inputting number
  911.     if @input_number_window != nil
  912.       @input_number_window.update
  913.       # Confirm
  914.       if Input.trigger?(Input::C)
  915.         $game_system.se_play($data_system.decision_se)
  916.         $game_variables[$game_temp.num_input_variable_id] =
  917.           @input_number_window.number
  918.         $game_map.need_refresh = true
  919.         # Dispose of number input window
  920.         @input_number_window.dispose
  921.         @input_number_window = nil
  922.         terminate_message
  923.       end
  924.       return
  925.     end
  926.  
  927.     if @wait != 0
  928.       return
  929.     end
  930.  
  931.     # If message is being displayed and contents are all written
  932.     if @contents_showing
  933.       # if choice
  934.       if $game_temp.choice_max > 0
  935.         if !@choice_window.active
  936.           @choice_window.visible = true
  937.           @choice_window.active = true
  938.           @choice_window.index = 0
  939.         end
  940.         @choice_window.update
  941.       else
  942.         # If choice isn't being displayed, show pause sign
  943.         self.pause = true
  944.       end
  945.       return
  946.     end
  947.   end
  948.  
  949.   #--------------------------------------------------------------------------
  950.   # * Process and write the given character
  951.   #--------------------------------------------------------------------------
  952.   def write_char(c)
  953.     if c == "\000"
  954.       # Return to original text
  955.       c = "\\"
  956.     end
  957.     # If \C[n]
  958.     if c == "\001"
  959.     # Change text color
  960.       @text.sub!(/\[([0-9]+)\]/, "")
  961.       color = $1.to_i
  962.       if color >= 0 and color <= 7
  963.         self.contents.font.color = text_color(color)
  964.       end
  965.       # go to next text
  966.       return
  967.     end
  968.     # If \G
  969.     if c == "\002"
  970.       # Make gold window
  971.       if @gold_window == nil
  972.         @gold_window = Window_Gold.new
  973.         @gold_window.x = 560 - @gold_window.width
  974.         if $game_temp.in_battle
  975.           @gold_window.y = 192
  976.         else
  977.           @gold_window.y = self.y >= 128 ? 32 : 384
  978.         end
  979.         @gold_window.opacity = self.opacity
  980.         @gold_window.back_opacity = self.back_opacity
  981.       end
  982.       # go to next text
  983.       return
  984.     end
  985.     # If \skip
  986.     if c == "\003"
  987.       # toggle text skipping
  988.       #$game_system.text_skip = !$game_system.text_skip
  989.       # go to next text
  990.       return
  991.     end
  992.     # If \b
  993.     if c == "\004"
  994.       # toggle bold
  995.       self.contents.font.bold = !self.contents.font.bold
  996.       # go to next text
  997.       return
  998.     end
  999.     # If \i
  1000.     if c == "\005"
  1001.       # toggle italics
  1002.       self.contents.font.italic = !self.contents.font.italic
  1003.       # go to next text
  1004.       return
  1005.     end
  1006.     # If \s
  1007.     if c == "\006"
  1008.       # toggle shadow
  1009.       #$game_system.shadowed_text = !$game_system.shadowed_text
  1010.       # go to next text
  1011.       return
  1012.     end
  1013.     # If \font
  1014.     if c == "\007"
  1015.       # change font
  1016.       @text.sub!(/\[(.*?)\]/, "")
  1017.       font = $1.to_s
  1018.       @font = font
  1019.       if font == ""
  1020.         self.contents.font.name = Font.default_name
  1021.       else
  1022.         self.contents.font.name = font
  1023.       end
  1024.       # go to next text
  1025.       return
  1026.     end
  1027.     # If \p[n]
  1028.     if c == "\010"
  1029.       @text.sub!(/\[([0-9]+)\]/, "")
  1030.       @pause_time = $1.to_i
  1031.  
  1032.       # go to next text
  1033.       return
  1034.     end
  1035.  
  1036.     # If \w[n]
  1037.     if c == "\011"
  1038.       @text.sub!(/\[([0-9]+)\]/, "")
  1039.       @wait = $1.to_i
  1040.  
  1041.       # go to next text
  1042.       return
  1043.     end
  1044.  
  1045.     # If \ws[n]
  1046.     if c == "\013"
  1047.       @text.sub!(/\[([0-9]+)\]/, "")
  1048.       $game_system.write_speed = $1.to_i
  1049.  
  1050.       # go to next text
  1051.       return
  1052.     end
  1053.     # If \oa[n]
  1054.     if c == "\014"
  1055.       @text.sub!(/\[([0-9]+)\]/, "")
  1056.       index = $1.to_i
  1057.       @text.sub!("  ", "")
  1058.       item = $data_armors[index]
  1059.       # draw the icon
  1060.       icon = RPG::Cache.icon(item.icon_name)
  1061.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  1062.       @x += 24
  1063.  
  1064.       # go to next text
  1065.       return
  1066.     end
  1067.  
  1068.     # If \oi[n]
  1069.     if c == "\015"
  1070.       @text.sub!(/\[([0-9]+)\]/, "")
  1071.       index = $1.to_i
  1072.       @text.sub!("  ", "")
  1073.       item = $data_items[index]
  1074.       # draw the icon
  1075.       icon = RPG::Cache.icon(item.icon_name)
  1076.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  1077.       @x += 24
  1078.  
  1079.       # go to next text
  1080.       return
  1081.     end
  1082.  
  1083.     # If \os[n]
  1084.     if c == "\016"
  1085.       @text.sub!(/\[([0-9]+)\]/, "")
  1086.       index = $1.to_i
  1087.       @text.sub!("  ", "")
  1088.       item = $data_skills[index]
  1089.       # draw the icon
  1090.       icon = RPG::Cache.icon(item.icon_name)
  1091.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  1092.       @x += 24
  1093.  
  1094.       # go to next text
  1095.       return
  1096.     end
  1097.  
  1098.     # If \ow[n]
  1099.     if c == "\017"
  1100.       @text.sub!(/\[([0-9]+)\]/, "")
  1101.       index = $1.to_i
  1102.       @text.sub!("  ", "")
  1103.       item = $data_weapons[index]
  1104.       # draw the icon
  1105.       icon = RPG::Cache.icon(item.icon_name)
  1106.       self.contents.blt(@x + 2, (@y * 32) + 4, icon, Rect.new(0, 0, 24, 24))
  1107.       @x += 24
  1108.  
  1109.       # go to next text
  1110.       return
  1111.     end
  1112.  
  1113.     # If \tc
  1114.     if c == "\020"
  1115.       # center justify
  1116.       @text_justification = CENTER
  1117.       get_x_value
  1118.       # go to next text
  1119.       return
  1120.     end
  1121.  
  1122.     # If \tl
  1123.     if c == "\021"
  1124.       # left justify
  1125.       @text_justification = LEFT
  1126.       get_x_value
  1127.       # go to next text
  1128.       return
  1129.     end
  1130.  
  1131.     # If \tr
  1132.     if c == "\022"
  1133.       # right justify
  1134.       @text_justification = RIGHT
  1135.       get_x_value
  1136.       # go to next text
  1137.       return
  1138.     end
  1139.  
  1140.     # If \ignr
  1141.     if c == "\023"
  1142.       # set ignore flage
  1143.       @ignore = true
  1144.       # go to next text
  1145.       return
  1146.     end
  1147.  
  1148.     # if \c (hex color)
  1149.     if c == "\026"
  1150.       # convert hex color to RGB
  1151.       @text.sub!(/\[([0123456789abcdef]+)\]/, "")
  1152.       hex_code = $1.to_s
  1153.  
  1154.       red   = ("0x" + hex_code.slice(0..1)).hex
  1155.       blue  = ("0x" + hex_code.slice(2..3)).hex
  1156.       green = ("0x" + hex_code.slice(4..5)).hex
  1157.  
  1158.       self.contents.font.color = Color.new(red, blue, green)
  1159.       return
  1160.     end
  1161.  
  1162.     # If new line text
  1163.     if c == "\n"
  1164.       # Add 1 to y
  1165.       if !@ignore
  1166.         @y += 1
  1167.       end
  1168.       if @text != ""
  1169.         get_x_value
  1170.       end
  1171.       @ignore = false
  1172.  
  1173.       # go to next text
  1174.       return
  1175.     end
  1176.     if @ignore
  1177.       return
  1178.     end
  1179.     # Draw text
  1180.     line = self.contents.text_size("dj").height
  1181.     if $game_system.shadowed_text
  1182.       old_color = self.contents.font.color.clone
  1183.       self.contents.font.color = $game_system.shadow_color
  1184.       self.contents.draw_text(6 + @x, line * @y + 2, 40, 32, c)
  1185.       self.contents.font.color = old_color
  1186.     end
  1187.     self.contents.draw_text(4 + @x, line * @y, 40, 32, c)
  1188.     # Add x to drawn text width
  1189.     @x += self.contents.text_size(c).width
  1190.   end
  1191.  
  1192.   def get_x_value
  1193.     # text justification - offset for first line
  1194.     if @text_justification == CENTER
  1195.       # get the length of the current line
  1196.       w = self.contents.text_size(@text.split("\n")[0]).width
  1197.       @x = (self.width - w - 48) / 2
  1198.     elsif @text_justification == RIGHT
  1199.       # get the length of the current line
  1200.       w = self.contents.text_size(@text.split("\n")[0]).width
  1201.       @x = self.width - w - 48
  1202.     else # left
  1203.       if @face_graphic == ""
  1204.         @x = 0
  1205.       else
  1206.         @x = @face_offset
  1207.       end
  1208.     end
  1209.   end
  1210. end

UMS 5 - Window_InputNumber
RUBY 代码复制
  1. #==============================================================================
  2. # ** Window_InputNumber
  3. #------------------------------------------------------------------------------
  4. #  This window is for inputting numbers, and is used within the
  5. #  message window.
  6. #==============================================================================
  7.  
  8. class Window_InputNumber < Window_Base
  9.   #--------------------------------------------------------------------------
  10.   # * Object Initialization
  11.   #     digits_max : digit count
  12.   #--------------------------------------------------------------------------
  13.   def initialize(digits_max)
  14.     @digits_max = digits_max
  15.     @number = 0
  16.     # Calculate cursor width from number width (0-9 equal width and postulate)
  17.     dummy_bitmap = Bitmap.new(32, 32)
  18.     @cursor_width = dummy_bitmap.text_size("0").width + 8
  19.     dummy_bitmap.dispose
  20.     super(0, 0, @cursor_width * @digits_max + 32, 64)
  21.     self.contents = Bitmap.new(width - 32, height - 32)
  22.     self.z += 9999
  23.     self.opacity = $game_system.opacity
  24.     self.back_opacity = $game_system.back_opacity
  25.     @index = 0
  26.     refresh
  27.     update_cursor_rect
  28.   end
  29.  
  30.   #--------------------------------------------------------------------------
  31.   # * Refresh
  32.   #--------------------------------------------------------------------------
  33.   def refresh
  34.     self.contents.clear
  35.     if $game_system.font_color.nil?
  36.       self.contents.font.color = normal_color
  37.     else
  38.       self.contents.font.color = $game_system.font_color
  39.     end
  40.     if $game_system.windowskin != ""  
  41.       self.windowskin = RPG::Cache.windowskin($game_system.windowskin)
  42.     else
  43.       self.windowskin = RPG::Cache.windowskin($data_system.windowskin_name)
  44.     end
  45.     s = sprintf("%0*d", @digits_max, @number)
  46.     for i in 0...@digits_max
  47.       # Draw text
  48.       if $game_system.shadowed_text
  49.         old_color = self.contents.font.color.clone
  50.         self.contents.font.color = $game_system.shadow_color
  51.         self.contents.draw_text(i * @cursor_width + 6, 2, 32, 32, s[i,1])
  52.         self.contents.font.color = old_color
  53.       end
  54.       self.contents.draw_text(i * @cursor_width + 4, 0, 32, 32, s[i,1])
  55.     end
  56.   end
  57. end
  

Lv1.梦旅人

梦石
0
星屑
50
在线时间
42 小时
注册时间
2010-11-20
帖子
11
2
 楼主| 发表于 2013-2-1 13:33:45 | 只看该作者
图片文件:




回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
42 小时
注册时间
2010-11-20
帖子
11
3
 楼主| 发表于 2013-2-2 15:16:59 | 只看该作者
不是吧……一天过去了,一个回复都没有……
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-12-2 07:43

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表