daily pastebin goal
28%
SHARE
TWEET

Pokétch_Apps

M3rein Oct 17th, 2017 (edited) 436 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # WARNING: RPG.Net is a bit buggy. You may get "RGSS Player stopped working"
  2. # when using an app that uses RPG.Net. I can sadly not do anything about this.
  3.  
  4.  
  5. # Process of creating your own application:
  6. #  -> Create the class
  7. #  -> Make sure it inherits from "PoketchApp"
  8. #  -> "Register" the app in the PoketchApps module by adding a unique ID and
  9. #     the classname.
  10.  
  11.  
  12. # Why to inherit PoketchApp and call "super" in some methods:
  13.  
  14. # class "PoketchApp"'s intention is to make your code as small as possible.
  15. # It will make you an @bg sprite and an @viewport if you call "super" in
  16. # the constructor of your class (def initialize). Make sure to call this first.
  17. # It will also handle "def click?", which is a method that handles normal
  18. # button clicks. To use, make sure to call "super" in the update method of your
  19. # class (def update).
  20. # To make sure everything (including the actual $Poketch.app), @bg, and @viewport
  21. # disposes correctly, call "super" LAST in your dispose method (def dispose).
  22.  
  23.  
  24. # If you only want the app to be available under certain circumstances (ON TOP OF
  25. # THE APP ENABLED STATE), you can overwrite "def self.usable?". Apps that need
  26. # RPG.Net to function, for example, have "return RNET".
  27.  
  28.  
  29.  
  30. # Additional Utility: (more can be found in Pokétch_Utility)
  31.  
  32. # <Sprite>.poketch_average: Will average out your sprite's colors to be of the
  33. # same 4 colors the Pokétch originally has. (used for party icons)
  34.  
  35. # pbFormat(integer, digits): Better to show some examples:
  36. #                            -> pbFormat(27,3) # => "027"
  37. #                            -> pbFormat(12,2) # => "12"
  38.  
  39. #==============================================================================#
  40. # Pokétch Clock. Shows the computer's time.                                    #
  41. #==============================================================================#
  42. class PoketchClock < PoketchApp
  43.   def initialize
  44.     super
  45.     @bg.bmp("Graphics/Pictures/Poketch/Clock/background")
  46.     @time = Time.now
  47.     @numbers = []
  48.     draw_time
  49.   end
  50.  
  51.   def update
  52.     if @time.hour != Time.now.hour || @time.min != Time.now.min
  53.       draw_time
  54.       @time = Time.now
  55.     end
  56.   end
  57.  
  58.   def draw_time
  59.     n = pbFormat(@time.hour,2).split("")
  60.     n.concat(pbFormat(@time.min,2).split(""))
  61.     for i in 0...4
  62.       @numbers[i].dispose if @numbers[i]
  63.       @numbers[i] = nil
  64.       @numbers[i] = Sprite.new(@viewport)
  65.       @numbers[i].bmp("Graphics/Pictures/Poketch/Clock/numbers")
  66.       @numbers[i].src_rect.width = 64
  67.       @numbers[i].src_rect.x = n[i].to_i * 64
  68.       @numbers[i].x = [15,97,208,290][i]
  69.       @numbers[i].y = 82
  70.     end
  71.   end
  72.  
  73.   def dispose
  74.     for n in @numbers
  75.       n.dispose
  76.     end
  77.     super
  78.   end
  79. end
  80.  
  81.  
  82. #==============================================================================#
  83. # Pokétch Clicker. Click your heart away.                                      #
  84. #==============================================================================#
  85. class PokemonTemp
  86.   attr_accessor :click_count
  87. end
  88.  
  89. class PoketchClicker < PoketchApp
  90.   def initialize
  91.     super
  92.     @bg.bmp("Graphics/Pictures/Poketch/Clicker/background")
  93.     @numbers = []
  94.     @btn = Sprite.new(@viewport)
  95.     @btn.bmp("Graphics/Pictures/Poketch/Clicker/btn")
  96.     @btn.x = 128
  97.     @btn.y = 166
  98.     $PokemonTemp.click_count = 0 if !$PokemonTemp.click_count
  99.     draw_count
  100.   end
  101.  
  102.   def draw_count
  103.     n = pbFormat($PokemonTemp.click_count, 4).split("")
  104.     for i in 0...4
  105.       @numbers[i].dispose if @numbers[i]
  106.       @numbers[i] = nil
  107.       @numbers[i] = Sprite.new(@viewport)
  108.       @numbers[i].bmp("Graphics/Pictures/Poketch/Clicker/numbers")
  109.       @numbers[i].src_rect.width = 24
  110.       @numbers[i].src_rect.x = n[i].to_i * 24
  111.       @numbers[i].x = 135 + 30 * i
  112.       @numbers[i].y = 68
  113.     end
  114.   end
  115.  
  116.   def update
  117.     super
  118.     if click?(@btn, "Graphics/Pictures/Poketch/Clicker", "btn")
  119.       $PokemonTemp.click_count += 1
  120.       $PokemonTemp.click_count = 0 if $PokemonTemp.click_count > 9999
  121.       draw_count
  122.     end
  123.   end
  124.  
  125.   def dispose
  126.     $PokemonTemp.click_count = 0
  127.     super
  128.   end
  129. end
  130.  
  131.  
  132. #==============================================================================#
  133. # Pokétch Calculator. You can do basic math with this.                         #
  134. #==============================================================================#
  135. class Float
  136.   def round_to(x)
  137.     return (self * 10 ** x).round.to_f / 10 ** x
  138.   end
  139. end
  140.  
  141. # This one's rather complex. Ignore this.
  142. class PoketchCalculator < PoketchApp
  143.   def initialize
  144.     super
  145.     @bg.bmp("Graphics/Pictures/Poketch/Calculator/background")
  146.     @buttons = []
  147.     @buttons[0] = []
  148.     @buttons[0][0] = 0
  149.     @buttons[0][1] = Sprite.new(@viewport)
  150.     @buttons[0][1].bmp("Graphics/Pictures/Poketch/Calculator/btnLarge")
  151.     @buttons[0][1].x = 32
  152.     @buttons[0][1].y = 256
  153.     @buttons[0][2] = Sprite.new(@viewport)
  154.     @buttons[0][2].bmp("Graphics/Pictures/Poketch/Calculator/buttonnumbers")
  155.     @buttons[0][2].src_rect.width = 16
  156.     @buttons[0][2].x = @buttons[0][1].x + 24
  157.     @buttons[0][2].y = @buttons[0][1].y + 16
  158.     for i in 0...9
  159.       @buttons[i+1] = []
  160.       @buttons[i+1][0] = i+1
  161.       @buttons[i+1][1] = Sprite.new(@viewport)
  162.       @buttons[i+1][1].bmp("Graphics/Pictures/Poketch/Calculator/btnSmall")
  163.       @buttons[i+1][1].x = 32 + 64 * (i % 3)
  164.       @buttons[i+1][1].y = 192 - 64 * (i / 3).floor
  165.       @buttons[i+1][2] = Sprite.new(@viewport)
  166.       @buttons[i+1][2].bmp("Graphics/Pictures/Poketch/Calculator/buttonnumbers")
  167.       @buttons[i+1][2].src_rect.width = 16
  168.       @buttons[i+1][2].src_rect.x = 16 * (i + 1)
  169.       @buttons[i+1][2].x = @buttons[i+1][1].x + 24
  170.       @buttons[i+1][2].y = @buttons[i+1][1].y + 16
  171.     end
  172.     @operators = []
  173.     for i in 0...6
  174.       @operators[i] = []
  175.       @operators[i][0] = ["+","-","*","/","=","."][i]
  176.       @operators[i][1] = Sprite.new(@viewport)
  177.       @operators[i][1].bmp("Graphics/Pictures/Poketch/Calculator/btn#{i == 4 ? "Large" : "Small"}")
  178.       @operators[i][1].x = [224,288][i % 2]
  179.       @operators[i][1].y = 128 + 64 * (i / 2).floor
  180.       @operators[i][1].x = 160 if i == 5
  181.       @operators[i][1].y = 256 if i == 5
  182.       @operators[i][2] = Sprite.new(@viewport)
  183.       @operators[i][2].bmp("Graphics/Pictures/Poketch/Calculator/operators")
  184.       @operators[i][2].src_rect.width = 24
  185.       @operators[i][2].src_rect.x = i * 24
  186.       @operators[i][2].x = @operators[i][1].x + 17
  187.       @operators[i][2].y = @operators[i][1].y + 14
  188.     end
  189.     @cbtn = []
  190.     @cbtn[0] = nil
  191.     @cbtn[1] = Sprite.new(@viewport)
  192.     @cbtn[1].bmp("Graphics/Pictures/Poketch/Calculator/btnLarge")
  193.     @cbtn[1].x = 224
  194.     @cbtn[1].y = 64
  195.     @cbtn[2] = Sprite.new(@viewport)
  196.     @cbtn[2].bmp("Graphics/Pictures/Poketch/Calculator/cbtn")
  197.     @cbtn[2].x = @cbtn[1].x + 19
  198.     @cbtn[2].y = @cbtn[1].y + 16
  199.    
  200.     @activeoperator = []
  201.     @activeoperator[0] = nil
  202.     @activeoperator[1] = Sprite.new(@viewport)
  203.     @activeoperator[1].x = 20
  204.     @activeoperator[1].y = 18
  205.    
  206.     @activenums = []
  207.     for i in 0...10
  208.       @activenums[i] = []
  209.       @activenums[i][0] = nil
  210.       @activenums[i][1] = Sprite.new(@viewport)
  211.       @activenums[i][1].bmp("Graphics/Pictures/Poketch/Calculator/empty")
  212.       @activenums[i][1].x = 344 - 32 * i
  213.       @activenums[i][1].y = 18
  214.     end
  215.     @old = ""
  216.     @stillactive = false
  217.     @error = false
  218.     @oldop = nil
  219.     @reset_on_next = false
  220.   end
  221.  
  222.   def click?(btn,path,unclicked,clicked=unclicked+"Click")
  223.     return false if !$mouse || !$mouse.click?(btn[1]) || @cooldown > -1
  224.     @tmp = [btn,path,unclicked]
  225.     @tmp[0][1].bmp(@tmp[1]+"/"+clicked)
  226.     @tmp[0][2].y += 12
  227.     @cooldown = 3
  228.     return true
  229.   end
  230.  
  231.   def update
  232.     @cooldown -= 1 if @cooldown > -1
  233.     if @cooldown == 0
  234.       @tmp[0][1].bmp(@tmp[1]+"/"+@tmp[2])
  235.       @tmp[0][2].y -= 12
  236.     end
  237.     for i in 0...@buttons.size
  238.       p = (i == 0 ? "btnLarge" : "btnSmall")
  239.       if click?(@buttons[i],"Graphics/Pictures/Poketch/Calculator",p)
  240.         if @error
  241.           reset_numbers
  242.         end
  243.         if @activeoperator[0] && @stillactive || @reset_on_next
  244.           @stillactive = false
  245.           @old = @activenums.map { |n| n[0] }.join.reverse
  246.           reset_numbers
  247.           @reset_on_next = false
  248.         end
  249.         if !@activenums[9][0]
  250.           @activenums[9][1].dispose
  251.           @activenums[9] = nil
  252.           @activenums.compact!
  253.           for j in 0...@activenums.size
  254.             @activenums[j][1].x -= 32
  255.           end
  256.           n = []
  257.           n[0] = @buttons[i][0]
  258.           n[1] = Sprite.new(@viewport)
  259.           n[1].bmp("Graphics/Pictures/Poketch/Calculator/numbers")
  260.           n[1].src_rect.width = 20
  261.           n[1].src_rect.x = 20 * i
  262.           n[1].x = 344
  263.           n[1].y = 18
  264.           @activenums.insert(0,n)
  265.         end
  266.       end
  267.     end
  268.     for i in 0...@operators.size
  269.       p = (i == 4 ? "btnLarge" : "btnSmall")
  270.       if click?(@operators[i],"Graphics/Pictures/Poketch/Calculator",p)
  271.         if @operators[i][0] == "."
  272.           if !@activenums[9][0]
  273.             @activenums[9][1].dispose
  274.             @activenums[9] = nil
  275.             @activenums.compact!
  276.             for j in 0...@activenums.size
  277.               @activenums[j][1].x -= 32
  278.             end
  279.             n = []
  280.             n[0] = "."
  281.             n[1] = Sprite.new(@viewport)
  282.             n[1].bmp("Graphics/Pictures/Poketch/Calculator/dot")
  283.             n[1].x = 344
  284.             n[1].y = 18
  285.             @activenums.insert(0,n)
  286.             @reset_on_next = false
  287.           end
  288.         elsif @operators[i][0] == "="
  289.           cur = @activenums.map { |n| n[0] }.join.reverse
  290.           if !@old || @old == ""
  291.             return
  292.           end
  293.           ex = nil
  294.           @old = @old.to_f.to_s
  295.           cur = cur.to_f.to_s
  296.           if @activeoperator[0]
  297.             ex = @old + @activeoperator[0] + cur
  298.           else
  299.             ex = cur + @oldop + @old
  300.           end
  301.           if ex.size == 1 || ex.size == 0
  302.             throw_error
  303.             return
  304.           end
  305.           n = (eval(ex) rescue nil)
  306.           if !n
  307.             throw_error
  308.             return
  309.           end
  310.           reset_numbers
  311.           # Some trickery to perform float operations properly, but also cut
  312.           # the .0 if it's a whole numbers (all calculations are done with floats)
  313.           n = n.to_f
  314.           slots = 9 - n.to_s.split('.')[0].size
  315.           n = n.round_to(slots).to_s
  316.           n = n.chomp('.0') if n[n.size - 2..n.size] == '.0'
  317.           n = n.reverse.split("") rescue nil
  318.           if !n || n.size == 0 || n.size > 10
  319.             throw_error
  320.             return
  321.           end
  322.           for j in 0...n.size
  323.             if n[j] == "-"
  324.               @activenums[j][0] = "-"
  325.               @activenums[j][1].bmp("Graphics/Pictures/Poketch/Calculator/operators")
  326.               @activenums[j][1].src_rect.width = 24
  327.               @activenums[j][1].src_rect.x = 24
  328.             elsif n[j] == "."
  329.               @activenums[j][0] = "."
  330.               @activenums[j][1].bmp("Graphics/Pictures/Poketch/Calculator/dot")
  331.             else
  332.               @activenums[j][0] = n[j].to_i
  333.               @activenums[j][1].bmp("Graphics/Pictures/Poketch/Calculator/numbers")
  334.               @activenums[j][1].src_rect.width = 20
  335.               @activenums[j][1].src_rect.x = 20 * n[j].to_i
  336.             end
  337.           end
  338.           @old = cur if @activeoperator[0]
  339.           @oldop = @activeoperator[0] if @activeoperator[0]
  340.           @activeoperator[0] = nil
  341.           @activeoperator[1].bitmap = nil
  342.           @reset_on_next = true
  343.         else
  344.           @activeoperator[0] = @operators[i][0]
  345.           @activeoperator[1].bmp("Graphics/Pictures/Poketch/Calculator/operators")
  346.           @activeoperator[1].src_rect.width = 24
  347.           @activeoperator[1].src_rect.x = 24 * i
  348.           @stillactive = true
  349.           @reset_on_next = false
  350.         end
  351.       end
  352.     end
  353.     if click?(@cbtn,"Graphics/Pictures/Poketch/Calculator","btnLarge")
  354.       reset_numbers
  355.       @old = ""
  356.       @stillactive = false
  357.       @activeoperator[0] = nil
  358.       @activeoperator[1].bitmap = nil
  359.       @oldop = nil
  360.       @error = false
  361.       @reset_on_next = false
  362.     end
  363.   end
  364.  
  365.   def reset_numbers
  366.     for i in 0...10
  367.       @activenums[i][0] = nil
  368.       @activenums[i][1].bmp("Graphics/Pictures/Poketch/Calculator/empty")
  369.     end
  370.   end
  371.  
  372.   def throw_error
  373.     @old = ""
  374.     @stillactive = false
  375.     @activeoperator[0] = nil
  376.     @activeoperator[1].bitmap = nil
  377.     for i in 0...10
  378.       @activenums[i][1].bmp("Graphics/Pictures/Poketch/Calculator/error")
  379.     end
  380.     @error = true
  381.   end
  382.  
  383.   def dispose
  384.     for btn in @buttons
  385.       btn[0] = nil
  386.       btn[1].dispose if btn[1]
  387.       btn[2].dispose if btn[2]
  388.     end
  389.     for op in @operators
  390.       op[0] = nil
  391.       op[1].dispose if op[1]
  392.       op[2].dispose if op[2]
  393.     end
  394.     for n in @activenums
  395.       n[0] = nil
  396.       n[1].dispose if n[1]
  397.       @activeoperator[0] = nil
  398.       @activeoperator[1].dispose if @activeoperator
  399.     end
  400.     @cbtn[0] = nil
  401.     @cbtn[1].dispose if @cbtn[1]
  402.     @cbtn[2].dispose if @cbtn[2]
  403.     @bg.dispose
  404.     super
  405.   end
  406. end
  407.  
  408.  
  409. #==============================================================================#
  410. # Pokétch Item Finder. AKA Dowsing Machine.                                    #
  411. #==============================================================================#
  412. # For an item to be picked up by the Itemfinder, make sure it has ".hidden"
  413. # (without the quotation marks) in the event name.
  414.  
  415. # How you should make your item ball events:
  416. #  -> Kernel.pbItemBall(item)
  417. #  -> Script: pbUnlist(event_id)
  418. #  -> Erase event
  419.  
  420. class Game_Event
  421.   attr_accessor :listed
  422.  
  423.   alias poketch_init initialize
  424.   def initialize(map_id, event, map = nil)
  425.     poketch_init(map_id, event, map)
  426.     @listed = true # Set to true, but whether it's actually listed or not
  427.                    # depends on the name.
  428.   end
  429. end
  430.  
  431. # If you call this on an event, it'll be no longer listed in the Itemfinder
  432. # (if it even was)
  433. def pbUnlist(event_id)
  434.   $game_map.events[event_id].listed = false if $game_map.events[event_id]
  435. end
  436.  
  437. # The Itemfinder will show this event (but still only if it has .hidden in name)
  438. def pbList(event_id)
  439.   $game_map.events[event_id].listed = true if $game_map.events[event_id]
  440. end
  441.  
  442. class PoketchItemFinder < PoketchApp
  443.   def initialize
  444.     super
  445.     @bg.bmp("Graphics/Pictures/Poketch/Item Finder/background")
  446.     @circles = []
  447.     @items = []
  448.   end
  449.  
  450.   def update
  451.     super
  452.     if $mouse && $mouse.inAreaLeftPress?(32,POKETCH_Y+32,384,320) && @cooldown == -1
  453.       @cooldown = 16
  454.       x = $mouse.x - 32
  455.       y = $mouse.y - POKETCH_Y - 32
  456.       if x < 384 && y < 320
  457.         c = Sprite.new(@viewport)
  458.         c.bmp("Graphics/Pictures/Poketch/Item Finder/circle")
  459.         c.ox = c.bitmap.width / 2
  460.         c.oy = c.bitmap.height / 2
  461.         c.x = x
  462.         c.y = y
  463.         c.zoom_x = 0
  464.         c.zoom_y = 0
  465.         @circles << [40, c]
  466.         redraw((x - 11) / 22, (y - 11) / 22)
  467.       end
  468.     end
  469.     for i in 0...@circles.size
  470.       @circles[i][0] -= 1
  471.       @circles[i][1].zoom_x += 0.06
  472.       @circles[i][1].zoom_y += 0.06
  473.       if @circles[i][0] < 16
  474.         @circles[i][1].opacity -= 16
  475.       end
  476.       if @circles[i][0] == 0
  477.         @circles[i][1].dispose
  478.         @circles[i][1] = nil
  479.         @circles[i] = nil
  480.       end
  481.     end
  482.     @circles.compact!
  483.     for i in 0...@items.size
  484.       @items[i][0] -= 1
  485.       @items[i][1].opacity += 255 / (@items[i][0] > 48 ? 16.0 : @items[i][0] < 32 ? -32.0 : 255)
  486.       if @items[i][0] == 0
  487.         @items[i][1].dispose
  488.         @items[i][1] = nil
  489.         @items[i] = nil
  490.       end
  491.     end
  492.     @items.compact!
  493.     $Poketch.click_up if $mouse.click?($Poketch.btnUp)
  494.     $Poketch.click_down if $mouse.click?($Poketch.btnDown)
  495.   end
  496.  
  497.   def redraw(cx, cy)
  498.     for i in 0...@items.size
  499.       @items[i][1].dispose
  500.       @items[i] = nil
  501.     end
  502.     @items.compact!
  503.     for k in $game_map.events.keys
  504.       e = $game_map.events[k]
  505.       # This one line below is the statement that decides if an event should be
  506.       # shown as a dot. The rest is just positioning, locating, and other crap.
  507.       if e.name.include?(".hidden") && e.listed
  508.         if $game_player.x - e.x >= -8 && $game_player.x - e.x <= 8
  509.           if $game_player.y - e.y >= -7 && $game_player.y - e.y <= 7
  510.             x = e.x - $game_player.x + 8
  511.             y = e.y - $game_player.y + 7
  512.             if cx - x >= -5 && cx - x <= 5
  513.               if cy - y >= -4 && cy - y <= 4
  514.                 item = Sprite.new(@viewport)
  515.                 item.bmp("Graphics/Pictures/Poketch/Item Finder/item")
  516.                 item.x = 11 + 22 * x
  517.                 item.y = 11 + 22 * y
  518.                 item.opacity = 0
  519.                 @items << [64, item]
  520.               end
  521.             end
  522.           end
  523.         end
  524.       end
  525.     end
  526.   end
  527.  
  528.   def dispose
  529.     for c in @circles
  530.       c[1].dispose
  531.     end
  532.     for i in @items
  533.       i[1].dispose
  534.     end
  535.     super
  536.   end
  537. end
  538.  
  539.  
  540. #==============================================================================#
  541. # Pokétch Rotom. Tells you things depending on what you predefine.             #
  542. #==============================================================================#
  543. # Normal Rotom Text:
  544. #  Array of message rotom can send by random.
  545.  
  546. # Forced Rotom Text:
  547. #  Array of messages rotom can send by random.
  548. #  If there are any messages in this array, it will always pick from this array.
  549.  
  550. # This will delete all other normal rotom messages.
  551. def pbSetRotomText(array_of_messages)
  552.   array_of_messages = [array_of_messages] if !array_of_messages.is_a?(Array)
  553.   $Trainer.poketch_rotom_text = array_of_messages
  554. end
  555.  
  556. # This will add to all other normal rotom messages.
  557. def pbAddRotomText(text)
  558.   $Trainer.poketch_rotom_text = [] if !$Trainer.poketch_rotom_text
  559.   $Trainer.poketch_rotom_text << text
  560. end
  561.  
  562. # This will delete a message that equals the passed "text" from the normal rotom messages
  563. def pbDeleteRotomText(text)
  564.   $Trainer.poketch_rotom_text = [] if !$Trainer.poketch_rotom_text
  565.   $Trainer.poketch_rotom_text.delete(text) if $Trainer.poketch_rotom_text.include?(text)
  566. end
  567.  
  568. # This will delete all other forced rotom messages
  569. def pbSetForcedRotomText(array_of_message)
  570.   array_of_messages = [array_of_messages] if !array_of_messages.is_a?(Array)
  571.   $Trainer.poketch_rotom_text_forced = array_of_messages
  572. end
  573.  
  574. # This will add to all other forced rotom messages
  575. def pbAddForcedRotomText(text)
  576.   $Trainer.poketch_rotom_text_forced = [] if !$Trainer.poketch_rotom_text_forced
  577.   $Trainer.poketch_rotom_text_forced << text
  578. end
  579.  
  580. # This will delete a message that equals the passed "text" from the forced rotom messages
  581. def pbDeleteForcedRotomText(text)
  582.   $Trainer.poketch_rotom_text_forced = [] if !$Trainer.poketch_rotom_text_forced
  583.   if $Trainer.poketch_rotom_text_forced.include?(text)
  584.     $Trainer.poketch_rotom_text_forced.delete(text)
  585.   end
  586. end
  587.  
  588. class PokeBattle_Trainer
  589.   attr_accessor :poketch_rotom_text
  590.   attr_accessor :poketch_rotom_text_forced
  591.  
  592.   alias poketch_rotom_init initialize
  593.   def initialize(name, trainertype)
  594.     poketch_rotom_init(name, trainertype)
  595.   end
  596. end
  597.  
  598. class PoketchRotom < PoketchApp
  599.   def initialize
  600.     super
  601.     @bg.bmp("Graphics/Pictures/Poketch/Rotom/idle")
  602.     @bg.src_rect.width = 384
  603.     @txtbar = Sprite.new(@viewport)
  604.     @txtbar.bmp("Graphics/Pictures/Poketch/Rotom/speech")
  605.     @txtbar.y = 320
  606.     @txtsprite = Sprite.new(@viewport)
  607.     @txtsprite.bmp(384,320)
  608.     pbSetSystemFont(@txtsprite.bitmap)
  609.     @txtsprite.bitmap.font.size += 10
  610.     if !$Trainer.poketch_rotom_text
  611.       # Default Normal Rotom Text
  612.       $Trainer.poketch_rotom_text = [
  613.         "Bzzt! I'm here to help you out on your journey!",
  614.         "Z-zzt! Where will we go next?"
  615.       ]
  616.     end
  617.     # Default Forced Rotom Text (if you enter anything in here, this will override
  618.     # all messages you wrote in the Normal Rotom Text array).
  619.     if !$Trainer.poketch_rotom_text_forced
  620.       $Trainer.poketch_rotom_text_forced = [
  621. #        "Message here",
  622.       ]
  623.     end
  624.     @txt = nil
  625.     @i = 0
  626.   end
  627.  
  628.   def update
  629.     if $mouse && $mouse.click?(@bg) && @cooldown == -1
  630.       if @draw
  631.         @cooldown = 1
  632.       else
  633.         draw
  634.       end
  635.     end
  636.     if @draw && @txt && @txt.size > 0
  637.       if @i < @txt.size
  638.         @cooldown = 0
  639.         @bg.y -= 4 if @bg.y > -52
  640.         @txtbar.y -= 5 if @txtbar.y > 210
  641.         @txtsprite.bitmap.clear
  642.         pbSetSystemFont(@txtsprite.bitmap)
  643.         @txtsprite.bitmap.font.size += 2
  644.         t = @txt[0..@i].join
  645.         if @txtbar.y <= 220
  646.           @bg.src_rect.x += 384 if @i % 7 == 0
  647.           @bg.src_rect.x = 0 if @bg.src_rect.x >= @bg.bitmap.width
  648.           drawTextEx(@txtsprite.bitmap,14,248,362,2,t,Color.new(16,41,24),
  649.               Color.new(57,82,49))
  650.           @i += 1
  651.         end
  652.       else
  653.         @cooldown = -1
  654.         @txt = nil
  655.         @i = 0
  656.         @bg.src_rect.x = 0
  657.       end
  658.     end
  659.     if @cooldown == 1
  660.       @bg.y += 4 unless @bg.y == 0
  661.       @txtbar.y += 5 unless @txtbar.y == 320
  662.       @txtsprite.y += 5 unless @txtbar.y == 320
  663.       if @txtbar.y == 320
  664.         @draw = false
  665.         @cooldown = -1
  666.         @txtsprite.bitmap.clear
  667.         @txtsprite.y = 0
  668.       end
  669.     end
  670.   end
  671.  
  672.   def draw
  673.     t = []
  674.     if $Trainer.poketch_rotom_text_forced.size > 0
  675.       t = $Trainer.poketch_rotom_text_forced
  676.     else
  677.       t = $Trainer.poketch_rotom_text
  678.     end
  679.     @txt = t[rand(t.size)].split("")
  680.     @draw = true
  681.   end
  682.  
  683.   def dispose
  684.     @txtbar.dispose
  685.     @txtsprite.dispose
  686.     super
  687.   end
  688. end
  689.  
  690.  
  691. #==============================================================================#
  692. # Pokétch Move Tester. Test type effectivenesses.                              #
  693. #==============================================================================#
  694. class PokeBattle_Trainer
  695.   attr_accessor :poketch_move_tester_move
  696.   attr_accessor :poketch_move_tester_type1
  697.   attr_accessor :poketch_move_tester_type2
  698. end
  699.  
  700. class PoketchMoveTester < PoketchApp
  701.   def initialize
  702.     super
  703.     @bg.bmp("Graphics/Pictures/Poketch/Move Tester/background")
  704.     @moveBtnLeft = Sprite.new(@viewport)
  705.     @moveBtnLeft.bmp("Graphics/Pictures/Poketch/Move Tester/btnLeft")
  706.     @moveBtnLeft.y = 191
  707.     @moveBtnRight = Sprite.new(@viewport)
  708.     @moveBtnRight.bmp("Graphics/Pictures/Poketch/Move Tester/btnRight")
  709.     @moveBtnRight.x = 176
  710.     @moveBtnRight.y = 192
  711.     @type1BtnLeft = Sprite.new(@viewport)
  712.     @type1BtnLeft.bmp("Graphics/Pictures/Poketch/Move Tester/btnLeft")
  713.     @type1BtnLeft.x = 160
  714.     @type1BtnLeft.y = 16
  715.     @type1BtnRight = Sprite.new(@viewport)
  716.     @type1BtnRight.bmp("Graphics/Pictures/Poketch/Move Tester/btnRight")
  717.     @type1BtnRight.x = 336
  718.     @type1BtnRight.y = 16
  719.     @type2BtnLeft = Sprite.new(@viewport)
  720.     @type2BtnLeft.bmp("Graphics/Pictures/Poketch/Move Tester/btnLeft")
  721.     @type2BtnLeft.x = 160
  722.     @type2BtnLeft.y = 80
  723.     @type2BtnRight = Sprite.new(@viewport)
  724.     @type2BtnRight.bmp("Graphics/Pictures/Poketch/Move Tester/btnRight")
  725.     @type2BtnRight.x = 336
  726.     @type2BtnRight.y = 80
  727.     @move = $Trainer.poketch_move_tester_move || 0
  728.     @type1 = $Trainer.poketch_move_tester_type1 || 0
  729.     @type2 = $Trainer.poketch_move_tester_type2 || -1
  730.     @txtsprite = Sprite.new(@viewport)
  731.     @txtsprite.bmp(384,320)
  732.     @txt = @txtsprite.bitmap
  733.     @excl = []
  734.     refresh
  735.   end
  736.  
  737.   def update
  738.     super
  739.     if click?(@moveBtnLeft,"Graphics/Pictures/Poketch/Move Tester","btnLeft")
  740.       @move -= 1
  741.       @move = PBTypes.maxValue if @move == -1
  742.       @move -= 1 if PBTypes.isPseudoType?(@move)
  743.       $Trainer.poketch_move_tester_move = @move
  744.       refresh
  745.     end
  746.     if click?(@moveBtnRight,"Graphics/Pictures/Poketch/Move Tester","btnRight")
  747.       @move += 1
  748.       @move = 0 if @move > PBTypes.maxValue
  749.       @move += 1 if PBTypes.isPseudoType?(@move)
  750.       $Trainer.poketch_move_tester_move = @move
  751.       refresh
  752.     end
  753.     if click?(@type1BtnLeft,"Graphics/Pictures/Poketch/Move Tester","btnLeft")
  754.       @type1 -= 1
  755.       @type1 = PBTypes.maxValue if @type1 == -1
  756.       @type1 -= 1 if PBTypes.isPseudoType?(@type1)
  757.       $Trainer.poketch_move_tester_type1 = @type1
  758.       refresh
  759.     end
  760.     if click?(@type1BtnRight,"Graphics/Pictures/Poketch/Move Tester","btnRight")
  761.       @type1 += 1
  762.       @type1 = 0 if @type1 > PBTypes.maxValue
  763.       @type1 += 1 if PBTypes.isPseudoType?(@type1)
  764.       $Trainer.poketch_move_tester_type1 = @type1
  765.       refresh
  766.     end
  767.     if click?(@type2BtnLeft,"Graphics/Pictures/Poketch/Move Tester","btnLeft")
  768.       @type2 -= 1
  769.       if @type2 == -2
  770.         @type2 = PBTypes.maxValue
  771.       elsif PBTypes.isPseudoType?(@type2)
  772.         @type2 -= 1
  773.       end
  774.       $Trainer.poketch_move_tester_type2 = @type2
  775.       refresh
  776.     end
  777.     if click?(@type2BtnRight,"Graphics/Pictures/Poketch/Move Tester","btnRight")
  778.       @type2 += 1
  779.       @type2 = -1 if @type2 > PBTypes.maxValue
  780.       @type2 += 1 if PBTypes.isPseudoType?(@type2)
  781.       $Trainer.poketch_move_tester_type2 = @type2
  782.       refresh
  783.     end
  784.   end
  785.  
  786.   def refresh
  787.     @txt.clear
  788.     pbSetSystemFont(@txt)
  789.     name2 = (@type2 == -1 ? "None" : PBTypes.getName(@type2).upcase)
  790.     pbDrawTextPositions(@txt,[
  791.         [PBTypes.getName(@move).upcase,112,207,2,Color.new(16,41,24),Color.new(57,82,49)],
  792.         [PBTypes.getName(@type1).upcase,272,31,2,Color.new(16,41,24),Color.new(57,82,49)],
  793.         [name2,272,95,2,Color.new(16,41,24),Color.new(57,82,49)]
  794.     ])
  795.     eff = PBTypes.getCombinedEffectiveness(@move, @type1, (@type2 == -1 ? nil : @type2))
  796.     txt = _INTL("Regularly effective")
  797.     txt = _INTL("Super effective") if eff > 8
  798.     txt = _INTL("Not very effective") if eff < 8
  799.     txt = _INTL("Not effective") if eff == 0
  800.     pbDrawTextPositions(@txt,[
  801.         [txt,16,271,0,Color.new(16,41,24),Color.new(57,82,49)]
  802.     ])
  803.     # Determines how many exclamation marks to put
  804.     e = 0 if eff == 0
  805.     e = 1 if eff == 1 || eff == 2
  806.     e = 2 if eff == 4
  807.     e = 3 if eff == 8
  808.     e = 4 if eff == 16
  809.     e = 5 if eff == 32
  810.     for i in 0...6
  811.       @excl[i].dispose if @excl[i]
  812.       if i < e
  813.         @excl[i] = Sprite.new(@viewport)
  814.         @excl[i].bmp("Graphics/Pictures/Poketch/Move Tester/effectiveness")
  815.         @excl[i].x = 48 + 16 * i
  816.         @excl[i].y = 40
  817.       end
  818.     end
  819.   end
  820.  
  821.   def dispose
  822.     for e in @excl
  823.       e.dispose
  824.     end
  825.     @moveBtnLeft.dispose
  826.     @moveBtnRight.dispose
  827.     @type1BtnRight.dispose
  828.     @type1BtnLeft.dispose
  829.     @type2BtnRight.dispose
  830.     @type2BtnLeft.dispose
  831.     @txtsprite.dispose
  832.     super
  833.   end
  834. end
  835.  
  836.  
  837. #==============================================================================#
  838. # Pokétch Pedometer. Counts your steps.                                        #
  839. #==============================================================================#
  840. class PokeBattle_Trainer
  841.   attr_accessor :steps
  842. end
  843.  
  844. Events.onStepTaken += proc do
  845.   $Trainer.steps = 0 if !$Trainer.steps
  846.   $Trainer.steps += 1
  847.   $Poketch.refresh if $Poketch && $Poketch.app.is_a?(PoketchPedometer)
  848. end
  849.  
  850. class PoketchPedometer < PoketchApp
  851.   def initialize
  852.     super
  853.     @bg.bmp("Graphics/Pictures/Poketch/Pedometer/background")
  854.     @btn = Sprite.new(@viewport)
  855.     @btn.bmp("Graphics/Pictures/Poketch/Pedometer/btn")
  856.     @btn.x = 133
  857.     @btn.y = 161
  858.     $Trainer.steps = 0 if !$Trainer.steps
  859.     @numbers = []
  860.     refresh
  861.   end
  862.  
  863.   def update
  864.     super
  865.     if click?(@btn, "Graphics/Pictures/Poketch/Pedometer", "btn")
  866.       $Trainer.steps = 0
  867.       refresh
  868.     end
  869.   end
  870.  
  871.   def refresh
  872.     n = pbFormat($Trainer.steps, 5)
  873.     n = n.to_s.split("")
  874.     for i in 0...5
  875.       @numbers[i].dispose if @numbers[i]
  876.       @numbers[i] = nil
  877.       @numbers[i] = Sprite.new(@viewport)
  878.       @numbers[i].bmp("Graphics/Pictures/Poketch/Pedometer/numbers")
  879.       @numbers[i].src_rect.width = 24
  880.       @numbers[i].src_rect.x = n[i].to_i * 24
  881.       @numbers[i].x = 117 + 32 * i
  882.       @numbers[i].y = 66
  883.     end
  884.   end
  885.  
  886.   def dispose
  887.     @btn.dispose
  888.     for n in @numbers
  889.       n.dispose
  890.     end
  891.     super
  892.   end
  893. end
  894.  
  895.  
  896. #==============================================================================#
  897. # Pokétch Marking Map. Allows you to draw markers onto the map.                 #
  898. #==============================================================================#
  899. class PokeBattle_Trainer
  900.   attr_accessor :poketch_markingmap_circle
  901.   attr_accessor :poketch_markingmap_star
  902.   attr_accessor :poketch_markingmap_cube
  903.   attr_accessor :poketch_markingmap_triangle
  904.   attr_accessor :poketch_markingmap_heart
  905.   attr_accessor :poketch_markingmap_diamond
  906. end
  907.  
  908. class PoketchMarkingMap < PoketchApp
  909.   def initialize
  910.     super
  911.     @bg.bmp("Graphics/Pictures/Poketch/Marking Map/background")
  912.     @circle = Sprite.new(@viewport)
  913.     @circle.bmp("Graphics/Pictures/Poketch/Marking Map/markings")
  914.     @circle.src_rect.width = 20
  915.     @circle.x = 208
  916.     @circle.y = 304
  917.     @circle.ox = @circle.bitmap.width / 6
  918.     @circle.oy = @circle.bitmap.height / 2
  919.     @star = Sprite.new(@viewport)
  920.     @star.bmp("Graphics/Pictures/Poketch/Marking Map/markings")
  921.     @star.src_rect.width = 20
  922.     @star.src_rect.x = 20
  923.     @star.x = 240
  924.     @star.y = 304
  925.     @star.ox = @star.bitmap.width / 6
  926.     @star.oy = @star.bitmap.height / 2
  927.     @cube = Sprite.new(@viewport)
  928.     @cube.bmp("Graphics/Pictures/Poketch/Marking Map/markings")
  929.     @cube.src_rect.width = 20
  930.     @cube.src_rect.x = 40
  931.     @cube.x = 272
  932.     @cube.y = 304
  933.     @cube.ox = @circle.bitmap.width / 6
  934.     @cube.oy = @cube.bitmap.height / 2
  935.     @triangle = Sprite.new(@viewport)
  936.     @triangle.bmp("Graphics/Pictures/Poketch/Marking Map/markings")
  937.     @triangle.src_rect.width = 20
  938.     @triangle.src_rect.x = 60
  939.     @triangle.x = 304
  940.     @triangle.y = 304
  941.     @triangle.ox = @triangle.bitmap.width / 6
  942.     @triangle.oy = @triangle.bitmap.height / 2
  943.     @heart = Sprite.new(@viewport)
  944.     @heart.bmp("Graphics/Pictures/Poketch/Marking Map/markings")
  945.     @heart.src_rect.width = 20
  946.     @heart.src_rect.x = 80
  947.     @heart.x = 336
  948.     @heart.y = 304
  949.     @heart.ox = @heart.bitmap.width / 6
  950.     @heart.oy = @heart.bitmap.height / 2
  951.     @diamond = Sprite.new(@viewport)
  952.     @diamond.bmp("Graphics/Pictures/Poketch/Marking Map/markings")
  953.     @diamond.src_rect.width = 20
  954.     @diamond.src_rect.x = 100
  955.     @diamond.x = 368
  956.     @diamond.y = 304
  957.     @diamond.ox = @diamond.bitmap.width / 6
  958.     @diamond.oy = @diamond.bitmap.height / 2
  959.     @circle.x, @circle.y = $Trainer.poketch_markingmap_circle if $Trainer.poketch_markingmap_circle
  960.     @star.x, @star.y = $Trainer.poketch_markingmap_star if $Trainer.poketch_markingmap_star
  961.     @cube.x, @cube.y = $Trainer.poketch_markingmap_cube if $Trainer.poketch_markingmap_cube
  962.     @triangle.x, @triangle.y = $Trainer.poketch_markingmap_triangle if $Trainer.poketch_markingmap_triangle
  963.     @heart.x, @heart.y = $Trainer.poketch_markingmap_heart if $Trainer.poketch_markingmap_heart
  964.     @diamond.x, @diamond.y = $Trainer.poketch_markingmap_diamond if $Trainer.poketch_markingmap_diamond
  965.     @obj = [@circle, @star, @cube, @triangle, @heart, @diamond]
  966.     @active = nil
  967.   end
  968.  
  969.   def update
  970.     super
  971.     for i in 0...@obj.size
  972.       if @cooldown == -1 && $mouse && $mouse.click?(@obj[i]) && !@active
  973.         @active = i
  974.       end
  975.     end
  976.     if @active && $mouse.x - 32 > 0 && $mouse.x - 32 < 384 &&
  977.        $mouse.y - POKETCH_Y - 32 > 0 && $mouse.y - POKETCH_Y - 32 < 320
  978.       @obj[@active].zoom_x = 2
  979.       @obj[@active].zoom_y = 2
  980.       @obj[@active].x = $mouse.x - 32
  981.       @obj[@active].y = $mouse.y - POKETCH_Y - 32
  982.       $Trainer.poketch_markingmap_circle = @circle.x, @circle.y if @active == 0
  983.       $Trainer.poketch_markingmap_star = @star.x, @star.y if @active == 1
  984.       $Trainer.poketch_markingmap_cube = @cube.x, @cube.y if @active == 2
  985.       $Trainer.poketch_markingmap_triangle = @triangle.x, @triangle.y if @active == 3
  986.       $Trainer.poketch_markingmap_heart = @heart.x, @heart.y if @active == 4
  987.       $Trainer.poketch_markingmap_diamond = @diamond.x, @diamond.y if @active == 5
  988.       if $mouse.press?
  989.         @obj[@active].x = $mouse.x - 32
  990.         @obj[@active].y = $mouse.y - POKETCH_Y - 32
  991.         @obj[@active].zoom_x = 1
  992.         @obj[@active].zoom_y = 1
  993.         @active = nil
  994.         @cooldown = 5
  995.       end
  996.     end
  997.   end
  998.  
  999.   def dispose
  1000.     for obj in @obj
  1001.       obj.dispose
  1002.     end
  1003.     super
  1004.   end
  1005. end
  1006.  
  1007.  
  1008. #==============================================================================#
  1009. # Pokétch Matchup Checker. Check how your Pokémon match up with one another.   #
  1010. #==============================================================================#
  1011. def pbGetCompat(poke1, poke2)
  1012.   temp1 = $PokemonGlobal.daycare[0].clone
  1013.   temp2 = $PokemonGlobal.daycare[1].clone
  1014.   $PokemonGlobal.daycare[0] = [poke1,poke1.level]
  1015.   $PokemonGlobal.daycare[1] = [poke2,poke2.level]
  1016.   compat = pbDayCareGetCompat
  1017.   $PokemonGlobal.daycare[0] = temp1
  1018.   $PokemonGlobal.daycare[1] = temp2
  1019.   return compat
  1020. end
  1021.  
  1022. class PoketchMatchupChecker < PoketchApp
  1023.   def self.usable?
  1024.     return $Trainer.party.size > 1
  1025.   end
  1026.  
  1027.   def initialize
  1028.     super
  1029.     @bg.bmp("Graphics/Pictures/Poketch/Matchup Checker/background")
  1030.     @btn = Sprite.new(@viewport)
  1031.     @btn.bmp("Graphics/Pictures/Poketch/Matchup Checker/btn")
  1032.     @btn.x = 144
  1033.     @btn.y = 232
  1034.     @poke1 = 0
  1035.     @poke2 = 1
  1036.     @icons = [nil, nil]
  1037.     draw_pokes
  1038.     @hearts = []
  1039.     @luvdiscLeft = Sprite.new(@viewport)
  1040.     @luvdiscLeft.bmp("Graphics/Pictures/Poketch/Matchup Checker/luvdisc")
  1041.     @luvdiscLeft.x = 36
  1042.     @luvdiscLeft.y = 104
  1043.    
  1044.     @luvdiscRight = Sprite.new(@viewport)
  1045.     @luvdiscRight.bmp("Graphics/Pictures/Poketch/Matchup Checker/luvdisc")
  1046.     @luvdiscRight.x = 288
  1047.     @luvdiscRight.y = 104
  1048.     @luvdiscRight.mirror = true
  1049.     @n = nil
  1050.   end
  1051.  
  1052.   def update
  1053.     super
  1054.     if !@n
  1055.       if click?(@btn, "Graphics/Pictures/Poketch/Matchup Checker", "btn")
  1056.         redraw
  1057.         c = pbGetCompat($Trainer.party[@poke1], $Trainer.party[@poke2])
  1058.         @n = [[72,29,59,69][c], c, -1]
  1059.       end
  1060.       if $mouse.inAreaLeftPress?(32+16,POKETCH_Y+32+228,96,72) && @cooldown == -1
  1061.         @poke1 += 1
  1062.         @poke1 = 0 if @poke1 >= $Trainer.party.size
  1063.         @poke1 += 1 if @poke1 == @poke2
  1064.         @poke1 = 0 if @poke1 >= $Trainer.party.size
  1065.         pbPlayCry($Trainer.party[@poke1].species)
  1066.         @cooldown = 5
  1067.         redraw
  1068.       elsif $mouse.inAreaLeftPress?(32+272,POKETCH_Y+32+228,96,72) && @cooldown == -1
  1069.         @poke2 += 1
  1070.         @poke2 = 0 if @poke2 >= $Trainer.party.size
  1071.         @poke2 += 1 if @poke2 == @poke1
  1072.         @poke2 = 0 if @poke2 >= $Trainer.party.size
  1073.         pbPlayCry($Trainer.party[@poke2].species)
  1074.         @cooldown = 5
  1075.         redraw
  1076.       end
  1077.     end
  1078.     if @n
  1079.       if @n[1] == 0
  1080.         if @n[0] >= 40
  1081.           @luvdiscLeft.x += 1
  1082.           @luvdiscRight.x -= 1
  1083.         elsif @n[0] <= 24
  1084.           @luvdiscRight.mirror = false
  1085.           @luvdiscLeft.mirror = true
  1086.           @luvdiscLeft.x -= 2
  1087.           @luvdiscRight.x += 2
  1088.         end
  1089.       elsif @n[1] > 0
  1090.         @luvdiscLeft.x += 1
  1091.         @luvdiscRight.x -= 1
  1092.       end
  1093.       @n[0] -= 1
  1094.       if @n[1] > 0 && @n[0] % 30 == 0
  1095.         @n[2] += 1
  1096.         @hearts[@n[2]] = Sprite.new(@viewport)
  1097.         @hearts[@n[2]].bmp("Graphics/Pictures/Poketch/Matchup Checker/heart")
  1098.         @hearts[@n[2]].x = 100 + 64 * @n[2]
  1099.         @hearts[@n[2]].y = 4
  1100.       end
  1101.       @n = nil if @n[0] == 0
  1102.     end
  1103.   end
  1104.  
  1105.   def redraw
  1106.     draw_pokes
  1107.     @luvdiscLeft.x = 36
  1108.     @luvdiscLeft.mirror = false
  1109.     @luvdiscRight.x = 288
  1110.     @luvdiscRight.mirror = true
  1111.     for i in 0...3
  1112.       @hearts[i].dispose if @hearts[i]
  1113.     end
  1114.   end
  1115.  
  1116.   def draw_pokes
  1117.     for i in 0...@icons.size
  1118.       @icons[i].dispose if @icons[i]
  1119.       @icons[i] = nil
  1120.       @icons[i] = Sprite.new(@viewport)
  1121.       sp = pbFormat($Trainer.party[[@poke1,@poke2][i]].species)
  1122.       @icons[i].bmp("Graphics/Icons/icon#{sp}")
  1123.       @icons[i].poketch_average
  1124.       @icons[i].src_rect.width = @icons[i].bitmap.width / 2
  1125.       @icons[i].ox = @icons[i].bitmap.width / 4
  1126.       @icons[i].oy = @icons[i].bitmap.height / 2
  1127.       @icons[i].x = [64,320][i]
  1128.       @icons[i].y = 264
  1129.     end
  1130.   end
  1131.  
  1132.   def dispose
  1133.     for i in @icons
  1134.       i.dispose
  1135.     end
  1136.     @luvdiscLeft.dispose
  1137.     @luvdiscRight.dispose
  1138.     for h in @hearts
  1139.       h.dispose
  1140.     end
  1141.     super
  1142.   end
  1143. end
  1144.  
  1145.  
  1146. #==============================================================================#
  1147. # Pokétch Party app. Displays your team with their items.                      #
  1148. #==============================================================================#
  1149. class PoketchParty < PoketchApp
  1150.   def initialize
  1151.     super
  1152.     @bg.bmp("Graphics/Pictures/Poketch/blank")
  1153.     @pokemon = []
  1154.     refresh
  1155.   end
  1156.  
  1157.   def update
  1158.     super
  1159.     # Refresh every 80 frames
  1160.     if @cooldown == -1
  1161.       refresh
  1162.       @cooldown = 80
  1163.     end
  1164.     for p in @pokemon
  1165.       if $mouse.press?(p[1])
  1166.         pbPlayCry(p[0])
  1167.       end
  1168.     end
  1169.   end
  1170.  
  1171.   def refresh
  1172.     for i in 0...6
  1173.       if @pokemon[i]
  1174.         @pokemon[i][1].dispose if @pokemon[i][1]
  1175.         @pokemon[i][2].dispose if @pokemon[i][2]
  1176.         @pokemon[i][3].dispose if @pokemon[i][3]
  1177.         @pokemon[i][4].dispose if @pokemon[i][4]
  1178.         @pokemon[i] = nil
  1179.       end
  1180.       if $Trainer.party[i]
  1181.         @pokemon[i] = []
  1182.         @pokemon[i][0] = $Trainer.party[i].species
  1183.         @pokemon[i][1] = Sprite.new(@viewport)
  1184.         @pokemon[i][1].bmp("Graphics/Icons/icon#{pbFormat($Trainer.party[i].species)}")
  1185.         if $Trainer.party[0].isFainted?
  1186.           @pokemon[i][1].color = Color.new(82,132,82)
  1187.         else
  1188.           @pokemon[i][1].poketch_average
  1189.         end
  1190.         @pokemon[i][1].src_rect.width = @pokemon[i][1].bitmap.width / 2
  1191.         @pokemon[i][1].ox = @pokemon[i][1].bitmap.width / 4
  1192.         @pokemon[i][1].oy = @pokemon[i][1].bitmap.height / 2
  1193.         @pokemon[i][1].zoom_x = 1.5
  1194.         @pokemon[i][1].zoom_y = 1.5
  1195.         @pokemon[i][1].x = [95,287][i % 2]
  1196.         @pokemon[i][1].y = [46,142,238][(i / 2).floor]
  1197.         @pokemon[i][1].z = 1
  1198.         @pokemon[i][2] = Sprite.new(@viewport)
  1199.         @pokemon[i][2].bmp("Graphics/Pictures/Poketch/Party/hpbar")
  1200.         @pokemon[i][2].x = [28,220][i % 2]
  1201.         @pokemon[i][2].y = [86,182,270][(i / 2).floor]
  1202.         @pokemon[i][3] = Sprite.new(@viewport)
  1203.         @pokemon[i][3].bmp("Graphics/Pictures/Poketch/Party/hp")
  1204.         perc = $Trainer.party[i].hp.to_f / $Trainer.party[i].totalhp.to_f
  1205.         @pokemon[i][3].src_rect.width = perc * @pokemon[i][3].bitmap.width
  1206.         @pokemon[i][3].x = @pokemon[i][2].x + 4
  1207.         @pokemon[i][3].y = @pokemon[i][2].y + 4
  1208.         if $Trainer.party[i].item && $Trainer.party[i].item > 0
  1209.           @pokemon[i][4] = Sprite.new(@viewport)
  1210.           @pokemon[i][4].bmp("Graphics/Pictures/Poketch/Party/item")
  1211.           @pokemon[i][4].x = @pokemon[i][2].x + 112
  1212.           @pokemon[i][4].y = @pokemon[i][2].y - 26
  1213.         end
  1214.       end
  1215.     end
  1216.   end
  1217.  
  1218.   def dispose
  1219.     for i in 0...6
  1220.       if @pokemon[i]
  1221.         @pokemon[i][1].dispose if @pokemon[i][1]
  1222.         @pokemon[i][2].dispose if @pokemon[i][2]
  1223.         @pokemon[i][3].dispose if @pokemon[i][3]
  1224.         @pokemon[i][4].dispose if @pokemon[i][4]
  1225.         @pokemon[i] = nil
  1226.       end
  1227.     end
  1228.     super
  1229.   end
  1230. end
  1231.  
  1232.  
  1233. #==============================================================================#
  1234. # Pokétch Color Changer. Changes the overlay color of the screen.              #
  1235. #==============================================================================#
  1236. class PokeBattle_Trainer
  1237.   attr_accessor :poketch_color
  1238. end
  1239.  
  1240. class PoketchColorChanger < PoketchApp
  1241.   def initialize
  1242.     super
  1243.     @pos = [48,80,144,176,240,272]
  1244.     @bg.bmp("Graphics/Pictures/Poketch/Color Changer/background")
  1245.     @sel = $Trainer.poketch_color || 0
  1246.     @slider = Sprite.new(@viewport)
  1247.     @slider.bmp("Graphics/Pictures/Poketch/Color Changer/slider")
  1248.     @slider.ox = 64
  1249.     @slider.x = @pos[@sel]
  1250.     @slider.y = 232
  1251.   end
  1252.  
  1253.   def update
  1254.     if $mouse && $mouse.drag_object_x?(@slider)
  1255.       @slider.x = 48 if @slider.x < 48
  1256.       @slider.x = 272 if @slider.x > 272
  1257.       case @slider.x
  1258.       when 48..64
  1259.         @sel = 0
  1260.       when 65..112
  1261.         @sel = 1
  1262.       when 113..160
  1263.         @sel = 2
  1264.       when 161..208
  1265.         @sel = 3
  1266.       when 209..256
  1267.         @sel = 4
  1268.       else
  1269.         @sel = 5
  1270.       end
  1271.       @slider.x = @pos[@sel]
  1272.       if @sel == 0
  1273.         $Poketch.no_color
  1274.       else
  1275.         $Poketch.set_color("Graphics/Pictures/Poketch/Color Changer/overlay#{@sel}")
  1276.       end
  1277.       $Trainer.poketch_color = @sel
  1278.     end
  1279.   end
  1280.  
  1281.   def dispose
  1282.     @slider.dispose
  1283.     super
  1284.   end
  1285. end
  1286.  
  1287.  
  1288. #==============================================================================#
  1289. # Pokétch Kitchen Timer. Can count down from 99 minutes max.                   #
  1290. #==============================================================================#
  1291. class PokemonTemp
  1292.   attr_reader :poketch_timer
  1293.   attr_accessor :poketch_timer_running
  1294.  
  1295.   def poketch_timer=(value)
  1296.     @poketch_timer = value
  1297.     @poketch_timer = 0 if @poketch_timer < 0
  1298.   end
  1299. end
  1300.  
  1301. module Graphics
  1302.   class << Graphics
  1303.     alias poketch_timer_update update
  1304.   end
  1305.  
  1306.   def self.update
  1307.     poketch_timer_update
  1308.     return if !$Poketch
  1309.     return if !$PokemonTemp || !$PokemonTemp.poketch_timer || !$PokemonTemp.poketch_timer_running
  1310.     if Graphics.frame_count % Graphics.frame_rate == 0
  1311.       $PokemonTemp.poketch_timer -= 1
  1312.       $Poketch.app.refresh if $Poketch.app.is_a?(PoketchKitchenTimer)
  1313.     end
  1314.   end
  1315. end
  1316.  
  1317. class PoketchKitchenTimer < PoketchApp
  1318.   def initialize
  1319.     super
  1320.     @bg.bmp("Graphics/Pictures/Poketch/Kitchen Timer/#{$PokemonTemp.poketch_timer_running ? "active" : "idle"}")
  1321.     @startBtn = Sprite.new(@viewport)
  1322.     $PokemonTemp.poketch_timer = 0 if !$PokemonTemp.poketch_timer
  1323.     path = "startBtn"
  1324.     path = "startBtnClick" if $PokemonTemp.poketch_timer_running ||
  1325.                               $PokemonTemp.poketch_timer == 0
  1326.     @startBtn.bmp("Graphics/Pictures/Poketch/Kitchen Timer/#{path}")
  1327.     @startBtn.y = 256
  1328.     @stopBtn = Sprite.new(@viewport)
  1329.     path = $PokemonTemp.poketch_timer_running ? "stopBtn" : "stopBtnClick"
  1330.     @stopBtn.bmp("Graphics/Pictures/Poketch/Kitchen Timer/#{path}")
  1331.     @stopBtn.x = 128
  1332.     @stopBtn.y = 256
  1333.     @resetBtn = Sprite.new(@viewport)
  1334.     @resetBtn.bmp("Graphics/Pictures/Poketch/Kitchen Timer/resetBtn")
  1335.     @resetBtn.x = 256
  1336.     @resetBtn.y = 256
  1337.     @numbers = []
  1338.     @arrows = []
  1339.     refresh
  1340.     for i in 0...8
  1341.       @arrows[i] = Sprite.new(@viewport)
  1342.       path = ["up","down"][(i / 4).floor]
  1343.       @arrows[i].bmp("Graphics/Pictures/Poketch/Kitchen Timer/arrow#{path}")
  1344.       @arrows[i].x = [114,146,210,242][i % 4]
  1345.       @arrows[i].y = [136,224][(i / 4).floor]
  1346.       @arrows[i].visible = !$PokemonTemp.poketch_timer_running
  1347.     end
  1348.     @canstart = false if $PokemonTemp.poketch_timer_running || $PokemonTemp.poketch_timer == 0
  1349.     @frame = 0
  1350.     @i = nil
  1351.   end
  1352.  
  1353.   def update
  1354.     super
  1355.     if @i
  1356.       @i += 1
  1357.       if @i == 8
  1358.         @bg.bmp("Graphics/Pictures/Poketch/Kitchen Timer/done1")
  1359.       elsif @i == 16
  1360.         @bg.bmp("Graphics/Pictures/Poketch/Kitchen Timer/done2")
  1361.       end
  1362.       @i = 0 if @i == 16
  1363.     end
  1364.     @frame += 1
  1365.     @frame = 0 if @frame == 41
  1366.     unless $PokemonTemp.poketch_timer_running
  1367.       for i in 0...8
  1368.         if $mouse.click?(@arrows[i])
  1369.           increment = [600,60,10,1][i % 4]
  1370.           $PokemonTemp.poketch_timer += [1,-1][(i / 4).floor] * increment
  1371.           $PokemonTemp.poketch_timer = 0 if $PokemonTemp.poketch_timer >= 6000
  1372.           update_can_start
  1373.           refresh
  1374.         end
  1375.         @arrows[i].visible = @frame < 20
  1376.       end
  1377.     end
  1378.     if click?(@resetBtn,"Graphics/Pictures/Poketch/Kitchen Timer","resetBtn")
  1379.       $PokemonTemp.poketch_timer_running = false
  1380.       $PokemonTemp.poketch_timer = 0
  1381.       for i in 0...8
  1382.         @arrows[i].visible = true
  1383.       end
  1384.       @bg.bmp("Graphics/Pictures/Poketch/Kitchen Timer/idle")
  1385.       update_can_start
  1386.       @stopBtn.bmp("Graphics/Pictures/Poketch/Kitchen Timer/stopBtnClick")
  1387.       refresh
  1388.       @frame = 20
  1389.       @i = nil
  1390.     end
  1391.     if $mouse.click?(@startBtn) && !$PokemonTemp.poketch_timer_running && @canstart
  1392.       @startBtn.bmp("Graphics/Pictures/Poketch/Kitchen Timer/startBtnClick")
  1393.       @stopBtn.bmp("Graphics/Pictures/Poketch/Kitchen Timer/stopBtn")
  1394.       $PokemonTemp.poketch_timer_running = true
  1395.       for i in 0...8
  1396.         @arrows[i].visible = false
  1397.       end
  1398.       @bg.bmp("Graphics/Pictures/Poketch/Kitchen Timer/active")
  1399.       @i = nil
  1400.     end
  1401.     if $mouse.click?(@stopBtn) && $PokemonTemp.poketch_timer_running
  1402.       @startBtn.bmp("Graphics/Pictures/Poketch/Kitchen Timer/startBtn")
  1403.       @stopBtn.bmp("Graphics/Pictures/Poketch/Kitchen Timer/stopBtnClick")
  1404.       for i in 0...8
  1405.         @arrows[i].visible = true
  1406.       end
  1407.       @bg.bmp("Graphics/Pictures/Poketch/Kitchen Timer/idle")
  1408.       update_can_start
  1409.       $PokemonTemp.poketch_timer_running = false
  1410.       @frame = 20
  1411.       @i = nil
  1412.     end
  1413.   end
  1414.  
  1415.   def update_can_start
  1416.     if $PokemonTemp.poketch_timer > 0
  1417.       @canstart = true
  1418.       @startBtn.bmp("Graphics/Pictures/Poketch/Kitchen Timer/startBtn")
  1419.     else
  1420.       @canstart = false
  1421.       @startBtn.bmp("Graphics/Pictures/Poketch/Kitchen Timer/startBtnClick")
  1422.     end
  1423.   end
  1424.  
  1425.   def refresh
  1426.     n = [0,0,0,0]
  1427.     begin
  1428.       mins = ($PokemonTemp.poketch_timer / 60).floor
  1429.       secs = $PokemonTemp.poketch_timer % 60
  1430.       nmin = pbFormat(mins, 2).split("")
  1431.       nsec = pbFormat(secs, 2).split("")
  1432.       n = nmin.concat(nsec)
  1433.     rescue; end
  1434.     for i in 0...4
  1435.       @numbers[i].dispose if @numbers[i]
  1436.       @numbers[i] = nil
  1437.       @numbers[i] = Sprite.new(@viewport)
  1438.       @numbers[i].bmp("Graphics/Pictures/Poketch/Kitchen Timer/numbers")
  1439.       @numbers[i].src_rect.width = 24
  1440.       @numbers[i].src_rect.x = 24 * n[i].to_i
  1441.       @numbers[i].x = [116,148,212,244][i]
  1442.       @numbers[i].y = 160
  1443.     end
  1444.     @i = 0 if $PokemonTemp.poketch_timer <= 0 && !@i && $PokemonTemp.poketch_timer_running
  1445.   end
  1446.  
  1447.   def dispose
  1448.     @startBtn.dispose
  1449.     @stopBtn.dispose
  1450.     @resetBtn.dispose
  1451.     for n in @numbers
  1452.       n.dispose
  1453.     end
  1454.     super
  1455.   end
  1456. end
  1457.  
  1458.  
  1459. #==============================================================================#
  1460. # Pokétch Analog Watch. Displays the current time, but analog.                 #
  1461. #==============================================================================#
  1462. class PoketchAnalogWatch < PoketchApp
  1463.   def initialize
  1464.     super
  1465.     @bg.bmp("Graphics/Pictures/Poketch/Analog Watch/background")
  1466.     @long = Sprite.new(@viewport)
  1467.     @long.bmp("Graphics/Pictures/Poketch/Analog Watch/long")
  1468.     @long.ox = @long.bitmap.width / 2
  1469.     @long.oy = @long.bitmap.height
  1470.     @long.x = 192
  1471.     @long.y = 168
  1472.     @short = Sprite.new(@viewport)
  1473.     @short.bmp("Graphics/Pictures/Poketch/Analog Watch/short")
  1474.     @short.ox = @short.bitmap.width / 2
  1475.     @short.oy = @short.bitmap.height
  1476.     @short.x = 192
  1477.     @short.y = 168
  1478.     @time = Time.now
  1479.     position
  1480.   end
  1481.  
  1482.   def position
  1483.     @short.angle = (@time.hour % 12) / 12.0 * -360
  1484.     @long.angle = @time.min / 60.0 * -360
  1485.   end
  1486.  
  1487.   def update
  1488.     if @time.hour != Time.now.hour || @time.min != Time.now.min
  1489.       @time = Time.now
  1490.       position
  1491.     end
  1492.   end
  1493.  
  1494.   def dispose
  1495.     @long.dispose
  1496.     @short.dispose
  1497.     super
  1498.   end
  1499. end
  1500.  
  1501.  
  1502. #==============================================================================#
  1503. # Pokétch Stat Display. Shows party members' EVs/IVs.                          #
  1504. #==============================================================================#
  1505. class PoketchStatDisplay < PoketchApp
  1506.   def initialize
  1507.     super
  1508.     @bg.bmp("Graphics/Pictures/Poketch/Stat Display/background")
  1509.     @evBtn = Sprite.new(@viewport)
  1510.     @evBtn.bmp("Graphics/Pictures/Poketch/Stat Display/evBtnClick")
  1511.     @evBtn.x = 268
  1512.     @evBtn.y = 108
  1513.     @ivBtn = Sprite.new(@viewport)
  1514.     @ivBtn.bmp("Graphics/Pictures/Poketch/Stat Display/ivBtn")
  1515.     @ivBtn.x = 268
  1516.     @ivBtn.y = 188
  1517.     @sel = 0
  1518.     @mode = :ev
  1519.     @icon = Sprite.new(@viewport)
  1520.     @icon.bmp("Graphics/Icons/icon#{pbFormat($Trainer.party[@sel].species)}")
  1521.     @icon.poketch_average
  1522.     @icon.src_rect.width = @icon.bitmap.width / 2
  1523.     @icon.ox = @icon.bitmap.width / 4
  1524.     @icon.oy = @icon.bitmap.height / 2
  1525.     @icon.x = 312
  1526.     @icon.y = 52
  1527.     @txtsprite = Sprite.new(@viewport)
  1528.     @txtsprite.bmp(384,320)
  1529.     @txt = @txtsprite.bitmap
  1530.     pbSetSystemFont(@txt)
  1531.     @stats = []
  1532.     draw
  1533.   end
  1534.  
  1535.   def update
  1536.     super
  1537.     if $mouse.click?(@ivBtn)
  1538.       @ivBtn.bmp("Graphics/Pictures/Poketch/Stat Display/ivBtnClick")
  1539.       @evBtn.bmp("Graphics/Pictures/Poketch/Stat Display/evBtn")
  1540.       @mode = :iv
  1541.       draw
  1542.     end
  1543.     if $mouse.click?(@evBtn)
  1544.       @evBtn.bmp("Graphics/Pictures/Poketch/Stat Display/evBtnClick")
  1545.       @ivBtn.bmp("Graphics/Pictures/Poketch/Stat Display/ivBtn")
  1546.       @mode = :ev
  1547.       draw
  1548.     end
  1549.     if $mouse.inAreaLeftPress?(296,POKETCH_Y+48,98,72) && @cooldown == -1
  1550.       @cooldown = 8
  1551.       @sel += 1
  1552.       @sel = 0 if @sel >= $Trainer.party.size
  1553.       pbPlayCry($Trainer.party[@sel].species)
  1554.       @icon.bmp("Graphics/Icons/icon#{pbFormat($Trainer.party[@sel].species)}")
  1555.       @icon.poketch_average
  1556.       @icon.src_rect.width = @icon.bitmap.width / 2
  1557.       @icon.ox = @icon.bitmap.width / 4
  1558.       @icon.oy = @icon.bitmap.height / 2
  1559.       draw
  1560.     end
  1561.   end
  1562.  
  1563.   def draw
  1564.     @txt.clear
  1565.     pbDrawTextPositions(@txt,[
  1566.         [_INTL("HP"),102,12,0,Color.new(16,41,24),Color.new(57,82,49)],
  1567.         [_INTL("Atk."),102,64,0,Color.new(16,41,24),Color.new(57,82,49)],
  1568.         [_INTL("Def."),102,116,0,Color.new(16,41,24),Color.new(57,82,49)],
  1569.         [_INTL("SpAtk."),102,168,0,Color.new(16,41,24),Color.new(57,82,49)],
  1570.         [_INTL("SpDef."),102,220,0,Color.new(16,41,24),Color.new(57,82,49)],
  1571.         [_INTL("Speed"),102,272,0,Color.new(16,41,24),Color.new(57,82,49)]
  1572.     ])
  1573.     a = (@mode == :ev ? $Trainer.party[@sel].ev : $Trainer.party[@sel].iv)
  1574.     # Sorting it to [HP,Atk,Def,SpAtk,SpDef,Speed]
  1575.     t = a[3]
  1576.     a[3] = nil
  1577.     a.compact!
  1578.     a << t
  1579.     for i in 0...a.size
  1580.       @stats[i] = [] if !@stats[i]
  1581.       n = pbFormat(a[i], a[i].to_s.size).split("")
  1582.       for j in 0...3
  1583.         @stats[i][j].dispose if @stats[i][j]
  1584.         if j < n.size
  1585.           @stats[i][j] = Sprite.new(@viewport)
  1586.           @stats[i][j].bmp("Graphics/Pictures/Poketch/Stat Display/numbers")
  1587.           @stats[i][j].src_rect.width = 20
  1588.           @stats[i][j].src_rect.x = 20 * n[j].to_i
  1589.           @stats[i][j].x = [[40],[24,56],[16,40,64]][n.size - 1][j]
  1590.           @stats[i][j].y = 12 + 52 * i
  1591.         end
  1592.       end
  1593.     end
  1594.   end
  1595.  
  1596.   def dispose
  1597.     @evBtn.dispose
  1598.     @ivBtn.dispose
  1599.     for i in 0...6
  1600.       next if !@stats[i]
  1601.       for j in 0...3
  1602.         @stats[i][j].dispose if @stats[i][j]
  1603.       end
  1604.       @stats[i] = nil
  1605.     end
  1606.     @icon.dispose
  1607.     @txtsprite.dispose
  1608.     super
  1609.   end
  1610. end
  1611.  
  1612.  
  1613. #==============================================================================#
  1614. # Pokétch Roulette. Spins an arrow and stops when you tell it to.              #
  1615. #==============================================================================#
  1616. class PoketchRoulette < PoketchApp
  1617.   # Only usable if RPG.Net is found
  1618.   # RNET is a boolean; true if RPG.Net.dll is found, false if not.
  1619.   def self.usable?
  1620.     return RNET
  1621.   end
  1622.  
  1623.   def initialize
  1624.     super
  1625.     @bg.bmp("Graphics/Pictures/Poketch/Roulette/background")
  1626.     @arrow = Sprite.new(@viewport)
  1627.     @arrow.bmp("Graphics/Pictures/Poketch/Roulette/arrow")
  1628.     @arrow.ox = @arrow.bitmap.width / 2
  1629.     @arrow.oy = @arrow.bitmap.height / 2
  1630.     @arrow.x = 160
  1631.     @arrow.y = 160
  1632.     @arrow.z = 2
  1633.     @playBtn = Sprite.new(@viewport)
  1634.     @playBtn.bmp("Graphics/Pictures/Poketch/Roulette/playBtn")
  1635.     @playBtn.x = 310
  1636.     @playBtn.y = 28
  1637.     @stopBtn = Sprite.new(@viewport)
  1638.     @stopBtn.bmp("Graphics/Pictures/Poketch/Roulette/stopBtnClick")
  1639.     @stopBtn.x = 310
  1640.     @stopBtn.y = 120
  1641.     @clearBtn = Sprite.new(@viewport)
  1642.     @clearBtn.bmp("Graphics/Pictures/Poketch/Roulette/clearBtn")
  1643.     @clearBtn.x = 310
  1644.     @clearBtn.y = 212
  1645.    
  1646.     @board = Sprite.new(@viewport)
  1647.     @board.bmp(280,280)
  1648.     @board.x = 20
  1649.     @board.y = 20
  1650.    
  1651.     @overlays = []
  1652.     @overlays[0] = Sprite.new(@viewport)
  1653.     @overlays[0].bmp("Graphics/Pictures/Poketch/Roulette/circleOverlay1")
  1654.     @overlays[0].x = 128
  1655.     @overlays[0].y = 128
  1656.     @overlays[0].z = 1
  1657.     @overlays[1] = Sprite.new(@viewport)
  1658.     @overlays[1].bmp("Graphics/Pictures/Poketch/Roulette/circleOverlay2")
  1659.     @overlays[1].x = 20
  1660.     @overlays[1].y = 20
  1661.     @overlays[1].z = 1
  1662.    
  1663.     @playing = false
  1664.     @stopping = false
  1665.     @frame = 0
  1666.    
  1667.     @olddata = []
  1668.     @newdata = []
  1669.   end
  1670.  
  1671.   def update
  1672.     super
  1673.     if $mouse.click?(@playBtn) && !@playing
  1674.       @playBtn.bmp("Graphics/Pictures/Poketch/Roulette/playBtnClick")
  1675.       @stopBtn.bmp("Graphics/Pictures/Poketch/Roulette/stopBtn")
  1676.       @clearBtn.bmp("Graphics/Pictures/Poketch/Roulette/clearBtnClick")
  1677.       @playing = true
  1678.     end
  1679.     if @playing
  1680.       if @stopping
  1681.         @arrow.angle -= 3 * [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16][[(@frame / 4).floor - 1,0].max]
  1682.         @frame -= 1
  1683.         if @frame <= 0
  1684.           @frame = 0
  1685.           @playing = false
  1686.           @stopping = false
  1687.           @playBtn.bmp("Graphics/Pictures/Poketch/Roulette/playBtn")
  1688.           @stopBtn.bmp("Graphics/Pictures/Poketch/Roulette/stopBtnClick")
  1689.           @clearBtn.bmp("Graphics/Pictures/Poketch/Roulette/clearBtn")
  1690.         end
  1691.       else
  1692.         @arrow.angle -= 3 * [(@frame / 2).floor,16].min
  1693.         @frame += 1
  1694.       end
  1695.     end
  1696.     if !@playing && click?(@clearBtn,"Graphics/Pictures/Poketch/Roulette","clearBtn")
  1697.       @board.bitmap.clear
  1698.     end
  1699.     if $mouse.click?(@stopBtn) && @playing
  1700.       @stopBtn.bmp("Graphics/Pictures/Poketch/Roulette/stopBtnClick")
  1701.       @frame = 64
  1702.       @stopping = true
  1703.     end
  1704.     if !@playing
  1705.       if $mouse.press?(@board) && !@player
  1706.         @newdata = [$mouse.x-52,$mouse.y-POKETCH_Y-52]
  1707.       else
  1708.         @olddata.clear
  1709.         @newdata.clear
  1710.       end
  1711.     end
  1712.     if @newdata.size > 0
  1713.       if @olddata.size > 0
  1714.         @board.bitmap.draw_line(@olddata[0],@olddata[1],@newdata[0],@newdata[1],
  1715.             Color.new(16,41,24),4)
  1716.       end
  1717.       @olddata = @newdata.clone
  1718.       @newdata.clear
  1719.     end
  1720.   end
  1721.  
  1722.   def dispose
  1723.     @playBtn.dispose
  1724.     @stopBtn.dispose
  1725.     @clearBtn.dispose
  1726.     @arrow.dispose
  1727.     for o in @overlays
  1728.       o.dispose
  1729.     end
  1730.     @board.dispose
  1731.     super
  1732.   end
  1733. end
  1734.  
  1735.  
  1736. #==============================================================================#
  1737. # Pokétch Day-Care Checker. Shows you what you got going on in the Day-care.   #
  1738. #==============================================================================#
  1739. class PoketchDayCareChecker < PoketchApp
  1740.   def initialize
  1741.     super
  1742.     @bg.bmp("Graphics/Pictures/Poketch/Day Care Checker/background")
  1743.     @pokes = []
  1744.     refresh
  1745.     @frame = 0
  1746.   end
  1747.  
  1748.   def update
  1749.     @frame += 1
  1750.     if @frame % 50 == 0
  1751.       @egg.dispose if @egg
  1752.       if pbEggGenerated?
  1753.         @egg = Sprite.new(@viewport)
  1754.         @egg.bmp("Graphics/Pictures/Poketch/Day Care Checker/egg")
  1755.         @egg.x = 166
  1756.         @egg.y = 204
  1757.       end
  1758.     end
  1759.     if @frame == 100
  1760.       refresh
  1761.       @frame = 0
  1762.     end
  1763.   end
  1764.  
  1765.   def refresh
  1766.     for i in 0...2
  1767.       @pokes[i] = [] if !@pokes[i]
  1768.       if $PokemonGlobal.daycare[i] && $PokemonGlobal.daycare[i][0].is_a?(PokeBattle_Pokemon)
  1769.         p = $PokemonGlobal.daycare[i]
  1770.         @pokes[i][0].dispose if @pokes[i][0]
  1771.         @pokes[i][0] = Sprite.new(@viewport)
  1772.         @pokes[i][0].bmp("Graphics/Icons/icon#{pbFormat(p[0].species)}")
  1773.         @pokes[i][0].poketch_average
  1774.         @pokes[i][0].src_rect.width = @pokes[i][0].bitmap.width / 2
  1775.         @pokes[i][0].mirror = true
  1776.         @pokes[i][0].ox = @pokes[i][0].bitmap.width / 4
  1777.         @pokes[i][0].oy = @pokes[i][0].bitmap.height / 2
  1778.         @pokes[i][0].zoom_x = 2
  1779.         @pokes[i][0].zoom_y = 2
  1780.         @pokes[i][0].x = [82,304][i]
  1781.         @pokes[i][0].y = 224
  1782.         n = pbFormat(p[1]).split("")
  1783.         for j in 0...3
  1784.           @pokes[i][j+1].dispose if @pokes[i][j+1]
  1785.           @pokes[i][j+1] = Sprite.new(@viewport)
  1786.           @pokes[i][j+1].bmp("Graphics/Pictures/Poketch/Day Care Checker/numbers")
  1787.           @pokes[i][j+1].src_rect.width = 16
  1788.           @pokes[i][j+1].src_rect.x = n[j].to_i * 16
  1789.           @pokes[i][j+1].x = [56,264][i] + 32 * j
  1790.           @pokes[i][j+1].y = 40
  1791.         end
  1792.       end
  1793.     end
  1794.   end
  1795.  
  1796.   def dispose
  1797.     for i in 0...2
  1798.       next if !@pokes[i]
  1799.       for j in 0...4
  1800.         next if !@pokes[i][j]
  1801.         @pokes[i][j].dispose
  1802.       end
  1803.     end
  1804.     @egg.dispose if @egg
  1805.     super
  1806.   end
  1807. end
  1808.  
  1809.  
  1810. #==============================================================================#
  1811. # Pokétch Pokémon History. Lists 12 most recent caught, evolved, and hatched.  #
  1812. #==============================================================================#
  1813. # Whenever a Pokémon evolves, is traded, caught, or hatched, it needs to be
  1814. # registered. This below all handles that tracking, and then the actual app.
  1815.  
  1816. #========= This all handles Pokémon History tracking =========#
  1817. # The actual history list (tracked in $Trainer)
  1818. class PokeBattle_Trainer
  1819.   attr_writer :pokemonhistory
  1820.  
  1821.   def pokemonhistory
  1822.     @pokemonhistory = [] if !@pokemonhistory
  1823.     return @pokemonhistory
  1824.   end
  1825. end
  1826.  
  1827. # Pushes to $Trainer.pokemonhistory and deletes a duplicate if found
  1828. def pbPushHistory(pokemon)
  1829.   unless isConst?($Trainer.pokemonhistory[$Trainer.pokemonhistory.size - 1].species,
  1830.          PBSpecies,:NINJASK) && isConst?(pokemon.species,PBSpecies,:SHEDINJA)
  1831.     for i in 0...$Trainer.pokemonhistory.size
  1832.       if $Trainer.pokemonhistory[i].personalID == pokemon.personalID
  1833.         $Trainer.pokemonhistory[i] = nil
  1834.         break
  1835.       end
  1836.     end
  1837.   end
  1838.   $Trainer.pokemonhistory.compact!
  1839.   $Trainer.pokemonhistory << pokemon.clone
  1840.   $Poketch.app.refresh if $Poketch && $Poketch.app.is_a?(PoketchPokemonHistory)
  1841. end
  1842.  
  1843. # Registers traded Pokémon to $Trainer.pokemonhistory
  1844. if defined?(PokemonTrade_Scene)
  1845.   class PokemonTrade_Scene
  1846.     alias poketch_trade pbTrade
  1847.     def pbTrade
  1848.       poketch_trade
  1849.       pbPushHistory(@pokemon2)
  1850.     end
  1851.   end
  1852. else
  1853.   class PokemonTradeScene
  1854.     alias poketch_trade pbTrade
  1855.     def pbTrade
  1856.       poketch_trade
  1857.       pbPushHistory(@pokemon2)
  1858.     end
  1859.   end
  1860. end
  1861.  
  1862. # Registers evolved Pokémon to $Trainer.pokemonhistory
  1863. class PokemonTemp
  1864.   attr_accessor :registerOnCalc
  1865. end
  1866.  
  1867. class PokeBattle_Pokemon
  1868.   alias poketch_calcStats calcStats
  1869.   def calcStats
  1870.     poketch_calcStats
  1871.     pbPushHistory(self) if $PokemonTemp.registerOnCalc
  1872.   end
  1873. end
  1874.  
  1875. class PokemonEvolutionScene
  1876.   alias poketch_evolution pbEvolution
  1877.   def pbEvolution(cancancel = true)
  1878.     $PokemonTemp.registerOnCalc = true
  1879.     poketch_evolution(cancancel)
  1880.     $PokemonTemp.registerOnCalc = false
  1881.   end
  1882. end
  1883.  
  1884. # Registers hatched Pokémon to $Trainer.pokemonhistory
  1885. alias poketch_hatch pbHatch
  1886. def pbHatch(pokemon)
  1887.   poketch_hatch(pokemon)
  1888.   pbPushHistory(pokemon)
  1889. end
  1890.  
  1891. # Registers caught Pokémon to $Trainer.pokemonhistory
  1892. module PokeBattle_BattleCommon
  1893.   alias poketch_store pbStorePokemon
  1894.   def pbStorePokemon(pokemon)
  1895.     poketch_store(pokemon)
  1896.     pbPushHistory(pokemon)
  1897.   end
  1898. end
  1899. #========= End all handling Pokémon History tracking =========#
  1900.  
  1901. class PoketchPokemonHistory < PoketchApp
  1902.   def initialize
  1903.     super
  1904.     @bg.bmp("Graphics/Pictures/Poketch/Pokemon History/background")
  1905.     @pokemon = []
  1906.     refresh
  1907.   end
  1908.  
  1909.   def update
  1910.     for p in @pokemon
  1911.       if $mouse.click?(p[0])
  1912.         pbPlayCry(p[1])
  1913.       end
  1914.     end
  1915.   end
  1916.  
  1917.   def refresh
  1918.     ret = $Trainer.pokemonhistory.clone
  1919.     if $Trainer.pokemonhistory.size > 12
  1920.       ret = $Trainer.pokemonhistory[-12,12]
  1921.     end
  1922.     ret.reverse!
  1923.     for i in 0...12
  1924.       @pokemon[i] = [] if !@pokemon[i]
  1925.       @pokemon[i][0].dispose if @pokemon[i][0]
  1926.       if i <= ret.size - 1
  1927.         @pokemon[i][0] = Sprite.new(@viewport)
  1928.         @pokemon[i][0].bmp("Graphics/Icons/icon#{pbFormat(ret[i].species)}")
  1929.         @pokemon[i][0].poketch_average
  1930.         @pokemon[i][0].src_rect.width = @pokemon[i][0].bitmap.width / 2
  1931.         @pokemon[i][0].zoom_x = 1.5
  1932.         @pokemon[i][0].zoom_y = 1.5
  1933.         @pokemon[i][0].ox = @pokemon[i][0].bitmap.width / 4
  1934.         @pokemon[i][0].oy = @pokemon[i][0].bitmap.height / 2
  1935.         @pokemon[i][0].x = [64,144,224,304][i % 4]
  1936.         @pokemon[i][0].y = [82,168,256][(i / 4).floor]
  1937.         @pokemon[i][1] = ret[i].species
  1938.       end
  1939.     end
  1940.   end
  1941.  
  1942.   def dispose
  1943.     for p in @pokemon
  1944.       p[0].dispose
  1945.     end
  1946.     @pokemon.clear
  1947.     super
  1948.   end
  1949. end
  1950.  
  1951.  
  1952. #==============================================================================#
  1953. # Pokétch Calendar. Shows you the days of this month.                          #
  1954. #==============================================================================#
  1955. class PokeBattle_Trainer
  1956.   attr_accessor :calendar_month
  1957.   attr_accessor :calendar_marked
  1958. end
  1959.  
  1960. def pbIsLeapYear?(y)
  1961.   return (y % 4 == 0) && !(y % 100 == 0) || (y % 400 == 0)
  1962. end
  1963.  
  1964. def pbGetTotalDays(t)
  1965.   return 29 if t.month == 2 && pbIsLeapYear?(t.year)
  1966.   return [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][t.month - 1]
  1967. end
  1968.  
  1969. def pbFirstDayOfMonth(t)
  1970.   wday = t.wday
  1971.   (t.day - 1).times do
  1972.     wday -= 1
  1973.     wday = 6 if wday < 0
  1974.   end
  1975.   return wday
  1976. end
  1977.  
  1978. class PoketchCalendar < PoketchApp
  1979.   def initialize
  1980.     super
  1981.     @bg.bmp("Graphics/Pictures/Poketch/Calendar/background")
  1982.     @header = []
  1983.     @time = Time.now
  1984.     if @time.month != $Trainer.calendar_month
  1985.       $Trainer.calendar_month = @time.month
  1986.       $Trainer.calendar_marked = []
  1987.     end
  1988.     n = @time.month.to_s.split("")
  1989.     for i in 0...n.size
  1990.       @header[i] = Sprite.new(@viewport)
  1991.       @header[i].bmp("Graphics/Pictures/Poketch/Calendar/numbersheader")
  1992.       @header[i].src_rect.width = 20
  1993.       @header[i].src_rect.x = 20 * n[i].to_i
  1994.       @header[i].x = [[181],[170,192]][n.size - 1][i]
  1995.       @header[i].y = 4
  1996.     end
  1997.     @start = pbFirstDayOfMonth(@time)
  1998.     @days = []
  1999.     for i in @start...(pbGetTotalDays(@time) + @start)
  2000.       idx = i - @start
  2001.       @days[idx] = []
  2002.       @days[idx][0] = Sprite.new(@viewport)
  2003.       w = 12
  2004.       w = 16 if (i % 7) == 0
  2005.       @days[idx][0].bmp("Graphics/Pictures/Poketch/Calendar/#{w == 12 ? "numbers" : "numbersfirst"}")
  2006.       @days[idx][0].src_rect.width = w
  2007.       @days[idx][0].src_rect.x = w * ((i + 1 - @start).to_s.split("")[0].to_i)
  2008.       @days[idx][0].x = 48 + 48 * (i % 7)
  2009.       @days[idx][0].y = 56 + 48 * (i / 7).floor
  2010.       @days[idx][0].z = 4
  2011.       if (i + 1 - @start).to_s.size > 1
  2012.         @days[idx][0].x -= 14
  2013.         @days[idx][0].x -= 4 if i % 7 == 0
  2014.         @days[idx][1] = Sprite.new(@viewport)
  2015.         @days[idx][1].bmp("Graphics/Pictures/Poketch/Calendar/#{w == 12 ? "numbers" : "numbersfirst"}")
  2016.         @days[idx][1].src_rect.width = w
  2017.         @days[idx][1].src_rect.x = w * ((i + 1 - @start).to_s.split("")[1].to_i)
  2018.         @days[idx][1].x = 48 + 48 * (i % 7)
  2019.         @days[idx][1].y = 56 + 48 * (i / 7).floor
  2020.         @days[idx][1].z = 4
  2021.       end
  2022.       @days[idx][2] = Sprite.new(@viewport)
  2023.       if $Trainer.calendar_marked.include?(i + 1 - @start)
  2024.         @days[idx][2].bmp("Graphics/Pictures/Poketch/Calendar/marked")
  2025.         @days[idx][2].z = 3
  2026.       else
  2027.         @days[idx][2].bmp(32,32)
  2028.         @days[idx][2].z = 2
  2029.       end
  2030.       @days[idx][2].x = (@days[idx][1] || @days[idx][0]).x - (i % 7 == 0 ? 14 : 16)
  2031.       @days[idx][2].y = @days[idx][0].y - 8
  2032.       if @time.day == (i + 1 - @start)
  2033.         @days[idx][3] = Sprite.new(@viewport)
  2034.         @days[idx][3].bmp("Graphics/Pictures/Poketch/Calendar/selector")
  2035.         @days[idx][3].x = (@days[idx][1] || @days[idx][0]).x - (w == 16 ? 18 : 20)
  2036.         @days[idx][3].y = @days[idx][0].y - 12
  2037.         @days[idx][3].z = 2
  2038.       end
  2039.       @days[idx][4] = i + 1 - @start
  2040.     end
  2041.   end
  2042.  
  2043.   def toggle_marker(day)
  2044.     @days[day][2] = Sprite.new(@viewport) if !@days[day][2]
  2045.     if @days[day][2].z == 2
  2046.       @days[day][2].bmp("Graphics/Pictures/Poketch/Calendar/marked")
  2047.       @days[day][2].z = 3
  2048.     else
  2049.       @days[day][2].bmp(32,32)
  2050.       @days[day][2].z = 2
  2051.     end
  2052.     @days[day][2].x = (@days[day][1] || @days[day][0]).x - ((@days[day][1] || @days[day][0]).x == 48 ? 14 : 16)
  2053.     @days[day][2].y = @days[day][0].y - 8
  2054.   end
  2055.  
  2056.   def update
  2057.     $Trainer.calendar_marked.clear
  2058.     for i in 0...@days.size
  2059.       toggle_marker(i) if $mouse.click?(@days[i][2])
  2060.       $Trainer.calendar_marked << @days[i][4] if @days[i][2].z == 3
  2061.     end
  2062.   end
  2063.  
  2064.   def dispose
  2065.     for day in @days
  2066.       day[0].dispose if day[0]
  2067.       day[1].dispose if day[1]
  2068.       day[2].dispose if day[2]
  2069.       day[3].dispose if day[3]
  2070.     end
  2071.     super
  2072.   end
  2073. end
  2074.  
  2075.  
  2076. #==============================================================================#
  2077. # Pokétch Coin Flip. Flip a coin.                                              #
  2078. #==============================================================================#
  2079. class PoketchCoinFlip < PoketchApp
  2080.   def initialize
  2081.     super
  2082.     @bg.bmp("Graphics/Pictures/Poketch/Coin Flip/background")
  2083.     @coin = Sprite.new(@viewport)
  2084.     @coin.x = 128
  2085.     set(192,"front")
  2086.     @idle = true
  2087.     @i = 0
  2088.   end
  2089.  
  2090.   def set(y, path = nil)
  2091.     @coin.y = y
  2092.     @coin.bmp("Graphics/Pictures/Poketch/Coin Flip/#{path}") if path
  2093.   end
  2094.  
  2095.   def update
  2096.     if @idle && $mouse.click?(@coin)
  2097.       @idle = false
  2098.     end
  2099.     if !@idle
  2100.       @i += 1
  2101.       # Yep. This is the whole animation.
  2102.       case @i
  2103.       when 1..2
  2104.         set(172)
  2105.       when 3..4
  2106.         set(170,"middle")
  2107.       when 5..6
  2108.         set(120,"back")
  2109.       when 7..8
  2110.         set(122,"middle")
  2111.       when 9..10
  2112.         set(62,"front")
  2113.       when 11..12
  2114.         set(80,"middle")
  2115.       when 13..14
  2116.         set(72)
  2117.       when 15..16
  2118.         set(30,"back")
  2119.       when 17..18
  2120.         set(58,"middle")
  2121.       when 19..20
  2122.         set(22,"front")
  2123.       when 21..22
  2124.         set(64,"middle")
  2125.       when 23..24
  2126.         set(44,"back")
  2127.       when 25..26
  2128.         set(92,"middle")
  2129.       when 27..28
  2130.         set(80,"front")
  2131.       when 29..30
  2132.         set(144,"middle")
  2133.       when 31..32
  2134.         set(146,"back")
  2135.       when 33..34
  2136.         set(216,"middle")
  2137.       when 35..36
  2138.         set(192,"front")
  2139.       when 37..38
  2140.         set(204,"middle")
  2141.       when 39..40
  2142.         set(152,"back")
  2143.       when 41..42
  2144.         set(172,"middle")
  2145.       when 43..44
  2146.         set(128,"front")
  2147.       when 45..46
  2148.         set(162,"middle")
  2149.       when 47..48
  2150.         set(132,"back")
  2151.       when 49..50
  2152.         set(172,"middle")
  2153.       when 51..52
  2154.         set(180)
  2155.       when 53..54
  2156.         set(160,"front")
  2157.       when 55..56
  2158.         set(218,"middle")
  2159.       when 57..58
  2160.         set(188,"back")
  2161.       when 59..60
  2162.         set(214,"middle")
  2163.       when 61..62
  2164.         set(168,"front")
  2165.       when 63..64
  2166.         set(200,"middle")
  2167.       when 65..66
  2168.         set(170,"back")
  2169.       when 67..68
  2170.         set(208,"middle")
  2171.       when 69..70
  2172.         set(184,"front")
  2173.       when 71..72
  2174.         set(222,"middle")
  2175.       when 73..74
  2176.         set(184,"back")
  2177.       when 75..76
  2178.         set(214,"middle")
  2179.       when 77..78
  2180.         set(182,["front","back"][rand(2)])
  2181.         @i = 0
  2182.         @idle = true
  2183.       end
  2184.       # Yeah, it was fun extracting the official animation's frames one by one.
  2185.     end
  2186.   end
  2187.  
  2188.   def dispose
  2189.     @coin.dispose
  2190.     super
  2191.   end
  2192. end
  2193.  
  2194.  
  2195. #==============================================================================#
  2196. # Pokétch Stopwatch. Counts up instead of down.                                #
  2197. #==============================================================================#
  2198. class PokemonTemp
  2199.   attr_accessor :stopwatch_running
  2200.   attr_accessor :stopwatch_seconds
  2201.   attr_accessor :stopwatch_ms
  2202. end
  2203.  
  2204. module Graphics
  2205.   class << Graphics
  2206.     alias poketch_stopwatch_update update
  2207.   end
  2208.  
  2209.   def self.update
  2210.     poketch_stopwatch_update
  2211.     return if !$Poketch
  2212.     return if !$PokemonTemp.stopwatch_running
  2213.     return if !$PokemonTemp || !$PokemonTemp.stopwatch_seconds || !$PokemonTemp.stopwatch_ms
  2214.     if Graphics.frame_count % Graphics.frame_rate == 0
  2215.       $PokemonTemp.stopwatch_seconds += 1
  2216.       $PokemonTemp.stopwatch_ms = 0
  2217.     end
  2218.     # Typically ends up being "+= 100.0 / 40.0", so "+= 2.5"
  2219.     $PokemonTemp.stopwatch_ms += 100.0 / Graphics.frame_rate.to_f
  2220.     $Poketch.app.refresh if $Poketch && $Poketch.app.is_a?(PoketchStopwatch)
  2221.   end
  2222. end
  2223.  
  2224. class PoketchStopwatch < PoketchApp
  2225.   def initialize
  2226.     super
  2227.     @bg.bmp("Graphics/Pictures/Poketch/Stopwatch/background")
  2228.     $PokemonTemp.stopwatch_running = false
  2229.     $PokemonTemp.stopwatch_seconds = 0
  2230.     $PokemonTemp.stopwatch_ms = 0
  2231.     @numbers = []
  2232.     @voltorb = Sprite.new(@viewport)
  2233.     @voltorb.bmp("Graphics/Pictures/Poketch/Stopwatch/idle")
  2234.     @voltorb.ox = @voltorb.bitmap.width / 2
  2235.     @voltorb.oy = @voltorb.bitmap.height / 2
  2236.     @voltorb.x = 192
  2237.     @voltorb.y = 200
  2238.     @i = 1
  2239.     refresh
  2240.   end
  2241.  
  2242.   def refresh
  2243.     s = $PokemonTemp.stopwatch_seconds % 60
  2244.     m = ($PokemonTemp.stopwatch_seconds / 60).floor % 60
  2245.     h = (($PokemonTemp.stopwatch_seconds / 60).floor / 60).floor
  2246.     n = [pbFormat(h,2).split(""),pbFormat(m,2).split(""),pbFormat(s,2).split(""),
  2247.         pbFormat($PokemonTemp.stopwatch_ms,2).split("")]
  2248.     for i in 0...8
  2249.       @numbers[i].dispose if @numbers[i]
  2250.       @numbers[i] = nil
  2251.       @numbers[i] = Sprite.new(@viewport)
  2252.       @numbers[i].bmp("Graphics/Pictures/Poketch/Stopwatch/numbers")
  2253.       @numbers[i].src_rect.width = 24
  2254.       @numbers[i].src_rect.x = 24 * n[(i / 2).floor][i % 2].to_i
  2255.       @numbers[i].x = [20,52,116,148,212,244,308,340][i]
  2256.       @numbers[i].y = 16
  2257.     end
  2258.   end
  2259.  
  2260.   def update
  2261.     @cooldown -= 1 if @cooldown > -1
  2262.     if @cooldown == -1 && @click
  2263.       @voltorb.bmp("Graphics/Pictures/Poketch/Stopwatch/#{@click}")
  2264.       @voltorb.ox = @voltorb.bitmap.width / 2
  2265.       @voltorb.oy = @voltorb.bitmap.height / 2
  2266.       $PokemonTemp.stopwatch_running = true if @click.include?("active")
  2267.       @click = nil
  2268.       @cooldown = 1
  2269.     end
  2270.     if !$PokemonTemp.stopwatch_running
  2271.       if $mouse.click?(@voltorb)
  2272.         @voltorb.bmp("Graphics/Pictures/Poketch/Stopwatch/click")
  2273.         @voltorb.ox = @voltorb.bitmap.width / 2
  2274.         @voltorb.oy = @voltorb.bitmap.height / 2
  2275.         @cooldown = 2
  2276.         @click = "active#{@i}"
  2277.       end
  2278.     else
  2279.       if @cooldown == -1 && !@click
  2280.         @voltorb.bmp("Graphics/Pictures/Poketch/Stopwatch/active#{@i}")
  2281.         if @i == 1
  2282.           @i = 2
  2283.         else
  2284.           @i = 1
  2285.         end
  2286.         @voltorb.ox = @voltorb.bitmap.width / 2
  2287.         @voltorb.oy = @voltorb.bitmap.height / 2
  2288.         @cooldown = 2
  2289.       end
  2290.       if $mouse.click?(@voltorb)
  2291.         $PokemonTemp.stopwatch_running = false
  2292.         @voltorb.bmp("Graphics/Pictures/Poketch/Stopwatch/click")
  2293.         @voltorb.ox = @voltorb.bitmap.width / 2
  2294.         @voltorb.oy = @voltorb.bitmap.height / 2
  2295.         @cooldown = 2
  2296.         @click = "idle"
  2297.       end
  2298.     end
  2299.   end
  2300.  
  2301.   def dispose
  2302.     @voltorb.dispose
  2303.     for n in @numbers
  2304.       n.dispose
  2305.     end
  2306.     $PokemonTemp.stopwatch_running = false
  2307.     $PokemonTemp.stopwatch_seconds = 0
  2308.     $PokemonTemp.stopwatch_ms = 0
  2309.     super
  2310.   end
  2311. end
  2312.  
  2313.  
  2314. #==============================================================================#
  2315. # Pokéch Notepad. You can write stuff down here.                               #
  2316. #==============================================================================#
  2317. class PokeBattle_Trainer
  2318.   attr_accessor :poketch_note
  2319. end
  2320.  
  2321. class PoketchNotepad < PoketchApp
  2322.   # 0x00 format: UTF-8 Hex
  2323.   # 000  format: JavaScript Keycodes
  2324.   BUTTONS = {
  2325.     0x41 => ["a","A"],
  2326.     0x42 => ["b","B"],
  2327.     0x43 => ["c","C"],
  2328.     0x44 => ["d","D"],
  2329.     0x45 => ["e","E"],
  2330.     0x46 => ["f","F"],
  2331.     0x47 => ["g","G"],
  2332.     0x48 => ["h","H"],
  2333.     0x49 => ["i","I"],
  2334.     0x4A => ["j","J"],
  2335.     0x4B => ["k","K"],
  2336.     0x4C => ["l","L"],
  2337.     0x4D => ["m","M"],
  2338.     0x4E => ["n","N"],
  2339.     0x4F => ["o","O"],
  2340.     0x50 => ["p","P"],
  2341.     0x51 => ["q","Q"],
  2342.     0x52 => ["r","R"],
  2343.     0x53 => ["s","S"],
  2344.     0x54 => ["t","T"],
  2345.     0x55 => ["u","U"],
  2346.     0x56 => ["v","V"],
  2347.     0x57 => ["w","W"],
  2348.     0x58 => ["x","X"],
  2349.     0x59 => ["y","Y"],
  2350.     0x5A => ["z","Z"],
  2351.     0x20 => [" "," "],
  2352.     0x30 => ["0",")"],
  2353.     0x31 => ["1","!"],
  2354.     0x32 => ["2","@"],
  2355.     0x33 => ["3","#"],
  2356.     0x34 => ["4","$"],
  2357.     0x35 => ["5","%"],
  2358.     0x36 => ["6","^"],
  2359.     0x37 => ["7","&"],
  2360.     0x38 => ["8","*"],
  2361.     0x39 => ["9","("],
  2362.     189  => ["-","_"],
  2363.     187  => ["=","+"],
  2364.     188  => [",","<"],
  2365.     190  => [".",">"],
  2366.     191  => ["/","?"],
  2367.     222  => ["'", '"'],
  2368.     219  => ["[","{"],
  2369.     221  => ["]","}"],
  2370.     13   => ["\n","\n"],
  2371.     186  => [";",":"],
  2372.     192  => ["`","~"],
  2373.     220  => ["\\","|"]
  2374.   }
  2375.  
  2376.   def initialize
  2377.     super
  2378.     @bg.bmp("Graphics/Pictures/Poketch/Notepad/background")
  2379.     @pencil = Sprite.new(@viewport)
  2380.     @pencil.bmp("Graphics/Pictures/Poketch/Notepad/btn")
  2381.     @pencil.x = 320
  2382.     @pencil.y = 84
  2383.     @drawing = false
  2384.     @bmp = Sprite.new(@viewport)
  2385.     @bmp.x = 16
  2386.     @bmp.y = 24
  2387.     @txt = $Trainer.poketch_note || ""
  2388.     draw_text
  2389.   end
  2390.  
  2391.   def update
  2392.     if $mouse.click?(@pencil)
  2393.       @drawing = true
  2394.       @pencil.bmp("Graphics/Pictures/Poketch/Notepad/btnClick")
  2395.     end
  2396.     if @drawing
  2397.       loop do
  2398.         @cooldown -= 1 if @cooldown > -1
  2399.         Graphics.update
  2400.         Input.update
  2401.         oldtxt = @txt
  2402.         for key in BUTTONS.keys
  2403.           if Input.triggerex?(key)
  2404.             @txt += BUTTONS[key][Input.press?(Input::SHIFT) || Input.press?(20) ? 1 : 0]
  2405.           end
  2406.         end
  2407.         # Special
  2408.         if @cooldown == -1 && Input.pressex?(0x08) # Backspace
  2409.           @txt.chop!
  2410.           draw_text
  2411.           @cooldown = 5
  2412.         end
  2413.         draw_text if oldtxt != @txt
  2414.         if $mouse.click?(@pencil)
  2415.           @drawing = false
  2416.           @pencil.bmp("Graphics/Pictures/Poketch/Notepad/btn")
  2417.           break
  2418.         end
  2419.         if $mouse.click?($Poketch.btnUp)
  2420.           $Poketch.click_up
  2421.           break
  2422.         end
  2423.         if $mouse.click?($Poketch.btnDown)
  2424.           $Poketch.click_down
  2425.           break
  2426.         end
  2427.       end
  2428.     end
  2429.   end
  2430.  
  2431.   def draw_text
  2432.     @bmp.bitmap = nil
  2433.     @bmp.bmp(276,268)
  2434.     pbSetSystemFont(@bmp.bitmap)
  2435.     drawTextEx(@bmp.bitmap,0,0,276,8,@txt,Color.new(16,41,24),Color.new(57,82,49))
  2436.     $Trainer.poketch_note = @txt
  2437.   end
  2438.  
  2439.   def dispose
  2440.     @pencil.dispose
  2441.     super
  2442.   end
  2443. end
  2444.  
  2445.  
  2446. #==============================================================================#
  2447. # Pokétch Alarm Clock.                                                         #
  2448. #==============================================================================#
  2449. class PokeBattle_Trainer
  2450.   attr_accessor :poketch_alarm
  2451.   attr_accessor :poketch_alarm_running
  2452. end
  2453.  
  2454. class PoketchAlarmClock < PoketchApp
  2455.   def initialize
  2456.     super
  2457.     @bg.bmp("Graphics/Pictures/Poketch/Alarm Clock/background1")
  2458.     @numbers = []
  2459.     $Trainer.poketch_alarm = 0 if !$Trainer.poketch_alarm
  2460.     $Trainer.poketch_alarm_running = false if !$Trainer.poketch_alarm_running
  2461.     draw_time($Trainer.poketch_alarm)
  2462.     @arrows = []
  2463.     for i in 0...4
  2464.       @arrows[i] = Sprite.new(@viewport)
  2465.       path = "arrow" + (i < 2 ? "Up" : "Down")
  2466.       @arrows[i].bmp("Graphics/Pictures/Poketch/Alarm Clock/#{path}")
  2467.       @arrows[i].x = [88,184][i % 2]
  2468.       @arrows[i].y = [184,284][(i / 2).floor]
  2469.     end
  2470.     @running = false
  2471.     @btns = []
  2472.     @btns[0] = Sprite.new(@viewport)
  2473.     @btns[0].bmp("Graphics/Pictures/Poketch/Alarm Clock/btn")
  2474.     @btns[0].x = 324
  2475.     @btns[0].y = 116
  2476.     @btns[1] = Sprite.new(@viewport)
  2477.     @btns[1].bmp("Graphics/Pictures/Poketch/Alarm Clock/btnClick")
  2478.     @btns[1].x = 324
  2479.     @btns[1].y = 180
  2480.     @time = Time.now
  2481.     @i = -1
  2482.     set_running if $Trainer.poketch_alarm_running
  2483.   end
  2484.  
  2485.   def draw_time(mins)
  2486.     n = pbFormat((mins / 60).floor, 2).split("")
  2487.     n.concat(pbFormat(mins % 60, 2).split(""))
  2488.     for i in 0...4
  2489.       @numbers[i].dispose if @numbers[i]
  2490.       @numbers[i] = nil
  2491.       @numbers[i] = Sprite.new(@viewport)
  2492.       @numbers[i].bmp("Graphics/Pictures/Poketch/Alarm Clock/numbers")
  2493.       @numbers[i].src_rect.width = 24
  2494.       @numbers[i].src_rect.x = 24 * n[i].to_i
  2495.       @numbers[i].x = [84,116,180,212][i]
  2496.       @numbers[i].y = 224
  2497.     end
  2498.   end
  2499.  
  2500.   def update
  2501.     @i += 1
  2502.     if !@running
  2503.       for i in 0...4
  2504.         @arrows[i].visible = @i < 24
  2505.       end
  2506.       @i = 0 if @i == 47
  2507.       oldt = $Trainer.poketch_alarm
  2508.       if $mouse.click?(@arrows[0])
  2509.         $Trainer.poketch_alarm += 60
  2510.         $Trainer.poketch_alarm -= 1440 if $Trainer.poketch_alarm >= 1440
  2511.       end
  2512.       if $mouse.click?(@arrows[1])
  2513.         $Trainer.poketch_alarm += 1
  2514.         $Trainer.poketch_alarm -= 60 if $Trainer.poketch_alarm % 60 == 0
  2515.       end
  2516.       if $mouse.click?(@arrows[2])
  2517.         $Trainer.poketch_alarm -= 60
  2518.         $Trainer.poketch_alarm += 1440 if $Trainer.poketch_alarm < 0
  2519.       end
  2520.       if $mouse.click?(@arrows[3])
  2521.         $Trainer.poketch_alarm -= 1
  2522.         $Trainer.poketch_alarm += 60 if $Trainer.poketch_alarm % 60 == 59
  2523.       end
  2524.       draw_time($Trainer.poketch_alarm) if oldt != $Trainer.poketch_alarm
  2525.     else
  2526.       if @time.hour != Time.now.hour || @time.min != Time.now.min
  2527.         @time = Time.now
  2528.         @sum = @time.min + @time.hour * 60
  2529.         draw_time(@sum)
  2530.         @i = 0 if @sum == $Trainer.poketch_alarm
  2531.       end
  2532.       if @sum == $Trainer.poketch_alarm
  2533.         if @i % 6 == 0
  2534.           @bg.bmp("Graphics/Pictures/Poketch/Alarm Clock/background3")
  2535.         elsif @i % 3 == 0
  2536.           @bg.bmp("Graphics/Pictures/Poketch/Alarm Clock/background4")
  2537.         end
  2538.         @alarm = true
  2539.         if @i == 18
  2540.           for i in 0...4
  2541.             @numbers[i].visible = !@numbers[i].visible
  2542.           end
  2543.           @i = 0
  2544.         end
  2545.       elsif @alarm
  2546.         @bg.bmp("Graphics/Pictures/Poketch/Alarm Clock/background2")
  2547.         @alarm = false
  2548.         for i in 0...4
  2549.           @numbers[i].visible = true
  2550.         end
  2551.       end
  2552.     end
  2553.     if !@running && $mouse.click?(@btns[0])
  2554.       set_running
  2555.     end
  2556.     if @running && $mouse.click?(@btns[1])
  2557.       $Trainer.poketch_alarm_running = false
  2558.       @bg.bmp("Graphics/Pictures/Poketch/Alarm Clock/background1")
  2559.       @btns[0].bmp("Graphics/Pictures/Poketch/Alarm Clock/btn")
  2560.       @btns[1].bmp("Graphics/Pictures/Poketch/Alarm Clock/btnClick")
  2561.       @running = false
  2562.       @i = 0
  2563.       @time = Time.now
  2564.       draw_time($Trainer.poketch_alarm)
  2565.     end
  2566.   end
  2567.  
  2568.   def set_running
  2569.     $Trainer.poketch_alarm_running = true
  2570.     @bg.bmp("Graphics/Pictures/Poketch/Alarm Clock/background2")
  2571.     @running = true
  2572.     for i in 0...4
  2573.       @arrows[i].visible = false
  2574.     end
  2575.     @time = Time.now
  2576.     @sum = @time.min + @time.hour * 60
  2577.     draw_time(@sum)
  2578.     @btns[0].bmp("Graphics/Pictures/Poketch/Alarm Clock/btnClick")
  2579.     @btns[1].bmp("Graphics/Pictures/Poketch/Alarm Clock/btn")
  2580.     @i = 0 if @sum == $Trainer.poketch_alarm
  2581.   end
  2582.  
  2583.   def dispose
  2584.     for btn in @btns
  2585.       btn.dispose
  2586.     end
  2587.     for n in @numbers
  2588.       n.dispose
  2589.     end
  2590.     for arrow in @arrows
  2591.       arrow.dispose
  2592.     end
  2593.     super
  2594.   end
  2595. end
  2596.  
  2597.  
  2598. #==============================================================================#
  2599. # Pokétch Safari Helper. Shows you some things like steps and balls left.      #
  2600. #==============================================================================#
  2601. class PoketchSafariHelper < PoketchApp
  2602.   def self.usable? # Only usable when in the Safari Zone
  2603.     return pbSafariState && pbSafariState.inProgress?
  2604.   end
  2605.  
  2606.   def initialize
  2607.     super
  2608.     @bg.bmp("Graphics/Pictures/Poketch/Safari Helper/background")
  2609.     @exit = Sprite.new(@viewport)
  2610.     @exit.bmp("Graphics/Pictures/Poketch/Safari Helper/exit")
  2611.     @exit.x = 284
  2612.     @exit.y = 208
  2613.     @balls = pbSafariState.ballcount
  2614.     @steps = pbSafariState.steps
  2615.     @ballsprites = []
  2616.     @stepsprites = []
  2617.     draw_balls
  2618.     draw_steps
  2619.   end
  2620.  
  2621.   def update
  2622.     super
  2623.     if @balls != pbSafariState.ballcount
  2624.       @balls = pbSafariState.ballcount
  2625.       draw_balls
  2626.     end
  2627.     if @steps != pbSafariState.steps
  2628.       @steps = pbSafariState.steps
  2629.       draw_steps
  2630.     end
  2631.     if click?(@exit,"Graphics/Pictures/Poketch/Safari Helper","exit")
  2632.       if Kernel.pbConfirmMessage(_INTL("Would you like to leave the Safari Game right now?"))
  2633.         pbSafariState.decision = 1
  2634.         pbSafariState.pbGoToStart
  2635.         $Poketch.click_down(false)
  2636.       end
  2637.     end
  2638.   end
  2639.  
  2640.   def draw_balls
  2641.     n = pbFormat(@balls, 2).split("")
  2642.     for i in 0...2
  2643.       @ballsprites[i].dispose if @ballsprites[i]
  2644.       @ballsprites[i] = nil
  2645.       @ballsprites[i] = Sprite.new(@viewport)
  2646.       @ballsprites[i].bmp("Graphics/Pictures/Poketch/Safari Helper/numbers")
  2647.       @ballsprites[i].src_rect.width = 24
  2648.       @ballsprites[i].src_rect.x = 24 * n[i].to_i
  2649.       @ballsprites[i].x = [100,132][i]
  2650.       @ballsprites[i].y = 27
  2651.     end
  2652.   end
  2653.  
  2654.   def draw_steps
  2655.     n = pbFormat(@steps).split("")
  2656.     for i in 0...3
  2657.       @stepsprites[i].dispose if @stepsprites[i]
  2658.       @stepsprites[i] = nil
  2659.       @stepsprites[i] = Sprite.new(@viewport)
  2660.       @stepsprites[i].bmp("Graphics/Pictures/Poketch/Safari Helper/numbers")
  2661.       @stepsprites[i].src_rect.width = 24
  2662.       @stepsprites[i].src_rect.x = 24 * n[i].to_i
  2663.       @stepsprites[i].x = [279,311,343][i]
  2664.       @stepsprites[i].y = 27
  2665.     end
  2666.   end
  2667.  
  2668.   def dispose
  2669.     for b in @ballsprites
  2670.       b.dispose
  2671.     end
  2672.     for s in @stepsprites
  2673.       s.dispose
  2674.     end
  2675.     @exit.dispose
  2676.     super
  2677.   end
  2678. end
  2679.  
  2680.  
  2681. #==============================================================================#
  2682. # All apps. To make a new app, you have to register it in this module.         #
  2683. # This is also the displayed order of the apps. The names are the class names. #
  2684. # The numbers you see after the name of an app is that app's ID.               #
  2685. # If you want to enable/disable an app, rather than looking up the ID, you     #
  2686. # could do something like "pbEnableApp(PoketchApps::PoketchNotepad)"           #
  2687. #==============================================================================#
  2688. module PoketchApps
  2689.   PoketchClock          = 0
  2690.   PoketchClicker        = 1
  2691.   PoketchCalculator     = 2
  2692.   PoketchPedometer      = 3
  2693.   PoketchItemFinder     = 4
  2694.   PoketchMoveTester     = 5
  2695.   PoketchRotom          = 6
  2696.   PoketchMarkingMap     = 7
  2697.   PoketchMatchupChecker = 8
  2698.   PoketchParty          = 9
  2699.   PoketchColorChanger   = 10
  2700.   PoketchKitchenTimer   = 11
  2701.   PoketchAnalogWatch    = 12
  2702.   PoketchStatDisplay    = 13
  2703.   PoketchRoulette       = 14
  2704.   PoketchDayCareChecker = 15
  2705.   PoketchPokemonHistory = 16
  2706.   PoketchCalendar       = 17
  2707.   PoketchCoinFlip       = 18
  2708.   PoketchStopwatch      = 19
  2709.   PoketchNotepad        = 20
  2710.   PoketchAlarmClock     = 21
  2711.   PoketchSafariHelper   = 22
  2712. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top