SYDONAY

Khas message with NON global font editing

Nov 4th, 2019
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 25.05 KB | None | 0 0
  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.  
  100. module Message_Core
  101.  
  102.   # ACTORS
  103.   # Declare your actors here, using the following format:
  104.   # "Actor Name" => ["color", "voice"]
  105.   # Actor Name: the actor name to be used with \a[Actor Name]
  106.   # color: the color name declared below
  107.   # voice: the voice file inside Audio/SE
  108.   Actors = {
  109.     "Eric" => ["blue", "male"],
  110.     "Natalie" => ["pink", "female"],
  111.     "Terence" => ["yellow", "male"],
  112.     "Ernest" => ["darkorange", "male"],
  113.     "Ryoma" => ["teal", "male"],
  114.     "Brenda" => ["gray", "female"],
  115.     "Miru" => ["pink", "female"],
  116.     "Rick" => ["green", "male"],
  117.     "Alice" => ["purple", "female"],
  118.     "Isabelle" => ["purple", "female"],
  119.     "Noah" => ["darkred", "male"],
  120.     "Old Man" => ["gray", "male"],
  121.     "Old Lady" => ["gray", "male"],
  122.     "Monster" => ["darkred", "male"],
  123.     "Boy" => ["blue", "male"],
  124.     "Girl" => ["pink", "female"],
  125.     "Lady" => ["purple", "female"],
  126.     "Man" => ["green", "male"],
  127.   }
  128.  
  129.   # COLORS
  130.   # Declare your colors here, using the following format:
  131.   # "colorname" => Color.new(R, G, B),
  132.   # The colorname can be used with \c[colorname]
  133.   Colors = {
  134.     "white" => Color.new(255, 255, 255),
  135.     "black" => Color.new(0, 0, 0),
  136.     "orange" => Color.new(255, 144, 9),
  137.     "blue" => Color.new(111, 147, 191),
  138.     "pink" => Color.new(189, 74, 99),
  139.     "yellow" => Color.new(222, 164, 86),
  140.     "darkorange" => Color.new(171, 86, 36),
  141.     "teal" => Color.new(39, 89, 97),
  142.     "darkred" => Color.new(171, 61, 86),
  143.     "purple" => Color.new(121, 83, 145),
  144.     "green" => Color.new(92, 154, 75),
  145.     "gray" => Color.new(135, 156, 176),
  146.     "darkgray" => Color.new(38, 38, 38),
  147.     "gold" => Color.new(255, 173, 20, 1),
  148.   }
  149.  
  150.   # MESSAGE BALLOON CONFIGURATION
  151.   # Background color
  152.   Background = Color.new(0,0,0,180)
  153.  
  154.   # Outline color
  155.   Outline = Color.new(255,255,255,120)
  156.  
  157.   # Minimum width
  158.   Minimum_Width = 80
  159.  
  160.  
  161.   # Message Font size by wyrelade
  162.   Font_Message_Size = 24
  163.  
  164.  
  165.   # Font properties GLOBAL
  166.   Font_Name = "Arial"
  167.   Font_Size = 18
  168.   Font_Bold = true
  169.   Font_Italic = false
  170.   Font_Outline = false
  171.  
  172.   # SE VOLUME
  173.   # Volume and pitch used to play voices
  174.   SE_Volume = 80
  175.  
  176.   # PAUSE CYCLE
  177.   # Number of frames to blink the cursor
  178.   Pause_Cycle = 30
  179.  
  180.   # Change these only if you're having trouble with your font
  181.   Standard_Padding = 4
  182.   New_Line_X = 4 + Standard_Padding
  183.   New_Page_Y = 3
  184.  
  185. end
  186.  
  187. #-------------------------------------------------------------------------------
  188. # * Default Font
  189. #-------------------------------------------------------------------------------
  190.  
  191. Font.default_name = [Message_Core::Font_Name]
  192. Font.default_size = Message_Core::Font_Size
  193. Font.default_bold = Message_Core::Font_Bold
  194. Font.default_outline = Message_Core::Font_Outline
  195. Font.default_italic = Message_Core::Font_Italic
  196.  
  197. #-------------------------------------------------------------------------------
  198. # * Sprite Message
  199. #-------------------------------------------------------------------------------
  200.  
  201. class Sprite_Message < Sprite
  202.  
  203.   include Message_Core
  204.  
  205.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  206.   # * Initialize (Executed once)
  207.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  208.  
  209.   def initialize
  210.     super(nil)
  211.     initialize_sprite
  212.     initialize_pause
  213.     create_all_windows
  214.     clear_instance_variables
  215.   end
  216.  
  217.   def initialize_sprite
  218.     self.bitmap = Bitmap.new(1,1)
  219.     self.opacity = 0
  220.     self.visible = false
  221.     self.z = 200
  222.   end
  223.  
  224.   def initialize_pause
  225.     @pause_sprite = Sprite.new
  226.     @pause_sprite.bitmap = Bitmap.new(3,3)
  227.     @pause_sprite.bitmap.fill_rect(0,0,3,3,Colors["white"])
  228.     @pause_sprite.visible = false
  229.     @pause_sprite.z = self.z + 1
  230.   end
  231.  
  232.   def create_all_windows
  233.     @gold_window = Window_Gold.new
  234.     @gold_window.x = Graphics.width - @gold_window.width
  235.     @gold_window.y = 0
  236.     @gold_window.openness = 0
  237.     @choice_window = Window_ChoiceList.new(self)
  238.     @number_window = Window_NumberInput.new(self)
  239.     @item_window = Window_KeyItem.new(self)
  240.   end
  241.  
  242.   def clear_instance_variables
  243.     @fiber = nil
  244.     @opening = false
  245.     @closing = false
  246.     @pause = false
  247.     clear_flags
  248.   end
  249.  
  250.  
  251.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  252.   # * Dispose (Executed once)
  253.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  254.  
  255.   def dispose
  256.     dispose_all_windows
  257.     dispose_pause
  258.     dispose_bitmap
  259.     super
  260.   end
  261.  
  262.   def dispose_all_windows
  263.     @gold_window.dispose
  264.     @choice_window.dispose
  265.     @number_window.dispose
  266.     @item_window.dispose
  267.   end
  268.  
  269.   def dispose_bitmap
  270.     self.bitmap.dispose if self.bitmap
  271.   end
  272.  
  273.   def dispose_pause
  274.     @pause_sprite.bitmap.dispose
  275.     @pause_sprite.dispose
  276.   end
  277.  
  278.  
  279.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  280.   # * Update
  281.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  282.  
  283.   def update
  284.     update_effects
  285.     update_all_windows
  286.     update_fiber
  287.   end
  288.  
  289.   def update_effects
  290.     update_open if @opening
  291.     update_close if @closing
  292.     update_pause if @pause
  293.     update_shake if @shake > 0
  294.   end
  295.  
  296.   def update_all_windows
  297.     @gold_window.update
  298.     @choice_window.update
  299.     @number_window.update
  300.     @item_window.update
  301.   end
  302.  
  303.   def update_fiber
  304.     if @fiber
  305.       @fiber.resume
  306.     elsif $game_message.busy? && !$game_message.scroll_mode
  307.       @fiber = Fiber.new { fiber_main }
  308.       @fiber.resume
  309.     else
  310.       $game_message.visible = false
  311.     end
  312.   end
  313.  
  314.   def update_open
  315.     self.opacity += 32
  316.     @opening = (self.opacity < 255)
  317.   end
  318.  
  319.   def update_close
  320.     self.opacity -= 32
  321.     @closing = (self.opacity > 0)
  322.   end
  323.  
  324.   def update_pause
  325.     if @pause_timer > 0
  326.       @pause_timer -= 1
  327.     else
  328.       @pause_sprite.visible = !@pause_sprite.visible
  329.       @pause_timer = Pause_Cycle
  330.     end
  331.   end
  332.  
  333.   def update_shake
  334.     if @shake > 1
  335.       self.ox = rand(17) - 8
  336.       self.oy = rand(17) - 8
  337.       @shake -= 1
  338.     else
  339.       stop_shake
  340.     end
  341.   end
  342.  
  343.  
  344.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  345.   # * Effect Control
  346.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  347.  
  348.   def open_and_wait
  349.     @opening = true
  350.     Fiber.yield while @opening
  351.   end
  352.  
  353.   def close_and_wait
  354.     @closing = true
  355.     Fiber.yield until all_close?
  356.   end
  357.  
  358.   def show_pause
  359.     @pause_sprite.visible = true
  360.     @pause = true
  361.     @pause_timer = Pause_Cycle
  362.   end
  363.  
  364.   def hide_pause
  365.     @pause_sprite.visible = false
  366.     @pause = false
  367.   end
  368.  
  369.   def shake(duration)
  370.     @shake = duration
  371.   end
  372.  
  373.   def stop_shake
  374.     self.ox = 0
  375.     self.oy = 0
  376.     @shake = 0
  377.   end
  378.  
  379.  
  380.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  381.   # * Main Processing
  382.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  383.  
  384.   def fiber_main
  385.     $game_message.visible = true
  386.     self.visible = true
  387.     loop do
  388.       process_all_text if $game_message.has_text?
  389.       process_input
  390.       $game_message.clear
  391.       @gold_window.close
  392.       Fiber.yield
  393.       break unless text_continue?
  394.     end
  395.     close_and_wait
  396.     clear_balloon
  397.     self.visible = false
  398.     $game_message.visible = false
  399.     @fiber = nil
  400.   end
  401.  
  402.  
  403.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  404.   # * Drawing processes
  405.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  406.  
  407.   def draw_balloon
  408.     # Reset stuff for new balloon
  409.     reset_font_settings
  410.     reset_character_actor
  411.    
  412.     # Process text
  413.     text = convert_escape_characters($game_message.all_text)
  414.     scan_special_commands(text)
  415.     text = remove_escape_characters(text)
  416.    
  417.     # Should the balloon float?
  418.     @float = true if @character.nil?
  419.    
  420.     # Check if the balloon will have a namebox
  421.     @namebox_yplus = (@actor ? text_size(@actor).height : 0)
  422.     @voice = (@actor ? Actors[@actor][1] : nil)
  423.    
  424.     # Check if the balloon will have a detail
  425.     @detail_yplus = (@float ? 0 : 10)
  426.    
  427.     # Calculate text dimensions
  428.     tw = fitting_width(text)
  429.     th = fitting_height(text) + @namebox_yplus + @detail_yplus
  430.    
  431.     # Check if the balloon needs to be inverted
  432.     if invert_balloon?(th)
  433.       @inverted = true
  434.       @margin_top = @detail_yplus
  435.       @margin_bottom = @namebox_yplus
  436.     else
  437.       @inverted = false
  438.       @margin_top = @namebox_yplus
  439.       @margin_bottom = @detail_yplus
  440.     end
  441.    
  442.     # Calculate balloon dimensions
  443.     balloon = Rect.new
  444.     balloon.x = 0
  445.     balloon.y = @margin_top
  446.     balloon.width = tw > Minimum_Width ? tw : Minimum_Width
  447.     balloon.height = th - @margin_top - @margin_bottom
  448.    
  449.     # Create a new bitmap
  450.     self.bitmap.dispose if self.bitmap
  451.     self.bitmap = Bitmap.new(balloon.width, th)
  452.     reset_font_settings
  453.    
  454.     # Draw the balloon
  455.     self.bitmap.fill_rect(balloon.x, balloon.y, balloon.width, balloon.height, Outline)
  456.     self.bitmap.fill_rect(balloon.x+1, balloon.y+1, balloon.width-2, balloon.height-2, Background)
  457.    
  458.     # Draw the namebox
  459.     draw_namebox(@inverted ? (th - @namebox_yplus - 2) : 0) if @actor
  460.   end
  461.  
  462.   def clear_balloon
  463.     self.bitmap.clear
  464.   end
  465.  
  466.   def draw_namebox(y)
  467.     rect = text_size(@actor)
  468.     color = Colors[Actors[@actor][0]]
  469.     color.alpha = Background.alpha
  470.     self.bitmap.fill_rect(4,y,rect.width+10,rect.height+2,Outline)
  471.     self.bitmap.fill_rect(5,y+1,rect.width+8,rect.height,color)
  472.     self.bitmap.draw_text(9,y+1,rect.width,rect.height,@actor)
  473.   end
  474.  
  475.   def draw_detail(x, y, reverse, upside_down)
  476.     dx = (reverse ? 1 : 0)
  477.     dy = (upside_down ? -1 : 1)
  478.     x -= 12 if reverse
  479.     for i in 12.downto(2)
  480.       fill_line(x, y, i)
  481.       x += dx
  482.       y += dy
  483.     end
  484.   end
  485.  
  486.   def fill_rect(x, y, sx, sy)
  487.     self.bitmap.fill_rect(x, y, sx, sy, Outline)
  488.     self.bitmap.fill_rect(x+1, y+1, sx-2, sy-2, Background)
  489.   end
  490.  
  491.   def fill_line(x, y, sx)
  492.     self.bitmap.fill_rect(x, y, sx, 1, Outline)
  493.     self.bitmap.fill_rect(x+1, y, sx-2, 1, Background)
  494.   end
  495.  
  496.  
  497.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  498.   # * Size/Position processing
  499.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  500.  
  501.   def move_balloon
  502.     if @float
  503.       x = (Graphics.width - width)/2
  504.       y = Graphics.height - height - self.bitmap.font.size
  505.     else
  506.       # Get the actual character and its height
  507.       bitmap = Cache.character(@character.character_name)
  508.       sign = @character.character_name[/^[\!\$]./]
  509.       if sign && sign.include?('$')
  510.         cw = bitmap.width / 6
  511.         ch = bitmap.height / 4
  512.       else
  513.         cw = bitmap.width / 24
  514.         ch = bitmap.height / 8
  515.       end
  516.      
  517.       # Calc initial position
  518.       x = @character.screen_x - width / 2
  519.       y = @character.screen_y - height - ch
  520.  
  521.       # Check if the ballon is out of the screen
  522.       x = 2 if x < 2
  523.       x = Graphics.width - width - 2 if (x + width) > (Graphics.width - 2)
  524.       y = @character.screen_y if y < 0
  525.      
  526.       # Draw the detail
  527.       reverse = @character.direction < 5
  528.       sx = @character.screen_x - x + (reverse ? -cw : cw)
  529.       if sx < 0
  530.         reverse = !reverse
  531.         sx = @character.screen_x - x + (reverse ? -cw : cw)
  532.       elsif sx > self.bitmap.width
  533.         reverse = !reverse
  534.         sx = @character.screen_x - x + (reverse ? -cw : cw)
  535.       end
  536.       sy = (@inverted ? @margin_top : (self.bitmap.height - @margin_bottom - 1))
  537.       draw_detail(sx, sy, reverse, @inverted)
  538.     end
  539.    
  540.     # Set the position
  541.     self.x = x
  542.     self.y = y
  543.    
  544.     # Set the pause sprite position
  545.     @pause_sprite.x = self.x + self.width - 6
  546.     @pause_sprite.y = self.y + self.height - @margin_bottom - 6
  547.   end
  548.  
  549.   def invert_balloon?(h)
  550.     return false if @float
  551.     bitmap = Cache.character(@character.character_name)
  552.     sign = @character.character_name[/^[\!\$]./]
  553.     char_height = bitmap.height / (sign && sign.include?('$') ? 4 : 8)
  554.     @character.screen_y - h - char_height < 0
  555.   end
  556.  
  557.   def width
  558.     self.bitmap ? self.bitmap.width : 1
  559.   end
  560.  
  561.   def height
  562.     self.bitmap ? self.bitmap.height : 1
  563.   end
  564.  
  565.   def text_width(text)
  566.     result = 0
  567.     text.each_line do |line|
  568.       lw = text_size(line).width
  569.       result = lw if lw > result
  570.     end
  571.     result
  572.   end
  573.  
  574.   def text_height(text)
  575.     result = 0
  576.     text.each_line do |line|
  577.       result += line_height(line)
  578.     end
  579.     result
  580.   end
  581.  
  582.   def line_height(text)
  583.     result = self.bitmap.font.size
  584.     last_font_size = self.bitmap.font.size
  585.     text.slice(/^.*$/).scan(/\e[\{\}]/).each do |esc|
  586.       make_font_bigger  if esc == "\e{"
  587.       make_font_smaller if esc == "\e}"
  588.       result = [result, self.bitmap.font.size].max
  589.     end
  590.     self.bitmap.font.size = last_font_size
  591.     result
  592.   end
  593.  
  594.   def fitting_height(text)
  595.     text_height(text) + Standard_Padding * 2
  596.   end
  597.  
  598.   def fitting_width(text)
  599.     text_width(text) + Standard_Padding * 2
  600.   end
  601.  
  602.  
  603.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  604.   # * Text processing
  605.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  606.  
  607.   def process_all_text
  608.     text = convert_escape_characters($game_message.all_text)
  609.     pos = {}
  610.     new_page(text, pos)
  611.     until text.empty?
  612.       Fiber.yield if @skip_frame
  613.       @skip_frame = !@skip_frame
  614.       process_character(text.slice!(0, 1), text, pos)
  615.     end
  616.   end
  617.  
  618.   def new_page(text, pos)
  619.     draw_balloon
  620.     move_balloon
  621.     open_and_wait if self.opacity < 255
  622.     pos[:x] = New_Line_X
  623.     pos[:y] = New_Page_Y + @margin_top
  624.     pos[:new_x] = New_Line_X
  625.     pos[:height] = line_height(text)
  626.     clear_flags
  627.   end
  628.  
  629.   def clear_flags
  630.     @show_fast = false
  631.     @pause_skip = false
  632.     @skip_frame = false
  633.     @sound = true
  634.     @shake = 0
  635.   end
  636.  
  637.   def text_continue?
  638.     $game_message.has_text?
  639.   end
  640.  
  641.   def update_show_fast
  642.     @show_fast = true if Input.trigger?(:C)
  643.   end
  644.  
  645.   def wait_for_one_character
  646.     update_show_fast
  647.     Fiber.yield unless @show_fast
  648.   end
  649.  
  650.   def need_new_page?(text, pos)
  651.     pos[:y] + pos[:height] > self.bitmap.height && !text.empty?
  652.   end
  653.  
  654.   def process_new_page(text, pos)
  655.     text.slice!(/^\n/)
  656.     input_pause
  657.     new_page(text, pos)
  658.   end
  659.  
  660.   def process_draw_icon(icon_index, pos)
  661.     bitmap = Cache.system("Iconset")
  662.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  663.     self.bitmap.blt(pos[:x], pos[:y], bitmap, rect)
  664.     pos[:x] += 24
  665.     wait_for_one_character
  666.   end
  667.  
  668.   def process_escape_character(code, text, pos)
  669.     case code.upcase
  670.     when '$'
  671.       @gold_window.open
  672.     when '.'
  673.       wait(15)
  674.     when '|'
  675.       wait(60)
  676.     when '!'
  677.       input_pause
  678.     when '>'
  679.       @show_fast = true
  680.     when '<'
  681.       @show_fast = false
  682.     when '^'
  683.       @pause_skip = true
  684.     when 'C'
  685.       change_color(text.slice!(/^\[#?\w+\]/)[/#?\w+/])
  686.     when 'I'
  687.       process_draw_icon(text.slice!(/^\[\d+\]/)[/\d+/].to_i, pos)
  688.     when '{'
  689.       make_font_bigger
  690.     when '}'
  691.       make_font_smaller
  692.     when 'A'
  693.       text.slice!(/^\[[\w\s]+\]/)
  694.     when 'S'
  695.       shake(text.slice!(/^\[\d+\]/)[/\d+/].to_i)
  696.     when 'E'
  697.       text.slice!(/^\[\d+\]/)
  698.     when 'T'
  699.       @voice = text.slice!(/^\[\w*\]/)[/\w*/]
  700.       @voice = nil unless @voice.size > 0
  701.     when 'X'
  702.       Audio.se_play("Audio/se/#{text.slice!(/^\[\w+\]/)[/\w+/]}", SE_Volume)
  703.     end
  704.   end
  705.  
  706.   def actor_name(n)
  707.     actor = n >= 1 ? $game_actors[n] : nil
  708.     actor ? actor.name : ""
  709.   end
  710.  
  711.   def party_member_name(n)
  712.     actor = n >= 1 ? $game_party.members[n - 1] : nil
  713.     actor ? actor.name : ""
  714.   end
  715.  
  716.   def convert_escape_characters(text)
  717.     result = text.to_s.clone
  718.     result.gsub!(/\\/)            { "\e" }
  719.     result.gsub!(/\e\e/)          { "\\" }
  720.     result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
  721.     result.gsub!(/\eV\[(\d+)\]/i) { $game_variables[$1.to_i] }
  722.     result.gsub!(/\eN\[(\d+)\]/i) { actor_name($1.to_i) }
  723.     result.gsub!(/\eP\[(\d+)\]/i) { party_member_name($1.to_i) }
  724.     result.gsub!(/\eG/i)          { Vocab::currency_unit }
  725.     result
  726.   end
  727.  
  728.   def remove_escape_characters(text)
  729.     result = text.to_s.clone
  730.     result.gsub!(/\ec\[#?\w+\]/i,"")
  731.     result.gsub!(/\es\[\d+\]/i,"")
  732.     result.gsub!(/\ee\[\d+\]/i,"")
  733.     result.gsub!(/\ea\[[\w\s]+\]/i,"")
  734.     result.gsub!(/\et\[\w*\]/i,"")
  735.     result.gsub!(/\ex\[\w+\]/i,"")
  736.     result.gsub!(/\ep/i, "")
  737.     result.gsub!(/\ef/i, "")
  738.     result.gsub!(/\e\|/, "")
  739.     result.gsub!(/\e\./, "")
  740.     result.gsub!(/\e\</, "")
  741.     result.gsub!(/\e\>/, "")
  742.     result.gsub!(/\e\^/, "")
  743.     result
  744.   end
  745.  
  746.   def scan_special_commands(text)
  747.     if text =~ /\ep/i
  748.       @character = $game_player
  749.     end
  750.    
  751.     if text =~ /\ef/i
  752.       @float = true
  753.     end
  754.    
  755.     if text =~ /\ea\[([\w\s]+)\]/i
  756.       @actor = $1 if Actors[$1]
  757.     end
  758.    
  759.     if text =~ /\ee\[(\d+)\]/i
  760.       @character = $game_map.events[$1.to_i] if $game_map.events[$1.to_i]
  761.     end
  762.    
  763.   end
  764.  
  765.   def text_size(str)
  766.     self.bitmap.text_size(str)
  767.   end
  768.  
  769.  
  770.  
  771.   def process_character(c, text, pos)
  772.     case c
  773.     when "\n"   # New line
  774.       process_new_line(text, pos)
  775.     when "\f"   # New page
  776.       process_new_page(text, pos)
  777.     when "\e"   # Control character
  778.       process_escape_character(obtain_escape_code(text), text, pos)
  779.     else        # Normal character
  780.       process_normal_character(c, pos)
  781.     end
  782.   end
  783.  
  784.   def process_normal_character(c, pos)
  785.     char_width = text_size(c).width
  786.     self.bitmap.draw_text(pos[:x], pos[:y], char_width * 2, pos[:height], c)
  787.     pos[:x] += char_width
  788.     Audio.se_play("Audio/se/#{@voice}", SE_Volume, (100..100).to_a.sample) if @sound && c != " " && @voice
  789.     @sound = !@sound
  790.    
  791.     wait_for_one_character
  792.   end
  793.  
  794.  
  795.   def process_new_line(text, pos)
  796.     pos[:x] = pos[:new_x]
  797.     pos[:y] += pos[:height]
  798.     pos[:height] = line_height(text)
  799.     if need_new_page?(text, pos)
  800.       input_pause
  801.       new_page(text, pos)
  802.     end
  803.   end
  804.  
  805.   def obtain_escape_code(text)
  806.     text.slice!(/^[\$\.\|\^!><\{\}\\]|^[A-Z]/i)
  807.   end
  808.  
  809.  
  810.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  811.   # * Font
  812.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  813.  
  814.   def reset_font_settings
  815.     change_color("white")
  816.     self.bitmap.font.size = Font_Message_Size
  817.     self.bitmap.font.bold = Font.default_bold
  818.     self.bitmap.font.italic = Font.default_italic
  819.   end
  820.  
  821.   def change_color(code)
  822.     if Colors[code]
  823.       self.bitmap.font.color.set(Colors[code])
  824.     elsif code =~ /#(..)(..)(..)/
  825.       self.bitmap.font.color.set(Color.new($1.hex, $2.hex, $3.hex))
  826.     end
  827.   end
  828.  
  829.   def make_font_bigger
  830.     self.bitmap.font.size += 8 if self.bitmap.font.size <= 64
  831.   end
  832.  
  833.   def make_font_smaller
  834.     self.bitmap.font.size -= 8 if self.bitmap.font.size >= 16
  835.   end
  836.  
  837.  
  838.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  839.   # * Input processing
  840.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  841.  
  842.   def process_input
  843.     if $game_message.choice?
  844.       input_choice
  845.     elsif $game_message.num_input?
  846.       input_number
  847.     elsif $game_message.item_choice?
  848.       input_item
  849.     else
  850.       input_pause unless @pause_skip
  851.     end
  852.   end
  853.  
  854.   def input_pause
  855.     show_pause
  856.     wait(10)
  857.     Fiber.yield until Input.trigger?(:B) || Input.trigger?(:C)
  858.     Input.update
  859.     hide_pause
  860.   end
  861.  
  862.   def input_choice
  863.     @choice_window.start
  864.     Fiber.yield while @choice_window.active
  865.   end
  866.  
  867.   def input_number
  868.     @number_window.start
  869.     Fiber.yield while @number_window.active
  870.   end
  871.  
  872.   def input_item
  873.     @item_window.start
  874.     Fiber.yield while @item_window.active
  875.   end
  876.  
  877.  
  878.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  879.   # * Other processing
  880.   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  881.  
  882.   def close?
  883.     (self.opacity == 0)
  884.   end
  885.  
  886.   def all_close?
  887.     close? && @choice_window.close? && @number_window.close? && @item_window.close?
  888.   end
  889.  
  890.   def wait(duration)
  891.     duration.times { Fiber.yield }
  892.   end
  893.  
  894.   def reset_character_actor
  895.     @float = false
  896.     @actor = nil
  897.     @character = nil
  898.     if $game_map.interpreter.event_id && $game_map.events[$game_map.interpreter.event_id]
  899.       @character = $game_map.events[$game_map.interpreter.event_id]
  900.     end
  901.   end
  902.  
  903. end
  904.  
  905. #-------------------------------------------------------------------------------
  906. # * Scene Map
  907. #-------------------------------------------------------------------------------
  908.  
  909. class Scene_Map < Scene_Base
  910.  
  911.   include Message_Core
  912.  
  913.   def create_message_window
  914.     @khas_message = Sprite_Message.new
  915.   end
  916.  
  917.   def update_all_windows
  918.     @khas_message.update
  919.     super
  920.   end
  921.  
  922.   def dispose_all_windows
  923.     @khas_message.dispose
  924.     super
  925.   end
  926.  
  927. end
  928.  
  929. #-------------------------------------------------------------------------------
  930. # * End
  931. #-------------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment