class Scene_Battle < Scene_Base
#--------------------------------------------------------------------------
# * 开始目标敌人选择 - 创建选择敌人指令光标
#--------------------------------------------------------------------------
def start_target_enemy_selection
@target_enemy_window = Window_TargetEnemy.new
@target_enemy_window.back_opacity = 100 # 设置窗口不透明度
@target_enemy_window.opacity = 255 # 设置窗口内容不透明
@target_enemy_window.height = 40 # 设置窗口高度
@target_enemy_window.width = 40 # 设置窗口宽度
@target_enemy_index = 0 # 初始化选择的敌人索引
@info_viewport.rect.x += @target_enemy_window.width
@info_viewport.ox += @target_enemy_window.width
@actor_command_window.active = false
@target_enemies = get_alive_enemies # 获取活着的敌人
update_enemy_cursor # 更新光标位置
end
#--------------------------------------------------------------------------
# * 获取活着的敌人实例
#--------------------------------------------------------------------------
def get_alive_enemies
alive_enemies = []
$game_troop.members.each do |enemy|
alive_enemies.push(enemy) if enemy.exist? && !enemy.dead?
end
alive_enemies
end
#--------------------------------------------------------------------------
# * 更新目标敌人选择
#--------------------------------------------------------------------------
def update_target_enemy_selection
if Input.trigger?(Input::B)
Sound.play_cancel
@enemy_name.visible = false
end_target_enemy_selection
elsif Input.trigger?(Input::C)
Sound.play_decision
select_enemy(@target_enemies[@target_enemy_index]) if @target_enemies
end_target_enemy_selection
end_skill_selection
end_item_selection
next_actor
elsif Input.trigger?(Input::RIGHT) || Input.trigger?(Input::DOWN)
@target_enemy_index = (@target_enemy_index + 1) % @target_enemies.size if @target_enemies
@enemy_name.visible = false
update_enemy_cursor
elsif Input.trigger?(Input::LEFT) || Input.trigger?(Input::UP)
@target_enemy_index = (@target_enemy_index - 1 + @target_enemies.size) % @target_enemies.size if @target_enemies
@enemy_name.visible = false
update_enemy_cursor
end
end
#--------------------------------------------------------------------------
# * 更新敌人光标的位置和名称窗口
#--------------------------------------------------------------------------
def update_enemy_cursor
return unless @target_enemies && @target_enemies[@target_enemy_index] # 确保数组存在且有元素
enemy = @target_enemies[@target_enemy_index] # 获取当前选中的敌人
@target_enemy_window.x = enemy.screen_x - 18 # 更新光标位置到敌人的坐标
@target_enemy_window.y = enemy.screen_y - 40
ememy = get_alive_enemies
@target_enemy_window.visible = true # 确保光标窗口可见
# 创建敌人名称显示窗口
@enemy_name = Window_Base.new(@target_enemy_window.x - 60, @target_enemy_window.y + 46, 160, 50)
@enemy_name.back_opacity = 180
@enemy_name.contents.clear
@enemy_name.contents.draw_text(0, 0, enemy.name.length * 22, 22, enemy.name)
@enemy_name.visible = true # 确保敌人名称可见
end
#--------------------------------------------------------------------------
# * 光标选定敌人
#--------------------------------------------------------------------------
def select_enemy(enemy)
@active_battler.action.target_index = enemy.index if enemy
end
#--------------------------------------------------------------------------
# * 结束目标敌人选择
#--------------------------------------------------------------------------
def end_target_enemy_selection
@info_viewport.rect.x -= @target_enemy_window.width
@info_viewport.ox -= @target_enemy_window.width
@target_enemy_window.dispose
@target_enemy_window = nil
@enemy_name.dispose
@enemy_name = nil
@actor_command_window.active = true if @actor_command_window.index == 0
end
end