khanhdu

Minimap - KMS_MiniMap ◆ VXAce

Sep 24th, 2016
302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 38.42 KB | None | 0 0
  1. #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  2. #_/    ◆ Minimap - KMS_MiniMap ◆ VXAce ◆
  3. #_/    ◇ Last update : 2012/02/12  (TOMY@Kamesoft) ◇
  4. #_/    ◇ Website: http://ytomy.sakura.ne.jp/ ◇
  5. #_/    ◇ Translated by Mr. Bubble ◇
  6. #_/----------------------------------------------------------------------------
  7. #_/ Createts a minimap HUD based off the passability settings of the map.
  8. #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  9. # This script is plug-and-play, but various customization options are available.
  10. #----------------------------------------------------------------------------
  11. #   Map Notetags
  12. #----------------------------------------------------------------------------
  13. # Notetags are added to "Notes" boxes. Right-click a map and select
  14. # Map Properties to find the "Notes" box for maps.
  15. #
  16. # <minimap hide>
  17. #   Completely disables the minimap on a specific map. [NOMAP] can also be
  18. #   added to the beginning of map names for the same effect.
  19. #----------------------------------------------------------------------------
  20. #   Event Comment Tags
  21. #----------------------------------------------------------------------------
  22. # Since events do not have noteboxes, comment tags are used instead. Open the
  23. # event, create a new event command, go to Tab 1, and click the "Comment..."
  24. # event command. A box will open up allowing you to enter tags.
  25. #
  26. # <minimap wall>
  27. #   Add this tag to an event's comment to change its minimap color to the
  28. #   same as an impassable tile.
  29. #
  30. # <minimap move>
  31. #   Add this tag to an event's comment to have them blink in the minimap.
  32. #
  33. # <minimap obj n>
  34. #   Add this tag to an event's comment to have them blink in the minimap with
  35. #   a specified color where n is the OBJ value defined in OBJECT_COLOR which
  36. #   is found in the customization module below.
  37. #----------------------------------------------------------------------------
  38. #   Script Calls
  39. #----------------------------------------------------------------------------
  40. # Script calls are used in "Script..." event commands located under Tab 3.
  41. #
  42. # hide_minimap
  43. #   Use this script call to hide the minimap on command.
  44. #
  45. # show_minimap
  46. #   Use this script call to show the minimap on command.
  47. #
  48. # refresh_minimap
  49. #   Use this script call to refresh the minimap.
  50. #
  51. # update_minimap_object
  52. #   Use this script call to refresh objects on the minimap such as events.
  53. #----------------------------------------------------------------------------
  54. #   Script Calls : Conditional Branches
  55. #----------------------------------------------------------------------------
  56. # The following script calls can be used in Conditional Branches.
  57. #
  58. # minimap_showing?
  59. #   Determines if the minimap is currently showing/hidden.
  60. #----------------------------------------------------------------------------
  61. #   Usage Notes
  62. #----------------------------------------------------------------------------
  63. # Impassable events will not appear as the correct color in the minimap.
  64. # This effect is intended. If you want an event to appear as impassable
  65. # on the minimap, add the tag <minimap wall> to an event's comment.
  66. #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  67.  
  68. #==============================================================================
  69. # ★ BEGIN Setting ★
  70. #==============================================================================
  71. module KMS_MiniMap
  72.   # * Minimap Display Toggle Button
  73.   # Set to nil to disable this function
  74.   SWITCH_BUTTON = nil
  75.  
  76.   # * Minimap Size and Position (x, y, width, height)
  77.   MAP_RECT = Rect.new(364, 20, 160, 120)
  78.   # * Minimap z-layer Priority
  79.   # Glitchy if this value is set too high
  80.   MAP_Z = 0
  81.   # * Minimap Grid Size
  82.   #   A size of 3 or higher is recommended
  83.   GRID_SIZE = 5
  84.  
  85.   # * Mini-Map Color Settings
  86.   #                  Color.new(red, green, blue, opacity)
  87.   FOREGROUND_COLOR = Color.new(224, 224, 255, 160)  # Foreground (passable)
  88.   BACKGROUND_COLOR = Color.new(  0,   0, 160, 160)  # Background (not passable)
  89.   POSITION_COLOR   = Color.new(255,   0,   0, 192)  # Current Position color
  90.   MOVE_EVENT_COLOR = Color.new(255, 160,   0, 192)  # Moving event color
  91.   VEHICLE_COLOR    = Color.new( 96, 128,   0, 192)  # Vehicle color
  92.  
  93.   # * Object Color Presets
  94.   #   Create custom color presets for events tagged with the
  95.   #   corresponding OBJ tag
  96.   OBJECT_COLOR = [
  97.   # Color.new(red, green, blue, opacity)
  98.     Color.new(  0, 128,   0, 192),  # OBJ 1
  99.     Color.new(  0, 160, 160, 192),  # OBJ 2
  100.     Color.new(160,   0, 160, 192),  # OBJ 3
  101.    
  102.     # More color presets may be added in this array where OBJ number is
  103.     # determined by the position in the list (OBJ 4, OBJ 5, etc.)
  104.  
  105.   ]  # <- Do not delete this line
  106.  
  107.   # * Minimap Blinking Frequency
  108.   # Values 5~8 are recommended
  109.   BLINK_LEVEL = 7
  110.  
  111.   # * Minimap Cache Setting
  112.   #   This script creates a cache for each map. If the number of cached
  113.   #   maps exceed CACHE_NUM, oldest cached maps are deleted.
  114.   CACHE_NUM = 10
  115. end
  116. #==============================================================================
  117. # ☆ END Setting ☆
  118. #==============================================================================
  119.  
  120. $kms_imported = {} if $kms_imported == nil
  121. $kms_imported["MiniMap"] = true
  122.  
  123. module KMS_MiniMap
  124.   # ミニマップ非表示
  125.   REGEX_NO_MINIMAP_NOTE = /<(?:ミニマップ|MINIMAP)\s*(?:非表示|HIDE)>/i
  126.   REGEX_NO_MINIMAP_NAME = /\[NOMAP\]/i
  127.  
  128.   # 障害物
  129.   REGEX_WALL_EVENT = /<(?:ミニマップ|MINIMAP)\s*(?:壁|障害物|WALL)>/i
  130.  
  131.   # 移動イベント
  132.   REGEX_MOVE_EVENT = /<(?:ミニマップ|MINIMAP)\s*(?:移動|MOVE)>/i
  133.  
  134.   # オブジェクト
  135.   REGEX_OBJECT = /<(?:ミニマップ|MINIMAP)\s+OBJ(?:ECT)?\s*(\d+)>/i
  136. end
  137.  
  138. # *****************************************************************************
  139.  
  140. #==============================================================================
  141. # □ KMS_Commands
  142. #==============================================================================
  143.  
  144. module KMS_Commands
  145.   module_function
  146.   #--------------------------------------------------------------------------
  147.   # ○ ミニマップを表示
  148.   #--------------------------------------------------------------------------
  149.   def show_minimap
  150.     $game_temp.minimap_manual_visible = true
  151.     $game_system.minimap_show         = true
  152.   end
  153.   #--------------------------------------------------------------------------
  154.   # ○ ミニマップを隠す
  155.   #--------------------------------------------------------------------------
  156.   def hide_minimap
  157.     $game_system.minimap_show = false
  158.   end
  159.   #--------------------------------------------------------------------------
  160.   # ○ ミニマップ表示状態の取得
  161.   #--------------------------------------------------------------------------
  162.   def minimap_showing?
  163.     return $game_system.minimap_show
  164.   end
  165.   #--------------------------------------------------------------------------
  166.   # ○ ミニマップをリフレッシュ
  167.   #--------------------------------------------------------------------------
  168.   def refresh_minimap
  169.     return unless SceneManager.scene_is?(Scene_Map)
  170.  
  171.     $game_map.refresh if $game_map.need_refresh
  172.     SceneManager.scene.refresh_minimap
  173.   end
  174.   #--------------------------------------------------------------------------
  175.   # ○ ミニマップのオブジェクトを更新
  176.   #--------------------------------------------------------------------------
  177.   def update_minimap_object
  178.     return unless SceneManager.scene_is?(Scene_Map)
  179.  
  180.     $game_map.refresh if $game_map.need_refresh
  181.     SceneManager.scene.update_minimap_object
  182.   end
  183. end
  184.  
  185. #==============================================================================
  186. # ■ Game_Interpreter
  187. #==============================================================================
  188.  
  189. class Game_Interpreter
  190.   # イベントコマンドから直接コマンドを叩けるようにする
  191.   include KMS_Commands
  192. end
  193.  
  194. #==============================================================================
  195. # ■ RPG::Map
  196. #==============================================================================
  197.  
  198. class RPG::Map
  199.   #--------------------------------------------------------------------------
  200.   # ○ ミニマップのキャッシュ生成
  201.   #--------------------------------------------------------------------------
  202.   def create_minimap_cache
  203.     @__minimap_show = true
  204.  
  205.     note.each_line { |line|
  206.       if line =~ KMS_MiniMap::REGEX_NO_MINIMAP_NOTE  # マップ非表示
  207.         @__minimap_show = false
  208.       end
  209.     }
  210.   end
  211.   #--------------------------------------------------------------------------
  212.   # ○ ミニマップ表示
  213.   #--------------------------------------------------------------------------
  214.   def minimap_show?
  215.     create_minimap_cache if @__minimap_show.nil?
  216.     return @__minimap_show
  217.   end
  218. end
  219.  
  220. #==============================================================================
  221. # ■ RPG::MapInfo
  222. #==============================================================================
  223.  
  224. class RPG::MapInfo
  225.   #--------------------------------------------------------------------------
  226.   # ● マップ名取得
  227.   #--------------------------------------------------------------------------
  228.   def name
  229.     return @name.gsub(/\[.*\]/) { "" }
  230.   end
  231.   #--------------------------------------------------------------------------
  232.   # ○ オリジナルマップ名取得
  233.   #--------------------------------------------------------------------------
  234.   def original_name
  235.     return @name
  236.   end
  237.   #--------------------------------------------------------------------------
  238.   # ○ ミニマップのキャッシュ生成
  239.   #--------------------------------------------------------------------------
  240.   def create_minimap_cache
  241.     @__minimap_show = !(@name =~ KMS_MiniMap::REGEX_NO_MINIMAP_NAME)
  242.   end
  243.   #--------------------------------------------------------------------------
  244.   # ○ ミニマップ表示
  245.   #--------------------------------------------------------------------------
  246.   def minimap_show?
  247.     create_minimap_cache if @__minimap_show == nil
  248.     return @__minimap_show
  249.   end
  250. end
  251.  
  252. #==============================================================================
  253. # ■ Game_Temp
  254. #==============================================================================
  255.  
  256. class Game_Temp
  257.   #--------------------------------------------------------------------------
  258.   # ○ 公開インスタンス変数
  259.   #--------------------------------------------------------------------------
  260.   attr_accessor :minimap_manual_visible  # ミニマップ手動表示切り替えフラグ
  261.   #--------------------------------------------------------------------------
  262.   # ○ オブジェクト初期化
  263.   #--------------------------------------------------------------------------
  264.   alias initialize_KMS_MiniMap initialize
  265.   def initialize
  266.     initialize_KMS_MiniMap
  267.  
  268.     @minimap_manual_visible = true
  269.   end
  270. end
  271.  
  272. #==============================================================================
  273. # ■ Game_System
  274. #==============================================================================
  275.  
  276. class Game_System
  277.   #--------------------------------------------------------------------------
  278.   # ○ 公開インスタンス変数
  279.   #--------------------------------------------------------------------------
  280.   attr_accessor :minimap_show  # ミニマップ表示フラグ
  281.   #--------------------------------------------------------------------------
  282.   # ○ オブジェクト初期化
  283.   #--------------------------------------------------------------------------
  284.   alias initialize_KMS_MiniMap initialize
  285.   def initialize
  286.     initialize_KMS_MiniMap
  287.  
  288.     @minimap_show = false
  289.   end
  290. end
  291.  
  292. #==============================================================================
  293. # ■ Game_Map
  294. #==============================================================================
  295.  
  296. class Game_Map
  297.   #--------------------------------------------------------------------------
  298.   # ○ 定数
  299.   #--------------------------------------------------------------------------
  300.   MINIMAP_FADE_NONE = 0  # ミニマップ フェードなし
  301.   MINIMAP_FADE_IN   = 1  # ミニマップ フェードイン
  302.   MINIMAP_FADE_OUT  = 2  # ミニマップ フェードアウト
  303.   #--------------------------------------------------------------------------
  304.   # ○ 公開インスタンス変数
  305.   #--------------------------------------------------------------------------
  306.   attr_accessor :minimap_fade
  307.   #--------------------------------------------------------------------------
  308.   # ○ ミニマップを表示するか
  309.   #--------------------------------------------------------------------------
  310.   def minimap_show?
  311.     return $data_mapinfos[map_id].minimap_show? && @map.minimap_show?
  312.   end
  313.   #--------------------------------------------------------------------------
  314.   # ○ ミニマップをフェードイン
  315.   #--------------------------------------------------------------------------
  316.   def fadein_minimap
  317.     @minimap_fade = MINIMAP_FADE_IN
  318.   end
  319.   #--------------------------------------------------------------------------
  320.   # ○ ミニマップをフェードアウト
  321.   #--------------------------------------------------------------------------
  322.   def fadeout_minimap
  323.     @minimap_fade = MINIMAP_FADE_OUT
  324.   end
  325.   #--------------------------------------------------------------------------
  326.   # ● リフレッシュ
  327.   #--------------------------------------------------------------------------
  328.   alias refresh_KMS_MiniMap refresh
  329.   def refresh
  330.     refresh_KMS_MiniMap
  331.  
  332.     SceneManager.scene.refresh_minimap if SceneManager.scene_is?(Scene_Map)
  333.   end
  334. end
  335.  
  336. #==============================================================================
  337. # ■ Game_Event
  338. #==============================================================================
  339.  
  340. class Game_Event < Game_Character
  341.   #--------------------------------------------------------------------------
  342.   # ○ ミニマップ用のキャッシュを作成
  343.   #--------------------------------------------------------------------------
  344.   def __create_minimap_cache
  345.     @__last_page = @page
  346.     @__minimap_wall_event  = false
  347.     @__minimap_move_event  = false
  348.     @__minimap_object_type = -1
  349.  
  350.     return if @page.nil?
  351.  
  352.     @page.list.each { |cmd|
  353.       # 注釈以外に到達したら離脱
  354.       break unless [108, 408].include?(cmd.code)
  355.  
  356.       # 正規表現判定
  357.       case cmd.parameters[0]
  358.       when KMS_MiniMap::REGEX_WALL_EVENT
  359.         @__minimap_wall_event = true
  360.       when KMS_MiniMap::REGEX_MOVE_EVENT
  361.         @__minimap_move_event = true
  362.       when KMS_MiniMap::REGEX_OBJECT
  363.         @__minimap_object_type = $1.to_i
  364.       end
  365.     }
  366.   end
  367.   private :__create_minimap_cache
  368.   #--------------------------------------------------------------------------
  369.   # ○ グラフィックがあるか
  370.   #--------------------------------------------------------------------------
  371.   def graphic_exist?
  372.     return (character_name != "" || tile_id > 0)
  373.   end
  374.   #--------------------------------------------------------------------------
  375.   # ○ 障害物か
  376.   #--------------------------------------------------------------------------
  377.   def is_minimap_wall_event?
  378.     if @__minimap_wall_event.nil? || @__last_page != @page
  379.       __create_minimap_cache
  380.     end
  381.  
  382.     return @__minimap_wall_event
  383.   end
  384.   #--------------------------------------------------------------------------
  385.   # ○ 移動イベントか
  386.   #--------------------------------------------------------------------------
  387.   def is_minimap_move_event?
  388.     if @__minimap_move_event.nil? || @__last_page != @page
  389.       __create_minimap_cache
  390.     end
  391.  
  392.     return @__minimap_move_event
  393.   end
  394.   #--------------------------------------------------------------------------
  395.   # ○ ミニマップオブジェクトか
  396.   #--------------------------------------------------------------------------
  397.   def is_minimap_object?
  398.     if @__minimap_object_type.nil? || @__last_page != @page
  399.       __create_minimap_cache
  400.     end
  401.  
  402.     return @__minimap_object_type > 0
  403.   end
  404.   #--------------------------------------------------------------------------
  405.   # ○ ミニマップオブジェクトタイプ
  406.   #--------------------------------------------------------------------------
  407.   def minimap_object_type
  408.     if @__minimap_object_type.nil? || @__last_page != @page
  409.       __create_minimap_cache
  410.     end
  411.  
  412.     return @__minimap_object_type
  413.   end
  414. end
  415.  
  416. #==============================================================================
  417. # □ Game_MiniMap
  418. #------------------------------------------------------------------------------
  419. #   ミニマップを扱うクラスです。
  420. #==============================================================================
  421.  
  422. class Game_MiniMap
  423.   #--------------------------------------------------------------------------
  424.   # ○ 構造体
  425.   #--------------------------------------------------------------------------
  426.   Point = Struct.new(:x, :y)
  427.   Size  = Struct.new(:width, :height)
  428.   PassageCache = Struct.new(:map_id, :table, :scan_table)
  429.   #--------------------------------------------------------------------------
  430.   # ○ クラス変数
  431.   #--------------------------------------------------------------------------
  432.   @@passage_cache = []  # 通行フラグテーブルキャッシュ
  433.   #--------------------------------------------------------------------------
  434.   # ● オブジェクト初期化
  435.   #--------------------------------------------------------------------------
  436.   def initialize(tilemap)
  437.     @map_rect  = KMS_MiniMap::MAP_RECT
  438.     @grid_size = [KMS_MiniMap::GRID_SIZE, 1].max
  439.  
  440.     @x = 0
  441.     @y = 0
  442.     @grid_num = Point.new(
  443.       (@map_rect.width  + @grid_size - 1) / @grid_size,
  444.       (@map_rect.height + @grid_size - 1) / @grid_size
  445.     )
  446.     @draw_grid_num    = Point.new(@grid_num.x + 2, @grid_num.y + 2)
  447.     @draw_range_begin = Point.new(0, 0)
  448.     @draw_range_end   = Point.new(0, 0)
  449.     @tilemap = tilemap
  450.  
  451.     @last_x = $game_player.x
  452.     @last_y = $game_player.y
  453.  
  454.     @showing = false
  455.     @hiding  = false
  456.  
  457.     create_sprites
  458.     refresh
  459.  
  460.     unless $game_temp.minimap_manual_visible
  461.       self.opacity = 0
  462.     end
  463.   end
  464.   #--------------------------------------------------------------------------
  465.   # ○ スプライト作成
  466.   #--------------------------------------------------------------------------
  467.   def create_sprites
  468.     @viewport   = Viewport.new(@map_rect)
  469.     @viewport.z = KMS_MiniMap::MAP_Z
  470.  
  471.     # ビットマップサイズ計算
  472.     @bmp_size = Size.new(
  473.       (@grid_num.x + 2) * @grid_size,
  474.       (@grid_num.y + 2) * @grid_size
  475.     )
  476.     @buf_bitmap = Bitmap.new(@bmp_size.width, @bmp_size.height)
  477.  
  478.     # マップ用スプライト作成
  479.     @map_sprite   = Sprite.new(@viewport)
  480.     @map_sprite.x = -@grid_size
  481.     @map_sprite.y = -@grid_size
  482.     @map_sprite.z = 0
  483.     @map_sprite.bitmap = Bitmap.new(@bmp_size.width, @bmp_size.height)
  484.  
  485.     # オブジェクト用スプライト作成
  486.     @object_sprite   = Sprite_MiniMapIcon.new(@viewport)
  487.     @object_sprite.x = -@grid_size
  488.     @object_sprite.y = -@grid_size
  489.     @object_sprite.z = 1
  490.     @object_sprite.bitmap = Bitmap.new(@bmp_size.width, @bmp_size.height)
  491.  
  492.     # 現在位置スプライト作成
  493.     @position_sprite   = Sprite_MiniMapIcon.new
  494.     @position_sprite.x = @map_rect.x + @grid_num.x / 2 * @grid_size
  495.     @position_sprite.y = @map_rect.y + @grid_num.y / 2 * @grid_size
  496.     @position_sprite.z = @viewport.z + 2
  497.     bitmap = Bitmap.new(@grid_size, @grid_size)
  498.     bitmap.fill_rect(bitmap.rect, KMS_MiniMap::POSITION_COLOR)
  499.     @position_sprite.bitmap = bitmap
  500.   end
  501.   #--------------------------------------------------------------------------
  502.   # ● 解放
  503.   #--------------------------------------------------------------------------
  504.   def dispose
  505.     @buf_bitmap.dispose
  506.     @map_sprite.bitmap.dispose
  507.     @map_sprite.dispose
  508.     @object_sprite.bitmap.dispose
  509.     @object_sprite.dispose
  510.     @position_sprite.bitmap.dispose
  511.     @position_sprite.dispose
  512.     @viewport.dispose
  513.   end
  514.   #--------------------------------------------------------------------------
  515.   # ○ 可視状態取得
  516.   #--------------------------------------------------------------------------
  517.   def visible
  518.     return @map_sprite.visible
  519.   end
  520.   #--------------------------------------------------------------------------
  521.   # ○ 可視状態設定
  522.   #--------------------------------------------------------------------------
  523.   def visible=(value)
  524.     @viewport.visible        = value
  525.     @map_sprite.visible      = value
  526.     @object_sprite.visible   = value
  527.     @position_sprite.visible = value
  528.   end
  529.   #--------------------------------------------------------------------------
  530.   # ○ 不透明度取得
  531.   #--------------------------------------------------------------------------
  532.   def opacity
  533.     return @map_sprite.opacity
  534.   end
  535.   #--------------------------------------------------------------------------
  536.   # ○ 不透明度設定
  537.   #--------------------------------------------------------------------------
  538.   def opacity=(value)
  539.     @map_sprite.opacity      = value
  540.     @object_sprite.opacity   = value
  541.     @position_sprite.opacity = value
  542.   end
  543.   #--------------------------------------------------------------------------
  544.   # ○ リフレッシュ
  545.   #--------------------------------------------------------------------------
  546.   def refresh
  547.     update_draw_range
  548.     update_passage_table
  549.     update_object_list
  550.     update_position
  551.     draw_map
  552.     draw_object
  553.     Graphics.frame_reset
  554.   end
  555.   #--------------------------------------------------------------------------
  556.   # ○ フェードイン
  557.   #--------------------------------------------------------------------------
  558.   def fadein
  559.     @showing = true
  560.     @hiding  = false
  561.   end
  562.   #--------------------------------------------------------------------------
  563.   # ○ フェードアウト
  564.   #--------------------------------------------------------------------------
  565.   def fadeout
  566.     @showing = false
  567.     @hiding  = true
  568.   end
  569.   #--------------------------------------------------------------------------
  570.   # ○ キー入力更新
  571.   #--------------------------------------------------------------------------
  572.   def update_input
  573.     return if KMS_MiniMap::SWITCH_BUTTON.nil?
  574.  
  575.     if Input.trigger?(KMS_MiniMap::SWITCH_BUTTON)
  576.       if opacity < 255 && !@showing
  577.         $game_temp.minimap_manual_visible = true
  578.         fadein
  579.       elsif opacity > 0 && !@hiding
  580.         $game_temp.minimap_manual_visible = false
  581.         fadeout
  582.       end
  583.     end
  584.   end
  585.   #--------------------------------------------------------------------------
  586.   # ○ 描画範囲更新
  587.   #--------------------------------------------------------------------------
  588.   def update_draw_range
  589.     range = []
  590.     (2).times { |i| range[i] = @draw_grid_num[i] / 2 }
  591.  
  592.     @draw_range_begin.x = $game_player.x - range[0]
  593.     @draw_range_begin.y = $game_player.y - range[1]
  594.     @draw_range_end.x   = $game_player.x + range[0]
  595.     @draw_range_end.y   = $game_player.y + range[1]
  596.   end
  597.   #--------------------------------------------------------------------------
  598.   # ○ 通行可否テーブル更新
  599.   #--------------------------------------------------------------------------
  600.   def update_passage_table
  601.     cache = get_passage_table_cache
  602.     @passage_table      = cache.table
  603.     @passage_scan_table = cache.scan_table
  604.  
  605.     update_around_passage_table
  606.   end
  607.   #--------------------------------------------------------------------------
  608.   # ○ 通行可否テーブルのキャッシュを取得
  609.   #--------------------------------------------------------------------------
  610.   def get_passage_table_cache
  611.     map_id = $game_map.map_id
  612.     cache  = @@passage_cache.find { |c| c.map_id == map_id }
  613.  
  614.     # キャッシュミスしたら新規作成
  615.     if cache == nil
  616.       cache = PassageCache.new(map_id)
  617.       cache.table      = Table.new($game_map.width, $game_map.height)
  618.       cache.scan_table = Table.new(
  619.         ($game_map.width  + @draw_grid_num.x - 1) / @draw_grid_num.x,
  620.         ($game_map.height + @draw_grid_num.y - 1) / @draw_grid_num.y
  621.       )
  622.     end
  623.  
  624.     # 直近のキャッシュは先頭に移動し、古いキャッシュは削除
  625.     @@passage_cache.unshift(cache)
  626.     @@passage_cache.delete_at(KMS_MiniMap::CACHE_NUM)
  627.  
  628.     return cache
  629.   end
  630.   #--------------------------------------------------------------------------
  631.   # ○ 通行可否テーブルのキャッシュをクリア
  632.   #--------------------------------------------------------------------------
  633.   def clear_passage_table_cache
  634.     return if @passage_scan_table == nil
  635.  
  636.     table = @passage_scan_table
  637.     @passage_scan_table = Table.new(table.xsize, table.ysize)
  638.   end
  639.   #--------------------------------------------------------------------------
  640.   # ○ 通行可否テーブルの探索
  641.   #     x, y : 探索位置
  642.   #--------------------------------------------------------------------------
  643.   def scan_passage(x, y)
  644.     dx = x / @draw_grid_num.x
  645.     dy = y / @draw_grid_num.y
  646.  
  647.     # 探索済み
  648.     return if @passage_scan_table[dx, dy] == 1
  649.  
  650.     # マップ範囲外
  651.     return unless dx.between?(0, @passage_scan_table.xsize - 1)
  652.     return unless dy.between?(0, @passage_scan_table.ysize - 1)
  653.  
  654.     rx = (dx * @draw_grid_num.x)...((dx + 1) * @draw_grid_num.x)
  655.     ry = (dy * @draw_grid_num.y)...((dy + 1) * @draw_grid_num.y)
  656.     mw = $game_map.width  - 1
  657.     mh = $game_map.height - 1
  658.  
  659.     # 探索範囲内の通行テーブルを生成
  660.     rx.each { |x|
  661.       next unless x.between?(0, mw)
  662.       ry.each { |y|
  663.         next unless y.between?(0, mh)
  664.  
  665.         # 通行方向フラグ作成
  666.         # (↓、←、→、↑ の順に 1, 2, 4, 8 が対応)
  667.         flag = 0
  668.         [2, 4, 6, 8].each{ |d|
  669.           flag |= 1 << (d / 2 - 1) if $game_map.passable?(x, y, d)
  670.         }
  671.         @passage_table[x, y] = flag
  672.       }
  673.     }
  674.     @passage_scan_table[dx, dy] = 1
  675.   end
  676.   #--------------------------------------------------------------------------
  677.   # ○ 周辺の通行可否テーブル更新
  678.   #--------------------------------------------------------------------------
  679.   def update_around_passage_table
  680.     gx = @draw_grid_num.x
  681.     gy = @draw_grid_num.y
  682.     dx = $game_player.x - gx / 2
  683.     dy = $game_player.y - gy / 2
  684.     scan_passage(dx,      dy)
  685.     scan_passage(dx + gx, dy)
  686.     scan_passage(dx,      dy + gy)
  687.     scan_passage(dx + gx, dy + gy)
  688.   end
  689.   #--------------------------------------------------------------------------
  690.   # ○ オブジェクト一覧更新
  691.   #--------------------------------------------------------------------------
  692.   def update_object_list
  693.     events = $game_map.events.values
  694.  
  695.     # WALL
  696.     @wall_events = events.find_all { |e| e.is_minimap_wall_event? }
  697.  
  698.     # MOVE
  699.     @move_events = events.find_all { |e| e.is_minimap_move_event? }
  700.  
  701.     # OBJ
  702.     @object_list = events.find_all { |e| e.is_minimap_object? }
  703.   end
  704.   #--------------------------------------------------------------------------
  705.   # ○ 位置更新
  706.   #--------------------------------------------------------------------------
  707.   def update_position
  708.     # 移動量算出
  709.     pt = Point.new($game_player.x, $game_player.y)
  710.     ox = ($game_player.real_x - pt.x) * @grid_size
  711.     oy = ($game_player.real_y - pt.y) * @grid_size
  712.  
  713.     @viewport.ox = ox
  714.     @viewport.oy = oy
  715.  
  716.     # 移動していたらマップ再描画
  717.     if pt.x != @last_x || pt.y != @last_y
  718.       draw_map
  719.       @last_x = pt.x
  720.       @last_y = pt.y
  721.     end
  722.   end
  723.   #--------------------------------------------------------------------------
  724.   # ○ 描画範囲内判定
  725.   #--------------------------------------------------------------------------
  726.   def in_draw_range?(x, y)
  727.     rb = @draw_range_begin
  728.     re = @draw_range_end
  729.     return (x.between?(rb.x, re.x) && y.between?(rb.y, re.y))
  730.   end
  731.   #--------------------------------------------------------------------------
  732.   # ○ マップ範囲内判定
  733.   #--------------------------------------------------------------------------
  734.   def in_map_range?(x, y)
  735.     mw = $game_map.width
  736.     mh = $game_map.height
  737.     return (x.between?(0, mw - 1) && y.between?(0, mh - 1))
  738.   end
  739.   #--------------------------------------------------------------------------
  740.   # ○ マップ描画
  741.   #--------------------------------------------------------------------------
  742.   def draw_map
  743.     update_around_passage_table
  744.  
  745.     bitmap  = @map_sprite.bitmap
  746.     bitmap.fill_rect(bitmap.rect, KMS_MiniMap::BACKGROUND_COLOR)
  747.  
  748.     draw_map_foreground(bitmap)
  749.     draw_map_move_event(bitmap)
  750.   end
  751.   #--------------------------------------------------------------------------
  752.   # ○ 通行可能領域の描画
  753.   #--------------------------------------------------------------------------
  754.   def draw_map_foreground(bitmap)
  755.     range_x = (@draw_range_begin.x)..(@draw_range_end.x)
  756.     range_y = (@draw_range_begin.y)..(@draw_range_end.y)
  757.     map_w   = $game_map.width  - 1
  758.     map_h   = $game_map.height - 1
  759.     rect    = Rect.new(0, 0, @grid_size, @grid_size)
  760.  
  761.     range_x.each { |x|
  762.       next unless x.between?(0, map_w)
  763.       range_y.each { |y|
  764.         next unless y.between?(0, map_h)
  765.         next if @passage_table[x, y] == 0
  766.         next if @wall_events.find { |e| e.x == x && e.y == y }  # 壁
  767.  
  768.         # グリッド描画サイズ算出
  769.         rect.set(0, 0, @grid_size, @grid_size)
  770.         rect.x = (x - @draw_range_begin.x) * @grid_size
  771.         rect.y = (y - @draw_range_begin.y) * @grid_size
  772.         flag = @passage_table[x, y]
  773.         if flag & 0x01 == 0  # 下通行不能
  774.           rect.height -= 1
  775.         end
  776.         if flag & 0x02 == 0  # 左通行不能
  777.           rect.x     += 1
  778.           rect.width -= 1
  779.         end
  780.         if flag & 0x04 == 0  # 右通行不能
  781.           rect.width -= 1
  782.         end
  783.         if flag & 0x08 == 0  # 上通行不能
  784.           rect.y      += 1
  785.           rect.height -= 1
  786.         end
  787.         bitmap.fill_rect(rect, KMS_MiniMap::FOREGROUND_COLOR)
  788.       }
  789.     }
  790.   end
  791.   #--------------------------------------------------------------------------
  792.   # ○ 移動イベントの描画
  793.   #--------------------------------------------------------------------------
  794.   def draw_map_move_event(bitmap)
  795.     rect = Rect.new(0, 0, @grid_size, @grid_size)
  796.     @move_events.each { |e|
  797.       rect.x = (e.x - @draw_range_begin.x) * @grid_size
  798.       rect.y = (e.y - @draw_range_begin.y) * @grid_size
  799.       bitmap.fill_rect(rect, KMS_MiniMap::MOVE_EVENT_COLOR)
  800.     }
  801.   end
  802.   #--------------------------------------------------------------------------
  803.   # ○ アニメーション更新
  804.   #--------------------------------------------------------------------------
  805.   def update_animation
  806.     if @showing
  807.       # フェードイン
  808.       self.opacity += 16
  809.       if opacity == 255
  810.         @showing = false
  811.       end
  812.     elsif @hiding
  813.       # フェードアウト
  814.       self.opacity -= 16
  815.       if opacity == 0
  816.         @hiding = false
  817.       end
  818.     end
  819.   end
  820.   #--------------------------------------------------------------------------
  821.   # ○ オブジェクト描画
  822.   #--------------------------------------------------------------------------
  823.   def draw_object
  824.     # 下準備
  825.     bitmap = @object_sprite.bitmap
  826.     bitmap.clear
  827.     rect = Rect.new(0, 0, @grid_size, @grid_size)
  828.  
  829.     # オブジェクト描画
  830.     @object_list.each { |obj|
  831.       next unless in_draw_range?(obj.x, obj.y)
  832.  
  833.       color = KMS_MiniMap::OBJECT_COLOR[obj.minimap_object_type - 1]
  834.       next if color.nil?
  835.  
  836.       rect.x = (obj.real_x - @draw_range_begin.x) * @grid_size
  837.       rect.y = (obj.real_y - @draw_range_begin.y) * @grid_size
  838.       bitmap.fill_rect(rect, color)
  839.     }
  840.  
  841.     # 乗り物描画
  842.     $game_map.vehicles.each { |vehicle|
  843.       next if vehicle.transparent
  844.  
  845.       rect.x = (vehicle.real_x - @draw_range_begin.x) * @grid_size
  846.       rect.y = (vehicle.real_y - @draw_range_begin.y) * @grid_size
  847.       bitmap.fill_rect(rect, KMS_MiniMap::VEHICLE_COLOR)
  848.     }
  849.   end
  850.   #--------------------------------------------------------------------------
  851.   # ○ 更新
  852.   #--------------------------------------------------------------------------
  853.   def update
  854.     update_input
  855.  
  856.     return unless need_update?
  857.  
  858.     update_draw_range
  859.     update_position
  860.     update_animation
  861.     draw_object
  862.  
  863.     @map_sprite.update
  864.     @object_sprite.update
  865.     @position_sprite.update
  866.   end
  867.   #--------------------------------------------------------------------------
  868.   # ○ 更新判定
  869.   #--------------------------------------------------------------------------
  870.   def need_update?
  871.     return (visible && opacity > 0) || @showing || @hiding
  872.   end
  873. end
  874.  
  875. #==============================================================================
  876. # □ Sprite_MiniMapIcon
  877. #------------------------------------------------------------------------------
  878. #   ミニマップ用アイコンのクラスです。
  879. #==============================================================================
  880.  
  881. class Sprite_MiniMapIcon < Sprite
  882.   DURATION_MAX = 60
  883.   #--------------------------------------------------------------------------
  884.   # ● オブジェクト初期化
  885.   #     viewport : ビューポート
  886.   #--------------------------------------------------------------------------
  887.   def initialize(viewport = nil)
  888.     super(viewport)
  889.     @duration = DURATION_MAX / 2
  890.   end
  891.   #--------------------------------------------------------------------------
  892.   # ● フレーム更新
  893.   #--------------------------------------------------------------------------
  894.   def update
  895.     super
  896.     @duration += 1
  897.     if @duration == DURATION_MAX
  898.       @duration = 0
  899.     end
  900.     update_effect
  901.   end
  902.   #--------------------------------------------------------------------------
  903.   # ○ エフェクトの更新
  904.   #--------------------------------------------------------------------------
  905.   def update_effect
  906.     self.color.set(255, 255, 255,
  907.       (@duration - DURATION_MAX / 2).abs * KMS_MiniMap::BLINK_LEVEL
  908.     )
  909.   end
  910. end
  911.  
  912. #==============================================================================
  913. # ■ Spriteset_Map
  914. #==============================================================================
  915.  
  916. class Spriteset_Map
  917.   attr_reader :minimap
  918.   #--------------------------------------------------------------------------
  919.   # ● オブジェクト初期化
  920.   #--------------------------------------------------------------------------
  921.   alias initialize_KMS_MiniMap initialize
  922.   def initialize
  923.     initialize_KMS_MiniMap
  924.  
  925.     create_minimap
  926.   end
  927.   #--------------------------------------------------------------------------
  928.   # ○ ミニマップの作成
  929.   #--------------------------------------------------------------------------
  930.   def create_minimap
  931.     @minimap = Game_MiniMap.new(@tilemap)
  932.     @minimap.visible = $game_system.minimap_show && $game_map.minimap_show?
  933.   end
  934.   #--------------------------------------------------------------------------
  935.   # ● 解放
  936.   #--------------------------------------------------------------------------
  937.   alias dispose_KMS_MiniMap dispose
  938.   def dispose
  939.     dispose_KMS_MiniMap
  940.  
  941.     dispose_minimap
  942.   end
  943.   #--------------------------------------------------------------------------
  944.   # ○ ミニマップの解放
  945.   #--------------------------------------------------------------------------
  946.   def dispose_minimap
  947.     @minimap.dispose
  948.     @minimap = nil
  949.   end
  950.   #--------------------------------------------------------------------------
  951.   # ● フレーム更新
  952.   #--------------------------------------------------------------------------
  953.   alias update_KMS_MiniMap update
  954.   def update
  955.     update_KMS_MiniMap
  956.  
  957.     update_minimap
  958.   end
  959.   #--------------------------------------------------------------------------
  960.   # ○ ミニマップ更新
  961.   #--------------------------------------------------------------------------
  962.   def minimap_show?
  963.     return $game_map.minimap_show? && $game_system.minimap_show
  964.   end
  965.   #--------------------------------------------------------------------------
  966.   # ○ ミニマップ更新
  967.   #--------------------------------------------------------------------------
  968.   def update_minimap
  969.     return if @minimap.nil?
  970.  
  971.     # 表示切替
  972.     if minimap_show?
  973.       @minimap.visible = true
  974.     else
  975.       @minimap.visible = false
  976.       return
  977.     end
  978.  
  979.     # フェード判定
  980.     case $game_map.minimap_fade
  981.     when Game_Map::MINIMAP_FADE_IN
  982.       @minimap.fadein
  983.       $game_map.minimap_fade = Game_Map::MINIMAP_FADE_NONE
  984.     when Game_Map::MINIMAP_FADE_OUT
  985.       @minimap.fadeout
  986.       $game_map.minimap_fade = Game_Map::MINIMAP_FADE_NONE
  987.     end
  988.  
  989.     @minimap.update
  990.   end
  991.   #--------------------------------------------------------------------------
  992.   # ○ ミニマップ全体をリフレッシュ
  993.   #--------------------------------------------------------------------------
  994.   def refresh_minimap
  995.     return if @minimap.nil?
  996.  
  997.     @minimap.clear_passage_table_cache
  998.     @minimap.refresh
  999.   end
  1000.   #--------------------------------------------------------------------------
  1001.   # ○ ミニマップのオブジェクトを更新
  1002.   #--------------------------------------------------------------------------
  1003.   def update_minimap_object
  1004.     @minimap.update_object_list unless @minimap.nil?
  1005.   end
  1006. end
  1007.  
  1008. #==============================================================================
  1009. # ■ Scene_Map
  1010. #==============================================================================
  1011.  
  1012. class Scene_Map
  1013.   #--------------------------------------------------------------------------
  1014.   # ● 場所移動後の処理
  1015.   #--------------------------------------------------------------------------
  1016.   alias post_transfer_KMS_MiniMap post_transfer
  1017.   def post_transfer
  1018.     refresh_minimap
  1019.  
  1020.     post_transfer_KMS_MiniMap
  1021.   end
  1022.   #--------------------------------------------------------------------------
  1023.   # ○ ミニマップ全体をリフレッシュ
  1024.   #--------------------------------------------------------------------------
  1025.   def refresh_minimap
  1026.     @spriteset.refresh_minimap unless @spriteset.nil?
  1027.   end
  1028.   #--------------------------------------------------------------------------
  1029.   # ○ ミニマップのオブジェクトを更新
  1030.   #--------------------------------------------------------------------------
  1031.   def update_minimap_object
  1032.     @spriteset.update_minimap_object unless @spriteset.nil?
  1033.   end
  1034. end
Add Comment
Please, Sign In to add comment