Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-------------------------------------------------------------------------------
- # Don't remove this header!
- #-------------------------------------------------------------------------------
- # Custom Map System Script
- # by Trihan
- #
- # Version : 1.2
- #
- # This script is commissioned by Batworks Software.
- #-------------------------------------------------------------------------------
- #-------------------------------------------------------------------------------
- # Version History
- #-------------------------------------------------------------------------------
- # 1.2 - Added icons for fast travel, party swap, shop and save coffins
- # 1.1 - Map name window position will now change if cursor overlaps it.
- # 1.0 - Initial script.
- #-------------------------------------------------------------------------------
- #-------------------------------------------------------------------------------
- # All pictures are located in the Graphics/Maps folder.
- #
- # To call the map scene, use the following script call
- #
- # SceneManager.call(Scene_MapSystem)
- #
- # This script runs mostly automatically. All you need to configure is the
- # graphic and offset for the cursor, the graphic for the player marker, and
- # the regex pattern to use for map filenames.
- #
- # The filename by default needs to meet the following pattern:
- # AreaXMap + name of map + _markerx_markery
- #
- # For example, Area1MapAbandonedShack_141_198.png
- # This will mark the map as belonging to area 1, connect it to the map named
- # AbandonedShack, and display the marker at (141, 198) on the screen.
- #
- # If you change the regex pattern, please ensure that (\d+) still appears in
- # it somewhere, otherwise the script won't be able to determine areas.
- #-------------------------------------------------------------------------------
- module TLBMapSystem
- #-------------------------------------------------------------------------------
- # Config
- CursorIcon = "fingerpointer"
- PlayerMarker = "alicemarker"
- FastTravelMarker = "bellmarker"
- PartySwapMarker = "laylamarker"
- PartySwapSwitch = 506
- ShopMarker = "jiangicon"
- RedCoffinMarker = "coffinmarkerred"
- OrangeCoffinMarker = "coffinmarkerorange"
- BlackCoffinMarker = "coffinmarkerblack"
- CursorXOffset = 5
- CursorYOffset = 0
- IconXOffset = 10
- IconYOffset = 10
- MapRegex = /Area(\d+)Map.*/
- # ** End Config **
- #
- # WARNING: Editing anything beyond this point may result in the script no
- # longer functioning as intended.
- #-------------------------------------------------------------------------------
- end
- module Cache; def self.maps(filename); load_bitmap("Graphics/Maps/", filename); end; end
- class Game_System
- attr_accessor :mapdata
- alias :tlb_mapsystem_initialize :initialize
- def initialize
- tlb_mapsystem_initialize
- create_map_data
- end
- def create_map_data
- @mapdata = {}
- regexpattern = TLBMapSystem::MapRegex
- files = Dir.entries("Graphics/Maps")
- .select { |file| file =~ regexpattern }
- .map { |file| File.basename(file, ".png") }
- areas = []
- files.each { |file|
- area = file.scan(regexpattern)
- if area.size > 0 && !areas.include?(area[0][0])
- areas.push(area[0][0])
- end
- }
- areas.each { |area|
- regexpattern = Regexp.new("Area#{area}Map(.*)")
- @mapdata[area] = files
- .select { |file| file =~ regexpattern }
- .map { |file|
- data = file.scan(regexpattern)[0][0].split("_")
- {
- :name => data[0],
- :filename => file,
- :cursor_x => data[1].to_i,
- :cursor_y => data[2].to_i,
- :visited => false
- }
- }
- }
- end
- def get_visited_maps(area)
- if @mapdata[area]
- @mapdata[area].select { |map| map[:visited] }
- else
- []
- end
- end
- def visit_map(area, mapname)
- map = @mapdata[area].select { |map| map[:name] == mapname }
- if map.size > 0
- map[0][:visited] = true
- end
- end
- end
- class Game_Map
- alias :tlb_mapsystem_setup :setup
- def setup(map_id)
- tlb_mapsystem_setup(map_id)
- mapname = $data_mapinfos[map_id].name
- area = get_current_area
- if area
- $game_system.visit_map(area, mapname)
- end
- end
- def get_current_area
- area = self.note.scan(/<area: ?(\d+)/)
- if area.size > 0
- return area[0][0]
- else
- return nil
- end
- end
- def get_map(mapname)
- area = get_current_area
- if area
- map = $game_system.mapdata[area].select { |map| map[:name] == mapname }
- if map
- map[0]
- else
- nil
- end
- end
- end
- def get_current_map
- mapname = $data_mapinfos[@map_id].name
- get_map(mapname)
- end
- def get_directional_map(start_map, direction)
- map_match = $data_mapinfos.select{|key, value| value.name == start_map[:name]}.keys
- if map_match
- map_id = map_match.first
- map = nil
- if map_id
- mapfile = load_data(sprintf("Data/Map%03d.rvdata2", map_id))
- case direction
- when 2
- map = mapfile.note.scan(/<south: ?(.*)>/)
- when 4
- map = mapfile.note.scan(/<west: ?(.*)>/)
- when 6
- map = mapfile.note.scan(/<east: ?(.*)>/)
- when 8
- map = mapfile.note.scan(/<north: ?(.*)>/)
- else
- map = nil
- end
- if map && map.size > 0
- map_strings = map[0][0].split("/")
- map_strings.each{|string|
- map_obj = get_map(string)
- if map_obj[:visited]
- return map_obj
- end
- }
- else
- nil
- end
- end
- end
- nil
- end
- def get_south_map(start_map)
- get_directional_map(start_map, 2)
- end
- def get_west_map(start_map)
- get_directional_map(start_map, 4)
- end
- def get_east_map(start_map)
- get_directional_map(start_map, 6)
- end
- def get_north_map(start_map)
- get_directional_map(start_map, 8)
- end
- end
- class Window_MapLabel < Window_Base
- def initialize
- super(0, 0, Graphics.width, 120)
- @text = ""
- refresh
- end
- def set_text(text)
- @text = text
- refresh
- end
- def refresh
- create_contents
- draw_text(0, 0, 32, line_height, @text)
- end
- end
- class Window_Mystery < Window_Base
- def initialize
- super(0, 0, 100, fitting_height(1))
- self.width = text_size("???").width + standard_padding * 2
- create_contents
- self.x = Graphics.width / 2 - self.width / 2
- self.y = Graphics.height / 2 - self.height / 2
- self.opacity = 0
- draw_text(0, 0, 32, line_height, "???")
- end
- end
- class Scene_MapSystem < Scene_Base
- def start
- super
- create_background
- create_map
- @current_map = $game_map.get_current_map
- @selected_map = $game_map.get_current_map
- create_player_marker
- create_pointer
- create_label_window
- create_mystery_window
- end
- def terminate
- super
- dispose_background
- dispose_map
- dispose_player_marker
- dispose_pointer
- end
- def update
- super
- end
- def create_background
- @sprite = Sprite.new
- @sprite.bitmap = Cache.maps("Mapbackground")
- center_sprite(@sprite)
- end
- def create_map
- @map_icons = []
- maps = $game_system.get_visited_maps($game_map.get_current_area)
- if maps.size > 0
- @area_sprites = []
- maps.each { |map|
- map_match = $data_mapinfos.select{|key, value| value.name == map[:name]}.keys
- if map_match
- map_id = map_match.first
- if map_id
- mapfile = load_data(sprintf("Data/Map%03d.rvdata2", map_id))
- fasttravel = mapfile.note.scan(/<fasttravel: ?(\d+)>/)
- partyswap = mapfile.note.scan(/<partyswap>/)
- shop = mapfile.note.scan(/<shop>/)
- save = mapfile.note.scan(/<save: ?(\d)>/)
- if fasttravel && fasttravel.size > 0
- switch_id = fasttravel[0][0].to_i
- if $game_switches[switch_id]
- sprite = Sprite.new
- sprite.bitmap = Cache.maps(TLBMapSystem::FastTravelMarker)
- sprite.x = map[:cursor_x] - TLBMapSystem::IconXOffset
- sprite.y = map[:cursor_y] - TLBMapSystem::IconYOffset
- sprite.z += 100
- @map_icons.push(sprite)
- end
- end
- if partyswap && partyswap.size > 0
- switch_id = TLBMapSystem::PartySwapSwitch
- if $game_switches[switch_id]
- sprite = Sprite.new
- sprite.bitmap = Cache.maps(TLBMapSystem::PartySwapMarker)
- sprite.x = map[:cursor_x] + TLBMapSystem::IconXOffset
- sprite.y = map[:cursor_y] - TLBMapSystem::IconYOffset
- sprite.z += 100
- @map_icons.push(sprite)
- end
- end
- if shop && shop.size > 0
- sprite = Sprite.new
- sprite.bitmap = Cache.maps(TLBMapSystem::ShopMarker)
- sprite.x = map[:cursor_x] - TLBMapSystem::IconXOffset
- sprite.y = map[:cursor_y] + TLBMapSystem::IconYOffset
- sprite.z += 100
- @map_icons.push(sprite)
- end
- if save && save.size > 0
- save_type = save[0][0].to_i
- case save_type
- when 1
- bitmap = Cache.maps(TLBMapSystem::RedCoffinMarker)
- when 2
- bitmap = Cache.maps(TLBMapSystem::OrangeCoffinMarker)
- when 3
- bitmap = Cache.maps(TLBMapSystem::BlackCoffinMarker)
- else
- bitmap = Cache.maps(TLBMapSystem::RedCoffinMarker)
- end
- sprite = Sprite.new
- sprite.bitmap = bitmap
- sprite.x = map[:cursor_x] + TLBMapSystem::IconXOffset
- sprite.y = map[:cursor_y] + TLBMapSystem::IconYOffset
- sprite.z += 100
- @map_icons.push(sprite)
- end
- end
- end
- sprite = Sprite.new
- sprite.bitmap = Cache.maps(map[:filename])
- center_sprite(sprite)
- @area_sprites.push(sprite)
- }
- end
- end
- def create_player_marker
- @player_marker_sprite = Sprite.new
- @player_marker_sprite.bitmap = Cache.maps(TLBMapSystem::PlayerMarker)
- if @current_map
- x = @current_map[:cursor_x]
- y = @current_map[:cursor_y]
- @player_marker_sprite.x = x if x
- @player_marker_sprite.y = y if y
- @player_marker_sprite.z += 100
- end
- end
- def create_pointer
- @pointer_sprite = Sprite.new
- @pointer_sprite.bitmap = Cache.menus(TLBMapSystem::CursorIcon)
- if @selected_map
- x = @selected_map[:cursor_x] + TLBMapSystem::CursorXOffset
- y = @selected_map[:cursor_y] + TLBMapSystem::CursorYOffset
- @pointer_sprite.x = x if x
- @pointer_sprite.y = y if y
- @pointer_sprite.z += 200
- end
- end
- def create_label_window
- @label_window = Window_MapLabel.new
- if @selected_map
- refresh_label
- end
- end
- def create_mystery_window
- @mystery_window = Window_Mystery.new
- if @area_sprites && @area_sprites.size > 0
- @mystery_window.hide
- end
- end
- def refresh_label
- map_text = @selected_map[:name]
- @label_window.set_text(map_text)
- if @pointer_sprite.y < @label_window.height
- @label_window.y = Graphics.height - @label_window.height
- else
- @label_window.y = 0
- end
- end
- def update
- super
- if Input.trigger?(:B)
- return_scene
- end
- if @area_sprites && @area_sprites.size > 0
- if Input.trigger?(:DOWN)
- map = $game_map.get_south_map(@selected_map)
- end
- if Input.trigger?(:LEFT)
- map = $game_map.get_west_map(@selected_map)
- end
- if Input.trigger?(:RIGHT)
- map = $game_map.get_east_map(@selected_map)
- end
- if Input.trigger?(:UP)
- map = $game_map.get_north_map(@selected_map)
- end
- end
- if map
- x = map[:cursor_x] + TLBMapSystem::CursorXOffset
- y = map[:cursor_y] + TLBMapSystem::CursorYOffset
- @pointer_sprite.x = x if x
- @pointer_sprite.y = y if y
- @selected_map = map
- refresh_label
- end
- if Graphics.frame_count % 60 == 0 && @area_sprites
- current_sprite = @area_sprites.select { |sprite| sprite.bitmap == Cache.maps(@current_map[:filename]) }
- if current_sprite
- current_sprite[0].flash(Color.new(255, 255, 255, 255), 60)
- end
- end
- if @area_sprites
- @area_sprites.each {|sprite| sprite.update }
- end
- end
- def dispose_background
- @sprite.bitmap.dispose
- @sprite.dispose
- end
- def dispose_map
- if @area_sprites
- @area_sprites.each { |sprite|
- sprite.bitmap.dispose
- sprite.dispose
- }
- end
- if @map_icons
- @map_icons.each { |sprite|
- sprite.bitmap.dispose
- sprite.dispose
- }
- end
- end
- def dispose_player_marker
- @player_marker_sprite.bitmap.dispose
- @player_marker_sprite.dispose
- end
- def dispose_pointer
- @pointer_sprite.bitmap.dispose
- @pointer_sprite.dispose
- end
- def center_sprite(sprite)
- sprite.ox = sprite.bitmap.width / 2
- sprite.oy = sprite.bitmap.height / 2
- sprite.x = Graphics.width / 2
- sprite.y = Graphics.height / 2
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement