赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 3852 |
最后登录 | 2020-11-14 |
在线时间 | 81 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 138
- 在线时间
- 81 小时
- 注册时间
- 2012-6-16
- 帖子
- 52
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
我用的是这个脚本,请问怎么在菜单栏添加 任务 选项
#encoding:utf-8
#==============================================================================
# ■ Task
#------------------------------------------------------------------------------
# 任务类。本类在 Game_Task 类的内部使用。
# 任务属性:名称,内容,是否是主线任务,是否有父任务
#==============================================================================
class Task
attr_reader :index
attr_reader :name
attr_reader :description
attr_reader :type
attr_reader :father_task
attr_reader :finished
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize(index, name, description, type = true, father_task = -1)
@type = type
@name = name
@description = description
@father_task = father_task
@Index = index
@finished = false
end
#--------------------------------------------------------------------------
# ● 是否是主线任务
#--------------------------------------------------------------------------
def key_task?
@type
end
#--------------------------------------------------------------------------
# ● 是否是子任务
#--------------------------------------------------------------------------
def has_father_task?
@father_task > -1
end
#--------------------------------------------------------------------------
# ● 完成任务
#--------------------------------------------------------------------------
def finish
@finished = true
end
end
#==============================================================================
# ■ Game_Party
#==============================================================================
class Game_Party < Game_Unit
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
alias old_init initialize
def initialize
old_init
@tasks = {}
@sub_tasks= {}
#定义了一个任务列表,提前把所有的任务都写进去了
@task_list=TaskList.new
@sub = false
end
#--------------------------------------------------------------------------
# ● 是否存在子任务
#--------------------------------------------------------------------------
def is_sub
@sub
end
#--------------------------------------------------------------------------
# ● 启用子任务
#--------------------------------------------------------------------------
def set_sub
@sub = true
end
#--------------------------------------------------------------------------
# ● 添加新的任务
#--------------------------------------------------------------------------
def new_task(i, name, desc, type, father_task = -1)
if !is_sub
@tasks = tmp if !have_task?(i)
return
end
tmp = Task.new(i, name, desc, type, father_task)
if father_task < 0
@tasks = tmp if !have_task?(i)
else
@sub_tasks = tmp if father_task?(father_task) && !sub_task?(i)
end
end
#--------------------------------------------------------------------------
# ● 从已定义好的任务列表中添加新的任务
#--------------------------------------------------------------------------
def set_task(index)
temp = @task_list.get_task(index)
if !is_sub
@tasks[index] = temp if !have_task?(index)
return
end
if temp.has_father_task?
@sub_tasks[index] = temp if father_task?(temp.father_task) && !sub_task?(index)
else
@tasks[index] = temp if !have_task?(index)
end
end
#--------------------------------------------------------------------------
# ● 查询任务是否存在
#--------------------------------------------------------------------------
def have_task?(i)
return father_task?(i) || sub_task?(i)
end
#--------------------------------------------------------------------------
# ● 查询父任务是否存在
#--------------------------------------------------------------------------
def father_task?(i)
@tasks != nil
end
#--------------------------------------------------------------------------
# ● 查询子任务是否存在
#--------------------------------------------------------------------------
def sub_task?(i)
@sub_tasks != nil
end
#--------------------------------------------------------------------------
# ● 完成已有的任务,如果该任务有没有完成的子任务,则不能完成
#--------------------------------------------------------------------------
def finish_task(i)
@tasks.finish if father_task?(i) && sub_tasks_finished?(i)
@sub_tasks.finish if sub_task?(i)
end
#--------------------------------------------------------------------------
# ● 查询父任务序号为i的子任务,返回一个数组
#--------------------------------------------------------------------------
def get_sub_tasks(i)
return [] if !is_sub
tmp = []
for j in @sub_tasks.values
next if j.father_task != i
tmp.push(j)
end
return tmp
end
#--------------------------------------------------------------------------
# ● 查询父任务序号为i的子任务是否都已完成
#--------------------------------------------------------------------------
def sub_tasks_finished?(i)
return true if !is_sub
for j in @sub_tasks.values
next if j.father_task != i
return false if !j.finished
end
return true
end
#--------------------------------------------------------------------------
# ● 获取任务类型为cat的任务集合
#--------------------------------------------------------------------------
def all_tasks(cat)
n = []
m = []
for i in @tasks.values
next if i.key_task? != cat
tmp = get_sub_tasks(i.index)
if i.finished
n.push(i)
n += tmp
else
m.push(i)
m += tmp
end
end
return m + n
end
end
#==============================================================================
# ■ Window_TaskList
#------------------------------------------------------------------------------
# 任务画面中,显示已获得任务的窗口。
#==============================================================================
class Window_TaskList < Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
super
@category = :none
@data = []
@sub_task = false
end
#--------------------------------------------------------------------------
# ● 设置是否有子任务
#--------------------------------------------------------------------------
def has_sub_task
@sub_task = true
end
#--------------------------------------------------------------------------
# ● 设置分类
#--------------------------------------------------------------------------
def category=(category)
return if @category == category
@category = category
if category == :true
refresh(true)
else
refresh(false)
end
self.oy = 0
end
#--------------------------------------------------------------------------
# ● 获取列数
#--------------------------------------------------------------------------
def col_max
if @sub_task
return 1
else
return 2
end
end
#--------------------------------------------------------------------------
# ● 获取项目数
#--------------------------------------------------------------------------
def item_max
@data ? @data.size : 1
end
#--------------------------------------------------------------------------
# ● 获取任务
#--------------------------------------------------------------------------
def item
@data && index >= 0 ? @data[index] : nil
end
#--------------------------------------------------------------------------
# ● 获取选择任务的有效状态
#--------------------------------------------------------------------------
def current_item_enabled?
enable?(@data[index])
end
#--------------------------------------------------------------------------
# ● 查询此任务是否完成
#--------------------------------------------------------------------------
def enable?(item)
!item.finished
end
#--------------------------------------------------------------------------
# ● 生成任务列表
#--------------------------------------------------------------------------
def make_item_list(type)
@data = $game_party.all_tasks(type)
end
#--------------------------------------------------------------------------
# ● 返回上一个选择的位置
#--------------------------------------------------------------------------
def select_last
select(0)
end
#--------------------------------------------------------------------------
# ● 绘制项目
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
if item
rect = item_rect(index)
rect.width -= 4
draw_item_name(item, rect.x, rect.y, enable?(item))
end
end
#--------------------------------------------------------------------------
# ● 绘制名称
# enabled : 有效的标志。false 的时候使用半透明效果绘制
#--------------------------------------------------------------------------
def draw_item_name(item, x, y, enabled = true, width = 172)
return unless item
text = item.name
text = " " + text if @sub_task && item.has_father_task?
text += "(已完成)" if item.finished
change_color(normal_color, enabled)
draw_text(x, y, width, line_height, text)
end
#--------------------------------------------------------------------------
# ● 更新帮助内容
#--------------------------------------------------------------------------
def update_help
@help_window.set_item(item)
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh(type)
make_item_list(type)
create_contents
draw_all_items
end
end
#==============================================================================
# ■ Window_TaskCategory
#------------------------------------------------------------------------------
# 任务画面中,显示任务列表的窗口。
#==============================================================================
class Window_TaskCategory < Window_HorzCommand
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :item_window
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize
super(0, 0)
end
#--------------------------------------------------------------------------
# ● 获取窗口的宽度
#--------------------------------------------------------------------------
def window_width
Graphics.width
end
#--------------------------------------------------------------------------
# ● 获取列数
#--------------------------------------------------------------------------
def col_max
return 2
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
super
@item_window.category = current_symbol if @item_window
end
#--------------------------------------------------------------------------
# ● 生成指令列表
#--------------------------------------------------------------------------
def make_command_list
add_command("主线任务", :true)
add_command("支线任务", :false)
end
#--------------------------------------------------------------------------
# ● 设置任务窗口
#--------------------------------------------------------------------------
def item_window=(item_window)
@item_window = item_window
update
end
end
#==============================================================================
# ■ Scene_Task
#------------------------------------------------------------------------------
# 任务画面
#==============================================================================
class Scene_Task < Scene_ItemBase
#--------------------------------------------------------------------------
# ● 开始处理
#--------------------------------------------------------------------------
def start
super
create_help_window
create_category_window
create_task_window
end
#--------------------------------------------------------------------------
# ● 生成分类窗口
#--------------------------------------------------------------------------
def create_category_window
@category_window = Window_TaskCategory.new
@category_window.viewport = @viewport
@category_window.help_window = @help_window
@category_window.y = @help_window.height
@category_window.set_handler(:ok, method(:on_category_ok))
@category_window.set_handler(:cancel, method(:return_scene))
end
#--------------------------------------------------------------------------
# ● 生成任务窗口
#--------------------------------------------------------------------------
def create_task_window
wy = @category_window.y + @category_window.height
wh = Graphics.height - wy
@item_window = Window_TaskList.new(0, wy, Graphics.width, wh)
#如果允许子任务则显示子任务
@item_window.has_sub_task if $game_party.is_sub
@item_window.viewport = @viewport
@item_window.help_window = @help_window
@item_window.set_handler(:cancel, method(:on_item_cancel))
@category_window.item_window = @item_window
end
#--------------------------------------------------------------------------
# ● 分类“确定”
#--------------------------------------------------------------------------
def on_category_ok
@item_window.activate
@item_window.select_last
end
#--------------------------------------------------------------------------
# ● 任务“取消”
#--------------------------------------------------------------------------
def on_item_cancel
@item_window.unselect
@category_window.activate
end
end
#==============================================================================
# ■ TaskList
#------------------------------------------------------------------------------
#
#==============================================================================
class TaskList
def initialize
#允许子任务
@list = []
@list.push(Task.new(0, "任务0", "任务描述0任务描述0任务描述0任务描述0任务"))
@list.push(Task.new(1, "任务一", "任务描述1"))
@list.push(Task.new(2, "任务2", "任务描述2",false))
@list.push(Task.new(3, "任务3", "任务描述3", true, 1))
@list.push(Task.new(4, "任务4", "任务描述4", true, 1))
@list.push(Task.new(5, "任务5", "任务描述5", false, 2))
@list.push(Task.new(6, "任务6", "任务描述6", false))
@list.push(Task.new(7, "任务7", "任务描述7", true, 1))
end
def get_task(index)
@list[index]
end
end |
|