查看: 1621|回复: 3

[已经解决] MOG伤害显示脚本字体被压扁了

[复制链接]
梦石
0
星屑
1487
在线时间
429 小时
注册时间
2014-4-25
回帖
32
发表于 2022-2-28 19:34:34 | 显示全部楼层 |阅读模式
悬赏50星屑已解决
QQ截图20220228191514.png
QQ截图20220228184400.png

p1是原范例的黑体,p2是我想要使用在游戏里的字体,都是横着被压扁了
T T请问有什么办法优化吗?或者把表示“防御”、“中毒”等状态的文字用图片显示该怎么做?

附上脚本和脚本需要的图片

[pre lang="ruby"]#==============================================================================
# +++ MOG - 战斗 Hud EX (v6.6) +++
#==============================================================================
# By Moghunter
# https://atelierrgss.wordpress.com/
#==============================================================================
# 可以在战斗画面中显示各种自定义HUD图片。
# 全部图片放在文件夹:
#
# Graphics/Huds/Battle/
#==============================================================================
# 显示或隐藏战斗Hud的脚本
#
# battle_hud_visible(false)
#
# 或
#
# battle_hud_visible(true)
#
#==============================================================================
# 改变脸图的脚本
#==============================================================================
#
# battler_face_name( 角色ID, 脸图文件名 )
#
#==============================================================================

#==============================================================================
# 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 精灵 (通用)
  #============================================================================
  # 最大战斗角色数.
  #---------------------------------------------------------------------------
  MAX_BATTLE_MEMBERS = 4
  #---------------------------------------------------------------------------
  # hud的Z坐标.
  #---------------------------------------------------------------------------
  HUD_Z = 110
  #---------------------------------------------------------------------------
  # hud的位置.
  #---------------------------------------------------------------------------
  HUD_POSITION = [0,323]
  #---------------------------------------------------------------------------
  # 调整数字间距
  #---------------------------------------------------------------------------
  MEMBERS_SPACE = [0,0]
  #---------------------------------------------------------------------------
  # 修改指定HUD的位置
  #
  # FIXED_POSITION[索引ID] = [X,Y]
  #
  #---------------------------------------------------------------------------
  FIXED_HUD_POSITION = []
  # FIXED_HUD_POSITION[0] = [10,10]
  # FIXED_HUD_POSITION[1] = [410,10]
  # FIXED_HUD_POSITION[2] = [10,320]
  # FIXED_HUD_POSITION[3] = [410,320]
  #---------------------------------------------------------------------------
  # 修改指定指令窗口的位置
  #---------------------------------------------------------------------------
  FIXED_COMMAND_POSITION = []
  #FIXED_COMMAND_POSITION[0] = [130,10]
  # FIXED_COMMAND_POSITION[1] = [300,10]
  # FIXED_COMMAND_POSITION[2] = [130,290]
  # FIXED_COMMAND_POSITION[3] = [300,290]
  #---------------------------------------------------------------------------
  # 是否在显示文章时隐藏HUD.
  #---------------------------------------------------------------------------
  MESSAGE_WINDOW_FADE_HUD = true
  #---------------------------------------------------------------------------
  # 设置视为低数值的百分比,这会影响HP、MP、TP的颜色。有快消耗完时改变值槽颜色的
  # 效果
  #---------------------------------------------------------------------------
  LOW_PARAMETER_PERCENTAGE = 30
  #============================================================================
  #============================================================================
  
  
  #============================================================================
  #============================================================================
  # * 名字
  #============================================================================
  # 是否显示名字的精灵
  #---------------------------------------------------------------------------
  NAME_VISIBLE = false
  #---------------------------------------------------------------------------
  # 名字精灵的Z坐标
  #---------------------------------------------------------------------------  
  NAME_Z = 5
  #---------------------------------------------------------------------------
  # 名字位置. [X,Y]
  #---------------------------------------------------------------------------
  NAME_POSITION = [0,-7]
  #---------------------------------------------------------------------------
  # 设定对齐方式.
  #
  # 0 - 左
  # 1 - 中
  # 2 - 右
  #---------------------------------------------------------------------------  
  NAME_ALIGN_TYPE = 1
  #---------------------------------------------------------------------------
  # 字体
  #---------------------------------------------------------------------------
  NAME_FONT_NAME = "Georgia"
  #---------------------------------------------------------------------------
  # 字体大小
  #---------------------------------------------------------------------------   
  NAME_FONT_SIZE = 16
  #---------------------------------------------------------------------------
  # 是否加粗
  #---------------------------------------------------------------------------   
  NAME_FONT_BOLD = true
  #---------------------------------------------------------------------------
  # 是否斜体
  #---------------------------------------------------------------------------   
  NAME_FONT_ITALIC = true
  #---------------------------------------------------------------------------
  # 字体颜色
  #---------------------------------------------------------------------------     
  NAME_FONT_COLOR = Color.new(255,255,255,255)
  #---------------------------------------------------------------------------
  # 是否显示字体阴影
  #---------------------------------------------------------------------------  
  NAME_FONT_SHADOW = false
  #---------------------------------------------------------------------------
  # 字体阴影的颜色
  #---------------------------------------------------------------------------   
  NAME_FONT_SHADOW_COLOR = Color.new(0,0,0,255)
  #---------------------------------------------------------------------------
  # 字体阴影的位置
  #---------------------------------------------------------------------------   
  NAME_FONT_SHADOW_POSITION = [2,2]  
  #============================================================================
  #============================================================================
   
  
  #============================================================================
  #============================================================================
  # * 脸图
  #============================================================================
  # 是否显示脸图.
  # 需要图片:
  #
  # 角色名 + _Face.png
  #
  # Eric_Face.png
  #
  #---------------------------------------------------------------------------
  FACE_VISIBLE = true
  # 是否将角色的脸图作为其战斗图
  # 如果脚本出现问题请设定为"false".
  FACE_BATTLER = true
  #---------------------------------------------------------------------------
  # 脸图的Z坐标.
  #---------------------------------------------------------------------------  
  FACE_Z = -1
  #---------------------------------------------------------------------------
  # 脸图的位置. [X,Y]
  #---------------------------------------------------------------------------
  FACE_POSITION = [68,5]
  #---------------------------------------------------------------------------
  # 是否显示脸图动画.
  # 你需要一张可以分成五分的图片.
  #
  # FACE1/FACE2/FACE3/FACE4
  #
  #---------------------------------------------------------------------------  
  FACE_ANIMATION = true
  #---------------------------------------------------------------------------
  # 是否显示脸图的缩放动画
  #---------------------------------------------------------------------------
  FACE_ZOOM_ANIMATION = true
  #---------------------------------------------------------------------------
  # 是否显示脸图镜像效果.
  #---------------------------------------------------------------------------
  FACE_ZOOM_MIRROR_EFFECT = false
  #---------------------------------------------------------------------------
  # 脸图动画的时间.
  #---------------------------------------------------------------------------  
  FACE_ANIMATION_DURATION = 40
  #---------------------------------------------------------------------------
  # 是否显示脸图震动效果.
  #---------------------------------------------------------------------------  
  FACE_SHAKE_EFFECT = true
  #============================================================================
  #============================================================================
  
  
  #============================================================================
  #============================================================================
  # * 回合数 (实时数值)
  #============================================================================
  # 是否显示回合数的图片
  # 需要图片
  #
  # Turn.png
  #
  #---------------------------------------------------------------------------
  TURN_SPRITE_VISIBLE = true
  #---------------------------------------------------------------------------
  # 回合数图片精灵Z坐标.
  #---------------------------------------------------------------------------   
  TURN_SPRITE_Z = 0
  #---------------------------------------------------------------------------
  # 回合数图片位置
  #---------------------------------------------------------------------------  
  TURN_SPRITE_POSITION = [8,-30]
  #---------------------------------------------------------------------------  
  # 是否显示闪烁效果
  #---------------------------------------------------------------------------  
  TURN_BLINK_EFFECT = true
  #---------------------------------------------------------------------------  
   
  
  #============================================================================
  #============================================================================
  # * HP
  #============================================================================
  # 是否显示HP数字图片
  # 需要图片
  #
  # HP_Number.png
  #
  #---------------------------------------------------------------------------
  HP_NUMBER_VISIBLE = true
  #---------------------------------------------------------------------------
  # Hp数字的Z坐标
  #---------------------------------------------------------------------------   
  HP_NUMBER_Z = 2
  #---------------------------------------------------------------------------
  # HP数字的位置. [X,Y]
  #---------------------------------------------------------------------------  
  HP_NUMBER_POSITION = [117,26]
  #---------------------------------------------------------------------------  
  # 是否显示HP总量数字的图片.
  # 需要图片:
  #
  # HP_Number_Max.png
  #
  #---------------------------------------------------------------------------
  HP_NUMBER_MAX_VISIBLE = false
  #---------------------------------------------------------------------------
  # HP总量数字的位置. [X,Y]
  #---------------------------------------------------------------------------  
  HP_NUMBER_MAX_POSITION = [165,30]
  #---------------------------------------------------------------------------
  # 设定数字对齐方式.
  #
  # 0 - 左
  # 1 - 中
  # 2 - 右
  #---------------------------------------------------------------------------  
  HP_NUMBER_ALIGN_TYPE = 2
  #---------------------------------------------------------------------------
  # 是否显示数字波浪形对齐方式.
  #---------------------------------------------------------------------------
  HP_NUMBER_WAVE_ALIGN_EFFECT = false
  #---------------------------------------------------------------------------
  # 是否以百分比显示数字
  #---------------------------------------------------------------------------   
  HP_NUMBER_PERCENTAGE = false
  #---------------------------------------------------------------------------
  # 是否显示数字动画效果 ("滚动").
  #---------------------------------------------------------------------------  
  HP_NUMBER_ANIMATION = true
  #---------------------------------------------------------------------------
  # 是否在HP低下时显示另一张颜色的图片作为HP数字.
  # 需要一张被分成两帧高的图片
  #
  # 普通颜色
  # 低下时颜色
  #
  # 如果你设定为false则图片会被分成一帧高.
  #---------------------------------------------------------------------------  
  HP_NUMBER_LOW_COLOR = false
  #---------------------------------------------------------------------------
  # 是否使用 HP 条图片.
  # 需要图片.
  #
  # HP_Meter.png
  #  
  #---------------------------------------------------------------------------  
  HP_METER_VISIBLE = true
  #---------------------------------------------------------------------------
  # 设定HP条的Z坐标.
  #---------------------------------------------------------------------------   
  HP_METER_Z = 1
  #---------------------------------------------------------------------------
  # 设定HP条的位置. [X,Y]
  #---------------------------------------------------------------------------  
  HP_METER_POSITION = [38,39]
  #---------------------------------------------------------------------------
  # 设定HP条的倾角.
  #---------------------------------------------------------------------------  
  HP_METER_ANGLE = 0
  #---------------------------------------------------------------------------
  # 是否显示HP条的镜像效果
  #---------------------------------------------------------------------------  
  HP_METER_MIRROR_EFFECT = false
  #---------------------------------------------------------------------------
  # 是否使用HP条在角色受到伤害时显示不同的颜色的效果
  # 需要一张被分成两帧高的图片
  #
  # 普通颜色
  # 受伤颜色
  #
  # 设定为false则显示普通效果.
  #---------------------------------------------------------------------------  
  HP_METER_REDUCTION_ANIMATION = true
  #---------------------------------------------------------------------------
  #是否使用HP条的动画流动效果,需要一张宽度为正常大小三倍的图片,图片需要有颜色
  #梯度变化来表现"流动"的效果。
  #设定为false则显示普通效果.
  #---------------------------------------------------------------------------  
  HP_METER_GRADIENT_ANIMATION = true
  #---------------------------------------------------------------------------
  # 是否显示HP图标图片.
  # 需要图片:
  #
  # HP_Icon.png
  #
  #---------------------------------------------------------------------------
  HP_ICON_VISIBLE = false
  #---------------------------------------------------------------------------
  # HP图标的Z坐标
  #---------------------------------------------------------------------------   
  HP_ICON_Z = 1
  #---------------------------------------------------------------------------
  # HP图标的位置.
  #---------------------------------------------------------------------------  
  HP_ICON_POSITION = [200,0]
  #---------------------------------------------------------------------------
  # 是否使用HP图标EX ,其作为HP图标的最后一个图标
  # 需要图片:
  #
  # HP_Icon_EX.png
  #
  #---------------------------------------------------------------------------
  HP_ICON_EX_VISIBLE = false
  #---------------------------------------------------------------------------
  # HP图标EX的位置.
  #---------------------------------------------------------------------------  
  HP_ICON_EX_POSITION = [0,0]
  #---------------------------------------------------------------------------
  # 是否显示HP图标EX的缩放效果.
  #---------------------------------------------------------------------------
  HP_ICON_EX_ZOOM_EFFECT = true
  #---------------------------------------------------------------------------
  # HP图标EX的间隔.
  #---------------------------------------------------------------------------   
  HP_ICON_SPACE = [-10,-10]
  #---------------------------------------------------------------------------
  # 设置水平上图标的最大数量
  #---------------------------------------------------------------------------  
  HP_ICON_COL_MAX = 10
  #---------------------------------------------------------------------------
  # 设置竖直上图标的最大数量
  #---------------------------------------------------------------------------   
  HP_ICON_ROW_MAX = 2
  #---------------------------------------------------------------------------
  # 是否显示HP图标图片
  # 需要图片
  #
  # HP_Icon_Number.png
  #
  #---------------------------------------------------------------------------
  HP_ICON_NUMBER_VISIBLE = false
  #---------------------------------------------------------------------------
  # Hp图标的Z坐标
  #---------------------------------------------------------------------------
  HP_ICON_NUMBER_Z = 4
  #---------------------------------------------------------------------------
  # Posição do número do ícone
  #---------------------------------------------------------------------------  
  HP_ICON_NUMBER_POSITION = [0,0]
  #---------------------------------------------------------------------------
  # 设定图标数字对齐方式.
  #
  # 0 - 左
  # 1 - 中
  # 2 - 右
  #---------------------------------------------------------------------------  
  HP_ICON_NUMBER_ALIGN_TYPE = 0   
  #============================================================================
  #============================================================================
  
  
  #============================================================================
  #============================================================================
  # * MP
  #============================================================================
  # 是否显示MP数字图片
  # 需要图片
  #
  # MP_Number.png
  #  
  #---------------------------------------------------------------------------  
  MP_NUMBER_VISIBLE = true
  #---------------------------------------------------------------------------
  # Mp数字的Z坐标
  #---------------------------------------------------------------------------   
  MP_NUMBER_Z = 2  
  #---------------------------------------------------------------------------
  # MP数字的位置
  #---------------------------------------------------------------------------  
  MP_NUMBER_POSITION = [90,44]
  #---------------------------------------------------------------------------  
  # 是否显示MP总量数字的图片.
  # 需要图片:
  #
  # MP_Number_Max.png
  #
  #---------------------------------------------------------------------------
  MP_NUMBER_MAX_VISIBLE = false
  #---------------------------------------------------------------------------
  # MP总量数字的位置. [X,Y]
  #---------------------------------------------------------------------------  
  MP_NUMBER_MAX_POSITION = [128,53]
  #---------------------------------------------------------------------------
  # 设定数字对齐方式.
  #
  # 0 - 左
  # 1 - 中
  # 2 - 右
  #---------------------------------------------------------------------------  
  MP_NUMBER_ALIGN_TYPE = 2
  #---------------------------------------------------------------------------
  #是否显示数字波浪形对齐方式.
  #---------------------------------------------------------------------------
  MP_NUMBER_WAVE_ALIGN_EFFECT = false   
  #---------------------------------------------------------------------------
  # 是否以百分比显示数字
  #---------------------------------------------------------------------------   
  MP_NUMBER_PERCENTAGE = false
  #---------------------------------------------------------------------------
  # 是否显示数字动画效果 ("滚动").
  #---------------------------------------------------------------------------  
  MP_NUMBER_ANIMATION = true
  #---------------------------------------------------------------------------
  # 是否在HP低下时显示另一张颜色的图片作为MP数字.
  # 需要一张被分成两帧高的图片
  #
  # 普通颜色
  # 低下时颜色
  #
  # 如果你设定为false则图片会被分成一帧高.
  #---------------------------------------------------------------------------  
  MP_NUMBER_LOW_COLOR = false
  #---------------------------------------------------------------------------
  # 是否使用 MP 条图片.
  # 需要图片.
  #
  # MP_Meter.png
  #   
  #---------------------------------------------------------------------------  
  MP_METER_VISIBLE = true
  #---------------------------------------------------------------------------
  # 设定MP条的Z坐标.
  #---------------------------------------------------------------------------   
  MP_METER_Z = 1  
  #---------------------------------------------------------------------------
  # 设定MP条的位置. [X,Y]
  #---------------------------------------------------------------------------  
  MP_METER_POSITION = [9,56]
  #---------------------------------------------------------------------------
  # 设定MP条的倾角.
  #---------------------------------------------------------------------------  
  MP_METER_ANGLE = 0
  #---------------------------------------------------------------------------
  # 是否显示MP条的镜像效果
  #---------------------------------------------------------------------------  
  MP_METER_MIRROR_EFFECT = false
  #---------------------------------------------------------------------------
  # 是否使用MP条在角色受到伤害时显示不同的颜色的效果
  # 需要一张被分成两帧高的图片
  #
  # 普通颜色
  # 受伤颜色
  #
  # 设定为false则显示普通效果.
  #---------------------------------------------------------------------------  
  MP_METER_REDUCTION_ANIMATION = true
  #---------------------------------------------------------------------------
  #是否使用MP条的动画流动效果,需要一张宽度为正常大小三倍的图片,图片需要有颜色
  #梯度变化来表现"流动"的效果。
  #设定为false则显示普通效果.
  #---------------------------------------------------------------------------  
  MP_METER_GRADIENT_ANIMATION = true
  #---------------------------------------------------------------------------
  # 是否显示MP图标图片.
  # 需要图片:
  #
  # MP_Icon.png
  #
  #---------------------------------------------------------------------------
  MP_ICON_VISIBLE = false
  #---------------------------------------------------------------------------
  # MP图标的Z坐标
  #---------------------------------------------------------------------------   
  MP_ICON_Z = 1  
  #---------------------------------------------------------------------------
  # MP图标的位置.
  #---------------------------------------------------------------------------  
  MP_ICON_POSITION = [200,64]
  #---------------------------------------------------------------------------
  # 是否使用MP图标EX ,其作为MP图标的最后一个图标
  # 需要图片:
  #
  # MP_Icon_EX.png
  #
  #---------------------------------------------------------------------------
  MP_ICON_EX_VISIBLE = false
  #---------------------------------------------------------------------------
  # MP图标EX的位置.
  #---------------------------------------------------------------------------  
  MP_ICON_EX_POSITION = [0,0]
  #---------------------------------------------------------------------------
  # 是否显示MP图标EX的缩放效果.
  #---------------------------------------------------------------------------
  MP_ICON_EX_ZOOM_EFFECT = true
  #---------------------------------------------------------------------------
  # MP图标EX的间隔.
  #---------------------------------------------------------------------------   
  MP_ICON_SPACE = [-10,-10]
  #---------------------------------------------------------------------------
  # 设置水平上图标的最大数量
  #---------------------------------------------------------------------------  
  MP_ICON_COL_MAX = 10
  #---------------------------------------------------------------------------
  # 设置竖直上图标的最大数量
  #---------------------------------------------------------------------------   
  MP_ICON_ROW_MAX = 2
  #---------------------------------------------------------------------------
  # 是否显示MP图标图片
  # 需要图片
  #
  # MP_Icon_Number.png
  #
  #---------------------------------------------------------------------------
  MP_ICON_NUMBER_VISIBLE = false
  #---------------------------------------------------------------------------
  # Mp图标的Z坐标
  #---------------------------------------------------------------------------
  MP_ICON_NUMBER_Z = 4
  #---------------------------------------------------------------------------
  # MP图标的位置
  #---------------------------------------------------------------------------  
  MP_ICON_NUMBER_POSITION = [0,64]
  #---------------------------------------------------------------------------
  # 设定图标数字对齐方式.
  #
  # 0 - 左
  # 1 - 中
  # 2 - 右
  #---------------------------------------------------------------------------  
  MP_ICON_NUMBER_ALIGN_TYPE = 0   
  #============================================================================
  #============================================================================
  
  
  #============================================================================
  #============================================================================
  # * TP
  #============================================================================
  # 是否显示TP数字图片
  # 需要图片
  #
  # TP_Number.png
  #   
  #---------------------------------------------------------------------------
  TP_NUMBER_VISIBLE = true
  #---------------------------------------------------------------------------
  # Tp数字的Z坐标
  #---------------------------------------------------------------------------
  TP_NUMBER_Z = 5  
  #---------------------------------------------------------------------------
  # TP数字的位置. [X,Y]
  #---------------------------------------------------------------------------  
  TP_NUMBER_POSITION = [19,23]
  #---------------------------------------------------------------------------  
  # 是否显示TP总量数字的图片.
  # 需要图片:
  #
  # TP_Number_Max.png
  #
  #---------------------------------------------------------------------------
  TP_NUMBER_MAX_VISIBLE = false
  #---------------------------------------------------------------------------
  # TP总量数字的位置. [X,Y]
  #---------------------------------------------------------------------------  
  TP_NUMBER_MAX_POSITION = [165,73]
  #---------------------------------------------------------------------------
  # 设定数字对齐方式.
  #
  # 0 - 左
  # 1 - 中
  # 2 - 右
  #---------------------------------------------------------------------------  
  TP_NUMBER_ALIGN_TYPE = 1
  #---------------------------------------------------------------------------
  # 是否显示数字波浪形对齐方式.
  #---------------------------------------------------------------------------
  TP_NUMBER_WAVE_ALIGN_EFFECT = false   
  #---------------------------------------------------------------------------
  # 是否以百分比显示数字
  #---------------------------------------------------------------------------   
  TP_NUMBER_PERCENTAGE = false
  #---------------------------------------------------------------------------
  # 是否显示数字动画效果 ("滚动").
  #---------------------------------------------------------------------------  
  TP_NUMBER_ANIMATION = true
  #---------------------------------------------------------------------------
  # 是否在HP低下时显示另一张颜色的图片作为TP数字.
  # 需要一张被分成两帧高的图片
  #
  # 普通颜色
  # 低下时颜色
  #
  # 如果你设定为false则图片会被分成一帧高.
  #---------------------------------------------------------------------------  
  TP_NUMBER_LOW_COLOR = false
  #---------------------------------------------------------------------------
  # 是否使用 TP 条图片.
  # 需要图片.
  #
  # TP_Meter.png
  #   
  #---------------------------------------------------------------------------  
  TP_METER_VISIBLE = false
  #---------------------------------------------------------------------------
  # 设定TP条的Z坐标.
  #---------------------------------------------------------------------------
  TP_METER_Z = 1  
  #---------------------------------------------------------------------------
  # 设定TP条的位置. [X,Y]
  #---------------------------------------------------------------------------  
  TP_METER_POSITION = [68,74]
  #---------------------------------------------------------------------------
  # 设定TP条的倾角.
  #---------------------------------------------------------------------------  
  TP_METER_ANGLE = 0
  #---------------------------------------------------------------------------
  # 是否显示TP条的镜像效果
  #---------------------------------------------------------------------------  
  TP_METER_MIRROR_EFFECT = false
  #---------------------------------------------------------------------------
  # 是否使用TP条在角色受到伤害时显示不同的颜色的效果
  # 需要一张被分成两帧高的图片
  #
  # 普通颜色
  # 受伤颜色
  #
  # 设定为false则显示普通效果.
  #---------------------------------------------------------------------------  
  TP_METER_REDUCTION_ANIMATION = true
  #---------------------------------------------------------------------------
  #是否使用TP条的动画流动效果,需要一张宽度为正常大小三倍的图片,图片需要有颜色
  #梯度变化来表现"流动"的效果。
  #设定为false则显示普通效果.
  #---------------------------------------------------------------------------  
  TP_METER_GRADIENT_ANIMATION = true
  #---------------------------------------------------------------------------
  # 是否显示TP图标图片.
  # 需要图片:
  #
  # TP_Icon.png
  #
  #---------------------------------------------------------------------------
  TP_ICON_VISIBLE = false
  #---------------------------------------------------------------------------
  # TP图标的Z坐标
  #---------------------------------------------------------------------------
  TP_ICON_Z = 1  
  #---------------------------------------------------------------------------
  # TP图标的位置.
  #---------------------------------------------------------------------------  
  TP_ICON_POSITION = [200,128]
  #---------------------------------------------------------------------------
  # 是否使用TP图标EX ,其作为TP图标的最后一个图标
  # 需要图片:
  #
  # TP_Icon_EX.png
  #
  #---------------------------------------------------------------------------
  TP_ICON_EX_VISIBLE = false
  #---------------------------------------------------------------------------
  # TP图标EX的位置.
  #---------------------------------------------------------------------------  
  TP_ICON_EX_POSITION = [0,0]
  #---------------------------------------------------------------------------
  # 是否显示TP图标EX的缩放效果.
  #---------------------------------------------------------------------------
  TP_ICON_EX_ZOOM_EFFECT = true
  #---------------------------------------------------------------------------
  # TP图标EX的间隔.
  #---------------------------------------------------------------------------   
  TP_ICON_SPACE = [-10,-10]
  #---------------------------------------------------------------------------
  # 设置水平上图标的最大数量
  #---------------------------------------------------------------------------  
  TP_ICON_COL_MAX = 10
  #---------------------------------------------------------------------------
  # 设置竖直上图标的最大数量
  #---------------------------------------------------------------------------   
  TP_ICON_ROW_MAX = 2
  #---------------------------------------------------------------------------
  # 是否显示TP图标图片
  # 需要图片
  #
  # TP_Icon_Number.png
  #
  #---------------------------------------------------------------------------
  TP_ICON_NUMBER_VISIBLE = false
  #---------------------------------------------------------------------------
  # Tp图标的Z坐标
  #---------------------------------------------------------------------------
  TP_ICON_NUMBER_Z = 4
  #---------------------------------------------------------------------------
  # TP图标的位置
  #---------------------------------------------------------------------------  
  TP_ICON_NUMBER_POSITION = [0,128]
  #---------------------------------------------------------------------------
  # 设定图标数字对齐方式.
  #
  # 0 - 左
  # 1 - 中
  # 2 - 右
  #---------------------------------------------------------------------------  
  TP_ICON_NUMBER_ALIGN_TYPE = 0   
  #============================================================================
  #============================================================================
  
  #============================================================================
  #============================================================================
  # * AT
  #============================================================================
  # 是否显示At数字图片
  # 需要图片
  #
  # AT_Number.png
  #
  #---------------------------------------------------------------------------
  AT_NUMBER_VISIBLE = false
  #---------------------------------------------------------------------------
  # AT数字的Z坐标
  #---------------------------------------------------------------------------   
  AT_NUMBER_Z = 2
  #---------------------------------------------------------------------------
  # AT数字的位置. [X,Y]
  #---------------------------------------------------------------------------  
  AT_NUMBER_POSITION = [125,-27]
  #---------------------------------------------------------------------------  
  # 是否显示AT总量数字的图片.
  # 需要图片:
  #
  # AT_Number_Max.png
  #
  #---------------------------------------------------------------------------
  AT_NUMBER_MAX_VISIBLE = false
  #---------------------------------------------------------------------------
  # AT总量数字的位置. [X,Y]
  #---------------------------------------------------------------------------  
  AT_NUMBER_MAX_POSITION = [165,-17]
  #---------------------------------------------------------------------------
  # 设定数字对齐方式.
  #
  # 0 - 左
  # 1 - 中
  # 2 - 右
  #---------------------------------------------------------------------------  
  AT_NUMBER_ALIGN_TYPE = 2
  #---------------------------------------------------------------------------
  # 是否显示数字波浪形对齐方式.
  #---------------------------------------------------------------------------
  AT_NUMBER_WAVE_ALIGN_EFFECT = false
  #---------------------------------------------------------------------------
  # 是否以百分比显示数字
  #---------------------------------------------------------------------------   
  AT_NUMBER_PERCENTAGE = true
  #---------------------------------------------------------------------------
  # 是否显示数字动画效果 ("滚动").
  #---------------------------------------------------------------------------  
  AT_NUMBER_ANIMATION = false
  #---------------------------------------------------------------------------
  # 是否使用 AT 条图片.
  # 需要图片.
  #
  # AT_Meter.png
  #  
  #---------------------------------------------------------------------------  
  AT_METER_VISIBLE = true
  #---------------------------------------------------------------------------
  # 设定AT条的Z坐标.
  #---------------------------------------------------------------------------   
  AT_METER_Z = 1
  #---------------------------------------------------------------------------
  # 设定AT条的位置. [X,Y]
  #---------------------------------------------------------------------------  
  AT_METER_POSITION = [38,76]
  #---------------------------------------------------------------------------
  # AT条的倾角.
  #---------------------------------------------------------------------------  
  AT_METER_ANGLE = 0
  #---------------------------------------------------------------------------
  # 是否显示AT条的镜像效果
  #---------------------------------------------------------------------------  
  AT_METER_MIRROR_EFFECT = false
  #---------------------------------------------------------------------------
  #是否使用AT条的动画流动效果,需要一张宽度为正常大小三倍的图片,图片需要有颜色
  #梯度变化来表现"流动"的效果。
  #设定为false则显示普通效果.
  #---------------------------------------------------------------------------  
  AT_METER_GRADIENT_ANIMATION = true
  #============================================================================
  
  
  #============================================================================
  #============================================================================
  # * LEVEL
  #============================================================================
  # 是否显示等级数字图片
  # 需要图片
  #
  # LV_Number.png
  #   
  #---------------------------------------------------------------------------
  LEVEL_NUMBER_VISIBLE = false
  #---------------------------------------------------------------------------
  # 等级数字的Z坐标
  #---------------------------------------------------------------------------   
  LEVEL_NUMBER_Z = 2
  #---------------------------------------------------------------------------
  # 等级数字的位置. [X,Y]
  #---------------------------------------------------------------------------  
  LEVEL_NUMBER_POSITION = [84,0]
  #---------------------------------------------------------------------------
  # 设定数字对齐方式.
  #
  # 0 - 左
  # 1 - 中
  # 2 - 右
  #---------------------------------------------------------------------------  
  LEVEL_NUMBER_ALIGN_TYPE = 1     
  #============================================================================
  #============================================================================
  
  
  #============================================================================
  #============================================================================
  # * 状态
  #============================================================================
  # 是否显示状态图标
  #---------------------------------------------------------------------------  
  STATES_VISIBLE = true
  #---------------------------------------------------------------------------
  # 状态精灵Z坐标
  #---------------------------------------------------------------------------   
  STATES_Z = 1
  #---------------------------------------------------------------------------
  # 状态位置. [X,Y]
  #---------------------------------------------------------------------------  
  STATES_POSITION = [7,65]
  #---------------------------------------------------------------------------
  # 是否显示状态滚动动画.
  #---------------------------------------------------------------------------  
  STATES_SCROLLING_ANIMATION = false
  #---------------------------------------------------------------------------
  # 状态倾角.
  #---------------------------------------------------------------------------   
  STATE_ANGLE = 0
  #---------------------------------------------------------------------------
  # 不在hud中显示状态图标的状态.
  # 例子 - HIDE_STATES_ID = [9,10,12,14]
  #---------------------------------------------------------------------------   
  HIDE_STATES_ID = []
  #============================================================================
  #============================================================================

  #============================================================================
  #============================================================================
  # * 第二图层 (Overlayer)
  #============================================================================  
  # 是否显示第二图层图片
  # 需要图片
  #
  # Layout_2.png
  #
  #============================================================================  
  SECOND_LAYOUT = false
  #---------------------------------------------------------------------------
  # 第二图层的Z坐标
  #---------------------------------------------------------------------------  
  SECOND_LAYOUT_Z = 4
  #---------------------------------------------------------------------------
  # 第二图层的位置
  #---------------------------------------------------------------------------   
  SECOND_LAYOUT_POSITION = [-5,-10]
  #============================================================================
  #============================================================================
   
  #============================================================================
  #============================================================================
  # * 画面图片
  #============================================================================  
  # 在画面上显示一张图片.
  # 需要图片:
  #
  # Layout_Screen.png
  #
  #============================================================================  
  #是否显示画面图片
  SCREEN_LAYOUT = false
  #---------------------------------------------------------------------------
  #画面图片的位置
  #---------------------------------------------------------------------------
  SCREEN_LAYOUT_POSITION = [0,0]
  #---------------------------------------------------------------------------
  #画面图片的Z坐标
  #---------------------------------------------------------------------------
  SCREEN_LAYOUT_Z = -2   
  
end

#============================================================================
#============================================================================
# * 自定义窗口 (通用)
#============================================================================
module MOG_BATTLE_HUD_EX
  
#============================================================================
# * 是否启用自定义窗口
#============================================================================
  ENABLE_CUSTOM_WINDOWS = true
  
#============================================================================
# * 战斗日志窗口
#============================================================================
# 修改战斗日志窗口的位置
  BATTLE_LOG_POSITION = [0,0]
#============================================================================
  
#============================================================================
# * 字体设定
#============================================================================
#是否启用窗口字体
ENABLE_WINDOW_FONT_SET = false
#窗口字体名
WINDOW_FONT_NAME = nil
#窗口字体大小
WINDOW_FONT_SIZE = 18
#窗口字体是否加粗
WINDOW_FONT_BOLD = true
#窗口字体是否斜体
WINDOW_FONT_ITALIC = false
  
#============================================================================
# * 技能窗口
#============================================================================
#技能窗口大小
  SKILL_WINDOW_SIZE = [Graphics.width, 120]
#技能窗口位置.
  SKILL_WINDOW_POSITION = [0,0]
#技能窗口不透明度
  SKILL_WINDOW_OPACITY = 0
#是否显示技能窗口的图片. ("Layout_Skill.png")
  SKILL_WINDOW_LAYOUT = true
#技能窗口图片的位置
  SKILL_WINDOW_LAYOUT_POSITION = [0,-7]
#Definição da quantidade colunas máxima.
  SKILL_COL_MAX = 2
  #是否显示技能窗口的滑动效果
  SKILL_WINDOW_SLIDE_EFFECT = false
  #技能窗口的滑动位置
  SKILL_WINDOW_SLIDE_POSITION = [150,150]   
#============================================================================
  
#============================================================================
# * 物品窗口
#============================================================================
#物品窗口大小.  
  ITEM_WINDOW_SIZE = [Graphics.width, 120]
#物品窗口的位置.
  ITEM_WINDOW_POSITION = [0,0]
#物品窗口不透明度
  ITEM_WINDOW_OPACITY = 0
#是否显示物品窗口的图片. ("Layout_Item.png")   
  ITEM_WINDOW_LAYOUT = true
#物品窗口图片的位置.  
  ITEM_WINDOW_LAYOUT_POSITION = [0,-7]   
#
  ITEM_COL_MAX = 2
  #是否显示物品窗口的滑动效果
  ITEM_WINDOW_SLIDE_EFFECT = false
  #物品窗口的滑动位置
  ITEM_WINDOW_SLIDE_POSITION = [150,150]   
#============================================================================

#============================================================================
# * 角色指令窗口(攻击/防御等)
#============================================================================
#是否自动调整指令窗口
  AUTO_ADJUST_ACTOR_COMMAND = true
#指令窗口的位置
  ACTOR_COMMAND_POSITION = [0,-50]
#指令窗口不透明度
  ACTOR_COMMAND_OPACITY = 0
#是否使用指令窗口的图片. ("Layout_Command.png")   
  ACTOR_COMMAND_LAYOUT = true
#指令窗口图片的位置.   
  ACTOR_COMMAND_LAYOUT_POSITION = [0,0]
#============================================================================

#============================================================================
# * 帮助窗口
#============================================================================
#帮助窗口的大小.   
  HELP_WINDOW_SIZE = [Graphics.width, 72]
#帮助窗口的位置.
  HELP_WINDOW_POSITION = [Graphics.width / 2, 0]  
#帮助窗口不透明度
  HELP_WINDOW_OPACITY = 0
#是否显示帮助窗口的图片. ("Layout_Help.png")   
  HELP_WINDOW_LAYOUT = true
#帮助窗口图片的位置.
  HELP_WINDOW_LAYOUT_POSITION = [0,0]
  #是否显示帮助窗口的滑动效果
  HELP_WINDOW_SLIDE_EFFECT = false
  #帮助窗口的滑动位置
  HELP_WINDOW_SLIDE_POSITION = [0,-150]   
#============================================================================

#============================================================================
# * 目标角色窗口
#============================================================================
#角色窗口的大小.   
  ACTOR_WINDOW_SIZE = [Graphics.width, 120]  
#角色窗口的位置.
  ACTOR_WINDOW_POSITION = [Graphics.width / 2, Graphics.height]
#角色窗口不透明度.  
  ACTOR_WINDOW_OPACITY = 0
#是否显示角色窗口的图片. ("Layout_Target_Actor.png")
  ACTOR_WINDOW_LAYOUT = true
#角色窗口图片的位置.
  ACTOR_WINDOW_LAYOUT_POSITION = [0,0]
  #是否显示角色窗口的滑动效果
  ACTOR_WINDOW_SLIDE_EFFECT = false
  #角色窗口的滑动位置
  ACTOR_WINDOW_SLIDE_POSITION = [0,100]  
#============================================================================

#============================================================================
# * 目标敌人窗口
#============================================================================
#敌人窗口的大小.
  ENEMY_WINDOW_SIZE = [Graphics.width, 120]
#敌人窗口的位置  
  ENEMY_WINDOW_POSITION = [Graphics.width / 2, Graphics.height]
#敌人窗口不透明度.   
  ENEMY_WINDOW_OPACITY = 0
#是否显示敌人窗口的图片. ("Layout_Target_Actor.png")
  ENEMY_WINDOW_LAYOUT = true
#敌人窗口图片的位置.
  ENEMY_WINDOW_LAYOUT_POSITION = [0,0]
  #是否显示敌人窗口的滑动效果
  ENEMY_WINDOW_SLIDE_EFFECT = false
  #敌人窗口的滑动位置
  ENEMY_WINDOW_SLIDE_POSITION = [0,100]      
#============================================================================

#============================================================================
# * 队伍窗口 (战斗/撤退)
#============================================================================
#队伍窗口位置  
  PARTY_COMMAND_POSITION = [Graphics.width / 2,Graphics.height / 2]
#队伍窗口不透明度   
  PARTY_COMMAND_OPACITY = 0
