Advertisement
M3rein

Pokétch_Main

Oct 17th, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.43 KB | None | 0 0
  1. #==============================================================================#
  2. #                  Pokétch for Pokémon Essentials v16.X | v17.X                #
  3. #                                     v1.0                                     #
  4. #                                                                              #
  5. #                                   by Marin                                   #
  6. #==============================================================================#
  7. #                               Dual-screen usage                              #
  8. #                                                                              #
  9. #               Double DEFAULTSCREENHEIGHT (usually 384; 384 * 2 = 768)        #
  10. #                            Set DUAL_SCREEN to true                           #
  11. #                              Set POKETCH_Y to 384                            #
  12. #                    Make sure NO_POKETCH_BACKGROUND has a value               #
  13. #                                                                              #
  14. #      This Dual-screen script has most likely messed up your battle scene     #
  15. #      You will have to do some repositioning in PokeBattle_SceneConstants     #
  16. #                                                                              #
  17. #      To give or take the Pokétch, use pbObtainPoketch and pbTakePoketch      #
  18. #==============================================================================#
  19. #                              Single-screen usage                             #
  20. #                                                                              #
  21. #            Set DEFAULTSCREENHEIGHT to 384 or whatever height you want        #
  22. #                             Set DUAL_SCREEN to false                         #
  23. #                                Set POKETCH_Y to 0                            #
  24. #                                                                              #
  25. #                       To call the Pokétch, use pbPoketch                     #
  26. #              You can use this method to call it from other menus             #
  27. #==============================================================================#
  28. #                                     Apps                                     #
  29. #                                                                              #
  30. #     To enable or disable an app, use pbEnableApp(id) or pbDisableApp(id)     #
  31. #        To enable or disable all apps, use pbEnableAll or pbDisableAll        #
  32. #        To determine if an app is enabled or not, use pbAppEnabled?(id)       #
  33. #                                                                              #
  34. #    To get the ID of an app, you could do, say, "PoketchApps::PoketchRotom"   #
  35. #           This will get you the ID of an app called "PoketchRotom"           #
  36. #                                                                              #
  37. #                                    Alternative:                              #
  38. #                    Scroll to the bottom of Pokétch_Apps.                     #
  39. #           You'll see a module with the number before the app.                #
  40. #                                                                              #
  41. #      If you want to change the Pokétch to a specific app, you can use        #
  42. #                             pbChangeApp(app_id)                              #
  43. #                This method bypasses usability and availability.              #
  44. #==============================================================================#
  45. #                              Making your own apps                            #
  46. #                                                                              #
  47. # The top of Pokétch_Apps contains a small tutorial as to how to make your own #
  48. #                                     apps.                                    #
  49. #                                                                              #
  50. #    Did you successfully make your own app? Feel free to share it in the      #
  51. #            PokéCommunity or RelicCastle thread for others to use!            #
  52. #==============================================================================#
  53.  
  54.  
  55.  
  56. # Set this to false if you don't want two screens. You'll also have to set
  57. # DEFAULTSCREENHEIGHT to 384.
  58. DUAL_SCREEN = true
  59.  
  60. # If you want this Pokétch to be on a single screen or elsewhere on the screen,
  61. # You'll likely want to set this value to 0. If not, set it to 384.
  62. POKETCH_Y = 384
  63.  
  64. # If you don't have the Pokétch, this is the image that will be displayed instead
  65. # (because it's not ideal to have just a black screen) (DUAL_SCREEN ONLY)
  66. NO_POKETCH_BACKGROUND = "Graphics/Pictures/Poketch/background"
  67.  
  68.  
  69.  
  70. $Poketch = nil if $Poketch # F12 soft reset fix
  71. $no_poketch_bg = nil if $no_poketch_bg # F12 soft reset fix
  72.  
  73. def pbPoketch # (NON-DUAL_SCREEN ONLY)
  74.   return if $Poketch
  75.   $Poketch = Poketch.new
  76.   $Poketch.show
  77.   if $Poketch.app
  78.     $Poketch.run_app
  79.     $Poketch.hideOverlay
  80.   end
  81.   loop do
  82.     Graphics.update
  83.     Input.update
  84.     $Poketch.update
  85.     break if Input.trigger?(Input::B)
  86.   end
  87.   if $Poketch.app
  88.     $Poketch.showOverlay(proc { $Poketch.app.dispose } )
  89.     24.times { Graphics.update; Input.update; $Poketch.update }
  90.   end
  91.   $Poketch.hide
  92.   $Poketch.dispose
  93.   $Poketch = nil
  94. end
  95.  
  96. def pbChangeApp(id)
  97.   $Poketch.changeApp(id)
  98. end
  99.  
  100. # Give the Pokétch (DUAL_SCREEN ONLY)
  101. def pbObtainPoketch(animate = true)
  102.   return if $Poketch
  103.   $Trainer.poketch = true
  104.   $Poketch = Poketch.new
  105.   $Poketch.show(animate)
  106.   if $Poketch.app
  107.     $Poketch.run_app
  108.     $Poketch.hideOverlay
  109.   end
  110.   $no_poketch_bg.dispose if $no_poketch_bg
  111. end
  112.  
  113. # Take away the Pokétch (DUAL_SCREEN ONLY)
  114. def pbTakePoketch(animate = true)
  115.   return if !$Poketch
  116.   if $Poketch.app
  117.     $Poketch.showOverlay(proc { $Poketch.app.dispose } )
  118.     24.times { Graphics.update; Input.update; $Poketch.update }
  119.   end
  120.   make_background
  121.   $Poketch.hide(animate)
  122.   $Poketch.dispose
  123.   $Poketch = nil
  124.   $Trainer.poketch = false
  125. end
  126.  
  127. def pbEnableAll
  128.   for const in PoketchApps.constants
  129.     key = appID(const)
  130.     $Trainer.poketch_app_access << key if !$Trainer.poketch_app_access.include?(key)
  131.   end
  132.   $Poketch.refresh
  133. end
  134.  
  135. def pbDisableAll
  136.   $Trainer.poketch_app_access.clear
  137.   $Poketch.refresh
  138. end
  139.  
  140. def pbEnableApp(id)
  141.   $Trainer.poketch_app_access << id if !$Trainer.poketch_app_access.include?(id)
  142.   $Poketch.refresh
  143. end
  144.  
  145. def pbDisableApp(id)
  146.   $Trainer.poketch_app_access.delete(id)
  147.   $Poketch.refresh
  148. end
  149.  
  150. def pbAppEnabled?(id)
  151.   return $Trainer.poketch_app_access.include?(id)
  152. end
  153.  
  154. class Poketch
  155.   attr_accessor :app
  156.   attr_accessor :apps
  157.   attr_accessor :updated_frame
  158.  
  159.   def initialize
  160.     @viewport = Viewport.new(0,POKETCH_Y,Graphics.width,Graphics.height)
  161.     @viewport.z = 99998
  162.     @viewport2 = Viewport.new(0,POKETCH_Y,Graphics.width,Graphics.height)
  163.     @viewport2.z = 100000
  164.     @overlay = Sprite.new(@viewport2)
  165.     @overlay.x = 32
  166.     @overlay.y = 32
  167.     @poketch = Sprite.new(@viewport)
  168.     @poketch.bmp("Graphics/Pictures/Poketch/poketch#{["Male","Female"][$Trainer.gender]}")
  169.     @btnUp = Sprite.new(@viewport)
  170.     @btnUp.bmp("Graphics/Pictures/Poketch/btnUp")
  171.     @btnUp.x = 448
  172.     @btnUp.y = 66
  173.     @btnDown = Sprite.new(@viewport)
  174.     @btnDown.bmp("Graphics/Pictures/Poketch/btnDown")
  175.     @btnDown.x = 448
  176.     @btnDown.y = 191
  177.     @transUp = Sprite.new(@viewport2)
  178.     @transUp.bmp("Graphics/Pictures/Poketch/transition")
  179.     @transUp.x = 32
  180.     @transUp.y = 32
  181.     @transUp.zoom_y = 160
  182.     @transUp.opacity = 0
  183.     @transUp.z = 1
  184.     @transDown = Sprite.new(@viewport2)
  185.     @transDown.bmp("Graphics/Pictures/Poketch/transition")
  186.     @transDown.x = 32
  187.     @transDown.y = 352
  188.     @transDown.zoom_y = 160
  189.     @transDown.oy = @transDown.bitmap.height
  190.     @transDown.opacity = 0
  191.     @transDown.z = 1
  192.     @i = 0
  193.     @proc = nil
  194.     @showOverlay = false
  195.     @hideOverlay = false
  196.     hide(false)
  197.     @transUp.zoom_y = 170
  198.     @transDown.zoom_y = 170
  199.     @sel = 0
  200.     sort_apps
  201.     if $Trainer.poketch_last_app
  202.       if @apps[$Trainer.poketch_last_app]
  203.         @sel = $Trainer.poketch_last_app
  204.       end
  205.     end
  206.     @app = @apps[@sel] if @apps[@sel]
  207.     if !$Trainer.poketch_color || $Trainer.poketch_color == 0
  208.       no_color
  209.     else
  210.       set_color("Graphics/Pictures/Poketch/Color Changer/overlay#{$Trainer.poketch_color}")
  211.     end
  212.   end
  213.  
  214.   def show(animate = true)
  215.     unless @poketch.opacity >= 255
  216.       for i in 0...25
  217.         if animate
  218.           Graphics.update
  219.           Input.update
  220.         end
  221.         @poketch.opacity += 256 / 24.0
  222.         @btnUp.opacity += 256 / 24.0
  223.         @btnDown.opacity += 256 / 24.0
  224.         @transUp.opacity += 256 / 23.0
  225.         @transDown.opacity += 256 / 23.0
  226.       end
  227.       @transDown.zoom_y = 160
  228.       @transUp.zoom_y = 160
  229.       showOverlay
  230.     end
  231.   end
  232.  
  233.   def hide(animate = true)
  234.     unless @poketch.opacity == 0
  235.       for i in 0...25
  236.         if animate
  237.           Graphics.update
  238.           Input.update
  239.         end
  240.         @poketch.opacity -= 256 / 24.0
  241.         @btnUp.opacity -= 256 / 24.0
  242.         @btnDown.opacity -= 256 / 24.0
  243.         @transUp.opacity -= 256 / 24.0
  244.         @transDown.opacity -= 256 / 24.0
  245.       end
  246.     end
  247.   end
  248.  
  249.   def showOverlay(proc = nil)
  250.     @showOverlay = true
  251.     @proc = proc
  252.   end
  253.  
  254.   def hideOverlay(proc = nil)
  255.     @hideOverlay = true
  256.     @proc = proc
  257.   end
  258.  
  259.   def sort_apps
  260.     @apps = {}
  261.     for const in PoketchApps.constants
  262.       key = appID(const)
  263.       cls = eval(const.to_s)
  264.       @apps[key] = cls if pbAppEnabled?(key) && cls.usable?
  265.     end
  266.   end
  267.  
  268.   def refresh
  269.     sort_apps
  270.     @app.refresh if @app.respond_to?("refresh")
  271.     if @apps.size == 0
  272.       showOverlay
  273.       @proc = proc { @app.dispose if @app && @app.respond_to?("dispose") }
  274.     else
  275.       if !@app
  276.         for const in PoketchApps.constants
  277.           key = appID(const)
  278.           if @apps[key]
  279.             @sel = key
  280.             break
  281.           end
  282.         end
  283.         run_app
  284.         hideOverlay
  285.       else
  286.         if !@apps.map { |app| app[1] }.include?(@app.class)
  287.           showOverlay
  288.           @proc = proc do
  289.             @app.dispose if @app.respond_to?("dispose")
  290.             move_up
  291.             run_app
  292.             hideOverlay
  293.           end
  294.         end
  295.       end
  296.     end
  297.   end
  298.  
  299.   def run_app
  300.     @app = @apps[@sel].new if @apps[@sel]
  301.   end
  302.  
  303.   def update
  304.     if @showOverlay
  305.       if @transUp.zoom_y != 160
  306.         @transUp.zoom_y += 10
  307.         @transDown.zoom_y += 10
  308.       end
  309.       @i += 1
  310.       if @i == 6
  311.         @btnDown.bmp("Graphics/Pictures/Poketch/btnDown")
  312.         @btnUp.bmp("Graphics/Pictures/Poketch/btnUp")
  313.       end
  314.       if @i == 24
  315.         @showOverlay = false
  316.         @proc.call if @proc
  317.         @proc = nil
  318.         @i = 0
  319.       end
  320.       return
  321.     end
  322.     if @hideOverlay
  323.       if @transUp.zoom_y != 0
  324.         @transUp.zoom_y -= 10
  325.         @transDown.zoom_y -= 10
  326.       end
  327.       @i += 1
  328.       if @i == 6
  329.         @btnDown.bmp("Graphics/Pictures/Poketch/btnDown")
  330.         @btnUp.bmp("Graphics/Pictures/Poketch/btnUp")
  331.       end
  332.       if @i == 16
  333.         @hideOverlay = false
  334.         @proc.call if @proc
  335.         @proc = nil
  336.         @i = 0
  337.       end
  338.       return
  339.     end
  340.     @app.update if @app.respond_to?("update")
  341.     return if @apps.size == 0
  342.     if $mouse && $mouse.click?(@btnUp)
  343.       click_up
  344.     end
  345.     if $mouse && $mouse.click?(@btnDown)
  346.       click_down
  347.     end
  348.   end
  349.  
  350.   # Change the app to something else. Bypasses usability/availability.
  351.   def changeApp(id)
  352.     @sel = id
  353.     refresh
  354.     showOverlay
  355.     @proc = proc do
  356.       @app.dispose if @app && @app.respond_to?("dispose")
  357.       run_app
  358.       $Trainer.poketch_last_app = @sel
  359.       hideOverlay
  360.     end
  361.   end
  362.  
  363.   # For the Itemfinder/Notepad to be able to read these buttons.
  364.   attr_reader :btnUp
  365.   attr_reader :btnDown
  366.  
  367.   def click_up(animate = true)
  368.     @btnUp.bmp("Graphics/Pictures/Poketch/btnUpClick") if animate
  369.     refresh
  370.     showOverlay
  371.     @proc = proc do
  372.       @app.dispose if @app && @app.respond_to?("dispose")
  373.       move_up
  374.       run_app
  375.       $Trainer.poketch_last_app = @sel
  376.       hideOverlay
  377.     end
  378.   end
  379.  
  380.   def click_down(animate = true)
  381.     @btnDown.bmp("Graphics/Pictures/Poketch/btnDownClick") if animate
  382.     refresh
  383.     showOverlay
  384.     @proc = proc do
  385.       @app.dispose if @app && @app.respond_to?("dispose")
  386.       move_down
  387.       run_app
  388.       $Trainer.poketch_last_app = @sel
  389.       hideOverlay
  390.     end
  391.   end
  392.  
  393.   def move_up
  394.     s = false
  395.     i = @sel
  396.     if @apps.size > 1
  397.       while !s
  398.         i += 1
  399.         if @apps[i]
  400.           s = true
  401.           @sel = i
  402.         end
  403.         if i >= PoketchApps.constants.size
  404.           i = -1
  405.         end
  406.       end
  407.     end
  408.   end
  409.  
  410.   def move_down
  411.     s = false
  412.     i = @sel
  413.     if @apps.size > 1
  414.       while !s
  415.         i -= 1
  416.         if @apps[i]
  417.           s = true
  418.           @sel = i
  419.         end
  420.         if i < 0
  421.           i = PoketchApps.constants.size
  422.         end
  423.       end
  424.     end
  425.   end
  426.  
  427.   def set_color(path)
  428.     @overlay.bmp(path)
  429.   end
  430.  
  431.   def no_color
  432.     @overlay.bitmap = nil
  433.   end
  434.  
  435.   def dispose
  436.     showOverlay
  437.     @proc = proc do
  438.       @app.dispose if @app && @app.respond_to?("dispose")
  439.     end
  440.     @poketch.dispose
  441.     @btnUp.dispose
  442.     @btnDown.dispose
  443.     @transUp.dispose
  444.     @transDown.dispose
  445.     $Poketch = nil
  446.   end
  447. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement