#============================================================================== # ■ メッセージログ # @version 0.1 10/11/29 # @author さば缶 #------------------------------------------------------------------------------ #   #============================================================================== module Saba module MessageLog # メッセージログ表示ボタン LOG_BUTTON = Input::X # 各メッセージの間のスペース Y_SPACE = 10 # 最大メッセージ保持数 # ※あまり巨大な数だと、ビットマップサイズの限界を超えてエラーになります MAX_HISTORY = 20 # 背景色 BG_COLOR = Color.new(0, 0, 0, 180) # スクロール速度 SCROLL_SPEED = 5 end end $imported = {} if $imported == nil $imported["MessageLog"] = true class Window_MessageLog < Window_Selectable def initialize @log_height = 0 super(0, 0, 544, 416) self.z = 600 self.active = false self.opacity = 0 create_back_sprite refresh end #-------------------------------------------------------------------------- # ● 背景スプライトの作成 #-------------------------------------------------------------------------- def create_back_sprite @back_sprite = Sprite.new @back_sprite.bitmap = Bitmap.new(544, 416) bg_color = Saba::MessageLog::BG_COLOR @back_sprite.bitmap.fill_rect(Rect.new(0, 0, 544, 416), bg_color) @back_sprite.visible = true @back_sprite.z = 590 end #-------------------------------------------------------------------------- # ● 背景スプライトの解放 #-------------------------------------------------------------------------- def dispose_back_sprite @back_sprite.bitmap.dispose @back_sprite.dispose end def update super if Input.press?(Input::DOWN) self.oy += Saba::MessageLog::SCROLL_SPEED end if Input.press?(Input::UP) self.oy -= Saba::MessageLog::SCROLL_SPEED end self.oy = 0 if self.oy < 0 self.oy = @max_oy if self.oy > @max_oy end #-------------------------------------------------------------------------- # ● リフレッシュ #-------------------------------------------------------------------------- def refresh @log_height = 0 @contents_y = 0 @data = [] for texts in $game_message_log.logs @log_height += texts.size * WLH @log_height += Saba::MessageLog::Y_SPACE end create_contents for texts in $game_message_log.logs draw_log(texts) end @max_oy = [0, @log_height - 416 + 32].max self.oy = @max_oy end #-------------------------------------------------------------------------- # ● 項目の描画 # index : 項目番号 #-------------------------------------------------------------------------- def draw_log(texts) @contents_x = 0 contents.font.color = text_color(0) @text = "" for i in 0...texts.size @text += texts[i].clone + "\x00" end convert_special_characters loop do c = @text.slice!(/./m) # 次の文字を取得 case c when nil # 描画すべき文字がない break when "\x00" # 改行 @contents_y += WLH @contents_x = 0 when "\x01" # \C[n] (文字色変更) @text.sub!(/\[([0-9]+)\]/, "") contents.font.color = text_color($1.to_i) next else # 普通の文字 contents.draw_text(@contents_x, @contents_y, 40, WLH, c) c_width = contents.text_size(c).width @contents_x += c_width end end @contents_y += Saba::MessageLog::Y_SPACE end def convert_special_characters @text.gsub!(/\\V\[([0-9]+)\]/i) { $game_variables[$1.to_i] } @text.gsub!(/\\N\[([0-9]+)\]/i) { $game_actors[$1.to_i].name } @text.gsub!(/\\C\[([0-9]+)\]/i) { "\x01[#{$1}]" } @text.gsub!(/\\G/) { "" } @text.gsub!(/\\\./) { "" } @text.gsub!(/\\\|/) { "" } @text.gsub!(/\\!/) { "" } @text.gsub!(/\\>/) { "" } @text.gsub!(/\\ Saba::MessageLog::MAX_HISTORY end end class Scene_Map alias saba_msglog_update update def update if @msg_log @msg_log.update if Input.trigger?(Input::B) dispose_message_log end return end if Input.trigger?(Saba::MessageLog::LOG_BUTTON) show_message_log return end saba_msglog_update end def show_message_log Sound.play_decision @msg_log = Window_MessageLog.new end def dispose_message_log Sound.play_cancel @msg_log.dispose @msg_log = nil end end class Window_Message alias saba_msglog_finish_message finish_message def finish_message $game_message_log.push_log($game_message.texts) unless $game_temp.in_battle saba_msglog_finish_message end end if $imported["GalGameTalkSystem"] class Window_MessageGal alias saba_msglog_finish_message finish_message def finish_message $game_message_log.push_log($game_message.texts) saba_msglog_finish_message end end end class Scene_Title #-------------------------------------------------------------------------- # ● 各種ゲームオブジェクトの作成 #-------------------------------------------------------------------------- alias saba_msglog_create_game_objects create_game_objects def create_game_objects saba_msglog_create_game_objects $game_message_log = Game_MessageLog.new end end class Scene_File #-------------------------------------------------------------------------- # ● セーブデータの書き込み # file : 書き込み用ファイルオブジェクト (オープン済み) #-------------------------------------------------------------------------- alias saba_msglog_write_save_data write_save_data def write_save_data(file) saba_msglog_write_save_data(file) Marshal.dump($game_message_log, file) end #-------------------------------------------------------------------------- # ● セーブデータの読み込み # file : 読み込み用ファイルオブジェクト (オープン済み) #-------------------------------------------------------------------------- alias saba_msglog_read_save_data read_save_data def read_save_data(file) saba_msglog_read_save_data(file) begin $game_message_log = Marshal.load(file) rescue $game_message_log = Game_MessageLog.new end end end