赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 0 |
最后登录 | 2025-3-2 |
在线时间 | 5 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 72
- 在线时间
- 5 小时
- 注册时间
- 2024-5-18
- 帖子
- 3
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本人RUBY基础为零,找DS帮我写的代码,老是会78行报错,不知道为什么,大佬求解
# ★★★★★ 横向滚动物品栏 ★★★★★
class Window_HorizontalItem < Window_Selectable
# 初始化
def initialize
super(0, 64, Graphics.width, Graphics.height - 64)
@scroll_x = 0 # 滚动偏移量
@scroll_speed = 20 # 每次滚动像素数
self.index = 0
refresh
end
# 每行显示数量
def col_max
5 # 修改数字可调整每行显示数量
end
# 动态计算窗口宽度
def window_width
Graphics.width
end
# 绘制单个物品
def draw_item(index)
return if index < 0
item = @data[index]
return unless item
rect = item_rect(index)
rect.x -= @scroll_x # 应用横向滚动偏移
# 绘制图标和名称
draw_icon(item.icon_index, rect.x, rect.y)
draw_text(rect.x + 24, rect.y, rect.width - 24, line_height, item.name)
end
# 处理横向滚动
def update_scroll
# 鼠标滚轮检测
if Input.repeat?(Input::MOUSESCROLLUP)
scroll_left
elsif Input.repeat?(Input::MOUSESCROLLDOWN)
scroll_right
end
# 键盘左右键检测
if Input.repeat?(Input::LEFT)
scroll_left
elsif Input.repeat?(Input::RIGHT)
scroll_right
end
end
# 向左滚动
def scroll_left
@scroll_x = [@scroll_x - @scroll_speed, 0].max
refresh
end
# 向右滚动
def scroll_right
max_scroll = [self.width - contents_width, 0].max
@scroll_x = [@scroll_x + @scroll_speed, max_scroll].min
refresh
end
# 优化刷新逻辑
def refresh
self.contents.dispose if self.contents
self.contents = Bitmap.new(contents_width, contents_height)
@data = $game_party.items
@item_max = @data.size
create_contents
draw_all_items
end
end
# ★★★★★ 修改菜单场景 ★★★★★
class Scene_Menu < Scene_Base
alias horizontal_start start
def start
horizontal_start
create_horizontal_window
end
def create_horizontal_window
@item_window = Window_HorizontalItem.new
@item_window.set_handler(:ok, method(:on_item_ok))
@item_window.set_handler(:cancel, method(:return_scene))
end
# 每帧更新滚动
def update
super
@item_window.update_scroll
end
# 资源释放
def terminate
super
@item_window.dispose if @item_window
end
end |
|