Map Browsing Navigation

Map Browsing Navigation
Xane

​
Versions
Latest Build: 1.5
Spoiler: History
Ruby:
#  Update Log (U - Unreleased | R - Released):
#  1.0(R) - Wrote original version of script.
#  1.1(U) - Added map effects and sprite viewings back in.
#  1.2(U) - Fixed a few bugs.
#  1.3(R) - Rewrote script to use data already provided by RM rather then
#           trying to collect new data. Script will now properly update
#           event data, weather effects, and any pictures display originally
#           in Scene_Map.
#  1.4(R) - Fixed typo error with variable. Added check for display coordinates
#           to check for map edges when maps do not loop.
#  1.5(R) - Fixed some more syntax typos and fixed the check for the display coordinates

Introduction
Wrote this in response to a script request in the sub forum found here. It has all the bells and whistles of your map but allows you to explore it kind of like in Super Mario World when you press 'select' and the arrows appear on the screen letting you navigate to look around the world.

Features
- Explore the given map with a single script call.
- Weather Effects, Pictures, Events, the Player, and other map effects still will show while navigating.
- Has a couple of configure options that let you change the navigation speed, arrow usage, displaying text etc.
- Excellent memory management. This doesn't take pictures of the map and make files, it's all rendered in-engine
like any other map so you don't have to worry about lag even if you're exploring a map as big as 500x500.

Screenshots
None. It's still just whatever map you're on.

How to use
This script is plug-in-play. If you want to access the scene, use the script call "(SceneManager.call(Scene_MapNav)" without quotes in an event or via the main menu if you have another script installed that allows custom commands such as Yanfly's Menu.

Bug Reporting, Compatibility, and Reporting
Spoiler: Please Review
Ruby:
#   Report all bugs to me on the RM forums. Any version prior to the current
#   version is not supported. All bugs steaming from user changes such as
#   modification of code will not be supported. Any compatibility patches
#   will be provided at my own accord and are not guaranteed in any way.

Terms and Conditions
Spoiler: Please Review
Ruby:
#  Retain this header at all times and do not release any new revisions online
#  without prior consent. You may modify the code below at your own discretion
#  but only for private usage. This script may be used both Non Commercially
#  and Commercially with credit provided.

Credits
Just place Xane in your credits somewhere. If it's commercial how about a copy?

Script
Spoiler: Grab it while it's hot!
Ruby:
#==============================================================================
#  Script      : Map Navigation
#  Author      : Xane
#  Build       : v1.5
#  Created On  : 12.17.2020
#  Last Update : 12.19.2020
#------------------------------------------------------------------------------
#  Terms and Conditions:
#  Retain this header at all times and do not release any new revisions online
#  without prior consent. You may modify the code below at your own discretion
#  but only for private usage. This script may be used both Non Commercially
#  and Commercially with credit provided.
#------------------------------------------------------------------------------
#  Bugs, Compatibility, and Reporting:
#   Report all bugs to me on the RM forums. Any version prior to the current
#   version is not supported. All bugs steaming from user changes such as
#   modification of code will not be supported. Any compatibility patches
#   will be provided at my own accord and are not guaranteed in any way.
#------------------------------------------------------------------------------
#  Update Log (U - Unreleased | R - Released):
#  1.0(R) - Wrote original version of script.
#  1.1(U) - Added map effects and sprite viewings back in.
#  1.2(U) - Fixed a few bugs.
#  1.3(R) - Rewrote script to use data already provided by RM rather then
#           trying to collect new data. Script will now properly update
#           event data, weather effects, and any pictures display originally
#           in Scene_Map.
#  1.4(R) - Fixed typo error with variable. Added check for display coordinate
#           to check for map edges when maps do not loop.
#  1.5(R) - Fixed some more syntax typos and fixed the check for the display coordinates
#------------------------------------------------------------------------------
#  Usage:
#  This script is plug-in-play. If you want to access the scene, use the script
#  call "(SceneManager.call(Scene_MapNav)" without quotes in an event or via
#  the main menu if you have another script installed that allows custom
#  commands such as Yanfly's Menu.
#==============================================================================

#==============================================================================
#  ** Xane_MapNavSettings
#------------------------------------------------------------------------------
#  This module handles various settings. New versions may add more settings.
#==============================================================================

module Xane_MapNavSettings

  # Controls how fast you want to move around the map.

  # Use a float point to adjust this setting. The max speed is 1.0
  Nav_Speed = 0.4

  # Set the text to be displayed on the screen.

  # You'll have a max width of 272 pixels to show a string. Consider this
  # when choosing what the message will display.
  Display_Text = 'Press ESC to return'

  # Displays arrows on screen for visual feedback.

  # Arrows use a single image stored inside your 'Graphics/System' folder.
  # The script will then create copies and map them to the edges of the game
  # window. You can also turn off visual feedback if you wish as well as set
  # the value for a 'blink' effect if you want more flare.
  Use_Nav_Arrows = true
  Use_Nav_Blink_Effect = true
  Nav_Arrow_Image = 'Nav_Arrow'

end

#==============================================================================
# ** Scene_MapNav
#------------------------------------------------------------------------------
#  This scene allows the player to have a viewing of the map as well as its
# events across the map by scrolling around.
#==============================================================================

class Scene_MapNav < Scene_MenuBase
  #--------------------------------------------------------------------------
  # * Included Modules
  #--------------------------------------------------------------------------
  include Xane_MapNavSettings
  #--------------------------------------------------------------------------
  # * Start Processing
  #--------------------------------------------------------------------------
  def start
    super
    @last_display_x = $game_map.display_x
    @last_display_y = $game_map.display_y
    @display_x = @last_display_x
    @display_y = @last_display_y
    @blink_count = 0
    @speed = [[Nav_Speed, 1.0].min, 0].max
    create_all_sprites
    $game_map.refresh
  end
  #--------------------------------------------------------------------------
  # * Create All Sprites
  #--------------------------------------------------------------------------
  def create_all_sprites
    @spriteset = Spriteset_Map.new
    @text_display = Sprite.new
    @text_display.bitmap = Bitmap.new(272, 48)
    @text_display.bitmap.draw_text(@text_display.bitmap.rect, Display_Text, 1)
    return unless Use_Nav_Arrows
    @nav_arrows = Sprite.new
    @nav_arrows.bitmap = Cache.system(Nav_Arrow_Image)
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    $game_map.update
    update_navigation
    update_all_sprites
    if Input.trigger?(:B) or Input.trigger?(:C)
      SceneManager.return
    end
  end
  #--------------------------------------------------------------------------
  # * Update Navigation
  #--------------------------------------------------------------------------
  def update_navigation
    @display_x -= @speed if Input.press?(:LEFT) && !Input.press?(:RIGHT)
    @display_x += @speed if Input.press?(:RIGHT) && !Input.press?(:LEFT)
    @display_y -= @speed if Input.press?(:UP) && !Input.press?(:DOWN)
    @display_y += @speed if Input.press?(:DOWN) && !Input.press?(:UP)
    @display_x = [0, [@display_x, $game_map.width - $game_map.screen_tile_x].min].max unless $game_map.loop_horizontal?
    @display_y = [0, [@display_y, $game_map.height - $game_map.screen_tile_y].min].max unless $game_map.loop_vertical?
    $game_map.set_display_pos(@display_x, @display_y)
  end
  #--------------------------------------------------------------------------
  # * Update Sprites
  #--------------------------------------------------------------------------
  def update_all_sprites
    @spriteset.update
    @text_display.update
    return unless Use_Nav_Arrows
    @nav_arrows.update
    return unless Use_Nav_Blink_Effect
    @blink_count = (@blink_count + 1) % 40
    @nav_arrows.opacity = 255 if @blink_count < 20
    @nav_arrows.opacity = 0 if @blink_count >= 20
  end
  #--------------------------------------------------------------------------
  # * Termination Processing
  #--------------------------------------------------------------------------
  def terminate
    super
    dispose_all_sprites
    $game_map.set_display_pos(@last_display_x, @last_display_y)
    dispose_variables
  end
  #--------------------------------------------------------------------------
  # * Dispose All Sprites
  #--------------------------------------------------------------------------
  def dispose_all_sprites
    @spriteset.dispose
    @text_display.bitmap.dispose unless @text_display.bitmap.disposed?
    @text_display.dispose
    return unless Use_Nav_Arrows
    @nav_arrows.bitmap.dispose unless @nav_arrows.bitmap.disposed?
    @nav_arrows.dispose
  end
  #--------------------------------------------------------------------------
  # * Dispose Variables * Good Coding Practice *
  #   Any @ variable is always stored in ram. This will free it.
  #--------------------------------------------------------------------------
  def dispose_variables
    @last_display_x = nil
    @last_display_y = nil
    @display_x = nil
    @display_y = nil
    @blink_count = nil
    @speed = nil
    @spriteset = nil
    @text_display = nil
    @nav_arrows = nil
  end
end

Additional Files
If you're using the arrows, here's a quick sample arrow image. Download it, name it whatever you listed in the settings and place inside 'Graphics/System'.

Spoiler
Nav_Arrow.png
As this is now up, I'll put my comment here

Yes, got it myself just now.
Script change removed by request

Oh and there was a small error in the dispose. @nav_arrow.bitmap.dispose needs to be @nav_arrows.bitmap.dispose unless @nav_arrows.bitmap.disposed?
Thanks, I'll review and update it afterwards.

@Roninator2 You can also clear your script edit. I've condensed it down to 2 lines. Thanks again for your excellent bug hunting skills.
What's the dimensions of the arrow picture?
@Ninjakillzu Currently 544x416 or the default engine's resolution you can adjust it to your screen size though a photo editor. I might change it so you only need to supply a single arrow and just make duplicates and placements using the script.
excellent bug hunting skills
Well thanks, so... under update_navigation you need to specify @display_x not x.
Otherwise the scrolling problem mentioned before is still there.

I think it's because the display_x is used in several places so without pointing directly to it for the value change then it doesn't have the effect desired.
Ruby:
    @display_x = [0, [@display_x, $game_map.width - $game_map.screen_tile_x].min].max unless $game_map.loop_horizontal?
    @display_y = [0, [@display_y, $game_map.height - $game_map.screen_tile_y].min].max unless $game_map.loop_vertical?
    $game_map.set_display_pos(@display_x, @display_y)
@Roninator2
No, x and y are fine because they are just definition variables and I'm directly calling them.
If you do it like that you're going to be adjusting the @display_x and @display_y class variables while trying to check them and get an incorrect reading.


Nevermind, I just realized what you were trying to tell me. I've been so busy today I thought you were saying I had to check it against it and what not. It's fixed now. Thanks again!
I feel a bit like an idiot, but I am having trouble adding this to the Yanfly Menu script.

I put this under commands section
Ruby:
      :map,

and I put this under the custom commands section
Ruby:
      :map   => [       "Map",            0,          0, :Scene_MapNav],

It causes the menu to crash when I open it. Here's the error log.

Yanfly - Ace Menu:642:in `method': undefined method `Scene_MapNav' for class `Scene_Menu', NameError
from Yanfly - Ace Menu:642:in `block in process_custom_commands'
from Yanfly - Ace Menu:639:in `each'
from Yanfly - Ace Menu:639:in `process_custom_commands'
from Yanfly - Ace Menu:611:in `create_command_window'
from MA - Quest Journal:3111:in `create_command_window'
from Casper - CSCA Menu Organizer:129:in `create_command_window'
from Vlue - Basic Options Menu:620:in `create_command_window'
from Scene_Menu:13:in `start'
from Yanfly - Ace Menu:431:in `start'
from Scene_Base:12:in `main'
from Vlue - Basic Options Menu:605:in `run'
from Main:10:in `block in <main>'

What am I doing wrong?

Also, to test it without the Yanfly Ace Menu, I got this error on hitting the ESC key to leave the map

Xane:163:in `dispose_all_sprites': undefined local variable or method `arrow' for #<Scene_MapNav:0x162943c8>, NameError
from Xane:151:in `terminate'
from Scene_Base:16:in `main'
from Vlue - Basic Options Menu:605:in `run'
from Main:10:in `block in <main>'

This is in the latest version, 1.4.

EDIT: I fixed the second error by changing line 163 to this
Ruby:
    @nav_arrows.bitmap.dispose unless @nav_arrows.bitmap.disposed?
It causes the menu to crash when I open it.
Because the command is not correct
Ruby:
      :map     => [         "Map",            0,          0,   :command_map],
Then near the bottom you have to define the method
Ruby:
  def command_map
    SceneManager.call(Scene_MapNav)
  end
Because the command is not correct
Ruby:
      :map     => [         "Map",            0,          0,   :command_map],
Then near the bottom you have to define the method
Ruby:
  def command_map
    SceneManager.call(Scene_MapNav)
  end

/facepalm

I can't believe I didn't look down that far. Thank you!

As for the script, it's incredible and everything I could've asked for! :MV1:
@Roninator2 Gah, I just fixed that! I must have copied the wrong file from the script editor and just reposted the same one. I'm sorry guys, I'll make sure it's right this time.
:rtear:

@Ninjakillzu It's the same stupid typo I fixed earlier but I'll make sure to fix it for good this time and copy the right script back into the topic. I'm glad you like it though! Let me know if you have any other possible ideas for it!

Original thread: https://forums.rpgmakerweb.com/threads/map-browsing-navigation.131168/