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

Project1

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

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

[复制链接]

Lv1.梦旅人

梦石
0
星屑
46
在线时间
1502 小时
注册时间
2010-8-27
帖子
392
跳转到指定楼层
1
发表于 2013-9-21 15:55:29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
2星屑
本帖最后由 存档不能 于 2013-9-21 18:50 编辑

  1. #==============================================================================
  2. # ■ Window_ShopBuy
  3. #------------------------------------------------------------------------------
  4. #  商店画面、浏览显示可以购买的商品的窗口。
  5. #==============================================================================

  6. class Window_ShopBuy < Window_Selectable
  7.   #--------------------------------------------------------------------------
  8.   # ● 初始化对像
  9.   #     shop_goods : 商品
  10.   #--------------------------------------------------------------------------
  11.   def initialize(shop_goods)
  12.     super(40, 128, 358, 272)
  13.     @shop_goods = shop_goods  
  14.     @column_max = 5
  15.     refresh
  16.     self.index = 0
  17.   end
  18.   #--------------------------------------------------------------------------
  19.   # ● 获取物品
  20.   #--------------------------------------------------------------------------
  21.   def item     
  22.     return @data[self.index]
  23.   end
  24.   #--------------------------------------------------------------------------
  25.   # ● 刷新
  26.   #--------------------------------------------------------------------------
  27.   def refresh
  28.     if self.contents != nil
  29.       self.contents.dispose
  30.       self.contents = nil
  31.     end
  32.     @data = []
  33.     for goods_item in @shop_goods
  34.       case goods_item[0]
  35.       when 0
  36.         item = $data_items[goods_item[1]]
  37.       when 1
  38.         item = $data_weapons[goods_item[1]]
  39.       when 2
  40.         item = $data_armors[goods_item[1]]
  41.       end
  42.       if item != nil
  43.         @data.push(item)
  44.       end
  45.     end     
  46.     # 如果项目数不是 0 就生成位图、描绘全部项目
  47.     @item_max = @data.size
  48.     if @item_max > 0
  49.       self.contents = Bitmap.new(width - 32, row_max * 47)
  50.       for i in 0...@item_max
  51.         draw_item(i)
  52.       end
  53.     end
  54.   end
  55.   #--------------------------------------------------------------------------
  56.   # ● 描绘羡慕
  57.   #     index : 项目编号
  58.   #--------------------------------------------------------------------------
  59.   def draw_item(index)
  60.     item = @data[index]   
  61.     # 获取物品所持数
  62.     case item
  63.     when RPG::Item
  64.       number = $game_party.item_number(item.id)
  65.       item_max = $item_max[@item.id] if $item_max[@item.id] != nil      
  66.     when RPG::Weapon
  67.       number = $game_party.weapon_number(item.id)
  68.       item_max = $item_max[@item.id] if $item_max[@item.id] != nil
  69.     when RPG::Armor
  70.       number = $game_party.armor_number(item.id)
  71.       item_max = $item_max[@item.id] if $item_max[@item.id] != nil
  72.     end
  73.     # 价格在所持金以下、并且所持数不是 99 的情况下为普通文字颜色
  74.     # 除此之外的情况设置为无效文字色
  75.     if item.price <= $game_party.gold and number < item_max
  76.       self.contents.font.color = normal_color
  77.     else
  78.       self.contents.font.color = disabled_color
  79.     end
  80.     x = (index % 5) * 57
  81.     y = ((index/5))*47
  82.     rect = Rect.new(x-20, y, self.width - 32, 32)
  83.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  84.     bitmap = RPG::Cache.icon(item.icon_name)
  85.     opacity = self.contents.font.color == normal_color ? 255 : 128
  86.     self.contents.font.size = 16
  87.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  88.     #self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)  
  89.     self.contents.draw_text(x-58, y + 22, 88, 32,  item.price.to_s, 2)
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # ● 刷新帮助文本
  93.   #--------------------------------------------------------------------------
  94.   def update_help
  95.     @help_window.set_text(self.item == nil ? "" : self.item.description,1,self.item == nil ? 0 : self.item.xhp)
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # ● 刷新光标矩形
  99.   #--------------------------------------------------------------------------
  100.    def update_cursor_rect
  101.     if [url=home.php?mod=space&uid=370741]@Index[/url] < 0
  102.       self.cursor_rect.empty
  103.     else
  104.       self.cursor_rect.set((index % 5) * 55 , ((index/5)) * 47, 40, 30)
  105.     end
  106.   end
  107. end
复制代码
我改了商店的购买物品的排列,改为5列4行、最多显示20个的模式,但是光标在最下面(即指向第二十个物品)时不会自动翻页,反而继续向下一行(但是画面没显示出该行)移动
希望能增加翻页功能,并且保持上下左右键都能移动光标 ,最重要的是上面脚本中的物品图标和价格的位置不能变

最佳答案

查看完整内容

楼主想要的结果已经改完。 下面是代码,楼主更改失败的原因是Window_Selectable中默认一行的高度是32,而楼主并未作出更改。 另外你那个$item_max应该是你自定义的Hash,应该是限制各种物品最大拥有数的,在前面已经定义过但是在这里没有给出。不知楼主是否满意呢?

点评

物品名没有了  发表于 2013-9-21 21:10
不明白你想要什么效果  发表于 2013-9-21 21:07
已编辑  发表于 2013-9-21 19:11
没看到4行,现在调整好了,其实就是调整窗口的大小  发表于 2013-9-21 16:37

Lv4.逐梦者 (版主)

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

开拓者贵宾剧作品鉴家

2
发表于 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 认可答案

查看全部评分

回复

使用道具 举报

Lv1.梦旅人

薄凉看客

梦石
0
星屑
50
在线时间
1269 小时
注册时间
2010-6-20
帖子
1316
3
发表于 2013-9-21 16:30:11 | 只看该作者
本帖最后由 恋′挂机 于 2013-9-21 21:10 编辑
  1. #==============================================================================
  2. # ■ Window_ShopBuy
  3. #------------------------------------------------------------------------------
  4. #  商店画面、浏览显示可以购买的商品的窗口。
  5. #==============================================================================

  6. class Window_ShopBuy < Window_Selectable
  7.   #请看65行脚本
  8.   #--------------------------------------------------------------------------
  9.   # ● 初始化对像
  10.   #     shop_goods : 商品
  11.   #--------------------------------------------------------------------------
  12.   def initialize(shop_goods)
  13.     #都五列了当然要把宽调大点,你说的翻页其实只要调小高度就可以了
  14.     super(0, 128, 368, 32 * 4 + 32)#X坐标、Y坐标、宽度、高度
  15.     self.z = 123
  16.     @column_max = 1#列数,直接改这里,1也不能省略
  17.     @shop_goods = shop_goods
  18.     refresh
  19.     self.index = 0
  20.   end
  21.   #--------------------------------------------------------------------------
  22.   # ● 获取物品
  23.   #--------------------------------------------------------------------------
  24.   def item
  25.     return @data[self.index]
  26.   end
  27.   #--------------------------------------------------------------------------
  28.   # ● 刷新
  29.   #--------------------------------------------------------------------------
  30.   def refresh
  31.     if self.contents != nil
  32.       self.contents.dispose
  33.       self.contents = nil
  34.     end
  35.     @data = []
  36.     for goods_item in @shop_goods
  37.       case goods_item[0]
  38.       when 0
  39.         item = $data_items[goods_item[1]]
  40.       when 1
  41.         item = $data_weapons[goods_item[1]]
  42.       when 2
  43.         item = $data_armors[goods_item[1]]
  44.       end
  45.       if item != nil
  46.         @data.push(item)
  47.       end
  48.     end
  49.     # 如果项目数不是 0 就生成位图、描绘全部项目
  50.     @item_max = @data.size
  51.     if @item_max > 0
  52.       self.contents = Bitmap.new(width - 32, row_max * 32)
  53.       for i in 0...@item_max
  54.         draw_item(i)
  55.       end
  56.     end
  57.   end
  58.   #--------------------------------------------------------------------------
  59.   # ● 描绘项目
  60.   #     index : 项目编号
  61.   #--------------------------------------------------------------------------
  62.   def draw_item(index)
  63.   ###################################################
  64.   icon_x = 0#图标的X坐标附加值,向右为正,向左为负
  65.   icon_y = 0#图标的Y坐标附加值,向下为正,向上为负
  66.   #name_x = 0#物品名的X坐标附加值,向右为正,向左为负
  67.   #name_y = 0#物品名的Y坐标附加值,向下为正,向上为负
  68.   price_x = 0#物品价格的X坐标附加值,向右为正,向左为负
  69.   price_y = 0#物品价格的Y坐标附加值,向下为正,向上为负
  70.   ##################################################
  71.     item = @data[index]
  72.     # 获取物品所持数
  73.     case item
  74.     when RPG::Item
  75.       number = $game_party.item_number(item.id)
  76.     when RPG::Weapon
  77.       number = $game_party.weapon_number(item.id)
  78.     when RPG::Armor
  79.       number = $game_party.armor_number(item.id)
  80.     end
  81.     # 价格在所持金以下、并且所持数不是 99 的情况下为普通文字颜色
  82.     # 除此之外的情况设置为无效文字色
  83.     if item.price <= $game_party.gold and number < 99
  84.       self.contents.font.color = normal_color
  85.     else
  86.       self.contents.font.color = disabled_color
  87.     end
  88.     #################################
  89.     x = 4 + index % @column_max * (95 + 32)
  90.     y = index / @column_max * 32
  91.     self.contents.font.size = 15#字体大小
  92.     #################################
  93.     rect = Rect.new(x, y, self.width - 32, 32)
  94.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  95.     bitmap = RPG::Cache.icon(item.icon_name)
  96.     opacity = self.contents.font.color == normal_color ? 255 : 128
  97.     self.contents.blt(x + icon_x, y + 4 + icon_y, bitmap, Rect.new(0, 0, 24, 24), opacity)
  98.     #self.contents.draw_text(x + 28 + name_x, y + name_y, 212, 32, item.name, 0)
  99.     self.contents.draw_text(x + 240 + price_x, y + price_y, 88, 32, item.price.to_s, 2)
  100.   end
  101.   #--------------------------------------------------------------------------
  102.   # ● 刷新帮助文本
  103.   #--------------------------------------------------------------------------
  104.   def update_help
  105.     @help_window.set_text(self.item == nil ? "" : self.item.description)
  106.   end
  107. end
复制代码

点评

我的意思是,原脚本中各项的位置不能变,你已经完全打乱了位置,上面改的那些都不是要点。  发表于 2013-9-21 21:26
你这个……跟上一个不是一样吗?光是改图标和价格的位置是没用的,你自己测试一下就知道了。  发表于 2013-9-21 21:05
如果这个要求不行的话也没关系,主要的问题还是图标和价格的位置,物品名不要。  发表于 2013-9-21 18:54
坐标  发表于 2013-9-21 18:53
另外如果可以的话,能不能让改窗口的x和y左边都是0呢?  发表于 2013-9-21 18:52
回复

使用道具 举报

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

本版积分规则

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

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

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

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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