| 赞 | 0 |
| VIP | 0 |
| 好人卡 | 0 |
| 积分 | 1 |
| 经验 | 0 |
| 最后登录 | 2026-5-8 |
| 在线时间 | 5 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 70
- 在线时间
- 5 小时
- 注册时间
- 2026-3-21
- 帖子
- 3
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 凯Katy 于 2026-4-30 08:17 编辑
为什么我的背包界面无法使用物品
为什么一但使用了物品就会卡在这个画面,按什么按键都没有用
代码部分
#==============================================================================
# ▼ 全屏背包插件(基于图片 shukai.png)
# 功能:将 Graphics/Pictures/shukai.png 拉伸至全窗口作为背景,
# 物品列表显示在左半区域,物品说明在右半区域。
#==============================================================================
module CustomBag
BG_IMAGE = "shukai" # 背景图片文件名
# 物品列表窗口区域(左半部分)
# 格式:Rect.new(x, y, width, height) 坐标以窗口左上角为原点(0,0)
LIST_RECT = Rect.new(20, 40, 250, 336)
# 物品说明窗口区域(右半部分)
DESC_RECT = Rect.new(280, 40, 244, 336)
LINE_HEIGHT = 24 # 物品列表每行高度(像素)
end
#==============================================================================
# 物品列表窗口(透明背景,仅显示图标和名称)
#==============================================================================
class Window_BagItemList < Window_Selectable
def initialize(x, y, width, height)
super(x, y, width, height)
@data = []
refresh
self.index = 0
activate
self.opacity = 0
self.back_opacity = 0
end
def refresh
@data = []
return unless $game_party
$game_party.items.each { |i| @data << i unless i.key_item? }
$game_party.items.each { |i| @data << i if i.key_item? }
$game_party.weapons.each { |w| @data << w }
$game_party.armors.each { |a| @data << a }
create_contents
draw_all_items
end
def item
@data[index] if @data && index >= 0 && index < @data.size
end
def draw_item(index)
item = @data[index]
return unless item
rect = item_rect(index)
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 item_max
@data ? @data.size : 0
end
end
#==============================================================================
# 物品说明窗口(透明背景,显示描述文字)
#==============================================================================
class Window_BagDesc < Window_Base
def initialize(x, y, width, height)
super(x, y, width, height)
self.opacity = 0
self.back_opacity = 0
@item = nil
end
def set_item(item)
@item = item
refresh
end
def refresh
contents.clear
return unless @item
draw_text_ex(4, 4, @item.description)
end
end
#==============================================================================
# 自定义背包场景
#==============================================================================
class Scene_Bag < Scene_Base
def start
super
create_background
create_item_list
create_description
end
def create_background
@bg_sprite = Sprite.new
src = Cache.picture(CustomBag::BG_IMAGE)
@bg_sprite.bitmap = Bitmap.new(Graphics.width, Graphics.height)
@bg_sprite.bitmap.stretch_blt(@bg_sprite.bitmap.rect, src, src.rect)
@bg_sprite.x = 0
@bg_sprite.y = 0
end
def create_item_list
@list_window = Window_BagItemList.new(
CustomBag::LIST_RECT.x, CustomBag::LIST_RECT.y,
CustomBag::LIST_RECT.width, CustomBag::LIST_RECT.height
)
@list_window.set_handler(:ok, method(:use_item))
@list_window.set_handler(:cancel, method(:return_scene))
end
def create_description
@desc_window = Window_BagDesc.new(
CustomBag::DESC_RECT.x, CustomBag::DESC_RECT.y,
CustomBag::DESC_RECT.width, CustomBag::DESC_RECT.height
)
update_description
end
def update_description
item = @list_window.item
@desc_window.set_item(item)
end
def update
super
if @list_window && @list_window.active
if @last_index != @list_window.index
update_description
@last_index = @list_window.index
end
end
end
def use_item
item = @list_window.item
if item && item.is_a?(RPG::Item) && item.consumable
$game_party.consume_item(item)
@list_window.refresh
update_description
Sound.play_use_item
else
Sound.play_buzzer
end
end
def return_scene
SceneManager.goto(Scene_Map)
end
end
#==============================================================================
# 替换默认物品场景
#==============================================================================
class << SceneManager
alias_method :custom_bag_call, :call
def call(scene_class)
if scene_class == Scene_Item
custom_bag_call(Scene_Bag)
else
custom_bag_call(scene_class)
end
end
end
|
|