Project1

标题: [脚本]敌人选择框替换成“移动光标” [打印本页]

作者: swbsl    时间: 2024-10-19 22:16
标题: [脚本]敌人选择框替换成“移动光标”
RUBY 代码复制
  1. class Scene_Battle < Scene_Base
  2.   #--------------------------------------------------------------------------
  3.   # * 开始目标敌人选择 - 创建选择敌人指令光标
  4.   #--------------------------------------------------------------------------
  5.   def start_target_enemy_selection
  6.     @target_enemy_window = Window_TargetEnemy.new
  7.     @target_enemy_window.back_opacity = 100  # 设置窗口不透明度
  8.     @target_enemy_window.opacity = 255       # 设置窗口内容不透明
  9.     @target_enemy_window.height = 40         # 设置窗口高度
  10.     @target_enemy_window.width = 40          # 设置窗口宽度
  11.     @target_enemy_index = 0                  # 初始化选择的敌人索引
  12.     @info_viewport.rect.x += @target_enemy_window.width
  13.     @info_viewport.ox += @target_enemy_window.width
  14.     @actor_command_window.active = false   
  15.     @target_enemies = get_alive_enemies # 获取活着的敌人
  16.     update_enemy_cursor   # 更新光标位置
  17.   end
  18.   #--------------------------------------------------------------------------
  19.   # * 获取活着的敌人实例
  20.   #--------------------------------------------------------------------------
  21.   def get_alive_enemies
  22.     alive_enemies = []
  23.     $game_troop.members.each do |enemy|
  24.       alive_enemies.push(enemy) if enemy.exist? && !enemy.dead?
  25.     end
  26.     alive_enemies
  27.   end   
  28.   #--------------------------------------------------------------------------
  29.   # * 更新目标敌人选择
  30.   #--------------------------------------------------------------------------
  31.   def update_target_enemy_selection
  32.     if Input.trigger?(Input::B)
  33.       Sound.play_cancel
  34.        @enemy_name.visible = false
  35.       end_target_enemy_selection
  36.     elsif Input.trigger?(Input::C)
  37.       Sound.play_decision
  38.       select_enemy(@target_enemies[@target_enemy_index]) if @target_enemies
  39.       end_target_enemy_selection
  40.       end_skill_selection
  41.       end_item_selection
  42.       next_actor
  43.     elsif Input.trigger?(Input::RIGHT) || Input.trigger?(Input::DOWN)
  44.       @target_enemy_index = (@target_enemy_index + 1) % @target_enemies.size if @target_enemies
  45.       @enemy_name.visible = false
  46.       update_enemy_cursor
  47.     elsif Input.trigger?(Input::LEFT) || Input.trigger?(Input::UP)
  48.       @target_enemy_index = (@target_enemy_index - 1 + @target_enemies.size) % @target_enemies.size if @target_enemies
  49.       @enemy_name.visible = false
  50.       update_enemy_cursor
  51.     end
  52.   end
  53.   #--------------------------------------------------------------------------
  54.   # * 更新敌人光标的位置和名称窗口
  55.   #--------------------------------------------------------------------------
  56.   def update_enemy_cursor
  57.     return unless @target_enemies && @target_enemies[@target_enemy_index] # 确保数组存在且有元素
  58.     enemy = @target_enemies[@target_enemy_index]  # 获取当前选中的敌人
  59.     @target_enemy_window.x = enemy.screen_x - 18  # 更新光标位置到敌人的坐标
  60.     @target_enemy_window.y = enemy.screen_y - 40
  61.     ememy = get_alive_enemies
  62.     @target_enemy_window.visible = true # 确保光标窗口可见
  63.   # 创建敌人名称显示窗口
  64.     @enemy_name = Window_Base.new(@target_enemy_window.x - 60, @target_enemy_window.y + 46, 160, 50)
  65.     @enemy_name.back_opacity = 180
  66.     @enemy_name.contents.clear
  67.     @enemy_name.contents.draw_text(0, 0, enemy.name.length * 22, 22, enemy.name)   
  68.     @enemy_name.visible = true  # 确保敌人名称可见
  69.   end
  70.   #--------------------------------------------------------------------------
  71.   # * 光标选定敌人
  72.   #--------------------------------------------------------------------------
  73.   def select_enemy(enemy)
  74.     @active_battler.action.target_index = enemy.index if enemy
  75.   end  
  76.   #--------------------------------------------------------------------------
  77.   # * 结束目标敌人选择
  78.   #--------------------------------------------------------------------------
  79.   def end_target_enemy_selection
  80.     @info_viewport.rect.x -= @target_enemy_window.width
  81.     @info_viewport.ox -= @target_enemy_window.width
  82.     @target_enemy_window.dispose
  83.     @target_enemy_window = nil
  84.     @enemy_name.dispose
  85.     @enemy_name = nil
  86.     @actor_command_window.active = true if @actor_command_window.index == 0
  87.   end
  88. end

局部截取_20241019_221117.png (209.32 KB, 下载次数: 12)

局部截取_20241019_221117.png

作者: swbsl    时间: 2024-10-20 16:27
修改功能:让“移动光标”窗口内显示敌人的状态图标。(状态显示最大数量:两排4个)

  1. class Window_TargetEnemy < Window_Base
  2.   #--------------------------------------------------------------------------
  3.   # * 初始化 敌人选择光标窗口
  4.   #--------------------------------------------------------------------------
  5.   def initialize
  6.     super(0, 0, 80, 80)
  7.     self.back_opacity = 75  # 设置窗口不透明度
  8.     self.opacity = 255       # 设置窗口内容不透明
  9.     @alive_enemies = get_alive_enemies
  10.   end
  11.   #--------------------------------------------------------------------------
  12.   # * 获取活着的敌人实例
  13.   #--------------------------------------------------------------------------
  14.   def get_alive_enemies
  15.     alive_enemies = []
  16.     $game_troop.members.each do |enemy|
  17.       alive_enemies.push(enemy) if enemy.exist? && !enemy.dead?
  18.     end
  19.     alive_enemies
  20.   end   
  21.   #--------------------------------------------------------------------------  
  22.   # * 获取并绘制敌人的状态图标
  23.   #--------------------------------------------------------------------------
  24.   def draw_enemy_state(ememy_index)
  25.     self.contents.clear
  26.     count = 0
  27.     x = 0
  28.     y = 0
  29.     for state in @alive_enemies[ememy_index].states
  30.       draw_icon(state.icon_index, x, y)
  31.       count +=1
  32.       if count == 2
  33.         x = 0
  34.         y += 24
  35.         count = 0
  36.       else
  37.         x += 24
  38.       end  
  39.     end
  40.   end
  41. end

  42. class Scene_Battle < Scene_Base
  43.   #--------------------------------------------------------------------------
  44.   # * 开始目标敌人选择 - 创建选择敌人指令光标
  45.   #--------------------------------------------------------------------------
  46.   def start_target_enemy_selection
  47.     @target_enemy_window = Window_TargetEnemy.new
  48.     @target_enemy_index = 0                  # 初始化选择的敌人索引
  49.     @info_viewport.rect.x += @target_enemy_window.width
  50.     @info_viewport.ox += @target_enemy_window.width
  51.     @actor_command_window.active = false   
  52.     @target_enemies = get_alive_enemies # 获取活着的敌人
  53.     update_enemy_cursor   # 更新光标位置
  54.   end
  55.   #--------------------------------------------------------------------------
  56.   # * 获取活着的敌人实例
  57.   #--------------------------------------------------------------------------
  58.   def get_alive_enemies
  59.     alive_enemies = []
  60.     $game_troop.members.each do |enemy|
  61.       alive_enemies.push(enemy) if enemy.exist? && !enemy.dead?
  62.     end
  63.     alive_enemies
  64.   end   
  65.   #--------------------------------------------------------------------------
  66.   # * 更新目标敌人选择
  67.   #--------------------------------------------------------------------------
  68.   def update_target_enemy_selection
  69.     if Input.trigger?(Input::B)
  70.       Sound.play_cancel
  71.        @enemy_name.visible = false
  72.       end_target_enemy_selection
  73.     elsif Input.trigger?(Input::C)
  74.       Sound.play_decision
  75.       select_enemy(@target_enemies[@target_enemy_index]) if @target_enemies
  76.       
  77.       end_target_enemy_selection
  78.       end_skill_selection
  79.       end_item_selection
  80.       next_actor
  81.     elsif Input.trigger?(Input::RIGHT) || Input.trigger?(Input::DOWN)
  82.       @target_enemy_index = (@target_enemy_index + 1) % @target_enemies.size if @target_enemies
  83.       @enemy_name.visible = false
  84.       update_enemy_cursor
  85.     elsif Input.trigger?(Input::LEFT) || Input.trigger?(Input::UP)
  86.       @target_enemy_index = (@target_enemy_index - 1 + @target_enemies.size) % @target_enemies.size if @target_enemies
  87.       @enemy_name.visible = false
  88.       update_enemy_cursor
  89.     end
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # * 更新敌人光标的位置和名称窗口
  93.   #--------------------------------------------------------------------------
  94.   def update_enemy_cursor
  95.     return unless @target_enemies && @target_enemies[@target_enemy_index] # 确保数组存在且有元素
  96.     enemy = @target_enemies[@target_enemy_index]  # 获取当前选中的敌人
  97.     @target_enemy_window.x = enemy.screen_x - 37 # 更新光标位置到敌人的坐标
  98.     @target_enemy_window.y = enemy.screen_y - 70
  99.     ememy = get_alive_enemies
  100.     @target_enemy_window.draw_enemy_state(@target_enemy_index) # 在光标窗口内部显示敌人状态图标
  101.     @target_enemy_window.visible = true # 确保光标窗口可见
  102.   # 创建敌人名称显示窗口
  103.     @enemy_name = Window_Base.new(@target_enemy_window.x - 40, @target_enemy_window.y + 78, 160, 50)
  104.     @enemy_name.back_opacity = 75
  105.     @enemy_name.opacity = 255
  106.     @enemy_name.contents.clear
  107.     @enemy_name.contents.draw_text(0, 0, enemy.name.length * 22, 22, enemy.name)   
  108.     @enemy_name.visible = true  # 确保敌人名称可见
  109.     play_animation_on_actor_character_window
  110.   end
  111.   #--------------------------------------------------------------------------
  112.   # * 光标选定敌人
  113.   #--------------------------------------------------------------------------
  114.   def select_enemy(enemy)
  115.     @active_battler.action.target_index = enemy.index if enemy
  116.   end  
  117.   #--------------------------------------------------------------------------
  118.   # * 结束目标敌人选择
  119.   #--------------------------------------------------------------------------
  120.   def end_target_enemy_selection
  121.     @info_viewport.rect.x -= @target_enemy_window.width
  122.     @info_viewport.ox -= @target_enemy_window.width
  123.     @target_enemy_window.dispose
  124.     @target_enemy_window = nil
  125.     @enemy_name.dispose
  126.     @enemy_name = nil
  127.     @actor_command_window.active = true if @actor_command_window.index == 0
  128.   end
  129. end
复制代码





欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1