设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2086|回复: 3
打印 上一主题 下一主题

带详细说明的任务系统[有点问题囧]

 关闭 [复制链接]

Lv1.梦旅人

梦石
0
星屑
55
在线时间
2 小时
注册时间
2006-11-10
帖子
931
跳转到指定楼层
1
发表于 2006-12-13 06:58:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
做话题游戏的过程中试着自制了一个带详细说明的任务系统……
这个系统可以将任务编号对应的说明存在system/Questdata.rxdata里。
在做游戏的时候可以随时用事件脚本——添加说明的方法把任务详细说明全都写在某个文件中,游戏做完后将添加详细说明的事件删除即可。只要发布时有将记载说明的文件放在文件夹里即可正常显示各任务的详细说明。
这样即使玩家拆了游戏也不会看到全任务-_-。并且省去了一些事件和脚本,扩大了任务系统的信息容量。

任务分类窗口是拿简单物品分类窗口改造的,所以里面夹杂了很多日文注释-_\\
参考脚本:月光奏鸣曲(布局),66的任务系统教学(架构)

另外,这个版本是整合版而非可以直接使用的版本=v=感兴趣的各位可以照下面步骤逐步整合=v=

1、首先是一个Window_Quest,包括command窗口和questlist窗口。
   可以看到某人为了偷工减料,直接把helpwindow用作显示详细说明的窗口了-_\\

  1. class Window_QuestCommand < Window_Selectable
  2. #--------------------------------------------------------------------------
  3.   # ● オブジェクト初期化
  4.   #--------------------------------------------------------------------------
  5.   def initialize
  6.     super(10, 10, 130, 195)
  7.     self.contents = Bitmap.new(width - 32, height - 32)
  8.     @item_max = 5
  9.     @commands = ["主线任务", "支线任务", "失效任务", "完成任务", "所有任务"]
  10.     refresh
  11.     self.index = 0
  12.   end
  13.   #--------------------------------------------------------------------------
  14.   # ● リフレッシュ
  15.   #--------------------------------------------------------------------------
  16.   def refresh
  17.     self.contents.clear
  18.     for i in 0...@item_max
  19.     draw_item(i, normal_color)
  20.     end
  21.   end
  22.   #--------------------------------------------------------------------------
  23.   # ● 項目の描画
  24.   # index : 項目番号
  25.   # color : 文字色
  26.   #--------------------------------------------------------------------------
  27.   def draw_item(index, color)
  28.     self.contents.font.color = color
  29.     y = index * 32
  30.     self.contents.draw_text(4, y, 128, 32, @commands[index])
  31.   end
  32.   #--------------------------------------------------------------------------
  33.   # ● ヘルプテキスト更新
  34.   #--------------------------------------------------------------------------
  35.   def update_help
  36.     case self.index
  37.     when 0
  38.       @text = "主线任务。"
  39.     when 1
  40.       @text = "支线任务。"
  41.     when 2
  42.       @text = "失效任务。"
  43.     when 3
  44.       @text = "完成任务。"
  45.     when 4
  46.       @text = "全部任务列表。"
  47.     end
  48.     @help_window.set_text_new(@text,1)
  49.   end
  50. end




  51. class Window_QuestList < Window_Selectable
  52.   def initialize
  53.     super(150, 10, 480, 195)
  54.     self.contents = Bitmap.new(width - 32, height - 32)
  55.     refresh
  56.     self.index = 0
  57.   end
  58.   #--------------------------------------------------------------------------
  59.   # ● 获取任务名称
  60.   #--------------------------------------------------------------------------
  61.   def item
  62.     return @data[self.index]
  63.   end
  64.   #--------------------------------------------------------------------------
  65.   # ● 获取任务类别
  66.   #--------------------------------------------------------------------------
  67.   def itemtype
  68.     return @type[self.index]
  69.   end
  70.   #--------------------------------------------------------------------------
  71.   # ● 获取任务说明
  72.   #--------------------------------------------------------------------------
  73.   def itemdesc
  74.     return @desc[self.index]
  75.   end
  76.   #--------------------------------------------------------------------------
  77.   # ● リフレッシュ
  78.   #--------------------------------------------------------------------------
  79.   def refresh
  80.     if self.contents != nil
  81.       self.contents.dispose
  82.       self.contents = nil
  83.     end
  84.     @data = []
  85.     @type = []
  86.     @desc = []
  87.   end
  88.   #--------------------------------------------------------------------------
  89.   # ● アイテム一覧設定
  90.   # command : 選択中のコマンド
  91.   #--------------------------------------------------------------------------
  92.   def set_item(command)
  93.     refresh
  94.     case command
  95.     when 0
  96.       for i in 0...$game_system.list.size
  97.         if ($game_system.type[i] == 0 or $game_system.type[i] == 1 or $game_system.type[i] == 2) and $game_system.contents != nil
  98.           @data.push($game_system.contents[i])
  99.           @type.push($game_system.type[i])
  100.           @desc.push($game_system.desc[i])
  101.         end
  102.       end
  103.     when 1
  104.       for i in 0...$game_system.list.size
  105.         if ($game_system.type[i] == 3 or $game_system.type[i] == 4 or $game_system.type[i] == 5) and $game_system.contents != nil
  106.           @data.push($game_system.contents[i])
  107.           @type.push($game_system.type[i])
  108.           @desc.push($game_system.desc[i])
  109.         end
  110.       end
  111.     when 2
  112.       for i in 0...$game_system.list.size
  113.         if $game_system.type[i] == 5 and $game_system.contents != nil
  114.           @data.push($game_system.contents[i])
  115.           @type.push($game_system.type[i])
  116.           @desc.push($game_system.desc[i])
  117.         end
  118.       end
  119.     when 3
  120.       for i in 0...$game_system.list.size
  121.         if ($game_system.type[i] == 0 or $game_system.type[i] == 3) and $game_system.contents != nil
  122.           @data.push($game_system.contents[i])
  123.           @type.push($game_system.type[i])
  124.           @desc.push($game_system.desc[i])
  125.         end
  126.       end
  127.     when 4
  128.       for i in 0...$game_system.list.size
  129.         if $game_system.contents != nil
  130.           @data.push($game_system.contents[i])
  131.           @type.push($game_system.type[i])
  132.           @desc.push($game_system.desc[i])
  133.         end
  134.       end
  135.     end
  136.     # 項目数が 0 でなければビットマップを作成し、全項目を描画
  137.     @item_max = @data.size
  138.     if @item_max > 0
  139.       self.contents = Bitmap.new(width - 32, row_max * 32)
  140.       self.contents.clear
  141.       for i in 0...@item_max
  142.         draw_item(i)
  143.       end
  144.     end
  145.   end
  146.   #--------------------------------------------------------------------------
  147.   # ● 種類別アイテム数の取得
  148.   #--------------------------------------------------------------------------
  149.   def item_number
  150.     return @item_max
  151.   end
  152.   #--------------------------------------------------------------------------
  153.   # ● 項目の描画
  154.   # index : 項目番号
  155.   #--------------------------------------------------------------------------
  156.   def draw_item(index)
  157.     item = @data[index]
  158.     type = @type[index]
  159.     typename = ""
  160.    
  161.     case type
  162.     when 0
  163.       self.contents.font.color = disabled_color
  164.       typename = "[主线]"
  165.     when 1
  166.       self.contents.font.color = system_color
  167.       typename = "[当前]"
  168.     when 2
  169.       self.contents.font.color = normal_color
  170.       typename = "[主线]"
  171.     when 3
  172.       self.contents.font.color = disabled_color
  173.       typename = "[支线]"
  174.     when 4
  175.       self.contents.font.color = normal_color
  176.       typename = "[支线]"
  177.     when 5
  178.       self.contents.font.color = crisis_color
  179.       typename = "[失效]"
  180.     end
  181.    
  182.     x = 4
  183.     y = index * 32
  184.     self.contents.draw_text(x, y, 100, 32, typename, 0)
  185.     self.contents.draw_text(x + 65, y, 212, 32, item, 0)
  186.   end
  187.   #--------------------------------------------------------------------------
  188.   # ● ヘルプテキスト更新
  189.   #--------------------------------------------------------------------------
  190.   def update_help
  191.     if @data == []
  192.       @text = "此项目中没有任务。"
  193.       @help_window.set_text_new(@text,1)
  194.     else
  195.       @help_window.set_text_new(self.itemdesc == nil ? "此任务详细内容不明。" : self.itemdesc)
  196.     end
  197.   end
  198. end
复制代码

2、其次是一个Scene_Quest,任务系统主界面。

  1. #==============================================================================
  2. # ■ Scene_Quest
  3. #------------------------------------------------------------------------------
  4. #  任务系统。
  5. #==============================================================================
  6. class Scene_Quest
  7.   #--------------------------------------------------------------------------
  8.   # ● メイン処理
  9.   #--------------------------------------------------------------------------
  10.   def main
  11.     if FileTest.exist?("system/Questdata.rxdata")
  12.        file = File.open("system/Questdata.rxdata", "r")
  13.        $game_system.desc = Marshal.load(file)
  14.        file.close
  15.     end
  16.     #コマンドウィンドウを作成
  17.     @questcommand_window = Window_QuestCommand.new
  18.     @command_index = @questcommand_window.index
  19.     #アイテムウィンドウを作成
  20.     @questlist_window = Window_QuestList.new
  21.     @questlist_window.active = false
  22.     #ヘルプウィンドウを作成
  23.     @help_window = Window_Help.new
  24.     # ヘルプウィンドウを関連付け
  25.     @questcommand_window.help_window = @help_window
  26.     @questlist_window.help_window = @help_window

  27.     # アイテムウィンドウ内容表示
  28.     @questlist_window.set_item(@command_index)
  29.     # トランジション実行
  30.     Graphics.transition
  31.     # メインループ
  32.     loop do
  33.       # ゲーム画面を更新
  34.       Graphics.update
  35.       # 入力情報を更新
  36.       Input.update
  37.       # フレーム更新
  38.       update
  39.       # 画面が切り替わったらループを中断
  40.       if $scene != self
  41.         break
  42.       end
  43.     end
  44.     # トランジション準備
  45.     Graphics.freeze
  46.     # ウィンドウを解放

  47.     @questcommand_window.dispose
  48.     @questlist_window.dispose
  49.     @help_window.dispose
  50.   end
  51.   #--------------------------------------------------------------------------
  52.   # ● フレーム更新
  53.   #--------------------------------------------------------------------------
  54.   def update
  55.     # ウィンドウを更新
  56.     @questcommand_window.update
  57.     @questlist_window.update
  58.     @help_window.update
  59.     if @command_index != @questcommand_window.index
  60.       @command_index = @questcommand_window.index
  61.       @questlist_window.set_item(@command_index)
  62.     end
  63.     # コマンドウィンドウがアクティブの場合: update_questcommand を呼ぶ
  64.     if @questcommand_window.active
  65.       update_questcommand
  66.       return
  67.     end
  68.     # アイテムウィンドウがアクティブの場合: update_questlist を呼ぶ
  69.     if @questlist_window.active
  70.       update_questlist
  71.       return
  72.     end
  73.   end
  74.   #--------------------------------------------------------------------------
  75.   # ● フレーム更新 (コマンドウィンドウがアクティブの場合)
  76.   #--------------------------------------------------------------------------
  77.   def update_questcommand
  78.   # B ボタンが押された場合
  79.   if Input.trigger?(Input::B)
  80.   # キャンセル SE を演奏
  81.   $game_system.se_play($data_system.cancel_se)
  82.   # メニュー画面に切り替え
  83.   $scene = Scene_Menu.new(5)
  84.   return
  85.   end
  86.   # C ボタンが押された場合
  87.   if Input.trigger?(Input::C)
  88.   # 決定 SE を演奏
  89.   $game_system.se_play($data_system.decision_se)
  90.   # アイテムウィンドウをアクティブにする
  91.   @questcommand_window.active = false
  92.   @questlist_window.active = true
  93.   @questlist_window.index = 0
  94.   return
  95.   end
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # ● フレーム更新 (アイテムウィンドウがアクティブの場合)
  99.   #--------------------------------------------------------------------------
  100.   def update_questlist
  101.     # B ボタンが押された場合
  102.     if Input.trigger?(Input::B)
  103.       # キャンセル SE を演奏
  104.       $game_system.se_play($data_system.cancel_se)
  105.       # アイテムウィンドウをアクティブにする
  106.       @questcommand_window.active = true
  107.       @questlist_window.active = false
  108.       @questlist_window.index = 0
  109.       @questcommand_window.index = @command_index
  110.       return
  111.     end
  112.   end
  113. end
