Advertisement
Raizen

Lune Message System

Apr 6th, 2015
5,294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 10.18 KB | None | 0 0
  1. module Lune_Message
  2. #=======================================================
  3. # Lune Message System
  4. # Author: Raizen
  5. # Compatible with: RMVXAce
  6. # The script allows message boxes above and below the
  7. # character, with automatic size making a more interatvice
  8. # message system between characters.
  9.  
  10.  
  11.  
  12. # Instructions
  13.  
  14. # To use the message just call the show message
  15. # either with a face or not.
  16.  
  17. # before showing the message configure the character that
  18. # will receive the message box.
  19. # Also configure if it is below or above the character.
  20.  
  21. # It is also possible to toggle between the new message system
  22. # and the old message system
  23.  
  24. # To configure the message system just do the following.
  25.  
  26. # Call Script:Lune_Message.config(p, id)
  27.  
  28. # Being p the position of the message box.
  29. # 1 = above the character
  30. # 0 = below the character
  31. # 2 = old message system
  32.  
  33. # To deactivate this script just
  34. # Call Script this way
  35. # Call Script:Lune_Message.config(2, 0)
  36. # Put a 1 frame wait before changing between the message systems,
  37. # to give the system the time to reconfigure all the positions back to
  38. # the old system, or from the old to the new system.
  39.  
  40. # ID is the event ID, being the ID 0 it is the Hero.
  41. # The windows size is configured automatically, being that you
  42. # will need to choose the length of the font to ajust better to the
  43. # message box. (In pixels)
  44.  
  45. Espacamento = 11
  46.  
  47. # Size of the characters that you are using, an estimate to calculate
  48. # the Boxes position.
  49.  
  50. Tamanho = 48
  51.  
  52. # Name of the picture file that will put a cursor above the character
  53. # which is talking.
  54. # In case you do not need any picture files put the constant this way.
  55. # Imagem = ""
  56. # The image needs to be in the file Graphics/System inside your project.
  57. Imagem = "arrow"
  58. # Height of the arrow image, for position displacement.
  59. Alt = 10
  60. # Movement of the arrow, 0 to deactivate.
  61. Mov = 0
  62. # ========================================================================
  63. # Here starts the script.
  64. # ========================================================================
  65.  
  66. def self.config(p, id)
  67. posicao(p)
  68. identificacao(id)
  69. end
  70.  
  71. def self.posicao(p = nil)
  72. @p = p unless p == nil
  73. return @p
  74. end
  75.  
  76. def self.identificacao(id = nil)
  77. @id = id unless id == nil
  78. return @id
  79. end
  80. end
  81.  
  82. #==============================================================================
  83. # ** Janela auxiliar
  84. #==============================================================================
  85. class Lune_Window_Message < Window_Base
  86. include Lune_Message
  87.   def initialize(x, y, window_width, window_height)
  88.     super(x, y, window_width, window_height)
  89.     self.z = 199
  90.     self.openness = 0
  91.     @get_sprite = true
  92.     @sprite_arrow = Sprite.new
  93.     @sprite_arrow.bitmap = Cache.system(Imagem)
  94.     if Lune_Message.identificacao == 0
  95.       @lune_x = $game_player.screen_x
  96.       @lune_y = $game_player.screen_y
  97.       else
  98.       @lune_x = $game_map.events[Lune_Message.identificacao].screen_x
  99.       @lune_y = $game_map.events[Lune_Message.identificacao].screen_y
  100.     end
  101.     @sprite_arrow.x = @lune_x - 8
  102.     @sprite_arrow.y = @lune_y - Lune_Message::Tamanho
  103.   end
  104.   def refresh
  105.   if @get_sprite == true
  106.   @sprite_arrow.y += Lune_Message::Mov
  107.   @get_sprite = false
  108.   else
  109.   @sprite_arrow.y -= Lune_Message::Mov
  110.   @get_sprite = true
  111.   end
  112.   end
  113.   def openlune
  114.     self.openness += 40
  115.     self.openness <= 254 ? (return false) : (return true)
  116.   end
  117.   def closelune
  118.     @sprite_arrow.opacity = 0 unless Imagem.nil?
  119.     self.openness -= 40
  120.     self.openness >= 1 ? (return false) : (return true)
  121.   end
  122.   def dispose
  123.   @sprite_arrow.dispose
  124.   super
  125.   end
  126. end
  127.  
  128.    
  129. class Game_Message
  130. # Retorna o valor da quantidade de linhas
  131.    def get_lune_lines
  132.      @lune_text_size = 0
  133.      @texts.inject("") {|r, text| @lune_text_size += 1}
  134.      return @lune_text_size
  135.    end
  136. # Retorna o valor do tamanho do texto.
  137.   def get_lune_length
  138.      @lune_length_size = 0
  139.      @biggest = 0
  140.      @texts.inject("") {|r, text|
  141.      if text.size > @lune_length_size
  142.       @lune_length_size = text.size
  143.       @biggest = text.dup
  144.       @biggest.delete! "\."
  145.       @biggest.delete! "\!"
  146.       @biggest.delete! "\c["
  147.       @biggest.delete! "]"
  148.       @biggest.delete! "["
  149.       p @biggest
  150.       end
  151.      }
  152.      return @biggest
  153.    end
  154.  end
  155.  
  156. #==============================================================================
  157. # ** Window_Message
  158. #------------------------------------------------------------------------------
  159. #  Esta janela de mensagem é usada para exibir textos.
  160. #==============================================================================
  161.   #--------------------------------------------------------------------------
  162.   # * Aquisição da largura da janela
  163.   #--------------------------------------------------------------------------
  164. class Window_Message < Window_Base
  165. # aliasing
  166. alias lune_message_update update  
  167. alias lune_process_all_text process_all_text
  168. alias lune_message_dispose dispose
  169. alias lune_input_choice input_choice
  170.   def initialize
  171.     super(0, 0, Graphics.width, fitting_height(4))
  172.     self.z = 200
  173.     self.openness = 0
  174.     create_all_windows
  175.     create_back_bitmap
  176.     create_back_sprite
  177.     clear_instance_variables
  178.    
  179.   end
  180.   def window_width
  181.     text_size($game_message.get_lune_length).width + Lune_Message::Espacamento
  182.   end
  183.   #--------------------------------------------------------------------------
  184.   # * Aquisição da altura da janela
  185.   #--------------------------------------------------------------------------
  186.   def window_height
  187.     fitting_height($game_message.get_lune_lines)
  188.   end
  189.   def update(*args)
  190.     lune_message_update(*args)
  191.     unless Lune_Message.posicao == 2
  192.     @lune_message.refresh if @lune_message and Graphics.frame_count % 25 == 1
  193.     self.opacity = 0
  194.     end
  195.   end
  196.   def fiber_main
  197.     $game_message.visible = true
  198.     update_background
  199.     lune_update_placement if Lune_Message.posicao == 2
  200.     loop do
  201.       if Lune_Message.posicao == 2
  202.       lune_process_all_text if $game_message.has_text?
  203.       else
  204.       process_all_text if $game_message.has_text?
  205.       end
  206.       process_input
  207.       $game_message.clear
  208.       @gold_window.close
  209.       Fiber.yield
  210.       break unless text_continue?
  211.     end
  212.     @lune_message.opacity = 0 unless @lune_message == nil and Lune_Message.posicao == 2
  213.     close_and_wait
  214.     $game_message.visible = false
  215.     @fiber = nil
  216.   end
  217.   def lune_update_placement
  218.     @position = $game_message.position
  219.     self.y = @position * (Graphics.height - height) / 2
  220.     self.x = 0
  221.     @gold_window.y = y > 0 ? 0 : Graphics.height - @gold_window.height
  222.   end
  223.   def update_placement
  224.     @gold_window.y = y > 0 ? 0 : Graphics.height - @gold_window.height
  225.     unless Lune_Message.identificacao.nil?
  226.       self.x = @lune_x - window_width / 2
  227.       self.x -= (self.x + window_width - Graphics.width) if self.x + window_width >= Graphics.width
  228.       self.x -= new_line_x
  229.       self.x = [self.x,0].max    
  230.       self.y = @lune_y
  231.       self.y -= window_height + Lune_Message::Tamanho if Lune_Message.posicao == 1
  232.       self.y = [self.y,0].max
  233.       self.y -= (self.y + window_height - Graphics.height) if self.y + window_height >= Graphics.height
  234.     end
  235.   end
  236.   #--------------------------------------------------------------------------
  237.   # * Execução de todos texto
  238.   #--------------------------------------------------------------------------
  239.   def process_all_text
  240.     if Lune_Message.identificacao == 0
  241.       @lune_x = $game_player.screen_x
  242.       @lune_y = $game_player.screen_y
  243.       else
  244.       @lune_x = $game_map.events[Lune_Message.identificacao].screen_x
  245.       @lune_y = $game_map.events[Lune_Message.identificacao].screen_y
  246.     end
  247.     @lune_message.dispose unless @lune_message.nil?
  248.     w = @lune_x - window_width / 2
  249.     h = @lune_y
  250.     $game_message.face_name.empty? ? (w = [w,0].max) : (w = [w,112].max)
  251.     h -= window_height + Lune_Message::Tamanho if Lune_Message.posicao == 1
  252.     h = [h,0].max
  253.     w -= (w + window_width - Graphics.width) if w + window_width >= Graphics.width
  254.     h -= (h + window_height - Graphics.height) if h + window_height >= Graphics.height
  255.     @lune_message = Lune_Window_Message.new(w, h, window_width, window_height)
  256.     @lune_face = Window_Base.new(w - 104, h + 8, 104, 104) unless $game_message.face_name.empty?
  257.     update_placement
  258.     text = convert_escape_characters($game_message.all_text)
  259.     pos = {}
  260.     new_page(text, pos)
  261.     open_and_wait
  262.     process_character(text.slice!(0, 1), text, pos) until text.empty?
  263.   end
  264.     #--------------------------------------------------------------------------
  265.   # * Abertura da janela e espeta até abertura total
  266.   #--------------------------------------------------------------------------
  267.   def open_and_wait
  268.     unless Lune_Message.posicao == 2
  269.     @lune_message.openlune
  270.     Fiber.yield until @lune_message.openlune
  271.     open
  272.   else
  273.     open
  274.     Fiber.yield until open?
  275.   end
  276.   end
  277.     #--------------------------------------------------------------------------
  278.   # * Fechamento da janela e espeta até fechamento total
  279.   #--------------------------------------------------------------------------
  280.   def close_and_wait
  281.     close
  282.     Fiber.yield until all_close?
  283.     @lune_message.closelune if @lune_message
  284.     Fiber.yield until @lune_message.closelune unless Lune_Message.posicao == 2
  285.   end
  286.     #--------------------------------------------------------------------------
  287.   # * Execução de espera de entrada
  288.   #--------------------------------------------------------------------------
  289.   def input_pause
  290.     self.pause = true if Lune_Message.posicao == 2
  291.     wait(10)
  292.     Fiber.yield until Input.trigger?(:B) || Input.trigger?(:C)
  293.     Input.update
  294.     @lune_face.dispose unless @lune_face.nil?
  295.     self.pause = false
  296.   end
  297.   def dispose
  298.     @lune_message.dispose if @lune_message
  299.     Lune_Message.config(2,0)
  300.     lune_message_dispose
  301.   end
  302.   #--------------------------------------------------------------------------
  303.   # * Execução de entrada de escolhas
  304.   #--------------------------------------------------------------------------
  305.   def input_choice
  306.     lune_input_choice
  307.     @lune_face.dispose unless @lune_face.nil?
  308.   end
  309. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement