Advertisement
M3rein

Pokétch_Main

Oct 19th, 2017
1,200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.73 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 = false
  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 = 0
  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. end
  94.  
  95. def pbChangeApp(id)
  96.   return if $Poketch
  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.   pbEnableApp(PoketchApps::PoketchClock)
  105.   pbEnableApp(PoketchApps::PoketchClicker)
  106.   pbEnableApp(PoketchApps::PoketchCalculator)
  107.   pbEnableApp(PoketchApps::PoketchAnalogWatch)
  108.   $Poketch = Poketch.new
  109.   $Poketch.show(animate)
  110.   if $Poketch.app
  111.     $Poketch.run_app
  112.     $Poketch.hideOverlay
  113.   end
  114.   $no_poketch_bg.dispose if $no_poketch_bg
  115. end
  116.  
  117. # Take away the Pokétch (DUAL_SCREEN ONLY)
  118. def pbTakePoketch(animate = true)
  119.   return if !$Poketch
  120.   if $Poketch.app
  121.     $Poketch.showOverlay(proc { $Poketch.app.dispose } )
  122.     24.times { Graphics.update; Input.update; $Poketch.update }
  123.   end
  124.   make_background
  125.   $Poketch.hide(animate)
  126.   $Poketch.dispose
  127.   $Poketch = nil
  128.   $Trainer.poketch = false
  129. end
  130.  
  131. def pbEnableAll
  132.   for const in PoketchApps.constants
  133.     key = appID(const)
  134.     $Trainer.poketch_app_access << key if !$Trainer.poketch_app_access.include?(key)
  135.   end
  136.   $Poketch.refresh if $Poketch
  137. end
  138.  
  139. def pbDisableAll
  140.   $Trainer.poketch_app_access.clear
  141.   $Poketch.refresh if $Poketch
  142. end
  143.  
  144. def pbEnableApp(id)
  145.   $Trainer.poketch_app_access << id if !$Trainer.poketch_app_access.include?(id)
  146.   $Poketch.refresh if $Poketch
  147. end
  148.  
  149. def pbDisableApp(id)
  150.   $Trainer.poketch_app_access.delete(id)
  151.   $Poketch.refresh if $Poketch
  152. end
  153.  
  154. def pbAppEnabled?(id)
  155.   return $Trainer.poketch_app_access.include?(id)
  156. end
  157.  
  158. class Poketch
  159.   attr_accessor :app
  160.   attr_accessor :apps
  161.   attr_accessor :updated_frame
  162.  
  163.   def initialize
  164.     @viewport = Viewport.new(0,POKETCH_Y,Graphics.width,Graphics.height)
  165.     @viewport.z = 99998
  166.     @viewport2 = Viewport.new(0,POKETCH_Y,Graphics.width,Graphics.height)
  167.     @viewport2.z = 100000
  168.     @overlay = Sprite.new(@viewport2)
  169.     @overlay.x = 32
  170.     @overlay.y = 32
  171.     @poketch = Sprite.new(@viewport)
  172.     @poketch.bmp("Graphics/Pictures/Poketch/poketch#{["Male","Female"][$Trainer.gender]}")
  173.     @btnUp = Sprite.new(@viewport)
  174.     @btnUp.bmp("Graphics/Pictures/Poketch/btnUp")
  175.     @btnUp.x = 448
  176.     @btnUp.y = 66
  177.     @btnDown = Sprite.new(@viewport)
  178.     @btnDown.bmp("Graphics/Pictures/Poketch/btnDown")
  179.     @btnDown.x = 448
  180.     @btnDown.y = 191
  181.     @transUp = Sprite.new(@viewport2)
  182.     @transUp.bmp("Graphics/Pictures/Poketch/transition")
  183.     @transUp.x = 32
  184.     @transUp.y = 32
  185.     @transUp.zoom_y = 160
  186.     @transUp.opacity = 0
  187.     @transUp.z = 1
  188.     @transDown = Sprite.new(@viewport2)
  189.     @transDown.bmp("Graphics/Pictures/Poketch/transition")
  190.     @transDown.x = 32
  191.     @transDown.y = 352
  192.     @transDown.zoom_y = 160
  193.     @transDown.oy = @transDown.bitmap.height
  194.     @transDown.opacity = 0
  195.     @transDown.z = 1
  196.     @i = 0
  197.     @proc = nil
  198.     @showOverlay = false
  199.     @hideOverlay = false
  200.     hide(false)
  201.     @transUp.zoom_y = 170
  202.     @transDown.zoom_y = 170
  203.     @sel = 0
  204.     sort_apps
  205.     if $Trainer.poketch_last_app
  206.       if @apps[$Trainer.poketch_last_app]
  207.         @sel = $Trainer.poketch_last_app
  208.       end
  209.     end
  210.     @app = @apps[@sel] if @apps[@sel]
  211.     if !$Trainer.poketch_color || $Trainer.poketch_color == 0
  212.       no_color
  213.     else
  214.       set_color("Graphics/Pictures/Poketch/Color Changer/overlay#{$Trainer.poketch_color}")
  215.     end
  216.   end
  217.  
  218.   def show(animate = true)
  219.     unless @poketch.opacity >= 255
  220.       for i in 0...25
  221.         if animate
  222.           Graphics.update
  223.           Input.update
  224.         end
  225.         @poketch.opacity += 256 / 24.0
  226.         @btnUp.opacity += 256 / 24.0
  227.         @btnDown.opacity += 256 / 24.0
  228.         @transUp.opacity += 256 / 23.0
  229.         @transDown.opacity += 256 / 23.0
  230.       end
  231.       @transDown.zoom_y = 160
  232.       @transUp.zoom_y = 160
  233.       showOverlay
  234.     end
  235.   end
  236.  
  237.   def hide(animate = true)
  238.     unless @poketch.opacity == 0
  239.       for i in 0...25
  240.         if animate
  241.           Graphics.update
  242.           Input.update
  243.         end
  244.         @poketch.opacity -= 256 / 24.0
  245.         @btnUp.opacity -= 256 / 24.0
  246.         @btnDown.opacity -= 256 / 24.0
  247.         @transUp.opacity -= 256 / 24.0
  248.         @transDown.opacity -= 256 / 24.0
  249.       end
  250.     end
  251.   end
  252.  
  253.   def showOverlay(proc = nil)
  254.     @showOverlay = true
  255.     @proc = proc
  256.   end
  257.  
  258.   def hideOverlay(proc = nil)
  259.     @hideOverlay = true
  260.     @proc = proc
  261.   end
  262.  
  263.   def sort_apps
  264.     @apps = {}
  265.     for const in PoketchApps.constants
  266.       key = appID(const)
  267.       cls = eval(const.to_s)
  268.       @apps[key] = cls if pbAppEnabled?(key) && cls.usable?
  269.     end
  270.   end
  271.  
  272.   def refresh
  273.     sort_apps
  274.     @app.refresh if @app.respond_to?("refresh")
  275.     if @apps.size == 0
  276.       showOverlay
  277.       @proc = proc { @app.dispose if @app && @app.respond_to?("dispose") }
  278.     else
  279.       if !@app
  280.         for const in PoketchApps.constants
  281.           key = appID(const)
  282.           if @apps[key]
  283.             @sel = key
  284.             break
  285.           end
  286.         end
  287.         run_app
  288.         hideOverlay
  289.       else
  290.         if !@apps.map { |app| app[1] }.include?(@app.class)
  291.           showOverlay
  292.           @proc = proc do
  293.             @app.dispose if @app.respond_to?("dispose")
  294.             move_up
  295.             run_app
  296.             hideOverlay
  297.           end
  298.         end
  299.       end
  300.     end
  301.   end
  302.  
  303.   def run_app
  304.     @app = @apps[@sel].new if @apps[@sel]
  305.   end
  306.  
  307.   def update
  308.     if @showOverlay
  309.       if @transUp.zoom_y != 160
  310.         @transUp.zoom_y += 10
  311.         @transDown.zoom_y += 10
  312.       end
  313.       @i += 1
  314.       if @i == 6
  315.         @btnDown.bmp("Graphics/Pictures/Poketch/btnDown")
  316.         @btnUp.bmp("Graphics/Pictures/Poketch/btnUp")
  317.       end
  318.       if @i == 24
  319.         @showOverlay = false
  320.         @proc.call if @proc
  321.         @proc = nil
  322.         @i = 0
  323.       end
  324.       return
  325.     end
  326.     if @hideOverlay
  327.       if @transUp.zoom_y != 0
  328.         @transUp.zoom_y -= 10
  329.         @transDown.zoom_y -= 10
  330.       end
  331.       @i += 1
  332.       if @i == 6
  333.         @btnDown.bmp("Graphics/Pictures/Poketch/btnDown")
  334.         @btnUp.bmp("Graphics/Pictures/Poketch/btnUp")
  335.       end
  336.       if @i == 16
  337.         @hideOverlay = false
  338.         @proc.call if @proc
  339.         @proc = nil
  340.         @i = 0
  341.       end
  342.       return
  343.     end
  344.     @app.update if @app.respond_to?("update")
  345.     return if @apps.size == 0
  346.     if $mouse && $mouse.click?(@btnUp)
  347.       click_up
  348.     end
  349.     if $mouse && $mouse.click?(@btnDown)
  350.       click_down
  351.     end
  352.   end
  353.  
  354.   # Change the app to something else. Bypasses usability/availability.
  355.   def changeApp(id)
  356.     @sel = id
  357.     refresh
  358.     showOverlay
  359.     @proc = proc do
  360.       @app.dispose if @app && @app.respond_to?("dispose")
  361.       run_app
  362.       $Trainer.poketch_last_app = @sel
  363.       hideOverlay
  364.     end
  365.   end
  366.  
  367.   # For the Itemfinder/Notepad to be able to read these buttons.
  368.   attr_reader :btnUp
  369.   attr_reader :btnDown
  370.  
  371.   def click_up(animate = true)
  372.     @btnUp.bmp("Graphics/Pictures/Poketch/btnUpClick") if animate
  373.     refresh
  374.     showOverlay
  375.     @proc = proc do
  376.       @app.dispose if @app && @app.respond_to?("dispose")
  377.       move_up
  378.       run_app
  379.       $Trainer.poketch_last_app = @sel
  380.       hideOverlay
  381.     end
  382.   end
  383.  
  384.   def click_down(animate = true)
  385.     @btnDown.bmp("Graphics/Pictures/Poketch/btnDownClick") if animate
  386.     refresh
  387.     showOverlay
  388.     @proc = proc do
  389.       @app.dispose if @app && @app.respond_to?("dispose")
  390.       move_down
  391.       run_app
  392.       $Trainer.poketch_last_app = @sel
  393.       hideOverlay
  394.     end
  395.   end
  396.  
  397.   def move_up
  398.     s = false
  399.     i = @sel
  400.     if @apps.size > 1
  401.       while !s
  402.         i += 1
  403.         if @apps[i]
  404.           s = true
  405.           @sel = i
  406.         end
  407.         if i >= PoketchApps.constants.size
  408.           i = -1
  409.         end
  410.       end
  411.     end
  412.   end
  413.  
  414.   def move_down
  415.     s = false
  416.     i = @sel
  417.     if @apps.size > 1
  418.       while !s
  419.         i -= 1
  420.         if @apps[i]
  421.           s = true
  422.           @sel = i
  423.         end
  424.         if i < 0
  425.           i = PoketchApps.constants.size
  426.         end
  427.       end
  428.     end
  429.   end
  430.  
  431.   def set_color(path)
  432.     @overlay.bmp(path)
  433.   end
  434.  
  435.   def no_color
  436.     @overlay.bitmap = nil
  437.   end
  438.  
  439.   def dispose
  440.     showOverlay
  441.     @proc = proc do
  442.       @app.dispose if @app && @app.respond_to?("dispose")
  443.     end
  444.     @poketch.dispose
  445.     @btnUp.dispose
  446.     @btnDown.dispose
  447.     @transUp.dispose
  448.     @transDown.dispose
  449.     $Poketch = nil
  450.   end
  451. end
  452. # Do not change.
  453. ERRORTEXT += "[Pokétch v1.0]\r\n" if defined?(ERRORTEXT)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement