#===========================================================================
# * draw_text必备扩展
#===========================================================================
=begin
!c[n] #改用n号颜色 *注 颜色在color处自定
!s[n] #改用n号大小
!n[name] #改用名称为name的字体
!b0 #关闭粗体
!b1 #开启粗体
!i0 #关闭斜体
!i1 #开启斜体
i[n] #描绘id为n的物品的图标
s[n] #描绘id为n的特技的图标
w[n] #描绘id为n的武器的图标
a[n] #描绘id为n的防具的图标
l[filename] #描绘文件名为filename的图标
\\n #手动换行
其他功能——
*投影
*自动换行
=end
class Bitmap
def dl_draw_text(x, y, text)
#记录bitmap数据
name_copy = self.font.name
size_copy = self.font.size
bold_copy = self.font.bold
italic_copy = self.font.italic
color_copy = self.font.color.clone
#初始数据
text_copy = text
tx,ty = x,y
rect = Rect.new(0, 0, 24, 24)
#字体
text_copy.gsub!(/!c\[([0-9]+)\]/) { "\001[#{$1}]" }
text_copy.gsub!(/!s\[([0-9]+)\]/) { "\002[#{$1}]" }
text_copy.gsub!(/!n\[(.+)\]/) { "\003[#{$1}]" }
text_copy.gsub!(/!b0/) { "\004" }
text_copy.gsub!(/!b1/) { "\005" }
text_copy.gsub!(/!i0/) { "\006" }
text_copy.gsub!(/!i1/) { "\007" }
#图标
text_copy.gsub!(/i\[([0-9]+)\]/) { "\020[#{$1}]" }
text_copy.gsub!(/s\[([0-9]+)\]/) { "\021[#{$1}]" }
text_copy.gsub!(/w\[([0-9]+)\]/) { "\022[#{$1}]" }
text_copy.gsub!(/a\[([0-9]+)\]/) { "\023[#{$1}]" }
text_copy.gsub!(/l\[(.+)\]/) { "\025[#{$1}]" }
#其他
text_copy.gsub!(/v\[([0-9]+)\]/) { $game_variables[$1.to_i] }
text_copy.gsub!(/\\n/) { "\030" }
#颜色
color = []
color[0] = Color.new(255, 255, 255, 255)#白
color[1] = Color.new(128, 128, 255, 255)#蓝
color[2] = Color.new(255, 0, 0, 255)#(255, 0, 80, 255) #红
color[3] = Color.new(128, 255, 128, 255)#绿
color[4] = Color.new(128, 255, 255, 255)#青
color[5] = Color.new(255, 128, 255, 255)#粉红
color[6] = Color.new(255, 255, 128, 255)#黄
color[7] = Color.new(192, 192, 192, 255)#灰
color[8] = Color.new(255, 195, 105, 255)#桔色
color[9] = Color.new(207, 212, 241, 255)#紫色
while ((c = text_copy.slice!(/./m)) != nil)
#====================================
#设置字体
#====================================
#颜色
if c == "\001"
text_copy.sub!(/\[([0-9]+)\]/, "")
next if color[$1.to_i].nil?
self.font.color = color[$1.to_i]
next
end
#大小
if c == "\002"
text_copy.sub!(/\[([0-9]+)\]/, "")
self.font.size = $1.to_i
next
end
#名称
if c == "\003"
text_copy.sub!(/\[(.+)\]/, "")
self.font.name = $1 if Font.exist?($1)
next
end
#粗体关
if c == "\004"
self.font.bold = false
next
end
#粗体开
if c == "\005"
self.font.bold = true
next
end
#斜体关
if c == "\006"
self.font.italic = false
next
end
#斜体开
if c == "\007"
self.font.italic = true
next
end
#====================================
#描绘图标
#====================================
#物品
if c == "\020"
text_copy.sub!(/\[([0-9]+)\]/, "")
if !$data_items[$1.to_i].nil? and $data_items[$1.to_i].icon_name != ""
next if tx + 24 > self.width - 32
bitmap = RPG::Cache.icon($data_items[$1.to_i].icon_name)
self.blt(tx, ty, bitmap, rect)
tx += 24
end
next
end
#特技
if c == "\021"
text_copy.sub!(/\[([0-9]+)\]/, "")
if !$data_skills[$1.to_i].nil? and $data_skills[$1.to_i].icon_name != ""
next if tx + 24 > self.width - 32
bitmap = RPG::Cache.icon($data_skills[$1.to_i].icon_name)
self.blt(tx, ty, bitmap, rect)
tx += 24
end
next
end
#武器
if c == "\022"
text_copy.sub!(/\[([0-9]+)\]/, "")
if !$data_weapons[$1.to_i].nil? and $data_weapons[$1.to_i].icon_name != ""
next if tx + 24 > self.width - 32
bitmap = RPG::Cache.icon($data_weapons[$1.to_i].icon_name)
self.blt(tx, ty, bitmap, rect)
tx += 24
end
next
end
#防具
if c == "\023"
text_copy.sub!(/\[([0-9]+)\]/, "")
if !$data_armors[$1.to_i].nil? and $data_armors[$1.to_i].icon_name != ""
next if tx + 24 > self.width - 32
bitmap = RPG::Cache.icon($data_armors[$1.to_i].icon_name)
self.blt(tx, ty, bitmap, rect)
tx += 24
end
next
end
#自定
if c == "\025"
text_copy.sub!(/\[(.+)\]/, "")
if $1 != ""
next if tx + 24 > self.width - 32
bitmap = RPG::Cache.icon($1)
self.blt(tx, ty, bitmap, rect)
tx += 24
end
next
end
#====================================
#其他
#====================================
#换行
if c == "\030"
ty += self.font.size
next
end
cx = self.text_size(c).width
#投影
#dl_color_copy = self.font.color.clone
#self.font.color.set(0, 0, 0)
#self.draw_text(tx+1, ty+1, cx, self.font.size, c)
#self.draw_text(tx-1, ty+1, cx, self.font.size, c)
#self.draw_text(tx+1, ty-1, cx, self.font.size, c)
#self.draw_text(tx-1, ty-1, cx, self.font.size, c)
#self.font.color = dl_color_copy
self.draw_text(tx, ty, cx, self.font.size, c)
tx += cx
#自动换行
if tx >= self.width
tx = 0
ty += self.font.size
end
end
#恢复调整
self.font.name = name_copy
self.font.size = size_copy
self.font.bold = bold_copy
self.font.italic = italic_copy
self.font.color = color_copy
end
end