The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: Sthrattoff on January 07, 2007, 07:22:02 PM

Title: A very simple Window_Base add-on
Post by: Sthrattoff on January 07, 2007, 07:22:02 PM
Hello,
after first failure, now I always tested my scripts, and this is one of my scripts.
Enjoy!

Code: [Select]
#=============================================================================
# Window_Base Add on
#-----------------------------------------------------------------------------
# ** Version 1.0
# ** Based on Tsunokiette's script
# ** Modified by Sthrattoff
#=============================================================================

# Description :
# This script add some capabilities to Window_Base by enabling user to draw hp /
# sp bar, draw faceset and support for longer hp / sp name

# Instruction :
# 1. draw_actor_face --> for drawing actor's face
# 2. draw_actor_hpbar --> for drawing actor's hp bar
# 3. draw_actor_spbar --> for drawing actor's sp bar
# 4. For face picture, the file name MUST exactly same to actor's name on
#    database and the size must be 72x72
# 5. Import the face picture to Picture

# Credits :
# See the header + Enterbrain
#=============================================================================

class Window_Base < Window
     
  #--------------------------------------------------------------------------
  # * Draw HP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #--------------------------------------------------------------------------
  def draw_actor_hp(actor, x, y, width = 144)
    # Draw "HP" text string
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 96, 32, $data_system.words.hp)
    # Calculate if there is draw space for MaxHP
    if width - 32 >= 108
      hp_x = x + width - 108
      flag = true
    elsif width - 32 >= 48
      hp_x = x + width - 48
      flag = false
    end
    # Draw HP
    self.contents.font.color = actor.hp == 0 ? knockout_color :
      actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color
    self.contents.draw_text(hp_x, y, 48, 32, actor.hp.to_s, 2)
    # Draw MaxHP
    if flag
      self.contents.font.color = normal_color
      self.contents.draw_text(hp_x + 48, y, 12, 32, "/", 1)
      self.contents.draw_text(hp_x + 60, y, 48, 32, actor.maxhp.to_s)
    end
  end
  #--------------------------------------------------------------------------
  # * Draw SP
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #     width : draw spot width
  #--------------------------------------------------------------------------
  def draw_actor_sp(actor, x, y, width = 144)
    # Draw "SP" text string
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 96, 32, $data_system.words.sp)
    # Calculate if there is draw space for MaxHP
    if width - 32 >= 108
      sp_x = x + width - 108
      flag = true
    elsif width - 32 >= 48
      sp_x = x + width - 48
      flag = false
    end
    # Draw SP
    self.contents.font.color = actor.sp == 0 ? knockout_color :
      actor.sp <= actor.maxsp / 4 ? crisis_color : normal_color
    self.contents.draw_text(sp_x, y, 48, 32, actor.sp.to_s, 2)
    # Draw MaxSP
    if flag
      self.contents.font.color = normal_color
      self.contents.draw_text(sp_x + 48, y, 12, 32, "/", 1)
      self.contents.draw_text(sp_x + 60, y, 48, 32, actor.maxsp.to_s)
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Face
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #--------------------------------------------------------------------------
  def draw_actor_face(actor, x, y)
    bitmap = RPG::Cache.picture(actor.name)
    self.contents.blt(x, y, bitmap, Rect.new(0, 0, 72, 72))
  end
  #--------------------------------------------------------------------------
  # * Draw HP Bar
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #--------------------------------------------------------------------------
  def draw_actor_hpbar(actor, x, y, w = 200)
    # Defines actor hp and maxhp
    vitality = actor.hp
    maxvitality = actor.maxhp
    # Defines color used on bar
    bordercolor = system_color
    outercolor  = Color.new(220, 10, 0, 255)
    midcolor    = Color.new(220, 35, 0, 255)
    innercolor  = Color.new(220, 60, 0, 255)
    emptycolor  = Color.new(0, 0, 0, 255)
    # Defines length of bar
    linewidth = (((vitality * 1.0) / maxvitality) * (w - 2))
    emptywidth = ((w - 1) - linewidth)
    emptyx = ((x + 1) + linewidth)
    # Drawing line and border
    borderup = Rect.new(x, y, w, 1)
    borderleft = Rect.new(x, y + 1, 1, 6)
    borderdown = Rect.new(x, y + 7, w, 1)
    borderright = Rect.new(x + w - 1, y + 1, 1, 6)
    emptyline = Rect.new(x + 1, y + 1, w - 2, 6)
    outerline = Rect.new(x + 1, y + 1, linewidth, 6)
    midline = Rect.new(x + 2, y + 2, linewidth - 2, 4)
    innerline = Rect.new(x + 3, y + 3, linewidth - 4, 2)
    # Coloring the bar
    self.contents.fill_rect(borderup, bordercolor)
    self.contents.fill_rect(borderleft, bordercolor)
    self.contents.fill_rect(borderdown, bordercolor)
    self.contents.fill_rect(borderright, bordercolor)
    self.contents.fill_rect(emptyline, emptycolor)
    self.contents.fill_rect(outerline, outercolor)
    self.contents.fill_rect(midline, midcolor)
    self.contents.fill_rect(innerline, innercolor)
  end
  #--------------------------------------------------------------------------
  # * Draw SP Bar
  #     actor : actor
  #     x     : draw spot x-coordinate
  #     y     : draw spot y-coordinate
  #--------------------------------------------------------------------------
  def draw_actor_spbar(actor, x, y, w = 200)
    # Defines actor sp and maxsp
    force = actor.sp
    maxforce = actor.maxsp
    # Defines color used on bar
    bordercolor = system_color
    outercolor = Color.new(0, 110, 180, 255)
    midcolor = Color.new(0, 135, 180, 255)
    innercolor = Color.new(0, 160, 180, 255)
    emptycolor = Color.new(0, 0, 0, 255)
    # Defines length of bar
    linewidth = (((force * 1.0) / maxforce) * (w - 2))
    emptywidth = ((w - 1) - linewidth)
    emptyx = ((x + 1) + linewidth)
    # Drawing line and border
    borderup = Rect.new(x, y, w, 1)
    borderleft = Rect.new(x, y + 1, 1, 6)
    borderdown = Rect.new(x, y + 7, w, 1)
    borderright = Rect.new(x + w - 1, y + 1, 1, 6)
    emptyline = Rect.new(x + 1, y + 1, w - 2, 6)
    outerline = Rect.new(x + 1, y + 1, linewidth, 6)
    midline = Rect.new(x + 2, y + 2, linewidth - 2, 4)
    innerline = Rect.new(x + 3, y + 3, linewidth - 4, 2)
    # Coloring the bar
    self.contents.fill_rect(borderup, bordercolor)
    self.contents.fill_rect(borderleft, bordercolor)
    self.contents.fill_rect(borderdown, bordercolor)
    self.contents.fill_rect(borderright, bordercolor)
    self.contents.fill_rect(emptyline, emptycolor)
    self.contents.fill_rect(outerline, outercolor)
    self.contents.fill_rect(midline, midcolor)
    self.contents.fill_rect(innerline, innercolor)
  end
 
end
Title: Re: A very simple Window_Base add-on
Post by: Falcon on January 07, 2007, 07:56:20 PM
Pretty cool, this could help a lot of beginning scripters :)
Title: Re: A very simple Window_Base add-on
Post by: Sthrattoff on January 08, 2007, 03:24:50 AM
Thanks ya...
Title: Re: A very simple Window_Base add-on
Post by: Arrow on January 08, 2007, 05:50:23 AM
Righteous script work bra.
Title: Re: A very simple Window_Base add-on
Post by: Blizzard on January 08, 2007, 09:06:40 AM
Keep up the good work. :)
Title: Re: A very simple Window_Base add-on
Post by: Zeriab on January 08, 2007, 03:56:12 PM
Yup, keep it up ^_^