Advertisement
Guest User

Untitled

a guest
May 23rd, 2025
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 36.71 KB | None | 0 0
  1. class Window_Pokedex < Window_DrawableCommand
  2. def initialize(x,y,width,height,viewport)
  3. @commands = []
  4. super(x,y,width,height,viewport)
  5. @selarrow = AnimatedBitmap.new("Graphics/Pictures/Pokedex/cursor_list")
  6. @pokeballOwn = AnimatedBitmap.new("Graphics/Pictures/Pokedex/icon_own")
  7. @pokeballSeen = AnimatedBitmap.new("Graphics/Pictures/Pokedex/icon_seen")
  8. self.baseColor = Color.new(248,248,248)
  9. self.shadowColor = Color.new(0,0,0,0)
  10. self.windowskin = nil
  11. end
  12.  
  13. def commands=(value)
  14. @commands = value
  15. refresh
  16. end
  17.  
  18. def dispose
  19. @pokeballOwn.dispose
  20. @pokeballSeen.dispose
  21. super
  22. end
  23.  
  24. def species
  25. return (@commands.length==0) ? 0 : @commands[self.index][0]
  26. end
  27.  
  28. def itemCount
  29. return @commands.length
  30. end
  31.  
  32. def drawItem(index,_count,rect)
  33. return if index>=self.top_row+self.page_item_max
  34. rect = Rect.new(rect.x+16,rect.y+2,rect.width-16,rect.height)
  35. species = @commands[index][0]
  36. indexNumber = @commands[index][4]
  37. indexNumber -= 1 if @commands[index][5]
  38. if $Trainer.seen[species]
  39. if $Trainer.owned[species]
  40. pbCopyBitmap(self.contents,@pokeballOwn.bitmap,rect.x-14,rect.y+14)
  41. else
  42. pbCopyBitmap(self.contents,@pokeballSeen.bitmap,rect.x-14,rect.y+14)
  43. end
  44. text = @commands[index][1]
  45. else
  46. text = "-----"
  47. end
  48. pbDrawShadowText(self.contents,rect.x+2,rect.y+6,rect.width,rect.height,
  49. text,self.baseColor,self.shadowColor)
  50. end
  51.  
  52. def refresh
  53. @item_max = itemCount
  54. dwidth = self.width-self.borderX
  55. dheight = self.height-self.borderY
  56. self.contents = pbDoEnsureBitmap(self.contents,dwidth,dheight)
  57. self.contents.clear
  58. for i in 0...@item_max
  59. next if i<self.top_item || i>self.top_item+self.page_item_max
  60. drawItem(i,@item_max,itemRect(i))
  61. end
  62. drawCursor(self.index,itemRect(self.index))
  63. end
  64.  
  65. def update
  66. super
  67. @uparrow.visible = false
  68. @downarrow.visible = false
  69. end
  70. end
  71.  
  72.  
  73.  
  74. class PokedexSearchSelectionSprite < SpriteWrapper
  75. attr_reader :index
  76. #attr_accessor :cmds
  77. #attr_accessor :minmax
  78.  
  79. def initialize(viewport=nil)
  80. super(viewport)
  81. @selbitmap = AnimatedBitmap.new("Graphics/Pictures/selarrow_white")
  82. self.bitmap = @selbitmap.bitmap
  83. self.mode = -1
  84. @index = 0
  85. refresh
  86. end
  87.  
  88. def dispose
  89. @selbitmap.dispose
  90. super
  91. end
  92.  
  93. def index=(value)
  94. @index = value
  95. refresh
  96. end
  97.  
  98. def mode=(value)
  99. @mode = value
  100. case @mode
  101. when 0 # Order
  102. @xstart = 20; @ystart = 72
  103. @xgap = 160; @ygap = 18
  104. @cols = 1
  105. when 1 # Name
  106. @xstart = 20; @ystart = 72
  107. @xgap = 32; @ygap = 18
  108. @cols = 7
  109. when 2 # Type
  110. @xstart = 20; @ystart = 72
  111. @xgap = 80; @ygap = 18
  112. @cols = 3
  113. when 3,4 # Height, weight
  114. @xstart = 54; @ystart = 74
  115. @xgap = 4; @ygap = 126
  116. when 5 # Color
  117. @xstart = 20; @ystart = 72
  118. @xgap = 112; @ygap = 18
  119. @cols = 2
  120. when 6 # Shape
  121. @xstart = 20; @ystart = 72
  122. @xgap = 52; @ygap = 48
  123. @cols = 5
  124. end
  125. end
  126.  
  127. def refresh
  128. case @index
  129. when 0; self.x = 34; self.y = 53
  130. when 1; self.x = 34; self.y = 85
  131. when 2; self.x = 34; self.y = 197
  132. when 3; self.x = 34; self.y = 229
  133. end
  134. end
  135. end
  136.  
  137. #===============================================================================
  138. # Pokédex main screen
  139. #===============================================================================
  140. class PokemonPokedex_Scene
  141. MODENUMERICAL = 0
  142. MODEATOZ = 1
  143. MODETALLEST = 2
  144. MODESMALLEST = 3
  145. MODEHEAVIEST = 4
  146. MODELIGHTEST = 5
  147.  
  148. def pbUpdate
  149. if @sprites["searchbg"].visible
  150. if @frame == 10
  151. @frame = 0
  152. @sprites["searchcursor"].visible = !(@sprites["searchcursor"].visible)
  153. end
  154. @frame += 1
  155. end
  156. pbUpdateSpriteHash(@sprites)
  157. end
  158.  
  159. def pbStartScene
  160. @sliderbitmap = AnimatedBitmap.new("Graphics/Pictures/Pokedex/icon_slider")
  161. @typebitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/Pokedex/icon_types"))
  162. @shapebitmap = AnimatedBitmap.new("Graphics/Pictures/Pokedex/icon_shapes")
  163. @hwbitmap = AnimatedBitmap.new("Graphics/Pictures/Pokedex/icon_hw")
  164. @selbitmap = AnimatedBitmap.new("Graphics/Pictures/Pokedex/icon_searchsel")
  165. @searchsliderbitmap = AnimatedBitmap.new(_INTL("Graphics/Pictures/Pokedex/icon_searchslider"))
  166. @sprites = {}
  167. @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  168. @viewport.z = 99999
  169. addBackgroundPlane(@sprites,"background","Pokedex/bg_list",@viewport)
  170. =begin
  171. # Suggestion for changing the background depending on region. You can change
  172. # the line above with the following:
  173. if pbGetPokedexRegion==-1 # Using national Pokédex
  174. addBackgroundPlane(@sprites,"background","Pokedex/bg_national",@viewport)
  175. elsif pbGetPokedexRegion==0 # Using first regional Pokédex
  176. addBackgroundPlane(@sprites,"background","Pokedex/bg_regional",@viewport)
  177. end
  178. =end
  179. addBackgroundPlane(@sprites,"searchbg","Pokedex/bg_search",@viewport)
  180. @sprites["searchbg"].visible = false
  181. @sprites["pokedex"] = Window_Pokedex.new(110,0,210,272,@viewport)
  182. @sprites["bgicon"]=IconSprite.new(6,16,@viewport)
  183. barBitmap = Bitmap.new(112,112)
  184. barRect = Rect.new(0,0,barBitmap.width,barBitmap.height)
  185. barBitmap.fill_rect(barRect,Color.new(88,184,0))
  186. @sprites["bgicon"].bitmap = barBitmap
  187. @sprites["icon"] = PokemonSprite.new(@viewport)
  188. @sprites["icon"].setOffset(PictureOrigin::Center)
  189. @sprites["icon"].x = 62
  190. @sprites["icon"].y = 72
  191. @sprites["icon"].tone = Tone.new(0,0,0,255)
  192. @sprites["overlayscrn"] = IconSprite.new(0,0,@viewport)
  193. @sprites["overlayscrn"].setBitmap("Graphics/Pictures/Pokedex/OverlayScreen")
  194. @sprites["overlayscrn"].blend_type = 2
  195. @sprites["overlay"] = BitmapSprite.new(Graphics.width,Graphics.height,@viewport)
  196. pbSetSystemFont(@sprites["overlay"].bitmap)
  197. @sprites["searchcursor"] = PokedexSearchSelectionSprite.new(@viewport)
  198. @sprites["searchcursor"].visible = false
  199. @sprites["searchanim"] = IconSprite.new(128,144,@viewport)
  200. @sprites["searchanim"].setBitmap("Graphics/Pictures/Pokedex/icon_searching")
  201. @sprites["searchanim"].src_rect.set(0,0,48,48)
  202. @sprites["searchanim"].visible = false
  203. @frame = 0
  204. @searchResults = false
  205. @searchParams = [$PokemonGlobal.pokedexMode,-1,0,-1,-1,-1,-1,-1,-1,-1]
  206. pbRefreshDexList($PokemonGlobal.pokedexIndex[pbGetSavePositionIndex])
  207. pbDeactivateWindows(@sprites)
  208. pbFadeInAndShow(@sprites)
  209. end
  210.  
  211. def pbEndScene
  212. pbFadeOutAndHide(@sprites)
  213. pbDisposeSpriteHash(@sprites)
  214. @sliderbitmap.dispose
  215. @typebitmap.dispose
  216. @shapebitmap.dispose
  217. @hwbitmap.dispose
  218. @selbitmap.dispose
  219. @searchsliderbitmap.dispose
  220. @viewport.dispose
  221. end
  222.  
  223. # Gets the region used for displaying Pokédex entries. Species will be listed
  224. # according to the given region's numbering and the returned region can have
  225. # any value defined in the town map data file. It is currently set to the
  226. # return value of pbGetCurrentRegion, and thus will change according to the
  227. # current map's MapPosition metadata setting.
  228. def pbGetPokedexRegion
  229. if USE_CURRENT_REGION_DEX
  230. region = pbGetCurrentRegion
  231. region = -1 if region>=$PokemonGlobal.pokedexUnlocked.length-1
  232. return region
  233. else
  234. return $PokemonGlobal.pokedexDex # National Dex -1, regional dexes 0 etc.
  235. end
  236. end
  237.  
  238. # Determines which index of the array $PokemonGlobal.pokedexIndex to save the
  239. # "last viewed species" in. All regional dexes come first in order, then the
  240. # National Dex at the end.
  241. def pbGetSavePositionIndex
  242. index = pbGetPokedexRegion
  243. if index==-1 # National Dex
  244. index = $PokemonGlobal.pokedexUnlocked.length-1 # National Dex index comes
  245. end # after regional Dex indices
  246. return index
  247. end
  248.  
  249. def pbCanAddForModeList?(mode,nationalSpecies)
  250. case mode
  251. when MODENUMERICAL
  252. return true
  253. when MODEATOZ
  254. return $Trainer.seen[nationalSpecies]
  255. when MODEHEAVIEST, MODELIGHTEST, MODETALLEST, MODESMALLEST
  256. return $Trainer.owned[nationalSpecies]
  257. end
  258. end
  259.  
  260. def pbGetDexList
  261. dexlist = []
  262. speciesData = pbLoadSpeciesData
  263. region = pbGetPokedexRegion
  264. regionalSpecies = pbAllRegionalSpecies(region)
  265. if regionalSpecies.length==1
  266. # If no Regional Dex defined for the given region, use National Pokédex
  267. for i in 1..PBSpecies.maxValue
  268. regionalSpecies.push(i)
  269. end
  270. end
  271. for i in 1...regionalSpecies.length
  272. nationalSpecies = regionalSpecies[i]
  273. if pbCanAddForModeList?($PokemonGlobal.pokedexMode,nationalSpecies)
  274. form = ($Trainer.formlastseen[nationalSpecies][1] || 0) rescue 0
  275. #raise _INTL("DEBUG: species = {1}; form = {2}; formlastseen = {3}",
  276. # nationalSpecies, form, $Trainer.formlastseen.length)
  277. fspecies = pbGetFSpeciesFromForm(nationalSpecies,form)
  278. color = speciesData[fspecies][SpeciesColor] || 0
  279. type1 = speciesData[fspecies][SpeciesType1] || 0
  280. type2 = speciesData[fspecies][SpeciesType2] || type1
  281. shape = speciesData[fspecies][SpeciesShape] || 0
  282. height = speciesData[fspecies][SpeciesHeight] || 1
  283. weight = speciesData[fspecies][SpeciesWeight] || 1
  284. shift = DEXES_WITH_OFFSETS.include?(region)
  285. dexlist.push([nationalSpecies,PBSpecies.getName(nationalSpecies),
  286. height,weight,i,shift,type1,type2,color,shape])
  287. end
  288. end
  289. return dexlist
  290. end
  291.  
  292. def pbRefreshDexList(index=0)
  293. dexlist = pbGetDexList
  294. case $PokemonGlobal.pokedexMode
  295. when MODENUMERICAL
  296. # Hide the Dex number 0 species if unseen
  297. dexlist[0] = nil if dexlist[0][5] && !$Trainer.seen[dexlist[0][0]]
  298. # Remove unseen species from the end of the list
  299. i = dexlist.length-1; loop do break unless i>=0
  300. break if !dexlist[i] || $Trainer.seen[dexlist[i][0]]
  301. dexlist[i] = nil
  302. i -= 1
  303. end
  304. dexlist.compact!
  305. # Sort species in ascending order by Regional Dex number
  306. dexlist.sort! { |a,b| a[4]<=>b[4] }
  307. when MODEATOZ
  308. dexlist.sort! { |a,b| (a[1]==b[1]) ? a[4]<=>b[4] : a[1]<=>b[1] }
  309. when MODEHEAVIEST
  310. dexlist.sort! { |a,b| (a[3]==b[3]) ? a[4]<=>b[4] : b[3]<=>a[3] }
  311. when MODELIGHTEST
  312. dexlist.sort! { |a,b| (a[3]==b[3]) ? a[4]<=>b[4] : a[3]<=>b[3] }
  313. when MODETALLEST
  314. dexlist.sort! { |a,b| (a[2]==b[2]) ? a[4]<=>b[4] : b[2]<=>a[2] }
  315. when MODESMALLEST
  316. dexlist.sort! { |a,b| (a[2]==b[2]) ? a[4]<=>b[4] : a[2]<=>b[2] }
  317. end
  318. @dexlist = dexlist
  319. @sprites["pokedex"].commands = @dexlist
  320. @sprites["pokedex"].index = index
  321. @sprites["pokedex"].refresh
  322. if @searchResults
  323. @sprites["background"].setBitmap("Graphics/Pictures/Pokedex/bg_listsearch")
  324. else
  325. @sprites["background"].setBitmap("Graphics/Pictures/Pokedex/bg_list")
  326. end
  327. pbRefresh
  328. end
  329.  
  330. def pbRefresh
  331. overlay = @sprites["overlay"].bitmap
  332. overlay.clear
  333. base = Color.new(248,248,248)
  334. shadow = Color.new(0,0,0,0)
  335. iconspecies = @sprites["pokedex"].species
  336. iconspecies = 0 if !$Trainer.seen[iconspecies]
  337. # Write various bits of text
  338. dexname = _INTL("Pokédex")
  339. if $PokemonGlobal.pokedexUnlocked.length>1
  340. thisdex = pbDexNames[pbGetSavePositionIndex]
  341. if thisdex!=nil
  342. dexname = (thisdex.is_a?(Array)) ? thisdex[0] : thisdex
  343. end
  344. end
  345. textpos = []
  346. #[dexname,64,160,2,Color.new(255,255,255),Color.new(0,0,0,0)]
  347. #textpos.push([PBSpecies.getName(iconspecies),112,52,2,base,shadow]) if iconspecies>0
  348. if @searchResults
  349. textpos.push([_INTL("FOUND:"),6,192,0,base,shadow])
  350. textpos.push([@dexlist.length.to_s,120,208,1,base,shadow])
  351. else
  352. textpos.push([_INTL("SEEN:"),6,168,0,base,shadow])
  353. textpos.push([$Trainer.pokedexSeen(pbGetPokedexRegion).to_s,118,184,1,base,shadow])
  354. textpos.push([_INTL("OWN:"),6,216,0,base,shadow])
  355. textpos.push([$Trainer.pokedexOwned(pbGetPokedexRegion).to_s,118,232,1,base,shadow])
  356. end
  357. # Draw all text
  358. pbDrawTextPositions(overlay,textpos)
  359. # Set Pokémon sprite
  360. setIconBitmap(iconspecies)
  361. # Draw slider arrows
  362. itemlist = @sprites["pokedex"]
  363. showslider = false
  364. if itemlist.top_row>0
  365. #overlay.blt(468,48,@sliderbitmap.bitmap,Rect.new(0,0,40,30))
  366. showslider = true
  367. end
  368. if itemlist.top_item+itemlist.page_item_max<itemlist.itemCount
  369. #overlay.blt(468,346,@sliderbitmap.bitmap,Rect.new(0,30,40,30))
  370. showslider = true
  371. end
  372. # Draw slider box
  373. if showslider
  374. #sliderheight = 268
  375. #boxheight = (sliderheight*itemlist.page_row_max/itemlist.row_max).floor
  376. #boxheight += [(sliderheight-boxheight)/2,sliderheight/6].min
  377. #boxheight = [boxheight.floor,40].max
  378. y = 10
  379. y+=242*itemlist.index/(itemlist.row_max-1)
  380. #y += ((sliderheight-boxheight)*itemlist.top_row/(itemlist.row_max-itemlist.page_row_max)).floor
  381. #overlay.blt(468,y,@sliderbitmap.bitmap,Rect.new(40,0,40,8))
  382. #i = 0
  383. #while i*16<boxheight-8-16
  384. #height = [boxheight-8-16-i*16,16].min
  385. overlay.blt(308,y,@sliderbitmap.bitmap,Rect.new(0,0,10,10))
  386. #i += 1
  387. #end
  388. #overlay.blt(468,y+boxheight-16,@sliderbitmap.bitmap,Rect.new(40,24,40,16))
  389. end
  390. end
  391.  
  392. def pbRefreshDexSearch(params,_index)
  393. overlay = @sprites["overlay"].bitmap
  394. overlay.clear
  395. base = Color.new(248,248,248)
  396. shadow = Color.new(0,0,0,0)
  397. # Write various bits of text
  398. textpos = []
  399. # Draw type text
  400. if params[2]>=0
  401. textpos.push([_INTL("{1}",PBTypes.getName(params[2])),208,56,2,base,shadow,1])
  402. else
  403. textpos.push(["----",208,56,2,base,shadow,1])
  404. end
  405. if params[3]>=0
  406. textpos.push([_INTL("{1}",PBTypes.getName(params[3])),208,88,2,base,shadow,1])
  407. else
  408. textpos.push(["----",208,88,2,base,shadow,1])
  409. end
  410. # Draw all text
  411. pbDrawTextPositions(overlay,textpos)
  412. end
  413.  
  414. def pbRefreshDexSearchParam(mode,cmds,sel,_index)
  415. overlay = @sprites["overlay"].bitmap
  416. overlay.clear
  417. base = Color.new(248,248,248)
  418. shadow = Color.new(0,0,0,0)
  419. # Write various bits of text
  420. textpos = [
  421. [_INTL("MODE"),Graphics.width/2,8,2,base,shadow],
  422. [_INTL("OK"),36,250,0,base,shadow,1],
  423. [_INTL("CANCEL"),Graphics.width-20,250,1,base,shadow,1]
  424. ]
  425. title = [_INTL("ORDER:"),_INTL("NAME:"),_INTL("TYPE:"),_INTL("HEIGHT:"),
  426. _INTL("WEIGHT:"),_INTL("COLOR:"),_INTL("SHAPE:")][mode]
  427. textpos.push([title,20,(mode==6) ? 40 : 40,0,base,shadow])
  428. case mode
  429. when 0 # Order
  430. xstart = 20; ystart = 66
  431. xgap = 160; ygap = 18
  432. halfwidth = 92; cols = 1
  433. selbuttony = 0; selbuttonheight = 16
  434. when 1 # Name
  435. xstart = 20; ystart = 66
  436. xgap = 32; ygap = 18
  437. halfwidth = 22; cols = 7
  438. selbuttony = 0; selbuttonheight = 16
  439. when 2 # Type
  440. xstart = 20; ystart = 60
  441. xgap = 80; ygap = 18
  442. halfwidth = 62; cols = 3
  443. selbuttony = 0; selbuttonheight = 16
  444. when 3,4 # Height, weight
  445. xstart = 20; ystart = 54
  446. xgap = 160/(cmds.length+1); ygap = 96
  447. halfwidth = 60; cols = cmds.length+1
  448. when 5 # Color
  449. xstart = 20; ystart = 66
  450. xgap = 112; ygap = 18
  451. halfwidth = 62; cols = 2
  452. selbuttony = 0; selbuttonheight = 16
  453. when 6 # Shape
  454. xstart = 12; ystart = 60
  455. xgap = 52; ygap = 48
  456. halfwidth = 0; cols = 5
  457. selbuttony = 16; selbuttonheight = 60
  458. end
  459. # Draw selected option(s) text in top bar
  460. case mode
  461. when 2 # Type icons
  462. for i in 0...2
  463. if !sel[i] || sel[i]<0
  464. textpos.push(["----",130+80*i,40,0,base,shadow,1])
  465. else
  466. typerect = Rect.new(0,@typeCommands[sel[i]]*28,64,28)
  467. overlay.blt(130+80*i,42,@typebitmap.bitmap,typerect)
  468. end
  469. end
  470. when 3 # Height range
  471. ht1 = (sel[0]<0) ? 0 : (sel[0]>[email protected]) ? 999 : @heightCommands[sel[0]]
  472. ht2 = (sel[1]<0) ? 999 : (sel[1]>[email protected]) ? 0 : @heightCommands[sel[1]]
  473. hwoffset = false
  474. if pbGetCountry==0xF4 # If the user is in the United States
  475. ht1 = (sel[0]>[email protected]) ? 99*12 : (ht1/0.254).round
  476. ht2 = (sel[1]<0) ? 99*12 : (ht2/0.254).round
  477. txt1 = sprintf("%d'%02d''",ht1/12,ht1%12)
  478. txt2 = sprintf("%d'%02d''",ht2/12,ht2%12)
  479. hwoffset = true
  480. else
  481. txt1 = sprintf("%.1f",ht1/10.0)
  482. txt2 = sprintf("%.1f",ht2/10.0)
  483. end
  484. #textpos.push([txt1,286,58,2,base,shadow,1])
  485. #textpos.push([txt2,414,58,2,base,shadow,1])
  486. #overlay.blt(462,52,@hwbitmap.bitmap,Rect.new(0,(hwoffset) ? 44 : 0,32,44))
  487. when 4 # Weight range
  488. wt1 = (sel[0]<0) ? 0 : (sel[0]>[email protected]) ? 9999 : @weightCommands[sel[0]]
  489. wt2 = (sel[1]<0) ? 9999 : (sel[1]>[email protected]) ? 0 : @weightCommands[sel[1]]
  490. hwoffset = false
  491. if pbGetCountry==0xF4 # If the user is in the United States
  492. wt1 = (sel[0]>[email protected]) ? 99990 : (wt1/0.254).round
  493. wt2 = (sel[1]<0) ? 99990 : (wt2/0.254).round
  494. txt1 = sprintf("%.1f",wt1/10.0)
  495. txt2 = sprintf("%.1f",wt2/10.0)
  496. hwoffset = true
  497. else
  498. txt1 = sprintf("%.1f",wt1/10.0)
  499. txt2 = sprintf("%.1f",wt2/10.0)
  500. end
  501. #textpos.push([txt1,286,58,2,base,shadow,1])
  502. #textpos.push([txt2,414,58,2,base,shadow,1])
  503. #overlay.blt(462,52,@hwbitmap.bitmap,Rect.new(32,(hwoffset) ? 44 : 0,32,44))
  504. when 6 # Shape icon
  505. if sel[0]>=0
  506. shaperect = Rect.new(0,@shapeCommands[sel[0]]*60,60,60)
  507. overlay.blt(332,50,@shapebitmap.bitmap,shaperect)
  508. end
  509. else
  510. if sel[0]<0
  511. text = ["----","-","----","","","----",""][mode]
  512. textpos.push([text,300,40,1,base,shadow,1])
  513. else
  514. textpos.push([cmds[sel[0]],300,40,1,base,shadow,1])
  515. end
  516. end
  517. # Draw selected option(s) button graphic
  518. if mode==3 || mode==4 # Height, weight
  519. xpos1 = xstart+(sel[0]+1)*xgap
  520. xpos1 = xstart if sel[0]<-1
  521. xpos2 = xstart+(sel[1]+1)*xgap
  522. xpos2 = xstart+cols*xgap if sel[1]<0
  523. xpos2 = xstart if sel[1]>=cols-1
  524. ypos1 = ystart+64-4+112
  525. ypos2 = ystart+32-4
  526. overlay.blt(16,84,@searchsliderbitmap.bitmap,Rect.new(0,192,32,44)) if sel[1]<cols-1
  527. overlay.blt(272,84,@searchsliderbitmap.bitmap,Rect.new(32,192,32,44)) if sel[1]>=0
  528. overlay.blt(16,192,@searchsliderbitmap.bitmap,Rect.new(0,192,32,44)) if sel[0]>=0
  529. overlay.blt(272,192,@searchsliderbitmap.bitmap,Rect.new(32,192,32,44)) if sel[0]<cols-1
  530. hwrect = Rect.new(0,0,120,96)
  531. overlay.blt(xpos2,ystart+6,@searchsliderbitmap.bitmap,hwrect)
  532. hwrect.y = 96
  533. overlay.blt(xpos1,ystart+ygap+16,@searchsliderbitmap.bitmap,hwrect)
  534. textpos.push([txt1,xpos1+halfwidth,ypos1,2,base,nil,1])
  535. textpos.push([txt2,xpos2+halfwidth,ypos2,2,base,nil,1])
  536. else
  537. for i in 0...sel.length
  538. xadd = mode==6 ? 4 : 0
  539. yadd = mode==2 ? 12 : 6
  540. if sel[i]>=0
  541. selrect = Rect.new(0,selbuttony,@selbitmap.bitmap.width,selbuttonheight)
  542. overlay.blt(xstart+(sel[i]%cols)*xgap+xadd,ystart+yadd+(sel[i]/cols).floor*ygap,@selbitmap.bitmap,selrect)
  543. else
  544. selrect = Rect.new(0,selbuttony,@selbitmap.bitmap.width,selbuttonheight)
  545. overlay.blt(xstart+(cols-1)*xgap+xadd,ystart+yadd+(cmds.length/cols).floor*ygap,@selbitmap.bitmap,selrect)
  546. end
  547. end
  548. end
  549. # Draw options
  550. case mode
  551. when 0,1,5 # Order, name, color
  552. for i in 0...cmds.length
  553. x = xstart+halfwidth+(i%cols)*xgap
  554. y = ystart+6+(i/cols).floor*ygap
  555. textpos.push([cmds[i],x,y,2,base,shadow,1])
  556. end
  557. if mode!=0
  558. textpos.push([(mode==1) ? "-" : "----",
  559. xstart+halfwidth+(cols-1)*xgap,ystart+6+(cmds.length/cols).floor*ygap,2,base,shadow,1])
  560. end
  561. when 2 # Type
  562. typerect = Rect.new(0,0,64,28)
  563. for i in 0...cmds.length
  564. typerect.y = @typeCommands[i]*28
  565. overlay.blt(xstart+14+(i%cols)*xgap,ystart+6+(i/cols).floor*ygap,@typebitmap.bitmap,typerect)
  566. end
  567. textpos.push(["----",
  568. xstart+halfwidth+(cols-1)*xgap,ystart+6+(cmds.length/cols).floor*ygap,2,base,shadow,1])
  569. when 6 # Shape
  570. shaperect = Rect.new(0,0,60,60)
  571. for i in 0...cmds.length
  572. shaperect.y = i*60
  573. overlay.blt(xstart+4+(i%cols)*xgap,ystart+4+(i/cols).floor*ygap,@shapebitmap.bitmap,shaperect)
  574. end
  575. end
  576. # Draw all text
  577. pbDrawTextPositions(overlay,textpos)
  578. end
  579.  
  580. def setIconBitmap(species)
  581. gender = ($Trainer.formlastseen[species][0] rescue 0)
  582. form = ($Trainer.formlastseen[species][1] rescue 0)
  583. @sprites["icon"].setSpeciesBitmap(species,(gender==1),form)
  584. end
  585.  
  586. def pbSearchDexList(params)
  587. $PokemonGlobal.pokedexMode = params[0]
  588. dexlist = pbGetDexList
  589. # Filter by name
  590. if params[1]>=0
  591. scanNameCommand = @nameCommands[params[1]].scan(/./)
  592. dexlist = dexlist.find_all { |item|
  593. next false if !$Trainer.seen[item[0]]
  594. firstChar = item[1][0,1]
  595. next scanNameCommand.any? { |v| v==firstChar }
  596. }
  597. end
  598. # Filter by type
  599. if params[2]>=0 || params[3]>=0
  600. stype1 = (params[2]>=0) ? params[2] : -1#@typeCommands[params[2]] : -1
  601. stype2 = (params[3]>=0) ? params[3] : -1#@typeCommands[params[3]] : -1
  602. dexlist = dexlist.find_all { |item|
  603. next false if !$Trainer.owned[item[0]]
  604. type1 = item[6]
  605. type2 = item[7]
  606. if stype1>=0 && stype2>=0
  607. # Find species that match both types
  608. next (type1==stype1 && type2==stype2) || (type1==stype2 && type2==stype1)
  609. elsif stype1>=0
  610. # Find species that match first type entered
  611. next type1==stype1 || type2==stype1
  612. elsif stype2>=0
  613. # Find species that match second type entered
  614. next type1==stype2 || type2==stype2
  615. else
  616. next false
  617. end
  618. }
  619. end
  620. # Filter by height range
  621. if params[4]>=0 || params[5]>=0
  622. minh = (params[4]<0) ? 0 : (params[4]>[email protected]) ? 999 : @heightCommands[params[4]]
  623. maxh = (params[5]<0) ? 999 : (params[5]>[email protected]) ? 0 : @heightCommands[params[5]]
  624. dexlist = dexlist.find_all { |item|
  625. next false if !$Trainer.owned[item[0]]
  626. height = item[2]
  627. next height>=minh && height<=maxh
  628. }
  629. end
  630. # Filter by weight range
  631. if params[6]>=0 || params[7]>=0
  632. minw = (params[6]<0) ? 0 : (params[6]>[email protected]) ? 9999 : @weightCommands[params[6]]
  633. maxw = (params[7]<0) ? 9999 : (params[7]>[email protected]) ? 0 : @weightCommands[params[7]]
  634. dexlist = dexlist.find_all { |item|
  635. next false if !$Trainer.owned[item[0]]
  636. weight = item[3]
  637. next weight>=minw && weight<=maxw
  638. }
  639. end
  640. # Filter by color
  641. if params[8]>=0
  642. colorCommands = []
  643. for i in 0..PBColors.maxValue
  644. j = PBColors.getName(i)
  645. colorCommands.push(i) if j
  646. end
  647. scolor = colorCommands[params[8]]
  648. dexlist = dexlist.find_all { |item|
  649. next false if !$Trainer.seen[item[0]]
  650. color = item[8]
  651. next color==scolor
  652. }
  653. end
  654. # Filter by shape
  655. if params[9]>=0
  656. sshape = @shapeCommands[params[9]]+1
  657. dexlist = dexlist.find_all { |item|
  658. next false if !$Trainer.seen[item[0]]
  659. shape = item[9]
  660. next shape==sshape
  661. }
  662. end
  663. # Remove all unseen species from the results
  664. dexlist = dexlist.find_all { |item| next $Trainer.seen[item[0]] }
  665. case $PokemonGlobal.pokedexMode
  666. when MODENUMERICAL; dexlist.sort! { |a,b| a[4]<=>b[4] }
  667. when MODEATOZ; dexlist.sort! { |a,b| a[1]<=>b[1] }
  668. when MODEHEAVIEST; dexlist.sort! { |a,b| b[3]<=>a[3] }
  669. when MODELIGHTEST; dexlist.sort! { |a,b| a[3]<=>b[3] }
  670. when MODETALLEST; dexlist.sort! { |a,b| b[2]<=>a[2] }
  671. when MODESMALLEST; dexlist.sort! { |a,b| a[2]<=>b[2] }
  672. end
  673. return dexlist
  674. end
  675.  
  676. def pbCloseSearch
  677. oldsprites = pbFadeOutAndHide(@sprites)
  678. oldspecies = @sprites["pokedex"].species
  679. @searchResults = false
  680. $PokemonGlobal.pokedexMode = MODENUMERICAL
  681. @searchParams = [$PokemonGlobal.pokedexMode,-1,0,-1,-1,-1,-1,-1,-1,-1]
  682. pbRefreshDexList($PokemonGlobal.pokedexIndex[pbGetSavePositionIndex])
  683. next if @dexlist[i][0]!=oldspecies
  684. @sprites["pokedex"].index = i
  685. pbRefresh
  686. break
  687. end
  688. $PokemonGlobal.pokedexIndex[pbGetSavePositionIndex] = @sprites["pokedex"].index
  689. pbFadeInAndShow(@sprites,oldsprites)
  690. end
  691.  
  692. def pbDexEntry(index)
  693. oldsprites = pbFadeOutAndHide(@sprites)
  694. region = -1
  695. if !USE_CURRENT_REGION_DEX
  696. dexnames = pbDexNames
  697. if dexnames[pbGetSavePositionIndex].is_a?(Array)
  698. region = dexnames[pbGetSavePositionIndex][1]
  699. end
  700. end
  701. scene = PokemonPokedexInfo_Scene.new
  702. screen = PokemonPokedexInfoScreen.new(scene)
  703. ret = screen.pbStartScreen(@dexlist,index,region)
  704. if @searchResults
  705. dexlist = pbSearchDexList(@searchParams)
  706. @dexlist = dexlist
  707. @sprites["pokedex"].commands = @dexlist
  708. ret = @dexlist.length-1 if ret>[email protected]
  709. ret = 0 if ret<0
  710. else
  711. pbRefreshDexList($PokemonGlobal.pokedexIndex[pbGetSavePositionIndex])
  712. $PokemonGlobal.pokedexIndex[pbGetSavePositionIndex] = ret
  713. end
  714. @sprites["pokedex"].index = ret
  715. @sprites["pokedex"].refresh
  716. pbRefresh
  717. pbFadeInAndShow(@sprites,oldsprites)
  718. end
  719.  
  720. def pbDexSearchCommands(mode,selitems,mainindex)
  721. cmds = [@orderCommands,@nameCommands,@typeCommands,@heightCommands,
  722. @weightCommands,@colorCommands,@shapeCommands][mode]
  723. cols = [1,7,3,1,1,2,5][mode]
  724. ret = nil
  725. # Set background
  726. case mode
  727. when 0; @sprites["searchbg"].setBitmap("Graphics/Pictures/Pokedex/bg_search")
  728. when 1; @sprites["searchbg"].setBitmap("Graphics/Pictures/Pokedex/bg_search")
  729. when 2
  730. if PBTypes.regularTypesCount==18
  731. @sprites["searchbg"].setBitmap("Graphics/Pictures/Pokedex/bg_search")
  732. else
  733. @sprites["searchbg"].setBitmap("Graphics/Pictures/Pokedex/bg_search")
  734. end
  735. when 3,4; @sprites["searchbg"].setBitmap("Graphics/Pictures/Pokedex/bg_search")
  736. when 5; @sprites["searchbg"].setBitmap("Graphics/Pictures/Pokedex/bg_search")
  737. when 6; @sprites["searchbg"].setBitmap("Graphics/Pictures/Pokedex/bg_search")
  738. end
  739. selindex = selitems.clone
  740. index = selindex[0]
  741. oldindex = index
  742. minmax = 1
  743. oldminmax = minmax
  744. if mode==3 || mode==4; index = oldindex = selindex[minmax]; end
  745. @sprites["searchcursor"].mode = mode
  746. @sprites["searchcursor"].cmds = cmds.length
  747. @sprites["searchcursor"].minmax = minmax
  748. @sprites["searchcursor"].index = index
  749. nextparam = cmds.length%2
  750. pbRefreshDexSearchParam(mode,cmds,selindex,index)
  751. loop do
  752. pbUpdate
  753. if index!=oldindex || minmax!=oldminmax
  754. @sprites["searchcursor"].minmax = minmax
  755. @sprites["searchcursor"].index = index
  756. oldindex = index
  757. oldminmax = minmax
  758. end
  759. Graphics.update
  760. Input.update
  761. if mode==3 || mode==4
  762. if Input.trigger?(Input::UP)
  763. if index<-1; minmax = 0; index = selindex[minmax] # From OK/Cancel
  764. elsif minmax==0; minmax = 1; index = selindex[minmax]
  765. end
  766. if index!=oldindex || minmax!=oldminmax
  767. pbPlayCursorSE
  768. pbRefreshDexSearchParam(mode,cmds,selindex,index)
  769. end
  770. elsif Input.trigger?(Input::DOWN)
  771. if minmax==1; minmax = 0; index = selindex[minmax]
  772. elsif minmax==0; minmax = -1; index = -2
  773. end
  774. if index!=oldindex || minmax!=oldminmax
  775. pbPlayCursorSE
  776. pbRefreshDexSearchParam(mode,cmds,selindex,index)
  777. end
  778. elsif Input.repeat?(Input::LEFT)
  779. if index==-3; index = -2
  780. elsif index>=-1
  781. if minmax==1 && index==-1
  782. index = cmds.length-1 if selindex[0]<cmds.length-1
  783. elsif minmax==1 && index==0
  784. index = cmds.length if selindex[0]<0
  785. elsif index>-1 && !(minmax==1 && index>=cmds.length)
  786. index -= 1 if minmax==0 || selindex[0]<=index-1
  787. end
  788. end
  789. if index!=oldindex
  790. selindex[minmax] = index if minmax>=0
  791. pbPlayCursorSE
  792. pbRefreshDexSearchParam(mode,cmds,selindex,index)
  793. end
  794. elsif Input.repeat?(Input::RIGHT)
  795. if index==-2; index = -3
  796. elsif index>=-1
  797. if minmax==1 && index>=cmds.length; index = 0
  798. elsif minmax==1 && index==cmds.length-1; index = -1
  799. elsif index<cmds.length && !(minmax==1 && index<0)
  800. index += 1 if minmax==1 || selindex[1]==-1 ||
  801. (selindex[1]<cmds.length && selindex[1]>=index+1)
  802. end
  803. end
  804. if index!=oldindex
  805. selindex[minmax] = index if minmax>=0
  806. pbPlayCursorSE
  807. pbRefreshDexSearchParam(mode,cmds,selindex,index)
  808. end
  809. end
  810. else
  811. if Input.trigger?(Input::UP)
  812. if index==-1 && mode==5; index = cmds.length-1
  813. elsif index==-1; index = cmds.length-1-(cmds.length-1)%cols-1 # From blank
  814. elsif index==-2; index = ((cmds.length-1)/cols).floor*cols # From OK
  815. elsif index==-3 && mode==0; index = cmds.length-1 # From Cancel
  816. elsif index==-3; index = -1 # From Cancel
  817. elsif index>=cols; index -= cols
  818. end
  819. pbPlayCursorSE if index!=oldindex
  820. elsif Input.trigger?(Input::DOWN)
  821. if index==-1; index = -3 # From blank
  822. elsif index==cmds.length-1 && mode==5; index=-1
  823. elsif index>=0
  824. if index+cols<cmds.length; index += cols
  825. elsif (index/cols).floor<((cmds.length-1)/cols).floor
  826. index = (index%cols<cols/2.0) ? cmds.length-1 : -1
  827. else
  828. index = (index%cols<cols/2.0) ? -2 : -3
  829. end
  830. end
  831. pbPlayCursorSE if index!=oldindex
  832. elsif Input.trigger?(Input::LEFT)
  833. if index==-3; index = -2
  834. elsif index==-1; index = cmds.length-1
  835. elsif index>0 && index%cols!=0; index -= 1
  836. end
  837. pbPlayCursorSE if index!=oldindex
  838. elsif Input.trigger?(Input::RIGHT)
  839. if index==-2; index = -3
  840. elsif index==cmds.length-1 && mode!=0; index = -1
  841. elsif index>=0 && index%cols!=cols-1; index += 1
  842. end
  843. pbPlayCursorSE if index!=oldindex
  844. end
  845. end
  846. if Input.trigger?(Input::ENTER)
  847. index = -2
  848. pbPlayCursorSE if index!=oldindex
  849. elsif Input.trigger?(Input::B)
  850. pbPlayCloseMenuSE
  851. ret = nil
  852. break
  853. elsif Input.trigger?(Input::C)
  854. if index==-2 # OK
  855. pbPlayDecisionSE
  856. ret = selindex
  857. break
  858. elsif index==-3 # Cancel
  859. pbPlayCloseMenuSE
  860. ret = nil
  861. break
  862. elsif selindex!=index && mode!=3 && mode!=4
  863. if mode==2
  864. if index==-1
  865. nextparam = (selindex[1]>=0) ? 1 : 0
  866. elsif index>=0
  867. nextparam = (selindex[0]<0) ? 0 : (selindex[1]<0) ? 1 : nextparam
  868. end
  869. if index<0 || selindex[(nextparam+1)%2]!=index
  870. pbPlayDecisionSE
  871. selindex[nextparam] = index
  872. nextparam = (nextparam+1)%2
  873. end
  874. else
  875. pbPlayDecisionSE
  876. selindex[0] = index
  877. end
  878. pbRefreshDexSearchParam(mode,cmds,selindex,index)
  879. end
  880. end
  881. end
  882. Input.update
  883. # Set background image
  884. @sprites["searchbg"].setBitmap("Graphics/Pictures/Pokedex/bg_search")
  885. @sprites["searchcursor"].mode = -1
  886. @sprites["searchcursor"].index = mainindex
  887. return ret
  888. end
  889.  
  890. def pbDexSearch
  891. oldsprites = pbFadeOutAndHide(@sprites)
  892. params = @searchParams.clone
  893. @typeCommands = []
  894. for i in 0..PBTypes.maxValue
  895. @typeCommands.push(i) if !PBTypes.isPseudoType?(i)
  896. end
  897. @sprites["searchbg"].visible = true
  898. @sprites["overlay"].visible = true
  899. @sprites["searchcursor"].visible = true
  900. index = 0
  901. oldindex = index
  902. @sprites["searchcursor"].mode = -1
  903. @sprites["searchcursor"].index = index
  904. pbRefreshDexSearch(params,index)
  905. pbFadeInAndShow(@sprites)
  906. loop do
  907. Graphics.update
  908. Input.update
  909. pbUpdate
  910. if index!=oldindex
  911. @sprites["searchcursor"].index = index
  912. oldindex = index
  913. end
  914. if Input.trigger?(Input::UP)
  915. index -= 1 if index > 0
  916. pbPlayCursorSE if index != oldindex
  917. elsif Input.trigger?(Input::DOWN)
  918. index += 1 if index<3
  919. pbPlayCursorSE if index!=oldindex
  920. elsif Input.trigger?(Input::LEFT)
  921. if index==0 || index==1
  922. param_index = (index==0)? 2 : 3
  923. param = params[param_index]
  924. param -= 1
  925. param -= 1 if PBTypes.isPseudoType?(param)
  926. if index == 1 && param < 0
  927. param = (param<-1)? PBTypes.maxValue : -1
  928. elsif param < 0
  929. param = PBTypes.maxValue
  930. end
  931. params[param_index] = param
  932. pbRefreshDexSearch(params,index)
  933. pbPlayCursorSE
  934. end
  935. elsif Input.trigger?(Input::RIGHT)
  936. if index==0 || index==1
  937. param_index = (index==0)? 2 : 3
  938. param = params[param_index]
  939. param += 1
  940. param += 1 if PBTypes.isPseudoType?(param)
  941. if index == 1 && param > PBTypes.maxValue
  942. param = -1
  943. elsif param > PBTypes.maxValue
  944. param = 0
  945. end
  946. params[param_index] = param
  947. pbRefreshDexSearch(params,index)
  948. pbPlayCursorSE
  949. end
  950. elsif Input.trigger?(Input::B)
  951. pbPlayCloseMenuSE
  952. break
  953. elsif Input.trigger?(Input::C)
  954. pbPlayDecisionSE if index!=2
  955. case index
  956. when 2 # Start search (filter)
  957. @frame = 0
  958. @sprites["searchcursor"].visible = true
  959. pbAnimSearch
  960. dexlist = pbSearchDexList(params)
  961. if dexlist.length==0
  962. pbMessage(_INTL("<c3=FFFFFFFF,00000000>No matching POKéMON were found.</c3>\\wtnp[40]"),nil,0,"Graphics/Windowskins/search")
  963. else
  964. @dexlist = dexlist
  965. @sprites["pokedex"].commands = @dexlist
  966. @sprites["pokedex"].index = 0
  967. @sprites["pokedex"].refresh
  968. @searchResults = true
  969. @searchParams = params
  970. break
  971. end
  972. when 3 # Cancel
  973. pbPlayCloseMenuSE
  974. break
  975. end
  976. end
  977. end
  978. pbFadeOutAndHide(@sprites)
  979. if @searchResults
  980. @sprites["background"].setBitmap("Graphics/Pictures/Pokedex/bg_listsearch")
  981. else
  982. @sprites["background"].setBitmap("Graphics/Pictures/Pokedex/bg_list")
  983. end
  984. pbRefresh
  985. pbFadeInAndShow(@sprites,oldsprites)
  986. Input.update
  987. return 0
  988. end
  989.  
  990. def pbAnimSearch
  991. pbWait(20)
  992. 5.times do
  993. i = 0
  994. 5.times do
  995. @sprites["searchanim"].src_rect.set(0+48*i,0,48,48)
  996. pbWait(4)
  997. i += 1
  998. end
  999. end
  1000. end
  1001.  
  1002. def pbPokedex
  1003. pbActivateWindow(@sprites,"pokedex") {
  1004. loop do
  1005. Graphics.update
  1006. Input.update
  1007. oldindex = @sprites["pokedex"].index
  1008. pbUpdate
  1009. if oldindex!=@sprites["pokedex"].index
  1010. $PokemonGlobal.pokedexIndex[pbGetSavePositionIndex] = @sprites["pokedex"].index if !@searchResults
  1011. pbRefresh
  1012. end
  1013. if Input.trigger?(Input::ENTER)
  1014. pbPlayDecisionSE
  1015. @sprites["pokedex"].active = false
  1016. pbDexSearch
  1017. @sprites["pokedex"].active = true
  1018. elsif Input.trigger?(Input::B)
  1019. if @searchResults
  1020. pbPlayCancelSE
  1021. pbCloseSearch
  1022. else
  1023. pbPlayCloseMenuSE
  1024. break
  1025. end
  1026. elsif Input.trigger?(Input::C)
  1027. if $Trainer.seen[@sprites["pokedex"].species]
  1028. pbPlayDecisionSE
  1029. pbDexEntry(@sprites["pokedex"].index)
  1030. end
  1031. end
  1032. end
  1033. }
  1034. end
  1035. end
  1036.  
  1037.  
  1038.  
  1039. class PokemonPokedexScreen
  1040. def initialize(scene)
  1041. @scene = scene
  1042. end
  1043.  
  1044. def pbStartScreen
  1045. @scene.pbStartScene
  1046. @scene.pbPokedex
  1047. @scene.pbEndScene
  1048. end
  1049. end
  1050.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement