Project1

标题: 怎么往这个菜单里添加存档的功能 [打印本页]

作者: as295d    时间: 2008-6-9 01:27
标题: 怎么往这个菜单里添加存档的功能
http://rpg.blue/web/htm/news460.htm
这个里面的菜单我感觉不错。问题是怎么往里面添加存档啊? [LINE]1,#dddddd[/LINE]版务信息:本贴由楼主自主结贴~
作者: havealook    时间: 2008-6-9 01:33
  1. #==============================================================================
  2. # ■ Scene_Save
  3. #------------------------------------------------------------------------------
  4. #  处理存档画面的类。
  5. #==============================================================================

  6. class Scene_Save < Scene_File
  7.   #--------------------------------------------------------------------------
  8.   # ● 初始化对像
  9.   #--------------------------------------------------------------------------
  10.   def initialize
  11.     super("要保存到这个文件吗?")
  12.   end
  13.   #--------------------------------------------------------------------------
  14.   # ● 确定时的处理
  15.   #--------------------------------------------------------------------------
  16.   def on_decision(filename)
  17.     # 演奏存档 SE
  18.     $game_system.se_play($data_system.save_se)
  19.     # 写入存档数据
  20.     file = File.open(filename, "wb")
  21.     write_save_data(file)
  22.     file.close
  23.     # 如果被事件调用
  24.     if $game_temp.save_calling
  25.       # 清除存档调用标志
  26.       $game_temp.save_calling = false
  27.       # 切换到地图画面
  28.       $scene = Scene_Map.new
  29.       return
  30.     end
  31.     # 切换到菜单画面
  32.     $scene = Scene_Menu.new(7)
  33.   end
  34.   #--------------------------------------------------------------------------
  35.   # ● 取消时的处理
  36.   #--------------------------------------------------------------------------
  37.   def on_cancel
  38.     # 演奏取消 SE
  39.     $game_system.se_play($data_system.cancel_se)
  40.     # 如果被事件调用
  41.     if $game_temp.save_calling
  42.       # 清除存档调用标志
  43.       $game_temp.save_calling = false
  44.       # 切换到地图画面
  45.       $scene = Scene_Map.new
  46.       return
  47.     end
  48.     # 切换到菜单画面
  49.     $scene = Scene_Menu.new(7)
  50.   end
  51.   #--------------------------------------------------------------------------
  52.   # ● 写入存档数据
  53.   #     file : 写入用文件对像 (已经打开)
  54.   #--------------------------------------------------------------------------
  55.   def write_save_data(file)
  56.     # 生成描绘存档文件用的角色图形
  57.     characters = []
  58.     for i in 0...$game_party.actors.size
  59.       actor = $game_party.actors[i]
  60.       characters.push([actor.character_name, actor.character_hue])
  61.     end
  62.     # 写入描绘存档文件用的角色数据
  63.     Marshal.dump(characters, file)
  64.     # 写入测量游戏时间用画面计数
  65.     Marshal.dump(Graphics.frame_count, file)
  66.     # 增加 1 次存档次数
  67.     $game_system.save_count += 1
  68.     # 保存魔法编号
  69.     # (将编辑器保存的值以随机值替换)
  70.     $game_system.magic_number = $data_system.magic_number
  71.     # 写入各种游戏对像
  72.     Marshal.dump($game_system, file)
  73.     Marshal.dump($game_switches, file)
  74.     Marshal.dump($game_variables, file)
  75.     Marshal.dump($game_self_switches, file)
  76.     Marshal.dump($game_screen, file)
  77.     Marshal.dump($game_actors, file)
  78.     Marshal.dump($game_party, file)
  79.     Marshal.dump($game_troop, file)
  80.     Marshal.dump($game_map, file)
  81.     Marshal.dump($game_player, file)
  82.   end
  83. end


  84. class Window_Command_New < Window_Selectable
  85.   def initialize(actors=4,enemynums=0)
  86.     super(438, 20, 172, 160)
  87.     self.contents = Bitmap.new(width - 32, height - 32)
  88.     self.opacity = HS::OPACITY
  89.     @commands = ["战斗","物品","魔法","状态","装备","队列","任务","存档"]
  90.     @item_max = 8
  91.     @column_max = 2
  92.     @actors = actors
  93.     @enemynums = enemynums
  94.     draw_item(0, @enemynums==0 ? disabled_color : normal_color)
  95.     draw_item(1, normal_color)
  96.     draw_item(2, @actors==0 ? disabled_color : normal_color)
  97.     draw_item(3, @actors==0 ? disabled_color : normal_color)
  98.     draw_item(4, @actors==0 ? disabled_color : normal_color)
  99.     draw_item(5, @actors==0 ? disabled_color : normal_color)
  100.     draw_item(6, normal_color)
  101.     draw_item(7, normal_color)
  102.     self.index = 0
  103.   end
  104.   def draw_item(index, color)
  105.     self.contents.font.color = color
  106.     x = 4 + index % 2 * 70
  107.     y = index / 2 * 32
  108.     rect = Rect.new(x, y, 64, 32)
  109.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  110.     self.contents.draw_text(rect, @commands[index], 1)
  111.   end
  112.   def update_cursor_rect
  113.     x = 4 + index % 2 * 70
  114.     y = index / 2 * 32
  115.     self.cursor_rect.set(x, y, 64, 32)
  116.   end
  117. end

  118. class Scene_Menu
  119.   def initialize(menu_index = 0)
  120.     @menu_index = menu_index
  121.   end
  122.   def main
  123. #   check_enemy_in_map($game_player.x,$game_player.y)
  124.     cmd = Window_Command_New.new($game_party.actors.size)
  125.     cmd.index = @menu_index
  126.     Graphics.transition
  127.     loop do
  128.       Graphics.update
  129.       Input.update
  130.       cmd.update
  131.       if Input.trigger?(Input::B)
  132.         $game_system.se_play($data_system.cancel_se)
  133.         $scene = Scene_Map.new
  134.       end
  135.       if Input.trigger?(Input::C)
  136.         case cmd.index
  137.         when 0
  138.           $game_system.se_play($data_system.buzzer_se)
  139.         when 1
  140.           $game_system.se_play($data_system.decision_se)
  141.           $scene = Scene_Item.new
  142.         when 2
  143.           $game_system.se_play($data_system.decision_se)
  144.           $scene = Scene_Skill.new
  145.         when 3
  146.           $game_system.se_play($data_system.decision_se)
  147.           $scene = Scene_Status.new
  148.         when 4
  149.           $game_system.se_play($data_system.decision_se)
  150.           $scene = Scene_Equip.new
  151.         when 5
  152.           $game_system.se_play($data_system.decision_se)
  153.           $scene = Scene_Change_Turn.new
  154.         when 6
  155.           print "可以自己结合叶子的任务系统设计"
  156.         when 7
  157.           $game_system.se_play($data_system.decision_se)
  158.           $scene=Scene_Save.new
  159.         end
  160.       end
  161.       if $scene != self
  162.         break
  163.       end
  164.     end
  165.     Graphics.freeze
  166.     cmd.dispose
  167.   end
  168. end

复制代码



插入到Main之前,少处修改{/gg} [LINE]1,#dddddd[/LINE]系统信息:本贴由楼主认可为正确答案,66RPG感谢您的热情解答~
作者: 八云紫    时间: 2008-6-9 01:36
菜单里的脚本 Scene_Menu , 第 8 行 :

@commands = ["战斗","物品","魔法","状态","装备","队列","任务","系统"]

系统换成 “存档”

就是 @commands = ["战斗","物品","魔法","状态","装备","队列","任务","存档"]


[LINE]1,#dddddd[/LINE]

第 77 行 改成


  1. if $game_system.save_disabled
  2.   # 演奏冻结 SE
  3.   $game_system.se_play($data_system.buzzer_se)
  4.   return
  5. end
  6.   # 演奏确定 SE
  7.   $game_system.se_play($data_system.decision_se)
  8.   # 切换到存档画面
  9.   $scene = Scene_Save.new

复制代码


在Main之前增加这个:


  1. class Scene_Save < Scene_File
  2.   def on_cancel
  3.     # 演奏取消 SE
  4.     $game_system.se_play($data_system.cancel_se)
  5.     # 如果被事件调用
  6.     if $game_temp.save_calling
  7.       # 清除存档调用标志
  8.       $game_temp.save_calling = false
  9.       # 切换到地图画面
  10.       $scene = Scene_Map.new
  11.       return
  12.     end
  13.     # 切换到菜单画面
  14.     $scene = Scene_Menu.new(7)
  15.   end
  16. end
复制代码

作者: 3535    时间: 2008-6-9 01:37
替换那脚本的Window_Command_New,havealook那个用了就不能用事件禁止存档,没了:
        if $game_system.save_disabled
          $game_system.se_play($data_system.buzzer_se)
          return
        end
  1. class Window_Command_New < Window_Selectable
  2.   def initialize(actors=4,enemynums=0)
  3.     super(438, 20, 172, 160)
  4.     self.contents = Bitmap.new(width - 32, height - 32)
  5.     self.opacity = HS::OPACITY
  6.     @commands = ["战斗","物品","魔法","状态","装备","队列","任务","存档"]
  7.     @item_max = 8
  8.     @column_max = 2
  9.     @actors = actors
  10.     @enemynums = enemynums
  11.     draw_item(0, @enemynums==0 ? disabled_color : normal_color)
  12.     draw_item(1, normal_color)
  13.     draw_item(2, @actors==0 ? disabled_color : normal_color)
  14.     draw_item(3, @actors==0 ? disabled_color : normal_color)
  15.     draw_item(4, @actors==0 ? disabled_color : normal_color)
  16.     draw_item(5, @actors==0 ? disabled_color : normal_color)
  17.     draw_item(6, normal_color)
  18.     draw_item(7, normal_color)
  19.     self.index = 0
  20.   end
  21.   def draw_item(index, color)
  22.     self.contents.font.color = color
  23.     x = 4 + index % 2 * 70
  24.     y = index / 2 * 32
  25.     rect = Rect.new(x, y, 64, 32)
  26.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  27.     self.contents.draw_text(rect, @commands[index], 1)
  28.   end
  29.   def update_cursor_rect
  30.     x = 4 + index % 2 * 70
  31.     y = index / 2 * 32
  32.     self.cursor_rect.set(x, y, 64, 32)
  33.   end
  34. end

  35. class Scene_Menu
  36.   def initialize(menu_index = 0)
  37.     @menu_index = menu_index
  38.   end
  39.   def main
  40. #   check_enemy_in_map($game_player.x,$game_player.y)
  41.     cmd = Window_Command_New.new($game_party.actors.size)
  42.     cmd.index = @menu_index
  43.     Graphics.transition
  44.     loop do
  45.       Graphics.update
  46.       Input.update
  47.       cmd.update
  48.       if Input.trigger?(Input::B)
  49.         $game_system.se_play($data_system.cancel_se)
  50.         $scene = Scene_Map.new
  51.       end
  52.       if Input.trigger?(Input::C)
  53.         case cmd.index
  54.         when 0
  55.           $game_system.se_play($data_system.buzzer_se)
  56.         when 1
  57.           $game_system.se_play($data_system.decision_se)
  58.           $scene = Scene_Item.new
  59.         when 2
  60.           $game_system.se_play($data_system.decision_se)
  61.           $scene = Scene_Skill.new
  62.         when 3
  63.           $game_system.se_play($data_system.decision_se)
  64.           $scene = Scene_Status.new
  65.         when 4
  66.           $game_system.se_play($data_system.decision_se)
  67.           $scene = Scene_Equip.new
  68.         when 5
  69.           $game_system.se_play($data_system.decision_se)
  70.           $scene = Scene_Change_Turn.new
  71.         when 6
  72.           print "可以自己结合叶子的任务系统设计"
  73.         when 7
  74.           # 禁止存档的情况下
  75.         if $game_system.save_disabled
  76.           # 演奏冻结 SE
  77.           $game_system.se_play($data_system.buzzer_se)
  78.           return
  79.         end
  80.         # 演奏确定 SE
  81.         $game_system.se_play($data_system.decision_se)
  82.         # 切换到存档画面
  83.         $scene = Scene_Save.new
  84.         end
  85.       end
  86.       if $scene != self
  87.         break
  88.       end
  89.     end
  90.     Graphics.freeze
  91.     cmd.dispose
  92.   end
  93. end
