设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
123
返回列表 发新帖
楼主: 恐惧剑刃
打印 上一主题 下一主题

[原创发布] draw_text必备扩展

[复制链接]

Lv4.逐梦者

梦石
0
星屑
9280
在线时间
2504 小时
注册时间
2011-5-20
帖子
15389

开拓者

21
发表于 2014-1-1 13:38:41 | 只看该作者
话说这脚本其实还有很大改进空间···比如显示角色名称、状态名称、技能等等

点评

赞同  发表于 2014-1-1 13:39
[img]http://service.t.sina.com.cn/widget/qmd/5339802982/c02e16bd/7.png
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
9280
在线时间
2504 小时
注册时间
2011-5-20
帖子
15389

开拓者

22
发表于 2014-1-1 13:43:07 | 只看该作者
  1. =begin

  2. by 薄凉看客
  3. 感谢 fux2 的帮助!
  4. 改进:Chd114

  5. 使用方法
  6. blkk_text(rect, str, align)
  7. blkk_text(x, y, width, height, str, align)

  8. 若str不是字符串对象,则会先调用 to_s 方法转换成字符串

  9. str所支持的控制符:
  10. !N[n] 显示ID为n的角色名
  11. !V[n] 显示n号变量值
  12. !C[n] 文字颜色改变(draw_color可自定义颜色)
  13. !II[n] 显示n号物品的图标
  14. !IW[n] 显示n号武器的图标
  15. !IA[n] 显示n号防具的图标
  16. !IS[n] 使用n号技能的图标
  17. !换行 手动换行
  18. !S[n] 使用n号字体大小

  19. =end

  20. # 即无视draw_text的参数width和height
  21. # width = 字符本身的宽度 height = 32
  22. $忽略默认宽高 = false

  23. # 彩色底 控制条件 建议命令窗口中使用
  24. $color_floor = false

  25. class Bitmap
  26.   alias text_old draw_text unless method_defined? :text_old
  27.   def draw_text(*arg)
  28.     if arg[0].is_a?(Rect)
  29.       color_coo = self.font.color.clone
  30.       self.font.color = Color.new(0, 0, 0)
  31.       rect_x = arg[0].x
  32.       rect_y = arg[0].y
  33.       rect_width = arg[0].width
  34.       rect_height = arg[0].height
  35.       rect = Rect.new(rect_x, rect_y, rect_width, rect_height)
  36.       for i in 1..4
  37.         rect.set(rect_x + 1, rect_y, rect_width, rect_height) if i == 1
  38.         rect.set(rect_x - 1, rect_y, rect_width, rect_height) if i == 2
  39.         rect.set(rect_x, rect_y + 1, rect_width, rect_height) if i == 3
  40.         rect.set(rect_x, rect_y - 1, rect_width, rect_height) if i == 4
  41.         text_old(rect, arg[1], arg[2] == nil ? 0 : arg[2])
  42.       end
  43.       self.font.color = color_coo
  44.       rect.set(rect_x, rect_y, rect_width, rect_height)
  45.       text_old(rect, arg[1], arg[2] == nil ? 0 : arg[2])
  46.     else
  47.       color_coo = self.font.color.clone
  48.       self.font.color = Color.new(0, 0, 0)
  49.       text_old(
  50.       arg[0] + 1, arg[1], arg[2], arg[3], arg[4], arg[5] == nil ? 0 : arg[5])
  51.       text_old(
  52.       arg[0] - 1, arg[1], arg[2], arg[3], arg[4], arg[5] == nil ? 0 : arg[5])
  53.       text_old(
  54.       arg[0], arg[1] + 1, arg[2], arg[3], arg[4], arg[5] == nil ? 0 : arg[5])
  55.       text_old(
  56.       arg[0], arg[1] - 1, arg[2], arg[3], arg[4], arg[5] == nil ? 0 : arg[5])
  57.       self.font.color = color_coo
  58.       text_old(
  59.       arg[0], arg[1], arg[2], arg[3], arg[4], arg[5] == nil ? 0 : arg[5])
  60.     end
  61.   end
  62.   def blkk_text(*arg)
  63.     if arg[0].is_a?(Rect)
  64.       rect_x = arg[0].x
  65.       rect_y = arg[0].y
  66.       rect_width = arg[0].width
  67.       rect_height = arg[0].height
  68.       rect = Rect.new(rect_x, rect_y, rect_width, rect_height)
  69.       text = arg[1]
  70.       align = arg[2] == nil ? 0 : arg[2]
  71.     else
  72.       x,y,width,height,text = arg[0],arg[1],arg[2],arg[3],arg[4]
  73.       align = arg[5] == nil ? 0 : arg[5]
  74.     end
  75.     size_copy = self.font.size
  76.     color_coo = self.font.color.clone
  77.     if $color_floor
  78.       ca = [[255, 128][rand(2)], [255, 128][rand(2)], [255, 128][rand(2)]]
  79.       for s in 0...width
  80.         self.fill_rect(x + s, y, 1, height, Color.new(
  81.         ca[0], ca[1], ca[2], 255 - s * 320 / width))
  82.       end
  83.     end
  84.     copy_text = text.clone
  85.     i_rect = Rect.new(0, 0, 24, 24)
  86.     begin
  87.       text = copy_text
  88.       text.gsub!(/\![V]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  89.     end until copy_text == text
  90.     text.gsub!(/\![N]\[([0-9]+)\]/) do
  91.       $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  92.     end
  93.     text.gsub!(/\\\\/) { "\000" }
  94.     text.gsub!(/\![C]\[([0-9]+)\]/) { "\001[#{$1}]" }
  95.     text.gsub!(/\![II]\[([0-9]+)\]/) { "\002[#{$1}]" }
  96.     text.gsub!(/\![IW]\[([0-9]+)\]/) { "\003[#{$1}]" }
  97.     text.gsub!(/\![IA]\[([0-9]+)\]/) { "\004[#{$1}]" }
  98.     text.gsub!(/\![IS]\[([0-9]+)\]/) { "\005[#{$1}]" }
  99.     text.gsub!(/\![S]\[([0-9]+)\]/) { "\006[#{$1}]" }
  100.     while ((c = text.slice!(/./m)) != nil)
  101.       if c == "\000"
  102.         c = "\\"
  103.       end
  104.       if c == "\001"
  105.         text.sub!(/\[([0-9]+)\]/, "")
  106.         color_coo = draw_color($1.to_i)
  107.         next
  108.       end
  109.       if c == "\002"
  110.         text.sub!(/\[([0-9]+)\]/, "")
  111.         unless arg[0].is_a?(Rect)
  112.           begin
  113.           self.blt(
  114.           x, y + 3, RPG::Cache.icon($data_items[$1.to_i].icon_name), i_rect)
  115.           x += 24
  116.           rescue
  117.           icon_index = $data_items[$1.to_i].icon_index
  118.           bitmap = Cache.system("Iconset")
  119.           rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  120.           self.blt(x, y + 3, bitmap, rect)
  121.           end
  122.         else
  123.           begin
  124.           self.blt(
  125.           rect_x, rect_y + 3, RPG::Cache.icon(
  126.           $data_items[$1.to_i].icon_name), i_rect)
  127.           rect_x += 24
  128.           rescue
  129.           icon_index = $data_items[$1.to_i].icon_index
  130.           bitmap = Cache.system("Iconset")
  131.           rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  132.           self.blt(x, y + 3, bitmap, rect)
  133.           end
  134.         end
  135.         next
  136.       end
  137.       if c == "\003"
  138.         text.sub!(/\[([0-9]+)\]/, "")
  139.         unless arg[0].is_a?(Rect)
  140.           begin
  141.           self.blt(
  142.           x, y + 3, RPG::Cache.icon(
  143.           $data_weapons[$1.to_i].icon_name), i_rect)
  144.           x += 24
  145.           rescue
  146.           icon_index = $data_weapons[$1.to_i].icon_index
  147.           bitmap = Cache.system("Iconset")
  148.           rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  149.           self.blt(x, y + 3, bitmap, rect)
  150.           end
  151.         else
  152.           begin
  153.           self.blt(
  154.           rect_x, rect_y + 3, RPG::Cache.icon(
  155.           $data_weapons[$1.to_i].icon_name), i_rect)
  156.           rect_x += 24
  157.           rescue
  158.           icon_index = $data_weapons[$1.to_i].icon_index
  159.           bitmap = Cache.system("Iconset")
  160.           rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  161.           self.blt(x, y + 3, bitmap, rect)
  162.           end
  163.         end
  164.         next
  165.       end
  166.       if c == "\004"
  167.         text.sub!(/\[([0-9]+)\]/, "")
  168.         unless arg[0].is_a?(Rect)
  169.           begin
  170.           self.blt(
  171.           x, y + 3, RPG::Cache.icon(
  172.           $data_armors[$1.to_i].icon_name), i_rect)
  173.           x += 24
  174.           rescue
  175.           icon_index = $data_armors[$1.to_i].icon_index
  176.           bitmap = Cache.system("Iconset")
  177.           rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  178.           self.blt(x, y + 3, bitmap, rect)
  179.           end
  180.         else
  181.           begin
  182.           self.blt(
  183.           rect_x, rect_y + 3, RPG::Cache.icon(
  184.           $data_armors[$1.to_i].icon_name), i_rect)
  185.           rect_x += 24
  186.           rescue
  187.           icon_index = $data_armors[$1.to_i].icon_index
  188.           bitmap = Cache.system("Iconset")
  189.           rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  190.           self.blt(x, y + 3, bitmap, rect)
  191.           end
  192.         end
  193.         next
  194.       end
  195.       if c == "\005"
  196.         text.sub!(/\[([0-9]+)\]/, "")
  197.         unless arg[0].is_a?(Rect)
  198.           begin
  199.           self.blt(
  200.           x, y + 3, RPG::Cache.icon(
  201.           $data_skills[$1.to_i].icon_name), i_rect)
  202.           x += 24
  203.           rescue
  204.           icon_index = $data_skills[$1.to_i].icon_index
  205.           bitmap = Cache.system("Iconset")
  206.           rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  207.           self.blt(x, y + 3, bitmap, rect)
  208.           end
  209.         else
  210.           begin
  211.           self.blt(
  212.           rect_x, rect_y + 3, RPG::Cache.icon(
  213.           $data_skills[$1.to_i].icon_name), i_rect)
  214.           rect_x += 24
  215.           rescue
  216.           icon_index = $data_skills[$1.to_i].icon_index
  217.           bitmap = Cache.system("Iconset")
  218.           rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  219.           self.blt(x, y + 3, bitmap, rect)
  220.           end
  221.         end
  222.         next
  223.       end
  224.       if c == "\006"
  225.         text.sub!(/\[([0-9]+)\]/, "")
  226.         self.font.size = $1.to_i
  227.         next
  228.       end
  229.       self.font.color = Color.new(0, 0, 0)
  230.       if $忽略默认宽高
  231.         self.font.color = color_coo
  232.         if arg[0].is_a?(Rect)
  233.           draw_text(rect.set(
  234.           rect_x, rect_y, self.text_size(c).width, 32), c, align)
  235.           rect_x += self.text_size(c).width
  236.         else
  237.           draw_text(x, y, self.text_size(c).width, 32, c, align)
  238.           x += self.text_size(c).width
  239.         end
  240.       else
  241.         self.font.color = color_coo
  242.         if arg[0].is_a?(Rect)
  243.           draw_text(rect.set(
  244.           rect_x, rect_y, rect_width, rect_height), c, align)
  245.           rect_x += self.text_size(c).width
  246.         else
  247.           draw_text(x, y, width, height, c, align)
  248.           x += self.text_size(c).width
  249.         end
  250.       end
  251.     end
  252.     self.font.size = size_copy
  253.   end
  254.   def draw_color(n)
  255.     return Color.new(255, 255, 255, 255) if n == 0
  256.     return Color.new(128, 128, 255, 255) if n == 1
  257.     return Color.new(255, 128, 128, 255) if n == 2
  258.     return Color.new(128, 255, 128, 255) if n == 3
  259.     return Color.new(128, 255, 255, 255) if n == 4
  260.     return Color.new(255, 128, 255, 255) if n == 5
  261.     return Color.new(255, 255, 128, 255) if n == 6
  262.     return Color.new(192, 192, 192, 255) if n == 7
  263.     return normal_color
  264.   end
  265. end

  266. class Bitmap
  267.   alias blkk_text_old blkk_text
  268.   def blkk_text(*arg)
  269.     if arg[0].is_a?(Rect)
  270.       rect_x = arg[0].x
  271.       rect_y = arg[0].y
  272.       rect_width = arg[0].width
  273.       rect_height = arg[0].height
  274.       rect = Rect.new(rect_x, rect_y, rect_width, rect_height)
  275.       unless arg[1].is_a?(String)
  276.         arg[1] = arg[1].to_s
  277.       end
  278.       y_plus = 0
  279.       arg[1].split("!换行").each{
  280.       |i| blkk_text_old(rect.set(
  281.       rect_x, rect_y + y_plus, rect_width, rect_height),
  282.       i, arg[2] == nil ? 0 : arg[2]) ; y_plus += 32}
  283.     else
  284.       unless arg[4].is_a?(String)
  285.         arg[4] = arg[4].to_s
  286.       end
  287.       y_plus = 0
  288.       arg[4].split("!换行").each{
  289.       |i| blkk_text_old(
  290.       arg[0], arg[1] + y_plus, arg[2], arg[3], i, arg[5] == nil ? 0 : arg[5]) ;
  291.       y_plus += 32}
  292.     end
  293.   end
  294. end
复制代码
[img]http://service.t.sina.com.cn/widget/qmd/5339802982/c02e16bd/7.png
回复 支持 反对

使用道具 举报

Lv1.梦旅人

薄凉看客

梦石
0
星屑
50
在线时间
1269 小时
注册时间
2010-6-20
帖子
1316
23
 楼主| 发表于 2014-1-1 13:51:27 | 只看该作者
chd114 发表于 2014-1-1 13:43

这样貌似不可以啊。。。

text.gsub!(/\![IW]\[([0-9]+)\]/) { "\003[#{$1}]" }

然后 !I[n] 和 !W[n] 都会触发条件

摘自F1 : /[abc]/ 表示只要匹配 "a"、"b"、"c" 中任何一个即可。
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
9280
在线时间
2504 小时
注册时间
2011-5-20
帖子
15389

开拓者

24
发表于 2014-1-1 13:53:28 | 只看该作者
恋′挂机 发表于 2014-1-1 13:51
这样貌似不可以啊。。。

text.gsub!(/\!\[([0-9]+)\]/) { "\003[#{$1}]" }

你发个工程看下···
[img]http://service.t.sina.com.cn/widget/qmd/5339802982/c02e16bd/7.png
回复 支持 反对

使用道具 举报

Lv1.梦旅人

薄凉看客

梦石
0
星屑
50
在线时间
1269 小时
注册时间
2010-6-20
帖子
1316
25
 楼主| 发表于 2014-1-1 13:57:38 | 只看该作者
chd114 发表于 2014-1-1 13:53
你发个工程看下···

text.gsub!(/\!IW\[([0-9]+)\]/) { "\003[#{$1}]" }

去掉 [] 就可以了
回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
9280
在线时间
2504 小时
注册时间
2011-5-20
帖子
15389

开拓者

26
发表于 2014-1-1 14:14:28 | 只看该作者
恋′挂机 发表于 2014-1-1 13:57
text.gsub!(/\!IW\[([0-9]+)\]/) { "\003[#{$1}]" }

去掉 [] 就可以了

全部都去掉[]?

点评

嗯  发表于 2014-1-1 14:18
[img]http://service.t.sina.com.cn/widget/qmd/5339802982/c02e16bd/7.png
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-15 02:02

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表