Project1
标题:
关键词统一变色
[打印本页]
作者:
Sora
时间:
2008-8-17 19:39
提示:
作者被禁止或删除 内容自动屏蔽
作者:
迅雷進
时间:
2008-8-17 20:01
http://rpg.blue/web/htm/news667.htm
可以直接使用 HTML 来更换颜色,
例如:#000000 就是黑色。
作者:
Sora
时间:
2008-8-17 20:27
提示:
作者被禁止或删除 内容自动屏蔽
作者:
灯笼菜刀王
时间:
2008-8-17 23:40
禾老大的增补功能范例一头
http://rpg.blue/viewthread.php?tid=88854
作者:
Sora
时间:
2008-8-18 01:40
提示:
作者被禁止或删除 内容自动屏蔽
作者:
MH穷奇
时间:
2008-8-18 03:21
提示:
作者被禁止或删除 内容自动屏蔽
作者:
沉影不器
时间:
2008-8-18 04:33
提示:
作者被禁止或删除 内容自动屏蔽
作者:
Sora
时间:
2008-8-19 16:37
提示:
作者被禁止或删除 内容自动屏蔽
作者:
IamI
时间:
2008-8-19 17:19
我只是想说……XP的制作人员们写那么长段的refresh你们不累吗……
改是改完了,和其他对话脚本冲突率99%
#==============================================================================
# 统一定义对话关键词颜色 by 沉影不器
#------------------------------------------------------------------------------
# 功能描述:在游戏对话中,经常为了突出某个关键词而用特定颜色描绘该词
# (这个关键词可能是某个人名地名或者物品、武器名之类)
# 该脚本允许统一定义这些关键词显示的颜色
# 比如“金箍棒”固定显示黄色、“紫水晶”固定显示紫色之类
#
# 使用说明:① 从脚本第22行开始定义各个关键词与颜色的对应关系,格式为
# 颜色代码=>["显示为此颜色的关键词1", "显示为此颜色的关键词2"...]
# 颜色代码是Window_Base中text_color(n)的取色代码
# 例:text_color(0) 表示普通文字色
# ② 特殊情况下让某个已定义的关键词失效的办法:
# 在对话中把关键词用@格开 例:金@箍棒
# ③ 显示@符号的方法是连续两个@ 例:@@
# ④ 根据snstar2006建议新增: 允许用户自定义关键词颜色,格式为
# 颜色代码(从32号开始)=>[红,绿,蓝[,不透明度]]
# 自定义的颜色从脚本第30行开始
#------------------------------------------------------------------------------
# 注:不要定义包含转义字符(串)的关键词,理由不需要展开说明吧?
#==============================================================================
KEY_WORDS = { # 定义各个关键词与颜色对应关系
1 =>["凤翅镏金铛","宇文成都"],
2 =>["紫金王朝","科比"],
3 =>["奥运","绿色"],
4 =>["选择项也支持关键词变色"],
32=>["自定义关键词颜色"],
}
CUSTOM_COLOR = { # 自定义关键词的颜色
32=>[0, 0, 0],
33=>[255, 64, 64, 128]
}
#==============================================================================
# ■ Window_Base
#==============================================================================
class Window_Base < Window
#--------------------------------------------------------------------------
# ● 获取文字颜色色
# n : 文字颜色编号 (0~31)
#--------------------------------------------------------------------------
alias old_t text_color
def text_color(n)
# 转移取色器
return text_color_plus(n) if n > 31
old_t(n)
end
#--------------------------------------------------------------------------
# ◎ 用户定义的取色器
# n : 文字颜色编号 (32~)
#--------------------------------------------------------------------------
def text_color_plus(n)
color_arg = CUSTOM_COLOR[n]
# 超过已定义范围时,返回普通颜色
return normal_color if color_arg == nil
alpha = color_arg[3] == nil ? 255 : color_arg[3]
color = Color.new(color_arg[0], color_arg[1], color_arg[2], alpha)
return color
end
end
#==============================================================================
# ■ Window_Message
#==============================================================================
class Window_Message < Window_Selectable
def refresh
self.contents.clear
self.contents.font.color = normal_color
x = y = 0
@cursor_width = 0
# 到选择项的下一行字
if $game_temp.choice_start == 0
x = 8
end
# 有等待显示的文字的情况下
if $game_temp.message_text != nil
text = $game_temp.message_text
@text = text
# 限制文字处理
begin
last_text = text.clone
text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
end until text == last_text
text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
$game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
end
# 为了方便、将 "\\\\" 变换为 "\000"
text.gsub!(/\\\\/) { "\000" }
# "\\C" 变为 "\001" 、"\\G" 变为 "\002"
text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
text.gsub!(/\\[Gg]/) { "\002" }
#############################
convert_keywords_color
###############################
# c 获取 1 个字 (如果不能取得文字就循环)
while ((c = text.slice!(/./m)) != nil)
# \\ 的情况下
if c == "\000"
# 还原为本来的文字
c = "\\"
end
# \C[n] 的情况下
if c == "\001"
# 更改文字色
text.sub!(/\[([0-9]+)\]/, "")
color = $1.to_i
if color >= 0 and color <= 7
self.contents.font.color = text_color(color)
end
# 下面的文字
next
end
# \G 的情况下
if c == "\002"
# 生成金钱窗口
if @gold_window == nil
@gold_window = Window_Gold.new
@gold_window.x = 560 - @gold_window.width
if $game_temp.in_battle
@gold_window.y = 192
else
@gold_window.y = self.y >= 128 ? 32 : 384
end
@gold_window.opacity = self.opacity
@gold_window.back_opacity = self.back_opacity
end
# 下面的文字
next
end
# 另起一行文字的情况下
if c == "\n"
# 刷新选择项及光标的高
if y >= $game_temp.choice_start
@cursor_width = [@cursor_width, x].max
end
# y 加 1
y += 1
x = 0
# 移动到选择项的下一行
if y >= $game_temp.choice_start
x = 8
end
# 下面的文字
next
end
# 描绘文字
self.contents.draw_text(4 + x, 32 * y, 40, 32, c)
# x 为要描绘文字的加法运算
x += self.contents.text_size(c).width
end
end
# 选择项的情况
if $game_temp.choice_max > 0
@item_max = $game_temp.choice_max
self.active = true
self.index = 0
end
# 输入数值的情况
if $game_temp.num_input_variable_id > 0
digits_max = $game_temp.num_input_digits_max
number = $game_variables[$game_temp.num_input_variable_id]
@input_number_window = Window_InputNumber.new(digits_max)
@input_number_window.number = number
@input_number_window.x = self.x + 8
@input_number_window.y = self.y + $game_temp.num_input_start * 32
end
end
#--------------------------------------------------------------------------
# ◎ 自定义关键词颜色
#--------------------------------------------------------------------------
def convert_keywords_color
for key in KEY_WORDS.keys
for key_words in KEY_WORDS[key]
@text.gsub!(key_words) {"\x01[#{key}]" + key_words + "\x01[0]"}
end
end
# 如果存在冲突,基本上就是此处了
# 把"\#x"任改一串基本不用的字符串就行
@text.gsub!(/@@/) { "\#x" }
@text.gsub!(/@/) { "" }
@text.gsub!("\#x") { "@" }
end
end
复制代码
作者:
Sora
时间:
2008-8-19 20:53
提示:
作者被禁止或删除 内容自动屏蔽
作者:
IamI
时间:
2008-8-19 21:05
我猛然发现,该死的XP制作员居然把数字锁死在了7……
我把上限改到了99。
#==============================================================================
# 统一定义对话关键词颜色 by 沉影不器
#------------------------------------------------------------------------------
# 功能描述:在游戏对话中,经常为了突出某个关键词而用特定颜色描绘该词
# (这个关键词可能是某个人名地名或者物品、武器名之类)
# 该脚本允许统一定义这些关键词显示的颜色
# 比如“金箍棒”固定显示黄色、“紫水晶”固定显示紫色之类
#
# 使用说明:① 从脚本第22行开始定义各个关键词与颜色的对应关系,格式为
# 颜色代码=>["显示为此颜色的关键词1", "显示为此颜色的关键词2"...]
# 颜色代码是Window_Base中text_color(n)的取色代码
# 例:text_color(0) 表示普通文字色
# ② 特殊情况下让某个已定义的关键词失效的办法:
# 在对话中把关键词用@格开 例:金@箍棒
# ③ 显示@符号的方法是连续两个@ 例:@@
# ④ 根据snstar2006建议新增: 允许用户自定义关键词颜色,格式为
# 颜色代码(从32号开始)=>[红,绿,蓝[,不透明度]]
# 自定义的颜色从脚本第30行开始
#------------------------------------------------------------------------------
# 注:不要定义包含转义字符(串)的关键词,理由不需要展开说明吧?
#==============================================================================
KEY_WORDS = { # 定义各个关键词与颜色对应关系
1 =>["凤翅镏金铛","宇文成都"],
2 =>["紫金王朝","科比"],
3 =>["奥运","绿色"],
4 =>["选择项也支持关键词变色"],
32=>["自定义关键词颜色"],
33=>["KAO","ORZ"]
}
CUSTOM_COLOR = { # 自定义关键词的颜色
32=>[99, 99, 99],
33=>[255, 64, 64, 128]
}
#==============================================================================
# ■ Window_Base
#==============================================================================
class Window_Base < Window
#--------------------------------------------------------------------------
# ● 获取文字颜色色
# n : 文字颜色编号 (0~31)
#--------------------------------------------------------------------------
alias old_t text_color
def text_color(n)
# 转移取色器
return text_color_plus(n) if n > 31
old_t(n)
end
#--------------------------------------------------------------------------
# ◎ 用户定义的取色器
# n : 文字颜色编号 (32~)
#--------------------------------------------------------------------------
def text_color_plus(n)
color_arg = CUSTOM_COLOR[n]
# 超过已定义范围时,返回普通颜色
return normal_color if color_arg == nil
alpha = color_arg[3] == nil ? 255 : color_arg[3]
color = Color.new(color_arg[0], color_arg[1], color_arg[2], alpha)
return color
end
end
#==============================================================================
# ■ Window_Message
#==============================================================================
class Window_Message < Window_Selectable
def refresh
self.contents.clear
self.contents.font.color = normal_color
x = y = 0
@cursor_width = 0
# 到选择项的下一行字
if $game_temp.choice_start == 0
x = 8
end
# 有等待显示的文字的情况下
if $game_temp.message_text != nil
text = $game_temp.message_text
@text = text
# 限制文字处理
begin
last_text = text.clone
text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
end until text == last_text
text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
$game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
end
# 为了方便、将 "\\\\" 变换为 "\000"
text.gsub!(/\\\\/) { "\000" }
# "\\C" 变为 "\001" 、"\\G" 变为 "\002"
text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
text.gsub!(/\\[Gg]/) { "\002" }
#############################
convert_keywords_color
###############################
# c 获取 1 个字 (如果不能取得文字就循环)
while ((c = text.slice!(/./m)) != nil)
# \\ 的情况下
if c == "\000"
# 还原为本来的文字
c = "\\"
end
# \C[n] 的情况下
if c == "\001"
# 更改文字色
text.sub!(/\[([0-99]+)\]/, "")
color = $1.to_i
if color >= 0 and color <= 99
self.contents.font.color = text_color(color)
end
# 下面的文字
next
end
# \G 的情况下
if c == "\002"
# 生成金钱窗口
if @gold_window == nil
@gold_window = Window_Gold.new
@gold_window.x = 560 - @gold_window.width
if $game_temp.in_battle
@gold_window.y = 192
else
@gold_window.y = self.y >= 128 ? 32 : 384
end
@gold_window.opacity = self.opacity
@gold_window.back_opacity = self.back_opacity
end
# 下面的文字
next
end
# 另起一行文字的情况下
if c == "\n"
# 刷新选择项及光标的高
if y >= $game_temp.choice_start
@cursor_width = [@cursor_width, x].max
end
# y 加 1
y += 1
x = 0
# 移动到选择项的下一行
if y >= $game_temp.choice_start
x = 8
end
# 下面的文字
next
end
# 描绘文字
self.contents.draw_text(4 + x, 32 * y, 40, 32, c)
# x 为要描绘文字的加法运算
x += self.contents.text_size(c).width
end
end
# 选择项的情况
if $game_temp.choice_max > 0
@item_max = $game_temp.choice_max
self.active = true
self.index = 0
end
# 输入数值的情况
if $game_temp.num_input_variable_id > 0
digits_max = $game_temp.num_input_digits_max
number = $game_variables[$game_temp.num_input_variable_id]
@input_number_window = Window_InputNumber.new(digits_max)
@input_number_window.number = number
@input_number_window.x = self.x + 8
@input_number_window.y = self.y + $game_temp.num_input_start * 32
end
end
#--------------------------------------------------------------------------
# ◎ 自定义关键词颜色
#--------------------------------------------------------------------------
def convert_keywords_color
for key in KEY_WORDS.keys
for key_words in KEY_WORDS[key]
@text.gsub!(key_words) {"\x01[#{key}]" + key_words + "\x01[0]"}
end
end
# 如果存在冲突,基本上就是此处了
# 把"\#x"任改一串基本不用的字符串就行
@text.gsub!(/@@/) { "\#x" }
@text.gsub!(/@/) { "" }
@text.gsub!("\#x") { "@" }
end
end
复制代码
[LINE]1,#dddddd[/LINE]
系统信息:本贴由楼主认可为正确答案,66RPG感谢您的热情解答~
作者:
makyo
时间:
2008-8-19 21:27
很佩服LS。。。。可以试试`
作者:
Sora
时间:
2008-8-20 17:04
提示:
作者被禁止或删除 内容自动屏蔽
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1