查看: 76|回复: 0

[转载发布] 【相隔1年多的更新][22.1.2015][v0.8】便民任务界面

[复制链接]
  • TA的每日心情
    开心
    5 天前
  • 签到天数: 33 天

    连续签到: 1 天

    [LV.5]常住居民I

    2022

    主题

    32

    回帖

    7144

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    0
    卡币
    5074
    OK点
    16
    积分
    7144
    发表于 同元一千年八月七日(秋) | 显示全部楼层 |阅读模式
    2015年1月22日正式开坑:下次更新时此脚本将升格为任务系统

    @Wait@Cache 防bug=w=

    用注释设置使设置更加简单
    1. 更新日志:  v0.8    1.添加了自动换行功能    2.删除了垂直对齐功能(对已使用的人深感抱歉)    4.更改了文本的解析法    3.描绘内容与刷新同步(可较顺滑的在任务间切换)    4.修正一个没被发现的BUG      v0.7    1.对脚本结构进行优化    2.更改数据结构(也就是说之前的存档再度全死)    3.缩短代码    4.加入自动记录并返回上个界面的功能    5.移除一个没用却一直忘了删掉的功能 =_=||    6.添加垂直对齐功能(很坑,请依情况使用)    7.添加把多行内容显示为一行的功能      v坑爹(超坑爹!失败告终)    1.添加ERB支持(非常坑,已放弃)    2.添加任务系统(已暂停并删除,以后会继续)    3.拥有自己的数据库(很坑,已抛弃)      v0.6    1.增加滚动功能    2.对脚本结构进行优化      v0.5    1.改名为任务界面(总觉得这只是界面不是系统)    2.优化所有正则表达式的匹配模式    4.解决一个大BUG    5.更改数据结构(也就是说之前的存档全死)    6.增加“追加说明”的功能      v0.4    1.优化代码    2.增加“任务更新”的功能      v0.3    1.增加“放弃任务”的功能    2.解决一个未曾被发现的BUG    3.设置简单化    4.美化打勾    5.增加打叉      v0.2    1.加强说明显示效果    2.去掉一些不必要的工作复制代码
    复制代码
    脚本:
    RUBY 代码
    1. #==============================================================================#
    2. #                          便民任务界面 by EngShun                             #
    3. #                                                                              #
    4. #    由于此版本仅做出了一些小优化,                                            #
    5. #    因此设置方法请参考v0.7的范例                                              #
    6. #                                                                              #
    7. #    效果说明:                                                                #
    8. #    支持普通对话框效果                                                        #
    9. #    \a[号码]     :更改左右对齐方式(0,1,2)。                                 #
    10. #    \itm[物品id] :物品数量                                                    #
    11. #    \wpn[武器id] :武器数量                                                    #
    12. #    \amr[防具id] :防具数量                                                    #
    13. #    \eval{脚本}  :运行脚本                                                    #
    14. #    \1line{内容} :把多行的内容显示为一行                                      #
    15. #    \bold        :字体加粗,插入多一次关闭                                    #
    16. #    \italic      :字体打斜,插入多一次关闭                                    #
    17. #    \f[字体名称] :更改字体                                                    #
    18. #    \s[号码]     :更改字体大小                                                #
    19. #    \p[名称]     :插入图片                                                    #
    20. #    \icon[名称]  :插入图标                                                    #
    21. #                                                                              #
    22. #==============================================================================#
    23. #===============================================================================
    24. # ■ 队伍
    25. #===============================================================================
    26. class Game_Party
    27.   Mission = Struct.new(:id, :name, :info, :status)
    28.   alias org_init_mission initialize if !defined?(org_init_mission)
    29.   #--------------------------------------------------------------------------
    30.   # ● 重定义初始化
    31.   #--------------------------------------------------------------------------
    32.   def initialize
    33.     @mission = {}
    34.     org_init_mission
    35.   end
    36.   def no_mission?
    37.     return@mission == {}
    38.   end
    39.   def missions
    40.     if no_mission?
    41.       m = Mission.new(0,"没有任务","\n\n\n\\a[1]\\s[32]你还没有领取任何任务",0)
    42.       return[m]
    43.     end
    44.     return@mission.values.sort_by{|m|m.id}
    45.   end
    46.   def get_mission(mission,info)
    47.     returnif@mission.has_key?(mission)
    48.     id = missions[-1].id + 1
    49.     @mission[mission] = Mission.new(id,mission,info,0)
    50.   end
    51.   def done_mission(mission)
    52.     @mission[mission].status = 1if@mission[mission].status == 0
    53.   end
    54.   def delete_mission(mission)
    55.     @mission.delete(mission)
    56.   end
    57.   def fail_mission(mission)
    58.     @mission[mission].status = 2if@mission[mission].status == 0
    59.   end
    60.   def resume_mission(mission)
    61.     @mission[mission].status = 0if@mission[mission].status == 2
    62.   end
    63.   def done_all_mission
    64.     @mission.each{|k,m|m.status = 1}
    65.   end
    66.   def update_mission(mission,info)
    67.     @mission[mission].info = info
    68.   end
    69.   def add_mission_info(mission,info)
    70.     @mission[mission].info += "\n" + info
    71.   end
    72.   def delete_all_mission
    73.     @mission = {}
    74.   end
    75.   def resume_all_mission
    76.     @mission.each{|k,m|m.status = 0if m.status == 2}
    77.   end
    78. end
    79. #===============================================================================
    80. # ■ 任务列表窗口
    81. #===============================================================================
    82. class Window_Mission < Window_Selectable
    83.   #--------------------------------------------------------------------------
    84.   # ● 初始化对象
    85.   #--------------------------------------------------------------------------
    86.   def initialize
    87.     super(0, 64, 200, 416)
    88.     self.index = 0
    89.     @mission = $game_party.missions
    90.     @item_max = @mission.size
    91.     ifself.contents != nil
    92.       self.contents.dispose
    93.       self.contents = nil
    94.     end
    95.     self.contents = Bitmap.new(width - 32, @item_max * 32)
    96.     for i in[email]0...@mission.size[/email]
    97.       t = @mission[i].status != 0
    98.       self.contents.font.color = t ? disabled_color : normal_color
    99.       text = @mission[i].name
    100.       self.contents.draw_text(4, i * 32, 160, 32, text.to_s)
    101.       self.contents.font.color = system_color
    102.       self.contents.draw_text(self.contents.width-32, i * 32, 32, 32, "□",1)unless$game_party.no_mission?
    103.       if@mission[i].status == 1
    104.         self.contents.font.color = crisis_color
    105.         self.contents.draw_text(self.contents.width-32, i * 32, 32, 32, "√",1)
    106.       elsif@mission[i].status == 2
    107.         self.contents.font.color = knockout_color
    108.         self.contents.draw_text(self.contents.width-32, i * 32, 32, 32, "×",1)
    109.       end
    110.     end
    111.   end
    112. end
    113. #===============================================================================
    114. # ■ 任务详情窗口
    115. #===============================================================================
    116. class Window_MissionInfo < Window_Base
    117.   attr_accessor :wait
    118.   attr_accessor :scroll_up
    119.   #--------------------------------------------------------------------------
    120.   # ● 初始化对象
    121.   #--------------------------------------------------------------------------
    122.   def initialize
    123.     super(200,64,440,416)
    124.     self.contents =  Bitmap.new(408, 384)
    125.     @scroll_up = false
    126.     @wait = 90
    127.     @items = []
    128.     @progress = 0
    129.     @draw_y = 0
    130.     @align = 0
    131.     @cache = Bitmap.new(160,160)
    132.     @font = Font.new
    133.   end
    134.   #--------------------------------------------------------------------------
    135.   # ● 刷新画面
    136.   #--------------------------------------------------------------------------
    137.   def update
    138.     super
    139.     parse_items if@items.size > 0
    140.     returnifself.contents.height  0
    141.     self.oy += @scroll_up ? -1 : 1
    142.     self.oy = 0ifself.oy < 0
    143.     self.oy = oy_max ifself.oy > oy_max
    144.     ifself.oy = oy_max
    145.       @scroll_up = true
    146.       @wait = 60
    147.     end
    148.   end
    149.   #--------------------------------------------------------------------------
    150.   # ● 释放
    151.   #--------------------------------------------------------------------------
    152.   def dispose
    153.     super
    154.     @cache.dispose
    155.   end
    156.   #--------------------------------------------------------------------------
    157.   # ● 滚动最大值
    158.   #--------------------------------------------------------------------------
    159.   def oy_max
    160.     returnself.contents.height - 384
    161.   end
    162.   #--------------------------------------------------------------------------
    163.   # ● 刷新
    164.   #--------------------------------------------------------------------------
    165.   def refresh(str)
    166.     str = str.clone
    167.     @scroll_up = false
    168.     @wait = 120
    169.     @draw_y = 0
    170.     @align = 0
    171.     @progress = 0
    172.     @lines = []
    173.     self.oy = 0
    174.     @cache.font = Font.new
    175.     @font = Font.new
    176.     self.contents.dispose
    177.     self.contents = Bitmap.new(408, 384)
    178.     parse_text(str)
    179.     12.times{parse_items}
    180.   end
    181.   #--------------------------------------------------------------------------
    182.   # ● 描绘行
    183.   #--------------------------------------------------------------------------
    184.   def draw_line(width, height, items)
    185.     bitmap = Bitmap.new(width, height)
    186.     bitmap.font = @font
    187.     x = 0
    188.     for item in items
    189.       if item.is_a?(Color)
    190.         bitmap.font.color = item
    191.       elsif item.is_a?(Integer)
    192.         bitmap.font.size = item
    193.       elsif item.is_a?(Array)
    194.         bitmap.font.name = item[0]if item.size == 1
    195.       elsif item.is_a?(Bitmap)
    196.         bitmap.blt(x + 2, (height - item.height) / 2,
    197.                    item, Rect.new(0,0,item.width,item.height))
    198.         x += item.width + 4
    199.       elsif item == :bold
    200.         bitmap.font.italic = !bitmap.font.bold
    201.       elsif item == :italic
    202.         bitmap.font.italic = !bitmap.font.italic
    203.       else
    204.         bitmap.draw_text(x,0,width,height,item)
    205.         x += bitmap.text_size(item).width
    206.       end
    207.     end
    208.     return bitmap
    209.   end
    210.   #--------------------------------------------------------------------------
    211.   # ● 解析文本
    212.   #--------------------------------------------------------------------------
    213.   def parse_text(str)
    214.     begin
    215.       last_text = str.clone
    216.       str.gsub!(/\\v\[(\d+)\]/i){$game_variables[$1.to_i]}
    217.       str.gsub!(/\\g/i){$game_party.gold.to_s}
    218.       str.gsub!(/\\itm\[(\d+)\]/i){$game_party.item_number($1.to_i)}
    219.       str.gsub!(/\\wpn\[(\d+)\]/i){$game_party.weapon_number($1.to_i)}
    220.       str.gsub!(/\\amr\[(\d+)\]/i){$game_party.armor_number($1.to_i)}
    221.       str.gsub!(/\\1line{(.+?)}/im){ $1.delete("\n")}
    222.       str.gsub!(/\\eval{(.+?)}/im){eval($1)}
    223.     enduntil str == last_text
    224.     str.gsub!(/\\n\[(\d+)\]/i)do
    225.       $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
    226.     end
    227.     str.gsub!(/\n/){"\000\002n\000"}
    228.     str.gsub!(/\\\\/){"\001"}
    229.     str.gsub!(/\\a\[([0-2])\]/i){"\000\0027#{$1}"}
    230.     str.gsub!(/\\c\[(\d+)\]/i){"\000\0020#{$1}\000"}
    231.     str.gsub!(/\\bold/i){"\000\0021\000"}
    232.     str.gsub!(/\\italic/i){"\000\0022\000"}
    233.     str.gsub!(/\\f\[(\w+)\]/i){"\000\0023#{$1}\000"}
    234.     str.gsub!(/\\s\[(\d+)\]/i){"\000\0024#{$1}\000"}
    235.     str.gsub!(/\\p\[(.+?)\]/i){"\000\0025#{$1}\000"}
    236.     str.gsub!(/\\icon\[(.+?)\]/i){"\000\0026#{$1}\000"}
    237.     str.gsub!(/\001/){"\"}
    238.     @items = str.split("\000")
    239.     @items.delete("")
    240.   end
    241.   #--------------------------------------------------------------------------
    242.   # ● 深度解析
    243.   #--------------------------------------------------------------------------
    244.   def parse_items
    245.     returnunless@items.size > 0
    246.     bitmap = @cache
    247.     width, height, items = 1, 32, []
    248.     while item = @items.delete_at(0)
    249.       if item[/^\002([0-9a-z])(.*)/]
    250.         case(a = $1)
    251.         when'7'
    252.           @align = $2.to_i
    253.         when'0'
    254.           color = $2.to_i
    255.           bitmap.font.color = if color >= 0and color  408
    256.             item.dispose
    257.             items.unshift("[图片太大无法显示]")
    258.             next
    259.           elsif width + item.width > 408
    260.             @items.unshift(item)
    261.             break
    262.           end
    263.           items.push(item)
    264.           width += item.width + 4
    265.           height = item.height + 4if item.height + 4 > height
    266.         when'n'
    267.           break
    268.         end
    269.       else
    270.         str = ""
    271.         size = Rect.new(0, 0, 0, 0)
    272.         while s = item.slice!(/./)
    273.           size = bitmap.text_size(str + s)
    274.           if width + size.width > 408
    275.             item.insert(0, s)
    276.             break
    277.           else
    278.             str += s
    279.           end
    280.         end
    281.         if items[-1].is_a?(String)
    282.           items[-1] += str
    283.         else
    284.           items.push(str)
    285.         end
    286.         width += size.width
    287.         height = size.height + 4if size.height + 4 > height
    288.         if item != ""
    289.           @items.unshift(item)
    290.           break
    291.         end
    292.       end
    293.     end
    294.     b = draw_line(width, height, items)
    295.     if@draw_y + b.height > 384
    296.       c = self.contents
    297.       self.contents = Bitmap.new(408, @draw_y + b.height)
    298.       self.contents.blt(0, 0, c, Rect.new(0,0,c.width, c.height))
    299.       c.dispose
    300.     end
    301.     x = 0
    302.     x = 204 - (b.width / 2)if@align == 1
    303.     x = 408 - b.widthif@align == 2
    304.     self.contents.blt(x, @draw_y, b, Rect.new(0,0,b.width, b.height))
    305.     @draw_y += b.height
    306.   end
    307. end
    308. #===============================================================================
    309. # ■ 任务界面
    310. #===============================================================================
    311. class Scene_Mission
    312.   #--------------------------------------------------------------------------
    313.   # ● 初始化
    314.   #--------------------------------------------------------------------------
    315.   def initialize
    316.     @last_scene = $scene
    317.   end
    318.   #--------------------------------------------------------------------------
    319.   # ● 主处理
    320.   #--------------------------------------------------------------------------
    321.   def main
    322.     @mission = $game_party.missions
    323.     @window1 = Window_Base.new(0,0,200,64)
    324.     @window1.contents = Bitmap.new(168,32)
    325.     @window1.contents.draw_text(0,0,168,32,"任务",1)
    326.     @window2 = Window_Base.new(200,0,440,64)
    327.     @window2.contents = Bitmap.new(408,32)
    328.     @window2.contents.draw_text(0,0,408,32,"任务说明",1)
    329.     @mission_window = Window_Mission.new
    330.     @mission_window.index = @mission.size - 1
    331.     @index = @mission_window.index
    332.     @info_window = Window_MissionInfo.new
    333.     @info_window.refresh(@mission[@index].info)
    334.     Graphics.transition
    335.     loopdo
    336.       Graphics.update
    337.       Input.update
    338.       update
    339.       if$scene != self
    340.         break
    341.       end
    342.     end
    343.     Graphics.freeze
    344.     @window1.dispose
    345.     @window2.dispose
    346.     @mission_window.dispose
    347.     @info_window.dispose
    348.   end
    349.   #--------------------------------------------------------------------------
    350.   # ● 刷新画面
    351.   #--------------------------------------------------------------------------
    352.   def update
    353.     @mission_window.update
    354.     @info_window.update
    355.     if@index != @mission_window.index
    356.       @index = @mission_window.index
    357.       @info_window.refresh(@mission[@index].info)
    358.     end
    359.     return update_mission if@mission_window.active
    360.     update_info
    361.   end
    362.   #--------------------------------------------------------------------------
    363.   # ● 刷新任务
    364.   #--------------------------------------------------------------------------
    365.   def update_mission
    366.     if Input.trigger?(Input::C)
    367.       $game_system.se_play($data_system.decision_se)
    368.       @mission_window.active = false
    369.       @info_window.oy = 0
    370.     elsif Input.trigger?(Input::B)
    371.       $game_system.se_play($data_system.cancel_se)
    372.       $scene = @last_scene
    373.       return
    374.     end
    375.   end
    376.   #--------------------------------------------------------------------------
    377.   # ● 刷新人物详情
    378.   #--------------------------------------------------------------------------
    379.   def update_info
    380.     @info_window.wait = 90
    381.     if Input.press?(Input::UP)
    382.       @info_window.oy -= 3
    383.       @info_window.oy = 0if@info_window.oy < 0
    384.     elsif Input.press?(Input::DOWN)
    385.       @info_window.oy += 3
    386.       @info_window.oy = @info_window.oy_maxif@info_window.oy > @info_window.oy_max
    387.     elsif Input.repeat?(Input::L)
    388.       $game_system.se_play($data_system.cursor_se)
    389.       @mission_window.index -= 1
    390.       @mission_window.index = $game_party.missions.size - 1if@mission_window.index < 0
    391.     elsif Input.repeat?(Input::R)
    392.       $game_system.se_play($data_system.cursor_se)
    393.       @mission_window.index += 1
    394.       @mission_window.index = 0if@mission_window.index >= $game_party.missions.size
    395.     elsif Input.trigger?(Input::B)
    396.       $game_system.se_play($data_system.cancel_se)
    397.       @mission_window.active = true
    398.       @info_window.scroll_up = false
    399.       @info_window.oy = 0
    400.     end
    401.   end
    402. end
    403. #===============================================================================
    404. # ■ 事件处理器
    405. #===============================================================================
    406. class Interpreter
    407.   alias orig_ec_mission execute_command if !defined?(orig_ec_mission)
    408.   #--------------------------------------------------------------------------
    409.   # ● 重定义执行事件命令
    410.   #--------------------------------------------------------------------------
    411.   def execute_command
    412.     if@index >= @list.size - 1
    413.       command_end
    414.       returntrue
    415.     end
    416.     @parameters = @list[@index].parameters
    417.     return command_108 if@list[@index].code == 108
    418.     return orig_ec_mission
    419.   end
    420.   #--------------------------------------------------------------------------
    421.   # ● 注释
    422.   #--------------------------------------------------------------------------
    423.   def command_108
    424.     case@list[@index].parameters[0]
    425.     when(/^删除任务\[(\w+)\]$/)
    426.       $game_party.delete_mission($1)
    427.       returntrue
    428.     when(/^完成任务\[(\w+)\]$/)
    429.       $game_party.done_mission($1)
    430.       returntrue
    431.     when"删除所有任务"
    432.       $game_party.delete_all_mission
    433.       returntrue
    434.     when"完成所有任务"
    435.       $game_party.done_all_mission
    436.       returntrue
    437.     when(/^放弃任务\[(\w+)\]$/)
    438.       $game_party.fail_mission($1)
    439.       returntrue
    440.     when(/^恢复任务\[(\w+)\]$/)
    441.       $game_party.resume_mission($1)
    442.       returntrue
    443.     when"恢复所有任务"
    444.       $game_party.resume_all_mission
    445.       returntrue
    446.     end
    447.     text = @list[@index].parameters[0]
    448.     loopdo
    449.       if@list[@index+1].code == 108or@list[@index+1].code == 408
    450.         text += "\n" + @list[@index+1].parameters[0]
    451.       else
    452.         break
    453.       end
    454.       @index += 1
    455.     end
    456.     split = text.split("\n")
    457.     if(split[0] == "任务设置"orsplit[0] == "任务更新"orsplit[0] == "追加说明")andsplit.size >= 3
    458.       info , name = split[2] , split[1]
    459.       ifsplit.size >= 4
    460.         for i in3...split.size
    461.           info += "\n" + split[i]
    462.         end
    463.       end
    464.       $game_party.get_mission(name,info)ifsplit[0] == "任务设置"
    465.       $game_party.update_mission(name,info)ifsplit[0] == "任务更新"
    466.       $game_party.add_mission_info(name,info)ifsplit[0] == "追加说明"
    467.     end
    468.     returntrue
    469.   end
    470. end
    复制代码

    截图:


    下载:
    v0.8并没有在功能上做出改动,因此不提供范例,
    需要的请下载v0.7范例。

    随工程附送VX→XP窗口皮肤一张

    旧版本:





             
                 本帖来自P1论坛作者英顺的马甲,因Project1站服务器在国外有时候访问缓慢不方便作者交流学习,经联系P1站长fux2同意署名转载一起分享游戏制作经验,共同为国内独立游戏作者共同创造良好交流环境,原文地址:https://rpg.blue/forum.php?mod=viewthread&tid=167490  若有侵权,发帖作者可联系底部站长QQ在线咨询功能删除,谢谢。

    本帖子中包含更多资源

    您需要 登录 才可以下载或查看,没有账号?立即注册

    x
    天天去同能,天天有童年!
    回复 论坛版权

    使用道具 举报

    ahome_bigavatar:guest
    ahome_bigavatar:welcomelogin
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2024-5-3 02:01 , Processed in 0.056065 second(s), 56 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表