Advertisement
Guest User

Untitled

a guest
Jan 1st, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 16.75 KB | None | 0 0
  1. #==============================================================================
  2. #
  3. # ¥ Yami Engine Symphony - Pop Message
  4. # -- Last Updated: 2013.01.29
  5. # -- Level: Easy
  6. # -- Requires: n/a
  7. #
  8. #==============================================================================
  9.  
  10. $imported = {} if $imported.nil?
  11. $imported["YES-PopMessage"] = true
  12.  
  13. #==============================================================================
  14. # ¥ Updates
  15. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  16. # 2013.01.29 - Compatible with: YEA - Ace Message System Namebox.
  17. # 2013.01.29 - Fixed a minor crash with Bubble Tag.
  18. # 2013.01.28 - Finished Script.
  19. # 2013.01.25 - Started Script.
  20. #
  21. #==============================================================================
  22. # ¥ Introduction
  23. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  24. # This script provides bubble messages feature, which makes message window pop
  25. # over player's or event's head.
  26. #
  27. #==============================================================================
  28. # ¥ Instructions
  29. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  30. # To install this script, open up your script editor and copy/paste this script
  31. # to an open slot below ¥ Materials/‘fÞ but above ¥ Main. Remember to save.
  32. #
  33. # -----------------------------------------------------------------------------
  34. # Message Window text Codes - These go inside of your message window.
  35. # -----------------------------------------------------------------------------
  36. #  Code:       Effect:
  37. #    \bm[x]     - Pops message on event ID x head.
  38. #                 Set x to 0 for player pop.
  39. #    \cbm       - Cancel pops message manually.
  40. #    \cbt[name] - Set bubble tag filename to name.
  41. #
  42. #==============================================================================
  43. # ¥ Compatibility
  44. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  45. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  46. # it will run with RPG Maker VX without adjustments.
  47. #
  48. #==============================================================================
  49.  
  50. #==============================================================================
  51. # ¡ Configuration
  52. #==============================================================================
  53.  
  54. module YES
  55.   module POP_MESSAGE
  56.    
  57.     #===========================================================================
  58.     # - Limit Settings -
  59.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  60.     # The following below will adjust the limit options for pop message.
  61.     #===========================================================================
  62.     LIMIT_SETTING = { # Start.
  63.       :width            =>  0, # Set to 0 to disable limitation.
  64.       :lines            =>  0, # Set to 0 to disable limitation.
  65.     } # End.
  66.    
  67.     #===========================================================================
  68.     # - Effect Settings -
  69.     #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  70.     # The following below will adjust the effect options for pop message.
  71.     #===========================================================================
  72.     EFFECT_SETTING = { # Start.
  73.       :default_face     =>  false,# Use default face draw.
  74.       # Effects for non-default face draw.
  75.       :face_fade        =>  true, # Makes face to be fading when start message.
  76.       :face_move        =>  true, # Makes face to be moving in when start message.
  77.       # Bubble tag settings.
  78.       :bubble_tag       =>  true, # Enables bubble tag for pop message.
  79.       :bubble_name      =>  "BubbleTag", # Put bubble tag image into
  80.                                          # Graphics/System
  81.       :bubble_offset_y  =>  -6,
  82.     } # End.
  83.    
  84.   end
  85. end
  86.  
  87. #==============================================================================
  88. # ¥ Editting anything past this point may potentially result in causing
  89. # computer damage, incontinence, explosion of user's head, coma, death, and/or
  90. # halitosis so edit at your own risk.
  91. #==============================================================================
  92.  
  93. #==============================================================================
  94. # ¡ Window_MessageFace
  95. #==============================================================================
  96.  
  97. class Window_MessageFace < Window_Base
  98.  
  99.   #--------------------------------------------------------------------------
  100.   # initialize
  101.   #--------------------------------------------------------------------------
  102.   def initialize
  103.     super(0, 0, 120, 120)
  104.     self.opacity = 0
  105.     self.contents_opacity = 0
  106.     self.close
  107.     @move_x = 0
  108.   end
  109.  
  110.   #--------------------------------------------------------------------------
  111.   # draw_content_face
  112.   #--------------------------------------------------------------------------
  113.   def draw_content_face
  114.     if $game_message.face_name.empty?
  115.       hide_face
  116.     else
  117.       self.y = - self.height
  118.       contents.clear
  119.       draw_face($game_message.face_name, $game_message.face_index, 0, 0)
  120.     end
  121.   end
  122.  
  123.   #--------------------------------------------------------------------------
  124.   # fade_time
  125.   #--------------------------------------------------------------------------
  126.   def fade_time
  127.     17
  128.   end
  129.  
  130.   #--------------------------------------------------------------------------
  131.   # move_time
  132.   #--------------------------------------------------------------------------
  133.   def move_time
  134.     17
  135.   end
  136.  
  137.   #--------------------------------------------------------------------------
  138.   # move_rate
  139.   #--------------------------------------------------------------------------
  140.   def move_rate
  141.     2
  142.   end
  143.  
  144.   #--------------------------------------------------------------------------
  145.   # show_face
  146.   #--------------------------------------------------------------------------
  147.   def show_face
  148.     return if $game_message.face_name.empty?
  149.     self.open
  150.     #---
  151.     if (YES::POP_MESSAGE::EFFECT_SETTING[:face_fade] ||
  152.         YES::POP_MESSAGE::EFFECT_SETTING[:face_move])
  153.         self.openness = 255
  154.     end
  155.     #---
  156.     if YES::POP_MESSAGE::EFFECT_SETTING[:face_fade]
  157.       self.contents_opacity = 0
  158.     else
  159.       self.contents_opacity = 255
  160.     end
  161.     #---
  162.     if YES::POP_MESSAGE::EFFECT_SETTING[:face_move]
  163.       @move_x = move_time * move_rate
  164.       self.x -= @move_x
  165.     end
  166.   end
  167.  
  168.   #--------------------------------------------------------------------------
  169.   # hide_face
  170.   #--------------------------------------------------------------------------
  171.   def hide_face
  172.     close
  173.   end
  174.  
  175.   #--------------------------------------------------------------------------
  176.   # update
  177.   #--------------------------------------------------------------------------
  178.   def update
  179.     super
  180.     #---
  181.     self.contents_opacity += 255.0 / fade_time
  182.     #---
  183.     if @move_x > 0
  184.       rate = [move_rate, @move_x].min
  185.       @move_x -= rate
  186.       self.x += rate      
  187.     end
  188.   end
  189.  
  190. end # Window_MessageFace
  191.  
  192. #==============================================================================
  193. # ¡ Window_Message
  194. #==============================================================================
  195.  
  196. class Window_Message < Window_Base
  197.  
  198.   #--------------------------------------------------------------------------
  199.   # new method: pop_message_initialize
  200.   #--------------------------------------------------------------------------
  201.   def pop_message_initialize(text)
  202.     if text =~ /\\BM\[(\d+)\]/i
  203.       setup_pop_message($1.to_i)
  204.     end
  205.     if text =~ /\\CBM/i
  206.       cancel_pop_message
  207.     end
  208.     if text =~ /\\CBT\[(.*)\]/i
  209.       create_bubble_sprite($1)
  210.       @bubble_sprite.opacity = 255
  211.     end
  212.   end
  213.  
  214.   #--------------------------------------------------------------------------
  215.   # new method: process_pop_message
  216.   #--------------------------------------------------------------------------
  217.   def process_pop_message(text)
  218.     text.gsub!(/\eCBT\[(.*)\]/i) { "" }
  219.     text.gsub!(/\eBM\[(\d+)\]/i) { "" }
  220.     text.gsub!(/\eCBM/i) { "" }
  221.     text
  222.   end
  223.  
  224.   #--------------------------------------------------------------------------
  225.   # alias method: convert_escape_characters
  226.   #--------------------------------------------------------------------------
  227.   alias yes_pm_convert_escape_characters convert_escape_characters
  228.   def convert_escape_characters(text)
  229.     result = yes_pm_convert_escape_characters(text)
  230.     result = process_pop_message(result)
  231.     result
  232.   end
  233.  
  234.   #--------------------------------------------------------------------------
  235.   # new method: setup_pop_message
  236.   #--------------------------------------------------------------------------
  237.   def setup_pop_message(id)
  238.     create_bubble_sprite
  239.     adjust_window_size
  240.     adjust_window_position(id)
  241.     @bubble_sprite.opacity = 255
  242.   end
  243.  
  244.   #--------------------------------------------------------------------------
  245.   # new method: create_bubble_sprite
  246.   #--------------------------------------------------------------------------
  247.   def create_bubble_sprite(filename = nil)
  248.     return unless YES::POP_MESSAGE::EFFECT_SETTING[:bubble_tag]
  249.     filename = YES::POP_MESSAGE::EFFECT_SETTING[:bubble_name] unless filename
  250.     bitmap = Cache.system(filename)
  251.     @bubble_sprite ||= Sprite.new
  252.     @bubble_sprite.z = self.z
  253.     @bubble_sprite.opacity = 0
  254.     @bubble_sprite.bitmap = bitmap
  255.     @bubble_sprite.src_rect.set(0, 0, bitmap.width, bitmap.height / 2)
  256.   end
  257.  
  258.   #--------------------------------------------------------------------------
  259.   # new method: adjust_window_position
  260.   #--------------------------------------------------------------------------
  261.   def adjust_window_position(id)
  262.     hash = $game_map.events
  263.     character = id <= 0 ? $game_player : hash[id]
  264.     #---
  265.     bitmap = Cache.character(character.character_name)
  266.     sign = character.character_name[/^[\!\$]./]
  267.     if sign && sign.include?('$')
  268.       ch = bitmap.height / 4
  269.     else
  270.       ch = bitmap.height / 8
  271.     end
  272.     #---
  273.     self.x = character.screen_x - self.width / 2
  274.     self.y = character.screen_y - self.height - ch
  275.     if @bubble_sprite
  276.       @bubble_sprite.x = character.screen_x - @bubble_sprite.width / 2
  277.       @bubble_sprite.y = self.y + self.height
  278.       @bubble_sprite.y += YES::POP_MESSAGE::EFFECT_SETTING[:bubble_offset_y]
  279.     end
  280.     #---
  281.     end_x = self.x + self.width
  282.     self.x = 0 if self.x < 0
  283.     self.x = Graphics.width - self.width if end_x > Graphics.width
  284.     if self.y < 0
  285.       self.y = character.screen_y
  286.       if @bubble_sprite
  287.         @bubble_sprite.y = self.y - @bubble_sprite.height
  288.         @bubble_sprite.y -= YES::POP_MESSAGE::EFFECT_SETTING[:bubble_offset_y]
  289.         @bubble_sprite.src_rect.set(0, @bubble_sprite.height,
  290.                                     @bubble_sprite.width, @bubble_sprite.height)
  291.       end
  292.     end
  293.   end
  294.  
  295.   #--------------------------------------------------------------------------
  296.   # new method: adjust_window_size
  297.   #--------------------------------------------------------------------------
  298.   def adjust_window_size
  299.     text = convert_escape_characters($game_message.all_text)
  300.     #---
  301.     width = cal_width_line(text) + standard_padding * 2
  302.     width = width + new_line_x
  303.     if YES::POP_MESSAGE::LIMIT_SETTING[:width] > 0
  304.       width = [YES::POP_MESSAGE::LIMIT_SETTING[:width], width]
  305.     end
  306.     #---
  307.     lines = cal_number_line(text)
  308.     if YES::POP_MESSAGE::LIMIT_SETTING[:lines] > 0
  309.       lines = [YES::POP_MESSAGE::LIMIT_SETTING[:lines], lines].min
  310.     end
  311.     if YES::POP_MESSAGE::EFFECT_SETTING[:default_face]
  312.       unless $game_message.face_name.empty?
  313.         lines = [4, lines].max
  314.       end
  315.     end
  316.     #---
  317.     self.width = width
  318.     self.height = fitting_height(lines)
  319.     create_contents
  320.   end
  321.    
  322.   #--------------------------------------------------------------------------
  323.   # new method: cal_number_line
  324.   #--------------------------------------------------------------------------
  325.   def cal_number_line(text)
  326.     result = 0
  327.     text.each_line { result += 1 }
  328.     return result
  329.   end
  330.  
  331.   #--------------------------------------------------------------------------
  332.   # new method: cal_width_line
  333.   #--------------------------------------------------------------------------
  334.   def cal_width_line(text)
  335.     result = 0
  336.     text.each_line { |line|
  337.       result = text_size(line).width if result < text_size(line).width
  338.     }
  339.     return result
  340.   end
  341.  
  342.   #--------------------------------------------------------------------------
  343.   # new method: cancel_pop_message
  344.   #--------------------------------------------------------------------------
  345.   def cancel_pop_message
  346.     update_placement
  347.     reset_size
  348.     create_bubble_sprite
  349.   end
  350.  
  351.   #--------------------------------------------------------------------------
  352.   # new method: reset_size
  353.   #--------------------------------------------------------------------------
  354.   def reset_size
  355.     self.width = window_width
  356.     self.height = window_height
  357.     update_padding
  358.     create_contents
  359.   end
  360.  
  361.   #--------------------------------------------------------------------------
  362.   # alias method: draw_face
  363.   #--------------------------------------------------------------------------
  364.   alias yes_pop_message_draw_face draw_face
  365.   def draw_face(face_name, face_index, x, y, enabled = true)
  366.     return unless YES::POP_MESSAGE::EFFECT_SETTING[:default_face]
  367.     yes_pop_message_draw_face(face_name, face_index, x, y, enabled)
  368.   end
  369.  
  370.   #--------------------------------------------------------------------------
  371.   # alias method: update_placement
  372.   #--------------------------------------------------------------------------
  373.   alias yes_pop_message_update_placement update_placement
  374.   def update_placement
  375.     yes_pop_message_update_placement
  376.     self.x = 0
  377.   end
  378.  
  379.   #--------------------------------------------------------------------------
  380.   # alias method: process_all_text
  381.   #--------------------------------------------------------------------------
  382.   alias yes_pop_message_process_all_text process_all_text
  383.   def process_all_text
  384.     pop_message_initialize($game_message.all_text)
  385.     yes_pop_message_process_all_text
  386.   end
  387.  
  388.   #--------------------------------------------------------------------------
  389.   # alias method: open_and_wait
  390.   #--------------------------------------------------------------------------
  391.   alias yes_pop_message_open_and_wait open_and_wait
  392.   def open_and_wait
  393.     yes_pop_message_open_and_wait
  394.     @face_window ||= Window_MessageFace.new
  395.     @face_window.draw_content_face
  396.     @face_window.x = self.x + 8
  397.     @face_window.y += self.y + self.height
  398.     @face_window.show_face
  399.   end
  400.  
  401.   #--------------------------------------------------------------------------
  402.   # alias method: close_and_wait
  403.   #--------------------------------------------------------------------------
  404.   alias yes_pop_message_close_and_wait close_and_wait
  405.   def close_and_wait
  406.     @face_window.hide_face
  407.     @bubble_sprite.opacity = 0 if @bubble_sprite
  408.     yes_pop_message_close_and_wait
  409.     cancel_pop_message
  410.   end
  411.  
  412.   #--------------------------------------------------------------------------
  413.   # alias method: update
  414.   #--------------------------------------------------------------------------
  415.   alias yes_pop_message_update update
  416.   def update
  417.     yes_pop_message_update
  418.     if @face_window
  419.       @face_window.update
  420.       @face_window.z = self.z
  421.     end
  422.     if @bubble_sprite
  423.       @bubble_sprite.update
  424.       @bubble_sprite.z = self.z
  425.     end
  426.   end
  427.  
  428.   #--------------------------------------------------------------------------
  429.   # overwrite method: adjust_message_window_size
  430.   # YEA - Message System Compatible
  431.   #--------------------------------------------------------------------------
  432.   def adjust_message_window_size
  433.     start_name_window
  434.   end
  435.  
  436. end # Window_Message
  437.  
  438. #==============================================================================
  439. # ¡ Window_NameMessage
  440. #==============================================================================
  441. if $imported["YEA-MessageSystem"]
  442. class Window_NameMessage < Window_Base
  443.  
  444.   #--------------------------------------------------------------------------
  445.   # set_x_position
  446.   #--------------------------------------------------------------------------
  447.   alias yes_pm_set_x_position set_x_position
  448.   def set_x_position(x_position)
  449.     yes_pm_set_x_position(x_position)
  450.     self.x += @message_window.new_line_x if x_position == 1
  451.     self.z = @message_window.z
  452.   end
  453.  
  454. end # Window_NameMessage
  455. end
  456.  
  457. #==============================================================================
  458. #
  459. # ¥ End of File
  460. #
  461. #==============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement