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

Project1

 找回密码
 注册会员
搜索
12
返回列表 发新帖
楼主: Sora
打印 上一主题 下一主题

关键词统一变色

 关闭 [复制链接]

Lv3.寻梦者

孤独守望

梦石
0
星屑
3133
在线时间
1535 小时
注册时间
2006-10-16
帖子
4321

开拓者贵宾

11
发表于 2008-8-19 21:05:05 | 只看该作者
我猛然发现,该死的XP制作员居然把数字锁死在了7……
我把上限改到了99。
  1. #==============================================================================
  2. # 统一定义对话关键词颜色 by 沉影不器
  3. #------------------------------------------------------------------------------
  4. # 功能描述:在游戏对话中,经常为了突出某个关键词而用特定颜色描绘该词
  5. #           (这个关键词可能是某个人名地名或者物品、武器名之类)
  6. #           该脚本允许统一定义这些关键词显示的颜色
  7. #           比如“金箍棒”固定显示黄色、“紫水晶”固定显示紫色之类
  8. #
  9. # 使用说明:① 从脚本第22行开始定义各个关键词与颜色的对应关系,格式为
  10. #              颜色代码=>["显示为此颜色的关键词1", "显示为此颜色的关键词2"...]
  11. #              颜色代码是Window_Base中text_color(n)的取色代码
  12. #              例:text_color(0) 表示普通文字色
  13. #           ② 特殊情况下让某个已定义的关键词失效的办法:
  14. #              在对话中把关键词用@格开        例:金@箍棒
  15. #           ③ 显示@符号的方法是连续两个@     例:@@
  16. #           ④ 根据snstar2006建议新增: 允许用户自定义关键词颜色,格式为
  17. #              颜色代码(从32号开始)=>[红,绿,蓝[,不透明度]]
  18. #              自定义的颜色从脚本第30行开始
  19. #------------------------------------------------------------------------------
  20. #         注:不要定义包含转义字符(串)的关键词,理由不需要展开说明吧?
  21. #==============================================================================
  22.   KEY_WORDS = {                         # 定义各个关键词与颜色对应关系
  23.   1 =>["凤翅镏金铛","宇文成都"],
  24.   2 =>["紫金王朝","科比"],
  25.   3 =>["奥运","绿色"],
  26.   4 =>["选择项也支持关键词变色"],
  27.   32=>["自定义关键词颜色"],
  28.   33=>["KAO","ORZ"]
  29.   }
  30.   
  31.   CUSTOM_COLOR = {                      # 自定义关键词的颜色
  32.   32=>[99, 99, 99],
  33.   33=>[255, 64, 64, 128]
  34.   }
  35.   
  36. #==============================================================================
  37. # ■ Window_Base
  38. #==============================================================================
  39. class Window_Base < Window
  40.   #--------------------------------------------------------------------------
  41.   # ● 获取文字颜色色
  42.   #     n : 文字颜色编号 (0~31)
  43.   #--------------------------------------------------------------------------
  44.   alias old_t text_color
  45.   def text_color(n)
  46.     # 转移取色器
  47.     return text_color_plus(n) if n > 31
  48.     old_t(n)
  49.   end
  50.   #--------------------------------------------------------------------------
  51.   # ◎ 用户定义的取色器
  52.   #     n : 文字颜色编号 (32~)
  53.   #--------------------------------------------------------------------------
  54.   def text_color_plus(n)
  55.     color_arg = CUSTOM_COLOR[n]
  56.     # 超过已定义范围时,返回普通颜色
  57.     return normal_color if color_arg == nil
  58.     alpha = color_arg[3] == nil ? 255 : color_arg[3]
  59.     color = Color.new(color_arg[0], color_arg[1], color_arg[2], alpha)
  60.     return color
  61.   end
  62. end

  63. #==============================================================================
  64. # ■ Window_Message
  65. #==============================================================================
  66. class Window_Message < Window_Selectable
  67.   def refresh
  68.     self.contents.clear
  69.     self.contents.font.color = normal_color
  70.     x = y = 0
  71.     @cursor_width = 0
  72.     # 到选择项的下一行字
  73.     if $game_temp.choice_start == 0
  74.       x = 8
  75.     end
  76.     # 有等待显示的文字的情况下
  77.     if $game_temp.message_text != nil
  78.       text = $game_temp.message_text
  79.       @text = text
  80.       # 限制文字处理
  81.       begin
  82.         last_text = text.clone
  83.         text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  84.       end until text == last_text
  85.       text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  86.         $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  87.       end
  88.       # 为了方便、将 "\\\\" 变换为 "\000"
  89.       text.gsub!(/\\\\/) { "\000" }
  90.       # "\\C" 变为 "\001" 、"\\G" 变为 "\002"
  91.       text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  92.       text.gsub!(/\\[Gg]/) { "\002" }
  93.       #############################
  94.       convert_keywords_color
  95.       ###############################
  96.       # c 获取 1 个字 (如果不能取得文字就循环)
  97.       while ((c = text.slice!(/./m)) != nil)
  98.         # \\ 的情况下
  99.         if c == "\000"
  100.           # 还原为本来的文字
  101.           c = "\\"
  102.         end
  103.         # \C[n] 的情况下
  104.         if c == "\001"
  105.           # 更改文字色
  106.           text.sub!(/\[([0-99]+)\]/, "")
  107.           color = $1.to_i
  108.           if color >= 0 and color <= 99
  109.             self.contents.font.color = text_color(color)
  110.           end
  111.           # 下面的文字
  112.           next
  113.         end
  114.         # \G 的情况下
  115.         if c == "\002"
  116.           # 生成金钱窗口
  117.           if @gold_window == nil
  118.             @gold_window = Window_Gold.new
  119.             @gold_window.x = 560 - @gold_window.width
  120.             if $game_temp.in_battle
  121.               @gold_window.y = 192
  122.             else
  123.               @gold_window.y = self.y >= 128 ? 32 : 384
  124.             end
  125.             @gold_window.opacity = self.opacity
  126.             @gold_window.back_opacity = self.back_opacity
  127.           end
  128.           # 下面的文字
  129.           next
  130.         end
  131.         # 另起一行文字的情况下
  132.         if c == "\n"
  133.           # 刷新选择项及光标的高
  134.           if y >= $game_temp.choice_start
  135.             @cursor_width = [@cursor_width, x].max
  136.           end
  137.           # y 加 1
  138.           y += 1
  139.           x = 0
  140.           # 移动到选择项的下一行
  141.           if y >= $game_temp.choice_start
  142.             x = 8
  143.           end
  144.           # 下面的文字
  145.           next
  146.         end
  147.         # 描绘文字
  148.         self.contents.draw_text(4 + x, 32 * y, 40, 32, c)
  149.         # x 为要描绘文字的加法运算
  150.         x += self.contents.text_size(c).width
  151.       end
  152.     end
  153.     # 选择项的情况
  154.     if $game_temp.choice_max > 0
  155.       @item_max = $game_temp.choice_max
  156.       self.active = true
  157.       self.index = 0
  158.     end
  159.     # 输入数值的情况
  160.     if $game_temp.num_input_variable_id > 0
  161.       digits_max = $game_temp.num_input_digits_max
  162.       number = $game_variables[$game_temp.num_input_variable_id]
  163.       @input_number_window = Window_InputNumber.new(digits_max)
  164.       @input_number_window.number = number
  165.       @input_number_window.x = self.x + 8
  166.       @input_number_window.y = self.y + $game_temp.num_input_start * 32
  167.     end
  168.   end
  169.   
  170.   #--------------------------------------------------------------------------
  171.   # ◎ 自定义关键词颜色
  172.   #--------------------------------------------------------------------------
  173.   def convert_keywords_color
  174.     for key in KEY_WORDS.keys
  175.       for key_words in KEY_WORDS[key]
  176.         @text.gsub!(key_words) {"\x01[#{key}]" + key_words + "\x01[0]"}
  177.       end
  178.     end
  179.     # 如果存在冲突,基本上就是此处了
  180.     # 把"\#x"任改一串基本不用的字符串就行
  181.     @text.gsub!(/@@/) { "\#x" }
  182.     @text.gsub!(/@/) { "" }
  183.     @text.gsub!("\#x") { "@" }
  184.   end
  185. end
复制代码

系统信息:本贴由楼主认可为正确答案,66RPG感谢您的热情解答~
菩提本非树,明镜本非台。回头自望路漫漫。不求姻缘,但求再见。
本来无一物,何处惹尘埃。风打浪吹雨不来。荒庭遍野,扶摇难接。
不知道多久更新一次的博客
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
60
在线时间
14 小时
注册时间
2008-8-12
帖子
52
12
发表于 2008-8-19 21:27:09 | 只看该作者
很佩服LS。。。。可以试试`
回复 支持 反对

使用道具 举报

头像被屏蔽

Lv1.梦旅人 (禁止发言)

梦石
0
星屑
50
在线时间
4 小时
注册时间
2008-7-11
帖子
96
13
 楼主| 发表于 2008-8-20 17:04:08 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2025-7-23 07:09

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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