复制代码

3、在GameSystem里添加以下accessor:

  attr_accessor :list                     # 任务编号
  attr_accessor :contents                 # 任务标题
  attr_accessor :type                     # 任务种类
  attr_accessor :desc                     # 任务详细信息

并且在initialize项里添加以下初始化:

    @list = []
    @contents = []
    @type = []
    @desc = []

然后,在GameSystem里添加以下三个方法:

  #----------------------
  # ● 插入任务
  #----------------------
  def new_quest(n1,n2,n3)
    @list.push(n1)
    @contents.push(n2)
    @type.push(n3)
  end
  #----------------------
  # ● 添加任务注释
  #----------------------
  def quest_illust(n1,n4)
    for i in [email protected]
      if @list == n1
         @desc = n4
      end
    end
    file = File.open("system/Questdata.rxdata", "wb")
    Marshal.dump($game_system.desc, file)
    file.close
  end
  #----------------------
  # ● 完成任务(失效处理或完成处理)
  #----------------------
  def end_quest(n1,n2,n3)
    for i in [email protected]
      if @list == n1 and @contents == n2
         @type = n3
      end
    end
  end
分别用来插入新任务,给任务添加注释和结束任务。

4、稍微改造一下WindowHelp,使之适合用来显示任务注释。
把WindowHelp默认的initialize用这个替换:
  def initialize
    if $scene.is_a?(Scene_Quest)
      super(10,215,620,255)
    else
      super(0, 0, 640, 64)
    end
    self.contents = Bitmap.new(width - 32, height - 32)
  end


在WindowHelp的set_text方法下添加新的方法set_text_new,用以给任务说明分段等。

  1.   def set_text_new1(text, align = 0)
  2.     if text != @text or align != @align
  3.     self.contents.clear
  4.     self.contents.font.color = normal_color
  5.     @text = text.clone
  6.     x = y = 0
  7.     begin
  8.       last_text = @text.clone
  9.       @text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  10.     end until @text == last_text
  11.     @text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  12.       $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  13.     end
  14. #    @text.gsub!(/\\\\/) { "\000" }
  15. #    @text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  16.     @text.gsub!(/\\[Hh]/) { "\002" }
  17. #    @text.gsub!(/\\[Ss]\[([0-9]+)\]/) { "\003[#{$1}]" }
  18.     while ((c = @text.slice!(/./m)) != nil)
  19. #      if c == "\000"
  20. #        c = "\\"
  21. #      end
  22. #      if c == "\001"
  23. #        @text.sub!(/\[([0-9]+)\]/, "")
  24. #        color = $1.to_i
  25. #        if color >= 0 and color <= 7
  26. #          self.contents.font.color = text_color(color)
  27. #        end
  28. #        next
  29. #      end
  30.       if c == "\002"
  31.         y += 1
  32.         x = 0
  33.         next
  34.       end
  35. #      if c == "\003"
  36. #        @text.sub!(/\[([0-9]+)\]/, "")
  37. #        t = RPG::Cache.icon("skill_#{$1}")
  38. #        self.contents.blt(x, 32 * y, t, t.rect)
  39. #        t.dispose
  40. #        next
  41. #      end
  42.       self.contents.draw_text(4 + x, 32 * y, 40, 32, c)
  43.       x += self.contents.text_size(c).width
  44.       if x + self.contents.text_size(c).width >= self.width - 40
  45.       y += 1
  46.       x = 0
  47.      end
  48.     end
  49.     end
  50.     self.visible = true
  51.   end  
复制代码

就在这段有个缺陷-_-。因为这段是以前别人给写的我直接拿来用了orz
缺陷就是当注释文字多了时帧数会明显下降,感觉应该是重复刷新helpwindow造成的。
将SceneQuest里的helpwindowupdate加上按键才刷新的条件,问题依旧orz
用以下这段set_text_new就没问题,所以可能是这个方法本身有点问题……orz正则表达式仍然完全不通,请高人指教。
附无错版的set_text_new方法:
  def set_text_new(text, align = 0)
  # 如果文本和对齐方式的至少一方与上次的不同
   if text != @text or align != @align
    # 再描绘文本
    self.contents.clear
    self.contents.font.color = normal_color
    x = 4; y = 0
    for c in text.scan(/./)
     if x + self.contents.text_size(c).width >= self.width - 40
      x = 4; y += 32
     end
     self.contents.draw_text(x, y, 40, 32, c, align)
     x += self.contents.text_size(c).width
    end
    @text = text
    @align = align
    @actor = nil
   end
   self.visible = true
  end
这个方法可以自动换行,缺点是没法手动换行……

5、默认路径是system/Questdata.rxdata,所以在工程文件夹下建立个system文件夹。如果不想建文件夹,就改quest_illust和SceneQuest里的两个文件路径。

6、完成。

用法:
见范例工程。
http://rpg.blue/upload_program/files/带说明任务系统.rar
添加任务说明:
quest_illust("任务编号","详细说明内容")

附type值对应的任务种类:
0-已完成主线,1-当前主线,2-未完成主线,3-已完成支线,4-未完成支线,5-失效支线。

——————————

修正工程已上传
嗯……改成可排版的就完美了TvT 正则表达式持续不会中……
……………………啊咧?

Lv1.梦旅人

梦石
0
星屑
55
在线时间
2 小时
注册时间
2006-11-10
帖子
931
2
 楼主| 发表于 2006-12-13 06:58:36 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
做话题游戏的过程中试着自制了一个带详细说明的任务系统……
这个系统可以将任务编号对应的说明存在system/Questdata.rxdata里。
在做游戏的时候可以随时用事件脚本——添加说明的方法把任务详细说明全都写在某个文件中,游戏做完后将添加详细说明的事件删除即可。只要发布时有将记载说明的文件放在文件夹里即可正常显示各任务的详细说明。
这样即使玩家拆了游戏也不会看到全任务-_-。并且省去了一些事件和脚本,扩大了任务系统的信息容量。

