#encoding:utf-8
# 小地图,不显示事件,只显示玩家位置和地图
# 进入新地图时会生成小地图,地图越大读取时间越久。
# 缓存最近使用的地图,最多10张(可在下面更改)。优先保留常用的地图
# 进入地图按 F5 打开小地图
# 不支持循环的地图。
class Window_MiniMap < Window_Base
ZoomRate = 0.25 #放大率
Hide_Text = '<hide minimap>'#地图备注中加入这个,该地图不显示小地图
@@cache = {}
@@show = false
def initialize(vp)
super(Graphics.width - 205, 5, 200, 160) #设置窗口的 x, y, width, height
self.viewport = vp
self.visible = false
self.z = 299
contents.fill_rect(contents.rect, Color.new(0, 0, 0, 255))#底色
create_minimap
create_player_sprite
refresh_visible
update
end
def update
super
update_player_sprite
update_minimap
switch_minimap if Input.trigger?(:F5) #设置呼出按键
end
def switch_minimap
@@show = !@@show
refresh_visible
end
def update_minimap
@minimap.src_rect.x = $game_player.real_x * 32 - @minimap_sw
@minimap.src_rect.y = $game_player.real_y * 32 - @minimap_sh
end
def dispose
dispose_player_sprite
@minimap.visible = false
super
end
def create_player_sprite
@player_sprite = Sprite_MapCharacter.new(viewport, $game_player)
@player_sprite.z = 301
@player_sprite.x = x + padding + (@minimap_sw+16)*ZoomRate
@player_sprite.y = y + padding + (@minimap_sh+28)*ZoomRate
@player_sprite.color = Color.new(220, 0, 0)
@player_sprite.zoom_x = @player_sprite.zoom_y = ZoomRate
end
def update_player_sprite
@player_sprite.update
end
def dispose_player_sprite
@player_sprite.dispose
end
def refresh_visible
show = !@hide&& @@show
self.visible = show
@minimap.visible = show
@player_sprite.visible = show
end
def create_minimap
@minimap_sw = contents.width / 2 / ZoomRate
@minimap_sh = contents.height / 2 / ZoomRate
@minimap = Sprite.new
@minimap.x = x + padding
@minimap.y = y + padding
@minimap.z = 300
spriteset_map = nil
SceneManager.scene.instance_eval {spriteset_map = @spriteset}
@minimap.bitmap = minimap_bitmap(spriteset_map)
@minimap.zoom_x = @minimap.zoom_y = ZoomRate
@minimap.src_rect = Rect.new(0, 0, @minimap_sw*2, @minimap_sh*2)
@minimap.viewport = viewport
end
def minimap_bitmap(spriteset_map)
hide = false
$game_map.instance_eval { hide = @map.note.include? Hide_Text }
@hide= hide
return nil if @hide
v = @@cache[$game_map.map_id]
bitmap = v ? v[1] : nil
if bitmap && !bitmap.disposed?
v[0] += 1
return bitmap
end
spriteset_map.update
spriteset_map.prepare_snap_minimap
tempSprite = Sprite.new
rect = contents.text_size( "LOADING" )
rect.width += 4
rect.height += 4
rect.x = Graphics.width - rect.width
rect.y = Graphics.height - rect.height
tempSprite.bitmap = Bitmap.new Graphics.width, Graphics.height
tempSprite.bitmap.fill_rect(tempSprite.bitmap.rect, Color.new(0,0,0) )
tempSprite.bitmap.draw_text(rect, "LOADING")
tempSprite.z = 1000
mw = $game_map.width
mh = $game_map.height
bitmap = Bitmap.new( mw*32, mh*32 )
sw = $game_map.screen_tile_x
sh = $game_map.screen_tile_y
(mw.fdiv sw).ceil.times {|x|
(mh.fdiv sh).ceil.times {|y|
tempSprite.visible = false
$game_map.set_display_pos(sw * x, sh * y)
spriteset_map.update_snap_minimap
dx = $game_map.display_x * 32
dy = $game_map.display_y * 32
bp = Graphics.snap_to_bitmap
bitmap.blt( dx, dy, bp, bp.rect )
tempSprite.visible = true
Graphics.update
}
}
tempSprite.bitmap.dispose
tempSprite.dispose
$game_player.center($game_player.x, $game_player.y)
spriteset_map.update
if @@cache.size > 10 #设置缓存地图张数
min_k = 0
@@cache.each {|k, v| min_k = k if v[0] > min_k}
@@cache.delete(min_k)[1].dispose
end
@@cache[$game_map.map_id] = [1, bitmap]
return bitmap
end
end
class Spriteset_Map
attr_reader :viewport1
def prepare_snap_minimap
@character_sprites.each {|s| s.visible = false}
@viewport1.tone.set(0, 0, 0, 0)
@viewport2.color.set(0, 0, 0, 0)
@viewport3.color.set(0, 0, 0, 0)
end
#
def update_snap_minimap
update_tileset
update_tilemap
update_parallax
#~ update_shadow
#~ update_weather
#~ update_pictures
#~ update_timer
#~ update_viewports
end
end
class Sprite_MapCharacter < Sprite_Character
def update_other
end
def update_position
end
def setup_new_effect
end
def end_animation
end
def start_balloon
end
def dispose_balloon
end
def update_balloon
end
def end_balloon
end
end
class Scene_Map
alias_method :sminimap_perform_transition, :create_spriteset
def create_spriteset#perform_transition
sminimap_perform_transition
create_mini_map
end
alias_method :minimap_terminate, :terminate
def terminate
minimap_terminate
@minimap.dispose
end
alias_method :sminimap_post_transfer, :post_transfer
def post_transfer
create_mini_map
sminimap_post_transfer
end
def create_mini_map
t = Graphics.brightness
Graphics.brightness = 255
c = @viewport.color
@viewport.color = Color.new
if @map_name_window && !@map_name_window.disposed?
v = @map_name_window.visible
@map_name_window.visible = false
end
@minimap.dispose if @minimap
@minimap = Window_MiniMap.new(@spriteset.viewport1)
Graphics.brightness = t
@viewport.color = c
if @map_name_window && !@map_name_window.disposed?
@map_name_window.visible = v
end
end
end