$hud_index = 1
class Spriteset_Map
# If you wish to use a background picture, put the image path below, like
# BGPATH="Graphics/Pictures/battleMessage". I recommend a 512x64 picture
BGPATH=""
USEBAR=true # Make as 'false' to don't show the blue bar
DRAWATBOTTOM=false # Make as 'true' to draw the HUD at bottom
UPDATESPERSECONDS=0.15 # More updates = more lag.
alias :initializeOldFL :initialize
alias :disposeOldFL :dispose
alias :updateOldFL :update
def initialize(map=nil)
@hud = []
initializeOldFL(map)
# Updates every time when a map is loaded (including connections)
$hud_need_refresh = true
end
def dispose
disposeOldFL
disposeHud
end
def update
updateOldFL
updateHud
end
def createHud
return if !$Trainer # Don't draw the hud if the player wasn't defined
yposition = DRAWATBOTTOM ? Graphics.height-64 : 0
@hud = []
if USEBAR # Draw the blue bar
bar=IconSprite.new(0,yposition,@viewport1)
bar.bitmap=Bitmap.new(Graphics.width,64)
bar.bitmap.fill_rect(Rect.new(0,0,bar.bitmap.width,bar.bitmap.height),
Color.new(128,128,192))
@hud.push(bar)
end
if BGPATH != "" # Draw the bar image
bgbar=IconSprite.new(0,yposition,@viewport1)
bgbar.setBitmap(BGPATH)
@hud.push(bgbar)
end
# Draw the text
baseColor=Color.new(72,72,72)
shadowColor=Color.new(160,160,160)
@hud.push(BitmapSprite.new(Graphics.width,Graphics.height,@viewport1))
text1= pbGetTimeNow.strftime("%I:%M %p")
text2=_INTL("Poké Balls: {1}",$PokemonBag.pbQuantity(PBItems::POKEBALL))
textPosition=[
[text1,Graphics.width-64,yposition,2,baseColor,shadowColor],
[text2,Graphics.width-64,yposition+32,2,baseColor,shadowColor]
]
pbSetSystemFont(@hud[-1].bitmap)
pbDrawTextPositions(@hud[-1].bitmap,textPosition)
# Draw the pokémon icons
pokemonStrings = []
bitmapOverlay = @hud[-1].bitmap
for i in 0...$Trainer.party.size
pokemon = $Trainer.party[i]
pokeicon=IconSprite.new(16+64*i,yposition-16,@viewport1)
pokeicon.setBitmap(pbPokemonIconFile(pokemon))
pokeicon.src_rect=Rect.new(0,0,64,64)
@hud.push(pokeicon)
next if pokemon.egg?
case $hud_index
when 1
x=64*i+48
y=yposition+44
pokemonStrings.push([pokemon.name,x,y,2,baseColor,shadowColor])
when 2
x=64*i+48
y=yposition+52
hpcolors=[
Color.new(24,192,32),Color.new(0,144,0), # Green
Color.new(248,184,0),Color.new(184,112,0), # Orange
Color.new(240,80,32),Color.new(168,48,56) # Red
]
hpzone=0
hpzone=1 if pokemon.hp<=(pokemon.totalhp/2).floor
hpzone=2 if pokemon.hp<=(pokemon.totalhp/4).floor
barSize=32
bitmapOverlay.fill_rect(x-barSize/2-2,y-2,
barSize+4,10,Color.new(0,0,0))
if pokemon.hp>0
bitmapOverlay.fill_rect(x-barSize/2,y,
pokemon.hp*barSize/pokemon.totalhp,2,hpcolors[hpzone*2+1])
bitmapOverlay.fill_rect(x-barSize/2,y+2,
pokemon.hp*barSize/pokemon.totalhp,4,hpcolors[hpzone*2])
end
when 3
x=64*i+48
y=yposition+52
startexp=PBExperience.pbGetStartExperience(
pokemon.level,pokemon.growthrate)
endexp=PBExperience.pbGetStartExperience(
pokemon.level+1,pokemon.growthrate)
barSize=32
bitmapOverlay.fill_rect(x-barSize/2-2,y-2,
barSize+4,10,Color.new(0,0,0))
if pokemon.level<PBExperience::MAXLEVEL
bitmapOverlay.fill_rect(x-barSize/2,y,(pokemon.exp-startexp
)*barSize/(endexp-startexp),2,Color.new(72,120,160))
bitmapOverlay.fill_rect(x-barSize/2,y+2,(pokemon.exp-startexp
)*barSize/(endexp-startexp),4,Color.new(24,144,248))
end
end
end
bitmapOverlay.font.size=18
pbDrawTextPositions(bitmapOverlay,pokemonStrings)
# Adjust z of every @hud sprite
for sprite in @hud
sprite.z+=600
end
end
def updateHud
for sprite in @hud
sprite.update
end
end
def disposeHud
for sprite in @hud
sprite.dispose
end
@hud.clear
end
end
class Scene_Map
alias :updateOldFL :update
alias :miniupdateOldFL :miniupdate
alias :createSpritesetsOldFL :createSpritesets
UPDATERATE = (Spriteset_Map::UPDATESPERSECONDS>0) ?
(Graphics.frame_rate/Spriteset_Map::UPDATESPERSECONDS).floor : 0x3FFF
def update
updateOldFL
if Input.trigger?(Input::N1)
$hud_index = 1
$hud_need_refresh = true
end
if Input.trigger?(Input::N2)
$hud_index = 2
$hud_need_refresh = true
end
if Input.trigger?(Input::N3)
$hud_index = 3
$hud_need_refresh = true
end
checkAndUpdateHud
end
def miniupdate
miniupdateOldFL
checkAndUpdateHud
end
def createSpritesets
createSpritesetsOldFL
checkAndUpdateHud
end
def checkAndUpdateHud
$hud_need_refresh = (Graphics.frame_count%UPDATERATE==0 ||
$hud_need_refresh)
if $hud_need_refresh
for s in @spritesets.values
s.disposeHud
s.createHud
end
$hud_need_refresh = false
end
end
end