RadethDart
Sponsor
Alright, thanks to Seph, I now have a good looking HUD (he cleaned my coding up A LOT), but one problem, the HUD image is not disposing when I go into another menu, so it looks really bad sitting there.
So, here is the script, and does anyone think that they could help me with it?
So, here is the script, and does anyone think that they could help me with it?
Code:
#==============================================================================
# ** Shifter HUD
#------------------------------------------------------------------------------
# SephirothSpawn
# Original Version by Joshua Long
# Version 2.0
# 2008-07-30
#==============================================================================
#==============================================================================
# ** Window_HUD
#==============================================================================
class Window_HUD < Window_Base
#--------------------------------------------------------------------------
# * Visible Switch
#--------------------------------------------------------------------------
Visible_Switch = 1
Color_HP_Start = Color.new(0, 175, 0)
Color_HP_Finish = Color.new(0, 73, 0)
Color_SP_Start = Color.new(170, 170, 0)
Color_SP_Finish = Color.new(235, 230, 0)
Color_Clear = Color.new(0, 0, 0, 0)
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
super(0, 0, 700, 700)
self.contents = Bitmap.new(width - 32, height - 32)
self.contents.font.name = 'Arial'
self.contents.font.size = 16
self.back_opacity = 0
self.opacity = 0
@sprite = Sprite.new
@sprite.z = self.z - 1
@sprite.bitmap = RPG::Cache.picture('HUD')
@sprite.x = self.x
@sprite.y = self.y
update
end
#--------------------------------------------------------------------------
# * Game Time
#--------------------------------------------------------------------------
def game_time
t = Graphics.frame_count / Graphics.frame_rate
return sprintf("%02d:%02d:%02d", t / 60 / 60, t / 60 % 60, t % 60)
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
# Saves Actor
@actor = $game_party.actors[0]
# If nil Actor
if @actor.nil?
self.contents.clear
return
end
# Draw HP
if @hp != @actor.hp || @maxhp != @actor.maxhp
@hp = @actor.hp
@maxhp = @actor.maxhp
self.contents.fill_rect(0, 409, 120, 20, Color_Clear)
self.contents.draw_seph_gradient_bar(0, 420, @hp, @maxhp, 128, 10,
Color_HP_Start, Color_HP_Finish, Color_Clear)
self.contents.draw_text(20, 409, 110, 32, "Health: " +$game_party.actors[0].hp.to_s + "/" +$game_party.actors[0].maxhp.to_s)
end
# Draw SP
if @sp != @actor.sp || @maxsp != @actor.maxsp
@sp = @actor.sp
@maxsp = @actor.maxsp
self.contents.fill_rect(20, 435, 120, 20, Color_Clear)
self.contents.draw_seph_gradient_bar(0, 440, @sp, @maxsp, 128, 10,
Color_SP_Start, Color_SP_Finish, Color_Clear)
self.contents.draw_text(20, 427, 120, 32, "Stamina: " + "#{@sp}/#{@maxsp}")
end
# Draw Name
if @name != @actor.name || @actor != @actor
@actor = $game_party.actors[0]
@name = @actor.name
self.contents.fill_rect(573, 0, 96, 81, Color_Clear)
self.contents.draw_text(573, 0, 96, 16, @name)
draw_actor_graphic(@actor, 590, 65)
end
# Draw Level
if @level != @actor.level
@level = @actor.level
self.contents.fill_rect(90, 10, 96, 16, Color_Clear)
self.contents.draw_text(90, 10, 96, 16, "Level: #{@level}")
end
# Draw STR
if @str != @actor.str
@str = @actor.str
self.contents.fill_rect(10, 12, 70, 16, Color_Clear)
self.contents.draw_text(10, 10, 96, 16, "#{$data_system.words.str}: #{@str}")
end
# Draw DEX
if @dex != @actor.dex
@dex = @actor.dex
self.contents.fill_rect(10, 26, 70, 16, Color_Clear)
self.contents.draw_text(10, 26, 96, 16, "#{$data_system.words.dex}: #{@dex}")
end
# Draw Int
if @int != @actor.int
@int = @actor.int
self.contents.fill_rect(10, 40, 70, 16, Color_Clear)
self.contents.draw_text(10, 40, 96, 16, "#{$data_system.words.int}: #{@int}")
end
# Draw Agi
if @agi != @actor.agi
@agi = @actor.agi
self.contents.fill_rect(10, 54, 70, 16, Color_Clear)
self.contents.draw_text(10, 54, 96, 16, "#{$data_system.words.agi}: #{@agi}")
end
# Draw Time
if @time != (t = $kts.time.to_s if $kts != nil)
@time = t
self.contents.fill_rect(415, 10, 96, 16, Color_Clear)
self.contents.draw_text(415, 10, 96, 16, @time, 2)
end
# Draw Gold
if @gold != $game_party.gold
@gold = $game_party.gold
self.contents.fill_rect(250, 10, 180, 16, Color_Clear)
self.contents.draw_text(320, 10, 96, 16,"#@gold", 2)
end
# Draw Weapon
if @weapon_id != @actor.weapon_id
@weapon_id = @actor.weapon_id
weapon = $data_weapons[@weapon_id]
if weapon.nil?
self.contents.fill_rect(500, 414, 100, 16, Color_Clear)
self.contents.draw_text(510, 414, 96, 16, 'Unarmed', 2)
else
icon = RPG::Cache.icon(weapon.icon_name)
self.contents.fill_rect(550, 400, 180, 100, Color_Clear)
self.contents.blt(568, 410, icon, icon.rect)
self.contents.draw_text(460, 430, 132, 16, weapon.name, 2)
end
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
# Alter Visibility
self.visible = $game_switches[Visible_Switch]
# Refresh Window
refresh
end
end
#==============================================================================
# ** Scene_Map
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias_method :seph_shifterhud_scnmap_main, :main
alias_method :seph_shifterhud_scnmap_update, :update
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def main
# Create HUD
@hud_window = Window_HUD.new
# Original Main Processing
seph_shifterhud_scnmap_main
# Dispose HUD
@hud_window.dispose
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update HUD
@hud_window.update
# Original Update
seph_shifterhud_scnmap_update
end
end
#==============================================================================
# ** Bitmap
#==============================================================================
class Bitmap
#-------------------------------------------------------------------------
# * Name : Draw Gradient Bar
# Info : Draws a Gradient Bar
# Author : SephirothSpawn
# Call Info : Four to Nince Arguments
# Integer x and y Defines Position
# Integer min and max Defines Dimensions of Bar
# Start Bar Color and End Color - Colors for Gradient Bar
# Background Bar Color
#-------------------------------------------------------------------------
def draw_seph_gradient_bar(x, y, cur, max, width = 152, height = 8,
s_color = Color.red, e_color = Color.yellow, b_color = Color.black)
# Draw Border
self.fill_rect(x, y, width, height, b_color)
# Draws Bar
for i in 1...((cur / max.to_f) * (width - 1))
c = Color.color_between(s_color, e_color, (i / width.to_f))
self.fill_rect(x + i, y + 1, 1, height - 2, c)
end
end
end
#==============================================================================
# ** Color
#==============================================================================
class Color
#-------------------------------------------------------------------------
# * Color Between Memory
#-------------------------------------------------------------------------
@color_between = {}
#-------------------------------------------------------------------------
# * Name : Color Between
# Info : Gets Color Between Two colors given the percent
# Author : SephirothSpawn
# Call Info : Start Color, Finish Color, Percent
#-------------------------------------------------------------------------
def self.color_between(color_a, color_b, percent = 0.5)
# Gets Save Key
key = [color_a, color_b, percent]
if @color_between.has_key?(key)
return @color_between[key]
end
# Calculates New Color
r = Integer(color_a.red + (color_b.red - color_a.red) * percent)
g = Integer(color_a.green + (color_b.green - color_a.green) * percent)
b = Integer(color_a.blue + (color_b.blue - color_a.blue) * percent)
a = Integer(color_a.alpha + (color_b.alpha - color_a.alpha) * percent)
# Saves Color
@color_between[key] = Color.new(r, g, b, a)
# Returns Color
return @color_between[key]
end
end