Author Topic: Over Drive in HUD(resolved)  (Read 764 times)

Offline nathmatt

  • Chaos User
  • ******
  • Posts: 1289
  • LV: 114
  • Gender: Male
  • The Add_on King
    • View Profile
    • Nathmatt Productions
Over Drive in HUD(resolved)
« on: January 16, 2010, 02:10:47 AM »
ok i added over drive to my hud but when it = 2.0 the fill_rect that refreshes it over lays it does fine when it = 1.0 but after that it over lays

Code: [Select]
#==============================================================================
# Hud
#------------------------------------------------------------------------------
#  This class was modified to support SR display and modify the number of
#  skills left to use.
#==============================================================================

class Hud < Sprite
  
  #----------------------------------------------------------------------------
  # Initialization
  #  viewport - the viewport for the sprite
  #----------------------------------------------------------------------------
  def initialize(viewport = nil)
    # call superclass method
    super
    # create positions
    create_positions
    # create bitmap
    self.bitmap = Bitmap.new(@hud_width, @hud_height)
    # set font
    self.bitmap.font.name = 'Arial'
    # set font size
    self.bitmap.font.size = 16
    # set font to bold
    self.bitmap.font.bold = true
    # set x, y position
    self.x, self.y = -4, 4
    # set z coordinate
    self.z = 1000
    # draw basic HUD
    draw_basic
    # update
    update
  end
  #----------------------------------------------------------------------------
  # create_positions
  #  Sets drawing positions. This method can be aliased and the positions
  #  modified to create a different HUD.
  #----------------------------------------------------------------------------
  def create_positions
    @original_width = @hud_width = 275
    @original_height = @hud_height = 120
    @face_x,@face_y, @exp_x, @exp_y = 4, 4, 4, 100
    @name_x, @name_y, @level_x, @level_y = 167, 1, 112, 1
    @hp_x, @hp_y, @sp_x, @sp_y = 125, 42, 115, 55
    @hot_x, @hot_y, @left_x, @left_y = 580, 150, 610, 150
    @over_drive_x, @over_drive_y = 105, 68
  end
  #----------------------------------------------------------------------------
  # draw_basic
  #  Draws the HUD template.
  #----------------------------------------------------------------------------
  def draw_basic
    # fill with grey rectangle
    self.bitmap.fill_rect(0, 0, self.bitmap.width, self.bitmap.height,
        Color.new(0, 0, 0, 0))
    # set font color
    self.bitmap.font.color = system_color
    # draw "LV"
    self.bitmap.draw_text_full(@level_x, @level_y, 20, 20, 'LV')
    # if direct hotkey option is turned off
    unless BlizzABS::Config::DIRECT_HOTKEYS
      # draw "Skill:"
      self.bitmap.draw_text_full(@hot_x, @hot_y+50, 48, 20, 'Skill:')
      # draw "Item:"
      self.bitmap.draw_text_full(@hot_x, @hot_y, 48, 20, 'Item:')
    end
    # draw "HP"
    self.bitmap.draw_text_full(@hp_x, @hp_y, 32, 20, $data_system.words.hp)
    # draw "SP"
    self.bitmap.draw_text_full(@sp_x, @sp_y, 32, 20, $data_system.words.sp)
    # draw "EXP"
    self.bitmap.draw_text_full(@exp_x, @exp_y, 32, 20, 'EXP')
    # draw "OVERDRIVE"
    self.bitmap.draw_text_full(@over_drive_x, @over_drive_y, 32, 20,
    BlizzCFG::OVERDRIVE_NAME.to_s)
    
  end
  #----------------------------------------------------------------------------
  # draw_empty
  #  Draws the HP and SP display when actor doesn't exist.
  #----------------------------------------------------------------------------
  def draw_empty
    # draw empty bars
    self.bitmap.gradient_bar_hud(@hp_x+32, @hp_y+3, 114, 0, 'hud_green_bar', 1)
    # draw empty bars
    self.bitmap.gradient_bar_hud(@sp_x+32, @sp_y+3, 114, 0, 'hud_blue_bar', 2)
    # set font color
    self.bitmap.font.color = disabled_color
    # draw empty HP
    self.bitmap.draw_text_full(@hp_x+38, @hp_y, 48, 20, '0', 2)
    self.bitmap.draw_text_full(@hp_x+86, @hp_y, 12, 20, '/', 1)
    self.bitmap.draw_text_full(@hp_x+98, @hp_y, 48, 20, '0')
    # draw empty SP
    self.bitmap.draw_text_full(@sp_x+38, @sp_y, 48, 20, '0', 2)
    self.bitmap.draw_text_full(@sp_x+86, @sp_y, 12, 20, '/', 1)
    self.bitmap.draw_text_full(@sp_x+98, @sp_y, 48, 20, '0')
    # reset all flag variables
    @name = @level = @hp = @sp = @maxhp = @maxsp = @exp = @states = @skill =
        @skills_left = @item = @items_left = @gold = nil
  end
  #----------------------------------------------------------------------------
  # draw_name
  #  Draws the name display.
  #----------------------------------------------------------------------------
  def draw_name
    # set current variable
    @name = actor.name
    # remove old display
    self.bitmap.fill_rect(@name_x, @name_y, 104, 20, Color.new(0, 0, 0, 0))
    # set font color
    self.bitmap.font.color = Color.new(0, 255, 0)
    # draw actor's name
    self.bitmap.draw_text_full(@name_x, @name_y, 104, 20, @name)
  end
  #----------------------------------------------------------------------------
  # draw_face
  #  Draws the face display.
  #----------------------------------------------------------------------------
  def draw_face
    # set current variable
    @face = actor.name
    # remove old display
    self.bitmap.fill_rect(@face_x, @face_y, 100, 100, Color.new(0, 0, 0, 0))
    # load bitmap
    bitmap = RPG::Cache.picture('Faces/'+@face+'_L')
    # draw bitmap
    self.bitmap.blt(@face_x, @face_y, bitmap, Rect.new(0, 0, 100, 100))
  end
  #----------------------------------------------------------------------------
  # draw_level
  #  Draws the level display.
  #----------------------------------------------------------------------------
  def draw_level
    # set current variable
    @level = actor.level
    # remove old display
    self.bitmap.fill_rect(@level_x+20, @level_y, 20, 20, Color.new(0, 0, 0, 0))
    # set font color
    self.bitmap.font.color = normal_color
    # draw actor's level
    self.bitmap.draw_text_full(@level_x+20, @level_y, 20, 20, @level.to_s, 2)
  end
  #----------------------------------------------------------------------------
  # draw_hp
  #  Draws the HP display.
  #----------------------------------------------------------------------------
  def draw_hp
    # set current variables
    @hp, @maxhp = actor.hp, actor.maxhp
    # remove old display
    self.bitmap.fill_rect(@hp_x+22, @hp_y+15, 150, 14, Color.new(0, 0, 0, 0))
    # Calculate The Rate
    rate = (actor.maxhp > 0 ? actor.hp.to_f / actor.maxhp : 0)
    # Draw Color For The Bar
    if rate > 0.6
      color1 = Color.new(80 - 150 * (rate-0.6), 80, 50 * (rate-0.6), 192)
      color2 = Color.new(240 - 450 * (rate-0.6), 240, 150 * (rate-0.6), 192)
    elsif rate > 0.2 && rate <= 0.6
      color1 = Color.new(80, 200 * (rate-0.2), 0, 192)
      color2 = Color.new(240, 600 * (rate-0.2), 0, 192)
    elsif rate <= 0.2
      color1 = Color.new(400 * rate, 0, 0, 192)
      color2 = Color.new(240, 0, 0, 192)
    end
    # background color
    color3 = Color.new(0, 80, 0, 192)
    # draw gradient bar
    self.bitmap.gradient_bar(@hp_x+22,@hp_y-15,114,color1,color2,color3,rate)
    # set font color depending on how many HP left
    self.bitmap.font.color = @hp == 0 ? knockout_color :
        @hp <= @maxhp / 4 ? crisis_color : normal_color
    # draw HP
    self.bitmap.draw_text_full(@hp_x+28, @hp_y, 48, 20, @hp.to_s, 2)
    # set color
    self.bitmap.font.color = normal_color
    # draw "/"
    self.bitmap.draw_text_full(@hp_x+76, @hp_y, 12, 20, '/', 1)
    # draw max HP
    self.bitmap.draw_text_full(@hp_x+88, @hp_y, 48, 20, @maxhp.to_s)
  end
  #----------------------------------------------------------------------------
  # draw_sp
  #  Draws the SP display.
  #----------------------------------------------------------------------------
  def draw_sp
    # set current variables
    @sp, @maxsp = actor.sp, actor.maxsp
    # remove old display
    self.bitmap.fill_rect(@sp_x+22, @sp_y+15, 150, 14, Color.new(0, 0, 0, 0))
    # Calculate The Rate
    rate = (actor.maxsp > 0 ? actor.sp.to_f / actor.maxsp : 0)
    # Draw Color For The Bar
    if rate > 0.4
      color1 = Color.new(60 - 66 * (rate-0.4), 20, 80, 192)
      color2 = Color.new(180 - 200 * (rate-0.4), 60, 240, 192)
    elsif rate <= 0.4
      color1 = Color.new(20 + 100 * rate, 50 * rate, 26 + 166 * rate, 192)
      color2 = Color.new(60 + 300 * rate, 150 * rate, 80 + 400 * rate, 192)
    end
    # background color
    color3 = Color.new(0, 80, 0, 192)
    # draw gradient bar
    self.bitmap.gradient_bar(@sp_x+22, @sp_y-15, 114, color1, color2, color3,
    rate)
    # set font color depending on how many SP left
    self.bitmap.font.color = @sp == 0 ? knockout_color :
        @sp <= @maxsp / 4 ? crisis_color : normal_color
    # draw SP
    self.bitmap.draw_text_full(@sp_x+28, @sp_y, 48, 20, @sp.to_s, 2)
    # set font color
    self.bitmap.font.color = normal_color
    # draw "/"
    self.bitmap.draw_text_full(@sp_x+76, @sp_y, 12, 20, '/', 1)
    # draw max SP
    self.bitmap.draw_text_full(@sp_x+88, @sp_y, 48, 20, @maxsp.to_s)
  end
  #----------------------------------------------------------------------------
  # draw_over_drive
  #  Draws the over_drive display.
  #----------------------------------------------------------------------------
  def draw_over_drive
    # set current variables
    @over_drive = $game_party.actors[0].overdrive
    # remove old display
    self.bitmap.fill_rect(@over_drive_x+22, @over_drive_y+15, 150, 14,
    Color.new(0, 0, 0, 0))
    # draw gradient bar
    self.bitmap.draw_actor_overdrive_with_bar(actor, @over_drive_x+22,
    @over_drive_y-15, 124)
    self.bitmap.draw_text_full(@over_drive_x+76, @over_drive_y, 48, 20,
    actor.overdrive_text)
  end
  #----------------------------------------------------------------------------
  # draw_exp
  #  Draws the EXP display.
  #----------------------------------------------------------------------------
  def draw_exp
    # set current variables
    @now_exp, @next_exp = actor.now_exp, actor.next_exp
    # remove old display
    self.bitmap.fill_rect(@exp_x+32, @exp_y, 58, 14, Color.new(0, 0, 0, 0))
    # Calculate The Rate
    rate = (actor.next_exp != 0 ? actor.now_exp.to_f / actor.next_exp : 1)
    # Draw Color For The Bar
    if rate < 0.5
      color1 = Color.new(20 * rate, 60, 80, 192)
      color2 = Color.new(60 * rate, 180, 240, 192)
    elsif rate >= 0.5
      color1 = Color.new(20 + 120 * (rate-0.5), 60 + 40 * (rate-0.5), 80, 192)
      color2 = Color.new(60 + 360 * (rate-0.5), 180 + 120 * (rate-0.5), 240, 192)
    end
    # background color
    color3 = Color.new(0, 80, 0, 192)
    # draw gradient bar
    self.bitmap.gradient_bar(@exp_x+32, @exp_y-18, 57, color1, color2, color3,
    rate)
  end
  #----------------------------------------------------------------------------
  # draw_hskill
  #  Draws the hot skill display.
  #----------------------------------------------------------------------------
  def draw_hskill
    # set current variable
    @skill = actor.skill
    # remove old display
    self.bitmap.fill_rect(@hot_x, @hot_y+74, 24, 24, Color.new(0, 0, 0, 0))
    # if skill hot skill exists
    if @skill != 0
      # load bitmap
      bitmap = RPG::Cache.icon($data_skills[@skill].icon_name)
      # draw bitmap
      self.bitmap.blt(@hot_x, @hot_y+74, bitmap, Rect.new(0, 0, 24, 24))
    end
    # removes skills left to use display
    draw_lskill
  end
  #----------------------------------------------------------------------------
  # draw_lskill
  #  Draws the skills left to use display.
  #----------------------------------------------------------------------------
  def draw_lskill
    # remove old display
    self.bitmap.fill_rect(@left_x, @left_y+50, 24, 16, Color.new(0, 0, 0, 0))
    # get the number of skills left
    @skills_left = get_skills_left
    # if hot skill exists
    if @skill != nil && @skill > 0
      # if normal SP cost
      if @skills_left >= 0
        # if not enough sp to use
        if @skills_left == 0
          # set font color
          self.bitmap.font.color = Color.new(255, 0, 0)
        # if enough SP for 5 or less skill uses
        elsif @skills_left <= 5
          # set font color
          self.bitmap.font.color = Color.new(255, 255, 0)
        else
          # set font color
          self.bitmap.font.color = normal_color
        end
        # decrease font color
        self.bitmap.font.size -= 2
        # draw number how many skills left to use
        self.bitmap.draw_text_full(@left_x, @left_y+50, 24, 20,
        @skills_left.to_s, 1)
        # increase font size
        self.bitmap.font.size += 2
      # if infinite skills left
      elsif @skills_left == -1
        # set font color
        self.bitmap.font.color = Color.new(0, 255, 0)
        # increase font size
        self.bitmap.font.size += 4
        # draw "∞" skill uses left
        self.bitmap.draw_text_full(@left_x, @left_y+50, 24, 20, '∞', 1)
        # decrease font size
        self.bitmap.font.size -= 4
      end
    end
  end
  #----------------------------------------------------------------------------
  # get_skills_left
  #  Gets the number of skill usages left.
  #----------------------------------------------------------------------------
  def get_skills_left
    # if skill hot skill exists
    if @skill != nil && @skill > 0
      # if SP cost is zero
      if $data_skills[@skill].sp_cost > 0
        # get basic SP cost
        sp_cost = $data_skills[@skill].sp_cost
        # if using SP Cost Mod Status
        if $tons_version != nil && $tons_version >= 6.54 &&
            $game_system.SP_COST_MOD
          # get modified cost
          sp_cost = BlizzCFG.get_cost_mod(actor.states, sp_cost)
        end
        # infinite
        return -1 if sp_cost == 0
        # calculate skills left to use
        return @sp / sp_cost
      end
      # set flag
      return -1
    end
    # set flag
    return -2
  end
  #----------------------------------------------------------------------------
  # draw_hitem
  #  Draws the hot item display.
  #----------------------------------------------------------------------------
  def draw_hitem
    # set current variable
    @item = actor.item
    # remove old display
    self.bitmap.fill_rect(@hot_x, @hot_y+24, 24, 24, Color.new(0, 0, 0, 0))
    # if hot item exists
    if @item != 0
      # load bitmap
      bitmap = RPG::Cache.icon($data_items[@item].icon_name)
      # draw bitmap
      self.bitmap.blt(@hot_x, @hot_y+24, bitmap, Rect.new(0, 0, 24, 24))
    end
    # removes items left to use display
    draw_litem
  end
  #----------------------------------------------------------------------------
  # draw_litem
  #  Draws the items left to use display.
  #----------------------------------------------------------------------------
  def draw_litem
    # set current variable
    @items_left = $game_party.item_number(@item)
    # remove old display
    self.bitmap.fill_rect(@left_x, @left_y, 24, 16, Color.new(0, 0, 0, 0))
    # if hot item exists
    if @item != nil && @item > 0
      # if item exists and cannot be consumed
      if $data_items[@item] != nil && !$data_items[@item].consumable
        # set font color
        self.bitmap.font.color = Color.new(0, 255, 0)
        # increase font size
        self.bitmap.font.size += 4
        # draw "∞" items left
        self.bitmap.draw_text_full(@left_x, @left_y, 24, 20, '∞', 1)
        # decrease font size
        self.bitmap.font.size -= 4
      else
        # if no items left
        if @items_left == 0
          # set font color
          self.bitmap.font.color = Color.new(255, 0, 0)
        # if equal or less items left
        elsif @items_left <= 10
          # set font color
          self.bitmap.font.color = Color.new(255, 255, 0)
        else
          # set font color
          self.bitmap.font.color = normal_color
        end
        # decrease font color
        self.bitmap.font.size -= 2
        # draw number how many items left to use
        self.bitmap.draw_text_full(@left_x, @left_y, 24, 20, @items_left.to_s, 1)
        # increase font size
        self.bitmap.font.size += 2
      end
    end
  end
  #----------------------------------------------------------------------------
  # update
  #  Checks if HUD needs refreshing.
  #----------------------------------------------------------------------------
  def update
    
    # if actor doesn't exist
    if actor == nil
      # unless already drawn empty HUD
      unless @empty_hud_drawn
        # draw HUD template
        draw_basic
        # draw empty HP, SP and EXP bars
        draw_empty
        # empty HUD was drawn
        @empty_hud_drawn = true
      end
    else
      # if HUD needs refresh
      if $game_temp.hud_refresh
        # draw all data about actor
        draw_name
        draw_face
        draw_level
        draw_hp
        draw_sp
        draw_exp
        draw_over_drive
        # remove flag
        $game_temp.hud_refresh = nil
      else
        # draw data that needs to ve updated
        test_name
        test_face
        test_level
        test_hp
        test_sp
        test_exp
        test_over_drive
      end
      # empty HUD wasn't drawn
      @empty_hud_drawn = false
    end
  end
  #----------------------------------------------------------------------------
  # test_face
  #  Tests and draws the name.
  #----------------------------------------------------------------------------
  def test_face
    # draw new face if face has changed
   draw_face if actor.name != @face
  end
  #----------------------------------------------------------------------------
  # test_exp
  #  Tests and draws the name.
  #----------------------------------------------------------------------------
  def test_over_drive
    # draw new name if name has changed
    draw_over_drive if  @over_drive != $game_party.actors[0].overdrive
  end
  #----------------------------------------------------------------------------
  # test_exp
  #  Tests and draws the name.
  #----------------------------------------------------------------------------
  def test_exp
    # draw new name if name has changed
    draw_exp if actor.now_exp != @now_exp|| actor.next_exp != @next_exp
  end
  #----------------------------------------------------------------------------
  # test_name
  #  Tests and draws the name.
  #----------------------------------------------------------------------------
  def test_name
    # draw new name if name has changed
    draw_name if actor.name != @name
  end
  #----------------------------------------------------------------------------
  # test_level
  #  Tests and draws the level.
  #----------------------------------------------------------------------------
  def test_level
    # draw new level if level has changed
    draw_level if actor.level != @level
  end
  #----------------------------------------------------------------------------
  # test_hp
  #  Tests and draws the HP.
  #----------------------------------------------------------------------------
  def test_hp
    # draw new HP if HP or max HP have changed
    draw_hp if actor.hp != @hp || actor.maxhp != @maxhp
  end
  #----------------------------------------------------------------------------
  # test_sp
  #  Tests and draws the SP.
  #----------------------------------------------------------------------------
  def test_sp
    # draw new SP if SP or max SP have changed
    draw_sp if actor.sp != @sp || actor.maxsp != @maxsp
  end
  #----------------------------------------------------------------------------
  # test_hskill
  #  Tests and draws the hskill.
  #----------------------------------------------------------------------------
  def test_hskill
    # draw new skill icon if assigned skill has changed
    draw_hskill if actor.skill != @skill
  end
  #----------------------------------------------------------------------------
  # test_lskill
  #  Tests and draws the lskill.
  #----------------------------------------------------------------------------
  def test_lskill
    # draw how many skills left to use if this number has changed
    draw_lskill if get_skills_left != @skills_left
  end
  #----------------------------------------------------------------------------
  # test_hitem
  #  Tests and draws the hitem.
  #----------------------------------------------------------------------------
  def test_hitem
    # draw new item icon if assigned item has changed
    draw_hitem if actor.item != @item
  end
  #----------------------------------------------------------------------------
  # test_litem
  #  Tests and draws the litem.
  #----------------------------------------------------------------------------
  def test_litem
    # draw how many items left to use if this number has changed
    draw_litem if $game_party.item_number(@item) != @items_left
  end
  #----------------------------------------------------------------------------
  # actor
  #  Returns the party leader's battler for easier reference.
  #----------------------------------------------------------------------------
  def actor
    return $game_player.battler
  end
  
end
« Last Edit: January 17, 2010, 09:31:39 PM by nathmatt »
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script
(click to show/hide)