查看: 2430|回复: 2

[已经解决] 文本添加颜色

[复制链接]
梦石
0
星屑
3850
在线时间
1899 小时
注册时间
2010-6-19
回帖
917
发表于 2022-10-27 13:18:48 | 显示全部楼层 |阅读模式
悬赏10星屑未解决
本帖最后由 黑米馒头 于 2022-10-27 13:21 编辑

来个大佬看看,下面这个draw_text必备扩展功能脚本如何整合到文本里面,


脚本调用: $game_party.update_message("养成存档习惯,避免从头再来!","_系统"),可以输出文本,
如何把下面dl_draw_text脚本里面的功能添加进去,比如修改颜色,显示武器装备物品图标这些。


  1. viewport = Viewport.new(0,0,640,480)
  2.         viewport.z = 200
  3.         $message_sprite = Sprite.new(viewport)
  4.         $message_sprite.bitmap = Bitmap.new(640,480)
  5.         $message_sprite.x = 6
  6.         $message_sprite.y = 5
  7.   $message_sprite.z = 99999
  8.         $message_sprite.visible = true
  9.         $message_sprite.bitmap.font.size = 15
  10.         $message_sprite.bitmap.font.color.set(255,255,255,255)


  11. class Window_Goods < Window_Base
  12.   def initialize
  13.     super(0, 0, 42, 42)
  14.     self.opacity = 120
  15.     self.visible = true
  16.     $game_party.update_message("养成存档习惯,避免从头再来!","_系统")
  17.   end
  18. end   
  19.   def update_message(txt,a="_系统")
  20.     bitmap = RPG::Cache.picture(a)
  21.     rect = Rect.new(0,0,bitmap.width,bitmap.height)
  22.     if $message_index < 19
  23.       $message_sprite.bitmap.blt(1,4 + $message_index * 25, bitmap,rect)
  24.       $message_sprite.bitmap.draw_text(5+bitmap.width, 4 + $message_index * 25, 300,bitmap.height, txt)
  25.       $message_index += 1
  26.     else
  27.       $message_sprite.bitmap.clear
  28.       $message_sprite.bitmap.blt(1,4,bitmap,rect)
  29.       $message_sprite.bitmap.draw_text(5+bitmap.width, 4, 300,bitmap.height, txt)
  30.       $message_index = 1
  31.     end
  32.   end
  33.   


