Advertisement
Zouzaka

V.M. modified

Apr 4th, 2014
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.34 KB | None | 0 0
  1. #Sleek Item Popup v1.12
  2. #----------#
  3. #Features: A nice and sleek little pop up you can use to tell the player
  4. #           they received (or lost) an item! Now with automatic popups whenever
  5. #           you use the gain item commands in events!
  6. #
  7. #Usage:   Event Script Call:
  8. #           popup(type,item,amount,[duration],[xoff],[yoff])
  9. #
  10. #          Where: type is category of item (0 = item, 1 = weapon,
  11. #                                            2 = armor, 3 = gold, 4 = Exp)
  12. #                 item is the id number of the item
  13. #                 amount is the amount lost or gained
  14. #                 duration is the time the window is up and is optional
  15. #          
  16. #          Examples:
  17. #            popup(0,1,5)
  18. #            popup(2,12,1,120)
  19. #            $PU_AUTOMATIC_POPUP = false
  20. #            $PU_AUTOMATIC_POPUP = true
  21. #        
  22. #Customization: Everything down there under customization
  23. #
  24. #----------#
  25. #-- Script by: V.M of D.T
  26. #
  27. #- Questions or comments can be:
  28. #    posted on the thread for the script
  29. #    given by email: sumptuaryspade@live.ca
  30. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  31. #    posed on site: daimonioustails.wordpress.com
  32. #
  33. #--- Free to use in any project, commercial or non-commercial, with credit given
  34. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  35.  
  36. #Sound effect played on popup: # "Filename", Volume(0-100), Pitch(50-150)
  37. PU_SOUND_EFFECT_GAIN = ["Item3",100,50]
  38. PU_SOUND_EFFECT_LOSE = ["Item3",100,50]
  39.  
  40. #Animation to be played on the player during popup
  41. PU_USE_ANIMATION = false
  42. PU_POPUP_ANIMATION = 2
  43.  
  44. #Duration in frames of Item Popup fadein and fadeout
  45. PU_FADEIN_TIME = 30
  46. PU_FADEOUT_TIME = 30
  47.  
  48. #Default duration of the popup
  49. PU_DEFAULT_DURATION = 90
  50.  
  51. #Use automatic popup? Can be enabled/disabled in game, see examples
  52. $PU_AUTOMATIC_POPUP = true
  53.  
  54. #Whether to use a custom or default font
  55. PU_USE_CUSTOM_FONT = false
  56.  
  57. #Settings for custom item popup font
  58. PU_DEFAULT_FONT_NAME = ["Verdana"]
  59. PU_DEFAULT_FONT_SIZE = 16
  60. PU_DEFAULT_FONT_COLOR = Color.new(255,255,255,255)
  61. PU_DEFAULT_FONT_BOLD = false
  62. PU_DEFAULT_FONT_ITALIC = false
  63. PU_DEFAULT_FONT_SHADOW = false
  64. PU_DEFAULT_FONT_OUTLINE = true
  65.  
  66. #Compact mode will hide the amount unless it's greater then 1
  67. PU_COMPACT_MODE = true
  68.  
  69. #Background Icon to be displayed under item icon
  70. PU_USE_BACKGROUND_ICON = true
  71. PU_BACKGROUND_ICON = 102
  72.  
  73. #Gold details:
  74. PU_GOLD_NAME = "Gold"
  75. PU_GOLD_ICON = 262
  76.  
  77. #True for single line, false for multi line
  78. PU_SINGLE_LINE = true
  79.  
  80. class Item_Popup < Window_Base
  81.   def initialize(item, amount, duration, nosound,xoff,yoff)
  82.     super(0,0,100,96)
  83.     sedg = PU_SOUND_EFFECT_GAIN
  84.     sedl = PU_SOUND_EFFECT_LOSE
  85.     se = RPG::SE.new(sedg[0],sedg[1],sedg[2]) unless sedg.nil? or nosound
  86.     se2 = RPG::SE.new(sedl[0],sedl[1],sedl[2]) unless sedl.nil? or nosound
  87.     se.play if se and amount > 0
  88.     se2.play if se2 and amount < 0
  89.     self.opacity = 0
  90.     self.x = $game_player.screen_x - 16
  91.     self.y = $game_player.screen_y - 80
  92.     @xoff = 0
  93.     @yoff = 0
  94.     @duration = 90
  95.     @item = item
  96.     @amount = amount
  97.     @name = item.name.clone
  98.     @text = ""
  99.     @padding = ' '*@name.size
  100.     @timer = 0
  101.     @split = (PU_FADEIN_TIME) / @name.size
  102.     @split = 2 if @split < 2
  103.     amount > 0 ? @red = Color.new(0,255,0) : @red = Color.new(255,0,0)
  104.     if PU_USE_CUSTOM_FONT
  105.       contents.font.size = PU_DEFAULT_FONT_SIZE
  106.     else
  107.       contents.font.size = 16
  108.     end
  109.     @textsize = text_size(@name)
  110.     textsize2 = text_size("+" + amount.to_s)
  111.     self.width = @textsize.width + standard_padding * 2 + 24
  112.     self.width += textsize2.width + 48 if PU_SINGLE_LINE
  113.     contents.font.size < 24 ? size = 24 : size = contents.font.size
  114.     self.height = size + standard_padding * 2
  115.     self.height += size if !PU_SINGLE_LINE
  116.     self.x -= self.width / 2
  117.     create_contents
  118.     if PU_USE_CUSTOM_FONT
  119.       contents.font.name = PU_DEFAULT_FONT_NAME
  120.       contents.font.size = PU_DEFAULT_FONT_SIZE
  121.       contents.font.color = PU_DEFAULT_FONT_COLOR
  122.       contents.font.bold = PU_DEFAULT_FONT_BOLD
  123.       contents.font.italic = PU_DEFAULT_FONT_ITALIC
  124.       contents.font.shadow = PU_DEFAULT_FONT_SHADOW
  125.       contents.font.outline = PU_DEFAULT_FONT_OUTLINE
  126.     end
  127.     self.contents_opacity = 0
  128.     $game_player.animation_id = PU_POPUP_ANIMATION if PU_USE_ANIMATION
  129.     update
  130.   end
  131.   def update
  132.     #super
  133.     return if self.disposed?
  134.     self.visible = true if !self.visible
  135.     self.x = $game_player.screen_x - contents.width/4 + 12
  136.     self.y = $game_player.screen_y - 80 + @yoff
  137.     self.x -= self.width / 3
  138.     open if @timer < (PU_FADEIN_TIME)
  139.     close if @timer > (PU_FADEOUT_TIME + @duration)
  140.     @timer += 1
  141.     return if @timer % @split != 0
  142.     @text += @name.slice!(0,1)
  143.     @padding.slice!(0,1)
  144.     contents.clear
  145.     contents.font.color = @red
  146.     stringamount = @amount
  147.     stringamount = "+" + @amount.to_s if @amount > 0
  148.     if PU_SINGLE_LINE
  149.       width = text_size(@item.name).width#@textsize.width
  150.       draw_text(27 + width,0,36,24,stringamount) unless PU_COMPACT_MODE and @amount == 1
  151.       if Module.const_defined?(:AFFIXES)
  152.         contents.font.color = @item.color
  153.       else
  154.         contents.font.color = Font.default_color
  155.       end
  156.       draw_text(24,0,contents.width,contents.height,@text+@padding)
  157.       draw_icon(PU_BACKGROUND_ICON,0,0) if PU_USE_BACKGROUND_ICON
  158.       draw_icon(@item.icon_index,0,0)
  159.     else
  160.       draw_text(contents.width / 4 + 16,24,36,24,stringamount) unless PU_COMPACT_MODE and @amount == 1
  161.       if Module.const_defined?(:AFFIXES)
  162.         contents.font.color = @item.color
  163.       else
  164.         contents.font.color = Font.default_color
  165.       end
  166.       draw_icon(PU_BACKGROUND_ICON,contents.width / 2 - 24,24) if PU_USE_BACKGROUND_ICON
  167.       draw_icon(@item.icon_index,contents.width / 2 - 24,24)
  168.       draw_text(0,0,contents.width,line_height,@text+@padding)
  169.     end
  170.   end
  171.   def close
  172.     self.contents_opacity -= (255 / (PU_FADEOUT_TIME))
  173.   end
  174.   def open
  175.     self.contents_opacity += (255 / (PU_FADEIN_TIME))
  176.   end
  177. end
  178.  
  179. class Game_Interpreter
  180.   alias pu_command_126 command_126
  181.   alias pu_command_127 command_127
  182.   alias pu_command_128 command_128
  183.   alias pu_command_125 command_125
  184.   def popup(type,item,amount,duration = PU_DEFAULT_DURATION,nosound = false, xo = 0, yo = 0)
  185.     data = $data_items[item] if type == 0
  186.     data = $data_weapons[item] if type == 1
  187.     data = $data_armors[item] if type == 2
  188.     if type == 3
  189.       data = RPG::Item.new
  190.       data.name = PU_GOLD_NAME
  191.       data.icon_index = PU_GOLD_ICON
  192.     end
  193.     if type == 4
  194.       data = RPG::Item.new
  195.       data.name = "Exp"
  196.       data.icon_index = 116
  197.     end
  198.     Popup_Manager.add(data,amount,duration,nosound,xo,yo)
  199.   end
  200.   def command_126
  201.     pu_command_126
  202.     value = operate_value(@params[1], @params[2], @params[3])
  203.     popup(0,@params[0],value) if $PU_AUTOMATIC_POPUP
  204.   end
  205.   def command_127
  206.     pu_command_127
  207.     value = operate_value(@params[1], @params[2], @params[3])
  208.     popup(1,@params[0],value) if $PU_AUTOMATIC_POPUP
  209.   end
  210.   def command_128
  211.     pu_command_128
  212.     value = operate_value(@params[1], @params[2], @params[3])
  213.     popup(2,@params[0],value) if $PU_AUTOMATIC_POPUP
  214.   end
  215.   def command_125
  216.     pu_command_125
  217.     value = operate_value(@params[0], @params[1], @params[2])
  218.     popup(3,@params[0],value) if $PU_AUTOMATIC_POPUP
  219.   end
  220. end
  221.  
  222. module Popup_Manager
  223.   def self.init
  224.     @queue = []
  225.   end
  226.   def self.add(item,value,dura,ns,xo,yo)
  227.     @queue.insert(0,[item,value,dura,ns,xo,yo])
  228.   end
  229.   def self.queue
  230.     @queue
  231.   end
  232. end  
  233.  
  234. Popup_Manager.init
  235.  
  236. class Scene_Map
  237.   alias popup_update update
  238.   alias popup_preterminate pre_terminate
  239.   def update
  240.     popup_update
  241.     update_popup_window unless $popupwindow.nil?
  242.     return if Popup_Manager.queue.empty?
  243.     if $popupwindow.nil? or $popupwindow.contents_opacity == 0
  244.       var = Popup_Manager.queue.pop
  245.       $popupwindow = Item_Popup.new(var[0],var[1],var[2],var[3],var[4],var[5])
  246.     end
  247.   end
  248.   def update_popup_window
  249.     $popupwindow.update
  250.     if !$popupwindow.disposed? and $popupwindow.contents_opacity == 0
  251.       $popupwindow.dispose
  252.       $popupwindow = nil
  253.     end
  254.   end
  255.   def pre_terminate
  256.     popup_preterminate
  257.     $popupwindow.visible = false unless $popupwindow.nil?
  258.   end
  259. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement