Galv’s Event Pop Ups V.1.1

Demo – Version 1.1 >

#-------------------------------------------------------------------------------
#  Galv's Event Pop-Ups
#-------------------------------------------------------------------------------
#  For: RPGMAKER VX ACE
#  Version 1.1
#------------------------------------------------------------------------------#
#  2013-03-03 - Version 1.1 - crash fix
#  2013-02-24 - Version 1.1 - release
#------------------------------------------------------------------------------#
#  Just another pop up script, nothing special here other than I made it (which
#  could be less special! haha). Manually create a text pop up or automatically 
#  whenever you give the player an item via event command - pops up the item's
#  icon above their head with amount gained.
#------------------------------------------------------------------------------#
#  SCRIPT CALL to manually call the pop up
#------------------------------------------------------------------------------#
#
#  popup(target,type,id,amount)
#
#  # target = event id you want popup to appear on. 0 is for player
#  # type = :item, :armor, :weapon or "Other Text"
#  # id = the item, armor or weapon id OR icon id if using "Other Text"
#  # amount = how many of item you wish to display are being gained or lost
#
#------------------------------------------------------------------------------#
#  EXAMPLES:
#  popup(0," Skulls",1,5)  # '5 x Skulls' with icon 1 above player
#  popup(2,"Hello  ",0,0)  # 'Hello' with no icon above event 2
#  popup(4,:item,1,-10)    # -10 Potions (with icon) above event 4
#
#  NOTE: The Gain item, weapon, armor and gold event commands automatically pop
#        up with the item gained/lost. Only one pop up can be active at a time.
#------------------------------------------------------------------------------#

($imported ||= {})["Galv_Map_Popups"] = true
module Galv_Mpop

#------------------------------------------------------------------------------#  
#  SETUP OPTIONS
#------------------------------------------------------------------------------#

  DISABLE_SWITCH = 1  # Turn swith ON to disable this.
  
  
  SE_GAIN = ["Item1",100,100]   # "SE_Name",volume,pitch when gaining item
  SE_LOSE = ["Miss",100,100]    # "SE_Name",volume,pitch when losing item
  
  # These sounds only play with the add or remove items event command. Custom
  # item pop up won't display a sound so you can play your own.


  Y_OFFSET = -50                # Y offset for popup text
  
  CURRENCY_ICON  = 361          # Icon that appears when gaining/losing money
  
  FONT = "Arial"                # Font used for pop ups
  GAIN_COLOR = [255,255,255]    # RGB colour for gaining item text
  LOSE_COLOR = [255,200,200]    # RGB colour for losing item text
  
#------------------------------------------------------------------------------#  
#  END SETUP OPTIONS
#------------------------------------------------------------------------------#

end


class Game_Map
  alias galv_map_pop_gp_initialize initialize
  def initialize
    galv_map_pop_gp_initialize
  end
  
  alias galv_map_pop_gp_update update
  def update(main = false)
    update_popup if @popsprite
    galv_map_pop_gp_update(main)
  end
  
  def update_popup
    @popsprite.update
  end
  
  def dispose_popup
    @popsprite.dispose if @popsprite
    @popsprite = nil
  end
  
  def popup(target,item_type,item_id,amount)
    @popsprite.dispose if @popsprite
    character = get_ptarget(target)
    item = get_pitem(item_type,item_id)
    @popsprite = Sprite_PopText.new(@viewport1,character,item,amount)
  end
  
  def get_ptarget(target)
    if target == 0; return $game_player
    elsif target > 0; return $game_map.events[target]
    end
  end
  
  def get_pitem(item_type,item_id)
    case item_type
    when :item;   $data_items[item_id]
    when :weapon; $data_weapons[item_id]
    when :armor;  $data_armors[item_id]
    else; [item_type.to_s,item_id]
    end
  end
  
end # Game_Player < Game_Character


class Scene_Map < Scene_Base
  def dispose_spriteset
    @spriteset.dispose
    $game_map.dispose_popup
  end
end

class Sprite_PopText < Sprite
  def initialize(viewport,target,item,amount)
    super(viewport)
    @character = target
    @item = item
    @rise = 0
    @rise_speed = 15
    @amount = amount
    create_bitmap
    update
  end

  def dispose
    self.bitmap.dispose
    if @icon_sprite
      @icon_sprite.bitmap.dispose
      @icon_sprite.dispose
    end
    super
  end

  def create_bitmap
    if @item
      @icon_sprite = Sprite.new
      @icon_sprite.bitmap = Cache.system("Iconset")
    end
    @x_offset = -92
    self.bitmap = Bitmap.new(200, 20)
    self.bitmap.font.size = 20
    self.bitmap.font.name = Galv_Mpop::FONT
    self.bitmap.font.shadow = 20
    self.bitmap.font.bold = true
    if @amount >= 0
      self.bitmap.font.color.set(
      Galv_Mpop::GAIN_COLOR[0],Galv_Mpop::GAIN_COLOR[1],Galv_Mpop::GAIN_COLOR[2])
    else
      self.bitmap.font.color.set(
      Galv_Mpop::LOSE_COLOR[0],Galv_Mpop::LOSE_COLOR[1],Galv_Mpop::LOSE_COLOR[2])
    end
    self.z = 2
  end

  def update
    super
    update_position
    update_bitmap
    update_visibility
    update_icon if @icon_sprite
    end_popup
  end

  def end_popup
    return $game_map.dispose_popup if @rise >= 280
  end

  def name_text
    if @item.is_a?(Array)
      amount = @amount > 1 || @amount < -1 ? @amount.to_s : ""
      return amount + @item[0].to_s
    elsif @item
      amount = @amount != 0 ? @amount.to_s : ""
      return @amount >= 1 ? "x" + amount : amount
    else
      return ""
    end
  end
  
  def update_bitmap
    @rise += 1
    self.bitmap.clear
    self.bitmap.draw_text(self.bitmap.rect, name_text, 1)
    if @item && @item.is_a?(Array)
      self.draw_icon(@item[1])
    elsif @item
      self.draw_icon(@item.icon_index)
    end
  end
  
  def draw_icon(icon_index)
    rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
    @icon_sprite.src_rect = rect
    @icon = icon_index
  end
  
  def calculate_y
    if @rise_speed > 0
      @rise_speed -= 1
      return -(@rise * @rise_speed * 0.2)
    else
      return 0
    end
  end

  def update_position
    self.x = @character.screen_x + @x_offset
    if @amount >= 0
      self.y = @character.screen_y + Galv_Mpop::Y_OFFSET + calculate_y
    else
      self.y = @character.screen_y + Galv_Mpop::Y_OFFSET - 10 + @rise * 0.2
    end
  end

  def update_icon
    @icon_sprite.x = @character.screen_x - name_text.length * 4 - 20
    @icon_sprite.y = self.y - 2
    @icon_sprite.opacity = self.opacity
  end
  
  def update_visibility
    self.opacity = 500 + (name_text.length * 20) - @rise * 6
  end
end # Sprite_PopText < Sprite


class Game_Interpreter
  
  def psound(amount)
    if amount > 0
      RPG::SE.new(Galv_Mpop::SE_GAIN[0],Galv_Mpop::SE_GAIN[1],Galv_Mpop::SE_GAIN[2]).play
    elsif amount < 0
      RPG::SE.new(Galv_Mpop::SE_LOSE[0],Galv_Mpop::SE_LOSE[1],Galv_Mpop::SE_LOSE[2]).play
    end
  end
  
  alias galv_map_pop_gi_command_125 command_125
  def command_125
    difference = $game_party.gold
    galv_map_pop_gi_command_125
    amount = $game_party.gold - difference
    return if amount == 0 || $game_switches[Galv_Mpop::DISABLE_SWITCH]
    psound(amount)
    $game_map.popup(0,"",Galv_Mpop::CURRENCY_ICON,amount)
  end

  alias galv_map_pop_gi_command_126 command_126
  def command_126
    difference = $game_party.item_number($data_items[@params[0]])
    galv_map_pop_gi_command_126
    amount = $game_party.item_number($data_items[@params[0]]) - difference
    return if amount == 0 || $game_switches[Galv_Mpop::DISABLE_SWITCH]
    psound(amount)
    $game_map.popup(0,:item,@params[0],amount)
  end
  
  alias galv_map_pop_gi_command_127 command_127
  def command_127
    difference = $game_party.item_number($data_weapons[@params[0]])
    galv_map_pop_gi_command_127
    amount = $game_party.item_number($data_weapons[@params[0]]) - difference
    return if amount == 0 || $game_switches[Galv_Mpop::DISABLE_SWITCH]
    psound(amount)
    $game_map.popup(0,:weapon,@params[0],amount)
  end
  
  alias galv_map_pop_gi_command_128 command_128
  def command_128
    difference = $game_party.item_number($data_armors[@params[0]])
    galv_map_pop_gi_command_128
    amount = $game_party.item_number($data_armors[@params[0]]) - difference
    return if amount == 0 || $game_switches[Galv_Mpop::DISABLE_SWITCH]
    psound(amount)
    $game_map.popup(0,:armor,@params[0],amount)
  end
  
  def popup(target,item_type,item_id,amount)
    $game_map.popup(target,item_type,item_id,amount)
  end
end # Game_Interpreter
Advertisements

18 thoughts on “Galv’s Event Pop Ups V.1.1

  1. Romain38 says:

    Hello,
    Firstly, bravo for your job!!

    I have changed resolution of my game to 640*480, and there is a gap of all POP ups.
    How i do to adjust, suitably, your script to work with this resolution ( script as Yanfly ace core engine )

    Sorry for my bad english, i’m french
    Thanks

    • Galv says:

      Hmm, you are right. This only happens if you are using a map smaller than the screen size. I recommend making the minimum size of your maps to fit the screen size.

    • Magno says:

      Create a new entry in the script list before Main, and add this text to it:

      class Sprite_PopText
      alias :old_update_position :update_position
      def update_position
      old_update_position
      if Graphics.width > $game_map.width * 32 && !$game_map.loop_horizontal?
      self.x += (Graphics.width – $game_map.width * 32) / 2
      end

      if Graphics.height > $game_map.height * 32 && !$game_map.loop_vertical?
      self.y += (Graphics.height – $game_map.height * 32) / 2
      end
      end
      end

  2. Johnny says:

    Hey Galv,

    This is a great script!

    But i’m getting the following error after using this script:

    After picking up an item (with a gain of variable), my text window becomes a little out of position:

    What could be the problem?

    Thanks!

  3. Galv says:

    This script doesn’t do anything with text windows… but Yanfly’s Message script uses a variable to determine how high message windows are. I am guessing you are using his message script and changing the variable that is set in his script settings.

  4. Johnny says:

    Hey thanks for pointing that out!

    I got it fixed now!

  5. Melkor says:

    Hi Galv

    Great script works really well!
    I was wondering is there a way to deactivate the popups on certain events?
    e.g A note tag or script call to have no popups when receiving item/weapon/armour on a certain event?

    I have a scenario where a switch activates when a certain item (an invisible item made just for the switch) is received but I don’t want it to pop up as I wish to keep it somewhat invisible.

    Is there a way to do this?
    Thanks in advance.

  6. Ellen says:

    Hi Galv, this is exactly what I need!
    Weird question…but do these pop-up messages appear even when the screen is faded out?
    Thanks!

  7. Ellen says:

    Oh, okay. I guess I’ll just try it out and see…

  8. Trace says:

    Hi Galv . . .
    is it a bug ?
    i can’t use this script with your random loot script, even with the fresh project . . .
    there is no pop up when using it with your random loot script

  9. Rotem says:

    Great script, I was wondering if I could set how much time the pop up will display and poof.
    I think it pops and poof’s too fast..

  10. Rotem says:

    Great script, I was wondering if you could do an option for the text to dissapear after people click on enter ?

    • Galv says:

      Unfortunately the script is very basic. I don’t have time to do improvements on it anytime soon, sorry. You could try asking in a forum or see if there are any other pop up scripts available :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s