| 赞 | 20 |
| VIP | |
| 好人卡 | |
| 积分 | 13 |
| 经验 | |
| 最后登录 | 2019-7-17 |
| 在线时间 | 995 小时 |
- 梦石
- 0
- 星屑
- 1297
- 在线时间
- 995 小时
- 注册时间
- 2014-12-14
- 回帖
- 2939

|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有账号?注册会员
×
本帖最后由 Vortur 于 2016-5-13 21:29 编辑
在下想要使用这个系统:https://rpg.blue/thread-377754-1-1.html
但是其【任务工会列表窗口】中,文字宽度显示不太合适:很长的文字都挤压在左方,右方却留了很大的空白
如图
在下搜索了一些帖子只找到一个结果,但并不能解决当下的问题:https://rpg.blue/thread-380604-1-1.html
如何才能使这段文字【正确显示】呢?
PS.4楼在下贴出自己的详细研究成果
原脚本:
新任务(设定与核心)[pre lang="ruby"]#------------------------------------------------------------------------------#
# 新任务
#------------------------------------------------------------------------------#
# 适用: RPGMAKER VX ACE
# 版本: 1.0
# 作者:66RPG的tan12345
#-------------------------------------------------------------------------------
# 自己写的任务系统
# 使用方法:将脚本插入至main以上
# 呼出时,请调用:
# SceneManager.call(Scene_Tan_Task)可查看任务情况
# SceneManager.call(Scene_Tan_Task2)任务工会接取任务完成任务用
#-------------------------------------------------------------------------------
module Tan_task
#任务内容描述是否自己描述,true自己描述,false使用默认描述
Tan_task_description_type = false
#公会面板显示的可接任务列表,具体使用可参考任务工会呼出事件
Tan_task_list2 = []
#公会面板显示的工会名,具体使用可参考任务工会呼出事件
Tan_task_text = ""
#任务列表
Tan_task_list = []
#任务格式设定如下:
#Tan_task_list[id] = ["任务名","任务描述",[任务奖励数组],[任务接取条件数组],[任务完成条件数组],是否可重复接取标志]
#例如:
#1号任务内容如下:
Tan_task_list[1] = [
"测试", #任务名
#任务描述
#描述会自动换行
#使用\\n可描述第i号角色名,使用\\p可描述第i号队员名
#使用\\j可描述第i号职业名,使用\\s可描述第i号技能名
#使用\\t可描述第i号物品名,使用\\w可描述第i号武器名
#使用\\a可描述第i号防具名,使用\\m可描述第i号地图名
#使用\\v可描述第i号变量值,使用\\e可描述第i号敌人名,
#使用\\q可描述第i号任务名
#使用\\c可将字体改为第i号颜色,使用\\+字体加粗,使用\\-字体斜体
#使用\\i绘制i号图标,使用\\{字体加大,使用\\}字体变小,使用\\n换行
"描述", #任务描述
#任务奖励
#第1位代表奖励类型,0金钱,1武器,2防具,3物品,5经验值,9其他
#第2位代表奖励的id,如果没有id,则统一0(金钱、经验值、其他都是没有id的)
#第3位代表奖励数值。
#例如:[0,0,100]金钱100,[1,99,2]99号武器2把,[5,0,1000]经验值1000(不显示升级),[5,1,1000]经验值1000(显示升级)
#例如:[2,3,1]3号防具1个,[3,5,7]5号物品7个,[9,0,"$game_party.add_actor(33)"]33号人物入队
[],#如果没有奖励,则[]
#任务接取条件
#第1位代表条件类型,l领队等级,i持有物品,s开关打开,v变量值,q前置任务,g金钱
#第2位代表条件类型的id,如果没有id,则统一0(领队等级、前置任务、金钱是没有id的)
#第3位代表条件数值。
#例如:["l",0,10]领队要求10级,["i",6,3]持有3个6号物品,["s",7,true]7号开关打开
#例如:["v",5,10]5号变量等于10,["g",0,3]持有3金钱,["q",0,3]完成3号任务
[],#如果没有条件,则[]
#任务完成条件
#第1位代表条件类型,l领队等级,i持有物品,s开关打开,v变量值,q前置任务,g金钱,e杀敌数
#第2位代表条件类型的id,如果没有id,则统一0(领队等级、前置任务、金钱是没有id的)
#第3位代表条件数值。
#例如:["l",0,10]领队要求10级,["i",6,3]持有3个6号物品,["s",7,true]7号开关打开
#例如:["v",5,10]5号变量等于10,["g",0,3]持有3金钱,["q",0,3]完成3号任务,["e",7,10]杀死10个7号敌人
[],#如果没有条件,则[]
#该任务完成后是否可重复接取,0不可重复,1可重复
0
]
Tan_task_list[3] = [
"任务3",
"要求队长达到10级。",
[],
[],
[["l",0,10]],
0
]
Tan_task_list[2] = [
"任务2",
"要求队长达到10级,杀死史莱姆3只。",
[],
[],
[["l",0,10],["e",1,3]],
0
]
Tan_task_list[5] = [
"任务5", #任务名
"任务5的描述", #任务描述
[],
[],
[],
0
]
end
class Game_Party < Game_Unit
attr_reader :tan_task_state #任务状态数组
attr_accessor :tan_task_enemy_kill_number #记录杀敌数
#--------------------------------------------------------------------------
# ● 初始化对象(alias重写)
#--------------------------------------------------------------------------
alias tan_task_game_party_init initialize
def initialize
tan_task_game_party_init
@tan_task_state = [0] * Tan_task::Tan_task_list.size
@tan_task_enemy_kill_number = {}
end
#--------------------------------------------------------------------------
# ● 判定任务是否可接取
#--------------------------------------------------------------------------
def can_accept_the_tan_task?(id)
return false if @tan_task_state[id] != 0
return true if Tan_task::Tan_task_list[id][3].size == 0
re = 0
Tan_task::Tan_task_list[id][3].each {|q|
case q[0]
when "l"#等级条件
re += 1 if leader.level < q[2].to_i
when "i"#持有物品
re += 1 if item_number($data_items[q[1].to_i]) < q[2].to_i
when "g"#金钱
re += 1 if gold < q[2].to_i
when "q"#前置任务
re += 1 if @tan_task_state[q[2].to_i] != 2
when "s"#开关状态
re += 1 if $game_switches[q[1].to_i] != q[2]
when "v"#变量值是否等于指定值
re += 1 if $game_variables[q[1].to_i].to_s != q[2].to_s
end
}
return false if re != 0
return true
end
#--------------------------------------------------------------------------
# ● 接取任务
#--------------------------------------------------------------------------
def accept_the_tan_task(id)
@tan_task_state[id] = 1
Tan_task::Tan_task_list[id][4].each {|q|
case q[0]
when "e"#杀敌数
t = id.to_s + "_" + q[1].to_s
@tan_task_enemy_kill_number[t] = [q[1].to_i,0]
end
}
end
#--------------------------------------------------------------------------
# ● 完成任务
#--------------------------------------------------------------------------
def finish_the_tan_task(id)
@tan_task_state[id] = 2
Tan_task::Tan_task_list[id][4].each {|q|
case q[0]
when "e"#杀敌数
t = id.to_s + "_" + q[1].to_s
@tan_task_enemy_kill_number.delete(t)
end
}
Tan_task::Tan_task_list[id][2].each {|q|
case q[0]
when 0#奖励金钱
gain_gold(q[2].to_i)
when 1#奖励武器
gain_item($data_weapons[q[1].to_i], q[2].to_i)
when 2#奖励防具
gain_item($data_armors[q[1].to_i], q[2].to_i)
when 3#奖励物品
gain_item($data_items[q[1].to_i], q[2].to_i)
when 5#奖励经验值
members.each {|actor| actor.change_exp(actor.exp + q[2].to_i, q[1].to_i == 1)}
when 9#其他
eval(q[2])
end
}
@tan_task_state[id] = 0 if Tan_task::Tan_task_list[id][5] == 1
end
#--------------------------------------------------------------------------
# ● 判定任务是否可交付
#--------------------------------------------------------------------------
def can_finish_the_tan_task?(id)
return false if @tan_task_state[id] != 1
return true if Tan_task::Tan_task_list[id][4].size == 0
re = 0
Tan_task::Tan_task_list[id][4].each {|q|
case q[0]
when "l"#等级条件
re += 1 if leader.level < q[2].to_i
when "i"#持有物品
re += 1 if item_number($data_items[q[1].to_i]) < q[2].to_i
when "g"#金钱
re += 1 if gold < q[2].to_i
when "q"#前置任务
re += 1 if @tan_task_state[q[2].to_i] != 2
when "s"#开关状态
re += 1 if $game_switches[q[1].to_i] != q[2]
when "v"#变量值是否等于指定值
re += 1 if $game_variables[q[1].to_i].to_s != q[2].to_s
when "e"#指定杀敌数
t = id.to_s + "_" + q[1].to_s
re += 1 if @tan_task_enemy_kill_number[t][1] < q[2].to_i
end
}
return false if re != 0
return true
end
end
#记录杀敌数
class Game_Troop < Game_Unit
#--------------------------------------------------------------------------
# ● 计算杀敌数
#--------------------------------------------------------------------------
def tan_task_kill_number
dead_members.each {|enemy|
$game_party.tan_task_enemy_kill_number.each_value{|knum| knum[1] += 1 if knum[0].to_i == enemy.enemy_id}
}
end
#--------------------------------------------------------------------------
# ● 生成物品数组(alias重写),将计算杀敌数的方法放到这里,在掉落物里计算杀敌数
#--------------------------------------------------------------------------
alias tan_task_game_troop_make_drop_items make_drop_items
def make_drop_items
tan_task_kill_number
return tan_task_game_troop_make_drop_items
end
end[/pre]任务类型窗口[pre lang="ruby"]#encoding:utf-8
#==============================================================================
#------------------------------------------------------------------------------
# 任务类型窗口。
#==============================================================================
class Window_Tan_Task_Type < Window_HorzCommand
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :item_list_window
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize
super(180, 0)
end
#--------------------------------------------------------------------------
# ● 获取窗口的宽度
#--------------------------------------------------------------------------
def window_width
Graphics.width - 180
end
#--------------------------------------------------------------------------
# ● 获取列数
#--------------------------------------------------------------------------
def col_max
return 2
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
super
@item_list_window.category = current_symbol if @item_list_window
end
#--------------------------------------------------------------------------
# ● 生成指令列表
#--------------------------------------------------------------------------
def make_command_list
#add_command("所有任务", 0)
add_command("当前任务", 1)
add_command("已完成任务", 2)
end
#--------------------------------------------------------------------------
# ● 设置物品窗口
#--------------------------------------------------------------------------
def item_list_window=(item_list_window)
@item_list_window = item_list_window
update
end
end
[/pre]
任务列表窗口[pre lang="ruby"]#--------------------------------------------------------------------------
# 任务列表窗口
#--------------------------------------------------------------------------
class Window_Tan_Task_List < Window_Command
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize
super(0,50)
@status_window = nil
@category = nil
end
#--------------------------------------------------------------------------
# ● 设置描述状态窗口
#--------------------------------------------------------------------------
def status_window=(status_window)
return if @status_window == status_window
@status_window = status_window
refresh
end
#--------------------------------------------------------------------------
# ● 设置分类
#--------------------------------------------------------------------------
def category=(category)
return if @category == category
@category = category
refresh
#self.oy = 0
end
#--------------------------------------------------------------------------
# ● 获取分类值
#--------------------------------------------------------------------------
def get_category
return @category
end
#--------------------------------------------------------------------------
# ● 获取窗口的宽度
#--------------------------------------------------------------------------
def window_width
return 160
end
#--------------------------------------------------------------------------
# ● 获取窗口的高度
#--------------------------------------------------------------------------
def window_height
return Graphics.height - 50
end
#--------------------------------------------------------------------------
# ● 生成指令列表
#--------------------------------------------------------------------------
def make_command_list
$game_party.tan_task_state.each_with_index {|pp,i|
next if @category and pp != @category
next if Tan_task::Tan_task_list == nil
text = Tan_task::Tan_task_list[0]
handle = i
case @category
when 0
add_command(text, handle, false)
when 1
add_command(text, handle, false)
when 2
add_command(text, handle, false)
end
}
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
super
@status_window.task_id = current_symbol if @status_window
end
def cursor_down(wrap = false); super;refresh;end
def cursor_up(wrap = false); super;refresh;end
def cursor_left(wrap = false); super;refresh;end
def cursor_right(wrap = false); super;refresh;end
end[/pre]
任务内容窗口[pre lang="ruby"]#--------------------------------------------------------------------------
# 任务内容窗口
#--------------------------------------------------------------------------
class Window_Tan_Task_Status < Window_Base
def initialize
super(160, 50, width, height)
@task_id = nil
refresh
end
#--------------------------------------------------------------------------
# ● 获取宽度
#--------------------------------------------------------------------------
def width
Graphics.width - 160
end
#--------------------------------------------------------------------------
# ● 获取高度
#--------------------------------------------------------------------------
def height
Graphics.height - 50
end
#--------------------------------------------------------------------------
# ● 设置task_id
#--------------------------------------------------------------------------
def task_id=(task_id)
return if @task_id == task_id
@task_id = task_id
refresh
end
#--------------------------------------------------------------------------
# ● 清除
#--------------------------------------------------------------------------
def clear
contents.clear
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
clear
draw_task if @task_id
end
#--------------------------------------------------------------------------
# ● 绘制内容
#--------------------------------------------------------------------------
def draw_task
self.contents.font.size = 18
if Tan_task::Tan_task_description_type
draw_quest_text(self.contents, 0, 0, self.contents.width - 15, 24, Tan_task::Tan_task_list[@task_id][1])
else
text = "\\c[2]接取要求:\\c[0]"
text += "无" if Tan_task::Tan_task_list[@task_id][3].size == 0
Tan_task::Tan_task_list[@task_id][3].each {|q|
case q[0]
when "l"#等级条件
text += "队长达到#{q[2].to_i}级。"
when "i"#持有物品
text += "持有#{q[2].to_i}个#{$data_items[q[1].to_i].name}。"
when "g"#金钱
text += "持有#{q[2].to_i}金钱。"
when "q"#前置任务
text += "前置任务:#{Tan_task::Tan_task_list[q[2].to_i][0]}。"
else
text += "完成其他指定要求。"
end
}
text += "\\n\\c[2]任务内容:\\c[0]"
text += "\\n" + Tan_task::Tan_task_list[@task_id][1].to_s
Tan_task::Tan_task_list[@task_id][4].each{|q|
case q[0]
when "e"
t = @task_id.to_s + "_" + q[1].to_s
text += "\\n需要杀死\\c[2]#{$data_enemies[q[1].to_i].name}\\c[0]#{q[2].to_i}个,当前已杀#{$game_party.tan_task_enemy_kill_number[t][1]}个。" if $game_party.tan_task_enemy_kill_number[t]
when "i"
text += "\\n需要持有\\c[6]#{$data_items[q[1].to_i].name}\\c[0]#{q[2].to_i}个,当前持有#{$game_party.item_number($data_items[q[1].to_i])}个。"
end
}
text += "\\n\\c[2]任务奖励:\\c[0]"
text += "无" if Tan_task::Tan_task_list[@task_id][2].size == 0
Tan_task::Tan_task_list[@task_id][2].each {|q|
case q[0].to_i
when 0#奖励金钱
text += "#{q[2].to_i}金钱。"
when 1#奖励武器
text += "#{$data_weapons[q[1].to_i].name}#{q[2].to_i}个。"
when 2#奖励防具
text += "#{$data_armors[q[1].to_i].name}#{q[2].to_i}个。"
when 3#奖励物品
text += "#{$data_items[q[1].to_i].name}#{q[2].to_i}个。"
when 5#奖励经验值
text += "#{q[2].to_i}经验。"
else
text += "#{q[1].to_s}。"
end
}
draw_quest_text(self.contents, 0, 0, self.contents.width - 15, 24, text)
end
end
#--------------------------------------------------------------------------
# ● 控制文字的变换
#--------------------------------------------------------------------------
def conv_text(txt)
return "" if txt.nil? or txt == ""
text = txt.dup
## 控制字符的解码变换
# 会先进行名称转换
# \\n[n] : ID:n-角色名$game_actors[$1.to_i].name
text.gsub!(/\\[Nn]\[([0-9]+)\]/) { actor_name($1.to_i) }
# \\e[n] : ID:n-敌人名
text.gsub!(/\\[Ee]\[([0-9]+)\]/) { $data_enemies[$1.to_i].name }
# \\j[n] : ID:n-职业名
text.gsub!(/\\[Jj]\[([0-9]+)\]/) { $data_classes[$1.to_i].name }
# \\s[n] : ID:n-技能名
text.gsub!(/\\[Ss]\[([0-9]+)\]/) { $data_skills[$1.to_i].name }
# \\i[n] : ID:n-物品名
text.gsub!(/\\[Tt]\[([0-9]+)\]/) { $data_items[$1.to_i].name }
# \\w[n] : ID:n-武器名
text.gsub!(/\\[Ww]\[([0-9]+)\]/) { $data_weapons[$1.to_i].name }
# \\a[n] : ID:n-防具名
text.gsub!(/\\[Aa]\[([0-9]+)\]/) { $data_armors[$1.to_i].name }
# \\m[n] : ID:n-地图名
text.gsub!(/\\[Mm]\[([0-9]+)\]/) { load_data(sprintf("Data/Map%03d.rvdata2", $1.to_i)).display_name }
# \\v[n] : ID:n-变量值
text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
# \\p[n] : ID:n-队员名
text.gsub!(/\\[Pp]\[([0-9]+)\]/) { party_member_name($1.to_i) }
# \\q[n] : ID:n-任务名
text.gsub!(/\\[Qq]\[([0-9]+)\]/) { Tan_task::Tan_task_list[$1.to_i][0].to_s }
return text
end
#--------------------------------------------------------------------------
# ● 内容绘制
#--------------------------------------------------------------------------
def draw_quest_text(bitmap, x, y, w, text_h, txt)
txt = "" if txt.nil?
text = conv_text(txt)
y_org = y
xx = 0
line = 0
# 便宜上
text.gsub!(/\\\\/) { "\000" }
# \\c[n] : 文字色変更
text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
# \\+ : 加粗表示 开始/结束
text.gsub!(/\\[+]/) { "\002" }
# \\- : 斜体表示 开始/结束
text.gsub!(/\\[-]/) { "\003" }
# \\x[n] : X轴方向 n 的当前位置刻画
text.gsub!(/\\[Xx]\[([0-9]+)\]/) { "\004[#{$1}]" }
# \\y[n] : 指定行CR回车
text.gsub!(/\\[Yy]\[([0-9]+)\]/) { "\005[#{$1}]" }
# \\i : icon表示
text.gsub!(/\\[Ii]\[(.*?+)\]/) { "\006[#{$1}]" }
# \\{} : 扩大・缩小
text.gsub!(/\\{/) { "\007" }
text.gsub!(/\\}/) { "\008" }
# \\n : 改行
text.gsub!(/\\[Nn]/) { "\n" }
bold = bitmap.font.bold
italic = bitmap.font.italic
color = bitmap.font.color.dup
size = bitmap.font.size
while ((c = text.slice!(/./m)) != nil)
case c
when "\000" # \\ 的场合,还原原来的文字
c = "\\"
when "\n" # \\n : 改行
xx = 0; y += text_h; line += 1
next # 下一个字符
when "\001" # \\c[n] : 文字色变更
text.sub!(/\[([0-9]+)\]/, "")
bitmap.font.color = text_color($1.to_i)
next # 下一个字符
when "\002" # \\+ : 加粗表示 开始/结束
bitmap.font.bold = !bitmap.font.bold
next # 下一个字符
when "\003" # \\- : 斜体表示 开始/结束
bitmap.font.italic = !bitmap.font.italic
next # 下一个字符
when "\004" # \\x[n] : X轴方向 n 的当前位置刻画
text.sub!(/\[([0-9]+)\]/, "")
xx = $1.to_i
next # 下一个字符
when "\005" # \\y[n] : 指定行CR回车
text.sub!(/\[([0-9]+)\]/, "")
y = y_org + $1.to_i * text_h
xx = 0
next # 下一个字符
when "\006" # \\i : icon显示
text.sub!(/\[(.*?+)\]/, "")
xx += draw_icon(bitmap, x+xx, y, text_h, $1.to_i)
next # 下一个字符
when "\007" # \\{ : 扩大
bitmap.font.size += 8 if bitmap.font.size <= 64
next # 下一个字符
when "\008" # \\} : 缩小
bitmap.font.size -= 8 if bitmap.font.size >= 16
next # 下一个字符
end
# 文字描画
bitmap.draw_text(x+xx, y, 40, text_h, c)
# x 被绘制字符宽度的加算
xx += bitmap.text_size(c).width
# 自动改行
if xx > w
xx = 0; y += text_h
end
end
# 作为预防措施,还原初始设定
bitmap.font.bold = bold
bitmap.font.italic = italic
bitmap.font.color = color.dup
bitmap.font.size = size
end
#--------------------------------------------------------------------------
# ● 描画(Icon) \\icon用
#--------------------------------------------------------------------------
def draw_icon(bitmap, x, y, h, icon_index)
bit = Cache.system("Iconset")
rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
bitmap.blt(x, y, bit, rect)
return rect.width
end
#--------------------------------------------------------------------------
# ● 描画色 \\c用
#--------------------------------------------------------------------------
def text_color(n)
return Cache.system("Window").get_pixel(64 + (n % 8) * 8, 96 + (n / 8) * 8)
end
end[/pre]
任务查看(界面)[pre lang="ruby"]#--------------------------------------------------------------------------
# 主窗体
#--------------------------------------------------------------------------
class Scene_Tan_Task < Scene_MenuBase
def start
super
create_task_window
create_tasklist_window
create_select_window
end
#类型窗体
def create_select_window
@tasktype_window = Window_Tan_Task_Type.new
@tasktype_window.viewport = @viewport
@tasktype_window.activate
@tasktype_window.item_list_window = @tasklist_window
@tasktype_window.set_handler(:ok, method(:on_tasktype_ok))
@tasktype_window.set_handler(:cancel, method(:return_scene))
end
#列表窗体
def create_tasklist_window
@tasklist_window = Window_Tan_Task_List.new
@tasklist_window.viewport = @viewport
@tasklist_window.status_window = @task_window
@tasklist_window.deactivate
@tasklist_window.set_handler(:ok, method(:select_tasklist_ok))
@tasklist_window.set_handler(:cancel, method(:select_tasklist_cancel))
end
#内容窗体
def create_task_window
@task_window = Window_Tan_Task_Status.new
@task_window.viewport = @viewport
@task_window.deactivate
end
#任务类型窗口按确定
def on_tasktype_ok
@tasktype_window.deactivate
@tasklist_window.activate
end
#任务类型窗口按取消
def return_scene
SceneManager.return
end
#任务选择窗口按确定
def select_tasklist_ok
end
#任务选择窗口按取消
def select_tasklist_cancel
@tasklist_window.deactivate
@tasktype_window.activate
end
end[/pre]
任务工会名窗口[pre lang="ruby"]#encoding:utf-8
#==============================================================================
# 显示工会名的窗口
#==============================================================================
class Window_Task_Help < Window_Base
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize(line_number = 2)
super(0,0, Graphics.width, 50)
end
#--------------------------------------------------------------------------
# ● 设置内容
#--------------------------------------------------------------------------
def set_text(text)
if text != @text
@text = text
refresh
end
end
#--------------------------------------------------------------------------
# ● 清除
#--------------------------------------------------------------------------
def clear
set_text("")
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
contents.clear
draw_text_ex(4, 0, @text)
end
end[/pre]
任务工会列表窗口[pre lang="ruby"]#--------------------------------------------------------------------------
# 任务列表窗口
#--------------------------------------------------------------------------
class Window_Tan_Task_List2 < Window_Command
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize
super(0,50)
@status_window = nil
@command_window = nil
end
#--------------------------------------------------------------------------
# ● 设置描述状态窗口
#--------------------------------------------------------------------------
def status_window=(status_window)
return if @status_window == status_window
@status_window = status_window
refresh
end
#--------------------------------------------------------------------------
# ● 设置命令窗口
#--------------------------------------------------------------------------
def command_window=(command_window)
return if @command_window == command_window
@command_window = command_window
refresh
end
#--------------------------------------------------------------------------
# ● 获取窗口的宽度
#--------------------------------------------------------------------------
def window_width
return 160
end
#--------------------------------------------------------------------------
# ● 获取窗口的高度
#--------------------------------------------------------------------------
def window_height
return Graphics.height - 50
end
#--------------------------------------------------------------------------
# ● 生成指令列表
#--------------------------------------------------------------------------
def make_command_list
return if Tan_task::Tan_task_list2.size == 0
Tan_task::Tan_task_list2.each {|i|
next if Tan_task::Tan_task_list == nil
text = Tan_task::Tan_task_list[0]
b = false
case $game_party.tan_task_state
when 0
b = true if $game_party.can_accept_the_tan_task?(i)
text += "(可接取)" if b
when 1
b = true if $game_party.can_finish_the_tan_task?(i)
if b
text += "(可交付)"
else
text += "(进行中)"
end
when 2
text += "(已完成)"
end
handle = i
add_command(text, handle, b)
}
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
super
@status_window.task_id = current_symbol if @status_window
@command_window.task_id = current_symbol if @command_window
end
def cursor_down(wrap = false); super;refresh;end
def cursor_up(wrap = false); super;refresh;end
def cursor_left(wrap = false); super;refresh;end
def cursor_right(wrap = false); super;refresh;end
end[/pre]任务工会内容窗口[pre lang="ruby"]#--------------------------------------------------------------------------
# 任务内容窗口
#--------------------------------------------------------------------------
class Window_Tan_Task_Status2 < Window_Base
def initialize
super(160, 50, width, height)
@task_id = nil
refresh
end
#--------------------------------------------------------------------------
# ● 获取宽度
#--------------------------------------------------------------------------
def width
Graphics.width - 160
end
#--------------------------------------------------------------------------
# ● 获取高度
#--------------------------------------------------------------------------
def height
Graphics.height - 50
end
#--------------------------------------------------------------------------
# ● 设置task_id
#--------------------------------------------------------------------------
def task_id=(task_id)
return if @task_id == task_id
@task_id = task_id
refresh
end
#--------------------------------------------------------------------------
# ● 清除
#--------------------------------------------------------------------------
def clear
contents.clear
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
clear
draw_task if @task_id
end
#--------------------------------------------------------------------------
# ● 绘制内容
#--------------------------------------------------------------------------
def draw_task
self.contents.font.size = 18
if Tan_task::Tan_task_description_type
draw_quest_text(self.contents, 0, 0, self.contents.width - 15, 24, Tan_task::Tan_task_list[@task_id][1])
else
text = "\\c[2]接取要求:\\c[0]"
text += "无" if Tan_task::Tan_task_list[@task_id][3].size == 0
Tan_task::Tan_task_list[@task_id][3].each {|q|
case q[0]
when "l"#等级条件
text += "队长达到#{q[2].to_i}级。"
when "i"#持有物品
text += "持有#{q[2].to_i}个#{$data_items[q[1].to_i].name}。"
when "g"#金钱
text += "持有#{q[2].to_i}金钱。"
when "q"#前置任务
text += "前置任务:#{Tan_task::Tan_task_list[q[2].to_i][0]}。"
else
text += "完成其他指定要求。"
end
}
text += "\\n\\c[2]任务内容:\\c[0]"
text += "\\n" + Tan_task::Tan_task_list[@task_id][1].to_s
Tan_task::Tan_task_list[@task_id][4].each{|q|
case q[0]
when "e"
t = @task_id.to_s + "_" + q[1].to_s
text += "\\n需要杀死\\c[2]#{$data_enemies[q[1].to_i].name}\\c[0]#{q[2].to_i}个,当前已杀#{$game_party.tan_task_enemy_kill_number[t][1]}个。" if $game_party.tan_task_enemy_kill_number[t]
when "i"
text += "\\n需要持有\\c[6]#{$data_items[q[1].to_i].name}\\c[0]#{q[2].to_i}个,当前持有#{$game_party.item_number($data_items[q[1].to_i])}个。"
end
}
text += "\\n\\c[2]任务奖励:\\c[0]"
text += "无" if Tan_task::Tan_task_list[@task_id][2].size == 0
Tan_task::Tan_task_list[@task_id][2].each {|q|
case q[0].to_i
when 0#奖励金钱
text += "#{q[2].to_i}金钱。"
when 1#奖励武器
text += "#{$data_weapons[q[1].to_i].name}#{q[2].to_i}个。"
when 2#奖励防具
text += "#{$data_armors[q[1].to_i].name}#{q[2].to_i}个。"
when 3#奖励物品
text += "#{$data_items[q[1].to_i].name}#{q[2].to_i}个。"
when 5#奖励经验值
text += "#{q[2].to_i}经验。"
else
text += "#{q[1].to_s}。"
end
}
draw_quest_text(self.contents, 0, 0, self.contents.width - 15, 24, text)
end
end
#--------------------------------------------------------------------------
# ● 控制文字的变换
#--------------------------------------------------------------------------
def conv_text(txt)
return "" if txt.nil? or txt == ""
text = txt.dup
## 控制字符的解码变换
# 会先进行名称转换
# \\n[n] : ID:n-角色名$game_actors[$1.to_i].name
text.gsub!(/\\[Nn]\[([0-9]+)\]/) { actor_name($1.to_i) }
# \\e[n] : ID:n-敌人名
text.gsub!(/\\[Ee]\[([0-9]+)\]/) { $data_enemies[$1.to_i].name }
# \\j[n] : ID:n-职业名
text.gsub!(/\\[Jj]\[([0-9]+)\]/) { $data_classes[$1.to_i].name }
# \\s[n] : ID:n-技能名
text.gsub!(/\\[Ss]\[([0-9]+)\]/) { $data_skills[$1.to_i].name }
# \\i[n] : ID:n-物品名
text.gsub!(/\\[Tt]\[([0-9]+)\]/) { $data_items[$1.to_i].name }
# \\w[n] : ID:n-武器名
text.gsub!(/\\[Ww]\[([0-9]+)\]/) { $data_weapons[$1.to_i].name }
# \\a[n] : ID:n-防具名
text.gsub!(/\\[Aa]\[([0-9]+)\]/) { $data_armors[$1.to_i].name }
# \\m[n] : ID:n-地图名
text.gsub!(/\\[Mm]\[([0-9]+)\]/) { load_data(sprintf("Data/Map%03d.rvdata2", $1.to_i)).display_name }
# \\v[n] : ID:n-变量值
text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
# \\p[n] : ID:n-队员名
text.gsub!(/\\[Pp]\[([0-9]+)\]/) { party_member_name($1.to_i) }
# \\q[n] : ID:n-任务名
text.gsub!(/\\[Qq]\[([0-9]+)\]/) { Tan_task::Tan_task_list[$1.to_i][0].to_s }
return text
end
#--------------------------------------------------------------------------
# ● 内容绘制
#--------------------------------------------------------------------------
def draw_quest_text(bitmap, x, y, w, text_h, txt)
txt = "" if txt.nil?
text = conv_text(txt)
y_org = y
xx = 0
line = 0
# 便宜上
text.gsub!(/\\\\/) { "\000" }
# \\c[n] : 文字色変更
text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
# \\+ : 加粗表示 开始/结束
text.gsub!(/\\[+]/) { "\002" }
# \\- : 斜体表示 开始/结束
text.gsub!(/\\[-]/) { "\003" }
# \\x[n] : X轴方向 n 的当前位置刻画
text.gsub!(/\\[Xx]\[([0-9]+)\]/) { "\004[#{$1}]" }
# \\y[n] : 指定行CR回车
text.gsub!(/\\[Yy]\[([0-9]+)\]/) { "\005[#{$1}]" }
# \\i : icon表示
text.gsub!(/\\[Ii]\[(.*?+)\]/) { "\006[#{$1}]" }
# \\{} : 扩大・缩小
text.gsub!(/\\{/) { "\007" }
text.gsub!(/\\}/) { "\008" }
# \\n : 改行
text.gsub!(/\\[Nn]/) { "\n" }
bold = bitmap.font.bold
italic = bitmap.font.italic
color = bitmap.font.color.dup
size = bitmap.font.size
while ((c = text.slice!(/./m)) != nil)
case c
when "\000" # \\ 的场合,还原原来的文字
c = "\\"
when "\n" # \\n : 改行
xx = 0; y += text_h; line += 1
next # 下一个字符
when "\001" # \\c[n] : 文字色变更
text.sub!(/\[([0-9]+)\]/, "")
bitmap.font.color = text_color($1.to_i)
next # 下一个字符
when "\002" # \\+ : 加粗表示 开始/结束
bitmap.font.bold = !bitmap.font.bold
next # 下一个字符
when "\003" # \\- : 斜体表示 开始/结束
bitmap.font.italic = !bitmap.font.italic
next # 下一个字符
when "\004" # \\x[n] : X轴方向 n 的当前位置刻画
text.sub!(/\[([0-9]+)\]/, "")
xx = $1.to_i
next # 下一个字符
when "\005" # \\y[n] : 指定行CR回车
text.sub!(/\[([0-9]+)\]/, "")
y = y_org + $1.to_i * text_h
xx = 0
next # 下一个字符
when "\006" # \\i : icon显示
text.sub!(/\[(.*?+)\]/, "")
xx += draw_icon(bitmap, x+xx, y, text_h, $1.to_i)
next # 下一个字符
when "\007" # \\{ : 扩大
bitmap.font.size += 8 if bitmap.font.size <= 64
next # 下一个字符
when "\008" # \\} : 缩小
bitmap.font.size -= 8 if bitmap.font.size >= 16
next # 下一个字符
end
# 文字描画
bitmap.draw_text(x+xx, y, 40, text_h, c)
# x 被绘制字符宽度的加算
xx += bitmap.text_size(c).width
# 自动改行
if xx > w
xx = 0; y += text_h
end
end
# 作为预防措施,还原初始设定
bitmap.font.bold = bold
bitmap.font.italic = italic
bitmap.font.color = color.dup
bitmap.font.size = size
end
#--------------------------------------------------------------------------
# ● 描画(Icon) \\icon用
#--------------------------------------------------------------------------
def draw_icon(bitmap, x, y, h, icon_index)
bit = Cache.system("Iconset")
rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
bitmap.blt(x, y, bit, rect)
return rect.width
end
#--------------------------------------------------------------------------
# ● 描画色 \\c用
#--------------------------------------------------------------------------
def text_color(n)
return Cache.system("Window").get_pixel(64 + (n % 8) * 8, 96 + (n / 8) * 8)
end
end[/pre]任务工会命令窗口[pre lang="ruby"]#--------------------------------------------------------------------------
# 任务命令窗体
#--------------------------------------------------------------------------
class Window_Tan_Task_Command < Window_HorzCommand
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :item_list_window
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize
super(180, Graphics.height / 2)
@task_id = nil
refresh
end
#--------------------------------------------------------------------------
# ● 设置task_id
#--------------------------------------------------------------------------
def task_id=(task_id)
return if @task_id == task_id
@task_id = task_id
refresh
end
#--------------------------------------------------------------------------
# ● 获取窗口的宽度
#--------------------------------------------------------------------------
def window_width
Graphics.width - 360
end
#--------------------------------------------------------------------------
# ● 获取列数
#--------------------------------------------------------------------------
def col_max
return 2
end
#--------------------------------------------------------------------------
# ● 判定窗口类型
#--------------------------------------------------------------------------
def accept_or_finish
return 9 if @task_id == nil
case $game_party.tan_task_state[@task_id]
when 0
return 0
when 1
return 1
else
return 9
end
end
#--------------------------------------------------------------------------
# ● 生成指令列表
#--------------------------------------------------------------------------
def make_command_list
return if @task_id == nil
case $game_party.tan_task_state[@task_id]
when 0
add_command("接受",1,$game_party.can_accept_the_tan_task?(@task_id))
add_command("取消",2)
when 1
add_command("完成",1,$game_party.can_finish_the_tan_task?(@task_id))
add_command("取消",2)
else
add_command("查看",1)
add_command("取消",2)
end
end
end[/pre]任务工会(界面)[pre lang="ruby"]#--------------------------------------------------------------------------
# 主窗体
#--------------------------------------------------------------------------
class Scene_Tan_Task2 < Scene_MenuBase
def start
super
create_task_help
create_task_window
create_command_window
create_tasklist_window
end
#标题窗体
def create_task_help
@taskhelp_window = Window_Task_Help.new
@taskhelp_window.viewport = @viewport
@taskhelp_window.set_text(Tan_task::Tan_task_text)
end
#列表窗体
def create_tasklist_window
@tasklist_window = Window_Tan_Task_List2.new
@tasklist_window.viewport = @viewport
@tasklist_window.status_window = @task_window
@tasklist_window.command_window = @command_window
@tasklist_window.activate
@tasklist_window.set_handler(:ok, method(:select_tasklist_ok))
@tasklist_window.set_handler(:cancel, method(:select_tasklist_cancel))
end
#内容窗体
def create_task_window
@task_window = Window_Tan_Task_Status2.new
@task_window.viewport = @viewport
@task_window.deactivate
end
#命令窗体
def create_command_window
@command_window = Window_Tan_Task_Command.new
@command_window.viewport = @viewport
@command_window.hide.deactivate
@command_window.set_handler(:ok, method(:on_taskcommand_ok))
@command_window.set_handler(:cancel, method(:on_taskcommand_scene))
end
#任务选择窗口按确定
def select_tasklist_ok
@command_window.task_id = @tasklist_window.current_symbol if @command_window
@tasklist_window.deactivate
@command_window.show.activate
end
#任务选择窗口按取消
def select_tasklist_cancel
SceneManager.return
end
#任务命令窗口按确定
def on_taskcommand_ok
if @command_window.current_symbol == 1
if @command_window.accept_or_finish == 0
$game_party.accept_the_tan_task(@tasklist_window.current_symbol)
elsif @command_window.accept_or_finish == 1
$game_party.finish_the_tan_task(@tasklist_window.current_symbol)
else
end
end
@tasklist_window.refresh
@task_window.refresh
@command_window.refresh
@command_window.hide.deactivate
@tasklist_window.activate
end
#任务命令窗口按取消
def on_taskcommand_scene
@command_window.hide.deactivate
@tasklist_window.activate
end
end[/pre]
|
|