Project1

标题: 想请教关于存档页面 [打印本页]

作者: timmyyayaya    时间: 2011-9-11 00:18
标题: 想请教关于存档页面
在下想请教关于存档页面的选择方式,
通常一个页面会显示4个档案(01、02、03、04),
当我们选到04按「下」,
看到页面会是02、03、04、05,

请问该如何固定一个页面就是4个档案,
在04按下的时候,页面呈现05、06、07、08。
dsu_plus_rewardpost_czw
作者: 雁北羽    时间: 2011-9-11 07:06
写一个当选到某个档案号码时,再按下“下键”,就出现后面四个
作者: Wind2010    时间: 2011-9-11 08:48
LZ应该用了某增加存档的脚本吧?
作者: timmyyayaya    时间: 2011-9-11 14:35
本帖最后由 timmyyayaya 于 2011-9-11 14:41 编辑

是的,在下使用了其他的存盘脚本,不知该如何设置当选到某个档案按下时,跳出后面四个。
  1. timmyyayaya于2011-9-11 14:38补充以下内容:
  2. #==============================================================================
  3. # ■ Window_SaveFile
  4. #------------------------------------------------------------------------------
  5. #==============================================================================

  6. class Window_SaveFile < Window_Selectable  
  7.   
  8.   
  9. attr_reader :file_exist
  10.   #--------------------------------------------------------------------------
  11.   # ● 初始化物件
  12.   #--------------------------------------------------------------------------
  13.   def initialize(x, y, width, height)
  14.     super(x, y, width, height)
  15.     #super(260, 110, 360, 300)
  16.     cursorOffset(70)  # 游标大小70
  17.     @item_max = $SAVE_FILE_MAX_NUM
  18.     @column_max = 1     #只有两列
  19.     self.index = 0
  20.     #确认档案是否存在
  21.     @file_exist = []
  22.     for i in 0..($SAVE_FILE_MAX_NUM - 1)
  23.       filename = "Save#{i + 1}.rxdata"
  24.       file_exist_temp = FileTest.exist?(filename)
  25.       if file_exist_temp
  26.         @file_exist[i] = 1
  27.       else
  28.         @file_exist[i] = 0
  29.       end
  30.     end
  31.     @filename = []
  32.     @time_stamp = []
  33.     @characters = []
  34.     @frame_count = []
  35.     @game_system = []
  36.     @game_switches = []
  37.     @game_variables = []
  38.     @total_sec = []
  39.    
  40.      #打开档案读数据
  41.     for i in 0..($SAVE_FILE_MAX_NUM - 1)
  42.       @time_stamp[i] = Time.at(0)
  43.       if @file_exist[i] == 1
  44.         filename = "Save#{i + 1}.rxdata"
  45.         file = File.open(filename, "r")
  46.         @filename[i] = filename
  47.         @time_stamp[i] = file.mtime
  48.         @characters[i] = Marshal.load(file)
  49.         @frame_count[i] = Marshal.load(file)
  50.         @game_system[i] = Marshal.load(file)
  51.         @game_switches[i] = Marshal.load(file)
  52.         @game_variables[i] = Marshal.load(file)
  53.         @total_sec[i] = @frame_count[i] / Graphics.frame_rate
  54.         file.close
  55.       end
  56.     end
  57.     refresh
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   # ● 更新
  61.   #--------------------------------------------------------------------------
  62.   def refresh
  63.     if self.contents != nil
  64.       self.contents.dispose
  65.       self.contents = nil
  66.     end
  67.    # self.contents = Bitmap.new(width - 32, $SAVE_FILE_MAX_NUM * 72)
  68.     self.contents = Bitmap.new(width - 32, ($SAVE_FILE_MAX_NUM-1) * 75-32)
  69.     for i in 0..($SAVE_FILE_MAX_NUM - 1)
  70.       draw_item(i)
  71.     end
  72.   end
  73.   #--------------------------------------------------------------------------
  74.   # ● 描绘项目
  75.   #     index : 项目编号
  76.   #--------------------------------------------------------------------------
  77.   def draw_item(index)
  78.     x = 0
  79.     y = index * 70#75
  80.     rect = Rect.new(x, y, 200, 36)
  81.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  82.     self.contents.font.color = system_color

  83.     #描绘文件编号
  84.     if index + 1 < 10
  85.     name = "DATA 0#{index + 1}"
  86.     self.contents.draw_text(x, y, 80, 32, name)
  87.     else
  88.     name = "DATA #{index + 1}"
  89.     self.contents.draw_text(x, y, 80, 32, name)
  90.     end

  91.     if @file_exist[index] == 1
  92.       # 描绘角色
  93.       for i in 0...@characters[index].size
  94.         first_one_pos = 160
  95.         stand_distance = 32
  96.         height_of_ground = 22
  97.         bitmap = RPG::Cache.character(@characters[index][i][0], @characters[index][i][1])
  98.         cw = bitmap.rect.width / 4
  99.         ch = bitmap.rect.height / 4
  100.         src_rect = Rect.new(0, 0, cw, ch)
  101.         cx = first_one_pos - @characters[index].size * stand_distance + i * 32 - cw / 2
  102.         self.contents.blt(cx, y+height_of_ground, bitmap, src_rect)
  103.         #cw = bitmap.rect.width / 4
  104.         #h = bitmap.rect.height / 4
  105.         #rect = Rect.new(x + 60 + (cw * index), y + 36, cw, ch)
  106.         #cx = 300 - @characters[index].size * 32 + index * 64 - cw / 2
  107.         #self.contents.blt(cx, 68 - ch, bitmap, rect)
  108.       end
  109.       # 描绘游戏时间
  110.       hour = @total_sec[index] / 60 / 60
  111.       min = @total_sec[index] / 60 % 60
  112.       time_string = sprintf("%02d:%02d", hour,min)
  113.       
  114.       self.contents.draw_text(x+150, y + 22, 160, 32, time_string, 2)
  115.       # 描绘时间标记
  116.       time_string = @time_stamp[index].strftime("%Y/%m/%d %H:%M")
  117.       self.contents.draw_text(x+150, y + 44, 160, 32, time_string, 2)
  118.     end
  119.   end

  120.   def save_window_update
  121.     #update_cursor_rect
  122.     if Input.trigger?(Input::B)
  123.       # 演奏取消 SE
  124.       $game_system.se_play($data_system.cancel_se)
  125.       # 切换到选单画面
  126.       $scene = Scene_Menu.new(5)
  127.       return
  128.     end
  129.     # 按下C键的场合下
  130.     #if Input.trigger?(Input::C)
  131.       # 命令窗口光标位置分歧
  132.     #  case self.index
  133.     #  when 0  # 返回标题画面
  134.     #    command_to_title
  135.     #  when 1  # 退出
  136.     #    command_shutdown
  137.     #  end
  138.     #  return
  139.     #end
  140.   end
  141.   
  142.   def make_filename(file_index)
  143.     return "Save#{file_index + 1}.rxdata"
  144.   end

  145. end
复制代码

作者: 2578699    时间: 2011-9-11 16:10
86行,把
  1. if index + 1 < 10
复制代码
10改成5试试?
作者: timmyyayaya    时间: 2011-9-11 16:12
本帖最后由 timmyyayaya 于 2011-9-11 16:13 编辑
2578699 发表于 2011-9-11 16:10
86行,把10改成5试试?


那个是文件的编号名称…

作者: 后知后觉    时间: 2011-9-11 16:41
你贴的脚本只是其中的一部分吧
作者: timmyyayaya    时间: 2011-9-11 16:46
后知后觉 发表于 2011-9-11 16:41
你贴的脚本只是其中的一部分吧

因为用了很多脚本,听朋友说主要的问题可能是在这个脚本,不知是否能从这里找出些问题?
  1. class Window_Selectable < Window_Base
  2.   #以下是控制游標選取區域大小的腳本
  3.   #--------------------------------------------------------------------------
  4.   # ● 用來定義游標選取區域大小的函式
  5.   #--------------------------------------------------------------------------
  6.   def cursorOffset(cursorOffsetVar)
  7.      @cursorOffset = cursorOffsetVar
  8.    end

  9.   #--------------------------------------------------------------------------
  10.   # ● 取得行數
  11.   #--------------------------------------------------------------------------
  12.   def row_max
  13.     # 由項目數和列數計算出行數
  14.     return (@item_max + @column_max - 1) / @column_max
  15.   end
  16.   #--------------------------------------------------------------------------
  17.   # ● 取得開頭行
  18.   #--------------------------------------------------------------------------
  19.   def top_row
  20.     # 將視窗內容的傳送源 Y 座標、1 行的高 32 等分
  21.     return self.oy / @cursorOffset
  22.   end
  23.   #--------------------------------------------------------------------------
  24.   # ● 設定開頭行
  25.   #     row : 顯示開頭的行
  26.   #--------------------------------------------------------------------------
  27.   def top_row=(row)
  28.     # row 未滿 0 的場合更正為 0
  29.     if row < 0
  30.       row = 0
  31.     end
  32.     # row 超過 row_max - 1 的情況下更正為 row_max - 1
  33.     if row > row_max - 1
  34.       row = row_max - 1
  35.     end
  36.     # row 1 行高的 32 倍、視窗內容的傳送源 Y 座標
  37.     self.oy = row * @cursorOffset
  38.   end
  39.   #--------------------------------------------------------------------------
  40.   # ● 獲取 1 頁可以顯示的行數
  41.   #--------------------------------------------------------------------------
  42.   def page_row_max
  43.     # 視窗的高度,設定畫面的高度減去 32 ,除以 1 行的高度 32
  44.     return (self.height - @cursorOffset) / @cursorOffset
  45.   end
  46.   #--------------------------------------------------------------------------
  47.   # ● 獲取 1 頁可以顯示的項目數
  48.   #--------------------------------------------------------------------------
  49.   def page_item_max
  50.     # 將行數 page_row_max 乘上列數 @column_max
  51.     return page_row_max * @column_max
  52.   end
  53.   #--------------------------------------------------------------------------
  54.   # ● 更新游標矩形
  55.   #--------------------------------------------------------------------------
  56.   def update_cursor_rect
  57.     #定義游標矩形與左右兩側的距離
  58.     cursor_width_grid = 32
  59.     #Null Guard
  60.     if @cursorOffset == nil  
  61.        #沒有調用cursorOffset的,都幫他將上一個預設值
  62.       @cursorOffset = 32
  63.     end  
  64.     # 游標位置不滿 0 的情況下
  65.     if @index < 0
  66.       self.cursor_rect.empty
  67.       return
  68.     end
  69.     # 取得當前的行
  70.     row = @index / @column_max
  71.     # 當前行被顯示開頭行前面的情況下
  72.     if row < self.top_row
  73.       # 從當前行向開頭行捲動
  74.       self.top_row = row
  75.     end
  76.     # 當前行被顯示末尾行之後的情況下
  77.    # if row > self.top_row + (self.page_row_max-1)
  78.     if row > self.top_row + (self.page_row_max)
  79.       # 從當前行向末尾捲動
  80.     #   self.top_row = row - (self.page_row_max-1)
  81.       self.top_row = row - (self.page_row_max)
  82.     end
  83.     # 計算游標的寬度
  84.     #cursor_width = self.width / @column_max - @cursorOffset
  85.     cursor_width = self.width / @column_max - cursor_width_grid
  86.     # 計算游標座標
  87.     x = @index % @column_max * (cursor_width + @cursorOffset)
  88.     y = @index / @column_max * @cursorOffset - self.oy
  89.     # 更新游標矩形
  90.     self.cursor_rect.set(x, y, cursor_width, @cursorOffset)
  91.   end
  92. end
复制代码

作者: 后知后觉    时间: 2011-9-11 16:59
这是选项窗口的父类.也的确可以对这个类下手.
但是改了后.那所有的以这个类为父类的窗口就都被改了.
不过要改的地方也不在你放的这段脚本里. 是改  def update 里的内容
作者: Wind2010    时间: 2011-9-11 17:12
LZ有一个外来脚本是调用到Window_SaveFile的,请全局搜索找找
作者: timmyyayaya    时间: 2011-9-11 17:23
class Window_SaveFile < Window_Selectable  

def initialize(x, y, width, height)
  (中略)
end
作者: 后知后觉    时间: 2011-9-11 17:37
我这给你改了个Selectable 的  一改那全都改了.
  1. #==============================================================================
  2. # ■ Window_Selectable
  3. #==============================================================================

  4. class Window_Selectable < Window_Base
  5.   #--------------------------------------------------------------------------
  6.   # ● 刷新画面
  7.   #--------------------------------------------------------------------------
  8.   def update
  9.     super
  10.     # 可以移动光标的情况下
  11.     if self.active and @item_max > 0 and @index >= 0
  12.       # 方向键下被按下的情况下
  13.       if Input.repeat?(Input::DOWN)
  14.         # 列数不是 1 并且不与方向键下的按下状态重复的情况、
  15.         # 或光标位置在(项目数-列数)之前的情况下
  16.         if (@column_max == 1 and Input.trigger?(Input::DOWN)) or
  17.            @index < @item_max - @column_max
  18.           # 光标向下移动
  19.           $game_system.se_play($data_system.cursor_se)
  20.           down_page_row = self.top_row + self.page_row_max
  21.           @index = (@index + @column_max) % @item_max
  22.           row = @index / @column_max
  23.           if row == down_page_row
  24.             self.top_row = row
  25.           end
  26.         end
  27.       end
  28.       # 方向键上被按下的情况下
  29.       if Input.repeat?(Input::UP)
  30.         # 列数不是 1 并且不与方向键下的按下状态重复的情况、
  31.         # 或光标位置在列之后的情况下
  32.         if (@column_max == 1 and Input.trigger?(Input::UP)) or
  33.            @index >= @column_max
  34.           # 光标向上移动
  35.           $game_system.se_play($data_system.cursor_se)
  36.           up_page_row = self.top_row - 1
  37.           h_top_row = self.top_row
  38.           @index = (@index - @column_max + @item_max) % @item_max
  39.           row = @index / @column_max
  40.           if row == up_page_row
  41.             self.top_row = [h_top_row - self.page_row_max, 0].max
  42.           end
  43.         end
  44.       end
  45.       # 方向键右被按下的情况下
  46.       if Input.repeat?(Input::RIGHT)
  47.         # 列数为 2 以上并且、光标位置在(项目数 - 1)之前的情况下
  48.         if @column_max >= 2 and @index < @item_max - 1
  49.           # 光标向右移动
  50.           $game_system.se_play($data_system.cursor_se)
  51.           down_page_row = self.top_row + self.page_row_max
  52.           @index += 1
  53.           row = @index / @column_max
  54.           if row == down_page_row
  55.             self.top_row = row
  56.           end
  57.         end
  58.       end
  59.       # 方向键左被按下的情况下
  60.       if Input.repeat?(Input::LEFT)
  61.         # 列数为 2 以上并且、光标位置在 0 之后的情况下
  62.         if @column_max >= 2 and @index > 0
  63.           # 光标向左移动
  64.           $game_system.se_play($data_system.cursor_se)
  65.           up_page_row = self.top_row - 1
  66.           h_top_row = self.top_row
  67.           @index -= 1
  68.           row = @index / @column_max
  69.           if row == up_page_row
  70.             self.top_row = [h_top_row - self.page_row_max, 0].max
  71.           end
  72.         end
  73.       end
  74.       # R 键被按下的情况下
  75.       if Input.repeat?(Input::R)
  76.         # 显示的最后行在数据中最后行上方的情况下
  77.         if self.top_row + (self.page_row_max - 1) < (self.row_max - 1)
  78.           # 光标向后移动一页
  79.           $game_system.se_play($data_system.cursor_se)
  80.           @index = [@index + self.page_item_max, @item_max - 1].min
  81.           self.top_row += self.page_row_max
  82.         end
  83.       end
  84.       # L 键被按下的情况下
  85.       if Input.repeat?(Input::L)
  86.         # 显示的开头行在位置 0 之后的情况下
  87.         if self.top_row > 0
  88.           # 光标向前移动一页
  89.           $game_system.se_play($data_system.cursor_se)
  90.           @index = [@index - self.page_item_max, 0].max
  91.           self.top_row -= self.page_row_max
  92.         end
  93.       end
  94.     end
  95.     # 刷新帮助文本 (update_help 定义了继承目标)
  96.     if self.active and @help_window != nil
  97.       update_help
  98.     end
  99.     # 刷新光标矩形
  100.     update_cursor_rect
  101.   end
  102. end
复制代码

作者: timmyyayaya    时间: 2011-9-11 23:43
本帖最后由 timmyyayaya 于 2011-9-11 23:45 编辑
后知后觉 发表于 2011-9-11 17:37
我这给你改了个Selectable 的  一改那全都改了.


感谢版主热心回应

套用上去后,在要选到存盘04的时候就会跳到下一页,
显示04、05、06、07,
在存盘01使用PageDown会翻到下一页,
也是显示04、05、06、07,

请问要怎么调整才能选到04时,接着按「下」跳到下一页,
显示05、06、07、08呢@@”

作者: 后知后觉    时间: 2011-9-12 00:19
本帖最后由 后知后觉 于 2011-9-12 00:37 编辑

因为你 8 楼放的那段脚本的关系所以出现了你说的问题.
那段脚本把 @cursorOffset 这个东西加入了计算.
在计算 page_row_max 的时候 计算出来是 3  所以你从3到4就算作翻页了.
这个东西的意思是计算每一页可以显示多少行.
你可以尝试把 @cursorOffset 稍微改小一点点.让计算 page_row_max 的结果为 4 就可以了.
根据 8 楼给的
  def page_row_max
    # 視窗的高度,設定畫面的高度減去 32 ,除以 1 行的高度 32
    return (self.height - @cursorOffset) / @cursorOffset
  end
@cursorOffset 需要设置为窗口的 height 的 1/5 的时候计算出来才是每页 4 个

或者是在 Window_SaveFile 的定义里 重新定义一下这个东西的计算

  1. class Window_SaveFile  < Window_Selectable
  2.   def page_row_max
  3.     return 4
  4.   end
  5. end
复制代码
你给的脚本东一块西一块的.我懒得测试.大概就这样了.
作者: Wind2010    时间: 2011-9-12 08:52
本帖最后由 Wind2010 于 2011-9-12 08:58 编辑

存档读档画面的选项其实各是一个窗口,改Window_Selectable没用的吧- -
LZ当真确定没用过这个以外的外来脚本么,这个只是改了窗口而已


想起自己有过一个增加存档的脚本,情况和LZ的差不多。LZ的是这个脚本吗?
复制代码
↑好吧不是这个,已经删了


LZ请确定是不是用的什么配套脚本,因为有以下几个参数找不到:
  1. $SAVE_FILE_MAX_NUM
  2. cursorOffset
复制代码

作者: timmyyayaya    时间: 2011-9-12 11:47
Wind2010 发表于 2011-9-12 08:52
存档读档画面的选项其实各是一个窗口,改Window_Selectable没用的吧- -
LZ当真确定没用过这个以外的外来脚 ...

感谢六翼天使热心回复,
已经使用版主的方式解决问题了,
cursorOffset是重新定义光标大小,
如版主所说,他取的范围过大导致翻页计算错误。



timmyyayaya于2011-9-12 11:52补充以下内容:
感谢版主的热心解答,
在 Window_SaveFile 重新定义后翻页已经正常,
因为脚本是朋友写的,
他在写@cursorOffset的时候,
说主要影响的是Window_Selectable和Window_SaveFile,
在下不是很清楚该贴上哪些脚本,所以才只贴了那两块…
很抱歉贴的东一块西一块...:'(





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