class VariableDisplay
###############################
# Default font face.
DEFAULTFONT="Arial"
# Default text size.
DEFAULTSIZE=22
# Default text color.
DEFAULTCOLOR=Color.new(255,255,255)
# Picture filename. Must be in Graphics/Pictures.
DEFAULTPICTURE="mapback.png"
# Default Z order.
DEFAULTZ=100
###############################
attr_reader :x,:y,:picture,:fontface
attr_reader :fontsize,:textcolor,:z,:opacity,:visible
def initialize(x,y,picture=nil)
@z=DEFAULTZ
@sprite=Sprite.new(nil)
@sprite.z=@z
@sprite2=Sprite.new(nil)
@sprite2.z=@z
@picture=nil
@picturename=picture ? picture : DEFAULTPICTURE
@bitmap=nil
@x=x
@y=y
@changeBitmap=true
@fontface=DEFAULTFONT
@fontsize=DEFAULTSIZE
@textcolor=DEFAULTCOLOR
@gettingtext=false
@opacity=255
@visible=true
@method=nil
@params=nil
privRefresh
end
def setUpdateMethod(value,params)
@method=Kernel.method(value.to_sym)
begin
@params=params.clone
rescue TypeError
@params=params
end
privRefresh
end
def dispose
@picture.dispose
@bitmap.dispose
@sprite.dispose
@sprite2.dispose
end
def z=(value)
@z=value
privRefresh
end
def fontsize=(value)
@fontsize=value
@changeBitmap=true
privRefresh
end
def fontface=(value)
@fontface=value
@changeBitmap=true
privRefresh
end
def picture=(value)
@picture=value
@changeBitmap=true
privRefresh
end
def textcolor=(value)
@textcolor=value
@changeBitmap=true
privRefresh
end
def x=(value)
@x=value
privRefresh
end
def y=(value)
@y=value
privRefresh
end
def z=(value)
@z=value
privRefresh
end
def opacity=(value)
@opacity=value
privRefresh
end
def visible=(value)
@visible=value
privRefresh
end
def update
privRefresh
end
private
def privRefresh
if @changeBitmap
@picture.dispose if @picture
@picture=RPG::Cache.picture(@picturename)
@bitmap.dispose if @bitmap
@bitmap=Bitmap.new(@picture.width,@picture.height)
@bitmap.font.name=[@fontface,"Arial","Times New Roman"]
@bitmap.font.size=@fontsize
@bitmap.font.color=@textcolor
@sprite.bitmap=@picture
@sprite2.bitmap=@bitmap
@changeBitmap=false
end
return if @gettingtext
@bitmap.clear
if @method
@gettingtext=true
text=@method.call(self,@params)
@gettingtext=false
@bitmap.draw_text(0,0,@bitmap.width,@bitmap.height,text,1)
end
@sprite.x=@x
@sprite.y=@y
@sprite.z=@z
@sprite.opacity=@opacity
@sprite.visible=@visible
@sprite2.x=@x
@sprite2.y=@y
@sprite2.z=@z
@sprite2.opacity=@opacity
@sprite2.visible=@visible
end
end
################
class Game_Temp
attr_accessor :vardisplays
end
def showVarDisplay(num,x,y)
if !$game_temp.vardisplays
$game_temp.vardisplays=[]
end
display=VariableDisplay.new(x,y)
$game_temp.vardisplays[num]=display
return display
end
def getVarDisplay(num)
return nil if !$game_temp.vardisplays
return $game_temp.vardisplays[num]
end
def hideVarDisplay(num)
display=getVarDisplay(num)
if display
display.dispose
$game_temp.vardisplays[num]=nil
end
end
def setVarDisplayUpdate(num,meth,params=nil)
display=getVarDisplay(num)
if display
display.setUpdateMethod(meth,params)
end
end
def updateVarDisplays
return if !$game_temp.vardisplays
for display in $game_temp.vardisplays
display.update if display
end
end
class Spriteset_Map
alias petero_vardisplays_Spriteset_Map_update update
def update
updateVarDisplays
petero_vardisplays_Spriteset_Map_update
end
end