Advertisement
mjshi

Lune Message System (convenience edit)

Mar 11th, 2016
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.86 KB | None | 0 0
  1. #=======================================================
  2. # Lune Message System
  3. #=======================================================
  4. # Author: Raizen
  5. # Fully translated & edited for convenience by mjshi
  6. # (because laziness :D)
  7. # Compatible with: RMVXAce
  8. # Works only with monospace fonts.
  9. #=======================================================
  10. # The script allows message boxes above and below the
  11. # character, with automatic size making a more interesting
  12. # dialogue between characters.
  13. #=======================================================
  14. # Instructions
  15. #=======================================================
  16. # To use the message just call the show message
  17. # either with a face or not.
  18. #
  19. # Before showing the message configure the character that
  20. # will receive the message box.
  21. #
  22. # To configure the message system just do the following
  23. # in a script call.
  24. #
  25. # Say.ID(speaker)
  26. #
  27. # speaker can be:
  28. #  0 = player
  29. # 1+ = events (event id)
  30. # -1 = revert to old message system
  31. #
  32. # To set the speaker to "this event", do:
  33. # 1. Control Variables (use any random temporary variable)
  34. # 2. Script... (set variable to) event_id
  35. # 3. Write Say.ID($game_variables[variable_ID])
  36. #
  37. # Or if you're lazy do this:
  38. # 1. Do 1 and 2 on the other one
  39. # 2. Write e = $game_variables[variable_ID]
  40. # 3. Then you can make them say stuff with Say.ID(e)
  41. #
  42. # Put a 1 frame wait before changing between the message systems,
  43. # to give the system the time to reconfigure all the positions back to
  44. # the old system, or from the old to the new system.
  45. #
  46. module Say # don't touch
  47.  
  48. #=======================================================
  49. # Begin Configuration
  50. #=======================================================
  51. # Spacing of the message box
  52.   MBox_Spacing = 18
  53.  
  54. # Size of the characters that you are using, an estimate to calculate
  55. # the Boxes position.
  56.   MBox_Size = 48
  57.  
  58. # Name of the picture file that will put a cursor above the character
  59. # which is talking.
  60. # In case you do not need any picture files put the constant this way.
  61. # Cursor = ""
  62. # The image needs to be in the file Graphics/System inside your project.
  63.   Cursor = "cursor"
  64.  
  65. # Movement of the arrow, 0 to deactivate.
  66.   C_Move = 1
  67.  
  68. # ========================================================================
  69. # End of configuration.
  70. # ========================================================================
  71.  
  72.   def self.ID(id)
  73.     if id == -1
  74.       position(2)
  75.     elsif ($game_player.direction == 2 and id != 0) or ($game_player.direction == 8 and id == 0)
  76.       position(0)
  77.     else
  78.       position(1)
  79.     end
  80.     identify(id)
  81.   end
  82.  
  83.   def self.position(p = nil)
  84.     @p = p unless p == nil
  85.     return @p
  86.   end
  87.  
  88.   def self.identify(id = nil)
  89.     @id = id unless id == nil
  90.     return @id
  91.   end
  92. end
  93.  
  94. #==============================================================================
  95. # ** Say window
  96. #==============================================================================
  97. class Lune_Window_Message < Window_Base
  98. include Say
  99.   def initialize(x, y, window_width, window_height)
  100.     super(x, y, window_width, window_height)
  101.     self.z = 199
  102.     self.openness = 0
  103.     @get_sprite = true
  104.     @sprite_arrow = Sprite.new
  105.     @sprite_arrow.bitmap = Cache.system(Cursor)
  106.     if Say.identify == 0
  107.       @lune_x = $game_player.screen_x
  108.       @lune_y = $game_player.screen_y
  109.     else
  110.       @lune_x = $game_map.events[Say.identify].screen_x
  111.       @lune_y = $game_map.events[Say.identify].screen_y
  112.     end
  113.    
  114.     @sprite_arrow.x = @lune_x - 8
  115.     @sprite_arrow.y = @lune_y - MBox_Size
  116.   end
  117.   def refresh
  118.   if @get_sprite == true
  119.   @sprite_arrow.y += C_Move
  120.   @get_sprite = false
  121.   else
  122.   @sprite_arrow.y -= C_Move
  123.   @get_sprite = true
  124.   end
  125.   end
  126.   def openlune
  127.     self.openness += 40
  128.     self.openness <= 254 ? (return false) : (return true)
  129.   end
  130.   def closelune
  131.     @sprite_arrow.opacity = 0 unless Cursor.nil?
  132.     self.openness -= 40
  133.     self.openness >= 1 ? (return false) : (return true)
  134.   end
  135.   def dispose
  136.     @sprite_arrow.dispose
  137.   super
  138.   end
  139. end
  140.  
  141. class Game_Message
  142. # Return the number of lines
  143.    def get_lune_lines
  144.      @lune_text_size = 0
  145.      @texts.inject("") {|r, text| @lune_text_size += 1}
  146.      return @lune_text_size
  147.    end
  148. # Return the length of the text
  149.   def get_lune_length
  150.     @lune_length_size = 0
  151.     @biggest = 0
  152.     @texts.inject("") {|r, text|
  153.     if get_truel(text) > @lune_length_size
  154.       @lune_length_size = get_truel(text)
  155.       @biggest = get_truel(text, true)
  156.     end
  157.     }
  158.     return @biggest
  159.   end
  160.  
  161. # New method to process true length
  162. # (no more strange formatting due to text codes!)
  163.   def get_truel(text, keep = false)
  164.     text = text.to_s
  165.    
  166.     # Scan text
  167.     text.scan(/\\[Nn]\[([0-9]+?)\]/).each do|id|
  168.       text.sub!(/\\[Nn]\[([0-9]+?)\]/, $game_actors[id[0].to_i].name)
  169.     end
  170.    
  171.     # Scan variables
  172.     text.scan(/\\[Vv]\[([0-9]+?)\]/).each do|id|
  173.       text.gsub!(/\\[Vv]\[([0-9]+?)\]/, $game_variables[id[0].to_i].to_s)
  174.     end
  175.    
  176.     text.gsub!("\\.", '')
  177.     text.gsub!("\\!", '')
  178.     text.gsub!("\\|", '')
  179.     text.gsub!("\\^", '')
  180.     text.gsub!("\\$", '')
  181.     text.gsub!(/\\[CcSs]\[[0-9]+?\]/, '')
  182.     text.strip!
  183.     return text if keep
  184.     return text.size
  185.   end  
  186. end
  187.  
  188. #==============================================================================
  189. # ** Window_Message
  190. #------------------------------------------------------------------------------
  191. #  This window is used to show text.
  192. #==============================================================================
  193.   #--------------------------------------------------------------------------
  194.   # * Acquire window width
  195.   #--------------------------------------------------------------------------
  196. class Window_Message < Window_Base
  197. # aliasing
  198. alias lune_message_update update  
  199. alias lune_process_all_text process_all_text
  200. alias lune_message_dispose dispose
  201. alias lune_input_choice input_choice
  202.   def initialize
  203.     super(0, 0, Graphics.width, fitting_height(4))
  204.     self.z = 200
  205.     self.openness = 0
  206.     create_all_windows
  207.     create_back_bitmap
  208.     create_back_sprite
  209.     clear_instance_variables
  210.   end
  211.   def window_width
  212.     text_size($game_message.get_lune_length).width + Say::MBox_Spacing
  213.   end
  214.   #--------------------------------------------------------------------------
  215.   # * Acquire window placement
  216.   #--------------------------------------------------------------------------
  217.   def window_height
  218.     fitting_height($game_message.get_lune_lines)
  219.   end
  220.   def update(*args)
  221.     lune_message_update(*args)
  222.     unless Say.position == 2
  223.     @lune_message.refresh if @lune_message and Graphics.frame_count % 25 == 1
  224.     self.opacity = 0
  225.     end
  226.   end
  227.   def fiber_main
  228.     $game_message.visible = true
  229.     update_background
  230.     lune_update_placement if Say.position == 2
  231.     loop do
  232.       if Say.position == 2
  233.       lune_process_all_text if $game_message.has_text?
  234.       else
  235.       process_all_text if $game_message.has_text?
  236.       end
  237.       process_input
  238.       $game_message.clear
  239.       @gold_window.close
  240.       Fiber.yield
  241.       break unless text_continue?
  242.     end
  243.     @lune_message.opacity = 0 unless @lune_message == nil and Say.position == 2
  244.     close_and_wait
  245.     $game_message.visible = false
  246.     @fiber = nil
  247.   end
  248.   def lune_update_placement
  249.     @position = $game_message.position
  250.     self.y = @position * (Graphics.height - height) / 2
  251.     self.x = 0
  252.     @gold_window.y = y > 0 ? 0 : Graphics.height - @gold_window.height
  253.   end
  254.   def update_placement
  255.     @gold_window.y = y > 0 ? 0 : Graphics.height - @gold_window.height
  256.     unless Say.identify.nil?
  257.       self.x = @lune_x - window_width / 2
  258.       self.x -= (self.x + window_width - Graphics.width) if self.x + window_width >= Graphics.width
  259.       self.x -= new_line_x
  260.       self.x = [self.x,0].max    
  261.       self.y = @lune_y
  262.       self.y -= window_height + Say::MBox_Size if Say.position == 1
  263.       self.y = [self.y,0].max
  264.       self.y -= (self.y + window_height - Graphics.height) if self.y + window_height >= Graphics.height
  265.     end
  266.   end
  267.   #--------------------------------------------------------------------------
  268.   # * Processing of text
  269.   #--------------------------------------------------------------------------
  270.   def process_all_text
  271.     if Say.identify == 0
  272.       @lune_x = $game_player.screen_x
  273.       @lune_y = $game_player.screen_y
  274.       else
  275.       @lune_x = $game_map.events[Say.identify].screen_x
  276.       @lune_y = $game_map.events[Say.identify].screen_y
  277.     end
  278.     @lune_message.dispose unless @lune_message.nil?
  279.     w = @lune_x - window_width / 2
  280.     h = @lune_y
  281.     $game_message.face_name.empty? ? (w = [w,0].max) : (w = [w,112].max)
  282.     h -= window_height + Say::MBox_Size if Say.position == 1
  283.     h = [h,0].max
  284.     w -= (w + window_width - Graphics.width) if w + window_width >= Graphics.width
  285.     h -= (h + window_height - Graphics.height) if h + window_height >= Graphics.height
  286.     w += 3
  287.     @lune_message = Lune_Window_Message.new(w, h, window_width, window_height)
  288.     @lune_face = Window_Base.new(w - 104, h + 8, 104, 104) unless $game_message.face_name.empty?
  289.     update_placement
  290.     text = convert_escape_characters($game_message.all_text)
  291.     pos = {}
  292.     new_page(text, pos)
  293.     open_and_wait
  294.     process_character(text.slice!(0, 1), text, pos) until text.empty?
  295.   end
  296.   #--------------------------------------------------------------------------
  297.   # * Window Opening Animation
  298.   #--------------------------------------------------------------------------
  299.   def open_and_wait
  300.     unless Say.position == 2
  301.     @lune_message.openlune
  302.     Fiber.yield until @lune_message.openlune
  303.     open
  304.   else
  305.     open
  306.     Fiber.yield until open?
  307.   end
  308.   end
  309.   #--------------------------------------------------------------------------
  310.   # * Window Closing Animation
  311.   #--------------------------------------------------------------------------
  312.   def close_and_wait
  313.     close
  314.     Fiber.yield until all_close?
  315.     @lune_message.closelune if @lune_message
  316.     Fiber.yield until @lune_message.closelune unless Say.position == 2
  317.   end
  318.  
  319.   #--------------------------------------------------------------------------
  320.   # * Processing of input
  321.   #--------------------------------------------------------------------------
  322.   def input_pause
  323.     self.pause = true if Say.position == 2
  324.     wait(10)
  325.     Fiber.yield until Input.trigger?(:B) || Input.trigger?(:C)
  326.     Input.update
  327.     @lune_face.dispose unless @lune_face.nil?
  328.     self.pause = false
  329.   end
  330.   def dispose
  331.     @lune_message.dispose if @lune_message
  332.     Say.ID(-1)
  333.     lune_message_dispose
  334.   end
  335.   #--------------------------------------------------------------------------
  336.   # * Processing of choices
  337.   #--------------------------------------------------------------------------
  338.   def input_choice
  339.     lune_input_choice
  340.     @lune_face.dispose unless @lune_face.nil?
  341.   end
  342. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement