Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #sb:nap_minimap [gui]
  2. #===============================================================================
  3. # Game Event
  4. # For: Adding a name-accessor to it.
  5. #===============================================================================
  6. class Game_Event
  7. if !defined?(self.name) || !defined?(self.name=())
  8. attr_accessor :name
  9.  
  10. #---------------------------------------------------------------------------
  11. # Initialize [ALIAS]
  12. #---------------------------------------------------------------------------
  13. alias nam_minimap_initialize initialize
  14. def initialize(map_id, event)
  15. nam_minimap_initialize(map_id, event)
  16. @name = event.name
  17. end
  18. end
  19. end
  20. #===============================================================================
  21. # Nap::Minimap
  22. #===============================================================================
  23. module Nap; class Minimap
  24. #-----------------------------------------------------------------------------
  25. # Super Visible Setter
  26. # For hiding/unhiding the minimap
  27. #-----------------------------------------------------------------------------
  28. def super_visible=(v)
  29. return if !@has_map
  30. 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).
  31. @sprite.visible = v
  32. @overlay.visible = v if @overlay
  33. @border.visible = v
  34. @player_sprite.visible = v
  35. end
  36. #-----------------------------------------------------------------------------
  37. # * initialize
  38. #-----------------------------------------------------------------------------
  39. def initialize
  40. @save_icons = [] # contains map-icon data for saving&loading
  41. @@cache ||= {}
  42. @disposed = false
  43. @arrows_src_img = Cache.minimap(ARROWS) if !@arrows_src_img
  44. @overlay_enabled = OVERLAY_ENABLED
  45. @@mode = MODE if !defined?(@@mode)
  46. @map_zoom_x = MAP_ZOOM_X
  47. @map_zoom_y = MAP_ZOOM_Y
  48. @border_img = Cache.minimap(BORDER_IMG) if BORDER_IMG
  49. @cursor_img = Cache.minimap(CURSOR_IMG) if CURSOR_IMG
  50. @enabled = true
  51. @visible = false
  52. @visibility_override = :normal
  53. @sprite = Sprite.new
  54. @@opacity = OPACITY if !defined?(@@opacity)
  55. @show_icons = true
  56. @icons = []
  57. @updated_count = 0
  58.  
  59. @mm_events = Minimap.get_minimap_events
  60. set_location(LOCATION) # also calls: create_sprite
  61. create_cursor
  62.  
  63. load_data
  64.  
  65. # Icons for poi
  66. # $mm_icons contains a hash with the event_id as the key and it's
  67. # sprite-character as the value.
  68. if $imported[:nap_minimap_menu]
  69. $mm_icons[:events].values.each { |icon| icon.dispose } if !$mm_icons.nil?
  70. $mm_icons = {:events => {}}
  71. @mm_events.each { |mm_ev|
  72. if mm_ev.event.sprite
  73. icon = Bitmap.new(mm_ev.event.sprite.src_rect.width, mm_ev.event.sprite.src_rect.height)
  74. icon.blt(0, 0, mm_ev.event.sprite.bitmap, mm_ev.event.sprite.src_rect)
  75. $mm_icons[:events][mm_ev.event.id] = icon
  76. end
  77. }
  78. end
  79. end
  80. #-----------------------------------------------------------------------------
  81. # * store_player_source_rect
  82. #-----------------------------------------------------------------------------
  83. def store_player_source_rect
  84. $mm_icons[:player_src_rect] = $game_player.sprite.src_rect if $imported[:nap_minimap_menu]
  85. end
  86. #-----------------------------------------------------------------------------
  87. # * Create Map Events
  88. #-----------------------------------------------------------------------------
  89. def self.get_minimap_events
  90. mm_events = []
  91. # Loop through all map events
  92. $game_map.events.values.each { |e|
  93. next if e.list.nil?
  94.  
  95. new_mm_ev = nil
  96. name = e.name # Default name in case no name-command will be found
  97. desc = nil
  98.  
  99. e.nap_note.each { |note|
  100. new_mm_ev = add_ev_by_nap_note(e) if new_mm_ev.nil?
  101.  
  102. if note =~ /<#{Regexp.escape(Minimap::EV_NAME_COMMENT_TAG)}: ([^>]*)>/ix
  103. name = $1
  104. elsif note =~ /<#{Regexp.escape(Minimap::EV_DESC_COMMENT_TAG)}: ([^>]*)>/ix
  105. desc = $1
  106. end
  107. } # e.nap_note.each { |note|
  108. # Old (outcommented) code below:
  109. #~ # Loop through all commands within the looped-event.
  110. #~ e.list.each{ |command|
  111. #~ # Scan for new mm_event command
  112. #~ new_mm_ev = Minimap.add_ev_by_command(e, command) if new_mm_ev.nil?
  113. #~
  114. #~ # Scan for name/desc commands
  115. #~ if command.code == 108
  116. #~ if command.parameters[0] =~ /<#{Regexp.escape(Minimap::EV_NAME_COMMENT_TAG)}: ([^>]*)>/ix
  117. #~ name = $1
  118. #~ elsif command.parameters[0] =~ /<#{Regexp.escape(Minimap::EV_DESC_COMMENT_TAG)}: ([^>]*)>/ix
  119. #~ desc = $1
  120. #~ end
  121. #~ end
  122. #~ } # Loop through all commands within the looped-event.
  123.  
  124. if !new_mm_ev.nil?
  125. new_mm_ev.name = name
  126. new_mm_ev.desc = desc
  127. mm_events << new_mm_ev
  128. end
  129. } # Loop through all map events
  130. return mm_events
  131. end
  132. #-----------------------------------------------------------------------------
  133. # Add Event By Nap-Note
  134. #-----------------------------------------------------------------------------
  135. def self.add_ev_by_nap_note(event)
  136. event.nap_note.each { |note|
  137. if note =~ /<#{Regexp.escape(Minimap::EV_COMMENT_TAG)}: ([^>]*)>/ix
  138. return MM_Event.new(event, $1.downcase.split(' '))
  139. end
  140. }
  141. return nil
  142. end
  143. #-----------------------------------------------------------------------------
  144. # * Add Event By Command
  145. # Returns: The minimap_event or nil if none was found.
  146. #-----------------------------------------------------------------------------
  147. def self.add_ev_by_command(ev, command)
  148. if command.code == 108
  149. if command.parameters[0] =~ /<#{Regexp.escape(Minimap::EV_COMMENT_TAG)}: ([^>]*)>/ix
  150. return MM_Event.new(ev, $1.downcase.split(' '))
  151. end
  152. end
  153. return nil
  154. end
  155. #-----------------------------------------------------------------------------
  156. # * Add Event Unique
  157. # - Only adds the event if it doesn't already exist on the minimap.
  158. #-----------------------------------------------------------------------------
  159. def add_ev_unique(ev, command)
  160. return if @mm_events.find {|e| e.event.id == ev.id}
  161. new_mm_ev = Minimap.add_ev_by_command(ev, command)
  162. @mm_events << new_mm_ev if !new_mm_ev.nil?
  163. end
  164. #-----------------------------------------------------------------------------
  165. # * Remove Event
  166. # - Removes the event from the minimap
  167. #-----------------------------------------------------------------------------
  168. def remove_ev(ev_id)
  169. @mm_events.reject!{ |e| e.event.id == ev_id}
  170. end
  171. #-----------------------------------------------------------------------------
  172. # * Create Cursor
  173. #-----------------------------------------------------------------------------
  174. def create_cursor
  175. @player_sprite.dispose if @player_sprite
  176. @player_sprite = Sprite.new
  177. @player_sprite.bitmap = Bitmap.new(CURSOR_SIZE, CURSOR_SIZE)
  178. @player_sprite.ox = CURSOR_SIZE / 2.0
  179. @player_sprite.oy = CURSOR_SIZE / 2.0
  180.  
  181. if !USE_PLAYER_GRAPHIC
  182. if @cursor_img
  183. @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)
  184. else
  185. @player_sprite.bitmap.fill_rect(0, 0, CURSOR_SIZE, CURSOR_SIZE, CURSOR_COLOR)
  186. end
  187. end
  188.  
  189. @player_sprite.z = Z_INDEX_CURSOR
  190. @player_sprite.visible = @visible
  191. reset_cursor_location
  192. end
  193. #-----------------------------------------------------------------------------
  194. # * Update Player Cursor
  195. # - Only called when USE_PLAYER_GRAPHIC == true
  196. #-----------------------------------------------------------------------------
  197. def update_player_cursor
  198. player_character = $game_player.sprite
  199. return if !player_character || player_character.disposed?
  200.  
  201. @player_sprite.bitmap.clear
  202. @player_sprite.bitmap.stretch_blt(Rect.new(0,0,@player_sprite.bitmap.width, @player_sprite.bitmap.height),
  203. player_character.bitmap,
  204. player_character.src_rect,
  205. 255)
  206. end
  207. #-----------------------------------------------------------------------------
  208. # * Reset Cursor Location
  209. #-----------------------------------------------------------------------------
  210. def reset_cursor_location
  211. @player_sprite.x = @location.x + @location.width / 2 + 16 * @map_zoom_x
  212. @player_sprite.y = @location.y + @location.height / 2 + 16 * @map_zoom_y
  213. end
  214. #-----------------------------------------------------------------------------
  215. # * Set location
  216. # Sets the new location and size of the minimap
  217. #-----------------------------------------------------------------------------
  218. def set_location(rect)
  219. @location = rect
  220.  
  221. @sprite.x = rect.x
  222. @sprite.y = rect.y
  223. @sprite.z = Z_INDEX_MAP
  224.  
  225. @sprite.bitmap.dispose if
  226. @sprite.bitmap = Bitmap.new(rect.width, rect.height)
  227.  
  228. create_overlay if OVERLAY_IMG
  229. create_sprite
  230. reset_cursor_location if @player_sprite
  231. end
  232. #-----------------------------------------------------------------------------
  233. # * Refresh
  234. #-----------------------------------------------------------------------------
  235. def refresh
  236. @has_map = false
  237. return if !SceneManager.scene.instance_of?(Scene_Map)
  238.  
  239. @mm_events = Minimap.get_minimap_events
  240. create_overlay if OVERLAY_IMG
  241. create_sprite
  242. reset_cursor_location if @player_sprite
  243. end
  244. #-----------------------------------------------------------------------------
  245. # * Create Overlay
  246. #-----------------------------------------------------------------------------
  247. def create_overlay
  248. @overlay.dispose if @overlay
  249. @overlay = Sprite.new
  250.  
  251. # bitmap
  252. if SCALE_OVERLAY
  253. img = Cache.minimap(OVERLAY_IMG)
  254. @overlay.bitmap = Bitmap.new(@location.width, @location.height)
  255. @overlay.bitmap.stretch_blt(Rect.new(0, 0, @location.width, @location.height),
  256. img, Rect.new(0, 0, img.width, img.height))
  257. img.dispose
  258. else
  259. @overlay.bitmap = Cache.minimap(OVERLAY_IMG)
  260. end
  261.  
  262. @overlay.x = @location.x + OVERLAY_OFFSET[0]
  263. @overlay.y = @location.y + OVERLAY_OFFSET[1]
  264. @overlay.z = Z_INDEX_OVERLAY
  265. @overlay.visible = @visible && @overlay_enabled
  266. end
  267. #-----------------------------------------------------------------------------
  268. # * Get Effective Map ID
  269. #-----------------------------------------------------------------------------
  270. def self.get_effective_map_id
  271. if MAP_IMAGE_OVERRIDE.has_key?($game_map.map_id)
  272. return MAP_IMAGE_OVERRIDE[$game_map.map_id]
  273. else
  274. return $game_map.map_id
  275. end
  276. end
  277. #-----------------------------------------------------------------------------
  278. # * get_map_bitmap
  279. # - returns the map bitmap (or nil if non exists) and sets @has_image
  280. # - also saves/loads from custom cache (if applicable)
  281. #-----------------------------------------------------------------------------
  282. def get_map_bitmap
  283. eff_map_id = Minimap.get_effective_map_id
  284. filename = "#{FILE_PREFIX}#{eff_map_id.to_s.rjust(3, '0')}"
  285.  
  286. # Use the bitmap from the custom cache if there is one.
  287. if @@cache.has_key?(Minimap.get_effective_map_id)
  288. @cached = true
  289. @has_image = true
  290. return @@cache[eff_map_id]
  291. else
  292. @cached = false
  293. end
  294.  
  295. # Rescue is required because if the game data is encrypted then
  296. # File.exists? will always return false (not supported by RPG Maker)
  297. # and Cache.load_bitmap will crash.
  298. # RM encryption supported methods: load_data(), Bitmap.new(),
  299. # Graphics.transition()
  300. #@has_image = (Cache.load_bitmap("Graphics/#{FOLDER}","#{filename}.#{FILE_EXT}") != nil)
  301. begin
  302. bmp = Bitmap.new("Graphics/#{FOLDER}/#{filename}.#{FILE_EXT}")
  303. @has_image = true
  304. rescue
  305. @has_image = false
  306. return nil
  307. end
  308.  
  309. # Save to cache if conditions are met
  310. if (bmp.width * bmp.height / 32) >= MIN_CACHE_SIZE && !@@cache.has_key?(eff_map_id)
  311. @@cache[eff_map_id] = bmp
  312. @cached = true
  313. end
  314.  
  315. return bmp
  316. end
  317. #-----------------------------------------------------------------------------
  318. # * Set Zoom
  319. #-----------------------------------------------------------------------------
  320. def set_zoom
  321. # Set Zoom
  322. if MAP_ZOOMS[$game_map.map_id] == nil
  323. @map_zoom_x = MAP_ZOOM_X
  324. @map_zoom_y = MAP_ZOOM_Y
  325. else
  326. @map_zoom_x = MAP_ZOOMS[$game_map.map_id][0]
  327. @map_zoom_y = MAP_ZOOMS[$game_map.map_id][1]
  328. end
  329. end
  330. #-----------------------------------------------------------------------------
  331. # * Create Sprite (the map itself)
  332. #-----------------------------------------------------------------------------
  333. def create_sprite
  334. map_img = get_map_bitmap
  335. if !@has_image
  336. @has_map = false
  337. return
  338. end
  339. @has_map = true
  340. @map_img = map_img.dup
  341.  
  342. @map_w = map_img.width.to_f
  343. @map_h = map_img.height.to_f
  344.  
  345. @base_map.dispose if @base_map
  346. case @@mode
  347. when :default
  348. @sprite.bitmap.stretch_blt(Rect.new(0, 0, @location.width, @location.height), map_img, Rect.new(0,0,@map_w,@map_h), @@opacity)
  349. @base_map = Bitmap.new(@location.width, @location.height)
  350. @base_map.stretch_blt(Rect.new(0, 0, @location.width, @location.height), map_img, Rect.new(0,0,@map_w,@map_h), @@opacity)
  351. when :scroll
  352. set_zoom
  353. # Store source map (zoomed)
  354. @base_map = Bitmap.new(map_img.width * @map_zoom_x, map_img.height * @map_zoom_y)
  355. @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)
  356. else
  357. raise "create_sprite: Unknown @@mode (#{@@mode})"
  358. end
  359. map_img.dispose if !@cached
  360.  
  361. create_border
  362. @sprite.visible = @visible
  363. render_events
  364. end
  365.  
  366. def refresh_events
  367. @mm_events = Minimap.get_minimap_events
  368. end
  369.  
  370. #-----------------------------------------------------------------------------
  371. # * Render Events
  372. #-----------------------------------------------------------------------------
  373. def render_events
  374. return if @mm_events.length == 0 || @player_sprite.nil?
  375. # There is no need to render a clean map (basemap w/o events) in :scroll_mode because the sets_scroll handles that.
  376. case @@mode
  377. when :default
  378. # Render the basemap onto the new spritemap (removing all events and such).
  379. @sprite.bitmap.dispose if @sprite.bitmap
  380. @sprite.bitmap = Bitmap.new(@location.width, @location.height)
  381. @sprite.bitmap.blt(0,0,@base_map, Rect.new(0,0,@sprite.bitmap.width,@sprite.bitmap.height))
  382. when :scroll
  383. # Make sur ethat the scroll_src_rect is set before rendering events in :scroll mode
  384. get_scroll_base_src_rect if !@scroll_src_rect
  385. else
  386. raise "render_events: Unknown @@mode (#{@@mode})"
  387. end
  388.  
  389. @mm_events.each { |ev| ev.render(self, @sprite.bitmap, @map_zoom_x, @map_zoom_y) }
  390. end
  391. #-----------------------------------------------------------------------------
  392. # * Create Border
  393. #-----------------------------------------------------------------------------
  394. def create_border
  395. @border.dispose if @border
  396. @border = Sprite.new
  397. @border.bitmap = Bitmap.new(@location.width + BORDER_SIZE * 2, @location.height + BORDER_SIZE * 2)
  398. @border.x = @location.x - BORDER_SIZE
  399. @border.y = @location.y - BORDER_SIZE
  400.  
  401. if BORDER_IMG
  402. @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)
  403. else
  404. @border.bitmap.fill_rect(0, 0, @border.bitmap.width, BORDER_SIZE, BORDER_COLOR)
  405. @border.bitmap.fill_rect(@border.bitmap.width - BORDER_SIZE, 0, BORDER_SIZE, @border.bitmap.height, BORDER_COLOR)
  406. @border.bitmap.fill_rect(0, @border.bitmap.height - BORDER_SIZE, @border.bitmap.width, BORDER_SIZE, BORDER_COLOR)
  407. @border.bitmap.fill_rect(0, 0, BORDER_SIZE, @border.bitmap.height, BORDER_COLOR)
  408. end
  409.  
  410. @border.z = Z_INDEX_MAP
  411. @border.visible = @visible
  412. end
  413. #-----------------------------------------------------------------------------
  414. # * Set Mode
  415. #-----------------------------------------------------------------------------
  416. def set_mode(mode)
  417. raise "Minimap.set_mode(#{mode}) Invalid mode." if mode != :default && mode != :scroll
  418. @@mode = mode
  419.  
  420. @sprite.bitmap.clear # This line is necessary in case the opacity is < 255.
  421. create_sprite
  422. reset_cursor_location
  423. end
  424. #-----------------------------------------------------------------------------
  425. # * Set Cursor Location
  426. #-----------------------------------------------------------------------------
  427. def set_cursor_location
  428. ratio_x = @location.width / @map_w
  429. ratio_y = @location.height / @map_h
  430.  
  431. map_x = $game_player.real_x * 32 * ratio_x + @location.x
  432. map_y = $game_player.real_y * 32 * ratio_y + @location.y
  433.  
  434. @player_sprite.x = map_x
  435. @player_sprite.y = map_y
  436. end
  437. #-----------------------------------------------------------------------------
  438. # * World map to minimap coordinates
  439. # real_x & real_y is the location in pixels (upper left corner is 0,0)
  440. # returns 2 values
  441. # Note: real_x usually requires a * 32 multiplication
  442. #-----------------------------------------------------------------------------
  443. def to_minimap_coords(real_x, real_y)
  444. case @@mode
  445. when :default
  446. ratio_x = @location.width.to_f / @map_w.to_f
  447. ratio_y = @location.height.to_f / @map_h.to_f
  448. x = real_x * @map_zoom_x
  449. y = real_y * @map_zoom_y
  450. return real_x * ratio_x, real_y * ratio_y
  451. when :scroll
  452. real_x += 16
  453. real_y += 16
  454. x = real_x * @map_zoom_x
  455. y = real_y * @map_zoom_y
  456. return x, y
  457. else
  458. raise "def to_minimap_coords - unknown mode: #{@@mode}"
  459. end
  460. end
  461. #-----------------------------------------------------------------------------
  462. # * Get Scroll Base Source Rectangle
  463. # - This method contains the real logic for drawing and calculating the
  464. # scrolling map.
  465. #-----------------------------------------------------------------------------
  466. def get_scroll_base_src_rect
  467. half_w = @location.width / 2
  468. half_h = @location.height / 2
  469.  
  470. # Calculate the location of the player on the basemap with zoom factor
  471. x = $game_player.real_x * 32 * @map_zoom_x - half_w
  472. y = $game_player.real_y * 32 * @map_zoom_y - half_h
  473.  
  474.  
  475.  
  476. mw = @map_img.width.to_f * @map_zoom_x
  477. mh = @map_img.height.to_f * @map_zoom_y
  478. dh = @location.height - mh
  479. dw = @location.width - mw
  480. equals = @location.width > mw && @location.height > mh
  481. if AUTO_CORRECT_MAP_SCROLL# && equals
  482. # The code below makes sure that the map is not scrolled when the player
  483. # is near the edge of the map. Otherwise you could see the minimap bg
  484. # near the edge...
  485. if x < 0 # Prevent the map from scrolling too far to the right (otherwise creating a gap on the left side)
  486. delta_x = x
  487. x = 0 # Prevent the map from scrolling too far to the right (otherwise creating a gap on the left side)
  488. # 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.
  489. @player_sprite.x = @location.x + @location.width / 2 + delta_x + 16 * @map_zoom_x
  490. elsif x + @location.width > @base_map.width
  491. delta_x = (x + @location.width) - @base_map.width
  492. x = @base_map.width - @location.width # Prevent the map from scrolling too far to the left (otherwise creating a gap on the right side)
  493. # 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.
  494. @player_sprite.x = @location.x + @location.width / 2 + delta_x + 16 * @map_zoom_x
  495. end
  496.  
  497. if y < 0 # Prevent the map from scrolling too far to the bottom (otherwise creating a gap on the top side)
  498. delta_y = y
  499. y = 0 # Prevent the map from scrolling too far to the right (otherwise creating a gap on the left side)
  500. # 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.
  501. @player_sprite.y = @location.y + @location.height / 2 + delta_y + 16 * @map_zoom_y
  502. elsif y + @location.height > @base_map.height
  503. delta_y = (y + @location.height) - @base_map.height
  504. y = @base_map.height - @location.height # Prevent the map from scrolling too far to the left (otherwise creating a gap on the right side)
  505. # 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.
  506. @player_sprite.y = @location.y + @location.height / 2 + delta_y + 16 * @map_zoom_y
  507. end
  508. end
  509. if equals
  510. if y < 0 # Prevent the map from scrolling too far to the bottom (otherwise creating a gap on the top side)
  511. delta_y = y
  512. y = 0 # Prevent the map from scrolling too far to the right (otherwise creating a gap on the left side)
  513. # 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.
  514. #@player_sprite.y = @location.y + @location.height / 2 + delta_y + 16 * @map_zoom_y
  515. @player_sprite.y -= dh
  516. end
  517. if x < 0 # Prevent the map from scrolling too far to the right (otherwise creating a gap on the left side)
  518. delta_x = x
  519. x = 0 # Prevent the map from scrolling too far to the right (otherwise creating a gap on the left side)
  520. # 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.
  521. @player_sprite.x -= dw
  522. end
  523. #unless equals
  524. cx = (@location.width - mw).ceil / 2
  525. cy = (@location.height - mh).ceil / 2
  526. x -= cx #* @map_zoom_x
  527. y -= cy #* @map_zoom_y
  528. @player_sprite.y += cy
  529. @player_sprite.x += cx
  530. #end
  531. end
  532.  
  533. @scroll_src_rect = Rect.new(x,y,@location.width, @location.height)
  534. return @scroll_src_rect
  535. end
  536. #-----------------------------------------------------------------------------
  537. # * Set Scroll
  538. #-----------------------------------------------------------------------------
  539. def set_scroll
  540. @sprite.bitmap.clear # This line is necessary in case the opacity is < 255.
  541.  
  542. # BG Color
  543. if BG_COLOR != nil
  544. @sprite.bitmap.fill_rect(0, 0, @sprite.bitmap.width, @sprite.bitmap.height,
  545. Color.new(BG_COLOR.red, BG_COLOR.blue, BG_COLOR.green, @@opacity))
  546. end
  547.  
  548. # Redraw the (newly) visible portion on the minimap
  549. @sprite.bitmap.stretch_blt(Rect.new(0,0,@location.width,@location.height),
  550. @base_map,
  551. get_scroll_base_src_rect,
  552. 255 # opacity was already applied when caching the @sprite.bitmap. So keep it at 255 here.
  553. ) # stretch_blt
  554. end
  555. #-----------------------------------------------------------------------------
  556. # * Blink Cursor
  557. #-----------------------------------------------------------------------------
  558. def blink_cursor
  559. @player_sprite.visible = !BLINK_PLAYER || Nap::MM_Event.blink_visible?
  560. end
  561. #-----------------------------------------------------------------------------
  562. # * Update
  563. # Set forced to true to skip the frame-skipping.
  564. #-----------------------------------------------------------------------------
  565. def update(forced=true)
  566. if !forced && FRAME_SKIP
  567. if @updated_count < Nap::Minimap::FRAME_SKIP
  568. @updated_count += 1
  569. else
  570. @updated_count = 0
  571. return
  572. end
  573. end
  574.  
  575. return if !SceneManager.scene.instance_of?(Scene_Map) || @disposed
  576.  
  577. if (SceneManager.scene.instance_of?(Scene_Map) || @visibility_override == :show) && @visibility_override != :hide && @enabled && switch_enabled? && @has_image
  578. set_visibility(true) if !@visible
  579.  
  580. MM_Event.update_blink
  581. blink_cursor
  582. update_player_cursor if USE_PLAYER_GRAPHIC
  583.  
  584. case @@mode
  585. when :default
  586. set_cursor_location
  587. when :scroll
  588. set_scroll
  589. else
  590. raise "update: Unknown @@mode (#{@@mode})"
  591. end
  592.  
  593. render_events
  594. @icons.each { |i| i.render(self, @sprite.bitmap) } if @show_icons
  595. @visible = true
  596. else
  597. set_visibility(false) if @visible
  598. @visible = false
  599. end
  600. end
  601. #-----------------------------------------------------------------------------
  602. # Switch Enabled?
  603. #-----------------------------------------------------------------------------
  604. def switch_enabled?
  605. return true if ENABLED_SWITCH == -1
  606. return $game_switches[ENABLED_SWITCH]
  607. end
  608. #-----------------------------------------------------------------------------
  609. # * Set Visibiliy Override
  610. # - Sets minimap visibility according to item/wpn/armor settings
  611. # - returns true if the map should be visible
  612. #-----------------------------------------------------------------------------
  613. def item_visiblity
  614. return true if !REQUIRE_ITEM # return true if items are not required
  615. map_id = $game_map.map_id
  616.  
  617. if ITEMS[:item].has_key?(map_id)
  618. $data_items.each { |i|
  619. next if i.nil?
  620. return true if ITEMS[:item][map_id].include?(i.id) && $game_party.item_number(i) > 0
  621. }
  622. end
  623.  
  624. if ITEMS[:weapon].has_key?(map_id)
  625. $data_weapons.each { |w|
  626. next if w.nil?
  627. return true if ITEMS[:weapon][map_id].include?(w.id) && $game_party.item_number(w) > 0
  628. }
  629. end
  630.  
  631. if ITEMS[:armor].has_key?(map_id)
  632. $data_armors.each { |a|
  633. next if a.nil?
  634. return true if ITEMS[:armor][map_id].include?(a.id) && $game_party.item_number(a) > 0
  635. }
  636. end
  637.  
  638. return false
  639. end
  640. #-----------------------------------------------------------------------------
  641. # * Set Visibiliy Override
  642. #-----------------------------------------------------------------------------
  643. def set_visibility_override
  644. if !item_visiblity
  645. @visibility_override = :hide
  646. return
  647. end
  648.  
  649. # Always hide/show on this map depending on the 2 setting arrays
  650. @visibility_override = :normal
  651. if ALWAYS_SHOW.include?($game_map.map_id)
  652. @visibility_override = :show
  653. elsif ALWAYS_HIDE.include?($game_map.map_id)
  654. @visibility_override = :hide
  655. end
  656. end
  657. #-----------------------------------------------------------------------------
  658. # * Set Visibility
  659. #-----------------------------------------------------------------------------
  660. def set_visibility(visibility=@visible)
  661. @sprite.visible = visibility
  662. @border.visible = visibility if @border
  663. @player_sprite.visible = visibility if @player_sprite
  664. @overlay.visible = visibility && @overlay_enabled if @overlay
  665. end
  666. #-----------------------------------------------------------------------------
  667. # * Add Icon
  668. # - icon_id: is an identifier purely used to allow to remove it later by
  669. # using this id again. If you do not supply an id it will default to -1.
  670. # - x,y: the location on the real map in pixels (not in tiles).
  671. # - icon_index: the index of the icon from the ICON_SHEET. Starts at 0 but
  672. # the 0-index is by default an empy icon.
  673. #-----------------------------------------------------------------------------
  674. def add_icon(icon_id=-1, x, y, icon_index)
  675. icon_sheet = Cache.system(ICON_SHEET)
  676.  
  677. icon_img = Bitmap.new(24, 24)
  678. rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  679. icon_img.blt(0, 0, icon_sheet, rect)
  680. @icons << MM_Icon.new(icon_id, x, y, icon_img)
  681. icon_sheet.dispose
  682.  
  683. @save_icons << [icon_id, x, y, icon_index]
  684. end
  685. #-----------------------------------------------------------------------------
  686. # * Remove Icon
  687. #-----------------------------------------------------------------------------
  688. def rem_icon(id)
  689. @icons.each { |i| i.dispose if i.id == id }
  690. @icons.reject! { |i| i.id == id }
  691. @save_icons.reject! { |i| i[0] == id}
  692. end
  693. #-----------------------------------------------------------------------------
  694. # * Dispose
  695. #-----------------------------------------------------------------------------
  696. def dispose
  697. @disposed = true
  698. @map_img.dispose if @map_img
  699. @map_img = nil
  700. @sprite.dispose if @sprite && !@sprite.disposed?
  701. @player_sprite.dispose if @player_sprite && !@player_sprite.disposed?
  702. @border.dispose if @border && !@border.disposed?
  703. @border_img.dispose if @border_img && !@border_img.disposed?
  704. @cursor_img.dispose if @cursor_img && !@cursor_img.disposed?
  705. @overlay.dispose if @overlay && !@overlay.disposed?
  706. @base_map.dispose if @base_map && !@base_map.disposed?
  707. @arrows_src_img.dispose if @arrows_src_img && !@arrows_src_img.disposed?
  708. @icons.each { |i| i.dispose if i && !i.disposed?}
  709. end
  710. end; end # Nap; Minimap
  711. #===============================================================================
  712. # Cache
  713. #===============================================================================
  714. module Cache
  715. #-----------------------------------------------------------------------------
  716. # * Get Minimap Graphic [NEW]
  717. #-----------------------------------------------------------------------------
  718. def self.minimap(filename)
  719. load_bitmap("Graphics/#{Nap::Minimap::FOLDER}/", filename)
  720. end
  721. end
  722. #===============================================================================
  723. # Game Party
  724. # To show/hide the minimap whenever the party gains/loses a 'map-related' item
  725. #===============================================================================
  726. class Game_Party < Game_Unit
  727. #-----------------------------------------------------------------------------
  728. # Gain Item [ALIAS]
  729. #-----------------------------------------------------------------------------
  730. alias nap_minimap_gain_item gain_item
  731. def gain_item(item, amount, include_equip = false)
  732. nap_minimap_gain_item(item, amount, include_equip)
  733. $minimap.set_visibility_override if $minimap && Nap::Minimap::REQUIRE_ITEM
  734. end
  735.  
  736. #-----------------------------------------------------------------------------
  737. # Lose Item [ALIAS]
  738. #-----------------------------------------------------------------------------
  739. alias nap_minimap_lose_item lose_item
  740. def lose_item(item, amount, include_equip = false)
  741. nap_minimap_lose_item(item, amount, include_equip)
  742. $minimap.set_visibility_override if $minimap && Nap::Minimap::REQUIRE_ITEM
  743. end
  744. end
  745. #===============================================================================
  746. # Spriteset Map
  747. # For updating the minimap
  748. #===============================================================================
  749. class Spriteset_Map
  750. #-----------------------------------------------------------------------------
  751. # Update [ALIAS]
  752. #-----------------------------------------------------------------------------
  753. alias nap_minimap_update update
  754. def update
  755. nap_minimap_update
  756. $minimap.update if $minimap
  757. end
  758. end
  759. #===============================================================================
  760. # Class Event
  761. # For removing events from the minimap when the event is erased
  762. #===============================================================================
  763. class Game_Event < Game_Character
  764. #-----------------------------------------------------------------------------
  765. # Erase [ALIAS]
  766. #-----------------------------------------------------------------------------
  767. alias nap_minimap_erase erase
  768. def erase
  769. nap_minimap_erase
  770. $minimap.mm_events.reject! { |e| e.event.id == @id } if $minimap
  771. end
  772. end
  773. #===============================================================================
  774. # Game Event
  775. # For making sure that the event is only shown on the minimap when the page
  776. # that contains the minimap-comment-tag is actually active.
  777. #===============================================================================
  778. class Game_Event < Game_Character
  779. #-----------------------------------------------------------------------------
  780. # Setup Page Settings [ALIAS]
  781. #-----------------------------------------------------------------------------
  782. alias nap_minimap_setup_page_settings setup_page_settings
  783. def setup_page_settings
  784. nap_minimap_setup_page_settings
  785.  
  786. if SceneManager.scene.instance_of?(Scene_Map) && $minimap
  787. $minimap.remove_ev(self.id)
  788. return if self.list == nil
  789. for command in self.list
  790. $minimap.add_ev_unique(self, command)
  791. end
  792. end
  793. end
  794. end
  795. #===============================================================================
  796. # Saving & Loading
  797. #===============================================================================
  798. module DataManager
  799. class << self
  800. alias nap_minimap_make_save_contents make_save_contents
  801. alias nap_minimap_extract_save_contents extract_save_contents
  802. end
  803. #-----------------------------------------------------------------------------
  804. # Make Save Contents [ALIAS]
  805. #-----------------------------------------------------------------------------
  806. def self.make_save_contents
  807. contents = nap_minimap_make_save_contents
  808. contents[:nap_minimap] = {}
  809.  
  810. if $minimap && !$minimap.disposed?
  811. contents[:nap_minimap][:mode] = $minimap.mode
  812. contents[:nap_minimap][:visibility_override] = $minimap.visibility_override
  813. contents[:nap_minimap][:enabled] = $minimap.enabled
  814. contents[:nap_minimap][:location] = $minimap.location
  815. contents[:nap_minimap][:scroll_src_rect] = $minimap.scroll_src_rect
  816. #contents[:nap_minimap][:mm_events] = $minimap.mm_events
  817. contents[:nap_minimap][:show_icons] = $minimap.show_icons
  818. contents[:nap_minimap][:map_zoom_x] = $minimap.map_zoom_x
  819. contents[:nap_minimap][:map_zoom_y] = $minimap.map_zoom_y
  820. contents[:nap_minimap][:overlay_enabled] = $minimap.overlay_enabled
  821.  
  822. contents[:nap_minimap][:opacity] = $minimap.opacity
  823. contents[:nap_minimap][:map_icons] = $minimap.save_icons
  824. end
  825.  
  826. contents
  827. end
  828. #-----------------------------------------------------------------------------
  829. # Extract Save Contents [ALIAS]
  830. #-----------------------------------------------------------------------------
  831. def self.extract_save_contents(contents)
  832. nap_minimap_extract_save_contents(contents)
  833. Nap::Minimap.save_data = contents[:nap_minimap]
  834. end
  835. end
  836. #===============================================================================
  837. # Class Minimap
  838. #===============================================================================
  839. module Nap
  840. class Minimap
  841. # in case a savegame was loaded
  842. def load_data
  843. return if Minimap.save_data.nil? || @@save_data.empty?
  844.  
  845. set_mode(@@save_data[:mode]) # no "self."
  846. self.visibility_override = @@save_data[:visibility_override]
  847. self.enabled = @@save_data[:enabled]
  848. location = @@save_data[:location] # no "self."
  849. scroll_src_rect = @@save_data[:scroll_src_rect] # no "self."
  850. #mm_events = @@save_data[:mm_events]
  851. self.show_icons = @@save_data[:show_icons]
  852. map_zoom_x = @@save_data[:map_zoom_x] # no "self."
  853. map_zoom_y= @@save_data[:map_zoom_y] # no "self."
  854. self.overlay_enabled = @@save_data[:overlay_enabled]
  855.  
  856. @@save_data[:map_icons].each { |i|
  857. @save_icons << i
  858. add_icon(i[0], i[1], i[2], i[3])
  859. }
  860.  
  861. self.opacity = @@save_data[:opacity]
  862. end
  863. end
  864. end
  865. #===============================================================================
  866. # Scene Base
  867. # For: Creates the minimap
  868. #===============================================================================
  869. class Scene_Base
  870. #-----------------------------------------------------------------------------
  871. # Post Start [ALIAS]
  872. #-----------------------------------------------------------------------------
  873. alias nap_minimap_post_start post_start
  874. def post_start
  875. if SceneManager.scene.instance_of?(Scene_Map) &&
  876. Nap::Minimap::ONLY_VISIBLE_IN_SCENES.include?(self.class.name)
  877. if $minimap
  878. $minimap.super_visible = true
  879. $minimap.refresh
  880. else
  881. $minimap = Nap::Minimap.new
  882. end
  883. else
  884. $minimap.super_visible = false if $minimap
  885. end
  886. nap_minimap_post_start
  887. end
  888. end
  889. #===============================================================================
  890. # Scene Map
  891. #===============================================================================
  892. class Scene_Map < Scene_Base
  893. #-------------------------------------------------------------------------------
  894. # Pre Battle Scene [ALIAS]
  895. # ** Mario Buonocore - Hide Napoleon's Minimap before the battle transition.
  896. #
  897. # Nasconde la minimappa durante la battaglia.
  898. # Fa riferimento al valore della costante HIDE_IN_MENU.
  899. #-------------------------------------------------------------------------------
  900. alias lm_pre_battle_scene pre_battle_scene
  901. def pre_battle_scene
  902. $minimap.super_visible = false if Nap::Minimap::HIDE_BEFORE_BATTLE_TRANSITION
  903. lm_pre_battle_scene
  904. end
  905. #-----------------------------------------------------------------------------
  906. # Call Menu [ALIAS]
  907. # For: Storing player source rect before opening the menu
  908. #-----------------------------------------------------------------------------
  909. alias nap_minimap_call_menu call_menu
  910. def call_menu
  911. $minimap.store_player_source_rect
  912. nap_minimap_call_menu
  913. end
  914. #-----------------------------------------------------------------------------
  915. # Post Transfer [ALIAS]
  916. #-----------------------------------------------------------------------------
  917. alias nap_minimap_post_transfer post_transfer
  918. def post_transfer
  919. $minimap.refresh
  920. nap_minimap_post_transfer
  921. $minimap.refresh_events
  922. end
  923. end # Scene_Map
  924. #===============================================================================