Advertisement
roninator2

Zane - Map Navigation - switch control

Dec 4th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.27 KB | None | 0 0
  1. #==============================================================================
  2. #  Script      : Map Navigation
  3. #  Author      : Xane
  4. #  Build       : v1.5
  5. #  Created On  : 12.17.2020
  6. #  Last Update : 12.19.2020
  7. #------------------------------------------------------------------------------
  8. #  Terms and Conditions:
  9. #  Retain this header at all times and do not release any new revisions online
  10. #  without prior consent. You may modify the code below at your own discretion
  11. #  but only for private usage. This script may be used both Non Commercially
  12. #  and Commercially with credit provided.
  13. #------------------------------------------------------------------------------
  14. #  Bugs, Compatibility, and Reporting:
  15. #   Report all bugs to me on the RM forums. Any version prior to the current
  16. #   version is not supported. All bugs steaming from user changes such as
  17. #   modification of code will not be supported. Any compatibility patches
  18. #   will be provided at my own accord and are not guaranteed in any way.
  19. #------------------------------------------------------------------------------
  20. #  Update Log (U - Unreleased | R - Released):
  21. #  1.0(R) - Wrote original version of script.
  22. #  1.1(U) - Added map effects and sprite viewings back in.
  23. #  1.2(U) - Fixed a few bugs.
  24. #  1.3(R) - Rewrote script to use data already provided by RM rather then
  25. #           trying to collect new data. Script will now properly update
  26. #           event data, weather effects, and any pictures display originally
  27. #           in Scene_Map.
  28. #  1.4(R) - Fixed typo error with variable. Added check for display coordinate
  29. #           to check for map edges when maps do not loop.
  30. #  1.5(R) - Fixed some more syntax typos and fixed the check for the display coordinates
  31. #  1.51(U)- Roninator2 edit. Added check for switch to call map
  32. #------------------------------------------------------------------------------
  33. #  Usage:
  34. #  This script is plug-in-play. If you want to access the scene, use the script
  35. #  call "(SceneManager.call(Scene_MapNav)" without quotes in an event or via
  36. #  the main menu if you have another script installed that allows custom
  37. #  commands such as Yanfly's Menu.
  38. #==============================================================================
  39.  
  40. #==============================================================================
  41. #  ** Xane_MapNavSettings
  42. #------------------------------------------------------------------------------
  43. #  This module handles various settings. New versions may add more settings.
  44. #==============================================================================
  45.  
  46. module Xane_MapNavSettings
  47.  
  48.   # Controls how fast you want to move around the map.
  49.  
  50.   # Use a float point to adjust this setting. The max speed is 1.0
  51.   Nav_Speed = 0.4
  52.  
  53.   # Set the text to be displayed on the screen.
  54.  
  55.   # You'll have a max width of 272 pixels to show a string. Consider this
  56.   # when choosing what the message will display.
  57.   Display_Text = 'Press ESC to return'
  58.  
  59.   # Displays arrows on screen for visual feedback.
  60.  
  61.   # Arrows use a single image stored inside your 'Graphics/System' folder.
  62.   # The script will then create copies and map them to the edges of the game
  63.   # window. You can also turn off visual feedback if you wish as well as set
  64.   # the value for a 'blink' effect if you want more flare.
  65.   Use_Nav_Arrows = true
  66.   Use_Nav_Blink_Effect = true
  67.   Nav_Arrow_Image = 'Nav_Arrow'
  68.  
  69.     # Use button to call map
  70.     Map_Button_Switch = 1
  71.     Map_Button = :ALT
  72.  
  73. end
  74.  
  75. #==============================================================================
  76. # ** Scene_MapNav
  77. #------------------------------------------------------------------------------
  78. #  This scene allows the player to have a viewing of the map as well as its
  79. # events across the map by scrolling around.
  80. #==============================================================================
  81.  
  82. class Scene_MapNav < Scene_MenuBase
  83.   #--------------------------------------------------------------------------
  84.   # * Included Modules
  85.   #--------------------------------------------------------------------------
  86.   include Xane_MapNavSettings
  87.   #--------------------------------------------------------------------------
  88.   # * Start Processing
  89.   #--------------------------------------------------------------------------
  90.   def start
  91.     super
  92.     @last_display_x = $game_map.display_x
  93.     @last_display_y = $game_map.display_y
  94.     @display_x = @last_display_x
  95.     @display_y = @last_display_y
  96.     @blink_count = 0
  97.     @speed = [[Nav_Speed, 1.0].min, 0].max
  98.     create_all_sprites
  99.     $game_map.refresh
  100.   end
  101.   #--------------------------------------------------------------------------
  102.   # * Create All Sprites
  103.   #--------------------------------------------------------------------------
  104.   def create_all_sprites
  105.     @spriteset = Spriteset_Map.new
  106.     @text_display = Sprite.new
  107.     @text_display.bitmap = Bitmap.new(272, 48)
  108.     @text_display.bitmap.draw_text(@text_display.bitmap.rect, Display_Text, 1)
  109.     return unless Use_Nav_Arrows
  110.     @nav_arrows = Sprite.new
  111.     @nav_arrows.bitmap = Cache.system(Nav_Arrow_Image)
  112.   end
  113.   #--------------------------------------------------------------------------
  114.   # * Frame Update
  115.   #--------------------------------------------------------------------------
  116.   def update
  117.     super
  118.     $game_map.update
  119.     update_navigation
  120.     update_all_sprites
  121.     if Input.trigger?(:B) or Input.trigger?(:C)
  122.       SceneManager.return
  123.     end
  124.   end
  125.   #--------------------------------------------------------------------------
  126.   # * Update Navigation
  127.   #--------------------------------------------------------------------------
  128.   def update_navigation
  129.     @display_x -= @speed if Input.press?(:LEFT) && !Input.press?(:RIGHT)
  130.     @display_x += @speed if Input.press?(:RIGHT) && !Input.press?(:LEFT)
  131.     @display_y -= @speed if Input.press?(:UP) && !Input.press?(:DOWN)
  132.     @display_y += @speed if Input.press?(:DOWN) && !Input.press?(:UP)
  133.     @display_x = [0, [@display_x, $game_map.width - $game_map.screen_tile_x].min].max unless $game_map.loop_horizontal?
  134.     @display_y = [0, [@display_y, $game_map.height - $game_map.screen_tile_y].min].max unless $game_map.loop_vertical?
  135.     $game_map.set_display_pos(@display_x, @display_y)
  136.   end
  137.   #--------------------------------------------------------------------------
  138.   # * Update Sprites
  139.   #--------------------------------------------------------------------------
  140.   def update_all_sprites
  141.     @spriteset.update
  142.     @text_display.update
  143.     return unless Use_Nav_Arrows
  144.     @nav_arrows.update
  145.     return unless Use_Nav_Blink_Effect
  146.     @blink_count = (@blink_count + 1) % 40
  147.     @nav_arrows.opacity = 255 if @blink_count < 20
  148.     @nav_arrows.opacity = 0 if @blink_count >= 20
  149.   end
  150.   #--------------------------------------------------------------------------
  151.   # * Termination Processing
  152.   #--------------------------------------------------------------------------
  153.   def terminate
  154.     super
  155.     dispose_all_sprites
  156.     $game_map.set_display_pos(@last_display_x, @last_display_y)
  157.     dispose_variables
  158.   end
  159.   #--------------------------------------------------------------------------
  160.   # * Dispose All Sprites
  161.   #--------------------------------------------------------------------------
  162.   def dispose_all_sprites
  163.     @spriteset.dispose
  164.     @text_display.bitmap.dispose unless @text_display.bitmap.disposed?
  165.     @text_display.dispose
  166.     return unless Use_Nav_Arrows
  167.     @nav_arrows.bitmap.dispose unless @nav_arrows.bitmap.disposed?
  168.     @nav_arrows.dispose
  169.   end
  170.   #--------------------------------------------------------------------------
  171.   # * Dispose Variables * Good Coding Practice *
  172.   #   Any @ variable is always stored in ram. This will free it.
  173.   #--------------------------------------------------------------------------
  174.   def dispose_variables
  175.     @last_display_x = nil
  176.     @last_display_y = nil
  177.     @display_x = nil
  178.     @display_y = nil
  179.     @blink_count = nil
  180.     @speed = nil
  181.     @spriteset = nil
  182.     @text_display = nil
  183.     @nav_arrows = nil
  184.   end
  185. end
  186. class Scene_Map < Scene_Base
  187.   alias test_update update
  188.   def update
  189.     test_update
  190.         if Xane_MapNavSettings::Map_Button_Switch == true
  191.       if Input.trigger?(Xane_MapNavSettings::Map_Button)
  192.         SceneManager.call(Scene_MapNav)
  193.       end
  194.         end
  195.   end
  196. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement