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

Project1

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

[已经解决] 请求解决商店菜单翻页问题。

[复制链接]

Lv4.逐梦者 (版主)

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

开拓者贵宾剧作品鉴家

1
发表于 2013-9-21 15:55:30 | 显示全部楼层
楼主想要的结果已经改完。
下面是代码,楼主更改失败的原因是Window_Selectable中默认一行的高度是32,而楼主并未作出更改。
另外你那个$item_max应该是你自定义的Hash,应该是限制各种物品最大拥有数的,在前面已经定义过但是在这里没有给出。
  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.     [url=home.php?mod=space&uid=370741]@Index[/url] = -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 行高的 32 倍、窗口内容的传送源 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

  201. #==============================================================================
  202. # ■ Window_ShopBuy
  203. #------------------------------------------------------------------------------
  204. #  商店画面、浏览显示可以购买的商品的窗口。
  205. #==============================================================================

  206. class Window_ShopBuy < Window_Selectable
  207.   #--------------------------------------------------------------------------
  208.   # ● 初始化对像
  209.   #     shop_goods : 商品
  210.   #--------------------------------------------------------------------------
  211.   def initialize(shop_goods)
  212.     super(0, 128, 368, 352, 64)
  213.     @shop_goods = shop_goods
  214.     @column_max = 5
  215.     refresh
  216.     self.index = 0
  217.   end
  218.   #--------------------------------------------------------------------------
  219.   # ● 获取物品
  220.   #--------------------------------------------------------------------------
  221.   def item     
  222.     return @data[self.index]
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # ● 刷新
  226.   #--------------------------------------------------------------------------
  227.   def refresh
  228.     if self.contents != nil
  229.       self.contents.dispose
  230.       self.contents = nil
  231.     end
  232.     @data = []
  233.     for goods_item in @shop_goods
  234.       case goods_item[0]
  235.       when 0
  236.         item = $data_items[goods_item[1]]
  237.       when 1
  238.         item = $data_weapons[goods_item[1]]
  239.       when 2
  240.         item = $data_armors[goods_item[1]]
  241.       end
  242.       if item != nil
  243.         @data.push(item)
  244.       end
  245.     end     
  246.     # 如果项目数不是 0 就生成位图、描绘全部项目
  247.     @item_max = @data.size
  248.     if @item_max > 0
  249.       self.contents = Bitmap.new(width - 32, row_max * 64)
  250.       for i in 0...@item_max
  251.         draw_item(i)
  252.       end
  253.     end
  254.   end
  255.   #--------------------------------------------------------------------------
  256.   # ● 描绘羡慕
  257.   #     index : 项目编号
  258.   #--------------------------------------------------------------------------
  259.   def draw_item(index)
  260.     item = @data[index]   
  261.     # 获取物品所持数
  262.     case item
  263.     when RPG::Item
  264.       number = $game_party.item_number(item.id)
  265.       item_max = $item_max[@item.id] if $item_max[@item.id] != nil      
  266.     when RPG::Weapon
  267.       number = $game_party.weapon_number(item.id)
  268.       item_max = $item_max[@item.id] if $item_max[@item.id] != nil
  269.     when RPG::Armor
  270.       number = $game_party.armor_number(item.id)
  271.       item_max = $item_max[@item.id] if $item_max[@item.id] != nil
  272.     end
  273.     # 价格在所持金以下、并且所持数不是 99 的情况下为普通文字颜色
  274.     # 除此之外的情况设置为无效文字色
  275.     if item.price <= $game_party.gold and number < item_max
  276.       self.contents.font.color = normal_color
  277.     else
  278.       self.contents.font.color = disabled_color
  279.     end
  280.     x = (index % 5) * 73
  281.     y = (index / 5) * 64
  282.     bitmap = RPG::Cache.icon(item.icon_name)
  283.     opacity = self.contents.font.color == normal_color ? 255 : 128
  284.     self.contents.font.size = 18
  285.     self.contents.blt(x + 10, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  286.     #self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)  
  287.     self.contents.draw_text(x - 56, y + 32, 96, 24,  item.price.to_s, 2)
  288.   end
  289.   #--------------------------------------------------------------------------
  290.   # ● 刷新帮助文本
  291.   #--------------------------------------------------------------------------
  292.   def update_help
  293.     @help_window.set_text(self.item == nil ? "" : self.item.description)
  294.   end
  295. end
复制代码
不知楼主是否满意呢?

点评

请容我测试一下  发表于 2013-9-22 14:05

评分

参与人数 1星屑 +120 收起 理由
myownroc + 120 认可答案

查看全部评分

回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-5-12 10:01

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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