text = xrxsv2_convert_escape_characters(text)
basic_width = text_size(text).width + add
esc = text.scan(/\e(\S)/)
return ( basic_width - esc.size * (contents.font.size - 4) ) #\eの幅は20?
end
#--------------------------------------------------------------------------
# ● 最も長い列の長さを調べる。エスケープ文字は含まない。
#--------------------------------------------------------------------------
def max_width
text_size = []
for i in 0 ... @all_texts.size
text_size.push text_width_no_escape(@all_texts,@all_texts) + 20
end
return text_size.max
end
#--------------------------------------------------------------------------
# ● 吹きだしテールが上か下の場合の画像を準備。
#--------------------------------------------------------------------------
def create_tail_up_under
skin = "Window"
tale_pos = get_tale_pos
case @position
when 0 # 上
@tail.bitmap = Cache.system(skin + "-top")
@tail.x = tale_pos[0]
@tail.y = tale_pos[1]
@tail.z = self.z + 1
when 1 # 中
@tail.dispose
@tail = nil
when 2 # 下
@tail.bitmap = Cache.system(skin + "-under")
@tail.x = tale_pos[0]
@tail.y = tale_pos[1]
@tail.z = self.z + 1
end
end
#--------------------------------------------------------------------------
# ● 全テキストの処理
#--------------------------------------------------------------------------
def process_all_text
#open_and_wait #リサイズがあるので、すぐにウィンドウをオープンしない。
text = convert_escape_characters($game_message.all_text)
pos = {}
new_page(text, pos)
process_character(text.slice!(0, 1), text, pos) until text.empty?
end
#--------------------------------------------------------------------------
# ● メッセージの更新 *
#--------------------------------------------------------------------------
def update_message
@wait_count = @type_wait
loop do
c = @text.slice!(/./m)
case update_message_type(c)
when 1
break
when 2
next
end
break unless @show_fast or @line_show_fast
end
end
#--------------------------------------------------------------------------
# 一文字の描画 (返り値 1:break, 2:next)
#--------------------------------------------------------------------------
#=begin
def process_escape_character(code, text, pos)
case code.upcase
when '$'
@gold_window.open
when '.'
wait(15)
when '|'
wait(60)
when '!'
input_pause
when '>'
@line_show_fast = true
when '<'
@line_show_fast = false
when '^'
@pause_skip = true
#when 'n' # 改行
# new_line
# max = MAX_LINE
# max = 14 if self.pop_character != nil
# if @line_count >= max # 行数が最大のとき
# unless @text.empty? # さらに続きがあるなら
# self.pause = true # 入力待ちを入れる
#return 1
# end
# end
#when 'S' # \S[n] (スピード変更)
# text.sub!(/\[([0-9]+)\]/, "")
# @type_wait = $1.to_i
# return 2
when 'O' # \O 文字を透明にする。
text.sub!(/\[([0-9]+)\]/, "")
contents.font.color.alpha = $1.to_i
#return 2
when 'D' #\D 文字に影をつける
contents.font.shadow ^= true
#when '18'
# name = ($game_temp.last_gain_holder.name rescue "")
# update_message_type_draw_at(name)
#when '19'
# item = ($game_temp.last_gain_material.item rescue nil)
# draw_item_name(item, @contents_x, @contents_y)
# @contents_x += 196
else
super
end
end
#=end
#--------------------------------------------------------------------------
# ● 改ページ処理
#--------------------------------------------------------------------------
alias xrxsv2_new_page new_page
def new_page(text, pos)
xrxsv2_new_page(text, pos)
update_charpop_window
end
#--------------------------------------------------------------------------
# ● 改行位置の取得
#--------------------------------------------------------------------------
#def new_line_x
# $game_message.face_name.empty? ? 0 : 112
#end
#--------------------------------------------------------------------------
# ● 改行処理
#--------------------------------------------------------------------------
alias xrxsv2_new_line_x new_line_x
def new_line
xrxsv2_new_line
set_align
end
#--------------------------------------------------------------------------
# 位置揃え
#--------------------------------------------------------------------------
def set_align
w = @line_widths[@line_count].to_i
a = @line_aligns[@line_count]
case a
when CENTER
@contents_x = @contents_x + ((contents.width - @contents_x) - w) / 2
when RIGHT
@contents_x = contents.width - w
end
end
#--------------------------------------------------------------------------
# ● ファイバーのメイン処理 ☆再定義
#--------------------------------------------------------------------------
def fiber_main
$game_message.visible = true
update_background
update_placement
loop do
process_all_text if $game_message.has_text?
process_input
$game_message.clear
@gold_window.close
process_hold #ホールドウィンドウの処理。
Fiber.yield
break unless text_continue?
end
close_and_wait
$game_message.visible = false
@fiber = nil
end
#--------------------------------------------------------------------------
# 定数
#--------------------------------------------------------------------------
AUTO = 0
LEFT = 1
CENTER = 2
RIGHT = 3
end
#==============================================================================
# アクティブイベント取得
#==============================================================================
class Game_Interpreter
attr_reader :event_id
end
#==============================================================================
# 各種機能の追加 - キャラポップ/ネーム/ホールド
#==============================================================================
class Window_Message < Window_Base
#--------------------------------------------------------------------------
# ● カーソルの更新 *
#--------------------------------------------------------------------------
def update_cursor
if @index >= 0
x = ($game_message.face_name.empty? ? 0 : 112)
y = ($game_message.choice_start + @index) * WLH - 1
w = contents.width - x
if self.pop_character != nil
x += 28
w -= 20
end
self.cursor_rect.set(x, y, w, WLH)
else
self.cursor_rect.empty
end
end
#--------------------------------------------------------------------------
# キャラクターの取得
# parameter : パラメータ
#--------------------------------------------------------------------------
def get_character(parameter)
# パラメータで分岐
case parameter
when -1 # プレイヤー
return $game_player
when 0 # 現在アクティブなイベント
id = $game_map.interpreter.event_id
events = $game_map.events
return events == nil ? nil : events[id]
else # 特定のイベント
events = $game_map.events
return events == nil ? nil : events[parameter]
end
end
#--------------------------------------------------------------------------
# (メッセージ終了時)ホールドの処理
#--------------------------------------------------------------------------
def process_hold
if @window_hold
@held_windows.push(Window_Copy.new(self))
@held_windows.push(Window_Copy.new(@name_window))
@held_windows.push(Sprite_Copy.new(@name_sprite))
@held_windows.push(Sprite_Copy.new(@back_sprite))
for sprite in @extra_sprites
next if sprite.disposed?
@held_windows.push(Sprite_Copy.new(sprite))
end
@extra_sprites.clear
self.openness = 0
#@name_window.openness = 0
@back_sprite.visible = false
else
@held_windows.each {|object| object.dispose}
@held_windows.clear
end
#@name_window.close
#@name_sprite.visible = false
end
#--------------------------------------------------------------------------
# キャラポップ位置の設定と取得
#--------------------------------------------------------------------------
def pop_character=(character_id)
@pop_character = character_id
end
def pop_character
return @pop_character
end
#--------------------------------------------------------------------------
# キャラポップ時のウィンドウリサイズ
#--------------------------------------------------------------------------
def reszie_window_for_pop
#キャラポップ
if self.pop_character != nil
max_x = @line_widths.max.to_i
n = max_x + 32
n += $game_message.face_name.empty? ? 0 : 122
m = $game_message.face_name.empty? ? 0 : 96
w = @name_sprite.bitmap.width
#self.width = [n, w].max
self.width = max_width
#self.height = [@lines_max * line_height, m].max + 32
self.height = [@all_texts.size * line_height, m].max + 32
create_contents
update_charpop_window
elsif @info_mode
@line_aligns[0] = CENTER
self.x = - 8
self.width = Graphics.width + 16
self.height = 56
create_contents
else
self.x = 0
self.width = Graphics.width
self.height = MAX_LINE * line_height + 32
update_placement #位置情報修正。
create_contents
end
end
#--------------------------------------------------------------------------
# ● 背景スプライトの作成
#--------------------------------------------------------------------------
alias xrxsv2_create_back_sprite create_back_sprite
def create_back_sprite
xrxsv2_create_back_sprite
@back_sprite.zoom_x = 1.0 * Graphics.width / @back_sprite.bitmap.width
@name_window = Window_Base.new(0,0,112,36)
@name_window.visible = false
@name_sprite = Sprite.new
@name_sprite.bitmap = Bitmap.new(32,32)
@name_sprite.visible = false
self.x = self.x
self.y = self.y
self.z = self.z
@held_windows = []
@extra_sprites = []
end
#--------------------------------------------------------------------------
# ● 背景スプライトの解放
#--------------------------------------------------------------------------
alias xrxsv2_dispose_back_sprite dispose_back_sprite
def dispose_back_sprite
xrxsv2_dispose_back_sprite
@name_window.dispose if @name_window != nil #メニュー画面を出そうとするとエラー?
@name_sprite.dispose if @name_sprite != nil
for window in @held_windows
window.dispose
end
end
#--------------------------------------------------------------------------
# ● 背景スプライトの更新
#--------------------------------------------------------------------------
alias xrxsv2_update_back_sprite update_back_sprite
def update_back_sprite
@name_window.update
xrxsv2_update_back_sprite
update_charpop_window
end
#--------------------------------------------------------------------------
# ウィンドウの位置と不透明度の設定 (キャラポップ)
#--------------------------------------------------------------------------
def update_charpop_window
if self.pop_character
character = get_character(self.pop_character)
return if character == nil
# [X座標]
n = self.width / 2
n = [n, @name_skin.width + 16].max if @current_name != nil
w = @name_sprite.bitmap.width
x = character.screen_x - [[n, w].max, self.width - 32].min
# [Y座標]
if self.pop_character == 0 and POP_DIRECTION #イベントの方向を考慮。
if character.direction == 2 #下向き
@position = 0 #上にポップ
elsif character.direction == 8 #上向き
@position = 2 #下にポップ
end
end
case @position
when 0
y = character.screen_y - CHARPOP_HEIGHT - self.height
else
y = character.screen_y + 16
end
x_max = Graphics.width - 4 - self.width
x_min = 4
y_max = Graphics.height - self.height
y_min = 4
self.x = [[x, x_max].min, x_min].max
self.y = [[y, y_max].min, y_min].max
end
end
#--------------------------------------------------------------------------
# 位置の連動
#--------------------------------------------------------------------------
def x=(n)
super
if @name_window
@name_window.x = n + NAME_WINDOW_OFFSET_X
@name_sprite.x = n + NAME_WINDOW_OFFSET_X + 8
end
end
def y=(n)
super
if @name_window
@name_window.y = n + NAME_WINDOW_OFFSET_Y
@name_sprite.y = n + NAME_WINDOW_OFFSET_Y + 2
end
end
def z=(n)
super
if @name_window
@name_window.z = n + 11#1 テールの上に表示されるので、Zを水増しする。
@name_sprite.z = n + 12#2
end
end
#--------------------------------------------------------------------------
# ● ファイバーのメイン処理
#--------------------------------------------------------------------------
def fiber_main_namewin
fiber_main_namewin_default
@name_window.openness = 0
@name_sprite.bitmap.clear
$name = ""
end
alias :fiber_main_namewin_default :fiber_main
alias :fiber_main :fiber_main_namewin
end
#==============================================================================
# 伸縮対応
#==============================================================================
class Window_Message < Window_Base
#--------------------------------------------------------------------------
# ● ウィンドウの背景と位置の設定 [再定義]
#--------------------------------------------------------------------------
def reset_window
@background = $game_message.background
@position = $game_message.position
if @background == 0 # 通常ウィンドウ
self.opacity = 255
else # 背景を暗くする、透明にする
self.opacity = 0
end
case @position
when 0 # 上
self.y = 0
@gold_window.y = 360
when 1 # 中
self.y = (Graphics.height - self.height) / 2
@gold_window.y = 0
when 2 # 下
self.y = Graphics.height - self.height
@gold_window.y = 0
end
end
end
#==============================================================================
# □ Window_Copy
#------------------------------------------------------------------------------
# 指定のウィンドウのコピーを作成します。
#==============================================================================
class Window_Copy < Window_Base
#--------------------------------------------------------------------------
# ○ オブジェクト初期化
#--------------------------------------------------------------------------
def initialize(window)
super(window.x, window.y, window.width, window.height)
self.contents = window.contents.dup unless window.contents.nil?
self.opacity = window.opacity
self.back_opacity = window.back_opacity
self.z = window.z - 3
self.visible = window.visible
end
end
#==============================================================================
# □ Sprite_Copy
#------------------------------------------------------------------------------
# 指定のスプライトのコピーを作成します。
#==============================================================================
class Sprite_Copy < Sprite
#--------------------------------------------------------------------------
# ○ オブジェクト初期化
#--------------------------------------------------------------------------
def initialize(sprite)
super()
self.bitmap = sprite.bitmap.dup unless sprite.bitmap.nil?
self.opacity = sprite.opacity
self.x = sprite.x
self.y = sprite.y
self.z = sprite.z - 3
self.ox = sprite.ox
self.oy = sprite.oy
self.zoom_x = sprite.zoom_x
self.visible = sprite.visible
end
end
#■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□
#■吹きだしテールの表示ルーチン。
#■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□
#==============================================================================
# +++ 「+ふきだし表示」VX +++
# by パラ犬 http://2d6.parasite.jp/
# ×
# row http://xms.rdy.jp/
#
# publish 2010/ 3/ 2
# update -
#
#------------------------------------------------------------------------------
# ほぼどんなメッセージウィンドウに対しても後付け可能な「ふきだし表示」です。
# また、テール部分のみの自動追尾機能を持ちます。
# ふきだし表示をするには、
# テール用画像「Window-top」「Window-under」を
# 「Graphics/System」フォルダにインポートしておく必要があります。
#==============================================================================
# ■ Window_Message
#==============================================================================
class Window_Message < Window_Base
#--------------------------------------------------------------------------
# ● メッセージの開始
#--------------------------------------------------------------------------
alias parashelf_update_all_windows update_all_windows
def update_all_windows
parashelf_update_all_windows
update_tail
end
#--------------------------------------------------------------------------
# クローズ [オーバーライド]
#--------------------------------------------------------------------------
def close
super
del_tail
@name_window.close if @name_window != nil #ネームウィンドウのクローズ動作。
end
#--------------------------------------------------------------------------
# ● 背景スプライトの更新
#--------------------------------------------------------------------------
alias parashelf_update_back_sprite update_back_sprite
def update_back_sprite
parashelf_update_back_sprite
update_tail
end
#--------------------------------------------------------------------------
# ○ フレーム更新 (ふきだしテールの更新)
#--------------------------------------------------------------------------
def update_tail
# ふきだしモードではイベントの動きに追従
if $mes_id != nil and @tail != nil
tale_pos = get_tale_pos
@tail.x = tale_pos[0]
@tail.y = tale_pos[1]
update_tail_bitmap
end
end
##--------------------------------------------------------------------------
# ○ ふきだしテールの画像を更新。
#--------------------------------------------------------------------------
def update_tail_bitmap
skin = "Window"
if $win_x != nil
if $win_x > 0
@tail.bitmap = Cache.system(skin + "-right")
elsif $win_x < 0
@tail.bitmap = Cache.system(skin + "-left")
else
case @position
when 0 # 上
@tail.bitmap = Cache.system(skin + "-top")
when 2 # 下
@tail.bitmap = Cache.system(skin + "-under")
end
end
else
case @position
when 0 # 上
@tail.bitmap = Cache.system(skin + "-top")
when 2 # 下
@tail.bitmap = Cache.system(skin + "-under")
end
end
# 可視状態
if self.visible == true
@tail.visible = self.openness == 255
else
@tail.visible = false
end
end
#--------------------------------------------------------------------------
# ○ テールの位置を計算
#--------------------------------------------------------------------------
def get_tale_pos
if defined?($game_system.show_stand_picture) #A1立ち絵スクリプトを入れている。
if $game_system.show_stand_picture #立ち絵on
pos = get_tale_pos_stand_pic
else
pos = get_tale_pos_normal
end
else
pos = get_tale_pos_normal
end
return pos
end
#--------------------------------------------------------------------------
# ○ テールの位置を計算/立ち絵使用時。※NAME_CHANGEの編集必須。
#--------------------------------------------------------------------------
def get_tale_pos_stand_pic
if $game_message.face_name != "" and @tail != nil
name = A1_System::StandPicture::NAME_CHANGE[$game_message.face_name]
chara = name[$game_message.face_index][0]
if @stand_pic[chara] != nil #立ち絵無しの場合通常通り。
x = @stand_pic[chara].pic_sprite.x + @stand_pic[chara].pic_sprite.width / 2
y = get_tale_pos_normal_updown
update_tail_bitmap
else
return get_tale_pos_normal #立ち絵が見つからない場合は通常通り。
end
else
return get_tale_pos_normal #立ち絵が見つからない場合は通常通り。
end
return [x,y]
end
#--------------------------------------------------------------------------
# ○ テールの位置を計算/立ち絵未使用時。
#--------------------------------------------------------------------------
def get_tale_pos_normal
if $mes_id == (-2) #左右の場合は高さはウィンドウ中心。上下ならやや左に配置。
if $win_x != nil
if $win_x > 0
x = $win_x - @tail.width / 2
y = self.y + self.height / 2 - @tail.height / 2
elsif $win_x < 0
x = self.width - @tail.width / 2
y = self.y + self.height / 2 - @tail.height / 2
else
x = MINAS_TWE_X_POS
y = get_tale_pos_normal_updown
end
else
x = MINAS_TWE_X_POS
y = get_tale_pos_normal_updown
end
elsif $mes_id <= (-3) #左右の場合は高さはウィンドウ中心。上下ならやや左に配置。
if $win_x != nil
if $win_x > 0
x = $win_x - @tail.width / 2
y = self.y + self.height / 2
elsif $win_x < 0
x = self.width - @tail.width / 2
y = self.y + self.height / 2
else
x = MINAS_THREE_X_POS
y = get_tale_pos_normal_updown
end
else
x = MINAS_THREE_X_POS
y = get_tale_pos_normal_updown
end
else
character = get_character($mes_id)
x = [[character.screen_x - 16, self.x].max, self.x + self.width - 32].min
if $win_x != nil
if $win_x > 0
x = $win_x - @tail.width / 2
y = character.screen_y
elsif $win_x < 0
x = self.width
y = character.screen_y
else
y = get_tale_pos_normal_updown
end
else
y = get_tale_pos_normal_updown
end
end
return [x, y]
end
#--------------------------------------------------------------------------
# ○ テールが上下の時、かつ[-2][-3]でない時のy座標の取得。
#--------------------------------------------------------------------------
def get_tale_pos_normal_updown
case @position
when 0
y = self.y + self.height - @tail.height / 2
else
y = self.y - @tail.height / 2
end
return y
end
#--------------------------------------------------------------------------
# ○ ふきだしを破棄
#--------------------------------------------------------------------------
def del_tail
if @tail != nil
@tail.dispose
@tail = nil
end
end
end
#
# ▼▲▼ XRXS 9拡張CO-X. ふきだし自動設定 ▼▲▼
#==============================================================================
# ■ Window_Message
#==============================================================================
class Window_Message < Window_Base
#--------------------------------------------------------------------------
# ○ ポップキャラクターの設定
#--------------------------------------------------------------------------
def pop_character=(character_id)
@pop_character = character_id
$mes_id = character_id
end
#--------------------------------------------------------------------------
# ○ テールキャラクターの設定
#--------------------------------------------------------------------------
def tail_character=(character_id)
#@pop_character = character_id
$mes_id = character_id
end
end
#==============================================================================
# ■ Scene_Menu
#------------------------------------------------------------------------------
# メニューを開いてからウィンドウが出るとネームウィンドウが表示される不具合修正。
#==============================================================================
#class Scene_Menu < Scene_MenuBase
# def terminate_hukidasi_menyu
# @name_window.openness = 0 if @name_window != nil
# terminate_hukidasi_menyu_default
# end
# alias :terminate_hukidasi_menyu_default :terminate
# alias :terminate :terminate_hukidasi_menyu
#end
#■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□
#■ウィンドウ非表示ルーチン
#■吹きだしテールとネームウィンドウに対応。
#■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□
#==============================================================================
# L(キーボードのQ)を押すと、メッセージウィンドウを表示?非表示
#==============================================================================
class Window_Message < Window_Base
def update_winoff
unless $game_party.in_battle #バトル中は無効。
if Input.trigger?(Input::L)
if self.visible == true
self.visible = false
@tail.visible = false if @tail != nil
else
self.visible = true
end
if @name_window != nil
if @name_window.visible == false and $name != nil and $name != ""
@name_window.visible = true
@name_sprite.visible = true
else
@name_window.visible = false
@name_sprite.visible = false
end
end
elsif Input.trigger?(Input::C) or Input.trigger?(Input::B)
self.visible = true if self.visible == false
@tail.visible = true if @tail != nil and @tail.visible == false
if @name_window != nil and $name != nil
if $name != ""
@name_window.visible = true
@name_sprite.visible = true
end
end
end
end
update_winoff_default
end
alias :update_winoff_default :update
alias :update :update_winoff
end
#■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□
#■ウィンドウ表示位置指定ルーチン
#■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□■□
#===========================================================================
#イベントコマンド「スクリプト」を使い、
#$win_x=100
#$win_y=100
#と入力すれば、ウィンドウを(100、100)の位置に表示します。
#使わない時は
#$win_x=nil
#などとnilを入力しておいてください。
#===========================================================================
class Window_Message < Window_Base
#--------------------------------------------------------------------------
# ● ウィンドウの背景と位置の設定 [再定義]
#--------------------------------------------------------------------------
def update_placement_position
update_placement_position_default
if $win_x != nil
if $win_x > 0
self.x = $win_x
self.width -= $win_x
else
self.x = 0
self.width += $win_x
end
end
if $win_y != nil
self.y = $win_y
end
end
alias_method :update_placement_position_default, :update_placement
alias_method :update_placement, :update_placement_position
end
#==============================================================================
# ■ SceneManager
#------------------------------------------------------------------------------
# シーン遷移のさい、テールを破棄する。
#==============================================================================
module SceneManager
#--------------------------------------------------------------------------
# ● 呼び出し
#--------------------------------------------------------------------------
def self.call_sceman_hukidasi(scene_class)
if defined?(self.scene.message_window)
#self.scene.message_window.del_tail if self.scene.message_window.tail != nil
end
@stack.push(@scene)
@scene = scene_class.new
end
#--------------------------------------------------------------------------
# ● クラスメソッドのエイリアス
#--------------------------------------------------------------------------
class << self
alias :call_sceman_hukidasi_default :call
alias :call :call_sceman_hukidasi
end
end