任务分类窗口是拿简单物品分类窗口改造的,所以里面夹杂了很多日文注释-_\\
参考脚本:月光奏鸣曲(布局),66的任务系统教学(架构)

另外,这个版本是整合版而非可以直接使用的版本=v=感兴趣的各位可以照下面步骤逐步整合=v=

1、首先是一个Window_Quest,包括command窗口和questlist窗口。
   可以看到某人为了偷工减料,直接把helpwindow用作显示详细说明的窗口了-_\\

  1. class Window_QuestCommand < Window_Selectable
  2. #--------------------------------------------------------------------------
  3.   # ● オブジェクト初期化
  4.   #--------------------------------------------------------------------------
  5.   def initialize
  6.     super(10, 10, 130, 195)
  7.     self.contents = Bitmap.new(width - 32, height - 32)
  8.     @item_max = 5
  9.     @commands = ["主线任务", "支线任务", "失效任务", "完成任务", "所有任务"]
  10.     refresh
  11.     self.index = 0
  12.   end
  13.   #--------------------------------------------------------------------------
  14.   # ● リフレッシュ
  15.   #--------------------------------------------------------------------------
  16.   def refresh
  17.     self.contents.clear
  18.     for i in 0...@item_max
  19.     draw_item(i, normal_color)
  20.     end
  21.   end
  22.   #--------------------------------------------------------------------------
  23.   # ● 項目の描画
  24.   # index : 項目番号
  25.   # color : 文字色
  26.   #--------------------------------------------------------------------------
  27.   def draw_item(index, color)
  28.     self.contents.font.color = color
  29.     y = index * 32
  30.     self.contents.draw_text(4, y, 128, 32, @commands[index])
  31.   end
  32.   #--------------------------------------------------------------------------
  33.   # ● ヘルプテキスト更新
  34.   #--------------------------------------------------------------------------
  35.   def update_help
  36.     case self.index
  37.     when 0
  38.       @text = "主线任务。"
  39.     when 1
  40.       @text = "支线任务。"
  41.     when 2
  42.       @text = "失效任务。"
  43.     when 3
  44.       @text = "完成任务。"
  45.     when 4
  46.       @text = "全部任务列表。"
  47.     end
  48.     @help_window.set_text_new(@text,1)
  49.   end
  50. end




  51. class Window_QuestList < Window_Selectable
  52.   def initialize
  53.     super(150, 10, 480, 195)
  54.     self.contents = Bitmap.new(width - 32, height - 32)
  55.     refresh
  56.     self.index = 0
  57.   end
  58.   #--------------------------------------------------------------------------
  59.   # ● 获取任务名称
  60.   #--------------------------------------------------------------------------
  61.   def item
  62.     return @data[self.index]
  63.   end
  64.   #--------------------------------------------------------------------------
  65.   # ● 获取任务类别
  66.   #--------------------------------------------------------------------------
  67.   def itemtype
  68.     return @type[self.index]
  69.   end
  70.   #--------------------------------------------------------------------------
  71.   # ● 获取任务说明
  72.   #--------------------------------------------------------------------------
  73.   def itemdesc
  74.     return @desc[self.index]
  75.   end
  76.   #--------------------------------------------------------------------------
  77.   # ● リフレッシュ
  78.   #--------------------------------------------------------------------------
  79.   def refresh
  80.     if self.contents != nil
  81.       self.contents.dispose
  82.       self.contents = nil
  83.     end
  84.     @data = []
  85.     @type = []
  86.     @desc = []
  87.   end
  88.   #--------------------------------------------------------------------------
  89.   # ● アイテム一覧設定
  90.   # command : 選択中のコマンド
  91.   #--------------------------------------------------------------------------
  92.   def set_item(command)
  93.     refresh
  94.     case command
  95.     when 0
  96.       for i in 0...$game_system.list.size
  97.         if ($game_system.type[i] == 0 or $game_system.type[i] == 1 or $game_system.type[i] == 2) and $game_system.contents != nil
  98.           @data.push($game_system.contents[i])
  99.           @type.push($game_system.type[i])
  100.           @desc.push($game_system.desc[i])
  101.         end
  102.       end
  103.     when 1
  104.       for i in 0...$game_system.list.size
  105.         if ($game_system.type[i] == 3 or $game_system.type[i] == 4 or $game_system.type[i] == 5) and $game_system.contents != nil
  106.           @data.push($game_system.contents[i])
  107.           @type.push($game_system.type[i])
  108.           @desc.push($game_system.desc[i])
  109.         end
  110.       end
  111.     when 2
  112.       for i in 0...$game_system.list.size
  113.         if $game_system.type[i] == 5 and $game_system.contents != nil
  114.           @data.push($game_system.contents[i])
  115.           @type.push($game_system.type[i])
  116.           @desc.push($game_system.desc[i])
  117.         end
  118.       end
  119.     when 3
  120.       for i in 0...$game_system.list.size
  121.         if ($game_system.type[i] == 0 or $game_system.type[i] == 3) and $game_system.contents != nil
  122.           @data.push($game_system.contents[i])
  123.           @type.push($game_system.type[i])
  124.           @desc.push($game_system.desc[i])
  125.         end
  126.       end
  127.     when 4
  128.       for i in 0...$game_system.list.size
  129.         if $game_system.contents != nil
  130.           @data.push($game_system.contents[i])
  131.           @type.push($game_system.type[i])
  132.           @desc.push($game_system.desc[i])
  133.         end
  134.       end
  135.     end
  136.     # 項目数が 0 でなければビットマップを作成し、全項目を描画
  137.     @item_max = @data.size
  138.     if @item_max > 0
  139.       self.contents = Bitmap.new(width - 32, row_max * 32)
  140.       self.contents.clear
  141.       for i in 0...@item_max
  142.         draw_item(i)
  143.       end
  144.     end
  145.   end
  146.   #--------------------------------------------------------------------------
  147.   # ● 種類別アイテム数の取得
  148.   #--------------------------------------------------------------------------
  149.   def item_number
  150.     return @item_max
  151.   end
  152.   #--------------------------------------------------------------------------
  153.   # ● 項目の描画
  154.   # index : 項目番号
  155.   #--------------------------------------------------------------------------
  156.   def draw_item(index)
  157.     item = @data[index]
  158.     type = @type[index]
  159.     typename = ""
  160.    
  161.     case type
  162.     when 0
  163.       self.contents.font.color = disabled_color
  164.       typename = "[主线]"
  165.     when 1
  166.       self.contents.font.color = system_color
  167.       typename = "[当前]"
  168.     when 2
  169.       self.contents.font.color = normal_color
  170.       typename = "[主线]"
  171.     when 3
  172.       self.contents.font.color = disabled_color
  173.       typename = "[支线]"
  174.     when 4
  175.       self.contents.font.color = normal_color
  176.       typename = "[支线]"
  177.     when 5
  178.       self.contents.font.color = crisis_color
  179.       typename = "[失效]"
  180.     end
  181.    
  182.     x = 4
  183.     y = index * 32
  184.     self.contents.draw_text(x, y, 100, 32, typename, 0)
  185.     self.contents.draw_text(x + 65, y, 212, 32, item, 0)
  186.   end
  187.   #--------------------------------------------------------------------------
  188.   # ● ヘルプテキスト更新
  189.   #--------------------------------------------------------------------------
  190.   def update_help
  191.     if @data == []
  192.       @text = "此项目中没有任务。"
  193.       @help_window.set_text_new(@text,1)
  194.     else
  195.       @help_window.set_text_new(self.itemdesc == nil ? "此任务详细内容不明。" : self.itemdesc)
  196.     end
  197.   end
  198. end
