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