Advertisement
M3rein

Pokétch_Utility

Oct 21st, 2017
1,125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.42 KB | None | 0 0
  1. # This is what actually makes the game dual-screen. DEFAULTSCREENHEIGHT still
  2. # has to be doubled (384 * 2) = 768. Don't change this code below.
  3. if DUAL_SCREEN
  4.   module Graphics
  5.     @@height = DEFAULTSCREENHEIGHT / 2
  6.   end
  7. end
  8.  
  9. class PokeBattle_Trainer
  10.   attr_accessor :poketch
  11.   attr_accessor :poketch_last_app
  12.   attr_writer :poketch_app_access
  13.  
  14.   alias poketch_init initialize
  15.   def initialize(name, trainertype)
  16.     poketch_init(name, trainertype)
  17.     @poketch = false
  18.     @poketch_last_app = PoketchClock
  19.     @poketch_app_access = []
  20.   end
  21.  
  22.   def poketch_app_access
  23.     @poketch_app_access = [] if !@poketch_app_access
  24.     return @poketch_app_access
  25.   end
  26. end
  27.  
  28. # Converts integers to string with N digits. Examples:
  29. #  -> pbFormat(19,4) => "0019"
  30. #  -> pbFormat(7) => "007"
  31. #  -> pbFormat(321,3) => "321"
  32. def pbFormat(int, n = 3)
  33.   strInt = int.to_s
  34.   numLeading = n - strInt.length
  35.   return strInt if numLeading <= 0
  36.   leadingZeroes = "0" * numLeading
  37.   return leadingZeroes + strInt
  38. end
  39.  
  40. class Sprite
  41.   def bmp(arg1 = nil, arg2 = nil)
  42.     if arg1
  43.       if arg1.is_a?(Bitmap)
  44.         self.bitmap = arg1
  45.       elsif arg2
  46.         self.bitmap = Bitmap.new(arg1, arg2)
  47.       else
  48.         self.bitmap = BitmapCache.load_bitmap(arg1)
  49.       end
  50.     else
  51.       return self.bitmap
  52.     end
  53.   end
  54. end
  55.  
  56. if DUAL_SCREEN
  57.   class Spriteset_Map
  58.     alias poketch_init initialize
  59.     def initialize(map = nil)
  60.       poketch_init(map)
  61.       if $Trainer && $Trainer.poketch && !$Poketch
  62.         pbObtainPoketch(false)
  63.       else
  64.         return if $no_poketch_bg
  65.         make_background
  66.       end
  67.     end
  68.    
  69.     alias poketch_update update
  70.     def update
  71.       poketch_update
  72.       # Ensuring the Pokétch only updates once per frame (bug fix for map transfer)
  73.       if $Poketch && $Poketch.updated_frame != Graphics.frame_count
  74.         $Poketch.update
  75.         $Poketch.updated_frame = Graphics.frame_count
  76.       end
  77.     end
  78.   end
  79. end
  80.  
  81. def make_background
  82.   $no_poketch_bg.dispose if $no_poketch_bg
  83.   $no_poketch_bg = Sprite.new((v=Viewport.new(0,POKETCH_Y,Graphics.width,Graphics.height);v.z=99997;v))
  84.   $no_poketch_bg.bmp(NO_POKETCH_BACKGROUND)
  85. end
  86.  
  87. class PoketchApp
  88.   def self.usable?
  89.     return true
  90.   end
  91.  
  92.   def initialize
  93.     @viewport = Viewport.new(32,POKETCH_Y+32,384,320)
  94.     @viewport.z = 100001
  95.     @cooldown = -1
  96.     @tmp = []
  97.     @bg = Sprite.new(@viewport)
  98.   end
  99.  
  100.   def update
  101.     @cooldown -= 1 if @cooldown > -1
  102.     if @cooldown == 0 && @tmp[0]
  103.       @tmp[0].bmp(@tmp[1]+"/"+@tmp[2])
  104.     end
  105.   end
  106.  
  107.   # "sprite": The sprite that is clicked on
  108.   # "path": Used for "unclicked" and "clicked"
  109.   # "unclicked": The path "sprite" will get when the cooldown ends (path is "path"/"unclicked")
  110.   # "clicked": The path "sprite" will get when clicked on (path is "path"/"clicked")
  111.   # "cooldown": How long other mouse input in this app will be disabled
  112.   def click?(sprite, path, unclicked, clicked = unclicked + "Click", cooldown = 3)
  113.     return false if !$mouse || !$mouse.click?(sprite) || @cooldown > -1
  114.     @tmp = [sprite,path,unclicked]
  115.     @tmp[0].bmp(@tmp[1]+"/"+clicked)
  116.     @cooldown = cooldown
  117.     return true
  118.   end
  119.  
  120.   def refresh
  121.   end
  122.  
  123.   def dispose
  124.     @bg.dispose
  125.     @viewport.dispose
  126.     $Poketch.app = nil
  127.   end
  128. end
  129.  
  130. class Sprite
  131.   def poketch_average
  132.     bmp = self.bitmap.clone
  133.     for x in 0...bmp.width
  134.       for y in 0...bmp.height
  135.         px = bmp.get_pixel(x, y)
  136.         next if px.alpha == 0
  137.         av = (px.red + px.green + px.blue) / 3
  138.         if av < 96
  139.           color = Color.new(57,82,49)
  140.         elsif av < 128
  141.           color = Color.new(76,120,74)
  142.         elsif av < 170
  143.           color = Color.new(82,132,82)
  144.         else
  145.           color = Color.new(115,181,115)
  146.         end
  147.         bmp.set_pixel(x, y, color)
  148.       end
  149.     end
  150.     self.bitmap = bmp.clone
  151.   end
  152. end
  153.  
  154. # Drawing method
  155. RNET = File.file?("Assemblies/RPG.Net.dll")
  156. if RNET
  157.   Win32API.new('Assemblies/RPG.Net.dll', 'Initialize', 'i', '').call(4)
  158.   class Bitmap
  159.     DrawLine = Win32API.new('RPG.Net.dll', 'BmDrawLine', 'iiiiiii', '')
  160.     def draw_line(x1, y1, x2, y2, color, thickness = 4)
  161.       c = color
  162.       c = [c.red.to_i.chr, c.green.to_i.chr, c.blue.to_i.chr, c.alpha.to_i.chr].join.unpack('L').shift
  163.       DrawLine.call(__id__, x1, y1, x2, y2, c, thickness)
  164.     end
  165.   end
  166. end
  167.  
  168. def appID(const)
  169.   return PoketchApps.const_get(const) rescue nil
  170. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement