class TrainerBattleLister
def initialize(selection,includeNew)
@sprite=IconSprite.new
@sprite.bitmap=nil
@sprite.z=2
@selection=selection
@commands=[]
@ids=[]
@includeNew=includeNew
@trainers=nil
@index=0
end
def setViewport(viewport)
@sprite.viewport=viewport
end
def startIndex
return @index
end
def commands
@commands.clear
@ids.clear
@trainers=load_data("Data/trainers.dat")
if @includeNew
@commands.push(_ISPRINTF("[NEW TRAINER BATTLE]"))
@ids.push(-1)
end
@trainers.length.times do |i|
next if !@trainers[i]
# Index: TrainerType TrainerName (version)
@commands.push(_ISPRINTF("{1:3d}: {2:s} {3:s} ({4:s})",i,
PBTrainers.getName(@trainers[i][0]),@trainers[i][1],@trainers[i][4])) # Trainer's name must not be localized
# Trainer type ID
@ids.push(@trainers[i][0])
end
@index=@selection
@[email protected] if @index>[email protected]
@index=0 if @index<0
return @commands
end
def value(index)
return nil if (index<0)
return [-1,nil] if index==0 && @includeNew
realIndex=(@includeNew) ? index-1 : index
return [realIndex,@trainers[realIndex]]
end
def dispose
@sprite.bitmap.dispose if @sprite.bitmap
@sprite.dispose
end
def refresh(index)
@sprite.bitmap.dispose if @sprite.bitmap
return if index<0
begin
@sprite.setBitmap(sprintf("Graphics/Characters/trainer%03d",@ids[index]),0)
rescue
@sprite.setBitmap(nil)
end
[email protected]
[email protected]
sx=(Graphics.width-256).to_f()/ww
sy=(Graphics.height-64).to_f()/wh
if sx<1.0 || sy<1.0
if sx>sy
ww=sy*ww
wh=(Graphics.height-64).to_f()
else
wh=sx*wh
ww=(Graphics.width-256).to_f()
end
end
@sprite.zoom_x=ww*1.0/@sprite.bitmap.width
@sprite.zoom_y=wh*1.0/@sprite.bitmap.height
@sprite.x=(Graphics.width-((Graphics.width-256)/2))-(ww/2)
@sprite.y=(Graphics.height-((Graphics.height-64)/2))-(wh/2)
end
end