Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================
- # ** Event Popups
- #------------------------------------------------------------------------------
- # made by: Silverwind (Metaclaw from GDU forums)
- # version: 2.0
- #
- # you have my permission to use this in comercial games.
- # please credit me if you use this script.
- #==============================================================================
- =begin
- 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 the icon of an Armor, Item, or Weapon
- replace the line saying 'icon = something', with:
- icon = get_icon(item_type, item_number) ***
- ie:
- icon = get_icon('Armor', 2)
- 4) You can draw two lines of text, by using:
- line1 = "Headline"
- line2 = "some text"
- icon = "icon name"
- popup(line1, icon, line2)
- the 2nd line will have smaller font and a white color.
- it will be displayed above the first.
- if you don't want an icon, set it to: nil
- 5) To set the font size, color and the window opacity
- as well as the time the popup stays on the screen,
- see line 95 and below.
- Notes:
- * To show only an icon, set the text to ""
- ** The icon-name should not include ".png", ".jpg" etc.
- *** You can also use 'skill' and a skill number.
- =end
- class Window_Base < Window
- # edited this method,
- # to not re-set the window skin to default.
- def update
- super
- end
- end
- class Interpreter
- def popup(text, icon=nil, line2=nil)
- return unless $scene.is_a?(Scene_Map)
- $scene.spriteset.popup(@event_id, text, icon, line2)
- end
- def get_icon(type, id)
- case type
- when 'Armor', 'armor'
- return $data_armors[id].icon_name
- when 'Item', 'item'
- return $data_items[id].icon_name
- when 'Skill', 'skill'
- return $data_skills[id].icon_name
- when 'Weapon', 'weapon'
- return $data_weapons[id].icon_name
- else
- return nil
- end
- end
- end
- class Window_Popup < Window_Base
- FONT = "Arial Black" # the font name
- OPACITY = 160 # window opacity. set to 0 to make it invisible
- DURATION = 100 # duration, in frames.
- FONT_SIZE = 32 # font size for the first text line
- FONT_SMALL_SIZE = 22 # font size for the second text line
- FONT_COLOR = [80,120,220] # for colors, use: [red, green, blue]
- WINDOWSKIN = "001-Blue01" # windowskin name.
- LINE_HEIGHT = 32 # change this value is your text is too big
- # for the popup / or the popup size is too big.
- POPUP_X = 200 # set where the popup shows. set it to -1
- POPUP_Y = 100 # , to draw it above the event.
- def initialize(char_sprite, width2, height2)
- x = char_sprite.x
- y = char_sprite.y
- y -= (char_sprite.bitmap.height / 4)
- is_tile = (char_sprite.character.tile_id != 0 )
- w = [width2 + 32, 640].min
- h = height2
- x -= w / 2
- y -= h - 16
- x = POPUP_X if POPUP_X > 0
- y = POPUP_Y if POPUP_Y > 0
- super(x,y,w,h)
- @windowskin_name = WINDOWSKIN
- self.windowskin = RPG::Cache.windowskin(@windowskin_name)
- self.contents = Bitmap.new(width - 32, height - 32)
- self.opacity = OPACITY
- self.back_opacity = OPACITY
- @countdown = DURATION
- end
- def draw_popup_text(text, text2=nil)
- x = 0
- y = -16
- w = 160
- h = 64
- w1 = self.contents.text_size(text).width
- unless text2.nil?
- w2 = self.contents.text_size(text2).width
- w = [w1, w2].max
- else
- w = w1
- end
- w = [w, width].min
- self.contents.font.name = FONT
- # draw the headline
- self.contents.font.size = FONT_SIZE
- self.contents.font.color.set(0,0,0)
- self.contents.draw_text(x-1, y-1, w, h, text, 1)
- self.contents.draw_text(x+1, y-1, w, h, text, 1)
- self.contents.draw_text(x-1, y+1, w, h, text, 1)
- self.contents.draw_text(x+1, y+1, w, h, text, 1)
- r = FONT_COLOR[0]
- g = FONT_COLOR[1]
- b = FONT_COLOR[2]
- self.contents.font.color.set(r,g,b)
- self.contents.draw_text(x, y, w, h, text, 1)
- # draw the second line
- return if text2.nil?
- y += 24
- self.contents.font.size = FONT_SMALL_SIZE
- self.contents.font.color.set(0,0,0)
- self.contents.draw_text(x-1, y-1, w, h, text2, 1)
- self.contents.draw_text(x+1, y-1, w, h, text2, 1)
- self.contents.draw_text(x-1, y+1, w, h, text2, 1)
- self.contents.draw_text(x+1, y+1, w, h, text2, 1)
- self.contents.font.color.set(r,g,b)
- self.contents.draw_text(x, y , w, h, text2, 1)
- end
- def draw_icon(icon_name)
- bitmap = RPG::Cache.icon(icon_name)
- opacity = 255
- x = (width / 2) - 24 - 6
- lines = height / LINE_HEIGHT
- y = LINE_HEIGHT * (lines - 2)
- self.contents.blt(x, y, bitmap, Rect.new(0, 0, 24, 24), opacity)
- end
- alias popup_update update
- def update
- popup_update
- @countdown -= 1 if @countdown > 0
- if @countdown < 30
- self.contents_opacity = self.contents_opacity - 20
- end
- end
- def hide?
- return @countdown == 0
- end
- end
- class Scene_Map
- attr_reader :spriteset
- end
- class Spriteset_Map
- #------------------------------------------------------#
- # > show a popup above the specified event,
- # with the specified text, and the icon (if any).
- # showing a second line of text is optional.
- #------------------------------------------------------#
- def popup(event_id, text, icon=nil, line2=nil)
- for char_sprite in @character_sprites
- if char_sprite.character.id == event_id
- show_popup_box(text, line2, char_sprite, icon)
- return
- end
- end
- end
- def show_popup_box(text, text2, char_sprite, icon)
- bit = Bitmap.new(1,1)
- w1 = bit.text_size(text).width
- unless text2.nil?
- w2 = bit.text_size(text2).width
- w = [w1, w2].max
- else
- w = w1
- end
- bit.dispose
- w = [w, 640].min
- w = [w, 64].max
- lines = 0
- lines += 1 unless text == ""
- lines += 1 unless text2.nil?
- lines += 1 unless icon.nil?
- lines = [lines, 1].max
- line_h = Window_Popup::LINE_HEIGHT
- h = (lines+1) * line_h
- @popups = [] if @popups.nil?
- popup = Window_Popup.new(char_sprite, w, h)
- popup.draw_popup_text(text, text2)
- unless icon.nil?
- popup.draw_icon(icon)
- end
- @popups.push(popup)
- end
- alias popup_icon_update update
- def update
- popup_icon_update
- if !@popups.nil?
- for pop in @popups
- pop.update
- pop.dispose if pop.hide?
- end
- @popups.delete_if {|pop| pop.disposed? }
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment