#sb:nap_minimap [gui]
#===============================================================================
# Game Event
# For: Adding a name-accessor to it.
#===============================================================================
class Game_Event
if !defined?(self.name) || !defined?(self.name=())
attr_accessor :name
#---------------------------------------------------------------------------
# Initialize [ALIAS]
#---------------------------------------------------------------------------
alias nam_minimap_initialize initialize
def initialize(map_id, event)
nam_minimap_initialize(map_id, event)
@name = event.name
end
end
end
#===============================================================================
# Nap::Minimap
#===============================================================================
module Nap; class Minimap
#-----------------------------------------------------------------------------
# Super Visible Setter
# For hiding/unhiding the minimap
#-----------------------------------------------------------------------------
def super_visible=(v)
return if !@has_map
update(true) if v # Is required to make sure that the minimap is up2date before it becomes visible. Imagine if the player teleports to another section of the map or comes out of a battle after walking without this. Then the minimap would be off for 1 frame (which is noticable).
@sprite.visible = v
@overlay.visible = v if @overlay
@border.visible = v
@player_sprite.visible = v
end
#-----------------------------------------------------------------------------
# * initialize
#-----------------------------------------------------------------------------
def initialize
@save_icons = [] # contains map-icon data for saving&loading
@@cache ||= {}
@disposed = false
@arrows_src_img = Cache.minimap(ARROWS) if !@arrows_src_img
@overlay_enabled = OVERLAY_ENABLED
@@mode = MODE if !defined?(@@mode)
@map_zoom_x = MAP_ZOOM_X
@map_zoom_y = MAP_ZOOM_Y
@border_img = Cache.minimap(BORDER_IMG) if BORDER_IMG
@cursor_img = Cache.minimap(CURSOR_IMG) if CURSOR_IMG
@enabled = true
@visible = false
@visibility_override = :normal
@sprite = Sprite.new
@@opacity = OPACITY if !defined?(@@opacity)
@show_icons = true
@icons = []
@updated_count = 0
@mm_events = Minimap.get_minimap_events
set_location(LOCATION) # also calls: create_sprite
create_cursor
load_data
# Icons for poi
# $mm_icons contains a hash with the event_id as the key and it's
# sprite-character as the value.
if $imported[:nap_minimap_menu]
$mm_icons[:events].values.each { |icon| icon.dispose } if !$mm_icons.nil?
$mm_icons = {:events => {}}
@mm_events.each { |mm_ev|
if mm_ev.event.sprite
icon = Bitmap.new(mm_ev.event.sprite.src_rect.width, mm_ev.event.sprite.src_rect.height)
icon.blt(0, 0, mm_ev.event.sprite.bitmap, mm_ev.event.sprite.src_rect)
$mm_icons[:events][mm_ev.event.id] = icon
end
}
end
end
#-----------------------------------------------------------------------------
# * store_player_source_rect
#-----------------------------------------------------------------------------
def store_player_source_rect
$mm_icons[:player_src_rect] = $game_player.sprite.src_rect if $imported[:nap_minimap_menu]
end
#-----------------------------------------------------------------------------
# * Create Map Events
#-----------------------------------------------------------------------------
def self.get_minimap_events
mm_events = []
# Loop through all map events
$game_map.events.values.each { |e|
next if e.list.nil?
new_mm_ev = nil
name = e.name # Default name in case no name-command will be found
desc = nil
e.nap_note.each { |note|
new_mm_ev = add_ev_by_nap_note(e) if new_mm_ev.nil?
if note =~ /<#{Regexp.escape(Minimap::EV_NAME_COMMENT_TAG)}: ([^>]*)>/ix
name = $1
elsif note =~ /<#{Regexp.escape(Minimap::EV_DESC_COMMENT_TAG)}: ([^>]*)>/ix
desc = $1
end
} # e.nap_note.each { |note|
# Old (outcommented) code below:
#~ # Loop through all commands within the looped-event.
#~ e.list.each{ |command|
#~ # Scan for new mm_event command
#~ new_mm_ev = Minimap.add_ev_by_command(e, command) if new_mm_ev.nil?
#~
#~ # Scan for name/desc commands
#~ if command.code == 108
#~ if command.parameters[0] =~ /<#{Regexp.escape(Minimap::EV_NAME_COMMENT_TAG)}: ([^>]*)>/ix
#~ name = $1
#~ elsif command.parameters[0] =~ /<#{Regexp.escape(Minimap::EV_DESC_COMMENT_TAG)}: ([^>]*)>/ix
#~ desc = $1
#~ end
#~ end
#~ } # Loop through all commands within the looped-event.
if !new_mm_ev.nil?
new_mm_ev.name = name
new_mm_ev.desc = desc
mm_events << new_mm_ev
end
} # Loop through all map events
return mm_events
end
#-----------------------------------------------------------------------------
# Add Event By Nap-Note
#-----------------------------------------------------------------------------
def self.add_ev_by_nap_note(event)
event.nap_note.each { |note|
if note =~ /<#{Regexp.escape(Minimap::EV_COMMENT_TAG)}: ([^>]*)>/ix
return MM_Event.new(event, $1.downcase.split(' '))
end
}
return nil
end
#-----------------------------------------------------------------------------
# * Add Event By Command
# Returns: The minimap_event or nil if none was found.
#-----------------------------------------------------------------------------
def self.add_ev_by_command(ev, command)
if command.code == 108
if command.parameters[0] =~ /<#{Regexp.escape(Minimap::EV_COMMENT_TAG)}: ([^>]*)>/ix
return MM_Event.new(ev, $1.downcase.split(' '))
end
end
return nil
end
#-----------------------------------------------------------------------------
# * Add Event Unique
# - Only adds the event if it doesn't already exist on the minimap.
#-----------------------------------------------------------------------------
def add_ev_unique(ev, command)
return if @mm_events.find {|e| e.event.id == ev.id}
new_mm_ev = Minimap.add_ev_by_command(ev, command)
@mm_events << new_mm_ev if !new_mm_ev.nil?
end
#-----------------------------------------------------------------------------
# * Remove Event
# - Removes the event from the minimap
#-----------------------------------------------------------------------------
def remove_ev(ev_id)
@mm_events.reject!{ |e| e.event.id == ev_id}
end
#-----------------------------------------------------------------------------
# * Create Cursor
#-----------------------------------------------------------------------------
def create_cursor
@player_sprite.dispose if @player_sprite
@player_sprite = Sprite.new
@player_sprite.bitmap = Bitmap.new(CURSOR_SIZE, CURSOR_SIZE)
@player_sprite.ox = CURSOR_SIZE / 2.0
@player_sprite.oy = CURSOR_SIZE / 2.0
if !USE_PLAYER_GRAPHIC
if @cursor_img
@player_sprite.bitmap.stretch_blt(Rect.new(0,0,@player_sprite.bitmap.width, @player_sprite.bitmap.height),@cursor_img,Rect.new(0,0,@cursor_img.width,@cursor_img.height), 255)
else
@player_sprite.bitmap.fill_rect(0, 0, CURSOR_SIZE, CURSOR_SIZE, CURSOR_COLOR)
end
end
@player_sprite.z = Z_INDEX_CURSOR
@player_sprite.visible = @visible
reset_cursor_location
end
#-----------------------------------------------------------------------------
# * Update Player Cursor
# - Only called when USE_PLAYER_GRAPHIC == true
#-----------------------------------------------------------------------------
def update_player_cursor
player_character = $game_player.sprite
return if !player_character || player_character.disposed?
@player_sprite.bitmap.clear
@player_sprite.bitmap.stretch_blt(Rect.new(0,0,@player_sprite.bitmap.width, @player_sprite.bitmap.height),
player_character.bitmap,
player_character.src_rect,
255)
end
#-----------------------------------------------------------------------------
# * Reset Cursor Location
#-----------------------------------------------------------------------------
def reset_cursor_location
@player_sprite.x = @location.x + @location.width / 2 + 16 * @map_zoom_x
@player_sprite.y = @location.y + @location.height / 2 + 16 * @map_zoom_y
end
#-----------------------------------------------------------------------------
# * Set location
# Sets the new location and size of the minimap
#-----------------------------------------------------------------------------
def set_location(rect)
@location = rect
@sprite.x = rect.x
@sprite.y = rect.y
@sprite.z = Z_INDEX_MAP
@sprite.bitmap.dispose if
@sprite.bitmap = Bitmap.new(rect.width, rect.height)
create_overlay if OVERLAY_IMG
create_sprite
reset_cursor_location if @player_sprite
end
#-----------------------------------------------------------------------------
# * Refresh
#-----------------------------------------------------------------------------
def refresh
@has_map = false
return if !SceneManager.scene.instance_of?(Scene_Map)
@mm_events = Minimap.get_minimap_events
create_overlay if OVERLAY_IMG
create_sprite
reset_cursor_location if @player_sprite
end
#-----------------------------------------------------------------------------
# * Create Overlay
#-----------------------------------------------------------------------------
def create_overlay
@overlay.dispose if @overlay
@overlay = Sprite.new
# bitmap
if SCALE_OVERLAY
img = Cache.minimap(OVERLAY_IMG)
@overlay.bitmap = Bitmap.new(@location.width, @location.height)
@overlay.bitmap.stretch_blt(Rect.new(0, 0, @location.width, @location.height),
img, Rect.new(0, 0, img.width, img.height))
img.dispose
else
@overlay.bitmap = Cache.minimap(OVERLAY_IMG)
end
@overlay.x = @location.x + OVERLAY_OFFSET[0]
@overlay.y = @location.y + OVERLAY_OFFSET[1]
@overlay.z = Z_INDEX_OVERLAY
@overlay.visible = @visible && @overlay_enabled
end
#-----------------------------------------------------------------------------
# * Get Effective Map ID
#-----------------------------------------------------------------------------
def self.get_effective_map_id
if MAP_IMAGE_OVERRIDE.has_key?($game_map.map_id)
return MAP_IMAGE_OVERRIDE[$game_map.map_id]
else
return $game_map.map_id
end
end
#-----------------------------------------------------------------------------
# * get_map_bitmap
# - returns the map bitmap (or nil if non exists) and sets @has_image
# - also saves/loads from custom cache (if applicable)
#-----------------------------------------------------------------------------
def get_map_bitmap
eff_map_id = Minimap.get_effective_map_id
filename = "#{FILE_PREFIX}#{eff_map_id.to_s.rjust(3, '0')}"
# Use the bitmap from the custom cache if there is one.
if @@cache.has_key?(Minimap.get_effective_map_id)
@cached = true
@has_image = true
return @@cache[eff_map_id]
else
@cached = false
end
# Rescue is required because if the game data is encrypted then
# File.exists? will always return false (not supported by RPG Maker)
# and Cache.load_bitmap will crash.
# RM encryption supported methods: load_data(), Bitmap.new(),
# Graphics.transition()
#@has_image = (Cache.load_bitmap("Graphics/#{FOLDER}","#{filename}.#{FILE_EXT}") != nil)
begin
bmp = Bitmap.new("Graphics/#{FOLDER}/#{filename}.#{FILE_EXT}")
@has_image = true
rescue
@has_image = false
return nil
end
# Save to cache if conditions are met
if (bmp.width * bmp.height / 32) >= MIN_CACHE_SIZE && !@@cache.has_key?(eff_map_id)
@@cache[eff_map_id] = bmp
@cached = true
end
return bmp
end
#-----------------------------------------------------------------------------
# * Set Zoom
#-----------------------------------------------------------------------------
def set_zoom
# Set Zoom
if MAP_ZOOMS[$game_map.map_id] == nil
@map_zoom_x = MAP_ZOOM_X
@map_zoom_y = MAP_ZOOM_Y
else
@map_zoom_x = MAP_ZOOMS[$game_map.map_id][0]
@map_zoom_y = MAP_ZOOMS[$game_map.map_id][1]
end
end
#-----------------------------------------------------------------------------
# * Create Sprite (the map itself)
#-----------------------------------------------------------------------------
def create_sprite
map_img = get_map_bitmap
if !@has_image
@has_map = false
return
end
@has_map = true
@map_img = map_img.dup
@map_w = map_img.width.to_f
@map_h = map_img.height.to_f
@base_map.dispose if @base_map
case @@mode
when :default
@sprite.bitmap.stretch_blt(Rect.new(0, 0, @location.width, @location.height), map_img, Rect.new(0,0,@map_w,@map_h), @@opacity)
@base_map = Bitmap.new(@location.width, @location.height)
@base_map.stretch_blt(Rect.new(0, 0, @location.width, @location.height), map_img, Rect.new(0,0,@map_w,@map_h), @@opacity)
when :scroll
set_zoom
# Store source map (zoomed)
@base_map = Bitmap.new(map_img.width * @map_zoom_x, map_img.height * @map_zoom_y)
@base_map.stretch_blt(Rect.new(0,0,@base_map.width, @base_map.height), map_img, Rect.new(0,0,map_img.width,map_img.height), @@opacity)
else
raise "create_sprite: Unknown @@mode (#{@@mode})"
end
map_img.dispose if !@cached
create_border
@sprite.visible = @visible
render_events
end
def refresh_events
@mm_events = Minimap.get_minimap_events
end
#-----------------------------------------------------------------------------
# * Render Events
#-----------------------------------------------------------------------------
def render_events
return if @mm_events.length == 0 || @player_sprite.nil?
# There is no need to render a clean map (basemap w/o events) in :scroll_mode because the sets_scroll handles that.
case @@mode
when :default
# Render the basemap onto the new spritemap (removing all events and such).
@sprite.bitmap.dispose if @sprite.bitmap
@sprite.bitmap = Bitmap.new(@location.width, @location.height)
@sprite.bitmap.blt(0,0,@base_map, Rect.new(0,0,@sprite.bitmap.width,@sprite.bitmap.height))
when :scroll
# Make sur ethat the scroll_src_rect is set before rendering events in :scroll mode
get_scroll_base_src_rect if !@scroll_src_rect
else
raise "render_events: Unknown @@mode (#{@@mode})"
end
@mm_events.each { |ev| ev.render(self, @sprite.bitmap, @map_zoom_x, @map_zoom_y) }
end
#-----------------------------------------------------------------------------
# * Create Border
#-----------------------------------------------------------------------------
def create_border
@border.dispose if @border
@border = Sprite.new
@border.bitmap = Bitmap.new(@location.width + BORDER_SIZE * 2, @location.height + BORDER_SIZE * 2)
@border.x = @location.x - BORDER_SIZE
@border.y = @location.y - BORDER_SIZE
if BORDER_IMG
@border.bitmap.stretch_blt(Rect.new(0,0,@border.bitmap.width, @border.bitmap.height),@border_img,Rect.new(0,0,@border_img.width,@border_img.height), 255)
else
@border.bitmap.fill_rect(0, 0, @border.bitmap.width, BORDER_SIZE, BORDER_COLOR)
@border.bitmap.fill_rect(@border.bitmap.width - BORDER_SIZE, 0, BORDER_SIZE, @border.bitmap.height, BORDER_COLOR)
@border.bitmap.fill_rect(0, @border.bitmap.height - BORDER_SIZE, @border.bitmap.width, BORDER_SIZE, BORDER_COLOR)
@border.bitmap.fill_rect(0, 0, BORDER_SIZE, @border.bitmap.height, BORDER_COLOR)
end
@border.z = Z_INDEX_MAP
@border.visible = @visible
end
#-----------------------------------------------------------------------------
# * Set Mode
#-----------------------------------------------------------------------------
def set_mode(mode)
raise "Minimap.set_mode(#{mode}) Invalid mode." if mode != :default && mode != :scroll
@@mode = mode
@sprite.bitmap.clear # This line is necessary in case the opacity is < 255.
create_sprite
reset_cursor_location
end
#-----------------------------------------------------------------------------
# * Set Cursor Location
#-----------------------------------------------------------------------------
def set_cursor_location
ratio_x = @location.width / @map_w
ratio_y = @location.height / @map_h
map_x = $game_player.real_x * 32 * ratio_x + @location.x
map_y = $game_player.real_y * 32 * ratio_y + @location.y
@player_sprite.x = map_x
@player_sprite.y = map_y
end
#-----------------------------------------------------------------------------
# * World map to minimap coordinates
# real_x & real_y is the location in pixels (upper left corner is 0,0)
# returns 2 values
# Note: real_x usually requires a * 32 multiplication
#-----------------------------------------------------------------------------
def to_minimap_coords(real_x, real_y)
case @@mode
when :default
ratio_x = @location.width.to_f / @map_w.to_f
ratio_y = @location.height.to_f / @map_h.to_f
x = real_x * @map_zoom_x
y = real_y * @map_zoom_y
return real_x * ratio_x, real_y * ratio_y
when :scroll
real_x += 16
real_y += 16
x = real_x * @map_zoom_x
y = real_y * @map_zoom_y
return x, y
else
raise "def to_minimap_coords - unknown mode: #{@@mode}"
end
end
#-----------------------------------------------------------------------------
# * Get Scroll Base Source Rectangle
# - This method contains the real logic for drawing and calculating the
# scrolling map.
#-----------------------------------------------------------------------------
def get_scroll_base_src_rect
half_w = @location.width / 2
half_h = @location.height / 2
# Calculate the location of the player on the basemap with zoom factor
x = $game_player.real_x * 32 * @map_zoom_x - half_w
y = $game_player.real_y * 32 * @map_zoom_y - half_h
mw = @map_img.width.to_f * @map_zoom_x
mh = @map_img.height.to_f * @map_zoom_y
dh = @location.height - mh
dw = @location.width - mw
equals = @location.width > mw && @location.height > mh
if AUTO_CORRECT_MAP_SCROLL# && equals
# The code below makes sure that the map is not scrolled when the player
# is near the edge of the map. Otherwise you could see the minimap bg
# near the edge...
if x < 0 # Prevent the map from scrolling too far to the right (otherwise creating a gap on the left side)
delta_x = x
x = 0 # Prevent the map from scrolling too far to the right (otherwise creating a gap on the left side)
# Because the map did not scroll we have to adjust the player cursor so that he is stilled drawn on the correct location on the minimap.
@player_sprite.x = @location.x + @location.width / 2 + delta_x + 16 * @map_zoom_x
elsif x + @location.width > @base_map.width
delta_x = (x + @location.width) - @base_map.width
x = @base_map.width - @location.width # Prevent the map from scrolling too far to the left (otherwise creating a gap on the right side)
# Because the map did not scroll we have to adjust the player cursor so that he is stilled drawn on the correct location on the minimap.
@player_sprite.x = @location.x + @location.width / 2 + delta_x + 16 * @map_zoom_x
end
if y < 0 # Prevent the map from scrolling too far to the bottom (otherwise creating a gap on the top side)
delta_y = y
y = 0 # Prevent the map from scrolling too far to the right (otherwise creating a gap on the left side)
# Because the map did not scroll we have to adjust the player cursor so that he is stilled drawn on the correct location on the minimap.
@player_sprite.y = @location.y + @location.height / 2 + delta_y + 16 * @map_zoom_y
elsif y + @location.height > @base_map.height
delta_y = (y + @location.height) - @base_map.height
y = @base_map.height - @location.height # Prevent the map from scrolling too far to the left (otherwise creating a gap on the right side)
# Because the map did not scroll we have to adjust the player cursor so that he is stilled drawn on the correct location on the minimap.
@player_sprite.y = @location.y + @location.height / 2 + delta_y + 16 * @map_zoom_y
end
end
if equals
if y < 0 # Prevent the map from scrolling too far to the bottom (otherwise creating a gap on the top side)
delta_y = y
y = 0 # Prevent the map from scrolling too far to the right (otherwise creating a gap on the left side)
# Because the map did not scroll we have to adjust the player cursor so that he is stilled drawn on the correct location on the minimap.
#@player_sprite.y = @location.y + @location.height / 2 + delta_y + 16 * @map_zoom_y
@player_sprite.y -= dh
end
if x < 0 # Prevent the map from scrolling too far to the right (otherwise creating a gap on the left side)
delta_x = x
x = 0 # Prevent the map from scrolling too far to the right (otherwise creating a gap on the left side)
# Because the map did not scroll we have to adjust the player cursor so that he is stilled drawn on the correct location on the minimap.
@player_sprite.x -= dw
end
#unless equals
cx = (@location.width - mw).ceil / 2
cy = (@location.height - mh).ceil / 2
x -= cx #* @map_zoom_x
y -= cy #* @map_zoom_y
@player_sprite.y += cy
@player_sprite.x += cx
#end
end
@scroll_src_rect = Rect.new(x,y,@location.width, @location.height)
return @scroll_src_rect
end
#-----------------------------------------------------------------------------
# * Set Scroll
#-----------------------------------------------------------------------------
def set_scroll
@sprite.bitmap.clear # This line is necessary in case the opacity is < 255.
# BG Color
if BG_COLOR != nil
@sprite.bitmap.fill_rect(0, 0, @sprite.bitmap.width, @sprite.bitmap.height,
Color.new(BG_COLOR.red, BG_COLOR.blue, BG_COLOR.green, @@opacity))
end
# Redraw the (newly) visible portion on the minimap
@sprite.bitmap.stretch_blt(Rect.new(0,0,@location.width,@location.height),
@base_map,
get_scroll_base_src_rect,
255 # opacity was already applied when caching the @sprite.bitmap. So keep it at 255 here.
) # stretch_blt
end
#-----------------------------------------------------------------------------
# * Blink Cursor
#-----------------------------------------------------------------------------
def blink_cursor
@player_sprite.visible = !BLINK_PLAYER || Nap::MM_Event.blink_visible?
end
#-----------------------------------------------------------------------------
# * Update
# Set forced to true to skip the frame-skipping.
#-----------------------------------------------------------------------------
def update(forced=true)
if !forced && FRAME_SKIP
if @updated_count < Nap::Minimap::FRAME_SKIP
@updated_count += 1
else
@updated_count = 0
return
end
end
return if !SceneManager.scene.instance_of?(Scene_Map) || @disposed
if (SceneManager.scene.instance_of?(Scene_Map) || @visibility_override == :show) && @visibility_override != :hide && @enabled && switch_enabled? && @has_image
set_visibility(true) if !@visible
MM_Event.update_blink
blink_cursor
update_player_cursor if USE_PLAYER_GRAPHIC
case @@mode
when :default
set_cursor_location
when :scroll
set_scroll
else
raise "update: Unknown @@mode (#{@@mode})"
end
render_events
@icons.each { |i| i.render(self, @sprite.bitmap) } if @show_icons
@visible = true
else
set_visibility(false) if @visible
@visible = false
end
end
#-----------------------------------------------------------------------------
# Switch Enabled?
#-----------------------------------------------------------------------------
def switch_enabled?
return true if ENABLED_SWITCH == -1
return $game_switches[ENABLED_SWITCH]
end
#-----------------------------------------------------------------------------
# * Set Visibiliy Override
# - Sets minimap visibility according to item/wpn/armor settings
# - returns true if the map should be visible
#-----------------------------------------------------------------------------
def item_visiblity
return true if !REQUIRE_ITEM # return true if items are not required
map_id = $game_map.map_id
if ITEMS[:item].has_key?(map_id)
$data_items.each { |i|
next if i.nil?
return true if ITEMS[:item][map_id].include?(i.id) && $game_party.item_number(i) > 0
}
end
if ITEMS[:weapon].has_key?(map_id)
$data_weapons.each { |w|
next if w.nil?
return true if ITEMS[:weapon][map_id].include?(w.id) && $game_party.item_number(w) > 0
}
end
if ITEMS[:armor].has_key?(map_id)
$data_armors.each { |a|
next if a.nil?
return true if ITEMS[:armor][map_id].include?(a.id) && $game_party.item_number(a) > 0
}
end
return false
end
#-----------------------------------------------------------------------------
# * Set Visibiliy Override
#-----------------------------------------------------------------------------
def set_visibility_override
if !item_visiblity
@visibility_override = :hide
return
end
# Always hide/show on this map depending on the 2 setting arrays
@visibility_override = :normal
if ALWAYS_SHOW.include?($game_map.map_id)
@visibility_override = :show
elsif ALWAYS_HIDE.include?($game_map.map_id)
@visibility_override = :hide
end
end
#-----------------------------------------------------------------------------
# * Set Visibility
#-----------------------------------------------------------------------------
def set_visibility(visibility=@visible)
@sprite.visible = visibility
@border.visible = visibility if @border
@player_sprite.visible = visibility if @player_sprite
@overlay.visible = visibility && @overlay_enabled if @overlay
end
#-----------------------------------------------------------------------------
# * Add Icon
# - icon_id: is an identifier purely used to allow to remove it later by
# using this id again. If you do not supply an id it will default to -1.
# - x,y: the location on the real map in pixels (not in tiles).
# - icon_index: the index of the icon from the ICON_SHEET. Starts at 0 but
# the 0-index is by default an empy icon.
#-----------------------------------------------------------------------------
def add_icon(icon_id=-1, x, y, icon_index)
icon_sheet = Cache.system(ICON_SHEET)
icon_img = Bitmap.new(24, 24)
rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
icon_img.blt(0, 0, icon_sheet, rect)
@icons << MM_Icon.new(icon_id, x, y, icon_img)
icon_sheet.dispose
@save_icons << [icon_id, x, y, icon_index]
end
#-----------------------------------------------------------------------------
# * Remove Icon
#-----------------------------------------------------------------------------
def rem_icon(id)
@icons.each { |i| i.dispose if i.id == id }
@icons.reject! { |i| i.id == id }
@save_icons.reject! { |i| i[0] == id}
end
#-----------------------------------------------------------------------------
# * Dispose
#-----------------------------------------------------------------------------
def dispose
@disposed = true
@map_img.dispose if @map_img
@map_img = nil
@sprite.dispose if @sprite && !@sprite.disposed?
@player_sprite.dispose if @player_sprite && !@player_sprite.disposed?
@border.dispose if @border && !@border.disposed?
@border_img.dispose if @border_img && !@border_img.disposed?
@cursor_img.dispose if @cursor_img && !@cursor_img.disposed?
@overlay.dispose if @overlay && !@overlay.disposed?
@base_map.dispose if @base_map && !@base_map.disposed?
@arrows_src_img.dispose if @arrows_src_img && !@arrows_src_img.disposed?
@icons.each { |i| i.dispose if i && !i.disposed?}
end
end; end # Nap; Minimap
#===============================================================================
# Cache
#===============================================================================
module Cache
#-----------------------------------------------------------------------------
# * Get Minimap Graphic [NEW]
#-----------------------------------------------------------------------------
def self.minimap(filename)
load_bitmap("Graphics/#{Nap::Minimap::FOLDER}/", filename)
end
end
#===============================================================================
# Game Party
# To show/hide the minimap whenever the party gains/loses a 'map-related' item
#===============================================================================
class Game_Party < Game_Unit
#-----------------------------------------------------------------------------
# Gain Item [ALIAS]
#-----------------------------------------------------------------------------
alias nap_minimap_gain_item gain_item
def gain_item(item, amount, include_equip = false)
nap_minimap_gain_item(item, amount, include_equip)
$minimap.set_visibility_override if $minimap && Nap::Minimap::REQUIRE_ITEM
end
#-----------------------------------------------------------------------------
# Lose Item [ALIAS]
#-----------------------------------------------------------------------------
alias nap_minimap_lose_item lose_item
def lose_item(item, amount, include_equip = false)
nap_minimap_lose_item(item, amount, include_equip)
$minimap.set_visibility_override if $minimap && Nap::Minimap::REQUIRE_ITEM
end
end
#===============================================================================
# Spriteset Map
# For updating the minimap
#===============================================================================
class Spriteset_Map
#-----------------------------------------------------------------------------
# Update [ALIAS]
#-----------------------------------------------------------------------------
alias nap_minimap_update update
def update
nap_minimap_update
$minimap.update if $minimap
end
end
#===============================================================================
# Class Event
# For removing events from the minimap when the event is erased
#===============================================================================
class Game_Event < Game_Character
#-----------------------------------------------------------------------------
# Erase [ALIAS]
#-----------------------------------------------------------------------------
alias nap_minimap_erase erase
def erase
nap_minimap_erase
$minimap.mm_events.reject! { |e| e.event.id == @id } if $minimap
end
end
#===============================================================================
# Game Event
# For making sure that the event is only shown on the minimap when the page
# that contains the minimap-comment-tag is actually active.
#===============================================================================
class Game_Event < Game_Character
#-----------------------------------------------------------------------------
# Setup Page Settings [ALIAS]
#-----------------------------------------------------------------------------
alias nap_minimap_setup_page_settings setup_page_settings
def setup_page_settings
nap_minimap_setup_page_settings
if SceneManager.scene.instance_of?(Scene_Map) && $minimap
$minimap.remove_ev(self.id)
return if self.list == nil
for command in self.list
$minimap.add_ev_unique(self, command)
end
end
end
end
#===============================================================================
# Saving & Loading
#===============================================================================
module DataManager
class << self
alias nap_minimap_make_save_contents make_save_contents
alias nap_minimap_extract_save_contents extract_save_contents
end
#-----------------------------------------------------------------------------
# Make Save Contents [ALIAS]
#-----------------------------------------------------------------------------
def self.make_save_contents
contents = nap_minimap_make_save_contents
contents[:nap_minimap] = {}
if $minimap && !$minimap.disposed?
contents[:nap_minimap][:mode] = $minimap.mode
contents[:nap_minimap][:visibility_override] = $minimap.visibility_override
contents[:nap_minimap][:enabled] = $minimap.enabled
contents[:nap_minimap][:location] = $minimap.location
contents[:nap_minimap][:scroll_src_rect] = $minimap.scroll_src_rect
#contents[:nap_minimap][:mm_events] = $minimap.mm_events
contents[:nap_minimap][:show_icons] = $minimap.show_icons
contents[:nap_minimap][:map_zoom_x] = $minimap.map_zoom_x
contents[:nap_minimap][:map_zoom_y] = $minimap.map_zoom_y
contents[:nap_minimap][:overlay_enabled] = $minimap.overlay_enabled
contents[:nap_minimap][:opacity] = $minimap.opacity
contents[:nap_minimap][:map_icons] = $minimap.save_icons
end
contents
end
#-----------------------------------------------------------------------------
# Extract Save Contents [ALIAS]
#-----------------------------------------------------------------------------
def self.extract_save_contents(contents)
nap_minimap_extract_save_contents(contents)
Nap::Minimap.save_data = contents[:nap_minimap]
end
end
#===============================================================================
# Class Minimap
#===============================================================================
module Nap
class Minimap
# in case a savegame was loaded
def load_data
return if Minimap.save_data.nil? || @@save_data.empty?
set_mode(@@save_data[:mode]) # no "self."
self.visibility_override = @@save_data[:visibility_override]
self.enabled = @@save_data[:enabled]
location = @@save_data[:location] # no "self."
scroll_src_rect = @@save_data[:scroll_src_rect] # no "self."
#mm_events = @@save_data[:mm_events]
self.show_icons = @@save_data[:show_icons]
map_zoom_x = @@save_data[:map_zoom_x] # no "self."
map_zoom_y= @@save_data[:map_zoom_y] # no "self."
self.overlay_enabled = @@save_data[:overlay_enabled]
@@save_data[:map_icons].each { |i|
@save_icons << i
add_icon(i[0], i[1], i[2], i[3])
}
self.opacity = @@save_data[:opacity]
end
end
end
#===============================================================================
# Scene Base
# For: Creates the minimap
#===============================================================================
class Scene_Base
#-----------------------------------------------------------------------------
# Post Start [ALIAS]
#-----------------------------------------------------------------------------
alias nap_minimap_post_start post_start
def post_start
if SceneManager.scene.instance_of?(Scene_Map) &&
Nap::Minimap::ONLY_VISIBLE_IN_SCENES.include?(self.class.name)
if $minimap
$minimap.super_visible = true
$minimap.refresh
else
$minimap = Nap::Minimap.new
end
else
$minimap.super_visible = false if $minimap
end
nap_minimap_post_start
end
end
#===============================================================================
# Scene Map
#===============================================================================
class Scene_Map < Scene_Base
#-------------------------------------------------------------------------------
# Pre Battle Scene [ALIAS]
# ** Mario Buonocore - Hide Napoleon's Minimap before the battle transition.
#
# Nasconde la minimappa durante la battaglia.
# Fa riferimento al valore della costante HIDE_IN_MENU.
#-------------------------------------------------------------------------------
alias lm_pre_battle_scene pre_battle_scene
def pre_battle_scene
$minimap.super_visible = false if Nap::Minimap::HIDE_BEFORE_BATTLE_TRANSITION
lm_pre_battle_scene
end
#-----------------------------------------------------------------------------
# Call Menu [ALIAS]
# For: Storing player source rect before opening the menu
#-----------------------------------------------------------------------------
alias nap_minimap_call_menu call_menu
def call_menu
$minimap.store_player_source_rect
nap_minimap_call_menu
end
#-----------------------------------------------------------------------------
# Post Transfer [ALIAS]
#-----------------------------------------------------------------------------
alias nap_minimap_post_transfer post_transfer
def post_transfer
$minimap.refresh
nap_minimap_post_transfer
$minimap.refresh_events
end
end # Scene_Map
#===============================================================================