Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =begin
- -----------------------------------------------------------------------
- Map Popups (v.1.0)
- made by: Silverwind (Metaclaw)
- -----------------------------------------------------------------------
- Instructions:
- 1) To show some text above an event, add a script command, saying:
- text = "place your text here"
- popup(text)
- 2) To show an icon in the popup, add a script command, saying:
- text = "place your text here" *
- icon = "the icon's name" **
- popup(text, icon)
- 3) To automatically get an Armor/Weapon/Item/Skill icon-name,
- use :
- icon = get_icon_name(type, id)
- where type is either:
- 'Armor' or 'Weapon' or 'Item' or 'Skill'
- and id is the number of the armor/item/etc
- Notes:
- * To show only an icon, set the text to ""
- ** The icon-name should not include ".png", ".jpg" etc.
- Please use "my_icon" instead of "my_icon.png"
- -----------------------------------------------------------------------
- =end
- class Sprite_Character < RPG::Sprite
- POPUP_DURATION = 50
- def show_icon(icon_name)
- @icon_bitmap = RPG::Cache.icon(icon_name)
- rect = Rect.new(0, 0, 24, 24)
- opacity = 255
- x = 0
- y = 0
- self.bitmap.blt(x, y, @icon_bitmap, rect, opacity)
- end
- alias popup_damage damage
- def damage(dmg, critical)
- popup_damage(dmg, critical)
- if $scene.is_a?(Scene_Map)
- @_damage_duration = POPUP_DURATION
- end
- end
- def update_popup
- return unless @_damage_duration > 0
- if @_damage_duration == 1
- self.bitmap.dispose
- char_name = @character.character_name
- char_hue = @character.character_hue
- self.bitmap = RPG::Cache.character(char_name, char_hue)
- @cw = bitmap.width / 4
- @ch = bitmap.height / 4
- self.ox = @cw / 2
- self.oy = @ch
- sx = @character.pattern * @cw
- sy = (@character.direction - 2) / 2 * @ch
- self.src_rect.set(sx, sy, @cw, @ch)
- end
- end
- end
- class Interpreter
- def popup(text, icon=nil)
- return unless $scene.is_a?(Scene_Map)
- $scene.spriteset.popup(@event_id, text, icon)
- end
- def get_icon_name(type, id)
- case type
- when 'Armor'
- legal = id < $data_armors.size
- when 'Item'
- legal = id < $data_items.size
- when 'Weapon'
- legal = id < $data_weapons.size
- when 'Skill'
- legal = id < $data_skills.size
- else
- end
- legal = legal && id > 0
- return "" if !legal
- case type
- when 'Armor'
- return $data_armors[id].icon_name
- when 'Item'
- return $data_items[id].icon_name
- when 'Weapon'
- return $data_weapons[id].icon_name
- when 'Skill'
- return $data_skills[id].icon_name
- else
- return ""
- end
- end
- end
- class Scene_Map
- attr_reader :spriteset
- end
- class Spriteset_Map
- def popup(event_id, text, icon=nil)
- for char_sprite in @character_sprites
- if char_sprite.character.id == event_id
- char_sprite.damage(text, false)
- char_sprite.show_icon(icon) unless icon.nil?
- return
- end
- end
- end
- alias popup_update update
- def update
- popup_update
- for char_sprite in @character_sprites
- char_sprite.update_popup
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment