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

Project1

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

[已经过期] 窗口翻页问题

[复制链接]

Lv2.观梦者

梦石
0
星屑
538
在线时间
254 小时
注册时间
2010-8-25
帖子
371
跳转到指定楼层
1
发表于 2014-8-4 17:11:09 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
因为想做个图标物品栏,设置成每个框120*120的。结果发现翻页以后,光标位置和原来的不一样

在每行只有32像素高的时候,发现翻页是正常的。但是设置成每行120像素,就发现跳页,或者物品栏都不正常了。求指教要改哪里


RUBY 代码复制
  1. #==============================================================================
  2. # ■ Window_Item
  3. #------------------------------------------------------------------------------
  4. #  物品画面、战斗画面、显示浏览物品的窗口。
  5. #==============================================================================
  6.  
  7. class Window_Item < Window_Selectable
  8.   #--------------------------------------------------------------------------
  9.   # ● 初始化对像
  10.   #--------------------------------------------------------------------------
  11.   def initialize
  12.     super(16, 48, 632, 392)
  13.     @column_max = 5
  14.     refresh
  15.     self.index = 0
  16.     # 战斗中的情况下将窗口移至中央并将其半透明化
  17.     if $game_temp.in_battle
  18.       self.y = 64
  19.       self.height = 256
  20.       self.back_opacity = 160
  21.     end
  22.   end
  23.   #--------------------------------------------------------------------------
  24.   # ● 获取物品
  25.   #--------------------------------------------------------------------------
  26.   def item
  27.     return @data[self.index]
  28.   end
  29.   #--------------------------------------------------------------------------
  30.   # ● 刷新
  31.   #--------------------------------------------------------------------------
  32.   def refresh
  33.     if self.contents != nil
  34.       self.contents.dispose
  35.       self.contents = nil
  36.     end
  37.     @data = []
  38.     # 添加报务
  39.     for i in 1...$data_items.size
  40.       if $game_party.item_number(i) > 0
  41.         @data.push($data_items[i])
  42.       end
  43.     end
  44.     # 在战斗中以外添加武器、防具
  45.     unless $game_temp.in_battle
  46.       for i in 1...$data_weapons.size
  47.         if $game_party.weapon_number(i) > 0
  48.           @data.push($data_weapons[i])
  49.         end
  50.       end
  51.       for i in 1...$data_armors.size
  52.         if $game_party.armor_number(i) > 0
  53.           @data.push($data_armors[i])
  54.         end
  55.       end
  56.     end
  57.     # 如果项目数不是 0 就生成位图、重新描绘全部项目
  58.     @item_max = @data.size
  59.     if @item_max > 0
  60.       self.contents = Bitmap.new(width - 32, row_max * 120)
  61.       for i in 0...@item_max
  62.         draw_item(i)
  63.       end
  64.     end
  65.   end
  66.   #--------------------------------------------------------------------------
  67.   # ● 描绘项目
  68.   #     index : 项目编号
  69.   #--------------------------------------------------------------------------
  70.   def draw_item(index)
  71.     item = @data[index]
  72.     case item
  73.     when RPG::Item
  74.       number = $game_party.item_number(item.id)
  75.     when RPG::Weapon
  76.       number = $game_party.weapon_number(item.id)
  77.     when RPG::Armor
  78.       number = $game_party.armor_number(item.id)
  79.     end
  80.     if item.is_a?(RPG::Item) and
  81.        $game_party.item_can_use?(item.id)
  82.       self.contents.font.color = normal_color
  83.     else
  84.       self.contents.font.color = disabled_color
  85.     end
  86.     x = index % @column_max * (88 + 32)
  87.     y = index / @column_max * 120
  88.     rect = Rect.new(x, y, self.width / @column_max - 32, 120)
  89.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  90.     bitmap = RPG::Cache.icon(item.icon_name)
  91.     opacity = self.contents.font.color == normal_color ? 255 : 128
  92.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 120, 120), opacity)
  93.     self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  94.     self.contents.draw_text(x + 240, y, 16, 32, ":", 1)
  95.     self.contents.draw_text(x + 256, y, 24, 32, number.to_s, 2)
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # ● 刷新帮助文本
  99.   #--------------------------------------------------------------------------
  100.   def update_help
  101.     @help_window.set_text(self.item == nil ? "" : self.item.description)
  102.   end
  103.  
  104.   #--------------------------------------------------------------------------
  105.   # ● 获取开头行
  106.   #--------------------------------------------------------------------------
  107.   def top_row
  108.     # 将窗口内容的传送源 Y 坐标、1 行的高 32 等分
  109.     return self.oy / 120
  110.   end
  111.   #--------------------------------------------------------------------------
  112.   # ● 设置开头行
  113.   #     row : 显示开头的行
  114.   #--------------------------------------------------------------------------
  115.   def top_row=(row)
  116.     # row 未满 0 的场合更正为 0
  117.     if row < 0
  118.       row = 0
  119.     end
  120.     # row 超过 row_max - 1 的情况下更正为 row_max - 1
  121.     if row > row_max - 1
  122.       row = row_max - 1
  123.     end
  124.     # row 1 行高的 32 倍、窗口内容的传送源 Y 坐标
  125.     self.oy = row * 120
  126.   end
  127.   #--------------------------------------------------------------------------
  128.   # ● 获取 1 页可以显示的行数
  129.   #--------------------------------------------------------------------------
  130.   def page_row_max
  131.     # 窗口的高度,设置画面的高度减去 32 ,除以 1 行的高度 32
  132.     return (self.height - 32) / 120
  133.   end
  134.  
  135.   #--------------------------------------------------------------------------
  136.   # ● 更新光标举行
  137.   #--------------------------------------------------------------------------
  138.   def update_cursor_rect
  139.     # 光标位置不满 0 的情况下
  140.     if @index < 0
  141.       self.cursor_rect.empty
  142.       return
  143.     end
  144.     # 获取当前的行
  145.     row = @index / @column_max
  146.     # 当前行被显示开头行前面的情况下
  147.     if row < self.top_row
  148.       # 从当前行向开头行滚动
  149.       self.top_row = row
  150.     end
  151.     # 当前行被显示末尾行之后的情况下
  152.     if row > self.top_row + (self.page_row_max - 1)
  153.       # 从当前行向末尾滚动
  154.       self.top_row = row - (self.page_row_max - 1)
  155.     end
  156.     # 计算光标的宽
  157.     cursor_width = 120#self.width / @column_max - 32
  158.     # 计算光标坐标
  159.     x = @index % @column_max * 120
  160.     y = @index / @column_max * 120
  161.     # 更新国标矩形
  162.     self.cursor_rect.set(x, y, cursor_width, 120)
  163.   end
  164. end

Lv2.观梦者

梦石
0
星屑
538
在线时间
254 小时
注册时间
2010-8-25
帖子
371
2
 楼主| 发表于 2014-8-4 17:17:05 | 只看该作者
@怪蜀黍
p叔速速来救场啊{:2_279:}
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
165
在线时间
809 小时
注册时间
2013-8-23
帖子
804

开拓者

3
发表于 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
遗失的签名。。。
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
538
在线时间
254 小时
注册时间
2010-8-25
帖子
371
4
 楼主| 发表于 2014-8-4 17:25:19 | 只看该作者
补上一张图,这是使用了脚本以后,如果物品栏超过15个物品就会出现这种情况,光标对应不上
回复 支持 反对

使用道具 举报

Lv4.逐梦者 (版主)

梦石
0
星屑
9497
在线时间
5073 小时
注册时间
2013-6-21
帖子
3580

开拓者贵宾剧作品鉴家

5
发表于 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
复制代码
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-5-6 04:56

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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