Vendily

trainercard

Mar 14th, 2018
157
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class PokemonTrainerCardScene
  2.    
  3.     GYMLEADERS=[["Kanto Region","Brock","Rock",[:ROCKRUFF,:GEODUDE,:ROGGENROLA,:ONIX]],
  4.                             ["Kanto Region","Misty","Water",[]]] # Region name, Gym Leader, Type, Party members
  5.    
  6.   def update
  7.     pbUpdateSpriteHash(@sprites)
  8.   end
  9.  
  10.   def pbStartScene
  11.     @side = 0
  12.     @page = 0
  13.     @sprites={}
  14.     @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
  15.     @viewport.z=99999
  16.     background=pbResolveBitmap(sprintf("Graphics/trcardgraph/trcard"))
  17.     if $Trainer.isFemale? && background
  18.       addBackgroundPlane(@sprites,"bg","trcard",@viewport)
  19.     else
  20.       addBackgroundPlane(@sprites,"bg","trcard",@viewport)
  21.     end
  22.     cardexists=pbResolveBitmap(sprintf("Graphics/trcardgraph/trcard"))
  23.     @sprites["card"]=IconSprite.new(0,0,@viewport)
  24.     if $Trainer.isFemale? && cardexists
  25.       @sprites["card"].setBitmap("Graphics/trcardgraph/trcard")
  26.     else
  27.       @sprites["card"].setBitmap("Graphics/trcardgraph/trcard")
  28.     end
  29.     @sprites["overlay"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
  30.     @sprites["trainer"]=IconSprite.new(18,74,@viewport)
  31.     @sprites["trainer"].setBitmap(pbPlayerSpriteFile($Trainer.trainertype))
  32.     @sprites["trainer"].x-=(@sprites["trainer"].bitmap.width-128)/2
  33.     @sprites["trainer"].y-=(@sprites["trainer"].bitmap.height-128)
  34.     @sprites["trainer"].z=2
  35.     pbSetSystemFont(@sprites["overlay"].bitmap)
  36.     drawbadges
  37.     pbDrawTrainerCardFront
  38.     if $PokemonGlobal.trainerRecording
  39.       $PokemonGlobal.trainerRecording.play
  40.     end
  41.     pbFadeInAndShow(@sprites) { update }
  42.   end
  43.  
  44.  
  45.   def pbDrawTrainerCardFront
  46.     overlay=@sprites["overlay"].bitmap
  47.     overlay.clear
  48.     totalsec = Graphics.frame_count / Graphics.frame_rate
  49.     hour = totalsec / 60 / 60
  50.     min = totalsec / 60 % 60
  51.     time=_ISPRINTF("{1:02d}:{2:02d}",hour,min)
  52.     $PokemonGlobal.startTime=pbGetTimeNow if !$PokemonGlobal.startTime
  53.     starttime=_ISPRINTF("{1:s} {2:d}, {3:d}",
  54.        pbGetAbbrevMonthName($PokemonGlobal.startTime.mon),
  55.        $PokemonGlobal.startTime.day,
  56.        $PokemonGlobal.startTime.year)
  57.     pubid=sprintf("%05d",$Trainer.publicID($Trainer.id))
  58.     baseColor=Color.new(72,72,72)
  59.     shadowColor=Color.new(160,160,160)
  60.     wbaseColor=Color.new(255,255,255)
  61.     bbaseColor=Color.new(0,188,255)
  62.     textPositions=[
  63.        [_INTL("Trainer"),10,5,0,wbaseColor],
  64.        [_INTL("Card"),90,5,0,bbaseColor],
  65.        [_INTL("{1}",$Trainer.name),42,227,0,wbaseColor],
  66.        [_INTL("ID:"),34,256,0,wbaseColor],
  67.        [_INTL("{1}",pubid),68,256,0,bbaseColor],
  68.        [_INTL("Money"),208,65,0,wbaseColor],
  69.        [_INTL("${1}",$Trainer.money),358,65,0,wbaseColor],
  70.        [_INTL("Pokédex"),208,100,0,wbaseColor],
  71.        [_ISPRINTF("{1:d}/{2:d}",$Trainer.pokedexOwned,$Trainer.pokedexSeen),358,100,0,wbaseColor],
  72.        [_INTL("Playtime"),208,135,0,wbaseColor],
  73.        [time,358,135,0,wbaseColor],
  74.        [_INTL("Started"),208,170,0,wbaseColor],
  75.        [starttime,358,170,0,wbaseColor]
  76.     ]
  77.     pbDrawTextPositions(overlay,textPositions)
  78.   end
  79.  
  80.     def drawbadges
  81.         x = 64
  82.         y = @side==0 ? 202 : 0
  83.     imagePositions = []
  84.     for i in 0...8
  85.       if $Trainer.badges[i]
  86.         imagePositions.push(["Graphics/Pictures/Trainer Card/icon_badges",x,y,i*32,0,32,32])
  87.       end
  88.       x += 48 #play with this, I'm working without assets
  89.     end
  90.         imagePositions.push(["Graphics/trcardgraph/BadgeSelect",64+(48*@page),0,0,32,32]) if @side==1
  91.     pbDrawImagePositions(overlay,imagePositions)
  92.     end
  93.    
  94.     def pbStartSceneBack
  95.     @sprites={}
  96.     @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
  97.     @viewport.z=99999
  98.         @sprites["card"]=IconSprite.new(0,0,@viewport)
  99.     @sprites["card"].setBitmap(sprintf("Graphics/trcardgraph/%s",GYMLEADERS[@page][1]))
  100.     drawbadges
  101.         x=354
  102.         y=254
  103.         index=0
  104.         for y in 0...2
  105.             for x in 0...3
  106.                 if index<PokemonSpeciesIconSprite.new(GYMLEADERS[@page][3].length
  107.                     @sprites[sprintf("pokemon{%d}",index)]=PokemonSpeciesIconSprite.new(getID(PBSpecies,GYMLEADERS[@page][3][index]),@viewport)
  108.                     @sprites[sprintf("pokemon{%d}",index)].x-=(@sprites[sprintf("pokemon{%d}",index)].bitmap.width-x)
  109.                     @sprites[sprintf("pokemon{%d}",index)].y-=(@sprites[sprintf("pokemon{%d}",index)].bitmap.height-y)
  110.                     @sprites[sprintf("pokemon{%d}",index)].z=2
  111.                 end
  112.                 index+=1
  113.             end
  114.             x=354 # I have no clue if these numbers are right.
  115.             y+=20
  116.         end
  117.         pbDrawTrainerCardBack
  118.     if $PokemonGlobal.trainerRecording
  119.       $PokemonGlobal.trainerRecording.play
  120.     end
  121.     pbFadeInAndShow(@sprites) { update }
  122.     end
  123.  
  124.   def pbDrawTrainerCardBack
  125.     background=pbResolveBitmap(sprintf("Graphics/trcardgraph/Brock"))
  126.     overlay=@sprites["overlay"].bitmap
  127.     overlay.clear
  128.     totalsec = Graphics.frame_count / Graphics.frame_rate
  129.     hour = totalsec / 60 / 60
  130.     min = totalsec / 60 % 60
  131.     time=_ISPRINTF("{1:02d}:{2:02d}",hour,min)
  132.     $PokemonGlobal.startTime=pbGetTimeNow if !$PokemonGlobal.startTime
  133.     starttime=_ISPRINTF("{1:s} {2:d}, {3:d}",
  134.        pbGetAbbrevMonthName($PokemonGlobal.startTime.mon),
  135.        $PokemonGlobal.startTime.day,
  136.        $PokemonGlobal.startTime.year)
  137.     pubid=sprintf("%05d",$Trainer.publicID($Trainer.id))
  138.     baseColor=Color.new(72,72,72)
  139.     shadowColor=Color.new(160,160,160)
  140.     wbaseColor=Color.new(255,255,255)
  141.     bbaseColor=Color.new(0,188,255)
  142.     textPositions=[
  143.        [_INTL("Trainer"),10,5,0,wbaseColor],
  144.        [_INTL("Card"),90,5,0,bbaseColor],
  145.        [_INTL("Badges"),10,75,0,wbaseColor],
  146.        [GYMLEADERS[@page][0],6,113,0,wbaseColor],
  147.        [@page,54,153,0,wbaseColor],
  148.        [_INTL("Gym leader:"),90,163,0,wbaseColor],
  149.        [GYMLEADERS[@page][1],102,190,0,bbaseColor],
  150.        [_INTL("Specialty:"),108,217,0,wbaseColor],
  151.        [GYMLEADERS[@page][2],120,244,0,bbaseColor]
  152.     ]
  153.     pbDrawTextPositions(overlay,textPositions)
  154.   end
  155.  
  156.   def pbTrainerCard
  157.     loop do
  158.       Graphics.update
  159.       Input.update
  160.       self.update
  161.       if @side==0
  162.                 if Input.trigger?(Input::A)
  163.                     @side=1
  164.                     pbDrawTrainerCardBack
  165.                 end
  166.       elsif @side==1
  167.                 if Input.trigger?(Input::A)
  168.                     @side=0
  169.                     pbDrawTrainerCardFront
  170.                 elsif Input.trigger?(Input::LEFT)
  171.                     oldpage = @page
  172.                     @page -= 1
  173.                     @page = 1 if @page<1
  174.                     @page = 8 if @page>8
  175.                     if @page!=oldpage # Move to next page
  176.                         dorefresh = true
  177.                     end
  178.                 elsif Input.trigger?(Input::RIGHT) && !@pokemon.egg?
  179.                     oldpage = @page
  180.                     @page += 1
  181.                     @page = 1 if @page>1
  182.                     @page = 8 if @page>8
  183.                     if @page!=oldpage # Move to next page
  184.                         dorefresh = true
  185.                     end
  186.                 end
  187.       elsif Input.trigger?(Input::B)
  188.         break
  189.       end
  190.             if dorefresh
  191.                 if @side==0
  192.                     pbDrawTrainerCardFront
  193.                 else
  194.                     pbDrawTrainerCardBack
  195.                 end
  196.             end
  197.     end
  198.   end
  199.  
  200.  
  201.   def pbEndScene
  202.     pbFadeOutAndHide(@sprites) { update }
  203.     pbDisposeSpriteHash(@sprites)
  204.     @viewport.dispose
  205.   end
  206. end
  207.  
  208.  
  209.  
  210. class PokemonTrainerCard
  211.   def initialize(scene)
  212.     @scene=scene
  213.   end
  214.  
  215.   def pbStartScreen
  216.     @scene.pbStartScene
  217.     @scene.pbTrainerCard
  218.     @scene.pbEndScene
  219.   end
  220. end
RAW Paste Data