View difference between Paste ID: UxpRn8jP and 9aFk56z7
SHOW: | | - or go back to the newest paste.
1
=begin
2
3
-----------------------------------------------------------------------
4-
   Event Popups  (v.1.0)
4+
   Map 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
 3) To automatically get an Armor/Weapon/Item/Skill icon-name,
22
    use :
23
    icon = get_icon_name(type, id)
24
     
25
    where type is either:
26
    'Armor' or 'Weapon' or 'Item' or 'Skill'
27
    and id is the number of the armor/item/etc
28
    
29
   Notes:
30
   *  To show only an icon, set the text to "" 
31
   ** The icon-name should not include ".png", ".jpg" etc.
32
      Please use "my_icon" instead of "my_icon.png"
33
-----------------------------------------------------------------------     
34
=end
35
36
class Sprite_Character < RPG::Sprite
37
  
38
  POPUP_DURATION = 50
39
  
40
  def show_icon(icon_name)
41
    @icon_bitmap = RPG::Cache.icon(icon_name)
42
    rect = Rect.new(0, 0, 24, 24) 
43
    opacity = 255
44
    x = 0 
45
    y = 0
46
    self.bitmap.blt(x, y, @icon_bitmap, rect, opacity)
47
  end
48
  
49
  alias popup_damage damage
50
  def damage(dmg, critical)
51
    popup_damage(dmg, critical)
52
    if $scene.is_a?(Scene_Map)
53
      @_damage_duration = POPUP_DURATION
54
    end
55
  end
56
  
57
  def update_popup
58
    return unless @_damage_duration > 0
59
    if @_damage_duration == 1
60
      self.bitmap.dispose
61
      char_name = @character.character_name
62
      char_hue = @character.character_hue
63
      self.bitmap = RPG::Cache.character(char_name, char_hue)
64
      @cw = bitmap.width / 4
65
      @ch = bitmap.height / 4
66
      self.ox = @cw / 2
67
      self.oy = @ch
68
      sx = @character.pattern * @cw
69
      sy = (@character.direction - 2) / 2 * @ch
70
      self.src_rect.set(sx, sy, @cw, @ch)
71
    end
72
  end
73
  
74
end
75
76
class Interpreter
77
  
78
  def popup(text, icon=nil)
79
    return unless $scene.is_a?(Scene_Map)
80
    $scene.spriteset.popup(@event_id, text, icon)
81
  end
82
  
83
  def get_icon_name(type, id)
84
    case type
85
    when 'Armor'
86
      legal = id < $data_armors.size
87
    when 'Item'
88
      legal = id < $data_items.size
89
    when 'Weapon'
90
      legal = id < $data_weapons.size
91
    when 'Skill'
92
      legal = id < $data_skills.size
93
    else
94
    end
95
    legal = legal && id > 0
96
    return "" if !legal
97
    case type
98
    when 'Armor'
99
      return $data_armors[id].icon_name
100
    when 'Item'
101
      return $data_items[id].icon_name
102
    when 'Weapon'
103
      return $data_weapons[id].icon_name
104
    when 'Skill'
105
      return $data_skills[id].icon_name
106
    else
107
      return ""
108
    end
109
  end
110
  
111
end
112
113
class Scene_Map
114
  attr_reader   :spriteset
115
end
116
117
class Spriteset_Map
118
  
119
  def popup(event_id, text, icon=nil)
120
    for char_sprite in @character_sprites
121
      if char_sprite.character.id == event_id
122
        char_sprite.damage(text, false)
123
        char_sprite.show_icon(icon) unless icon.nil?
124
        return
125
      end
126
    end
127
  end
128
  
129
  alias popup_update update
130
  def update
131
    popup_update
132
    for char_sprite in @character_sprites
133
      char_sprite.update_popup
134
    end
135
    
136
  end
137
  
138
  
139
end