复制代码

作者: as295d    时间: 2008-6-9 01:37
试试看
作者: havealook    时间: 2008-6-9 01:38
回八云紫,你考虑不周到哦{/gg}
如果按你说的,进入存档界面后,按ESC后,光标不会在“存档”上
还得修改Scene_Save返回后光标停留到第几项
这点我在2楼的脚本中修改了{/gg}
作者: Infrared    时间: 2008-6-9 01:38
提示: 作者被禁止或删除 内容自动屏蔽
作者: 八云紫    时间: 2008-6-9 01:39
以下引用havealook于2008-6-8 17:38:14的发言:

回八云紫,你考虑不周到哦
如果按你说的,进入存档界面后,按ESC后,光标不会在“存档”上
还得修改Scene_Save返回后光标停留到第几项
这点我在2楼的脚本中修改了


呵呵,忘记返回了。 明白了。
作者: havealook    时间: 2008-6-9 01:41
事件存档...
谁会考虑到那啊...{/gg}
作者: as295d    时间: 2008-6-9 01:41
怎么用了后就不透明了啊{/ll}
作者: 八云紫    时间: 2008-6-9 01:43
以下引用as295d于2008-6-8 17:41:50的发言:

怎么用了后就不透明了啊


窗口不透明吗?
作者: havealook    时间: 2008-6-9 01:45
  1. class Window_Base < Window
  2.   alias xrxs_mp7_initialize initialize
  3.   def initialize(x, y, width, height)
  4.     xrxs_mp7_initialize(x, y, width, height)
  5.     if $scene.is_a?(Scene_Menu) or
  6.        $scene.is_a?(Scene_Item) or
  7.        $scene.is_a?(Scene_Skill) or
  8.        $scene.is_a?(Scene_Equip) or
  9.        $scene.is_a?(Scene_Status) or
  10.        $scene.is_a?(Scene_Save) or
  11.        $scene.is_a?(Scene_End)
  12.       self.back_opacity = 160  #————这个数值可调,为透明程度
  13.     end
  14.   end
  15. end

  16. class Scene_Save
  17.   include XRXS_MP7_Module
  18.   alias xrxs_mp7_main main
  19.   def main
  20.     create_spriteset
  21.     xrxs_mp7_main
  22.     dispose_spriteset
  23.   end
  24. end
复制代码


再插入这个小脚本试下{/gg}{/gg}

作者: as295d    时间: 2008-6-9 01:50
原来是要插入到所有脚本之前啊,好了。。谢谢八云的热情解答。。虽然没选你的答案。。
作者: havealook    时间: 2008-6-9 01:51
别人家电脑的网速就是快 -v-
作者: Infrared    时间: 2008-6-9 01:52
提示: 作者被禁止或删除 内容自动屏蔽
作者: 八云紫    时间: 2008-6-9 02:19
以下引用Infrared于2008-6-8 17:52:14的发言:


我始终被无视。。。


那啥,风头被版主抢光了。{/tp}




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1