Advertisement
OGButtjuice

Luka's Modular Menu

Jul 17th, 2018
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.42 KB | None | 0 0
  1. #===============================================================================
  2. # Neo PauseMenu (for v17.x)
  3. # by Luka S.J.
  4. # ----------------
  5. # Provides only features present in the default version of the Pokedex in
  6. # Essentials. Mean as a new cosmetic overhaul, adhering to the UI design
  7. # language of the Elite Battle System: The Next Generation
  8. #
  9. # Enjoy the script, and make sure to give credit!
  10. # (DO NOT ALTER THE NAMES OF THE INDIVIDUAL SCRIPT SECTIONS OR YOU WILL BREAK
  11. # YOUR SYSTEM!)
  12. #-------------------------------------------------------------------------------
  13. # Main module for handling each menu item/entry
  14. #===============================================================================
  15. module MenuHandlers
  16. # hash used to store the elements inside of the menu
  17. @@menuEntry = {}
  18. # hash used to store whether or not an element is unlocked
  19. @@available = {}
  20. # hash used to store the index of each element; for sorting
  21. @@indexes = {}
  22. @@index = 0
  23. # function to add a new element/entry to the menu.
  24. def self.addEntry(ref,name,icon,proc,conditional)
  25. @@menuEntry[ref] = [name,icon,proc]
  26. @@available[ref] = conditional
  27. @@indexes[ref] = @@index
  28. @@index += 1
  29. end
  30. # function to get the name of an element/entry
  31. def self.getName(ref)
  32. return @@menuEntry[ref][0]
  33. end
  34. # function to get the icon of an element/entry
  35. def self.getIcon(ref)
  36. return "Graphics/Icons/#{@@menuEntry[ref][1]}"
  37. end
  38. # function to get all the possible keys from the main hash
  39. def self.getKeys
  40. entries = Array.new(@@menuEntry.keys.length)
  41. for key in @@menuEntry.keys
  42. entries[@@indexes[key]] = key
  43. end
  44. return entries
  45. end
  46. # function used to invoke the stored code for each element/entry
  47. def self.runAction(ref,scene)
  48. @@menuEntry[ref][2].call(scene)
  49. end
  50. # function to check if the player has access to an element/entry
  51. def self.available?(ref)
  52. return @@available[ref].call
  53. end
  54. # function that lists all accessible menu elements/entries
  55. def self.elements?
  56. ent = self.getKeys
  57. items = 0
  58. for val in ent
  59. items += 1 if self.available?(val)
  60. end
  61. return items
  62. end
  63. end
  64. #-------------------------------------------------------------------------------
  65. # Main class used to handle the visuals
  66. #-------------------------------------------------------------------------------
  67. class PokemonPauseMenu_Scene
  68. attr_accessor :index
  69. attr_accessor :entries
  70. attr_accessor :endscene
  71. attr_accessor :close
  72. attr_accessor :hidden
  73.  
  74. # retained for compatibility
  75. def pbShowInfo(text)
  76. @sprites["helpwindow"].resizeToFit(text,Graphics.height)
  77. @sprites["helpwindow"].text = text
  78. @sprites["helpwindow"].visible = true
  79. @helpstate = true
  80. pbBottomLeft(@sprites["helpwindow"])
  81. end
  82. # retained for compatibility
  83. def pbShowHelp(text)
  84. @sprites["helpwindow"].resizeToFit(text,Graphics.height)
  85. @sprites["helpwindow"].text = text
  86. @sprites["helpwindow"].visible = true
  87. @helpstate = true
  88. pbBottomLeft(@sprites["helpwindow"])
  89. end
  90. # main scene generation
  91. def pbStartScene
  92. pbSetViableDexes
  93. # sets the default index
  94. @index = $PokemonTemp.menuLastChoice.nil? ? 0 : $PokemonTemp.menuLastChoice
  95. @index = 0 if @index >= MenuHandlers.elements?
  96. @oldindex = 0
  97. @endscene = true
  98. @close = false
  99. @hidden = false
  100. # loads the visual parts of the
  101. @viewport = Viewport.new(0,0,Graphics.width,Graphics.height)
  102. @viewport.z = 99999
  103. @sprites = {}
  104. # initializes the background graphic
  105. @bitmap = Graphics.snap_to_bitmap if !@bitmap
  106. @sprites["background"] = Sprite.new(@viewport)
  107. @sprites["background"].bitmap = @bitmap
  108. @sprites["background"].blur_sprite(3)
  109. @sprites["background"].bitmap.blt(0,0,pbBitmap("Graphics/Pictures/PauseMenu/bg"),Rect.new(0,0,Graphics.width,Graphics.height))
  110. bmp = pbBitmap("Graphics/Pictures/Common/scrollbar_bg")
  111. @sprites["background"].bitmap.blt(Graphics.width - 28,(Graphics.height - bmp.height)/2,bmp,Rect.new(0,0,bmp.width,bmp.height))
  112. # initializes the scrolling panorama
  113. @sprites["panorama"] = ScrollingSprite.new(@viewport)
  114. @sprites["panorama"].setBitmap("Graphics/Pictures/Common/panorama")
  115. @sprites["panorama"].speed = 1
  116. # retained for compatibility
  117. @sprites["infowindow"] = Window_UnformattedTextPokemon.newWithSize("",0,0,32,32,@viewport)
  118. @sprites["infowindow"].visible = false
  119. @sprites["helpwindow"] = Window_UnformattedTextPokemon.newWithSize("",0,0,32,32,@viewport)
  120. @sprites["helpwindow"].visible = false
  121. # draw the contest crap
  122. @sprites["textOverlay"] = Sprite.new(@viewport)
  123. @sprites["textOverlay"].bitmap = Bitmap.new(@viewport.rect.width,@viewport.rect.height)
  124. @sprites["textOverlay"].end_x = 0
  125. @sprites["textOverlay"].x = -@viewport.rect.width
  126. pbSetSystemFont(@sprites["textOverlay"].bitmap)
  127. bmp = pbBitmap("Graphics/Pictures/Common/partyBar")
  128. content = []
  129. text = []
  130. if pbInSafari?
  131. content.push(_INTL("Steps: {1}/{2}",pbSafariState.steps,SAFARISTEPS)) if SAFARISTEPS > 0
  132. content.push(_INTL("Balls: {1}",pbSafariState.ballcount))
  133. elsif pbInBugContest?
  134. if pbBugContestState.lastPokemon
  135. content.push(_INTL("Caught: {1}",PBSpecies.getName(pbBugContestState.lastPokemon.species)))
  136. content.push(_INTL("Level: {1}",pbBugContestState.lastPokemon.level))
  137. content.push(_INTL("Balls: {1}",pbBugContestState.ballcount))
  138. else
  139. content.push("Caught: none")
  140. end
  141. content.push(_INTL("Balls: {1}",pbBugContestState.ballcount))
  142. end
  143. for i in 0...content.length
  144. text.push([content[i],16, 60 + i*50, 0, Color.new(255,255,255),Color.new(0,0,0,65)])
  145. @sprites["textOverlay"].bitmap.blt(-2,92 + i*50,bmp,Rect.new(0,0,bmp.width,bmp.height))
  146. end
  147. pbDrawTextPositions(@sprites["textOverlay"].bitmap,text)
  148. # initializes the scroll bar
  149. @sprites["scroll"] = Sprite.new(@viewport)
  150. # rendering elements on screen
  151. self.refresh
  152. self.update
  153. # memorizes the target opacities and sets them to 0
  154. @opacities = {}
  155. for key in @sprites.keys
  156. @opacities[key] = @sprites[key].opacity
  157. @sprites[key].opacity = 0
  158. end
  159. end
  160.  
  161. def pbHideMenu
  162. # animations for closing the menu
  163. @sprites["textOverlay"].end_x = -@viewport.rect.width
  164. 8.times do
  165. for key in @sprites.keys
  166. next if !@sprites[key] || @sprites[key].disposed?
  167. @sprites[key].opacity -= 32
  168. end
  169. @sprites["textOverlay"].x += (@sprites["textOverlay"].end_x - @sprites["textOverlay"].x)*0.2
  170. Graphics.update
  171. end
  172. end
  173.  
  174. def pbShowMenu
  175. # animations for opening the menu
  176. @sprites["textOverlay"].end_x = 0
  177. 8.times do
  178. for key in @sprites.keys
  179. next if !@sprites[key] || @sprites[key].disposed?
  180. @sprites[key].opacity += 32 if @sprites[key].opacity < @opacities[key]
  181. end
  182. @sprites["textOverlay"].x += (@sprites["textOverlay"].end_x - @sprites["textOverlay"].x)*0.4
  183. Graphics.update
  184. end
  185. end
  186.  
  187. def refresh
  188. # index safety
  189. @index = MenuHandlers.elements? - 1 if @index >= MenuHandlers.elements?
  190. @oldindex = @index
  191. # disposes old items in the menu
  192. if @entries
  193. for i in 0...@entries.length
  194. @sprites["#{i}"].dispose if @sprites["#{i}"]
  195. end
  196. end
  197. # creates a new list of available items
  198. ent = MenuHandlers.getKeys
  199. @entries = []
  200. for val in ent
  201. @entries.push(val) if MenuHandlers.available?(val)
  202. end
  203. # draws individual item entries
  204. bmp = pbBitmap("Graphics/Pictures/PauseMenu/sel")
  205. for i in 0...@entries.length
  206. key = @entries[i]
  207. @sprites["#{i}"] = Sprite.new(@viewport)
  208. @sprites["#{i}"].bitmap = Bitmap.new(bmp.width,bmp.height)
  209. pbSetSystemFont(@sprites["#{i}"].bitmap)
  210. @sprites["#{i}"].src_rect.set(0,0,bmp.width/2,bmp.height)
  211. @sprites["#{i}"].bitmap.blt(0,0,bmp,Rect.new(0,0,bmp.width,bmp.height))
  212. for j in 0...2
  213. opac = j == 0 ? 155 : 255
  214. icon = pbBitmap(MenuHandlers.getIcon(key))
  215. text = MenuHandlers.getName(key)
  216. text.gsub!("\\pn"){"#{$Trainer.name}"}
  217. text.gsub!("\\contest"){pbInSafari? ? "Quit" : "Quit Contest"}
  218. @sprites["#{i}"].bitmap.blt(18 + j*bmp.width/2,6,icon,Rect.new(0,0,48,48),opac)
  219. pbDrawOutlineText(@sprites["#{i}"].bitmap,66 + j*bmp.width/2,6,136,48,text,Color.new(255,255,255),Color.new(64,64,64),1)
  220. end
  221. @sprites["#{i}"].x = Graphics.width - bmp.width/2 - 52
  222. @sprites["#{i}"].y = 49 + (bmp.height + 12)*i
  223. @sprites["#{i}"].opacity = 128
  224. end
  225. # configures the scroll bar
  226. n = (@entries.length < 4 ? 1 : @entries.length - 3)
  227. height = 204/n
  228. height += 204 - (height*n)
  229. height += 16
  230. @sprites["scroll"].bitmap = Bitmap.new(16,height)
  231. bmp = pbBitmap("Graphics/Pictures/Common/scrollbar_kn")
  232. @sprites["scroll"].bitmap.blt(0,0,bmp,Rect.new(0,0,16,6))
  233. @sprites["scroll"].bitmap.stretch_blt(Rect.new(0,6,16,height-14),bmp,Rect.new(0,6,16,1))
  234. @sprites["scroll"].bitmap.blt(0,height-8,bmp,Rect.new(0,8,16,8))
  235. @sprites["scroll"].x = Graphics.width - 32
  236. @sprites["scroll"].y = (Graphics.height - 204)/2
  237. @sprites["scroll"].end_y = (Graphics.height - 204)/2
  238. end
  239.  
  240. def update
  241. # scrolling background image
  242. @sprites["panorama"].update
  243. # calculations for updating the scrollbar position
  244. k = (@entries.length < 4 ? 0 : @index - 3)
  245. k = 0 if k < 0
  246. n = (@entries.length < 4 ? 1 : @entries.length - 3)
  247. height = 204/n
  248. @sprites["scroll"].end_y = (Graphics.height-204)/2 + height*k
  249. @sprites["scroll"].y += (@sprites["scroll"].end_y - @sprites["scroll"].y)*0.2
  250. # updates for each element/entry in the menu
  251. for i in 0...@entries.length
  252. j = @entries.length < 4 ? 0 : (@index - 3)
  253. j = 0 if j < 0
  254. y = (-j)*(@sprites["#{i}"].src_rect.height + 12) + 49 + i*(@sprites["#{i}"].src_rect.height + 12)
  255. @sprites["#{i}"].y -= (@sprites["#{i}"].y - y)*0.1
  256. @sprites["#{i}"].src_rect.x = @sprites["#{i}"].src_rect.width*(@index == i ? 1 : 0)
  257. @sprites["#{i}"].x += 2 if @sprites["#{i}"].x < Graphics.width - @sprites["#{i}"].src_rect.width - 52
  258. if i.between?(j,j+3)
  259. @sprites["#{i}"].opacity += 15 if @sprites["#{i}"].opacity < 255
  260. else
  261. @sprites["#{i}"].opacity -= 15 if @sprites["#{i}"].opacity > 128
  262. end
  263. if @index == i
  264. @sprites["#{i}"].tone.gray -= 51 if @sprites["#{i}"].tone.gray > 0
  265. else
  266. @sprites["#{i}"].tone.gray += 51 if @sprites["#{i}"].tone.gray < 255
  267. end
  268. end
  269. # sets the index
  270. if @oldindex != @index
  271. @sprites["#{@index}"].x -= 6
  272. @oldindex = @index
  273. end
  274. end
  275.  
  276. def pbEndScene
  277. # disposes the sprite hash
  278. pbHideMenu
  279. pbDisposeSpriteHash(@sprites)
  280. @viewport.dispose
  281. end
  282.  
  283. def pbRefresh
  284. end
  285. end
  286. #-------------------------------------------------------------------------------
  287. # Main class used to handle the logic of the pause menu
  288. #-------------------------------------------------------------------------------
  289. class PokemonPauseMenu
  290. def initialize(scene)
  291. @scene = scene
  292. end
  293.  
  294. def pbShowMenu
  295. #@scene.pbRefresh
  296. @scene.pbShowMenu
  297. end
  298.  
  299. def pbStartPokemonMenu
  300. # loads up the scene
  301. @scene.pbStartScene
  302. @scene.pbShowMenu
  303. loop do
  304. # main loop
  305. Graphics.update
  306. Input.update
  307. @scene.update
  308. if Input.repeat?(Input::DOWN)
  309. @scene.index += 1
  310. @scene.index = 0 if @scene.index > @scene.entries.length - 1
  311. $PokemonTemp.menuLastChoice = @scene.index
  312. pbSEPlay("SE_Select1")
  313. elsif Input.repeat?(Input::UP)
  314. @scene.index -= 1
  315. @scene.index = @scene.entries.length - 1 if @scene.index < 0
  316. $PokemonTemp.menuLastChoice = @scene.index
  317. pbSEPlay("SE_Select1")
  318. elsif Input.trigger?(Input::C)
  319. MenuHandlers.runAction(@scene.entries[@scene.index],@scene)
  320. end
  321. break if @scene.close || Input.trigger?(Input::B)
  322. end
  323. # used to dispose of the scene
  324. @scene.pbEndScene if @scene.endscene
  325. end
  326. end
  327. #-------------------------------------------------------------------------------
  328. # Your own entries for the pause menu
  329. #
  330. # How to use
  331. #
  332. # MenuHandlers.addEntry(:name,"button text","icon name",proc{|menu|
  333. # # code you want to run
  334. # # when the entry in the menu is selected
  335. # },proc{ # code to check if menu entry is available })
  336. #-------------------------------------------------------------------------------
  337. # PokeDex
  338. MenuHandlers.addEntry(:POKEDEX,_INTL("Pokédex"),"menuPokedex",proc{|menu|
  339. if DEXDEPENDSONLOCATION
  340. pbFadeOutIn(99999){
  341. scene = PokemonPokedex_Scene.new
  342. screen = PokemonPokedexScreen.new(scene)
  343. screen.pbStartScreen
  344. menu.refresh
  345. }
  346. else
  347. if $PokemonGlobal.pokedexViable.length==1
  348. $PokemonGlobal.pokedexDex = $PokemonGlobal.pokedexViable[0]
  349. $PokemonGlobal.pokedexDex = -1 if $PokemonGlobal.pokedexDex==$PokemonGlobal.pokedexUnlocked.length-1
  350. pbFadeOutIn(99999){
  351. scene = PokemonPokedex_Scene.new
  352. screen = PokemonPokedexScreen.new(scene)
  353. screen.pbStartScreen
  354. menu.refresh
  355. }
  356. else
  357. pbFadeOutIn(99999){
  358. scene = PokemonPokedexMenu_Scene.new
  359. screen = PokemonPokedexMenuScreen.new(scene)
  360. screen.pbStartScreen
  361. menu.refresh
  362. }
  363. end
  364. end
  365. },proc{ return $Trainer.pokedex && $PokemonGlobal.pokedexViable.length > 0 })
  366. # Party Screen
  367. MenuHandlers.addEntry(:POKEMON,_INTL("Pokémon"),"menuPokemon",proc{|menu|
  368. sscene = PokemonParty_Scene.new
  369. sscreen = PokemonPartyScreen.new(sscene,$Trainer.party)
  370. hiddenmove = nil
  371. pbFadeOutIn(99999) {
  372. hiddenmove = sscreen.pbPokemonScreen
  373. if hiddenmove
  374. menu.pbEndScene
  375. menu.endscene = false
  376. end
  377. }
  378. if hiddenmove
  379. Kernel.pbUseHiddenMove(hiddenmove[0],hiddenmove[1])
  380. menu.close = true
  381. end
  382. },proc{ return $Trainer.party.length > 0 })
  383. # Bag Screen
  384. MenuHandlers.addEntry(:BAG,_INTL("Bag"),"menuBag",proc{|menu|
  385. item = 0
  386. scene = PokemonBag_Scene.new
  387. screen = PokemonBagScreen.new(scene,$PokemonBag)
  388. pbFadeOutIn(99999) {
  389. item = screen.pbStartScreen
  390. if item > 0
  391. menu.pbEndScene
  392. menu.endscene = false
  393. end
  394. }
  395. if item > 0
  396. Kernel.pbUseKeyItemInField(item)
  397. menu.close = true
  398. end
  399. },proc{ return true })
  400. # PokeGear
  401. MenuHandlers.addEntry(:POKEGEAR,_INTL("Pokégear"),"menuPokegear",proc{|menu|
  402. scene = PokemonPokegear_Scene.new
  403. screen = PokemonPokegearScreen.new(scene)
  404. pbFadeOutIn(99999) {
  405. screen.pbStartScreen
  406. }
  407. },proc{ return true })
  408. # Trainer Card
  409. MenuHandlers.addEntry(:TRAINER,_INTL("\\pn"),"menuTrainer",proc{|menu|
  410. scene = PokemonTrainerCard_Scene.new
  411. screen = PokemonTrainerCardScreen.new(scene)
  412. pbFadeOutIn(99999) {
  413. screen.pbStartScreen
  414. }
  415. },proc{ return true })
  416. # Save Screen
  417. MenuHandlers.addEntry(:SAVE,_INTL("Save"),"menuSave",proc{|menu|
  418. scene = PokemonSave_Scene.new
  419. screen = PokemonSaveScreen.new(scene)
  420. menu.pbEndScene
  421. menu.endscene = false
  422. if screen.pbSaveScreen
  423. menu.close = true
  424. else
  425. menu.pbStartScene
  426. menu.pbShowMenu
  427. menu.close = false
  428. end
  429. },proc{ return !$game_system || !$game_system.save_disabled && !(pbInSafari? || pbInBugContest?)})
  430. # Quit Safari-Zone
  431. MenuHandlers.addEntry(:QUIT,_INTL("\\contest"),"menuQuit",proc{|menu|
  432. if pbInSafari?
  433. if Kernel.pbConfirmMessage(_INTL("Would you like to leave the Safari Game right now?"))
  434. menu.pbEndScene
  435. menu.endscene = false
  436. menu.close = true
  437. pbSafariState.decision=1
  438. pbSafariState.pbGoToStart
  439. end
  440. else
  441. if Kernel.pbConfirmMessage(_INTL("Would you like to end the Contest now?"))
  442. menu.pbEndScene
  443. menu.endscene = false
  444. menu.close = true
  445. pbBugContestState.pbStartJudging
  446. return
  447. end
  448. end
  449. },proc{ return pbInSafari? || pbInBugContest? })
  450. # Options Screen
  451. MenuHandlers.addEntry(:OPTIONS,_INTL("Options"),"menuOptions",proc{|menu|
  452. scene = PokemonOption_Scene.new
  453. screen = PokemonOptionScreen.new(scene)
  454. pbFadeOutIn(99999) {
  455. screen.pbStartScreen
  456. pbUpdateSceneMap
  457. }
  458. },proc{ return true })
  459. # Debug Menu
  460. MenuHandlers.addEntry(:DEBUG,_INTL("Debug"),"menuDebug",proc{|menu|
  461. pbFadeOutIn(99999) {
  462. pbDebugMenu
  463. menu.refresh
  464. }
  465. },proc{ return $DEBUG })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement