Advertisement
M3rein

Pokétch_Apps

Oct 18th, 2017
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 83.10 KB | None | 0 0
  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 $Trainer.pokemonhistory.size > 0 &&
  1830.          isConst?($Trainer.pokemonhistory[$Trainer.pokemonhistory.size - 1].species,
  1831.          PBSpecies,:NINJASK) && isConst?(pokemon.species,PBSpecies,:SHEDINJA)
  1832.     for i in 0...$Trainer.pokemonhistory.size
  1833.       if $Trainer.pokemonhistory[i].personalID == pokemon.personalID
  1834.         $Trainer.pokemonhistory[i] = nil
  1835.         break
  1836.       end
  1837.     end
  1838.   end
  1839.   $Trainer.pokemonhistory.compact!
  1840.   $Trainer.pokemonhistory << pokemon.clone
  1841.   $Poketch.app.refresh if $Poketch && $Poketch.app.is_a?(PoketchPokemonHistory)
  1842. end
  1843.  
  1844. # Registers traded Pokémon to $Trainer.pokemonhistory
  1845. if defined?(PokemonTrade_Scene)
  1846.   class PokemonTrade_Scene
  1847.     alias poketch_trade pbTrade
  1848.     def pbTrade
  1849.       poketch_trade
  1850.       pbPushHistory(@pokemon2)
  1851.     end
  1852.   end
  1853. else
  1854.   class PokemonTradeScene
  1855.     alias poketch_trade pbTrade
  1856.     def pbTrade
  1857.       poketch_trade
  1858.       pbPushHistory(@pokemon2)
  1859.     end
  1860.   end
  1861. end
  1862.  
  1863. # Registers evolved Pokémon to $Trainer.pokemonhistory
  1864. class PokemonTemp
  1865.   attr_accessor :registerOnCalc
  1866. end
  1867.  
  1868. class PokeBattle_Pokemon
  1869.   alias poketch_calcStats calcStats
  1870.   def calcStats
  1871.     poketch_calcStats
  1872.     pbPushHistory(self) if $PokemonTemp.registerOnCalc
  1873.   end
  1874. end
  1875.  
  1876. class PokemonEvolutionScene
  1877.   alias poketch_evolution pbEvolution
  1878.   def pbEvolution(cancancel = true)
  1879.     $PokemonTemp.registerOnCalc = true
  1880.     poketch_evolution(cancancel)
  1881.     $PokemonTemp.registerOnCalc = false
  1882.   end
  1883. end
  1884.  
  1885. # Registers hatched Pokémon to $Trainer.pokemonhistory
  1886. alias poketch_hatch pbHatch
  1887. def pbHatch(pokemon)
  1888.   poketch_hatch(pokemon)
  1889.   pbPushHistory(pokemon)
  1890. end
  1891.  
  1892. # Registers caught Pokémon to $Trainer.pokemonhistory
  1893. module PokeBattle_BattleCommon
  1894.   alias poketch_store pbStorePokemon
  1895.   def pbStorePokemon(pokemon)
  1896.     poketch_store(pokemon)
  1897.     pbPushHistory(pokemon)
  1898.   end
  1899. end
  1900. #========= End all handling Pokémon History tracking =========#
  1901.  
  1902. class PoketchPokemonHistory < PoketchApp
  1903.   def initialize
  1904.     super
  1905.     @bg.bmp("Graphics/Pictures/Poketch/Pokemon History/background")
  1906.     @pokemon = []
  1907.     refresh
  1908.   end
  1909.  
  1910.   def update
  1911.     for p in @pokemon
  1912.       if $mouse.click?(p[0])
  1913.         pbPlayCry(p[1])
  1914.       end
  1915.     end
  1916.     $Poketch.click_up if $mouse.click?($Poketch.btnUp) # Didn't work apparently
  1917.     $Poketch.click_down if $mouse.click?($Poketch.btnDown) # Didn't work apparently
  1918.   end
  1919.  
  1920.   def refresh
  1921.     ret = $Trainer.pokemonhistory.clone
  1922.     if $Trainer.pokemonhistory.size > 12
  1923.       ret = $Trainer.pokemonhistory[-12,12]
  1924.     end
  1925.     ret.reverse!
  1926.     for i in 0...12
  1927.       @pokemon[i] = [] if !@pokemon[i]
  1928.       @pokemon[i][0].dispose if @pokemon[i][0]
  1929.       if i <= ret.size - 1
  1930.         @pokemon[i][0] = Sprite.new(@viewport)
  1931.         @pokemon[i][0].bmp("Graphics/Icons/icon#{pbFormat(ret[i].species)}")
  1932.         @pokemon[i][0].poketch_average
  1933.         @pokemon[i][0].src_rect.width = @pokemon[i][0].bitmap.width / 2
  1934.         @pokemon[i][0].zoom_x = 1.5
  1935.         @pokemon[i][0].zoom_y = 1.5
  1936.         @pokemon[i][0].ox = @pokemon[i][0].bitmap.width / 4
  1937.         @pokemon[i][0].oy = @pokemon[i][0].bitmap.height / 2
  1938.         @pokemon[i][0].x = [64,144,224,304][i % 4]
  1939.         @pokemon[i][0].y = [82,168,256][(i / 4).floor]
  1940.         @pokemon[i][1] = ret[i].species
  1941.       end
  1942.     end
  1943.   end
  1944.  
  1945.   def dispose
  1946.     for p in @pokemon
  1947.       p[0].dispose if p[0]
  1948.     end
  1949.     @pokemon.clear
  1950.     super
  1951.   end
  1952. end
  1953.  
  1954.  
  1955. #==============================================================================#
  1956. # Pokétch Calendar. Shows you the days of this month.                          #
  1957. #==============================================================================#
  1958. class PokeBattle_Trainer
  1959.   attr_accessor :calendar_month
  1960.   attr_accessor :calendar_marked
  1961. end
  1962.  
  1963. def pbIsLeapYear?(y)
  1964.   return (y % 4 == 0) && !(y % 100 == 0) || (y % 400 == 0)
  1965. end
  1966.  
  1967. def pbGetTotalDays(t)
  1968.   return 29 if t.month == 2 && pbIsLeapYear?(t.year)
  1969.   return [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][t.month - 1]
  1970. end
  1971.  
  1972. def pbFirstDayOfMonth(t)
  1973.   wday = t.wday
  1974.   (t.day - 1).times do
  1975.     wday -= 1
  1976.     wday = 6 if wday < 0
  1977.   end
  1978.   return wday
  1979. end
  1980.  
  1981. class PoketchCalendar < PoketchApp
  1982.   def initialize
  1983.     super
  1984.     @bg.bmp("Graphics/Pictures/Poketch/Calendar/background")
  1985.     @header = []
  1986.     @time = Time.now
  1987.     if @time.month != $Trainer.calendar_month
  1988.       $Trainer.calendar_month = @time.month
  1989.       $Trainer.calendar_marked = []
  1990.     end
  1991.     n = @time.month.to_s.split("")
  1992.     for i in 0...n.size
  1993.       @header[i] = Sprite.new(@viewport)
  1994.       @header[i].bmp("Graphics/Pictures/Poketch/Calendar/numbersheader")
  1995.       @header[i].src_rect.width = 20
  1996.       @header[i].src_rect.x = 20 * n[i].to_i
  1997.       @header[i].x = [[181],[170,192]][n.size - 1][i]
  1998.       @header[i].y = 4
  1999.     end
  2000.     @start = pbFirstDayOfMonth(@time)
  2001.     @days = []
  2002.     for i in @start...(pbGetTotalDays(@time) + @start)
  2003.       idx = i - @start
  2004.       @days[idx] = []
  2005.       @days[idx][0] = Sprite.new(@viewport)
  2006.       w = 12
  2007.       w = 16 if (i % 7) == 0
  2008.       @days[idx][0].bmp("Graphics/Pictures/Poketch/Calendar/#{w == 12 ? "numbers" : "numbersfirst"}")
  2009.       @days[idx][0].src_rect.width = w
  2010.       @days[idx][0].src_rect.x = w * ((i + 1 - @start).to_s.split("")[0].to_i)
  2011.       @days[idx][0].x = 48 + 48 * (i % 7)
  2012.       @days[idx][0].y = 56 + 48 * (i / 7).floor
  2013.       @days[idx][0].z = 4
  2014.       if (i + 1 - @start).to_s.size > 1
  2015.         @days[idx][0].x -= 14
  2016.         @days[idx][0].x -= 4 if i % 7 == 0
  2017.         @days[idx][1] = Sprite.new(@viewport)
  2018.         @days[idx][1].bmp("Graphics/Pictures/Poketch/Calendar/#{w == 12 ? "numbers" : "numbersfirst"}")
  2019.         @days[idx][1].src_rect.width = w
  2020.         @days[idx][1].src_rect.x = w * ((i + 1 - @start).to_s.split("")[1].to_i)
  2021.         @days[idx][1].x = 48 + 48 * (i % 7)
  2022.         @days[idx][1].y = 56 + 48 * (i / 7).floor
  2023.         @days[idx][1].z = 4
  2024.       end
  2025.       @days[idx][2] = Sprite.new(@viewport)
  2026.       if $Trainer.calendar_marked.include?(i + 1 - @start)
  2027.         @days[idx][2].bmp("Graphics/Pictures/Poketch/Calendar/marked")
  2028.         @days[idx][2].z = 3
  2029.       else
  2030.         @days[idx][2].bmp(32,32)
  2031.         @days[idx][2].z = 2
  2032.       end
  2033.       @days[idx][2].x = (@days[idx][1] || @days[idx][0]).x - (i % 7 == 0 ? 14 : 16)
  2034.       @days[idx][2].y = @days[idx][0].y - 8
  2035.       if @time.day == (i + 1 - @start)
  2036.         @days[idx][3] = Sprite.new(@viewport)
  2037.         @days[idx][3].bmp("Graphics/Pictures/Poketch/Calendar/selector")
  2038.         @days[idx][3].x = (@days[idx][1] || @days[idx][0]).x - (w == 16 ? 18 : 20)
  2039.         @days[idx][3].y = @days[idx][0].y - 12
  2040.         @days[idx][3].z = 2
  2041.       end
  2042.       @days[idx][4] = i + 1 - @start
  2043.     end
  2044.   end
  2045.  
  2046.   def toggle_marker(day)
  2047.     @days[day][2] = Sprite.new(@viewport) if !@days[day][2]
  2048.     if @days[day][2].z == 2
  2049.       @days[day][2].bmp("Graphics/Pictures/Poketch/Calendar/marked")
  2050.       @days[day][2].z = 3
  2051.     else
  2052.       @days[day][2].bmp(32,32)
  2053.       @days[day][2].z = 2
  2054.     end
  2055.     @days[day][2].x = (@days[day][1] || @days[day][0]).x - ((@days[day][1] || @days[day][0]).x == 48 ? 14 : 16)
  2056.     @days[day][2].y = @days[day][0].y - 8
  2057.   end
  2058.  
  2059.   def update
  2060.     $Trainer.calendar_marked.clear
  2061.     for i in 0...@days.size
  2062.       toggle_marker(i) if $mouse.click?(@days[i][2])
  2063.       $Trainer.calendar_marked << @days[i][4] if @days[i][2].z == 3
  2064.     end
  2065.   end
  2066.  
  2067.   def dispose
  2068.     for day in @days
  2069.       day[0].dispose if day[0]
  2070.       day[1].dispose if day[1]
  2071.       day[2].dispose if day[2]
  2072.       day[3].dispose if day[3]
  2073.     end
  2074.     super
  2075.   end
  2076. end
  2077.  
  2078.  
  2079. #==============================================================================#
  2080. # Pokétch Coin Flip. Flip a coin.                                              #
  2081. #==============================================================================#
  2082. class PoketchCoinFlip < PoketchApp
  2083.   def initialize
  2084.     super
  2085.     @bg.bmp("Graphics/Pictures/Poketch/Coin Flip/background")
  2086.     @coin = Sprite.new(@viewport)
  2087.     @coin.x = 128
  2088.     set(192,"front")
  2089.     @idle = true
  2090.     @i = 0
  2091.   end
  2092.  
  2093.   def set(y, path = nil)
  2094.     @coin.y = y
  2095.     @coin.bmp("Graphics/Pictures/Poketch/Coin Flip/#{path}") if path
  2096.   end
  2097.  
  2098.   def update
  2099.     if @idle && $mouse.click?(@coin)
  2100.       @idle = false
  2101.     end
  2102.     if !@idle
  2103.       @i += 1
  2104.       # Yep. This is the whole animation.
  2105.       case @i
  2106.       when 1..2
  2107.         set(172)
  2108.       when 3..4
  2109.         set(170,"middle")
  2110.       when 5..6
  2111.         set(120,"back")
  2112.       when 7..8
  2113.         set(122,"middle")
  2114.       when 9..10
  2115.         set(62,"front")
  2116.       when 11..12
  2117.         set(80,"middle")
  2118.       when 13..14
  2119.         set(72)
  2120.       when 15..16
  2121.         set(30,"back")
  2122.       when 17..18
  2123.         set(58,"middle")
  2124.       when 19..20
  2125.         set(22,"front")
  2126.       when 21..22
  2127.         set(64,"middle")
  2128.       when 23..24
  2129.         set(44,"back")
  2130.       when 25..26
  2131.         set(92,"middle")
  2132.       when 27..28
  2133.         set(80,"front")
  2134.       when 29..30
  2135.         set(144,"middle")
  2136.       when 31..32
  2137.         set(146,"back")
  2138.       when 33..34
  2139.         set(216,"middle")
  2140.       when 35..36
  2141.         set(192,"front")
  2142.       when 37..38
  2143.         set(204,"middle")
  2144.       when 39..40
  2145.         set(152,"back")
  2146.       when 41..42
  2147.         set(172,"middle")
  2148.       when 43..44
  2149.         set(128,"front")
  2150.       when 45..46
  2151.         set(162,"middle")
  2152.       when 47..48
  2153.         set(132,"back")
  2154.       when 49..50
  2155.         set(172,"middle")
  2156.       when 51..52
  2157.         set(180)
  2158.       when 53..54
  2159.         set(160,"front")
  2160.       when 55..56
  2161.         set(218,"middle")
  2162.       when 57..58
  2163.         set(188,"back")
  2164.       when 59..60
  2165.         set(214,"middle")
  2166.       when 61..62
  2167.         set(168,"front")
  2168.       when 63..64
  2169.         set(200,"middle")
  2170.       when 65..66
  2171.         set(170,"back")
  2172.       when 67..68
  2173.         set(208,"middle")
  2174.       when 69..70
  2175.         set(184,"front")
  2176.       when 71..72
  2177.         set(222,"middle")
  2178.       when 73..74
  2179.         set(184,"back")
  2180.       when 75..76
  2181.         set(214,"middle")
  2182.       when 77..78
  2183.         set(182,["front","back"][rand(2)])
  2184.         @i = 0
  2185.         @idle = true
  2186.       end
  2187.       # Yeah, it was fun extracting the official animation's frames one by one.
  2188.     end
  2189.   end
  2190.  
  2191.   def dispose
  2192.     @coin.dispose
  2193.     super
  2194.   end
  2195. end
  2196.  
  2197.  
  2198. #==============================================================================#
  2199. # Pokétch Stopwatch. Counts up instead of down.                                #
  2200. #==============================================================================#
  2201. class PokemonTemp
  2202.   attr_accessor :stopwatch_running
  2203.   attr_accessor :stopwatch_seconds
  2204.   attr_accessor :stopwatch_ms
  2205. end
  2206.  
  2207. module Graphics
  2208.   class << Graphics
  2209.     alias poketch_stopwatch_update update
  2210.   end
  2211.  
  2212.   def self.update
  2213.     poketch_stopwatch_update
  2214.     return if !$Poketch
  2215.     return if !$PokemonTemp.stopwatch_running
  2216.     return if !$PokemonTemp || !$PokemonTemp.stopwatch_seconds || !$PokemonTemp.stopwatch_ms
  2217.     if Graphics.frame_count % Graphics.frame_rate == 0
  2218.       $PokemonTemp.stopwatch_seconds += 1
  2219.       $PokemonTemp.stopwatch_ms = 0
  2220.     end
  2221.     # Typically ends up being "+= 100.0 / 40.0", so "+= 2.5"
  2222.     $PokemonTemp.stopwatch_ms += 100.0 / Graphics.frame_rate.to_f
  2223.     $Poketch.app.refresh if $Poketch && $Poketch.app.is_a?(PoketchStopwatch)
  2224.   end
  2225. end
  2226.  
  2227. class PoketchStopwatch < PoketchApp
  2228.   def initialize
  2229.     super
  2230.     @bg.bmp("Graphics/Pictures/Poketch/Stopwatch/background")
  2231.     $PokemonTemp.stopwatch_running = false
  2232.     $PokemonTemp.stopwatch_seconds = 0
  2233.     $PokemonTemp.stopwatch_ms = 0
  2234.     @numbers = []
  2235.     @voltorb = Sprite.new(@viewport)
  2236.     @voltorb.bmp("Graphics/Pictures/Poketch/Stopwatch/idle")
  2237.     @voltorb.ox = @voltorb.bitmap.width / 2
  2238.     @voltorb.oy = @voltorb.bitmap.height / 2
  2239.     @voltorb.x = 192
  2240.     @voltorb.y = 200
  2241.     @i = 1
  2242.     refresh
  2243.   end
  2244.  
  2245.   def refresh
  2246.     s = $PokemonTemp.stopwatch_seconds % 60
  2247.     m = ($PokemonTemp.stopwatch_seconds / 60).floor % 60
  2248.     h = (($PokemonTemp.stopwatch_seconds / 60).floor / 60).floor
  2249.     n = [pbFormat(h,2).split(""),pbFormat(m,2).split(""),pbFormat(s,2).split(""),
  2250.         pbFormat($PokemonTemp.stopwatch_ms,2).split("")]
  2251.     for i in 0...8
  2252.       @numbers[i].dispose if @numbers[i]
  2253.       @numbers[i] = nil
  2254.       @numbers[i] = Sprite.new(@viewport)
  2255.       @numbers[i].bmp("Graphics/Pictures/Poketch/Stopwatch/numbers")
  2256.       @numbers[i].src_rect.width = 24
  2257.       @numbers[i].src_rect.x = 24 * n[(i / 2).floor][i % 2].to_i
  2258.       @numbers[i].x = [20,52,116,148,212,244,308,340][i]
  2259.       @numbers[i].y = 16
  2260.     end
  2261.   end
  2262.  
  2263.   def update
  2264.     @cooldown -= 1 if @cooldown > -1
  2265.     if @cooldown == -1 && @click
  2266.       @voltorb.bmp("Graphics/Pictures/Poketch/Stopwatch/#{@click}")
  2267.       @voltorb.ox = @voltorb.bitmap.width / 2
  2268.       @voltorb.oy = @voltorb.bitmap.height / 2
  2269.       $PokemonTemp.stopwatch_running = true if @click.include?("active")
  2270.       @click = nil
  2271.       @cooldown = 1
  2272.     end
  2273.     if !$PokemonTemp.stopwatch_running
  2274.       if $mouse.click?(@voltorb)
  2275.         @voltorb.bmp("Graphics/Pictures/Poketch/Stopwatch/click")
  2276.         @voltorb.ox = @voltorb.bitmap.width / 2
  2277.         @voltorb.oy = @voltorb.bitmap.height / 2
  2278.         @cooldown = 2
  2279.         @click = "active#{@i}"
  2280.       end
  2281.     else
  2282.       if @cooldown == -1 && !@click
  2283.         @voltorb.bmp("Graphics/Pictures/Poketch/Stopwatch/active#{@i}")
  2284.         if @i == 1
  2285.           @i = 2
  2286.         else
  2287.           @i = 1
  2288.         end
  2289.         @voltorb.ox = @voltorb.bitmap.width / 2
  2290.         @voltorb.oy = @voltorb.bitmap.height / 2
  2291.         @cooldown = 2
  2292.       end
  2293.       if $mouse.click?(@voltorb)
  2294.         $PokemonTemp.stopwatch_running = false
  2295.         @voltorb.bmp("Graphics/Pictures/Poketch/Stopwatch/click")
  2296.         @voltorb.ox = @voltorb.bitmap.width / 2
  2297.         @voltorb.oy = @voltorb.bitmap.height / 2
  2298.         @cooldown = 2
  2299.         @click = "idle"
  2300.       end
  2301.     end
  2302.   end
  2303.  
  2304.   def dispose
  2305.     @voltorb.dispose
  2306.     for n in @numbers
  2307.       n.dispose
  2308.     end
  2309.     $PokemonTemp.stopwatch_running = false
  2310.     $PokemonTemp.stopwatch_seconds = 0
  2311.     $PokemonTemp.stopwatch_ms = 0
  2312.     super
  2313.   end
  2314. end
  2315.  
  2316.  
  2317. #==============================================================================#
  2318. # Pokéch Notepad. You can write stuff down here.                               #
  2319. #==============================================================================#
  2320. class PokeBattle_Trainer
  2321.   attr_accessor :poketch_note
  2322. end
  2323.  
  2324. class PoketchNotepad < PoketchApp
  2325.   # 0x00 format: UTF-8 Hex
  2326.   # 000  format: JavaScript Keycodes
  2327.   BUTTONS = {
  2328.     0x41 => ["a","A"],
  2329.     0x42 => ["b","B"],
  2330.     0x43 => ["c","C"],
  2331.     0x44 => ["d","D"],
  2332.     0x45 => ["e","E"],
  2333.     0x46 => ["f","F"],
  2334.     0x47 => ["g","G"],
  2335.     0x48 => ["h","H"],
  2336.     0x49 => ["i","I"],
  2337.     0x4A => ["j","J"],
  2338.     0x4B => ["k","K"],
  2339.     0x4C => ["l","L"],
  2340.     0x4D => ["m","M"],
  2341.     0x4E => ["n","N"],
  2342.     0x4F => ["o","O"],
  2343.     0x50 => ["p","P"],
  2344.     0x51 => ["q","Q"],
  2345.     0x52 => ["r","R"],
  2346.     0x53 => ["s","S"],
  2347.     0x54 => ["t","T"],
  2348.     0x55 => ["u","U"],
  2349.     0x56 => ["v","V"],
  2350.     0x57 => ["w","W"],
  2351.     0x58 => ["x","X"],
  2352.     0x59 => ["y","Y"],
  2353.     0x5A => ["z","Z"],
  2354.     0x20 => [" "," "],
  2355.     0x30 => ["0",")"],
  2356.     0x31 => ["1","!"],
  2357.     0x32 => ["2","@"],
  2358.     0x33 => ["3","#"],
  2359.     0x34 => ["4","$"],
  2360.     0x35 => ["5","%"],
  2361.     0x36 => ["6","^"],
  2362.     0x37 => ["7","&"],
  2363.     0x38 => ["8","*"],
  2364.     0x39 => ["9","("],
  2365.     189  => ["-","_"],
  2366.     187  => ["=","+"],
  2367.     188  => [",","<"],
  2368.     190  => [".",">"],
  2369.     191  => ["/","?"],
  2370.     222  => ["'", '"'],
  2371.     219  => ["[","{"],
  2372.     221  => ["]","}"],
  2373.     13   => ["\n","\n"],
  2374.     186  => [";",":"],
  2375.     192  => ["`","~"],
  2376.     220  => ["\\","|"]
  2377.   }
  2378.  
  2379.   def initialize
  2380.     super
  2381.     @bg.bmp("Graphics/Pictures/Poketch/Notepad/background")
  2382.     @pencil = Sprite.new(@viewport)
  2383.     @pencil.bmp("Graphics/Pictures/Poketch/Notepad/btn")
  2384.     @pencil.x = 320
  2385.     @pencil.y = 84
  2386.     @drawing = false
  2387.     @bmp = Sprite.new(@viewport)
  2388.     @bmp.x = 16
  2389.     @bmp.y = 24
  2390.     @txt = $Trainer.poketch_note || ""
  2391.     draw_text
  2392.   end
  2393.  
  2394.   def update
  2395.     if $mouse.click?(@pencil)
  2396.       @drawing = true
  2397.       @pencil.bmp("Graphics/Pictures/Poketch/Notepad/btnClick")
  2398.     end
  2399.     if @drawing
  2400.       loop do
  2401.         @cooldown -= 1 if @cooldown > -1
  2402.         Graphics.update
  2403.         Input.update
  2404.         oldtxt = @txt
  2405.         for key in BUTTONS.keys
  2406.           if Input.triggerex?(key)
  2407.             @txt += BUTTONS[key][Input.press?(Input::SHIFT) || Input.press?(20) ? 1 : 0]
  2408.           end
  2409.         end
  2410.         # Special
  2411.         if @cooldown == -1 && Input.pressex?(0x08) # Backspace
  2412.           @txt.chop!
  2413.           draw_text
  2414.           @cooldown = 5
  2415.         end
  2416.         draw_text if oldtxt != @txt
  2417.         if $mouse.click?(@pencil)
  2418.           @drawing = false
  2419.           @pencil.bmp("Graphics/Pictures/Poketch/Notepad/btn")
  2420.           break
  2421.         end
  2422.         if $mouse.click?($Poketch.btnUp)
  2423.           $Poketch.click_up
  2424.           break
  2425.         end
  2426.         if $mouse.click?($Poketch.btnDown)
  2427.           $Poketch.click_down
  2428.           break
  2429.         end
  2430.       end
  2431.     end
  2432.   end
  2433.  
  2434.   def draw_text
  2435.     @bmp.bitmap = nil
  2436.     @bmp.bmp(276,268)
  2437.     pbSetSystemFont(@bmp.bitmap)
  2438.     drawTextEx(@bmp.bitmap,0,0,276,8,@txt,Color.new(16,41,24),Color.new(57,82,49))
  2439.     $Trainer.poketch_note = @txt
  2440.   end
  2441.  
  2442.   def dispose
  2443.     @pencil.dispose
  2444.     super
  2445.   end
  2446. end
  2447.  
  2448.  
  2449. #==============================================================================#
  2450. # Pokétch Alarm Clock.                                                         #
  2451. #==============================================================================#
  2452. class PokeBattle_Trainer
  2453.   attr_accessor :poketch_alarm
  2454.   attr_accessor :poketch_alarm_running
  2455. end
  2456.  
  2457. class PoketchAlarmClock < PoketchApp
  2458.   def initialize
  2459.     super
  2460.     @bg.bmp("Graphics/Pictures/Poketch/Alarm Clock/background1")
  2461.     @numbers = []
  2462.     $Trainer.poketch_alarm = 0 if !$Trainer.poketch_alarm
  2463.     $Trainer.poketch_alarm_running = false if !$Trainer.poketch_alarm_running
  2464.     draw_time($Trainer.poketch_alarm)
  2465.     @arrows = []
  2466.     for i in 0...4
  2467.       @arrows[i] = Sprite.new(@viewport)
  2468.       path = "arrow" + (i < 2 ? "Up" : "Down")
  2469.       @arrows[i].bmp("Graphics/Pictures/Poketch/Alarm Clock/#{path}")
  2470.       @arrows[i].x = [88,184][i % 2]
  2471.       @arrows[i].y = [184,284][(i / 2).floor]
  2472.     end
  2473.     @running = false
  2474.     @btns = []
  2475.     @btns[0] = Sprite.new(@viewport)
  2476.     @btns[0].bmp("Graphics/Pictures/Poketch/Alarm Clock/btn")
  2477.     @btns[0].x = 324
  2478.     @btns[0].y = 116
  2479.     @btns[1] = Sprite.new(@viewport)
  2480.     @btns[1].bmp("Graphics/Pictures/Poketch/Alarm Clock/btnClick")
  2481.     @btns[1].x = 324
  2482.     @btns[1].y = 180
  2483.     @time = Time.now
  2484.     @i = -1
  2485.     set_running if $Trainer.poketch_alarm_running
  2486.   end
  2487.  
  2488.   def draw_time(mins)
  2489.     n = pbFormat((mins / 60).floor, 2).split("")
  2490.     n.concat(pbFormat(mins % 60, 2).split(""))
  2491.     for i in 0...4
  2492.       @numbers[i].dispose if @numbers[i]
  2493.       @numbers[i] = nil
  2494.       @numbers[i] = Sprite.new(@viewport)
  2495.       @numbers[i].bmp("Graphics/Pictures/Poketch/Alarm Clock/numbers")
  2496.       @numbers[i].src_rect.width = 24
  2497.       @numbers[i].src_rect.x = 24 * n[i].to_i
  2498.       @numbers[i].x = [84,116,180,212][i]
  2499.       @numbers[i].y = 224
  2500.     end
  2501.   end
  2502.  
  2503.   def update
  2504.     @i += 1
  2505.     if !@running
  2506.       for i in 0...4
  2507.         @arrows[i].visible = @i < 24
  2508.       end
  2509.       @i = 0 if @i == 47
  2510.       oldt = $Trainer.poketch_alarm
  2511.       if $mouse.click?(@arrows[0])
  2512.         $Trainer.poketch_alarm += 60
  2513.         $Trainer.poketch_alarm -= 1440 if $Trainer.poketch_alarm >= 1440
  2514.       end
  2515.       if $mouse.click?(@arrows[1])
  2516.         $Trainer.poketch_alarm += 1
  2517.         $Trainer.poketch_alarm -= 60 if $Trainer.poketch_alarm % 60 == 0
  2518.       end
  2519.       if $mouse.click?(@arrows[2])
  2520.         $Trainer.poketch_alarm -= 60
  2521.         $Trainer.poketch_alarm += 1440 if $Trainer.poketch_alarm < 0
  2522.       end
  2523.       if $mouse.click?(@arrows[3])
  2524.         $Trainer.poketch_alarm -= 1
  2525.         $Trainer.poketch_alarm += 60 if $Trainer.poketch_alarm % 60 == 59
  2526.       end
  2527.       draw_time($Trainer.poketch_alarm) if oldt != $Trainer.poketch_alarm
  2528.     else
  2529.       if @time.hour != Time.now.hour || @time.min != Time.now.min
  2530.         @time = Time.now
  2531.         @sum = @time.min + @time.hour * 60
  2532.         draw_time(@sum)
  2533.         @i = 0 if @sum == $Trainer.poketch_alarm
  2534.       end
  2535.       if @sum == $Trainer.poketch_alarm
  2536.         if @i % 6 == 0
  2537.           @bg.bmp("Graphics/Pictures/Poketch/Alarm Clock/background3")
  2538.         elsif @i % 3 == 0
  2539.           @bg.bmp("Graphics/Pictures/Poketch/Alarm Clock/background4")
  2540.         end
  2541.         @alarm = true
  2542.         if @i == 18
  2543.           for i in 0...4
  2544.             @numbers[i].visible = !@numbers[i].visible
  2545.           end
  2546.           @i = 0
  2547.         end
  2548.       elsif @alarm
  2549.         @bg.bmp("Graphics/Pictures/Poketch/Alarm Clock/background2")
  2550.         @alarm = false
  2551.         for i in 0...4
  2552.           @numbers[i].visible = true
  2553.         end
  2554.       end
  2555.     end
  2556.     if !@running && $mouse.click?(@btns[0])
  2557.       set_running
  2558.     end
  2559.     if @running && $mouse.click?(@btns[1])
  2560.       $Trainer.poketch_alarm_running = false
  2561.       @bg.bmp("Graphics/Pictures/Poketch/Alarm Clock/background1")
  2562.       @btns[0].bmp("Graphics/Pictures/Poketch/Alarm Clock/btn")
  2563.       @btns[1].bmp("Graphics/Pictures/Poketch/Alarm Clock/btnClick")
  2564.       @running = false
  2565.       @i = 0
  2566.       @time = Time.now
  2567.       draw_time($Trainer.poketch_alarm)
  2568.     end
  2569.   end
  2570.  
  2571.   def set_running
  2572.     $Trainer.poketch_alarm_running = true
  2573.     @bg.bmp("Graphics/Pictures/Poketch/Alarm Clock/background2")
  2574.     @running = true
  2575.     for i in 0...4
  2576.       @arrows[i].visible = false
  2577.     end
  2578.     @time = Time.now
  2579.     @sum = @time.min + @time.hour * 60
  2580.     draw_time(@sum)
  2581.     @btns[0].bmp("Graphics/Pictures/Poketch/Alarm Clock/btnClick")
  2582.     @btns[1].bmp("Graphics/Pictures/Poketch/Alarm Clock/btn")
  2583.     @i = 0 if @sum == $Trainer.poketch_alarm
  2584.   end
  2585.  
  2586.   def dispose
  2587.     for btn in @btns
  2588.       btn.dispose
  2589.     end
  2590.     for n in @numbers
  2591.       n.dispose
  2592.     end
  2593.     for arrow in @arrows
  2594.       arrow.dispose
  2595.     end
  2596.     super
  2597.   end
  2598. end
  2599.  
  2600.  
  2601. #==============================================================================#
  2602. # Pokétch Safari Helper. Shows you some things like steps and balls left.      #
  2603. #==============================================================================#
  2604. class PoketchSafariHelper < PoketchApp
  2605.   def self.usable? # Only usable when in the Safari Zone
  2606.     return pbSafariState && pbSafariState.inProgress?
  2607.   end
  2608.  
  2609.   def initialize
  2610.     super
  2611.     @bg.bmp("Graphics/Pictures/Poketch/Safari Helper/background")
  2612.     @exit = Sprite.new(@viewport)
  2613.     @exit.bmp("Graphics/Pictures/Poketch/Safari Helper/exit")
  2614.     @exit.x = 284
  2615.     @exit.y = 208
  2616.     @balls = pbSafariState.ballcount
  2617.     @steps = pbSafariState.steps
  2618.     @ballsprites = []
  2619.     @stepsprites = []
  2620.     draw_balls
  2621.     draw_steps
  2622.   end
  2623.  
  2624.   def update
  2625.     super
  2626.     if @balls != pbSafariState.ballcount
  2627.       @balls = pbSafariState.ballcount
  2628.       draw_balls
  2629.     end
  2630.     if @steps != pbSafariState.steps
  2631.       @steps = pbSafariState.steps
  2632.       draw_steps
  2633.     end
  2634.     if click?(@exit,"Graphics/Pictures/Poketch/Safari Helper","exit")
  2635.       if Kernel.pbConfirmMessage(_INTL("Would you like to leave the Safari Game right now?"))
  2636.         pbSafariState.decision = 1
  2637.         pbSafariState.pbGoToStart
  2638.         $Poketch.click_down(false)
  2639.       end
  2640.     end
  2641.   end
  2642.  
  2643.   def draw_balls
  2644.     n = pbFormat(@balls, 2).split("")
  2645.     for i in 0...2
  2646.       @ballsprites[i].dispose if @ballsprites[i]
  2647.       @ballsprites[i] = nil
  2648.       @ballsprites[i] = Sprite.new(@viewport)
  2649.       @ballsprites[i].bmp("Graphics/Pictures/Poketch/Safari Helper/numbers")
  2650.       @ballsprites[i].src_rect.width = 24
  2651.       @ballsprites[i].src_rect.x = 24 * n[i].to_i
  2652.       @ballsprites[i].x = [100,132][i]
  2653.       @ballsprites[i].y = 27
  2654.     end
  2655.   end
  2656.  
  2657.   def draw_steps
  2658.     n = pbFormat(@steps).split("")
  2659.     for i in 0...3
  2660.       @stepsprites[i].dispose if @stepsprites[i]
  2661.       @stepsprites[i] = nil
  2662.       @stepsprites[i] = Sprite.new(@viewport)
  2663.       @stepsprites[i].bmp("Graphics/Pictures/Poketch/Safari Helper/numbers")
  2664.       @stepsprites[i].src_rect.width = 24
  2665.       @stepsprites[i].src_rect.x = 24 * n[i].to_i
  2666.       @stepsprites[i].x = [279,311,343][i]
  2667.       @stepsprites[i].y = 27
  2668.     end
  2669.   end
  2670.  
  2671.   def dispose
  2672.     for b in @ballsprites
  2673.       b.dispose
  2674.     end
  2675.     for s in @stepsprites
  2676.       s.dispose
  2677.     end
  2678.     @exit.dispose
  2679.     super
  2680.   end
  2681. end
  2682.  
  2683.  
  2684. #==============================================================================#
  2685. # All apps. To make a new app, you have to register it in this module.         #
  2686. # This is also the displayed order of the apps. The names are the class names. #
  2687. # The numbers you see after the name of an app is that app's ID.               #
  2688. # If you want to enable/disable an app, rather than looking up the ID, you     #
  2689. # could do something like "pbEnableApp(PoketchApps::PoketchNotepad)"           #
  2690. #==============================================================================#
  2691. module PoketchApps
  2692.   PoketchClock          = 0
  2693.   PoketchClicker        = 1
  2694.   PoketchCalculator     = 2
  2695.   PoketchPedometer      = 3
  2696.   PoketchItemFinder     = 4
  2697.   PoketchMoveTester     = 5
  2698.   PoketchRotom          = 6
  2699.   PoketchMarkingMap     = 7
  2700.   PoketchMatchupChecker = 8
  2701.   PoketchParty          = 9
  2702.   PoketchColorChanger   = 10
  2703.   PoketchKitchenTimer   = 11
  2704.   PoketchAnalogWatch    = 12
  2705.   PoketchStatDisplay    = 13
  2706.   PoketchRoulette       = 14
  2707.   PoketchDayCareChecker = 15
  2708.   PoketchPokemonHistory = 16
  2709.   PoketchCalendar       = 17
  2710.   PoketchCoinFlip       = 18
  2711.   PoketchStopwatch      = 19
  2712.   PoketchNotepad        = 20
  2713.   PoketchAlarmClock     = 21
  2714.   PoketchSafariHelper   = 22
  2715. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement