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

Project1

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

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

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1264
在线时间
301 小时
注册时间
2023-6-6
帖子
22
跳转到指定楼层
1
发表于 2023-9-2 16:52:49 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
10星屑
以下存檔擴充的腳本
如何讓游標停在最後操作的檔案上
比如存在第6個檔案
在讀取檔案時 游標就停在第6號檔案上
依此類推
像原内建一樣存哪裡游標就會在哪裡

RUBY 代码复制
  1. #==============================================================================
  2. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  3. #==============================================================================
  4.  
  5.  
  6.  
  7. # --------------------------------------------------------------------
  8. # 本脚本来自[url]www.66rpg.com[/url],转载自[url]www.phylomortis.com[/url],转载请保留此信息
  9. # --------------------------------------------------------------------
  10. class Scene_File
  11.   #——最大存档数量,一般我认为最多50足够了,20比较合适
  12.   SAVEFILE_MAX = 30
  13.   # -------------------
  14.   def initialize(help_text)
  15.     @help_text = help_text
  16.   end
  17.   # -------------------
  18.   def main
  19.     @help_window = Window_Help.new
  20.     @help_window.set_text(@help_text)
  21.     @savefile_windows = []
  22.     @cursor_displace = 0
  23.     for i in 0..3
  24.       @savefile_windows.push(Window_SaveFile.new(i, make_filename(i), i))
  25.     end
  26.     @file_index = 0
  27.     @savefile_windows[@file_index].selected = true
  28.     Graphics.transition
  29.     loop do
  30.       Graphics.update
  31.       Input.update
  32.       update
  33.       if $scene != self
  34.         break
  35.       end
  36.     end
  37.     Graphics.freeze
  38.     @help_window.dispose
  39.     for i in @savefile_windows
  40.       i.dispose
  41.     end
  42.   end
  43.   # -------------------
  44.   def update
  45.     @help_window.update
  46.     for i in @savefile_windows
  47.       i.update
  48.     end
  49.     if Input.trigger?(Input::C)
  50.       on_decision(make_filename(@file_index))
  51.       $game_temp.last_file_index = @file_index
  52.       return
  53.     end
  54.     if Input.trigger?(Input::B)
  55.       on_cancel
  56.       return
  57.     end
  58.     if Input.repeat?(Input::DOWN)
  59.       if Input.trigger?(Input::DOWN) or @file_index < SAVEFILE_MAX - 1
  60.         if @file_index == SAVEFILE_MAX - 1
  61.           $game_system.se_play($data_system.buzzer_se)
  62.           return
  63.         end
  64.         @cursor_displace += 1
  65.         if @cursor_displace == 4
  66.           @cursor_displace = 3
  67.           for i in @savefile_windows
  68.             i.dispose
  69.           end
  70.           @savefile_windows = []
  71.           for i in 0..3
  72.             f = i - 2 + @file_index
  73.             name = make_filename(f)
  74.             @savefile_windows.push(Window_SaveFile.new(f, name, i))
  75.             @savefile_windows[i].selected = false
  76.           end
  77.         end
  78.         $game_system.se_play($data_system.cursor_se)
  79.         @file_index = (@file_index + 1)
  80.         if @file_index == SAVEFILE_MAX
  81.           @file_index = SAVEFILE_MAX - 1
  82.         end
  83.         for i in 0..3
  84.           @savefile_windows[i].selected = false
  85.         end
  86.         @savefile_windows[@cursor_displace].selected = true
  87.         return
  88.       end
  89.     end
  90.     if Input.repeat?(Input::UP)
  91.       if Input.trigger?(Input::UP) or @file_index > 0
  92.         if @file_index == 0
  93.           $game_system.se_play($data_system.buzzer_se)
  94.           return
  95.         end
  96.         @cursor_displace -= 1
  97.         if @cursor_displace == -1
  98.           @cursor_displace = 0
  99.           for i in @savefile_windows
  100.             i.dispose
  101.           end
  102.           @savefile_windows = []
  103.           for i in 0..3
  104.             f = i - 1 + @file_index
  105.             name = make_filename(f)
  106.             @savefile_windows.push(Window_SaveFile.new(f, name, i))
  107.             @savefile_windows[i].selected = false
  108.           end
  109.         end
  110.         $game_system.se_play($data_system.cursor_se)
  111.         @file_index = (@file_index - 1)
  112.         if @file_index == -1
  113.           @file_index = 0
  114.         end
  115.         for i in 0..3
  116.           @savefile_windows[i].selected = false
  117.         end
  118.         @savefile_windows[@cursor_displace].selected = true
  119.         return
  120.       end
  121.     end
  122.   end
  123.   # -------------------
  124.   def make_filename(file_index)
  125.     return "Save#{file_index +1}.rxdata"
  126.   end
  127.   # -------------------
  128. end
  129.  
  130.  
  131.  
  132.  
  133. class Window_SaveFile < Window_Base
  134.   # -------------------
  135.   def initialize(file_index, filename, position)
  136.     y = 64 + position * 104
  137.     super(0, y, 640, 104)
  138.     self.contents = Bitmap.new(width - 32, height - 32)
  139.     @file_index = file_index
  140.     @filename = "Save#{@file_index +1}.rxdata"
  141.     @time_stamp = Time.at(0)
  142.     @file_exist = FileTest.exist?(@filename)
  143.     if @file_exist
  144.       file = File.open(@filename, "r")
  145.       @time_stamp = file.mtime
  146.       @characters = Marshal.load(file)
  147.       @frame_count = Marshal.load(file)
  148.       @game_system = Marshal.load(file)
  149.       @game_switches = Marshal.load(file)
  150.       @game_variables = Marshal.load(file)
  151.       @total_sec = @frame_count / Graphics.frame_rate
  152.       file.close
  153.     end
  154.     refresh
  155.     @selected = false
  156.   end
  157. end
  158.  
  159.  
  160. #==============================================================================
  161. # 本脚本来自[url]www.66RPG.com[/url],使用和转载请保留此信息
  162. #==============================================================================

最佳答案

查看完整内容

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

Lv5.捕梦者 (版主)

遠航の猫咪

梦石
3
星屑
22452
在线时间
2335 小时
注册时间
2005-10-15
帖子
1160

开拓者

2
发表于 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] 到本站一游。
回复

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
33188
在线时间
10490 小时
注册时间
2009-3-15
帖子
4756
3
发表于 2023-9-2 17:39:49 | 只看该作者
本帖最后由 soulsaga 于 2023-9-2 17:42 编辑

RUBY 代码复制
  1. #--------------------------------------------------------------------------
  2.   # ● 主处理
  3.   #--------------------------------------------------------------------------
  4.   def main
  5.     # 生成帮助窗口
  6.     @help_window = Window_Help.new
  7.     @help_window.width = 480
  8.     @help_window.contents = Bitmap.new(@help_window.width-32, @help_window.height-32)
  9.     @help_window.set_text(@help_text)
  10.     @savepage_window = Window_SavePage.new
  11.     #@savepage_window.opacity=0
  12.     @savepage_window.set_text(PagesText[0])
  13.     @file_index = $game_temp.last_file_index
  14.     # 生成存档文件窗口
  15.     @savefile_windows = []
  16.     # 选择最后操作的文件
  17.     for i in @file_index / 4 * 4..@file_index / 4 * 4 + 3
  18.       load_window(i)
  19.       @savefile_windows[i].visible = true
  20.     end
  21.     @savefile_windows[@file_index].selected = true
  22.     # 执行过渡
  23.     Graphics.transition
  24.     # 主循环
  25.     loop do
  26.       # 刷新游戏画面
  27.       Graphics.update
  28.       # 刷新输入信息
  29.       Input.update
  30.       # 刷新画面
  31.       update
  32.       # 如果画面被切换的话就中断循环
  33.       if $scene != self
  34.         break
  35.       end
  36.     end
  37.  
  38.     # 准备过渡
  39.     Graphics.freeze
  40.     # 释放窗口
  41.     @help_window.dispose
  42.     @savepage_window.dispose
  43.     for i in 0...@slots
  44.       @savefile_windows[i].dispose if @savefile_windows[i] != nil
  45.     end
  46.   end


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

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1264
在线时间
301 小时
注册时间
2023-6-6
帖子
22
4
 楼主| 发表于 2023-9-2 18:53:45 | 只看该作者
soulsaga 发表于 2023-9-2 17:39
#--------------------------------------------------------------------------
  # ● 主处理
  #------- ...

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

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
7964
在线时间
744 小时
注册时间
2018-11-3
帖子
8
5
发表于 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 塞糖

查看全部评分

回复

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1264
在线时间
301 小时
注册时间
2023-6-6
帖子
22
6
 楼主| 发表于 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號  這個樣子

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

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1264
在线时间
301 小时
注册时间
2023-6-6
帖子
22
7
 楼主| 发表于 2023-9-4 21:33:19 | 只看该作者
SailCat 发表于 2023-9-4 20:58
你的这个插件版本过老了
https://rpg.blue/thread-403346-1-1.html

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

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

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

謝謝你們
回复

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
7964
在线时间
744 小时
注册时间
2018-11-3
帖子
8
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 我很赞同

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-28 14:02

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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