marlosgama

Untitled

May 22nd, 2019
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.45 KB | None | 0 0
  1. #==============================================================================
  2. # ** Window_Message
  3. #------------------------------------------------------------------------------
  4. #  Autor: Valentine
  5. #==============================================================================
  6.  
  7. class Game_Message
  8.  
  9.   attr_accessor :event_id
  10.  
  11.   def clear
  12.     @texts = []
  13.     @choices = []
  14.     @face_name = ''
  15.     @face_index = 0
  16.     @background = 0
  17.     @position = 2
  18.     @event_id = 0
  19.     @choice_cancel_type = 0
  20.     @choice_proc = nil
  21.     @num_input_variable_id = 0
  22.     @num_input_digits_max = 0
  23.     @item_choice_variable_id = 0
  24.     @scroll_mode = false
  25.     @scroll_speed = 2
  26.     @scroll_no_fast = false
  27.   end
  28.  
  29. end
  30.  
  31. #==============================================================================
  32. # ** Game_Interpreter
  33. #==============================================================================
  34. class Game_Interpreter
  35.  
  36.   def command_101
  37.     wait_for_message
  38.     $game_message.face_name = @params[0]
  39.     $game_message.face_index = @params[1]
  40.     $game_message.background = @params[2]
  41.     $game_message.position = @params[3]
  42.     $game_message.event_id = @event_id
  43.     while next_event_code == 401 # Texto
  44.       @index += 1
  45.       $game_message.add(@list[@index].parameters[0])
  46.     end
  47.     case next_event_code
  48.     when 102 # Mostrar escolhas
  49.       @index += 1
  50.       setup_choices(@list[@index].parameters)
  51.     when 103 # Entrada numérica
  52.       @index += 1
  53.       setup_num_input(@list[@index].parameters)
  54.     when 104 # Selecionar item
  55.       @index += 1
  56.       setup_item_choice(@list[@index].parameters)
  57.     end
  58.     wait_for_message
  59.   end
  60.  
  61. end
  62.  
  63. #==============================================================================
  64. # ** Window_ChoiceList
  65. #==============================================================================
  66. class Window_ChoiceList < Window_Command
  67.  
  68.   def initialize(message_window)
  69.     @message_window = message_window
  70.     super(0, 0)
  71.     self.openness = 0
  72.     self.windowskin = Cache.system('WindowMessage')
  73.     deactivate
  74.   end
  75.  
  76.   def update_placement
  77.     self.width = [max_choice_width + 12, 96].max + padding * 2
  78.     self.width = [width, Graphics.width].min
  79.     self.height = fitting_height($game_message.choices.size)
  80.     self.x = @message_window.x + @message_window.width - width
  81.     self.y = @message_window.y + @message_window.height
  82.   end
  83.  
  84. end
  85.  
  86. #==============================================================================
  87. # ** Window_Message
  88. #==============================================================================
  89. class Window_Message < Window_Base
  90.  
  91.   def initialize
  92.     super(0, 0, window_width, window_height)
  93.     self.z = 200
  94.     self.openness = 0
  95.     self.windowskin = Cache.system('WindowMessage')
  96.     create_all_windows
  97.     clear_instance_variables
  98.   end
  99.  
  100.   def dispose
  101.     super
  102.     dispose_all_windows
  103.   end
  104.  
  105.   def update
  106.     super
  107.     update_all_windows
  108.     update_fiber
  109.   end
  110.  
  111.   def fiber_main
  112.     $game_message.visible = true
  113.     loop do
  114.       process_all_text if $game_message.has_text?
  115.       process_input
  116.       $game_message.clear
  117.       @gold_window.close
  118.       Fiber.yield
  119.       break unless text_continue?
  120.     end
  121.     close_and_wait
  122.     $game_message.visible = false
  123.     @fiber = nil
  124.   end
  125.  
  126.   def process_all_text
  127.     text = convert_escape_characters($game_message.all_text)
  128.     open_and_wait(text)
  129.     pos = {}
  130.     new_page(text, pos)
  131.     process_character(text.slice!(0, 1), text, pos) until text.empty?
  132.   end
  133.  
  134.   def open_and_wait(text)
  135.     lines = text.split("\n")
  136.     width = text_size(lines.max{ |a, b| a.size <=> b.size }).width
  137.     self.width = width + 42
  138.     self.height = lines.size * 18 + 32
  139.     self.x = [$game_map.events[$game_message.event_id].screen_x - self.width / 2, 0].max
  140.     self.y = [$game_map.events[$game_message.event_id].screen_y - 35 - self.height, 0].max
  141.     self.x = Graphics.width - width - 42 if self.x + width + 42 > Graphics.width
  142.     choice_height = fitting_height($game_message.choices.size)
  143.     self.y = Graphics.height - height - choice_height if self.y + height + choice_height > Graphics.height
  144.     open
  145.     Fiber.yield until open?
  146.   end
  147.  
  148.   def text_continue?
  149.     $game_message.has_text?
  150.   end
  151.  
  152.   def new_page(text, pos)
  153.     contents.clear
  154.     reset_font_settings
  155.     pos[:x] = 5
  156.     pos[:y] = 0
  157.     pos[:new_x] = 5
  158.     pos[:height] = calc_line_height(text)
  159.     clear_flags
  160.   end
  161.  
  162. end
Advertisement
Add Comment
Please, Sign In to add comment