=begin
说明:
01 把字幕强化了,添加对话框的一些功能到里头去。
\f[字体]:更改字体
\c[颜色]:更改颜色,与默认对话框相同
\s[字体大小]:更改字体大小
\p[图片名称]:显示在picture文件夹下指定的图片
<b>字幕</b>:被包围的字将会变成粗体
<i>字幕</i>:被包围的字将会变成斜体
<left>:该行左边对齐
<center>:该行中间对齐
<right>:该行右边对齐
02 调用方法:(1) $scene = Scene_Credit.new
(2) $scene = Scene_Credit.new("文字")
(1) 为默认调用发,字幕会直接读取脚本里设定好的字幕
(2) 为更改字幕,字幕将变成设定的文字,支持\txt[TXT名称],将会读取
Credit文件夹底下的指定TXT,TXT格式参考范例。
03 其他玩转设置参考范例。
=end
module CREDIT
# 字幕
Subtitle=<<_end_
最普通的字幕显示
更改字幕的显示字体\\f[楷体]楷体\\f[微软雅黑]微软雅黑\\f[黑体]
更改\\c[1]字幕\\c[2]显示\\c[3]颜色\\c[0]
\\s[16]更改\\s[48]字体的显示\\s[16]大小\\s[22]
图片显示:
\\p[picture]
<b>粗体字幕</b>
<i>斜体字幕</i>
<left>左边(上边)对齐
<center>中间(中间)对齐
<right>右边(下边)对齐
_end_
# 字幕移动方式 y 垂直移动,x 横着移动
Subtitle_move = "y"
# 允许按键推出
AllowButtonExit = true
# 边距
MarginX = 20
MarginY = 20
# 背景
Background = "" # 空着会调用背景颜色
BackgroundRepeat = false # 背景循环 (背景移动时强行打开)
BackgroundColor = Color.new(0,0,0) # 背景颜色
BackgroundMoveX = 0 # 背景移动X值
BackgroundMoveY = 0 # 背景移动Y值
# 背景声音 放 "" 为没有声音
BackgroundBGM = "017-Theme06"
# 默认字体
Font_name = "黑体" # 字体
Font_size = 22 #大小
Font_color = Color.new(255,255,255) # 颜色
Font_bold = false # 是否粗体
Font_italic = false # 是否斜体
# 默认行高
DefaultLineHeight = 32
# 退出后回到的场景
ExitScene = Scene_Map.new
end
class Scene_Credit
include CREDIT
def initialize(text = nil)
if text == nil
@text = Subtitle
else
text.gsub!(/\\[Tt][Xx][Tt]\[(\w+)\]/){"\001[#{$1}]"}
new_text = ""
while ((c = text.slice!(/./m)) != nil)
if c == "\001"
text.sub!(/\[(\w+)\]/,"")
name = "Credit/" + $1 + ".txt"
file = File.open(name)
a = file.readlines
for i in 1...a.size
new_text += a[i]
end
file.close
else
new_text += c
end
end
@text = new_text
end
end
def main
initialize_font_setting
if BackgroundRepeat or (BackgroundMoveX + BackgroundMoveY != 0)
@background = Plane.new
else
@background = Sprite.new
end
if Background != ""
@background.bitmap = RPG::Cache.picture(Background)
else
@background.bitmap = Bitmap.new(640,480)
@background.bitmap.fill_rect(0,0,640,480,BackgroundColor)
end
@subtitle = Sprite.new
process_credit(@text)
if BackgroundBGM != ""
Audio.bgm_play("Audio/BGM/#{BackgroundBGM}")
end
Graphics.transition
loop do
Graphics.update
Input.update
update
break if $scene != self
end
@subtitle.dispose
@background.dispose
end
def update
update_subtitle
if @background.is_a?(Plane)
@background.ox += BackgroundMoveX
@background.oy += BackgroundMoveY
end
if AllowButtonExit
if Input.trigger?(Input::B)
exit_scene
end
end
end
def update_subtitle
if Subtitle_move == "y"
@subtitle.y -= 1
exit_scene if @subtitle.y <= (-20 - @subtitle.bitmap.height)
else
@subtitle.x += 1
exit_scene if @subtitle.x >= (660)
end
end
def exit_scene
Audio.bgm_fade(800)
$scene = ExitScene
end
def initialize_font_setting
@align = 0
@font_size = Font_size
@font_name = Font_name
@font_color = Font_color
@font_bold = Font_bold
@font_italic = Font_italic
end
def process_credit(text)
text = text.split("\n")
if Subtitle_move == "y"
total_height = 0
for line in text
w,h = calc_line_rect(line)
total_height += h
end
initialize_font_setting
bitmap = Bitmap.new(640-2*MarginX,total_height)
y = 0
for line in text
w,h = calc_line_rect(line)
bitmap2 = create_line_bitmap(line,w,h)
rect = Rect.new(0,0,bitmap2.width,bitmap2.height)
x = @align == 0 ? 0 : @align == 1 ? (bitmap.width/2-bitmap2.width/2) : (bitmap.width-bitmap2.width)
bitmap.blt(x,y,bitmap2,rect)
y += h
end
@subtitle.bitmap = bitmap
@subtitle.x = MarginX
@subtitle.y = 481
else
total_width = 0
for line in text
w,h = calc_line_rect(line)
total_width += w
end
initialize_font_setting
bitmap = Bitmap.new(total_width,480-MarginY*2)
x = total_width
for line in text
w,h = calc_line_rect(line)
x -= w
bitmap2 = create_line_bitmap(line,w,h)
rect = Rect.new(0,0,bitmap2.width,bitmap2.height)
y = @align == 0 ? 0 : @align == 1 ? (bitmap.height/2-bitmap2.height/2) : (bitmap.height-bitmap2.height)
bitmap.blt(x,y,bitmap2,rect)
end
@subtitle.bitmap = bitmap
@subtitle.x = -total_width
@subtitle.y = MarginY
end
end
def calc_line_rect(line_text)
temp_bitmap = Bitmap.new(32,32)
temp_bitmap.font.name = @font_name
temp_bitmap.font.size = @font_size
temp_bitmap.font.color = @font_color
temp_bitmap.font.bold = @font_bold
temp_bitmap.font.italic = @font_italic
line = line_text.dup
height = 0
width = 0
line.gsub!(/\<[Cc][Ee][Nn][Tt][Ee][Rr]\>/){""}
line.gsub!(/\<[Rr][Ii][Gg][Hh][Tt]\>/){""}
line.gsub!(/\<[Ll][Ee][Ff][Tt]\>/){""}
line.gsub!(/\\\\/){"\000"}
line.gsub!(/\\[Ff]\[(\w+)\]/){"\001[#{$1}]"}
line.gsub!(/\\[Cc]\[(\d+)\]/){"\002[#{$1}]"}
line.gsub!(/\\[Ss]\[(\d+)\]/){"\003[#{$1}]"}
line.gsub!(/\\[Pp]\[(\w+)\]/){"\004[#{$1}]"}
line.gsub!(/\<[Bb]\>/){"\201"}
line.gsub!(/\<\/[Bb]\>/){"\202"}
line.gsub!(/\<[Ii]\>/){"\203"}
line.gsub!(/\<\/[Ii]\>/){"\204"}
while ((c = line.slice!(/./m)) != nil)
if c == "\000"
c = "\\"
elsif c == "\001"
line.sub!(/\[(\w+)\]/,"")
font_name = $1 == nil ? Font_name : $1
temp_bitmap.font.name = @font_name = font_name
elsif c == "\003"
line.sub!(/\[(\d+)\]/,"")
font_size = $1 == nil ? @font_size : [[$1.to_i,16].max,96].min
temp_bitmap.font.size = @font_size = font_size
elsif c == "\004"
line.sub!(/\[(\w+)\]/,"")
bitmap_name = $1 == nil ? "" : $1
if bitmap_name != ""
_temp_bitmap = RPG::Cache.picture(bitmap_name)
if Subtitle_move == "y"
width += _temp_bitmap.width
height = _temp_bitmap.height > height ? _temp_bitmap.height : height
else
width = _temp_bitmap.width > width ? _temp_bitmap.width : width
height += _temp_bitmap.height
end
_temp_bitmap.clear
_temp_bitmap.dispose
_temp_bitmap = nil
end
elsif c == "\201"
temp_bitmap.font.bold = @font_bold = true
elsif c == "\202"
temp_bitmap.font.bold = @font_bold = false
elsif c == "\203"
temp_bitmap.font.italic = @font_italic = true
elsif c == "\204"
temp_bitmap.font.italic = @font_italic = false
else
if Subtitle_move == "y"
width += temp_bitmap.text_size(c).width
height = temp_bitmap.text_size(c).height > height ?\
temp_bitmap.text_size(c).height : height
else
width = temp_bitmap.text_size(c).width > width ?\
temp_bitmap.text_size(c).width : width
height += temp_bitmap.text_size(c).height
end
end
end
if Subtitle_move == "y"
height = DefaultLineHeight if height < DefaultLineHeight
width = 32 if width == 0
else
width = DefaultLineHeight if width < DefaultLineHeight
height = 32 if height == 0
end
temp_bitmap.clear
temp_bitmap.dispose
temp_bitamp = nil
return width,height
end
def create_line_bitmap(line,width,height)
temp_bitmap = Bitmap.new(width,height)
temp_bitmap.font.name = @font_name
temp_bitmap.font.size = @font_size
temp_bitmap.font.color = @font_color
temp_bitmap.font.bold = @font_bold
temp_bitmap.font.italic = @font_italic
x = 0
line = line.dup
line.gsub!(/\<[Cc][Ee][Nn][Tt][Ee][Rr]\>/){"\101"}
line.gsub!(/\<[Rr][Ii][Gg][Hh][Tt]\>/){"\102"}
line.gsub!(/\<[Ll][Ee][Ff][Tt]\>/){"\100"}
line.gsub!(/\\\\/){"\000"}
line.gsub!(/\\[Ff]\[(\w+)\]/){"\001[#{$1}]"}
line.gsub!(/\\[Cc]\[(\d+)\]/){"\002[#{$1}]"}
line.gsub!(/\\[Ss]\[(\d+)\]/){"\003[#{$1}]"}
line.gsub!(/\\[Pp]\[(\w+)\]/){"\004[#{$1}]"}
line.gsub!(/\<[Bb]\>/){"\201"}
line.gsub!(/\<\/[Bb]\>/){"\202"}
line.gsub!(/\<[Ii]\>/){"\203"}
line.gsub!(/\<\/[Ii]\>/){"\204"}
while ((c = line.slice!(/./m)) != nil)
if c == "\100"
@align = 0
elsif c == "\101"
@align = 1
elsif c == "\102"
@align = 2
elsif c == "\000"
c = "\\"
elsif c == "\001"
line.sub!(/\[(\w+)\]/,"")
font_name = $1 == nil ? Font_name : $1
temp_bitmap.font.name = @font_name = font_name
elsif c == "\002"
line.sub!(/\[(\d+)\]/,"")
font_color = $1 == nil ? 0 : $1.to_i
case font_color
when 1
temp_bitmap.font.color = @font_color = Color.new(128,128,255)
when 2
temp_bitmap.font.color = @font_color = Color.new(255,128,128)
when 3
temp_bitmap.font.color = @font_color = Color.new(128,255,128)
when 4
temp_bitmap.font.color = @font_color = Color.new(128,255,255)
when 5
temp_bitmap.font.color = @font_color = Color.new(255,128,255)
when 6
temp_bitmap.font.color = @font_color = Color.new(255,255,128)
when 7
temp_bitmap.font.color = @font_color = Color.new(192,192,192)
else
temp_bitmap.font.color = @font_color = Color.new(255,255,255)
end
elsif c == "\003"
line.sub!(/\[(\d+)\]/,"")
font_size = $1 == nil ? @font_size : [[$1.to_i,16].max,96].min
temp_bitmap.font.size = @font_size = font_size
elsif c == "\004"
line.sub!(/\[(\w+)\]/,"")
bitmap_name = $1 == nil ? "" : $1
if bitmap_name != ""
_temp_bitmap = RPG::Cache.picture(bitmap_name)
rect = Rect.new(0,0,_temp_bitmap.width,_temp_bitmap.height)
if Subtitle_move == "y"
temp_bitmap.blt(x,height/2-_temp_bitmap.height/2,_temp_bitmap,rect)
else
temp_bitmap.blt(width/2-_temp_bitmap.width/2,x,_temp_bitmap,rect)
end
_temp_bitmap.clear
_temp_bitmap.dispose
_temp_bitmap = nil
end
elsif c == "\201"
temp_bitmap.font.bold = @font_bold = true
elsif c == "\202"
temp_bitmap.font.bold = @font_bold = false
elsif c == "\203"
temp_bitmap.font.italic = @font_italic = true
elsif c == "\204"
temp_bitmap.font.italic = @font_italic = false
else
if Subtitle_move == "y"
temp_bitmap.draw_text(x,0,temp_bitmap.text_size(c).width,height,c)
x += temp_bitmap.text_size(c).width
else
temp_bitmap.draw_text(0,x,width,temp_bitmap.text_size(c).height,c,1)
x += temp_bitmap.text_size(c).height
end
end
end
return temp_bitmap
end
end