ArchyTheArc

Untitled

Jun 24th, 2020
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 44.41 KB | None | 0 0
  1. # ========================================================================
  2. # Boonzeet's Habitat List
  3. # v1.0
  4. # ========================================================================
  5. # Extension for the Pokedex and Town Map to display a Habitat List -
  6. # a list of all the available Pokémon in the area, like in B2W2.
  7. # ========================================================================
  8. # Credit is required to use this script.
  9. # ========================================================================]
  10.  
  11. # Functions
  12. # ---------
  13. # Habitats.checkMapHabitat(mapID, type) e.g. Habitats.checkMapHabitat(5,:grass)
  14. # This checks the encounter type (from HabitatConfig::Types below) to see if
  15. # the player has seen or caught all the Pokémon for the type, returning 2 for
  16. # caught, 1 for seen, 0 for none. Used for NPCs that give items on completion.
  17. #
  18. # Habitats.updateHabitatsForSpecies(species)
  19. # Forces an update of all habitats associated with a species
  20. #
  21. # Habitats.setup
  22. # Run this to force a refresh or add Habitat data to an existing save. This
  23. # will reset the status of 'viewed' Habitats back to 'alert', so a player
  24. # will need to view completed habitats again to earn the badges.
  25. #
  26. # Habitats.update
  27. # Updates Pokémon data for all areas without clearing progress, unless new
  28. # Pokémon appear. Use this to update if you have changed Pokémon in areas.
  29. # !!! DO NOT USE if you have changed the order of the Habitats list
  30. # in the config. Use Habitats.setup instead if so
  31. #
  32. # Notes
  33. # ------
  34. # If marking a Pokémon as seen for the player, use pbSetSeen. Directly
  35. # manipulating the $Trainer.seen and $Trainer.owned arrays will not update
  36. # Habitat data.
  37. # For scripts that might directly edit these variables, add
  38. # Habitats.updateHabitatsForSpecies(species) underneath the seen/caught set.
  39.  
  40.  
  41. # ========================================================================
  42. # Config
  43. # ========================================================================
  44. # If using my Phenomenon script, uncomment the encounters below.
  45.  
  46. module HabitatConfig
  47. Types = {
  48. :grass => [
  49. EncounterTypes::Land,
  50. EncounterTypes::LandMorning,
  51. EncounterTypes::LandDay,
  52. EncounterTypes::LandNight,
  53. ],
  54. :place => [
  55. EncounterTypes::Cave,
  56. ],
  57. :surf => [
  58. EncounterTypes::Water,
  59. ],
  60. :lava => [
  61. EncounterTypes::Lava,
  62. ],
  63. :fish => [
  64. EncounterTypes::WoodenRod,
  65. EncounterTypes::RustedRod,
  66. EncounterTypes::FishingRod,
  67. EncounterTypes::TechRod,
  68. ],
  69. :net => [
  70. EncounterTypes::WoodenNet,
  71. EncounterTypes::RustedNet,
  72. EncounterTypes::BugNet,
  73. EncounterTypes::TechNet,
  74. ],
  75. :tree => [
  76. EncounterTypes::HeadbuttLow,
  77. EncounterTypes::HeadbuttHigh,
  78. EncounterTypes::Honey,
  79. ],
  80. :urban => [
  81. EncounterTypes::Bin,
  82. ],
  83. :marsh => [
  84. EncounterTypes::Mud,
  85. ]
  86. }
  87. TypeOrder = [:grass, :place, :surf, :lava, :fish, :net, :tree, :urban, :marsh] # order shown in screens
  88.  
  89. # Note: It's not recommend to use Place and Grass at the same time
  90. # 1. Array of map IDs for the same Habitat area
  91. # 2. Array of the Habitat Encounter Types for this Habitat (don't mix :grass and :place)
  92. # This order must be kept the same if Habitat.update is intended to be used
  93. # Remember the commas!
  94. Habitats = [
  95. [[38], [:surf, :tree]], #Newbark Town
  96. [[6, 6], [:grass, :surf, :fish, :net, :tree]], #Route 29 East
  97. [[11, 11], [:grass, :surf, :fish, :net, :tree]], #Route 29 West
  98. [[12], [:grass, :surf, :fish, :net, :tree, :Urban]], #Cherrygrove City
  99. [[13], [:grass, :surf, :fish, :net, :tree]], #Cherrygrove Shore
  100. [[14], [:grass, :surf, :fish, :net, :tree]], #Cherrygrove Port
  101. [[15], [:grass, :surf, :fish, :net, :tree]], #Route 30 South
  102. [[17], [:place]], #Invar Passage
  103. [[18], [:grass, :net, :tree]], #Route 30 North
  104. [[19], [:grass, :surf, :fish, :net, :tree]], #Route 31 East
  105. [[20], [:grass, :net, :tree]], #Caving Site A
  106. [[25], [:grass, :surf, :fish, :net, :tree]], #Route 31 West
  107. [[26], [:tree, :urban]], #Violet Eastern
  108. [[27], [:tree, :urban]], #Violet Southern
  109. [[29], [:surf, :tree, :urban]], #Violet Northern
  110. [[30], [:grass, :tree, :urban, :net]], #Violet Western
  111. [[31], [:grass, :surf, :fish, :net, :tree]] #Route 32 North
  112.  
  113. ]
  114.  
  115. # In some cases the automatic selector will choose another map on the same tile
  116. # e.g. a route instead of a cave. Supply the region,regionMapX,regionMapY here
  117. # and the mapID you want to load instead. Only one mapID for the Habitat is required.
  118. # Press CTRL+F on a map tile while in Debug to get the R,X,Y value quickly.
  119. # Remember the commas!
  120. RegionOverride = {
  121. #[0,15,6] => 34, # Ice Cave
  122. #[0,16,10] => 49 # Rock Cave
  123. }
  124. end
  125.  
  126. # ========================================================================
  127. # Existing Class Extensions
  128. # ========================================================================
  129.  
  130. # Adds the necessary save data to $Trainer and piggybacks on the setOwned command
  131. class PokeBattle_Trainer
  132. attr_accessor(:habitatData)
  133. attr_accessor(:habitatPokeIndexes)
  134. attr_accessor(:habitatMapIndexes)
  135.  
  136. alias setOwned_habitat setOwned
  137. def setOwned(species)
  138. setOwned_habitat(species)
  139. Habitats.updateHabitatsForSpecies(species)
  140. end
  141. end
  142.  
  143. # Sets up Habitats automatically when a new Trainer is created
  144. alias pbTrainerName_habitat pbTrainerName
  145. def pbTrainerName(*args)
  146. pbTrainerName_habitat(*args)
  147. Habitats.setup # setup habitat data for a new trainer
  148. end
  149.  
  150. # Modifies catch event to update Habitats list
  151. class PokeBattle_Battle
  152. alias pbSetSeen_habitat pbSetSeen
  153. def pbSetSeen(pokemon)
  154. prevseen = $Trainer.seen[pokemon.species]
  155. pbSetSeen_habitat(pokemon)
  156. Habitats.updateHabitatsForSpecies(pokemon.species) if !prevseen
  157. end
  158. end
  159.  
  160. # Allows Habitats code to access encounter types
  161. class PokemonEncounters
  162. attr_accessor :enctypes
  163. end
  164.  
  165. # Create a temp store of the Habitats encounters setup
  166. class PokemonTemp
  167. attr_accessor :habitatEncounters
  168. end
  169.  
  170. # Update habitats after Pokemon added
  171. alias pbNicknameAndStore_habitat pbNicknameAndStore
  172. def pbNicknameAndStore(pokemon)
  173. pbNicknameAndStore_habitat(pokemon)
  174. Habitats.updateHabitatsForSpecies(pokemon.species)
  175. end
  176.  
  177. # Update habitats after Pokemon added silently
  178. alias pbAddPokemonSilent_habitat pbAddPokemonSilent
  179. def pbAddPokemonSilent(pokemon, level = nil, seeform = true)
  180. pbAddPokemonSilent_habitat(pokemon, level, seeform)
  181. Habitats.updateHabitatsForSpecies(pokemon.species)
  182. end
  183.  
  184. # ========================================================================
  185. # Habitats Classes
  186. # ========================================================================
  187. class Habitats
  188.  
  189. # Shared for two functions. Indexes a sp
  190. def self.processEncounterPokemon(n, encounter, sysindex)
  191. # If we've not seen this 'mon, add a quick index to look up the Habitat data
  192. $Trainer.habitatPokeIndexes[n] = [] if !$Trainer.habitatPokeIndexes.key?(n)
  193.  
  194. $Trainer.habitatPokeIndexes[n].push(sysindex)
  195. # As soon as we encounter an unowned/unseen Pokémon, we can say that the
  196. # player hasn't completed that part of the Habitat
  197. if !$Trainer.owned[n]
  198. encounter[:owned] = false
  199. if !$Trainer.seen[n]
  200. encounter[:seen] = false
  201. encounter[:alert] = false
  202. end
  203. end
  204. end
  205.  
  206. # Loads a list of all available Pokémon across the encounter types
  207. # for a given Habitat Type
  208. def self.loadEncountersForType(index, habitatEncounter, enctypes, types, sysindex)
  209. pokes = []
  210. # Iterate over each encounter type in the Habitat type and add unique pokemon
  211. types.each do |t|
  212. if $PokemonTemp.habitatEncounters.hasEncounter?(t)
  213. enc = enctypes[t]
  214. for i in 0...enc.length
  215. pokes.push(enc[i][0])
  216. end
  217. pokes.uniq!
  218. end
  219. end
  220. if pokes.length
  221. pokes.each do|n|
  222. self.processEncounterPokemon(n,habitatEncounter,sysindex)
  223. end
  224. end
  225. habitatEncounter[:list].push(*pokes).uniq!
  226. end
  227.  
  228. # Adds the data for a Habitat Config Item to the $Trainer.habitatData object
  229. def self.addHabitat(habitat, index)
  230. newHabitat = {
  231. :mapIDs => habitat[0],
  232. :completed => false, # gets marked as true on view
  233. :encounters => Hash.new,
  234. }
  235. # Add indexing for each mapID
  236. habitat[0].each do |n|
  237. $Trainer.habitatMapIndexes[n] = index
  238. end
  239.  
  240. for type in habitat[1]
  241. newHabitat[:encounters][type] = {
  242. :alert => true,
  243. :seen => true,
  244. :owned => true,
  245. :list => [],
  246. }
  247. end
  248. for i in 0...habitat[0].length
  249. $PokemonTemp.habitatEncounters.setup(habitat[0][i])
  250. for type in habitat[1]
  251. self.loadEncountersForType(i, newHabitat[:encounters][type],
  252. $PokemonTemp.habitatEncounters.enctypes, HabitatConfig::Types[type], index)
  253. end
  254. end
  255. return newHabitat
  256. end
  257.  
  258. # Updates an existing habitat
  259. def self.updateHabitat(habitat, index)
  260. existingHabitat = $Trainer.habitatData[index]
  261. if existingHabitat == nil
  262. print "#{index} failed at Habitat check"
  263. end
  264. # Add or update indexing for each mapID
  265. habitat[0].each do |n|
  266. $Trainer.habitatMapIndexes[n] = index
  267. end
  268. for type in habitat[1]
  269. if !existingHabitat[:encounters].key?(type)
  270. !existingHabitat[:encounters][type] = {
  271. :alert => true,
  272. :seen => true,
  273. :owned => true,
  274. :list => [],
  275. }
  276. end
  277. end
  278. for i in 0...habitat[0].length
  279. $PokemonTemp.habitatEncounters.setup(habitat[0][i])
  280. for type in habitat[1]
  281. self.loadEncountersForType(i, existingHabitat[:encounters][type],
  282. $PokemonTemp.habitatEncounters.enctypes, HabitatConfig::Types[type], index)
  283. if !existingHabitat[:encounters][type][:owned]
  284. existingHabitat[:completed] = false
  285. end
  286. end
  287. end
  288. end
  289.  
  290.  
  291. # Clears any existing habitats - avoid using as will wipe progress
  292. def self.clear
  293. $Trainer.habitatData = []
  294. $Trainer.habitatPokeIndexes = Hash.new
  295. $Trainer.habitatMapIndexes = Hash.new
  296. end
  297.  
  298. # First-run setup of the Habitats, from the Habitat config
  299. def self.setup
  300. self.clear
  301. $PokemonTemp.habitatEncounters = PokemonEncounters.new
  302. for i in 0...HabitatConfig::Habitats.length
  303. habitat = addHabitat(HabitatConfig::Habitats[i], i)
  304. $Trainer.habitatData.push(habitat)
  305. end
  306. end
  307.  
  308. # Updates the Habitats without deleting data
  309. def self.update
  310. $PokemonTemp.habitatEncounters = PokemonEncounters.new
  311. for i in 0...HabitatConfig::Habitats.length
  312. if i < $Trainer.habitatData.size
  313. updateHabitat(HabitatConfig::Habitats[i], i)
  314. else
  315. habitat = addHabitat(HabitatConfig::Habitats[i], i)
  316. $Trainer.habitatData.push(habitat)
  317. end
  318. end
  319. end
  320.  
  321. # Updates the status for a habitat type.
  322. # Checks if all owned/seen and sets status to alert if something's changed
  323. def self.updateHabitatTypeStatus(habitatType)
  324. seen = true
  325. owned = true
  326. habitatType[:list].each do |n|
  327. if !$Trainer.owned[n]
  328. owned = false
  329. if !$Trainer.seen[n]
  330. seen = false
  331. break
  332. end
  333. end
  334. end
  335. if seen != habitatType[:seen] || owned != habitatType[:owned]
  336. habitatType[:alert] = true
  337. end
  338. habitatType[:seen] = seen
  339. habitatType[:owned] = owned
  340. end
  341.  
  342. # Fetches data for a Habitat
  343. def self.getIndexByMapID(mapID)
  344. return $Trainer.habitatMapIndexes.key?(mapID) ? $Trainer.habitatMapIndexes[mapID] : -1
  345. end
  346.  
  347. # Updates a Habitat by its Index
  348. def self.updateHabitatStatus(index)
  349. if index > -1
  350. encounters = $Trainer.habitatData[index][:encounters]
  351. for type in encounters.keys
  352. self.updateHabitatTypeStatus(encounters[type])
  353. end
  354. end
  355. end
  356.  
  357. # Updates all the Habitat records for a given species
  358. def self.updateHabitatsForSpecies(species)
  359. if species.is_a?(String) || species.is_a?(Symbol)
  360. species = getID(PBSpecies,species)
  361. end
  362. if $Trainer.habitatPokeIndexes && $Trainer.habitatPokeIndexes.key?(species)
  363. ids = $Trainer.habitatPokeIndexes[species]
  364. for i in 0...ids.length
  365. self.updateHabitatStatus(ids[i])
  366. end
  367. end
  368. end
  369.  
  370. # Check if the player has been to the habitat
  371. def self.visited?(index)
  372. if index > $Trainer.habitatData.size
  373. return false
  374. end
  375. h = $Trainer.habitatData[index]
  376. for i in 0...h[:mapIDs].size
  377. if $PokemonGlobal.visitedMaps[h[:mapIDs][i]]
  378. return true
  379. break
  380. end
  381. end
  382. return false
  383. end
  384.  
  385.  
  386. # Checks the status of a Habitat by Map ID
  387. # Returns 2 if all owned, 1 if all seen, 0 if not
  388. def self.checkMapHabitat(mapID, type)
  389. index = self.getIndexByMapID(mapID)
  390. if index == -1
  391. Kernel.pbMessage("The Habitat List for map ##{mapID} isn't set up.")
  392. return
  393. end
  394. encounters = $Trainer.habitatData[index][:encounters]
  395. if encounters[type][:owned]
  396. return 2
  397. elsif encounters[type][:seen]
  398. return 1
  399. else
  400. return 0
  401. end
  402. end
  403.  
  404. # Gets a list of all Habitats formatted for UI elements
  405. def self.getHabitatList
  406. commandlist = []
  407. if $Trainer && defined?($Trainer.habitatData)
  408. $Trainer.habitatData.each_with_index do |h, i|
  409. if self.visited?(i)
  410. command = [i, h[:mapIDs][0], h[:encounters], h[:completed]]
  411. commandlist.push(command)
  412. end
  413. end
  414. end
  415. #commandlist.sort! { |a, b| a[0] <=> b[0] }
  416. return commandlist
  417. end
  418.  
  419. # finds habitat index by region map coords
  420. def self.getIndexByRegionCoords(x,y, region, mapdata)
  421. meta = pbLoadMetadata
  422. find = nil
  423. meta.each_with_index do |n,index|
  424. next if !n || n.size < MetadataMapPosition || !n[MetadataMapPosition]
  425. mappos = n[MetadataMapPosition]
  426. next if !mappos || mappos[0] != region
  427.  
  428. # We can just return the mapID if the coords match
  429. if mappos[1] == x && mappos[2] == y
  430. sysindex = self.getIndexByMapID(index)
  431. return self.visited?(sysindex) ? sysindex : -1
  432. end
  433.  
  434. # If we've still not got the map ID match, look at map shapes
  435. points = []
  436. showpoint = true
  437. for loc in mapdata[region][2]
  438. showpoint = false if loc[0] == mappos[1] && loc[1] == mappos[2] &&
  439. loc[7] && !$game_switches[loc[7]]
  440. end
  441. if showpoint
  442. mapsize = n[MetadataMapSize]
  443. if mapsize && mapsize[0] && mapsize[0] > 0
  444. sqwidth = mapsize[0]
  445. sqheight = (mapsize[1].length * 1.0 / mapsize[0]).ceil
  446. for i in 0...sqwidth
  447. for j in 0...sqheight
  448. if mapsize[1][i + j * sqwidth, 1].to_i > 0
  449. points.push([mappos[1] + i,(mappos[2] + j)])
  450. end
  451. end
  452. end
  453. else
  454. points.push([mappos[1],mappos[2]])
  455. end
  456. end
  457. if points.size > 0
  458. points.each do |p|
  459. if p[0] == x && p[1] == y
  460. sysindex = self.getIndexByMapID(index)
  461. return self.visited?(sysindex) ? sysindex : -1
  462. end
  463. end
  464. end
  465. end
  466. return -1
  467. end
  468.  
  469. # -------
  470. # Debug functions
  471. # -------
  472. # Check status for all types across a Habitat
  473. def self.debugHabitat(index)
  474. if index == nil || index > $Trainer.habitatData.size
  475. return
  476. end
  477. habitat = $Trainer.habitatData[index]
  478. encounters = habitat[:encounters]
  479. output = "MapIDs: #{habitat[:mapIDs].join(",")}\n"
  480. for type in encounters.keys
  481. output += "#{type}: Seen #{encounters[type][:seen]},"
  482. output += "Owned #{encounters[type][:owned]},"
  483. output += "Alert #{encounters[type][:alert]}\n"
  484. end
  485. Kernel.pbMessage(output)
  486. end
  487.  
  488. # Test if a species has a record in Habitats
  489. def self.debugSpecies(species)
  490. Kernel.pbMessage($Trainer.habitatPokeIndexes.keys.join(", "))
  491. if $Trainer.habitatPokeIndexes && $Trainer.habitatPokeIndexes.key?(species)
  492. Kernel.pbMessage("Species #{species} logged")
  493. else
  494. Kernel.pbMessage("Species #{species} not logged")
  495. end
  496. end
  497. end
  498.  
  499. #===============================================================================
  500. # Habitats Menu List UI
  501. #===============================================================================
  502.  
  503. class Window_HabitatList < Window_DrawableCommand
  504.  
  505. attr_accessor(:region)
  506. def initialize(x, y, width, height, viewport)
  507. @commands = []
  508. super(x, y, width, height, viewport)
  509. @habitatbg = Bitmap.new(32, 32)
  510. @habitatoverlay = Bitmap.new(32, 32)
  511. @habitatoverlay.fill_rect(0, 0, 32, 32, Color.new(0, 0, 0, 100))
  512. @habitatoverlay.fill_rect(2, 2, 28, 14, Color.new(0, 0, 0, 0))
  513. @habitatoverlay.fill_rect(2, 16, 28, 14, Color.new(0, 0, 0, 20))
  514. @selarrow = AnimatedBitmap.new("Graphics/Pictures/Habitats/cursor_list")
  515. @pokeballOwn = AnimatedBitmap.new("Graphics/Pictures/Habitats/icon_list_owned")
  516. @pokeballSeen = AnimatedBitmap.new("Graphics/Pictures/Habitats/icon_list_seen")
  517. @pokeballAlert = AnimatedBitmap.new("Graphics/Pictures/Habitats/icon_list_alert")
  518.  
  519. @completed = Bitmap.new(84, height)
  520. bmp = BitmapCache.load_bitmap("Graphics/Pictures/Habitats/stamp_seen")
  521. @completed.blt(0, 0, bmp, Rect.new(0, 14, 84, 38))
  522.  
  523. self.baseColor = Color.new(88, 88, 80)
  524. self.shadowColor = Color.new(168, 184, 184)
  525. self.windowskin = nil
  526. end
  527.  
  528. def commands=(value)
  529. @commands = value
  530. refresh
  531. end
  532.  
  533. def dispose
  534. @pokeballOwn.dispose
  535. @pokeballSeen.dispose
  536. super
  537. end
  538.  
  539. def itemCount
  540. return @commands.length
  541. end
  542.  
  543. def drawEncounterIcon(i, type, encounter, rect)
  544. if type == :grass || type == :net
  545. color = Color.new(86, 168, 0)
  546. elsif type == :surf
  547. color = Color.new(24, 206, 239)
  548. elsif type == :lava
  549. color = Color.new(188, 52, 52)
  550. elsif type == :tree
  551. color = Color.new(224, 170, 41)
  552. elsif type == :place || type == :marsh
  553. color = Color.new(160, 111, 64)
  554. elsif type == :urban
  555. color = Color.new(161, 161, 161)
  556. end
  557. @habitatbg.fill_rect(0, 0, 32, 32, color)
  558. @habitatbg.stretch_blt(@habitatbg.rect, @habitatoverlay, @habitatoverlay.rect)
  559.  
  560. baseX = rect.x + 104 - (32 * i)
  561. pbCopyBitmap(self.contents, @habitatbg, baseX, rect.y + 6)
  562. if encounter[:alert]
  563. pbCopyBitmap(self.contents, @pokeballAlert.bitmap, baseX + 2, rect.y + 8)
  564. elsif encounter[:owned]
  565. pbCopyBitmap(self.contents, @pokeballOwn.bitmap, baseX + 2, rect.y + 8)
  566. elsif encounter[:seen]
  567. pbCopyBitmap(self.contents, @pokeballSeen.bitmap, baseX + 2, rect.y + 8)
  568. end
  569. i += 1
  570. end
  571.  
  572. def drawItem(index, count, rect)
  573. return if index >= self.top_row + self.page_item_max
  574. rect = Rect.new(rect.x, rect.y, rect.width - 16, rect.height)
  575. encounters = @commands[index][2]
  576. if @commands[index][3]
  577. pbCopyBitmap(self.contents, @completed, rect.x + 244, rect.y + 2)
  578. end
  579.  
  580. i = 1
  581. HabitatConfig::TypeOrder.each do |n|
  582. next if n==:net || n==:fish || n==:urban || n==:marsh
  583. if encounters.key?(n)
  584. drawEncounterIcon(i, n, encounters[n], rect)
  585. i += 1
  586. end
  587. end
  588.  
  589. text = sprintf("%s", pbGetMessage(MessageTypes::MapNames, @commands[index][1]))
  590. pbDrawShadowText(self.contents, rect.x + 128, rect.y + 6, rect.width, rect.height,
  591. text, self.baseColor, self.shadowColor)
  592. end
  593.  
  594. def refresh
  595. @item_max = itemCount
  596. dwidth = self.width - self.borderX
  597. dheight = self.height - self.borderY
  598. self.contents = pbDoEnsureBitmap(self.contents, dwidth, dheight)
  599. self.contents.clear
  600. for i in 0...@item_max
  601. next if i < self.top_item || i > self.top_item + self.page_item_max
  602. drawItem(i, @item_max, itemRect(i))
  603. end
  604. mappos = (@commands.length == 0) ? nil : pbGetMetadata(@commands[index][1], MetadataMapPosition)
  605. @region = (mappos) ? mappos[0] : 0 # Region 0 default
  606. drawCursor(self.index, itemRect(self.index))
  607. end
  608.  
  609. def update
  610. super
  611. @uparrow.visible = false
  612. @downarrow.visible = false
  613. end
  614. end
  615.  
  616. class PokemonGlobalMetadata
  617. attr_accessor :habitatIndex
  618. end
  619.  
  620. class PokemonHabitatList_Scene
  621. def pbUpdate
  622. pbUpdateSpriteHash(@sprites)
  623. end
  624.  
  625. def pbStartScene
  626. @sprites = {}
  627. @viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
  628. @viewport.z = 99999
  629. addBackgroundPlane(@sprites, "background", "Habitats/bg_list", @viewport)
  630. @sprites["habitatlist"] = Window_HabitatList.new(100, 34, 380, 364, @viewport)
  631. @sprites["overlay"] = BitmapSprite.new(Graphics.width, Graphics.height, @viewport)
  632. #@sprites["mapthumb"] = IconSprite.new(8, 68, @viewport)
  633. #@sprites["mapthumb"].setBitmap("Graphics/Pictures/Habitats/mapthumbRegion0")
  634. pbSetSystemFont(@sprites["overlay"].bitmap)
  635. if ($PokemonGlobal.habitatIndex)
  636. pbRefreshHabitatList($PokemonGlobal.habitatIndex)
  637. else
  638. pbRefreshHabitatList(0)
  639. end
  640.  
  641. pbDeactivateWindows(@sprites)
  642. pbFadeInAndShow(@sprites)
  643. end
  644.  
  645. def pbEndScene
  646. pbFadeOutAndHide(@sprites)
  647. pbDisposeSpriteHash(@sprites)
  648. @viewport.dispose
  649. end
  650.  
  651. def pbRefreshHabitatList(index = 0)
  652. @habitatlist = Habitats.getHabitatList
  653. @sprites["habitatlist"].commands = @habitatlist
  654. @sprites["habitatlist"].index = index > @habitatlist.size ? 0 : index
  655. @sprites["habitatlist"].refresh
  656. pbRefresh
  657. end
  658.  
  659. def pbRefresh
  660. overlay = @sprites["overlay"].bitmap
  661. overlay.clear
  662. base = Color.new(88, 88, 80)
  663. shadow = Color.new(168, 184, 184)
  664. # Write various bits of text
  665. dexname = _INTL("Habitat List")
  666. textpos = [
  667. [dexname, (Graphics.width / 2)+10, 18, 2, Color.new(88, 88, 80), Color.new(168, 184, 184)],
  668. ]
  669. # Draw all text
  670. pbDrawTextPositions(overlay, textpos)
  671. end
  672.  
  673. def pbProcessEntry
  674. pbActivateWindow(@sprites, "habitatlist") {
  675. loop do
  676. Graphics.update
  677. Input.update
  678. oldindex = @sprites["habitatlist"].index
  679. pbUpdate
  680. if oldindex != @sprites["habitatlist"].index
  681. $PokemonGlobal.habitatIndex = @sprites["habitatlist"].index
  682. region = @sprites["habitatlist"].region
  683. #if FileTest.image_exist?("Graphics/Pictures/Habitats/mapthumbRegion#{region}")
  684. # @sprites["mapthumb"].setBitmap("Graphics/Pictures/Habitats/mapthumbRegion#{region}")
  685. #end
  686. pbRefresh
  687. end
  688. if Input.trigger?(Input::C)
  689. pbPlayDecisionSE
  690. pbHabitatDetail(@sprites["habitatlist"].index)
  691. elsif Input.trigger?(Input::B)
  692. pbPlayCancelSE
  693. break
  694. end
  695. end
  696. }
  697. end
  698.  
  699. def pbHabitatDetail(index)
  700. oldsprites = pbFadeOutAndHide(@sprites)
  701. ret = -1
  702. scene = HabitatDetailScene.new
  703. screen = HabitatDetailScreen.new(scene)
  704. ret = screen.pbStartScreen(index, @habitatlist, @sprites["habitatlist"].region)
  705. $PokemonGlobal.habitatIndex = ret
  706. @sprites["habitatlist"].index = ret
  707. @sprites["habitatlist"].refresh
  708. pbRefresh
  709. pbFadeInAndShow(@sprites, oldsprites)
  710. end
  711. end
  712.  
  713. class PokemonHabitatListScreen
  714. def initialize(scene)
  715. @scene = scene
  716. end
  717.  
  718. def pbStartScreen
  719. @scene.pbStartScene
  720. @scene.pbProcessEntry
  721. @scene.pbEndScene
  722. end
  723. end
  724.  
  725. def pbLoadHabitatList
  726. pbFadeOutIn(99999) {
  727. scene = PokemonHabitatList_Scene.new
  728. screen = PokemonHabitatListScreen.new(scene)
  729. screen.pbStartScreen
  730. }
  731. end
  732.  
  733.  
  734. #===============================================================================
  735. # Habitats Menu Detail Screen UI
  736. #===============================================================================
  737.  
  738. #============================
  739. # Habitat View Screen
  740. #============================
  741. class HabitatDetailScene
  742. def setup(index)
  743. @viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
  744. @viewport.z = 99999
  745. @index = index
  746. @page = 0
  747. @encounter = nil
  748. @animateStamp = false
  749. @loaded = false
  750. @order = []
  751.  
  752. @labels = {
  753. :grass => "Pokémon found in tall grass",
  754. :place => "Pokémon found in caves",
  755. :surf => "Pokémon found by surfing",
  756. :fish => "Pokémon caught with a rod",
  757. :net => "Pokémon caught with a net",
  758. :lava => "Pokémon found by surfing",
  759. :tree => "Pokémon found by headbutting trees",
  760. :urban => "Pokémon found in bins",
  761. :marsh => "Pokémon found in mud",
  762. }
  763.  
  764. @sprites = {}
  765. @sprites["background"] = IconSprite.new(0, 0, @viewport)
  766. @sprites["infosprite"] = PokemonSprite.new(@viewport)
  767. #@sprites["infosprite"].setOffset(PictureOrigin::Center)
  768. @sprites["infosprite"].x = 104
  769. @sprites["infosprite"].y = 136
  770. @sprites["leftarrow"] = IconSprite.new(20, 10, @viewport)
  771. @sprites["rightarrow"] = IconSprite.new(Graphics.width - 38, 10, @viewport)
  772. @sprites["leftarrow"].setBitmap("Graphics/Pictures/Habitats/selarrows")
  773. @sprites["rightarrow"].setBitmap("Graphics/Pictures/Habitats/selarrows")
  774. @sprites["leftarrow"].src_rect.set(0, 0, 18, 26)
  775. @sprites["rightarrow"].src_rect.set(18, 0, 18, 26)
  776.  
  777. @sprites["habitat_icon_grass"] = IconSprite.new(0, 12, @viewport)
  778. @sprites["habitat_icon_surf"] = IconSprite.new(0, 12, @viewport)
  779. @sprites["habitat_icon_fish"] = IconSprite.new(0, 12, @viewport)
  780. @sprites["habitat_icon_net"] = IconSprite.new(0, 12, @viewport)
  781. @sprites["habitat_icon_lava"] = IconSprite.new(0, 12, @viewport)
  782. @sprites["habitat_icon_tree"] = IconSprite.new(0, 12, @viewport)
  783. @sprites["habitat_icon_urban"] = IconSprite.new(0, 12, @viewport)
  784. @sprites["habitat_icon_marsh"] = IconSprite.new(0, 12, @viewport)
  785. @sprites["habitat_icon_cave"] = IconSprite.new(0, 12, @viewport)
  786. @sprites["habitat_icon_map"] = IconSprite.new(0, 20, @viewport)
  787. @sprites["habitat_cursor"] = IconSprite.new(0, 8, @viewport)
  788.  
  789. @sprites["habitat_pokemon"] = BitmapSprite.new(62, 62, @viewport)
  790. @sprites["habitat_pokemonbg"] = IconSprite.new(62, 48, @viewport)
  791. @sprites["habitat_pokemonsprite"] = IconSprite.new(62, 62, @viewport)
  792.  
  793. @sprites["stamp"] = ChangelingSprite.new(400, 293, @viewport)
  794. @sprites["stamp"].addBitmap("s_owned", "Graphics/Pictures/Habitats/stamp_owned")
  795. @sprites["stamp"].addBitmap("s_seen", "Graphics/Pictures/Habitats/stamp_seen")
  796. @sprites["stamp"].visible = false
  797.  
  798. @sprites["habitat_icon_grass"].setBitmap("Graphics/Pictures/Habitats/habitat_grass")
  799. @sprites["habitat_icon_surf"].setBitmap("Graphics/Pictures/Habitats/habitat_surf")
  800. @sprites["habitat_icon_fish"].setBitmap("Graphics/Pictures/Habitats/habitat_fish")
  801. @sprites["habitat_icon_net"].setBitmap("Graphics/Pictures/Habitats/habitat_net")
  802. @sprites["habitat_icon_lava"].setBitmap("Graphics/Pictures/Habitats/habitat_lava")
  803. @sprites["habitat_icon_tree"].setBitmap("Graphics/Pictures/Habitats/habitat_tree")
  804. @sprites["habitat_icon_urban"].setBitmap("Graphics/Pictures/Habitats/habitat_urban")
  805. @sprites["habitat_icon_marsh"].setBitmap("Graphics/Pictures/Habitats/habitat_marsh")
  806. @sprites["habitat_icon_cave"].setBitmap("Graphics/Pictures/Habitats/habitat_cave")
  807. @sprites["habitat_icon_map"].setBitmap("Graphics/Pictures/Habitats/habitat_map")
  808. @sprites["habitat_cursor"].setBitmap("Graphics/Pictures/Habitats/habitat_cursor")
  809.  
  810. @sprites["overlay"] = BitmapSprite.new(Graphics.width, Graphics.height, @viewport)
  811. pbSetSystemFont(@sprites["overlay"].bitmap)
  812.  
  813. end
  814.  
  815. # Start scene from Pokédex view
  816. def pbStartScene(index, habitatlist, region)
  817. setup(index)
  818. @single = false
  819. @habitatlist = habitatlist
  820. @habitat = $Trainer.habitatData[@habitatlist[@index][0]]
  821. @encpages = @habitat[:encounters].keys.size - 1
  822. HabitatConfig::TypeOrder.each do |n|
  823. if @habitat[:encounters].key?(n)
  824. @order.push(n)
  825. end
  826. end
  827. setEncounter
  828.  
  829. pbRgssOpen("Data/townmap.dat", "rb") { |f|
  830. @mapdata = Marshal.load(f)
  831. }
  832. @region = region
  833. @sprites["areamap"] = IconSprite.new(0, 0, @viewport)
  834. @sprites["areamap"].setBitmap("Graphics/Pictures/Townmap/#{@mapdata[@region][1]}")
  835. @sprites["areamap"].x += (Graphics.width - @sprites["areamap"].bitmap.width) / 2
  836. @sprites["areamap"].y += (Graphics.width - @sprites["areamap"].bitmap.width) / 2
  837. #@sprites["areamap"].y += (Graphics.height + 46 - @sprites["areamap"].bitmap.height) / 2
  838. for hidden in REGIONMAPEXTRAS
  839. if hidden[0] == @region && hidden[1] > 0 && $game_switches[hidden[1]]
  840. pbDrawImagePositions(@sprites["areamap"].bitmap, [
  841. ["Graphics/Pictures/#{hidden[4]}",
  842. hidden[2] * PokemonRegionMapScene::SQUAREWIDTH,
  843. hidden[3] * PokemonRegionMapScene::SQUAREHEIGHT, 0, 0, -1, -1],
  844. ])
  845. end
  846. end
  847. @sprites["areahighlight"] = BitmapSprite.new(Graphics.width, Graphics.height, @viewport)
  848.  
  849. drawPage(@page)
  850. pbFadeInAndShow(@sprites) { pbUpdate }
  851. @loaded = true
  852. updateStamp
  853. end
  854.  
  855. # Start scene from Region Map view
  856. def pbStartSceneSingle(index)
  857. setup(index)
  858. @single = true
  859. @sprites["habitat_icon_map"].visible = false
  860. @habitat = $Trainer.habitatData[index]
  861. @encpages = @habitat[:encounters].keys.size - 1
  862. HabitatConfig::TypeOrder.each do |n|
  863. if @habitat[:encounters].key?(n)
  864. @order.push(n)
  865. end
  866. end
  867. setEncounter
  868. drawPage(@page)
  869. pbFadeInAndShow(@sprites) { pbUpdate }
  870. @loaded = true
  871. updateStamp
  872. end
  873.  
  874. def pbUpdateHabitat
  875. for i in 0...@encounter[:list].size
  876. if defined?(@sprites["pokemon#{i}"])
  877. #@pkmnsprite.dispose
  878. @sprites["pokemon#{i}"].dispose
  879. end
  880. end
  881. @habitat = $Trainer.habitatData[@habitatlist[@index][0]]
  882. @order = []
  883.  
  884. HabitatConfig::TypeOrder.each do |n|
  885. if @habitat[:encounters].key?(n)
  886. @order.push(n)
  887. end
  888. end
  889.  
  890. oldsize = @encpages
  891. @encpages = @order.size - 1
  892. if @page == oldsize
  893. @page = @encpages
  894. elsif @page >= @encpages
  895. @page = @encpages
  896. end
  897. end
  898.  
  899. def setEncounter
  900. key = @order[@page]
  901. @encounter = @habitat[:encounters][key]
  902. end
  903.  
  904. def pbEndScene
  905. pbFadeOutAndHide(@sprites) { pbUpdate }
  906. pbDisposeSpriteHash(@sprites)
  907. @viewport.dispose
  908. end
  909.  
  910. def pbUpdate
  911. if @single == false && @page == -1
  912. intensity = (Graphics.frame_count % 40) * 12
  913. intensity = 480 - intensity if intensity > 240
  914. @sprites["areahighlight"].opacity = intensity
  915. end
  916. pbUpdateSpriteHash(@sprites)
  917. end
  918.  
  919. def drawPage(page)
  920. setEncounter
  921.  
  922. overlay = @sprites["overlay"].bitmap
  923. overlay.clear
  924. if @single == false
  925. @sprites["areamap"].visible = (@page == -1) if @sprites["areamap"]
  926. @sprites["areahighlight"].visible = (@page == -1) if @sprites["areahighlight"]
  927. end
  928.  
  929. @sprites["habitat_icon_grass"].visible = false
  930. @sprites["habitat_icon_cave"].visible = false
  931. @sprites["habitat_icon_surf"].visible = false
  932. @sprites["habitat_icon_fish"].visible = false
  933. @sprites["habitat_icon_net"].visible = false
  934. @sprites["habitat_icon_lava"].visible = false
  935. @sprites["habitat_icon_tree"].visible = false
  936. @sprites["habitat_icon_urban"].visible = false
  937. @sprites["habitat_icon_marsh"].visible = false
  938. @sprites["habitat_cursor"].visible = true
  939. @sprites["stamp"].visible = false
  940.  
  941. # uses the TypeOrder to print keys in order
  942. x = 0
  943. @order.each_with_index do |key, i|
  944. x = 52 + ((i + (@single == false ? 1 : 0)) * 70)
  945. sprite = ""
  946. case key
  947. when :grass
  948. sprite = "habitat_icon_grass"
  949. when :place
  950. sprite = "habitat_icon_cave"
  951. when :surf
  952. sprite = "habitat_icon_surf"
  953. when :fish
  954. sprite = "habitat_icon_fish"
  955. when :net
  956. sprite = "habitat_icon_net"
  957. when :lava
  958. sprite = "habitat_icon_lava"
  959. when :tree
  960. sprite = "habitat_icon_tree"
  961. when :urban
  962. sprite = "habitat_icon_urban"
  963. when :marsh
  964. sprite = "habitat_icon_marsh"
  965. end
  966. @sprites[sprite].x = x
  967. @sprites[sprite].visible = true
  968.  
  969. if i == page
  970. @sprites["habitat_cursor"].x = x - 4
  971. end
  972. end
  973. if @single == false
  974. @sprites["habitat_icon_map"].x = 60
  975. end
  976.  
  977. # control visuals depending on page
  978. @sprites["leftarrow"].opacity = 255
  979. @sprites["rightarrow"].opacity = 255
  980. if page == @encpages
  981. @sprites["rightarrow"].opacity = 125
  982. end
  983. if @single == false
  984. if page == -1
  985. @sprites["habitat_icon_map"].opacity = 255
  986. @sprites["habitat_cursor"].x = 48
  987. @sprites["leftarrow"].opacity = 125
  988. else
  989. @sprites["habitat_icon_map"].opacity = 125
  990. end
  991. else
  992. if @page == 0
  993. @sprites["leftarrow"].opacity = 125
  994. end
  995. end
  996.  
  997. # Draw page-specific information
  998. if @single || page > -1
  999. key = @order[page]
  1000. drawPageInfo(key)
  1001. else
  1002. drawPageArea
  1003. end
  1004. end
  1005.  
  1006. def updateStamp
  1007. if @page > -1 && @encounter != nil
  1008. # if alert flag is set, play the stamp animation
  1009. if @encounter[:alert]
  1010. return if !@loaded # wait until load to play anim
  1011. animateStamp(@encounter[:owned]) if @encounter != nil
  1012. @encounter[:alert] = false
  1013. completed = true
  1014. for type in @habitat[:encounters].keys
  1015. if @habitat[:encounters][type][:alert] || !@habitat[:encounters][type][:owned]
  1016. completed = false
  1017. end
  1018. end
  1019. @habitat[:completed] = completed
  1020.  
  1021. # otherwise just draw the appropriate stamp
  1022. elsif @encounter[:owned] || @encounter[:seen]
  1023. drawStamp(@encounter[:owned])
  1024. end
  1025. end
  1026. end
  1027.  
  1028. # Draws a stamp animation. Takes owned true/false to determine owned/seen stamp
  1029. def animateStamp(owned)
  1030. @sprites["stamp"].changeBitmap(owned ? "s_owned" : "s_seen")
  1031. @sprites["stamp"].opacity = 0
  1032. @sprites["stamp"].x -= 34
  1033. @sprites["stamp"].y -= 34
  1034. @sprites["stamp"].zoom_x = 1.51
  1035. @sprites["stamp"].zoom_y = 1.51
  1036. @sprites["stamp"].visible = true
  1037.  
  1038. for i in 0..17
  1039. @sprites["stamp"].opacity += 15
  1040. if @sprites["stamp"].zoom_x > 1.0
  1041. @sprites["stamp"].zoom_x -= 0.03
  1042. @sprites["stamp"].zoom_y -= 0.03
  1043. end
  1044. if @sprites["stamp"].x < 400
  1045. @sprites["stamp"].x += 2
  1046. @sprites["stamp"].y += 2
  1047. end
  1048. if @sprites["stamp"].opacity > 255
  1049. @sprites["stamp"].opacity = 255
  1050. end
  1051. pbWait(1)
  1052. Graphics.update
  1053. end
  1054. end
  1055.  
  1056. # Draws a stamp without animation
  1057. def drawStamp(owned)
  1058. @sprites["stamp"].changeBitmap(owned ? "s_owned" : "s_seen")
  1059. @sprites["stamp"].visible = true
  1060. end
  1061.  
  1062. def drawPageInfo(type)
  1063. @sprites["background"].setBitmap(_INTL("Graphics/Pictures/Habitats/bg_info"))
  1064.  
  1065. @encounter[:list].each_with_index do |n, i|
  1066. x = (i % 6) * 72 + 36
  1067. y = ((i.to_f / 6).floor * 64) + 80
  1068. status = "none"
  1069. if $Trainer.owned[i]
  1070. status = "owned"
  1071. elsif $Trainer.seen[i]
  1072. status = "seen"
  1073. end
  1074. @sprites["pokemon#{i}"] = HabitatPokemonPanel.new(n, status, x, y, @viewport)
  1075. end
  1076.  
  1077. typelabel = @labels.key?(type) ? @labels[type] : @labels[:place]
  1078.  
  1079. overlay = @sprites["overlay"].bitmap
  1080. base = Color.new(88, 88, 80)
  1081. shadow = Color.new(168, 184, 184)
  1082. textpos = [
  1083. [pbGetMessage(MessageTypes::MapNames, @habitat[:mapIDs][0]), 24 + 156, 298, 0, base, shadow],
  1084. [typelabel, 24, 338, 0, base, shadow],
  1085. ]
  1086. pbDrawTextPositions(@sprites["overlay"].bitmap, textpos)
  1087.  
  1088. @sprites["stamp"].visible = false
  1089. updateStamp
  1090. end
  1091.  
  1092. def drawPageArea
  1093. @sprites["background"].setBitmap(_INTL("Graphics/Pictures/Habitats/bg_info"))
  1094. overlay = @sprites["overlay"].bitmap
  1095. base = Color.new(88, 88, 80)
  1096. shadow = Color.new(168, 184, 184)
  1097. @sprites["areahighlight"].bitmap.clear
  1098. # Fill the array "points" with all squares of the region map in which the
  1099. # species can be found
  1100. points = []
  1101. mapwidth = 1 + PokemonRegionMapScene::RIGHT - PokemonRegionMapScene::LEFT
  1102. @habitat[:mapIDs].each do |map|
  1103. mappos = pbGetMetadata(map, MetadataMapPosition)
  1104. if mappos && mappos[0] == @region
  1105. showpoint = true
  1106. for loc in @mapdata[@region][2]
  1107. showpoint = false if loc[0] == mappos[1] && loc[1] == mappos[2] &&
  1108. loc[7] && !$game_switches[loc[7]]
  1109. end
  1110. if showpoint
  1111. mapsize = pbGetMetadata(map, MetadataMapSize)
  1112. if mapsize && mapsize[0] && mapsize[0] > 0
  1113. sqwidth = mapsize[0]
  1114. sqheight = (mapsize[1].length * 1.0 / mapsize[0]).ceil
  1115. for i in 0...sqwidth
  1116. for j in 0...sqheight
  1117. if mapsize[1][i + j * sqwidth, 1].to_i > 0
  1118. points[mappos[1] + i + (mappos[2] + j) * mapwidth] = true
  1119. end
  1120. end
  1121. end
  1122. else
  1123. points[mappos[1] + mappos[2] * mapwidth] = true
  1124. end
  1125. end
  1126. end
  1127. end
  1128. # Draw coloured squares on each square of the region map with a nest
  1129. pointcolor = Color.new(0, 248, 248)
  1130. pointcolorhl = Color.new(192, 248, 248)
  1131. sqwidth = PokemonRegionMapScene::SQUAREWIDTH
  1132. sqheight = PokemonRegionMapScene::SQUAREHEIGHT
  1133. for j in 0...points.length
  1134. if points[j]
  1135. x = (j % mapwidth) * sqwidth
  1136. x += (Graphics.width - @sprites["areamap"].bitmap.width) / 2 -16
  1137. y = (j / mapwidth) * sqheight
  1138. #y += (Graphics.height + 46 - @sprites["areamap"].bitmap.height) / 2
  1139. y += (Graphics.height - @sprites["areamap"].bitmap.height) / 2 +16
  1140.  
  1141. @sprites["areahighlight"].bitmap.fill_rect(x, y, sqwidth, sqheight, pointcolor)
  1142. if j - mapwidth < 0 || !points[j - mapwidth]
  1143. @sprites["areahighlight"].bitmap.fill_rect(x, y - 2, sqwidth, 2, pointcolorhl)
  1144. end
  1145. if j + mapwidth >= points.length || !points[j + mapwidth]
  1146. @sprites["areahighlight"].bitmap.fill_rect(x, y + sqheight, sqwidth, 2, pointcolorhl)
  1147. end
  1148. if j % mapwidth == 0 || !points[j - 1]
  1149. @sprites["areahighlight"].bitmap.fill_rect(x - 2, y, 2, sqheight, pointcolorhl)
  1150. end
  1151. if (j + 1) % mapwidth == 0 || !points[j + 1]
  1152. @sprites["areahighlight"].bitmap.fill_rect(x + sqwidth, y, 2, sqheight, pointcolorhl)
  1153. end
  1154. end
  1155. end
  1156. # Set the text
  1157. textpos = []
  1158. if points.length == 0
  1159. pbDrawImagePositions(overlay, [
  1160. [sprintf("Graphics/Pictures/Pokedex/overlay_areanone"), 108, 188, 0, 0, -1, -1],
  1161. ])
  1162. textpos.push([_INTL("Area unknown"), Graphics.width / 2, Graphics.height / 2, 2, base, shadow])
  1163. end
  1164. pbDrawTextPositions(overlay, textpos)
  1165. end
  1166.  
  1167. def pbGoToPrevious
  1168. newindex = @index
  1169. if newindex > 0
  1170. newindex -= 1
  1171. end
  1172. @index = newindex
  1173. end
  1174.  
  1175. def pbGoToNext
  1176. newindex = @index
  1177. if newindex < @habitatlist.length - 1
  1178. newindex += 1
  1179. end
  1180. @index = newindex
  1181. end
  1182.  
  1183. def pbScene
  1184. loop do
  1185. Graphics.update
  1186. Input.update
  1187. pbUpdate
  1188. dorefresh = false
  1189. if Input.trigger?(Input::B)
  1190. pbPlayCancelSE
  1191. break
  1192. #elsif Input.trigger?(Input::C)
  1193. #
  1194. elsif Input.trigger?(Input::UP) && @single == false && @page != -1
  1195. oldindex = @index
  1196. pbGoToPrevious
  1197. @page = 0
  1198. if @index != oldindex
  1199. pbPlayDecisionSE
  1200. pbUpdateHabitat
  1201. pbSEStop
  1202. dorefresh = true
  1203. end
  1204. elsif Input.trigger?(Input::DOWN) && @single == false && @page != -1
  1205. oldindex = @index
  1206. pbGoToNext
  1207. @page = 0
  1208. if @index != oldindex
  1209. pbPlayDecisionSE
  1210. pbUpdateHabitat
  1211. dorefresh = true
  1212. end
  1213. elsif Input.trigger?(Input::LEFT)
  1214. oldpage = @page
  1215. @page -= 1
  1216. if @single
  1217. @page = 0 if @page < 0
  1218. else
  1219. @page = -1 if @page < -1
  1220. end
  1221. @page = @encpages if @page > @encpages
  1222. if @page != oldpage
  1223. pbPlayCursorSE
  1224. for i in 0...@encounter[:list].size
  1225. if @sprites["pokemon#{i}"] && !@sprites["pokemon#{i}"].disposed?
  1226. @sprites["pokemon#{i}"].dispose
  1227. end
  1228. end
  1229. dorefresh = true
  1230. end
  1231. elsif Input.trigger?(Input::RIGHT)
  1232. oldpage = @page
  1233. @page += 1
  1234. if @single
  1235. @page = 0 if @page < 0
  1236. else
  1237. @page = -1 if @page < -1
  1238. end
  1239. @page = @encpages if @page > @encpages
  1240. if @page != oldpage
  1241. pbPlayCursorSE
  1242. for i in 0...@encounter[:list].size
  1243. if defined?(@sprites["pokemon#{i}"]) &&
  1244. @sprites["pokemon#{i}"] != nil && !@sprites["pokemon#{i}"].disposed?
  1245. @sprites["pokemon#{i}"].dispose
  1246. end
  1247. end
  1248. dorefresh = true
  1249. end
  1250. end
  1251. if dorefresh
  1252. drawPage(@page)
  1253. end
  1254. end
  1255. return @index
  1256. end
  1257. end
  1258.  
  1259. class HabitatDetailScreen
  1260. def initialize(scene)
  1261. @scene = scene
  1262. end
  1263.  
  1264. def pbStartScreenSingle(index)
  1265. @scene.pbStartSceneSingle(index)
  1266. ret = @scene.pbScene
  1267. @scene.pbEndScene
  1268. return ret
  1269. end
  1270.  
  1271. def pbStartScreen(index, habitat, region)
  1272. @scene.pbStartScene(index, habitat, region)
  1273. ret = @scene.pbScene
  1274. @scene.pbEndScene
  1275. return ret # Index of last habitat viewed in list
  1276. end
  1277. end
  1278.  
  1279. class HabitatPokemonPanel < SpriteWrapper
  1280. attr_reader :pokemon
  1281. attr_accessor :icon
  1282.  
  1283. def initialize(pokemonID, status, x, y, viewport = nil)
  1284. super(viewport)
  1285. self.x = x
  1286. self.y = y
  1287. @id = pokemonID
  1288. @status = status
  1289. @refreshing = true
  1290. @panelbgsprite = IconSprite.new(64, 48, viewport)
  1291. @panelbgsprite.z = self.z + 1
  1292. @panelbgsprite.setBitmap("Graphics/Pictures/Habitats/ListPokemonBg")
  1293.  
  1294. @pkmnsprite = IconSprite.new(0, 0, viewport)
  1295. @pkmnsprite.setBitmap(pbCheckPokemonIconFiles([pokemonID, false, false, 0, false], false))
  1296. @pkmnsprite.z = self.z + 2
  1297. @pkmnsprite.src_rect.set(0, 0, 64, 64)
  1298.  
  1299. @caughticonsprite = ChangelingSprite.new(48, 0, viewport)
  1300. @caughticonsprite.addBitmap("owned", "Graphics/Pictures/Habitats/iconowned")
  1301. @caughticonsprite.addBitmap("seen", "Graphics/Pictures/Habitats/iconseen")
  1302. @caughticonsprite.z = self.z + 3
  1303.  
  1304. @overlaysprite = BitmapSprite.new(Graphics.width, Graphics.height, viewport)
  1305. @overlaysprite.z = self.z + 4
  1306. @refreshing = false
  1307. refresh
  1308. end
  1309.  
  1310. def dispose
  1311. @pkmnsprite.dispose
  1312. @panelbgsprite.dispose
  1313. @caughticonsprite.dispose
  1314. @overlaysprite.bitmap.dispose
  1315. @overlaysprite.dispose
  1316. super
  1317. end
  1318.  
  1319. def x=(value)
  1320. super
  1321. refresh
  1322. end
  1323.  
  1324. def y=(value)
  1325. super
  1326. refresh
  1327. end
  1328.  
  1329. def color=(value)
  1330. super
  1331. refresh
  1332. end
  1333.  
  1334. def refresh
  1335. return if disposed?
  1336. return if @refreshing
  1337. @refreshing = true
  1338. if @panelbgsprite && !@panelbgsprite.disposed?
  1339. @panelbgsprite.x = self.x
  1340. @panelbgsprite.y = self.y
  1341. @panelbgsprite.color = self.color
  1342. end
  1343. if @caughticonsprite && !@caughticonsprite.disposed?
  1344. if $Trainer.owned[@id]
  1345. @caughticonsprite.changeBitmap("owned")
  1346. @caughticonsprite.visible = true
  1347. elsif $Trainer.seen[@id]
  1348. @caughticonsprite.changeBitmap("seen")
  1349. @caughticonsprite.visible = true
  1350. else
  1351. @caughticonsprite.visible = false
  1352. end
  1353. @caughticonsprite.x = self.x + 46
  1354. @caughticonsprite.y = self.y + 2
  1355. @caughticonsprite.color = self.color
  1356. end
  1357. if @pkmnsprite && !@pkmnsprite.disposed?
  1358. @pkmnsprite.x = self.x
  1359. @pkmnsprite.y = self.y - 16
  1360. @pkmnsprite.color = self.color
  1361. @pkmnsprite.visible = @caughticonsprite.visible
  1362. end
  1363. if @overlaysprite && !@overlaysprite.disposed?
  1364. @overlaysprite.x = self.x
  1365. @overlaysprite.y = self.y
  1366. @overlaysprite.color = self.color
  1367. end
  1368. @refreshing = false
  1369. end
  1370.  
  1371. def update
  1372. super
  1373. @caughticonsprite.update if @caughticonsprite && !@caughticonsprite.disposed?
  1374. @pkmnsprite.update if @pkmnsprite && !@pkmnsprite.disposed?
  1375. end
  1376. end
Add Comment
Please, Sign In to add comment