#是否显示队伍窗口的图片 ("Layout_Party.png")  
  PARTY_COMMAND_LAYOUT = true
#队伍窗口图片的位置  
  PARTY_COMMAND_LAYOUT_POSITION = [0,0]
  #是否显示队伍窗口的滑动效果
  PARTY_COMMAND_SLIDE_EFFECT = false
  #队伍窗口的滑动位置
  PARTY_COMMAND_SLIDE_POSITION = [0,-150]     
#============================================================================

end

#==============================================================================
# ** 核心
#==============================================================================
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]
      @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      
      else
         @ani_sprites.each_with_index do |sprite, i|
         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
      @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
      @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[/pre]

[pre lang="ruby"]#==============================================================================
# +++ MOG - 伤害显示  (v4.5) +++
#==============================================================================
# By Moghunter
# https://atelierrgss.wordpress.com/
#==============================================================================
# 用图片显示伤害数字.
#==============================================================================
# 需要以下图片
#
# Critical
# Evaded
# Exp
# Gold
# Level Up
# Missed
# MP
# Number
# TP
#
# 全部放在 /GRAPHICS/DAMAGE/
#==============================================================================

#==============================================================================
# 行走图上显示伤害数字 (事件)
#==============================================================================
# 如果你想要在地图上或战斗中手动显示伤害数字,使用以下脚本:
#
# damage_popup(目标ID,数值,"类型")
#
# 目标ID
#      1...999    - 地图上的事件ID
#      0          - 玩家
#      -1...-3    - 队友
#
# 数值
#       显示伤害的数值(可以是负值)或文本.当类型为"States"时为状态的ID,不能为负值
#
# 类型 (可选)
#      "Exp" - 显示EXP.
#      "Gold" - 显示金币.
#      "States" - 显示状态图标.
#
#==============================================================================
#
# damage_popup(1,999)
# damage_popup(4,"存档点.")
# damage_popup(0,"我饿了!!!")     <- 玩家
# damage_popup(-1,"Booo!")        <- 1号队友(离玩家最近的队友,不是ID=1的队友)
# damage_popup(0,2000,"Exp")      <- 显示 2000 Exp
# damage_popup(0,5000,"Gold")     <- 显示 5000 金币
#
#==============================================================================
# 使用以下脚本来在全部队友的头顶显示伤害数字.:
#
# damage_popup_party(目标ID,数值,"类型")
#
#==============================================================================
# 地图上显示/不显示伤害数字.
#==============================================================================
# 使用以下脚本来在地图上显示/不显示伤害数字:
#
# damage_popup_map(true)        -> 或 (false)
#  
#==============================================================================
# ● Histórico (Version History)
#==============================================================================
# v 4.5 - Correção de ativar o dano quando o alvo é morto e o dano é zero.
#==============================================================================

$imported = {} if $imported.nil?
$imported[:mog_damage_popup] = true

module MOG_DAMAGEPOPUP
  #是否允许在地图上显示伤害数字. (默认)
  DAMAGE_POPUP_MAP = false
  #是否在获得物品时显示该物品图标. (仅在地图上).
  ITEM_POPUP_MAP = true
  #是否允许在敌人身上显示EXP和金币.
  EXP_GOLD_POPUP_BATTLE = true
  EXP_GOLD_POPUP_MAP = true
  #是否显示升级
  LEVEL_POPUP_BATTLE = true
  LEVEL_POPUP_MAP = true
  #是否显示状态图标
  STATES_POPUP_BATTLE = true
  STATES_POPUP_MAP = true
  #设定字体 (物品名/状态名/ etc...).
  FONT_SIZE = 28
  FONT_BOLD = true
  FONT_ITALIC = false
  FONT_COLOR = Color.new(255,255,255)
  FONT_COLOR_ITEM = Color.new(255,255,255)
  FONT_COLOR_STATUS_PLUS = Color.new(155,155,255)
  FONT_COLOR_STATUS_MINUS = Color.new(255,150,150)
  #每条伤害间的距离(竖直距离).
  Y_SPACE = 28
  #伤害数字的Z坐标
  DAMAGE_Z = 151
end

#==============================================================================
# ■ Game_System
#==============================================================================
class Game_System
  attr_accessor :damage_popup_map
  
  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------         
  alias mog_damage_popup_initialize initialize
  def initialize
      @damage_popup_map = MOG_DAMAGEPOPUP::DAMAGE_POPUP_MAP
      mog_damage_popup_initialize
  end
  
  #--------------------------------------------------------------------------
  # ● Damage Popup Clear
  #--------------------------------------------------------------------------         
  def damage_popup_clear
      $game_party.character_members.each {|t|
      t.actor.damage.clear; t.actor.skip_dmg_popup = false ;
      t.damage.clear; t.skip_dmg_popup = false} rescue nil
      $game_map.events.values.each {|t| t.damage.clear ;
      t.skip_dmg_popup = false} rescue nil
  end
  
end  

#==============================================================================
# ■ Game Temp
#==============================================================================
class Game_Temp
  
  attr_accessor :battle_end

  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------   
  alias mog_damage_temp_opup_initialize initialize
  def initialize
      @battle_end = false
      mog_damage_temp_opup_initialize
  end
  
  #--------------------------------------------------------------------------
  # ● Sprite Visible
  #--------------------------------------------------------------------------   
  def sprite_visible
      return false if $game_message.visible
      return false if $game_temp.battle_end
      return true
  end
   
end
#==============================================================================
# ■ Game CharacterBase
#==============================================================================
class Game_CharacterBase
  
  attr_accessor :damage ,:battler ,:skip_dmg_popup
  
  #--------------------------------------------------------------------------
  # ● Ini Public Members
  #--------------------------------------------------------------------------         
  alias mog_damage_popup_init_public_members init_public_members
  def init_public_members
      @damage = [] ; @skip_dmg_popup = false
      mog_damage_popup_init_public_members
  end
  
  #--------------------------------------------------------------------------
  # ● Damage Popup
  #--------------------------------------------------------------------------         
  def damage_popup(value,type = "String")      
      @damage.push([value,type])
  end  
  
end

#==============================================================================
# ■ Scene Map
#==============================================================================
class Scene_Map < Scene_Base  
  #--------------------------------------------------------------------------
  # ● Start
  #--------------------------------------------------------------------------
  alias mog_damage_popup_start start
  def start
      $game_system.damage_popup_clear ; $game_temp.battle_end = false
      mog_damage_popup_start
  end  
end

#==============================================================================
# ■ Game Player
#==============================================================================
class Game_Player < Game_Character   
  #--------------------------------------------------------------------------
  # ● Battler
  #--------------------------------------------------------------------------
  def battler
      actor
  end   
end

#==============================================================================
# ■ Game Follower
#==============================================================================
class Game_Follower < Game_Character  
  #--------------------------------------------------------------------------
  # ● Battler
  #--------------------------------------------------------------------------
  def battler
      actor
  end   
end

#==============================================================================
# ■ Game_BattlerBase
#==============================================================================
class Game_BattlerBase  
  #--------------------------------------------------------------------------
  # ● Change HP
  #--------------------------------------------------------------------------         
  alias mog_damage_popup_change_hp change_hp
  def change_hp(value, enable_death)
      mog_damage_popup_change_hp(value, enable_death)
      self.damage.push([-value,"Hp"])
  end   
end

#==============================================================================
# ■ Game_Battler
#==============================================================================
class Game_Battler < Game_BattlerBase  
  include MOG_DAMAGEPOPUP
  attr_accessor :damage , :skip_dmg_popup
  
  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------         
  alias mog_damage_sprite_initialize initialize
  def initialize      
      @damage = [] ; @skip_dmg_popup = false
      mog_damage_sprite_initialize
  end  
   
  #--------------------------------------------------------------------------
  # ● Item Apply
  #--------------------------------------------------------------------------  
   alias mog_damage_pop_item_apply item_apply
   def item_apply(user, item)
       mog_damage_pop_item_apply(user, item)
       execute_damage_popup(user,item)
  end
  
  #--------------------------------------------------------------------------
  # ● Execute Damage Popup
  #--------------------------------------------------------------------------
  def execute_damage_popup(user,item)
      if !@result.missed and !@result.evaded and @result.hit?
        self.damage.push([@result.hp_damage,"HP",@result.critical]) if item.damage.to_hp? or @result.hp_damage != 0
        user.damage.push([-@result.hp_drain,"HP",@result.critical]) if item.damage.type == 5
        self.damage.push([@result.mp_damage,"MP",@result.critical]) if item.damage.to_mp? or @result.mp_damage != 0
        user.damage.push([-@result.mp_drain,"MP",@result.critical]) if item.damage.type == 6
        self.damage.push([@result.tp_damage,"TP",@result.critical]) if @result.tp_damage != 0
     elsif !self.dead?
        if @result.missed ; self.damage.push(["Missed","Missed"])
        elsif @result.evaded ; self.damage.push(["Evaded","Evaded"])
        end        
      end
  end
     
  #--------------------------------------------------------------------------
  # ● Regenerate HP
  #--------------------------------------------------------------------------
  alias mog_damage_pop_regenerate_hp regenerate_hp
  def regenerate_hp
      mog_damage_pop_regenerate_hp
      self.damage.push(["Regenerate",""]) if @result.hp_damage < 0  
      self.damage.push([@result.hp_damage,"HP"]) if @result.hp_damage != 0
  end

  #--------------------------------------------------------------------------
  # ● Regenerate MP
  #--------------------------------------------------------------------------
  alias mog_damage_pop_regenerate_mp regenerate_mp
  def regenerate_mp
      mog_damage_pop_regenerate_mp
      self.damage.push([@result.mp_damage,"MP"]) if @result.mp_damage != 0
  end
  
  #--------------------------------------------------------------------------
  # ● Regenerate TP
  #--------------------------------------------------------------------------
  alias mog_damage_pop_regenerate_tp regenerate_tp
  def regenerate_tp
      mog_damage_pop_regenerate_tp
      tp_damage = 100 * trg
      self.damage.push([tp_damage,"TP"]) if tp_damage != 0
  end

  #--------------------------------------------------------------------------
  # ● Added New State
  #--------------------------------------------------------------------------  
  alias mog_damage_pop_add_new_state add_new_state
  def add_new_state(state_id)
      mog_damage_pop_add_new_state(state_id)
      execute_popup_add_new_state(state_id)
  end
   
  #--------------------------------------------------------------------------
  # ● Execute Popup Add New State
  #--------------------------------------------------------------------------  
def execute_popup_add_new_state(state_id)
      st = $data_states[state_id]
      if self.hp > 0
         unless (SceneManager.scene_is?(Scene_Battle) and !STATES_POPUP_BATTLE) or
                (SceneManager.scene_is?(Scene_Map) and !STATES_POPUP_MAP)
                self.damage.push([st.name.to_s,"States Plus",false,st.icon_index])
         end
      end
  end
  
  #--------------------------------------------------------------------------
  # ● Remove State
  #--------------------------------------------------------------------------  
  alias mog_damage_pop_remove_state remove_state
  def remove_state(state_id)
      execute_popup_remove_state(state_id)  
      mog_damage_pop_remove_state(state_id)
  end      
  
  #--------------------------------------------------------------------------
  # ● Execute Popup Remove State
  #--------------------------------------------------------------------------  
  def execute_popup_remove_state(state_id)  
      if state?(state_id) and self.hp > 0
         st = $data_states[state_id]
         unless (SceneManager.scene_is?(Scene_Battle) and !STATES_POPUP_BATTLE) or
                (SceneManager.scene_is?(Scene_Map) and !STATES_POPUP_MAP)
                self.damage.push([st.name.to_s,"States Minus",false,st.icon_index]) unless BattleManager.escape?
         end
      end
  end     

end

#==============================================================================
# ■ BattleManager
#==============================================================================
module BattleManager
  #--------------------------------------------------------------------------
  # ● Escape?
  #--------------------------------------------------------------------------
  def self.escape?
      @phase == nil
  end  
end

#==============================================================================
# ■ Game_Temp
#==============================================================================
class Game_Temp
  attr_accessor :dmg_battle_mode
  
  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------         
  alias mog_damage_popup_initialize initialize
  def initialize
      @dmg_battle_mode = false
      mog_damage_popup_initialize
  end
  
end

#==============================================================================
# ■ Scene Battle
#==============================================================================
class Scene_Battle < Scene_Base

  #--------------------------------------------------------------------------
  # ● Start
  #--------------------------------------------------------------------------         
  alias mog_damage_popup_start start
  def start
      $game_temp.dmg_battle_mode = true
      mog_damage_popup_start
  end
   
  #--------------------------------------------------------------------------
  # ● Terminate
  #--------------------------------------------------------------------------         
  alias mog_damage_popup_terminate terminate
  def terminate
      mog_damage_popup_terminate
      $game_temp.dmg_battle_mode = false
  end
  
end

#==============================================================================
# ■ Game Party
#==============================================================================
class Game_Party < Game_Unit

  #--------------------------------------------------------------------------
  # ● Character Members
  #--------------------------------------------------------------------------         
  def character_members
      char_m = [] ; char_m.push($game_player)
      $game_player.followers.each do |f| char_m.push(f) end
      return char_m
  end
  
  #--------------------------------------------------------------------------
  # ● Gain Gold
  #--------------------------------------------------------------------------         
  alias mog_damage_popup_gain_gold gain_gold
  def gain_gold(amount)
      mog_damage_popup_gain_gold(amount)
      $game_party.members[0].damage.push([amount,"Gold"]) if can_damage_popup_gold?
  end  
  
  #--------------------------------------------------------------------------
  # ● Can Damage Popup Gold
  #--------------------------------------------------------------------------         
  def can_damage_popup_gold?
      return false if !SceneManager.scene_is?(Scene_Map)
      return false if $game_temp.dmg_battle_mode
      return false if !MOG_DAMAGEPOPUP::EXP_GOLD_POPUP_MAP
      return false if !$game_system.damage_popup_map
      return false if !$game_party.members[0]
      return true
  end
  
#--------------------------------------------------------------------------
# ● Gain Item
#--------------------------------------------------------------------------
alias mog_damage_popup_gain_item gain_item
def gain_item(item, amount, include_equip = false)
     mog_damage_popup_gain_item(item, amount, include_equip)
     execute_item_popup(item) if can_damage_popup_item?(item)
end
  
#--------------------------------------------------------------------------
# ● Can Damage Poupup Item
#--------------------------------------------------------------------------
def can_damage_popup_item?(item)
     return false if item == nil
     return false if !MOG_DAMAGEPOPUP::ITEM_POPUP_MAP
     return false if !$game_system.damage_popup_map
     return false if SceneManager.scene_is?(Scene_Battle)
     return false if !$game_party.members[0]
     return false if $game_temp.dmg_battle_mode
     return true     
end

#--------------------------------------------------------------------------
# ● Execute Item Popup
#--------------------------------------------------------------------------
def execute_item_popup(item)
     it = $data_items[item.id] if item.is_a?(RPG::Item)
     it = $data_weapons[item.id] if item.is_a?(RPG::Weapon)
     it = $data_armors[item.id] if item.is_a?(RPG::Armor)   
     $game_party.members[0].damage.push([it.name.to_s,"Item",false,it.icon_index])
end

end

#==============================================================================
# ■ Game Interpreter
#==============================================================================
class Game_Interpreter

#--------------------------------------------------------------------------
# ● Damage Popup Map
#--------------------------------------------------------------------------
  def damage_popup_map(value)
      $game_system.damage_popup_map = value
  end   
  
  #--------------------------------------------------------------------------
  # ● Damage Popup
  #--------------------------------------------------------------------------
  def damage_popup(target_id, value,type = "")
      return if !$game_system.damage_popup_map
      target = set_target_dmg(target_id) rescue nil
      target.damage.push([value,type]) if target
  end
  
  #--------------------------------------------------------------------------
  # ● Set Target Dmg
  #--------------------------------------------------------------------------
  def set_target_dmg(target)
      return $game_player.battler if target == 0
      return $game_player.followers.battler[(target_id + 1).abs] if target < 0
      $game_map.events.values.each do |event|
      return event.battler if event.id == target_id and event.battler
      return event if event.id == target_id
      end
  end
  
  #--------------------------------------------------------------------------
  # * Change MP
  #--------------------------------------------------------------------------
  alias mog_damage_popup_command_312 command_312
  def command_312
      value = operate_value(@params[2], @params[3], @params[4])
      iterate_actor_var(@params[0], @params[1]) do |actor|
      actor.damage.push([-value,"MP"])
      end   
      mog_damage_popup_command_312
  end  
  
end

#==============================================================================
# ■ Game Actor
#==============================================================================
class Game_Actor < Game_Battler
  include MOG_DAMAGEPOPUP
  #--------------------------------------------------------------------------
  # ● Level UP
  #--------------------------------------------------------------------------         
   alias mog_damage_pop_level_up level_up
   def level_up
       mog_damage_pop_level_up      
       execute_level_popup
   end

  #--------------------------------------------------------------------------
  # ● Execute Level Popup
  #--------------------------------------------------------------------------         
   def execute_level_popup
       if (SceneManager.scene_is?(Scene_Battle) and LEVEL_POPUP_BATTLE) or
          (SceneManager.scene_is?(Scene_Map) and LEVEL_POPUP_MAP)
          @damage.push(["Level UP","Level_UP"]) unless @skip_dmg_popup
          @skip_dmg_popup = true
       end     
   end
     
  #--------------------------------------------------------------------------
  # ● Change Exp
  #--------------------------------------------------------------------------         
  alias mog_damage_popup_change_exp change_exp
  def change_exp(exp, show)
      n_exp = self.exp
      mog_damage_popup_change_exp(exp, show)
      c_exp = n_exp - self.exp
      @damage.push([c_exp.abs,"Exp"]) if can_popup_exp?(exp)
  end   
   
  #--------------------------------------------------------------------------
  # ● Can Popup EXP
  #--------------------------------------------------------------------------         
  def can_popup_exp?(exp)
      return false if !EXP_GOLD_POPUP_MAP
      return false if exp <= 0
      return false if self.skip_dmg_popup
      return false if self.max_level?
      return true
  end
  
end

#==============================================================================
# ■ Scene_Battle
#==============================================================================
class Scene_Battle < Scene_Base
  
  #--------------------------------------------------------------------------
  # ● Invoke Counter Attack
  #--------------------------------------------------------------------------        
  alias mog_damage_popup_invoke_counter_attack invoke_counter_attack
  def invoke_counter_attack(target, item)
      mog_damage_popup_invoke_counter_attack(target, item)
      target.damage.push(["Counter","Counter"])
  end  
  
  #--------------------------------------------------------------------------
  # ● Invoke Counter Attack
  #--------------------------------------------------------------------------        
  alias mog_damage_popup_invoke_magic_reflection invoke_magic_reflection
  def invoke_magic_reflection(target, item)
      mog_damage_popup_invoke_magic_reflection(target, item)
      target.damage.push(["Reflection","Reflection"])
  end  
  
end

#==============================================================================
# ■ Cache
#==============================================================================
module Cache

  #--------------------------------------------------------------------------
  # * Damage
  #--------------------------------------------------------------------------
  def self.damage(filename)
      load_bitmap("Graphics/Damage/", filename)
  end

end

#==============================================================================
# ■ Game Temp
#==============================================================================
class Game_Temp
  
  attr_accessor :pre_cache_damage
  
  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------  
  alias mog_damage_pop_initialize initialize
  def initialize
      mog_damage_pop_initialize
      pre_cache_damage_temp
  end
  
  #--------------------------------------------------------------------------
  # ● Pre Cache Damage Temp
  #--------------------------------------------------------------------------   
  def pre_cache_damage_temp
      return if @pre_cache_damage != nil
      @pre_cache_damage = []
      @pre_cache_damage.push(Cache.damage("HP_Number"))
      @pre_cache_damage.push(Cache.damage("MP"))
      @pre_cache_damage.push(Cache.damage("TP"))
      @pre_cache_damage.push(Cache.damage("Missed"))
      @pre_cache_damage.push(Cache.damage("Evaded"))
      @pre_cache_damage.push(Cache.damage("Critical"))
      @pre_cache_damage.push(Cache.damage("Exp"))
      @pre_cache_damage.push(Cache.damage("Gold"))
      @pre_cache_damage.push(Cache.damage("Level UP"))
      @pre_cache_damage.push(Cache.damage("Counter"))
      @pre_cache_damage.push(Cache.damage("Reflection"))
      @pre_cache_damage.push(Cache.damage("MP_Number"))
      @pre_cache_damage.push(Cache.damage("TP_Number"))
      @pre_cache_damage.push(Cache.damage("EG_Number"))
      @pre_cache_damage.push(Cache.system("Iconset"))
  end
  
end

#==============================================================================
# ■ Sprite Base
#==============================================================================
class Sprite_Base < Sprite

  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------  
  alias mog_damage_popup_sprite_initialize initialize
  def initialize(viewport = nil)
      mog_damage_popup_sprite_initialize(viewport)
      damage_popup_setup
  end

  #--------------------------------------------------------------------------
  # ● Damage Popup Setup
  #--------------------------------------------------------------------------  
  def damage_popup_setup      
      $game_temp.pre_cache_damage_temp ; @damage_sprites = []
      $game_system.damage_popup_clear
  end

  #--------------------------------------------------------------------------
  # ● Dispose
  #--------------------------------------------------------------------------  
  alias mog_damage_popup_sprite_dispose dispose
  def dispose      
      mog_damage_popup_sprite_dispose
      dispose_damage_sprites
  end
  
  #--------------------------------------------------------------------------
  # ● Dispose Damage Sprites
  #--------------------------------------------------------------------------   
  def dispose_damage_sprites
      return if @damage_sprites == nil
      @damage_sprites.each {|sprite| sprite.dispose_damage }
  end  
  
  #--------------------------------------------------------------------------
  # ● Update
  #--------------------------------------------------------------------------  
  alias mog_damage_popup_sprite_update update
  def update
      mog_damage_popup_sprite_update
      update_damage_popup
  end  
  
  #--------------------------------------------------------------------------
  # ● Update Damage Popup
  #--------------------------------------------------------------------------   
  def update_damage_popup
      return if @damage_sprites == nil
      create_damage_sprite if can_create_damage?
      update_damage_sprite if !@damage_sprites.empty?
  end  
  
  #--------------------------------------------------------------------------
  # ● Can Create Damage?
  #--------------------------------------------------------------------------     
  def can_create_damage?      
      return false if $game_message.visible
      if @battler
         return false if @battler.damage == nil
         return false if @battler.damage.empty?
         if $game_temp.battle_end and @battler.is_a?(Game_Actor)
            return false if $game_message.visible
            return false if $imported[:mog_battler_result] and $game_temp.result
         end
      elsif @character
         return false if !$game_system.damage_popup_map
         if @character.battler
            return false if @character.battler.damage == nil
            return false if @character.battler.damage.empty?
         else
            return false if @character.damage == nil
            return false if @character.damage.empty?            
         end  
      end
      return false if @battler == nil and @character == nil      
      return true
  end
  
  #--------------------------------------------------------------------------
  # ● Create Damage Sprite
  #--------------------------------------------------------------------------     
  def create_damage_sprite
      target = @battler ? @battler : @character
      screen_x_available = target.screen_x rescue nil
      return if screen_x_available == nil
      sx = target.screen_x != nil ? target.screen_x : self.x
      sy = target.screen_y != nil ? target.screen_y : self.y
      @damage_sprites = [] if @damage_sprites == nil  
      target = @character.battler if @character and @character.battler
      target.damage.each_with_index do |i, index|
      @damage_sprites.push(Damage_Sprite.new(nil,sx,sy,i,index,@damage_sprites.size,self)) end
      if SceneManager.scene_is?(Scene_Battle)
      @damage_sprites.each_with_index do |i, index| i.set_duration(index) end
      end
      target.damage.clear ; target.skip_dmg_popup = false
  end  
  
  #--------------------------------------------------------------------------
  # ● Update Damage Sprite
  #--------------------------------------------------------------------------     
  def update_damage_sprite
      clear = true
      @damage_sprites.each_with_index do |sprite, i|
          sprite.update_damage(@damage_sprites.size,i,@battler)
          sprite.dispose_damage if sprite.duration <= 0
          clear = false if sprite.duration > 0
      end   
      @damage_sprites.clear if clear
  end  
  
end

#==============================================================================
# ■ Damage Sprite
#==============================================================================
class Damage_Sprite < Sprite
   include MOG_DAMAGEPOPUP
   attr_accessor :duration
  
  #--------------------------------------------------------------------------
  # ● Initialize
  #--------------------------------------------------------------------------      
  def initialize(viewport = nil , x,y, value ,index,index_max,target)
      super(viewport)
      dispose_damage ; setup_base(value,x,y,index,index_max,target) ; create_sprites
  end   
     
  #--------------------------------------------------------------------------
  # ● Setup Base
  #--------------------------------------------------------------------------      
  def setup_base(value,x,y,index,index_max,target)
      @target = target ; y2 = 0
      if @target.bitmap != nil ; y2 = SceneManager.scene_is?(Scene_Battle) ? @target.bitmap.height / 2 : 0 ; end
      @animation_type = 0 ; @index = index ; @index_max = index_max + 1
      @image = $game_temp.pre_cache_damage ; self.z = index + DAMAGE_Z
      @cw = @image[0].width / 10 ; @ch = @image[0].height / 2 ; @cw2 = 0
      @x = x ; @y = y - y2 ; @value = value[0] ; @type = value[1] ; @ch2 = 0
      @critical = (value[2] and @value.to_i >= 0) ? true : false; self.opacity = 0
      @state_index = value[3] ; @oxy = [0,0,0,0] ; @org_xy = [0,0] ; @spxy = [0,0]
      @duration = 92 ; @org_oxy = [0,0,0,0]
      self.visible = false ;set_initial_position(index,nil)
  end
  
  #--------------------------------------------------------------------------
  # ● Set Duration
  #--------------------------------------------------------------------------      
  def set_duration(index,pre_index = nil)
      return if @duration != 0
      @duration = 82 + (2 * index) if @animation_type == 0
  end
  
  #--------------------------------------------------------------------------
  # ● Set Initial Position
  #--------------------------------------------------------------------------      
  def set_initial_position(index,old_duration)
      @org_xy = [@x,@y]
      self.zoom_y = self.zoom_x
  end
  
  #--------------------------------------------------------------------------
  # ● Dispose Damage
  #--------------------------------------------------------------------------      
  def dispose_damage
      (self.bitmap.dispose ; self.bitmap = nil) if self.bitmap
      (@sup_sprite.bitmap.dispose ; @sup_sprite.dispose) if @sup_sprite  
      @duration = -1
  end
  
  #--------------------------------------------------------------------------
  # ● Create Sprites
  #--------------------------------------------------------------------------      
  def create_sprites
      if @value.is_a?(Numeric)
         create_number         
      elsif ["Missed","Evaded","Level UP","Counter","Reflection"].include?(@value.to_s)
         create_miss
      else
         create_string
      end      
      set_damage_position
  end
  
  #--------------------------------------------------------------------------
  # ● Set Damage Position
  #--------------------------------------------------------------------------      
  def set_damage_position
      return if self.bitmap == nil
      self.ox = (self.bitmap.width - @cw2) / 2
      self.oy = self.bitmap.height / 2 ; self.x = @x ; self.y = @y
      @org_oxy[0] = self.ox
      @org_oxy[1] = self.oy
      set_animation_type
      if @sup_sprite
         @sup_sprite.ox = self.bitmap.width / 2 ;
         @sup_sprite.oy = self.bitmap.height / 2
         @org_oxy[2] = @sup_sprite.ox
         @org_oxy[3] = @sup_sprite.oy
         if @critical
            @sup_sprite.x = @x - (@sup_sprite.bitmap.width / 2) + ((@cw / 2) * @number_value.size)
            @sup_sprite.y = self.y
         end   
         update_sup_position(@index_max - @index)
      end
  end   
  
  #--------------------------------------------------------------------------
  # ● Set Damage Position
  #--------------------------------------------------------------------------      
  def set_animation_type
      s = rand(2) ; s2 = (rand(10) * 0.1).round(2)
      @oxy[2] = s == 1 ? s2 : -s2
  end
  
  #--------------------------------------------------------------------------
  # ● Create Number
  #--------------------------------------------------------------------------      
  def create_number
      case @type
      when "MP"
      number_image = @image[11] ;h = @value >= 0 ? 0 : @ch ; create_sup_sprite
      when "TP"
      number_image = @image[12] ;h = @value >= 0 ? 0 : @ch ; create_sup_sprite
      when "Exp"
      number_image = @image[13] ;h = 0 ; create_sup_sprite
      when "Gold"
      number_image = @image[13] ;h = @ch ; create_sup_sprite            
      else
      number_image = @image[0] ; h = @value >= 0 ? 0 : @ch
      end
      @number_value = @value.abs.truncate.to_s.split(//)
      self.bitmap = Bitmap.new(@cw * @number_value.size, @ch)
      for r in 0...@number_value.size        
          number_value_abs = @number_value[r].to_i
          src_rect = Rect.new(@cw * number_value_abs, h, @cw, @ch)
          self.bitmap.blt(@cw *  r, 0, number_image, src_rect)
      end   
      create_sup_sprite if @critical
  end
  
  #--------------------------------------------------------------------------
  # ● Create Sup Sprite
  #--------------------------------------------------------------------------      
  def create_sup_sprite
      return if @sup_sprite != nil
      @sup_sprite = Sprite.new ; @sup_sprite.visible = false ; fy = 0 ; sp = [0,0]
      if @type == "MP" ; @sup_sprite.bitmap = @image[1].dup
      elsif @type == "TP" ; @sup_sprite.bitmap = @image[2].dup
      elsif @critical
         @sup_sprite.bitmap = @image[5].dup
         @cw2 = 0 ; @ch2 = @sup_sprite.bitmap.height  
         return
      elsif @type == "Exp"
         @sup_sprite.bitmap = @image[6].dup ; fy = @ch ; sp[1] = 1.0
      elsif @type == "Gold"
         @sup_sprite.bitmap = @image[7].dup ; fy = (@ch * 2) ; sp[1] = 0.5
     end  
     fy = 0 if !SceneManager.scene_is?(Scene_Battle)
     @y += fy ; @org_xy[1] += 0
     @cw2 = @sup_sprite.bitmap.width + @cw
     @spxy = [sp[0],sp[1]]
  end

  #--------------------------------------------------------------------------
  # ● Update Sup Position
  #--------------------------------------------------------------------------      
  def update_sup_position(dif_y)
      @sup_sprite.x = self.x - @cw unless @critical
      @sup_sprite.y = @critical ? self.y - @ch2 : self.y
      @sup_sprite.opacity = self.opacity ; @sup_sprite.angle = self.angle
      @sup_sprite.zoom_x = self.zoom_x ; @sup_sprite.zoom_y = self.zoom_y
      @sup_sprite.z = self.z ; @sup_sprite.viewport = self.viewport
      @sup_sprite.visible = self.visible
  end  
  
  #--------------------------------------------------------------------------
  # ● Create Miss
  #--------------------------------------------------------------------------      
  def create_miss
      self.bitmap = @image[3].dup if @value == "Missed"
      self.bitmap = @image[4].dup if @value == "Evaded"
      self.bitmap = @image[8].dup if @value == "Level UP"
      self.bitmap = @image[9].dup if @value == "Counter"
      self.bitmap = @image[10].dup if @value == "Reflection"
  end
  
  #--------------------------------------------------------------------------
  # ● Create Spring
  #--------------------------------------------------------------------------               
  def create_string
      string_size = @value.to_s.split(//) ; fsize = FONT_SIZE > 10 ? FONT_SIZE : 10
      @stg_size = string_size.size > 0 ? ((1 + string_size.size ) * ((fsize / 2) - 2)) : 32      
      self.bitmap = Bitmap.new(@stg_size,32)
      self.bitmap.font.color = FONT_COLOR
      self.bitmap.font.size = fsize ; self.bitmap.font.bold = FONT_BOLD
      self.bitmap.font.italic = FONT_ITALIC
      if @type == "Item"
         self.bitmap.font.color = FONT_COLOR_ITEM
      elsif @type == "States Plus"
         self.bitmap.font.color = FONT_COLOR_STATUS_PLUS
      elsif @type == "States Minus"
         self.bitmap.font.color = FONT_COLOR_STATUS_MINUS
      end      
      self.bitmap.draw_text(0, 0, self.bitmap.width, self.bitmap.height, @value.to_s,0)
      draw_states if @state_index != nil
  end
  
  #--------------------------------------------------------------------------
  # ● Draw States
  #--------------------------------------------------------------------------               
  def draw_states
      @sup_sprite = Sprite.new ; @sup_sprite.bitmap = Bitmap.new(24,24)
      rect = Rect.new(@state_index % 16 * 24, @state_index / 16 * 24, 24, 24)
      @image[14] = Cache.system("Iconset") if @image[14]== nil or @image[14].disposed?
      @sup_sprite.bitmap.blt(0, 0, @image[14].dup, rect)
      (@org_xy[1] += (@ch + 5) ; @y += (@ch + 5)) unless !SceneManager.is_a?(Scene_Battle)
      @cw2 = @sup_sprite.bitmap.width + @cw / 2 ; @sup_sprite.visible = false
  end  
  
  #--------------------------------------------------------------------------
  # ● Update Damage
  #--------------------------------------------------------------------------               
  def update_damage(index_max,index,battler)
      @index_max = index_max ; @index = index
      return if self.bitmap == nil or self.bitmap.disposed?
      @duration -= 1
      self.visible = @duration > 90 ? false : true
      return if !self.visible
      dif_y = (@index_max - @index)
      update_animation(dif_y)
      update_sprite_position(dif_y,battler)
      update_sup_position(dif_y) if @sup_sprite
      dispose_damage if @duration <= 0
  end
  
  #--------------------------------------------------------------------------
  # ● Update Sprite Position
  #--------------------------------------------------------------------------               
  def update_sprite_position(dif_y,battler)
      execute_move(0,self,@org_xy[0] + @oxy[0])
      execute_move(1,self,@org_xy[1] + @oxy[1] - (dif_y * Y_SPACE))
      self.zoom_y = self.zoom_x
      update_battle_camera if oxy_camera?(battler)
  end   
  
  #--------------------------------------------------------------------------
  # ● Update Battle Camera
  #--------------------------------------------------------------------------               
  def update_battle_camera
      self.ox = $game_temp.viewport_oxy[0] + @org_oxy[0]
      self.oy = $game_temp.viewport_oxy[1] + @org_oxy[1]
      @sup_sprite.ox = $game_temp.viewport_oxy[0] + @org_oxy[2] if @sup_sprite != nil
      @sup_sprite.oy = $game_temp.viewport_oxy[1] + @org_oxy[3] if @sup_sprite != nil
  end  
  
  #--------------------------------------------------------------------------
  # ● OXY_CAMERA
  #--------------------------------------------------------------------------               
  def oxy_camera?(battler)
      return false if $imported[:mog_battle_camera] == nil
      if battler.is_a?(Game_Actor)
         return false if $imported[:mog_battle_hud_ex] and SceneManager.face_battler?
      end
      return true
  end
  
  #--------------------------------------------------------------------------
  # ● Execute Move
  #--------------------------------------------------------------------------      
  def execute_move(type,sprite,np)
      cp = type == 0 ? sprite.x : sprite.y
      sp = 1 + ((cp - np).abs / 10)
      sp = 1 if @duration < 60
      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   
  
  #--------------------------------------------------------------------------
  # ● Update Animation
  #--------------------------------------------------------------------------               
  def update_animation(dif_y)
     @oxy[1] -= 1
     case @duration
     when 60..90 ; self.opacity += 15
     when 30..60 ; self.opacity = 255
     when 0..30  ; self.opacity -= 9
     end
  end

end

#==============================================================================
# ■ Sprite Battler
#==============================================================================
class Sprite_Battler < Sprite_Base
  
  #--------------------------------------------------------------------------
  # ● Update Collapse
  #--------------------------------------------------------------------------  
  alias mog_damage_pop_update_collapse update_collapse
  def update_collapse
      mog_damage_pop_update_collapse
      execute_exp_pop
  end
  
  #--------------------------------------------------------------------------
  # ● Update Instant Collapse
  #--------------------------------------------------------------------------  
  alias mog_damage_pop_update_instant_collapse update_instant_collapse
  def update_instant_collapse
      mog_damage_pop_update_instant_collapse
      execute_exp_pop
  end   
  
  #--------------------------------------------------------------------------
  # ● Update Boss Collapse
  #--------------------------------------------------------------------------  
  alias mog_damage_pop_update_boss_collapse update_boss_collapse
  def update_boss_collapse
      mog_damage_pop_update_boss_collapse
      execute_exp_pop
  end
  
  #--------------------------------------------------------------------------
  # ● Execute Exp Pop
  #--------------------------------------------------------------------------  
  def execute_exp_pop
      return if !MOG_DAMAGEPOPUP::EXP_GOLD_POPUP_BATTLE or @dam_exp != nil
      return if @battler == nil or @battler.is_a?(Game_Actor)
      @dam_exp = true
      if $imported[:mog_active_bonus_gauge] != nil
         real_exp = $game_troop.bonus_exp? ? @battler.exp * 2 : @battler.exp
         real_gold = $game_troop.bonus_gold? ? @battler.gold * 2 : @battler.gold
      else
         real_exp = @battler.exp ;  real_gold = @battler.gold
      end
      @battler.damage.push([real_exp,"Exp"]) if @battler.exp > 0
      @battler.damage.push([real_gold,"Gold"]) if @battler.gold > 0
  end   
  
end[/pre]

Graphics.zip

735.95 KB, 下载次数: 18

脚本用到的图片

最佳答案

查看完整内容

搜索draw_text 把宽度width调大
梦石
0
星屑
30103
在线时间
5741 小时
注册时间
2016-3-8
回帖
1662
发表于 2022-2-28 19:34:35 | 显示全部楼层
搜索draw_text
把宽度width调大

评分

参与人数 1赞 +1 收起 理由
yz3440080 + 1 成功了!!!太感谢了T T!!

查看全部评分

回复

使用道具 举报

梦石
0
星屑
1487
在线时间
429 小时
注册时间
2014-4-25
回帖
32
 楼主| 发表于 2022-2-28 21:43:40 | 显示全部楼层
alexncf125 发表于 2022-2-28 21:12
搜索draw_text
把宽度width调大

QQ截图20220228213059.png 宽度解决了!不过一部分字会被截掉T T改了字体大小也不行……

点评

bitmap的宽度也调大试试  发表于 2022-2-28 21:54
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部