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

Project1

 找回密码
 注册会员
搜索

窗口翻页问题

查看数: 2433 | 评论数: 4 | 收藏 0
关灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2014-8-4 17:11

正文摘要:

因为想做个图标物品栏,设置成每个框120*120的。结果发现翻页以后,光标位置和原来的不一样 在每行只有32像素高的时候,发现翻页是正常的。但是设置成每行120像素,就发现跳页,或者物品栏都不正常了。求指教要改哪 ...

回复

RyanBern 发表于 2014-8-4 19:40:04
出现翻页不正常的原因是Window_Selectable编写是按照一行高度32来算的,因此翻页计算光标都按照32来,有一定局限性。这个Window_Selectable可以实现任意高度的行高窗口。
使用的时候,你的Window_Item中的initialize其中有一句:
super(16, 48, 632, 392)要改成:
super(16, 48, 632, 392, 120),最后一个数表示行高是120。
  1. #==============================================================================
  2. # ■ Window_Selectable
  3. #------------------------------------------------------------------------------
  4. #  拥有光标的移动以及滚动功能的窗口类。
  5. #==============================================================================

  6. class Window_Selectable < Window_Base
  7.   #--------------------------------------------------------------------------
  8.   # ● 定义实例变量
  9.   #--------------------------------------------------------------------------
  10.   attr_reader   :index                    # 光标位置
  11.   attr_reader   :help_window              # 帮助窗口
  12.   attr_accessor :row_height               # 行高
  13.   #--------------------------------------------------------------------------
  14.   # ● 初始化对像
  15.   #     x      : 窗口的 X 坐标
  16.   #     y      : 窗口的 Y 坐标
  17.   #     width  : 窗口的宽
  18.   #     height : 窗口的高
  19.   #     row_height : 行高 默认是32
  20.   #--------------------------------------------------------------------------
  21.   def initialize(x, y, width, height, row_height=32)
  22.     super(x, y, width, height)
  23.     @item_max = 1
  24.     @column_max = 1
  25.     @index = -1
  26.     @row_height = row_height
  27.   end
  28.   #--------------------------------------------------------------------------
  29.   # ● 设置光标的位置
  30.   #     index : 新的光标位置
  31.   #--------------------------------------------------------------------------
  32.   def index=(index)
  33.     @index = index
  34.     # 刷新帮助文本 (update_help 定义了继承目标)
  35.     if self.active and @help_window != nil
  36.       update_help
  37.     end
  38.     # 刷新光标矩形
  39.     update_cursor_rect
  40.   end
  41.   #--------------------------------------------------------------------------
  42.   # ● 获取行数
  43.   #--------------------------------------------------------------------------
  44.   def row_max
  45.     # 由项目数和列数计算出行数
  46.     return (@item_max + @column_max - 1) / @column_max
  47.   end
  48.   #--------------------------------------------------------------------------
  49.   # ● 获取开头行
  50.   #--------------------------------------------------------------------------
  51.   def top_row
  52.     # 将窗口内容的传送源 Y 坐标、1 行的高 @row_height 等分
  53.     return self.oy / @row_height
  54.   end
  55.   #--------------------------------------------------------------------------
  56.   # ● 设置开头行
  57.   #     row : 显示开头的行
  58.   #--------------------------------------------------------------------------
  59.   def top_row=(row)
  60.     # row 未满 0 的场合更正为 0
  61.     if row < 0
  62.       row = 0
  63.     end
  64.     # row 超过 row_max - 1 的情况下更正为 row_max - 1
  65.     if row > row_max - 1
  66.       row = row_max - 1
  67.     end
  68.     # row 1 行高的 @row_height 倍、窗口内容的传送源 Y 坐标
  69.     self.oy = row * @row_height
  70.   end
  71.   #--------------------------------------------------------------------------
  72.   # ● 获取 1 页可以显示的行数
  73.   #--------------------------------------------------------------------------
  74.   def page_row_max
  75.     # 窗口的高度,设置画面的高度减去 32 ,除以 1 行的高度 row_height
  76.     return (self.height - 32) / @row_height
  77.   end
  78.   #--------------------------------------------------------------------------
  79.   # ● 获取 1 页可以显示的项目数
  80.   #--------------------------------------------------------------------------
  81.   def page_item_max
  82.     # 将行数 page_row_max 乘上列数 @column_max
  83.     return page_row_max * @column_max
  84.   end
  85.   #--------------------------------------------------------------------------
  86.   # ● 帮助窗口的设置
  87.   #     help_window : 新的帮助窗口
  88.   #--------------------------------------------------------------------------
  89.   def help_window=(help_window)
  90.     @help_window = help_window
  91.     # 刷新帮助文本 (update_help 定义了继承目标)
  92.     if self.active and @help_window != nil
  93.       update_help
  94.     end
  95.   end
  96.   #--------------------------------------------------------------------------
  97.   # ● 更新光标举行
  98.   #--------------------------------------------------------------------------
  99.   def update_cursor_rect
  100.     # 光标位置不满 0 的情况下
  101.     if @index < 0
  102.       self.cursor_rect.empty
  103.       return
  104.     end
  105.     # 获取当前的行
  106.     row = @index / @column_max
  107.     # 当前行被显示开头行前面的情况下
  108.     if row < self.top_row
  109.       # 从当前行向开头行滚动
  110.       self.top_row = row
  111.     end
  112.     # 当前行被显示末尾行之后的情况下
  113.     if row > self.top_row + (self.page_row_max - 1)
  114.       # 从当前行向末尾滚动
  115.       self.top_row = row - (self.page_row_max - 1)
  116.     end
  117.     # 计算光标的宽
  118.     cursor_width = self.width / @column_max - 32
  119.     # 计算光标坐标
  120.     x = @index % @column_max * (cursor_width + 32)
  121.     y = @index / @column_max * @row_height - self.oy
  122.     # 更新光标矩形
  123.     self.cursor_rect.set(x, y, cursor_width, @row_height)
  124.   end
  125.   #--------------------------------------------------------------------------
  126.   # ● 刷新画面
  127.   #--------------------------------------------------------------------------
  128.   def update
  129.     super
  130.     # 可以移动光标的情况下
  131.     if self.active and @item_max > 0 and @index >= 0
  132.       # 方向键下被按下的情况下
  133.       if Input.repeat?(Input::DOWN)
  134.         # 列数不是 1 并且方向键的下的按下状态不是重复的情况、
  135.         # 或光标位置在(项目数-列数)之前的情况下
  136.         if (@column_max == 1 and Input.trigger?(Input::DOWN)) or
  137.            @index < @item_max - @column_max
  138.           # 光标向下移动
  139.           $game_system.se_play($data_system.cursor_se)
  140.           @index = (@index + @column_max) % @item_max
  141.         end
  142.       end
  143.       # 方向键上被按下的情况下
  144.       if Input.repeat?(Input::UP)
  145.         # 列数不是 1 并且方向键的下的按下状态不是重复的情况、
  146.         # 或光标位置在列之后的情况下
  147.         if (@column_max == 1 and Input.trigger?(Input::UP)) or
  148.            @index >= @column_max
  149.           # 光标向上移动
  150.           $game_system.se_play($data_system.cursor_se)
  151.           @index = (@index - @column_max + @item_max) % @item_max
  152.         end
  153.       end
  154.       # 方向键右被按下的情况下
  155.       if Input.repeat?(Input::RIGHT)
  156.         # 列数为 2 以上并且、光标位置在(项目数 - 1)之前的情况下
  157.         if @column_max >= 2 and @index < @item_max - 1
  158.           # 光标向右移动
  159.           $game_system.se_play($data_system.cursor_se)
  160.           @index += 1
  161.         end
  162.       end
  163.       # 方向键左被按下的情况下
  164.       if Input.repeat?(Input::LEFT)
  165.         # 列数为 2 以上并且、光标位置在 0 之后的情况下
  166.         if @column_max >= 2 and @index > 0
  167.           # 光标向左移动
  168.           $game_system.se_play($data_system.cursor_se)
  169.           @index -= 1
  170.         end
  171.       end
  172.       # R 键被按下的情况下
  173.       if Input.repeat?(Input::R)
  174.         # 显示的最后行在数据中最后行上方的情况下
  175.         if self.top_row + (self.page_row_max - 1) < (self.row_max - 1)
  176.           # 光标向后移动一页
  177.           $game_system.se_play($data_system.cursor_se)
  178.           @index = [@index + self.page_item_max, @item_max - 1].min
  179.           self.top_row += self.page_row_max
  180.         end
  181.       end
  182.       # L 键被按下的情况下
  183.       if Input.repeat?(Input::L)
  184.         # 显示的开头行在位置 0 之后的情况下
  185.         if self.top_row > 0
  186.           # 光标向前移动一页
  187.           $game_system.se_play($data_system.cursor_se)
  188.           @index = [@index - self.page_item_max, 0].max
  189.           self.top_row -= self.page_row_max
  190.         end
  191.       end
  192.     end
  193.     # 刷新帮助文本 (update_help 定义了继承目标)
  194.     if self.active and @help_window != nil
  195.       update_help
  196.     end
  197.     # 刷新光标矩形
  198.     update_cursor_rect
  199.   end
  200. end
复制代码
冰水金刚 发表于 2014-8-4 17:24:26
光标位置不一样
在更新光标矩形处调整光标坐标

点评

原来如此啊,第一次看的时候把他和大耳兽搞混了……话说他俩的耳朵可真大啊,⊙﹏⊙b汗……  发表于 2014-8-6 15:23
古乐兽啊,第六部我找不到国语版的所以没看,我只看到第五部  发表于 2014-8-5 10:51
额,这个我也试过,最后是一个伙伴两个光标…… (话说楼主的头像是小纯洁么?本楼的头像是萌呆的数码宝贝3的那个啥?{我都看到第6部了})  发表于 2014-8-4 21:59
看4楼,我调整过光标坐标了,脚本也提过  发表于 2014-8-4 17:25
zxc3824 发表于 2014-8-4 17:17:05
@怪蜀黍
p叔速速来救场啊{:2_279:}
拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

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

GMT+8, 2025-2-16 19:59

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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