复制代码




  1. #===========================================================================
  2. #  *  draw_text必备扩展
  3. #===========================================================================
  4. =begin

  5.   !c[n]       #改用n号颜色 *注 颜色在color处自定
  6.   !s[n]       #改用n号大小
  7.   !n[name]    #改用名称为name的字体
  8.   !b0         #关闭粗体
  9.   !b1         #开启粗体
  10.   !i0         #关闭斜体
  11.   !i1         #开启斜体
  12.   
  13.   i[n]        #描绘id为n的物品的图标
  14.   s[n]        #描绘id为n的特技的图标
  15.   w[n]        #描绘id为n的武器的图标
  16.   a[n]        #描绘id为n的防具的图标
  17.   l[filename] #描绘文件名为filename的图标
  18.   
  19.   \\n         #手动换行
  20.   
  21.   其他功能——
  22.   *投影
  23.   *自动换行

  24. =end
  25. class Bitmap
  26.   def dl_draw_text(x, y, text)
  27.     #记录bitmap数据
  28.     name_copy = self.font.name
  29.     size_copy = self.font.size
  30.     bold_copy = self.font.bold
  31.     italic_copy = self.font.italic
  32.     color_copy = self.font.color.clone
  33.     #初始数据
  34.     text_copy = text
  35.     tx,ty = x,y
  36.     rect = Rect.new(0, 0, 24, 24)
  37.     #字体
  38.     text_copy.gsub!(/!c\[([0-9]+)\]/) { "\001[#{$1}]" }
  39.     text_copy.gsub!(/!s\[([0-9]+)\]/) { "\002[#{$1}]" }
  40.     text_copy.gsub!(/!n\[(.+)\]/) { "\003[#{$1}]" }
  41.     text_copy.gsub!(/!b0/) { "\004" }
  42.     text_copy.gsub!(/!b1/) { "\005" }
  43.     text_copy.gsub!(/!i0/) { "\006" }
  44.     text_copy.gsub!(/!i1/) { "\007" }
  45.     #图标
  46.     text_copy.gsub!(/i\[([0-9]+)\]/) { "\020[#{$1}]" }
  47.     text_copy.gsub!(/s\[([0-9]+)\]/) { "\021[#{$1}]" }
  48.     text_copy.gsub!(/w\[([0-9]+)\]/) { "\022[#{$1}]" }
  49.     text_copy.gsub!(/a\[([0-9]+)\]/) { "\023[#{$1}]" }
  50.     text_copy.gsub!(/l\[(.+)\]/) { "\025[#{$1}]" }
  51.     #其他
  52.     text_copy.gsub!(/v\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  53.     text_copy.gsub!(/\\n/) { "\030" }
  54.     #颜色
  55.     color = []
  56.     color[0] = Color.new(255, 255, 255, 255)#白
  57.     color[1] = Color.new(128, 128, 255, 255)#蓝
  58.     color[2] = Color.new(255, 0, 0, 255)#(255, 0, 80, 255)   #红
  59.     color[3] = Color.new(128, 255, 128, 255)#绿
  60.     color[4] = Color.new(128, 255, 255, 255)#青
  61.     color[5] = Color.new(255, 128, 255, 255)#粉红
  62.     color[6] = Color.new(255, 255, 128, 255)#黄
  63.     color[7] = Color.new(192, 192, 192, 255)#灰
  64.     color[8] = Color.new(255, 195, 105, 255)#桔色
  65.     color[9] = Color.new(207, 212, 241, 255)#紫色
  66.    
  67.     while ((c = text_copy.slice!(/./m)) != nil)
  68.       #====================================
  69.       #设置字体
  70.       #====================================
  71.       #颜色
  72.       if c == "\001"
  73.         text_copy.sub!(/\[([0-9]+)\]/, "")
  74.         next if color[$1.to_i].nil?
  75.         self.font.color = color[$1.to_i]
  76.         next
  77.       end
  78.       #大小
  79.       if c == "\002"
  80.         text_copy.sub!(/\[([0-9]+)\]/, "")
  81.         self.font.size = $1.to_i
  82.         next
  83.       end
  84.       #名称
  85.       if c == "\003"
  86.         text_copy.sub!(/\[(.+)\]/, "")
  87.         self.font.name = $1 if Font.exist?($1)
  88.         next
  89.       end
  90.       #粗体关
  91.       if c == "\004"
  92.         self.font.bold = false
  93.         next
  94.       end
  95.       #粗体开
  96.       if c == "\005"
  97.         self.font.bold = true
  98.         next
  99.       end
  100.       #斜体关
  101.       if c == "\006"
  102.         self.font.italic = false
  103.         next
  104.       end
  105.       #斜体开
  106.       if c == "\007"
  107.         self.font.italic = true
  108.         next
  109.       end
  110.       #====================================
  111.       #描绘图标
  112.       #====================================
  113.       #物品
  114.       if c == "\020"
  115.         text_copy.sub!(/\[([0-9]+)\]/, "")
  116.         if !$data_items[$1.to_i].nil? and $data_items[$1.to_i].icon_name != ""
  117.           next if tx + 24 > self.width - 32
  118.           bitmap = RPG::Cache.icon($data_items[$1.to_i].icon_name)
  119.           self.blt(tx, ty, bitmap, rect)
  120.           tx += 24
  121.         end
  122.         next
  123.       end
  124.       #特技
  125.       if c == "\021"
  126.         text_copy.sub!(/\[([0-9]+)\]/, "")
  127.         if !$data_skills[$1.to_i].nil? and $data_skills[$1.to_i].icon_name != ""
  128.           next if tx + 24 > self.width - 32
  129.           bitmap = RPG::Cache.icon($data_skills[$1.to_i].icon_name)
  130.           self.blt(tx, ty, bitmap, rect)
  131.           tx += 24
  132.         end
  133.         next
  134.       end
  135.       #武器
  136.       if c == "\022"
  137.         text_copy.sub!(/\[([0-9]+)\]/, "")
  138.         if !$data_weapons[$1.to_i].nil? and $data_weapons[$1.to_i].icon_name != ""
  139.           next if tx + 24 > self.width - 32
  140.           bitmap = RPG::Cache.icon($data_weapons[$1.to_i].icon_name)
  141.           self.blt(tx, ty, bitmap, rect)
  142.           tx += 24
  143.         end
  144.         next
  145.       end
  146.       #防具
  147.       if c == "\023"
  148.         text_copy.sub!(/\[([0-9]+)\]/, "")
  149.         if !$data_armors[$1.to_i].nil? and $data_armors[$1.to_i].icon_name != ""
  150.           next if tx + 24 > self.width - 32
  151.           bitmap = RPG::Cache.icon($data_armors[$1.to_i].icon_name)
  152.           self.blt(tx, ty, bitmap, rect)
  153.           tx += 24
  154.         end
  155.         next
  156.       end
  157.       #自定
  158.       if c == "\025"
  159.         text_copy.sub!(/\[(.+)\]/, "")
  160.         if $1 != ""
  161.           next if tx + 24 > self.width - 32
  162.           bitmap = RPG::Cache.icon($1)
  163.           self.blt(tx, ty, bitmap, rect)
  164.           tx += 24
  165.         end
  166.         next
  167.       end
  168.       #====================================
  169.       #其他
  170.       #====================================
  171.       #换行
  172.       if c == "\030"
  173.         ty += self.font.size
  174.         next
  175.       end
  176.       cx = self.text_size(c).width
  177.       #投影
  178.       #dl_color_copy = self.font.color.clone
  179.       #self.font.color.set(0, 0, 0)
  180.       #self.draw_text(tx+1, ty+1, cx, self.font.size, c)
  181.       #self.draw_text(tx-1, ty+1, cx, self.font.size, c)
  182.       #self.draw_text(tx+1, ty-1, cx, self.font.size, c)
  183.       #self.draw_text(tx-1, ty-1, cx, self.font.size, c)
  184.       #self.font.color = dl_color_copy
  185.       self.draw_text(tx, ty, cx, self.font.size, c)
  186.       tx += cx
  187.       #自动换行
  188.       if tx >= self.width
  189.         tx = 0
  190.         ty += self.font.size
  191.       end
  192.     end
  193.     #恢复调整
  194.     self.font.name = name_copy
  195.     self.font.size = size_copy
  196.     self.font.bold = bold_copy
  197.     self.font.italic = italic_copy
  198.     self.font.color = color_copy
  199.   end
  200. end
复制代码

梦石
1
星屑
24088
在线时间
3339 小时
注册时间
2011-7-8
回帖
3862

开拓者

发表于 2022-10-27 14:40:21 | 显示全部楼层
26行,31行,去掉draw_text的第3、4参数,然后把draw_text改成dl_draw_text

点评

3Q。 如何采纳  发表于 2022-10-28 02:16
熟悉rgss和ruby,xp区版主~
正在填坑:《膜拜组传奇》讲述膜拜组和学霸们的故事。
已上steam:与TXBD合作的Reformers《变革者》
* 战斗调用公共事件 *
* RGSOS 网络脚本 *
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部