#==============================================================================
# +++ MOG - Battle Hud EX (v6.6) +++
#==============================================================================
# By Moghunter
# [url]https://atelierrgss.wordpress.com/[/url]
#==============================================================================
#
# Coloque as imagens da hud na pasta.
#
# Graphics/Huds/Battle/
#==============================================================================
# Para ocultar ou apresentar a hud de batalha use o código abaixo.
#
# battle_hud_visible(false)
#
# ou
#
# battle_hud_visible(true)
#
#==============================================================================
# Para mudar o sprite da face do battler use o código abaixo.
#==============================================================================
#
# battler_face_name( ACTOR_ID, FIlE_NAME )
#
#==============================================================================
 
#==============================================================================
# Atualizações desta versão. 
#==============================================================================
# (ver 6.6)
#      - Correção do Crash caso optar por desativar o layout das janelas.
# (ver 6.5) 
#      - Melhoria no cálculo da posição Z.
#      - Correção de travar o menu.
# (ver 6.4)
#      - Correção do glitch de aparecer um pedaço da Windowskin quando se
#        usa mais de 4 battlers na batalha.
# (ver 6.3)
#      - Compatibilidade com o MOG Battle Camera.
# (ver 6.2)
#     - Refresh da hud ao trocar a posição dos personagens.
# (ver 6.0)
#     - Adição da camada da tela.
#     - Adição do efeito Slide.
#     - Adição de novas opções referente a fonte.
#==============================================================================
 
$imported = {} if $imported.nil?
$imported[:mog_battle_hud_ex] = true
 
module MOG_BATTLE_HUD_EX  
 
  #============================================================================
  #============================================================================
  # * HUD SPRITE (GENERAL)
  #============================================================================
  # Definição da quantidade maxima de personagens na batalha.
  #---------------------------------------------------------------------------
  MAX_BATTLE_MEMBERS = 3
  #---------------------------------------------------------------------------
  # Definição da prioridade da hud.
  #---------------------------------------------------------------------------
  HUD_Z = 110 #110
  #---------------------------------------------------------------------------
  # Definição da posição geral da hud, influência em todos os sprites da hud.
  #---------------------------------------------------------------------------
  HUD_POSITION = [-100,310]
  #---------------------------------------------------------------------------
  # Definição do espaço entre os membros do grupo.
  # (Use apenas para ajustes)
  #---------------------------------------------------------------------------
  MEMBERS_SPACE = [-24,0]
  #---------------------------------------------------------------------------
  # Definição fixa da hud se deseja posicionar a hud em lugares
  # específicos da tela.
  #
  # FIXED_POSITION[INDEX_ID] = [X,Y]
  #
  #---------------------------------------------------------------------------
  FIXED_HUD_POSITION = []
  # FIXED_HUD_POSITION[0] = [10,50]
  # FIXED_HUD_POSITION[1] = [440,50]
  # FIXED_HUD_POSITION[2] = [10,330]
  # FIXED_HUD_POSITION[3] = [440,330]
  #---------------------------------------------------------------------------
  # Definição da posição do comando quando a opção de janelas fixa é ativada.
  #---------------------------------------------------------------------------
  FIXED_COMMAND_POSITION = []
   FIXED_COMMAND_POSITION[0] = [10,350]
  # FIXED_COMMAND_POSITION[1] = [300,10]
  # FIXED_COMMAND_POSITION[2] = [130,290]
  # FIXED_COMMAND_POSITION[3] = [300,290]
  #---------------------------------------------------------------------------
  # Ocultar a HUD quando a janela de mensagem está ativa.
  #---------------------------------------------------------------------------
  MESSAGE_WINDOW_FADE_HUD = false
  #---------------------------------------------------------------------------
  # Definição da posição da janela de mensagem.
  #---------------------------------------------------------------------------
  # 0 - Acima
  # 1 - Centro
  # 2 - Abaixo
  #---------------------------------------------------------------------------
  BATTLE_MESSAGE_POSITION = 2  
  #---------------------------------------------------------------------------
  # Definição da porcentagem do parâmetro baixo, isso influência na cor
  # do número dos parâmetros de HP, MP e TP.
  #---------------------------------------------------------------------------
  LOW_PARAMETER_PERCENTAGE = 30
  #============================================================================
  #============================================================================
 
 
  #============================================================================
  #============================================================================
  # * NAME
  #============================================================================
  # Ativar o Sprite do nome do personagem.
  #---------------------------------------------------------------------------
  NAME_VISIBLE = false
  #---------------------------------------------------------------------------
  # Definição da prioridade do Sprite.
  #---------------------------------------------------------------------------  
  NAME_Z = 5
  #---------------------------------------------------------------------------
  # Definição da posição da Face. [X,Y]
  #---------------------------------------------------------------------------
  NAME_POSITION = [-40,103]
  #---------------------------------------------------------------------------
  # Definição do tipo alinhamento do nome.
  #
  # 0 - Esquerda
  # 1 - Centro
  # 2 - Direita
  #---------------------------------------------------------------------------  
  NAME_ALIGN_TYPE = 1
  #---------------------------------------------------------------------------
  # Definição do nome da fonte.
  #--------------------------------------------------------------------------- 
  NAME_FONT_NAME = "Lolita"
  #---------------------------------------------------------------------------
  # Definição do tamanho da fonte.
  #---------------------------------------------------------------------------   
  NAME_FONT_SIZE = 16
  #---------------------------------------------------------------------------
  # Ativar Bold.
  #---------------------------------------------------------------------------   
  NAME_FONT_BOLD = true
  #---------------------------------------------------------------------------
  # Ativar Italic.
  #---------------------------------------------------------------------------   
  NAME_FONT_ITALIC = true
  #---------------------------------------------------------------------------
  # Definição da cor da fonte
  #---------------------------------------------------------------------------     
  NAME_FONT_COLOR = Color.new(255,255,255,255)
  #---------------------------------------------------------------------------
  # Ativar Sombra
  #---------------------------------------------------------------------------  
  NAME_FONT_SHADOW = false
  #---------------------------------------------------------------------------
  # Definição da cor da sombra
  #---------------------------------------------------------------------------    
  NAME_FONT_SHADOW_COLOR = Color.new(0,0,0,255)
  #---------------------------------------------------------------------------
  # Definição da distância da sombra. 
  #---------------------------------------------------------------------------    
  NAME_FONT_SHADOW_POSITION = [2,2]  
  #============================================================================
  #============================================================================
 
 
  #============================================================================
  #============================================================================
  # * FACE
  #============================================================================
  # Ativar a face.
  # Será necessário o arquivo.
  #
  # ACTOR_NAME + _Face.png
  #
  # Eric_Face.png
  #
  #---------------------------------------------------------------------------
  FACE_VISIBLE = true
  # Ativar as Faces representando os battlers.
  # Deixe "false" se tiver problemas de compatibilidade com scripts.
  FACE_BATTLER = true
  #---------------------------------------------------------------------------
  # Definição da prioridade do sprite.
  #---------------------------------------------------------------------------  
  FACE_Z = -1 # 100
  #---------------------------------------------------------------------------
  # Definição da posição da Face. [X,Y]
  #---------------------------------------------------------------------------
  FACE_POSITION = [350,0] #[330,0]
  #---------------------------------------------------------------------------
  # Ativar faces animadas.
  # Será necessário ter uma imagem de 4 faces do personagem no mesmo arquivo.
  #
  # FACE1/FACE2/FACE3/FACE4
  #
  # A imagem será dividida por 4 frames, no caso de definir a função como FALSE
  # a imagem será dividida por 1 frame
  #---------------------------------------------------------------------------  
  FACE_ANIMATION = true
  #---------------------------------------------------------------------------
  # Ativar o efeito de Zoom quando o personagem usar alguma ação.
  #---------------------------------------------------------------------------
  FACE_ZOOM_ANIMATION = false
  #---------------------------------------------------------------------------
  # Ativar o efeito Mirror na animação de ação do personagem.
  #---------------------------------------------------------------------------
  FACE_ZOOM_MIRROR_EFFECT = false
  #---------------------------------------------------------------------------
  # Definição do tempo duração da animação da face.
  #---------------------------------------------------------------------------  
  FACE_ANIMATION_DURATION = 40
  #---------------------------------------------------------------------------
  # Ativar o efeito tremor da face quando o personagem sofrer dano.
  #---------------------------------------------------------------------------  
  FACE_SHAKE_EFFECT = true
  #============================================================================
  #============================================================================
 
  #============================================================================
  #============================================================================
  # * TURN (ACTIVE INDICATOR)
  #============================================================================
  # Ativar o indicador de turno do personagem.
  # Será necessário o arquivo.
  #
  # Turn.png
  #
  #---------------------------------------------------------------------------
  TURN_SPRITE_VISIBLE = false
  #---------------------------------------------------------------------------
  # Definição da prioridade do Sprite.
  #---------------------------------------------------------------------------    
  TURN_SPRITE_Z = 0
  #---------------------------------------------------------------------------
  # Definição da posição do sprite de turno.
  #---------------------------------------------------------------------------  
  TURN_SPRITE_POSITION = [-5,-47]
  #---------------------------------------------------------------------------  
  # Ativar o efeito de animação de piscar.
  #---------------------------------------------------------------------------  
  TURN_BLINK_EFFECT = true
  #---------------------------------------------------------------------------  
 
  #============================================================================
  #============================================================================
  # * HP
  #============================================================================
  # Ativar o número de HP.
  # Será necessário o arquivo.
  #
  # HP_Number.png
  #
  #---------------------------------------------------------------------------
  HP_NUMBER_VISIBLE = true
  #---------------------------------------------------------------------------
  # Definição da prioridade do Sprite.
  #---------------------------------------------------------------------------    
  HP_NUMBER_Z = 2
  #---------------------------------------------------------------------------
  # Definição da posição do número de HP. [X,Y]
  #---------------------------------------------------------------------------  
  HP_NUMBER_POSITION = [114,21] #[110,17]
  #---------------------------------------------------------------------------  
  # Ativar o número de HP Total.
  # Será necessário o arquivo.
  #
  # HP_Number_Max.png
  #
  #---------------------------------------------------------------------------
  HP_NUMBER_MAX_VISIBLE = false
  #---------------------------------------------------------------------------
  # Definição da posição do número de HP Total. [X,Y]
  #---------------------------------------------------------------------------  
  HP_NUMBER_MAX_POSITION = [88,64]
  #---------------------------------------------------------------------------
  # Definição do tipo alinhamento do número.
  #
  # 0 - Esquerda
  # 1 - Centro
  # 2 - Direita
  #---------------------------------------------------------------------------  
  HP_NUMBER_ALIGN_TYPE = 1
  #---------------------------------------------------------------------------
  # Ativa o efeito de alinhar os números em posições de Y diferentes.
  #---------------------------------------------------------------------------
  HP_NUMBER_WAVE_ALIGN_EFFECT = false
  #---------------------------------------------------------------------------
  # Apresentar os números em porcentagem.
  #---------------------------------------------------------------------------    
  HP_NUMBER_PERCENTAGE = false
  #---------------------------------------------------------------------------
  # Ativar números animados ("Rolantes").
  #---------------------------------------------------------------------------  
  HP_NUMBER_ANIMATION = true
  #---------------------------------------------------------------------------
  # Ativar a cor do HP baixo.
  # Será necessário ter a imagem com as duas cores do paramêtro no mesmo 
  # arquivo de imagem, a imagem será dividida por 2 frames de altura.
  #
  # NORMAL_COLOR
  # LOW_PARAMETER_COLOR
  #
  # Caso definir a função como FALSE a imagem será dividida apenas como 
  # 1 frame de altura.
  #---------------------------------------------------------------------------  
  HP_NUMBER_LOW_COLOR = false
  #---------------------------------------------------------------------------
  # Ativar o medidor de HP.
  # Será necessário o arquivo.
  #
  # HP_Meter.png
  #  
  #---------------------------------------------------------------------------  
  HP_METER_VISIBLE = true
  #---------------------------------------------------------------------------
  # Definição da prioridade do sprite.
  #---------------------------------------------------------------------------    
  HP_METER_Z = 3
  #---------------------------------------------------------------------------
  # Definição da posição do medidor de HP. [X,Y]
  #---------------------------------------------------------------------------  
  HP_METER_POSITION = [58,44]
  #---------------------------------------------------------------------------
  # Definição do ângulo do medidor.
  #---------------------------------------------------------------------------  
  HP_METER_ANGLE = 0
  #---------------------------------------------------------------------------
  # Ativar o efeito mirror, essa opção faz com que o medidor tenha o movimento
  # inverso.
  #---------------------------------------------------------------------------  
  HP_METER_MIRROR_EFFECT = false
  #---------------------------------------------------------------------------
  # Ativar o efeito animado de dano no medidor.
  # Será necessário ter a imagem com as duas cores do paramêtro no mesmo 
  # arquivo de imagem, a imagem será dividida por 2 frames de altura.
  #
  # NORMAL_COLOR
  # DAMAGE_COLOR
  #
  # Se definir como FALSE use apenas use uma imagem com o tamanho normal.
  #---------------------------------------------------------------------------  
  HP_METER_REDUCTION_ANIMATION = true
  #---------------------------------------------------------------------------
  # Ativar o efeito animado do "medidor fluindo".
  # Será necessário ter a imagem com a largura 3 vezes maior que o tamanho normal.
  # Essa imagem dever estar em gradiente para ter o efeito "fluindo".
  # Se definir como FALSE use apenas uma imagem com o tamanho normal.
  #---------------------------------------------------------------------------  
  HP_METER_GRADIENT_ANIMATION = false
  #---------------------------------------------------------------------------
  # Ativar HP em ícones.
  # Será necessário ter a imagem. 
  #
  # HP_Icon.png
  #
  #--------------------------------------------------------------------------- 
  HP_ICON_VISIBLE = false
  #---------------------------------------------------------------------------
  # Definição da prioridade do Sprite.
  #---------------------------------------------------------------------------    
  HP_ICON_Z = 1
  #---------------------------------------------------------------------------
  # Posição do ícone de HP.
  #---------------------------------------------------------------------------  
  HP_ICON_POSITION = [200,0]
  #---------------------------------------------------------------------------
  # Ativar o sprite EX do ultimo ícone
  # Será necessário ter a imagem. 
  #
  # HP_Icon_EX.png
  #
  #--------------------------------------------------------------------------- 
  HP_ICON_EX_VISIBLE = false
  #---------------------------------------------------------------------------
  # Posição do ícone Animado.
  #---------------------------------------------------------------------------  
  HP_ICON_EX_POSITION = [0,0]
  #---------------------------------------------------------------------------
  # Ativar o efeito de Zoom do Sprite.
  #--------------------------------------------------------------------------- 
  HP_ICON_EX_ZOOM_EFFECT = true
  #---------------------------------------------------------------------------
  # Espaço entre os ícones.
  #---------------------------------------------------------------------------    
  HP_ICON_SPACE = [-10,-10]
  #---------------------------------------------------------------------------
  # Definição da quantidade maxima de ícones na horizontal.
  #---------------------------------------------------------------------------  
  HP_ICON_COL_MAX = 10
  #---------------------------------------------------------------------------
  # Definição da quantidade maxima de ícones na vertical.
  #---------------------------------------------------------------------------    
  HP_ICON_ROW_MAX = 2
  #---------------------------------------------------------------------------
  # Ativar o número de HP de ícones.
  # Será necessário ter a imagem.
  #
  # HP_Icon_Number.png
  #
  #--------------------------------------------------------------------------- 
  HP_ICON_NUMBER_VISIBLE = false
  #---------------------------------------------------------------------------
  # Definição da prioridade do sprite.
  #--------------------------------------------------------------------------- 
  HP_ICON_NUMBER_Z = 4
  #---------------------------------------------------------------------------
  # Posição do número do ícone
  #---------------------------------------------------------------------------  
  HP_ICON_NUMBER_POSITION = [0,0]
  #---------------------------------------------------------------------------
  # Definição do tipo alinhamento do número.
  #
  # 0 - Esquerda
  # 1 - Centro
  # 2 - Direita
  #---------------------------------------------------------------------------  
  HP_ICON_NUMBER_ALIGN_TYPE = 0   
  #============================================================================
  #============================================================================
 
 
  #============================================================================
  #============================================================================
  # * MP
  #============================================================================
  # Ativar o número de MP.
  # Será necessário o arquivo.
  #
  # MP_Number.png
  #  
  #---------------------------------------------------------------------------  
  MP_NUMBER_VISIBLE = true
  #---------------------------------------------------------------------------
  # Definição da prioridade do Sprite.
  #---------------------------------------------------------------------------    
  MP_NUMBER_Z = 2  
  #---------------------------------------------------------------------------
  # Definição da posição do número de MP. [X,Y]
  #---------------------------------------------------------------------------  
  MP_NUMBER_POSITION = [146,50] #[142,46]
  #---------------------------------------------------------------------------  
  # Ativar o número de MP Total.
  # Será necessário o arquivo.
  #
  # MP_Number_Max.png
  #
  #---------------------------------------------------------------------------
  MP_NUMBER_MAX_VISIBLE = false
  #---------------------------------------------------------------------------
  # Definição da posição do número de MP Total. [X,Y]
  #---------------------------------------------------------------------------  
  MP_NUMBER_MAX_POSITION = [100,48]
  #---------------------------------------------------------------------------
  # Definição do tipo alinhamento do número.
  #
  # 0 - Esquerda
  # 1 - Centro
  # 2 - Direita
  #---------------------------------------------------------------------------  
  MP_NUMBER_ALIGN_TYPE = 1
  #---------------------------------------------------------------------------
  # Ativa o efeito de alinhar os números em posições de Y diferentes.
  #---------------------------------------------------------------------------
  MP_NUMBER_WAVE_ALIGN_EFFECT = false    
  #---------------------------------------------------------------------------
  # Apresentar os números em porcentagem.
  #---------------------------------------------------------------------------    
  MP_NUMBER_PERCENTAGE = false
  #---------------------------------------------------------------------------
  # Ativar números animados ("Rolantes").
  #---------------------------------------------------------------------------  
  MP_NUMBER_ANIMATION = true
  #---------------------------------------------------------------------------
  # Ativar a cor do MP baixo.
  # Será necessário ter a imagem com as duas cores do paramêtro no mesmo 
  # arquivo de imagem, a imagem será dividida por 2 frames de altura.
  #
  # NORMAL_COLOR
  # LOW_PARAMETER_COLOR
  #
  # Se definir como FALSE use apenas use uma imagem com o tamanho normal.
  #---------------------------------------------------------------------------  
  MP_NUMBER_LOW_COLOR = false
  #---------------------------------------------------------------------------
  # Ativar o medidor de MP.
  # Será necessário o arquivo.
  #
  # MP_Meter.png
  #    
  #---------------------------------------------------------------------------  
  MP_METER_VISIBLE = true
  #---------------------------------------------------------------------------
  # Definição da prioridade do sprite.
  #---------------------------------------------------------------------------    
  MP_METER_Z = 3
  #---------------------------------------------------------------------------
  # Definição da posição do medidor de MP. [X,Y]
  #---------------------------------------------------------------------------  
  MP_METER_POSITION = [91,73]
  #---------------------------------------------------------------------------
  # Definição do ângulo do medidor.
  #---------------------------------------------------------------------------  
  MP_METER_ANGLE = 0
  #---------------------------------------------------------------------------
  # Ativar o efeito mirror, essa opção faz com que o medidor tenha o movimento
  # inverso.
  #---------------------------------------------------------------------------  
  MP_METER_MIRROR_EFFECT = false
  #---------------------------------------------------------------------------
  # Ativar o efeito animado de dano no medidor.
  # Será necessário ter a imagem com as duas cores do paramêtro no mesmo 
  # arquivo de imagem, a imagem será dividida por 2 frames de altura.
  #
  # NORMAL_COLOR
  # DAMAGE_COLOR
  #
  # Se definir como FALSE use apenas use uma imagem com o tamanho normal.
  #---------------------------------------------------------------------------  
  MP_METER_REDUCTION_ANIMATION = true
  #---------------------------------------------------------------------------
  # Ativar o efeito animado do "medidor fluindo".
  # Será necessário ter a imagem com a largura 3 vezes maior que o tamanho normal.
  # Essa imagem dever estar em gradiente para ter o efeito "fluindo".
  # Se definir como FALSE use apenas uma imagem com o tamanho normal.
  #---------------------------------------------------------------------------  
  MP_METER_GRADIENT_ANIMATION = false
  #---------------------------------------------------------------------------
  # Ativar MP em ícones.
  # Será necessário ter a imagem. 
  #
  # MP_Icon.png
  #
  #--------------------------------------------------------------------------- 
  MP_ICON_VISIBLE = false
  #---------------------------------------------------------------------------
  # Definição da prioridade do Sprite.
  #---------------------------------------------------------------------------    
  MP_ICON_Z = 1  
  #---------------------------------------------------------------------------
  # Posição do ícone de MP.
  #---------------------------------------------------------------------------  
  MP_ICON_POSITION = [200,64]
  #---------------------------------------------------------------------------
  # Ativar o sprite EX do ultimo ícone
  # Será necessário ter a imagem. 
  #
  # MP_Icon_EX.png
  #
  #--------------------------------------------------------------------------- 
  MP_ICON_EX_VISIBLE = false
  #---------------------------------------------------------------------------
  # Posição do ícone Animado.
  #---------------------------------------------------------------------------  
  MP_ICON_EX_POSITION = [0,0]
  #---------------------------------------------------------------------------
  # Ativar o efeito de Zoom do Sprite.
  #--------------------------------------------------------------------------- 
  MP_ICON_EX_ZOOM_EFFECT = true
  #---------------------------------------------------------------------------
  # Espaço entre os ícones.
  #---------------------------------------------------------------------------    
  MP_ICON_SPACE = [-10,-10]
  #---------------------------------------------------------------------------
  # Definição da quantidade maxima de ícones na horizontal.
  #---------------------------------------------------------------------------  
  MP_ICON_COL_MAX = 10
  #---------------------------------------------------------------------------
  # Definição da quantidade maxima de ícones na vertical.
  #---------------------------------------------------------------------------    
  MP_ICON_ROW_MAX = 2
  #---------------------------------------------------------------------------
  # Ativar o número de MP de ícones.
  # Será necessário ter a imagem.
  #
  # MP_Icon_Number.png
  #
  #--------------------------------------------------------------------------- 
  MP_ICON_NUMBER_VISIBLE = false
  #---------------------------------------------------------------------------
  # Definição da prioridade do sprite.
  #--------------------------------------------------------------------------- 
  MP_ICON_NUMBER_Z = 4
  #---------------------------------------------------------------------------
  # Posição do número do ícone
  #---------------------------------------------------------------------------  
  MP_ICON_NUMBER_POSITION = [0,64]
  #---------------------------------------------------------------------------
  # Definição do tipo alinhamento do número.
  #
  # 0 - Esquerda
  # 1 - Centro
  # 2 - Direita
  #---------------------------------------------------------------------------  
  MP_ICON_NUMBER_ALIGN_TYPE = 0    
  #============================================================================
  #============================================================================
 
 
  #============================================================================
  #============================================================================
  # * TP
  #============================================================================
  # Ativar o número de TP.
  # Será necessário o arquivo.
  #
  # TP_Number.png
  #    
  #---------------------------------------------------------------------------
  TP_NUMBER_VISIBLE = true
  #---------------------------------------------------------------------------
  # Definição da prioridade do sprite.
  #--------------------------------------------------------------------------- 
  TP_NUMBER_Z = 10  
  #---------------------------------------------------------------------------
  # Definição da posição do número de TP. [X,Y]
  #---------------------------------------------------------------------------  
  TP_NUMBER_POSITION = [52,0]
  #---------------------------------------------------------------------------  
  # Ativar o número de TP Total.
  # Será necessário o arquivo.
  #
  # TP_Number_Max.png
  #
  #---------------------------------------------------------------------------
  TP_NUMBER_MAX_VISIBLE = false
  #---------------------------------------------------------------------------
  # Definição da posição do número de TP Total. [X,Y]
  #---------------------------------------------------------------------------  
  TP_NUMBER_MAX_POSITION = [165,77]
  #---------------------------------------------------------------------------
  # Definição do tipo alinhamento do número.
  #
  # 0 - Esquerda
  # 1 - Centro
  # 2 - Direita
  #---------------------------------------------------------------------------  
  TP_NUMBER_ALIGN_TYPE = 2
  #---------------------------------------------------------------------------
  # Ativa o efeito de alinhar os números em posições de Y diferentes.
  #---------------------------------------------------------------------------
  TP_NUMBER_WAVE_ALIGN_EFFECT = false   
  #---------------------------------------------------------------------------
  # Apresentar os números em porcentagem.
  #---------------------------------------------------------------------------    
  TP_NUMBER_PERCENTAGE = true
  #---------------------------------------------------------------------------
  # Ativar números animados ("Rolantes").
  #---------------------------------------------------------------------------  
  TP_NUMBER_ANIMATION = false
  #---------------------------------------------------------------------------
  # Ativar a cor do TP baixo.
  # Será necessário ter a imagem com as duas cores do paramêtro no mesmo 
  # arquivo de imagem, a imagem será dividida por 2 frames de altura.
  #
  # NORMAL_COLOR
  # LOW_PARAMETER_COLOR
  #
  # Se definir como FALSE use apenas use uma imagem com o tamanho normal.
  #---------------------------------------------------------------------------  
  TP_NUMBER_LOW_COLOR = false
  #---------------------------------------------------------------------------
  # Ativar o medidor de TP.
  # Será necessário o arquivo.
  #
  # TP_Meter.png
  #    
  #---------------------------------------------------------------------------  
  TP_METER_VISIBLE = true
  #---------------------------------------------------------------------------
  # Definição da prioridade do sprite.
  #--------------------------------------------------------------------------- 
  TP_METER_Z = 3  
  #---------------------------------------------------------------------------
  # Definição da posição do medidor de TP. [X,Y]
  #---------------------------------------------------------------------------  
  TP_METER_POSITION = [14,68]
  #---------------------------------------------------------------------------
  # Definição do ângulo do medidor.
  #---------------------------------------------------------------------------  
  TP_METER_ANGLE = 91
  #---------------------------------------------------------------------------
  # Ativar o efeito mirror, essa opção faz com que o medidor tenha o movimento
  # inverso.
  #---------------------------------------------------------------------------  
  TP_METER_MIRROR_EFFECT = false
  #---------------------------------------------------------------------------
  # Ativar o efeito animado de dano no medidor.
  # Será necessário ter a imagem com as duas cores do paramêtro no mesmo 
  # arquivo de imagem, a imagem será dividida por 2 frames de altura.
  #
  # NORMAL_COLOR
  # DAMAGE_COLOR
  #
  # Se definir como FALSE use apenas use uma imagem com o tamanho normal.
  #---------------------------------------------------------------------------  
  TP_METER_REDUCTION_ANIMATION = false
  #---------------------------------------------------------------------------
  # Ativar o efeito animado do "medidor fluindo".
  # Será necessário ter a imagem com a largura 3 vezes maior que o tamanho normal.
  # Essa imagem dever estar em gradiente para ter o efeito "fluindo".
  # Se definir como FALSE use apenas uma imagem com o tamanho normal.
  #---------------------------------------------------------------------------  
  TP_METER_GRADIENT_ANIMATION = true
  #---------------------------------------------------------------------------
  # Ativar TP em ícones.
  # Será necessário ter a imagem. 
  #
  # TP_Icon.png
  #
  #--------------------------------------------------------------------------- 
  TP_ICON_VISIBLE = false
  #---------------------------------------------------------------------------
  # Definição da prioridade do sprite.
  #--------------------------------------------------------------------------- 
  TP_ICON_Z = 1  
  #---------------------------------------------------------------------------
  # Posição do ícone de TP.
  #---------------------------------------------------------------------------  
  TP_ICON_POSITION = [200,128]
  #---------------------------------------------------------------------------
  # Ativar o sprite EX do ultimo ícone
  # Será necessário ter a imagem. 
  #
  # TP_Icon_EX.png
  #
  #--------------------------------------------------------------------------- 
  TP_ICON_EX_VISIBLE = false
  #---------------------------------------------------------------------------
  # Posição do ícone Animado.
  #---------------------------------------------------------------------------  
  TP_ICON_EX_POSITION = [0,0]
  #---------------------------------------------------------------------------
  # Ativar o efeito de Zoom do Sprite.
  #--------------------------------------------------------------------------- 
  TP_ICON_EX_ZOOM_EFFECT = true
  #---------------------------------------------------------------------------
  # Espaço entre os ícones.
  #---------------------------------------------------------------------------    
  TP_ICON_SPACE = [-10,-10]
  #---------------------------------------------------------------------------
  # Definição da quantidade maxima de ícones na horizontal.
  #---------------------------------------------------------------------------  
  TP_ICON_COL_MAX = 10
  #---------------------------------------------------------------------------
  # Definição da quantidade maxima de ícones na vertical.
  #---------------------------------------------------------------------------    
  TP_ICON_ROW_MAX = 2
  #---------------------------------------------------------------------------
  # Ativar o número de TP de ícones.
  # Será necessário ter a imagem.
  #
  # TP_Icon_Number.png
  #
  #--------------------------------------------------------------------------- 
  TP_ICON_NUMBER_VISIBLE = false
  #---------------------------------------------------------------------------
  # Definição da prioridade do sprite.
  #--------------------------------------------------------------------------- 
  TP_ICON_NUMBER_Z = 4
  #---------------------------------------------------------------------------
  # Posição do número do ícone
  #---------------------------------------------------------------------------  
  TP_ICON_NUMBER_POSITION = [0,128]
  #---------------------------------------------------------------------------
  # Definição do tipo alinhamento do número.
  #
  # 0 - Esquerda
  # 1 - Centro
  # 2 - Direita
  #---------------------------------------------------------------------------  
  TP_ICON_NUMBER_ALIGN_TYPE = 0    
  #============================================================================
  #============================================================================
 
  #============================================================================
  #============================================================================
  # * AT
  #============================================================================
  # Ativar o número de AT.
  # Será necessário o arquivo.
  #
  # AT_Number.png
  #
  #---------------------------------------------------------------------------
  AT_NUMBER_VISIBLE = false
  #---------------------------------------------------------------------------
  # Definição da prioridade do Sprite.
  #---------------------------------------------------------------------------    
  AT_NUMBER_Z = 2
  #---------------------------------------------------------------------------
  # Definição da posição do número de AT. [X,Y]
  #---------------------------------------------------------------------------  
  AT_NUMBER_POSITION = [125,-27]
  #---------------------------------------------------------------------------  
  # Ativar o número de AT Total.
  # Será necessário o arquivo.
  #
  # AT_Number_Max.png
  #
  #---------------------------------------------------------------------------
  AT_NUMBER_MAX_VISIBLE = false
  #---------------------------------------------------------------------------
  # Definição da posição do número de AT Total. [X,Y]
  #---------------------------------------------------------------------------  
  AT_NUMBER_MAX_POSITION = [165,-17]
  #---------------------------------------------------------------------------
  # Definição do tipo alinhamento do número.
  #
  # 0 - Esquerda
  # 1 - Centro
  # 2 - Direita
  #---------------------------------------------------------------------------  
  AT_NUMBER_ALIGN_TYPE = 2
  #---------------------------------------------------------------------------
  # Ativa o efeito de alinhar os números em posições de Y diferentes.
  #---------------------------------------------------------------------------
  AT_NUMBER_WAVE_ALIGN_EFFECT = false
  #---------------------------------------------------------------------------
  # Apresentar os números em porcentagem.
  #---------------------------------------------------------------------------    
  AT_NUMBER_PERCENTAGE = true
  #---------------------------------------------------------------------------
  # Ativar números animados ("Rolantes").
  #---------------------------------------------------------------------------  
  AT_NUMBER_ANIMATION = false
  #---------------------------------------------------------------------------
  # Ativar o medidor de AT.
  # Será necessário o arquivo.
  #
  # AT_Meter.png
  #  
  #---------------------------------------------------------------------------  
  AT_METER_VISIBLE = true
  #---------------------------------------------------------------------------
  # Definição da prioridade do sprite.
  #---------------------------------------------------------------------------    
  AT_METER_Z = 3
  #---------------------------------------------------------------------------
  # Definição da posição do medidor de AT. [X,Y]
  #---------------------------------------------------------------------------  
  AT_METER_POSITION = [23,60]
  #---------------------------------------------------------------------------
  # Definição do ângulo do medidor.
  #---------------------------------------------------------------------------  
  AT_METER_ANGLE = 91
  #---------------------------------------------------------------------------
  # Ativar o efeito mirror, essa opção faz com que o medidor tenha o movimento
  # inverso.
  #---------------------------------------------------------------------------  
  AT_METER_MIRROR_EFFECT = false
  #---------------------------------------------------------------------------
  # Ativar o efeito animado do "medidor fluindo".
  # Será necessário ter a imagem com a largura 3 vezes maior que o tamanho normal.
  # Essa imagem dever estar em gradiente para ter o efeito "fluindo".
  # Se definir como FALSE use apenas uma imagem com o tamanho normal.
  #---------------------------------------------------------------------------  
  AT_METER_GRADIENT_ANIMATION = true
  #============================================================================
 
 
  #============================================================================
  #============================================================================
  # * LEVEL
  #============================================================================ 
  # Ativar o número de Level.
  # Será necessário o arquivo.
  #
  # LV_Number.png
  #    
  #---------------------------------------------------------------------------
  LEVEL_NUMBER_VISIBLE = false
  #---------------------------------------------------------------------------
  # Definição da prioridade do Sprite.
  #---------------------------------------------------------------------------    
  LEVEL_NUMBER_Z = 2
  #---------------------------------------------------------------------------
  # Definição da posição do número do Level. [X,Y]
  #---------------------------------------------------------------------------  
  LEVEL_NUMBER_POSITION = [84,0]
  #---------------------------------------------------------------------------
  # Definição do tipo alinhamento do número.
  #
  # 0 - Esquerda
  # 1 - Centro
  # 2 - Direita
  #---------------------------------------------------------------------------  
  LEVEL_NUMBER_ALIGN_TYPE = 1     
  #============================================================================
  #============================================================================
 
 
  #============================================================================
  #============================================================================
  # * STATE
  #============================================================================
  # Ativar as condições.
  #---------------------------------------------------------------------------  
  STATES_VISIBLE = true
  #---------------------------------------------------------------------------
  # Definição da prioridade do sprite.
  #---------------------------------------------------------------------------    
  STATES_Z = 4
  #---------------------------------------------------------------------------
  # Definição da posição das condições. [X,Y] 
  #---------------------------------------------------------------------------  
  STATES_POSITION = [25,54]
  #---------------------------------------------------------------------------
  # Ativar o efeito animado das condições deslizando. 
  #---------------------------------------------------------------------------  
  STATES_SCROLLING_ANIMATION = false
  #---------------------------------------------------------------------------
  # Definição do ângulo do sprite.
  #---------------------------------------------------------------------------   
  STATE_ANGLE = 0
  #---------------------------------------------------------------------------
  # Definição das condições que serão ocultadas pela hud.
  # EX - HIDE_STATES_ID = [9,10,13]
  #---------------------------------------------------------------------------   
  HIDE_STATES_ID = []
  #============================================================================
  #============================================================================
 
  #============================================================================
  #============================================================================
  # * SECOND LAYOUT (Overlayer)
  #============================================================================  
  # Ativar a segunda camada de Layout
  # Será necessário o arquivo.
  #
  # Layout_2.png
  #
  #============================================================================  
  SECOND_LAYOUT = false
  #---------------------------------------------------------------------------
  # Definição da prioridade do sprite.
  #---------------------------------------------------------------------------  
  SECOND_LAYOUT_Z = 2
  #---------------------------------------------------------------------------
  # Definição da posição do sprite.
  #---------------------------------------------------------------------------   
  SECOND_LAYOUT_POSITION = [0,0]
  #============================================================================
  #============================================================================ 
 
  #============================================================================
  #============================================================================
  # * SCREEN LAYOUT
  #============================================================================  
  # Ativar o Layout da tela.
  # Será necessário o arquivo.
  #
  # Layout_Screen.png
  #
  #============================================================================  
  #Ativar o Layout da tela
  SCREEN_LAYOUT = false
  #---------------------------------------------------------------------------
  #Posição do layout
  #---------------------------------------------------------------------------
  SCREEN_LAYOUT_POSITION = [0,0]
  #---------------------------------------------------------------------------
  #Definição da posição Z
  #---------------------------------------------------------------------------
  SCREEN_LAYOUT_Z = -2     
 
end
 
#============================================================================
#============================================================================
# * CUSTOM WINDOWS (GENERAL)
#============================================================================
module MOG_BATTLE_HUD_EX
 
 #============================================================================
 # * Ativar Janelas Customizadas.
 #============================================================================
  ENABLE_CUSTOM_WINDOWS = true
 
 #============================================================================
 # * BATTLE LOG WINDOW
 #============================================================================
 #Definição da posição da janela de log. 
  BATTLE_LOG_POSITION = [0,0]
 #============================================================================
 
 #============================================================================
 # * FONT SETTING
 #============================================================================
 #Ativar a configuração da fonte.
 ENABLE_WINDOW_FONT_SET = false
 #Definição do nome da fonte.
 WINDOW_FONT_NAME = nil
 #Definição do tamanho da fonte.
 WINDOW_FONT_SIZE = 18
 #Ativar fonte em bold;
 WINDOW_FONT_BOLD = true
 #Ativar fonte em itálico.
 WINDOW_FONT_ITALIC = false 
 
 #============================================================================
 # * SKILL WINDOW
 #============================================================================
 #Definição do tamanho da janela.
  SKILL_WINDOW_SIZE = [Graphics.width, 120]
 #Definição da posição da janela.
  SKILL_WINDOW_POSITION = [0,0]
 #Definição da transparência da janela. 
  SKILL_WINDOW_OPACITY = 0
 #Ativar a imagem de Layout. ("Layout_Skill.png") 
  SKILL_WINDOW_LAYOUT = true
 #Definição do layout.
  SKILL_WINDOW_LAYOUT_POSITION = [0,-7]  
 #Definição da quantidade colunas máxima. 
  SKILL_COL_MAX = 2  
   #Ativar a animação de slide.
  SKILL_WINDOW_SLIDE_EFFECT = false
  #Definição da posição do slide.
  SKILL_WINDOW_SLIDE_POSITION = [150,0]    
 #============================================================================ 
 
 #============================================================================
 # * ITEM WINDOW
 #============================================================================
 #Definição do tamanho da janela.  
  ITEM_WINDOW_SIZE = [Graphics.width, 120]
 #Definição da posição da janela.
  ITEM_WINDOW_POSITION = [0,0]
 #Definição da transparência da janela. 
  ITEM_WINDOW_OPACITY = 0
 #Ativar a imagem de Layout. ("Layout_Item.png")   
  ITEM_WINDOW_LAYOUT = true
 #Definição do layout.  
  ITEM_WINDOW_LAYOUT_POSITION = [0,-7]
 #Definição da quantidade colunas máxima. 
  ITEM_COL_MAX = 2    
  #Ativar a animação de slide.
  ITEM_WINDOW_SLIDE_EFFECT = false
  #Definição da posição do slide.
  ITEM_WINDOW_SLIDE_POSITION = [150,0]  
 #============================================================================
 
 #============================================================================
 # * COMMAND WINDOW
 #============================================================================
 #Definição da posição da janela. (Apenas para Ajustes)
  ACTOR_COMMAND_POSITION = [0,0] #[30,-70]
 #Definição da transparência da janela. 
  ACTOR_COMMAND_OPACITY = 0
 #Ativar a imagem de Layout. ("Layout_Command.png")    
  ACTOR_COMMAND_LAYOUT = true
 #Definição do layout.   
  ACTOR_COMMAND_LAYOUT_POSITION = [0,0] #[0,0]
 #============================================================================
 
 #============================================================================
 # * HELP WINDOW
 #============================================================================
 #Definição do tamanho da janela.   
  HELP_WINDOW_SIZE = [Graphics.width, 72]
 #Definição do tamanho da janela. 
  HELP_WINDOW_POSITION = [Graphics.width / 2, 0]  
 #Definição da transparência da janela. 
  HELP_WINDOW_OPACITY = 0
 #Ativar a imagem de Layout. ("Layout_Help.png")    
  HELP_WINDOW_LAYOUT = true
 #Definição do layout.
  HELP_WINDOW_LAYOUT_POSITION = [0,0]
  #Ativar a animação de slide.
  HELP_WINDOW_SLIDE_EFFECT = false
  #Definição da posição do slide.
  HELP_WINDOW_SLIDE_POSITION = [0,-150]    
 #============================================================================
 
 #============================================================================
 # * TARGET ACTOR WINDOW
 #============================================================================
 #Definição do tamanho da janela.    
  ACTOR_WINDOW_SIZE = [Graphics.width, 120]  
 #Definição do tamanho da janela. 
  ACTOR_WINDOW_POSITION = [Graphics.width / 2, Graphics.height]
 #Definição da transparência da janela.  
  ACTOR_WINDOW_OPACITY = 0
 #Ativar a imagem de Layout. ("Layout_Target_Actor.png")
  ACTOR_WINDOW_LAYOUT = true
 #Definição do layout.
  ACTOR_WINDOW_LAYOUT_POSITION = [0,0]
  #Ativar a animação de slide.
  ACTOR_WINDOW_SLIDE_EFFECT = false
  #Definição da posição do slide.
  ACTOR_WINDOW_SLIDE_POSITION = [0,100]    
 #============================================================================
 
 #============================================================================
 # * TARGET ENEMY WINDOW
 #============================================================================
 #Definição do tamanho da janela. 
  ENEMY_WINDOW_SIZE = [Graphics.width, 120]
 #Definição do tamanho da janela.  
  ENEMY_WINDOW_POSITION = [Graphics.width / 2, Graphics.height]
 #Definição da transparência da janela.   
  ENEMY_WINDOW_OPACITY = 0
 #Ativar a imagem de Layout. ("Layout_Target_Actor.png") 
  ENEMY_WINDOW_LAYOUT = true
 #Definição do layout. 
  ENEMY_WINDOW_LAYOUT_POSITION = [0,0]
  #Ativar a animação de slide.
  ENEMY_WINDOW_SLIDE_EFFECT = false
  #Definição da posição do slide.
  ENEMY_WINDOW_SLIDE_POSITION = [0,100]    
 #============================================================================
 
 #============================================================================
 # * PARTY WINDOW (Fight/Escape)
 #============================================================================
 #Definição do tamanho da janela.  
  #PARTY_COMMAND_POSITION = [Graphics.width / 2,Graphics.height / 2]
  PARTY_COMMAND_POSITION = [70,430]
 #Definição da transparência da janela.   
  PARTY_COMMAND_OPACITY = 0
 #Ativar a imagem de Layout. ("Layout_Party.png")  
  PARTY_COMMAND_LAYOUT = true
 #Definição do layout.  
  PARTY_COMMAND_LAYOUT_POSITION = [0,0]
  #Ativar a animação de slide.
  PARTY_COMMAND_SLIDE_EFFECT = false
  #Definição da posição do slide.
  PARTY_COMMAND_SLIDE_POSITION = [0,-150]    
 #============================================================================
 
end
 
#==============================================================================
# ** Cache
#==============================================================================
module Cache
 
  #--------------------------------------------------------------------------
  # * Hud
  #--------------------------------------------------------------------------
  def self.battle_hud(filename)
      load_bitmap("Graphics/Huds/Battle/", filename)
  end
 
end
 
#==============================================================================
# ** Game Temp
#==============================================================================
class Game_Temp
 
  attr_accessor :battler_face_pos
  attr_accessor :hud_pos
  attr_accessor :hud_pos_real
  attr_accessor :com_pos
  attr_accessor :mbhud_force_refresh
  attr_accessor :mbhud_window
  attr_accessor :command_visible
  attr_accessor :refresh_turn_sprite
  attr_accessor :battle_hud_visible
  attr_accessor :battle_hud_visible_refresh
  attr_accessor :battle_end
 
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------    
  alias mog_monogatari_bhud_initialize initialize
  def initialize
      @battler_face_pos = []
      @hud_pos = []
      @hud_pos_real = []
      @com_pos = []
      @mbhud_force_refresh = false
      @mbhud_window = [false,false,false,false,false,false,false]
      @command_visible = false
      @refresh_turn_sprite = false
      @battle_hud_visible = true
      @battle_hud_visible_refresh = [false,false]
      @battle_end = false      
      mog_monogatari_bhud_initialize
  end
 
  #--------------------------------------------------------------------------
  # * Check Screen Xyz
  #--------------------------------------------------------------------------   
  def check_screen_xyz_nil
      return if !SceneManager.face_battler?
      for actor in $game_party.battle_members
          actor.screen_x = 0 if actor.screen_x == nil
          actor.screen_y = 0 if actor.screen_y == nil
          actor.screen_z = 0 if actor.screen_z == nil
      end
  end  
 
  #--------------------------------------------------------------------------
  # ● Sprite Visible
  #--------------------------------------------------------------------------    
  def sprite_visible
      return false if $game_message.visible
      return false if $game_temp.battle_end 
      return true
  end  
 
end
 
#==============================================================================
# ** Game Interpreter
#==============================================================================
class Game_Interpreter
 
 #--------------------------------------------------------------------------
 # * Refresh Battle Hud
 #--------------------------------------------------------------------------
 def refresh_battle_hud
     $game_temp.check_screen_xyz_nil rescue nil
     $game_temp.mbhud_force_refresh = true
 end
 
 #--------------------------------------------------------------------------
 # * Battler Face Name
 #--------------------------------------------------------------------------
 def battler_face_name(actor_id,face_name = "")
     for actor in $game_party.members
         actor.battler_face_name = face_name if actor.id == actor_id
     end
     refresh_battle_hud
 end  
 
 #--------------------------------------------------------------------------
 # * Battler Hud Visible
 #--------------------------------------------------------------------------
 def battle_hud_visible(value)
     $game_temp.battle_hud_visible = value
 end
 
 #--------------------------------------------------------------------------
 # * Command_129
 #--------------------------------------------------------------------------
 alias mog_monogatari_bhud_command_129 command_129
 def command_129
     mog_monogatari_bhud_command_129     
     refresh_battle_hud if SceneManager.scene_is?(Scene_Battle)
 end
 
end
 
#==============================================================================
# ** Game Actor
#==============================================================================
class Game_Actor < Game_Battler
 
  attr_accessor :face_animation
  attr_accessor :battler_face_name
 
  #--------------------------------------------------------------------------
  # * Setup
  #--------------------------------------------------------------------------
  alias mog_monogatari_face_animation setup
  def setup(actor_id)
      mog_monogatari_face_animation(actor_id)
      @face_animation = [0,0,0]
 
      #追記
      p "setup"      
 
      if $game_variables[1] == 1
        @battler_face_name = "Face_1"
      end
      if $game_variables[1] == 0
        @battler_face_name = "Face_2"
      end
      #追記終わり
 
 
      @battler_face_name = "Face_" + actor_id.to_s
  end    
 
  #--------------------------------------------------------------------------
  # ● Real Next Level
  #--------------------------------------------------------------------------  
  def real_next_level
      next_level_exp - exp_for_level(level)
  end
 
  #--------------------------------------------------------------------------
  # ● Remain Exp
  #--------------------------------------------------------------------------  
  def remain_exp
      exp - exp_for_level(level)
  end
 
  #--------------------------------------------------------------------------
  # ● Gain Exp Test
  #--------------------------------------------------------------------------
  def gain_exp_test
      exp_r = rand(next_level_exp)
      change_exp(self.exp + (exp_r * final_exp_rate).to_i, false)
  end    
 
  #--------------------------------------------------------------------------
  # ● Low HP?
  #--------------------------------------------------------------------------    
  def low_hp?
      hp <= (mhp * MOG_BATTLE_HUD_EX::LOW_PARAMETER_PERCENTAGE) / 100
  end
 
  #--------------------------------------------------------------------------
  # ● Low MP?
  #--------------------------------------------------------------------------    
  def low_mp?
      mp <= (mmp * MOG_BATTLE_HUD_EX::LOW_PARAMETER_PERCENTAGE) / 100
  end  
 
  #--------------------------------------------------------------------------
  # ● Low TP?
  #--------------------------------------------------------------------------    
  def low_tp?
      tp <= (max_tp * MOG_BATTLE_HUD_EX::LOW_PARAMETER_PERCENTAGE) / 100
  end  
 
end
 
#==============================================================================
# ** Game Party
#==============================================================================
class Game_Party < Game_Unit
 
  #--------------------------------------------------------------------------
  # * Get Maximum Number of Battle Members
  #--------------------------------------------------------------------------
  def max_battle_members
      return MOG_BATTLE_HUD_EX::MAX_BATTLE_MEMBERS
  end
 
 #--------------------------------------------------------------------------
 # * Swap Order
 #--------------------------------------------------------------------------
 alias mog_bhex_swap_order swap_order
 def swap_order(index1, index2)
     mog_bhex_swap_order(index1, index2)
     if SceneManager.scene_is?(Scene_Battle)  
     $game_temp.check_screen_xyz_nil rescue nil
     $game_temp.mbhud_force_refresh = true     
     end
 end  
 
end
 
#==============================================================================
# ** BattleManager
#==============================================================================
module BattleManager
 
 #--------------------------------------------------------------------------
 # * Current Index
 #--------------------------------------------------------------------------   
 def self.current_index
     if $imported[:mog_atb_system]
        return actor.index if actor
     end   
     return 0 if @actor_index == nil
     return @actor_index != -1 ? @actor_index : 0
 end
 
 #--------------------------------------------------------------------------
 # * Current Index Real
 #--------------------------------------------------------------------------   
 def self.current_index_real
     return -1 if @actor_index == nil
     return @actor_index
 end 
 
  #--------------------------------------------------------------------------
  # * Next Actor Avaliable
  #--------------------------------------------------------------------------
  def self.next_actor_avaliable?
      return false if @actor_index == nil
      next_index = @actor_index + 1
      return false if next_index >= $game_party.members.size
      return true
  end 
 
  #--------------------------------------------------------------------------
  # * To Next Command Input
  #--------------------------------------------------------------------------
  def self.next_command_avaliable
    aindex = @actor_index
    begin      
      if !actor || !actor.next_command
        return false if actor == nil
        aindex += 1
        return false if aindex >= $game_party.members.size
      end
    end until actor.inputable?
    return true
  end  
 
  #--------------------------------------------------------------------------
  # * Can Enable Window?
  #--------------------------------------------------------------------------
  def self.can_enable_window?
      max_members = $game_party.members.size
      index_real = current_index_real + 1
      return false if index_real > max_members
      return false if in_turn?
      return false if $imported[:mog_battle_cursor]
      return true
  end
 
end
 
#==============================================================================
# ** SceneManager
#==============================================================================
module SceneManager
 
  #--------------------------------------------------------------------------
  # * Face Battler
  #--------------------------------------------------------------------------
  def self.face_battler?
      return false if !MOG_BATTLE_HUD_EX::FACE_BATTLER
      return false if !MOG_BATTLE_HUD_EX::FACE_VISIBLE
      return false if $imported[:mog_sprite_actor]
      return false if $imported[:ve_animated_battle]
      return false if $imported[:ve_actor_battlers]
      return false if $imported["YES-BattleSymphony"]
      return false if $imported["YEA-VisualBattlers"]
      return false if $imported["Galv_Animated_Battlers"]
      return false if $imported['KRX-AnimatedBattlers']
      return false if $imported[:Theo_BasicFuntions]
      return false if $sv_camera != nil
      return false if BattleManager.true_surprise != nil rescue nil
      return false if $imported[:jet][:AnimatedBattlers] rescue nil      
      return true
  end
 
end
 
#==============================================================================
# ■ Sprite Picture
#==============================================================================
class Sprite_Picture < Sprite
 
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------
  alias mog_battle_hud_initialize initialize
  def initialize(viewport, picture)
      mog_battle_hud_initialize(viewport, picture)
      self.viewport = nil if SceneManager.scene_is?(Scene_Battle)
 
  end  
 
  #--------------------------------------------------------------------------
  # * Update Position
  #--------------------------------------------------------------------------
  alias mog_battle_hud_update_position update_position
  def update_position
      mog_battle_hud_update_position
      self.z = @picture.number + 120 if SceneManager.scene_is?(Scene_Battle)
  end
 
end
 
#==============================================================================
# ■ Sprite Base
#==============================================================================
class Sprite_Base < Sprite
 
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------
  alias mog_bhud_ex_initialize initialize
  def initialize(viewport = nil)
      #追加
      @ani_x = SceneManager.face_battler? ? MOG_BATTLE_HUD_EX::HUD_Z + 20 : 100
      mog_bhud_ex_initialize(viewport)
  end  
 
  #--------------------------------------------------------------------------
  # * Animation Set Sprite
  #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_animation_set_sprites animation_set_sprites
  def animation_set_sprites(frame)
      mog_battle_hud_ex_animation_set_sprites(frame)
      update_sprite_z_animation rescue nil if SceneManager.scene_is?(Scene_Battle)
  end  
 
  #--------------------------------------------------------------------------
  # * Update Sprite Z Animation
  #--------------------------------------------------------------------------
  def update_sprite_z_animation  
      if $imported[:mog_battle_camera]
         @ani_sprites.each_with_index do |sprite, i|
         sprite.z = @ani_x + i end  
         #追加
         #sprite.z = @ani_x + i end
      else
         @ani_sprites.each_with_index do |sprite, i|
         sprite.viewport = nil ; sprite.z = @ani_x + i end
          #追加
         #sprite.viewport = nil ; sprite.z = @ani_x + i end
      end   
  end  
 
end
 
#==============================================================================
# ** Spriteset Battle
#==============================================================================
class Spriteset_Battle  
 
  #--------------------------------------------------------------------------
  # * Create Actors
  #--------------------------------------------------------------------------
  alias mog_battle_hud_create_actors create_actors
  def create_actors
      if can_create_max_members?
         @actor_sprites = Array.new($game_party.max_battle_members) { Sprite_Battler.new(@viewport1) }
         return
      end
      mog_battle_hud_create_actors
  end
 
  #--------------------------------------------------------------------------
  # * Can Create Max Members
  #--------------------------------------------------------------------------
  def can_create_max_members?
      return false if $imported[:ve_animated_battle] 
      return false if $imported[:ve_actor_battlers]
      return false if $sv_camera != nil
      return true
  end
 
end
 
#==============================================================================
# ■ Scene Battle
#==============================================================================
class Scene_Battle < Scene_Base
 
 #--------------------------------------------------------------------------
 # ● Clear All Windows
 #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_start start
  def start
      setup_battle_hud_ex
      mog_battle_hud_ex_start
  end
 
 #--------------------------------------------------------------------------
 # ● Setup Battle Hud EX
 #--------------------------------------------------------------------------
 def setup_battle_hud_ex
     @force_clear_duration = 0
 end
 
 #--------------------------------------------------------------------------
 # ● Clear All Windows
 #--------------------------------------------------------------------------
 def clear_all_windows
     if @actor_window != nil
        @actor_window.visible = false
        @actor_window.active = false
     end   
     if @status_window != nil
        @status_window.visible = false
        @status_window.active = false
     end   
     if @actor_command_window != nil
        @actor_command_window.visible = false
        @actor_command_window.active = false
     end
     if @party_command_window != nil
        @party_command_window.visible = false
        @party_command_window.active = false
     end
     if @help_window != nil
        @help_window.visible = false 
     end  
 end    
 
 #--------------------------------------------------------------------------
 # ● Update
 #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_update_main update
  def update
      mog_battle_hud_ex_update_main
      update_battle_hud_ex
  end
 
 #--------------------------------------------------------------------------
 # ● Update Battle Hud_ex
 #--------------------------------------------------------------------------
  def update_battle_hud_ex
      @status_window.visible = false
  end
 
  if MOG_BATTLE_HUD_EX::ENABLE_CUSTOM_WINDOWS
  #--------------------------------------------------------------------------
  # * On Skill OK
  #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_on_skill_ok on_skill_ok
  def on_skill_ok
      @skill = @skill_window.item
      @skill_window.hide if @skill.for_opponent? or @skill.for_friend?
      mog_battle_hud_ex_on_skill_ok
  end
 
  #--------------------------------------------------------------------------
  # * On Item OK
  #--------------------------------------------------------------------------
  alias mog_battle_hud_on_item_ok on_item_ok
  def on_item_ok
      @item = @item_window.item
      @item_window.hide if @item.for_opponent? or @item.for_friend?
      mog_battle_hud_on_item_ok
  end     
 
  #--------------------------------------------------------------------------
  # * On Enemy Cancel
  #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_on_enemy_cancel on_enemy_cancel
  def on_enemy_cancel
      mog_battle_hud_ex_on_enemy_cancel
      @skill_window.show if @skill_window.active
      @item_window.show if @item_window.active      
  end
 
  #--------------------------------------------------------------------------
  # * On Actor Cancel
  #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_on_actor_cancel on_actor_cancel
  def on_actor_cancel
      mog_battle_hud_ex_on_actor_cancel
      @skill_window.show if @skill_window.active
      @item_window.show if @item_window.active
      mog_battle_hud_ex_on_actor_cancel
  end  
  end
 
end
 
if SceneManager.face_battler?
#==============================================================================
# ■ Game_Actor
#==============================================================================
class Game_Actor < Game_Battler
 
  attr_accessor :screen_x
  attr_accessor :screen_y
  attr_accessor :screen_z
 
 
 #--------------------------------------------------------------------------
 # ● Use Sprite?
 #--------------------------------------------------------------------------
  def use_sprite?
      return true
  end
 
end
 
#==============================================================================
# ■ Sprite_Battler
#==============================================================================
class Sprite_Battler < Sprite_Base 
  include MOG_BATTLE_HUD_EX
 
  #--------------------------------------------------------------------------
  # ● Update Collapse
  #--------------------------------------------------------------------------                          
   alias mog_battle_hud_update_collapse update_collapse
   def update_collapse
       return if face_can_cancel_method?
       mog_battle_hud_update_collapse
   end  
 
  #--------------------------------------------------------------------------
  # ● Update Instant Collapse
  #--------------------------------------------------------------------------                             
   alias mog_battle_hud_update_instant_collapse update_instant_collapse
   def update_instant_collapse
       return if face_can_cancel_method?
       mog_battle_hud_update_instant_collapse
   end  
 
  #--------------------------------------------------------------------------
  # ● Face Can Cancel Method
  #--------------------------------------------------------------------------                                  
  def face_can_cancel_method?
      return false if !SceneManager.face_battler?
      return false if @battler.is_a?(Game_Enemy)
      self.opacity = 255 ; self.visible = true
      return true
  end  
 
  #--------------------------------------------------------------------------
  # ● Update Bitmap
  #--------------------------------------------------------------------------                                  
  alias mog_battle_hud_ex_update_bitmap update_bitmap
  def update_bitmap
      return if face_can_cancel_method?
      mog_battle_hud_ex_update_bitmap
  end  
 
  #--------------------------------------------------------------------------
  # ● Update Position
  #--------------------------------------------------------------------------                                  
  alias mog_battle_hud_ex_update_position update_position
  def update_position
      if @battler.is_a?(Game_Actor) and SceneManager.face_battler?
         if !face_sprite_visible? or $game_temp.battle_end
             self.y = -1000
             return
         end
      end   
      mog_battle_hud_ex_update_position
  end  
 
  #--------------------------------------------------------------------------
  # * Sprite Visible
  #--------------------------------------------------------------------------
  def face_sprite_visible?
      return false if $game_message.visible and MESSAGE_WINDOW_FADE_HUD
      return false if !$game_temp.battle_hud_visible
      return true
  end  
 
end
 
end
 
#==============================================================================
# ** Window_BattleStatus
#==============================================================================
class Window_BattleStatus < Window_Selectable
 include MOG_BATTLE_HUD_EX
 
  #--------------------------------------------------------------------------
  # * Get Window Width
  #--------------------------------------------------------------------------
  def window_width
      ACTOR_WINDOW_SIZE[0]
  end 
 
 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------   
 alias mog_monogatari_refresh refresh
 def refresh
     mog_monogatari_refresh
     self.visible = false
     self.opacity = 0
     self.contents_opacity = 0
     self.y = 1200
 end  
 
end  
 
#==============================================================================
# ** Window Actor Command
#==============================================================================
class Window_ActorCommand < Window_Command
 
 #--------------------------------------------------------------------------
 # * Update
 #--------------------------------------------------------------------------   
  alias mog_hud_battle_hud_ex_turn_sprite_update update
  def update
      mog_hud_battle_hud_ex_turn_sprite_update
      $game_temp.command_visible = self.visible
  end
 
end
 
#==============================================================================
# ** Window_BattleActor
#==============================================================================
class Window_BattleActor < Window_BattleStatus
 
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_actor_w_refresh refresh
  def refresh
      mog_battle_hud_ex_actor_w_refresh
      self.contents_opacity = 255
      self.opacity = 255 if !MOG_BATTLE_HUD_EX::ENABLE_CUSTOM_WINDOWS
      self.visible = true
  end
 
end  
 
if MOG_BATTLE_HUD_EX::ENABLE_CUSTOM_WINDOWS
 
#==============================================================================
# ** Window BattleLog
#==============================================================================
class Window_BattleLog < Window_Selectable
 
  include MOG_BATTLE_HUD_EX
 
 #--------------------------------------------------------------------------
 # * Initialize
 #--------------------------------------------------------------------------    
  alias mog_battle_hud_ex_log_initialize initialize
  def initialize
      mog_battle_hud_ex_log_initialize
      self.x = BATTLE_LOG_POSITION[0]
      self.y = BATTLE_LOG_POSITION[1]
      self.z = MOG_BATTLE_HUD_EX::HUD_Z + 140
  end
 
 #--------------------------------------------------------------------------
 # * Create Back Sprite
 #--------------------------------------------------------------------------    
  alias mog_battle_hud_ex_log_create_back_sprite create_back_sprite
  def create_back_sprite
      self.x = BATTLE_LOG_POSITION[0]
      self.y = BATTLE_LOG_POSITION[1]
      self.z = MOG_BATTLE_HUD_EX::HUD_Z + 140
      mog_battle_hud_ex_log_create_back_sprite
  end
 
end  
 
#==============================================================================
# ** Window Actor Command
#==============================================================================
class Window_ActorCommand < Window_Command
 
  include MOG_BATTLE_HUD_EX
 
 #--------------------------------------------------------------------------
 # * Initialize
 #--------------------------------------------------------------------------    
 alias mog_monogatari_initialize initialize
 def initialize
     mog_monogatari_initialize
     create_layout if $imported[:mog_battle_command_ex] == nil
 end
 
 #--------------------------------------------------------------------------
 # * Dispose
 #-------------------------------------------------------------------------- 
 alias mog_monogatari_actor_command_dispose dispose
 def dispose
     mog_monogatari_actor_command_dispose
     dispose_layout
 end
 
 #--------------------------------------------------------------------------
 # * Create Layout
 #--------------------------------------------------------------------------   
 def create_layout
     return if @layout != nil
     return if !ACTOR_COMMAND_LAYOUT
     return if $game_temp.mbhud_window[0]
     self.z = MOG_BATTLE_HUD_EX::HUD_Z + 150
     $game_temp.mbhud_window[0] = true
     @layout = Sprite.new
     @layout.bitmap = Cache.battle_hud("Layout_Command")
     @layout.z = self.z - 1
     @layout.x = self.x + ACTOR_COMMAND_LAYOUT_POSITION[0]
     @layout.y = self.y + ACTOR_COMMAND_LAYOUT_POSITION[1]
     @layout.visible = false
 end
 
 #--------------------------------------------------------------------------
 # * Dispose Layout
 #-------------------------------------------------------------------------- 
 def dispose_layout
     return if @layout == nil
     @layout.dispose
     @layout = nil
 end
 
 #--------------------------------------------------------------------------
 # * Refresh Layout
 #--------------------------------------------------------------------------
 def refresh_layout
     return if @layout == nil
     @layout.x = self.x + ACTOR_COMMAND_LAYOUT_POSITION[0]
     @layout.y = self.y + ACTOR_COMMAND_LAYOUT_POSITION[1]
     @layout.visible = self.visible
     @layout.z = self.z - 1
 end
 
 #--------------------------------------------------------------------------
 # * Select
 #--------------------------------------------------------------------------  
 alias mog_monogatari_select_actor_command select
 def select(index)
     mog_monogatari_select_actor_command(index)
     set_command_position if $imported[:mog_battle_command_ex] == nil
 end    
 
 #--------------------------------------------------------------------------
 # * Set Command Position
 #--------------------------------------------------------------------------   
 def set_command_position
     self.viewport = nil
     self.opacity = ACTOR_COMMAND_OPACITY
     battler_index = BattleManager.current_index rescue nil
     battler_index = 0 if battler_index == nil     
     if @actor != nil and $game_temp.hud_pos[battler_index] != nil
        if FIXED_COMMAND_POSITION[battler_index] != nil
           self.x = FIXED_COMMAND_POSITION[battler_index][0]
           self.y = FIXED_COMMAND_POSITION[battler_index][1]              
        else  
           self.x = ACTOR_COMMAND_POSITION[0] + $game_temp.hud_pos[battler_index][0] - (self.width / 2)
           self.x = Graphics.width - self.width if self.x + self.width > Graphics.width
           self.x = 0 if self.x < 0
           self.y = ACTOR_COMMAND_POSITION[1] + $game_temp.hud_pos[battler_index][1] - self.height
        end   
     end      
     refresh_layout
 end  
 
 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------   
 alias mog_battle_hud_ex_refresh refresh
 def refresh
     mog_battle_hud_ex_refresh
     $game_temp.refresh_turn_sprite = true if $imported[:mog_battle_command_ex] == nil
 end
 
 #--------------------------------------------------------------------------
 # * Update
 #--------------------------------------------------------------------------  
 alias mog_monogatari_actor_commnand_update update
 def update     
     mog_monogatari_actor_commnand_update
     if $imported[:mog_battle_command_ex] == nil
     self.visible = self.active 
     if !@layout.nil?
        refresh_layout if @layout.visible != self.visible
        @layout.visible = false if !$game_temp.sprite_visible
     end        
     self.visible = false if !$game_temp.sprite_visible     
     end
end
 
end
 
#==============================================================================
# ** Window_PartyCommand
#==============================================================================
class Window_PartyCommand < Window_Command
 
  include MOG_BATTLE_HUD_EX
 
 #--------------------------------------------------------------------------
 # * Initialize
 #--------------------------------------------------------------------------   
  alias mog_monogatari_party_initialize initialize
  def initialize
      mog_monogatari_party_initialize
    #  self.x = @org_position[0] ; self.y = @org_position[1]
    #  self.opacity = PARTY_COMMAND_OPACITY    
      create_layout
  end
 
 #--------------------------------------------------------------------------
 # * Dispose
 #-------------------------------------------------------------------------- 
 alias mog_monogatari_party_window_dispose dispose
 def dispose
     mog_monogatari_party_window_dispose
     dispose_layout
 end 
 
 #--------------------------------------------------------------------------
 # * Create Layout
 #--------------------------------------------------------------------------   
 def create_layout
     return if @layout != nil
     return if !PARTY_COMMAND_LAYOUT
     return if $game_temp.mbhud_window[1]
     self.z = MOG_BATTLE_HUD_EX::HUD_Z + 150
     $game_temp.mbhud_window[1] = true
     @org_position_2 = [@org_position[0] + PARTY_COMMAND_LAYOUT_POSITION[0],@org_position[1] + PARTY_COMMAND_LAYOUT_POSITION[1]] 
     @layout = Sprite.new
     @layout.bitmap = Cache.battle_hud("Layout_Party")
     @layout.z = self.z - 1
     refresh_layout
     @layout.visible = false
 end
 
 #--------------------------------------------------------------------------
 # * Dispose Layout
 #-------------------------------------------------------------------------- 
 def dispose_layout
     return if @layout == nil
     @layout.dispose
     @layout = nil
 end
 
 #--------------------------------------------------------------------------
 # * Refresh Layout
 #--------------------------------------------------------------------------
 def refresh_layout
     return if @layout == nil
     @layout.x = @org_position_2[0]
     @layout.y = @org_position_2[1]
     @layout.x += PARTY_COMMAND_SLIDE_POSITION[0] if PARTY_COMMAND_SLIDE_EFFECT
     @layout.y += PARTY_COMMAND_SLIDE_POSITION[1] if PARTY_COMMAND_SLIDE_EFFECT
     @layout.visible = self.visible
 end         
 
 #--------------------------------------------------------------------------
 # * Select
 #--------------------------------------------------------------------------  
 alias mog_monogatari_refresh_partycommand refresh
 def refresh
     if @org_position == nil
      @org_position = [PARTY_COMMAND_POSITION[0] - (self.width / 2),
                       PARTY_COMMAND_POSITION[1] - (self.height / 2)]  
     end                  
     mog_monogatari_refresh_partycommand
 
      self.viewport = nil      
      self.x = @org_position[0] ; self.y = @org_position[1]
      if PARTY_COMMAND_SLIDE_EFFECT
         self.x += PARTY_COMMAND_SLIDE_POSITION[0]
         self.y += PARTY_COMMAND_SLIDE_POSITION[1]
 
      end
      self.opacity = PARTY_COMMAND_OPACITY     
 end    
 
 def show
 
 end
 
 #--------------------------------------------------------------------------
 # * Show
 #--------------------------------------------------------------------------    
  alias mog_bg_ex_slide_show_party show
  def show
      self.viewport = nil
      self.x = @org_position[0] ; self.y = @org_position[1]
      if PARTY_COMMAND_SLIDE_EFFECT
         self.x += PARTY_COMMAND_SLIDE_POSITION[0]
         self.y += PARTY_COMMAND_SLIDE_POSITION[1]
 
      end
      self.opacity = PARTY_COMMAND_OPACITY
      mog_bg_ex_slide_show_party 
  end 
 
 #--------------------------------------------------------------------------
 # * Update
 #--------------------------------------------------------------------------  
 alias mog_monogatari_party_window_update update
 def update
     mog_monogatari_party_window_update  
     self.visible = self.active
     if @layout != nil and @layout.visible != self.visible        
        refresh_layout
     end
     execute_slide_effect if self.visible 
 end   
 
end
 
#==============================================================================
# ** Window_Help
#==============================================================================
class Window_Help < Window_Base
 
  include MOG_BATTLE_HUD_EX
 
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias mog_monogatari_battle_help_initialize initialize
  def initialize(line_number = 2)
      @battle_phase = false
      mog_monogatari_battle_help_initialize(line_number)
      @wait_time = 5
      if SceneManager.scene_is?(Scene_Battle)
         @battle_phase = true         
         self.width = HELP_WINDOW_SIZE[0]
         self.height = HELP_WINDOW_SIZE[1]      
         @org_position = [HELP_WINDOW_POSITION[0] - (self.width / 2),
                          HELP_WINDOW_POSITION[1]]         
         self.x = @org_position[0]
         self.y = @org_position[1]  
         self.opacity = HELP_WINDOW_OPACITY
         self.z = MOG_BATTLE_HUD_EX::HUD_Z + 150
         create_layout
      end     
 end
 
 #--------------------------------------------------------------------------
 # * Dispose
 #-------------------------------------------------------------------------- 
 alias mog_monogatari_help_window_dispose dispose
 def dispose
     mog_monogatari_help_window_dispose
     dispose_layout
 end 
 
 #--------------------------------------------------------------------------
 # * Create Layout
 #--------------------------------------------------------------------------   
 def create_layout
     return if @layout != nil
     return if !HELP_WINDOW_LAYOUT
     return if $game_temp.mbhud_window[2]
     return if !SceneManager.scene_is?(Scene_Battle)
     $game_temp.mbhud_window[2] = true
     @org_position_2 = [self.x + HELP_WINDOW_LAYOUT_POSITION[0],self.y + HELP_WINDOW_LAYOUT_POSITION[1]] 
     @layout = Sprite.new
     @layout.bitmap = Cache.battle_hud("Layout_Help")
     @layout.z = self.z - 1
     refresh_layout
     @layout.visible = false
 end
 
 #--------------------------------------------------------------------------
 # * Dispose Layout
 #-------------------------------------------------------------------------- 
 def dispose_layout
     return if @layout == nil
     @layout.dispose
     @layout = nil
 end
 
 #--------------------------------------------------------------------------
 # * Refresh Layout
 #--------------------------------------------------------------------------
 def refresh_layout
     return if @layout == nil
     @layout.x = @org_position_2[0]
     @layout.y = @org_position_2[1]
     @layout.x += HELP_WINDOW_SLIDE_POSITION[0] if HELP_WINDOW_SLIDE_EFFECT
     @layout.y += HELP_WINDOW_SLIDE_POSITION[1] if HELP_WINDOW_SLIDE_EFFECT
     @layout.visible = self.visible  
 end    
 
 #--------------------------------------------------------------------------
 # * Show
 #--------------------------------------------------------------------------    
  alias mog_bg_ex_slide_show_help show
  def show
      if @battle_phase
      self.viewport = nil
      self.x = @org_position[0] ; self.y = @org_position[1]
      if HELP_WINDOW_SLIDE_EFFECT
         self.x += HELP_WINDOW_SLIDE_POSITION[0]
         self.y += HELP_WINDOW_SLIDE_POSITION[1]
      end
      self.opacity = HELP_WINDOW_OPACITY
      end
      mog_bg_ex_slide_show_help
  end  
 
 #--------------------------------------------------------------------------
 # * Update
 #--------------------------------------------------------------------------  
 alias mog_monogatari_help_window_update update
 def update
     if @wait_time > 0
        @wait_time -= 1
        return 
     end   
     mog_monogatari_help_window_update
     if SceneManager.scene_is?(Scene_Battle)
        if @layout != nil           
           refresh_layout if @layout.visible != self.visible 
           @layout.visible = self.visible 
        end
        self.visible = false if !$game_temp.sprite_visible
        execute_slide_effect if self.visible        
     end
 end   
 
end
 
#==============================================================================
# ** Window_BattleActor
#==============================================================================
class Window_BattleActor < Window_BattleStatus
 
  include MOG_BATTLE_HUD_EX
 
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------    
  alias mog_monogatari_battle_actor_initialize initialize
  def initialize(info_viewport)
      @force_hide = can_force_hide?
      mog_monogatari_battle_actor_initialize(info_viewport)
      self.width = ACTOR_WINDOW_SIZE[0]
      self.height = ACTOR_WINDOW_SIZE[1]
      @org_position = [ACTOR_WINDOW_POSITION[0] - (self.width / 2),
                       ACTOR_WINDOW_POSITION[1] - self.height]
      @org_position[1] = Graphics.height + 64 if @force_hide
      self.x = @org_position[0]
      self.y = @org_position[1]
      self.opacity = ACTOR_WINDOW_OPACITY
      self.z = MOG_BATTLE_HUD_EX::HUD_Z + 151
      self.viewport = nil
      create_layout
  end
 
  #--------------------------------------------------------------------------
  # * Can Force Hide?
  #--------------------------------------------------------------------------    
  def can_force_hide?
      return true if $imported[:ve_target_arrow]
      return true if $imported[:mog_battle_cursor]
      return false
  end
 
 #--------------------------------------------------------------------------
 # * Dispose
 #-------------------------------------------------------------------------- 
 alias mog_monogatari_actor_window_dispose dispose
 def dispose
     mog_monogatari_actor_window_dispose
     dispose_layout
 end 
 
 #--------------------------------------------------------------------------
 # * Create Layout
 #--------------------------------------------------------------------------   
 def create_layout
     return if @layout != nil
     return if !ACTOR_WINDOW_LAYOUT
     return if $game_temp.mbhud_window[3]
     $game_temp.mbhud_window[3] = true
     @org_position_2 = [self.x + ACTOR_WINDOW_LAYOUT_POSITION[0],self.y + ACTOR_WINDOW_LAYOUT_POSITION[1]] 
     @layout = Sprite.new
     @layout.bitmap = Cache.battle_hud("Layout_Target_Actor")
     @layout.z = self.z - 1
     refresh_layout
     @layout.visible = false
 end
 
 #--------------------------------------------------------------------------
 # * Dispose Layout
 #-------------------------------------------------------------------------- 
 def dispose_layout
     return if @layout == nil
     @layout.dispose
     @layout = nil
 end
 
 #--------------------------------------------------------------------------
 # * Refresh Layout
 #--------------------------------------------------------------------------
 def refresh_layout
     return if @layout == nil
     @layout.x = @org_position_2[0]
     @layout.y = @org_position_2[1]
     @layout.x += ACTOR_WINDOW_SLIDE_POSITION[0] if ACTOR_WINDOW_SLIDE_EFFECT
     @layout.y += ACTOR_WINDOW_SLIDE_POSITION[1] if ACTOR_WINDOW_SLIDE_EFFECT
     @layout.visible = self.visible
 end     
 
  if $imported[:ve_target_arrow]
  #--------------------------------------------------------------------------
  # * New method: show_actor
  #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_show_actor show_actor
  def show_actor
      return true if SceneManager.face_battler?
      mog_battle_hud_ex_show_actor
  end
  end 
 
 #--------------------------------------------------------------------------
 # * Show
 #--------------------------------------------------------------------------    
  alias mog_bg_ex_slide_show_actor show
  def show
      self.viewport = nil
      self.x = @org_position[0] ; self.y = @org_position[1]
      if ACTOR_WINDOW_SLIDE_EFFECT
         self.x += ACTOR_WINDOW_SLIDE_POSITION[0]
         self.y += ACTOR_WINDOW_SLIDE_POSITION[1]
      end
      self.opacity = ACTOR_WINDOW_OPACITY
      mog_bg_ex_slide_show_actor
  end  
 
 #--------------------------------------------------------------------------
 # * Update
 #--------------------------------------------------------------------------  
 alias mog_monogatari_actor_window_update update
 def update
     mog_monogatari_actor_window_update   
     self.visible = self.active
     self.visible = false if @force_hide
     if @layout != nil        
        refresh_layout if @layout.visible != self.visible        
     end
     if !$game_temp.sprite_visible   
        self.visible = false 
        @layout.visible = self.visible if @layout != nil
     end   
     execute_slide_effect if self.visible
  end  
 
end
 
#==============================================================================
# ** Window_BattleEnemy
#==============================================================================
class Window_BattleEnemy < Window_Selectable
 
  include MOG_BATTLE_HUD_EX
 
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------    
  alias mog_monogatari_battle_enemy_initialize initialize
  def initialize(info_viewport)
      @force_hide = can_force_hide?
      mog_monogatari_battle_enemy_initialize(info_viewport)
      self.width = ENEMY_WINDOW_SIZE[0]
      self.height = ENEMY_WINDOW_SIZE[1]      
      @org_position = [ENEMY_WINDOW_POSITION[0] - (self.width / 2),
                       ENEMY_WINDOW_POSITION[1] - self.height]
      @org_position[1] = Graphics.height + 64 if @force_hide               
      self.x = @org_position[0]
      self.y = @org_position[1]      
      self.opacity = ENEMY_WINDOW_OPACITY
      self.z = MOG_BATTLE_HUD_EX::HUD_Z + 151
      create_layout
  end  
 
  #--------------------------------------------------------------------------
  # * Can Force Hide?
  #--------------------------------------------------------------------------    
  def can_force_hide?
      return true if $imported[:ve_target_arrow]
      return true if $imported[:mog_battle_cursor]
      return false
  end    
 
 #--------------------------------------------------------------------------
 # * Dispose
 #-------------------------------------------------------------------------- 
 alias mog_monogatari_enemy_window_dispose dispose
 def dispose
     mog_monogatari_enemy_window_dispose
     dispose_layout
 end 
 
 #--------------------------------------------------------------------------
 # * Create Layout
 #--------------------------------------------------------------------------   
 def create_layout
     return if @layout != nil
     return if !ENEMY_WINDOW_LAYOUT
     return if $game_temp.mbhud_window[4]
     $game_temp.mbhud_window[4] = true     
     @org_position_2 = [self.x + ENEMY_WINDOW_LAYOUT_POSITION[0],self.y + ENEMY_WINDOW_LAYOUT_POSITION[1]] 
     @layout = Sprite.new
     @layout.bitmap = Cache.battle_hud("Layout_Target_Enemy")
     @layout.z = self.z - 1
     refresh_layout
     @layout.visible = false
 end
 
 #--------------------------------------------------------------------------
 # * Dispose Layout
 #-------------------------------------------------------------------------- 
 def dispose_layout
     return if @layout == nil
     @layout.dispose
     @layout = nil
 end
 
 #--------------------------------------------------------------------------
 # * Refresh Layout
 #--------------------------------------------------------------------------
 def refresh_layout
     return if @layout == nil
     @layout.x = @org_position_2[0]
     @layout.y = @org_position_2[1]
     @layout.x += ENEMY_WINDOW_SLIDE_POSITION[0] if ENEMY_WINDOW_SLIDE_EFFECT
     @layout.y += ENEMY_WINDOW_SLIDE_POSITION[1] if ENEMY_WINDOW_SLIDE_EFFECT
     @layout.visible = self.visible
 end      
 
 #--------------------------------------------------------------------------
 # * Show
 #--------------------------------------------------------------------------    
  alias mog_bg_ex_slide_show_enemy show
  def show
      self.viewport = nil
      self.x = @org_position[0] ; self.y = @org_position[1]
      if ENEMY_WINDOW_SLIDE_EFFECT
         self.x += ENEMY_WINDOW_SLIDE_POSITION[0]
         self.y += ENEMY_WINDOW_SLIDE_POSITION[1]
      end
      self.opacity = ENEMY_WINDOW_OPACITY
      mog_bg_ex_slide_show_enemy
  end  
 
 #--------------------------------------------------------------------------
 # * Update
 #--------------------------------------------------------------------------  
 alias mog_monogatari_enemy_window_update update
 def update
     mog_monogatari_enemy_window_update
     self.visible = false if @force_hide
     if @layout != nil and @layout.visible != self.visible        
        refresh_layout
     end
     if !$game_temp.sprite_visible   
        self.visible = false 
        @layout.visible = self.visible if @layout != nil
     end   
     execute_slide_effect if self.visible
  end   
 
  if $imported["YEA-BattleEngine"] 
  #--------------------------------------------------------------------------
  # * Draw Item
  #--------------------------------------------------------------------------
  def draw_item(index)
      change_color(normal_color)
      name = $game_troop.alive_members[index].name
      draw_text(item_rect_for_text(index), name)
  end 
  end
 
  #--------------------------------------------------------------------------
  # * Process Cursor Move
  #--------------------------------------------------------------------------
  alias mog_atb_wenemy_process_cursor_move process_cursor_move
  def process_cursor_move
      return if SceneManager.scene_is?(Scene_Battle) and !$game_temp.sprite_visible
      mog_atb_wenemy_process_cursor_move
  end
 
  #--------------------------------------------------------------------------
  # * Process Handling
  #--------------------------------------------------------------------------
  alias mog_atb_wenemy_process_handling process_handling
  def process_handling  
      return if SceneManager.scene_is?(Scene_Battle) and !$game_temp.sprite_visible 
      mog_atb_wenemy_process_handling
  end  
 
end
 
#==============================================================================
# ** Window_BattleSkill
#==============================================================================
class Window_BattleSkill < Window_SkillList
 include MOG_BATTLE_HUD_EX
 
 #--------------------------------------------------------------------------
 # * Initialize
 #--------------------------------------------------------------------------   
 alias mog_monogatari_battle_skill_initialize initialize
 def initialize(help_window, info_viewport)
     @force_hide = can_force_hide?
     @force_hide_active = can_force_hide_active?     
     mog_monogatari_battle_skill_initialize(help_window, info_viewport)
     self.width = SKILL_WINDOW_SIZE[0]
     self.height = SKILL_WINDOW_SIZE[1]    
     @org_position = [SKILL_WINDOW_POSITION[0],
          Graphics.height - self.height + SKILL_WINDOW_POSITION[1]]
     self.x = @org_position[0]
     self.y = @org_position[1]
     self.opacity = SKILL_WINDOW_OPACITY
     self.viewport = nil
     self.z = MOG_BATTLE_HUD_EX::HUD_Z + 150
     create_layout
 end
 
 #--------------------------------------------------------------------------
 # * Col Max
 #--------------------------------------------------------------------------    
  def col_max
      return SKILL_COL_MAX
  end 
 
 #--------------------------------------------------------------------------
 # * Can Force Hide Active?
 #--------------------------------------------------------------------------    
 def can_force_hide_active?
     return true if $imported[:ve_target_arrow]
     return true if $imported[:mog_battle_cursor] != nil
     return false
 end   
 
  #--------------------------------------------------------------------------
  # * Can Force Hide?
  #--------------------------------------------------------------------------    
  def can_force_hide?
      return false
  end 
 
 #--------------------------------------------------------------------------
 # * Dispose
 #-------------------------------------------------------------------------- 
 alias mog_monogatari_skill_window_dispose dispose
 def dispose
     mog_monogatari_skill_window_dispose
     dispose_layout
 end 
 
 #--------------------------------------------------------------------------
 # * Create Layout
 #--------------------------------------------------------------------------   
 def create_layout
     return if @layout != nil
     return if !SKILL_WINDOW_LAYOUT
     return if $game_temp.mbhud_window[5]
     $game_temp.mbhud_window[5] = true 
     @org_position_2 = [self.x + SKILL_WINDOW_LAYOUT_POSITION[0],self.y + SKILL_WINDOW_LAYOUT_POSITION[1]] 
     @layout = Sprite.new
     @layout.bitmap = Cache.battle_hud("Layout_Skill")
     @layout.z = self.z - 1
     refresh_layout
     @layout.visible = false
 end
 
 #--------------------------------------------------------------------------
 # * Dispose Layout
 #-------------------------------------------------------------------------- 
 def dispose_layout
     return if @layout == nil
     @layout.dispose
     @layout = nil
 end
 
 #--------------------------------------------------------------------------
 # * Refresh Layout
 #--------------------------------------------------------------------------
 def refresh_layout
     return if @layout == nil
     @layout.x = @org_position_2[0]
     @layout.y = @org_position_2[1]
     @layout.x += SKILL_WINDOW_SLIDE_POSITION[0] if SKILL_WINDOW_SLIDE_EFFECT
     @layout.y += SKILL_WINDOW_SLIDE_POSITION[1] if SKILL_WINDOW_SLIDE_EFFECT
     @layout.visible = self.visible
 end  
 
 #--------------------------------------------------------------------------
 # * Show
 #--------------------------------------------------------------------------    
  alias mog_bg_ex_slide_show_skill show
  def show
      self.viewport = nil
      self.x = @org_position[0] ; self.y = @org_position[1]
      if SKILL_WINDOW_SLIDE_EFFECT
         self.x += SKILL_WINDOW_SLIDE_POSITION[0]
         self.y += SKILL_WINDOW_SLIDE_POSITION[1]
      end
      self.opacity = SKILL_WINDOW_OPACITY
      mog_bg_ex_slide_show_skill
  end 
 
 #--------------------------------------------------------------------------
 # * Update
 #--------------------------------------------------------------------------  
 alias mog_monogatari_skill_window_update update
 def update
     mog_monogatari_skill_window_update
     self.visible = self.active if @force_hide_active
     self.visible = false if @force_hide
     if @layout != nil and @layout.visible != self.visible        
        refresh_layout
    end
    self.visible = false if !$game_temp.sprite_visible
    execute_slide_effect if self.visible
 end 
 
end
 
#==============================================================================
# ** Window_BattleItem
#==============================================================================
class Window_BattleItem < Window_ItemList
  include MOG_BATTLE_HUD_EX
 
 #--------------------------------------------------------------------------
 # * Initialize
 #--------------------------------------------------------------------------  
 alias mog_monogatari_battle_item_initialize initialize
 def initialize(help_window, info_viewport)
     @force_hide = can_force_hide?
     @force_hide_active = can_force_hide_active?
     mog_monogatari_battle_item_initialize(help_window, info_viewport)
     self.width = ITEM_WINDOW_SIZE[0]
     self.height = ITEM_WINDOW_SIZE[1]
     @org_position = [ITEM_WINDOW_POSITION[0],
          Graphics.height - self.height + ITEM_WINDOW_POSITION[1]]
     self.x = @org_position[0]
     self.y = @org_position[1]
     self.viewport = nil
     self.opacity = ITEM_WINDOW_OPACITY
     self.z = MOG_BATTLE_HUD_EX::HUD_Z + 150
     create_layout
 end  
 
 #--------------------------------------------------------------------------
 # * Col Max
 #--------------------------------------------------------------------------    
  def col_max
      return ITEM_COL_MAX
  end  
 
 #--------------------------------------------------------------------------
 # * Can Force Hide Active?
 #--------------------------------------------------------------------------    
 def can_force_hide_active?
     return true if $imported[:ve_target_arrow]
     return true if $imported[:mog_battle_cursor] != nil
     return false
 end  
 
 #--------------------------------------------------------------------------
 # * Can Force Hide?
 #--------------------------------------------------------------------------    
 def can_force_hide?
     return false
 end 
 
 #--------------------------------------------------------------------------
 # * Dispose
 #-------------------------------------------------------------------------- 
 alias mog_monogatari_item_window_dispose dispose
 def dispose
     mog_monogatari_item_window_dispose
     dispose_layout
 end 
 
 #--------------------------------------------------------------------------
 # * Create Layout
 #--------------------------------------------------------------------------   
 def create_layout
     return if @layout != nil
     return if !ITEM_WINDOW_LAYOUT
     return if $game_temp.mbhud_window[6]
     $game_temp.mbhud_window[6] = true
     @org_position_2 = [self.x + ITEM_WINDOW_LAYOUT_POSITION[0],self.y + ITEM_WINDOW_LAYOUT_POSITION[1]] 
     @layout = Sprite.new
     @layout.bitmap = Cache.battle_hud("Layout_Item")
     @layout.z = self.z - 1
     refresh_layout
     @layout.visible = false
 end
 
 #--------------------------------------------------------------------------
 # * Dispose Layout
 #-------------------------------------------------------------------------- 
 def dispose_layout
     return if @layout == nil
     @layout.dispose
     @layout = nil
 end
 
 #--------------------------------------------------------------------------
 # * Refresh Layout
 #--------------------------------------------------------------------------
 def refresh_layout
     return if @layout == nil
     @layout.x = @org_position_2[0]
     @layout.y = @org_position_2[1]
     @layout.x += ITEM_WINDOW_SLIDE_POSITION[0] if ITEM_WINDOW_SLIDE_EFFECT
     @layout.y += ITEM_WINDOW_SLIDE_POSITION[1] if ITEM_WINDOW_SLIDE_EFFECT
     @layout.visible = self.visible
 end  
 
 #--------------------------------------------------------------------------
 # * Show
 #--------------------------------------------------------------------------    
  alias mog_bg_ex_slide_show_item show
  def show
      self.viewport = nil
      self.x = @org_position[0] ; self.y = @org_position[1]
      if ITEM_WINDOW_SLIDE_EFFECT
         self.x += ITEM_WINDOW_SLIDE_POSITION[0]
         self.y += ITEM_WINDOW_SLIDE_POSITION[1]
      end
      self.opacity = ITEM_WINDOW_OPACITY
      mog_bg_ex_slide_show_item      
  end 
 
 #--------------------------------------------------------------------------
 # * Update
 #--------------------------------------------------------------------------  
 alias mog_monogatari_item_window_update update
 def update
     mog_monogatari_item_window_update
     self.visible = self.active if @force_hide_active
     self.visible = false if @force_hide
     if @layout != nil
        refresh_layout if @layout.visible != self.visible
     end
     self.visible = false if !$game_temp.sprite_visible
     execute_slide_effect if self.visible
  end  
 
end
 
end
 
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
#################################
if $imported["YEA-BattleEngine"]
#################################
 
#==============================================================================
# ** Window_BattleStatusAid
#==============================================================================
class Window_BattleStatusAid < Window_BattleStatus
 
 #--------------------------------------------------------------------------
 # * Refresh
 #--------------------------------------------------------------------------   
  def refresh
      contents.clear
      self.visible = false
  end
 
end
 
#==============================================================================
# ** Window_BattleStatus
#==============================================================================
class Window_BattleStatus < Window_Selectable
 
 #--------------------------------------------------------------------------
 # * Update
 #-------------------------------------------------------------------------- 
 alias mog_monogatari_bhud_yf_update update
 def update
     mog_monogatari_bhud_yf_update
     update_visible_yf
 end
 
 #--------------------------------------------------------------------------
 # * Update Visible Yf
 #-------------------------------------------------------------------------- 
 def update_visible_yf
     self.visible = self.active
     self.visible = false if !$game_temp.sprite_visible
 end
 
end  
 
#==============================================================================
# ■ Window ActorCommand
#==============================================================================
class Window_ActorCommand < Window_Command
 
 #--------------------------------------------------------------------------
 # * Show
 #-------------------------------------------------------------------------- 
  alias mog_bhud_yf_command_show show
  def show
      return if !BattleManager.can_enable_window?
      mog_bhud_yf_command_show
  end
 
 #--------------------------------------------------------------------------
 # * Update
 #-------------------------------------------------------------------------- 
 alias mog_monogatari_bhud_yf_actorcommand_update update
 def update
     mog_monogatari_bhud_yf_actorcommand_update
     update_visible_yf
 end 
 
 #--------------------------------------------------------------------------
 # * Update Visible Yf
 #-------------------------------------------------------------------------- 
 def update_visible_yf
     self.visible = self.active
     self.visible = false if !$game_temp.sprite_visible
 end 
 
end
 
#==============================================================================
# ** Scene Battle
#==============================================================================
class Scene_Battle < Scene_Base
 
  include MOG_BATTLE_HUD_EX
 
  #--------------------------------------------------------------------------
  # alias method: create_skill_window
  #--------------------------------------------------------------------------
  alias mog_yf_scene_battle_create_skill_window create_skill_window
  def create_skill_window
      mog_yf_scene_battle_create_skill_window
      @skill_window.width = SKILL_WINDOW_SIZE[0]
      @skill_window.height = SKILL_WINDOW_SIZE[1]
      @skill_window.x = SKILL_WINDOW_POSITION[0]
      @skill_window.y = SKILL_WINDOW_POSITION[1]
  end
 
  #--------------------------------------------------------------------------
  # alias method: create_item_window
  #--------------------------------------------------------------------------
  alias mog_yf_scene_battle_create_item_window create_item_window
  def create_item_window
      mog_yf_scene_battle_create_item_window
      @item_window.width = ITEM_WINDOW_SIZE[0]
      @item_window.height = ITEM_WINDOW_SIZE[1]
      @item_window.x = ITEM_WINDOW_POSITION[0]
      @item_window.y = ITEM_WINDOW_POSITION[1]
  end  
 
 if !$imported[:mog_atb_system]
 #--------------------------------------------------------------------------
 # * Next Command
 #--------------------------------------------------------------------------
  def next_command
    if BattleManager.next_command
       @status_window.show
       redraw_current_status
       @actor_command_window.show
       @status_aid_window.hide      
       start_actor_command_selection
    else
      turn_start
    end
  end
  end
 
 #--------------------------------------------------------------------------
 # * STW Can Visible
 #--------------------------------------------------------------------------   
  def stw_can_visible?
      return false if !BattleManager.can_enable_window?
      return false if @item_window.visible
      return false if @skill_window.visible
      return true if @actor_window.active
      return false
  end
 
 if $imported["YEA-CommandEquip"]
 #--------------------------------------------------------------------------
 # * Command Equip
 #--------------------------------------------------------------------------   
  alias mog_yf_command_equip command_equip
  def command_equip
      @actor_command_window.visible = false
      @actor_command_window.update
      $game_temp.battle_hud_visible_refresh = [true,false]
      @spriteset.update_battle_hud_ex
      @spriteset.battler_sprites.each do |s| s.dispose_animation end
      mog_yf_command_equip
      $game_temp.battle_hud_visible_refresh = [true,true]
  end 
  end
 
end
 
end
#--------------------------------------------------------------------------
 
 
######################################
if $imported["YEA-EnemyTargetInfo"]
######################################
 
#==============================================================================
# ■ Window_Comparison
#==============================================================================
class Window_Comparison < Window_Base
 
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------     
  alias mog_battle_hud_ex_yf_refresh refresh
  def refresh
      mog_battle_hud_ex_yf_refresh
      self.z = MOG_BATTLE_HUD_EX::HUD_Z + 152
      self.viewport = nil
  end
 
end
 
#==============================================================================
# ■ Window_ComparisonHelp
#==============================================================================
class Window_ComparisonHelp < Window_Base
 
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------     
  alias mog_battle_hud_ex_yf_refresh refresh
  def refresh
      mog_battle_hud_ex_yf_refresh
      self.z = MOG_BATTLE_HUD_EX::HUD_Z + 152
      self.viewport = nil
  end
 
end
end
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
 
 
#################################
if $imported["YEA-EnemyTargetInfo"]
#################################
class Window_Comparison < Window_Base
 
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  alias mog_battle_hud_yf_wcomparison_initialize initialize
  def initialize(type)
      mog_battle_hud_yf_wcomparison_initialize(type)
      self.z = 102
  end  
 
end
end
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
 
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
#################################
if $imported["YSA-CATB"]
#################################
 
#==============================================================================
# ■ Enemy CATB Gauge Viewport
#==============================================================================
class Enemy_CATB_Gauge_Viewport < Viewport
 
  #--------------------------------------------------------------------------
  # initialize
  #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_yami_initialize initialize
  def initialize(battler, sprite, type)
      mog_battle_hud_ex_yami_initialize(battler, sprite, type)
      self.z = 90
  end
 
end
 
#==============================================================================
# ■ Game_Battler
#==============================================================================
class Game_Battler < Game_BattlerBase
 
  attr_accessor :catb_value  
  attr_accessor :max_atb
 
  #--------------------------------------------------------------------------
  # * Max ATB
  #--------------------------------------------------------------------------    
  def max_atb
      return MAX_CATB_VALUE
      return 1
  end
 
end
 
end
#--------------------------------------------------------------------------
#--------------------------------------------------------------------------
 
#==============================================================================
# ** Window Base
#==============================================================================
class Window_Base < Window
 
 #--------------------------------------------------------------------------
 # * Execute Move W
 #--------------------------------------------------------------------------      
 def execute_move_w(sprite,type,cp,np)
     sp = 6 + ((cp - np).abs / 10)
     if cp > np ;    cp -= sp ; cp = np if cp < np
        elsif cp < np ; cp += sp ; cp = np if cp > np
     end     
     sprite.x = cp if type == 0 ; sprite.y = cp if type == 1
 end 
 
 #--------------------------------------------------------------------------
 # * Set BH EX Font
 #--------------------------------------------------------------------------    
  def set_bh_ex_font
      return if !MOG_BATTLE_HUD_EX::ENABLE_WINDOW_FONT_SET
      self.contents.font.bold = MOG_BATTLE_HUD_EX::WINDOW_FONT_BOLD
      self.contents.font.size = MOG_BATTLE_HUD_EX::WINDOW_FONT_SIZE
      self.contents.font.italic = MOG_BATTLE_HUD_EX::WINDOW_FONT_ITALIC
      self.contents.font.name = MOG_BATTLE_HUD_EX::WINDOW_FONT_NAME if MOG_BATTLE_HUD_EX::WINDOW_FONT_NAME != nil
  end
 
 #--------------------------------------------------------------------------
 # * Execute Slide Effect
 #--------------------------------------------------------------------------    
 def execute_slide_effect
     return if @org_position == nil
     execute_move_w(self,0,self.x,@org_position[0])
     execute_move_w(self,1,self.y,@org_position[1])
     return if @layout == nil
     execute_move_w(@layout,0,@layout.x,@org_position_2[0])
     execute_move_w(@layout,1,@layout.y,@org_position_2[1])     
 end     
 
end
 
#==============================================================================
# ** Window Help
#==============================================================================
class Window_Help < Window_Base
 
 #--------------------------------------------------------------------------
 # * Draw Text
 #--------------------------------------------------------------------------    
  alias mog_bh_ex_draw_text_help draw_text
  def draw_text(*args)
      set_bh_ex_font
      mog_bh_ex_draw_text_help(*args)
  end
 
end
 
#==============================================================================
# ** Window BattleActor
#==============================================================================
class Window_BattleActor < Window_BattleStatus
 
 #--------------------------------------------------------------------------
 # * Draw Item
 #--------------------------------------------------------------------------    
  alias mog_bbex_draw_item_actor draw_item
  def draw_item(index)
      set_bh_ex_font
      mog_bbex_draw_item_actor(index)
  end
 
end
 
#==============================================================================
# ** Window BattleEnemy
#==============================================================================
class Window_BattleEnemy < Window_Selectable
 
 #--------------------------------------------------------------------------
 # * Draw Item
 #--------------------------------------------------------------------------    
  alias mog_bbex_draw_item_enemy draw_item
  def draw_item(index)
      set_bh_ex_font
      mog_bbex_draw_item_enemy(index)
  end
 
end
 
#==============================================================================
# ** Window ItemList
#==============================================================================
class Window_ItemList < Window_Selectable
 
 #--------------------------------------------------------------------------
 # * Draw Item Name
 #--------------------------------------------------------------------------    
   alias mog_bhex_draw_item_name_item draw_item_name
   def draw_item_name(item, x, y, enabled = true, width = 172)
       set_bh_ex_font
       mog_bhex_draw_item_name_item(item, x, y, enabled , width )
   end  
 
end
 
#==============================================================================
# ** Window SkillList
#==============================================================================
class Window_SkillList < Window_Selectable  
 
 #--------------------------------------------------------------------------
 # * Draw Item Name
 #--------------------------------------------------------------------------    
   alias mog_bhex_draw_item_name_skill draw_item_name
   def draw_item_name(item, x, y, enabled = true, width = 172)
       set_bh_ex_font
       mog_bhex_draw_item_name_skill(item, x, y, enabled , width )
   end    
 
end
 
#==============================================================================
# ** Spriteset_Battle
#==============================================================================
class Spriteset_Battle
 
  #--------------------------------------------------------------------------
  # * Initialize
  #-------------------------------------------------------------------------- 
  alias mog_battle_hud_ex_initialize initialize
  def initialize
      check_screen_xyz_nil rescue nil
      mog_battle_hud_ex_initialize
      create_battle_hud_ex
  end
 
  #--------------------------------------------------------------------------
  # * Check Screen Xyz
  #--------------------------------------------------------------------------   
  def check_screen_xyz_nil
      return if !SceneManager.face_battler?
      for actor in $game_party.battle_members
          actor.screen_x = 0 if actor.screen_x == nil
          actor.screen_y = 0 if actor.screen_y == nil
          actor.screen_z = 0 if actor.screen_z == nil
      end
  end
 
  #--------------------------------------------------------------------------
  # * Check Screen Xyz after
  #--------------------------------------------------------------------------     
  def check_screen_xyz_after
      return if !SceneManager.face_battler?
      $game_party.battle_members.each_with_index do |actor, index|
          actor.screen_x = $game_temp.battler_face_pos[index][0] rescue nil
          actor.screen_y = $game_temp.battler_face_pos[index][1] rescue nil
          actor.screen_z = $game_temp.battler_face_pos[index][2] rescue nil
      end    
  end
 
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------  
  alias mog_battle_hud_ex_dispose dispose
  def dispose
      dispose_battle_hud_ex
      mog_battle_hud_ex_dispose
  end
 
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------  
  alias mog_battle_hud_ex_update update
  def update
      mog_battle_hud_ex_update
      update_battle_hud_ex
  end
 
  #--------------------------------------------------------------------------
  # * Create Battle Hud EX
  #--------------------------------------------------------------------------    
  def create_battle_hud_ex
      return if @battle_hud_ex != nil
      $game_temp.battle_hud_visible = true
      @battle_hud_ex = Monogatari_Bhud.new(nil)
      check_screen_xyz_after
  end
 
  #--------------------------------------------------------------------------
  # * Dispose Battle Hud EX
  #--------------------------------------------------------------------------   
  def dispose_battle_hud_ex
      return if @battle_hud_ex == nil
      @battle_hud_ex.dispose
      @battle_hud_ex = nil
      $game_temp.mbhud_window = [false,false,false,false,false,false,false]
  end
 
  #--------------------------------------------------------------------------
  # * Update Battle Hud EX
  #--------------------------------------------------------------------------    
  def update_battle_hud_ex
      refresh_battle_hud if $game_temp.mbhud_force_refresh
      return if @battle_hud_ex == nil
      @battle_hud_ex.update
  end
 
  #--------------------------------------------------------------------------
  # * Refresh Battle Hud
  #--------------------------------------------------------------------------    
  def refresh_battle_hud
      $game_temp.mbhud_force_refresh = false
      check_screen_xyz_nil rescue nil
      dispose_battle_hud_ex
      create_battle_hud_ex
  end
 
end
 
#==============================================================================
# ** Monogatari Bhud
#==============================================================================
class Monogatari_Bhud
 
  include MOG_BATTLE_HUD_EX
 
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------  
  def initialize(viewport)
      @battle_hud = [] ; @sprite_visitle_wait = 0
      $game_party.battle_members.each_with_index do |actor, index|
      @battle_hud.push(Battle_Hud_EX.new(actor,index,max_members,nil)) end
      create_turn_sprite(nil)
      create_screen_layout(nil)      
  end
 
  #--------------------------------------------------------------------------
  # * Max members
  #--------------------------------------------------------------------------    
  def max_members
      if $game_party.members.size > $game_party.max_battle_members
         return $game_party.max_battle_members
      end   
      return $game_party.members.size
  end
 
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------    
  def dispose
      @battle_hud.each {|sprite| sprite.dispose }
      dispose_turn_sprite
      dispose_screen_layout
  end
 
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------   
  def update
      @battle_hud.each {|sprite| sprite.update }
      update_turn_sprite
      update_screen_layout
      refresh_battle_hud_visible if $game_temp.battle_hud_visible_refresh[0]
  end
 
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------   
  def refresh_battle_hud_visible
      $game_temp.battle_hud_visible_refresh[0] = false
      @turn_sprite.visible = $game_temp.battle_hud_visible_refresh[1] if @turn_sprite != nil
      @screen_layout.visible = $game_temp.battle_hud_visible_refresh[1] if @screen_layout != nil
      @skill_name.visible = $game_temp.battle_hud_visible_refresh[1] if @skill_name != nil
      @battle_hud.each {|sprite| sprite.refresh_visible($game_temp.battle_hud_visible_refresh[1]) }
 end
 
end
 
#==============================================================================
# ** Monogatari Bhud
#==============================================================================
class Monogatari_Bhud
 
 #--------------------------------------------------------------------------
 # * Can Update Turn Sprite
 #-------------------------------------------------------------------------- 
  def can_refresh_turn_sprite?
      return true if @turn_sprite.visible != $game_temp.command_visible
      return true if $game_temp.refresh_turn_sprite
      return false
  end
 
 #--------------------------------------------------------------------------
 # * Create Turn Sprite
 #-------------------------------------------------------------------------- 
  def create_turn_sprite(viewport)
      return if !TURN_SPRITE_VISIBLE
      return if @turn_sprite != nil
      @turn_sprite = Sprite.new
      @turn_sprite.bitmap = Cache.battle_hud("Turn")
      @turn_sprite.viewport = viewport
      @turn_sprite.z = HUD_Z + TURN_SPRITE_Z
      @turn_sprite.visible = false
      @turn_sprite_update_time = 5
      @turn_sprite_blink = [0,0]
  end
 
 #--------------------------------------------------------------------------
 # * Dispose Turn Sprite
 #-------------------------------------------------------------------------- 
  def dispose_turn_sprite
      return if @turn_sprite == nil
      @turn_sprite.dispose
      @turn_sprite = nil
  end
 
 #--------------------------------------------------------------------------
 # * Update Turn Sprite
 #-------------------------------------------------------------------------- 
  def update_turn_sprite
      return if @turn_sprite == nil
      if @turn_sprite_update_time > 0 
         @turn_sprite_update_time -= 1
         return 
      end  
      update_turn_visible
      update_turn_blink
  end
 
 #--------------------------------------------------------------------------
 # * Update Turn Visible
 #--------------------------------------------------------------------------   
  def update_turn_visible    
      $game_temp.refresh_turn_sprite = false
      @turn_sprite.visible = can_turn_sprite_visible?
      return if BattleManager.actor == nil 
      x = $game_temp.hud_pos_real[BattleManager.actor.index][0] + TURN_SPRITE_POSITION[0] rescue nil
      y = $game_temp.hud_pos_real[BattleManager.actor.index][1] + TURN_SPRITE_POSITION[1] rescue nil
      x = -1000 if x == nil ; y = -1000 if y == nil
      @turn_sprite.x = x ; @turn_sprite.y = y      
 end
 
 #--------------------------------------------------------------------------
 # * Can Turn Sprite Visible?
 #--------------------------------------------------------------------------   
 def can_turn_sprite_visible?
     return false if BattleManager.actor == nil
     return false if $game_temp.battle_end
     return false if $game_message.visible
     return true
 end
 
 #--------------------------------------------------------------------------
 # * Update Turn Blink
 #--------------------------------------------------------------------------   
 def update_turn_blink
     return if !TURN_BLINK_EFFECT
     return if !@turn_sprite.visible
     @turn_sprite_blink[0] += 1
     case @turn_sprite_blink[0]
       when 0..30
          @turn_sprite_blink[1] += 3
       when 31..60
          @turn_sprite_blink[1] -= 3
       else
         @turn_sprite_blink = [0,0]
     end
     @turn_sprite.opacity = 150 + @turn_sprite_blink[1]
 end
 
 
end
 
#==============================================================================
# ** Monogatari Bhud
#==============================================================================
class Monogatari_Bhud
 
  #--------------------------------------------------------------------------
  # * Create Screen Layout
  #--------------------------------------------------------------------------    
  def create_screen_layout(viewport)
      return if !SCREEN_LAYOUT
      @screen_layout = Sprite.new
      @screen_layout.bitmap = Cache.battle_hud("Layout_Screen")
      @screen_layout.z = HUD_Z + SCREEN_LAYOUT_Z
      @screen_layout.x = SCREEN_LAYOUT_POSITION[0]
      @screen_layout.y = SCREEN_LAYOUT_POSITION[1]
      @screen_layout.opacity = 0
      @screen_layout.viewport = viewport
   end     
 
  #--------------------------------------------------------------------------
  # * Dispose Screen Layout
  #--------------------------------------------------------------------------
   def dispose_screen_layout
       return if @screen_layout == nil
       @screen_layout.dispose ; @screen_layout = nil     
   end
 
  #--------------------------------------------------------------------------
  # * Update Screen Layout
  #--------------------------------------------------------------------------
   def update_screen_layout
       return if @screen_layout == nil
       @sprite_visitle_wait -= 1 if @sprite_visitle_wait > 0
       sprite_visible(@screen_layout)
   end
 
  #--------------------------------------------------------------------------
  # * Sprite Visible
  #--------------------------------------------------------------------------
  def sprite_visible?
      return false if $game_message.visible and MESSAGE_WINDOW_FADE_HUD
      return false if !$game_temp.battle_hud_visible
      return false if !$game_temp.sprite_visible
      return true
  end
 
  #--------------------------------------------------------------------------
  # * Sprite Visible
  #--------------------------------------------------------------------------
  def sprite_visible(sprite)      
      if sprite_visible?
         sprite.opacity += 5 unless @sprite_visitle_wait > 0
      else
         sprite.opacity -= 10 ; @sprite_visitle_wait = 5
      end
  end   
 
end
 
#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
  include MOG_BATTLE_HUD_EX
 
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------  
  def initialize(actor = nil,index = 0, max_members = 0,viewport = nil)
      pre_cache
      setup(actor,index,max_members)
      create_sprites(viewport)
  end
 
  #--------------------------------------------------------------------------
  # * Setup
  #--------------------------------------------------------------------------    
  def setup(actor,index,max_members)
      $game_temp.battle_end = false
      @actor = actor
      @actor_index = index
      @max_members = max_members
      @actor.face_animation = [0,0,0]
      @hp_icon_max = -1
      @hp_icon_old = -1
      @hp_icon_col_max = HP_ICON_COL_MAX
      @hp_icon_col_max = 1 if @hp_icon_col_max <= 0
      @hp_icon_row_max = HP_ICON_ROW_MAX
      @hp_icon_row_max = 1 if @hp_icon_row_max <= 0
      @hp_icon_real_max = @hp_icon_col_max * @hp_icon_row_max
      @mp_icon_max = -1
      @mp_icon_old = -1
      @mp_icon_col_max = MP_ICON_COL_MAX
      @mp_icon_col_max = 1 if @mp_icon_col_max <= 0
      @mp_icon_row_max = MP_ICON_ROW_MAX
      @mp_icon_row_max = 1 if @mp_icon_row_max <= 0
      @mp_icon_real_max = @mp_icon_col_max * @mp_icon_row_max
      @tp_icon_max = -1
      @tp_icon_old = -1
      @tp_icon_col_max = TP_ICON_COL_MAX
      @tp_icon_col_max = 1 if @tp_icon_col_max <= 0
      @tp_icon_row_max = TP_ICON_ROW_MAX
      @tp_icon_row_max = 1 if @tp_icon_row_max <= 0
      @tp_icon_real_max = @tp_icon_col_max * @tp_icon_row_max
      @sprite_visible = true
      @sprite_visitle_wait = 0
      setup_actor
      setup_position
  end
 
  #--------------------------------------------------------------------------
  # * Setup Actor
  #--------------------------------------------------------------------------    
  def setup_actor
      return if @actor == nil
      @hp_number_refresh = true
      @hp_number2_refresh = true
      @hp_number_old = @actor.hp
      @hp_number2_old = @actor.mhp
      @hp_old_meter = 0      
      @mp_number_refresh = true
      @mp_number2_refresh = true
      @mp_number_old = @actor.mp
      @mp_number2_old = @actor.mmp
      @mp_old_meter = 0      
      @tp_number_refresh = true
      @tp_number2_refresh = true
      @tp_number_old = @actor.tp
      @tp_number2_old = @actor.max_tp  
      @tp_old_meter = 0
      @at_number_refresh = true
      @at_number2_refresh = true
      @at_number_old = actor_at
      @at_number2_old = actor_max_at 
      @at_old_meter = 0
      catb = ATB::MAX_AP rescue nil
      @ccwinter_atb = true if catb != nil
  end  
 
  #--------------------------------------------------------------------------
  # * Terminate
  #--------------------------------------------------------------------------    
  def terminate
      @actor.atb = 0 rescue nil if $imported[:ve_active_time_battle]
  end
 
  #--------------------------------------------------------------------------
  # * AT
  #--------------------------------------------------------------------------  
  def actor_at
      return @actor.atb if $imported[:mog_atb_system]
      return @actor.atb if $imported[:ve_active_time_battle]
      return @actor.catb_value if $imported["YSA-CATB"]
      return @actor.ap if @ccwinter_atb != nil
      return 0
  end
 
  #--------------------------------------------------------------------------
  # * Max AT
  #--------------------------------------------------------------------------  
  def actor_max_at
      return @actor.atb_max if $imported[:mog_atb_system]
      return @actor.max_atb if $imported[:ve_active_time_battle]
      return @actor.max_atb if $imported["YSA-CATB"]
      return ATB::MAX_AP if @ccwinter_atb != nil
      return 1
  end
 
  #--------------------------------------------------------------------------
  # ● Actor Cast
  #--------------------------------------------------------------------------            
  def actor_cast
      return @actor.atb_cast[1] if $imported[:mog_atb_system]
      return @actor.atb if $imported[:ve_active_time_battle]
      return @actor.chant_count rescue 0 if @ccwinter_atb != nil 
      return 0
  end
 
  #--------------------------------------------------------------------------
  # ● Actor Max Cast
  #--------------------------------------------------------------------------            
  def actor_max_cast
      if $imported[:mog_atb_system]
         return @actor.atb_cast[2] if @actor.atb_cast[2] != 0
         return @actor.atb_cast[0].speed.abs
      end    
      return @actor.max_atb if $imported[:ve_active_time_battle]
      return @actor.max_chant_count rescue 1 if @ccwinter_atb != nil 
      return 1
  end
 
  #--------------------------------------------------------------------------
  # ● Actor Cast?
  #--------------------------------------------------------------------------            
  def actor_cast?   
      if $imported[:mog_atb_system]
         return true if !@actor.atb_cast.empty?
      end   
      if $imported[:ve_active_time_battle]
         return true if @actor.cast_action?
      end       
      if @ccwinter_atb 
         return true if @actor.chanting? 
      end
      return false
  end  
 
  #--------------------------------------------------------------------------
  # * Create Sprites
  #--------------------------------------------------------------------------    
  def create_sprites(viewport)
      dispose
      return if @actor == nil
      create_layout(viewport)
      create_layout_2(viewport)
      create_name(viewport)
      create_face(viewport)
      create_hp_number(viewport)
      create_hp_number_max(viewport)
      create_hp_meter(viewport)
      create_hp_icon(viewport)
      create_hp_icon_ex(viewport)
      create_hp_icon_number(viewport)
      create_mp_number(viewport)
      create_mp_number_max(viewport)
      create_mp_meter(viewport)
      create_mp_icon(viewport)
      create_mp_icon_ex(viewport)
      create_mp_icon_number(viewport)
      create_tp_number(viewport)
      create_tp_number_max(viewport)
      create_tp_meter(viewport)
      create_tp_icon(viewport)
      create_tp_icon_ex(viewport)
      create_tp_icon_number(viewport)
      create_at_number(viewport)
      create_at_number_max(viewport)
      create_at_meter(viewport)      
      create_level_number(viewport)
      create_states(viewport)
      update
  end    
 
  #--------------------------------------------------------------------------
  # * Sprite Visible
  #--------------------------------------------------------------------------
  def sprite_visible?
      return false if $game_message.visible and MESSAGE_WINDOW_FADE_HUD
      return false if !$game_temp.battle_hud_visible
      return false if !$game_temp.sprite_visible
      return true
  end
 
  #--------------------------------------------------------------------------
  # * Sprite Visible
  #--------------------------------------------------------------------------
  def sprite_visible(sprite)
      if @sprite_visible         
         sprite.opacity += 5 unless @sprite_visitle_wait > 0
      else
         sprite.opacity -= 10 ; @sprite_visitle_wait = 5
      end
  end
 
end
 
#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
 
  #--------------------------------------------------------------------------
  # * Setup Position
  #--------------------------------------------------------------------------
  def setup_position
      sprite_width = (Graphics.width - 64) / 4
      sprite_center = sprite_width / 2  
      if $game_party.battle_members.size > 4
         members = $game_party.battle_members.size - 4
         fx = 32 * members
       else
         fx = 0
      end   
      space_x = MEMBERS_SPACE[0] - fx
      space_y = MEMBERS_SPACE[1]      
      center = Graphics.width / 2
      members_space = (Graphics.width + space_x) / @max_members
      members_space2 = (members_space * @actor_index)      
      members_space3 = ((members_space / 2) * (@max_members - 1))
      members_space_y = space_y * @actor_index
      x = HUD_POSITION[0] - sprite_center + center + members_space2 - members_space3
      screen_resize_y = 0
      screen_resize_y = (Graphics.height - 416) if Graphics.height > 416
      y = HUD_POSITION[1] + members_space_y + screen_resize_y
      @hud_position = [x,y]
      $game_temp.hud_pos_real[@actor_index] = [] if $game_temp.hud_pos_real[@actor_index] == nil
      $game_temp.hud_pos_real[@actor_index] = [x,y]
      x2 = x + sprite_center 
      $game_temp.hud_pos[@actor_index] = [] if $game_temp.hud_pos[@actor_index] == nil
      $game_temp.hud_pos[@actor_index] = [x2,y]
      if FIXED_HUD_POSITION[@actor_index] != nil     
         @hud_position = [FIXED_HUD_POSITION[@actor_index][0],FIXED_HUD_POSITION[@actor_index][1]]
         $game_temp.hud_pos_real[@actor_index] = [@hud_position[0],@hud_position[1]]
         $game_temp.hud_pos[@actor_index] = [] if $game_temp.hud_pos[@actor_index] == nil
         $game_temp.hud_pos[@actor_index] = [Graphics.width / 2,(Graphics.height / 2) + 96]    
      end      
  end
 
end
 
#==============================================================================
# ** Game Temp
#==============================================================================
class Game_Temp
 
  attr_accessor :cache_bhud_sprites
 
  #--------------------------------------------------------------------------
  # * Cache Battle Hud
  #--------------------------------------------------------------------------  
  def cache_battle_hud      
      execute_cache_bhud_sprites if @cache_bhud_sprites == nil
  end
 
  #--------------------------------------------------------------------------
  # * Execute Cache Bhud Sprites
  #--------------------------------------------------------------------------  
  def execute_cache_bhud_sprites
      @cache_bhud_sprites = []
      windows = ["Layout_Command","Layout_Party","Layout_Help",
      "Layout_Target_Actor","Layout_Target_Enemy","Layout_Skill",
      "Layout_Item"]
      for s in windows
          @cache_bhud_sprites.push(Cache.battle_hud(s)) rescue nil
      end
      sprites = ["Layout","Layout_2",
     "MP_Number","Max_MP_Number","MP_Icon","MP_Icon_EX","MP_Icon_Number",
     "TP_Number","Max_TP_Number","TP_Icon","TP_Icon_EX","TP_Icon_Number",  
     "AT_Number","Max_AT_Number","AT_Icon","AT_Icon_EX","AT_Icon_Number",  
     "LV_Number","Turn","Iconset","Layout_Screen"
      ]
      for s in sprites
          @cache_bhud_sprites.push(Cache.battle_hud(s)) rescue nil
      end      
  end
 
end
 
#==============================================================================
# ** Spriteset_Map
#==============================================================================
class Spriteset_Map
 
  #--------------------------------------------------------------------------
  # * Initialize
  #--------------------------------------------------------------------------
  alias mog_monogatari_bhud_initialize initialize
  def initialize
      $game_temp.cache_battle_hud
      mog_monogatari_bhud_initialize
  end
 
end
 
#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
 
  #--------------------------------------------------------------------------
  # * Pre Cache
  #--------------------------------------------------------------------------
  def pre_cache
      $game_temp.cache_battle_hud
      @force_hide = false
      @force_hide_time = 0
      @fade_hud = false
      @fade_hud_gold = false     
      @fade_hud_equip = false
      @layout_image = Cache.battle_hud("Layout")
      @layout_cw = @layout_image.width
      @layout_ch = @layout_image.height
      @layout2_image = Cache.battle_hud("Layout_2") rescue nil
      @layout2_cw = @layout2_image.width if @layout2_image != nil
      @layout2_ch = @layout2_image.height if @layout2_image != nil
      @layout2_cw = 0 if @layout2_cw == nil      
      #------------------------------------------------
      # HP
      #------------------------------------------------
      if HP_NUMBER_VISIBLE
         @hp_number_image = Cache.battle_hud("HP_Number")
         @hp_number_cw = @hp_number_image.width / 10
         if HP_NUMBER_LOW_COLOR
            @hp_number_ch = @hp_number_image.height / 2
         else
            @hp_number_ch = @hp_number_image.height
         end   
         @hp_wave_number = HP_NUMBER_WAVE_ALIGN_EFFECT
         @hp_number_ch += (@hp_number_ch / 2) if @hp_wave_number      
      end
      if HP_NUMBER_MAX_VISIBLE
         @hp_number2_image = Cache.battle_hud("Max_HP_Number")
         @hp_number2_cw = @hp_number2_image.width / 10
         @hp_number2_ch = @hp_number2_image.height
      end
      if HP_METER_VISIBLE
         @hp_meter_image = Cache.battle_hud("HP_Meter")
         if HP_METER_GRADIENT_ANIMATION
            @hp_meter_cw = @hp_meter_image.width / 3
         else   
            @hp_meter_cw = @hp_meter_image.width
         end   
         if HP_METER_REDUCTION_ANIMATION
            @hp_meter_ch = @hp_meter_image.height / 2
         else
            @hp_meter_ch = @hp_meter_image.height
         end  
      end
      if HP_ICON_VISIBLE
         @hp_icon_image = Cache.battle_hud("HP_Icon")
         @hp_icon_cw = @hp_icon_image.width / 2 
         @hp_icon_ch = @hp_icon_image.height
      end
      if HP_ICON_EX_VISIBLE
         @hp_icon2_image = Cache.battle_hud("HP_Icon_EX")
         @hp_icon2_cw = @hp_icon2_image.width
         @hp_icon2_ch = @hp_icon2_image.height        
      end      
      if HP_ICON_NUMBER_VISIBLE
         @hp_icon_number_image = Cache.battle_hud("HP_Icon_Number")
         @hp_icon_number_cw = @hp_icon_number_image.width / 10 
         @hp_icon_number_ch = @hp_icon_number_image.height        
      end
      #------------------------------------------------
      # MP
      #------------------------------------------------
      if MP_NUMBER_VISIBLE
         @mp_number_image = Cache.battle_hud("MP_Number")
         @mp_number_cw = @mp_number_image.width / 10
         if MP_NUMBER_LOW_COLOR
            @mp_number_ch = @mp_number_image.height / 2
         else
            @mp_number_ch = @mp_number_image.height
        end
        @mp_wave_number = MP_NUMBER_WAVE_ALIGN_EFFECT
        @mp_number_ch += (@mp_number_ch / 2) if @mp_wave_number
      end
      if MP_NUMBER_MAX_VISIBLE
         @mp_number2_image = Cache.battle_hud("Max_MP_Number")
         @mp_number2_cw = @mp_number2_image.width / 10
         @mp_number2_ch = @mp_number2_image.height
      end
      if MP_METER_VISIBLE
         @mp_meter_image = Cache.battle_hud("MP_Meter") 
         if MP_METER_GRADIENT_ANIMATION
            @mp_meter_cw = @mp_meter_image.width / 3
         else   
            @mp_meter_cw = @mp_meter_image.width
         end  
         if MP_METER_REDUCTION_ANIMATION
            @mp_meter_ch = @mp_meter_image.height / 2
         else
            @mp_meter_ch = @mp_meter_image.height
         end
      end
      if MP_ICON_VISIBLE
         @mp_icon_image = Cache.battle_hud("MP_Icon")
         @mp_icon_cw = @mp_icon_image.width / 2 
         @mp_icon_ch = @mp_icon_image.height
      end
      if MP_ICON_EX_VISIBLE
         @mp_icon2_image = Cache.battle_hud("MP_Icon_EX")
         @mp_icon2_cw = @mp_icon2_image.width
         @mp_icon2_ch = @mp_icon2_image.height        
      end      
      if MP_ICON_NUMBER_VISIBLE
         @mp_icon_number_image = Cache.battle_hud("MP_Icon_Number")
         @mp_icon_number_cw = @mp_icon_number_image.width / 10 
         @mp_icon_number_ch = @mp_icon_number_image.height        
      end
      #------------------------------------------------
      # TP
      #------------------------------------------------
      if TP_NUMBER_VISIBLE
         @tp_number_image = Cache.battle_hud("TP_Number")
         @tp_number_cw = @tp_number_image.width / 10
         if TP_NUMBER_LOW_COLOR
            @tp_number_ch = @tp_number_image.height / 2
         else
            @tp_number_ch = @tp_number_image.height
         end  
        @tp_wave_number = TP_NUMBER_WAVE_ALIGN_EFFECT
        @tp_number_ch += (@tp_number_ch / 2) if @tp_wave_number      
      end
      if TP_NUMBER_MAX_VISIBLE
         @tp_number2_image = Cache.battle_hud("Max_TP_Number")
         @tp_number2_cw = @tp_number2_image.width / 10
         @tp_number2_ch = @tp_number2_image.height
      end
      if TP_METER_VISIBLE
         @tp_meter_image = Cache.battle_hud("TP_Meter")
         if TP_METER_GRADIENT_ANIMATION
            @tp_meter_cw = @tp_meter_image.width / 3
         else   
            @tp_meter_cw = @tp_meter_image.width
         end  
         if TP_METER_REDUCTION_ANIMATION
            @tp_meter_ch = @tp_meter_image.height / 2      
         else
            @tp_meter_ch = @tp_meter_image.height
         end   
      end        
      if TP_ICON_VISIBLE
         @tp_icon_image = Cache.battle_hud("TP_Icon")
         @tp_icon_cw = @tp_icon_image.width / 2
         @tp_icon_ch = @tp_icon_image.height
      end  
      if TP_ICON_EX_VISIBLE
         @tp_icon2_image = Cache.battle_hud("TP_Icon_EX")
         @tp_icon2_cw = @tp_icon2_image.width 
         @tp_icon2_ch = @tp_icon2_image.height        
      end      
      if TP_ICON_NUMBER_VISIBLE
         @tp_icon_number_image = Cache.battle_hud("TP_Icon_Number")
         @tp_icon_number_cw = @tp_icon_number_image.width / 10 
         @tp_icon_number_ch = @tp_icon_number_image.height        
      end 
      #------------------------------------------------
      # AT
      #------------------------------------------------
      if AT_NUMBER_VISIBLE
         @at_number_image = Cache.battle_hud("AT_Number")
         @at_number_cw = @at_number_image.width / 10
         @at_number_ch = @at_number_image.height
         @at_wave_number = AT_NUMBER_WAVE_ALIGN_EFFECT
         @at_number_ch += (@at_number_ch / 2) if @at_wave_number      
      end
      if AT_NUMBER_MAX_VISIBLE
         @at_number2_image = Cache.battle_hud("Max_AT_Number")
         @at_number2_cw = @at_number2_image.width / 10
         @at_number2_ch = @at_number2_image.height
      end
      if AT_METER_VISIBLE
         @at_meter_image = Cache.battle_hud("AT_Meter")
         if AT_METER_GRADIENT_ANIMATION
            @at_meter_cw = @at_meter_image.width / 3
         else   
            @at_meter_cw = @at_meter_image.width
         end   
         @at_meter_ch = @at_meter_image.height / 3
      end
      #------------------------------------------------
      # LV
      #------------------------------------------------  
      if LEVEL_NUMBER_VISIBLE
         @lv_number_image = Cache.battle_hud("LV_Number")
         @lv_number_cw = @lv_number_image.width / 10
         @lv_number_ch = @lv_number_image.height
      end      
      #------------------------------------------------
      # ICON
      #------------------------------------------------  
      if STATES_VISIBLE or EQUIPMENT_VISIBLE 
         @icon_image = Cache.system("Iconset")
      end         
  end
 
  #--------------------------------------------------------------------------
  # * Check Icon Image
  #--------------------------------------------------------------------------          
  def check_icon_image
      if @icon_image == nil or @icon_image.disposed?
         @icon_image = Cache.system("Iconset")
      end   
  end  
 
end
 
#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
 
  #--------------------------------------------------------------------------
  # * Update Number
  #--------------------------------------------------------------------------    
  def update_number(type,value)
      actor_value = @actor.hp if type == 0
      actor_value = @actor.mp if type == 1
      actor_value = @actor.tp if type == 2
      actor_value = @actor.mhp if type == 3
      actor_value = @actor.mmp if type == 4
      actor_value = @actor.max_tp if type == 5
      actor_value = actor_at if type == 6
      actor_value = actor_max_at if type == 7
      if value < actor_value
         value += number_refresh_speed(actor_value,value)
         value = actor_value if value >= actor_value
         refresh_sprite_number(type,value) 
     elsif value > actor_value
         value -= number_refresh_speed(actor_value,value)
         value = actor_value if value <= actor_value
         refresh_sprite_number(type,value)
     end  
  end
 
  #--------------------------------------------------------------------------
  # * Number Refresh Speed
  #--------------------------------------------------------------------------      
  def number_refresh_speed(actor_value,value)
      n =  1 * (actor_value - value).abs / 10
      return [[n, 99999999].min,1].max    
  end
 
  #--------------------------------------------------------------------------
  # * Update Number Fix
  #--------------------------------------------------------------------------      
  def update_number_fix(type)
      if type == 0
         @hp_number_old =  @actor.hp
         @hp_number_refresh = true
      elsif type == 1 
         @mp_number_old =  @actor.mp
         @mp_number_refresh = true
      elsif type == 2 
         @tp_number_old =  @actor.tp
         @tp_number_refresh = true  
      elsif type == 3
         @hp_number2_old =  @actor.mhp
         @hp_number2_refresh = true
      elsif type == 4 
         @mp_number2_old =  @actor.mmp
         @mp_number2_refresh = true
      elsif type == 5 
         @tp_number2_old =  @actor.max_tp
         @tp_number2_refresh = true  
      elsif type == 6 
         @at_number_old =  actor_at
         @at_number_refresh = true         
      elsif type == 7 
         @at_number2_old = actor_max_at
         @at_number2_refresh = true            
      end   
  end  
 
  #--------------------------------------------------------------------------
  # * Refresh Sprite Number
  #--------------------------------------------------------------------------   
  def refresh_sprite_number(type,value)    
      @hp_number_refresh = true if type == 0
      @hp_number_old = value if type == 0
      @mp_number_refresh = true if type == 1
      @mp_number_old = value if type == 1
      @tp_number_refresh = true if type == 2
      @tp_number_old = value if type == 2
      @hp_number2_refresh = true if type == 3
      @hp_number2_old = value if type == 3
      @mp_number2_refresh = true if type == 4
      @mp_number2_old = value if type == 4
      @tp_number2_refresh = true if type == 5
      @tp_number2_old = value if type == 5
      @at_number_refresh = true if type == 6
      @at_number_old = value if type == 6
      @at_number2_refresh = true if type == 7
      @at_number2_old = value if type == 7
  end  
 
  #--------------------------------------------------------------------------
  # * Refresh Number
  #--------------------------------------------------------------------------    
  def refresh_number(type,value,sprite,image,number_cw,number_ch,wave_number = false)
      sprite.bitmap.clear
      clear_number_refresh(type) 
      number_color = low_number_color(type,number_ch)
      if type == 0 and HP_NUMBER_PERCENTAGE
         value_max = @actor.mhp 
         value = value.to_f / value_max.to_f * 100
         value = 1 if (value < 0 and @actor.hp > 0) or @actor.hp == 1
      elsif type == 1 and MP_NUMBER_PERCENTAGE
         value_max = @actor.mmp 
         value = value.to_f / value_max.to_f * 100
      elsif type == 2 and TP_NUMBER_PERCENTAGE
         value_max = @actor.max_tp 
         value = value.to_f / value_max.to_f * 100  
      elsif type == 3 and HP_NUMBER_PERCENTAGE
         value = 100
      elsif type == 4 and MP_NUMBER_PERCENTAGE
         value = 100
      elsif type == 5 and TP_NUMBER_PERCENTAGE
         value = 100
      elsif type == 6 and AT_NUMBER_PERCENTAGE
         value_max = actor_max_at
         value = value.to_f / value_max.to_f * 100
      elsif type == 7 and AT_NUMBER_PERCENTAGE
         value = 100         
      end
      value = 9999999 if value > 9999999 
      number_value = value.truncate.abs.to_s.split(//)
      wave_h = 0
      wave_h2 = wave_number ? (number_ch / 3) : 0
      wave_h3 = number_color != 0 ? wave_h2 : 0 
      for r in 0..number_value.size - 1         
         number_value_abs = number_value[r].to_i 
         wh = wave_h2 * wave_h
         wh2 = wave_h == 0 ? wave_h2 : 0
         nsrc_rect = Rect.new(number_cw * number_value_abs, number_color - wave_h3, number_cw, number_ch - wh2)
         sprite.bitmap.blt(number_cw *  r, wh, image, nsrc_rect) 
         wave_h = wave_h == 0 ? 1 : 0
      end
      refresh_number_position(type,number_value.size,number_cw)
  end
 
  #--------------------------------------------------------------------------
  # * Refresh Number
  #--------------------------------------------------------------------------     
  def refresh_number_position(type,number_value,number_cw)
      cx = number_value * number_cw
      if type == 0
         case HP_NUMBER_ALIGN_TYPE
           when 0; @hp_number.x = @hud_position[0] + HP_NUMBER_POSITION[0]
           when 1; @hp_number.x = @hud_position[0] + HP_NUMBER_POSITION[0] - (cx / 2)
           when 2; @hp_number.x = @hud_position[0] + HP_NUMBER_POSITION[0] - cx
         end            
      elsif type == 1
         case MP_NUMBER_ALIGN_TYPE
           when 0; @mp_number.x = @hud_position[0] + MP_NUMBER_POSITION[0]
           when 1; @mp_number.x = @hud_position[0] + MP_NUMBER_POSITION[0] - (cx / 2)
           when 2; @mp_number.x = @hud_position[0] + MP_NUMBER_POSITION[0] - cx
         end     
      elsif type == 2  
         case TP_NUMBER_ALIGN_TYPE
           when 0; @tp_number.x = @hud_position[0] + TP_NUMBER_POSITION[0]
           when 1; @tp_number.x = @hud_position[0] + TP_NUMBER_POSITION[0] - (cx / 2)
           when 2; @tp_number.x = @hud_position[0] + TP_NUMBER_POSITION[0] - cx
         end           
      elsif type == 3   
         case HP_NUMBER_ALIGN_TYPE
           when 0; @hp_number2.x = @hud_position[0] + HP_NUMBER_MAX_POSITION[0]
           when 1; @hp_number2.x = @hud_position[0] + HP_NUMBER_MAX_POSITION[0] - (cx / 2)
           when 2; @hp_number2.x = @hud_position[0] + HP_NUMBER_MAX_POSITION[0] - cx
         end           
      elsif type ==  4
         case MP_NUMBER_ALIGN_TYPE
           when 0; @mp_number2.x = @hud_position[0] + MP_NUMBER_MAX_POSITION[0]
           when 1; @mp_number2.x = @hud_position[0] + MP_NUMBER_MAX_POSITION[0] - (cx / 2)
           when 2; @mp_number2.x = @hud_position[0] + MP_NUMBER_MAX_POSITION[0] - cx
         end          
      elsif type ==  5
         case TP_NUMBER_ALIGN_TYPE
           when 0; @tp_number2.x = @hud_position[0] + TP_NUMBER_MAX_POSITION[0]
           when 1; @tp_number2.x = @hud_position[0] + TP_NUMBER_MAX_POSITION[0] - (cx / 2)
           when 2; @tp_number2.x = @hud_position[0] + TP_NUMBER_MAX_POSITION[0] - cx
         end 
      elsif type ==  6     
         case MP_NUMBER_ALIGN_TYPE
           when 0; @at_number.x = @hud_position[0] + AT_NUMBER_POSITION[0]
           when 1; @at_number.x = @hud_position[0] + AT_NUMBER_POSITION[0] - (cx / 2)
           when 2; @at_number.x = @hud_position[0] + AT_NUMBER_POSITION[0] - cx
         end            
      elsif type ==  7     
         case AT_NUMBER_ALIGN_TYPE
           when 0; @at_number2.x = @hud_position[0] + AT_NUMBER_POSITION[0]
           when 1; @at_number2.x = @hud_position[0] + AT_NUMBER_POSITION[0] - (cx / 2)
           when 2; @at_number2.x = @hud_position[0] + AT_NUMBER_POSITION[0] - cx
         end
      end  
  end
 
  #--------------------------------------------------------------------------
  # * Low Number Color
  #--------------------------------------------------------------------------      
  def low_number_color(type,number_ch)
      if type == 0
         if HP_NUMBER_LOW_COLOR
            return @actor.low_hp? ? number_ch : 0
         else
            return 0
         end  
      elsif type == 1
         if MP_NUMBER_LOW_COLOR    
            return @actor.low_mp? ? number_ch : 0
         else
            return 0
         end          
      elsif type == 2
         if TP_NUMBER_LOW_COLOR
            return @actor.low_tp? ? number_ch : 0
         else
            return 0
         end
      else    
         return 0  
      end     
  end
 
  #--------------------------------------------------------------------------
  # * Clear Number Refresh
  #--------------------------------------------------------------------------      
  def clear_number_refresh(type)
      @hp_number_refresh = false if type == 0
      @mp_number_refresh = false if type == 1
      @tp_number_refresh = false if type == 2
      @hp_number2_refresh = false if type == 3
      @mp_number2_refresh = false if type == 4
      @tp_number2_refresh = false if type == 5
      @at_number_refresh = false if type == 6
      @at_number2_refresh = false if type == 7
  end  
 
  #--------------------------------------------------------------------------
  # * Icon Limit
  #--------------------------------------------------------------------------      
  def icon_limit(value,value_max)
      n1 = value / value_max
      n2 = value - (n1 * value_max)
      n2 = value_max if (n2 == 0 and value > 0)
      return n2
  end  
 
end
 
#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
 
  #--------------------------------------------------------------------------
  # * Create Layout
  #--------------------------------------------------------------------------    
  def create_layout(viewport)
      @layout = Sprite.new
      @layout.bitmap = @layout_image
      @layout.z = HUD_Z
      @layout.x = @hud_position[0]
      @layout.y = @hud_position[1]
      @layout.opacity = 0
      @layout.viewport = viewport
  end    
 
  #--------------------------------------------------------------------------
  # * Update Layout
  #--------------------------------------------------------------------------    
  def update_layout
      return if @layout == nil
      sprite_visible(@layout)
  end
 
  #--------------------------------------------------------------------------
  # * Create Layout
  #--------------------------------------------------------------------------    
  def create_layout_2(viewport)
      return if !SECOND_LAYOUT
      @layout2 = Sprite.new
      @layout2.bitmap = @layout2_image
      @layout2.z = HUD_Z + SECOND_LAYOUT_Z
      @layout2.x = @hud_position[0] + SECOND_LAYOUT_POSITION[0]
      @layout2.y = @hud_position[1] + SECOND_LAYOUT_POSITION[1]
      @layout2.opacity = 0
      @layout2.viewport = viewport
  end    
 
  #--------------------------------------------------------------------------
  # * Update Layout
  #--------------------------------------------------------------------------    
  def update_layout_2
      return if @layout2 == nil
      sprite_visible(@layout2)
  end  
 
end
 
#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
 
  #--------------------------------------------------------------------------
  # * Create Name
  #--------------------------------------------------------------------------      
  def create_name(viewport)
      return if !NAME_VISIBLE
      @name = Sprite.new
      @name.bitmap = Bitmap.new(160,32)
      @name.bitmap.font.size = NAME_FONT_SIZE
      @name.bitmap.font.bold = NAME_FONT_BOLD
      @name.bitmap.font.italic = NAME_FONT_ITALIC
      @name.bitmap.font.color = NAME_FONT_COLOR
      @name.z = HUD_Z + NAME_Z
      @name.x = @hud_position[0] + NAME_POSITION[0]
      @name.y = @hud_position[1] + NAME_POSITION[1]
      @name.viewport = viewport
      @name.opacity = 0
      refresh_name
  end
 
  #--------------------------------------------------------------------------
  # * Refresh Name
  #--------------------------------------------------------------------------      
  def refresh_name
      return if @name == nil
      @name.bitmap.clear
      if NAME_FONT_SHADOW
         @name.bitmap.font.color = NAME_FONT_SHADOW_COLOR
         @name.bitmap.draw_text(NAME_FONT_SHADOW_POSITION[0],NAME_FONT_SHADOW_POSITION[1],160,32,@actor.name,NAME_ALIGN_TYPE)
         @name.bitmap.font.color = NAME_FONT_COLOR
      end   
      @name.bitmap.draw_text(0,0,160,32,@actor.name,NAME_ALIGN_TYPE)
  end
 
  #--------------------------------------------------------------------------
  # * Update Name
  #--------------------------------------------------------------------------        
  def update_name
      return if @name == nil
      sprite_visible(@name)
  end
 
end
 
#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
 
  #--------------------------------------------------------------------------
  # * Create HP Number
  #--------------------------------------------------------------------------  
  def create_hp_number(viewport)
      return if !HP_NUMBER_VISIBLE
      @hp_number = Sprite.new
      @hp_number.bitmap = Bitmap.new(@hp_number_cw * 6,@hp_number_ch)
      @hp_number.z = HUD_Z + HP_NUMBER_Z
      @hp_number.x = @hud_position[0] + HP_NUMBER_POSITION[0]
      @hp_number.y = @hud_position[1] + HP_NUMBER_POSITION[1]
      @hp_number.viewport = viewport
      @hp_number.opacity = 0
  end
 
  #--------------------------------------------------------------------------
  # * Create HP Number Max
  #--------------------------------------------------------------------------  
  def create_hp_number_max(viewport)
      return if !HP_NUMBER_MAX_VISIBLE
      @hp_number2 = Sprite.new
      @hp_number2.bitmap = Bitmap.new(@hp_number2_cw * 6,@hp_number2_ch)
      @hp_number2.z = HUD_Z + HP_NUMBER_Z
      @hp_number2.x = @hud_position[0] + HP_NUMBER_MAX_POSITION[0]
      @hp_number2.y = @hud_position[1] + HP_NUMBER_MAX_POSITION[1]
      @hp_number2.viewport = viewport
      @hp_number2.opacity = 0
  end  
 
  #--------------------------------------------------------------------------
  # * Create HP Meter
  #--------------------------------------------------------------------------    
  def create_hp_meter(viewport)
      return if !HP_METER_VISIBLE
      @hp_flow_max = @hp_meter_cw * 2
      @hp_flow = rand(@hp_flow_max)
      @hp_meter = Sprite.new
      @hp_meter.bitmap = Bitmap.new(@hp_meter_cw,@hp_meter_ch)
      @hp_meter.z = HUD_Z + HP_METER_Z
      @hp_meter.x = @hud_position[0] + HP_METER_POSITION[0]
      @hp_meter.y = @hud_position[1] + HP_METER_POSITION[1]
      @hp_meter.angle = HP_METER_ANGLE
      @hp_meter.mirror = HP_METER_MIRROR_EFFECT
      @hp_meter.viewport = viewport
      @hp_meter.opacity = 0
  end
 
  #--------------------------------------------------------------------------
  # ● Update Flow HP
  #--------------------------------------------------------------------------            
  def update_flow_hp
      @hp_meter.bitmap.clear
      @hp_flow = 0 if !HP_METER_GRADIENT_ANIMATION
      meter_width = @hp_meter_cw * @actor.hp / @actor.mhp rescue nil
      meter_width = 0 if meter_width == nil
      execute_hp_damage_flow(meter_width)      
      meter_src_rect = Rect.new(@hp_flow, 0,meter_width, @hp_meter_ch)
      @hp_meter.bitmap.blt(0,0, @hp_meter_image, meter_src_rect)  
      @hp_flow += 1
      @hp_flow = 0 if @hp_flow >= @hp_flow_max
  end  
 
  #--------------------------------------------------------------------------
  # ● Execute HP Damage Flow
  #-------------------------------------------------------------------------- 
  def execute_hp_damage_flow(meter_width)
      return if !HP_METER_REDUCTION_ANIMATION
      return if @hp_old_meter == meter_width
      n = (@hp_old_meter - meter_width).abs * 3 / 100
      damage_flow = [[n, 2].min,0.5].max
      @hp_old_meter -= damage_flow
      @hp_old_meter = meter_width if @hp_old_meter <= meter_width
      src_rect_old = Rect.new(0,@hp_meter_ch, @hp_old_meter, @hp_meter_ch)
      @hp_meter.bitmap.blt(0,0, @hp_meter_image, src_rect_old)      
  end
 
  #--------------------------------------------------------------------------
  # * Create HP Icon
  #--------------------------------------------------------------------------  
  def create_hp_icon(viewport)
      return if !HP_ICON_VISIBLE
      @hp_icon = Sprite.new
      icon_width = @hp_icon_col_max * (@hp_icon_cw + HP_ICON_SPACE[0].abs)
      icon_height = @hp_icon_row_max * (@hp_icon_ch + HP_ICON_SPACE[1].abs) 
      @hp_icon.bitmap = Bitmap.new(icon_width,icon_height)      
      @hp_icon.z = HUD_Z + HP_ICON_Z
      @hp_icon.x = @hud_position[0] + HP_ICON_POSITION[0]
      @hp_icon.y = @hud_position[1] + HP_ICON_POSITION[1]
      @hp_icon.viewport = viewport
      @hp_icon.opacity = 0
  end
 
  #--------------------------------------------------------------------------
  # * Refresh HP Icon
  #--------------------------------------------------------------------------    
  def refresh_hp_icon
      @hp_icon_old = @actor.hp
      @hp_icon.bitmap.clear
      max_value = (@actor.mhp / @hp_icon_real_max) * @hp_icon_real_max
      if @actor.hp > max_value
         icon_max = icon_limit(@actor.mhp,@hp_icon_real_max)
      else   
         icon_max = @actor.mhp
      end      
      for i in 0...icon_max
          break if (i / @hp_icon_col_max) >= @hp_icon_row_max
          rx = (i * (@hp_icon_cw + HP_ICON_SPACE[0]) ) - ((i / @hp_icon_col_max) * (@hp_icon_cw + HP_ICON_SPACE[0]) * @hp_icon_col_max)
          ry = (i / @hp_icon_col_max) * (@hp_icon_ch + HP_ICON_SPACE[1])
          i_scr = Rect.new(0,0,@hp_icon_cw,@hp_icon_ch)
          @hp_icon.bitmap.blt(rx,ry,@hp_icon_image ,i_scr )      
      end      
      icon_max = icon_limit(@actor.hp,@hp_icon_real_max)
      rx = 0
      ry = 0
      for i in 0...icon_max
          break if (i / @hp_icon_col_max) >= @hp_icon_row_max
          rx = (i * (@hp_icon_cw + HP_ICON_SPACE[0]) ) - ((i / @hp_icon_col_max) * (@hp_icon_cw + HP_ICON_SPACE[0]) * @hp_icon_col_max)
          ry = (i / @hp_icon_col_max) * (@hp_icon_ch + HP_ICON_SPACE[1])
          i_scr = Rect.new(@hp_icon_cw,0,@hp_icon_cw,@hp_icon_ch)
          @hp_icon.bitmap.blt(rx,ry,@hp_icon_image ,i_scr )
      end
      refresh_hp_icon_ex(rx,ry)      
  end
 
  #--------------------------------------------------------------------------
  # * Create HP Icon EX
  #--------------------------------------------------------------------------  
  def create_hp_icon_ex(viewport)
      return if !HP_ICON_EX_VISIBLE
      @hp_icon3_anime_phase = 0
      @hp_icon3 = Sprite.new
      @hp_icon3.bitmap = Bitmap.new(@hp_icon2_cw,@hp_icon2_ch)
      @hp_icon3.ox = @hp_icon3.bitmap.width / 2
      @hp_icon3.oy = @hp_icon3.bitmap.height / 2
      @hp_icon3.z = HUD_Z + HP_ICON_Z + 2
      @hp_icon3_org = [@hud_position[0] + HP_ICON_POSITION[0] + HP_ICON_EX_POSITION[0] + @hp_icon3.ox,
                       @hud_position[1] + HP_ICON_POSITION[1] + HP_ICON_EX_POSITION[1] + @hp_icon3.oy]
      @hp_icon3.x = @hp_icon3_org[0]
      @hp_icon3.y = @hp_icon3_org[1]
      @hp_icon3.viewport = viewport
      @hp_icon3.opacity = 0
  end   
 
  #--------------------------------------------------------------------------
  # * Refresh HP Icon EX
  #--------------------------------------------------------------------------      
  def refresh_hp_icon_ex(rx,ry)
      return if @hp_icon3 == nil
      @hp_icon3.bitmap.clear
      return if @actor.hp == 0 
      i_scr = Rect.new(0,0,@hp_icon2_cw,@hp_icon2_ch)
      @hp_icon3.bitmap.blt(0,0, @hp_icon2_image ,i_scr )
      @hp_icon3.x = @hp_icon3_org[0] + rx
      @hp_icon3.y = @hp_icon3_org[1] + ry     
  end
 
  #--------------------------------------------------------------------------
  # * Update Icon HP EX Anime
  #--------------------------------------------------------------------------  
  def update_icon_hp_ex_anime
      return if !HP_ICON_EX_ZOOM_EFFECT
      if @hp_icon3_anime_phase == 0
         @hp_icon3.zoom_x += 0.01
         if @hp_icon3.zoom_x >= 1.30
            @hp_icon3.zoom_x = 1.30
            @hp_icon3_anime_phase = 1
         end  
      else
        @hp_icon3.zoom_x -= 0.01
        if @hp_icon3.zoom_x <= 1.05
           @hp_icon3.zoom_x = 1.05
           @hp_icon3_anime_phase = 0
        end    
      end  
      @hp_icon3.zoom_y = @hp_icon3.zoom_x
  end
 
  #--------------------------------------------------------------------------
  # * Create HP Icon Nummber
  #--------------------------------------------------------------------------      
  def create_hp_icon_number(viewport)
      return if !HP_ICON_NUMBER_VISIBLE
      @hp_icon_number_old = [-1,-1]
      @hp_icon_number = Sprite.new
      @hp_icon_number.bitmap = Bitmap.new(@hp_icon_number_cw * 4,@hp_icon_number_ch)
      @hp_icon_number.z = HUD_Z + HP_ICON_NUMBER_Z 
      @hp_icon_number.x = @hud_position[0] + HP_ICON_NUMBER_POSITION[0]
      @hp_icon_number.y = @hud_position[1] + HP_ICON_NUMBER_POSITION[1]
      @hp_icon_number.viewport = viewport
      @hp_icon_number.opacity = 0
  end
 
  #--------------------------------------------------------------------------
  # * Refresh Icon Number HP
  #--------------------------------------------------------------------------  
  def refresh_icon_number_hp
      @hp_icon_number_old[0] = @actor.hp
      @hp_icon_number_old[1] = @actor.mhp
      @hp_icon_number.bitmap.clear
      value = ((@actor.hp - 1) / @hp_icon_col_max) / @hp_icon_row_max
      value = 0 if value < 0
      number_value = value.truncate.abs.to_s.split(//)
      for r in 0..number_value.size - 1         
         number_value_abs = number_value[r].to_i 
         nsrc_rect = Rect.new(@hp_icon_number_cw * number_value_abs, 0, @hp_icon_number_cw, @hp_icon_number_ch)
         @hp_icon_number.bitmap.blt(@hp_icon_number_cw *  r, 0, @hp_icon_number_image, nsrc_rect) 
      end
      cx = (number_value.size * @hp_icon_number_cw)
      case HP_ICON_NUMBER_ALIGN_TYPE
         when 0; @hp_icon_number.x = @hud_position[0] + HP_ICON_NUMBER_POSITION[0]
         when 1; @hp_icon_number.x = @hud_position[0] + HP_ICON_NUMBER_POSITION[0] - (cx / 2)
         when 2; @hp_icon_number.x = @hud_position[0] + HP_ICON_NUMBER_POSITION[0] - cx
      end    
  end
 
  #--------------------------------------------------------------------------
  # * Can Refresh Icon Number HP
  #--------------------------------------------------------------------------  
  def can_refresh_icon_number_hp?
      return true if @hp_icon_number_old[0] != @actor.hp
      return true if @hp_icon_number_old[1] != @actor.mhp
      return false
  end
 
  #--------------------------------------------------------------------------
  # * Update HP
  #--------------------------------------------------------------------------    
  def update_hp
      if @hp_number != nil
         if HP_NUMBER_ANIMATION
            update_number(0,@hp_number_old)
         else   
            update_number_fix(0) if @hp_number_old != @actor.hp
         end 
         sprite_visible(@hp_number)  
         refresh_number(0,@hp_number_old,@hp_number,@hp_number_image,@hp_number_cw,@hp_number_ch,@hp_wave_number) if @hp_number_refresh
      end
      if @hp_number2 != nil
         if HP_NUMBER_ANIMATION
            update_number(3,@hp_number2_old)
         else   
            update_number_fix(3) if @hp_number2_old != @actor.mhp
         end  
         refresh_number(3,@hp_number2_old,@hp_number2,@hp_number2_image,@hp_number2_cw,@hp_number2_ch,@hp_wave_number) if @hp_number2_refresh
         sprite_visible(@hp_number2)
      end
      if @hp_meter != nil
         sprite_visible(@hp_meter)
         update_flow_hp 
      end   
      if @hp_icon != nil
         sprite_visible(@hp_icon)
         refresh_hp_icon if @hp_icon_old != @actor.hp
      end 
      if @hp_icon3 != nil
         sprite_visible(@hp_icon3)
         update_icon_hp_ex_anime
      end       
      if @hp_icon_number != nil
         sprite_visible(@hp_icon_number)
         refresh_icon_number_hp if can_refresh_icon_number_hp?
      end  
  end  
 
end
 
#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
 
  #--------------------------------------------------------------------------
  # * Create MP Number
  #--------------------------------------------------------------------------  
  def create_mp_number(viewport)
      return if !MP_NUMBER_VISIBLE
      @mp_number = Sprite.new
      @mp_number.bitmap = Bitmap.new(@mp_number_cw * 6, @mp_number_ch)
      @mp_number.z = HUD_Z + MP_NUMBER_Z
      @mp_number.x = @hud_position[0] + MP_NUMBER_POSITION[0]
      @mp_number.y = @hud_position[1] + MP_NUMBER_POSITION[1]
      @mp_number.viewport = viewport
      @mp_number.opacity = 0
  end
 
  #--------------------------------------------------------------------------
  # * Create MP Number Max
  #--------------------------------------------------------------------------  
  def create_mp_number_max(viewport)
      return if !MP_NUMBER_MAX_VISIBLE
      @mp_number2 = Sprite.new
      @mp_number2.bitmap = Bitmap.new(@mp_number2_cw * 6, @mp_number2_ch)
      @mp_number2.z = HUD_Z + MP_NUMBER_Z
      @mp_number2.x = @hud_position[0] + MP_NUMBER_MAX_POSITION[0]
      @mp_number2.y = @hud_position[1] + MP_NUMBER_MAX_POSITION[1]
      @mp_number2.viewport = viewport
      @mp_number2.opacity = 0
  end  
 
  #--------------------------------------------------------------------------
  # * Create MP Meter
  #--------------------------------------------------------------------------    
  def create_mp_meter(viewport)
      return if !MP_METER_VISIBLE
      @mp_flow_max = @mp_meter_cw * 2
      @mp_flow = rand(@mp_flow_max)
      @mp_meter = Sprite.new
      @mp_meter.bitmap = Bitmap.new(@mp_meter_cw,@mp_meter_ch)
      @mp_meter.z = HUD_Z + MP_METER_Z
      @mp_meter.x = @hud_position[0] + MP_METER_POSITION[0]
      @mp_meter.y = @hud_position[1] + MP_METER_POSITION[1]
      @mp_meter.angle = MP_METER_ANGLE
      @mp_meter.mirror = MP_METER_MIRROR_EFFECT
      @mp_meter.viewport = viewport
      @mp_meter.opacity = 0
  end
 
  #--------------------------------------------------------------------------
  # ● Update Flow MP
  #--------------------------------------------------------------------------            
  def update_flow_mp
      @mp_meter.bitmap.clear
      @mp_flow = 0 if !MP_METER_GRADIENT_ANIMATION
      meter_width = @mp_meter_cw * @actor.mp / @actor.mmp rescue nil
      meter_width = 0 if meter_width == nil
      execute_mp_damage_flow(meter_width)      
      meter_src_rect = Rect.new(@mp_flow, 0,meter_width, @mp_meter_ch)
      @mp_meter.bitmap.blt(0,0, @mp_meter_image, meter_src_rect)  
      @mp_flow += 1
      @mp_flow = 0 if @mp_flow >= @mp_flow_max
  end  
 
  #--------------------------------------------------------------------------
  # ● Execute MP Damage Flow
  #-------------------------------------------------------------------------- 
  def execute_mp_damage_flow(meter_width)
      return if !MP_METER_REDUCTION_ANIMATION
      return if @mp_old_meter == meter_width
      n = (@mp_old_meter - meter_width).abs * 3 / 100
      damage_flow = [[n, 2].min,0.5].max
      @mp_old_meter -= damage_flow      
      @mp_old_meter = meter_width if @mp_old_meter <= meter_width
      src_rect_old = Rect.new(0,@mp_meter_ch, @mp_old_meter, @mp_meter_ch)
      @mp_meter.bitmap.blt(0,0, @mp_meter_image, src_rect_old)       
  end 
 
  #--------------------------------------------------------------------------
  # * Create MP Icon
  #--------------------------------------------------------------------------  
  def create_mp_icon(viewport)
      return if !MP_ICON_VISIBLE
      @mp_icon = Sprite.new
      icon_width = @mp_icon_col_max * (@mp_icon_cw + MP_ICON_SPACE[0].abs)
      icon_height = @mp_icon_row_max * (@mp_icon_ch + MP_ICON_SPACE[1].abs) 
      @mp_icon.bitmap = Bitmap.new(icon_width,icon_height)      
      @mp_icon.z = HUD_Z + MP_ICON_Z
      @mp_icon.x = @hud_position[0] + MP_ICON_POSITION[0]
      @mp_icon.y = @hud_position[1] + MP_ICON_POSITION[1]
      @mp_icon.viewport = viewport
      @mp_icon.opacity = 0
  end
 
  #--------------------------------------------------------------------------
  # * Refresh MP Icon
  #--------------------------------------------------------------------------    
  def refresh_mp_icon
      @mp_icon_old = @actor.mp
      @mp_icon.bitmap.clear
      max_value = (@actor.mmp / @mp_icon_real_max) * @mp_icon_real_max
      if @actor.mp > max_value
         icon_max = icon_limit(@actor.mmp,@mp_icon_real_max)
      else   
         icon_max = @actor.mmp
      end      
      for i in 0...icon_max
          break if (i / @mp_icon_col_max) >= @mp_icon_row_max
          rx = (i * (@mp_icon_cw + MP_ICON_SPACE[0]) ) - ((i / @mp_icon_col_max) * (@mp_icon_cw + MP_ICON_SPACE[0]) * @mp_icon_col_max)
          ry = (i / @mp_icon_col_max) * (@mp_icon_ch + MP_ICON_SPACE[1])
          i_scr = Rect.new(0,0,@mp_icon_cw,@mp_icon_ch)
          @mp_icon.bitmap.blt(rx,ry,@mp_icon_image ,i_scr )      
      end      
      icon_max = icon_limit(@actor.mp,@mp_icon_real_max)
      rx = 0
      ry = 0
      for i in 0...icon_max
          break if (i / @mp_icon_col_max) >= @mp_icon_row_max
          rx = (i * (@mp_icon_cw + MP_ICON_SPACE[0]) ) - ((i / @mp_icon_col_max) * (@mp_icon_cw + MP_ICON_SPACE[0]) * @mp_icon_col_max)
          ry = (i / @mp_icon_col_max) * (@mp_icon_ch + MP_ICON_SPACE[1])
          i_scr = Rect.new(@mp_icon_cw,0,@mp_icon_cw,@mp_icon_ch)
          @mp_icon.bitmap.blt(rx,ry,@mp_icon_image ,i_scr )
      end
      refresh_mp_icon_ex(rx,ry)      
  end
 
  #--------------------------------------------------------------------------
  # * Create MP Icon EX
  #--------------------------------------------------------------------------  
  def create_mp_icon_ex(viewport)
      return if !MP_ICON_EX_VISIBLE
      @mp_icon3_anime_phase = 0
      @mp_icon3 = Sprite.new
      @mp_icon3.bitmap = Bitmap.new(@mp_icon2_cw,@mp_icon2_ch)
      @mp_icon3.ox = @mp_icon3.bitmap.width / 2
      @mp_icon3.oy = @mp_icon3.bitmap.height / 2
      @mp_icon3.z = HUD_Z + MP_ICON_Z + 2
      @mp_icon3_org = [@hud_position[0] + MP_ICON_POSITION[0] + MP_ICON_EX_POSITION[0] + @mp_icon3.ox,
                       @hud_position[1] + MP_ICON_POSITION[1] + MP_ICON_EX_POSITION[1] + @mp_icon3.oy]
      @mp_icon3.x = @mp_icon3_org[0]
      @mp_icon3.y = @mp_icon3_org[1]
      @mp_icon3.viewport = viewport
      @mp_icon3.opacity = 0
  end   
 
  #--------------------------------------------------------------------------
  # * Refresh MP Icon EX
  #--------------------------------------------------------------------------      
  def refresh_mp_icon_ex(rx,ry)
      return if @mp_icon3 == nil
      @mp_icon3.bitmap.clear
      return if @actor.mp == 0
      i_scr = Rect.new(0,0,@mp_icon2_cw,@mp_icon2_ch)
      @mp_icon3.bitmap.blt(0,0, @mp_icon2_image ,i_scr )
      @mp_icon3.x = @mp_icon3_org[0] + rx
      @mp_icon3.y = @mp_icon3_org[1] + ry     
  end
 
  #--------------------------------------------------------------------------
  # * Update Icon MP EX Anime
  #--------------------------------------------------------------------------  
  def update_icon_mp_ex_anime
      return if !MP_ICON_EX_ZOOM_EFFECT
      if @mp_icon3_anime_phase == 0
         @mp_icon3.zoom_x += 0.01
         if @mp_icon3.zoom_x >= 1.30
            @mp_icon3.zoom_x = 1.30
            @mp_icon3_anime_phase = 1
         end  
      else
        @mp_icon3.zoom_x -= 0.01
        if @mp_icon3.zoom_x <= 1.05
           @mp_icon3.zoom_x = 1.05
           @mp_icon3_anime_phase = 0
        end   
      end  
      @mp_icon3.zoom_y = @mp_icon3.zoom_x
  end  
 
  #--------------------------------------------------------------------------
  # * Create MP Icon Number
  #--------------------------------------------------------------------------      
  def create_mp_icon_number(viewport)
      return if !MP_ICON_NUMBER_VISIBLE
      @mp_icon_number_old = [-1,-1]
      @mp_icon_number = Sprite.new
      @mp_icon_number.bitmap = Bitmap.new(@mp_icon_number_cw * 4,@mp_icon_number_ch)
      @mp_icon_number.z = HUD_Z + MP_ICON_NUMBER_Z
      @mp_icon_number.x = @hud_position[0] + MP_ICON_NUMBER_POSITION[0]
      @mp_icon_number.y = @hud_position[1] + MP_ICON_NUMBER_POSITION[1]
      @mp_icon_number.viewport = viewport
      @mp_icon_number.opacity = 0
  end
 
  #--------------------------------------------------------------------------
  # * Refresh Icon Number MP
  #--------------------------------------------------------------------------  
  def refresh_icon_number_mp
      @mp_icon_number_old[0] = @actor.mp
      @mp_icon_number_old[1] = @actor.mmp
      @mp_icon_number.bitmap.clear
      value = ((@actor.mp - 1) / @mp_icon_col_max) / @mp_icon_row_max
      value = 0 if value < 0
      number_value = value.truncate.abs.to_s.split(//)
      for r in 0..number_value.size - 1         
         number_value_abs = number_value[r].to_i 
         nsrc_rect = Rect.new(@mp_icon_number_cw * number_value_abs, 0, @mp_icon_number_cw, @mp_icon_number_ch)
         @mp_icon_number.bitmap.blt(@mp_icon_number_cw *  r, 0, @mp_icon_number_image, nsrc_rect) 
      end
      cx = (number_value.size * @mp_icon_number_cw)
      case MP_ICON_NUMBER_ALIGN_TYPE
         when 0; @mp_icon_number.x = @hud_position[0] + MP_ICON_NUMBER_POSITION[0]
         when 1; @mp_icon_number.x = @hud_position[0] + MP_ICON_NUMBER_POSITION[0] - (cx / 2)
         when 2; @mp_icon_number.x = @hud_position[0] + MP_ICON_NUMBER_POSITION[0] - cx
      end        
  end
 
  #--------------------------------------------------------------------------
  # * Can Refresh Icon Number MP
  #--------------------------------------------------------------------------  
  def can_refresh_icon_number_mp?
      return true if @mp_icon_number_old[0] != @actor.mp
      return true if @mp_icon_number_old[1] != @actor.mmp
      return false
  end    
 
  #--------------------------------------------------------------------------
  # * Update MP
  #--------------------------------------------------------------------------    
  def update_mp
      if @mp_number != nil 
         sprite_visible(@mp_number)
         if MP_NUMBER_ANIMATION
            update_number(1,@mp_number_old)
         else 
            update_number_fix(1) if @mp_number_old != @actor.mp
         end  
         refresh_number(1,@mp_number_old,@mp_number,@mp_number_image,@mp_number_cw,@mp_number_ch,@mp_wave_number) if @mp_number_refresh
      end
      if @mp_number2 != nil 
         sprite_visible(@mp_number2)
         if MP_NUMBER_ANIMATION
            update_number(4,@mp_number2_old)
         else 
            update_number_fix(4) if @mp_number2_old != @actor.mmp
         end  
         refresh_number(4,@mp_number2_old,@mp_number2,@mp_number2_image,@mp_number2_cw,@mp_number2_ch,@mp_wave_number) if @mp_number2_refresh
      end      
      if @mp_meter != nil 
         sprite_visible(@mp_meter)
         update_flow_mp
      end
      if @mp_icon != nil
         sprite_visible(@mp_icon)
         refresh_mp_icon if @mp_icon_old != @actor.mp
      end
      if @mp_icon3 != nil
         sprite_visible(@mp_icon3)
         update_icon_mp_ex_anime
      end          
      if @mp_icon_number != nil
         sprite_visible(@mp_icon_number)
         refresh_icon_number_mp if can_refresh_icon_number_mp?
      end       
  end  
 
end
 
#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
 
  #--------------------------------------------------------------------------
  # * Create TP Number
  #--------------------------------------------------------------------------  
  def create_tp_number(viewport)
      return if !TP_NUMBER_VISIBLE
      @tp_number = Sprite.new
      @tp_number.bitmap = Bitmap.new(@tp_number_cw * 6, @tp_number_ch)
      @tp_number.z = HUD_Z + TP_NUMBER_Z
      @tp_number.x = @hud_position[0] + TP_NUMBER_POSITION[0]
      @tp_number.y = @hud_position[1] + TP_NUMBER_POSITION[1]
      @tp_number.viewport = viewport
      @tp_number.opacity = 0
  end
 
  #--------------------------------------------------------------------------
  # * Create TP Number MAX
  #--------------------------------------------------------------------------  
  def create_tp_number_max(viewport)
      return if !TP_NUMBER_MAX_VISIBLE
      @tp_number2 = Sprite.new
      @tp_number2.bitmap = Bitmap.new(@tp_number2_cw * 6, @tp_number2_ch)
      @tp_number2.z = HUD_Z + TP_NUMBER_Z
      @tp_number2.x = @hud_position[0] + TP_NUMBER_MAX_POSITION[0]
      @tp_number2.y = @hud_position[1] + TP_NUMBER_MAX_POSITION[1]
      @tp_number2.viewport = viewport
      @tp_number2.opacity = 0
  end  
 
  #--------------------------------------------------------------------------
  # * Create TP Meter
  #--------------------------------------------------------------------------    
  def create_tp_meter(viewport)
      return if !TP_METER_VISIBLE
      @tp_flow_max = @tp_meter_cw * 2
      @tp_flow = rand(@tp_flow_max)
      @tp_meter = Sprite.new
      @tp_meter.bitmap = Bitmap.new(@tp_meter_cw,@tp_meter_ch)
      @tp_meter.z = HUD_Z + TP_METER_Z
      @tp_meter.x = @hud_position[0] + TP_METER_POSITION[0]
      @tp_meter.y = @hud_position[1] + TP_METER_POSITION[1]
      @tp_meter.angle = TP_METER_ANGLE
      @tp_meter.mirror = TP_METER_MIRROR_EFFECT
      @tp_meter.viewport = viewport
      @tp_meter.opacity = 0
  end
 
  #--------------------------------------------------------------------------
  # ● Update Flow TP
  #--------------------------------------------------------------------------            
  def update_flow_tp
      @tp_meter.bitmap.clear      
      @tp_flow = 0 if !TP_METER_GRADIENT_ANIMATION
      meter_width = @tp_meter_cw * @actor.tp / @actor.max_tp rescue nil  
      meter_width = 0 if meter_width == nil
      execute_tp_damage_flow(meter_width)      
      meter_src_rect = Rect.new(@tp_flow, 0,meter_width, @tp_meter_ch)
      @tp_meter.bitmap.blt(0,0, @tp_meter_image, meter_src_rect)  
      @tp_flow += 1
      @tp_flow = 0 if @tp_flow >= @tp_flow_max
  end  
 
  #--------------------------------------------------------------------------
  # ● Execute TP Damage Flow
  #-------------------------------------------------------------------------- 
  def execute_tp_damage_flow(meter_width)
      return if !TP_METER_REDUCTION_ANIMATION
      return if @tp_old_meter == meter_width
      n = (@tp_old_meter - meter_width).abs * 3 / 100
      damage_flow = [[n, 2].min,0.5].max
      @tp_old_meter -= damage_flow
      @tp_old_meter = meter_width if @tp_old_meter <= meter_width
      src_rect_old = Rect.new(0,@tp_meter_ch, @tp_old_meter, @tp_meter_ch)
      @tp_meter.bitmap.blt(0,0, @tp_meter_image, src_rect_old)      
  end
 
  #--------------------------------------------------------------------------
  # * Create TP Icon
  #--------------------------------------------------------------------------  
  def create_tp_icon(viewport)
      return if !TP_ICON_VISIBLE
      @tp_icon = Sprite.new
      icon_width = @tp_icon_col_max * (@tp_icon_cw + TP_ICON_SPACE[0].abs)
      icon_height = @tp_icon_row_max * (@tp_icon_ch + TP_ICON_SPACE[1].abs) 
      @tp_icon.bitmap = Bitmap.new(icon_width,icon_height)      
      @tp_icon.z = HUD_Z + TP_ICON_Z
      @tp_icon.x = @hud_position[0] + TP_ICON_POSITION[0]
      @tp_icon.y = @hud_position[1] + TP_ICON_POSITION[1]
      @tp_icon.viewport = viewport
      @tp_icon.opacity = 0
  end
 
  #--------------------------------------------------------------------------
  # * Refresh TP Icon
  #--------------------------------------------------------------------------    
  def refresh_tp_icon
      @tp_icon_old = @actor.tp
      @tp_icon.bitmap.clear
      max_value = (@actor.max_tp / @tp_icon_real_max) * @tp_icon_real_max
      if @actor.mp > max_value
         icon_max = icon_limit(@actor.max_tp,@tp_icon_real_max)
      else   
         icon_max = @actor.max_tp
      end      
      for i in 0...icon_max
          break if (i / @tp_icon_col_max) >= @tp_icon_row_max
          rx = (i * (@tp_icon_cw + TP_ICON_SPACE[0]) ) - ((i / @tp_icon_col_max) * (@tp_icon_cw + TP_ICON_SPACE[0]) * @tp_icon_col_max)
          ry = (i / @tp_icon_col_max) * (@tp_icon_ch + TP_ICON_SPACE[1])
          i_scr = Rect.new(0,0,@tp_icon_cw,@tp_icon_ch)
          @tp_icon.bitmap.blt(rx,ry,@tp_icon_image ,i_scr )      
      end      
      icon_max = icon_limit(@actor.tp,@tp_icon_real_max)
      rx = 0
      ry = 0
      for i in 0...icon_max
          break if (i / @tp_icon_col_max) >= @tp_icon_row_max
          rx = (i * (@tp_icon_cw + TP_ICON_SPACE[0]) ) - ((i / @tp_icon_col_max) * (@tp_icon_cw + TP_ICON_SPACE[0]) * @tp_icon_col_max)
          ry = (i / @tp_icon_col_max) * (@tp_icon_ch + TP_ICON_SPACE[1])
          i_scr = Rect.new(@mp_icon_cw,0,@tp_icon_cw,@tp_icon_ch)
          @tp_icon.bitmap.blt(rx,ry,@tp_icon_image ,i_scr )
      end
      refresh_tp_icon_ex(rx,ry)      
  end
 
  #--------------------------------------------------------------------------
  # * Create TP Icon EX
  #--------------------------------------------------------------------------  
  def create_tp_icon_ex(viewport)
      return if !TP_ICON_EX_VISIBLE
      @tp_icon3_anime_phase = 0
      @tp_icon3 = Sprite.new
      @tp_icon3.bitmap = Bitmap.new(@tp_icon2_cw,@tp_icon2_ch)
      @tp_icon3.ox = @tp_icon3.bitmap.width / 2
      @tp_icon3.oy = @tp_icon3.bitmap.height / 2
      @tp_icon3.z = HUD_Z + TP_ICON_Z + 2
      @tp_icon3_org = [@hud_position[0] + TP_ICON_POSITION[0] + TP_ICON_EX_POSITION[0] + @tp_icon3.ox,
                       @hud_position[1] + TP_ICON_POSITION[1] + TP_ICON_EX_POSITION[1] + @tp_icon3.oy]
      @tp_icon3.x = @tp_icon3_org[0]
      @tp_icon3.y = @tp_icon3_org[1]
      @tp_icon3.viewport = viewport
      @tp_icon3.opacity = 0
  end   
 
  #--------------------------------------------------------------------------
  # * Refresh TP Icon EX
  #--------------------------------------------------------------------------      
  def refresh_tp_icon_ex(rx,ry)
      return if @tp_icon3 == nil
      @tp_icon3.bitmap.clear
      return if @actor.tp == 0
      i_scr = Rect.new(0,0,@tp_icon2_cw,@tp_icon2_ch)
      @tp_icon3.bitmap.blt(0,0, @tp_icon2_image ,i_scr )
      @tp_icon3.x = @tp_icon3_org[0] + rx
      @tp_icon3.y = @tp_icon3_org[1] + ry     
  end
 
  #--------------------------------------------------------------------------
  # * Update Icon TP EX Anime
  #--------------------------------------------------------------------------  
  def update_icon_tp_ex_anime
      return if !MP_ICON_EX_ZOOM_EFFECT
      if @tp_icon3_anime_phase == 0
         @tp_icon3.zoom_x += 0.01
         if @tp_icon3.zoom_x >= 1.30
            @tp_icon3.zoom_x = 1.30
            @tp_icon3_anime_phase = 1
         end  
      else
        @tp_icon3.zoom_x -= 0.01
        if @tp_icon3.zoom_x <= 1.05
           @tp_icon3.zoom_x = 1.05
           @tp_icon3_anime_phase = 0
        end   
      end  
      @tp_icon3.zoom_y = @tp_icon3.zoom_x
  end    
 
  #--------------------------------------------------------------------------
  # * Create HP Icon Number
  #--------------------------------------------------------------------------      
  def create_tp_icon_number(viewport)
      return if !TP_ICON_NUMBER_VISIBLE
      @tp_icon_number_old = [-1,-1]
      @tp_icon_number = Sprite.new
      @tp_icon_number.bitmap = Bitmap.new(@tp_icon_number_cw * 3,@tp_icon_number_ch)
      @tp_icon_number.z = HUD_Z + TP_ICON_NUMBER_Z
      @tp_icon_number.x = @hud_position[0] + TP_ICON_NUMBER_POSITION[0]
      @tp_icon_number.y = @hud_position[1] + TP_ICON_NUMBER_POSITION[1]
      @tp_icon_number.viewport = viewport
      @tp_icon_number.opacity = 0
  end
 
  #--------------------------------------------------------------------------
  # * Refresh Icon Number TP
  #--------------------------------------------------------------------------  
  def refresh_icon_number_tp
      @tp_icon_number_old[0] = @actor.tp
      @tp_icon_number_old[1] = @actor.max_tp
      @tp_icon_number.bitmap.clear
      value = ((@actor.tp - 1) / @tp_icon_col_max) / @tp_icon_row_max
      value = 0 if value < 0
      number_value = value.truncate.abs.to_s.split(//)
      for r in 0..number_value.size - 1         
         number_value_abs = number_value[r].to_i 
         nsrc_rect = Rect.new(@tp_icon_number_cw * number_value_abs, 0, @tp_icon_number_cw, @tp_icon_number_ch)
         @tp_icon_number.bitmap.blt(@tp_icon_number_cw *  r, 0, @tp_icon_number_image, nsrc_rect) 
      end
      cx = (number_value.size * @tp_icon_number_cw)
      case TP_ICON_NUMBER_ALIGN_TYPE
         when 0; @tp_icon_number.x = @hud_position[0] + TP_ICON_NUMBER_POSITION[0]
         when 1; @tp_icon_number.x = @hud_position[0] + TP_ICON_NUMBER_POSITION[0] - (cx / 2)
         when 2; @tp_icon_number.x = @hud_position[0] + TP_ICON_NUMBER_POSITION[0] - cx
      end        
  end
 
  #--------------------------------------------------------------------------
  # * Can Refresh Icon Number TP
  #--------------------------------------------------------------------------  
  def can_refresh_icon_number_tp?
      return true if @tp_icon_number_old[0] != @actor.tp
      return true if @tp_icon_number_old[1] != @actor.max_tp
      return false
  end   
 
  #--------------------------------------------------------------------------
  # * Update TP
  #--------------------------------------------------------------------------    
  def update_tp
      if @tp_number != nil
         sprite_visible(@tp_number)
         if MP_NUMBER_ANIMATION
            update_number(2,@tp_number_old)
         else 
            update_number_fix(2) if @tp_number_old != @actor.tp
         end           
         refresh_number(2,@tp_number_old,@tp_number,@tp_number_image,@tp_number_cw,@tp_number_ch,@tp_wave_number) if @tp_number_refresh         
      end    
      if @tp_number2 != nil
         sprite_visible(@tp_number2)
         if MP_NUMBER_ANIMATION
            update_number(5,@tp_number2_old)
         else 
            update_number_fix(5) if @tp_number2_old != @actor.max_tp
         end           
         refresh_number(5,@tp_number2_old,@tp_number2,@tp_number2_image,@tp_number2_cw,@tp_number2_ch,@tp_wave_number) if @tp_number2_refresh
      end        
      if @tp_meter != nil
         sprite_visible(@tp_meter)
         update_flow_tp
      end
      if @tp_icon != nil
         sprite_visible(@tp_icon)
         refresh_tp_icon if @tp_icon_old != @actor.tp
      end 
      if @tp_icon3 != nil
         sprite_visible(@tp_icon3)
         update_icon_tp_ex_anime
      end         
      if @tp_icon_number != nil
         sprite_visible(@tp_icon_number)
         refresh_icon_number_tp if can_refresh_icon_number_tp?
      end  
  end  
 
end
 
#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
 
  #--------------------------------------------------------------------------
  # * Create AT Number
  #--------------------------------------------------------------------------  
  def create_at_number(viewport)
      return if !AT_NUMBER_VISIBLE
      @at_number = Sprite.new
      @at_number.bitmap = Bitmap.new(@at_number_cw * 4,@at_number_ch)
      @at_number.z = HUD_Z + AT_NUMBER_Z
      @at_number.x = @hud_position[0] + AT_NUMBER_POSITION[0]
      @at_number.y = @hud_position[1] + AT_NUMBER_POSITION[1]
      @at_number.viewport = viewport
      @at_number.opacity = 0
  end
 
  #--------------------------------------------------------------------------
  # * Create AT Number Max
  #--------------------------------------------------------------------------  
  def create_at_number_max(viewport)
      return if !AT_NUMBER_MAX_VISIBLE
      @at_number2 = Sprite.new
      @at_number2.bitmap = Bitmap.new(@at_number2_cw * 4,@at_number2_ch)
      @at_number2.z = HUD_Z + AT_NUMBER_Z
      @at_number2.x = @hud_position[0] + AT_NUMBER_MAX_POSITION[0]
      @at_number2.y = @hud_position[1] + AT_NUMBER_MAX_POSITION[1]
      @at_number2.viewport = viewport
      @at_number2.opacity = 0
  end  
 
  #--------------------------------------------------------------------------
  # * Create AT Meter
  #--------------------------------------------------------------------------    
  def create_at_meter(viewport)
      return if !AT_METER_VISIBLE
      @at_flow_max = @at_meter_cw * 2
      @at_flow = rand(@at_flow_max)
      @at_meter = Sprite.new
      @at_meter.bitmap = Bitmap.new(@at_meter_cw,@at_meter_ch)
      @at_meter.z = HUD_Z + AT_METER_Z
      @at_meter.x = @hud_position[0] + AT_METER_POSITION[0]
      @at_meter.y = @hud_position[1] + AT_METER_POSITION[1]
      @at_meter.angle = AT_METER_ANGLE
      @at_meter.mirror = AT_METER_MIRROR_EFFECT
      @at_meter.viewport = viewport
      @at_meter.opacity = 0
  end
 
  #--------------------------------------------------------------------------
  # ● Update Flow AT
  #--------------------------------------------------------------------------            
  def update_flow_at
      @at_meter.bitmap.clear
      @at_flow = 0 if !AT_METER_GRADIENT_ANIMATION
      if actor_cast?
         meter_width = @at_meter_cw * actor_cast / actor_max_cast rescue nil
         meter_width = 0 if meter_width == nil 
         ch = @at_meter_ch * 2
      else
         meter_width = @at_meter_cw * actor_at / actor_max_at rescue nil
         meter_width = 0 if meter_width == nil         
         ch = actor_at >= actor_max_at ? @at_meter_ch : 0
      end   
      meter_src_rect = Rect.new(@at_flow, ch,meter_width, @at_meter_ch)
      @at_meter.bitmap.blt(0,0, @at_meter_image, meter_src_rect)  
      @at_flow += 1
      @at_flow = 0 if @at_flow >= @at_flow_max
  end  
 
  #--------------------------------------------------------------------------
  # * Update AT
  #--------------------------------------------------------------------------    
  def update_at
      if @at_number != nil
         sprite_visible(@at_number)
         if AT_NUMBER_ANIMATION
            update_number(6,@at_number_old)
         else   
            update_number_fix(6) if @at_number_old != actor_at
         end  
         refresh_number(6,@at_number_old,@at_number,@at_number_image,@at_number_cw,@at_number_ch,@at_wave_number) if @at_number_refresh
      end
      if @at_number2 != nil
         sprite_visible(@at_number2)
         if AT_NUMBER_ANIMATION
            update_number(7,@at_number2_old)
         else   
            update_number_fix(7) if @at_number2_old != actor_max_at
         end  
         refresh_number(7,@at_number2_old,@at_number2,@at_number2_image,@at_number2_cw,@at_number2_ch,@at_wave_number) if @at_number2_refresh
      end
      if @at_meter != nil
         sprite_visible(@at_meter)
         update_flow_at
      end   
  end  
 
end
 
#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
 
  #--------------------------------------------------------------------------
  # * Create Level Number
  #--------------------------------------------------------------------------    
  def create_level_number(viewport)
      return if !LEVEL_NUMBER_VISIBLE
      @old_level = -1
      @lv_number = Sprite.new
      @lv_number.bitmap = Bitmap.new(@lv_number_cw * 2, @lv_number_ch)
      @lv_number.z = HUD_Z + LEVEL_NUMBER_Z
      @lv_number.x = @hud_position[0] + LEVEL_NUMBER_POSITION[0]
      @lv_number.y = @hud_position[1] + LEVEL_NUMBER_POSITION[1]
      @lv_number.viewport = viewport
      @lv_number.opacity = 0
  end
 
  #--------------------------------------------------------------------------
  # * Refresh Level Number
  #--------------------------------------------------------------------------  
  def refresh_level_number
      @lv_number.bitmap.clear
      @old_level = @actor.level      
      number_value = @actor.level.abs.to_s.split(//)
      for r in 0..number_value.size - 1         
         number_value_abs = number_value[r].to_i 
         nsrc_rect = Rect.new(@lv_number_cw * number_value_abs, 0, @lv_number_cw, @lv_number_ch)
         @lv_number.bitmap.blt(@lv_number_cw *  r, 0, @lv_number_image, nsrc_rect) 
      end
      cx = (number_value.size * @lv_number_cw)
      case LEVEL_NUMBER_ALIGN_TYPE
           when 0; @lv_number.x = @hud_position[0] + LEVEL_NUMBER_POSITION[0]
           when 1; @lv_number.x = @hud_position[0] + LEVEL_NUMBER_POSITION[0] - (cx / 2)
           when 2; @lv_number.x = @hud_position[0] + LEVEL_NUMBER_POSITION[0] - cx 
      end
  end
 
  #--------------------------------------------------------------------------
  # * Update Level
  #--------------------------------------------------------------------------  
  def update_level
      return if @lv_number == nil
      sprite_visible(@lv_number)
      refresh_level_number if @old_level != @actor.level
  end
 
end
 
#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
 
  #--------------------------------------------------------------------------
  # * Create States
  #--------------------------------------------------------------------------  
  def create_states(viewport)
      return if !STATES_VISIBLE
      @status_old = nil
      @status_flow = [-24,0]
      @status_size_real = 0
      @status = Sprite.new
      @status.bitmap = Bitmap.new(24,24)
      @status.x = @hud_position[0] + STATES_POSITION[0]
      @status.y = @hud_position[1] + STATES_POSITION[1] 
      @status.z = HUD_Z + STATES_Z
      @status.angle = STATE_ANGLE
      @status.viewport = viewport
      @status.opacity = 0
  end
 
  #--------------------------------------------------------------------------
  # * Refresh States
  #--------------------------------------------------------------------------        
  def refresh_states
      check_icon_image
      @status_size_real = set_real_states_size
      @status_old = @actor.states
      @status_flow = [0,0]
      @states_size = @status_size_real > 0 ? (26 * @status_size_real) : 24 
      @actor_status.dispose if @actor_status != nil
      @actor_status = Bitmap.new(@states_size,24)
      index = 0
      for i in @actor.states
         next if HIDE_STATES_ID.include?(i.id)         
         rect = Rect.new(i.icon_index % 16 * 24, i.icon_index / 16 * 24, 24, 24)
         @actor_status.blt(26 * index , 0, @icon_image, rect)
         index += 1
      end
  end   
 
  #--------------------------------------------------------------------------
  # * Set Real States Size
  #--------------------------------------------------------------------------        
  def set_real_states_size
      n = 0
      for i in @actor.states
          next if HIDE_STATES_ID.include?(i.id)  
          n += 1
      end
      return n
  end
 
  #--------------------------------------------------------------------------
  # * Flow_Status
  #--------------------------------------------------------------------------          
  def flow_states
      return if @actor_status == nil
      @status.bitmap.clear
      return if @actor.states.size == 0
      st_src_rect = Rect.new(@status_flow[0],0, 24,24)
      @status.bitmap.blt(0,0, @actor_status, st_src_rect)
      if STATES_SCROLLING_ANIMATION
         @status_flow[0] += 1
         @status_flow[0] = -24 if @status_flow[0] >= @states_size + 2
      else   
         @status_flow[1] += 1 unless @actor.states.size <= 1
         if @status_flow[1] > 30
            @status_flow[1] = 0
            @status_flow[0] += 26
            @status_flow[0] = 0 if @status_flow[0] >= (@states_size - 0)
         end   
     end   
  end      
 
  #--------------------------------------------------------------------------
  # * Update States
  #--------------------------------------------------------------------------  
  def update_states
      return if @status == nil
      sprite_visible(@status)
      refresh_states if @status_old != @actor.states
      flow_states
  end  
 
end
 
#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
 
  #--------------------------------------------------------------------------
  # * Create Face
  #--------------------------------------------------------------------------    
  def create_face(viewport)
      return if !FACE_VISIBLE
      @face_old_hp = @actor.hp
      @face_old_mp = @actor.mp
      @face_old_tp = @actor.tp
      @face_name = ""
      @face = Sprite.new
      @face_org = [@hud_position[0] + FACE_POSITION[0], @hud_position[1] + FACE_POSITION[1]]
      @face.x = @face_org[0]
      @face.y = @face_org[1]
      @face.z = HUD_Z + FACE_Z
      @face.viewport = viewport
      @face.opacity = 0
      refresh_face_name
  end
 
  #--------------------------------------------------------------------------
  # * Refresh Face Name
  #--------------------------------------------------------------------------      
  def refresh_face_name      
      @face_image.dispose if @face_image != nil
      @face.bitmap.dispose if @face.bitmap != nil
      return if @actor == nil or @actor.id == nil
      #追加
      p @actor.battler_face_name.to_s
 
      @face_image = Cache.battle_hud(@actor.battler_face_name.to_s) rescue nil
      @face_image = Bitmap.new(32,32) if @face_image == nil
      @face_cw = FACE_ANIMATION ? @face_image.width / 5 : @face_image.width
      @face_ch = @face_image.height
      @face.ox = @face_cw / 2
      @face.oy = @face_ch / 2      
      @face.bitmap = Bitmap.new(@face_cw,@face_ch)
      @face_org = [@hud_position[0] + FACE_POSITION[0], 
                   @hud_position[1] + @face.oy + FACE_POSITION[1]]
      if $game_temp.battler_face_pos[@actor_index] == nil
         $game_temp.battler_face_pos[@actor_index] = [] 
      end
      @face.x = @face_org[0]
      @face.y = @face_org[1]  
      limit_Y = (@hud_position[1] + FACE_POSITION[1] + @face_image.height)
      fy = @face_org[1] 
      if limit_Y > Graphics.height
         @face.y = Graphics.height - (@face_image.height - @face.oy)
         fy = Graphics.height - 16
         @face_org[1] = @face.y
      end
      $game_temp.battler_face_pos[@actor_index][0] = @face_org[0] 
      $game_temp.battler_face_pos[@actor_index][1] = fy
      $game_temp.battler_face_pos[@actor_index][2] = @face.z     
      clear_face_index
  end
 
  #--------------------------------------------------------------------------
  # * Refresh Face
  #--------------------------------------------------------------------------  
  def refresh_face
      #追記
      p "refresh_face"
      #p @actor.battler_face_name.to_s
      #def battler_face_name()
      #@actor.battler_face_name = @battler_face_name(1,"Face_2") 
      #end
 
      #@actor.battler_face_name = "Face_2"
      #追加 戦闘中の立ち絵画像の切り替え
      #HP60%未満で服破け切替 回復で通常立ち絵へ
      if $game_actors[1].param(0) * 0.6 > $game_actors[1].hp
 
        $game_variables[1] = 1
 
        actor = $game_actors[1]
 
        if actor.state?(30)
          $game_variables[1] = 3
        end
        if actor.state?(31)
          $game_variables[1] = 5
        end
        if $game_variables[10] == 3
          $game_variables[1] = 7
        end
        if $game_switches[275] == true
          $game_variables[1] = 9
        end
 
        $game_switches[56] = true
      end
      if $game_actors[1].param(0) * 0.6 <= $game_actors[1].hp
 
        $game_variables[1] = 0
        actor = $game_actors[1]
 
        if actor.state?(30)
          $game_variables[1] = 2
        end
        if actor.state?(31)
          $game_variables[1] = 4
        end
        if $game_variables[10] == 3
          $game_variables[1] = 6
        end
        if $game_switches[275] == true
          $game_variables[1] = 8
        end        
 
        $game_switches[56] = false
      end
 
      #通常立ち絵 表示
      if $game_variables[1] == 0
        p $game_variables[1]
        @actor.battler_face_name = "Face_1"
        @face_image = Cache.battle_hud(@actor.battler_face_name.to_s) rescue nil
      end
      #ダメージ立ち絵 表示
      if $game_variables[1] == 1
        p $game_variables[1]
        @actor.battler_face_name = "Face_2"
        @face_image = Cache.battle_hud(@actor.battler_face_name.to_s) rescue nil
      end      
      #通常立ち絵(スライム) 表示
      if $game_variables[1] == 2
        p $game_variables[1]
        @actor.battler_face_name = "Face_3"
        @face_image = Cache.battle_hud(@actor.battler_face_name.to_s) rescue nil
      end
      #ダメージ立ち絵(スライム) 表示
      if $game_variables[1] == 3
        p $game_variables[1]
        @actor.battler_face_name = "Face_4"
        @face_image = Cache.battle_hud(@actor.battler_face_name.to_s) rescue nil
      end
      #通常立ち絵(触手) 表示
      if $game_variables[1] == 4
        p $game_variables[1]
        @actor.battler_face_name = "Face_5"
        @face_image = Cache.battle_hud(@actor.battler_face_name.to_s) rescue nil
      end
      #ダメージ立ち絵(触手) 表示
      if $game_variables[1] == 5
        p $game_variables[1]
        @actor.battler_face_name = "Face_6"
        @face_image = Cache.battle_hud(@actor.battler_face_name.to_s) rescue nil
      end
      #通常立ち絵(手ブラ) 表示
      if $game_variables[1] == 6
        p $game_variables[1]
        @actor.battler_face_name = "Face_7"
        @face_image = Cache.battle_hud(@actor.battler_face_name.to_s) rescue nil
      end
      #ダメージ立ち絵(手ブラ) 表示
      if $game_variables[1] == 7
        p $game_variables[1]
        @actor.battler_face_name = "Face_8"
        @face_image = Cache.battle_hud(@actor.battler_face_name.to_s) rescue nil
      end
      #通常立ち絵(手ブラ) 表示
      if $game_variables[1] == 8
        p $game_variables[1]
        @actor.battler_face_name = "Face_9"
        @face_image = Cache.battle_hud(@actor.battler_face_name.to_s) rescue nil
      end
      #ダメージ立ち絵(手ブラ) 表示
      if $game_variables[1] == 9
        p $game_variables[1]
        @actor.battler_face_name = "Face_10"
        @face_image = Cache.battle_hud(@actor.battler_face_name.to_s) rescue nil
      end      
 
 
      #p @actor.battler_face_name.to_s
      #p @face_cw.to_s   
      #追記終わり
 
      @face.mirror = false
      @face.zoom_x = 1.00
      @face.zoom_y = 1.00
      @face_index = @actor.face_animation[1]
      @face.bitmap.clear
      if !FACE_ANIMATION
         f_scr = Rect.new(0,0,@face_cw,@face_ch)
      else
         f_scr = Rect.new(@face_index * @face_cw,0,@face_cw,@face_ch)
       end
      @face.bitmap.blt(0,0,@face_image,f_scr)
  end
 
  #--------------------------------------------------------------------------
  # * Update Face Duration
  #--------------------------------------------------------------------------    
  def update_face_duration
      return if @actor.face_animation[0] == 0
      @actor.face_animation[0] -= 1
      update_face_shake_effect
      update_face_zoom if @actor.face_animation[1] == 2
      return if @actor.face_animation[0] > 0
      clear_face_index
  end
 
  #--------------------------------------------------------------------------
  # * Clear Face Index
  #--------------------------------------------------------------------------      
  def clear_face_index
      @actor.face_animation[1] = @actor.low_hp? ? 3 : 0
      @actor.face_animation[1] = 4 if @actor.dead?
      refresh_face
  end
 
  #--------------------------------------------------------------------------
  # * Update Face Zoom
  #--------------------------------------------------------------------------      
  def update_face_zoom
      return if !FACE_ZOOM_ANIMATION
      case @actor.face_animation[0]
         when 30..60
            @face.zoom_x += 0.01
            @face.zoom_x = 1.30 if @face.zoom_x > 1.30
            @face.mirror = true unless !FACE_ZOOM_MIRROR_EFFECT
         when 1..29
            @face.zoom_x -= 0.01
            @face.zoom_x = 1.00 if @face.zoom_x < 1.00
            @face.mirror = false
         else 
            @face.zoom_x = 1.00
            @face.mirror = false
      end
      @face.zoom_y = @face.zoom_x
  end
 
  #--------------------------------------------------------------------------
  # * Can Refresh Index MP TP?
  #--------------------------------------------------------------------------     
  def can_refresh_index_mp_tp?
      return true if @face_old_mp != @actor.mp
      return false
  end
 
  #--------------------------------------------------------------------------
  # * Refresh Face Index HP
  #--------------------------------------------------------------------------  
  def refresh_face_index_hp
      @actor.face_animation[0] = FACE_ANIMATION_DURATION
      @actor.face_animation[1] = @face_old_hp > @actor.hp ? 3 : 1
      @face_old_hp = @actor.hp
  end
 
  #--------------------------------------------------------------------------
  # * Refresh Face Index MP TP
  #--------------------------------------------------------------------------  
  def refresh_face_index_mp_tp
      if @face_old_mp < @actor.mp
         @actor.face_animation[0] = FACE_ANIMATION_DURATION
         @actor.face_animation[1] = 1
      end
      @face_old_mp = @actor.mp
      @face_old_tp = @actor.tp
  end  
 
  #--------------------------------------------------------------------------
  # * Update Face Shake Effect
  #--------------------------------------------------------------------------  
  def update_face_shake_effect
      return if !FACE_SHAKE_EFFECT
      if FACE_ANIMATION
         update_shake_animated_face
      else            
         update_shake_still_face 
      end  
  end      
 
  #--------------------------------------------------------------------------
  # * Update Shake Still Effect Face 
  #--------------------------------------------------------------------------    
  def update_shake_still_face 
      if @actor.face_animation[0] > 0 and @actor.face_animation[1] == 3 and @actor.hp > 0
         @face.x = @face_org[0] - 4 + rand(8)
      else
         @face.x = @face_org[0]
      end     
  end
 
  #--------------------------------------------------------------------------
  # * Update Shake Animated Face
  #--------------------------------------------------------------------------    
  def update_shake_animated_face
      if @actor.face_animation[0] == 0
         @face.x = @face_org[0]
         return
      end
      if @actor.face_animation[1] == 3 and @actor.hp > 0
         @face.x = @face_org[0] - 4 + rand(8)
      else
         @face.x = @face_org[0]
      end         
  end
 
  #--------------------------------------------------------------------------
  # * Update Face
  #--------------------------------------------------------------------------   
  def update_face
      return if @face == nil
      sprite_visible(@face)
      refresh_face_index_hp if !FACE_ANIMATION and @face_old_hp != @actor.hp
      update_face_duration
      return if !FACE_ANIMATION
      refresh_face_index_mp_tp if can_refresh_index_mp_tp?
      refresh_face_index_hp if @face_old_hp != @actor.hp
      refresh_face if @face_index != @actor.face_animation[1]
  end  
 
end
 
#==============================================================================
# ■ Battle Manager
#==============================================================================
class << BattleManager
 
  #--------------------------------------------------------------------------
  # ● Battle End
  #--------------------------------------------------------------------------                    
  alias mog_battle_hud_battle_process_victory process_victory
  def process_victory
      execute_face_effect_end
      mog_battle_hud_battle_process_victory
  end
 
  #--------------------------------------------------------------------------
  # ● Execute Face Effect End
  #--------------------------------------------------------------------------                  
  def execute_face_effect_end
      $game_temp.battle_end = true
      for i in $game_party.members
          i.face_animation = [120,1,0] if i.hp > 0   
      end  
  end
 
  #--------------------------------------------------------------------------
  # * Display EXP Earned
  #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_message_battle_process_defeat process_defeat
  def process_defeat 
      $game_temp.battle_end = true
      mog_battle_hud_ex_message_battle_process_defeat
  end
 
  #--------------------------------------------------------------------------
  # * Process Abort
  #--------------------------------------------------------------------------
  alias mog_battle_hud_ex_process_abort process_abort
  def process_abort
      $game_temp.battle_end = true
      mog_battle_hud_ex_process_abort
  end  
 
end
 
#==============================================================================
# ** Scene Battle
#==============================================================================
class Scene_Battle < Scene_Base
 
  #--------------------------------------------------------------------------
  # * Use Item
  #--------------------------------------------------------------------------      
  alias mog_monogatari_use_item use_item
  def use_item
      execute_face_animation
      mog_monogatari_use_item
  end
 
  #--------------------------------------------------------------------------
  # * Execute Face Animation
  #--------------------------------------------------------------------------  
  def execute_face_animation
      return if @subject.is_a?(Game_Enemy)
      @subject.face_animation = [60 ,2,0]   
  end
 
end
 
#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
 
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------  
  def dispose
      terminate
      dispose_layout
      dispose_layout_2
      dispose_name
      dispose_face
      dispose_hp_number
      dispose_hp_number_max
      dispose_hp_meter
      dispose_hp_icon
      dispose_hp_icon_ex
      dispose_hp_icon_number
      dispose_mp_number
      dispose_mp_number_max
      dispose_mp_meter
      dispose_mp_icon
      dispose_mp_icon_ex
      dispose_mp_icon_number
      dispose_tp_number
      dispose_tp_number_max
      dispose_tp_meter
      dispose_tp_icon
      dispose_tp_icon_ex
      dispose_tp_icon_number
      dispose_at_number
      dispose_at_number_max
      dispose_at_meter      
      dispose_lv_number
      dispose_states
  end
 
  #--------------------------------------------------------------------------
  # * Dispose Layout
  #--------------------------------------------------------------------------  
  def dispose_layout
      return if @layout == nil
      @layout.dispose
      @layout = nil
  end
 
  #--------------------------------------------------------------------------
  # * Dispose Layout 2
  #--------------------------------------------------------------------------  
  def dispose_layout_2
      return if @layout2 == nil
      @layout2.dispose
      @layout2 = nil
  end  
 
  #--------------------------------------------------------------------------
  # * Dispose Name
  #--------------------------------------------------------------------------          
  def dispose_name
      return if @name == nil
      @name.bitmap.dispose
      @name.dispose
      @name = nil
  end  
 
  #--------------------------------------------------------------------------
  # * Dispose Face
  #--------------------------------------------------------------------------        
  def dispose_face
      return if @face == nil      
      @face.bitmap.dispose if @face.bitmap != nil    
      @face.dispose
      @face = nil
      @face_image.dispose if @face_image != nil
  end  
 
  #--------------------------------------------------------------------------
  # * Dispose HP Number
  #--------------------------------------------------------------------------    
  def dispose_hp_number
      return if @hp_number == nil
      @hp_number.bitmap.dispose
      @hp_number.dispose
      @hp_number = nil
  end
 
  #--------------------------------------------------------------------------
  # * Dispose HP Number Max
  #--------------------------------------------------------------------------    
  def dispose_hp_number_max
      return if @hp_number2 == nil
      @hp_number2.bitmap.dispose
      @hp_number2.dispose
      @hp_number2 = nil
  end    
 
  #--------------------------------------------------------------------------
  # * Dispose HP Meter
  #--------------------------------------------------------------------------     
  def dispose_hp_meter
      return if @hp_meter == nil
      @hp_meter.bitmap.dispose
      @hp_meter.dispose
      @hp_meter = nil
  end   
 
  #--------------------------------------------------------------------------
  # * Dispose HP Icon
  #--------------------------------------------------------------------------       
  def dispose_hp_icon
      return if @hp_icon == nil
      @hp_icon.bitmap.dispose if @hp_icon.bitmap != nil
      @hp_icon.dispose
      @hp_icon = nil
  end    
 
  #--------------------------------------------------------------------------
  # * Dispose HP Icon EX
  #--------------------------------------------------------------------------       
  def dispose_hp_icon_ex
      return if @hp_icon3 == nil
      @hp_icon3.bitmap.dispose
      @hp_icon3.dispose
      @hp_icon3 = nil
  end      
 
  #--------------------------------------------------------------------------
  # * Dispose HP Icon Number
  #--------------------------------------------------------------------------  
  def dispose_hp_icon_number
      return if @hp_icon_number == nil
      @hp_icon_number.bitmap.dispose
      @hp_icon_number.dispose
      @hp_icon_number = nil
  end    
 
  #--------------------------------------------------------------------------
  # * Dispose MP Number
  #--------------------------------------------------------------------------    
  def dispose_mp_number
      return if @mp_number == nil
      @mp_number.bitmap.dispose
      @mp_number.dispose
      @mp_number = nil
  end    
 
  #--------------------------------------------------------------------------
  # * Dispose MP Number Max
  #--------------------------------------------------------------------------    
  def dispose_mp_number_max
      return if @mp_number2 == nil
      @mp_number2.bitmap.dispose
      @mp_number2.dispose
      @mp_number2 = nil
  end   
 
  #--------------------------------------------------------------------------
  # * Dispose MP Meter
  #--------------------------------------------------------------------------     
  def dispose_mp_meter
      return if @mp_meter == nil
      @mp_meter.bitmap.dispose
      @mp_meter.dispose
      @mp_meter = nil
  end     
 
  #--------------------------------------------------------------------------
  # * Dispose MP Icon
  #--------------------------------------------------------------------------       
  def dispose_mp_icon
      return if @mp_icon == nil
      @mp_icon.bitmap.dispose if @mp_icon.bitmap != nil
      @mp_icon.dispose
      @mp_icon = nil
  end     
 
  #--------------------------------------------------------------------------
  # * Dispose MP Icon EX
  #--------------------------------------------------------------------------       
  def dispose_mp_icon_ex
      return if @mp_icon3 == nil
      @mp_icon3.bitmap.dispose
      @mp_icon3.dispose
      @mp_icon3 = nil
  end        
 
  #--------------------------------------------------------------------------
  # * Dispose MP Icon Number
  #--------------------------------------------------------------------------  
  def dispose_mp_icon_number
      return if @mp_icon_number == nil
      @mp_icon_number.bitmap.dispose
      @mp_icon_number.dispose
      @mp_icon_number = nil
  end   
 
  #--------------------------------------------------------------------------
  # * Dispose TP Number
  #--------------------------------------------------------------------------    
  def dispose_tp_number
      return if @tp_number == nil
      @tp_number.bitmap.dispose
      @tp_number.dispose
      @tp_number = nil
  end
 
  #--------------------------------------------------------------------------
  # * Dispose TP Number Max
  #--------------------------------------------------------------------------    
  def dispose_tp_number_max
      return if @tp_number2 == nil
      @tp_number2.bitmap.dispose
      @tp_number2.dispose
      @tp_number2 = nil
  end  
 
  #--------------------------------------------------------------------------
  # * Dispose TP Meter
  #--------------------------------------------------------------------------     
  def dispose_tp_meter
      return if @tp_meter == nil
      @tp_meter.bitmap.dispose
      @tp_meter.dispose
      @tp_meter = nil
  end     
 
  #--------------------------------------------------------------------------
  # * Dispose TP Icon
  #--------------------------------------------------------------------------       
  def dispose_tp_icon
      return if @tp_icon == nil
      @tp_icon.bitmap.dispose if @tp_icon.bitmap != nil
      @tp_icon.dispose
      @tp_icon = nil
  end    
 
  #--------------------------------------------------------------------------
  # * Dispose TP Icon EX
  #--------------------------------------------------------------------------       
  def dispose_tp_icon_ex
      return if @tp_icon3 == nil
      @tp_icon3.bitmap.dispose
      @tp_icon3.dispose
      @tp_icon3 = nil
  end   
 
  #--------------------------------------------------------------------------
  # * Dispose TP Icon Number
  #--------------------------------------------------------------------------  
  def dispose_tp_icon_number
      return if @tp_icon_number == nil
      @tp_icon_number.bitmap.dispose
      @tp_icon_number.dispose
      @tp_icon_numbe = nil
  end     
 
  #--------------------------------------------------------------------------
  # * Dispose AT Number
  #--------------------------------------------------------------------------    
  def dispose_at_number
      return if @at_number == nil
      @at_number.bitmap.dispose
      @at_number.dispose
      @at_number = nil
  end
 
  #--------------------------------------------------------------------------
  # * Dispose AT Number Max
  #--------------------------------------------------------------------------    
  def dispose_at_number_max
      return if @at_number2 == nil
      @at_number2.bitmap.dispose
      @at_number2.dispose
      @at_number2 = nil
  end    
 
  #--------------------------------------------------------------------------
  # * Dispose AT Meter
  #--------------------------------------------------------------------------     
  def dispose_at_meter
      return if @at_meter == nil
      @at_meter.bitmap.dispose
      @at_meter.dispose
      @at_meter = nil
  end     
 
  #--------------------------------------------------------------------------
  # * Dispose Lv Number
  #--------------------------------------------------------------------------    
  def dispose_lv_number
      return if @lv_number == nil
      @lv_number.bitmap.dispose
      @lv_number.dispose
      @lv_number = nil
  end
 
  #--------------------------------------------------------------------------
  # * Dispose States
  #--------------------------------------------------------------------------      
  def dispose_states
      return if @status == nil
      @status.bitmap.dispose if @status.bitmap != nil
      @status.dispose
      @actor_status.dispose if @actor_status != nil
      @status = nil
  end
 
end
 
#==============================================================================
#==============================================================================
# ** Battle Hud EX
#==============================================================================
#==============================================================================
class Battle_Hud_EX
 
 #--------------------------------------------------------------------------
 # * Refresh Visible
 #--------------------------------------------------------------------------  
 def refresh_visible(vis)
     @layout.visible = vis if @layout
     @layout2.visible = vis if @layout2
     @name.visible = vis if @name
     @lv_number.visible = vis if @lv_number
     @status.visible = vis if @status
     @face.visible = vis if @face     
     @hp_number.visible = vis if @hp_number
     @hp_number2.visible = vis if @hp_number2
     @hp_meter.visible = vis if @hp_meter
     @hp_icon.visible = vis if @hp_icon
     @hp_icon3.visible = vis if @hp_icon3
     @hp_icon_number.visible = vis if @hp_icon_number     
     @mp_number.visible = vis if @mp_number
     @mp_number2.visible = vis if @mp_number2
     @mp_meter.visible = vis if @mp_meter
     @mp_icon.visible = vis if @mp_icon
     @mp_icon3.visible = vis if @mp_icon3
     @mp_icon_number.visible = vis if @mp_icon_number
     @tp_number.visible = vis if @tp_number
     @tp_number2.visible = vis if @tp_number2
     @tp_meter.visible = vis if @tp_meter
     @tp_icon.visible = vis if @tp_icon
     @tp_icon3.visible = vis if @tp_icon3
     @tp_icon_number.visible = vis if @tp_icon_number      
     @at_number.visible = vis if @at_number
     @at_number2.visible = vis if @at_number2
     @at_meter.visible = vis if @at_meter    
  end  
 
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------  
  def update
      return if @actor == nil
      @sprite_visible = sprite_visible?
      @sprite_visitle_wait -= 1 if @sprite_visitle_wait > 0
      update_layout ; update_layout_2 ; update_name
      update_face ; update_hp ; update_mp ; update_tp
      update_at ; update_level ; update_states
  end
 
end
 
#==============================================================================
# ■ Sprite Battler
#==============================================================================
class Sprite_Battler < Sprite_Base
 
  #--------------------------------------------------------------------------
  # ● Set AV
  #--------------------------------------------------------------------------      
  def set_av(a_viewport)
      @viewport_cm = a_viewport 
  end
 
  #--------------------------------------------------------------------------
  # ● Dispose
  #--------------------------------------------------------------------------      
  alias mog_bc_dispose dispose
  def dispose
      mog_bc_dispose
      @viewport_cm.dispose if @viewport_cm != nil
  end
 
  #--------------------------------------------------------------------------
  # ● Maker Animation Sprites
  #--------------------------------------------------------------------------      
  alias mog_bc_make_animation_sprites make_animation_sprites
  def make_animation_sprites
      mog_bc_make_animation_sprites
      set_cm_viewport if $imported[:mog_battle_camera]
  end
 
  #--------------------------------------------------------------------------
  # ● Set CM Viewpor
  #--------------------------------------------------------------------------      
  def set_cm_viewport
      return if @viewport_cm == nil
      return if @ani_sprites == nil
      if @battler.is_a?(Game_Actor) and SceneManager.face_battler?
         @ani_sprites.each {|sprite| sprite.viewport = nil; sprite.z = 100} 
         return
      end
      @ani_sprites.each {|sprite| sprite.viewport = @viewport_cm; sprite.z = 100} 
  end
 
end 
 
#==============================================================================
# ■ Game Temp
#==============================================================================
class Spriteset_Battle
 
  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------      
  alias mog_bc_sp_initialize initialize
  def initialize
      mog_bc_sp_initialize
      if $imported[:mog_battle_camera] and @viewport_cm != nil
         battler_sprites.each do |sprite| sprite.set_av(@viewport_cm) end
      end
  end
 
  #--------------------------------------------------------------------------
  # ● Create Viewports
  #--------------------------------------------------------------------------      
  alias mog_bc_create_viewports create_viewports
  def create_viewports
      mog_bc_create_viewports
      if $imported[:mog_battle_camera]
         @viewport_cm = Viewport.new
         #追加
         @viewport_cm.z = 100
      end   
  end
 
  #--------------------------------------------------------------------------
  # ● Dispose Viewports
  #--------------------------------------------------------------------------      
  alias mog_bc_dispose_viewports dispose_viewports
  def dispose_viewports
      mog_bc_dispose_viewports
      @viewport_cm.dispose if $imported[:mog_battle_camera] and @viewport_cm != nil
  end
 
  #--------------------------------------------------------------------------
  # ● Update Viewports
  #--------------------------------------------------------------------------      
  alias mog_bcf_update_viewports update_viewports
  def update_viewports
      mog_bcf_update_viewports
      update_viewport_cm if $imported[:mog_battle_camera]
  end
 
  #--------------------------------------------------------------------------
  # ● Update Viewport CM
  #--------------------------------------------------------------------------      
  def update_viewport_cm
      return if @viewport_cm == nil  
      @viewport_cm.ox = $game_troop.screen.shake + $game_temp.bc_data[0]
      @viewport_cm.oy = $game_temp.bc_data[1]
      @viewport_cm.update
  end
 
end