Chaos Project

RPG Maker => RPG Maker Scripts => Script Requests => Topic started by: Sase on March 16, 2008, 04:35:16 am

Title: [RESOLVED] RTAB window edit (Request)
Post by: Sase on March 16, 2008, 04:35:16 am
I need a window edit (totally lagless) to my RTAB.

The original System looks like this, note the bars go over each other
(http://i61.photobucket.com/albums/h51/Apocolator/bugiiii.jpg)

#===============================================================================
# ** BattleStatus Modification (RTAB Version)                            Credits
#    by DerVVulfman
#    Version 1.1
#    06-22-06
#
#-------------------------------------------------------------------------------
# ** A MODIFICATION OF
# ** Real time active battle (RTAB) Ver 1.12
# ** RTAB engine available at...
# ** http://members.jcom.home.ne.jp/cogwheel/
#
#-------------------------------------------------------------------------------
#  This script is a reponse  to a friend who wanted  the battle status window to
#  display the hero(s) information in a different manner.  Instead of displaying
#  each hero's information  directly underneath of them,  it displays it along a
#  single horizontal line in the style of the Final Fantasy games.
#
#  EX:  ARSHES        HP 204 / SP 199   [Normal ]        [=========]
#       BASIL         HP 184 / SP  49   [Knockout]       [=========]
#       GLORIA        HP 234 / SP 299   [Normal ]        [=========]
#       HILDA         HP 214 / SP 129   [Normal ]        [=========]
#
#  As a bonus, the system can Right-Justify the display and set the transparency
#  of the status window.   The only caveat of this is that  it doesn't highlight
#  the name of the hero in action. But, I have altered the battle command window
#  to change its height to appear just over the name (or atb bar) of the current
#  hero in action (instead of moving left to right).
#
#-------------------------------------------------------------------------------
#  There are two editable values:
#
#  BATTLESTATUS_LEFTJUSTIFY       Controls whether  the display shows the hero's
#                                 data left to right, or right to left.  It is a
#                                 boolean value (either true or false).
#
#                                 true - This setting will display the data just
#                                        like the above example.
#
#                                 false - This reverses the display  so the name
#                                         of the hero  is on the right,  and the
#                                         ATB bar is on the left.
#
#
#  BATTLESTATUS_OPACITY           Controls the transparency  of the display  and
#                                 of the battle command window. The value ranges
#                                 from 0 to 2...
#
#                                 0 - The display and command windows are set to
#                                     a totally solid display.
#
#                                 1 - This is the 'semi-transparent' look of the
#                                     RTAB system,  with the exception  that the
#                                     battle command window is  more solid so it
#                                     will show up over the battlestatus window.
#
#                                 2 - This setting  will make  the battle status
#                                     window totally invisible.  Only the battle
#                                     command window will be visible,  though it
#                                     will be semi-transparent for effect.
#
#  BATTLESTATUS_FULLWINDOW        Controls whether the display resizes itself to
#                                 fit the total number  of heroes  in the party.
#                                 It's a boolean value (either true or false).
#
#                                 true - This setting will  increase or decrease
#                                        the height of the window itself as well
#                                        as adjust its position on the screen.
#
#                                 false - This keeps  the battlestatus window in
#                                         the same position  and size regardless
#                                         of the number of party members.
#
#
#-------------------------------------------------------------------------------
#
#  * Scripts Added
#    Window_Base            - draw_battler_name
#
#  * Scripts Edited
#    Window_BattleStatus    - initialize        (RTAB version Edit)
#    Window_BattleStatus    - update            (RTAB version Edit)
#    Window_ActorStatus     - initialize        (RTAB version Edit)
#    Window_DetailsStatus   - initialize        (RTAB version Edit)
#    Window_DetailsStatus   - refresh           (RTAB version Edit)
#    Window_DetailsStatus   - update            (RTAB version Edit)
#    Scene_Battle (part 3)  - initialize        (Default Edit)
#
#-------------------------------------------------------------------------------
#  * Bug Fixes
#    System was designed to ensure that 4 characters were playable.  However, it
#    screwed up the display's vertical position when less than 4 characters were
#    in the party.  This has been fixed.
#
#-------------------------------------------------------------------------------


#==============================================================================
# ** EDITABLE CONSTANTS
#==============================================================================
BATTLESTATUS_LEFTJUSTIFY = true 
BATTLESTATUS_OPACITY = 2
BATTLESTATUS_FULLWINDOW = false


#==============================================================================
# ** Window_BattleStatus
#------------------------------------------------------------------------------
# * It is the window which indicates the status of the party member in the
#   battle picture.
#==============================================================================

class Window_BattleStatus < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize
   
    if BATTLESTATUS_FULLWINDOW
      y = 320
      super(0, y, 640, 160)
    else
      y = 480 - ($game_party.actors.size * 40)
      height = $game_party.actors.size * 40
      super(0, y, 640, height)
    end
   
    case BATTLESTATUS_OPACITY
    when 0
      self.back_opacity = 255
      self.opacity = 255
    when 1
      self.back_opacity = 160
      self.opacity = 255
    when 2
      self.back_opacity = 0
      self.opacity = 0
    end
   
    @actor_window = []
    for i in 0...$game_party.actors.size
      @actor_window.push(Window_ActorStatus.new(i, y + i * 40))
    end
    @level_up_flags = [false, false, false, false]
    refresh
  end
  #--------------------------------------------------------------------------
  # * Frame Renewal
  #--------------------------------------------------------------------------
  def update
    super
    if BATTLESTATUS_FULLWINDOW
      if self.y != 320
        self.y = 320
        self.height = 320
        for window in @actor_window
          window.dispose
        end
        @actor_window = []
        for i in 0...$game_party.actors.size
          @actor_window.push(Window_ActorStatus.new(i, y + i * 40))
        end
        refresh     
      end
    else
      if self.y != 480 - ($game_party.actors.size * 40)
        self.y = 480 - ($game_party.actors.size * 40)
        self.height = $game_party.actors.size * 40
        for window in @actor_window
          window.dispose
        end
        @actor_window = []
        for i in 0...$game_party.actors.size
          @actor_window.push(Window_ActorStatus.new(i, y + i * 40))
        end
        refresh
      end
    end
   
    for window in @actor_window
      window.update
    end
  end
end

#==============================================================================
# ** Window_ActorStatus
#------------------------------------------------------------------------------
# * It is the window which indicates the status of the party member respectively
#   in the battle picture.
#==============================================================================

class Window_ActorStatus < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(id, y)
    @actor_num = id
    super(0, y, 640, 160)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    self.back_opacity = 0
    actor = $game_party.actors[@actor_num]
    @actor_nm = actor.name
    @actor_mhp = actor.maxhp
    @actor_msp = actor.maxsp
    @actor_hp = actor.hp
    @actor_sp = actor.sp
    @actor_st = make_battler_state_text(actor, 120, true)
    @status_window = []
    for i in 0...5
      @status_window.push(Window_DetailsStatus.new(actor, i, y))
    end
    refresh(false)
  end
end
#==============================================================================
# ** Window_DetailsStatus
#------------------------------------------------------------------------------
# * It is the window which indicates the status of the actor in individually in
#   the battle picture.
#==============================================================================

class Window_DetailsStatus < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(actor, id, y)
    @status_id = id
    super(0, y, 640, 64)
    self.contents = Bitmap.new(width - 32, height - 32)
    self.opacity = 0
    self.back_opacity = 0
    refresh(actor, false)
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh(actor, level_up_flags = false)
    self.contents.clear
    if BATTLESTATUS_LEFTJUSTIFY
      # Draw Name/Hp etc left to right
      case @status_id
      when 0
        draw_actor_name(actor, 4, -8)
      when 1
        draw_actor_hp(actor, 152, -8, 80)
      when 2
        draw_actor_sp(actor, 248, -8, 80)
      when 3
        if level_up_flags
          self.contents.font.color = normal_color
          self.contents.draw_text(344, -8, 120, 32, "LEVEL UP!")
        else
          draw_actor_state(actor, 344, -8)
        end
      when 4
        draw_actor_atg(actor, 488, -8, 120)
      end
    else
      # Draw Name/Hp etc right to left
      case @status_id
      when 0
        draw_battler_name(actor, 488, -8)
      when 1
        draw_actor_hp(actor, 296, -8, 80)
      when 2
        draw_actor_sp(actor, 392, -8, 80)
      when 3
        if level_up_flags
          self.contents.font.color = normal_color
          self.contents.draw_text(160, -8, 120, 32, "LEVEL UP!")
        else
          draw_actor_state(actor, 160, -8)
        end
      when 4
        draw_actor_atg(actor, 0, -8, 120)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Frame renewal
  #--------------------------------------------------------------------------
  def update
    #At the time of main phase opacity is lowered a little
    if $game_temp.battle_main_phase
      self.contents_opacity -= 4 if self.contents_opacity > 191
    else
      self.contents_opacity += 4 if self.contents_opacity < 255
    end
  end
end

#==============================================================================
# ** Window_Base
#------------------------------------------------------------------------------
#  This class is for all in-game windows.
#==============================================================================

class Window_Base < Window
  #--------------------------------------------------------------------------
  # * Draw Name (battler)
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #--------------------------------------------------------------------------
  def draw_battler_name(actor, x, y)
    self.contents.font.color = normal_color
    self.contents.draw_text(x, y, 120, 32, actor.name, 2)
  end 
end


#==============================================================================
# ** Scene_Battle (Division definition 3)
#------------------------------------------------------------------------------
# * It is the class which processes the battle picture.
#==============================================================================
class Scene_Battle
  #--------------------------------------------------------------------------
  # * Setup of actor command window
  #--------------------------------------------------------------------------
  def phase3_setup_command_window
    # Nullifying the party command window
    @party_command_window.active = false
    @party_command_window.visible = false
    # Enabling the actor command window
    @actor_command_window.active = true
    @actor_command_window.visible = true

    # My corrections to set the Command window & transparency effect
    # Setting the position of the actor command window
    if BATTLESTATUS_FULLWINDOW
      @actor_command_window.y = (160 + (@actor_index * 40))
    else
      @actor_command_window.y = (320 - ($game_party.actors.size * 40)) +
        (@actor_index * 40)
    end
     
                             
    case BATTLESTATUS_OPACITY
    when 0
      @actor_command_window.back_opacity = 255
      @actor_command_window.opacity = 255
    when 1
      @actor_command_window.back_opacity = 255
      @actor_command_window.opacity = 191
    when 2
      @actor_command_window.back_opacity = 255
      @actor_command_window.opacity = 160
    end                             
    @actor_command_window.z=125
    # End of corrections
   
    # Setting the index to 0
    @actor_command_window.index = 0
  end
end

# HP/SP/EXP Gauge Script v1.00
# Distribution original support URL
# http://members.jcom.home.ne.jp/cogwheel/

#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
#  This class handles the actor. It's used within the Game_Actors class
#  ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================

class Game_Actor < Game_Battler
  def now_exp
    return @exp - @exp_list[@level]
  end
  def next_exp
    return @exp_list[@level+1] > 0 ? @exp_list[@level+1] - @exp_list[@level] : 0
  end
end

#==============================================================================
# ** Window_Base
#------------------------------------------------------------------------------
#  This class is for all in-game windows.
#==============================================================================

class Window_Base < Window
  #--------------------------------------------------------------------------
  # * Draw HP Gauge
  #--------------------------------------------------------------------------
  # Modification of the original Draw HP process
  alias :draw_actor_hp_hpsp :draw_actor_hp
  def draw_actor_hp(actor, x, y, width = 144)
    # Determine the rate of fill based on the actor's HP and HP Max
    if actor.maxhp != 0
      rate = actor.hp.to_f / actor.maxhp
    else
      rate = 0
    end
    # plus_x:     revised x-coordinate
    # rate_x:     revised X-coordinate as (%)
    # plus_y:     revised y-coordinate
    # plus_width: revised width
    # rate_width: revised width as (%)
    # height:     Vertical width
    # align1: Type 1 ( 0: left justify  1: center justify 2: right justify )
    # align2: Type 2 ( 0: Upper stuffing 1: Central arranging  2:Lower stuffing )
    # align3: Gauge type 0:Left justify 1: Right justify
    plus_x = 0
    rate_x = 0
    plus_y = 25
    plus_width = 0
    rate_width = 100
    height = 10
    align1 = 1
    align2 = 2
    align3 = 0
    # Gradation settings:  grade1: Empty gauge   grade2:Actual gauge
    # (0:On side gradation   1:Vertically gradation    2: Slantedly gradation)
    grade1 = 1
    grade2 = 0
    # Color setting. color1: Outermost framework, color2: Medium framework
    # color3: Empty framework dark color, color4: Empty framework light/write color
    color1 = Color.new(0, 0, 0, 192)
    color2 = Color.new(255, 255, 192, 192)
    color3 = Color.new(0, 0, 0, 192)
    color4 = Color.new(64, 0, 0, 192)
    # Color setting of gauge
    # Usually color setting of the time   
    color5 = Color.new(80 - 24 * rate, 80 * rate, 14 * rate, 192)
    color6 = Color.new(240 - 72 * rate, 240 * rate, 62 * rate, 192)
    # Determine the gauge's width & fill based on the actor's HP
    if actor.maxhp != 0
      hp = (width + plus_width) * actor.hp * rate_width / 100 / actor.maxhp
    else
      hp = 0
    end
    # Drawing of gauge
    gauge_rect(x + plus_x + width * rate_x / 100, y + plus_y,
                width, plus_width + width * rate_width / 100,
                height, hp, align1, align2, align3,
                color1, color2, color3, color4, color5, color6, grade1, grade2)
    # Call the original Draw HP process
    draw_actor_hp_hpsp(actor, x, y, width)
  end
  #--------------------------------------------------------------------------
  # * Draw SP Gauge
  #--------------------------------------------------------------------------
  # Modification of the original Draw SP process
  alias :draw_actor_sp_hpsp :draw_actor_sp
  def draw_actor_sp(actor, x, y, width = 144)
    # Determine the rate of fill based on the actor's SP and SP Max
    if actor.maxsp != 0
      rate = actor.sp.to_f / actor.maxsp
    else
      rate = 1
    end
    # plus_x:     revised x-coordinate
    # rate_x:     revised X-coordinate as (%)
    # plus_y:     revised y-coordinate
    # plus_width: revised width
    # rate_width: revised width as (%)
    # height:     Vertical width
    # align1: Type 1 ( 0: left justify  1: center justify 2: right justify )
    # align2: Type 2 ( 0: Upper stuffing 1: Central arranging  2:Lower stuffing )
    # align3: Gauge type 0:Left justify 1: Right justify
    plus_x = 0
    rate_x = 0
    plus_y = 25
    plus_width = 0
    rate_width = 100
    height = 10
    align1 = 1
    align2 = 2
    align3 = 0
    # Gradation settings:  grade1: Empty gauge   grade2:Actual gauge
    # (0:On side gradation   1:Vertically gradation    2: Slantedly gradation)
    grade1 = 1
    grade2 = 0
    # Color setting. color1: Outermost framework, color2: Medium framework
    # color3: Empty framework dark color, color4: Empty framework light/write color
    color1 = Color.new(0, 0, 0, 192)
    color2 = Color.new(255, 255, 192, 192)
    color3 = Color.new(0, 0, 0, 192)
    color4 = Color.new(0, 64, 0, 192)
    # Color setting of gauge
    # Usually color setting of the time       
    color5 = Color.new(14 * rate, 80 - 24 * rate, 80 * rate, 192)
    color6 = Color.new(62 * rate, 240 - 72 * rate, 240 * rate, 192)
    # Determine the gauge's width & fill based on the actor's SP
    if actor.maxsp != 0
      sp = (width + plus_width) * actor.sp * rate_width / 100 / actor.maxsp
    else
      sp = (width + plus_width) * rate_width / 100
    end
    # Drawing of gauge
    gauge_rect(x + plus_x + width * rate_x / 100, y + plus_y,
                width, plus_width + width * rate_width / 100,
                height, sp, align1, align2, align3,
                color1, color2, color3, color4, color5, color6, grade1, grade2)
    # Call the original Draw HP process
    draw_actor_sp_hpsp(actor, x, y, width)
  end
  #--------------------------------------------------------------------------
  # * Draw EXP Gauge
  #--------------------------------------------------------------------------
  # Modification of the original Draw HP process
  alias :draw_actor_exp_hpsp :draw_actor_exp
  def draw_actor_exp(actor, x, y, width = 204)
    # Determine the rate of fill based on the actor's EXP and Next EXP
    if actor.next_exp != 0
      rate = actor.now_exp.to_f / actor.next_exp
    else
      rate = 1
    end
    # plus_x:     revised x-coordinate
    # rate_x:     revised X-coordinate as (%)
    # plus_y:     revised y-coordinate
    # plus_width: revised width
    # rate_width: revised width as (%)
    # height:     Vertical width
    # align1: Type 1 ( 0: left justify  1: center justify 2: right justify )
    # align2: Type 2 ( 0: Upper stuffing 1: Central arranging  2:Lower stuffing )
    # align3: Gauge type 0:Left justify 1: Right justify
    plus_x = 0
    rate_x = 0
    plus_y = 25
    plus_width = 0
    rate_width = 100
    height = 10
    align1 = 1
    align2 = 2
    align3 = 0
    # Gradation settings:  grade1: Empty gauge   grade2:Actual gauge
    # (0:On side gradation   1:Vertically gradation    2: Slantedly gradation)
    grade1 = 1
    grade2 = 0
    # Color setting. color1: Outermost framework, color2: Medium framework
    # color3: Empty framework dark color, color4: Empty framework light/write color
    color1 = Color.new(0, 0, 0, 192)
    color2 = Color.new(255, 255, 192, 192)
    color3 = Color.new(0, 0, 0, 192)
    color4 = Color.new(64, 0, 0, 192)
    # Color setting of gauge
    # Usually color setting of the time     
    color5 = Color.new(80 * rate, 80 - 80 * rate ** 2, 80 - 80 * rate, 192)
    color6 = Color.new(240 * rate, 240 - 240 * rate ** 2, 240 - 240 * rate, 192)
    # Determine the gauge's width & fill based on the actor's Next EXP
    if actor.next_exp != 0
      exp = (width + plus_width) * actor.now_exp * rate_width /
                                                          100 / actor.next_exp
    else
      exp = (width + plus_width) * rate_width / 100
    end
    # Drawing of gauge
    gauge_rect(x + plus_x + width * rate_x / 100, y + plus_y,
                width, plus_width + width * rate_width / 100,
                height, exp, align1, align2, align3,
                color1, color2, color3, color4, color5, color6, grade1, grade2)
    # Call the original Draw EXP process
    draw_actor_exp_hpsp(actor, x, y)
  end
  #--------------------------------------------------------------------------
  # * Drawing of gauge
  #--------------------------------------------------------------------------
  def gauge_rect(x, y, rect_width, width, height, gauge, align1, align2, align3,
                color1, color2, color3, color4, color5, color6, grade1, grade2)
    case align1
    when 1
      x += (rect_width - width) / 2
    when 2
      x += rect_width - width
    end
    case align2
    when 1
      y -= height / 2
    when 2
      y -= height
    end
    # Framework Drawing
    self.contents.fill_rect(x, y, width, height, color1)
    self.contents.fill_rect(x + 1, y + 1, width - 2, height - 2, color2)
    if align3 == 0
      if grade1 == 2
        grade1 = 3
      end
      if grade2 == 2
        grade2 = 3
      end
    end
    if (align3 == 1 and grade1 == 0) or grade1 > 0
      color = color3
      color3 = color4
      color4 = color
    end
    if (align3 == 1 and grade2 == 0) or grade2 > 0
      color = color5
      color5 = color6
      color6 = color
    end
    # Drawing of empty gauge
    self.contents.gradation_rect(x + 2, y + 2, width - 4, height - 4,
                                  color3, color4, grade1)
    if align3 == 1
      x += width - gauge
    end
    #  Drawing of actual gauge
    self.contents.gradation_rect(x + 2, y + 2, gauge - 4, height - 4,
                                  color5, color6, grade2)
  end
end

#------------------------------------------------------------------------------
# New routine added to the Bitmap class.
#==============================================================================

class Bitmap
#--------------------------------------------------------------------------
# * Rectangle Gradation Indicator
#   color1: Start color
#   color2: Ending color
#   align: 0: On side gradation
#          1: Vertically gradation
#          2: The gradation (intense concerning slantedly heavily note)
#--------------------------------------------------------------------------
  def gradation_rect(x, y, width, height, color1, color2, align = 0)
    if align == 0
      for i in x...x + width
        red   = color1.red + (color2.red - color1.red) * (i - x) / (width - 1)
        green = color1.green +
                (color2.green - color1.green) * (i - x) / (width - 1)
        blue  = color1.blue +
                (color2.blue - color1.blue) * (i - x) / (width - 1)
        alpha = color1.alpha +
                (color2.alpha - color1.alpha) * (i - x) / (width - 1)
        color = Color.new(red, green, blue, alpha)
        fill_rect(i, y, 1, height, color)
      end
    elsif align == 1
      for i in y...y + height
        red   = color1.red +
                (color2.red - color1.red) * (i - y) / (height - 1)
        green = color1.green +
                (color2.green - color1.green) * (i - y) / (height - 1)
        blue  = color1.blue +
                (color2.blue - color1.blue) * (i - y) / (height - 1)
        alpha = color1.alpha +
                (color2.alpha - color1.alpha) * (i - y) / (height - 1)
        color = Color.new(red, green, blue, alpha)
        fill_rect(x, i, width, 1, color)
      end
    elsif align == 2
      for i in x...x + width
        for j in y...y + height
          red   = color1.red + (color2.red - color1.red) *
                  ((i - x) / (width - 1.0) + (j - y) / (height - 1.0)) / 2
          green = color1.green + (color2.green - color1.green) *
                  ((i - x) / (width - 1.0) + (j - y) / (height - 1.0)) / 2
          blue  = color1.blue + (color2.blue - color1.blue) *
                  ((i - x) / (width - 1.0) + (j - y) / (height - 1.0)) / 2
          alpha = color1.alpha + (color2.alpha - color1.alpha) *
                  ((i - x) / (width - 1.0) + (j - y) / (height - 1.0)) / 2
          color = Color.new(red, green, blue, alpha)
          set_pixel(i, j, color)
        end
      end
    elsif align == 3
      for i in x...x + width
        for j in y...y + height
          red   = color1.red + (color2.red - color1.red) *
                ((x + width - i) / (width - 1.0) + (j - y) / (height - 1.0)) / 2
          green = color1.green + (color2.green - color1.green) *
                ((x + width - i) / (width - 1.0) + (j - y) / (height - 1.0)) / 2
          blue  = color1.blue + (color2.blue - color1.blue) *
                ((x + width - i) / (width - 1.0) + (j - y) / (height - 1.0)) / 2
          alpha = color1.alpha + (color2.alpha - color1.alpha) *
                ((x + width - i) / (width - 1.0) + (j - y) / (height - 1.0)) / 2
          color = Color.new(red, green, blue, alpha)
          set_pixel(i, j, color)
        end
      end
    end
  end
end


Thu the Blizzard's 3-party fix (which is needed lagless) looks like this:
(http://i61.photobucket.com/albums/h51/Apocolator/bigoooo.jpg)
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# RTAB BattleStatus Blizz-Art Hack by Blizzard
# Version: 1.0
# Date: 4.7.2007
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#
# Explanation:
#
# This script will hack into RTAB's code and mod the battle status for a 3
# member party.
#
#
# Features:
#
# - uses "Super Lagless Bar" code
# - overrides SephirothSpawn's slant bars and DerVVulfman's BattleStatus mod
# - possiblity to use original bar style from "Gradient Bar Styler"
# - can mod the text in the status window without affecting the rest of the
#   game
# - fixes the command window position, size and opacity
# - the currently selected actor has his AT Bar color changed to red instead of
#   yellow
# - AT Bar is blinking when at 100%
# - overrides the stupid refresh interruption when somebody is attacking so the
#   bars keep blinking, no matter what
# - adds HP/SP/EXP bars as well
#
#
# Instructions:
#
# To apply this code, put it UNDER ALL of the RTAB codes.
#
#
# If you have any problems, please report them here:
# http://www.chaosproject.co.nr
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

TEXTTYPE = 1 # 0 - normal, 1 - shadowed, 2 - outlined
BACK_COLOR = Color.new(0, 0, 0, 192) # color of shadow/outline
ORIGINAL = true # true changes the bar display to the original gradient style
ATB_TEXT = 'AT' # AT Bar text (note that too long strings WILL cause lag)

#==============================================================================
# Bitmap
#==============================================================================

class Bitmap

# RTAB updates the AT bar constantly. Without an extremely optimized code
# imense lag would occur. The code has a complexity of just n (instead of n^2
# like usual bar scripts) and instead of coloring each pixel, it treats the
# slant bar like a normal gradient bar, but creates an optical illusion of a
# totally slanted bar.
def super_lagless_bar(x, y, w, color1, color2, color3, rate)
   offset = 8
   height = 16
   x += offset
   y += height
   for i in 0...offset+3
     fill_rect(x-i, y+i-2, w+3, 1, Color.new(0, 0, 0))
   end
   if ORIGINAL
     for i in 0...offset+1
       fill_rect(x-i, y+i-1, w+1, 1, Color.new(255, 255, 255))
     end
   end
   for i in 0...offset
     red = color3.red * i / offset
     green = color3.green * i / offset
     blue = color3.blue * i / offset
     fill_rect(x-i+1, y+i-1, w, 1, Color.new(red, green, blue))
   end
   if (w*rate).to_i >= offset
     for i in 0...(w*rate).to_i+offset
       red = color1.red + (color2.red-color1.red)*i / ((w+offset)*rate)
       green = color1.green + (color2.green-color1.green)*i / ((w+offset)*rate)
       blue = color1.blue + (color2.blue-color1.blue)*i / ((w+offset)*rate)
       oy = i < offset ? offset-i : 0
       off = i < offset ? i : i > w*rate ? (w*rate).to_i+offset-i : offset
       fill_rect(x+i-offset+1, y+oy-1, 1, off, Color.new(red, green, blue))
     end
   else
     for i in 0...(w * rate).to_i
       for j in 0...offset
         red = color1.red + (color2.red-color1.red)*i / (w*rate)
         green = color1.green + (color2.green-color1.green)*i / (w*rate)
         blue = color1.blue + (color2.blue-color1.blue)*i / (w*rate)
         set_pixel(x+i-j+1, y+j-1, Color.new(red, green, blue))
       end
     end
   end
end

end

#==============================================================================
# Window_Base
#==============================================================================

class Window_Base

# byebye, Seph's slant bars :)
def draw_slant_bar(a, b, c, d, e = 0, f = 0, g = nil, h = nil)
end

# adds bar wherever HP are displayed
alias draw_actor_hp_blizzart_gradient_later draw_actor_hp
def draw_actor_hp(actor, x, y, w = 148)
   w -= 12
   rate = actor.hp.to_f / actor.maxhp
   if rate > 0.6
     color1 = Color.new(80 - 150 * (rate-0.6), 80, 50 * (rate-0.6))
     color2 = Color.new(240 - 450 * (rate-0.6), 240, 150 * (rate-0.6))
   elsif rate > 0.2 and rate <= 0.6
     color1 = Color.new(80, 200 * (rate-0.2), 0)
     color2 = Color.new(240, 600 * (rate-0.2), 0)
   elsif rate <= 0.2
     color1 = Color.new(400 * rate, 0, 0)
     color2 = Color.new(240, 0, 0)
   end
   color3 = Color.new(0, 80, 0)
   self.contents.super_lagless_bar(x, y, w, color1, color2, color3, rate)
   draw_actor_hp_blizzart_gradient_later(actor, x, y)
end

# adds bar wherever SP are displayed
alias draw_actor_sp_blizzart_gradient_later draw_actor_sp
def draw_actor_sp(actor, x, y, w = 148)
   w -= 12
   rate = (actor.maxsp > 0 ? actor.sp.to_f / actor.maxsp : 0)
   if rate > 0.4
     color1 = Color.new(60 - 66 * (rate-0.4), 20, 80)
     color2 = Color.new(180 - 200 * (rate-0.4), 60, 240)
   elsif rate <= 0.4
     color1 = Color.new(20 + 100 * rate, 50 * rate, 26 + 166 * rate)
     color2 = Color.new(60 + 300 * rate, 150 * rate, 80 + 400 * rate)
   end
   color3 = Color.new(0, 0, 80, 192)
   self.contents.super_lagless_bar(x, y, w, color1, color2, color3, rate)
   draw_actor_sp_blizzart_gradient_later(actor, x, y)
end

# adds bar wherever EXP are displayed
alias draw_actor_exp_blizzart_gradient_later draw_actor_exp
def draw_actor_exp(actor, x, y, w = 180)
   rate = (actor.next_exp != 0 ? actor.now_exp.to_f / actor.next_exp : 1)
   if rate < 0.5
     color1 = Color.new(20 * rate, 60, 80)
     color2 = Color.new(60 * rate, 180, 240)
   elsif rate >= 0.5
     color1 = Color.new(20 + 120 * (rate-0.5), 60 + 40 * (rate-0.5), 80)
     color2 = Color.new(60 + 360 * (rate-0.5), 180 + 120 * (rate-0.5), 240)
   end
   color3 = Color.new(80, 80, 80)
   self.contents.super_lagless_bar(x, y, w, color1, color2, color3, rate)
   draw_actor_exp_blizzart_gradient_later(actor, x, y)
end

end

#==============================================================================
# Window_BattleStatus
#==============================================================================

class Window_BattleStatus

# initialization
def initialize
   super(160, 352, 480, 128)
   self.contents = Bitmap.new(width - 32, height - 32)
   self.contents.font.bold = true
   self.contents.font.name = "Arial"
   self.contents.font.size = 22
   @level_up_flags = [false, false, false]
   @glow_flags = [false, false, false]
   @name = []
   @hp = []
   @sp = []
   @atp = []
   for i in 0...$game_party.actors.size
     norm_refresh(i)
   end
end

# necessary to override RTAB method.
def refresh(num = 0)
   norm_refresh(num-1) if num != 0
end

# necessary to override RTAB method.
def at_refresh(num = 0)
   xat_refresh(num-1) if num != 0
end

# refreshes the whole status for actor with index i
def norm_refresh(i)
   draw_name($game_party.actors[i], i) if @name[i] != $game_party.actors[i].name
   draw_hp($game_party.actors[i], i) if @hp[i] != $game_party.actors[i].hp
   draw_sp($game_party.actors[i], i) if @sp[i] != $game_party.actors[i].sp
   @name[i] = $game_party.actors[i].name
   @hp[i] = $game_party.actors[i].hp
   @sp[i] = $game_party.actors[i].sp
   xat_refresh(i)
end

# refreshes the AT Bar for actor with index i
def xat_refresh(i)
   return if @atp[i] == $game_party.actors[i].atp and @atp[i] != 100
   self.contents.font.size -= 4
   self.contents.font.italic = true
   self.contents.fill_rect(349, i*32, 98, 32, Color.new(0, 0, 0, 0))
   draw_actor_atb($game_party.actors[i], 349, i*32, 84)
   draw_text_special(358, -1+i*32, 96, 32, ATB_TEXT)
   self.contents.font.size += 4
   self.contents.font.italic = false
   @atp[i] = $game_party.actors[i].atp
end

# draws name
def draw_name(actor, i)
   self.contents.fill_rect(0, i*32, 90, 40, Color.new(0, 0, 0, 0))
   draw_text_special(4, i*32, 84, 32, actor.name)
end

# draws HP and bar
def draw_hp(actor, i)
   self.contents.fill_rect(90, i*32, 140, 40, Color.new(0, 0, 0, 0))
   rate = actor.hp.to_f / actor.maxhp
   if rate > 0.6
     color1 = Color.new(80 - 150 * (rate-0.6), 80, 50 * (rate-0.6))
     color2 = Color.new(240 - 450 * (rate-0.6), 240, 150 * (rate-0.6))
   elsif rate > 0.2 and rate <= 0.6
     color1 = Color.new(80, 200 * (rate-0.2), 0)
     color2 = Color.new(240, 600 * (rate-0.2), 0)
   elsif rate <= 0.2
     color1 = Color.new(400 * rate, 0, 0)
     color2 = Color.new(240, 0, 0)
   end
   color3 = Color.new(0, 80, 0)
   self.contents.super_lagless_bar(124, i*32, 86, color1, color2, color3, rate)
   self.contents.font.italic = true
   self.contents.font.color = system_color
   draw_text_special(94, i*32, 100, 32, $data_system.words.hp)
   self.contents.font.italic = false
   self.contents.font.size -= 4
   self.contents.font.color = actor.hp == 0 ? knockout_color :
       actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color
   draw_text_special(86, i*32, 80, 32, actor.hp.to_s, 2)
   self.contents.font.color = normal_color
   draw_text_special(74, i*32, 100, 32, "/", 2)
   draw_text_special(178, i*32, 80, 32, actor.maxhp.to_s)
   self.contents.font.size += 4
end

# draws SP and bar
def draw_sp(actor, i)
   self.contents.fill_rect(230, i*32, 129, 40, Color.new(0, 0, 0, 0))
   rate = (actor.maxsp > 0 ? actor.sp.to_f / actor.maxsp : 0)
   if rate > 0.4
     color1 = Color.new(60 - 66 * (rate-0.4), 20, 80)
     color2 = Color.new(180 - 200 * (rate-0.4), 60, 240)
   elsif rate <= 0.4
     color1 = Color.new(20 + 100 * rate, 50 * rate, 26 + 166 * rate)
     color2 = Color.new(60 + 300 * rate, 150 * rate, 80 + 400 * rate)
   end
   color3 = Color.new(0, 0, 80, 192)
   self.contents.super_lagless_bar(260, i*32, 72, color1, color2, color3, rate)
   self.contents.font.italic = true
   self.contents.font.color = system_color
   draw_text_special(230, i*32, 100, 32, $data_system.words.sp)
   self.contents.font.italic = false
   self.contents.font.size -= 4
   self.contents.font.color = actor.sp == 0 ? knockout_color :
       actor.sp <= actor.maxsp / 4 ? crisis_color : normal_color
   draw_text_special(216, i*32, 80, 32, actor.sp.to_s, 2)
   self.contents.font.color = normal_color
   draw_text_special(204, i*32, 100, 32, "/", 2)
   draw_text_special(308, i*32, 80, 32, actor.maxsp.to_s)
   self.contents.font.size += 4
end

# draws the AT bar
def draw_actor_atb(actor, x, y, w = 120)
   if actor.rtp != 0
     rate = 1 - actor.rt.to_f / actor.rtp
     color1 = Color.new(0, 48, 64)
     color2 = Color.new(0, 192, 255)
   else
     rate = actor.atp.to_f / 100
     frame = Graphics.frame_count % Graphics.frame_rate
     glow = (frame < 6 ? frame / 5.0 : frame < 12 ? (11-frame) / 5.0 : 0)
     if rate == 1
       @glow_flags[actor.index] = false if glow == 0
     else
       @glow_flags[actor.index] = (glow != 0)
     end
     glow = 0 if @glow_flags[actor.index]
     if actor == $scene.active_actor
       color1 = Color.new(64 + glow*191, glow*255, glow*255)
       color2 = Color.new(255, glow*255, glow*255)
     else
       color1 = Color.new(64 + glow*191, 64 + glow*191, glow*255)
       color2 = Color.new(255, 255, glow*255)
     end
   end
   color3 = Color.new(80, 80, 80)
   self.contents.super_lagless_bar(x, y, w, color1, color2, color3, rate)
end

# mods the status window text
def draw_text_special(x2, y2, w2 = 0, h2 = 0, text2 = "", a2 = 0)
   if x2.is_a?(Rect)
     x, y, w, h, text, a = x2.x, x2.y, x2.width, x2.height, y2, w2
   else
     x, y, w, h, text, a = x2, y2, w2, h2, text2, a2
   end
   save_color = self.contents.font.color.clone
   self.contents.font.color = BACK_COLOR
   if TEXTTYPE > 0
     self.contents.draw_text(x+1, y+1, w, h, text, a)
     if TEXTTYPE == 2
       self.contents.draw_text(x-1, y+1, w, h, text, a)
       self.contents.draw_text(x+1, y-1, w, h, text, a)
       self.contents.draw_text(x-1, y-1, w, h, text, a)
     end
   end
   self.contents.font.color = save_color
   self.contents.draw_text(x, y, w, h, text, a)
end

# pointless, but necessary to override RTAB method
def update
   super
end

# pointless, but necessary to override RTAB method
def dispose
   super
end

end

#==============================================================================
# Scene_Battle
#==============================================================================

class Scene_Battle

attr_reader :active_actor

# fixes the command window position, size and opacity
alias ph3_scw_rtab_battlestatus_hack_later phase3_setup_command_window
def phase3_setup_command_window
   ph3_scw_rtab_battlestatus_hack_later
   @actor_command_window.height = 128
   @actor_command_window.x = 0
   @actor_command_window.y = 480 - @actor_command_window.height
   @actor_command_window.back_opacity = @actor_command_window.opacity = 255
end

# overrides the stupid refresh interruption when somebody is attacking
alias upd_ph0_rtab_battlestatus_hack_later update_phase0
def update_phase0
   for i in 0...$game_party.actors.size
     @status_window.xat_refresh(i)
   end
   upd_ph0_rtab_battlestatus_hack_later
end

end


I'd like to get the window, but the original bars etc, because the window flash etc. lags alot on many betatester's computers.

Thanks,
Tsurara
Title: Re: RTAB window edit (Request)
Post by: Nortos on March 16, 2008, 04:39:10 am
umm sorry what do u want lol can't understand
Title: Re: RTAB window edit (Request)
Post by: Sase on March 16, 2008, 09:11:02 am
In other words:
I want a LAGLESS window around the HP/MP/Turn bar HUD, and fixed HP/MP bars which will NOT go over each other.
Title: Re: RTAB window edit (Request)
Post by: Nortos on March 16, 2008, 11:54:21 pm
so lemme get this straight all u want is the window added to top two scripts and the bars not overlapping? Pretty simple just gimme a few mins to look at them

EDIT: sorry...can u explain it further also when I tried those two I didn't get anything looking like the first image
Title: Re: RTAB window edit (Request)
Post by: Blizzard on March 17, 2008, 06:21:04 am
You want me to remove the blinking feature to decrease lag? Here's v1.1b which has the blinking feature optional:

*SCRIPT REMOVED, NEWER VERSION FURTHER BELOW*
Title: Re: RTAB window edit (Request)
Post by: Sase on March 17, 2008, 08:48:29 am
Setting the blinking false will cause the AT bar to always be full yellow :o Tho the turns still go the same time.
Title: Re: RTAB window edit (Request)
Post by: Blizzard on March 17, 2008, 12:39:11 pm
Oh, you wanted to keep the red bars...? (-_-) Here you go:

*SCRIPT REMOVED, NEWER VERSION FURTHER BELOW*
Title: Re: RTAB window edit (Request)
Post by: Flermza on March 17, 2008, 12:47:10 pm
All hail the mighty scripter Blizzard. XD
Title: Re: RTAB window edit (Request)
Post by: Nortos on March 17, 2008, 04:52:34 pm
i was gonna do this but couldn't understand the request lol, anyways gj Blizz
Title: Re: RTAB window edit (Request)
Post by: Sase on March 18, 2008, 10:38:04 am
Ehm I meaned the bars are always full, even when the turns have already elapsed. Sprry for the trouble :F
Observe, here 2 characters have just spend their turn and Zachafer has been waiting for his turn for a sec, and the bar still looks like full.
(http://i61.photobucket.com/albums/h51/Apocolator/omglag.jpg)
Title: Re: RTAB window edit (Request)
Post by: Blizzard on March 19, 2008, 09:11:43 am
Here you go:

*SCRIPT REMOVED, NEWER VERSION FURTHER BELOW*

*AH, HERE IT IS:*
http://forum.chaos-project.com/index.php?topic=1244.0
Title: Re: RTAB window edit (Request)
Post by: Sase on March 19, 2008, 10:15:41 am
Well thanks again Blizz ^^ Uber lagless and working.
*bows*