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

Project1

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

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

[复制链接]

Lv1.梦旅人

梦石
0
星屑
70
在线时间
5 小时
注册时间
2026-3-21
帖子
3
跳转到指定楼层
1
发表于 2026-4-29 13:19:18 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

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

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

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

Lv4.逐梦者

梦石
8
星屑
2406
在线时间
109 小时
注册时间
2021-3-30
帖子
49

极短24获奖极短23参与

2
发表于 2026-4-29 15:47:55 | 只看该作者
可能是使用物品时没有实现目标选择
回复 支持 反对

使用道具 举报

Lv5.捕梦者

梦石
0
星屑
29116
在线时间
5658 小时
注册时间
2016-3-8
帖子
1723
3
发表于 2026-4-29 22:11:27 | 只看该作者
def use_item里再加句@list_window.activate吧?
回复 支持 1 反对 0

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
70
在线时间
5 小时
注册时间
2026-3-21
帖子
3
4
 楼主| 发表于 2026-4-30 08:10:37 | 只看该作者
alexncf125 发表于 2026-4-29 22:11
def use_item里再加句@list_window.activate吧?

不行呢,但感谢帮助
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
70
在线时间
5 小时
注册时间
2026-3-21
帖子
3
5
 楼主| 发表于 2026-4-30 08:14:12 | 只看该作者
alexncf125 发表于 2026-4-29 22:11
def use_item里再加句@list_window.activate吧?

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

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2026-6-4 16:11

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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