Vendily

new classes

Jan 22nd, 2019
173
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class AnimatedBitmapWrapperAnim
  2.   attr_reader :width
  3.   attr_reader :height
  4.   attr_reader :totalFrames
  5.   attr_reader :animationFrames
  6.   attr_reader :currentIndex
  7.   attr_reader :scale
  8.  
  9.   def initialize(file,twoframe=false)
  10.     raise "filename is nil" if file==nil
  11.     @scale = 2
  12.     @width = 0
  13.     @height = 0
  14.     @frame = 0
  15.     @frames = 2
  16.     @direction = +1
  17.     @twoframe = twoframe
  18.     @animationFinish = false
  19.     @totalFrames = 0
  20.     @currentIndex = 0
  21.     @speed = 1
  22.     @finished=false
  23.     @middle=false
  24.       # 0 - not moving at all
  25.       # 1 - normal speed
  26.       # 2 - medium speed
  27.       # 3 - slow speed
  28.     @bitmapFile=BitmapCache.load_bitmap(file)
  29.       # initializes full Pokemon bitmap
  30.     @bitmap=Bitmap.new(@bitmapFile.width,@bitmapFile.height)
  31.     @bitmap.blt(0,0,@bitmapFile,Rect.new(0,0,@bitmapFile.width,@bitmapFile.height))
  32.     @width=@bitmap.height*@scale
  33.     @height=@bitmap.height*@scale
  34.    
  35.     @totalFrames=@bitmap.width/@bitmap.height
  36.     @animationFrames=@totalFrames*@frames
  37.       # calculates total number of frames
  38.     @loop_points=[0,@totalFrames]
  39.       # first value is start, second is end
  40.    
  41.     @actualBitmap=Bitmap.new(@width,@height)
  42.     @actualBitmap.clear
  43.     @actualBitmap.stretch_blt(Rect.new(0,0,@width,@height),@bitmap,Rect.new(@currentIndex*(@width/@scale),0,@width/@scale,@height/@scale))
  44.    
  45.     end
  46.    
  47.   def length; @totalFrames; end
  48.   def disposed?; @actualBitmap.disposed?; end
  49.   def dispose; @actualBitmap.dispose; end
  50.   def copy; @actualBitmap.clone; end
  51.   def bitmap; @actualBitmap; end
  52.   def bitmap=(val); @actualBitmap=val; end
  53.   def each; end
  54.   def alterBitmap(index); return @strip[index]; end
  55.    
  56.   def prepareStrip
  57.     @strip=[]
  58.     for i in 0...@totalFrames
  59.       bitmap=Bitmap.new(@width,@height)
  60.       bitmap.stretch_blt(Rect.new(0,0,@width,@height),@bitmapFile,Rect.new((@width/@scale)*i,0,@width/@scale,@height/@scale))
  61.       @strip.push(bitmap)
  62.     end
  63.   end
  64.   def compileStrip
  65.     @bitmap.clear
  66.     for i in 0...@strip.length
  67.       @bitmap.stretch_blt(Rect.new((@width/@scale)*i,0,@width/@scale,@height/@scale),@strip[i],Rect.new(0,0,@width,@height))
  68.     end
  69.   end
  70.  
  71.   def reverse
  72.     if @direction  >  0
  73.       @direction=-1
  74.     elsif @direction < 0
  75.       @direction=+1
  76.     end
  77.   end
  78.  
  79.   def setLoop(start, finish)
  80.     @loop_points=[start,finish]
  81.   end
  82.  
  83.   def setSpeed(value)
  84.     @speed=value
  85.   end
  86.  
  87.   def update
  88.     return false if @speed < 1
  89.     case @speed
  90.     # frame skip
  91.     when 1
  92.       @frames=2
  93.     when 2
  94.       @frames=4
  95.     when 3
  96.       @frames=5
  97.     end
  98.     @frame+=1
  99.    
  100.     if @frame >=@frames
  101.       # processes animation speed
  102.       if @currentIndex < @totalFrames
  103.       @currentIndex+=@direction
  104.       end
  105.       @frame=0
  106.     end
  107.    
  108.     @currentIndex=@totalFrames if @currentIndex > @totalFrames
  109.     @finished=true if @currentIndex==@totalFrames
  110.     @middle=true if @currentIndex==@totalFrames/2
  111.    
  112.     @actualBitmap.clear
  113.     @actualBitmap.stretch_blt(Rect.new(0,0,@width,@height),@bitmap,Rect.new(@currentIndex*(@width/@scale),0,@width/@scale,@height/@scale))
  114.       # updates the actual bitmap
  115.     end
  116.    
  117.     def finished?
  118.       return @finished
  119.     end
  120.    
  121.     def middle?
  122.       return @middle
  123.     end
  124.    
  125.   # returns bitmap to original state
  126.   def deanimate
  127.     @frame=0
  128.     @currentIndex=0
  129.     @actualBitmap.clear
  130.     @actualBitmap.stretch_blt(Rect.new(0,0,@width,@height),@bitmap,Rect.new(@currentIndex*(@width/@scale),0,@width/@scale,@height/@scale))
  131.   end
  132. end
  133.  
  134. class GifAnim
  135.   attr_accessor :selected
  136.   attr_accessor :shadow
  137.   attr_accessor :sprite
  138.   attr_accessor :src_rect
  139.   attr_accessor :showshadow
  140.   attr_accessor :status
  141.   attr_reader :loaded
  142.  
  143.   def initialize(x,y,viewport=nil,repeat=false)
  144.     @viewport=viewport
  145.     @metrics=load_data("Data/metrics.dat")
  146.     @selected=0
  147.     @status=0
  148.     @loaded=false
  149.     @repeat=repeat
  150.     @showshadow=false
  151.     @altitude=0
  152.     @yposition=0
  153.     @sprite=Sprite.new(@viewport)
  154.     @sprite.x=x
  155.     @sprite.y=y
  156.  
  157.     @overlay=Sprite.new(@viewport)
  158.     @lock=false
  159.   end
  160.  
  161.   def x; @sprite.x; end
  162.   def y; @sprite.y; end
  163.   def z; @sprite.z; end
  164.   def ox; @sprite.ox; end
  165.   def oy; @sprite.oy; end
  166.   def ox=(val);;end
  167.   def oy=(val);;end
  168.   def zoom_x; @sprite.zoom_x; end
  169.   def zoom_y; @sprite.zoom_y; end
  170.   def visible; @sprite.visible; end
  171.   def opacity; @sprite.opacity; end
  172.   def width; @bitmap.width; end
  173.   def height; @bitmap.height; end
  174.   def tone; @sprite.tone; end
  175.   def bitmap; @bitmap.bitmap; end
  176.   def actualBitmap; @bitmap; end
  177.   def disposed?; @sprite.disposed?; end
  178.   def color; @sprite.color; end
  179.   def src_rect; @sprite.src_rect; end
  180.   def blend_type; @sprite.blend_type; end
  181.   def angle; @sprite.angle; end
  182.   def mirror; @sprite.mirror; end
  183.   def lock
  184.     @lock=true
  185.   end
  186.   def unlock
  187.     @lock=false
  188.   end
  189.   def bitmap=(val)
  190.     @bitmap.bitmap=val
  191.   end
  192.  
  193.   def finished?
  194.     return @bitmap.finished?
  195.   end
  196.  
  197.   def middle?
  198.     return @bitmap.middle?
  199.   end
  200.  
  201.   def x=(val)
  202.     @sprite.x=val
  203.   end
  204.   def ox=(val)
  205.     @sprite.ox=val
  206.   end
  207.   def oy=(val)
  208.     @sprite.oy=val
  209.   end
  210.   def y=(val)
  211.     @sprite.y=val
  212.   end
  213.   def zoom_x=(val)
  214.     @sprite.zoom_x=val
  215.   end
  216.   def zoom_y=(val)
  217.     @sprite.zoom_y=val
  218.   end
  219.   def visible=(val)
  220.     @sprite.visible=val
  221.   end
  222.   def opacity=(val)
  223.     @sprite.opacity=val
  224.   end
  225.   def tone=(val)
  226.     @sprite.tone=val
  227.   end
  228.   def color=(val)
  229.     @sprite.color=val
  230.   end
  231.   def blend_type=(val)
  232.     @sprite.blend_type=val
  233.   end
  234.   def angle=(val)
  235.     @sprite.angle=(val)
  236.   end
  237.   def mirror=(val)
  238.     @sprite.mirror=(val)
  239.   end
  240.   def dispose
  241.     @sprite.dispose
  242.   end
  243.   def z=(val)
  244.     @sprite.z=val
  245.   end
  246.  
  247.   def totalFrames; @bitmap.animationFrames; end
  248.   def toLastFrame; @bitmap.toFrame("last"); end
  249.   def selected; end
  250.    
  251.   def setBitmap(file)
  252.     if !@repeat
  253.     @bitmap=AnimatedBitmapWrapperAnim.new(file)
  254.     @sprite.ox=@bitmap.width/2
  255.     @sprite.oy=@bitmap.height/2
  256.     else
  257.     @bitmap=AnimatedBitmapWrapper.new(file)
  258.     @bitmap.setSpeed(2)
  259.     @sprite.oy=@bitmap.height/2
  260.     end
  261.     @sprite.bitmap=@bitmap.bitmap.clone
  262.   end
  263.  
  264.  
  265.   def update
  266.     return if @lock
  267.     if @bitmap
  268.       @bitmap.update
  269.       @sprite.bitmap=@bitmap.bitmap.clone
  270.     end
  271.   end  
  272. end
RAW Paste Data