复制代码

2、其次是一个Scene_Quest,任务系统主界面。

  1. #==============================================================================
  2. # ■ Scene_Quest
  3. #------------------------------------------------------------------------------
  4. #  任务系统。
  5. #==============================================================================
  6. class Scene_Quest
  7.   #--------------------------------------------------------------------------
  8.   # ● メイン処理
  9.   #--------------------------------------------------------------------------
  10.   def main
  11.     if FileTest.exist?("system/Questdata.rxdata")
  12.        file = File.open("system/Questdata.rxdata", "r")
  13.        $game_system.desc = Marshal.load(file)
  14.        file.close
  15.     end
  16.     #コマンドウィンドウを作成
  17.     @questcommand_window = Window_QuestCommand.new
  18.     @command_index = @questcommand_window.index
  19.     #アイテムウィンドウを作成
  20.     @questlist_window = Window_QuestList.new
  21.     @questlist_window.active = false
  22.     #ヘルプウィンドウを作成
  23.     @help_window = Window_Help.new
  24.     # ヘルプウィンドウを関連付け
  25.     @questcommand_window.help_window = @help_window
  26.     @questlist_window.help_window = @help_window

  27.     # アイテムウィンドウ内容表示
  28.     @questlist_window.set_item(@command_index)
  29.     # トランジション実行
  30.     Graphics.transition
  31.     # メインループ
  32.     loop do
  33.       # ゲーム画面を更新
  34.       Graphics.update
  35.       # 入力情報を更新
  36.       Input.update
  37.       # フレーム更新
  38.       update
  39.       # 画面が切り替わったらループを中断
  40.       if $scene != self
  41.         break
  42.       end
  43.     end
  44.     # トランジション準備
  45.     Graphics.freeze
  46.     # ウィンドウを解放

  47.     @questcommand_window.dispose
  48.     @questlist_window.dispose
  49.     @help_window.dispose
  50.   end
  51.   #--------------------------------------------------------------------------
  52.   # ● フレーム更新
  53.   #--------------------------------------------------------------------------
  54.   def update
  55.     # ウィンドウを更新
  56.     @questcommand_window.update
  57.     @questlist_window.update
  58.     @help_window.update
  59.     if @command_index != @questcommand_window.index
  60.       @command_index = @questcommand_window.index
  61.       @questlist_window.set_item(@command_index)
  62.     end
  63.     # コマンドウィンドウがアクティブの場合: update_questcommand を呼ぶ
  64.     if @questcommand_window.active
  65.       update_questcommand
  66.       return
  67.     end
  68.     # アイテムウィンドウがアクティブの場合: update_questlist を呼ぶ
  69.     if @questlist_window.active
  70.       update_questlist
  71.       return
  72.     end
  73.   end
  74.   #--------------------------------------------------------------------------
  75.   # ● フレーム更新 (コマンドウィンドウがアクティブの場合)
  76.   #--------------------------------------------------------------------------
  77.   def update_questcommand
  78.   # B ボタンが押された場合
  79.   if Input.trigger?(Input::B)
  80.   # キャンセル SE を演奏
  81.   $game_system.se_play($data_system.cancel_se)
  82.   # メニュー画面に切り替え
  83.   $scene = Scene_Menu.new(5)
  84.   return
  85.   end
  86.   # C ボタンが押された場合
  87.   if Input.trigger?(Input::C)
  88.   # 決定 SE を演奏
  89.   $game_system.se_play($data_system.decision_se)
  90.   # アイテムウィンドウをアクティブにする
  91.   @questcommand_window.active = false
  92.   @questlist_window.active = true
  93.   @questlist_window.index = 0
  94.   return
  95.   end
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # ● フレーム更新 (アイテムウィンドウがアクティブの場合)
  99.   #--------------------------------------------------------------------------
  100.   def update_questlist
  101.     # B ボタンが押された場合
  102.     if Input.trigger?(Input::B)
  103.       # キャンセル SE を演奏
  104.       $game_system.se_play($data_system.cancel_se)
  105.       # アイテムウィンドウをアクティブにする
  106.       @questcommand_window.active = true
  107.       @questlist_window.active = false
  108.       @questlist_window.index = 0
  109.       @questcommand_window.index = @command_index
  110.       return
  111.     end
  112.   end
  113. end
