Advertisement
Guest User

Untitled

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