Guest User

Event Popups (RMXP)

a guest
Feb 20th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.41 KB | None | 0 0
  1. =begin
  2.  
  3. -----------------------------------------------------------------------
  4.    Event Popups  (v.1.0)
  5.  
  6.    made by: Silverwind (Metaclaw)
  7. -----------------------------------------------------------------------
  8.  
  9.  
  10.  Instructions:
  11.  
  12.  1) To show some text above an event, add a script command, saying:
  13.     text = "place your text here"
  14.     popup(text)
  15.    
  16.  2) To show an icon in the popup, add a script command, saying:
  17.     text = "place your text here" *
  18.     icon = "the icon's name" **
  19.     popup(text, icon)
  20.    
  21.    Notes:
  22.    *  To show only an icon, set the text to ""
  23.    ** The icon-name should not include ".png", ".jpg" etc.
  24.       Please use "my_icon" instead of "my_icon.png"
  25. -----------------------------------------------------------------------    
  26. =end
  27.  
  28. class Sprite_Character < RPG::Sprite
  29.  
  30.   POPUP_DURATION = 50
  31.  
  32.   def show_icon(icon_name)
  33.     @icon_bitmap = RPG::Cache.icon(icon_name)
  34.     rect = Rect.new(0, 0, 24, 24)
  35.     opacity = 255
  36.     x = 0
  37.     y = 0
  38.     self.bitmap.blt(x, y, @icon_bitmap, rect, opacity)
  39.   end
  40.  
  41.   alias popup_damage damage
  42.   def damage(dmg, critical)
  43.     popup_damage(dmg, critical)
  44.     if $scene.is_a?(Scene_Map)
  45.       @_damage_duration = POPUP_DURATION
  46.     end
  47.   end
  48.  
  49.   def update_popup
  50.     return unless @_damage_duration > 0
  51.     if @_damage_duration == 1
  52.       self.bitmap.dispose
  53.       char_name = @character.character_name
  54.       char_hue = @character.character_hue
  55.       self.bitmap = RPG::Cache.character(char_name, char_hue)
  56.       @cw = bitmap.width / 4
  57.       @ch = bitmap.height / 4
  58.       self.ox = @cw / 2
  59.       self.oy = @ch
  60.       sx = @character.pattern * @cw
  61.       sy = (@character.direction - 2) / 2 * @ch
  62.       self.src_rect.set(sx, sy, @cw, @ch)
  63.     end
  64.   end
  65.  
  66. end
  67.  
  68. class Interpreter
  69.  
  70.   def popup(text, icon=nil)
  71.     return unless $scene.is_a?(Scene_Map)
  72.     $scene.spriteset.popup(@event_id, text, icon)
  73.   end
  74.  
  75. end
  76.  
  77. class Scene_Map
  78.   attr_reader   :spriteset
  79. end
  80.  
  81. class Spriteset_Map
  82.  
  83.   def popup(event_id, text, icon=nil)
  84.     for char_sprite in @character_sprites
  85.       if char_sprite.character.id == event_id
  86.         char_sprite.damage(text, false)
  87.         char_sprite.show_icon(icon) unless icon.nil?
  88.         return
  89.       end
  90.     end
  91.   end
  92.  
  93.   alias popup_update update
  94.   def update
  95.     popup_update
  96.     for char_sprite in @character_sprites
  97.       char_sprite.update_popup
  98.     end
  99.   end
  100.  
  101. end
Advertisement
Add Comment
Please, Sign In to add comment