06-09-2010, 08:12 PM
I have a newer version in my HD. Although it isn't really ready to be released, I'm posting it here:
As you can see, there's a new section in the configuration,
which allows you to define keywords to identify any event you want to be displayed on the map. You just need to put a comment in the first page of this event You have to name the event with that same keyword. Try it.
version 0.4.4
Code:
#==============================================================================
# ** Passability Mini-map by Charlie Fleed
#
# Version: 0.4.4
# Author: Charlie Fleed
#==============================================================================
#
# Instructions: use the commands show_passmap and hide_passmap to make the
# minimap appear and disappear, the last setting will be saved in your savefile.
#
#==============================================================================
PASSABILITY_MAP_H=48*2
PASSABILITY_MAP_W=64*2
PASSABILITY_MAP_X=16 #640-PASSABILITY_MAP_W-16
PASSABILITY_MAP_Y=480-PASSABILITY_MAP_H-16 #480-PASSABILITY_MAP_H-32-16
PASSABILITY_MAP_OPACITY=150
MAP_ZOOM=1
PASSMAP_BACKGROUND_IMAGE="passmap bg" # Put "" if not used
PASSMAP_BACKGROUND_OPACITY=255
PASSMAP_PLAYER_IMAGE=""
PASSMAP_ALLY_IMAGE=""
PASSMAP_ENEMY_IMAGE=""
PASSMAP_BG_COLOR=Color.new(102,90,66,255)
PASSMAP_FG_COLOR=Color.new(179,158,116,255)
HIDE_WHEN_SHOWING_MESSAGES=true
HIDE_WHEN_SWITCH_ON=true
HIDE_SWITCH_NUMBER=19
KEYWORDS={"Gabbiano"=>Color.new(255,255,255,100),
"Crow"=>Color.new(255,255,255,100),
"Squirrel"=>Color.new(255,255,255,100)}
#==============================================================================
# **
#------------------------------------------------------------------------------
#
#==============================================================================
class Interpreter
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def redraw_passmap
$game_temp.redraw_passmap=true
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def hide_passmap
$game_system.minimap_visible=false
return
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def show_passmap
$game_system.minimap_visible=true
return
end
end
#==============================================================================
# **
#------------------------------------------------------------------------------
#
#==============================================================================
class Game_System
attr_accessor :minimap_visible
attr_accessor :minimap_opacity
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
alias minimap_initialize initialize
def initialize
minimap_initialize
@minimap_visible=true
@minimap_opacity=PASSABILITY_MAP_OPACITY
end
end
#==============================================================================
# **
#------------------------------------------------------------------------------
#
#==============================================================================
class Passability_Map < Sprite
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def initialize(viewport)
super(viewport)
@objects=Map_Objects.new(viewport)
self.opacity=$game_system.minimap_opacity
self.visible = ($game_system.minimap_visible and
((not HIDE_WHEN_SHOWING_MESSAGES) or (not $game_temp.message_window_showing)) and
((not HIDE_WHEN_SWITCH_ON) or (not $game_switches[HIDE_SWITCH_NUMBER])))
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def renew
@map=Bitmap.new(4*$game_map.width,4*$game_map.height)
for x in 0...$game_map.width
Graphics.update
for y in 0...$game_map.height
temp=0
@map.fill_rect(x*4,y*4,4,4,PASSMAP_FG_COLOR)
if !$game_map.passable?(x,y,2) # DOWN
@map.fill_rect(x*4,y*4+3,4,1,PASSMAP_BG_COLOR)
temp+=1
end
if !$game_map.passable?(x,y,4) # LEFT
@map.fill_rect(x*4,y*4,1,4,PASSMAP_BG_COLOR)
temp+=1
end
if !$game_map.passable?(x,y,6) # RIGHT
@map.fill_rect(x*4+3,y*4,1,4,PASSMAP_BG_COLOR)
temp+=1
end
if !$game_map.passable?(x,y,8) # UP
@map.fill_rect(x*4,y*4,4,1,PASSMAP_BG_COLOR)
temp+=1
end
if temp==4
@map.fill_rect(x*4+1,y*4+1,2,2,PASSMAP_BG_COLOR)
end
end
end
@map.make_png(@name_map)
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def redraw
self.visible=false
renew
self.bitmap=Bitmap.new(@map.width/MAP_ZOOM,@map.height/MAP_ZOOM)
self.bitmap.stretch_blt(self.bitmap.rect,@map,@map.rect,255)
self.visible=($game_system.minimap_visible and
((not HIDE_WHEN_SHOWING_MESSAGES) or (not $game_temp.message_window_showing)) and
((not HIDE_WHEN_SWITCH_ON) or (not $game_switches[HIDE_SWITCH_NUMBER])))
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def refresh
begin
Dir.mkdir 'Graphics/Pictures/pass_maps'
rescue
begin
Dir.mkdir 'Graphics/Pictures'
Dir.mkdir 'Graphics/Pictures/pass_maps'
rescue
begin
Dir.mkdir 'Graphics'
Dir.mkdir 'Graphics/Pictures'
Dir.mkdir 'Graphics/Pictures/pass_maps'
rescue
end
end
end
@name_map="Graphics/Pictures/pass_maps/pass_map_"+$game_map.map_id.to_s
begin
@map=Bitmap.new(@name_map)
rescue
renew
end
self.bitmap=Bitmap.new(@map.width/MAP_ZOOM,@map.height/MAP_ZOOM)
self.bitmap.stretch_blt(self.bitmap.rect,@map,@map.rect)
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def update
return unless @map!=nil
self.visible = ($game_system.minimap_visible and
((not HIDE_WHEN_SHOWING_MESSAGES) or (not $game_temp.message_window_showing)) and
((not HIDE_WHEN_SWITCH_ON) or (not $game_switches[HIDE_SWITCH_NUMBER])))
@objects.visible=self.visible
return if not self.visible
player_x=(4*$game_player.real_x/128.0)/MAP_ZOOM
player_y=(4*$game_player.real_y/128.0)/MAP_ZOOM
tilesize=4/MAP_ZOOM
self.ox=[[0, player_x - self.viewport.rect.width/2 + tilesize/2].max,
@map.width/MAP_ZOOM-self.viewport.rect.width].min
self.oy=[[0, player_y - self.viewport.rect.height/2+ tilesize/2].max,
@map.height/MAP_ZOOM-self.viewport.rect.height].min
@objects.update
self.opacity=$game_system.minimap_opacity
@objects.opacity=self.opacity
# $scene.debug_window.draw_text(0,0,460,30,"map_w="+(@map.width/MAP_ZOOM).to_s+" h="+(@map.height/MAP_ZOOM).to_s+" viewport_w"+(self.viewport.rect.width).to_s+" viewport_h"+(self.viewport.rect.height).to_s,true)
# $scene.debug_window.draw_text(0,30,460,30,"ox="+self.ox.to_s+"\toy="+self.oy.to_s)
# $scene.debug_window.draw_text(0,60,460,30,"player_x="+player_x.to_s+"\tplayer_y="+player_y.to_s)
# $scene.debug_window.draw_text(0,90,460,30,(self.viewport.rect.height/2).to_s)
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def height
return [@map.height/MAP_ZOOM,self.viewport.rect.height].min
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def width
return [@map.width/MAP_ZOOM,self.viewport.rect.width].min
end
end
#==============================================================================
# **
#------------------------------------------------------------------------------
#
#==============================================================================
class Map_Objects < Sprite
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def update
if self.bitmap!=nil
self.bitmap.dispose
end
self.bitmap=Bitmap.new(4*$game_map.width/MAP_ZOOM,4*$game_map.height/MAP_ZOOM)
player_x=(4*$game_player.real_x/128.0)/MAP_ZOOM
player_y=(4*$game_player.real_y/128.0)/MAP_ZOOM
tilesize=4/MAP_ZOOM
self.ox=[[0, player_x - self.viewport.rect.width/2 + tilesize/2].max,
4*$game_map.width/MAP_ZOOM-self.viewport.rect.width].min
self.oy=[[0, player_y - self.viewport.rect.height/2+ tilesize/2].max,
4*$game_map.height/MAP_ZOOM-self.viewport.rect.height].min
# ENEMIES
for object in $game_map.events.values
if object.is_enemy?
object_x=(4*object.real_x/128.0)/MAP_ZOOM
object_y=(4*object.real_y/128.0)/MAP_ZOOM
if PASSMAP_ENEMY_IMAGE != ""
enemy_bitmap=RPG::Cache.picture(PASSMAP_ENEMY_IMAGE)
self.bitmap.blt([0,object_x-0.5*enemy_bitmap.width].max,
[0,object_y-0.5*enemy_bitmap.height].max,
enemy_bitmap,enemy_bitmap.rect,128)
else
self.bitmap.fill_rect(object_x+tilesize/4,object_y+tilesize/4,2/MAP_ZOOM,2/MAP_ZOOM,Color.new(255,0,0))
end
end
if object.is_teleport?
object_x=(4*object.real_x/128.0)/MAP_ZOOM
object_y=(4*object.real_y/128.0)/MAP_ZOOM
self.bitmap.fill_rect(object_x,object_y,4/MAP_ZOOM,4/MAP_ZOOM,Color.new(255,0,255,200))
end
end
# EVENTS
for object in $game_map.events.values
if KEYWORDS[object.event.name]
object_x=(4*object.real_x/128.0)/MAP_ZOOM
object_y=(4*object.real_y/128.0)/MAP_ZOOM
self.bitmap.fill_rect(object_x+tilesize/4,object_y+tilesize/4,2/MAP_ZOOM,
2/MAP_ZOOM,KEYWORDS[object.event.name]) unless object.no_map?
end
end
# ALLIES
unless $game_allies==nil
for ally in $game_allies.values
ally_x=(4*ally.real_x/128.0)/MAP_ZOOM
ally_y=(4*ally.real_y/128.0)/MAP_ZOOM
if PASSMAP_ALLY_IMAGE != ""
ally_bitmap=RPG::Cache.picture(PASSMAP_ALLY_IMAGE)
self.bitmap.blt([0,ally_x-0.5*ally_bitmap.width].max,
[0,ally_y-0.5*ally_bitmap.height].max,
ally_bitmap,ally_bitmap.rect,128)
else
self.bitmap.fill_rect(ally_x+tilesize/4,ally_y+tilesize/4,2/MAP_ZOOM,2/MAP_ZOOM,Color.new(150,150,0))
end
end
end
# HERO
if PASSMAP_PLAYER_IMAGE != ""
player_bitmap=RPG::Cache.picture(PASSMAP_PLAYER_IMAGE)
self.bitmap.blt([0,player_x-0.5*player_bitmap.width].max,
[0,player_y-0.5*player_bitmap.height].max,
player_bitmap,player_bitmap.rect,128)
else
self.bitmap.fill_rect(player_x+tilesize/4, player_y+tilesize/4,2/MAP_ZOOM,2/MAP_ZOOM,Color.new(0,0,255))
end
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def height
return [4*$game_map.height/MAP_ZOOM,self.viewport.rect.height].min
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def width
return [4*$game_map.width/MAP_ZOOM,self.viewport.rect.width].min
end
end
#class Window_Debug < Window_Base
# def draw_text(a,b,c,d,e,clean=false)
# if clean
# self.contents=Bitmap.new(width-32,height-32)
# end
# self.contents.draw_text(a,b,c,d,e)
# end
#end
#==============================================================================
# **
#------------------------------------------------------------------------------
#
#==============================================================================
class Scene_Map
attr_accessor :map
# attr_accessor :debug_window
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
alias passmap_main main
def main
@map_viewport=Viewport.new(PASSABILITY_MAP_X,PASSABILITY_MAP_Y,
PASSABILITY_MAP_W,PASSABILITY_MAP_H)
@map_viewport.z=9999
@map_viewport.visible=true
@map=Passability_Map.new(@map_viewport)
@map.refresh
if PASSMAP_BACKGROUND_IMAGE != ""
@map_bg_viewport=Viewport.new(PASSABILITY_MAP_X+PASSABILITY_MAP_W-@map.width-8,
PASSABILITY_MAP_Y+PASSABILITY_MAP_H-@map.height-8,
@map.width+16,@map.height+16)
# p "width: %d, height: %d",@map.width,@map.height
@map_bg_viewport.z=9998
@map_bg_viewport.visible=($game_system.minimap_visible and
((not HIDE_WHEN_SHOWING_MESSAGES) or (not $game_temp.message_window_showing)) and
((not HIDE_WHEN_SWITCH_ON) or (not $game_switches[HIDE_SWITCH_NUMBER])))
@map_bg=Sprite.new(@map_bg_viewport)
@map_bg.bitmap=RPG::Cache.picture(PASSMAP_BACKGROUND_IMAGE)
@map_bg.opacity=PASSMAP_BACKGROUND_OPACITY
@map_bg.zoom_x = 1.0*(@map_bg_viewport.rect.width)/@map_bg.bitmap.width
@map_bg.zoom_y = 1.0*(@map_bg_viewport.rect.height)/@map_bg.bitmap.height
end
# @debug_window=Window_Debug.new(0,0,640,180)
passmap_main
if PASSMAP_BACKGROUND_IMAGE != ""
@map_bg.dispose
@map_bg_viewport.dispose
end
@map.dispose
@map_viewport.dispose
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
alias passmap_update update
def update
passmap_update
if PASSMAP_BACKGROUND_IMAGE != ""
@map_bg_viewport.visible=($game_system.minimap_visible and
((not HIDE_WHEN_SHOWING_MESSAGES) or (not $game_temp.message_window_showing)) and
((not HIDE_WHEN_SWITCH_ON) or (not $game_switches[HIDE_SWITCH_NUMBER])))
end
if $game_temp.redraw_passmap
@map.redraw
$game_temp.redraw_passmap=false
end
if $game_temp.refresh_passmap
@map.refresh
if PASSMAP_BACKGROUND_IMAGE != ""
@map_bg_viewport.rect.width=@map.width+16
@map_bg_viewport.rect.height=@map.height+16
@map_bg_viewport.rect.x=PASSABILITY_MAP_X+PASSABILITY_MAP_W-@map.width-8
@map_bg_viewport.rect.y=PASSABILITY_MAP_Y+PASSABILITY_MAP_H-@map.height-8
@map_bg.zoom_x = 1.0*(@map_bg_viewport.rect.width)/@map_bg.bitmap.width
@map_bg.zoom_y = 1.0*(@map_bg_viewport.rect.height)/@map_bg.bitmap.height
end
$game_temp.refresh_passmap=false
end
@map.update
end
end
#==============================================================================
# **
#------------------------------------------------------------------------------
#
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
alias passmap_setup setup
def setup(id)
passmap_setup(id)
$game_temp.refresh_passmap=true
end
end
#==============================================================================
# **
#------------------------------------------------------------------------------
#
#==============================================================================
class Game_Temp
attr_accessor :redraw_passmap
attr_accessor :refresh_passmap
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
alias passmap_initialize initialize
def initialize
passmap_initialize
@redraw_passmap=false
@refresh_passmap=false
end
end
#==============================================================================
# PNG #
#==============================================================================
module Zlib
class Png_File < GzipWriter
def make_png(bitmap_Fx)
@bitmap_Fx = bitmap_Fx
self.write(make_header)
self.write(make_ihdr)
self.write(make_idat)
self.write(make_iend)
end
def make_header
return [0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a].pack("C*")
end
def make_ihdr
ih_size = [13].pack("N")
ih_sign = "IHDR"
ih_width = [@bitmap_Fx.width].pack("N")
ih_height = [@bitmap_Fx.height].pack("N")
ih_bit_depth = [8].pack("C")
ih_color_type = [6].pack("C")
ih_compression_method = [0].pack("C")
ih_filter_method = [0].pack("C")
ih_interlace_method = [0].pack("C")
string = ih_sign + ih_width + ih_height + ih_bit_depth + ih_color_type +
ih_compression_method + ih_filter_method + ih_interlace_method
ih_crc = [Zlib.crc32(string)].pack("N")
return ih_size + string + ih_crc
end
def make_idat
header = "\x49\x44\x41\x54"
data = make_bitmap_data
data = Zlib::Deflate.deflate(data, 8)
crc = [Zlib.crc32(header + data)].pack("N")
size = [data.length].pack("N")
return size + header + data + crc
end
def make_bitmap_data
gz = Zlib::GzipWriter.open('hoge.gz')
t_Fx = 0
w = @bitmap_Fx.width
h = @bitmap_Fx.height
data = []
for y in 0...h
data.push(0)
for x in 0...w
t_Fx += 1
if t_Fx % 10000 == 0
Graphics.update
end
if t_Fx % 100000 == 0
s = data.pack("C*")
gz.write(s)
data.clear
end
color = @bitmap_Fx.get_pixel(x, y)
red = color.red
green = color.green
blue = color.blue
alpha = color.alpha
data.push(red)
data.push(green)
data.push(blue)
data.push(alpha)
end
end
s = data.pack("C*")
gz.write(s)
gz.close
data.clear
gz = Zlib::GzipReader.open('hoge.gz')
data = gz.read
gz.close
File.delete('hoge.gz')
return data
end
def make_iend
ie_size = [0].pack("N")
ie_sign = "IEND"
ie_crc = [Zlib.crc32(ie_sign)].pack("N")
return ie_size + ie_sign + ie_crc
end
end
end
class Bitmap
def make_png(name="Gui_Img_Save", path="",mode=0)
make_dir(path) if path != ""
Zlib::Png_File.open("temp.gz") {|gz|
gz.make_png(self)
}
Zlib::GzipReader.open("temp.gz") {|gz|
$read = gz.read
}
f = File.open(path + name + ".png","wb")
f.write($read)
f.close
File.delete('temp.gz')
end
def make_dir(path)
dir = path.split("/")
for i in 0...dir.size
unless dir == "."
add_dir = dir[0..i].join("/")
begin
Dir.mkdir(add_dir)
rescue
end
end
end
end
end
#==============================================================================
# **
#------------------------------------------------------------------------------
#
#==============================================================================
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def is_enemy?
if no_map?
return false
end
for p in @event.pages
for command in p.list
if command.code == 108
if command.parameters[0]=="Enemy"
return true
end
end
end
end
return false
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def is_teleport?
if no_map?
return false
end
for p in @event.pages
for command in p.list
if command.code == 108
if command.parameters[0]=="Teleport"
return true
end
end
end
end
return false
end
#--------------------------------------------------------------------------
# *
#--------------------------------------------------------------------------
def no_map?
if @page==nil
return true
end
for command in @page.list
if command.code == 108
if command.parameters[0]=="No Map"
return true
end
end
end
return false
end
end
As you can see, there's a new section in the configuration,
Code:
KEYWORDS={"Gabbiano"=>Color.new(255,255,255,100),
"Crow"=>Color.new(255,255,255,100),
"Squirrel"=>Color.new(255,255,255,100)}
which allows you to define keywords to identify any event you want to be displayed on the map. You just need to put a comment in the first page of this event You have to name the event with that same keyword. Try it.