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

Project1

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

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

[复制链接]

Lv3.寻梦者

梦石
0
星屑
1712
在线时间
98 小时
注册时间
2017-9-5
帖子
173
跳转到指定楼层
1
发表于 2025-3-3 18:38:43 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 间桐樱 于 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

Lv3.寻梦者

梦石
0
星屑
2364
在线时间
606 小时
注册时间
2012-5-3
帖子
102

开拓者

2
发表于 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
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2364
在线时间
606 小时
注册时间
2012-5-3
帖子
102

开拓者

3
发表于 2025-3-3 23:49:30 | 只看该作者
本帖最后由 邱小谦 于 2025-3-4 12:01 编辑

这次应该完美了吧?测试了半天,我觉得挺好的。
RUBY 代码复制
  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.     @item_max = 2
  9.     @column_max = 2
  10.     @item_width = 120
  11.     refresh
  12.   end
  13.  
  14.   def unselect
  15.     self.index = -1
  16.   end
  17.  
  18.   # 添加item_max方法覆盖
  19.   def item_max
  20.     2
  21.   end
  22.  
  23.  
  24.  
  25.   # 新增:覆盖方向键处理逻辑
  26.   def cursor_right(wrap = false)
  27.     if index % @column_max < @column_max - 1
  28.       select((index + 1) % @item_max)
  29.     end
  30.   end
  31.  
  32.   def cursor_left(wrap = false)
  33.     if index % @column_max > 0
  34.       select((index - 1) % @item_max)
  35.     end
  36.   end
  37.  
  38.   # 修改:恢复上下键功能但限制移动
  39.   def cursor_down(wrap = false)
  40.     # 禁用垂直移动
  41.   end
  42.  
  43.   def cursor_up(wrap = false)
  44.     # 禁用垂直移动
  45.   end
  46.  
  47.   # 修改:调整光标移动判断
  48.   def cursor_movable?
  49.     return false unless super
  50.     return false if @cursor_all
  51.     (index % @column_max > 0 && Input.repeat?(:LEFT)) ||
  52.     (index % @column_max < @column_max - 1 && Input.repeat?(:RIGHT))
  53.   end
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.   def refresh
  69.     contents.clear
  70.     # 绘制标题(添加居中参数)
  71.     draw_text(0, 0, 240, line_height, "是否忘记该技能?", 1)
  72.  
  73.     # 使用循环绘制可选项(添加居中参数)
  74.     @item_max.times do |i|
  75.       rect = item_rect(i)
  76.       text = i == 0 ? "确认" : "取消"
  77.       draw_text(rect, text, 1)  # 使用矩形区域和居中参数
  78.     end
  79.   end
  80.   # 修正光标矩形计算方法
  81.   def item_rect(index)
  82.     rect = Rect.new
  83.     rect.width = @item_width
  84.     rect.height = line_height
  85.     rect.x = index % @column_max * (rect.width + 0)  # 列间距为0
  86.     rect.y = line_height * 2  # 标题下方留两行空间
  87.     rect
  88.   end
  89.  
  90.   # 重写绘制光标方法
  91.   def draw_cursor(index)
  92.     rect = item_rect(index)
  93.     text = index == 0 ? "确认" : "取消"
  94.  
  95.     # 获取实际文字尺寸
  96.     text_width = text_size(text).width + 8  # 增加边距
  97.     text_height = line_height * 0.8
  98.  
  99.     # 计算居中坐标
  100.     cursor_x = rect.x + (rect.width - text_width) / 2
  101.     cursor_y = rect.y + (rect.height - text_height) / 2
  102.  
  103.     draw_cursor_rect(cursor_x, cursor_y, text_width, text_height)
  104.   end
  105.  
  106.   # 重写绘制项目方法,调用调整后的光标绘制方法
  107.   def draw_item(index)
  108.     rect = item_rect(index)
  109.     text = index == 0 ? "确认" : "取消"
  110.     draw_text(rect.x, rect.y, rect.width, rect.height, text)
  111.     if index == self.index
  112.       draw_cursor(index)
  113.     end
  114.   end
  115.  
  116.   #  # 重写 update_cursor 方法
  117.   def update_cursor
  118.     if index >= 0
  119.       rect = item_rect(index)
  120.       text = index == 0 ? "确认" : "取消"
  121.  
  122.       text_width = text_size(text).width + 8
  123.       text_height = line_height * 0.8
  124.  
  125.       cursor_x = rect.x + (rect.width - text_width) / 2
  126.       cursor_y = rect.y + (rect.height - text_height) / 2
  127.  
  128.       self.cursor_rect.set(cursor_x, cursor_y, text_width, text_height)
  129.     else
  130.       self.cursor_rect.empty
  131.     end
  132.   end
  133.  
  134.  
  135.  
  136.   # 简化绘制项目方法
  137.   def draw_item(index)
  138.     rect = item_rect(index)
  139.     text = index == 0 ? "确认" : "取消"
  140.     draw_text(rect, text, 1)  # 使用矩形区域和居中参数
  141.   end
  142. end
  143.  
  144. # 以下部分代码保持不变
  145. #==============================================================================
  146. # ■ Scene_Skill
  147. #==============================================================================
  148. class Scene_Skill < Scene_ItemBase
  149.   #--------------------------------------------------------------------------
  150.   # ● 开始处理(新增确认窗口创建)
  151.   #--------------------------------------------------------------------------
  152.   alias start_skill_confirm start
  153.   def start
  154.     start_skill_confirm
  155.     create_skill_confirm_window
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # ● 创建技能确认窗口
  159.   #--------------------------------------------------------------------------
  160.   def create_skill_confirm_window
  161.     @confirm_window = Window_SkillConfirm.new
  162.     @confirm_window.viewport = @viewport
  163.     @confirm_window.hide.deactivate  # 增加deactivate
  164.     @confirm_window.hide
  165.     @confirm_window.set_handler(:ok,     method(:on_confirm_ok))
  166.     @confirm_window.set_handler(:cancel, method(:on_confirm_cancel))
  167.     @confirm_window.select(0)  # 添加默认选择项
  168.   end
  169.   #--------------------------------------------------------------------------
  170.   # ● アイテムウィンドウの作成
  171.   #--------------------------------------------------------------------------
  172.   def create_item_window
  173.     wx = 0
  174.     wy = @status_window.y + @status_window.height
  175.     ww = Graphics.width
  176.     wh = Graphics.height - wy
  177.     @item_window = Window_SkillList.new(wx, wy, ww, wh)
  178.     @item_window.actor = @actor
  179.     @item_window.viewport = @viewport
  180.     @item_window.help_window = @help_window
  181.     @item_window.set_handler(:ok,     method(:on_item_ok))
  182.     @item_window.set_handler(:cancel, method(:on_item_cancel))
  183.     @item_window.set_handler(:CTRL,   method(:on_item_del))
  184.     @command_window.skill_window = @item_window
  185.   end
  186.   #--------------------------------------------------------------------------
  187.   # ● スキルを忘れる(修改后的版本)
  188.   #--------------------------------------------------------------------------
  189.   def on_item_del
  190.     if !item.nil?
  191.       Sound.play_ok
  192.       @confirm_window.show.activate
  193.       @confirm_window.select(0)  # 新增这行重置选择状态
  194.       @item_window.deactivate
  195.     else
  196.       Sound.play_buzzer
  197.     end
  198.   end
  199.  
  200.   #--------------------------------------------------------------------------
  201.   # ● 确认窗口[确定]
  202.   #--------------------------------------------------------------------------
  203.   # 修改 Scene_Skill 中的 on_confirm_ok 方法
  204.   def on_confirm_ok
  205.     # 根据当前选中的索引判断操作
  206.     if @confirm_window.index == 0
  207.       # 确认操作
  208.       skill_id = item.id
  209.       @actor.forget_skill(skill_id)
  210.       @item_window.refresh
  211.       Sound.play_ok
  212.       @confirm_window.hide.deactivate
  213.       activate_item_window
  214.       @confirm_window.unselect
  215.     else
  216.       # 取消操作
  217.       on_confirm_cancel
  218.     end
  219.   end
  220.   #--------------------------------------------------------------------------
  221.   # ● 确认窗口[取消]
  222.   #--------------------------------------------------------------------------
  223.   def on_confirm_cancel
  224.     Sound.play_cancel
  225.     @confirm_window.hide.deactivate  # 同时停用窗口
  226.     activate_item_window
  227.     @confirm_window.unselect        # 清除选择状态
  228.   end
  229.  
  230.   # 新增激活技能窗口方法
  231.   def activate_item_window
  232.     @item_window.activate.refresh  # 强制刷新窗口
  233.   end
  234. end
  235.  
  236. #==============================================================================
  237. # ■ Game_Actor
  238. #==============================================================================
  239. class Game_Actor < Game_Battler
  240.   #--------------------------------------------------------------------------
  241.   # ● オブジェクト初期化(新增初始化方法)
  242.   #--------------------------------------------------------------------------
  243.   alias _initialize_copy initialize
  244.   def initialize(actor_id)
  245.     _initialize_copy(actor_id)
  246.     @copy_skills ||= []  # 确保副本技能数组初始化
  247.   end
  248.   #--------------------------------------------------------------------------
  249.   # ● スキルを忘れる
  250.   #--------------------------------------------------------------------------
  251.  
  252.   #--------------------------------------------------------------------------
  253.   # ● スキルを忘れる(修复后的方法)
  254.   #--------------------------------------------------------------------------
  255.   alias _forget_skill_copy forget_skill
  256.   def forget_skill(skill_id)
  257.     _forget_skill_copy(skill_id)
  258.     @copy_skills.delete(skill_id) if @copy_skills  # 增加存在性检查
  259.   end
  260. end
  261.  
  262. #==============================================================================
  263. # ■ Window_Selectable
  264. #==============================================================================
  265. class Window_Selectable < Window_Base
  266.   #--------------------------------------------------------------------------
  267.   # ● 決定やキャンセルなどのハンドリング処理
  268.   #--------------------------------------------------------------------------
  269.   def process_handling
  270.     return unless open? && active
  271.     return process_ok       if ok_enabled?        && Input.trigger?(:C)
  272.     return process_cancel   if cancel_enabled?    && Input.trigger?(:B)
  273.     return process_pagedown if handle?(:pagedown) && Input.trigger?(:R)
  274.     return process_pageup   if handle?(:pageup)   && Input.trigger?(:L)
  275.     return process_ctrl     if Input.trigger?(:CTRL)
  276.   end
  277.   #--------------------------------------------------------------------------
  278.   # ● CTRL ボタン(CTRL)が押されたときの処理
  279.   #--------------------------------------------------------------------------
  280.   def process_ctrl
  281.     Sound.play_ok
  282.     if Time.now - (@last_ctrl_time || Time.at(0)) < 1
  283.       Sound.play_ok
  284.       Input.update
  285.       call_handler(:CTRL)
  286.       @last_ctrl_time = nil
  287.     else
  288.       @last_ctrl_time = Time.now
  289.     end
  290.   end
  291. end
  292.  
  293. #==============================================================================
  294. # ■ Window_ItemList
  295. #==============================================================================
  296. class Window_ItemList < Window_Selectable
  297.   #--------------------------------------------------------------------------
  298.   # ● 決定やキャンセルなどのハンドリング処理
  299.   #--------------------------------------------------------------------------
  300.   def process_handling
  301.     return unless open? && active
  302.     return call_handler(:append_ctrl) if handle?(:append_ctrl) && Input.trigger?(:CTRL)
  303.     super
  304.   end
  305. end
  306.  
  307. #==============================================================================
  308. # ■ Window_ItemNumber
  309. #==============================================================================
  310. class Window_ItemNumber < Window_ShopNumber
  311.   #--------------------------------------------------------------------------
  312.   # ● 公開インスタンス変数
  313.   #--------------------------------------------------------------------------
  314.   attr_reader   :number                   # 入力された個数
  315.   #--------------------------------------------------------------------------
  316.   # ● オブジェクト初期化
  317.   #--------------------------------------------------------------------------
  318.   def initialize
  319.     x = (Graphics.width - window_width) / 2
  320.     super(x, 200, line_height * 2 + 32)
  321.     @item = nil
  322.     @Max = 1
  323.     @number = 1
  324.   end
  325.   #--------------------------------------------------------------------------
  326.   # ● アイテム、最大個数の設定
  327.   #--------------------------------------------------------------------------
  328.   def set(item, max)
  329.     @item = item
  330.     @max = max
  331.     @number = 1
  332.     refresh
  333.   end
  334.   #--------------------------------------------------------------------------
  335.   # ● リフレッシュ
  336.   #--------------------------------------------------------------------------
  337.   def refresh
  338.     contents.clear
  339.     contents.draw_text(0, 0, 200, line_height, "捨てる数:")
  340.     draw_item_name(@item, 4, line_height)
  341.     draw_number
  342.   end
  343.   #--------------------------------------------------------------------------
  344.   # ● アイテム名表示行の Y 座標
  345.   #--------------------------------------------------------------------------
  346.   def item_y
  347.     line_height
  348.   end
  349. end
  350.  
  351. #==============================================================================
  352. # ■ Scene_Item
  353. #==============================================================================
  354. class Scene_Item < Scene_ItemBase
  355.   #--------------------------------------------------------------------------
  356.   # ● 開始処理
  357.   #--------------------------------------------------------------------------
  358.   alias start_dump start
  359.   def start
  360.     start_dump
  361.     create_item_dump_window
  362.   end
  363.   #--------------------------------------------------------------------------
  364.   # ● アイテムウィンドウの作成
  365.   #--------------------------------------------------------------------------
  366.   alias create_item_window_dump create_item_window
  367.   def create_item_window
  368.     create_item_window_dump
  369.     @item_window.set_handler(:append_ctrl, method(:on_item_dump))
  370.   end
  371.   #--------------------------------------------------------------------------
  372.   # ● アイテム数選択ウィンドウの作成
  373.   #--------------------------------------------------------------------------
  374.   def create_item_dump_window
  375.     @number_window = Window_ItemNumber.new
  376.     @number_window.viewport = @viewport
  377.     @number_window.hide
  378.     @number_window.set_handler(:ok,     method(:on_number_ok))
  379.     @number_window.set_handler(:cancel, method(:on_number_cancel))
  380.   end
  381.   #--------------------------------------------------------------------------
  382.   # ● アイテム[捨てる]
  383.   #--------------------------------------------------------------------------
  384.   def on_item_dump
  385.     if item_dumpable?
  386.       Sound.play_ok
  387.       if Time.now - (@last_ctrl_time || Time.at(0)) < 1
  388.         Sound.play_ok
  389.         @number_window.set(item, max_item)
  390.         @number_window.show.activate
  391.         @item_window.deactivate
  392.         @last_ctrl_time = nil
  393.       else
  394.         @last_ctrl_time = Time.now
  395.       end
  396.     else
  397.       Sound.play_buzzer
  398.     end
  399.   end
  400.   #--------------------------------------------------------------------------
  401.   # ● 個数入力[決定]
  402.   #--------------------------------------------------------------------------
  403.   def on_number_ok
  404.     Sound.play_ok
  405.     do_item_dump(@number_window.number)
  406.     @number_window.hide
  407.     activate_item_window
  408.   end
  409.   #--------------------------------------------------------------------------
  410.   # ● 個数入力[キャンセル]
  411.   #--------------------------------------------------------------------------
  412.   def on_number_cancel
  413.     Sound.play_cancel
  414.     @number_window.hide
  415.     activate_item_window
  416.   end
  417.   #--------------------------------------------------------------------------
  418.   # ● 捨てるの実行
  419.   #--------------------------------------------------------------------------
  420.   def do_item_dump(number)
  421.     $game_party.lose_item(item, number)
  422.   end
  423.   #--------------------------------------------------------------------------
  424.   # ● アイテムを捨てる判定
  425.   #--------------------------------------------------------------------------
  426.   def item_dumpable?
  427.     item.is_a?(RPG::Item) ? !item.key_item? : (!item.nil?)
  428.   end
  429.   #--------------------------------------------------------------------------
  430.   # ● 所持数の取得
  431.   #--------------------------------------------------------------------------
  432.   def max_item
  433.     $game_party.item_number(item)
  434.   end
  435. end

点评

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

评分

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

查看全部评分

回复 支持 1 反对 0

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
2364
在线时间
606 小时
注册时间
2012-5-3
帖子
102

开拓者

4
发表于 7 天前 | 只看该作者
邱小谦 发表于 2025-3-3 23:49
这次应该完美了吧?测试了半天,我觉得挺好的。

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

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

点评

感谢大佬,这次完美了!  发表于 7 天前
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2025-3-11 01:24

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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