Guest User

Untitled

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