Advertisement
TechSkylander1518

Map Zoom for Essentials v20

May 19th, 2022
678
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ZoomMap
  2.   attr_accessor :goal
  3.   attr_accessor :speed
  4.   attr_accessor :zoom
  5.  
  6.   def initialize(goal,speed,zoom="in")
  7.     @viewport = Viewport.new(0, 0, Graphics.width, Graphics.height)
  8.     @viewport.z = 99999
  9.     self.goal = goal
  10.     self.speed = speed
  11.     self.zoom = zoom.downcase
  12.     @sprites = {}
  13.     @sprites["map"] = Sprite.new(@viewport)
  14.     @sprites["map"].bitmap =  Graphics.snap_to_bitmap
  15.     @sprites["map"].center_origins
  16.     @sprites["map"].x = Graphics.width/2
  17.     @sprites["map"].y = Graphics.height/2
  18.     Graphics.update
  19.   end
  20.  
  21.  
  22.   def update
  23.     if @sprites
  24.       @sprites["map"].bitmap.clear
  25.       messagewindow = $game_temp.message_window
  26.       cmdwindow = $game_temp.cmd_window
  27.       pausemenu = $game_temp.pause_menu_scene
  28.       messagewindow.visible = false if messagewindow
  29.       cmdwindow.visible = false if cmdwindow
  30.       pausemenu.pbHideMenu if pausemenu
  31.       @sprites["map"].bitmap =  Graphics.snap_to_bitmap
  32.       @sprites["map"].center_origins
  33.       @sprites["map"].x = Graphics.width/2
  34.       @sprites["map"].y = Graphics.height/2
  35.       messagewindow.visible = true if messagewindow
  36.       cmdwindow.visible = true if cmdwindow
  37.       pausemenu.pbShowMenu if pausemenu
  38.       case self.zoom
  39.         when "in"
  40.           if @sprites["map"].zoom < self.goal
  41.             altspeed = self.goal - @sprites["map"].zoom
  42.             @sprites["map"].zoom+=[self.speed,altspeed].min
  43.           end
  44.         when "out"
  45.           if @sprites["map"].zoom > @goal
  46.             altspeed = @sprites["map"].zoom - self.goal
  47.             @sprites["map"].zoom-=[self.speed,altspeed].min
  48.           end
  49.         end
  50.     else
  51.       dispose
  52.     end
  53.   end
  54.  
  55.  
  56.   def dispose
  57.     pbDisposeSpriteHash(@sprites)
  58.     @viewport.dispose
  59.   end
  60.  
  61. end
  62.  
  63.  
  64. def pbZoomMap(goal,speed,zoom="in")
  65.   if !$game_temp.background_zoom
  66.     $game_temp.background_zoom = ZoomMap.new(goal,speed,zoom)
  67.   else
  68.     $game_temp.background_zoom.goal = goal
  69.     $game_temp.background_zoom.speed = speed
  70.     $game_temp.background_zoom.zoom = zoom
  71.   end
  72. end
  73.  
  74.  
  75. def pbDisposeZoomMap
  76.   if $game_temp.background_zoom
  77.     $game_temp.background_zoom.dispose
  78.     $game_temp.background_zoom = nil
  79.   end
  80.       Graphics.update
  81. end
  82.  
  83.  
  84. EventHandlers.add(:on_frame_update,:map_zoom,
  85.   proc {
  86.   next if !$player
  87.   if $game_temp.background_zoom.is_a?(ZoomMap)
  88.   $game_temp.background_zoom.update
  89.   sprites = $game_temp.background_zoom.instance_variable_get(:@sprites)
  90.     if $game_temp.background_zoom.goal == 1 && sprites["map"].zoom == 1
  91.       pbDisposeZoomMap
  92.     end
  93.   end
  94.   }
  95. )
  96.  
  97.  
  98. #===============================================================================
  99. #Pause Menu Rewriting
  100. #===============================================================================
  101. #If you're using an alternate pause UI,
  102. #you should probably delete this whole section.
  103.  
  104.  
  105. class Scene_Map
  106.  
  107.   def call_menu
  108.     $game_temp.menu_calling = false
  109.     $game_temp.in_menu = true
  110.     $game_player.straighten
  111.     $game_map.update
  112.     $game_temp.pause_menu_scene = PokemonPauseMenu_Scene.new
  113.     $game_temp.pause_menu_screen = PokemonPauseMenu.new($game_temp.pause_menu_scene)
  114.     $game_temp.pause_menu_screen.pbStartPokemonMenu
  115.     $game_temp.in_menu = false
  116.   end
  117.  
  118. end
  119.  
  120.  
  121. class PokemonPauseMenu_Scene
  122.   def pbShowMenu
  123.     @sprites["cmdwindow"].visible = true if @sprites["cmdwindow"]
  124.     @sprites["infowindow"].visible = @infostate if @sprites["infowindow"]
  125.     @sprites["helpwindow"].visible = @helpstate if @sprites["helpwindow"]
  126.   end
  127.  
  128.   def pbHideMenu
  129.     @sprites["cmdwindow"].visible = false if @sprites["cmdwindow"]
  130.     @sprites["infowindow"].visible = false if @sprites["infowindow"]
  131.     @sprites["helpwindow"].visible = false if @sprites["helpwindow"]
  132.   end
  133. end
  134.  
  135. #===============================================================================
  136. #Sprite Utilities
  137. #===============================================================================
  138. #If you have these utilities defined elsewhere, you can delete this section.
  139. class Sprite
  140.   #Utility from Marin
  141.   # Centers the sprite by setting the origin points to half the width and height
  142.   def center_origins
  143.     return if !self.bitmap
  144.     self.ox = self.bitmap.width / 2
  145.     self.oy = self.bitmap.height / 2
  146.   end
  147.  
  148.   #Utility from Luka
  149.   #-----------------------------------------------------------------------------
  150.   #  gets zoom
  151.   #-----------------------------------------------------------------------------
  152.   def zoom
  153.     return self.zoom_x
  154.   end
  155.   #-----------------------------------------------------------------------------
  156.   #  sets all zoom values
  157.   #-----------------------------------------------------------------------------
  158.   def zoom=(val)
  159.     self.zoom_x = val
  160.     self.zoom_y = val
  161.   end
  162.  
  163. end
  164.  
  165.  
  166.  
  167. #===============================================================================
  168. #Game Temp and Message Window rewriting
  169. #===============================================================================
  170. #This code is to allow the ZoomMap class to hide these windows
  171. #when taking a screenshot, so that the text won't be zoomed in.
  172. class Game_Temp
  173.   attr_accessor :background_zoom
  174.   attr_accessor :message_window
  175.   attr_accessor :cmd_window
  176.   attr_accessor :pause_menu_scene
  177.   attr_accessor :pause_menu_screen
  178.  
  179. end
  180.  
  181.  
  182.  
  183. def pbCreateMessageWindow(viewport=nil,skin=nil)
  184.   $game_temp.message_window = Window_AdvancedTextPokemon.new("")
  185.   msgwindow=$game_temp.message_window
  186.   if !viewport
  187.     msgwindow.z=99999
  188.   else
  189.     msgwindow.viewport=viewport
  190.   end
  191.   msgwindow.visible=true
  192.   msgwindow.letterbyletter=true
  193.   msgwindow.back_opacity=MessageConfig::WINDOW_OPACITY
  194.   pbBottomLeftLines(msgwindow,2)
  195.   $game_temp.message_window_showing=true if $game_temp
  196.   skin=MessageConfig.pbGetSpeechFrame() if !skin
  197.   msgwindow.setSkin(skin)
  198.   return msgwindow
  199. end
  200.  
  201. def pbDisposeMessageWindow(msgwindow)
  202.   $game_temp.message_window_showing=false if $game_temp
  203.   $game_temp.message_window.dispose if $game_temp.message_window
  204.   msgwindow.dispose
  205. end
  206.  
  207.  
  208.  
  209. def pbShowCommands(msgwindow,commands=nil,cmdIfCancel=0,defaultCmd=0)
  210.   return 0 if !commands
  211.   $game_temp.cmd_window = Window_CommandPokemonEx.new(commands)
  212.   cmdwindow = $game_temp.cmd_window
  213.   cmdwindow.z=99999
  214.   cmdwindow.visible=true
  215.   cmdwindow.resizeToFit(cmdwindow.commands)
  216.   pbPositionNearMsgWindow(cmdwindow,msgwindow,:right)
  217.   cmdwindow.index=defaultCmd
  218.   command=0
  219.   loop do
  220.     Graphics.update
  221.     Input.update
  222.     cmdwindow.update
  223.     msgwindow.update if msgwindow
  224.     yield if block_given?
  225.     if Input.trigger?(Input::BACK)
  226.       if cmdIfCancel>0
  227.         command=cmdIfCancel-1
  228.         break
  229.       elsif cmdIfCancel<0
  230.         command=cmdIfCancel
  231.         break
  232.       end
  233.     end
  234.     if Input.trigger?(Input::USE)
  235.       command=cmdwindow.index
  236.       break
  237.     end
  238.     pbUpdateSceneMap
  239.   end
  240.   ret=command
  241.   cmdwindow.dispose
  242.   Input.update
  243.   return ret
  244. end
  245.  
  246. def pbShowCommandsWithHelp(msgwindow,commands,help,cmdIfCancel=0,defaultCmd=0)
  247.   msgwin=msgwindow
  248.   msgwin=pbCreateMessageWindow(nil) if !msgwindow
  249.   oldlbl=msgwin.letterbyletter
  250.   msgwin.letterbyletter=false
  251.   if commands
  252.     $game_temp.cmd_window = Window_CommandPokemonEx.new(commands)
  253.     cmdwindow = $game_temp.cmd_window
  254.     cmdwindow.z=99999
  255.     cmdwindow.visible=true
  256.     cmdwindow.resizeToFit(cmdwindow.commands)
  257.     cmdwindow.height=msgwin.y if cmdwindow.height>msgwin.y
  258.     cmdwindow.index=defaultCmd
  259.     command=0
  260.     msgwin.text=help[cmdwindow.index]
  261.     msgwin.width=msgwin.width   # Necessary evil to make it use the proper margins
  262.     loop do
  263.       Graphics.update
  264.       Input.update
  265.       oldindex=cmdwindow.index
  266.       cmdwindow.update
  267.       if oldindex!=cmdwindow.index
  268.         msgwin.text=help[cmdwindow.index]
  269.       end
  270.       msgwin.update
  271.       yield if block_given?
  272.       if Input.trigger?(Input::BACK)
  273.         if cmdIfCancel>0
  274.           command=cmdIfCancel-1
  275.           break
  276.         elsif cmdIfCancel<0
  277.           command=cmdIfCancel
  278.           break
  279.         end
  280.       end
  281.       if Input.trigger?(Input::USE)
  282.         command=cmdwindow.index
  283.         break
  284.       end
  285.       pbUpdateSceneMap
  286.     end
  287.     ret=command
  288.     cmdwindow.dispose
  289.     Input.update
  290.   end
  291.   msgwin.letterbyletter=oldlbl
  292.   msgwin.dispose if !msgwindow
  293.   return ret
  294. end
Advertisement
RAW Paste Data Copied
Advertisement