class Game_Task
attr_accessor :name # 名称
attr_accessor :briefing # 简介
def initialize(name, briefing)
@name = name
@briefing = briefing
end
def height
text = @briefing.clone
x = 0
y = 64
min_y = 0
# 限制文字处理
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"
text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
# "\I" 变为 "\002"
text.gsub!(/\\[Ii]/) { "\002" }
# "\P" 变为 "\003"
text.gsub!(/\\[Pp]/) { "\003" }
# c 获取 1 个字 (如果不能取得文字就循环)
while ((c = text.slice!(/./m)) != nil)
# \\ 的情况下
if c == "\000"
# 还原为本来的文字
c = "\\"
end
# \C[n] 的情况下
if c == "\001"
# 更改文字色
text.sub!(/\[([0-9a-zA-Z]+)\]/, "")
# 下面的文字
next
end
# 图标的情况下
if c == "\002"
icon_name = ''
while ((cha = text.slice!(/./m)) != ']')
next if cha == '['
icon_name += cha
end
if x + 24 > 368
x = 0
y += [24, min_y].max
min_y = 0
end
x += 28
next
end
# 图片的情况下
if c == "\003"
pic_name = ''
while ((cha = text.slice!(/./m)) != ']')
next if cha == '['
pic_name += cha
end
pic = Cache.picture(pic_name)
if x + pic.width > 368
x = 0
y += [24, min_y].max
min_y = 0
end
x += pic.width
min_y = [pic.height, 24].max
next
end
# 另起一行文字的情况下
if c == "\n"
y += [24, min_y].max
min_y = 0
x = 0
# 下面的文字
next
end
# 自动换行处理
if x + 22 > 368
y += [24, min_y].max
min_y = 0
x = 0
end
# x 为要描绘文字的加法运算
x += 22
end
return (y + [24, min_y].max)
end
def id
return $game_party.tasks_info.index(self)
end
end
class Window_Task < Window_Base
#--------------------------------------------------------------------------
# ● 初始化对像
#--------------------------------------------------------------------------
def initialize(task_id)
super(204, 0, 340, 416)
refresh(task_id)
end
#--------------------------------------------------------------------------
# ● 刷新内容
#--------------------------------------------------------------------------
def refresh(task_id)
self.oy = 0
self.visible = true
return if task_id.nil?
task = $game_party.tasks_info[task_id]
if !task.nil?
self.contents = Bitmap.new(self.width - 32, task.height)
else
self.contents = Bitmap.new(self.width - 32, self.height - 32)
return
end
self.contents.font.color = normal_color
# 描绘任务内容
draw_task_info(task)
end
#--------------------------------------------------------------------------
# ● 描绘任务内容
#--------------------------------------------------------------------------
def draw_task_info(task)
self.contents.font.color = normal_color
# 描绘任务简介
chenge_special_character(task.briefing.clone)
end
end
class Window_Base < Window
def chenge_special_character(text, x=0, y=0)
# 记录换行时y坐标最小加值
min_y = 0
# 限制文字处理
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"
text.gsub!(/\\[Cc]\[([0-9a-zA-Z]+)\]/) { "\001[#{$1}]" }
# "\I" 变为 "\002"
text.gsub!(/\\[Ii]/) { "\002" }
# "\P" 变为 "\003"
text.gsub!(/\\[Pp]/) { "\003" }
# c 获取 1 个字 (如果不能取得文字就循环)
while ((c = text.slice!(/./m)) != nil)
# \\ 的情况下
if c == "\000"
# 还原为本来的文字
c = "\\"
end
# \C[n] 的情況下
if c == "\001"
# 更改文字色
text.sub!(/\[([0-9a-zA-Z]+)\]/, "")
# 如果是设定RGB颜色
if $1[0,1]=="H"
# 先拷贝一下文字
c=$1.dup
# 分3段分别取出R,G,B颜色
c.sub!(/H([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})([0-9A-Fa-f]{2})/, "")
# 设定文字颜色
self.contents.font.color = Color.new($1.to_i(16), $2.to_i(16), $3.to_i(16))
else
color = $1.to_i
if color >= 0 and color <= 31
self.contents.font.color = text_color(color)
elsif color == 32
self.contents.font.color = disabled_color
elsif color == 33
self.contents.font.color = system_color
end
end
# 下面的文字
next
end
# 图标的情况下
if c == "\002"
icon_name = ''
while ((cha = text.slice!(/./m)) != ']')
next if cha == '['
icon_name += cha
end
if x + 24 > self.contents.width
x = 0
y += [WLH, min_y].max
min_y = 0
end
draw_icon(icon_name.to_i, x+4, y+4, true)
x += 28
next
end
# 图片的情况下
if c == "\003"
pic_name = ''
while ((cha = text.slice!(/./m)) != ']')
next if cha == '['
pic_name += cha
end
pic = Cache.picture(pic_name)
if x + pic.width > self.contents.width
x = 0
y += [WLH, min_y].max
min_y = 0
end
self.contents.blt(x + 4, y, pic, Rect.new(0, 0, pic.width, pic.height))
x += pic.width
min_y = [pic.height, WLH].max
next
end
# 另起一行文字的情况下
if c == "\n"
y += [WLH, min_y].max
min_y = 0
x = 0
# 下面的文字
next
end
# 自动换行处理
if x + self.contents.text_size(c).width > self.contents.width
y += [WLH, min_y].max
min_y = 0
x = 0
end
# 描绘文字
self.contents.draw_text(4 + x, y, 40, WLH, c)
# x 为要描绘文字的加法运算
x += self.contents.text_size(c).width
end
end
end
class Game_Party < Game_Unit
def item_no(n)
return item_number($data_items[n])
end
def weapon_no(n)
return item_number($data_weapons[n])
end
def armor_no(n)
return item_number($data_armors[n])
end
end
class Scene_Task < Scene_Base
def initialize(index=nil)
@menu_index = index
end
#--------------------------------------------------------------------------
# ● 主处理
#--------------------------------------------------------------------------
def start
# 刷新任务资料
$game_party.get_tasks_info
# 生成任务名称窗口
@task_names_window = Window_Task_Name.new($game_party.current_tasks)
@task_names_window.active = true
if $game_party.current_tasks != []
@task_names_window.index = $game_party.current_tasks.index($game_party.latest_task)
end
# 生成任务内容窗口
@task_info_window = Window_Task.new($game_party.latest_task)
@task_info_window.active = true
end
def terminate
# 释放窗口
@task_names_window.dispose
@task_info_window.dispose
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
# 刷新窗口
@task_names_window.update
@task_info_window.update
update_task_names_window
end
#--------------------------------------------------------------------------
# ● 刷新任务名称窗口
#--------------------------------------------------------------------------
def update_task_names_window
# 按下 B 键的情况下
if Input.trigger?(Input::B)
# 演奏取消 SE
Sound.play_cancel
# 这里设置返回的场景,返回地图是Scene_Map.new,菜单是Scene_Menu.new(任务界面index)
if @menu_index == nil
$scene = Scene_Map.new
else
$scene = Scene_Menu.new(@menu_index)
end
return
end
# 按下 C 键的情况下
if Input.trigger?(Input::C)
# 无任务可显示的话
if @task_names_window.task == nil
# 演奏冻结 SE
Sound.play_buzzer
return
end
# 如果光标没有移动的话,翻页
if $game_party.latest_task == @task_names_window.task.id
if @task_info_window.oy + @task_info_window.height - 32 > @task_info_window.contents.height
@task_info_window.oy = 0
else
@task_info_window.oy += 480-32
end
else
@task_info_window.refresh(@task_names_window.task.id)
$game_party.latest_task = @task_names_window.task.id
# 演奏确定 SE
Sound.play_decision
end
end
end
end