查看: 1102|回复: 8

[已经解决] 冒头,哪位大佬能帮忙加个确定窗口【已解决】

[复制链接]
梦石
0
星屑
1966
在线时间
112 小时
注册时间
2017-9-5
回帖
157
发表于 2025-3-3 18:38:43 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 间桐樱 于 2025-3-4 12:36 编辑

这是按两次CTRL删除技能的脚本,但总觉得差点儿什么,哪位大佬能帮忙向下边那个道具舍弃的脚本一样,添加个弹出是否确认删除技能的窗口
#==============================================================================
# ■ Scene_Skill
#==============================================================================
class Scene_Skill < Scene_ItemBase
  #--------------------------------------------------------------------------
  # ● アイテムウィンドウの作成
  #--------------------------------------------------------------------------
  def create_item_window
    wx = 0
    wy = @status_window.y + @status_window.height
    ww = Graphics.width
    wh = Graphics.height - wy
    @item_window = Window_SkillList.new(wx, wy, ww, wh)
    @item_window.actor = @actor
    @item_window.viewport = @viewport
    @item_window.help_window = @help_window
    @item_window.set_handler(:ok,     method(:on_item_ok))
    @item_window.set_handler(:cancel, method(:on_item_cancel))
    @item_window.set_handler(:CTRL,   method(:on_item_del))
    @command_window.skill_window = @item_window
  end
  #--------------------------------------------------------------------------
  # ● スキルを忘れる
  #--------------------------------------------------------------------------
  def on_item_del
    if !item.nil?
      skill_id = item.id
      @actor.forget_skill(skill_id)
      @item_window.refresh
    end
  end
end
#==============================================================================
# ■ Game_Actor
#==============================================================================
class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # ● スキルを忘れる
  #--------------------------------------------------------------------------
  alias _forget_skill_copy forget_skill
  def forget_skill(skill_id)
    _forget_skill_copy(skill_id)
    @copy_skills.delete(skill_id)
  end
end
#==============================================================================
# ■ Window_Selectable
#==============================================================================
class Window_Selectable < Window_Base
  #--------------------------------------------------------------------------
  # ● 決定やキャンセルなどのハンドリング処理
  #--------------------------------------------------------------------------
  def process_handling
    return unless open? && active
    return process_ok       if ok_enabled?        && Input.trigger?(:C)
    return process_cancel   if cancel_enabled?    && Input.trigger?(:B)
    return process_pagedown if handle?(:pagedown) && Input.trigger?(:R)
    return process_pageup   if handle?(:pageup)   && Input.trigger?(:L)
    return process_ctrl     if Input.trigger?(:CTRL)
  end
  #--------------------------------------------------------------------------
  # ● CTRL ボタン(CTRL)が押されたときの処理
  #--------------------------------------------------------------------------
  def process_ctrl
    Sound.play_ok
    if Time.now - (@last_ctrl_time || Time.at(0)) < 1
      Sound.play_ok
      Input.update
      call_handler(:CTRL)
      @last_ctrl_time = nil
    else
      @last_ctrl_time = Time.now
    end
  end
end

#==============================================================================
# ■ Window_ItemList
#==============================================================================
class Window_ItemList < Window_Selectable
  #--------------------------------------------------------------------------
  # ● 決定やキャンセルなどのハンドリング処理
  #--------------------------------------------------------------------------
  def process_handling
    return unless open? && active
    return call_handler(:append_ctrl) if handle?(:append_ctrl) && Input.trigger?(:CTRL)
    super
  end
end
#==============================================================================
# ■ Window_ItemNumber
#==============================================================================
class Window_ItemNumber < Window_ShopNumber
  #--------------------------------------------------------------------------
  # ● 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_reader   :number                   # 入力された個数
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    x = (Graphics.width - window_width) / 2
    super(x, 200, line_height * 2 + 32)
    @item = nil
    @Max = 1
    @number = 1
  end
  #--------------------------------------------------------------------------
  # ● アイテム、最大個数の設定
  #--------------------------------------------------------------------------
  def set(item, max)
    @item = item
    @Max = max
    @number = 1
    refresh
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    contents.draw_text(0, 0, 200, line_height, "捨てる数:")
    draw_item_name(@item, 4, line_height)
    draw_number
  end
  #--------------------------------------------------------------------------
  # ● アイテム名表示行の Y 座標
  #--------------------------------------------------------------------------
  def item_y
    line_height
  end
end
#==============================================================================
# ■ Scene_Item
#==============================================================================
class Scene_Item < Scene_ItemBase
  #--------------------------------------------------------------------------
  # ● 開始処理
  #--------------------------------------------------------------------------
  alias start_dump start
  def start
    start_dump
    create_item_dump_window
  end
  #--------------------------------------------------------------------------
  # ● アイテムウィンドウの作成
  #--------------------------------------------------------------------------
  alias create_item_window_dump create_item_window
  def create_item_window
    create_item_window_dump
    @item_window.set_handler(:append_ctrl, method(:on_item_dump))
  end
  #--------------------------------------------------------------------------
  # ● アイテム数選択ウィンドウの作成
  #--------------------------------------------------------------------------
  def create_item_dump_window
    @number_window = Window_ItemNumber.new
    @number_window.viewport = @viewport
    @number_window.hide
    @number_window.set_handler(:ok,     method(:on_number_ok))
    @number_window.set_handler(:cancel, method(:on_number_cancel))
  end
  #--------------------------------------------------------------------------
  # ● アイテム[捨てる]
  #--------------------------------------------------------------------------
  def on_item_dump
    if item_dumpable?
      Sound.play_ok
      if Time.now - (@last_ctrl_time || Time.at(0)) < 1
        Sound.play_ok
        @number_window.set(item, max_item)
        @number_window.show.activate
        @item_window.deactivate
        @last_ctrl_time = nil
      else
        @last_ctrl_time = Time.now
      end
    else
      Sound.play_buzzer
    end
  end
  #--------------------------------------------------------------------------
  # ● 個数入力[決定]
  #--------------------------------------------------------------------------
  def on_number_ok
    Sound.play_ok
    do_item_dump(@number_window.number)
    @number_window.hide
    activate_item_window
  end
  #--------------------------------------------------------------------------
  # ● 個数入力[キャンセル]
  #--------------------------------------------------------------------------
  def on_number_cancel
    Sound.play_cancel
    @number_window.hide
    activate_item_window
  end
  #--------------------------------------------------------------------------
  # ● 捨てるの実行
  #--------------------------------------------------------------------------
  def do_item_dump(number)
    $game_party.lose_item(item, number)
  end
  #--------------------------------------------------------------------------
  # ● アイテムを捨てる判定
  #--------------------------------------------------------------------------
  def item_dumpable?
   item.is_a?(RPG::Item) ? !item.key_item? : (!item.nil?)
  end
  #--------------------------------------------------------------------------
  # ● 所持数の取得
  #--------------------------------------------------------------------------
  def max_item
    $game_party.item_number(item)
  end
end
梦石
0
星屑
2914
在线时间
665 小时
注册时间
2012-5-3
回帖
78

开拓者

发表于 2025-3-3 22:15:38 | 显示全部楼层

  1. #==============================================================================
  2. # ■ Window_SkillConfirm
  3. #==============================================================================
  4. class Window_SkillConfirm < Window_Selectable
  5.   def initialize
  6.     super((Graphics.width - 240) / 2, 200, 240, 96)
  7.     self.opacity = 200
  8.     refresh
  9.   end

  10.   def refresh
  11.     contents.clear
  12.     draw_text(0, 0, 240, line_height, "是否忘记该技能?", 1)
  13.     draw_text(0, 36, 120, line_height, "确认")
  14.     draw_text(120, 36, 120, line_height, "取消")
  15.   end
  16. end

  17. #==============================================================================
  18. # ■ Scene_Skill
  19. #==============================================================================
  20. class Scene_Skill < Scene_ItemBase
  21.    #--------------------------------------------------------------------------
  22.   # ● 开始处理(新增确认窗口创建)
  23.   #--------------------------------------------------------------------------
  24.   alias start_skill_confirm start
  25.   def start
  26.     start_skill_confirm
  27.     create_skill_confirm_window
  28.   end
  29.   #--------------------------------------------------------------------------
  30.   # ● 创建技能确认窗口
  31.   #--------------------------------------------------------------------------
  32.   def create_skill_confirm_window
  33.     @confirm_window = Window_SkillConfirm.new
  34.     @confirm_window.viewport = @viewport
  35.     @confirm_window.hide
  36.     @confirm_window.set_handler(:ok,     method(:on_confirm_ok))
  37.     @confirm_window.set_handler(:cancel, method(:on_confirm_cancel))
  38.   end
  39.   #--------------------------------------------------------------------------
  40.   # ● アイテムウィンドウの作成
  41.   #--------------------------------------------------------------------------
  42.   def create_item_window
  43.     wx = 0
  44.     wy = @status_window.y + @status_window.height
  45.     ww = Graphics.width
  46.     wh = Graphics.height - wy
  47.     @item_window = Window_SkillList.new(wx, wy, ww, wh)
  48.     @item_window.actor = @actor
  49.     @item_window.viewport = @viewport
  50.     @item_window.help_window = @help_window
  51.     @item_window.set_handler(:ok,     method(:on_item_ok))
  52.     @item_window.set_handler(:cancel, method(:on_item_cancel))
  53.     @item_window.set_handler(:CTRL,   method(:on_item_del))
  54.     @command_window.skill_window = @item_window
  55.   end
  56.   #--------------------------------------------------------------------------
  57.   # ● スキルを忘れる(修改后的版本)
  58.   #--------------------------------------------------------------------------
  59.   def on_item_del
  60.     if !item.nil?
  61.       Sound.play_ok
  62.       @confirm_window.show.activate  # 显示确认窗口
  63.       @item_window.deactivate        # 禁用技能列表窗口
  64.     else
  65.       Sound.play_buzzer
  66.     end
  67.   end
  68.   
  69.   
  70.    #--------------------------------------------------------------------------
  71.   # ● 确认窗口[确定]
  72.   #--------------------------------------------------------------------------
  73.   def on_confirm_ok
  74.     skill_id = item.id
  75.     @actor.forget_skill(skill_id)
  76.     @item_window.refresh
  77.     Sound.play_ok
  78.     @confirm_window.hide
  79.     activate_item_window
  80.   end

  81.   #--------------------------------------------------------------------------
  82.   # ● 确认窗口[取消]
  83.   #--------------------------------------------------------------------------
  84.   def on_confirm_cancel
  85.     Sound.play_cancel
  86.     @confirm_window.hide
  87.     activate_item_window
  88.   end
  89.   
  90.   
  91. end
  92. #==============================================================================
  93. # ■ Game_Actor
  94. #==============================================================================
  95. class Game_Actor < Game_Battler

  96. #--------------------------------------------------------------------------
  97.   # ● オブジェクト初期化(新增初始化方法)
  98.   #--------------------------------------------------------------------------
  99.   alias _initialize_copy initialize
  100.   def initialize(actor_id)
  101.     _initialize_copy(actor_id)
  102.     @copy_skills ||= []  # 确保副本技能数组初始化
  103.   end
  104.   #--------------------------------------------------------------------------
  105.   # ● スキルを忘れる
  106.   #--------------------------------------------------------------------------
  107.   
  108.    #--------------------------------------------------------------------------
  109.   # ● スキルを忘れる(修复后的方法)
  110.   #--------------------------------------------------------------------------
  111.   alias _forget_skill_copy forget_skill
  112.   def forget_skill(skill_id)
  113.     _forget_skill_copy(skill_id)
  114.     @copy_skills.delete(skill_id) if @copy_skills  # 增加存在性检查
  115.   end
  116. end
  117. #==============================================================================
  118. # ■ Window_Selectable
  119. #==============================================================================
  120. class Window_Selectable < Window_Base
  121.   #--------------------------------------------------------------------------
  122.   # ● 決定やキャンセルなどのハンドリング処理
  123.   #--------------------------------------------------------------------------
  124.   def process_handling
  125.     return unless open? && active
  126.     return process_ok       if ok_enabled?        && Input.trigger?(:C)
  127.     return process_cancel   if cancel_enabled?    && Input.trigger?(:B)
  128.     return process_pagedown if handle?(:pagedown) && Input.trigger?(:R)
  129.     return process_pageup   if handle?(:pageup)   && Input.trigger?(:L)
  130.     return process_ctrl     if Input.trigger?(:CTRL)
  131.   end
  132.   #--------------------------------------------------------------------------
  133.   # ● CTRL ボタン(CTRL)が押されたときの処理
  134.   #--------------------------------------------------------------------------
  135.   def process_ctrl
  136.     Sound.play_ok
  137.     if Time.now - (@last_ctrl_time || Time.at(0)) < 1
  138.       Sound.play_ok
  139.       Input.update
  140.       call_handler(:CTRL)
  141.       @last_ctrl_time = nil
  142.     else
  143.       @last_ctrl_time = Time.now
  144.     end
  145.   end
  146. end

  147. #==============================================================================
  148. # ■ Window_ItemList
  149. #==============================================================================
  150. class Window_ItemList < Window_Selectable
  151.   #--------------------------------------------------------------------------
  152.   # ● 決定やキャンセルなどのハンドリング処理
  153.   #--------------------------------------------------------------------------
  154.   def process_handling
  155.     return unless open? && active
  156.     return call_handler(:append_ctrl) if handle?(:append_ctrl) && Input.trigger?(:CTRL)
  157.     super
  158.   end
  159. end
  160. #==============================================================================
  161. # ■ Window_ItemNumber
  162. #==============================================================================
  163. class Window_ItemNumber < Window_ShopNumber
  164.   #--------------------------------------------------------------------------
  165.   # ● 公開インスタンス変数
  166.   #--------------------------------------------------------------------------
  167.   attr_reader   :number                   # 入力された個数
  168.   #--------------------------------------------------------------------------
  169.   # ● オブジェクト初期化
  170.   #--------------------------------------------------------------------------
  171.   def initialize
  172.     x = (Graphics.width - window_width) / 2
  173.     super(x, 200, line_height * 2 + 32)
  174.     @item = nil
  175.     @Max = 1
  176.     @number = 1
  177.   end
  178.   #--------------------------------------------------------------------------
  179.   # ● アイテム、最大個数の設定
  180.   #--------------------------------------------------------------------------
  181.   def set(item, max)
  182.     @item = item
  183.     @max = max
  184.     @number = 1
  185.     refresh
  186.   end
  187.   #--------------------------------------------------------------------------
  188.   # ● リフレッシュ
  189.   #--------------------------------------------------------------------------
  190.   def refresh
  191.     contents.clear
  192.     contents.draw_text(0, 0, 200, line_height, "捨てる数:")
  193.     draw_item_name(@item, 4, line_height)
  194.     draw_number
  195.   end
  196.   #--------------------------------------------------------------------------
  197.   # ● アイテム名表示行の Y 座標
  198.   #--------------------------------------------------------------------------
  199.   def item_y
  200.     line_height
  201.   end
  202. end
  203. #==============================================================================
  204. # ■ Scene_Item
  205. #==============================================================================
  206. class Scene_Item < Scene_ItemBase
  207.   #--------------------------------------------------------------------------
  208.   # ● 開始処理
  209.   #--------------------------------------------------------------------------
  210.   alias start_dump start
  211.   def start
  212.     start_dump
  213.     create_item_dump_window
  214.   end
  215.   #--------------------------------------------------------------------------
  216.   # ● アイテムウィンドウの作成
  217.   #--------------------------------------------------------------------------
  218.   alias create_item_window_dump create_item_window
  219.   def create_item_window
  220.     create_item_window_dump
  221.     @item_window.set_handler(:append_ctrl, method(:on_item_dump))
  222.   end
  223.   #--------------------------------------------------------------------------
  224.   # ● アイテム数選択ウィンドウの作成
  225.   #--------------------------------------------------------------------------
  226.   def create_item_dump_window
  227.     @number_window = Window_ItemNumber.new
  228.     @number_window.viewport = @viewport
  229.     @number_window.hide
  230.     @number_window.set_handler(:ok,     method(:on_number_ok))
  231.     @number_window.set_handler(:cancel, method(:on_number_cancel))
  232.   end
  233.   #--------------------------------------------------------------------------
  234.   # ● アイテム[捨てる]
  235.   #--------------------------------------------------------------------------
  236.   def on_item_dump
  237.     if item_dumpable?
  238.       Sound.play_ok
  239.       if Time.now - (@last_ctrl_time || Time.at(0)) < 1
  240.         Sound.play_ok
  241.         @number_window.set(item, max_item)
  242.         @number_window.show.activate
  243.         @item_window.deactivate
  244.         @last_ctrl_time = nil
  245.       else
  246.         @last_ctrl_time = Time.now
  247.       end
  248.     else
  249.       Sound.play_buzzer
  250.     end
  251.   end
  252.   #--------------------------------------------------------------------------
  253.   # ● 個数入力[決定]
  254.   #--------------------------------------------------------------------------
  255.   def on_number_ok
  256.     Sound.play_ok
  257.     do_item_dump(@number_window.number)
  258.     @number_window.hide
  259.     activate_item_window
  260.   end
  261.   #--------------------------------------------------------------------------
  262.   # ● 個数入力[キャンセル]
  263.   #--------------------------------------------------------------------------
  264.   def on_number_cancel
  265.     Sound.play_cancel
  266.     @number_window.hide
  267.     activate_item_window
  268.   end
  269.   #--------------------------------------------------------------------------
  270.   # ● 捨てるの実行
  271.   #--------------------------------------------------------------------------
  272.   def do_item_dump(number)
  273.     $game_party.lose_item(item, number)
  274.   end
  275.   #--------------------------------------------------------------------------
  276.   # ● アイテムを捨てる判定
  277.   #--------------------------------------------------------------------------
  278.   def item_dumpable?
  279.    item.is_a?(RPG::Item) ? !item.key_item? : (!item.nil?)
  280.   end
  281.   #--------------------------------------------------------------------------
  282.   # ● 所持数の取得
  283.   #--------------------------------------------------------------------------
  284.   def max_item
  285.     $game_party.item_number(item)
  286.   end
  287. end
复制代码


你看看这样行不行?不行你看看需要什么别的功能吗?我再改改。

点评

可以可以,挺好的,就是大佬能再给确认取消的选项加个光标吗  发表于 2025-3-3 22:33
回复

使用道具 举报

梦石
0
星屑
2914
在线时间
665 小时
注册时间
2012-5-3
回帖
78

开拓者

发表于 2025-3-3 23:49:30 | 显示全部楼层
本帖最后由 邱小谦 于 2025-3-4 12:01 编辑

这次应该完美了吧?测试了半天,我觉得挺好的。
[pre lang="ruby"]
#==============================================================================
# ■ Window_SkillConfirm
#==============================================================================
class Window_SkillConfirm < Window_Selectable
  def initialize
    super((Graphics.width - 240) / 2, 200, 240, 96)
    self.opacity = 200
    @item_max = 2
    @column_max = 2
    @item_width = 120
    refresh
  end

  def unselect
    self.index = -1
  end

  # 添加item_max方法覆盖
  def item_max
    2
  end

  
  
  # 新增:覆盖方向键处理逻辑
  def cursor_right(wrap = false)
    if index % @column_max < @column_max - 1
      select((index + 1) % @item_max)
    end
  end

  def cursor_left(wrap = false)
    if index % @column_max > 0
      select((index - 1) % @item_max)
    end
  end

  # 修改:恢复上下键功能但限制移动
  def cursor_down(wrap = false)
    # 禁用垂直移动
  end

  def cursor_up(wrap = false)
    # 禁用垂直移动
  end

  # 修改:调整光标移动判断
  def cursor_movable?
    return false unless super
    return false if @cursor_all
    (index % @column_max > 0 && Input.repeat?(:LEFT)) ||
    (index % @column_max < @column_max - 1 && Input.repeat?(:RIGHT))
  end
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  def refresh
    contents.clear
    # 绘制标题(添加居中参数)
    draw_text(0, 0, 240, line_height, "是否忘记该技能?", 1)

    # 使用循环绘制可选项(添加居中参数)
    @item_max.times do |i|
      rect = item_rect(i)
      text = i == 0 ? "确认" : "取消"
      draw_text(rect, text, 1)  # 使用矩形区域和居中参数
    end
  end
  # 修正光标矩形计算方法
  def item_rect(index)
    rect = Rect.new
    rect.width = @item_width
    rect.height = line_height
    rect.x = index % @column_max * (rect.width + 0)  # 列间距为0
    rect.y = line_height * 2  # 标题下方留两行空间
    rect
  end

  # 重写绘制光标方法
  def draw_cursor(index)
    rect = item_rect(index)
    text = index == 0 ? "确认" : "取消"
   
    # 获取实际文字尺寸
    text_width = text_size(text).width + 8  # 增加边距
    text_height = line_height * 0.8
   
    # 计算居中坐标
    cursor_x = rect.x + (rect.width - text_width) / 2
    cursor_y = rect.y + (rect.height - text_height) / 2
   
    draw_cursor_rect(cursor_x, cursor_y, text_width, text_height)
  end

  # 重写绘制项目方法,调用调整后的光标绘制方法
  def draw_item(index)
    rect = item_rect(index)
    text = index == 0 ? "确认" : "取消"
    draw_text(rect.x, rect.y, rect.width, rect.height, text)
    if index == self.index
      draw_cursor(index)
    end
  end

  #  # 重写 update_cursor 方法
  def update_cursor
    if index >= 0
      rect = item_rect(index)
      text = index == 0 ? "确认" : "取消"
      
      text_width = text_size(text).width + 8
      text_height = line_height * 0.8
      
      cursor_x = rect.x + (rect.width - text_width) / 2
      cursor_y = rect.y + (rect.height - text_height) / 2
      
      self.cursor_rect.set(cursor_x, cursor_y, text_width, text_height)
    else
      self.cursor_rect.empty
    end
  end
  
  
  
  # 简化绘制项目方法
  def draw_item(index)
    rect = item_rect(index)
    text = index == 0 ? "确认" : "取消"
    draw_text(rect, text, 1)  # 使用矩形区域和居中参数
  end
end

# 以下部分代码保持不变
#==============================================================================
# ■ Scene_Skill
#==============================================================================
class Scene_Skill < Scene_ItemBase
  #--------------------------------------------------------------------------
  # ● 开始处理(新增确认窗口创建)
  #--------------------------------------------------------------------------
  alias start_skill_confirm start
  def start
    start_skill_confirm
    create_skill_confirm_window
  end
  #--------------------------------------------------------------------------
  # ● 创建技能确认窗口
  #--------------------------------------------------------------------------
  def create_skill_confirm_window
    @confirm_window = Window_SkillConfirm.new
    @confirm_window.viewport = @viewport
    @confirm_window.hide.deactivate  # 增加deactivate
    @confirm_window.hide
    @confirm_window.set_handler(:ok,     method(:on_confirm_ok))
    @confirm_window.set_handler(:cancel, method(:on_confirm_cancel))
    @confirm_window.select(0)  # 添加默认选择项
  end
  #--------------------------------------------------------------------------
  # ● アイテムウィンドウの作成
  #--------------------------------------------------------------------------
  def create_item_window
    wx = 0
    wy = @status_window.y + @status_window.height
    ww = Graphics.width
    wh = Graphics.height - wy
    @item_window = Window_SkillList.new(wx, wy, ww, wh)
    @item_window.actor = @actor
    @item_window.viewport = @viewport
    @item_window.help_window = @help_window
    @item_window.set_handler(:ok,     method(:on_item_ok))
    @item_window.set_handler(:cancel, method(:on_item_cancel))
    @item_window.set_handler(:CTRL,   method(:on_item_del))
    @command_window.skill_window = @item_window
  end
  #--------------------------------------------------------------------------
  # ● スキルを忘れる(修改后的版本)
  #--------------------------------------------------------------------------
  def on_item_del
    if !item.nil?
      Sound.play_ok
      @confirm_window.show.activate
      @confirm_window.select(0)  # 新增这行重置选择状态
      @item_window.deactivate
    else
      Sound.play_buzzer
    end
  end

  #--------------------------------------------------------------------------
  # ● 确认窗口[确定]
  #--------------------------------------------------------------------------
  # 修改 Scene_Skill 中的 on_confirm_ok 方法
  def on_confirm_ok
    # 根据当前选中的索引判断操作
    if @confirm_window.index == 0
      # 确认操作
      skill_id = item.id
      @actor.forget_skill(skill_id)
      @item_window.refresh
      Sound.play_ok
      @confirm_window.hide.deactivate
      activate_item_window
      @confirm_window.unselect
    else
      # 取消操作
      on_confirm_cancel
    end
  end
  #--------------------------------------------------------------------------
  # ● 确认窗口[取消]
  #--------------------------------------------------------------------------
  def on_confirm_cancel
    Sound.play_cancel
    @confirm_window.hide.deactivate  # 同时停用窗口
    activate_item_window
    @confirm_window.unselect        # 清除选择状态
  end

  # 新增激活技能窗口方法
  def activate_item_window
    @item_window.activate.refresh  # 强制刷新窗口
  end
end

#==============================================================================
# ■ Game_Actor
#==============================================================================
class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化(新增初始化方法)
  #--------------------------------------------------------------------------
  alias _initialize_copy initialize
  def initialize(actor_id)
    _initialize_copy(actor_id)
    @copy_skills ||= []  # 确保副本技能数组初始化
  end
  #--------------------------------------------------------------------------
  # ● スキルを忘れる
  #--------------------------------------------------------------------------

  #--------------------------------------------------------------------------
  # ● スキルを忘れる(修复后的方法)
  #--------------------------------------------------------------------------
  alias _forget_skill_copy forget_skill
  def forget_skill(skill_id)
    _forget_skill_copy(skill_id)
    @copy_skills.delete(skill_id) if @copy_skills  # 增加存在性检查
  end
end

#==============================================================================
# ■ Window_Selectable
#==============================================================================
class Window_Selectable < Window_Base
  #--------------------------------------------------------------------------
  # ● 決定やキャンセルなどのハンドリング処理
  #--------------------------------------------------------------------------
  def process_handling
    return unless open? && active
    return process_ok       if ok_enabled?        && Input.trigger?(:C)
    return process_cancel   if cancel_enabled?    && Input.trigger?(:B)
    return process_pagedown if handle?(:pagedown) && Input.trigger?(:R)
    return process_pageup   if handle?(:pageup)   && Input.trigger?(:L)
    return process_ctrl     if Input.trigger?(:CTRL)
  end
  #--------------------------------------------------------------------------
  # ● CTRL ボタン(CTRL)が押されたときの処理
  #--------------------------------------------------------------------------
  def process_ctrl
    Sound.play_ok
    if Time.now - (@last_ctrl_time || Time.at(0)) < 1
      Sound.play_ok
      Input.update
      call_handler(:CTRL)
      @last_ctrl_time = nil
    else
      @last_ctrl_time = Time.now
    end
  end
end

#==============================================================================
# ■ Window_ItemList
#==============================================================================
class Window_ItemList < Window_Selectable
  #--------------------------------------------------------------------------
  # ● 決定やキャンセルなどのハンドリング処理
  #--------------------------------------------------------------------------
  def process_handling
    return unless open? && active
    return call_handler(:append_ctrl) if handle?(:append_ctrl) && Input.trigger?(:CTRL)
    super
  end
end

#==============================================================================
# ■ Window_ItemNumber
#==============================================================================
class Window_ItemNumber < Window_ShopNumber
  #--------------------------------------------------------------------------
  # ● 公開インスタンス変数
  #--------------------------------------------------------------------------
  attr_reader   :number                   # 入力された個数
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize
    x = (Graphics.width - window_width) / 2
    super(x, 200, line_height * 2 + 32)
    @item = nil
    @Max = 1
    @number = 1
  end
  #--------------------------------------------------------------------------
  # ● アイテム、最大個数の設定
  #--------------------------------------------------------------------------
  def set(item, max)
    @item = item
    @max = max
    @number = 1
    refresh
  end
  #--------------------------------------------------------------------------
  # ● リフレッシュ
  #--------------------------------------------------------------------------
  def refresh
    contents.clear
    contents.draw_text(0, 0, 200, line_height, "捨てる数:")
    draw_item_name(@item, 4, line_height)
    draw_number
  end
  #--------------------------------------------------------------------------
  # ● アイテム名表示行の Y 座標
  #--------------------------------------------------------------------------
  def item_y
    line_height
  end
end

#==============================================================================
# ■ Scene_Item
#==============================================================================
class Scene_Item < Scene_ItemBase
  #--------------------------------------------------------------------------
  # ● 開始処理
  #--------------------------------------------------------------------------
  alias start_dump start
  def start
    start_dump
    create_item_dump_window
  end
  #--------------------------------------------------------------------------
  # ● アイテムウィンドウの作成
  #--------------------------------------------------------------------------
  alias create_item_window_dump create_item_window
  def create_item_window
    create_item_window_dump
    @item_window.set_handler(:append_ctrl, method(:on_item_dump))
  end
  #--------------------------------------------------------------------------
  # ● アイテム数選択ウィンドウの作成
  #--------------------------------------------------------------------------
  def create_item_dump_window
    @number_window = Window_ItemNumber.new
    @number_window.viewport = @viewport
    @number_window.hide
    @number_window.set_handler(:ok,     method(:on_number_ok))
    @number_window.set_handler(:cancel, method(:on_number_cancel))
  end
  #--------------------------------------------------------------------------
  # ● アイテム[捨てる]
  #--------------------------------------------------------------------------
  def on_item_dump
    if item_dumpable?
      Sound.play_ok
      if Time.now - (@last_ctrl_time || Time.at(0)) < 1
        Sound.play_ok
        @number_window.set(item, max_item)
        @number_window.show.activate
        @item_window.deactivate
        @last_ctrl_time = nil
      else
        @last_ctrl_time = Time.now
      end
    else
      Sound.play_buzzer
    end
  end
  #--------------------------------------------------------------------------
  # ● 個数入力[決定]
  #--------------------------------------------------------------------------
  def on_number_ok
    Sound.play_ok
    do_item_dump(@number_window.number)
    @number_window.hide
    activate_item_window
  end
  #--------------------------------------------------------------------------
  # ● 個数入力[キャンセル]
  #--------------------------------------------------------------------------
  def on_number_cancel
    Sound.play_cancel
    @number_window.hide
    activate_item_window
  end
  #--------------------------------------------------------------------------
  # ● 捨てるの実行
  #--------------------------------------------------------------------------
  def do_item_dump(number)
    $game_party.lose_item(item, number)
  end
  #--------------------------------------------------------------------------
  # ● アイテムを捨てる判定
  #--------------------------------------------------------------------------
  def item_dumpable?
    item.is_a?(RPG::Item) ? !item.key_item? : (!item.nil?)
  end
  #--------------------------------------------------------------------------
  # ● 所持数の取得
  #--------------------------------------------------------------------------
  def max_item
    $game_party.item_number(item)
  end
end[/pre]

点评

by——麻烦大佬帮忙还不要脸提要求的萌新  发表于 2025-3-4 11:17
连续删除技能时,光标会从‘确定’上消失,需要移动一次才会显示,还有光标在‘消失’上显示不全,而且光标移动是上下键,能不能改成左右  发表于 2025-3-4 11:16
太棒了,大佬完美理解了我的意图,就是脚本还有一点儿小瑕疵,算是咱不要脸的鸡蛋里挑骨头  发表于 2025-3-4 11:13

评分

参与人数 1赞 +1 收起 理由
小怪兽奇奇侠 + 1 路见不平,拔刀相助。汝乃真好汉也!.

查看全部评分

回复 1 0

使用道具 举报

梦石
0
星屑
2914
在线时间
665 小时
注册时间
2012-5-3
回帖
78

开拓者

发表于 2025-3-4 12:02:19 | 显示全部楼层
邱小谦 发表于 2025-3-3 23:49
这次应该完美了吧?测试了半天,我觉得挺好的。

#=========================================== ...

你再试试,整个都调整完了。

点评

感谢大佬,这次完美了!  发表于 2025-3-4 12:36
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部