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

Project1

 找回密码
 注册会员
搜索
查看: 1381|回复: 2
打印 上一主题 下一主题

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

[复制链接]

Lv3.寻梦者

梦石
0
星屑
3186
在线时间
1863 小时
注册时间
2010-6-19
帖子
1205
跳转到指定楼层
1
发表于 2022-10-27 13:18:48 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
10星屑
本帖最后由 黑米馒头 于 2022-10-27 13:21 编辑

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


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


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





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

Lv5.捕梦者 (版主)

梦石
1
星屑
23963
在线时间
3338 小时
注册时间
2011-7-8
帖子
3925

开拓者

2
发表于 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 网络脚本 *
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-28 09:54

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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