Advertisement
Guest User

Simple Map HUD

a guest
Dec 29th, 2011
587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.66 KB | None | 0 0
  1. #==============================================================================
  2. #   Simple Map HUD
  3. #   Author: Nicke
  4. #   Created: 07/06/2011
  5. #   Edited: 05/12/2011
  6. #   Version: 1.1a
  7. #==============================================================================
  8. # Instructions
  9. # -----------------------------------------------------------------------------
  10. # To install this script, open up your script editor and copy/paste this script
  11. # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
  12. #==============================================================================
  13. ($imported ||= {})["NICKE-MAP"] = true
  14.  
  15. module NICKE
  16.   module MAP_HUD
  17. #==============================================================================#
  18. # ** Settings
  19. #==============================================================================#
  20.  
  21.   # MAP_FONT   |FONT|     |SIZE|        |COLOR|           |SHADOW|
  22.   MAP_FONT = ["Tahoma",    16,   Color.new(255,215,100),  true]
  23.  
  24.   # MAP_WINDOW   |X|      |Y|       |Z|        |OPACITY|
  25.   MAP_WINDOW =  [-12,     -20,      200,           0]
  26.  
  27.   # MAP_HUD     |ICON|   |VISIBLITY|   |SHOW_ICON|
  28.   MAP_HUD =     [153,       1,            true]
  29.  
  30.   SHOW_MAP_ID = nil  # Show map for ID(s).
  31.  
  32.   MAPNAME_REPLACE = {                    # Map ID => "ReplacedName"
  33.   } # Don't remove this line!
  34.  
  35.   # If you don't use the replace function feel free to comment it out.
  36.   #=========================================================================#
  37.   Map_Example = "This text will be shown for id 1 to 5."
  38.   Map_Example2 = "This text will be shown for id 6 and 8."
  39.  
  40.   def self.replace_mapname(oldname, map_id)    
  41.     case map_id
  42.       when 1..5 ;              return Map_Example
  43.       when 6,8 ;                return Map_Example2
  44.     end
  45.     return MAPNAME_REPLACE[map_id] if MAPNAME_REPLACE.has_key?(map_id)
  46.     return oldname
  47.   end
  48.   #=========================================================================#
  49.  
  50.   end
  51. end
  52. # *** Don't edit below unless you know what you are doing. ***
  53. include NICKE::MAP_HUD
  54. #==============================================================================#
  55. # ** Game_Map
  56. #------------------------------------------------------------------------------
  57. #  Method for reading the map id and name.
  58. #==============================================================================#
  59. class Game_Map
  60.  
  61.   attr_reader :name
  62.   alias nicke_map_hud_setup setup
  63.   def setup(map_id)
  64.     nicke_map_hud_setup(map_id)
  65.     @map_infos = load_data("Data/MapInfos.rvdata") if @map_infos.nil?
  66.     @name = NICKE::MAP_HUD.replace_mapname(@map_infos[@map_id].name, @map_id)
  67.   end
  68.  
  69. end
  70.  
  71. #==============================================================================#
  72. # ** Window_Base
  73. #------------------------------------------------------------------------------
  74. #  Method for drawing the map.
  75. #==============================================================================#
  76. class Window_Base < Window
  77.  
  78.   def draw_map_hud(x, y)
  79.     self.contents.font.name  = MAP_FONT[0]
  80.     self.contents.font.size  = MAP_FONT[1]
  81.     self.contents.font.color = MAP_FONT[2]
  82.     self.contents.font.shadow = MAP_FONT[3]
  83.     self.contents.draw_text(x + 30, y, 260, 32, $game_map.name.to_s, 0)
  84.   end
  85.  
  86. end
  87.  
  88. #==============================================================================
  89. # ** Simple_Map_HUD
  90. #------------------------------------------------------------------------------
  91. #  This window displays the current location.
  92. #==============================================================================
  93. class Simple_Map_HUD < Window_Base
  94.  
  95.   def initialize(x, y)
  96.     super(x, y, 360, WLH + 38)
  97.     @map_id = $game_map.map_id
  98.     refresh
  99.   end
  100.  
  101.   def refresh
  102.     self.contents.clear
  103.     draw_map_hud(0, 0) # // Draw map.
  104.     draw_icon(MAP_HUD[0], 0, 6) if MAP_HUD[2]
  105.   end
  106.  
  107.   def update
  108.     super
  109.     if @map_id != $game_map.map_id # // Refresh if map changed.
  110.       refresh
  111.       @map_id = $game_map.map_id
  112.     end  
  113.   end
  114.  
  115. end
  116.  
  117. #==============================================================================
  118. # ** Scene_Map
  119. #------------------------------------------------------------------------------
  120. #  Show a location window on the map.
  121. #==============================================================================
  122. class Scene_Map < Scene_Base
  123.    
  124.   alias nicke_map_hud_start start unless $@
  125.   def start(*args, &block)
  126.     nicke_map_hud_start(*args, &block)
  127.     create_map_hud
  128.     @map_hud.visible = $game_switches[MAP_HUD[1]]
  129.     if SHOW_MAP_ID != nil
  130.       if SHOW_MAP_ID.include?($game_map.map_id)
  131.          @map_hud.visible = true
  132.       else
  133.         @map_hud.visible = false
  134.       end
  135.     end
  136.   end
  137.  
  138.   alias nicke_map_hud_terminate terminate unless $@
  139.   def terminate(*args, &block)
  140.     nicke_map_hud_terminate(*args, &block)
  141.     dispose_map_hud
  142.   end
  143.  
  144.   def create_map_hud
  145.     @map_hud = Simple_Map_HUD.new(MAP_WINDOW[0], MAP_WINDOW[1])
  146.     @map_hud.z = MAP_WINDOW[2]
  147.     @map_hud.opacity = MAP_WINDOW[3]
  148.   end
  149.  
  150.   def dispose_map_hud
  151.     @map_hud.dispose unless @map_hud.nil?
  152.     @map_hud = nil
  153.   end
  154.  
  155.   alias nicke_map_hud_update update unless $@
  156.   def update(*args, &block)
  157.     nicke_map_hud_update(*args, &block)
  158.     @map_hud.update
  159.     @map_hud.visible = $game_switches[MAP_HUD[1]]
  160.     if SHOW_MAP_ID != nil
  161.       if SHOW_MAP_ID.include?($game_map.map_id)
  162.          @map_hud.visible = true
  163.       else
  164.         @map_hud.visible = false
  165.       end
  166.     end
  167.   end
  168.  
  169. end # END OF FILE
  170.  
  171. #=*==========================================================================*=#
  172. # ** END OF FILE
  173. #=*==========================================================================*=#
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement