#==============================================================================#
# 便民任务界面v0.5 by EngShun #
# #
# 设置方法请参考范例 #
# #
# 效果说明: #
# 支持普通对话框效果 #
# \a[号码] :更改对齐方式(0,1,2)。 #
# \itm[物品id] :物品数量 #
# \wpn[武器id] :武器数量 #
# \amr[防具id] :防具数量 #
# \eval{脚本} :运行脚本 #
# \bold :字体加粗,插入多一次关闭 #
# \italic :字体打斜,插入多一次关闭 #
# \f[字体名称] :更改字体 #
# \s[号码] :更改字体大小 #
# \p[名称] :插入图片 #
# \icon[名称] :插入图标 #
# #
#==============================================================================#
#===============================================================================
# ■ 队伍
#===============================================================================
class Game_Party
Mission = Struct.new(:name, :info, :status)
alias org_init_mission initialize
def initialize
[url=home.php?mod=space&uid=364398]@mission[/url] = []
org_init_mission
end
def no_mission?
return @mission == []
end
def mission
if @mission == []
m = Mission.new("没有任务","\n\n\n\\a[1]\\s[32]你还没有领取任何任务",0)
return [m]
end
return @mission
end
def get_mission(mission,info)
for i in [email]0...@mission.size[/email]
if @mission[i].name == mission
return
end
end
@mission.push(Mission.new(mission,info,0))
end
def done_mission(done_mission)
for i in [email]0...@mission.size[/email]
if @mission[i].name == done_mission
@mission[i].status = 1 if @mission[i].status == 0
end
end
end
def delete_mission(delete_mission)
for i in [email]0...@mission.size[/email]
if @mission[i].name == delete_mission
@mission.delete(@mission[i])
return
end
end
end
def fail_mission(mission)
for i in [email]0...@mission.size[/email]
if @mission[i].name == mission
@mission[i].status = 2 if @mission[i].status == 0
end
end
end
def resume_mission(mission)
for i in [email]0...@mission.size[/email]
if @mission[i].name == mission
@mission[i].status = 0 if @mission[i].status == 2
end
end
end
def done_all_mission
@mission.each{|m|m.status = 1}
end
def update_mission(mission,info)
for i in [email]0...@mission.size[/email]
if @mission[i].name == mission
@mission[i].info = info
end
end
end
def add_mission_info(mission,info)
for i in [email]0...@mission.size[/email]
if @mission[i].name == mission
@mission[i].info += "\n" + info
end
end
end
def delete_all_mission
@mission = []
end
def resume_all_mission
@mission.each{|m|m.status = 0 if m.status == 2}
end
end
#===============================================================================
# ■ 任务列表窗口
#===============================================================================
class Window_Mission < Window_Selectable
def initialize
super(0, 64, 200, 416)
self.index = 0
@item_max = $game_party.mission.size
if self.contents != nil
self.contents.dispose
self.contents = nil
end
self.contents = Bitmap.new(width - 32, @item_max * 32)
for i in 0...$game_party.mission.size
t = $game_party.mission[i].status != 0
self.contents.font.color = t ? disabled_color : normal_color
text = $game_party.mission[i].name
self.contents.draw_text(4, i * 32, 160, 32, text.to_s)
self.contents.font.color = system_color
self.contents.draw_text(self.contents.width-32, i * 32, 32, 32, "□",1) unless $game_party.no_mission?
if $game_party.mission[i].status == 1
self.contents.font.color = crisis_color
self.contents.draw_text(self.contents.width-32, i * 32, 32, 32, "√",1)
elsif $game_party.mission[i].status == 2
self.contents.font.color = knockout_color
self.contents.draw_text(self.contents.width-32, i * 32, 32, 32, "×",1)
end
end
end
end
#===============================================================================
# ■ 任务详情窗口
#===============================================================================
class Window_MissionInfo < Window_Base
def initialize
super(200,64,440,416)
self.contents = Bitmap.new(408, 384)
end
def refresh(str)
self.contents = Bitmap.new(408, 384) if self.contents == nil
self.contents.clear
y = 0
align = 0
begin
last_text = str.clone
str.gsub!(/\\v\[(\d+)\]/i) { $game_variables[$1.to_i] }
str.gsub!(/\\g/i) { $game_party.gold.to_s }
str.gsub!(/\\itm\[(\d+)\]/i) { $game_party.item_number($1.to_i) }
str.gsub!(/\\wpn\[(\d+)\]/i) { $game_party.weapon_number($1.to_i) }
str.gsub!(/\\amr\[(\d+)\]/i) { $game_party.armor_number($1.to_i) }
str.gsub!(/\\eval{(.+?)}/im) { eval($1) }
end until str == last_text
str.gsub!(/\\n\[(\d+)\]/i) do
$game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
end
lines = str.split("\n")
for line in lines
bitmap,align = bitmap_line(line,align)
w = bitmap.width
h = bitmap.height
case align
when 0
x = 4
when 1
x = 204 - w / 2
when 2
x = 404 - w
end
self.contents.blt(x,y,bitmap,Rect.new(0,0,w,h))
y += h
end
end
def bitmap_line(str,old_align)
w,h = get_wh(str.clone)
w = 1 if w == 0
bitmap = Bitmap.new(w,h)
text = str
align = old_align
x = 0
text.gsub!(/\\\\/) { "\000" }
text.gsub!(/\\a\[([0-2])\]/i){ align = $1.to_i; "" }
text.gsub!(/\\c\[(\d+)\]/i) { "\001[#{$1}]" }
text.gsub!(/\\bold/i) { "\002" }
text.gsub!(/\\italic/i) { "\003" }
text.gsub!(/\\f\[(\w+)\]/i) { "\004[#{$1}]" }
text.gsub!(/\\bd\[(\w+)\]/i) { "\005[#{$1}]" }
text.gsub!(/\\s\[(\d+)\]/i) { "\006[#{$1}]" }
text.gsub!(/\\p\[(.+?)\]/i) { "\007[#{$1}]" }
text.gsub!(/\\icon\[(.+?)\]/i){ "\201[#{$1}]" }
while ((c = text.slice!(/./m)) != nil)
if c == "\000"
c = "\\"
end
if c == "\001"
text.sub!(/\[(\d+)\]/, "")
color = $1.to_i
if color >= 0 and color <= 9
bitmap.font.color = text_color(color)
elsif color == 8
bitmap.font.color = disabled_color
elsif color == 9
bitmap.font.color = system_color
end
next
end
if c == "\002"
bitmap.font.bold = bitmap.font.bold ? false : true
next
end
if c == "\003"
bitmap.font.italic = bitmap.font.italic ? false : true
next
end
if c == "\004"
text.sub!(/\[(\w+)\]/,"")
bitmap.font.name = $1
next
end
if c == "\005"
text.sub!(/\[(\w+)\]/,"")
color = bitmap.font.color.clone
w = bitmap.text_size($1).width
bitmap.font.color = Color.new(0,0,0,255)
bitmap.draw_text((4 + x)-1, y-1, w, 32, $1)
bitmap.draw_text((4 + x)-1, y+1, w, 32, $1)
bitmap.draw_text((4 + x)+1, y-1, w, 32, $1)
bitmap.draw_text((4 + x)+1, y+1, w, 32, $1)
bitmap.font.color = color
bitmap.draw_text(4 + x, y, w, 32, $1)
x += bitmap.text_size($1).width
next
end
if c == "\006"
text.sub!(/\[(\d+)\]/,"")
bitmap.font.size = $1.to_i
next
end
if c == "\007"
text.sub!(/\[(.+?)\]/,"")
pic = RPG::Cache.picture($1)
r = Rect.new(0,0,pic.width,pic.height)
y = h / 2 - pic.height / 2
bitmap.blt(x+2,y,pic,r)
x += pic.width + 4
next
end
if c == "\201"
text.sub!(/\[(.+?)\]/,"")
pic = RPG::Cache.icon($1)
r = Rect.new(0,0,pic.width,pic.height)
y = h / 2 - pic.height / 2
bitmap.blt(x+2,y,pic,r)
x += pic.width + 4
next
end
bitmap.draw_text(x,0,w,h,c)
x += bitmap.text_size(c).width
end
return bitmap.clone,align
end
def get_wh(str)
bitmap = Bitmap.new(160,160)
w = 0
h = 32
text = str
text.gsub!(/\\\\/) { "\000" }
text.gsub!(/\\a\[([0-2])\]/i) { "" }
text.gsub!(/\\c\[(\d+)\]/i) { "" }
text.gsub!(/\\bold/i) { "" }
text.gsub!(/\\italic/i) { "" }
text.gsub!(/\\f\[(\w+)\]/i) { "\001[#{$1}]" }
text.gsub!(/\\bd\[(\w+)\]/i) { $1 }
text.gsub!(/\\s\[(\d+)\]/i) { "\002[#{$1}]" }
text.gsub!(/\\p\[(.+?)\]/i) { "\003[#{$1}]" }
text.gsub!(/\\icon\[(.+?)\]/i) { "\004[#{$1}]" }
while ((c = text.slice!(/./m)) != nil)
if c == "\000"
c = "\\"
end
if c == "\001"
text.sub!(/\[(\w+)]/,"")
bitmap.font.name = $1
next
end
if c == "\002"
text.sub!(/\[(\d+)]/,"")
bitmap.font.size = $1.to_i
next
end
if c == "\003"
text.sub!(/\[(.+?)\]/,"")
w += RPG::Cache.picture($1).width+4
h = RPG::Cache.picture($1).height if RPG::Cache.picture($1).height > 32 and RPG::Cache.picture($1).height > h
next
end
if c == "\004"
text.sub!(/\[(.+?)\]/,"")
w += RPG::Cache.icon($1).width+4
h = RPG::Cache.icon($1).height if RPG::Cache.icon($1).height > 32 and RPG::Cache.icon($1).height > h
next
end
w += bitmap.text_size(c).width
h = bitmap.text_size(c).height if bitmap.text_size(c).height > 32 and bitmap.text_size(c).height > h
end
return w,h
end
end
#===============================================================================
# ■ 任务界面
#===============================================================================
class Scene_Mission
def main
@window1 = Window_Base.new(0,0,200,64)
@window1.contents = Bitmap.new(168,32)
@window1.contents.draw_text(0,0,168,32,"任务",1)
@window2 = Window_Base.new(200,0,440,64)
@window2.contents = Bitmap.new(408,32)
@window2.contents.draw_text(0,0,408,32,"任务说明",1)
@mission_window = Window_Mission.new
@mission_window.index = $game_party.mission.size - 1
[url=home.php?mod=space&uid=370741]@Index[/url] = @mission_window.index
@info_window = Window_MissionInfo.new
info = $game_party.mission[@index].info.clone
@info_window.refresh(info)
Graphics.transition
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
Graphics.freeze
@window1.dispose
@window2.dispose
@mission_window.dispose
@info_window.dispose
end
def update
@mission_window.update
@info_window.update
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
$scene = Scene_Map.new
return
end
if @index != @mission_window.index
@index = @mission_window.index
info = $game_party.mission[@index].info.clone
@info_window.refresh(info)
end
end
end
#===============================================================================
# ■ 事件处理器
#===============================================================================
class Interpreter
alias orig_ec execute_command
def execute_command
if @index >= @list.size - 1
command_end
return true
end
@parameters = @list[@index].parameters
return command_108 if @list[@index].code == 108
return orig_ec
end
def command_108
case @list[@index].parameters[0]
when (/^删除任务\[(\w+)\]$/)
$game_party.delete_mission($1)
return true
when (/^完成任务\[(\w+)\]$/)
$game_party.done_mission($1)
return true
when "删除所有任务"
$game_party.delete_all_mission
return true
when "完成所有任务"
$game_party.done_all_mission
return true
when (/^放弃任务\[(\w+)\]$/)
$game_party.fail_mission($1)
return true
when (/^恢复任务\[(\w+)\]$/)
$game_party.resume_mission($1)
return true
when "恢复所有任务"
$game_party.resume_all_mission
return true
end
text = @list[@index].parameters[0]
loop do
if @list[@index+1].code == 108 or @list[@index+1].code == 408
text += "\n" + @list[@index+1].parameters[0]
else
break
end
@index += 1
end
split = text.split("\n")
if (split[0] == "任务设置" or split[0] == "任务更新" or split[0] == "追加说明") and split.size >= 3
info , name = split[2] , split[1]
if split.size >= 4
for i in 3...split.size
info += "\n" + split[i]
end
end
$game_party.get_mission(name,info) if split[0] == "任务设置"
$game_party.update_mission(name,info) if split[0] == "任务更新"
$game_party.add_mission_info(name,info) if split[0] == "追加说明"
end
return true
end
end