复制代码

3、在GameSystem里添加以下accessor:

  attr_accessor :list                     # 任务编号
  attr_accessor :contents                 # 任务标题
  attr_accessor :type                     # 任务种类
  attr_accessor :desc                     # 任务详细信息

并且在initialize项里添加以下初始化:

    @list = []
    @contents = []
    @type = []
    @desc = []

然后,在GameSystem里添加以下三个方法:

  #----------------------
  # ● 插入任务
  #----------------------
  def new_quest(n1,n2,n3)
    @list.push(n1)
    @contents.push(n2)
    @type.push(n3)
  end
  #----------------------
  # ● 添加任务注释
  #----------------------
  def quest_illust(n1,n4)
    for i in [email protected]
      if @list == n1
         @desc = n4
      end
    end
    file = File.open("system/Questdata.rxdata", "wb")
    Marshal.dump($game_system.desc, file)
    file.close
  end
  #----------------------
  # ● 完成任务(失效处理或完成处理)
  #----------------------
  def end_quest(n1,n2,n3)
    for i in [email protected]
      if @list == n1 and @contents == n2
         @type = n3
      end
    end
  end
分别用来插入新任务,给任务添加注释和结束任务。

4、稍微改造一下WindowHelp,使之适合用来显示任务注释。
把WindowHelp默认的initialize用这个替换:
  def initialize
    if $scene.is_a?(Scene_Quest)
      super(10,215,620,255)
    else
      super(0, 0, 640, 64)
    end
    self.contents = Bitmap.new(width - 32, height - 32)
  end


在WindowHelp的set_text方法下添加新的方法set_text_new,用以给任务说明分段等。

  1.   def set_text_new1(text, align = 0)
  2.     if text != @text or align != @align
  3.     self.contents.clear
  4.     self.contents.font.color = normal_color
  5.     @text = text.clone
  6.     x = y = 0
  7.     begin
  8.       last_text = @text.clone
  9.       @text.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  10.     end until @text == last_text
  11.     @text.gsub!(/\\[Nn]\[([0-9]+)\]/) do
  12.       $game_actors[$1.to_i] != nil ? $game_actors[$1.to_i].name : ""
  13.     end
  14. #    @text.gsub!(/\\\\/) { "\000" }
  15. #    @text.gsub!(/\\[Cc]\[([0-9]+)\]/) { "\001[#{$1}]" }
  16.     @text.gsub!(/\\[Hh]/) { "\002" }
  17. #    @text.gsub!(/\\[Ss]\[([0-9]+)\]/) { "\003[#{$1}]" }
  18.     while ((c = @text.slice!(/./m)) != nil)
  19. #      if c == "\000"
  20. #        c = "\\"
  21. #      end
  22. #      if c == "\001"
  23. #        @text.sub!(/\[([0-9]+)\]/, "")
  24. #        color = $1.to_i
  25. #        if color >= 0 and color <= 7
  26. #          self.contents.font.color = text_color(color)
  27. #        end
  28. #        next
  29. #      end
  30.       if c == "\002"
  31.         y += 1
  32.         x = 0
  33.         next
  34.       end
  35. #      if c == "\003"
  36. #        @text.sub!(/\[([0-9]+)\]/, "")
  37. #        t = RPG::Cache.icon("skill_#{$1}")
  38. #        self.contents.blt(x, 32 * y, t, t.rect)
  39. #        t.dispose
  40. #        next
  41. #      end
  42.       self.contents.draw_text(4 + x, 32 * y, 40, 32, c)
  43.       x += self.contents.text_size(c).width
  44.       if x + self.contents.text_size(c).width >= self.width - 40
  45.       y += 1
  46.       x = 0
  47.      end
  48.     end
  49.     end
  50.     self.visible = true
  51.   end  
复制代码

就在这段有个缺陷-_-。因为这段是以前别人给写的我直接拿来用了orz
缺陷就是当注释文字多了时帧数会明显下降,感觉应该是重复刷新helpwindow造成的。
将SceneQuest里的helpwindowupdate加上按键才刷新的条件,问题依旧orz
用以下这段set_text_new就没问题,所以可能是这个方法本身有点问题……orz正则表达式仍然完全不通,请高人指教。
附无错版的set_text_new方法:
  def set_text_new(text, align = 0)
  # 如果文本和对齐方式的至少一方与上次的不同
   if text != @text or align != @align
    # 再描绘文本
    self.contents.clear
    self.contents.font.color = normal_color
    x = 4; y = 0
    for c in text.scan(/./)
     if x + self.contents.text_size(c).width >= self.width - 40
      x = 4; y += 32
     end
     self.contents.draw_text(x, y, 40, 32, c, align)
     x += self.contents.text_size(c).width
    end
    @text = text
    @align = align
    @actor = nil
   end
   self.visible = true
  end
这个方法可以自动换行,缺点是没法手动换行……

5、默认路径是system/Questdata.rxdata,所以在工程文件夹下建立个system文件夹。如果不想建文件夹,就改quest_illust和SceneQuest里的两个文件路径。

6、完成。

用法:
见范例工程。
http://rpg.blue/upload_program/files/带说明任务系统.rar
添加任务说明:
quest_illust("任务编号","详细说明内容")

附type值对应的任务种类:
0-已完成主线,1-当前主线,2-未完成主线,3-已完成支线,4-未完成支线,5-失效支线。

——————————

修正工程已上传
嗯……改成可排版的就完美了TvT 正则表达式持续不会中……
……………………啊咧?

Lv1.梦旅人

梦石
0
星屑
50
在线时间
2 小时
注册时间
2006-11-15
帖子
1
3
发表于 2006-12-13 16:41:29 | 只看该作者
先下载看一下,学习一下
游戏是我终身的伴侣
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
55
在线时间
2 小时
注册时间
2006-11-10
帖子
931
4
 楼主| 发表于 2006-12-13 23:55:57 | 只看该作者
12.13测试发现个小问题:
所有的添加注释操作必须在一次游戏进程内完成。
如果一次游戏进程只添加了部分注释,下次再用quest_illust添加时,上次进程所写的注释会不见= =

可以在游戏全部做完之后写一个事件一次性添加,然后删掉这个事件,这样可以一次性得到完整的注释文件= =

_________________________________________________


itemdesc方法写错了,修改中- -U
……………………啊咧?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-4 17:07

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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