赞 | 153 |
VIP | 10 |
好人卡 | 39 |
积分 | 93 |
经验 | 146191 |
最后登录 | 2024-5-6 |
在线时间 | 2504 小时 |
Lv4.逐梦者
- 梦石
- 0
- 星屑
- 9280
- 在线时间
- 2504 小时
- 注册时间
- 2011-5-20
- 帖子
- 15389
|
- =begin
- by 薄凉看客
- 感谢 fux2 的帮助!
- 改进:Chd114
- 使用方法
- blkk_text(rect, str, align)
- blkk_text(x, y, width, height, str, align)
- 若str不是字符串对象,则会先调用 to_s 方法转换成字符串
- str所支持的控制符:
- !N[n] 显示ID为n的角色名
- !V[n] 显示n号变量值
- !C[n] 文字颜色改变(draw_color可自定义颜色)
- !II[n] 显示n号物品的图标
- !IW[n] 显示n号武器的图标
- !IA[n] 显示n号防具的图标
- !IS[n] 使用n号技能的图标
- !换行 手动换行
- !S[n] 使用n号字体大小
- =end
- # 即无视draw_text的参数width和height
- # width = 字符本身的宽度 height = 32
- $忽略默认宽高 = false
- # 彩色底 控制条件 建议命令窗口中使用
- $color_floor = false
- class Bitmap
- alias text_old draw_text unless method_defined? :text_old
- def draw_text(*arg)
- if arg[0].is_a?(Rect)
- color_coo = self.font.color.clone
- self.font.color = Color.new(0, 0, 0)
- rect_x = arg[0].x
- rect_y = arg[0].y
- rect_width = arg[0].width
- rect_height = arg[0].height
- rect = Rect.new(rect_x, rect_y, rect_width, rect_height)
- for i in 1..4
- rect.set(rect_x + 1, rect_y, rect_width, rect_height) if i == 1
- rect.set(rect_x - 1, rect_y, rect_width, rect_height) if i == 2
- rect.set(rect_x, rect_y + 1, rect_width, rect_height) if i == 3
- rect.set(rect_x, rect_y - 1, rect_width, rect_height) if i == 4
- text_old(rect, arg[1], arg[2] == nil ? 0 : arg[2])
- end
- self.font.color = color_coo
- rect.set(rect_x, rect_y, rect_width, rect_height)
- text_old(rect, arg[1], arg[2] == nil ? 0 : arg[2])
- else
- color_coo = self.font.color.clone
- self.font.color = Color.new(0, 0, 0)
- text_old(
- arg[0] + 1, arg[1], arg[2], arg[3], arg[4], arg[5] == nil ? 0 : arg[5])
- text_old(
- arg[0] - 1, arg[1], arg[2], arg[3], arg[4], arg[5] == nil ? 0 : arg[5])
- text_old(
- arg[0], arg[1] + 1, arg[2], arg[3], arg[4], arg[5] == nil ? 0 : arg[5])
- text_old(
- arg[0], arg[1] - 1, arg[2], arg[3], arg[4], arg[5] == nil ? 0 : arg[5])
- self.font.color = color_coo
- text_old(
- arg[0], arg[1], arg[2], arg[3], arg[4], arg[5] == nil ? 0 : arg[5])
- end
- end
- def blkk_text(*arg)
- if arg[0].is_a?(Rect)
- rect_x = arg[0].x
- rect_y = arg[0].y
- rect_width = arg[0].width
- rect_height = arg[0].height
- rect = Rect.new(rect_x, rect_y, rect_width, rect_height)
- text = arg[1]
- align = arg[2] == nil ? 0 : arg[2]
- else
- x,y,width,height,text = arg[0],arg[1],arg[2],arg[3],arg[4]
- align = arg[5] == nil ? 0 : arg[5]
- end
- size_copy = self.font.size
- color_coo = self.font.color.clone
- if $color_floor
- ca = [[255, 128][rand(2)], [255, 128][rand(2)], [255, 128][rand(2)]]
- for s in 0...width
- self.fill_rect(x + s, y, 1, height, Color.new(
- ca[0], ca[1], ca[2], 255 - s * 320 / width))
- end
- end
- copy_text = text.clone
- i_rect = Rect.new(0, 0, 24, 24)
- begin
- text = copy_text
- text.gsub!(/\![V]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
- end until copy_text == text
- text.gsub!(/\![N]\[([0-9]+)\]/) do
- $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
- end
- text.gsub!(/\\\\/) { "\000" }
- text.gsub!(/\![C]\[([0-9]+)\]/) { "\001[#{$1}]" }
- text.gsub!(/\![II]\[([0-9]+)\]/) { "\002[#{$1}]" }
- text.gsub!(/\![IW]\[([0-9]+)\]/) { "\003[#{$1}]" }
- text.gsub!(/\![IA]\[([0-9]+)\]/) { "\004[#{$1}]" }
- text.gsub!(/\![IS]\[([0-9]+)\]/) { "\005[#{$1}]" }
- text.gsub!(/\![S]\[([0-9]+)\]/) { "\006[#{$1}]" }
- while ((c = text.slice!(/./m)) != nil)
- if c == "\000"
- c = "\\"
- end
- if c == "\001"
- text.sub!(/\[([0-9]+)\]/, "")
- color_coo = draw_color($1.to_i)
- next
- end
- if c == "\002"
- text.sub!(/\[([0-9]+)\]/, "")
- unless arg[0].is_a?(Rect)
- begin
- self.blt(
- x, y + 3, RPG::Cache.icon($data_items[$1.to_i].icon_name), i_rect)
- x += 24
- rescue
- icon_index = $data_items[$1.to_i].icon_index
- bitmap = Cache.system("Iconset")
- rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
- self.blt(x, y + 3, bitmap, rect)
- end
- else
- begin
- self.blt(
- rect_x, rect_y + 3, RPG::Cache.icon(
- $data_items[$1.to_i].icon_name), i_rect)
- rect_x += 24
- rescue
- icon_index = $data_items[$1.to_i].icon_index
- bitmap = Cache.system("Iconset")
- rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
- self.blt(x, y + 3, bitmap, rect)
- end
- end
- next
- end
- if c == "\003"
- text.sub!(/\[([0-9]+)\]/, "")
- unless arg[0].is_a?(Rect)
- begin
- self.blt(
- x, y + 3, RPG::Cache.icon(
- $data_weapons[$1.to_i].icon_name), i_rect)
- x += 24
- rescue
- icon_index = $data_weapons[$1.to_i].icon_index
- bitmap = Cache.system("Iconset")
- rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
- self.blt(x, y + 3, bitmap, rect)
- end
- else
- begin
- self.blt(
- rect_x, rect_y + 3, RPG::Cache.icon(
- $data_weapons[$1.to_i].icon_name), i_rect)
- rect_x += 24
- rescue
- icon_index = $data_weapons[$1.to_i].icon_index
- bitmap = Cache.system("Iconset")
- rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
- self.blt(x, y + 3, bitmap, rect)
- end
- end
- next
- end
- if c == "\004"
- text.sub!(/\[([0-9]+)\]/, "")
- unless arg[0].is_a?(Rect)
- begin
- self.blt(
- x, y + 3, RPG::Cache.icon(
- $data_armors[$1.to_i].icon_name), i_rect)
- x += 24
- rescue
- icon_index = $data_armors[$1.to_i].icon_index
- bitmap = Cache.system("Iconset")
- rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
- self.blt(x, y + 3, bitmap, rect)
- end
- else
- begin
- self.blt(
- rect_x, rect_y + 3, RPG::Cache.icon(
- $data_armors[$1.to_i].icon_name), i_rect)
- rect_x += 24
- rescue
- icon_index = $data_armors[$1.to_i].icon_index
- bitmap = Cache.system("Iconset")
- rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
- self.blt(x, y + 3, bitmap, rect)
- end
- end
- next
- end
- if c == "\005"
- text.sub!(/\[([0-9]+)\]/, "")
- unless arg[0].is_a?(Rect)
- begin
- self.blt(
- x, y + 3, RPG::Cache.icon(
- $data_skills[$1.to_i].icon_name), i_rect)
- x += 24
- rescue
- icon_index = $data_skills[$1.to_i].icon_index
- bitmap = Cache.system("Iconset")
- rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
- self.blt(x, y + 3, bitmap, rect)
- end
- else
- begin
- self.blt(
- rect_x, rect_y + 3, RPG::Cache.icon(
- $data_skills[$1.to_i].icon_name), i_rect)
- rect_x += 24
- rescue
- icon_index = $data_skills[$1.to_i].icon_index
- bitmap = Cache.system("Iconset")
- rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
- self.blt(x, y + 3, bitmap, rect)
- end
- end
- next
- end
- if c == "\006"
- text.sub!(/\[([0-9]+)\]/, "")
- self.font.size = $1.to_i
- next
- end
- self.font.color = Color.new(0, 0, 0)
- if $忽略默认宽高
- self.font.color = color_coo
- if arg[0].is_a?(Rect)
- draw_text(rect.set(
- rect_x, rect_y, self.text_size(c).width, 32), c, align)
- rect_x += self.text_size(c).width
- else
- draw_text(x, y, self.text_size(c).width, 32, c, align)
- x += self.text_size(c).width
- end
- else
- self.font.color = color_coo
- if arg[0].is_a?(Rect)
- draw_text(rect.set(
- rect_x, rect_y, rect_width, rect_height), c, align)
- rect_x += self.text_size(c).width
- else
- draw_text(x, y, width, height, c, align)
- x += self.text_size(c).width
- end
- end
- end
- self.font.size = size_copy
- end
- def draw_color(n)
- return Color.new(255, 255, 255, 255) if n == 0
- return Color.new(128, 128, 255, 255) if n == 1
- return Color.new(255, 128, 128, 255) if n == 2
- return Color.new(128, 255, 128, 255) if n == 3
- return Color.new(128, 255, 255, 255) if n == 4
- return Color.new(255, 128, 255, 255) if n == 5
- return Color.new(255, 255, 128, 255) if n == 6
- return Color.new(192, 192, 192, 255) if n == 7
- return normal_color
- end
- end
- class Bitmap
- alias blkk_text_old blkk_text
- def blkk_text(*arg)
- if arg[0].is_a?(Rect)
- rect_x = arg[0].x
- rect_y = arg[0].y
- rect_width = arg[0].width
- rect_height = arg[0].height
- rect = Rect.new(rect_x, rect_y, rect_width, rect_height)
- unless arg[1].is_a?(String)
- arg[1] = arg[1].to_s
- end
- y_plus = 0
- arg[1].split("!换行").each{
- |i| blkk_text_old(rect.set(
- rect_x, rect_y + y_plus, rect_width, rect_height),
- i, arg[2] == nil ? 0 : arg[2]) ; y_plus += 32}
- else
- unless arg[4].is_a?(String)
- arg[4] = arg[4].to_s
- end
- y_plus = 0
- arg[4].split("!换行").each{
- |i| blkk_text_old(
- arg[0], arg[1] + y_plus, arg[2], arg[3], i, arg[5] == nil ? 0 : arg[5]) ;
- y_plus += 32}
- end
- end
- end
复制代码 |
|