# v1.3 选择敌人时隐藏物品窗口
# 未完全测试,如有 bug 请通过短消息告知。
class Scene_Battle
attr(:spriteset)
def create_enemy_window
@enemy_window = Window_BattleEnemyInfo.new(@spriteset)
@enemy_window.set_handler(:ok, method(:on_enemy_ok))
@enemy_window.set_handler(:cancel, method(:on_enemy_cancel))
end
alias_method :sion_mouse_choose_enemy_on_enemy_ok, :on_enemy_ok
def on_enemy_ok
if @enemy_window.index
Sound.play_ok
sion_mouse_choose_enemy_on_enemy_ok
else
Sound.play_buzzer
end
end
#方法覆盖
def on_skill_ok
@skill = @skill_window.item
BattleManager.actor.input.set_skill(@skill.id)
BattleManager.actor.last_skill.object = @skill
if !@skill.need_selection?
@skill_window.hide
next_command
elsif @skill.for_opponent?
@skill_window.hide ###
@skill_window.help_window.show ###
select_enemy_selection
else
select_actor_selection
end
end
#方法覆盖
def on_item_ok
@item = @item_window.item
BattleManager.actor.input.set_item(@item.id)
if !@item.need_selection?
@item_window.hide
next_command
elsif @item.for_opponent?
@item_window.hide ###
@item_window.help_window.show ###
select_enemy_selection
else
select_actor_selection
end
$game_party.last_item.object = @item
end
#方法覆盖
def on_enemy_cancel
@enemy_window.hide
case @actor_command_window.current_symbol
when :attack
@actor_command_window.activate
when :skill
@skill_window.show.activate ###
when :item
@item_window.show.activate ###
end
end
end
#
class Window_BattleEnemyInfo < Window_Base
attr(:index)
def choosing_color
Color.new(255, 0, 0, 150)
end
#
def initialize(spriteset)
super(0, 0, 100, fitting_height(1))
@enemy_sprites = spriteset.enemy_sprites
@handler = {}
hide
end
def set_handler(symbol, method)
@handler[symbol] = method
end
#
def update
super
if active
update_mouse_choose_enemy
update_input
end
end
def update_mouse_choose_enemy
m_x = Mouse.x; m_y = Mouse.y
mouse_enemy = @enemy_sprites.reverse.find {|s| s.mouse_at_enemy?(m_x, m_y)}
if @mouse_enemy != mouse_enemy
enemy_unchoose
@mouse_enemy = mouse_enemy
enemy_choose
end
end
#
def update_input
if Input.trigger?(:C)
if @mouse_enemy
@last_enemy = @mouse_enemy
enemy_unchoose
else
@index = nil
end
@handler[:ok].call
elsif Input.trigger?(:B)
@handler[:cancel].call
end
end
def refresh
end
#
def enemy_choose
if @mouse_enemy
@enemy_before_choose_color = @mouse_enemy.color.clone
@mouse_enemy.color = choosing_color
@index = $game_troop.alive_members.index(@mouse_enemy.battler)
name = $game_troop.alive_members[@index].name
self.width = contents.text_size(name).width + 10 + standard_padding * 2
create_contents
draw_text(0, 0, contents_width, contents_height, name, 1)
self.x = @mouse_enemy.x - width / 2
self.y = @mouse_enemy.y
open
end
end
def enemy_unchoose
if @mouse_enemy
@mouse_enemy.color = @enemy_before_choose_color
@mouse_enemy = nil
close
end
end
#
def activate
select_last_enemy
super
end
#
def hide
self.active = false
enemy_unchoose
close
super
end
def select_last_enemy
@last_enemy && @last_enemy.opacity > 0 ?
Mouse.set_pos(@last_enemy.x, @last_enemy.y - @last_enemy.height / 2) :
select_first_enemy
end
def select_first_enemy
battler = $game_troop.alive_members[0]
if battler
enemy = @enemy_sprites.find {|s| s.battler == battler}
Mouse.set_pos(enemy.x, enemy.y - enemy.height / 2)
end
end
#
def enemy
$game_troop.alive_members[@index]
end
end
class Sprite_Battler
def mouse_at_enemy?(mx, my)
dx = mx - x + ox
dy = my - y + oy
return if opacity == 0 || dx < 0 || dx > width || dy < 0 || dy > height
return bitmap.get_pixel(dx, dy).alpha > 0
end
end
class Spriteset_Battle
attr(:enemy_sprites)
end