查看: 1842|回复: 9

[有事请教] 存檔欄位擴充腳本如何讓游標停在最後操作的檔案上

[复制链接]
梦石
0
星屑
2179
在线时间
379 小时
注册时间
2023-6-6
回帖
16
发表于 2023-9-2 16:52:49 | 显示全部楼层 |阅读模式
悬赏10星屑已解决
以下存檔擴充的腳本
如何讓游標停在最後操作的檔案上
比如存在第6個檔案
在讀取檔案時 游標就停在第6號檔案上
依此類推
像原内建一樣存哪裡游標就會在哪裡

[pre lang="ruby"]#==============================================================================
# 本脚本来自www.66RPG.com,使用和转载请保留此信息
#==============================================================================



# --------------------------------------------------------------------
# 本脚本来自www.66rpg.com,转载自www.phylomortis.com,转载请保留此信息
# --------------------------------------------------------------------
class Scene_File
  #——最大存档数量,一般我认为最多50足够了,20比较合适
  SAVEFILE_MAX = 30
  # -------------------
  def initialize(help_text)
    @help_text = help_text
  end
  # -------------------
  def main
    @help_window = Window_Help.new
    @help_window.set_text(@help_text)
    @savefile_windows = []
    @cursor_displace = 0
    for i in 0..3
      @savefile_windows.push(Window_SaveFile.new(i, make_filename(i), i))
    end
    @file_index = 0
    @savefile_windows[@file_index].selected = true
    Graphics.transition
    loop do
      Graphics.update
      Input.update
      update
      if $scene != self
        break
      end
    end
    Graphics.freeze
    @help_window.dispose
    for i in @savefile_windows
      i.dispose
    end
  end
  # -------------------
  def update
    @help_window.update
    for i in @savefile_windows
      i.update
    end
    if Input.trigger?(Input::C)
      on_decision(make_filename(@file_index))
      $game_temp.last_file_index = @file_index
      return
    end
    if Input.trigger?(Input::B)
      on_cancel
      return
    end
    if Input.repeat?(Input::DOWN)
      if Input.trigger?(Input::DOWN) or @file_index < SAVEFILE_MAX - 1
        if @file_index == SAVEFILE_MAX - 1
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        @cursor_displace += 1
        if @cursor_displace == 4
          @cursor_displace = 3
          for i in @savefile_windows
            i.dispose
          end
          @savefile_windows = []
          for i in 0..3
            f = i - 2 + @file_index
            name = make_filename(f)
            @savefile_windows.push(Window_SaveFile.new(f, name, i))
            @savefile_windows.selected = false
          end
        end
        $game_system.se_play($data_system.cursor_se)
        @file_index = (@file_index + 1)
        if @file_index == SAVEFILE_MAX
          @file_index = SAVEFILE_MAX - 1
        end
        for i in 0..3
          @savefile_windows.selected = false
        end
        @savefile_windows[@cursor_displace].selected = true
        return
      end
    end
    if Input.repeat?(Input::UP)
      if Input.trigger?(Input::UP) or @file_index > 0
        if @file_index == 0
          $game_system.se_play($data_system.buzzer_se)
          return
        end
        @cursor_displace -= 1
        if @cursor_displace == -1
          @cursor_displace = 0
          for i in @savefile_windows
            i.dispose
          end
          @savefile_windows = []
          for i in 0..3
            f = i - 1 + @file_index
            name = make_filename(f)
            @savefile_windows.push(Window_SaveFile.new(f, name, i))
            @savefile_windows.selected = false
          end
        end
        $game_system.se_play($data_system.cursor_se)
        @file_index = (@file_index - 1)
        if @file_index == -1
          @file_index = 0
        end
        for i in 0..3
          @savefile_windows.selected = false
        end
        @savefile_windows[@cursor_displace].selected = true
        return
      end
    end
  end
  # -------------------
  def make_filename(file_index)
    return "Save#{file_index +1}.rxdata"
  end
  # -------------------
end




class Window_SaveFile < Window_Base
  # -------------------
  def initialize(file_index, filename, position)
    y = 64 + position * 104
    super(0, y, 640, 104)
    self.contents = Bitmap.new(width - 32, height - 32)
    @file_index = file_index
    @filename = "Save#{@file_index +1}.rxdata"
    @time_stamp = Time.at(0)
    @file_exist = FileTest.exist?(@filename)
    if @file_exist
      file = File.open(@filename, "r")
      @time_stamp = file.mtime
      @characters = Marshal.load(file)
      @frame_count = Marshal.load(file)
      @game_system = Marshal.load(file)
      @game_switches = Marshal.load(file)
      @game_variables = Marshal.load(file)
      @total_sec = @frame_count / Graphics.frame_rate
      file.close
    end
    refresh
    @selected = false
  end
