1. #===============================================================================
  2. # Pokémon icons
  3. #===============================================================================
  4. class PokemonBoxIcon < IconSprite
  5. def initialize(pokemon, viewport = nil)
  6. super(0, 0, viewport)
  7. @pokemon = pokemon
  8. @release_timer_start = nil
  9. refresh
  10. end
  11.  
  12. def releasing?
  13. return !@release_timer_start.nil?
  14. end
  15.  
  16. def release
  17. self.ox = self.src_rect.width / 2 # 32
  18. self.oy = self.src_rect.height / 2 # 32
  19. self.x += self.src_rect.width / 2 # 32
  20. self.y += self.src_rect.height / 2 # 32
  21. @release_timer_start = System.uptime
  22. end
  23.  
  24. def refresh
  25. return if !@pokemon
  26. self.setBitmap(GameData::Species.icon_filename_from_pokemon(@pokemon))
  27. self.src_rect = Rect.new(0, 0, self.bitmap.height, self.bitmap.height)
  28. end
  29.  
  30. def update
  31. super
  32.  
  33. if releasing?
  34. time_now = System.uptime
  35. self.zoom_x = lerp(1.0, 0.0, 1.5, @release_timer_start, System.uptime)
  36. self.zoom_y = self.zoom_x
  37. self.opacity = lerp(255, 0, 1.5, @release_timer_start, System.uptime)
  38. if self.opacity == 0
  39. @release_timer_start = nil
  40. dispose
  41. end
  42. end
  43. end
  44. end
  45.  
  46. #===============================================================================
  47. # Pokémon sprite
  48. #===============================================================================
  49. class MosaicPokemonSprite < PokemonSprite
  50. attr_reader :mosaic
  51.  
  52. def initialize(*args)
  53. super(*args)
  54. @mosaic = 0
  55. @inrefresh = false
  56. @mosaicbitmap = nil
  57. @mosaicbitmap2 = nil
  58. @oldbitmap = self.bitmap
  59. end
  60.  
  61. def dispose
  62. super
  63. @mosaicbitmap&.dispose
  64. @mosaicbitmap = nil
  65. @mosaicbitmap2&.dispose
  66. @mosaicbitmap2 = nil
  67. end
  68.  
  69. def bitmap=(value)
  70. super
  71. mosaicRefresh(value)
  72. end
  73.  
  74. def mosaic=(value)
  75. @mosaic = value
  76. @mosaic = 0 if @mosaic < 0
  77. mosaicRefresh(@oldbitmap)
  78. end
  79.  
  80. def mosaicRefresh(bitmap)
  81. return if @inrefresh
  82. @inrefresh = true
  83. @oldbitmap = bitmap
  84. if @mosaic <= 0 || !@oldbitmap
  85. @mosaicbitmap&.dispose
  86. @mosaicbitmap = nil
  87. @mosaicbitmap2&.dispose
  88. @mosaicbitmap2 = nil
  89. self.bitmap = @oldbitmap
  90. else
  91. newWidth = [(@oldbitmap.width / @mosaic), 1].max
  92. newHeight = [(@oldbitmap.height / @mosaic), 1].max
  93. @mosaicbitmap2&.dispose
  94. @mosaicbitmap = pbDoEnsureBitmap(@mosaicbitmap, newWidth, newHeight)
  95. @mosaicbitmap.clear
  96. @mosaicbitmap2 = pbDoEnsureBitmap(@mosaicbitmap2, @oldbitmap.width, @oldbitmap.height)
  97. @mosaicbitmap2.clear
  98. @mosaicbitmap.stretch_blt(Rect.new(0, 0, newWidth, newHeight), @oldbitmap, @oldbitmap.rect)
  99. @mosaicbitmap2.stretch_blt(
  100. Rect.new((-@mosaic / 2) + 1, (-@mosaic / 2) + 1, @mosaicbitmap2.width, @mosaicbitmap2.height),
  101. @mosaicbitmap, Rect.new(0, 0, newWidth, newHeight)
  102. )
  103. self.bitmap = @mosaicbitmap2
  104. end
  105. @inrefresh = false
  106. end
  107. end
  108.  
  109. #===============================================================================
  110. #
  111. #===============================================================================
  112. class AutoMosaicPokemonSprite < MosaicPokemonSprite
  113. INITIAL_MOSAIC = 10 # Pixellation factor
  114.  
  115. def mosaic=(value)
  116. @mosaic = value
  117. @mosaic = 0 if @mosaic < 0
  118. @start_mosaic = @mosaic if !@start_mosaic
  119. end
  120.  
  121. def mosaic_duration=(val)
  122. @mosaic_duration = val
  123. @mosaic_duration = 0 if @mosaic_duration < 0
  124. @mosaic_timer_start = System.uptime if @mosaic_duration > 0
  125. end
  126.  
  127. def update
  128. super
  129. if @mosaic_timer_start
  130. @start_mosaic = INITIAL_MOSAIC if !@start_mosaic || @start_mosaic == 0
  131. new_mosaic = lerp(@start_mosaic, 0, @mosaic_duration, @mosaic_timer_start, System.uptime).to_i
  132. self.mosaic = new_mosaic
  133. mosaicRefresh(@oldbitmap)
  134. if new_mosaic == 0
  135. @mosaic_timer_start = nil
  136. @start_mosaic = nil
  137. end
  138. end
  139. end
  140. end
  141.  
  142. #===============================================================================
  143. # Cursor
  144. #===============================================================================
  145. class PokemonBoxArrow < Sprite
  146. attr_accessor :quickswap
  147.  
  148. # Time in seconds for the cursor to move down and back up to grab/drop a
  149. # Pokémon.
  150. GRAB_TIME = 0.4
  151.  
  152. def initialize(viewport = nil)
  153. super(viewport)
  154. @holding = false
  155. @updating = false
  156. @quickswap = false
  157. @heldpkmn = nil
  158. @handsprite = ChangelingSprite.new(0, 0, viewport)
  159. @handsprite.addBitmap("point1", "Graphics/UI/Storage/cursor_point_1")
  160. @handsprite.addBitmap("point2", "Graphics/UI/Storage/cursor_point_2")
  161. @handsprite.addBitmap("grab", "Graphics/UI/Storage/cursor_grab")
  162. @handsprite.addBitmap("fist", "Graphics/UI/Storage/cursor_fist")
  163. @handsprite.addBitmap("point1q", "Graphics/UI/Storage/cursor_point_1_q")
  164. @handsprite.addBitmap("point2q", "Graphics/UI/Storage/cursor_point_2_q")
  165. @handsprite.addBitmap("grabq", "Graphics/UI/Storage/cursor_grab_q")
  166. @handsprite.addBitmap("fistq", "Graphics/UI/Storage/cursor_fist_q")
  167. @handsprite.changeBitmap("fist")
  168. @spriteX = self.x
  169. @spriteY = self.y
  170. end
  171.  
  172. def dispose
  173. @handsprite.dispose
  174. @heldpkmn&.dispose
  175. super
  176. end
  177.  
  178. def x=(value)
  179. super
  180. @handsprite.x = self.x
  181. @spriteX = x if !@updating
  182. heldPokemon.x = self.x if holding?
  183. end
  184.  
  185. def y=(value)
  186. super
  187. @handsprite.y = self.y
  188. @spriteY = y if !@updating
  189. heldPokemon.y = self.y + 16 if holding?
  190. end
  191.  
  192. def z=(value)
  193. super
  194. @handsprite.z = value
  195. end
  196.  
  197. def visible=(value)
  198. super
  199. @handsprite.visible = value
  200. sprite = heldPokemon
  201. sprite.visible = value if sprite
  202. end
  203.  
  204. def color=(value)
  205. super
  206. @handsprite.color = value
  207. sprite = heldPokemon
  208. sprite.color = value if sprite
  209. end
  210.  
  211. def heldPokemon
  212. @heldpkmn = nil if @heldpkmn&.disposed?
  213. @holding = false if !@heldpkmn
  214. return @heldpkmn
  215. end
  216.  
  217. def holding?
  218. return self.heldPokemon && @holding
  219. end
  220.  
  221. def grabbing?
  222. return !@grabbing_timer_start.nil?
  223. end
  224.  
  225. def placing?
  226. return !@placing_timer_start.nil?
  227. end
  228.  
  229. def setSprite(sprite)
  230. if holding?
  231. @heldpkmn = sprite
  232. @heldpkmn.viewport = self.viewport if @heldpkmn
  233. @heldpkmn.z = 1 if @heldpkmn
  234. @holding = false if !@heldpkmn
  235. self.z = 2
  236. end
  237. end
  238.  
  239. def deleteSprite
  240. @holding = false
  241. if @heldpkmn
  242. @heldpkmn.dispose
  243. @heldpkmn = nil
  244. end
  245. end
  246.  
  247. def grab(sprite)
  248. @grabbing_timer_start = System.uptime
  249. @heldpkmn = sprite
  250. @heldpkmn.viewport = self.viewport
  251. @heldpkmn.z = 1
  252. self.z = 2
  253. end
  254.  
  255. def place
  256. @placing_timer_start = System.uptime
  257. end
  258.  
  259. def release
  260. @heldpkmn&.release
  261. end
  262.  
  263. def update
  264. @updating = true
  265. super
  266. heldpkmn = heldPokemon
  267. heldpkmn&.update
  268. @handsprite.update
  269. @holding = false if !heldpkmn
  270. if @grabbing_timer_start
  271. if System.uptime - @grabbing_timer_start <= GRAB_TIME / 2
  272. @handsprite.changeBitmap((@quickswap) ? "grabq" : "grab")
  273. self.y = @spriteY + lerp(0, 16, GRAB_TIME / 2, @grabbing_timer_start, System.uptime)
  274. else
  275. @holding = true
  276. @handsprite.changeBitmap((@quickswap) ? "fistq" : "fist")
  277. delta_y = lerp(16, 0, GRAB_TIME / 2, @grabbing_timer_start + (GRAB_TIME / 2), System.uptime)
  278. self.y = @spriteY + delta_y
  279. @grabbing_timer_start = nil if delta_y == 0
  280. end
  281. elsif @placing_timer_start
  282. if System.uptime - @placing_timer_start <= GRAB_TIME / 2
  283. @handsprite.changeBitmap((@quickswap) ? "fistq" : "fist")
  284. self.y = @spriteY + lerp(0, 16, GRAB_TIME / 2, @placing_timer_start, System.uptime)
  285. else
  286. @holding = false
  287. @heldpkmn = nil
  288. @handsprite.changeBitmap((@quickswap) ? "grabq" : "grab")
  289. delta_y = lerp(16, 0, GRAB_TIME / 2, @placing_timer_start + (GRAB_TIME / 2), System.uptime)
  290. self.y = @spriteY + delta_y
  291. @placing_timer_start = nil if delta_y == 0
  292. end
  293. elsif holding?
  294. @handsprite.changeBitmap((@quickswap) ? "fistq" : "fist")
  295. else # Idling
  296. self.x = @spriteX
  297. self.y = @spriteY
  298. if (System.uptime / 0.5).to_i.even? # Changes every 0.5 seconds
  299. @handsprite.changeBitmap((@quickswap) ? "point1q" : "point1")
  300. else
  301. @handsprite.changeBitmap((@quickswap) ? "point2q" : "point2")
  302. end
  303. end
  304. @updating = false
  305. end
  306. end
  307.  
  308. #===============================================================================
  309. # Box
  310. #===============================================================================
  311. class PokemonBoxSprite < Sprite
  312. attr_accessor :refreshBox
  313. attr_accessor :refreshSprites
  314.  
  315. def initialize(storage, boxnumber, viewport = nil)
  316. super(viewport)
  317. @storage = storage
  318. @boxnumber = boxnumber
  319. @refreshBox = true
  320. @refreshSprites = true
  321. @pokemonsprites = []
  322. PokemonBox::BOX_SIZE.times do |i|
  323. @pokemonsprites[i] = nil
  324. pokemon = @storage[boxnumber, i]
  325. @pokemonsprites[i] = PokemonBoxIcon.new(pokemon, viewport) if pokemon
  326.  
  327. Graphics.update if (i + 1) % 15 == 0
  328. end
  329. @contents = Bitmap.new(650, 390)
  330. self.bitmap = @contents
  331. self.x = 184
  332. self.y = 18
  333. refresh
  334. end
  335.  
  336. def dispose
  337. if !disposed?
  338. @pokemonsprites.each do |sprite|
  339. sprite&.dispose
  340. end
  341. @pokemonsprites.clear
  342. @boxbitmap.dispose
  343. @contents.dispose
  344. super
  345. end
  346. end
  347.  
  348. def x=(value)
  349. super
  350. end
  351.  
  352. def y=(value)
  353. super
  354. end
  355.  
  356. def color=(value)
  357. super
  358. if @refreshSprites
  359. @pokemonsprites.each do |sprite|
  360. sprite.color = value if sprite && !sprite.disposed?
  361. end
  362. end
  363. refresh
  364. end
  365.  
  366. def visible=(value)
  367. super
  368. @pokemonsprites.each do |sprite|
  369. sprite.visible = value if sprite && !sprite.disposed?
  370. end
  371. refresh
  372. end
  373.  
  374. def getBoxBitmap
  375. if !@bg || @bg != @storage[@boxnumber].background
  376. curbg = @storage[@boxnumber].background
  377. if !curbg || (curbg.is_a?(String) && curbg.length == 0)
  378. @bg = @boxnumber % PokemonStorage::BASICWALLPAPERQTY
  379. else
  380. if curbg.is_a?(String) && curbg[/^box(\d+)$/]
  381. curbg = $~[1].to_i
  382. @storage[@boxnumber].background = curbg
  383. end
  384. @bg = curbg
  385. end
  386. @bg = @boxnumber % PokemonStorage::BASICWALLPAPERQTY
  387. @storage[@boxnumber].background = @bg
  388. end
  389. @boxbitmap&.dispose
  390. @boxbitmap = AnimatedBitmap.new("Graphics/UI/Storage/box_#{@bg}")
  391. end
  392. end
  393.  
  394. def getPokemon(index)
  395. return @pokemonsprites[index]
  396. end
  397.  
  398. def setPokemon(index, sprite)
  399. @pokemonsprites[index] = sprite
  400.  
  401. row = index / PokemonBox::BOX_WIDTH
  402. column = index % PokemonBox::BOX_WIDTH
  403.  
  404. sprite.viewport = self.viewport
  405. sprite.x = self.x + 10 + (column * 48)
  406. sprite.y = self.y + 30 + (row * 48)
  407. sprite.z = 1
  408. end
  409.  
  410. def grabPokemon(index, arrow)
  411. sprite = @pokemonsprites[index]
  412. if sprite
  413. arrow.grab(sprite)
  414. @pokemonsprites[index] = nil
  415. end
  416. end
  417.  
  418. def deletePokemon(index)
  419. @pokemonsprites[index]&.dispose
  420. @pokemonsprites[index] = nil
  421. end
  422.  
  423. def refresh
  424. if @refreshBox
  425. boxname = @storage[@boxnumber].name
  426. getBoxBitmap
  427. @contents.stretch_blt(
  428. Rect.new(0, 0, 650, 390),
  429. @boxbitmap.bitmap,
  430. Rect.new(0, 0, 324, 296)
  431. )
  432. pbSetSystemFont(@contents)
  433. widthval = @contents.text_size(boxname).width
  434. xval = 162 - (widthval / 2)
  435. pbDrawShadowText(@contents, xval, 14, widthval, 32,
  436. boxname, Color.new(248, 248, 248), Color.new(40, 48, 48))
  437. @refreshBox = false
  438. end
  439. yval = self.y + 30
  440. PokemonBox::BOX_HEIGHT.times do |j|
  441. xval = self.x + 10
  442. PokemonBox::BOX_WIDTH.times do |k|
  443. sprite = @pokemonsprites[(j * PokemonBox::BOX_WIDTH) + k]
  444. if sprite && !sprite.disposed?
  445. sprite.viewport = self.viewport
  446. sprite.x = xval
  447. sprite.y = yval
  448. sprite.z = 1
  449. end
  450. xval += 48
  451. end
  452. yval += 48
  453. end
  454. end
  455.  
  456. def update
  457. super
  458. @frame_limiter = 0 if !@frame_limiter
  459. @frame_limiter = (@frame_limiter + 1) % 4
  460.  
  461. @pokemonsprites.each_with_index do |sprite, index|
  462. next if !sprite || sprite.disposed?
  463. if index % 4 == @frame_limiter || (sprite.respond_to?(:releasing?) && sprite.releasing?)
  464. sprite.update
  465. end
  466. end
  467. end
  468. end
  469.  
  470. #===============================================================================
  471. # Party pop-up panel
  472. #===============================================================================
  473. class PokemonBoxPartySprite < Sprite
  474. def initialize(party, viewport = nil)
  475. super(viewport)
  476. @party = party
  477. @boxbitmap = AnimatedBitmap.new("Graphics/UI/Storage/overlay_party")
  478. @pokemonsprites = []
  479. Settings::MAX_PARTY_SIZE.times do |i|
  480. @pokemonsprites[i] = nil
  481. pokemon = @party[i]
  482. @pokemonsprites[i] = PokemonBoxIcon.new(pokemon, viewport) if pokemon
  483. end
  484. @contents = Bitmap.new(172, 352)
  485. self.bitmap = @contents
  486. self.x = 182
  487. self.y = Graphics.height - 352
  488. pbSetSystemFont(self.bitmap)
  489. refresh
  490. end
  491.  
  492. def dispose
  493. Settings::MAX_PARTY_SIZE.times do |i|
  494. @pokemonsprites[i]&.dispose
  495. end
  496. @boxbitmap.dispose
  497. @contents.dispose
  498. super
  499. end
  500.  
  501. def x=(value)
  502. super
  503. end
  504.  
  505. def y=(value)
  506. super
  507. end
  508.  
  509. def color=(value)
  510. super
  511. Settings::MAX_PARTY_SIZE.times do |i|
  512. if @pokemonsprites[i] && !@pokemonsprites[i].disposed?
  513. @pokemonsprites[i].color = pbSrcOver(@pokemonsprites[i].color, value)
  514. end
  515. end
  516. end
  517.  
  518. def visible=(value)
  519. super
  520. @pokemonsprites.each do |sprite|
  521. sprite.visible = value if sprite && !sprite.disposed?
  522. end
  523. refresh
  524. end
  525.  
  526. def getPokemon(index)
  527. return @pokemonsprites[index]
  528. end
  529.  
  530. def setPokemon(index, sprite)
  531. @pokemonsprites[index] = sprite
  532. end
  533.  
  534. def grabPokemon(index, arrow)
  535. sprite = @pokemonsprites[index]
  536. if sprite
  537. arrow.grab(sprite)
  538. @pokemonsprites[index] = nil
  539. end
  540. end
  541.  
  542. def deletePokemon(index)
  543. @pokemonsprites[index]&.dispose
  544. @pokemonsprites[index] = nil
  545. end
  546.  
  547. def refresh
  548. @contents.blt(0, 0, @boxbitmap.bitmap, Rect.new(0, 0, 324, 296))
  549. pbDrawTextPositions(
  550. self.bitmap,
  551. [[_INTL("Back"), 86, 248, :center, Color.new(248, 248, 248), Color.new(80, 80, 80), :outline]]
  552. )
  553. xvalues = [] # [18, 90, 18, 90, 18, 90]
  554. yvalues = [] # [2, 18, 66, 82, 130, 146]
  555. Settings::MAX_PARTY_SIZE.times do |i|
  556. xvalues.push(18 + (72 * (i % 2)))
  557. yvalues.push(2 + (16 * (i % 2)) + (64 * (i / 2)))
  558. end
  559. @pokemonsprites.delete_if { |sprite| sprite&.disposed? }
  560.  
  561. Settings::MAX_PARTY_SIZE.times do |j|
  562. sprite = @pokemonsprites[j]
  563. next if sprite.nil? || sprite.disposed?
  564.  
  565. sprite.viewport = self.viewport
  566. sprite.x = self.x + xvalues[j]
  567. sprite.y = self.y + yvalues[j]
  568. sprite.z = 1
  569. end
  570. end
  571.  
  572. def update
  573. super
  574. Settings::MAX_PARTY_SIZE.times do |i|
  575. @pokemonsprites[i].update if @pokemonsprites[i] && !@pokemonsprites[i].disposed?
  576. end
  577. end
  578. end
  579.  
  580. #===============================================================================
  581. # Pokémon storage visuals
  582. #===============================================================================
  583. class PokemonStorageScene
  584. attr_reader :quickswap
  585.  
  586. MARK_WIDTH = 16
  587. MARK_HEIGHT = 16
  588.  
  589. def initialize
  590. @command = 1
  591. end
  592.  
  593. def pbStartBox(screen, command)
  594. @screen = screen
  595. @storage = screen.storage
  596. @bgviewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
  597. @bgviewport.z = 99999
  598. @boxviewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
  599. @boxviewport.z = 99999
  600. @boxsidesviewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
  601. @boxsidesviewport.z = 99999
  602. @arrowviewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
  603. @arrowviewport.z = 99999
  604. @viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
  605. @viewport.z = 99999
  606. @selection = 0
  607. @quickswap = false
  608. @sprites = {}
  609. @choseFromParty = false
  610. @command = command
  611. addBackgroundPlane(@sprites, "background", "Storage/bg", @bgviewport)
  612. @sprites["box"] = PokemonBoxSprite.new(@storage, @storage.currentBox, @boxviewport)
  613. @sprites["boxsides"] = IconSprite.new(0, 0, @boxsidesviewport)
  614. @sprites["boxsides"].setBitmap("Graphics/UI/Storage/overlay_main")
  615. @sprites["overlay"] = BitmapSprite.new(Graphics.width, Graphics.height, @boxsidesviewport)
  616. pbSetSystemFont(@sprites["overlay"].bitmap)
  617. @sprites["pokemon"] = AutoMosaicPokemonSprite.new(@boxsidesviewport)
  618. @sprites["pokemon"].setOffset(PictureOrigin::CENTER)
  619. @sprites["pokemon"].x = 90
  620. @sprites["pokemon"].y = 134
  621. @sprites["boxparty"] = PokemonBoxPartySprite.new(@storage.party, @boxsidesviewport)
  622. if command != 2 # Drop down tab only on Deposit
  623. @sprites["boxparty"].x = 182
  624. @sprites["boxparty"].y = Graphics.height
  625. end
  626. @markingbitmap = AnimatedBitmap.new("Graphics/UI/Storage/markings")
  627. @sprites["markingbg"] = IconSprite.new(292, 68, @boxsidesviewport)
  628. @sprites["markingbg"].setBitmap("Graphics/UI/Storage/overlay_marking")
  629. @sprites["markingbg"].z = 10
  630. @sprites["markingbg"].visible = false
  631. @sprites["markingoverlay"] = BitmapSprite.new(Graphics.width, Graphics.height, @boxsidesviewport)
  632. @sprites["markingoverlay"].z = 11
  633. @sprites["markingoverlay"].visible = false
  634. pbSetSystemFont(@sprites["markingoverlay"].bitmap)
  635. @sprites["arrow"] = PokemonBoxArrow.new(@arrowviewport)
  636. @sprites["arrow"].z += 1
  637. if command == 2
  638. pbPartySetArrow(@sprites["arrow"], @selection)
  639. pbUpdateOverlay(@selection, @storage.party)
  640. else
  641. pbSetArrow(@sprites["arrow"], @selection)
  642. pbUpdateOverlay(@selection)
  643. end
  644. pbSetMosaic(@selection)
  645. pbSEPlay("PC access")
  646. pbFadeInAndShow(@sprites)
  647. end
  648.  
  649. def pbCloseBox
  650. pbFadeOutAndHide(@sprites)
  651. pbDisposeSpriteHash(@sprites)
  652. @markingbitmap&.dispose
  653. @boxviewport.dispose
  654. @boxsidesviewport.dispose
  655. @arrowviewport.dispose
  656. end
  657.  
  658. def pbDisplay(message)
  659. msgwindow = Window_UnformattedTextPokemon.newWithSize("", 180, 0, Graphics.width - 180, 32)
  660. msgwindow.viewport = @viewport
  661. msgwindow.visible = true
  662. msgwindow.letterbyletter = false
  663. msgwindow.resizeHeightToFit(message, Graphics.width - 180)
  664. msgwindow.text = message
  665. pbBottomRight(msgwindow)
  666. loop do
  667. Graphics.update
  668. Input.update
  669. if Input.trigger?(Input::BACK) || Input.trigger?(Input::USE)
  670. break
  671. end
  672. msgwindow.update
  673. self.update
  674. end
  675. msgwindow.dispose
  676. Input.update
  677. end
  678.  
  679. def pbShowCommands(message, commands, index = 0)
  680. ret = -1
  681. msgwindow = Window_UnformattedTextPokemon.newWithSize("", 180, 0, Graphics.width - 180, 32)
  682. msgwindow.viewport = @viewport
  683. msgwindow.visible = true
  684. msgwindow.letterbyletter = false
  685. msgwindow.text = message
  686. msgwindow.resizeHeightToFit(message, Graphics.width - 180)
  687. pbBottomRight(msgwindow)
  688. cmdwindow = Window_CommandPokemon.new(commands)
  689. cmdwindow.viewport = @viewport
  690. cmdwindow.visible = true
  691. cmdwindow.resizeToFit(cmdwindow.commands)
  692. cmdwindow.height = Graphics.height - msgwindow.height if cmdwindow.height > Graphics.height - msgwindow.height
  693. pbBottomRight(cmdwindow)
  694. cmdwindow.y -= msgwindow.height
  695. cmdwindow.index = index
  696. loop do
  697. Graphics.update
  698. Input.update
  699. msgwindow.update
  700. cmdwindow.update
  701. if Input.trigger?(Input::BACK)
  702. ret = -1
  703. break
  704. elsif Input.trigger?(Input::USE)
  705. ret = cmdwindow.index
  706. break
  707. end
  708. self.update
  709. end
  710. msgwindow.dispose
  711. cmdwindow.dispose
  712. Input.update
  713. return ret
  714. end
  715.  
  716. def pbSetArrow(arrow, selection)
  717. case selection
  718. when -1, -4, -5
  719. arrow.x = 488
  720. arrow.y = -24
  721. when -2
  722. arrow.x = 280
  723. arrow.y = 450
  724. when -3
  725. arrow.x = 600
  726. arrow.y = 450
  727. else
  728. arrow.x = (97 + (24 * (selection % PokemonBox::BOX_WIDTH))) * 2
  729. arrow.y = (8 + (24 * (selection / PokemonBox::BOX_WIDTH))) * 2
  730. end
  731. end
  732.  
  733. def pbChangeSelection(key, selection)
  734. case key
  735. when Input::UP
  736. case selection
  737. when -1
  738. selection = PokemonBox::BOX_SIZE - PokemonBox::BOX_WIDTH
  739. when -2, -3
  740. selection = 0
  741. else
  742. new_selection = selection - PokemonBox::BOX_WIDTH
  743. if new_selection < 0
  744. selection = -1 # Box name
  745. else
  746. selection = new_selection
  747. end
  748. end
  749. when Input::DOWN
  750. case selection
  751. when -1
  752. selection = 0
  753. when -2
  754. selection = 0
  755. when -3
  756. selection = 0
  757. else
  758. new_selection = selection + PokemonBox::BOX_WIDTH
  759. if new_selection >= PokemonBox::BOX_SIZE
  760. if (selection % PokemonBox::BOX_WIDTH) < (PokemonBox::BOX_WIDTH / 2)
  761. selection = -2 # Party
  762. else
  763. selection = -3 # Exit
  764. end
  765. else
  766. selection = new_selection
  767. end
  768. end
  769. when Input::LEFT
  770. if selection >= 0
  771. if (selection % PokemonBox::BOX_WIDTH) == 0
  772. selection += PokemonBox::BOX_WIDTH - 1
  773. else
  774. selection -= 1
  775. end
  776. elsif selection == -1
  777. selection = -4
  778. elsif selection == -2
  779. selection = -3
  780. elsif selection == -3
  781. selection = -2
  782. end
  783. when Input::RIGHT
  784. if selection >= 0
  785. if (selection % PokemonBox::BOX_WIDTH) == PokemonBox::BOX_WIDTH - 1
  786. selection -= PokemonBox::BOX_WIDTH - 1
  787. else
  788. selection += 1
  789. end
  790. elsif selection == -1
  791. selection = -5
  792. elsif selection == -2
  793. selection = -3
  794. elsif selection == -3
  795. selection = -2
  796. end
  797. end
  798. return selection
  799. end
  800.  
  801. def pbPartySetArrow(arrow, selection)
  802. return if selection < 0
  803. xvalues = [] # [200, 272, 200, 272, 200, 272, 236]
  804. yvalues = [] # [2, 18, 66, 82, 130, 146, 220]
  805. Settings::MAX_PARTY_SIZE.times do |i|
  806. xvalues.push(200 + (72 * (i % 2)))
  807. yvalues.push(190 + (16 * (i % 2)) + (64 * (i / 2)))
  808. end
  809. xvalues.push(268)
  810. yvalues.push(Graphics.height - 104)
  811. arrow.angle = 0
  812. arrow.mirror = false
  813. arrow.ox = 0
  814. arrow.oy = 0
  815. arrow.x = xvalues[selection]
  816. arrow.y = yvalues[selection]
  817. end
  818.  
  819. def pbPartyChangeSelection(key, selection)
  820. case key
  821. when Input::LEFT
  822. if selection == 1 || selection == 3 || selection == 5
  823. selection -= 1
  824. elsif selection == 6
  825. selection = 5
  826. end
  827.  
  828. when Input::RIGHT
  829. if selection == 0 || selection == 2 || selection == 4
  830. selection += 1
  831. elsif selection == 6
  832. selection = 0
  833. end
  834.  
  835. when Input::UP
  836. if selection == 6
  837. selection = 4
  838. elsif selection >= 2
  839. selection -= 2
  840. end
  841.  
  842. when Input::DOWN
  843. if selection < 4
  844. selection += 2
  845. elsif selection == 4 || selection == 5
  846. selection = 6
  847. elsif selection == 6
  848. selection = 0
  849. end
  850. end
  851.  
  852. return selection
  853. end
  854.  
  855. def pbSelectBoxInternal(_party)
  856. selection = @selection
  857. pbSetArrow(@sprites["arrow"], selection)
  858. pbUpdateOverlay(selection)
  859. pbSetMosaic(selection)
  860. loop do
  861. Graphics.update
  862. Input.update
  863. key = -1
  864. key = Input::DOWN if Input.repeat?(Input::DOWN)
  865. key = Input::RIGHT if Input.repeat?(Input::RIGHT)
  866. key = Input::LEFT if Input.repeat?(Input::LEFT)
  867. key = Input::UP if Input.repeat?(Input::UP)
  868. if key >= 0
  869. pbPlayCursorSE
  870. selection = pbChangeSelection(key, selection)
  871. pbSetArrow(@sprites["arrow"], selection)
  872. case selection
  873. when -4
  874. nextbox = (@storage.currentBox + @storage.maxBoxes - 1) % @storage.maxBoxes
  875. pbSwitchBoxToLeft(nextbox)
  876. @storage.currentBox = nextbox
  877. when -5
  878. nextbox = (@storage.currentBox + 1) % @storage.maxBoxes
  879. pbSwitchBoxToRight(nextbox)
  880. @storage.currentBox = nextbox
  881. end
  882. selection = -1 if [-4, -5].include?(selection)
  883. pbUpdateOverlay(selection)
  884. pbSetMosaic(selection)
  885. end
  886. self.update
  887. if Input.trigger?(Input::JUMPUP)
  888. pbPlayCursorSE
  889. nextbox = (@storage.currentBox + @storage.maxBoxes - 1) % @storage.maxBoxes
  890. pbSwitchBoxToLeft(nextbox)
  891. @storage.currentBox = nextbox
  892. pbUpdateOverlay(selection)
  893. pbSetMosaic(selection)
  894. elsif Input.trigger?(Input::JUMPDOWN)
  895. pbPlayCursorSE
  896. nextbox = (@storage.currentBox + 1) % @storage.maxBoxes
  897. pbSwitchBoxToRight(nextbox)
  898. @storage.currentBox = nextbox
  899. pbUpdateOverlay(selection)
  900. pbSetMosaic(selection)
  901. elsif Input.trigger?(Input::SPECIAL) # Jump to box name
  902. if selection != -1
  903. pbPlayCursorSE
  904. selection = -1
  905. pbSetArrow(@sprites["arrow"], selection)
  906. pbUpdateOverlay(selection)
  907. pbSetMosaic(selection)
  908. end
  909. elsif Input.trigger?(Input::ACTION) && @command == 0 # Organize only
  910. pbPlayDecisionSE
  911. pbSetQuickSwap(!@quickswap)
  912. elsif Input.trigger?(Input::BACK)
  913. @selection = selection
  914. return nil
  915. elsif Input.trigger?(Input::USE)
  916. @selection = selection
  917. if selection >= 0
  918. return [@storage.currentBox, selection]
  919. elsif selection == -1 # Box name
  920. return [-4, -1]
  921. elsif selection == -2 # Party Pokémon
  922. return [-2, -1]
  923. elsif selection == -3 # Close Box
  924. return [-3, -1]
  925. end
  926. end
  927. end
  928. end
  929.  
  930. def pbSelectBox(party)
  931. return pbSelectBoxInternal(party) if @command == 1 # Withdraw
  932. ret = nil
  933. loop do
  934. ret = pbSelectBoxInternal(party) if !@choseFromParty
  935. if @choseFromParty || (ret && ret[0] == -2) # Party Pokémon
  936. if !@choseFromParty
  937. pbShowPartyTab
  938. @selection = 0
  939. end
  940. ret = pbSelectPartyInternal(party, false)
  941. if ret < 0
  942. pbHidePartyTab
  943. @selection = -2
  944. @choseFromParty = false
  945. else
  946. @choseFromParty = true
  947. return [-1, ret]
  948. end
  949. else
  950. @choseFromParty = false
  951. return ret
  952. end
  953. end
  954. end
  955.  
  956. def pbSelectPartyInternal(party, depositing)
  957. selection = @selection
  958. pbPartySetArrow(@sprites["arrow"], selection)
  959. pbUpdateOverlay(selection, party)
  960. pbSetMosaic(selection)
  961. lastsel = 1
  962. loop do
  963. Graphics.update
  964. Input.update
  965. key = -1
  966. key = Input::DOWN if Input.repeat?(Input::DOWN)
  967. key = Input::RIGHT if Input.repeat?(Input::RIGHT)
  968. key = Input::LEFT if Input.repeat?(Input::LEFT)
  969. key = Input::UP if Input.repeat?(Input::UP)
  970. if key >= 0
  971. pbPlayCursorSE
  972. newselection = pbPartyChangeSelection(key, selection)
  973. case newselection
  974. when -1
  975. return -1 if !depositing
  976. when -2
  977. selection = lastsel
  978. else
  979. selection = newselection
  980. end
  981. pbPartySetArrow(@sprites["arrow"], selection)
  982. lastsel = selection if selection > 0
  983. pbUpdateOverlay(selection, party)
  984. pbSetMosaic(selection)
  985. end
  986. self.update
  987. if Input.trigger?(Input::ACTION) && @command == 0 # Organize only
  988. pbPlayDecisionSE
  989. pbSetQuickSwap(!@quickswap)
  990. elsif Input.trigger?(Input::BACK)
  991. @selection = selection
  992. return -1
  993. elsif Input.trigger?(Input::USE)
  994. if selection >= 0 && selection < Settings::MAX_PARTY_SIZE
  995. @selection = selection
  996. return selection
  997. elsif selection == Settings::MAX_PARTY_SIZE # Back
  998. @selection = selection
  999. return -1
  1000. end
  1001. end
  1002. end
  1003. end
  1004.  
  1005. def pbSelectParty(party)
  1006. return pbSelectPartyInternal(party, true)
  1007. end
  1008.  
  1009. def pbChangeBackground(wp)
  1010. duration = 0.2 # Time in seconds to fade out or fade in
  1011. @sprites["box"].refreshSprites = false
  1012. Graphics.update
  1013. self.update
  1014. # Fade old background to white
  1015. timer_start = System.uptime
  1016. loop do
  1017. alpha = lerp(0, 255, duration, timer_start, System.uptime)
  1018. @sprites["box"].color = Color.new(248, 248, 248, alpha)
  1019. Graphics.update
  1020. self.update
  1021. break if alpha >= 255
  1022. end
  1023. # Fade in new background from white
  1024. @sprites["box"].refreshBox = true
  1025. @storage[@storage.currentBox].background = wp
  1026. timer_start = System.uptime
  1027. loop do
  1028. alpha = lerp(255, 0, duration, timer_start, System.uptime)
  1029. @sprites["box"].color = Color.new(248, 248, 248, alpha)
  1030. Graphics.update
  1031. self.update
  1032. break if alpha <= 0
  1033. end
  1034. @sprites["box"].refreshSprites = true
  1035. Input.update
  1036. end
  1037.  
  1038. def pbSwitchBoxToRight(new_box_number)
  1039. start_x = @sprites["box"].x
  1040. heldsprite = @sprites["arrow"].heldPokemon
  1041. newbox = PokemonBoxSprite.new(@storage, new_box_number, @boxviewport)
  1042. newbox.x = start_x + 336
  1043. timer_start = System.uptime
  1044. loop do
  1045. @sprites["box"].x = lerp(start_x, start_x - 336, 0.25, timer_start, System.uptime)
  1046. newbox.x = @sprites["box"].x + 336
  1047. @sprites["arrow"].update
  1048. Graphics.update
  1049. break if newbox.x == start_x
  1050. end
  1051. @sprites["box"].dispose
  1052. @sprites["box"] = newbox
  1053. Input.update
  1054. end
  1055.  
  1056. def pbSwitchBoxToLeft(new_box_number)
  1057. start_x = @sprites["box"].x
  1058. heldsprite = @sprites["arrow"].heldPokemon
  1059. newbox = PokemonBoxSprite.new(@storage, new_box_number, @boxviewport)
  1060. newbox.x = start_x - 336
  1061. timer_start = System.uptime
  1062. loop do
  1063. @sprites["box"].x = lerp(start_x, start_x + 336, 0.25, timer_start, System.uptime)
  1064. newbox.x = @sprites["box"].x - 336
  1065. @sprites["arrow"].update
  1066. Graphics.update
  1067. break if newbox.x == start_x
  1068. end
  1069. @sprites["box"].dispose
  1070. @sprites["box"] = newbox
  1071. Input.update
  1072. end
  1073.  
  1074. def pbJumpToBox(newbox)
  1075. return if @storage.currentBox == newbox
  1076. if newbox > @storage.currentBox
  1077. pbSwitchBoxToRight(newbox)
  1078. else
  1079. pbSwitchBoxToLeft(newbox)
  1080. end
  1081. @storage.currentBox = newbox
  1082. end
  1083.  
  1084. def pbSetMosaic(selection)
  1085. return if @screen.pbHeldPokemon
  1086. return if @boxForMosaic == @storage.currentBox && @selectionForMosaic == selection
  1087. @sprites["pokemon"].mosaic_duration = 0.25 # In seconds
  1088. @boxForMosaic = @storage.currentBox
  1089. @selectionForMosaic = selection
  1090. end
  1091.  
  1092. def pbSetQuickSwap(value)
  1093. @quickswap = value
  1094. @sprites["arrow"].quickswap = value
  1095. end
  1096.  
  1097. def pbShowPartyTab
  1098. @sprites["arrow"].visible = false
  1099. pbUpdateOverlay(-1)
  1100. pbSetMosaic(-1)
  1101. end
  1102. pbSEPlay("GUI storage show party panel")
  1103. start_y = @sprites["boxparty"].y # Graphics.height
  1104. timer_start = System.uptime
  1105. loop do
  1106. @sprites["boxparty"].y = lerp(start_y, start_y - @sprites["boxparty"].height,
  1107. 0.4, timer_start, System.uptime)
  1108. self.update
  1109. Graphics.update
  1110. break if @sprites["boxparty"].y == start_y - @sprites["boxparty"].height
  1111. end
  1112. Input.update
  1113. @sprites["arrow"].visible = true
  1114. end
  1115.  
  1116. def pbHidePartyTab
  1117. @sprites["arrow"].visible = false
  1118. pbUpdateOverlay(-1)
  1119. pbSetMosaic(-1)
  1120. end
  1121. pbSEPlay("GUI storage hide party panel")
  1122. start_y = @sprites["boxparty"].y # Graphics.height - @sprites["boxparty"].height
  1123. timer_start = System.uptime
  1124. loop do
  1125. @sprites["boxparty"].y = lerp(start_y, start_y + @sprites["boxparty"].height,
  1126. 0.4, timer_start, System.uptime)
  1127. self.update
  1128. Graphics.update
  1129. break if @sprites["boxparty"].y == start_y + @sprites["boxparty"].height
  1130. end
  1131. Input.update
  1132. @sprites["arrow"].visible = true
  1133. end
  1134.  
  1135. def pbHold(selected)
  1136. pbSEPlay("GUI storage pick up")
  1137. if selected[0] == -1
  1138. @sprites["boxparty"].grabPokemon(selected[1], @sprites["arrow"])
  1139. else
  1140. @sprites["box"].grabPokemon(selected[1], @sprites["arrow"])
  1141. end
  1142. while @sprites["arrow"].grabbing?
  1143. Graphics.update
  1144. Input.update
  1145. self.update
  1146. end
  1147. end
  1148.  
  1149. def pbSwap(selected, _heldpoke)
  1150. pbSEPlay("GUI storage pick up")
  1151. heldpokesprite = @sprites["arrow"].heldPokemon
  1152. boxpokesprite = nil
  1153. if selected[0] == -1
  1154. boxpokesprite = @sprites["boxparty"].getPokemon(selected[1])
  1155. else
  1156. boxpokesprite = @sprites["box"].getPokemon(selected[1])
  1157. end
  1158. if selected[0] == -1
  1159. @sprites["boxparty"].setPokemon(selected[1], heldpokesprite)
  1160. else
  1161. @sprites["box"].setPokemon(selected[1], heldpokesprite)
  1162. end
  1163. @sprites["arrow"].setSprite(boxpokesprite)
  1164. @sprites["pokemon"].mosaic_duration = 0.25 # In seconds
  1165. @boxForMosaic = @storage.currentBox
  1166. @selectionForMosaic = selected[1]
  1167. end
  1168.  
  1169. def pbPlace(selected, _heldpoke)
  1170. pbSEPlay("GUI storage put down")
  1171. heldpokesprite = @sprites["arrow"].heldPokemon
  1172. @sprites["arrow"].place
  1173. while @sprites["arrow"].placing?
  1174. Graphics.update
  1175. Input.update
  1176. self.update
  1177. end
  1178. if selected[0] == -1
  1179. @sprites["boxparty"].setPokemon(selected[1], heldpokesprite)
  1180. else
  1181. @sprites["box"].setPokemon(selected[1], heldpokesprite)
  1182. end
  1183. @boxForMosaic = @storage.currentBox
  1184. @selectionForMosaic = selected[1]
  1185. end
  1186.  
  1187. def pbWithdraw(selected, heldpoke, partyindex)
  1188. pbHold(selected) if !heldpoke
  1189. pbShowPartyTab
  1190. pbPartySetArrow(@sprites["arrow"], partyindex)
  1191. pbPlace([-1, partyindex], heldpoke)
  1192. pbHidePartyTab
  1193. end
  1194.  
  1195. def pbStore(selected, heldpoke, destbox, firstfree)
  1196. if heldpoke
  1197. if destbox == @storage.currentBox
  1198. heldpokesprite = @sprites["arrow"].heldPokemon
  1199. @sprites["box"].setPokemon(firstfree, heldpokesprite)
  1200. @sprites["arrow"].setSprite(nil)
  1201. else
  1202. heldpokesprite = @sprites["arrow"].heldPokemon
  1203. @sprites["arrow"].setSprite(nil)
  1204. heldpokesprite&.dispose
  1205. end
  1206. else
  1207. sprite = @sprites["boxparty"].getPokemon(selected[1])
  1208. if destbox == @storage.currentBox
  1209. @sprites["box"].setPokemon(firstfree, sprite)
  1210. @sprites["boxparty"].setPokemon(selected[1], nil)
  1211. else
  1212. @sprites["boxparty"].deletePokemon(selected[1])
  1213. end
  1214. end
  1215. end
  1216.  
  1217. def pbRelease(selected, heldpoke)
  1218. box = selected[0]
  1219. index = selected[1]
  1220. if heldpoke
  1221. sprite = @sprites["arrow"].heldPokemon
  1222. elsif box == -1
  1223. sprite = @sprites["boxparty"].getPokemon(index)
  1224. else
  1225. sprite = @sprites["box"].getPokemon(index)
  1226. end
  1227. if sprite
  1228. sprite.release
  1229. while sprite.releasing?
  1230. Graphics.update
  1231. sprite.update
  1232. self.update
  1233. end
  1234. end
  1235. end
  1236.  
  1237. def pbChooseBox(msg)
  1238. commands = []
  1239. @storage.maxBoxes.times do |i|
  1240. box = @storage[i]
  1241. if box
  1242. commands.push(_INTL("{1} ({2}/{3})", box.name, box.nitems, box.length))
  1243. end
  1244. end
  1245. return pbShowCommands(msg, commands, @storage.currentBox)
  1246. end
  1247.  
  1248. def pbBoxName(helptext, minchars, maxchars)
  1249. oldsprites = pbFadeOutAndHide(@sprites)
  1250. ret = pbEnterBoxName(helptext, minchars, maxchars)
  1251. @storage[@storage.currentBox].name = ret if ret.length > 0
  1252. @sprites["box"].refreshBox = true
  1253. pbRefresh
  1254. pbFadeInAndShow(@sprites, oldsprites)
  1255. end
  1256.  
  1257. def pbChooseItem(bag)
  1258. ret = nil
  1259. pbFadeOutIn do
  1260. scene = PokemonBag_Scene.new
  1261. screen = PokemonBagScreen.new(scene, bag)
  1262. ret = screen.pbChooseItemScreen(proc { |item| GameData::Item.get(item).can_hold? })
  1263. end
  1264. return ret
  1265. end
  1266.  
  1267. def pbSummary(selected, heldpoke)
  1268. oldsprites = pbFadeOutAndHide(@sprites)
  1269. scene = PokemonSummary_Scene.new
  1270. screen = PokemonSummaryScreen.new(scene)
  1271. if heldpoke
  1272. screen.pbStartScreen([heldpoke], 0)
  1273. elsif selected[0] == -1
  1274. @selection = screen.pbStartScreen(@storage.party, selected[1])
  1275. pbPartySetArrow(@sprites["arrow"], @selection)
  1276. pbUpdateOverlay(@selection, @storage.party)
  1277. else
  1278. @selection = screen.pbStartScreen(@storage.boxes[selected[0]], selected[1])
  1279. pbSetArrow(@sprites["arrow"], @selection)
  1280. pbUpdateOverlay(@selection)
  1281. end
  1282. pbFadeInAndShow(@sprites, oldsprites)
  1283. end
  1284.  
  1285. def pbMarkingSetArrow(arrow, selection)
  1286. if selection >= 0
  1287. xvalues = [162, 191, 220, 162, 191, 220, 184, 184]
  1288. yvalues = [24, 24, 24, 49, 49, 49, 77, 109]
  1289. arrow.angle = 0
  1290. arrow.mirror = false
  1291. arrow.ox = 0
  1292. arrow.oy = 0
  1293. arrow.x = xvalues[selection] * 2
  1294. arrow.y = yvalues[selection] * 2
  1295. end
  1296. end
  1297.  
  1298. def pbMarkingChangeSelection(key, selection)
  1299. case key
  1300. when Input::LEFT
  1301. if selection < 6
  1302. selection -= 1
  1303. selection += 3 if selection % 3 == 2
  1304. end
  1305. when Input::RIGHT
  1306. if selection < 6
  1307. selection += 1
  1308. selection -= 3 if selection % 3 == 0
  1309. end
  1310. when Input::UP
  1311. if selection == 7
  1312. selection = 6
  1313. elsif selection == 6
  1314. selection = 4
  1315. elsif selection < 3
  1316. selection = 7
  1317. else
  1318. selection -= 3
  1319. end
  1320. when Input::DOWN
  1321. if selection == 7
  1322. selection = 1
  1323. elsif selection == 6
  1324. selection = 7
  1325. elsif selection >= 3
  1326. selection = 6
  1327. else
  1328. selection += 3
  1329. end
  1330. end
  1331. return selection
  1332. end
  1333.  
  1334. def pbMark(selected, heldpoke)
  1335. @sprites["markingbg"].visible = true
  1336. @sprites["markingoverlay"].visible = true
  1337. msg = _INTL("Mark your Pokémon.")
  1338. msgwindow = Window_UnformattedTextPokemon.newWithSize("", 180, 0, Graphics.width - 180, 32)
  1339. msgwindow.viewport = @viewport
  1340. msgwindow.visible = true
  1341. msgwindow.letterbyletter = false
  1342. msgwindow.text = msg
  1343. msgwindow.resizeHeightToFit(msg, Graphics.width - 180)
  1344. pbBottomRight(msgwindow)
  1345. base = Color.new(248, 248, 248)
  1346. shadow = Color.new(80, 80, 80)
  1347. pokemon = heldpoke
  1348. if heldpoke
  1349. pokemon = heldpoke
  1350. elsif selected[0] == -1
  1351. pokemon = @storage.party[selected[1]]
  1352. else
  1353. pokemon = @storage.boxes[selected[0]][selected[1]]
  1354. end
  1355. markings = pokemon.markings.clone
  1356. mark_variants = @markingbitmap.bitmap.height / MARK_HEIGHT
  1357. index = 0
  1358. redraw = true
  1359. markrect = Rect.new(0, 0, MARK_WIDTH, MARK_HEIGHT)
  1360. loop do
  1361. # Redraw the markings and text
  1362. if redraw
  1363. @sprites["markingoverlay"].bitmap.clear
  1364. (@markingbitmap.bitmap.width / MARK_WIDTH).times do |i|
  1365. markrect.x = i * MARK_WIDTH
  1366. markrect.y = [(markings[i] || 0), mark_variants - 1].min * MARK_HEIGHT
  1367. @sprites["markingoverlay"].bitmap.blt(336 + (58 * (i % 3)), 106 + (50 * (i / 3)),
  1368. @markingbitmap.bitmap, markrect)
  1369. end
  1370. textpos = [
  1371. [_INTL("OK"), 402, 216, :center, base, shadow, :outline],
  1372. [_INTL("Cancel"), 402, 280, :center, base, shadow, :outline]
  1373. ]
  1374. pbDrawTextPositions(@sprites["markingoverlay"].bitmap, textpos)
  1375. pbMarkingSetArrow(@sprites["arrow"], index)
  1376. redraw = false
  1377. end
  1378. Graphics.update
  1379. Input.update
  1380. key = -1
  1381. key = Input::DOWN if Input.repeat?(Input::DOWN)
  1382. key = Input::RIGHT if Input.repeat?(Input::RIGHT)
  1383. key = Input::LEFT if Input.repeat?(Input::LEFT)
  1384. key = Input::UP if Input.repeat?(Input::UP)
  1385. if key >= 0
  1386. oldindex = index
  1387. index = pbMarkingChangeSelection(key, index)
  1388. pbPlayCursorSE if index != oldindex
  1389. pbMarkingSetArrow(@sprites["arrow"], index)
  1390. end
  1391. self.update
  1392. if Input.trigger?(Input::BACK)
  1393. pbPlayCancelSE
  1394. break
  1395. elsif Input.trigger?(Input::USE)
  1396. pbPlayDecisionSE
  1397. case index
  1398. when 6 # OK
  1399. pokemon.markings = markings
  1400. break
  1401. when 7 # Cancel
  1402. break
  1403. else
  1404. markings[index] = ((markings[index] || 0) + 1) % mark_variants
  1405. redraw = true
  1406. end
  1407. end
  1408. end
  1409. @sprites["markingbg"].visible = false
  1410. @sprites["markingoverlay"].visible = false
  1411. msgwindow.dispose
  1412. end
  1413.  
  1414. def pbRefresh
  1415. @sprites["box"].refresh
  1416. @sprites["boxparty"].refresh
  1417. end
  1418.  
  1419. def pbHardRefresh
  1420. @sprites["box"].refresh
  1421. @sprites["boxparty"].refresh
  1422. end
  1423.  
  1424. def drawMarkings(bitmap, x, y, _width, _height, markings)
  1425. mark_variants = @markingbitmap.bitmap.height / MARK_HEIGHT
  1426. markrect = Rect.new(0, 0, MARK_WIDTH, MARK_HEIGHT)
  1427. (@markingbitmap.bitmap.width / MARK_WIDTH).times do |i|
  1428. markrect.x = i * MARK_WIDTH
  1429. markrect.y = [(markings[i] || 0), mark_variants - 1].min * MARK_HEIGHT
  1430. bitmap.blt(x + (i * MARK_WIDTH), y, @markingbitmap.bitmap, markrect)
  1431. end
  1432. end
  1433.  
  1434. def pbUpdateOverlay(selection, party = nil)
  1435. overlay = @sprites["overlay"].bitmap
  1436. overlay.clear
  1437. buttonbase = Color.new(248, 248, 248)
  1438. buttonshadow = Color.new(80, 80, 80)
  1439. pbDrawTextPositions(
  1440. overlay,
  1441. [[_INTL("Party: {1}", (@storage.party.length rescue 0)), 280, 470, :center, buttonbase, buttonshadow, :outline],
  1442. [_INTL("Exit"), 600, 470, :center, buttonbase, buttonshadow, :outline]]
  1443. )
  1444. pokemon = nil
  1445. if @screen.pbHeldPokemon
  1446. pokemon = @screen.pbHeldPokemon
  1447. elsif selection >= 0
  1448. pokemon = (party) ? party[selection] : @storage[@storage.currentBox, selection]
  1449. end
  1450. if !pokemon
  1451. @sprites["pokemon"].visible = false
  1452. return
  1453. end
  1454. @sprites["pokemon"].visible = true
  1455. base = Color.new(88, 88, 80)
  1456. shadow = Color.new(168, 184, 184)
  1457. nonbase = Color.new(208, 208, 208)
  1458. nonshadow = Color.new(224, 224, 224)
  1459. pokename = pokemon.name
  1460. textstrings = [
  1461. [pokename, 10, 14, :left, base, shadow]
  1462. ]
  1463. if !pokemon.egg?
  1464. imagepos = []
  1465. if pokemon.male?
  1466. textstrings.push([_INTL("♂"), 148, 14, :left, Color.new(24, 112, 216), Color.new(136, 168, 208)])
  1467. elsif pokemon.female?
  1468. textstrings.push([_INTL("♀"), 148, 14, :left, Color.new(248, 56, 32), Color.new(224, 152, 144)])
  1469. end
  1470. imagepos.push([_INTL("Graphics/UI/Storage/overlay_lv"), 6, 246])
  1471. textstrings.push([pokemon.level.to_s, 28, 240, :left, base, shadow])
  1472. if pokemon.ability
  1473. textstrings.push([pokemon.ability.name, 86, 312, :center, base, shadow])
  1474. else
  1475. textstrings.push([_INTL("No ability"), 86, 312, :center, nonbase, nonshadow])
  1476. end
  1477. if pokemon.item
  1478. textstrings.push([pokemon.item.name, 86, 348, :center, base, shadow])
  1479. else
  1480. textstrings.push([_INTL("No item"), 86, 348, :center, nonbase, nonshadow])
  1481. end
  1482. imagepos.push(["Graphics/UI/shiny", 156, 198]) if pokemon.shiny?
  1483. typebitmap = AnimatedBitmap.new(_INTL("Graphics/UI/types"))
  1484.  
  1485. pokemon.types.each_with_index do |type, i|
  1486. type_number = GameData::Type.get(type).icon_position
  1487. type_rect = Rect.new(0, type_number * 28, 64, 28)
  1488. type_x = (pokemon.types.length == 1) ? 52 : 18 + (70 * i)
  1489. overlay.blt(type_x, 272, typebitmap.bitmap, type_rect)
  1490. end
  1491.  
  1492. typebitmap.dispose
  1493. drawMarkings(overlay, 70, 240, 128, 20, pokemon.markings)
  1494. pbDrawImagePositions(overlay, imagepos)
  1495. end
  1496. pbDrawTextPositions(overlay, textstrings)
  1497. @sprites["pokemon"].setPokemonBitmap(pokemon)
  1498. end
  1499.  
  1500. def update
  1501. pbUpdateSpriteHash(@sprites)
  1502. end
  1503. end
  1504.  
  1505. #===============================================================================
  1506. # Pokémon storage mechanics
  1507. #===============================================================================
  1508. class PokemonStorageScreen
  1509. attr_reader :scene
  1510. attr_reader :storage
  1511. attr_accessor :heldpkmn
  1512.  
  1513. def initialize(scene, storage)
  1514. @scene = scene
  1515. @storage = storage
  1516. @pbHeldPokemon = nil
  1517. end
  1518.  
  1519. def pbStartScreen(command)
  1520. $game_temp.in_storage = true
  1521. @heldpkmn = nil
  1522. case command
  1523. when 0 # Organise
  1524. @scene.pbStartBox(self, command)
  1525. loop do
  1526. selected = @scene.pbSelectBox(@storage.party)
  1527. if selected.nil?
  1528. if pbHeldPokemon
  1529. pbDisplay(_INTL("You're holding a Pokémon!"))
  1530. next
  1531. end
  1532. next if pbConfirm(_INTL("Continue Box operations?"))
  1533. break
  1534. elsif selected[0] == -3 # Close box
  1535. if pbHeldPokemon
  1536. pbDisplay(_INTL("You're holding a Pokémon!"))
  1537. next
  1538. end
  1539. if pbConfirm(_INTL("Exit from the Box?"))
  1540. pbSEPlay("PC close")
  1541. break
  1542. end
  1543. next
  1544. elsif selected[0] == -4 # Box name
  1545. pbBoxCommands
  1546. else
  1547. pokemon = @storage[selected[0], selected[1]]
  1548. heldpoke = pbHeldPokemon
  1549. next if !pokemon && !heldpoke
  1550. if @scene.quickswap
  1551. if @heldpkmn
  1552. (pokemon) ? pbSwap(selected) : pbPlace(selected)
  1553. else
  1554. pbHold(selected)
  1555. end
  1556. else
  1557. commands = []
  1558. cmdMove = -1
  1559. cmdSummary = -1
  1560. cmdWithdraw = -1
  1561. cmdItem = -1
  1562. cmdMark = -1
  1563. cmdRelease = -1
  1564. cmdDebug = -1
  1565. if heldpoke
  1566. helptext = _INTL("{1} is selected.", heldpoke.name)
  1567. commands[cmdMove = commands.length] = (pokemon) ? _INTL("Shift") : _INTL("Place")
  1568. elsif pokemon
  1569. helptext = _INTL("{1} is selected.", pokemon.name)
  1570. commands[cmdMove = commands.length] = _INTL("Move")
  1571. end
  1572. commands[cmdSummary = commands.length] = _INTL("Summary")
  1573. commands[cmdWithdraw = commands.length] = (selected[0] == -1) ? _INTL("Store") : _INTL("Withdraw")
  1574. commands[cmdItem = commands.length] = _INTL("Item")
  1575. commands[cmdMark = commands.length] = _INTL("Mark")
  1576. commands[cmdRelease = commands.length] = _INTL("Release")
  1577. commands[cmdDebug = commands.length] = _INTL("Debug") if $DEBUG
  1578. commands[commands.length] = _INTL("Cancel")
  1579. command = pbShowCommands(helptext, commands)
  1580. if cmdMove >= 0 && command == cmdMove # Move/Shift/Place
  1581. if @heldpkmn
  1582. (pokemon) ? pbSwap(selected) : pbPlace(selected)
  1583. else
  1584. pbHold(selected)
  1585. end
  1586. elsif cmdSummary >= 0 && command == cmdSummary # Summary
  1587. pbSummary(selected, @heldpkmn)
  1588. elsif cmdWithdraw >= 0 && command == cmdWithdraw # Store/Withdraw
  1589. (selected[0] == -1) ? pbStore(selected, @heldpkmn) : pbWithdraw(selected, @heldpkmn)
  1590. elsif cmdItem >= 0 && command == cmdItem # Item
  1591. pbItem(selected, @heldpkmn)
  1592. elsif cmdMark >= 0 && command == cmdMark # Mark
  1593. pbMark(selected, @heldpkmn)
  1594. elsif cmdRelease >= 0 && command == cmdRelease # Release
  1595. pbRelease(selected, @heldpkmn)
  1596. elsif cmdDebug >= 0 && command == cmdDebug # Debug
  1597. pbPokemonDebug((@heldpkmn) ? @heldpkmn : pokemon, selected, heldpoke)
  1598. end
  1599. end
  1600. end
  1601. end
  1602. @scene.pbCloseBox
  1603. when 1 # Withdraw
  1604. @scene.pbStartBox(self, command)
  1605. loop do
  1606. selected = @scene.pbSelectBox(@storage.party)
  1607. if selected.nil?
  1608. next if pbConfirm(_INTL("Continue Box operations?"))
  1609. break
  1610. else
  1611. case selected[0]
  1612. when -2 # Party Pokémon
  1613. pbDisplay(_INTL("Which one will you take?"))
  1614. next
  1615. when -3 # Close box
  1616. if pbConfirm(_INTL("Exit from the Box?"))
  1617. pbSEPlay("PC close")
  1618. break
  1619. end
  1620. next
  1621. when -4 # Box name
  1622. pbBoxCommands
  1623. next
  1624. end
  1625. pokemon = @storage[selected[0], selected[1]]
  1626. next if !pokemon
  1627. command = pbShowCommands(_INTL("{1} is selected.", pokemon.name),
  1628. [_INTL("Withdraw"),
  1629. _INTL("Summary"),
  1630. _INTL("Mark"),
  1631. _INTL("Release"),
  1632. _INTL("Cancel")])
  1633. case command
  1634. when 0 then pbWithdraw(selected, nil)
  1635. when 1 then pbSummary(selected, nil)
  1636. when 2 then pbMark(selected, nil)
  1637. when 3 then pbRelease(selected, nil)
  1638. end
  1639. end
  1640. end
  1641. @scene.pbCloseBox
  1642. when 2 # Deposit
  1643. @scene.pbStartBox(self, command)
  1644. loop do
  1645. selected = @scene.pbSelectParty(@storage.party)
  1646. if selected == -3 # Close box
  1647. if pbConfirm(_INTL("Exit from the Box?"))
  1648. pbSEPlay("PC close")
  1649. break
  1650. end
  1651. next
  1652. elsif selected < 0
  1653. next if pbConfirm(_INTL("Continue Box operations?"))
  1654. break
  1655. else
  1656. pokemon = @storage[-1, selected]
  1657. next if !pokemon
  1658. command = pbShowCommands(_INTL("{1} is selected.", pokemon.name),
  1659. [_INTL("Store"),
  1660. _INTL("Summary"),
  1661. _INTL("Mark"),
  1662. _INTL("Release"),
  1663. _INTL("Cancel")])
  1664. case command
  1665. when 0 then pbStore([-1, selected], nil)
  1666. when 1 then pbSummary([-1, selected], nil)
  1667. when 2 then pbMark([-1, selected], nil)
  1668. when 3 then pbRelease([-1, selected], nil)
  1669. end
  1670. end
  1671. end
  1672. @scene.pbCloseBox
  1673. when 3
  1674. @scene.pbStartBox(self, command)
  1675. @scene.pbCloseBox
  1676. end
  1677. $game_temp.in_storage = false
  1678. end
  1679.  
  1680. # For debug purposes.
  1681. def pbUpdate
  1682. @scene.update
  1683. end
  1684.  
  1685. # For debug purposes.
  1686. def pbHardRefresh
  1687. @scene.pbHardRefresh
  1688. end
  1689.  
  1690. # For debug purposes.
  1691. def pbRefreshSingle(i)
  1692. @scene.pbUpdateOverlay(i[1], (i[0] == -1) ? @storage.party : nil)
  1693. @scene.pbHardRefresh
  1694. end
  1695.  
  1696. def pbDisplay(message)
  1697. @scene.pbDisplay(message)
  1698. end
  1699.  
  1700. def pbConfirm(str)
  1701. return pbShowCommands(str, [_INTL("Yes"), _INTL("No")]) == 0
  1702. end
  1703.  
  1704. def pbShowCommands(msg, commands, index = 0)
  1705. return @scene.pbShowCommands(msg, commands, index)
  1706. end
  1707.  
  1708. def pbAble?(pokemon)
  1709. pokemon && !pokemon.egg? && pokemon.hp > 0
  1710. end
  1711.  
  1712. def pbAbleCount
  1713. count = 0
  1714. @storage.party.each do |p|
  1715. count += 1 if pbAble?(p)
  1716. end
  1717. return count
  1718. end
  1719.  
  1720. def pbHeldPokemon
  1721. return @heldpkmn
  1722. end
  1723.  
  1724. def pbWithdraw(selected, heldpoke)
  1725. box = selected[0]
  1726. index = selected[1]
  1727. raise _INTL("Can't withdraw from party...") if box == -1
  1728. if @storage.party_full?
  1729. pbDisplay(_INTL("Your party's full!"))
  1730. return false
  1731. end
  1732. @scene.pbWithdraw(selected, heldpoke, @storage.party.length)
  1733. if heldpoke
  1734. @storage.pbMoveCaughtToParty(heldpoke)
  1735. @heldpkmn = nil
  1736. else
  1737. @storage.pbMove(-1, -1, box, index)
  1738. end
  1739. @scene.pbRefresh
  1740. return true
  1741. end
  1742.  
  1743. def pbStore(selected, heldpoke)
  1744. box = selected[0]
  1745. index = selected[1]
  1746. raise _INTL("Can't deposit from box...") if box != -1
  1747. if pbAbleCount <= 1 && pbAble?(@storage[box, index]) && !heldpoke
  1748. pbPlayBuzzerSE
  1749. pbDisplay(_INTL("That's your last Pokémon!"))
  1750. elsif heldpoke&.mail
  1751. pbDisplay(_INTL("Please remove the Mail."))
  1752. elsif !heldpoke && @storage[box, index].mail
  1753. pbDisplay(_INTL("Please remove the Mail."))
  1754. elsif heldpoke&.cannot_store
  1755. pbDisplay(_INTL("{1} refuses to go into storage!", heldpoke.name))
  1756. elsif !heldpoke && @storage[box, index].cannot_store
  1757. pbDisplay(_INTL("{1} refuses to go into storage!", @storage[box, index].name))
  1758. else
  1759. loop do
  1760. destbox = @scene.pbChooseBox(_INTL("Deposit in which Box?"))
  1761. if destbox >= 0
  1762. firstfree = @storage.pbFirstFreePos(destbox)
  1763. if firstfree < 0
  1764. pbDisplay(_INTL("The Box is full."))
  1765. next
  1766. end
  1767. if heldpoke || selected[0] == -1
  1768. p = (heldpoke) ? heldpoke : @storage[-1, index]
  1769. if Settings::HEAL_STORED_POKEMON
  1770. old_ready_evo = p.ready_to_evolve
  1771. p.heal
  1772. p.ready_to_evolve = old_ready_evo
  1773. end
  1774. end
  1775. @scene.pbStore(selected, heldpoke, destbox, firstfree)
  1776. if heldpoke
  1777. @storage.pbMoveCaughtToBox(heldpoke, destbox)
  1778. @heldpkmn = nil
  1779. else
  1780. @storage.pbMove(destbox, -1, -1, index)
  1781. end
  1782. end
  1783. break
  1784. end
  1785. @scene.pbRefresh
  1786. end
  1787. end
  1788.  
  1789. def pbHold(selected)
  1790. box = selected[0]
  1791. index = selected[1]
  1792. if box == -1 && pbAble?(@storage[box, index]) && pbAbleCount <= 1
  1793. pbPlayBuzzerSE
  1794. pbDisplay(_INTL("That's your last Pokémon!"))
  1795. return
  1796. end
  1797. @scene.pbHold(selected)
  1798. @heldpkmn = @storage[box, index]
  1799. @storage.pbDelete(box, index)
  1800. @scene.pbRefresh
  1801. end
  1802.  
  1803. def pbPlace(selected)
  1804. box = selected[0]
  1805. index = selected[1]
  1806. if @storage[box, index]
  1807. raise _INTL("Position {1},{2} is not empty...", box, index)
  1808. elsif box != -1
  1809. if index >= @storage.maxPokemon(box)
  1810. pbDisplay("Can't place that there.")
  1811. return
  1812. elsif @heldpkmn.mail
  1813. pbDisplay("Please remove the mail.")
  1814. return
  1815. elsif @heldpkmn.cannot_store
  1816. pbDisplay(_INTL("{1} refuses to go into storage!", @heldpkmn.name))
  1817. return
  1818. end
  1819. end
  1820. if Settings::HEAL_STORED_POKEMON && box >= 0
  1821. old_ready_evo = @heldpkmn.ready_to_evolve
  1822. @heldpkmn.heal
  1823. @heldpkmn.ready_to_evolve = old_ready_evo
  1824. end
  1825. @scene.pbPlace(selected, @heldpkmn)
  1826. @storage[box, index] = @heldpkmn
  1827. @storage.party.compact! if box == -1
  1828. @scene.pbRefresh
  1829. @heldpkmn = nil
  1830. end
  1831.  
  1832. def pbSwap(selected)
  1833. box = selected[0]
  1834. index = selected[1]
  1835. if !@storage[box, index]
  1836. raise _INTL("Position {1},{2} is empty...", box, index)
  1837. end
  1838. if @heldpkmn.cannot_store && box != -1
  1839. pbPlayBuzzerSE
  1840. pbDisplay(_INTL("{1} refuses to go into storage!", @heldpkmn.name))
  1841. return false
  1842. elsif box == -1 && pbAble?(@storage[box, index]) && pbAbleCount <= 1 && !pbAble?(@heldpkmn)
  1843. pbPlayBuzzerSE
  1844. pbDisplay(_INTL("That's your last Pokémon!"))
  1845. return false
  1846. end
  1847. if box != -1 && @heldpkmn.mail
  1848. pbDisplay("Please remove the mail.")
  1849. return false
  1850. end
  1851. if Settings::HEAL_STORED_POKEMON && box >= 0
  1852. old_ready_evo = @heldpkmn.ready_to_evolve
  1853. @heldpkmn.heal
  1854. @heldpkmn.ready_to_evolve = old_ready_evo
  1855. end
  1856. @scene.pbSwap(selected, @heldpkmn)
  1857. tmp = @storage[box, index]
  1858. @storage[box, index] = @heldpkmn
  1859. @heldpkmn = tmp
  1860. @scene.pbRefresh
  1861. return true
  1862. end
  1863.  
  1864. def pbRelease(selected, heldpoke)
  1865. box = selected[0]
  1866. index = selected[1]
  1867. pokemon = (heldpoke) ? heldpoke : @storage[box, index]
  1868. return if !pokemon
  1869. if pokemon.egg?
  1870. pbDisplay(_INTL("You can't release an Egg."))
  1871. return false
  1872. elsif pokemon.mail
  1873. pbDisplay(_INTL("Please remove the mail."))
  1874. return false
  1875. elsif pokemon.cannot_release
  1876. pbDisplay(_INTL("{1} refuses to leave you!", pokemon.name))
  1877. return false
  1878. end
  1879. if box == -1 && pbAbleCount <= 1 && pbAble?(pokemon) && !heldpoke
  1880. pbPlayBuzzerSE
  1881. pbDisplay(_INTL("That's your last Pokémon!"))
  1882. return
  1883. end
  1884. command = pbShowCommands(_INTL("Release this Pokémon?"), [_INTL("No"), _INTL("Yes")])
  1885. if command == 1
  1886. pkmnname = pokemon.name
  1887. @scene.pbRelease(selected, heldpoke)
  1888. if heldpoke
  1889. @heldpkmn = nil
  1890. else
  1891. @storage.pbDelete(box, index)
  1892. end
  1893. @scene.pbRefresh
  1894. pbDisplay(_INTL("{1} was released.", pkmnname))
  1895. pbDisplay(_INTL("Bye-bye, {1}!", pkmnname))
  1896. @scene.pbRefresh
  1897. end
  1898. return
  1899. end
  1900.  
  1901. def pbChooseMove(pkmn, helptext, index = 0)
  1902. movenames = []
  1903. pkmn.moves.each do |i|
  1904. if i.total_pp <= 0
  1905. movenames.push(_INTL("{1} (PP: ---)", i.name))
  1906. else
  1907. movenames.push(_INTL("{1} (PP: {2}/{3})", i.name, i.pp, i.total_pp))
  1908. end
  1909. end
  1910. return @scene.pbShowCommands(helptext, movenames, index)
  1911. end
  1912.  
  1913. def pbSummary(selected, heldpoke)
  1914. @scene.pbSummary(selected, heldpoke)
  1915. end
  1916.  
  1917. def pbMark(selected, heldpoke)
  1918. @scene.pbMark(selected, heldpoke)
  1919. end
  1920.  
  1921. def pbItem(selected, heldpoke)
  1922. box = selected[0]
  1923. index = selected[1]
  1924. pokemon = (heldpoke) ? heldpoke : @storage[box, index]
  1925. if pokemon.egg?
  1926. pbDisplay(_INTL("Eggs can't hold items."))
  1927. return
  1928. elsif pokemon.mail
  1929. pbDisplay(_INTL("Please remove the mail."))
  1930. return
  1931. end
  1932. if pokemon.item
  1933. itemname = pokemon.item.portion_name
  1934. if pbConfirm(_INTL("Take the {1}?", itemname))
  1935. if $bag.add(pokemon.item)
  1936. pbDisplay(_INTL("Took the {1}.", itemname))
  1937. pokemon.item = nil
  1938. @scene.pbHardRefresh
  1939. else
  1940. pbDisplay(_INTL("Can't store the {1}.", itemname))
  1941. end
  1942. end
  1943. else
  1944. item = scene.pbChooseItem($bag)
  1945. if item
  1946. itemname = GameData::Item.get(item).name
  1947. pokemon.item = item
  1948. $bag.remove(item)
  1949. pbDisplay(_INTL("{1} is now being held.", itemname))
  1950. @scene.pbHardRefresh
  1951. end
  1952. end
  1953. end
  1954.  
  1955. def pbBoxCommands
  1956. commands = [
  1957. _INTL("Jump"),
  1958. _INTL("Wallpaper"),
  1959. _INTL("Name"),
  1960. _INTL("Cancel")
  1961. ]
  1962. command = pbShowCommands(_INTL("What do you want to do?"), commands)
  1963. case command
  1964. when 0
  1965. destbox = @scene.pbChooseBox(_INTL("Jump to which Box?"))
  1966. @scene.pbJumpToBox(destbox) if destbox >= 0
  1967. when 1
  1968. papers = @storage.availableWallpapers
  1969. index = 0
  1970. papers[1].length.times do |i|
  1971. if papers[1][i] == @storage[@storage.currentBox].background
  1972. index = i
  1973. break
  1974. end
  1975. end
  1976. wpaper = pbShowCommands(_INTL("Pick the wallpaper."), papers[0], index)
  1977. @scene.pbChangeBackground(papers[1][wpaper]) if wpaper >= 0
  1978. when 2
  1979. @scene.pbBoxName(_INTL("Box name?"), 0, 12)
  1980. end
  1981. end
  1982.  
  1983. def pbChoosePokemon(_party = nil)
  1984. $game_temp.in_storage = true
  1985. @heldpkmn = nil
  1986. @scene.pbStartBox(self, 1)
  1987. retval = nil
  1988. loop do
  1989. selected = @scene.pbSelectBox(@storage.party)
  1990. if selected && selected[0] == -3 # Close box
  1991. if pbConfirm(_INTL("Exit from the Box?"))
  1992. pbSEPlay("PC close")
  1993. break
  1994. end
  1995. next
  1996. end
  1997. if selected.nil?
  1998. next if pbConfirm(_INTL("Continue Box operations?"))
  1999. break
  2000. elsif selected[0] == -4 # Box name
  2001. pbBoxCommands
  2002. else
  2003. pokemon = @storage[selected[0], selected[1]]
  2004. next if !pokemon
  2005. commands = [
  2006. _INTL("Select"),
  2007. _INTL("Summary"),
  2008. _INTL("Withdraw"),
  2009. _INTL("Item"),
  2010. _INTL("Mark")
  2011. ]
  2012. commands.push(_INTL("Cancel"))
  2013. commands[2] = _INTL("Store") if selected[0] == -1
  2014. helptext = _INTL("{1} is selected.", pokemon.name)
  2015. command = pbShowCommands(helptext, commands)
  2016. case command
  2017. when 0 # Select
  2018. if pokemon
  2019. retval = selected
  2020. break
  2021. end
  2022. when 1
  2023. pbSummary(selected, nil)
  2024. when 2 # Store/Withdraw
  2025. if selected[0] == -1
  2026. pbStore(selected, nil)
  2027. else
  2028. pbWithdraw(selected, nil)
  2029. end
  2030. when 3
  2031. pbItem(selected, nil)
  2032. when 4
  2033. pbMark(selected, nil)
  2034. end
  2035. end
  2036. end
  2037. @scene.pbCloseBox
  2038. $game_temp.in_storage = false
  2039. return retval
  2040. end
  2041. end