#==============================================================================
# ■ 滑动(In/Out)战斗信息 (VX Ace用)
#------------------------------------------------------------------------------
# 制作者 : CanariAlternate
# 主页名 : カルトの鳥篭
# 主页URL : [url]http://canarialt.blog.fc2.com[/url]
#------------------------------------------------------------------------------
# ■ 概要 : 战斗信息滑动进入和退出。
#
# ■ 需要脚本 : 无
#
# ■ 位置 : 「Scene_Battle」之下。
#------------------------------------------------------------------------------
# 更新履歴 : 2012/10/02 Ver1.00 基礎部分の製作が完了する。
# 2012/10/05 Ver1.01 バトルログをこのスクリプトで表示する機能を実装
# 2013/02/19 Ver1.02 説明文の表記方法などを他と統一した。
#==============================================================================
$imported ||= {}
$imported[:CanariAlternate_Window_BattleMessageLog] = true
#==============================================================================
# ■ Calt
#------------------------------------------------------------------------------
# CanariAlternateが製作したスクリプト用のモジュールです。
#==============================================================================
module Calt
#-----------------------------------------------------------------------------
# ★このスクリプトでバトルログを表示させる。
Alternate_Window_BattleLog = true
#-----------------------------------------------------------------------------
end
if Calt::Alternate_Window_BattleLog
$imported[:CanariAlternate_Window_BattleLog] = true
#==============================================================================
# ■ Scene_Battle
#------------------------------------------------------------------------------
# バトル画面の処理を行うクラスです。
#==============================================================================
class Scene_Battle < Scene_Base
#--------------------------------------------------------------------------
# ● フレーム更新(基本)[追加]
#--------------------------------------------------------------------------
alias _update_basic_alter_battle_log update_basic
def update_basic
_update_basic_alter_battle_log
@log_window.update # バトルログを更新
end
end
Window_BattleMessageLog = Window_BattleLog # 別名(変更を共有)
else
Window_BattleMessageLog = Window_BattleLog.clone # クローン
end
#==============================================================================
# ■ Window_BattleMessageLog
#------------------------------------------------------------------------------
# ログを表示する機能の設定を定義しています。
#==============================================================================
class Window_BattleMessageLog
#--------------------------------------------------------------------------
# ● ラインを移動する速度(行をつめる速度) ※縦にスライドする速度
def now_speed ; return 3 ; end
#--------------------------------------------------------------------------
# ● ラインを消去する速度(画面外へのスライド速度) ※縦にスライドする速度
def del_speed ; return 4 ; end
#--------------------------------------------------------------------------
# ● ラインを追加する速度(画面内へのスライド速度) ※横にスライドする速度
def add_speed ; return 96 ; end
#--------------------------------------------------------------------------
# ● 追加するラインの始点(x座標)
def add_line_start_x ; return contents_width ; end
#--------------------------------------------------------------------------
# ● 消去するラインの終点(y座標)
def del_line_end_y ; return -line_height ; end
#--------------------------------------------------------------------------
# ● 最大行数の取得
def max_line_number ; return 6 ; end
#--------------------------------------------------------------------------
# ● 消去中のラインの不透明度 (透明) 0 ~ 255 (不透明)
def del_opacity ; return 64 ; end
#--------------------------------------------------------------------------
# ● 背景ビットマップの取得
def get_back_bitmap(line_rect)
##back_bitmap = Bitmap.new("Graphics/System/" + "画像名") # 画像を読み込み
##return back_bitmap
back_bitmap = Bitmap.new(line_rect.width, line_rect.height) # ビットマップを生成
color_l = left_color # ラインの左端の色を取得
color_r = right_color # ラインの右端の色を取得
# 左から右へグラデーションさせながら塗りつぶし
back_bitmap.gradient_fill_rect(line_rect, color_l, color_r)
# これだけだと寂しいので少し装飾(枠をつける)
color_l.alpha += 64
color_r.alpha += 64
frame_rect = Rect.new(0, 0, line_rect.width, 1)
back_bitmap.gradient_fill_rect(frame_rect, color_l, color_r) # 上の枠を描画
frame_rect.y = line_rect.height - 1
back_bitmap.gradient_fill_rect(frame_rect, color_l, color_r) # 下の枠を描画
frame_rect = Rect.new(0, 0, 1, line_rect.height)
back_bitmap.fill_rect(frame_rect, color_l) # 左の枠を描画
frame_rect.x = line_rect.width - 1
back_bitmap.fill_rect(frame_rect, color_r) # 右の枠を描画
return back_bitmap
end
#--------------------------------------------------------------------------
# ● ラインの左端の色 (red, green, blue, alpha)
def left_color ; return Color.new(255, 128, 64, 128) ; end
#--------------------------------------------------------------------------
# ● ラインの右端の色 (red, green, blue, alpha)
def right_color ; return Color.new(255, 255, 255, 32) ; end
#--------------------------------------------------------------------------
# ● ラインの幅を取得
def line_width ; return contents_width - 16 ; end
#--------------------------------------------------------------------------
# ● ラインの高さを取得
def line_height ; return 24 ; end
#--------------------------------------------------------------------------
# ● ウィンドウ幅の初期値を取得
def window_width ; return Graphics.width ; end
#--------------------------------------------------------------------------
# ● ウィンドウ高さの初期値を取得
def window_height ; return fitting_height(max_line_number) ; end
#--------------------------------------------------------------------------
# ● ウィンドウの初期設定
def window_parameter
##self.windowskin = Cache.system("Window") # ウィンドウスキンの変更
self.z = 100 # Z座標
self.opacity = 0 # 透明度
self.arrows_visible = false # カーソルは表示しない
end
#--------------------------------------------------------------------------
# ● 標準パディングサイズの取得
def standard_padding ; return 0 ; end
#--------------------------------------------------------------------------
# ● ウィンドウ内容の幅を計算
def contents_width ; return width - standard_padding * 2 ; end
#--------------------------------------------------------------------------
# ● ウィンドウ内容の高さを計算
def contents_height ; return height - standard_padding * 2 ; end
#--------------------------------------------------------------------------
# ● 余白(x座標)
def padding_x ; return 0 ; end
#--------------------------------------------------------------------------
# ● 余白(y座標)
def padding_y ; return 8 ; end
#--------------------------------------------------------------------------
# ● ラインのテキストの余白(x座標)
def text_padding_x ; return 16 ; end
#--------------------------------------------------------------------------
# ● ラインのテキストの余白(y座標)
def text_padding_y ; return 0 ; end
#--------------------------------------------------------------------------
# ● ラインとラインの間隔
def line_spacing ; return 4 ; end
#--------------------------------------------------------------------------
end
#==============================================================================
# ■ Window_BattleMessageLog
#------------------------------------------------------------------------------
# ログを表示する機能を制御するメソッドを定義しています。
#==============================================================================
class Window_BattleMessageLog
#--------------------------------------------------------------------------
# ● 最下行の文章の取得
def last_text ; return line_text(@exist_lines[-1]) ; end
#--------------------------------------------------------------------------
# ● データ行数の取得
def line_number ; return @exist_lines.size ; end
#--------------------------------------------------------------------------
# ● 一行戻る
def back_one ; del_line(@exist_lines.pop) ; end
#--------------------------------------------------------------------------
# ● 指定した行を消去
def del_text(gyou) ; del_line(@exist_lines.delete_at(gyou - 1)) ; end
#--------------------------------------------------------------------------
# ● 指定した行に戻る
def back_to(line_index) ; back_one while line_number > line_index ; end
#--------------------------------------------------------------------------
# ● 一行シフト
def shift_one
@shift_lines[@exist_lines.shift] = del_line_end_y
@change_lines = true
end
#--------------------------------------------------------------------------
# ● クリア
def clear
@num_wait = 0
@dying_lines += @exist_lines
@exist_lines.clear
@entry_lines.clear
end
#--------------------------------------------------------------------------
# ● 文章の追加(行を指定するとその行に追加)
def add_text(text, line_index = line_number)
shift_one unless line_number < max_line_number # 行数が上限以上
add_line(text, line_index)
end
#--------------------------------------------------------------------------
# ● 文章の置き換え
def replace_text(text)
back_one
add_text(text)
end
#--------------------------------------------------------------------------
end
#==============================================================================
# ■ Window_BattleMessageLog
#------------------------------------------------------------------------------
# ログを表示する機能の処理で使用する変数の操作・取得を定義しています。
#==============================================================================
class Window_BattleMessageLog
#--------------------------------------------------------------------------
# ● 定数
#--------------------------------------------------------------------------
Text = 0 # テキストのインデックス
Back = 1 # 背景のスプライトのインデクッス
Window = 2 # 文章のウィンドウのインデックス
#--------------------------------------------------------------------------
# ● 指定行数に適合するウィンドウの高さを計算
#--------------------------------------------------------------------------
def fitting_height(line_index)
return line_position_y(line_index) + standard_padding * 2
end
#--------------------------------------------------------------------------
# ● 指定行数に適合するラインの高さを計算
#--------------------------------------------------------------------------
def line_position_y(line_index)
return padding_y + (line_height + line_spacing) * line_index
end
#--------------------------------------------------------------------------
# ● ラインの背景スプライトを取得
#--------------------------------------------------------------------------
def line_text(window_index)
return @line_windows[window_index][Text]
end
#--------------------------------------------------------------------------
# ● ラインの背景スプライトを取得
#--------------------------------------------------------------------------
def line_back(window_index)
return @line_windows[window_index][Back]
end
#--------------------------------------------------------------------------
# ● ラインの文章ウィンドウを取得
#--------------------------------------------------------------------------
def line_window(window_index)
return @line_windows[window_index][Window]
end
#--------------------------------------------------------------------------
# ● ラインのx座標を設定
#--------------------------------------------------------------------------
def set_line_window_x(window_index, new_x)
@line_windows[window_index][Back].x = new_x
@line_windows[window_index][Window].x = new_x
end
#--------------------------------------------------------------------------
# ● ラインのy座標を設定
#--------------------------------------------------------------------------
def set_line_window_y(window_index, new_y)
@line_windows[window_index][Back].y = new_y
@line_windows[window_index][Window].y = new_y
end
#--------------------------------------------------------------------------
# ● ラインのx座標に加算
#--------------------------------------------------------------------------
def add_line_window_x(window_index, add_x)
@line_windows[window_index][Back].x += add_x
@line_windows[window_index][Window].x += add_x
end
#--------------------------------------------------------------------------
# ● ラインのy座標に加算
#--------------------------------------------------------------------------
def add_line_window_y(window_index, add_y)
@line_windows[window_index][Back].y += add_y
@line_windows[window_index][Window].y += add_y
end
#--------------------------------------------------------------------------
# ● ラインのx座標を取得
#--------------------------------------------------------------------------
def line_window_x(window_index)
return @line_windows[window_index][Window].x
end
#--------------------------------------------------------------------------
# ● ラインのy座標を取得
#--------------------------------------------------------------------------
def line_window_y(window_index)
return @line_windows[window_index][Window].y
end
end
#==============================================================================
# ■ Window_BattleMessageLog
#------------------------------------------------------------------------------
# ログを表示する機能の処理を定義しています。
#==============================================================================
class Window_BattleMessageLog
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
def initialize(x = 0, y = 0, width = window_width, height = window_height)
super(x, y, width, height)
window_parameter # このウィンドウの初期値を設定
create_lines_viewport # ラインが枠内から出ないようにするビューポートを生成
create_back_bitmap # ラインの背景Bitmapを生成
@death_sentence = [] # 消去中に状態を変更するウィンドウを記憶する変数
@change_lines = false # ライン状態の変更を記憶する変数
@num_wait = 0 # バトルログのウェイトで使用する変数
# ラインの状態リスト
@exist_lines = [] # 表示中(空文含む)
@entry_lines = [] # 追加中
@dying_lines = [] # 消去中
@shift_lines = {} # 移動中(ハッシュ)
# ラインを描画する為のウィンドウとスプライトのセットの配列を準備
@line_windows = Array.new(max_line_number * 3) do |i|
@shift_lines[i] = false # ハッシュにKeyを登録する
create_line_window_set
end
end
#--------------------------------------------------------------------------
# ● 解放
#--------------------------------------------------------------------------
def dispose
super
dispose_back_bitmap
dispose_line_windows
dispose_lines_viewport
end
#--------------------------------------------------------------------------
# ● ラインのビューポートを生成
#--------------------------------------------------------------------------
def create_lines_viewport
@lines_viewport = Viewport.new(0, 0, contents_width, contents_height)
@lines_viewport.rect.x = self.x + standard_padding
@lines_viewport.rect.y = self.y + standard_padding
@lines_viewport.z = self.z
end
#--------------------------------------------------------------------------
# ● ラインの背景になるビットマップを生成
#--------------------------------------------------------------------------
def create_back_bitmap
line_rect = Rect.new(0, 0, line_width, line_height) # ラインの矩形
@back_bitmap = get_back_bitmap(line_rect) # Bitmapの取得
end
#--------------------------------------------------------------------------
# ● ラインの背景になるスプライトの生成
#--------------------------------------------------------------------------
def create_back_sprite
back_sprite = Sprite.new(@lines_viewport)
back_sprite.bitmap = @back_bitmap
back_sprite.visible = false
back_sprite.z = 150
return back_sprite
end
#--------------------------------------------------------------------------
# ● テキストを表示するウィンドウの生成
#--------------------------------------------------------------------------
def create_line_window
line_window = Window_MessageLine.new(0, 0, line_width, line_height)
line_window.viewport = @lines_viewport
line_window.visible = false
line_window.z = 200
return line_window
end
#--------------------------------------------------------------------------
# ● テキストとウィンドウと背景の配列を生成
#--------------------------------------------------------------------------
def create_line_window_set
return [nil, create_back_sprite, create_line_window]
end
#--------------------------------------------------------------------------
# ● 背景ビットマップの解放
#--------------------------------------------------------------------------
def dispose_back_bitmap
@back_bitmap.dispose
end
#--------------------------------------------------------------------------
# ● ウィンドウと背景の解放
#--------------------------------------------------------------------------
def dispose_line_windows
@line_windows.each do |window_set|
window_set[Back].dispose # 背景のスプライトを解放
window_set[Window].dispose # 文章のウィンドウを解放
end
end
#--------------------------------------------------------------------------
# ● ラインのビューポートの解放
#--------------------------------------------------------------------------
def dispose_lines_viewport
@lines_viewport.dispose
end
#--------------------------------------------------------------------------
# ● ラインのビューポートの同期と更新
#--------------------------------------------------------------------------
def update_lines_viewport
# 移動しない場合は更新不要。それに同期させるより移動する際に更新する方が良い。
@lines_viewport.rect.x = self.x + standard_padding
@lines_viewport.rect.y = self.y + standard_padding
@lines_viewport.z = self.z
@lines_viewport.rect.width = contents_width
@lines_viewport.rect.height = contents_height
@lines_viewport.visible = self.visible
##@lines_viewport.update # フラッシュは使用しないので更新はしない
end
#--------------------------------------------------------------------------
# ● 更新処理
#--------------------------------------------------------------------------
def update
super
check_shift_line if @change_lines # ライン状態が操作されている
@death_sentence.reject! { |window_index| execution(window_index) }
##update_lines_viewport # ラインのビューポートの同期と更新
@dying_lines.each_index { |index| dying_line_process(index) }
@entry_lines.each_index { |index| entry_line_process(index) }
@shift_lines.each { |key, value| shift_line_process(key, value) if value }
##@line_windows.each do |window_set| # 波形描画などはしないので更新しない
## window_set[Back].update # 背景のスプライトを更新
## window_set[Window].update # 文章のウィンドウを更新
##end
end
#--------------------------------------------------------------------------
# ● ラインを追加する処理
#--------------------------------------------------------------------------
def add_line(text, line_index)
window_index = nil
@line_windows.each_index do |i| # 待機中のウィンドウを探索
break window_index = i unless @line_windows[i][Text]
end
unless window_index # 待機中のウィンドウが存在しない場合
@shift_lines[@line_windows.size] = false # ハッシュにKeyを登録する
@line_windows.push create_line_window_set # 新たにウィンドウを生成して追加
window_index = @line_windows.size
end
# 表示中のリストに登録
if line_index < line_number
@exist_lines.insert(line_index, window_index) # 途中に挿入
else
line_index = line_number
@exist_lines.push window_index # 末尾に追加
end
# ラインの位置を設定
set_line_window_x(window_index, add_line_start_x)
set_line_window_y(window_index, line_position_y(line_index))
# ラインの可視化と文章の描画
@line_windows[window_index][Text] = text # 描画する文章を記憶
line_back(window_index).opacity = 255 # 背景の透明度を初期化
line_back(window_index).z = 150 # z座標を初期化
line_window(window_index).z = 200 # z座標を初期化
line_window(window_index).draw_text_ex(text_padding_x, text_padding_y, text) # 文章を描画
line_window(window_index).contents_opacity = 255 # 文章の透明度を初期化
# ラインの表示
unless text.empty? # 空文は表示しない
line_back(window_index).visible = true
line_window(window_index).visible = true
@entry_lines.push window_index # 追加中のリストに登録
end
@change_lines = true # ライン状態の変更を記憶
end
#--------------------------------------------------------------------------
# ● ラインの消去を予約する処理
#--------------------------------------------------------------------------
def del_line(window_index)
@death_sentence.push window_index # 消去を予約
@change_lines = true # ライン状態の変更を記憶
end
#--------------------------------------------------------------------------
# ● ラインを消去中にする処理
#--------------------------------------------------------------------------
def execution(window_index)
line_back(window_index).opacity = del_opacity # 背景を半透明に
line_window(window_index).contents_opacity = del_opacity # 文章を半透明に
line_back(window_index).z = 50 # 表示位置を奥に設定
line_window(window_index).z = 100 # 表示位置を奥に設定
@dying_lines.push window_index # 消去中のリストに登録
return true
end
#--------------------------------------------------------------------------
# ● ラインを消去する処理
#--------------------------------------------------------------------------
def dead_line(window_index)
@line_windows[window_index][Text] = nil # 文章の記憶を初期化
line_back(window_index).visible = false # ラインの背景を非表示
line_window(window_index).visible = false # ラインの文章を非表示
line_window(window_index).contents.clear # 文章のBitmapを初期化
end
#--------------------------------------------------------------------------
# ● シフトするラインを探索
#--------------------------------------------------------------------------
def check_shift_line
@change_lines = false # ライン状態の変更の記憶を初期化
@exist_lines.each_index do |line_index|
window_index = @exist_lines[line_index] # ウィンドウのインデックスを取得
position_y = line_position_y(line_index) # 移動先を取得
if position_y != line_window_y(window_index) # 移動先が現在地以外
@shift_lines[window_index] = position_y # 移動中のリストに登録
elsif value = @shift_lines[window_index] # 既に移動先が登録済
@shift_lines[window_index] = false unless value == del_line_end_y # 消去シフト以外は解除
end
end
end
#--------------------------------------------------------------------------
# ● ラインを行数に従って定位置へ移動する処理
#--------------------------------------------------------------------------
def shift_line_process(window_index, position_y)
line_y = line_window_y(window_index)
if (line_y - position_y).abs >= now_speed
slide_y = line_y < position_y ? now_speed : -now_speed
add_line_window_y(window_index, slide_y) # ウィンドウを移動
else
set_line_window_y(window_index, position_y) # ウィンドウの位置を設定
@shift_lines[window_index] = false
if position_y == del_line_end_y # 消去シフト移動の場合
dead_line(window_index) # ラインを消去
@dying_lines.delete(window_index) # 消去中のリストから消去
@entry_lines.delete(window_index) # 追加中のリストから消去
end
end
end
#--------------------------------------------------------------------------
# ● 追加されたラインを画面内へ移動する処理
#--------------------------------------------------------------------------
def entry_line_process(index)
window_index = @entry_lines[index] # ウィンドウのインデックスを取得
line_x = line_window_x(window_index) # ラインのx座標を取得
if (line_x - padding_x).abs >= add_speed
slide_x = line_x < padding_x ? add_speed : -add_speed
add_line_window_x(window_index, slide_x) # ウィンドウを移動
else
set_line_window_x(window_index, padding_x) # ウィンドウの位置を設定
@entry_lines.delete_at(index) # 追加中のリストから消去
end
end
#--------------------------------------------------------------------------
# ● ラインを画面外へ移動させて消去する処理
#--------------------------------------------------------------------------
def dying_line_process(index)
window_index = @dying_lines[index] # ウィンドウのインデックスを取得
line_y = line_window_y(window_index)
if (line_y - del_line_end_y).abs >= del_speed
slide_y = line_y < del_line_end_y ? now_speed : -now_speed
add_line_window_y(window_index, slide_y) # ウィンドウを移動
else
dead_line(window_index) # ラインを消去
@dying_lines.delete_at(index) # 消去中のリストから消去
@entry_lines.delete(window_index) # 追加中のリストから消去
@shift_lines[window_index] = false # 移動中のリストから消去
end
end
end
#==============================================================================
# ■ Window_MessageLine
#------------------------------------------------------------------------------
# テキストを表示するスプライトのクラスです。スプライトもどき。
#==============================================================================
class Window_MessageLine < Window_Base
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
super
self.arrows_visible = false # カーソルは表示しない
self.opacity = 0 # 文字の描画以外は不要
end
#--------------------------------------------------------------------------
# ● 標準パディングサイズの取得
#--------------------------------------------------------------------------
def standard_padding
return 0 # 余白を確保する必要はなし
end
end