end


#==============================================================================
# 本脚本来自www.66RPG.com,使用和转载请保留此信息
#============================================================================== [/pre]

最佳答案

查看完整内容

你的这个插件版本过老了 https://rpg.blue/thread-403346-1-1.html

遠航の猫咪

梦石
3
星屑
26947
在线时间
2423 小时
注册时间
2005-10-15
回帖
987

开拓者

发表于 2023-9-2 16:52:50 | 显示全部楼层
xuprmpau 发表于 2023-9-4 20:22
照你的方式修改了
存檔介面是成功達到我想要的效果了
可是讀取檔案的介面只有存1~4欄位會正常

你的这个插件版本过老了
https://rpg.blue/thread-403346-1-1.html

评分

参与人数 1赞 +1 收起 理由
xuprmpau + 1 认可答案

查看全部评分

SailCat (小猫子·要开心一点) 共上站 24 次,发表过 11 篇文章 上 次 在: [2006年01月28日11:41:18 星期六] 从 [162.105.120.91] 到本站一游。
回复

使用道具 举报

梦石
0
星屑
39236
在线时间
11155 小时
注册时间
2009-3-15
回帖
4768
发表于 2023-9-2 17:39:49 | 显示全部楼层
本帖最后由 soulsaga 于 2023-9-2 17:42 编辑

[pre lang="ruby"]#--------------------------------------------------------------------------
  # ● 主处理
  #--------------------------------------------------------------------------
  def main
    # 生成帮助窗口
    @help_window = Window_Help.new
    @help_window.width = 480
    @help_window.contents = Bitmap.new(@help_window.width-32, @help_window.height-32)
    @help_window.set_text(@help_text)
    @savepage_window = Window_SavePage.new
    #@savepage_window.opacity=0
    @savepage_window.set_text(PagesText[0])
    @file_index = $game_temp.last_file_index
    # 生成存档文件窗口
    @savefile_windows = []
    # 选择最后操作的文件
    for i in @file_index / 4 * 4..@file_index / 4 * 4 + 3
      load_window(i)
      @savefile_windows.visible = true
    end
    @savefile_windows[@file_index].selected = true
    # 执行过渡
    Graphics.transition
    # 主循环
    loop do
      # 刷新游戏画面
      Graphics.update
      # 刷新输入信息
      Input.update
      # 刷新画面
      update
      # 如果画面被切换的话就中断循环
      if $scene != self
        break
      end
    end
     
    # 准备过渡
    Graphics.freeze
    # 释放窗口
    @help_window.dispose
    @savepage_window.dispose
    for i in 0...@slots
      @savefile_windows.dispose if @savefile_windows != nil
    end
  end[/pre]

上面的脚本决定的..
回复

使用道具 举报

梦石
0
星屑
2179
在线时间
379 小时
注册时间
2023-6-6
回帖
16
 楼主| 发表于 2023-9-2 18:53:45 | 显示全部楼层
soulsaga 发表于 2023-9-2 17:39
#--------------------------------------------------------------------------
  # ● 主处理
  #------- ...

你這個跟我貼的那個腳本不同吧
你這個還有新的窗口Window_SavePage.new
應該不太一樣
回复

使用道具 举报

梦石
0
星屑
8474
在线时间
776 小时
注册时间
2018-11-3
回帖
8
发表于 2023-9-4 01:12:54 | 显示全部楼层
看到你的脚本中每次存档时仍然记录了档案编号(第 51 行):
  1. $game_temp.last_file_index = @file_index
复制代码

那么进入存读档界面时,将光标位置设为先前的记录即可(第 26 行):
  1. @file_index = $game_temp.last_file_index
复制代码


不过存读档窗口的显示逻辑不同于一般的基于 Window_Selectable 建立的选择项窗口,仅通过设置光标位置并不会显示正确的档案。
进入存读档界面时,描绘当前页面档案的部分位于脚本的第 22 - 27 行,这一部分一并替换如下:
  1. # 获取最后一次操作的档案编号
  2. @file_index = $game_temp.last_file_index
  3. # 计算页面显示的第一条档案编号、显示档案
  4. delta_index = [@file_index, SAVEFILE_MAX - 3].min
  5. for i in 0...4
  6.   @savefile_windows << Window_SaveFile.new(delta_index + i, make_filename(delta_index + i),  i)
  7. end
  8. # 设置光标在当前界面的位置
  9. @cursor_display = @file_index - delta_index
  10. @savefile_windows[@cursor_display].selected = true
复制代码


上面的显示效果是:
假设你有30个存档,如果最后一次操作的存档编号是一个小于28的数 X,
那么进入存档界面时会显示编号从 X 到 X+3 的四个档案,光标停留在最上方(即编号为 X 的)档案上,
如果 X 不小于 28,那么会显示27、28、29、30四个档案,光标停留在相应的地方。
即大部分情况下进入存档界面,光标总是停留在最上方的档案。。。

我其实有见过另外一个版本的档案破限脚本,
它以 4 个档案为一个周期,每一次页面上总是显示从 4x 到 4x+3 的档案,这样光标不至于经常做惰性位移。
不过从你这边的写法来看,在实际光标移动的时候一个页面显示的连续四个编号档案是随意变化的,
所以上面这种显示效果我理解上可能是更适合你的移动逻辑的。

点评

NewBee  发表于 2023-9-4 16:06

评分

参与人数 1赞 +1 收起 理由
xuprmpau + 1 塞糖

查看全部评分

回复

使用道具 举报

梦石
0
星屑
2179
在线时间
379 小时
注册时间
2023-6-6
回帖
16
 楼主| 发表于 2023-9-4 20:22:16 | 显示全部楼层
Istrien 发表于 2023-9-4 01:12
看到你的脚本中每次存档时仍然记录了档案编号(第 51 行):

那么进入存读档界面时,将光标位置设为先前的 ...

照你的方式修改了
存檔介面是成功達到我想要的效果了
可是讀取檔案的介面只有存1~4欄位會正常
存到5~30之後 讀檔時  光標總是停在第2欄位

其實我只是想要和基本內建時只有4個檔案時的效果一樣
存在1時 打開存檔或讀取 光標都會在1
如果這時存在3  那再次開啟存檔或讀取時光標會在3
而這時如果又存新的檔案覆蓋1號  那下次打開存檔或讀取時  光標會ˋ自動停在1號  這個樣子

目前依你的方式修改  存檔是達到效果了  讀取卻沒有
還是很感謝你
回复

使用道具 举报

梦石
0
星屑
2179
在线时间
379 小时
注册时间
2023-6-6
回帖
16
 楼主| 发表于 2023-9-4 21:33:19 | 显示全部楼层
SailCat 发表于 2023-9-4 20:58
你的这个插件版本过老了
https://rpg.blue/thread-403346-1-1.html

其實之前有看到貓大的這份腳本
確實非常強大
可是總覺得有些玩家天生叛逆  存檔時不是從一號位開始存檔 而是先存在 第5位 第9位 之類的
所以一直在考慮

不過我現在思考思考……
或許不要執著才是對的QQ

決定了 就認可貓大的答案了
也很感謝@Istrien 的解答

謝謝你們
回复

使用道具 举报

梦石
0
星屑
8474
在线时间
776 小时
注册时间
2018-11-3
回帖
8
发表于 2023-9-4 21:50:11 | 显示全部楼层
xuprmpau 发表于 2023-9-4 20:22
照你的方式修改了
存檔介面是成功達到我想要的效果了
可是讀取檔案的介面只有存1~4欄位會正常

你用的这个插件好像是因为没有做这个自动指向最后操作的档案功能,所以没有改动 Scene_Load 的部分,
抱歉,是我考虑的不周到。。
保留原版的 Scene_Load 的初始化方法,就会导致只在前四个档案中寻找最后操作的档案。

6楼老师提供的新版插件应该效果会这个更好一点吧,可以直接改用那个。

或者如果打算保留这个版本,可以去 Scene_Load 中
将 initialize 方法里将遍历所有档案的循环次数从 4 改成 SAVEFILE_MAX
  1. def initialize
  2.   # 再生成临时对像
  3.   $game_temp = Game_Temp.new
  4.   # 选择存档时间最新的文件
  5.   $game_temp.last_file_index = 0
  6.   latest_time = Time.at(0)
  7.   for i in 0...SAVEFILE_MAX
  8.     filename = make_filename(i)
  9.     if FileTest.exist?(filename)
  10.       file = File.open(filename, "r")
  11.       if file.mtime > latest_time
  12.         latest_time = file.mtime
  13.         $game_temp.last_file_index = i
  14.       end
  15.       file.close
  16.     end
  17.   end
  18.   super("要载入哪个文件?")
  19. end
复制代码


还是使用6楼的老师提供的新版插件吧,个人感觉,
既然打算选择灵活的排版方式,就让它在各个效果上都变成自适应吧。

点评

謝謝你不斷熱心的解答!  发表于 2023-9-4 21:52

评分

参与人数 1赞 +1 收起 理由
xuprmpau + 1 我很赞同

查看全部评分

回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部