查看: 2199|回复: 1

[已经过期] 关于Khas的气泡对话框脚本问题

[复制链接]
梦石
0
星屑
212
在线时间
52 小时
注册时间
2019-1-23
回帖
6
发表于 2019-2-11 23:03:26 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 VIPArcher 于 2019-9-26 15:01 编辑

这个脚本是即插即用的,但是我想一个地图里面使用【开启脚本】,另一个地图里不使用【也就是关闭脚本】
我是个小白不知道怎么用…………求大神指点哇QWQ
  1. #-------------------------------------------------------------------------------
  2. # * [ACE] Khas Message System
  3. #-------------------------------------------------------------------------------
  4. # * By Nilo K. (Khas)
  5. # * Version: 1.1
  6. # * Released on: 04.23.2017
  7. #
  8. # * Social Media
  9. # Blog: arcthunder.blogspot.com
  10. # Facebook: facebook.com/khasarc
  11. # Twitter: twitter.com/arcthunder
  12. # Youtube: youtube.com/c/khasarc
  13. #
  14. # * Khas Scripts @ RPG Maker Web forums (official support!)
  15. # forums.rpgmakerweb.com/index.php?/forum/132-khas-scripts
  16. #
  17. #-------------------------------------------------------------------------------
  18. # * Terms of Use
  19. #-------------------------------------------------------------------------------
  20. # When using KHAS MESSAGE SYSTEM (the script), you agree with the following terms:
  21. # 1. If you purchased a license to one of my scripts, credit is not required.
  22. #    Otherwise, you must give credit to Khas (if you want, a link to my blog is
  23. #    always appreciated);
  24. # 2. You can use the script for free in both non-commercial and commercial
  25. #    projects;
  26. # 4. You can edit the script for using in your own project. However, you are
  27. #    not allowed to share/distribute any modified version;
  28. # 5. If you want to share a Khas script, don’t post the direct download link,
  29. #    redirect the user to my blog instead;
  30. # 6. The script can not be ported to any RPG Maker version than VX Ace.
  31. #
  32. #-------------------------------------------------------------------------------
  33. # * Instructions
  34. #-------------------------------------------------------------------------------
  35. # This script changes the original message system design and adds some new
  36. # commands that can be used when displaying messages. Below you will find a
  37. # list of these commands.
  38. #
  39. # Due to the unique design of this script, it's  recommended to think carefully
  40. # about the windowskin that you will use (it's used for menus and choices).
  41. #
  42. # The Khas Message System is plug'n'play, you will need to import to your
  43. # project only the voice SE files of the actors.
  44. #
  45. #-------------------------------------------------------------------------------
  46. # * Commands
  47. #-------------------------------------------------------------------------------
  48. # EXISTING COMMANDS
  49. # \v[x] Variable X (int)
  50. # \n[x] Actor X name (int)
  51. # \p[x] Party member X name (int)
  52. # \i[x] Draw icon X (int)
  53. # \g    Currency unit
  54. # \{    Increase text size
  55. # \}    Decrease text size
  56. # \$    Open money window
  57. # \.    Pause (1/4 second)
  58. # \|    Pause (1 second)
  59. # \!    Wait for button
  60. # \>    Instantly display (line)
  61. # \<    Cancel above
  62. # \^    Do not wait for next page
  63. # \\    Backslash
  64. #
  65. # NEW COMMANDS
  66. # \c[color] Change text color (can be an hex color like #ffffff or
  67. #           a color declared on the configuration part. Examples:
  68. #           \c[#00ff00]
  69. #           \c[green]
  70. #
  71. # \a[actor] Change the actor who's speaking. The actor must be declared
  72. #           on the configuration part. Examples:
  73. #           \a[Alice]
  74. #           \c[Ernest]
  75. #
  76. # \s[time]  Shake the screen/balloon by the given time (in frames).
  77. #           Example:
  78. #           \s[20]
  79. #
  80. # \e[x]     Place the balloon over the event X.
  81. #           Example:
  82. #           \e[12]
  83. #
  84. # \p        Place the balloon over the player.
  85. #
  86. # \f        Make the balloon float (useful for a narrator).
  87. #
  88. # \t[se]    Change the typing sound to the given sound effect.
  89. #           Example:
  90. #           \t[female]
  91. #
  92. # \x[se]    Play the given sound effect.
  93. #           Example:
  94. #           \x[Cat]
  95. #
  96. #-------------------------------------------------------------------------------
  97. # * Message Core (configuration)
  98. #-------------------------------------------------------------------------------

  99. module Message_Core
  100.   
  101.   # ACTORS
  102.   # Declare your actors here, using the following format:
  103.   # "Actor Name" => ["color", "voice"]
  104.   # Actor Name: the actor name to be used with \a[Actor Name]
  105.   # color: the color name declared below
  106.   # voice: the voice file inside Audio/SE
  107.   Actors = {
  108.     "Eric" => ["blue", "male"],
  109.     "Natalie" => ["pink", "female"],
  110.     "Terence" => ["yellow", "male"],
  111.     "Ernest" => ["darkorange", "male"],
  112.     "Ryoma" => ["teal", "male"],
  113.     "Brenda" => ["gray", "female"],
  114.     "Rick" => ["green", "male"],
  115.     "Alice" => ["purple", "female"],
  116.     "Isabelle" => ["purple", "female"],
  117.     "Noah" => ["darkred", "male"],
  118.     "Old Man" => ["gray", "male"],
  119.     "Old Lady" => ["gray", "male"],
  120.     "Monster" => ["darkred", "male"],
  121.     "Boy" => ["blue", "male"],
  122.     "Girl" => ["pink", "female"],
  123.     "Lady" => ["purple", "female"],
  124.     "Man" => ["green", "male"],
  125.   }
  126.   
  127.   # COLORS
  128.   # Declare your colors here, using the following format:
  129.   # "colorname" => Color.new(R, G, B),
  130.   # The colorname can be used with \c[colorname]
  131.   Colors = {
  132.     "white" => Color.new(255, 255, 255),
  133.     "black" => Color.new(0, 0, 0),
  134.     "orange" => Color.new(255, 144, 9),
  135.    
  136.     "blue" => Color.new(111, 147, 191),
  137.     "pink" => Color.new(189, 74, 99),
  138.     "yellow" => Color.new(222, 164, 86),
  139.     "darkorange" => Color.new(171, 86, 36),
  140.     "teal" => Color.new(39, 89, 97),
  141.     "darkred" => Color.new(171, 61, 86),
  142.     "purple" => Color.new(121, 83, 145),
  143.     "green" => Color.new(92, 154, 75),
  144.     "gray" => Color.new(135, 156, 176),
  145.   }
  146.   
  147.   # MESSAGE BALLOON CONFIGURATION
  148.   # Background color
  149.   Background = Color.new(0,0,0,180)
  150.   
  151.   # Outline color
  152.   Outline = Color.new(255,255,255,120)
  153.   
  154.   # Minimum width
  155.   Minimum_Width = 80
  156.   
  157.   # Font properties
  158.   Font_Name = "Arial"
  159.   Font_Size = 18
  160.   Font_Bold = true
  161.   Font_Italic = false
  162.   Font_Outline = false
  163.   
  164.   # SE VOLUME
  165.   # Volume used to play voices
  166.   SE_Volume = 80
  167.   
  168.   # PAUSE CYCLE
  169.   # Number of frames to blink the cursor
  170.   Pause_Cycle = 30
  171.   
  172.   # Change these only if you're having trouble with your font
  173.   Standard_Padding = 4
  174.   New_Line_X = 4 + Standard_Padding
  175.   New_Page_Y = 3
  176.   
  177. end

  178. #-------------------------------------------------------------------------------
  179. # * Default Font
  180. #-------------------------------------------------------------------------------

  181. Font.default_name = [Message_Core::Font_Name]
  182. Font.default_size = Message_Core::Font_Size
  183. Font.default_bold = Message_Core::Font_Bold
  184. Font.default_outline = Message_Core::Font_Outline
  185. Font.default_italic = Message_Core::Font_Italic

  186. #-------------------------------------------------------------------------------
  187. # * Sprite Message
  188. #-------------------------------------------------------------------------------

  189. class Sprite_Message < Sprite
  190.   
  191.   include Message_Core
  192.   
  193.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  194.   # * Initialize (Executed once)
  195.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  196.   
  197.   def initialize
  198.     super(nil)
  199.     initialize_sprite
  200.     initialize_pause
  201.     create_all_windows
  202.     clear_instance_variables
  203.   end
  204.   
  205.   def initialize_sprite
  206.     self.bitmap = Bitmap.new(1,1)
  207.     self.opacity = 0
  208.     self.visible = false
  209.     self.z = 200
  210.   end
  211.   
  212.   def initialize_pause
  213.     @pause_sprite = Sprite.new
  214.     @pause_sprite.bitmap = Bitmap.new(3,3)
  215.     @pause_sprite.bitmap.fill_rect(0,0,3,3,Colors["white"])
  216.     @pause_sprite.visible = false
  217.     @pause_sprite.z = self.z + 1
  218.   end
  219.   
  220.   def create_all_windows
  221.     @gold_window = Window_Gold.new
  222.     @gold_window.x = Graphics.width - @gold_window.width
  223.     @gold_window.y = 0
  224.     @gold_window.openness = 0
  225.     @choice_window = Window_ChoiceList.new(self)
  226.     @number_window = Window_NumberInput.new(self)
  227.     @item_window = Window_KeyItem.new(self)
  228.   end
  229.   
  230.   def clear_instance_variables
  231.     @fiber = nil
  232.     @opening = false
  233.     @closing = false
  234.     @pause = false
  235.     clear_flags
  236.   end
  237.   
  238.   
  239.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  240.   # * Dispose (Executed once)
  241.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  242.   
  243.   def dispose
  244.     dispose_all_windows
  245.     dispose_pause
  246.     dispose_bitmap
  247.     super
  248.   end
  249.   
  250.   def dispose_all_windows
  251.     @gold_window.dispose
  252.     @choice_window.dispose
  253.     @number_window.dispose
  254.     @item_window.dispose
  255.   end
  256.   
  257.   def dispose_bitmap
  258.     self.bitmap.dispose if self.bitmap
  259.   end
  260.   
  261.   def dispose_pause
  262.     @pause_sprite.bitmap.dispose
  263.     @pause_sprite.dispose
  264.   end
  265.   
  266.   
  267.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  268.   # * Update
  269.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  270.   
  271.   def update
  272.     update_effects
  273.     update_all_windows
  274.     update_fiber
  275.   end
  276.   
  277.   def update_effects
  278.     update_open if @opening
  279.     update_close if @closing
  280.     update_pause if @pause
  281.     update_shake if @shake > 0
  282.   end
  283.   
  284.   def update_all_windows
  285.     @gold_window.update
  286.     @choice_window.update
  287.     @number_window.update
  288.     @item_window.update
  289.   end
  290.   
  291.   def update_fiber
  292.     if @fiber
  293.       @fiber.resume
  294.     elsif $game_message.busy? && !$game_message.scroll_mode
  295.       @fiber = Fiber.new { fiber_main }
  296.       @fiber.resume
  297.     else
  298.       $game_message.visible = false
  299.     end
  300.   end
  301.   
  302.   def update_open
  303.     self.opacity += 32
  304.     @opening = (self.opacity < 255)
  305.   end
  306.   
  307.   def update_close
  308.     self.opacity -= 32
  309.     @closing = (self.opacity > 0)
  310.   end
  311.   
  312.   def update_pause
  313.     if @pause_timer > 0
  314.       @pause_timer -= 1
  315.     else
  316.       @pause_sprite.visible = !@pause_sprite.visible
  317.       @pause_timer = Pause_Cycle
  318.     end
  319.   end
  320.   
  321.   def update_shake
  322.     if @shake > 1
  323.       self.ox = rand(17) - 8
  324.       self.oy = rand(17) - 8
  325.       @shake -= 1
  326.     else
  327.       stop_shake
  328.     end
  329.   end
  330.   
  331.   
  332.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  333.   # * Effect Control
  334.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  335.   
  336.   def open_and_wait
  337.     @opening = true
  338.     Fiber.yield while @opening
  339.   end
  340.   
  341.   def close_and_wait
  342.     @closing = true
  343.     Fiber.yield until all_close?
  344.   end
  345.   
  346.   def show_pause
  347.     @pause_sprite.visible = true
  348.     @pause = true
  349.     @pause_timer = Pause_Cycle
  350.   end
  351.   
  352.   def hide_pause
  353.     @pause_sprite.visible = false
  354.     @pause = false
  355.   end
  356.   
  357.   def shake(duration)
  358.     @shake = duration
  359.   end
  360.   
  361.   def stop_shake
  362.     self.ox = 0
  363.     self.oy = 0
  364.     @shake = 0
  365.   end
  366.   
  367.   
  368.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  369.   # * Main Processing
  370.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  371.   
  372.   def fiber_main
  373.     $game_message.visible = true
  374.     self.visible = true
  375.     loop do
  376.       process_all_text if $game_message.has_text?
  377.       process_input
  378.       $game_message.clear
  379.       @gold_window.close
  380.       Fiber.yield
  381.       break unless text_continue?
  382.     end
  383.     close_and_wait
  384.     clear_balloon
  385.     self.visible = false
  386.     $game_message.visible = false
  387.     @fiber = nil
  388.   end
  389.   
  390.   
  391.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  392.   # * Drawing processes
  393.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  394.   
  395.   def draw_balloon
  396.     # Reset stuff for new balloon
  397.     reset_font_settings
  398.     reset_character_actor
  399.    
  400.     # Process text
  401.     text = convert_escape_characters($game_message.all_text)
  402.     scan_special_commands(text)
  403.     text = remove_escape_characters(text)
  404.    
  405.     # Should the balloon float?
  406.     @float = true if @character.nil?
  407.    
  408.     # Check if the balloon will have a namebox
  409.     @namebox_yplus = (@actor ? text_size(@actor).height : 0)
  410.     @voice = (@actor ? Actors[@actor][1] : nil)
  411.    
  412.     # Check if the balloon will have a detail
  413.     @detail_yplus = (@float ? 0 : 10)
  414.    
  415.     # Calculate text dimensions
  416.     tw = fitting_width(text)
  417.     th = fitting_height(text) + @namebox_yplus + @detail_yplus
  418.    
  419.     # Check if the balloon needs to be inverted
  420.     if invert_balloon?(th)
  421.       @inverted = true
  422.       @margin_top = @detail_yplus
  423.       @margin_bottom = @namebox_yplus
  424.     else
  425.       @inverted = false
  426.       @margin_top = @namebox_yplus
  427.       @margin_bottom = @detail_yplus
  428.     end
  429.    
  430.     # Calculate balloon dimensions
  431.     balloon = Rect.new
  432.     balloon.x = 0
  433.     balloon.y = @margin_top
  434.     balloon.width = tw > Minimum_Width ? tw : Minimum_Width
  435.     balloon.height = th - @margin_top - @margin_bottom
  436.    
  437.     # Create a new bitmap
  438.     self.bitmap.dispose if self.bitmap
  439.     self.bitmap = Bitmap.new(balloon.width, th)
  440.     reset_font_settings
  441.    
  442.     # Draw the balloon
  443.     self.bitmap.fill_rect(balloon.x, balloon.y, balloon.width, balloon.height, Outline)
  444.     self.bitmap.fill_rect(balloon.x+1, balloon.y+1, balloon.width-2, balloon.height-2, Background)
  445.    
  446.     # Draw the namebox
  447.     draw_namebox(@inverted ? (th - @namebox_yplus - 2) : 0) if @actor
  448.   end
  449.   
  450.   def clear_balloon
  451.     self.bitmap.clear
  452.   end
  453.   
  454.   def draw_namebox(y)
  455.     rect = text_size(@actor)
  456.     color = Colors[Actors[@actor][0]]
  457.     color.alpha = Background.alpha
  458.     self.bitmap.fill_rect(4,y,rect.width+10,rect.height+2,Outline)
  459.     self.bitmap.fill_rect(5,y+1,rect.width+8,rect.height,color)
  460.     self.bitmap.draw_text(9,y+1,rect.width,rect.height,@actor)
  461.   end
  462.   
  463.   def draw_detail(x, y, reverse, upside_down)
  464.     dx = (reverse ? 1 : 0)
  465.     dy = (upside_down ? -1 : 1)
  466.     x -= 12 if reverse
  467.     for i in 12.downto(2)
  468.       fill_line(x, y, i)
  469.       x += dx
  470.       y += dy
  471.     end
  472.   end
  473.   
  474.   def fill_rect(x, y, sx, sy)
  475.     self.bitmap.fill_rect(x, y, sx, sy, Outline)
  476.     self.bitmap.fill_rect(x+1, y+1, sx-2, sy-2, Background)
  477.   end
  478.   
  479.   def fill_line(x, y, sx)
  480.     self.bitmap.fill_rect(x, y, sx, 1, Outline)
  481.     self.bitmap.fill_rect(x+1, y, sx-2, 1, Background)
  482.   end
  483.   
  484.   
  485.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  486.   # * Size/Position processing
  487.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  488.   
  489.   def move_balloon
  490.     if @float
  491.       x = (Graphics.width - width)/2
  492.       y = Graphics.height - height - self.bitmap.font.size
  493.     else
  494.       # Get the actual character and its height
  495.       bitmap = Cache.character(@character.character_name)
  496.       sign = @character.character_name[/^[\!\$]./]
  497.       if sign && sign.include?('$')
  498.         cw = bitmap.width / 6
  499.         ch = bitmap.height / 4
  500.       else
  501.         cw = bitmap.width / 24
  502.         ch = bitmap.height / 8
  503.       end
  504.       
  505.       # Calc initial position
  506.       x = @character.screen_x - width / 2
  507.       y = @character.screen_y - height - ch

  508.       # Check if the ballon is out of the screen
  509.       x = 2 if x < 2
  510.       x = Graphics.width - width - 2 if (x + width) > (Graphics.width - 2)
  511.       y = @character.screen_y if y < 0
  512.       
  513.       # Draw the detail
  514.       reverse = @character.direction < 5
  515.       sx = @character.screen_x - x + (reverse ? -cw : cw)
  516.       if sx < 0
  517.         reverse = !reverse
  518.         sx = @character.screen_x - x + (reverse ? -cw : cw)
  519.       elsif sx > self.bitmap.width
  520.         reverse = !reverse
  521.         sx = @character.screen_x - x + (reverse ? -cw : cw)
  522.       end
  523.       sy = (@inverted ? @margin_top : (self.bitmap.height - @margin_bottom - 1))
  524.       draw_detail(sx, sy, reverse, @inverted)
  525.     end
  526.    
  527.     # Set the position
  528.     self.x = x
  529.     self.y = y
  530.    
  531.     # Set the pause sprite position
  532.     @pause_sprite.x = self.x + self.width - 6
  533.     @pause_sprite.y = self.y + self.height - @margin_bottom - 6
  534.   end
  535.   
  536.   def invert_balloon?(h)
  537.     return false if @float
  538.     bitmap = Cache.character(@character.character_name)
  539.     sign = @character.character_name[/^[\!\$]./]
  540.     char_height = bitmap.height / (sign && sign.include?('$') ? 4 : 8)
  541.     @character.screen_y - h - char_height < 0
  542.   end
  543.   
  544.   def width
  545.     self.bitmap ? self.bitmap.width : 1
  546.   end
  547.   
  548.   def height
  549.     self.bitmap ? self.bitmap.height : 1
  550.   end
  551.   
  552.   def text_width(text)
  553.     result = 0
  554.     text.each_line do |line|
  555.       lw = text_size(line).width
  556.       result = lw if lw > result
  557.     end
  558.     result
  559.   end
  560.   
  561.   def text_height(text)
  562.     result = 0
  563.     text.each_line do |line|
  564.       result += line_height(line)
  565.     end
  566.     result
  567.   end
  568.   
  569.   def line_height(text)
  570.     result = self.bitmap.font.size
  571.     last_font_size = self.bitmap.font.size
  572.     text.slice(/^.*$/).scan(/\e[\{\}]/).each do |esc|
  573.       make_font_bigger  if esc == "\e{"
  574.       make_font_smaller if esc == "\e}"
  575.       result = [result, self.bitmap.font.size].max
  576.     end
  577.     self.bitmap.font.size = last_font_size
  578.     result
  579.   end
  580.   
  581.   def fitting_height(text)
  582.     text_height(text) + Standard_Padding * 2
  583.   end
  584.   
  585.   def fitting_width(text)
  586.     text_width(text) + Standard_Padding * 2
  587.   end
  588.   
  589.   
  590.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  591.   # * Text processing
  592.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  593.   
  594.   def process_all_text
  595.     text = convert_escape_characters($game_message.all_text)
  596.     pos = {}
  597.     new_page(text, pos)
  598.     until text.empty?
  599.       Fiber.yield if @skip_frame
  600.       @skip_frame = !@skip_frame
  601.       process_character(text.slice!(0, 1), text, pos)
  602.     end
  603.   end
  604.   
  605.   def new_page(text, pos)
  606.     draw_balloon
  607.     move_balloon
  608.     open_and_wait if self.opacity < 255
  609.     pos[:x] = New_Line_X
  610.     pos[:y] = New_Page_Y + @margin_top
  611.     pos[:new_x] = New_Line_X
  612.     pos[:height] = line_height(text)
  613.     clear_flags
  614.   end
  615.   
  616.   def clear_flags
  617.     @show_fast = false
  618.     @pause_skip = false
  619.     @skip_frame = false
  620.     @sound = true
  621.     @shake = 0
  622.   end
  623.   
  624.   def text_continue?
  625.     $game_message.has_text?
  626.   end
  627.   
  628.   def update_show_fast
  629.     @show_fast = true if Input.trigger?(:C)
  630.   end
  631.   
  632.   def wait_for_one_character
  633.     update_show_fast
  634.     Fiber.yield unless @show_fast
  635.   end
  636.   
  637.   def need_new_page?(text, pos)
  638.     pos[:y] + pos[:height] > self.bitmap.height && !text.empty?
  639.   end
  640.   
  641.   def process_new_page(text, pos)
  642.     text.slice!(/^\n/)
  643.     input_pause
  644.     new_page(text, pos)
  645.   end
  646.   
  647.   def process_draw_icon(icon_index, pos)
  648.     bitmap = Cache.system("Iconset")
  649.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  650.     self.bitmap.blt(pos[:x], pos[:y], bitmap, rect)
  651.     pos[:x] += 24
  652.     wait_for_one_character
  653.   end
  654.   
  655.   def process_escape_character(code, text, pos)
  656.     case code.upcase
  657.     when '$'
  658.       @gold_window.open
  659.     when '.'
  660.       wait(15)
  661.     when '|'
  662.       wait(60)
  663.     when '!'
  664.       input_pause
  665.     when '>'
  666.       @show_fast = true
  667.     when '<'
  668.       @show_fast = false
  669.     when '^'
  670.       @pause_skip = true
  671.     when 'C'
  672.       change_color(text.slice!(/^\[#?\w+\]/)[/#?\w+/])
  673.     when 'I'
  674.       process_draw_icon(text.slice!(/^\[\d+\]/)[/\d+/].to_i, pos)
  675.     when '{'
  676.       make_font_bigger
  677.     when '}'
  678.       make_font_smaller
  679.     when 'A'
  680.       text.slice!(/^\[[\w\s]+\]/)
  681.     when 'S'
  682.       shake(text.slice!(/^\[\d+\]/)[/\d+/].to_i)
  683.     when 'E'
  684.       text.slice!(/^\[\d+\]/)
  685.     when 'T'
  686.       @voice = text.slice!(/^\[\w*\]/)[/\w*/]
  687.       @voice = nil unless @voice.size > 0
  688.     when 'X'
  689.       Audio.se_play("Audio/se/#{text.slice!(/^\[\w+\]/)[/\w+/]}", SE_Volume)
  690.     end
  691.   end
  692.   
  693.   def actor_name(n)
  694.     actor = n >= 1 ? $game_actors[n] : nil
  695.     actor ? actor.name : ""
  696.   end
  697.   
  698.   def party_member_name(n)
  699.     actor = n >= 1 ? $game_party.members[n - 1] : nil
  700.     actor ? actor.name : ""
  701.   end
  702.   
  703.   def convert_escape_characters(text)
  704.     result = text.to_s.clone
  705.     result.gsub!(/\\/)            { "\e" }
  706.     result.gsub!(/\e\e/)          { "\" }
  707.     result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
  708.     result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
  709.     result.gsub!(/\eN\[(\d+)\]/i) { actor_name($1.to_i) }
  710.     result.gsub!(/\eP\[(\d+)\]/i) { party_member_name($1.to_i) }
  711.     result.gsub!(/\eG/i)          { Vocab::currency_unit }
  712.     result
  713.   end
  714.   
  715.   def remove_escape_characters(text)
  716.     result = text.to_s.clone
  717.     result.gsub!(/\ec\[#?\w+\]/i,"")
  718.     result.gsub!(/\es\[\d+\]/i,"")
  719.     result.gsub!(/\ee\[\d+\]/i,"")
  720.     result.gsub!(/\ea\[[\w\s]+\]/i,"")
  721.     result.gsub!(/\et\[\w*\]/i,"")
  722.     result.gsub!(/\ex\[\w+\]/i,"")
  723.     result.gsub!(/\ep/i, "")
  724.     result.gsub!(/\ef/i, "")
  725.     result.gsub!(/\e\|/, "")
  726.     result.gsub!(/\e\./, "")
  727.     result.gsub!(/\e\</, "")
  728.     result.gsub!(/\e\>/, "")
  729.     result.gsub!(/\e\^/, "")
  730.     result
  731.   end
  732.   
  733.   def scan_special_commands(text)
  734.     if text =~ /\ep/i
  735.       @character = $game_player
  736.     end
  737.    
  738.     if text =~ /\ef/i
  739.       @float = true
  740.     end
  741.    
  742.     if text =~ /\ea\[([\w\s]+)\]/i
  743.       @actor = $1 if Actors[$1]
  744.     end
  745.    
  746.     if text =~ /\ee\[(\d+)\]/i
  747.       @character = $game_map.events[$1.to_i] if $game_map.events[$1.to_i]
  748.     end
  749.    
  750.   end
  751.   
  752.   def text_size(str)
  753.     self.bitmap.text_size(str)
  754.   end
  755.   
  756.   
  757.   
  758.   def process_character(c, text, pos)
  759.     case c
  760.     when "\n"   # New line
  761.       process_new_line(text, pos)
  762.     when "\f"   # New page
  763.       process_new_page(text, pos)
  764.     when "\e"   # Control character
  765.       process_escape_character(obtain_escape_code(text), text, pos)
  766.     else        # Normal character
  767.       process_normal_character(c, pos)
  768.     end
  769.   end
  770.   
  771.   def process_normal_character(c, pos)
  772.     char_width = text_size(c).width
  773.     self.bitmap.draw_text(pos[:x], pos[:y], char_width * 2, pos[:height], c)
  774.     pos[:x] += char_width
  775.     Audio.se_play("Audio/se/#{@voice}") if @sound && c != " " && @voice
  776.     @sound = !@sound
  777.    
  778.     wait_for_one_character
  779.   end

  780.   
  781.   def process_new_line(text, pos)
  782.     pos[:x] = pos[:new_x]
  783.     pos[:y] += pos[:height]
  784.     pos[:height] = line_height(text)
  785.     if need_new_page?(text, pos)
  786.       input_pause
  787.       new_page(text, pos)
  788.     end
  789.   end
  790.   
  791.   def obtain_escape_code(text)
  792.     text.slice!(/^[\$\.\|\^!><\{\}\\]|^[A-Z]/i)
  793.   end
  794.   
  795.   
  796.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  797.   # * Font
  798.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  799.   
  800.   def reset_font_settings
  801.     change_color("white")
  802.     self.bitmap.font.size = Font.default_size
  803.     self.bitmap.font.bold = Font.default_bold
  804.     self.bitmap.font.italic = Font.default_italic
  805.   end
  806.   
  807.   def change_color(code)
  808.     if Colors[code]
  809.       self.bitmap.font.color.set(Colors[code])
  810.     elsif code =~ /#(..)(..)(..)/
  811.       self.bitmap.font.color.set(Color.new($1.hex, $2.hex, $3.hex))
  812.     end
  813.   end
  814.   
  815.   def make_font_bigger
  816.     self.bitmap.font.size += 8 if self.bitmap.font.size <= 64
  817.   end
  818.   
  819.   def make_font_smaller
  820.     self.bitmap.font.size -= 8 if self.bitmap.font.size >= 16
  821.   end
  822.   
  823.   
  824.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  825.   # * Input processing
  826.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  827.   
  828.   def process_input
  829.     if $game_message.choice?
  830.       input_choice
  831.     elsif $game_message.num_input?
  832.       input_number
  833.     elsif $game_message.item_choice?
  834.       input_item
  835.     else
  836.       input_pause unless @pause_skip
  837.     end
  838.   end
  839.   
  840.   def input_pause
  841.     show_pause
  842.     wait(10)
  843.     Fiber.yield until Input.trigger?(:B) || Input.trigger?(:C)
  844.     Input.update
  845.     hide_pause
  846.   end
  847.   
  848.   def input_choice
  849.     @choice_window.start
  850.     Fiber.yield while @choice_window.active
  851.   end
  852.   
  853.   def input_number
  854.     @number_window.start
  855.     Fiber.yield while @number_window.active
  856.   end
  857.   
  858.   def input_item
  859.     @item_window.start
  860.     Fiber.yield while @item_window.active
  861.   end
  862.   
  863.   
  864.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  865.   # * Other processing
  866.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  867.   
  868.   def close?
  869.     (self.opacity == 0)
  870.   end
  871.   
  872.   def all_close?
  873.     close? && @choice_window.close? && @number_window.close? && @item_window.close?
  874.   end
  875.   
  876.   def wait(duration)
  877.     duration.times { Fiber.yield }
  878.   end
  879.   
  880.   def reset_character_actor
  881.     @float = false
  882.     @actor = nil
  883.     @character = nil
  884.     if $game_map.interpreter.event_id && $game_map.events[$game_map.interpreter.event_id]
  885.       @character = $game_map.events[$game_map.interpreter.event_id]
  886.     end
  887.   end
  888.   
  889. end

  890. #-------------------------------------------------------------------------------
  891. # * Scene Map
  892. #-------------------------------------------------------------------------------

  893. class Scene_Map < Scene_Base
  894.   
  895.   include Message_Core
  896.   
  897.   def create_message_window
  898.     @khas_message = Sprite_Message.new
  899.   end
  900.   
  901.   def update_all_windows
  902.     @khas_message.update
  903.     super
  904.   end
  905.   
  906.   def dispose_all_windows
  907.     @khas_message.dispose
  908.     super
  909.   end
  910.   
  911. end

  912. #-------------------------------------------------------------------------------
  913. # * End
  914. #-------------------------------------------------------------------------------
复制代码
梦石
0
星屑
16296
在线时间
4017 小时
注册时间
2015-9-14
回帖
1322

开拓者

发表于 2019-2-12 14:09:51 | 显示全部楼层
原作者示例工程. Khas Message System.zip (1.39 MB, 下载次数: 124)
https://rpg.blue/data/attachment/album/202003/28/021323lltgrsvfytfwuya5.gif
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部