Advertisement
Guest User

Untitled

a guest
Apr 26th, 2011
986
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.54 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Shanghai Simple Script - Location Name
  4. # Last Date Updated: 2010.05.21
  5. # Level: Easy
  6. #
  7. # This places a small window in the upper left corner of the map screen to show
  8. # the name of the current location. The location name window will also hide if
  9. # the player's screen position is directly under the location name window.
  10. # This will also update to the area's name if the player is inside of an area.
  11. #===============================================================================
  12. # Instructions
  13. # -----------------------------------------------------------------------------
  14. # To install this script, open up your script editor and copy/paste this script
  15. # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
  16. #
  17. # These commands go into the script call event.
  18. #   hide_location_name
  19. #   show_location_name
  20. # They do exactly as they suggest.
  21. #===============================================================================
  22.  
  23. $imported = {} if $imported == nil
  24. $imported["LocationName"] = true
  25.  
  26. module SSS
  27.   # This adjusts the backsprite used for the location background text.
  28.   LOCATION_COLOR1 = Color.new(0, 0, 0, 128)
  29.   LOCATION_COLOR2 = Color.new(0, 0, 0, 0)
  30.   LOCATION_PREFIX = "◆%s"
  31. end
  32.  
  33. #==============================================================================
  34. # ** Game_System
  35. #==============================================================================
  36.  
  37. class Game_System
  38.   #--------------------------------------------------------------------------
  39.   # * Public Instance Variables
  40.   #--------------------------------------------------------------------------
  41.   attr_accessor :hide_location_name
  42. end
  43.  
  44. #===============================================================================
  45. # ** Game_Map
  46. #===============================================================================
  47.  
  48. class Game_Map
  49.   #--------------------------------------------------------------------------
  50.   # * Location Name
  51.   #--------------------------------------------------------------------------
  52.   def location_name
  53.     data = load_data("Data/MapInfos.rvdata")
  54.     text = data[@map_id].name.gsub(/\[.*\]/) { "" }
  55.     for area in $data_areas.values
  56.       next unless $game_player.in_area?(area)
  57.       text = area.name.gsub(/\[.*\]/) { "" }
  58.       break
  59.     end
  60.     return text
  61.   end
  62. end
  63.  
  64. #==============================================================================
  65. # ** Game_Interpreter
  66. #==============================================================================
  67.  
  68. class Game_Interpreter
  69.   #--------------------------------------------------------------------------
  70.   # * Hide Location Name
  71.   #--------------------------------------------------------------------------
  72.   def hide_location_name
  73.     $game_system.hide_location_name = true
  74.   end
  75.   #--------------------------------------------------------------------------
  76.   # * Show Location Name
  77.   #--------------------------------------------------------------------------
  78.   def show_location_name
  79.     $game_system.hide_location_name = false
  80.   end
  81. end
  82.  
  83. #==============================================================================
  84. # ** Window_LocationName
  85. #==============================================================================
  86.  
  87. class Window_LocationName < Window_Base
  88.   #--------------------------------------------------------------------------
  89.   # * Object Initialization
  90.   #--------------------------------------------------------------------------
  91.   def initialize
  92.     super(0, 0, Graphics.width/2, 56)
  93.     self.back_opacity = 0
  94.     self.opacity = 0
  95.     create_location_color_sprite
  96.     @location_name = $game_map.location_name
  97.     refresh
  98.   end
  99.   #--------------------------------------------------------------------------
  100.   # * Dispose
  101.   #--------------------------------------------------------------------------
  102.   def dispose
  103.     @background_color_sprite.bitmap.dispose
  104.     @background_color_sprite.dispose
  105.     super
  106.   end
  107.   #--------------------------------------------------------------------------
  108.   # * Create Location Color Sprite
  109.   #--------------------------------------------------------------------------
  110.   def create_location_color_sprite
  111.     bitmap = Bitmap.new(Graphics.width/2, 24)
  112.     g1 = SSS::LOCATION_COLOR1
  113.     g2 = SSS::LOCATION_COLOR2
  114.     bitmap.gradient_fill_rect(0, 0, Graphics.width/4, 24, g1, g1)
  115.     bitmap.gradient_fill_rect(Graphics.width/4, 0, Graphics.width/4, 24, g1, g2)
  116.     @background_color_sprite = Sprite.new(self.viewport)
  117.     @background_color_sprite.bitmap = bitmap
  118.     @background_color_sprite.y = 16
  119.   end
  120.   #--------------------------------------------------------------------------
  121.   # * Frame Update
  122.   #--------------------------------------------------------------------------
  123.   def update
  124.     super
  125.     @background_color_sprite.update
  126.     rate = hide_sprite? ? -16 : 16
  127.     @background_color_sprite.opacity += rate
  128.     refresh if @location_name != $game_map.location_name
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # * Hide Sprite?
  132.   #--------------------------------------------------------------------------
  133.   def hide_sprite?
  134.     return true if $game_system.hide_location_name
  135.     if $game_player.screen_x < Graphics.width/3 and $game_player.screen_y <= 60
  136.       return true
  137.     end
  138.     return false
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # * Refresh
  142.   #--------------------------------------------------------------------------
  143.   def refresh
  144.     self.contents.clear
  145.     @location_name = $game_map.location_name
  146.     t = sprintf(SSS::LOCATION_PREFIX, @location_name)
  147.     @background_color_sprite.bitmap.dispose
  148.     create_location_color_sprite
  149.     @background_color_sprite.bitmap.draw_text(16, 0, contents.width, WLH, t)
  150.   end
  151. end
  152.  
  153. #==============================================================================
  154. # ** Scene_Map
  155. #==============================================================================
  156.  
  157. class Scene_Map < Scene_Base
  158.   #--------------------------------------------------------------------------
  159.   # * Start processing
  160.   #--------------------------------------------------------------------------
  161.   alias start_sss_location_name start unless $@
  162.   def start
  163.     start_sss_location_name
  164.     @location_window = Window_LocationName.new
  165.   end
  166.   #--------------------------------------------------------------------------
  167.   # * Termination Processing
  168.   #--------------------------------------------------------------------------
  169.   alias terminate_sss_location_name terminate unless $@
  170.   def terminate
  171.     @location_window.dispose
  172.     terminate_sss_location_name
  173.   end
  174.   #--------------------------------------------------------------------------
  175.   # * Basic Update Processing
  176.   #--------------------------------------------------------------------------
  177.   alias update_basic_sss_location_name update_basic unless $@
  178.   def update_basic
  179.     update_basic_sss_location_name
  180.     @location_window.update
  181.   end
  182.   #--------------------------------------------------------------------------
  183.   # * Frame Update
  184.   #--------------------------------------------------------------------------
  185.   alias update_sss_location_name update unless $@
  186.   def update
  187.     update_sss_location_name
  188.     @location_window.update
  189.   end
  190. end
  191.  
  192. #===============================================================================
  193. #
  194. # END OF FILE
  195. #
  196. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement