#======================================================= # Lune Message System #======================================================= # Author: Raizen # Fully translated & edited for convenience by mjshi # (because laziness :D) # Compatible with: RMVXAce # Works only with monospace fonts. #======================================================= # The script allows message boxes above and below the # character, with automatic size making a more interesting # dialogue between characters. #======================================================= # Instructions #======================================================= # To use the message just call the show message # either with a face or not. # # Before showing the message configure the character that # will receive the message box. # # To configure the message system just do the following # in a script call. # # Say.ID(speaker) # # speaker can be: # 0 = player # 1+ = events (event id) # -1 = revert to old message system # # To set the speaker to "this event", do: # 1. Control Variables (use any random temporary variable) # 2. Script... (set variable to) event_id # 3. Write Say.ID($game_variables[variable_ID]) # # Or if you're lazy do this: # 1. Do 1 and 2 on the other one # 2. Write e = $game_variables[variable_ID] # 3. Then you can make them say stuff with Say.ID(e) # # Put a 1 frame wait before changing between the message systems, # to give the system the time to reconfigure all the positions back to # the old system, or from the old to the new system. # module Say # don't touch #======================================================= # Begin Configuration #======================================================= # Spacing of the message box MBox_Spacing = 18 # Size of the characters that you are using, an estimate to calculate # the Boxes position. MBox_Size = 48 # Name of the picture file that will put a cursor above the character # which is talking. # In case you do not need any picture files put the constant this way. # Cursor = "" # The image needs to be in the file Graphics/System inside your project. Cursor = "cursor" # Movement of the arrow, 0 to deactivate. C_Move = 1 # ======================================================================== # End of configuration. # ======================================================================== def self.ID(id) if id == -1 position(2) elsif ($game_player.direction == 2 and id != 0) or ($game_player.direction == 8 and id == 0) position(0) else position(1) end identify(id) end def self.position(p = nil) @p = p unless p == nil return @p end def self.identify(id = nil) @id = id unless id == nil return @id end end #============================================================================== # ** Say window #============================================================================== class Lune_Window_Message < Window_Base include Say def initialize(x, y, window_width, window_height) super(x, y, window_width, window_height) self.z = 199 self.openness = 0 @get_sprite = true @sprite_arrow = Sprite.new @sprite_arrow.bitmap = Cache.system(Cursor) if Say.identify == 0 @lune_x = $game_player.screen_x @lune_y = $game_player.screen_y else @lune_x = $game_map.events[Say.identify].screen_x @lune_y = $game_map.events[Say.identify].screen_y end @sprite_arrow.x = @lune_x - 8 @sprite_arrow.y = @lune_y - MBox_Size end def refresh if @get_sprite == true @sprite_arrow.y += C_Move @get_sprite = false else @sprite_arrow.y -= C_Move @get_sprite = true end end def openlune self.openness += 40 self.openness <= 254 ? (return false) : (return true) end def closelune @sprite_arrow.opacity = 0 unless Cursor.nil? self.openness -= 40 self.openness >= 1 ? (return false) : (return true) end def dispose @sprite_arrow.dispose super end end class Game_Message # Return the number of lines def get_lune_lines @lune_text_size = 0 @texts.inject("") {|r, text| @lune_text_size += 1} return @lune_text_size end # Return the length of the text def get_lune_length @lune_length_size = 0 @biggest = 0 @texts.inject("") {|r, text| if get_truel(text) > @lune_length_size @lune_length_size = get_truel(text) @biggest = get_truel(text, true) end } return @biggest end # New method to process true length # (no more strange formatting due to text codes!) def get_truel(text, keep = false) text = text.to_s # Scan text text.scan(/\\[Nn]\[([0-9]+?)\]/).each do|id| text.sub!(/\\[Nn]\[([0-9]+?)\]/, $game_actors[id[0].to_i].name) end # Scan variables text.scan(/\\[Vv]\[([0-9]+?)\]/).each do|id| text.gsub!(/\\[Vv]\[([0-9]+?)\]/, $game_variables[id[0].to_i].to_s) end text.gsub!("\\.", '') text.gsub!("\\!", '') text.gsub!("\\|", '') text.gsub!("\\^", '') text.gsub!("\\$", '') text.gsub!(/\\[CcSs]\[[0-9]+?\]/, '') text.strip! return text if keep return text.size end end #============================================================================== # ** Window_Message #------------------------------------------------------------------------------ # This window is used to show text. #============================================================================== #-------------------------------------------------------------------------- # * Acquire window width #-------------------------------------------------------------------------- class Window_Message < Window_Base # aliasing alias lune_message_update update alias lune_process_all_text process_all_text alias lune_message_dispose dispose alias lune_input_choice input_choice def initialize super(0, 0, Graphics.width, fitting_height(4)) self.z = 200 self.openness = 0 create_all_windows create_back_bitmap create_back_sprite clear_instance_variables end def window_width text_size($game_message.get_lune_length).width + Say::MBox_Spacing end #-------------------------------------------------------------------------- # * Acquire window placement #-------------------------------------------------------------------------- def window_height fitting_height($game_message.get_lune_lines) end def update(*args) lune_message_update(*args) unless Say.position == 2 @lune_message.refresh if @lune_message and Graphics.frame_count % 25 == 1 self.opacity = 0 end end def fiber_main $game_message.visible = true update_background lune_update_placement if Say.position == 2 loop do if Say.position == 2 lune_process_all_text if $game_message.has_text? else process_all_text if $game_message.has_text? end process_input $game_message.clear @gold_window.close Fiber.yield break unless text_continue? end @lune_message.opacity = 0 unless @lune_message == nil and Say.position == 2 close_and_wait $game_message.visible = false @fiber = nil end def lune_update_placement @position = $game_message.position self.y = @position * (Graphics.height - height) / 2 self.x = 0 @gold_window.y = y > 0 ? 0 : Graphics.height - @gold_window.height end def update_placement @gold_window.y = y > 0 ? 0 : Graphics.height - @gold_window.height unless Say.identify.nil? self.x = @lune_x - window_width / 2 self.x -= (self.x + window_width - Graphics.width) if self.x + window_width >= Graphics.width self.x -= new_line_x self.x = [self.x,0].max self.y = @lune_y self.y -= window_height + Say::MBox_Size if Say.position == 1 self.y = [self.y,0].max self.y -= (self.y + window_height - Graphics.height) if self.y + window_height >= Graphics.height end end #-------------------------------------------------------------------------- # * Processing of text #-------------------------------------------------------------------------- def process_all_text if Say.identify == 0 @lune_x = $game_player.screen_x @lune_y = $game_player.screen_y else @lune_x = $game_map.events[Say.identify].screen_x @lune_y = $game_map.events[Say.identify].screen_y end @lune_message.dispose unless @lune_message.nil? w = @lune_x - window_width / 2 h = @lune_y $game_message.face_name.empty? ? (w = [w,0].max) : (w = [w,112].max) h -= window_height + Say::MBox_Size if Say.position == 1 h = [h,0].max w -= (w + window_width - Graphics.width) if w + window_width >= Graphics.width h -= (h + window_height - Graphics.height) if h + window_height >= Graphics.height w += 3 @lune_message = Lune_Window_Message.new(w, h, window_width, window_height) @lune_face = Window_Base.new(w - 104, h + 8, 104, 104) unless $game_message.face_name.empty? update_placement text = convert_escape_characters($game_message.all_text) pos = {} new_page(text, pos) open_and_wait process_character(text.slice!(0, 1), text, pos) until text.empty? end #-------------------------------------------------------------------------- # * Window Opening Animation #-------------------------------------------------------------------------- def open_and_wait unless Say.position == 2 @lune_message.openlune Fiber.yield until @lune_message.openlune open else open Fiber.yield until open? end end #-------------------------------------------------------------------------- # * Window Closing Animation #-------------------------------------------------------------------------- def close_and_wait close Fiber.yield until all_close? @lune_message.closelune if @lune_message Fiber.yield until @lune_message.closelune unless Say.position == 2 end #-------------------------------------------------------------------------- # * Processing of input #-------------------------------------------------------------------------- def input_pause self.pause = true if Say.position == 2 wait(10) Fiber.yield until Input.trigger?(:B) || Input.trigger?(:C) Input.update @lune_face.dispose unless @lune_face.nil? self.pause = false end def dispose @lune_message.dispose if @lune_message Say.ID(-1) lune_message_dispose end #-------------------------------------------------------------------------- # * Processing of choices #-------------------------------------------------------------------------- def input_choice lune_input_choice @lune_face.dispose unless @lune_face.nil? end end