Project1
标题:
请求解决商店菜单翻页问题。
[打印本页]
作者:
存档不能
时间:
2013-9-21 15:55
标题:
请求解决商店菜单翻页问题。
本帖最后由 存档不能 于 2013-9-21 18:50 编辑
#==============================================================================
# ■ Window_ShopBuy
#------------------------------------------------------------------------------
# 商店画面、浏览显示可以购买的商品的窗口。
#==============================================================================
class Window_ShopBuy < Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化对像
# shop_goods : 商品
#--------------------------------------------------------------------------
def initialize(shop_goods)
super(40, 128, 358, 272)
@shop_goods = shop_goods
@column_max = 5
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# ● 获取物品
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
for goods_item in @shop_goods
case goods_item[0]
when 0
item = $data_items[goods_item[1]]
when 1
item = $data_weapons[goods_item[1]]
when 2
item = $data_armors[goods_item[1]]
end
if item != nil
@data.push(item)
end
end
# 如果项目数不是 0 就生成位图、描绘全部项目
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 47)
for i in 0...@item_max
draw_item(i)
end
end
end
#--------------------------------------------------------------------------
# ● 描绘羡慕
# index : 项目编号
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
# 获取物品所持数
case item
when RPG::Item
number = $game_party.item_number(item.id)
item_max = $item_max[@item.id] if $item_max[@item.id] != nil
when RPG::Weapon
number = $game_party.weapon_number(item.id)
item_max = $item_max[@item.id] if $item_max[@item.id] != nil
when RPG::Armor
number = $game_party.armor_number(item.id)
item_max = $item_max[@item.id] if $item_max[@item.id] != nil
end
# 价格在所持金以下、并且所持数不是 99 的情况下为普通文字颜色
# 除此之外的情况设置为无效文字色
if item.price <= $game_party.gold and number < item_max
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
x = (index % 5) * 57
y = ((index/5))*47
rect = Rect.new(x-20, y, self.width - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(item.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.font.size = 16
self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
#self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(x-58, y + 22, 88, 32, item.price.to_s, 2)
end
#--------------------------------------------------------------------------
# ● 刷新帮助文本
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description,1,self.item == nil ? 0 : self.item.xhp)
end
#--------------------------------------------------------------------------
# ● 刷新光标矩形
#--------------------------------------------------------------------------
def update_cursor_rect
if [url=home.php?mod=space&uid=370741]@Index[/url] < 0
self.cursor_rect.empty
else
self.cursor_rect.set((index % 5) * 55 , ((index/5)) * 47, 40, 30)
end
end
end
复制代码
我改了商店的购买物品的排列,改为5列4行、最多显示20个的模式,但是光标在最下面(即指向第二十个物品)时不会自动翻页,反而继续向下一行(但是画面没显示出该行)移动
希望能增加翻页功能,并且保持上下左右键都能移动光标 ,最重要的是上面脚本中的
物品图标和价格的位置不能变
。
作者:
RyanBern
时间:
2013-9-21 15:55
楼主想要的结果已经改完。
下面是代码,楼主更改失败的原因是Window_Selectable中默认一行的高度是32,而楼主并未作出更改。
另外你那个$item_max应该是你自定义的Hash,应该是限制各种物品最大拥有数的,在前面已经定义过但是在这里没有给出。
#==============================================================================
# ■ Window_Selectable
#------------------------------------------------------------------------------
# 拥有光标的移动以及滚动功能的窗口类。
#==============================================================================
class Window_Selectable < Window_Base
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_reader :index # 光标位置
attr_reader :help_window # 帮助窗口
attr_accessor :row_height # 行高
#--------------------------------------------------------------------------
# ● 初始画对像
# x : 窗口的 X 坐标
# y : 窗口的 Y 坐标
# width : 窗口的宽
# height : 窗口的高
# row_height : 行高 默认是32
#--------------------------------------------------------------------------
def initialize(x, y, width, height, row_height=32)
super(x, y, width, height)
@item_max = 1
@column_max = 1
[url=home.php?mod=space&uid=370741]@Index[/url] = -1
@row_height = row_height
end
#--------------------------------------------------------------------------
# ● 设置光标的位置
# index : 新的光标位置
#--------------------------------------------------------------------------
def index=(index)
@index = index
# 刷新帮助文本 (update_help 定义了继承目标)
if self.active and @help_window != nil
update_help
end
# 刷新光标矩形
update_cursor_rect
end
#--------------------------------------------------------------------------
# ● 获取行数
#--------------------------------------------------------------------------
def row_max
# 由项目数和列数计算出行数
return (@item_max + @column_max - 1) / @column_max
end
#--------------------------------------------------------------------------
# ● 获取开头行
#--------------------------------------------------------------------------
def top_row
# 将窗口内容的传送源 Y 坐标、1 行的高 row_height 等分
return self.oy / @row_height
end
#--------------------------------------------------------------------------
# ● 设置开头行
# row : 显示开头的行
#--------------------------------------------------------------------------
def top_row=(row)
# row 未满 0 的场合更正为 0
if row < 0
row = 0
end
# row 超过 row_max - 1 的情况下更正为 row_max - 1
if row > row_max - 1
row = row_max - 1
end
# row 1 行高的 32 倍、窗口内容的传送源 Y 坐标
self.oy = row * @row_height
end
#--------------------------------------------------------------------------
# ● 获取 1 页可以显示的行数
#--------------------------------------------------------------------------
def page_row_max
# 窗口的高度,设置画面的高度减去 32 ,除以 1 行的高度 row_height
return (self.height - 32) / @row_height
end
#--------------------------------------------------------------------------
# ● 获取 1 页可以显示的项目数
#--------------------------------------------------------------------------
def page_item_max
# 将行数 page_row_max 乘上列数 @column_max
return page_row_max * @column_max
end
#--------------------------------------------------------------------------
# ● 帮助窗口的设置
# help_window : 新的帮助窗口
#--------------------------------------------------------------------------
def help_window=(help_window)
@help_window = help_window
# 刷新帮助文本 (update_help 定义了继承目标)
if self.active and @help_window != nil
update_help
end
end
#--------------------------------------------------------------------------
# ● 更新光标举行
#--------------------------------------------------------------------------
def update_cursor_rect
# 光标位置不满 0 的情况下
if @index < 0
self.cursor_rect.empty
return
end
# 获取当前的行
row = @index / @column_max
# 当前行被显示开头行前面的情况下
if row < self.top_row
# 从当前行向开头行滚动
self.top_row = row
end
# 当前行被显示末尾行之后的情况下
if row > self.top_row + (self.page_row_max - 1)
# 从当前行向末尾滚动
self.top_row = row - (self.page_row_max - 1)
end
# 计算光标的宽
cursor_width = self.width / @column_max - 32
# 计算光标坐标
x = @index % @column_max * (cursor_width + 32)
y = @index / @column_max * @row_height - self.oy
# 更新国标矩形
self.cursor_rect.set(x, y, cursor_width, @row_height)
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
super
# 可以移动光标的情况下
if self.active and @item_max > 0 and @index >= 0
# 方向键下被按下的情况下
if Input.repeat?(Input::DOWN)
# 列数不是 1 并且方向键的下的按下状态不是重复的情况、
# 或光标位置在(项目数-列数)之前的情况下
if (@column_max == 1 and Input.trigger?(Input::DOWN)) or
@index < @item_max - @column_max
# 光标向下移动
$game_system.se_play($data_system.cursor_se)
@index = (@index + @column_max) % @item_max
end
end
# 方向键上被按下的情况下
if Input.repeat?(Input::UP)
# 列数不是 1 并且方向键的下的按下状态不是重复的情况、
# 或光标位置在列之后的情况下
if (@column_max == 1 and Input.trigger?(Input::UP)) or
@index >= @column_max
# 光标向上移动
$game_system.se_play($data_system.cursor_se)
@index = (@index - @column_max + @item_max) % @item_max
end
end
# 方向键右被按下的情况下
if Input.repeat?(Input::RIGHT)
# 列数为 2 以上并且、光标位置在(项目数 - 1)之前的情况下
if @column_max >= 2 and @index < @item_max - 1
# 光标向右移动
$game_system.se_play($data_system.cursor_se)
@index += 1
end
end
# 方向键左被按下的情况下
if Input.repeat?(Input::LEFT)
# 列数为 2 以上并且、光标位置在 0 之后的情况下
if @column_max >= 2 and @index > 0
# 光标向左移动
$game_system.se_play($data_system.cursor_se)
@index -= 1
end
end
# R 键被按下的情况下
if Input.repeat?(Input::R)
# 显示的最后行在数据中最后行上方的情况下
if self.top_row + (self.page_row_max - 1) < (self.row_max - 1)
# 光标向后移动一页
$game_system.se_play($data_system.cursor_se)
@index = [@index + self.page_item_max, @item_max - 1].min
self.top_row += self.page_row_max
end
end
# L 键被按下的情况下
if Input.repeat?(Input::L)
# 显示的开头行在位置 0 之后的情况下
if self.top_row > 0
# 光标向前移动一页
$game_system.se_play($data_system.cursor_se)
@index = [@index - self.page_item_max, 0].max
self.top_row -= self.page_row_max
end
end
end
# 刷新帮助文本 (update_help 定义了继承目标)
if self.active and @help_window != nil
update_help
end
# 刷新光标矩形
update_cursor_rect
end
end
#==============================================================================
# ■ Window_ShopBuy
#------------------------------------------------------------------------------
# 商店画面、浏览显示可以购买的商品的窗口。
#==============================================================================
class Window_ShopBuy < Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化对像
# shop_goods : 商品
#--------------------------------------------------------------------------
def initialize(shop_goods)
super(0, 128, 368, 352, 64)
@shop_goods = shop_goods
@column_max = 5
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# ● 获取物品
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
for goods_item in @shop_goods
case goods_item[0]
when 0
item = $data_items[goods_item[1]]
when 1
item = $data_weapons[goods_item[1]]
when 2
item = $data_armors[goods_item[1]]
end
if item != nil
@data.push(item)
end
end
# 如果项目数不是 0 就生成位图、描绘全部项目
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 64)
for i in 0...@item_max
draw_item(i)
end
end
end
#--------------------------------------------------------------------------
# ● 描绘羡慕
# index : 项目编号
#--------------------------------------------------------------------------
def draw_item(index)
item = @data[index]
# 获取物品所持数
case item
when RPG::Item
number = $game_party.item_number(item.id)
item_max = $item_max[@item.id] if $item_max[@item.id] != nil
when RPG::Weapon
number = $game_party.weapon_number(item.id)
item_max = $item_max[@item.id] if $item_max[@item.id] != nil
when RPG::Armor
number = $game_party.armor_number(item.id)
item_max = $item_max[@item.id] if $item_max[@item.id] != nil
end
# 价格在所持金以下、并且所持数不是 99 的情况下为普通文字颜色
# 除此之外的情况设置为无效文字色
if item.price <= $game_party.gold and number < item_max
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
x = (index % 5) * 73
y = (index / 5) * 64
bitmap = RPG::Cache.icon(item.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.font.size = 18
self.contents.blt(x + 10, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
#self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
self.contents.draw_text(x - 56, y + 32, 96, 24, item.price.to_s, 2)
end
#--------------------------------------------------------------------------
# ● 刷新帮助文本
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
end
复制代码
不知楼主是否满意呢?
作者:
恐惧剑刃
时间:
2013-9-21 16:30
本帖最后由 恋′挂机 于 2013-9-21 21:10 编辑
#==============================================================================
# ■ Window_ShopBuy
#------------------------------------------------------------------------------
# 商店画面、浏览显示可以购买的商品的窗口。
#==============================================================================
class Window_ShopBuy < Window_Selectable
#请看65行脚本
#--------------------------------------------------------------------------
# ● 初始化对像
# shop_goods : 商品
#--------------------------------------------------------------------------
def initialize(shop_goods)
#都五列了当然要把宽调大点,你说的翻页其实只要调小高度就可以了
super(0, 128, 368, 32 * 4 + 32)#X坐标、Y坐标、宽度、高度
self.z = 123
@column_max = 1#列数,直接改这里,1也不能省略
@shop_goods = shop_goods
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# ● 获取物品
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
for goods_item in @shop_goods
case goods_item[0]
when 0
item = $data_items[goods_item[1]]
when 1
item = $data_weapons[goods_item[1]]
when 2
item = $data_armors[goods_item[1]]
end
if item != nil
@data.push(item)
end
end
# 如果项目数不是 0 就生成位图、描绘全部项目
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new(width - 32, row_max * 32)
for i in 0...@item_max
draw_item(i)
end
end
end
#--------------------------------------------------------------------------
# ● 描绘项目
# index : 项目编号
#--------------------------------------------------------------------------
def draw_item(index)
###################################################
icon_x = 0#图标的X坐标附加值,向右为正,向左为负
icon_y = 0#图标的Y坐标附加值,向下为正,向上为负
#name_x = 0#物品名的X坐标附加值,向右为正,向左为负
#name_y = 0#物品名的Y坐标附加值,向下为正,向上为负
price_x = 0#物品价格的X坐标附加值,向右为正,向左为负
price_y = 0#物品价格的Y坐标附加值,向下为正,向上为负
##################################################
item = @data[index]
# 获取物品所持数
case item
when RPG::Item
number = $game_party.item_number(item.id)
when RPG::Weapon
number = $game_party.weapon_number(item.id)
when RPG::Armor
number = $game_party.armor_number(item.id)
end
# 价格在所持金以下、并且所持数不是 99 的情况下为普通文字颜色
# 除此之外的情况设置为无效文字色
if item.price <= $game_party.gold and number < 99
self.contents.font.color = normal_color
else
self.contents.font.color = disabled_color
end
#################################
x = 4 + index % @column_max * (95 + 32)
y = index / @column_max * 32
self.contents.font.size = 15#字体大小
#################################
rect = Rect.new(x, y, self.width - 32, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
bitmap = RPG::Cache.icon(item.icon_name)
opacity = self.contents.font.color == normal_color ? 255 : 128
self.contents.blt(x + icon_x, y + 4 + icon_y, bitmap, Rect.new(0, 0, 24, 24), opacity)
#self.contents.draw_text(x + 28 + name_x, y + name_y, 212, 32, item.name, 0)
self.contents.draw_text(x + 240 + price_x, y + price_y, 88, 32, item.price.to_s, 2)
end
#--------------------------------------------------------------------------
# ● 刷新帮助文本
#--------------------------------------------------------------------------
def update_help
@help_window.set_text(self.item == nil ? "" : self.item.description)
end
end
复制代码
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1