Advertisement
LiTTleDRAgo

[RGSS/2] Show Event Name v3

Jul 25th, 2011
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 15.54 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  2. # [Xp/Vx] Show Event Name
  3. # Version: 3.14
  4. # Author : LiTTleDRAgo
  5. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  6. #
  7. # Explanation:
  8. #
  9. #   - This script shows event name in map
  10. #
  11. # Instructions:
  12. #
  13. #   - Setup the few configurations below.  
  14. #   - This script uses comments in the event's pages at any line.
  15. #    
  16. #     Comment : Show Name
  17. #
  18. #   That's all
  19. #
  20. #   To show name actor, set the event name to \a[ ActorID ]
  21. #   To show value of variable, set to \v[ VariableID ]
  22. #
  23. #  Extra Function
  24. #     \fontsize[ Size ]
  25. #     \bold
  26. #     \italic
  27. #     \fontname[ Fontname ]
  28. #     \color[ R, G, B, ALPHA ]
  29. #     \sn[ Name ]
  30. #
  31. #  Press Z and C together to turn on the name on / off
  32. #
  33. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  34.  
  35. module EventName
  36.  
  37.   FONT        = ['Calibri',12]   # Font Name and Font Size
  38.   BOLD        = true             # Toggle Bold
  39.   ITALIC      = true             # Toggle Italic
  40.   PLAYER_NAME = true             # Show the player name too?
  41.   SWITCH      = 50               # Switch for Disable Show Event Name
  42.   PRESS_BTN   = [Input::A,       # (Z Keyboard XP) (Shift Keyboard VX)
  43.                  Input::C]       # (C/Enter Keyboard XP) (Z/Enter Keyboard VX)
  44.   COLOR       = Color.new(255,255,255,240) # Color Default
  45.   POSITION    = "A"              # A = Above, B = Below
  46.   RANGE       = 3                # Range from character to show the name
  47.  
  48. end
  49.  
  50.  
  51.  
  52. #------------------------------------------------------------------------------
  53. # SDK Check
  54. #------------------------------------------------------------------------------
  55. if Object.const_defined?('SDK')
  56.  SDK.log('Show Event Name', 'LiTTleDRAgo', 3, '03.02.11')
  57.  @event_name_disabled = !SDK.enabled?('Show Event Name')
  58. end
  59.  
  60. if !@event_name_disabled
  61.  
  62. Sprite_Base = RPG::Sprite  if !defined? Sprite_Base
  63. #==============================================================================
  64. # ** Sprite_EventName
  65. #------------------------------------------------------------------------------
  66. #  This sprite is used to display Event Name. It observes a instance of the
  67. # Game_Character class and automatically changes sprite conditions.
  68. #==============================================================================
  69. class Sprite_EventName < Sprite_Base
  70.  
  71.   FONT          = EventName::FONT
  72.   BOLD          = EventName::BOLD
  73.   ITALIC        = EventName::ITALIC
  74.   PLAYER_NAME   = EventName::PLAYER_NAME
  75.   DIS_EV_SWITCH = EventName::SWITCH
  76.   PRESS_BTN     = EventName::PRESS_BTN
  77.   COLOR         = EventName::COLOR
  78.   POS           = EventName::POSITION
  79.   RANGE         = EventName::RANGE
  80.   #--------------------------------------------------------------------------
  81.   # * Public Instance Variables
  82.   #--------------------------------------------------------------------------
  83.   attr_accessor :character
  84.   #--------------------------------------------------------------------------
  85.   # * Object Initialization
  86.   #     viewport  : viewport
  87.   #     character : character (Game_Character)
  88.   #--------------------------------------------------------------------------
  89.   def initialize(v,character)
  90.     super(v)
  91.     @character = character
  92.     @name_event = Sprite.new
  93.     @name_event.bitmap = Bitmap.new(100,280)
  94.     @name_event.visible = true
  95.     refresh_name
  96.     update
  97.   end
  98.   #--------------------------------------------------------------------------
  99.   # * Coloring
  100.   #--------------------------------------------------------------------------
  101.   def coloring
  102.     size, name, bold, italic, color = FONT[1], FONT[0], BOLD, ITALIC, COLOR
  103.       if $xrxs_xas
  104.         @char.gsub!(/<Enemy(\d+)>/i) do color = Color.new(255,0,0,240) end
  105.       elsif $BlizzABS && @character.is_a?(Map_Battler)
  106.         case @character.ai.group
  107.         when 1 then color = Color.new(0  , 0  , 255, 240)
  108.         when 2 then color = Color.new(255, 0  , 0  , 240)
  109.         when 3 then color = Color.new(128, 128, 128, 240)
  110.         when 4 then color = Color.new(128, 128, 128, 240)
  111.         when 5 then color = Color.new(255, 255, 0  , 240)
  112.         when 6 then color = Color.new(0  , 255, 0  , 240)
  113.         end
  114.       end
  115.       @char.gsub!(/\\fontsize\[(\d+)\]/) do size   = $1.to_i  end
  116.       @char.gsub!('\\bold')              do bold   = true     end
  117.       @char.gsub!('\\italic')            do italic = true     end
  118.       @char.gsub!(/\\fontname\[(.*?)\]/) do name   = $1.to_s  end
  119.       @char.gsub!(/\\color\[(\d+),(\d+),(\d+),(\d+)\]/) do
  120.         color = Color.new($1.to_i,$2.to_i,$3.to_i,$4.to_i)    end
  121.     @name_event.bitmap.font.name   = name
  122.     @name_event.bitmap.font.bold   = bold
  123.     @name_event.bitmap.font.italic = italic
  124.     @name_event.bitmap.font.size   = size
  125.     @name_event.bitmap.font.color  = color
  126.   end
  127.   #--------------------------------------------------------------------------
  128.   # * Check Name
  129.   #--------------------------------------------------------------------------
  130.   def event_name_check
  131.     @char.gsub!(/\\[Vv]\[([0-9]+)\]/) { $game_variables[$1.to_i] }
  132.     @char.gsub!(/\\[Aa]\[([0-9]+)\]/) { !$game_actors[$1.to_i].nil? ?
  133.                                         $game_actors[$1.to_i].name : ''}
  134.     @char.gsub!(/\\fontsize\[(\d+)\]/) {''}
  135.     @char.gsub!('\\bold')              {''}
  136.     @char.gsub!('\\italic')            {''}
  137.     @char.gsub!(/\\fontname\[(.*?)\]/) {''}
  138.     @char.gsub!(/\\color\[(\d+),(\d+),(\d+),(\d+)\]/) {''}
  139.     if $xrxs_xas
  140.       @char.gsub!(/<Footstep>/i) {''}
  141.       @char.gsub!(/<Throw(\d+)>/i) {''}
  142.       @char.gsub!(/<Somaria(\d+)>/i) {''}
  143.       @char.gsub!(/<Hookshot(\d+)>/i) {''}
  144.       @char.gsub!(/<Enemy(\d+)>/i) { !$data_enemies[$1.to_i].nil? ?
  145.                                      $data_enemies[$1.to_i].name : ''}
  146.     end
  147.     @char.gsub!(/\\[Ss][Nn]\[(.*?)\]/) do @char = $1.to_s end
  148.   end
  149.   #--------------------------------------------------------------------------
  150.   # * Update
  151.   #--------------------------------------------------------------------------
  152.   def update
  153.     super
  154.     if @tile_id != @character.tile_id or
  155.         @character_name != @character.character_name or
  156.         (!rpgvx? && @character_hue != @character.character_hue)
  157.       @tile_id, @character_name = @character.tile_id, @character.character_name
  158.       @character_hue = @character.character_hue  if !rpgvx?
  159.       refresh_name
  160.     end
  161.     return @name_event.visible = false if !DIS_EV_SWITCH.nil? and
  162.        (@character.opacity < 50 or $game_switches[DIS_EV_SWITCH])
  163.     visibility if !PRESS_BTN.nil?
  164.     if @name_event.visible
  165.       refresh_name if @cw.nil?
  166.       @name_event.x = @character.screen_x - (@cw.nil? ? 0 : @cw /2)
  167.       @name_event.y = @character.screen_y - (POS == "A" ? @ch : 0)
  168.       @name_event.z = 1
  169.       @name_event.opacity    = @character.opacity
  170.       @name_event.blend_type = @character.blend_type
  171.       @name_event.bush_depth = @character.bush_depth
  172.     end
  173.   end
  174.   #--------------------------------------------------------------------------
  175.   # * Refresh
  176.   #--------------------------------------------------------------------------
  177.   def refresh_name
  178.     return if @name_event.nil? or @name_event.bitmap.nil? or
  179.     @name_event.disposed? or !@name_event.visible or @character.name_effect.nil?
  180.     @name_event.bitmap.clear
  181.     @character.name_effect.each {|@char| coloring; event_name_check }
  182.     draw_name if ($BlizzABS && @character.is_a?(Map_Actor) && PLAYER_NAME) or
  183.             ($BlizzABS && @character.is_a?(Map_Enemy) && @character.nametag) or
  184.             (@character.is_a?(Game_Event) && @character.nametag) or
  185.             (@character.is_a?(Game_Player) && PLAYER_NAME) or
  186.             ($xas_caterpillar && @character.is_a?(Game_Party) && PLAYER_NAME)
  187.     @x_frame, @y_frame = 4, 4
  188.     if POS == "A"
  189.       if rpgvx?
  190.         @cw = @name_event.bitmap.width / @x_frame / 2
  191.         @ch = @name_event.bitmap.height / @y_frame - 40
  192.         return
  193.       end
  194.       bit = RPG::Cache.character(@character.character_name,
  195.           @character.character_hue)
  196.       @cw = bit.width / @x_frame / 2
  197.       @ch = bit.height / @y_frame + 15
  198.     else
  199.       @cw = @name_event.bitmap.width / @x_frame / 2
  200.       @ch = @name_event.bitmap.height / @y_frame - 40
  201.     end
  202.   end
  203.   #--------------------------------------------------------------------------
  204.   # * Draw Name
  205.   #--------------------------------------------------------------------------
  206.   def draw_name
  207.     if defined? Bitmap.draw_hemming_text
  208.       @name_event.bitmap.draw_hemming_text(0, 0, 100, 20, @char ,4)
  209.     else
  210.       @name_event.bitmap.draw_text(0, 0, 100, 20, @char ,4)
  211.     end
  212.   end
  213.   #--------------------------------------------------------------------------
  214.   # * Dispose
  215.   #--------------------------------------------------------------------------
  216.   def dispose
  217.     super
  218.     @name_event.dispose
  219.   end
  220.   #--------------------------------------------------------------------------
  221.   # * Visibility
  222.   #--------------------------------------------------------------------------
  223.   def visibility
  224.     pressed = Input.press?(PRESS_BTN[0]) && Input.trigger?(PRESS_BTN[1])
  225.     if RANGE != nil && !@pressed
  226.       x = ($game_player.x-@character.x).abs+($game_player.y-@character.y).abs
  227.       @name_event.visible = (x <= RANGE)
  228.     end
  229.     if !@pressed && pressed
  230.       @name_event.visible, @pressed = false, true
  231.     elsif @pressed && pressed
  232.       @name_event.visible, @pressed = true, false
  233.     end
  234.   end  
  235. end
  236.  
  237. #==============================================================================
  238. # ** Kernel
  239. #==============================================================================
  240. module Kernel
  241.   def rpgvx?() return (defined? Graphics.resize_screen) end
  242. end
  243.  
  244. Cache = RPG::Cache if !defined? Cache
  245. #==============================================================================
  246. # ** Game_Party
  247. #------------------------------------------------------------------------------
  248. #  This class handles the party. It includes information on amount of gold
  249. # and items. The instance of this class is referenced by $game_party.
  250. #==============================================================================
  251. class Game_Party
  252.   #--------------------------------------------------------------------------
  253.   # * Name
  254.   #--------------------------------------------------------------------------
  255.   def name_effect() leader_name  end
  256.   #--------------------------------------------------------------------------
  257.   # * Leader Name
  258.   #--------------------------------------------------------------------------
  259.   def leader_name
  260.     return @actors[0].nil? ? '' : @actors[0].name if !rpgvx?
  261.     return members[0].nil? ? '' : members[0].name
  262.   end  
  263. end
  264.  
  265. #==============================================================================
  266. # ** Game_Event
  267. #------------------------------------------------------------------------------
  268. #  This class deals with events. It handles functions including event page
  269. # switching via condition determinants, and running parallel process events.
  270. # It's used within the Game_Map class.
  271. #==============================================================================
  272. class Game_Event
  273.   #--------------------------------------------------------------------------
  274.   # * Name
  275.   #--------------------------------------------------------------------------
  276.   def name_effect() @event.name  end
  277.   #--------------------------------------------------------------------------
  278.   # * Nametag
  279.   #--------------------------------------------------------------------------
  280.   def nametag
  281.     return (!@list.nil? && @list.any? {|i| i.code == 108 &&
  282.       i.parameters == ['Show Name']})
  283.   end
  284. end
  285.  
  286. #==============================================================================
  287. # ** Game_Player
  288. #------------------------------------------------------------------------------
  289. #  This class handles maps. It includes event starting determinants and map
  290. # scrolling functions. The instance of this class is referenced by $game_map.
  291. #==============================================================================
  292. class Game_Player
  293.   #--------------------------------------------------------------------------
  294.   # * Name
  295.   #--------------------------------------------------------------------------
  296.   def name_effect() return $game_party.leader_name end
  297. end
  298.  
  299. #==============================================================================
  300. # ** Map Battler
  301. #------------------------------------------------------------------------------
  302. #  This class handles battlers in Blizz ABS
  303. #==============================================================================
  304. if $BlizzABS  
  305.   class Map_Battler
  306.     def name_effect() return @battler.name end
  307.     def nametag
  308.       return (!@list.nil? && @list.any? {|i| i.code == 108 &&
  309.         i.parameters == ['Show Name']})
  310.     end
  311.   end
  312. end
  313.  
  314. #==============================================================================
  315. # ** Scene_Map
  316. #------------------------------------------------------------------------------
  317. #  This class performs the map screen processing.
  318. #==============================================================================
  319. class Scene_Map
  320.   attr_accessor :spriteset
  321. end
  322.  
  323.   #--------------------------------------------------------------------------
  324.   # * Refresh Name
  325.   #--------------------------------------------------------------------------
  326.   def refresh_name(val=nil)  
  327.     return $scene.spriteset.eventname[val].refresh_name if !val.nil?
  328.     $scene.spriteset.eventname.each {|i| i.refresh_name}
  329.   end
  330.  
  331. #==============================================================================
  332. # ** Spriteset_Map
  333. #------------------------------------------------------------------------------
  334. #  This class brings together map screen sprites, tilemaps, etc. It's used
  335. # within the Scene_Map class.
  336. #==============================================================================
  337. class Spriteset_Map
  338.  
  339.   PRESS_BTN     = EventName::PRESS_BTN
  340.   #--------------------------------------------------------------------------
  341.   # * Public Instance Variables
  342.   #--------------------------------------------------------------------------
  343.   attr_accessor :eventname
  344.   #--------------------------------------------------------------------------
  345.   # * Main Processing
  346.   #--------------------------------------------------------------------------
  347.   def init_eventname
  348.     @eventname = []
  349.     @eventname[0] = Sprite_EventName.new(@viewport1,$game_player)  
  350.     ($game_map.events.keys.sort).each {|i|
  351.       @eventname[i] = Sprite_EventName.new(@viewport1,$game_map.events[i])}
  352.   end
  353.   #--------------------------------------------------------------------------
  354.   # * Frame Update
  355.   #--------------------------------------------------------------------------
  356.   alias update_eventname_earlier update
  357.   def update
  358.     @eventname.nil? ? init_eventname : @eventname.each {|i|i.update if !i.nil?}
  359.     update_eventname_earlier
  360.   end  
  361.   #--------------------------------------------------------------------------
  362.   # * Dispose
  363.   #--------------------------------------------------------------------------
  364.   alias dispose_eventname dispose
  365.   def dispose
  366.     @eventname.each {|i| i.dispose if !i.nil?}
  367.     dispose_eventname
  368.   end
  369. end
  370. #--------------------------------------------------------------------------
  371. # SDK Check End
  372. #--------------------------------------------------------------------------
  373. end
  374. #--------------------------------------------------------------------------
  375. # END OF SCRIPT
  376. #--------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement