Advertisement
LiTTleDRAgo

[RGSS/2] Show Event Name v4

Oct 28th, 2011
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 18.69 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # [Xp/Vx] Show Event Name
  3. # Version: 4.21
  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. #
  15. #
  16. #   - Insert the event name
  17. #     <Name=X>       X = Name showed in map
  18. #     <SizeX>        X = Size the font
  19. #     <Bold>         Toggle Bold
  20. #     <Italic>       Toggle Italic
  21. #     <Font[X]>      X = Font name
  22. #     <ColorX,X,X,X> X,X,X,X = Color the font(in RGB)
  23. #
  24. #   - Or use call script to show the event name
  25. #    
  26. #     $game_map.events[2].show_name = x
  27. #     $game_player.show_name = x
  28. #
  29. #     where x is a string
  30. #
  31. #   That's all
  32. #
  33. #  Press Z and C together to turn on the name on / off
  34. #
  35. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  36.  
  37. module EventName
  38.  
  39.   FONT        = ['Calibri',16]   # Font Name and Font Size
  40.  
  41.   BOLD        = true             # Toggle Bold
  42.   ITALIC      = true             # Toggle Italic
  43.  
  44.   SWITCH      = 50               # Switch for Disable Show Event Name
  45.   PRESS_BTN   = [Input::A,       # (Z Keyboard XP) (Shift Keyboard VX)
  46.                  Input::C]       # (C/Enter Keyboard XP) (Z/Enter Keyboard VX)
  47.                  
  48.   COLOR       = Color.new(0,0,0,240) # Color Default
  49.   POSITION    = "A"                  # A = Above, B = Below
  50.   RANGE       = 3                    # Range from character to show the name
  51.  
  52.   USEPICT     = nil       # Show background for event name (in folder Pictures)
  53.                           # leave nil if you don't want to
  54.   OFFSET      = [0,0]     # offset x and y
  55.                          
  56. end
  57.  
  58. VX  = defined?(Window_ActorCommand)
  59. VXA = defined?(Window_BattleActor)
  60.  
  61. if true
  62. #==============================================================================
  63. # ** Sprite_EventName
  64. #------------------------------------------------------------------------------
  65. #  This sprite is used to display Event Name. It observes a instance of the
  66. # Game_Character class and automatically changes sprite conditions.
  67. #==============================================================================
  68. class Sprite_EventName < RPG::Sprite
  69.  
  70.   FONT          = EventName::FONT
  71.   BOLD          = EventName::BOLD
  72.   ITALIC        = EventName::ITALIC
  73.   DIS_EV_SWITCH = EventName::SWITCH
  74.   PRESS_BTN     = EventName::PRESS_BTN
  75.   COLOR         = EventName::COLOR
  76.   POS           = EventName::POSITION
  77.   RANGE         = EventName::RANGE
  78.   USEPICT       = EventName::USEPICT
  79.   OFFSET       = EventName::OFFSET
  80.   #--------------------------------------------------------------------------
  81.   # * Public Instance Variables
  82.   #--------------------------------------------------------------------------
  83.   attr_accessor :character
  84.   define_method(:cache) { VX ? Cache : RPG::Cache }
  85.   #--------------------------------------------------------------------------
  86.   # * Object Initialization
  87.   #     viewport  : viewport
  88.   #     character : character (Game_Character)
  89.   #--------------------------------------------------------------------------
  90.   def initialize(v,character)
  91.     super(v)
  92.     @character = character
  93.     @character.load_name
  94.     @name_event = Sprite.new
  95.     @name_event.bitmap = Bitmap.new(200,280)
  96.     if USEPICT
  97.       @back = Sprite.new
  98.       @back.bitmap = cache.picture(USEPICT)
  99.       @back.visible = false
  100.     end
  101.     @name_event.visible = true
  102.     refresh_name
  103.     update
  104.   end
  105.   #--------------------------------------------------------------------------
  106.   # * Coloring
  107.   #--------------------------------------------------------------------------
  108.   def coloring
  109.     size, name, bold, italic, color = FONT[1], FONT[0], BOLD, ITALIC, COLOR
  110.     size   = @character.fontsize if @character.fontsize
  111.     bold   = @character.bold
  112.     italic = @character.italic
  113.     color  = @character.color if @character.color
  114.     name   = @character.font if @character.font
  115.       if $xrxs_xas
  116.         @char.gsub!(/<Enemy(\d+)>/i) do color = Color.new(255,0,0,240) end
  117.       elsif $BlizzABS && @character.is_a?(Map_Battler)
  118.         case @character.ai.group
  119.         when 1 then color = Color.new(0  , 0  , 255, 240)
  120.         when 2 then color = Color.new(255, 0  , 0  , 240)
  121.         when 3 then color = Color.new(128, 128, 128, 240)
  122.         when 4 then color = Color.new(128, 128, 128, 240)
  123.         when 5 then color = Color.new(255, 255, 0  , 240)
  124.         when 6 then color = Color.new(0  , 255, 0  , 240)
  125.         end
  126.       end
  127.       @char.gsub!(/<Size(\d+)>/)      do size   = $1.to_i  end
  128.       @char.gsub!(/<Bold>/i)          do bold   = true     end
  129.       @char.gsub!(/<Italic>/i)        do italic = true     end
  130.       @char.gsub!(/<Font\[(.*?)\]>/) do name   = $1.to_s  end
  131.       @char.gsub!(/<Color(\d+),(\d+),(\d+),(\d+)>/) do
  132.         color = Color.new($1.to_i,$2.to_i,$3.to_i,$4.to_i) end
  133.     @name_event.bitmap.font.name   = name
  134.     @name_event.bitmap.font.bold   = bold
  135.     @name_event.bitmap.font.italic = italic
  136.     @name_event.bitmap.font.size   = size
  137.     @name_event.bitmap.font.color  = color
  138.   end
  139.   #--------------------------------------------------------------------------
  140.   # * Check Name
  141.   #--------------------------------------------------------------------------
  142.   def event_name_check
  143.     @char.gsub!(/<V([0-9]+)>/){ $game_variables[$1.to_i] }
  144.     @char.gsub!(/<A([0-9]+)>/){ !$game_actors[$1.to_i].nil? ?
  145.                                 $game_actors[$1.to_i].name : ''}
  146.     @char.gsub!(/<Size(\d+)>/)    {''}
  147.     @char.gsub!(/<Bold>/i)        {''}
  148.     @char.gsub!(/<Italic>/i)      {''}
  149.     @char.gsub!(/<Font\[(.*?)\]>/){''}
  150.     @char.gsub!(/<Color(\d+),(\d+),(\d+),(\d+)>/) {''}
  151.     @char.gsub!(/<Enemy(\d+)>/i) { !$data_enemies[$1.to_i].nil? ?
  152.                                     $data_enemies[$1.to_i].name : ''}
  153.     @char.gsub!(/<\[(.*?)\]>/) do @char = $1.to_s end
  154.   end
  155.   #--------------------------------------------------------------------------
  156.   # * Update
  157.   #--------------------------------------------------------------------------
  158.   def update
  159.     super
  160.     if @show_name != @character.show_name or
  161.       @character_graphic != @character.character_name
  162.       @character_graphic = @character.character_name
  163.       @show_name = @character.show_name
  164.       refresh_name
  165.     end
  166.     update_event_name
  167.     update_back
  168.   end
  169.  
  170.   #--------------------------------------------------------------------------
  171.   # * Refresh
  172.   #--------------------------------------------------------------------------
  173.   def refresh_name
  174.     return if @name_event.nil? or @name_event.bitmap.nil? or
  175.       @name_event.disposed? or !@name_event.visible or
  176.       @character.show_name.nil? or @show_name.nil?
  177.     @name_event.bitmap.clear
  178.     return if @character.character_name == ''
  179.     @show_name.each {|@char|  coloring; event_name_check  }
  180.     draw_name
  181.     conf_position
  182.   end
  183.   #--------------------------------------------------------------------------
  184.   # * Conf Position
  185.   #--------------------------------------------------------------------------
  186.   def conf_position
  187.     @x_frame, @y_frame = 4, 4
  188.     if POS == "A"
  189.       bit = cache.character(@character.character_name,
  190.           @character.character_hue)
  191.       @cw = ((bit.width / @x_frame) + @char.length)/2
  192.       @ch = bit.height / @y_frame + 15
  193.       if $xrxs_xas
  194.         @cw = ((@name_event.bitmap.width / @x_frame) + @char.length)/2
  195.         @ch = @name_event.bitmap.height / @y_frame - 5
  196.       end
  197.       @ch += 5 if USEPICT
  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.     coor = [OFFSET, 100, 20, @char ,4].flatten
  208.     if defined? Bitmap.draw_hemming_text
  209.       @name_event.bitmap.draw_hemming_text(*coor)
  210.     else
  211.       @name_event.bitmap.draw_text(*coor)
  212.     end
  213.   end
  214.   #--------------------------------------------------------------------------
  215.   # * Dispose
  216.   #--------------------------------------------------------------------------
  217.   def dispose
  218.     super
  219.     [@name_event, @back].each {|i| i.dispose if !i.nil? && !i.disposed? }
  220.   end
  221.   #--------------------------------------------------------------------------
  222.   # * Visibility
  223.   #--------------------------------------------------------------------------
  224.   def visibility
  225.     pressed = Input.press?(PRESS_BTN[0]) && Input.trigger?(PRESS_BTN[1])
  226.     if RANGE != nil && !@pressed
  227.       x = ($game_player.x-@character.x).abs+($game_player.y-@character.y).abs
  228.       @name_event.visible = (x <= RANGE)
  229.     end
  230.     if !@pressed && pressed
  231.       @name_event.visible, @pressed = false, true
  232.     elsif @pressed && pressed
  233.       @name_event.visible, @pressed = true, false
  234.     end
  235.   end  
  236.   #--------------------------------------------------------------------------
  237.   # * Update Event Name
  238.   #--------------------------------------------------------------------------
  239.   def update_event_name
  240.     return @name_event.visible = false if !DIS_EV_SWITCH.nil? and
  241.        (@character.opacity < 50 or $game_switches[DIS_EV_SWITCH])
  242.     visibility if !PRESS_BTN.nil?
  243.     if @name_event.visible
  244.       @name_event.x = @character.screen_x - (@cw.nil? ? 0 : @cw)
  245.       @name_event.y = @character.screen_y - (POS == 'A' ? @ch.nil? ? 0 : @ch : 0)
  246.  
  247.       @name_event.z = 1
  248.       @name_event.opacity    = @character.opacity
  249.       @name_event.blend_type = @character.blend_type
  250.       @name_event.bush_depth = @character.bush_depth
  251.     end
  252.   end
  253.   #--------------------------------------------------------------------------
  254.   # * Update Back
  255.   #--------------------------------------------------------------------------
  256.   def update_back
  257.     return if !USEPICT
  258.     @back.visible = @name_event.visible && !@char.nil? &&
  259.       !@char.empty? && @char != ' '
  260.     if @back.visible
  261.       @back.opacity = @name_event.opacity - 100
  262.       @back.x = @name_event.x - 5
  263.       @back.y = @name_event.y - 5
  264.       @back.z = @name_event.z - 1
  265.     end
  266.   end
  267. end
  268.  
  269. #==============================================================================
  270. # ** Game_Character
  271. #------------------------------------------------------------------------------
  272. #  This class deals with characters. It's used as a superclass for the
  273. #  Game_Player and Game_Event classes.
  274. #==============================================================================
  275. class Game_Character
  276.   #--------------------------------------------------------------------------
  277.   # * Public Instance Variables
  278.   #--------------------------------------------------------------------------
  279.   attr_accessor :show_name,:fontsize,:bold,:italic,:font,:color
  280.   #--------------------------------------------------------------------------
  281.   # * Show Name
  282.   #--------------------------------------------------------------------------
  283.   def show_name=(v= ' ')
  284.     @show_name=v
  285.     record_name
  286.   end
  287.   #--------------------------------------------------------------------------
  288.   # * Record Name
  289.   #--------------------------------------------------------------------------
  290.   def record_name
  291.     if self == $game_player
  292.       $game_system.player_name = @show_name
  293.     end
  294.   end
  295.   #--------------------------------------------------------------------------
  296.   # * Load Name
  297.   #--------------------------------------------------------------------------
  298.   def load_name
  299.     if self == $game_player
  300.       if !$game_system.player_name.nil?
  301.         @show_name = $game_system.player_name
  302.       end
  303.     end
  304.   end
  305.   #--------------------------------------------------------------------------
  306.   # * Clear Name
  307.   #--------------------------------------------------------------------------
  308.   def clear_name
  309.     @show_name = ' '
  310.     if self == $game_player
  311.       $game_system.player_name = @show_name
  312.     end
  313.   end
  314.   #--------------------------------------------------------------------------
  315.   # * Clear every Name
  316.   #--------------------------------------------------------------------------
  317.   def clear_every_name
  318.     $game_system.record_name = {}
  319.     $game_system.player_name = nil
  320.   end
  321. end
  322.  
  323. #==============================================================================
  324. # ** Game_Event
  325. #------------------------------------------------------------------------------
  326. #  This class deals with events. It handles functions including event page
  327. #  switching via condition determinants, and running parallel process events.
  328. #  It's used within the Game_Map class.
  329. #==============================================================================
  330. class Game_Event < Game_Character
  331.   #--------------------------------------------------------------------------
  332.   # * Alias listing
  333.   #--------------------------------------------------------------------------
  334.   alias erase_show_name erase
  335.   alias init_event_name initialize
  336.   #--------------------------------------------------------------------------
  337.   # * Public Instance Variables
  338.   #--------------------------------------------------------------------------
  339.   attr_reader   :event
  340.   #--------------------------------------------------------------------------
  341.   # * Object Initialization
  342.   #--------------------------------------------------------------------------
  343.   def initialize(map_id, event)
  344.     if event.name =~ /<Name=(.*?)>/i
  345.       @show_name = $1.to_s
  346.     end
  347.     if event.name =~ /<Size(\d+)>/i
  348.       @fontsize = $1.to_i
  349.     end
  350.     @bold   = event.name =~ /<Bold>/i
  351.     @italic = event.name =~ /<Italic>/i
  352.     if event.name =~ /<Font\[(.*?)\]>/i
  353.       @font = $1.to_s
  354.     end
  355.     if event.name =~ /<Color(\d+),(\d+),(\d+),(\d+)>/
  356.       @color = Color.new($1.to_i,$2.to_i,$3.to_i,$4.to_i)
  357.     end
  358.     init_event_name(map_id, event)
  359.   end
  360.   #--------------------------------------------------------------------------
  361.   # * Record Name
  362.   #--------------------------------------------------------------------------
  363.   def record_name
  364.     key = [@map_id, @event.id]
  365.     clear_every_name if  $game_system.record_name.nil?
  366.     $game_system.record_name[key]=[@show_name]
  367.   end
  368.   #--------------------------------------------------------------------------
  369.   # * Load Name
  370.   #--------------------------------------------------------------------------
  371.   def load_name
  372.     key = [@map_id, @event.id]
  373.     clear_every_name if  $game_system.record_name.nil?
  374.     if $game_system.record_name[key] != nil
  375.       @show_name=$game_system.record_name[key][0]
  376.     end
  377.   end
  378.   #--------------------------------------------------------------------------
  379.   # * Clear Name
  380.   #--------------------------------------------------------------------------
  381.   def clear_name
  382.     super
  383.     key = [@map_id, @event.id]
  384.     if $game_system.record_name[key] != nil
  385.       $game_system.record_name[key] = nil
  386.     end
  387.   end
  388.   #--------------------------------------------------------------------------
  389.   # * Temporarily Erase
  390.   #--------------------------------------------------------------------------
  391.   def erase
  392.     clear_name
  393.     erase_show_name
  394.   end
  395. end
  396.  
  397. #==============================================================================
  398. # ** Game_Map
  399. #------------------------------------------------------------------------------
  400. #  This class handles the map. It includes scrolling and passable determining
  401. #  functions. Refer to "$game_map" for the instance of this class.
  402. #==============================================================================
  403. class Game_Map
  404.   #--------------------------------------------------------------------------
  405.   # * Alias listing
  406.   #--------------------------------------------------------------------------
  407.   alias setup_record setup
  408.   #--------------------------------------------------------------------------
  409.   # * Setup
  410.   #     map_id : map ID
  411.   #--------------------------------------------------------------------------
  412.   def setup(map_id)
  413.     setup_record (map_id)
  414.     @map.events.keys.each {|i| @events[i].load_name if !events[i].nil?}
  415.   end
  416. end
  417.  
  418. #==============================================================================
  419. # ** Game_System
  420. #------------------------------------------------------------------------------
  421. #  This class handles data surrounding the system. Backround music, etc.
  422. #  is managed here as well. Refer to "$game_system" for the instance of
  423. #  this class.
  424. #==============================================================================
  425. class Game_System
  426.   #--------------------------------------------------------------------------
  427.   # * Public Instance Variables
  428.   #--------------------------------------------------------------------------
  429.   attr_accessor :player_name, :record_name
  430. end
  431.  
  432. #==============================================================================
  433. # ** Spriteset_Map
  434. #------------------------------------------------------------------------------
  435. #  This class brings together map screen sprites, tilemaps, etc. It's used
  436. # within the Scene_Map class.
  437. #==============================================================================
  438. class Spriteset_Map
  439.  
  440.   PRESS_BTN     = EventName::PRESS_BTN
  441.   #--------------------------------------------------------------------------
  442.   # * Public Instance Variables
  443.   #--------------------------------------------------------------------------
  444.   attr_accessor :eventname
  445.   #--------------------------------------------------------------------------
  446.   # * Main Processing
  447.   #--------------------------------------------------------------------------
  448.   def init_eventname
  449.     @eventname = []
  450.     @eventname[0] = Sprite_EventName.new(@viewport1,$game_player)  
  451.     ($game_map.events.keys.sort).each {|i|
  452.       next if $game_map.events[i].character_name == ''
  453.       @eventname[i] = Sprite_EventName.new(@viewport1,$game_map.events[i])}
  454.   end
  455.   #--------------------------------------------------------------------------
  456.   # * Frame Update
  457.   #--------------------------------------------------------------------------
  458.   alias update_eventname_earlier update
  459.   def update
  460.     @eventname.nil? ? init_eventname : @eventname.each {|i|i.update if !i.nil?}
  461.     update_eventname_earlier
  462.   end  
  463.   #--------------------------------------------------------------------------
  464.   # * Dispose
  465.   #--------------------------------------------------------------------------
  466.   alias dispose_eventname dispose
  467.   def dispose
  468.     @eventname.each {|i| i.dispose if !i.nil?}
  469.     dispose_eventname
  470.   end
  471. end
  472. end
  473. #--------------------------------------------------------------------------
  474. # END OF SCRIPT
  475. #--------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement