查看: 1097|回复: 4

[交流讨论] 【已解决】谢谢帮助

[复制链接]
梦石
0
星屑
139
在线时间
13 小时
注册时间
2026-3-21
回帖
2
发表于 2026-4-29 13:19:18 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 凯Katy 于 2026-4-30 08:17 编辑

为什么我的背包界面无法使用物品

屏幕截图 2026-04-29 115548.png
为什么一但使用了物品就会卡在这个画面,按什么按键都没有用

代码部分

#==============================================================================
# ▼ 全屏背包插件(基于图片 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
梦石
8
星屑
2444
在线时间
112 小时
注册时间
2021-3-30
回帖
47

极短24获奖极短23参与

发表于 2026-4-29 15:47:55 | 显示全部楼层
可能是使用物品时没有实现目标选择
回复

使用道具 举报

梦石
0
星屑
29896
在线时间
5733 小时
注册时间
2016-3-8
回帖
1653
发表于 2026-4-29 22:11:27 | 显示全部楼层
def use_item里再加句@list_window.activate吧?
回复 1 0

使用道具 举报

梦石
0
星屑
139
在线时间
13 小时
注册时间
2026-3-21
回帖
2
 楼主| 发表于 2026-4-30 08:10:37 | 显示全部楼层
alexncf125 发表于 2026-4-29 22:11
def use_item里再加句@list_window.activate吧?

不行呢,但感谢帮助
回复

使用道具 举报

梦石
0
星屑
139
在线时间
13 小时
注册时间
2026-3-21
回帖
2
 楼主| 发表于 2026-4-30 08:14:12 | 显示全部楼层
alexncf125 发表于 2026-4-29 22:11
def use_item里再加句@list_window.activate吧?

删了一段代码,在加@list_window.activate就能用了,谢谢帮助
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部