Advertisement
Guest User

Untitled

a guest
Aug 24th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.47 KB | None | 0 0
  1. #===============================================================================
  2. # Elite Battle system
  3. # by Luka S.J.
  4. # ----------------
  5. # BitmapWrapper Script
  6. # ----------------
  7. # system is based off the original Essentials battle system, made by
  8. # Poccil & Maruno
  9. # No additional features added to AI, mechanics
  10. # or functionality of the battle system.
  11. # This update is purely cosmetic, and includes a B/W like dynamic scene with a
  12. # custom interface.
  13. #
  14. # Enjoy the script, and make sure to give credit!
  15. #-------------------------------------------------------------------------------
  16. # New animation methods for Pokemon sprites
  17. # * supports both animated, and static sprites
  18. # * does NOT support the usage of GIFs (officially)
  19. # * any one frame of sprite HAS to be of equal width and height
  20. # * all sprites need to be in 1*1 px resolution
  21. # or if you don't want to do that, you can change the value of
  22. # POKEMONSPRITESCALE to change the size of the bitmaps
  23. # * allows the use of custom looping points
  24. # Use dragonnite's(Lucy's) GIF to PNG converter to properly format your sprites
  25. #==============================================================================
  26.  
  27. # Toggle off to use the default UI in your version of Essentials
  28. USENEWUI = true
  29. # Fresh new UI (added with the "Next Gen" update
  30. NEXTGENUI = true
  31. # Toggle to show the Pokeball-styled team preview
  32. SHOWPARTYARROWS = true
  33.  
  34. # Waiting period (in seconds) before battle "camera" starts moving
  35. BATTLEMOTIONTIMER = 30
  36. #-------------------------------------------------------------------------------
  37. # Various config constants used for sprite scaling
  38. # used to scale the trainer bitmaps to 200%
  39. TRAINERSPRITESCALE = 2
  40.  
  41. # used to scale the Pokemon bitmaps to 200%
  42. POKEMONSPRITESCALE = 2
  43.  
  44. # used to scale the backsprite for battle perspective
  45. BACKSPRITESCALE = 1
  46.  
  47.  
  48. class AnimatedBitmapWrapper
  49. attr_reader :width
  50. attr_reader :height
  51. attr_reader :totalFrames
  52. attr_reader :animationFrames
  53. attr_reader :currentIndex
  54. attr_accessor :scale
  55.  
  56. def initialize(file,scale=2)
  57. raise "filename is nil" if file==nil
  58.  
  59. @scale = scale
  60. @width = 0
  61. @height = 0
  62. @frame = 0
  63. @frames = 2
  64. @direction = +1
  65. @animationFinish = false
  66. @totalFrames = 0
  67. @currentIndex = 0
  68. @speed = 1
  69. # 0 - not moving at all
  70. # 1 - normal speed
  71. # 2 - medium speed
  72. # 3 - slow speed
  73. bmp = BitmapCache.load_bitmap(file)
  74. #bmp = Bitmap.new(file)
  75. @bitmapFile=Bitmap.new(bmp.width,bmp.height); @bitmapFile.blt(0,0,bmp,Rect.new(0,0,bmp.width,bmp.height))
  76. # initializes full Pokemon bitmap
  77. @bitmap=Bitmap.new(@bitmapFile.width,@bitmapFile.height)
  78. @bitmap.blt(0,0,@bitmapFile,Rect.new(0,0,@bitmapFile.width,@bitmapFile.height))
  79. @width=@bitmapFile.height*@scale
  80. @height=@bitmap.height*@scale
  81.  
  82. @totalFrames=@bitmap.width/@bitmap.height
  83. @animationFrames=@totalFrames*@frames
  84. # calculates total number of frames
  85. @loop_points=[0,@totalFrames]
  86. # first value is start, second is end
  87.  
  88. @actualBitmap=Bitmap.new(@width,@height)
  89. @actualBitmap.clear
  90. @actualBitmap.stretch_blt(Rect.new(0,0,@width,@height),@bitmap,Rect.new(@currentIndex*(@width/@scale),0,@width/@scale,@height/@scale))
  91. end
  92. alias initialize_elite initialize
  93.  
  94. def length; @totalFrames; end
  95. def disposed?; @actualBitmap.disposed?; end
  96. def dispose; @actualBitmap.dispose; end
  97. def copy; @actualBitmap.clone; end
  98. def bitmap; @actualBitmap; end
  99. def bitmap=(val); @actualBitmap=val; end
  100. def each; end
  101. def alterBitmap(index); return @strip[index]; end
  102.  
  103. def prepareStrip
  104. @strip=[]
  105. for i in 0...@totalFrames
  106. bitmap=Bitmap.new(@width,@height)
  107. bitmap.stretch_blt(Rect.new(0,0,@width,@height),@bitmapFile,Rect.new((@width/@scale)*i,0,@width/@scale,@height/@scale))
  108. @strip.push(bitmap)
  109. end
  110. end
  111. def compileStrip
  112. @bitmap.clear
  113. for i in 0...@strip.length
  114. @bitmap.stretch_blt(Rect.new((@width/@scale)*i,0,@width/@scale,@height/@scale),@strip[i],Rect.new(0,0,@width,@height))
  115. end
  116. end
  117.  
  118. def reverse
  119. if @direction > 0
  120. @direction=-1
  121. elsif @direction < 0
  122. @direction=+1
  123. end
  124. end
  125.  
  126. def setLoop(start, finish)
  127. @loop_points=[start,finish]
  128. end
  129.  
  130. def setSpeed(value)
  131. @speed=value
  132. end
  133.  
  134. def toFrame(frame)
  135. if frame.is_a?(String)
  136. if frame=="last"
  137. frame=@totalFrames-1
  138. else
  139. frame=0
  140. end
  141. end
  142. frame=@totalFrames if frame > @totalFrames
  143. frame=0 if frame < 0
  144. @currentIndex=frame
  145. @actualBitmap.clear
  146. @actualBitmap.stretch_blt(Rect.new(0,0,@width,@height),@bitmap,Rect.new(@currentIndex*(@width/@scale),0,@width/@scale,@height/@scale))
  147. end
  148.  
  149. def play
  150. return if @currentIndex >= @loop_points[1]-1
  151. self.update
  152. end
  153.  
  154. def finished?
  155. return (@currentIndex==@totalFrames-1)
  156. end
  157.  
  158. def update
  159. return false if @actualBitmap.disposed?
  160. return false if @speed < 1
  161. case @speed
  162. # frame skip
  163. when 1
  164. @frames=2
  165. when 2
  166. @frames=4
  167. when 3
  168. @frames=5
  169. end
  170. @frame+=1
  171.  
  172. if @frame >=@frames
  173. # processes animation speed
  174. @currentIndex+=@direction
  175. @currentIndex=@loop_points[0] if @currentIndex >=@loop_points[1]
  176. @currentIndex=@loop_points[1]-1 if @currentIndex < @loop_points[0]
  177. @frame=0
  178. end
  179. @actualBitmap.clear
  180. @actualBitmap.stretch_blt(Rect.new(0,0,@width,@height),@bitmap,Rect.new(@currentIndex*(@width/@scale),0,@width/@scale,@height/@scale))
  181. # updates the actual bitmap
  182. end
  183. alias update_elite update
  184.  
  185. # returns bitmap to original state
  186. def deanimate
  187. @frame=0
  188. @currentIndex=0
  189. @actualBitmap.clear
  190. @actualBitmap.stretch_blt(Rect.new(0,0,@width,@height),@bitmap,Rect.new(@currentIndex*(@width/@scale),0,@width/@scale,@height/@scale))
  191. end
  192. end
  193. #===============================================================================
  194. # New Sprite class to utilize the animated bitmap wrappers
  195. #===============================================================================
  196. class BitmapWrapperSprite < Sprite
  197.  
  198. def setBitmap(file,scale=POKEMONSPRITESCALE)
  199. gif=(File.extname(pbResolveBitmap(file))==".gif") ? true : false
  200. if gif
  201. @animatedBitmap = AnimatedBitmap.new(file)
  202. else
  203. @animatedBitmap = AnimatedBitmapWrapper.new(file,scale)
  204. end
  205. self.bitmap = @animatedBitmap.bitmap.clone
  206. end
  207.  
  208. def setSpeciesBitmap(species,female=false,form=0,shiny=false,shadow=false,back=false,egg=false)
  209. if species > 0
  210. pokemon = PokeBattle_Pokemon.new(species,5)
  211. @animatedBitmap = pbLoadPokemonBitmapSpecies(pokemon, species, back)
  212. else
  213. @animatedBitmap = AnimatedBitmapWrapper.new("Graphics/Battlers/000")
  214. end
  215. self.bitmap = @animatedBitmap.bitmap.clone
  216. end
  217.  
  218. def play
  219. @animatedBitmap.play
  220. self.bitmap = @animatedBitmap.bitmap.clone
  221. end
  222.  
  223. def finished?; return @animatedBitmap.finished?; end
  224. def animatedBitmap; return @animatedBitmap; end
  225.  
  226. alias update_wrapper update
  227. def update
  228. update_wrapper
  229. return if @animatedBitmap.nil?
  230. @animatedBitmap.update
  231. self.bitmap = @animatedBitmap.bitmap.clone
  232. end
  233.  
  234. end
  235.  
  236. class AnimatedSpriteWrapper < BitmapWrapperSprite; end
  237. #===============================================================================
  238. # Aliases old PokemonBitmap generating functions and creates new ones,
  239. # utilizing the new BitmapWrapper
  240. #===============================================================================
  241.  
  242. alias pbLoadPokemonBitmap_old pbLoadPokemonBitmap
  243. def pbLoadPokemonBitmap(pokemon, back=false,scale=POKEMONSPRITESCALE)
  244. return pbLoadPokemonBitmapSpecies(pokemon,pokemon.species,back,scale)
  245. end
  246.  
  247. # Note: Returns an AnimatedBitmap, not a Bitmap
  248. alias pbLoadPokemonBitmapSpecies_old pbLoadPokemonBitmapSpecies
  249. def pbLoadPokemonBitmapSpecies(pokemon, species, back=false, scale=POKEMONSPRITESCALE)
  250. ret=nil
  251. pokemon = pokemon.pokemon if pokemon.respond_to?(:pokemon)
  252. if pokemon.isEgg?
  253. bitmapFileName=sprintf("Graphics/Battlers/%segg",getConstantName(PBSpecies,species)) rescue nil
  254. if !pbResolveBitmap(bitmapFileName)
  255. bitmapFileName=sprintf("Graphics/Battlers/%03degg",species)
  256. if !pbResolveBitmap(bitmapFileName)
  257. bitmapFileName=sprintf("Graphics/Battlers/egg")
  258. end
  259. end
  260. bitmapFileName=pbResolveBitmap(bitmapFileName)
  261. else
  262. bitmapFileName=pbCheckPokemonBitmapFiles([species,back,
  263. (pokemon.isFemale?),
  264. pokemon.isShiny?,
  265. (pokemon.form rescue 0),
  266. (pokemon.isShadow? rescue false)])
  267. end
  268. gif=(File.extname(bitmapFileName)==".gif") ? true : false
  269. if gif
  270. alterBitmap=(MultipleForms.getFunction(species,"alterBitmap") rescue nil)
  271. if bitmapFileName && alterBitmap
  272. animatedBitmap=AnimatedBitmap.new(bitmapFileName)
  273. copiedBitmap=animatedBitmap.copy
  274. animatedBitmap.dispose
  275. copiedBitmap.each {|bitmap|
  276. alterBitmap.call(pokemon,bitmap)
  277. }
  278. ret=copiedBitmap
  279. elsif bitmapFileName
  280. ret=AnimatedBitmap.new(bitmapFileName)
  281. end
  282. else
  283. animatedBitmap=AnimatedBitmapWrapper.new(bitmapFileName,scale) if bitmapFileName
  284. ret=animatedBitmap if bitmapFileName
  285. # Full compatibility with the alterBitmap methods is maintained
  286. # but unless the alterBitmap method gets rewritten and sprite animations get
  287. # hardcoded in the system, the bitmap alterations will not function properly
  288. # as they will not account for the sprite animation itself
  289.  
  290. # alterBitmap methods for static sprites will work just fine
  291. alterBitmap=(MultipleForms.getFunction(species,"alterBitmap") rescue nil) if !pokemon.isEgg? && animatedBitmap && animatedBitmap.totalFrames==1 # remove this totalFrames clause to allow for dynamic sprites too
  292. if bitmapFileName && alterBitmap
  293. animatedBitmap.prepareStrip
  294. for i in 0...animatedBitmap.totalFrames
  295. alterBitmap.call(pokemon,animatedBitmap.alterBitmap(i))
  296. end
  297. animatedBitmap.compileStrip
  298. ret=animatedBitmap
  299. end
  300. end
  301. return ret
  302. end
  303. #===============================================================================
  304. # Pokedex Fix
  305. #===============================================================================
  306. unless defined?(SCREENDUALHEIGHT) # Check to make sure not to overwrite Klein's stuff
  307. class PokedexFormScene
  308. alias pbStartScene_fix pbStartScene
  309. def pbStartScene(species)
  310. return pbStartScene_fix(species) if INCLUDEGEN6
  311. @skipupdate = true
  312. pbStartScene_fix(species)
  313. viewport = (INCLUDEGEN6 && @viewport2) ? @viewport2 : @viewport
  314. @sprites["front"].dispose if @sprites["front"]
  315. @sprites["front"] = BitmapWrapperSprite.new(viewport)
  316. @sprites["back"].dispose if @sprites["back"]
  317. @sprites["back"] = BitmapWrapperSprite.new(viewport)
  318. @skipupdate = false
  319. pbUpdate
  320. return true
  321. end
  322.  
  323. alias pbUpdate_old pbUpdate
  324. def pbUpdate
  325. return pbUpdate_old if INCLUDEGEN6
  326. return if @skipupdate
  327. @sprites["info"].bitmap.clear
  328. pbSetSystemFont(@sprites["info"].bitmap)
  329. name=""
  330. for i in @available
  331. if i[1]==@gender && i[2]==@form
  332. name=i[0]
  333. break
  334. end
  335. end
  336. text=[
  337. [_INTL("{1}",PBSpecies.getName(@species)),
  338. (Graphics.width+72)/2,Graphics.height-86,2,
  339. Color.new(88,88,80),Color.new(168,184,184)],
  340. [_INTL("{1}",name),
  341. (Graphics.width+72)/2,Graphics.height-54,2,
  342. Color.new(88,88,80),Color.new(168,184,184)],
  343. ]
  344. pbDrawTextPositions(@sprites["info"].bitmap,text)
  345. frontBitmap=pbCheckPokemonBitmapFiles([@species,false,(@gender==1),false,@form,false])
  346. if frontBitmap
  347. @sprites["front"].setBitmap(frontBitmap)
  348. end
  349. backBitmap=pbCheckPokemonBitmapFiles([@species,true,(@gender==1),false,@form,false])
  350. if backBitmap
  351. @sprites["back"].setBitmap(backBitmap)
  352. end
  353. metrics=load_data("Data/metrics.dat")
  354. backMetric=metrics[0][@species]
  355. pbPositionPokemonSprite(@sprites["front"],74,96)
  356. pbPositionPokemonSprite(@sprites["back"],310,96)
  357. end
  358. end
  359.  
  360. class PokemonPokedexScene
  361. alias pbStartScene_fix pbStartScene
  362. def pbStartScene
  363. return pbStartScene_fix if INCLUDEGEN6 || defined?(SCREENDUALHEIGHT)
  364. @sprites={}
  365. @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
  366. @viewport.z=99999
  367. @sprites["pokedex"]=Window_Pokedex.new(214,18,268,332)
  368. @sprites["pokedex"].viewport=@viewport
  369. @sprites["dexentry"]=IconSprite.new(0,0,@viewport)
  370. @sprites["dexentry"].setBitmap(_INTL("Graphics/Pictures/pokedexEntry"))
  371. @sprites["dexentry"].visible=false
  372. @sprites["overlay"]=BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
  373. pbSetSystemFont(@sprites["overlay"].bitmap)
  374. @sprites["overlay"].x=0
  375. @sprites["overlay"].y=0
  376. @sprites["overlay"].visible=false
  377. @sprites["searchtitle"]=Window_AdvancedTextPokemon.newWithSize("",2,-18,Graphics.width,64,@viewport)
  378. @sprites["searchtitle"].windowskin=nil
  379. @sprites["searchtitle"].baseColor=Color.new(248,248,248)
  380. @sprites["searchtitle"].shadowColor=Color.new(0,0,0)
  381. @sprites["searchtitle"].text=_ISPRINTF("<ac>Search Mode</ac>")
  382. @sprites["searchtitle"].visible=false
  383. @sprites["searchlist"]=Window_ComplexCommandPokemon.newEmpty(-6,32,284,352,@viewport)
  384. @sprites["searchlist"].baseColor=Color.new(248,248,248)
  385. @sprites["searchlist"].shadowColor=Color.new(0,0,0)
  386. @sprites["searchlist"].visible=false
  387. @sprites["auxlist"]=Window_CommandPokemonWhiteArrow.newEmpty(256,32,284,224,@viewport)
  388. @sprites["auxlist"].baseColor=Color.new(248,248,248)
  389. @sprites["auxlist"].shadowColor=Color.new(0,0,0)
  390. @sprites["auxlist"].visible=false
  391. @sprites["messagebox"]=Window_UnformattedTextPokemon.newWithSize("",254,256,264,128,@viewport)
  392. @sprites["messagebox"].baseColor=Color.new(248,248,248)
  393. @sprites["messagebox"].shadowColor=Color.new(0,0,0)
  394. @sprites["messagebox"].visible=false
  395. @sprites["messagebox"].letterbyletter=false
  396. @sprites["dexname"]=Window_AdvancedTextPokemon.newWithSize("",2,-18,Graphics.width,64,@viewport)
  397. @sprites["dexname"].windowskin=nil
  398. @sprites["dexname"].baseColor=Color.new(248,248,248)
  399. @sprites["dexname"].shadowColor=Color.new(0,0,0)
  400. @sprites["species"]=Window_AdvancedTextPokemon.newWithSize("",38,22,160,64,@viewport)
  401. @sprites["species"].windowskin=nil
  402. @sprites["species"].baseColor=Color.new(88,88,80)
  403. @sprites["species"].shadowColor=Color.new(168,184,184)
  404. @sprites["seen"]=Window_AdvancedTextPokemon.newWithSize("",38,242,164,64,@viewport)
  405. @sprites["seen"].windowskin=nil
  406. @sprites["seen"].baseColor=Color.new(88,88,80)
  407. @sprites["seen"].shadowColor=Color.new(168,184,184)
  408. @sprites["owned"]=Window_AdvancedTextPokemon.newWithSize("",38,282,164,64,@viewport)
  409. @sprites["owned"].windowskin=nil
  410. @sprites["owned"].baseColor=Color.new(88,88,80)
  411. @sprites["owned"].shadowColor=Color.new(168,184,184)
  412. addBackgroundPlane(@sprites,"searchbg",_INTL("pokedexSearchbg"),@viewport)
  413. @sprites["searchbg"].visible=false
  414. @searchResults=false
  415. addBackgroundPlane(@sprites,"background",_INTL("pokedexbg"),@viewport)
  416. @sprites["slider"]=IconSprite.new(Graphics.width-44,62,@viewport)
  417. @sprites["slider"].setBitmap(sprintf("Graphics/Pictures/pokedexSlider"))
  418. @sprites["icon"] = BitmapWrapperSprite.new(@viewport)
  419. @sprites["icon"].x = 116
  420. @sprites["icon"].y = 164
  421. @sprites["entryicon"]=PokemonSprite.new(@viewport)
  422. pbRefreshDexList($PokemonGlobal.pokedexIndex[pbGetSavePositionIndex])
  423. pbDeactivateWindows(@sprites)
  424. pbFadeInAndShow(@sprites)
  425. end
  426.  
  427. alias pbChangeToDexEntry_old pbChangeToDexEntry
  428. def pbChangeToDexEntry(species)
  429. return pbChangeToDexEntry_old(species) if INCLUDEGEN6 || defined?(SCREENDUALHEIGHT)
  430. @sprites["dexentry"].visible=true
  431. @sprites["overlay"].visible=true
  432. @sprites["overlay"].bitmap.clear
  433. basecolor=Color.new(88,88,80)
  434. shadowcolor=Color.new(168,184,184)
  435. indexNumber=pbGetRegionalNumber(pbGetPokedexRegion(),species)
  436. indexNumber=species if indexNumber==0
  437. indexNumber-=1 if DEXINDEXOFFSETS.include?(pbGetPokedexRegion)
  438. textpos=[
  439. [_ISPRINTF("{1:03d}{2:s} {3:s}",indexNumber," ",PBSpecies.getName(species)),
  440. 244,40,0,Color.new(248,248,248),Color.new(0,0,0)],
  441. [sprintf(_INTL("HT")),318,158,0,basecolor,shadowcolor],
  442. [sprintf(_INTL("WT")),318,190,0,basecolor,shadowcolor]
  443. ]
  444. if $Trainer.owned[species]
  445. dexdata=pbOpenDexData
  446. pbDexDataOffset(dexdata,species,8)
  447. type1=dexdata.fgetb
  448. type2=dexdata.fgetb
  449. pbDexDataOffset(dexdata,species,33)
  450. height=dexdata.fgetw
  451. weight=dexdata.fgetw
  452. dexdata.close
  453. kind=pbGetMessage(MessageTypes::Kinds,species)
  454. dexentry=pbGetMessage(MessageTypes::Entries,species)
  455. inches=(height/0.254).round
  456. pounds=(weight/0.45359).round
  457. textpos.push([_ISPRINTF("{1:s} Pokémon",kind),244,74,0,basecolor,shadowcolor])
  458. if pbGetCountry()==0xF4 # If the user is in the United States
  459. textpos.push([_ISPRINTF("{1:d}'{2:02d}\"",inches/12,inches%12),456,158,1,basecolor,shadowcolor])
  460. textpos.push([_ISPRINTF("{1:4.1f} lbs.",pounds/10.0),490,190,1,basecolor,shadowcolor])
  461. else
  462. textpos.push([_ISPRINTF("{1:.1f} m",height/10.0),466,158,1,basecolor,shadowcolor])
  463. textpos.push([_ISPRINTF("{1:.1f} kg",weight/10.0),478,190,1,basecolor,shadowcolor])
  464. end
  465. drawTextEx(@sprites["overlay"].bitmap,
  466. 42,240,Graphics.width-(42*2),4,dexentry,basecolor,shadowcolor)
  467. footprintfile=pbPokemonFootprintFile(species)
  468. if footprintfile
  469. footprint=BitmapCache.load_bitmap(footprintfile)
  470. @sprites["overlay"].bitmap.blt(226,136,footprint,footprint.rect)
  471. footprint.dispose
  472. end
  473. pbDrawImagePositions(@sprites["overlay"].bitmap,[["Graphics/Pictures/pokedexOwned",212,42,0,0,-1,-1]])
  474. typebitmap=AnimatedBitmap.new(_INTL("Graphics/Pictures/pokedexTypes"))
  475. type1rect=Rect.new(0,type1*32,96,32)
  476. type2rect=Rect.new(0,type2*32,96,32)
  477. @sprites["overlay"].bitmap.blt(296,118,typebitmap.bitmap,type1rect)
  478. @sprites["overlay"].bitmap.blt(396,118,typebitmap.bitmap,type2rect) if type1!=type2
  479. typebitmap.dispose
  480. else
  481. textpos.push([_INTL("????? Pokémon"),244,74,0,basecolor,shadowcolor])
  482. if pbGetCountry()==0xF4 # If the user is in the United States
  483. textpos.push([_INTL("???'??\""),456,158,1,basecolor,shadowcolor])
  484. textpos.push([_INTL("????.? lbs."),490,190,1,basecolor,shadowcolor])
  485. else
  486. textpos.push([_INTL("????.? m"),466,158,1,basecolor,shadowcolor])
  487. textpos.push([_INTL("????.? kg"),478,190,1,basecolor,shadowcolor])
  488. end
  489. end
  490. pbDrawTextPositions(@sprites["overlay"].bitmap,textpos)
  491. file=pbPokemonBitmapFile(species,false)
  492. gif=(File.extname(pbResolveBitmap(file))==".gif") ? true : false
  493. if gif
  494. pkmnbitmap=AnimatedBitmap.new(file)
  495. else
  496. pkmnbitmap=AnimatedBitmapWrapper.new(file)
  497. end
  498. @sprites["overlay"].bitmap.blt(
  499. 40-(pkmnbitmap.width-128)/2,
  500. 70-(pkmnbitmap.height-128)/2,
  501. pkmnbitmap.bitmap,pkmnbitmap.bitmap.rect)
  502. pkmnbitmap.dispose
  503. pbPlayCry(species)
  504. end
  505. end
  506. end
  507. #===============================================================================
  508. # Just a little utility I made to load up all the correct files from a directory
  509. #===============================================================================
  510. def readDirectoryFiles(directory,formats)
  511. files=[]
  512. Dir.chdir(directory){
  513. for i in 0...formats.length
  514. Dir.glob(formats[i]){|f| files.push(f) }
  515. end
  516. }
  517. return files
  518. end
  519. #===============================================================================
  520. # Use this to automatically scale down any 2*2 px resolution sprites you may
  521. # have, to the smaller 1*1 px resolution, for full compatibility with the new
  522. # bitmap wrappers utilized in displaying and animating sprites
  523. #===============================================================================
  524. def resizePngs(scale=0.5)
  525. destination="./Convert/"
  526. Dir.mkdir(destination+"New/") if !FileTest.directory?(destination+"New/")
  527. search_for=["*.png"]
  528.  
  529. @files=readDirectoryFiles(destination,search_for)
  530. @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
  531. @viewport.z=999999
  532.  
  533. @bar=Sprite.new(@viewport)
  534. @bar.bitmap=Bitmap.new(Graphics.width,34)
  535. pbSetSystemFont(@bar.bitmap)
  536.  
  537. for i in 0...@files.length
  538. @files[i]=@files[i].gsub(/.png/) {""}
  539. end
  540.  
  541. return false if !Kernel.pbConfirmMessage(_INTL("There is a total of #{@files.length} PNG(s) available for conversion. Would you like to begin the process?"))
  542. for i in 0...@files.length
  543. file=@files[i]
  544.  
  545. width=((i*1.000)/@files.length)*Graphics.width
  546. @bar.bitmap.clear
  547. @bar.bitmap.fill_rect(0,0,Graphics.width,34,Color.new(255,255,255))
  548. @bar.bitmap.fill_rect(0,0,Graphics.width,32,Color.new(0,0,0))
  549. @bar.bitmap.fill_rect(0,0,width,32,Color.new(25*4,90*2,25*4))
  550. text=[["#{i}/#{@files.length}",Graphics.width/2,2,2,Color.new(255,255,255),nil]]
  551. pbDrawTextPositions(@bar.bitmap,text)
  552.  
  553. next if RTP.exists?("#{destination}New/#{file}.png")
  554.  
  555. sprite=pbBitmap("#{destination}#{file}.png")
  556. width=sprite.width
  557. height=sprite.height
  558.  
  559. bitmap=Bitmap.new(width*scale,height*scale)
  560. bitmap.stretch_blt(Rect.new(0,0,width*scale,height*scale),sprite,Rect.new(0,0,width,height))
  561. bitmap.saveToPng("#{destination}New/#{file}.png")
  562. sprite.dispose
  563. pbWait(1)
  564. RPG::Cache.clear
  565. end
  566. @bar.dispose
  567. @viewport.dispose
  568. Kernel.pbMessage(_INTL("Done!"))
  569. end
  570. #===============================================================================
  571. # Utility to cut sprite reels into static ones
  572. #===============================================================================
  573. def pbCutSpriteReel
  574. dir="./Graphics/Battlers/"
  575. new_dir=dir+"Cut/"
  576. Dir.mkdir(new_dir) if !FileTest.directory?(new_dir)
  577. search_for=["*.png"]
  578.  
  579. @files=readDirectoryFiles(dir,search_for)
  580. @viewport=Viewport.new(0,0,Graphics.width,Graphics.height)
  581. @viewport.z=999999
  582.  
  583. @bar=Sprite.new(@viewport)
  584. @bar.bitmap=Bitmap.new(Graphics.width,34)
  585. pbSetSystemFont(@bar.bitmap)
  586.  
  587. for i in 0...@files.length
  588. @files[i]=@files[i].gsub(/.png/) {""}
  589. end
  590.  
  591. return false if !Kernel.pbConfirmMessage(_INTL("There is a total of #{@files.length} PNG(s) available for conversion. Would you like to begin the process?"))
  592. for i in 0...@files.length
  593. file=@files[i]
  594.  
  595. width=((i*1.000)/@files.length)*Graphics.width
  596. @bar.bitmap.clear
  597. @bar.bitmap.fill_rect(0,0,Graphics.width,34,Color.new(255,255,255))
  598. @bar.bitmap.fill_rect(0,0,Graphics.width,32,Color.new(0,0,0))
  599. @bar.bitmap.fill_rect(0,0,width,32,Color.new(25*4,90*2,25*4))
  600. text=[["#{i}/#{@files.length}",Graphics.width/2,2,2,Color.new(255,255,255),nil]]
  601. pbDrawTextPositions(@bar.bitmap,text)
  602.  
  603. next if RTP.exists?("#{new_dir}#{file}.png")
  604.  
  605. sprite=pbBitmap("#{dir}#{file}.png")
  606. width=sprite.width
  607. height=sprite.height
  608.  
  609. bitmap=Bitmap.new(height,height)
  610. bitmap.blt(0,0,sprite,Rect.new(0,0,height,height))
  611. bitmap.saveToPng("#{new_dir}#{file}.png")
  612. sprite.dispose
  613. pbWait(1)
  614. RPG::Cache.clear
  615. end
  616. @bar.dispose
  617. @viewport.dispose
  618. Kernel.pbMessage(_INTL("Done! All your converted sprites are saved in the Graphics/Battlers/Cut/ folder."))
  619. end
  620. #-------------------------------------------------------------------------------
  621. # Draws a circle inside of the bitmap rectangle
  622. #-------------------------------------------------------------------------------
  623. class Bitmap
  624.  
  625. def drawCircle(color=Color.new(255,255,255),r=(self.width/2),tx=(self.width/2),ty=(self.height/2),hollow=false)
  626. self.clear
  627. # basic circle formula
  628. # (x - tx)**2 + (y - ty)**2 = r**2
  629. for x in 0...self.width
  630. y1 = -Math.sqrt(r**2 - (x - tx)**2).to_i + ty
  631. y2 = Math.sqrt(r**2 - (x - tx)**2).to_i + ty
  632. if hollow
  633. self.set_pixel(x,y1,color)
  634. self.set_pixel(x,y2,color)
  635. else
  636. for y in y1..y2
  637. self.set_pixel(x,y,color)
  638. end
  639. end
  640. end
  641. end
  642.  
  643. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement