#==============================================================================
# ** Sub_Map
#------------------------------------------------------------------------------
# Script by : Plague180
# Last Update : April 26, 2010
# Version : 1.0
# Contact Information : plague180([url=http://www.hbgames.org]http://www.hbgames.org[/url])
# Contact Information : [email=plague180@yahoo.com]plague180@yahoo.com[/email]
#------------------------------------------------------------------------------
# May 9, 2010 - Version 1.0 Release
#------------------------------------------------------------------------------
class Sub_Map < Window_Base
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(index=$game_map.map_id)
super(0, 0, 640, 480)
self.contents = Bitmap.new(640-32, 480-32)
self.z = 2010
self.opacity = 0
@section = []
make_section
@draw_player = true
@start = index
@pindex = first_check
@cursor = Sprite_Cursor.new()
@cursor.bitmap = RPG::Cache.icon(Map_Items::CURSOR)
@cursor.z = 2020
if Map_Items::CURSOR_TYPE == 2
@cursor.x = Sub::Towns[@pindex].screen_x + RPG::Cache.icon(Sub::Towns[@pindex].icon).width/4
@cursor.y = Sub::Towns[@pindex].screen_y + RPG::Cache.icon(Sub::Towns[@pindex].icon).height
@cursor.z = 2020
end
if second_check != true
@draw_player = false
end
refresh
end
#--------------------------------------------------------------------------
# * find map to start on(for cursor)
#--------------------------------------------------------------------------
def make_section
for i in 1...Sub::Towns.size+1
if Sub::Towns[i].upper_level == @upper
@section.push(Sub::Towns[i])
print(@section.size.to_s)
end
end
end
#--------------------------------------------------------------------------
# * Return value of @pindex
#--------------------------------------------------------------------------
def pindex
return @pindex
end
#--------------------------------------------------------------------------
# * Update the value of @pindex so the name box knows what name to disply
#--------------------------------------------------------------------------
def update_pindex
@cursor.x, @cursor.y = Mouse.mouse_pos
end
#--------------------------------------------------------------------------
# * Set the value of @cursor.x
#--------------------------------------------------------------------------
def set_x(set)
@cursor.x = set
end
#--------------------------------------------------------------------------
# * Set the value of @cursor.x
#--------------------------------------------------------------------------
def set_y(set)
@cursor.y = set
end
#--------------------------------------------------------------------------
# * find map to start on(for cursor)
#--------------------------------------------------------------------------
def first_check
for i in 1...Sub::Towns.size+1
if $game_switches[Sub::Towns[i].switch] == true
return i
end
end
end
#--------------------------------------------------------------------------
# * Check to see if the player is on a valid map(inside of Sub::Towns)
#--------------------------------------------------------------------------
def second_check
for i in 1...Sub::Towns.size+1
if Sub::Towns[i].map_id == $game_map.map_id
if $game_switches[Sub::Towns[i].switch] == true
return true
end
end
end
end
#--------------------------------------------------------------------------
# * Move Player To New Map
#--------------------------------------------------------------------------
def move(index=0)
$game_system.se_play(Map_Items::MOVE_SE)
if Map_Items::CURSOR_TYPE == 1
index = @pindex
end
Audio.bgm_fade(800)
Audio.bgs_fade(800)
Audio.me_fade(800)
$game_temp.player_new_map_id = Sub::Towns[index].map_id
$game_temp.player_new_x = Sub::Towns[index].map_x
$game_temp.player_new_y = Sub::Towns[index].map_y
$game_temp.player_new_direction = Sub::Towns[index].direction
$game_temp.player_transferring = true
$game_map.autoplay
$scene = Scene_Map.new
end
#--------------------------------------------------------------------------
# * Check if can move(and do it if you can)
#--------------------------------------------------------------------------
def move_if_can
for i in 1...Sub::Towns.size+1
if @cursor.x > Sub::Towns[i].screen_x-Map_Items::PIXEL_OFFSET && @cursor.x < Sub::Towns[i].screen_x + RPG::Cache.icon(Sub::Towns[i].icon).width + Map_Items::PIXEL_OFFSET
if @cursor.y > Sub::Towns[i].screen_y-Map_Items::PIXEL_OFFSET && @cursor.y < Sub::Towns[i].screen_y + RPG::Cache.icon(Sub::Towns[i].icon).height + Map_Items::PIXEL_OFFSET
move(i)
end
end
end
end
#--------------------------------------------------------------------------
# * Check if you can click on town, if so show name
#--------------------------------------------------------------------------
def check_name
for i in 1...Sub::Towns.size+1
if @cursor.x > Sub::Towns[i].screen_x - Map_Items::PIXEL_OFFSET && @cursor.x < Sub::Towns[i].screen_x + RPG::Cache.icon(Sub::Towns[i].icon).width + Map_Items::PIXEL_OFFSET
if @cursor.y > Sub::Towns[i].screen_y - Map_Items::PIXEL_OFFSET && @cursor.y < Sub::Towns[i].screen_y + RPG::Cache.icon(Sub::Towns[i].icon).height + Map_Items::PIXEL_OFFSET
self.contents.clear
refresh
self.contents.font.size = 18
self.contents.font.color = text_color(Map_Items::TOWN_TEXT_COLOR)
cx = contents.text_size(Sub::Towns[i].town_name).width
if $game_switches[Sub::Towns[i].switch] == true #unlocked?
self.contents.draw_text(@cursor.x-cx/2,@cursor.y,cx,32,Sub::Towns[i].town_name)
end
end
end
end
end
#--------------------------------------------------------------------------
# * Check if you can click on town, if so show name window
#--------------------------------------------------------------------------
def check_name_window
for i in 1...Sub::Towns.size+1
if @cursor.x > Sub::Towns[i].screen_x - Map_Items::PIXEL_OFFSET && @cursor.x < Sub::Towns[i].screen_x + RPG::Cache.icon(Sub::Towns[i].icon).width + Map_Items::PIXEL_OFFSET
if @cursor.y > Sub::Towns[i].screen_y-Map_Items::PIXEL_OFFSET && @cursor.y < Sub::Towns[i].screen_y + RPG::Cache.icon(Sub::Towns[i].icon).height + Map_Items::PIXEL_OFFSET
if $game_switches[Sub::Towns[i].switch] == true #unlocked?
return Sub::Towns[i].town_name
end
end
end
end
return ""
end
#--------------------------------------------------------------------------
# * Move Cursor Right
#--------------------------------------------------------------------------
def move_cursor_right_one
@cursor.x += Map_Items::MOVE_PIXEL
refresh
end
#--------------------------------------------------------------------------
# * Move Cursor Left
#--------------------------------------------------------------------------
def move_cursor_left_one
@cursor.x -= Map_Items::MOVE_PIXEL
refresh
end
#--------------------------------------------------------------------------
# * Move Cursor Up
#--------------------------------------------------------------------------
def move_cursor_up_one
@cursor.y -= Map_Items::MOVE_PIXEL
refresh
end
#--------------------------------------------------------------------------
# * Move Cursor Down
#--------------------------------------------------------------------------
def move_cursor_down_one
@cursor.y += Map_Items::MOVE_PIXEL
refresh
end
#--------------------------------------------------------------------------
# * Move Cursor Right
#--------------------------------------------------------------------------
def move_cursor_right
@pindex += 1
if @pindex > Sub::Towns.size
@pindex = 1
end
for i in 1...Sub::Towns.size+1
if $game_switches[Sub::Towns[@pindex].switch] == false
@pindex += 1
if @pindex > Sub::Towns.size
@pindex = 1
end
end
end
refresh
end
#--------------------------------------------------------------------------
# * Move Cursor Left
#--------------------------------------------------------------------------
def move_cursor_left
@pindex -= 1
if @pindex < 1
@pindex = Sub::Towns.size
end
for i in 1...Sub::Towns.size+1
if $game_switches[Sub::Towns[@pindex].switch] == false
@pindex -= 1
if @pindex < 1
@pindex = Sub::Towns.size
end
end
end
refresh
end
#--------------------------------------------------------------------------
# * Move Cursor Up
#--------------------------------------------------------------------------
def move_cursor_up
@pindex += 1
if @pindex > Sub::Towns.size
@pindex = 1
end
for i in 1...Sub::Towns.size+1
if $game_switches[Sub::Towns[@pindex].switch] == false
@pindex += 1
if @pindex > Sub::Towns.size
@pindex = 1
end
end
end
refresh
end
#--------------------------------------------------------------------------
# * Move Cursor Down
#--------------------------------------------------------------------------
def move_cursor_down
@pindex -= 1
if @pindex < 1
@pindex = Sub::Towns.size
end
for i in 1...Sub::Towns.size+1
if $game_switches[Sub::Towns[@pindex].switch] == false
@pindex -= 1
if @pindex < 1
@pindex = Sub::Towns.size
end
end
end
refresh
end
#--------------------------------------------------------------------------
# * Draw Player
#--------------------------------------------------------------------------
def draw_player
bitmap = RPG::Cache.icon(Map_Items::PLAYER_ICON)
@player_offset_x = Sub::Towns[@start].screen_x + ((RPG::Cache.icon(Sub::Towns[@start].icon).width / 2) - (bitmap.width / 2))
@player_offset_y = Sub::Towns[@start].screen_y - bitmap.height
self.contents.blt(@player_offset_x,@player_offset_y, bitmap, Rect.new(0,0,RPG::Cache.icon(Map_Items::PLAYER_ICON).height,RPG::Cache.icon(Map_Items::PLAYER_ICON).width))
end
#--------------------------------------------------------------------------
# * Draw Towns
#--------------------------------------------------------------------------
def draw_towns
for i in [email=1...@section.size]1...@section.size[/email]
if $game_switches[@section[i].switch] == true #unlocked?
bitmap = RPG::Cache.icon(@section[i].icon)
print(bitmap.to_s)
self.contents.blt(@section[i].screen_x, @section[i].screen_y, bitmap, Rect.new(0,0,bitmap.width,bitmap.height))
end
end
end
#--------------------------------------------------------------------------
# * Draw Cursor(i know this could be done better, will fix in update)
# been waiting too long to release this.
#--------------------------------------------------------------------------
def draw_cursor
if Map_Items::CURSOR_TYPE == 1
bitmap = @cursor.bitmap
if $game_switches[Sub::Towns[@pindex].switch] == true
if Sub::Towns[@pindex].icon != nil
x = Sub::Towns[@pindex].screen_x + (RPG::Cache.icon(Sub::Towns[@pindex].icon).width/2)-(bitmap.width/2)
y = Sub::Towns[@pindex].screen_y + (RPG::Cache.icon(Sub::Towns[@pindex].icon).height+3)
end
if Sub::Towns[@pindex].icon != nil
self.contents.blt(x, y, bitmap, Rect.new(0,0,bitmap.height,bitmap.width))
else
self.contents.blt(Sub::Towns[@pindex].screen_x, Sub::Towns[@pindex].screen_y+bitmap.width, bitmap, Rect.new(0,0,bitmap.height,bitmap.width))
end
if Map_Items::NAME_STYLE == 1
self.contents.font.size = 18
cx = contents.text_size(Sub::Towns[@pindex].town_name).width
x = Sub::Towns[@pindex].screen_x+(RPG::Cache.icon(Sub::Towns[@pindex].icon).width/2)-cx/2
self.contents.font.color = text_color(Map_Items::TOWN_TEXT_COLOR)
self.contents.draw_text(x,y,cx,32,Sub::Towns[@pindex].town_name)
end
end
end
if Map_Items::CURSOR_TYPE == 2
bitmap = @cursor.bitmap
self.contents.blt(@cursor.x, @cursor.y, bitmap, Rect.new(0,0,bitmap.height,bitmap.width))
end
end
#--------------------------------------------------------------------------
# * Check cursor bounds so it doesnt go off screen
#--------------------------------------------------------------------------
def check_cursor_bounds
if @cursor.x < 0
@cursor.x = 0
end
if @cursor.x > 640 - RPG::Cache.icon(Map_Items::CURSOR).width - 32
@cursor.x = 640 - RPG::Cache.icon(Map_Items::CURSOR).width - 32
end
if @cursor.y < 0
@cursor.y = 0
end
if @cursor.y > 480 - RPG::Cache.icon(Map_Items::CURSOR).height - 32
@cursor.y = 480 - RPG::Cache.icon(Map_Items::CURSOR).height - 32
end
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
check_cursor_bounds
#draws player
if Map_Items::SHOW_PLAYER == true
if @draw_player == true
draw_player
end
end
#draws all towns
draw_towns
#draw cursor
draw_cursor
end
end #class