Advertisement
roninator2

Vlue Sleek Item Popup - mod

Dec 4th, 2024 (edited)
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.43 KB | None | 0 0
  1. #Sleek Item Popup v1.14f
  2. #Mod by Roninator2
  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],event_id)
  9. #
  10. #          Where: type is category of item (0 = item, 1 = weapon,
  11. #                                            2 = armor, 3 = gold)
  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. #            $game_switches[X] = false
  20. #            $game_switches[X] = true
  21. #          To use the event, you can use x offset and y offset but it is
  22. #          not required, but still must be placed in the script call.
  23. #          popup(1,   5,    1,     120,    0,   0,    3)
  24. #         popup(type,item,amount,duration,xoff,yoff,event)
  25. #               event #3 will have the popup
  26. #
  27. #Customization: Everything down there under customization
  28. #
  29. #----------#
  30. #-- Script by: V.M of D.T
  31. #
  32. #- Questions or comments can be:
  33. #    given by email: sumptuaryspade@live.ca
  34. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  35. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  36. #
  37. #--- Free to use in any project, commercial or non-commercial, with credit given
  38. # - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)
  39.  
  40. $imported = {} if $imported.nil?
  41. $imported[:Vlue_SleekPopup] = true
  42.  
  43. module Vlue_Popup
  44. #Sound effect played on popup: # "Filename", Volume(0-100), Pitch(50-150)
  45. PU_SOUND_EFFECT_GAIN = ["Item3",100,50]
  46. PU_SOUND_EFFECT_LOSE = ["Item3",100,50]
  47. PU_SOUND_GOLD_GAIN = ["Coin",100,50]
  48. PU_SOUND_GOLD_LOSE = ["Coin",100,50]
  49.  
  50. #Animation to be played on the player during popup
  51. PU_USE_ANIMATION = false
  52. PU_POPUP_ANIMATION = 2
  53.  
  54. #Duration in frames of Item Popup fadein and fadeout
  55. PU_FADEIN_TIME = 30
  56. PU_FADEOUT_TIME = 30
  57.  
  58. #Default duration of the popup
  59. PU_DEFAULT_DURATION = 90
  60.  
  61. #Use automatic popup? Can be enabled/disabled in game, see examples
  62. PU_AUTOMATIC_POPUP = 186 # switch to turn on off
  63. PU_IGNORE_ITEM_LOSS = true
  64.  
  65. #Whether to use a custom or default font
  66. PU_USE_CUSTOM_FONT = false
  67.  
  68. #Settings for custom item popup font
  69. PU_DEFAULT_FONT_NAME = ["Verdana"]
  70. PU_DEFAULT_FONT_SIZE = 16
  71. PU_DEFAULT_FONT_COLOR = Color.new(255,255,255,255)
  72. PU_DEFAULT_FONT_BOLD = false
  73. PU_DEFAULT_FONT_ITALIC = false
  74. PU_DEFAULT_FONT_SHADOW = false
  75. PU_DEFAULT_FONT_OUTLINE = true
  76.  
  77. #Compact mode will hide the amount unless it's greater then 1
  78. PU_COMPACT_MODE = true
  79.  
  80. #Background Icon to be displayed under item icon
  81. PU_USE_BACKGROUND_ICON = true
  82. PU_BACKGROUND_ICON = 102
  83.  
  84. #Gold details:
  85. PU_GOLD_NAME = "Lytil"
  86. PU_GOLD_ICON = 262
  87.  
  88. #True for single line, false for multi line
  89. PU_SINGLE_LINE = true
  90.  
  91. end
  92.  
  93. class Item_Popup < Window_Base
  94.   def initialize(item, amount, duration, nosound,xoff,yoff,event)
  95.     super(0,0,100,96)
  96.     return if item.nil?
  97.     amount = 0 if amount.nil?
  98.     if item.name == Vlue_Popup::PU_GOLD_NAME
  99.       sedg, sedl = Vlue_Popup::PU_SOUND_GOLD_GAIN, Vlue_Popup::PU_SOUND_GOLD_LOSE
  100.     else
  101.       sedg, sedl = Vlue_Popup::PU_SOUND_EFFECT_GAIN, Vlue_Popup::PU_SOUND_EFFECT_LOSE
  102.     end
  103.     se = RPG::SE.new(sedg[0],sedg[1],sedg[2]) unless sedg.nil? or nosound
  104.     se2 = RPG::SE.new(sedl[0],sedl[1],sedl[2]) unless sedl.nil? or nosound
  105.     se.play if se and amount > 0
  106.     se2.play if se2 and amount < 0
  107.     self.opacity = 0
  108.     self.x = $game_player.screen_x - 16
  109.     self.y = $game_player.screen_y - 80
  110.     @xoff = xoff
  111.     @yoff = yoff
  112.     @duration = duration ? duration : 120
  113.     @item = item
  114.     @amount = amount
  115.     @name = item.name.clone
  116.     @text = ""
  117.     @padding = ' '*@name.size
  118.     @timer = 0
  119.     @event = event
  120.     @split = (Vlue_Popup::PU_FADEIN_TIME) / @name.size
  121.     @split = 2 if @split < 2
  122.     amount > 0 ? @red = Color.new(0,255,0) : @red = Color.new(255,0,0)
  123.     if Vlue_Popup::PU_USE_CUSTOM_FONT
  124.       contents.font.size = Vlue_Popup::PU_DEFAULT_FONT_SIZE
  125.     else
  126.       contents.font.size = 16
  127.     end
  128.     @textsize = text_size(@name)
  129.     textsize2 = text_size("+" + amount.to_s)
  130.     self.width = @textsize.width + standard_padding * 2 + 24
  131.     self.width += textsize2.width + 48 if Vlue_Popup::PU_SINGLE_LINE
  132.     contents.font.size < 24 ? size = 24 : size = contents.font.size
  133.     self.height = size + standard_padding * 2
  134.     self.height += size if !Vlue_Popup::PU_SINGLE_LINE
  135.     self.x -= self.width / 2
  136.     create_contents
  137.     if Vlue_Popup::PU_USE_CUSTOM_FONT
  138.       contents.font.name = Vlue_Popup::PU_DEFAULT_FONT_NAME
  139.       contents.font.size = Vlue_Popup::PU_DEFAULT_FONT_SIZE
  140.       contents.font.color = Vlue_Popup::PU_DEFAULT_FONT_COLOR
  141.       contents.font.bold = Vlue_Popup::PU_DEFAULT_FONT_BOLD
  142.       contents.font.italic = Vlue_Popup::PU_DEFAULT_FONT_ITALIC
  143.       contents.font.shadow = Vlue_Popup::PU_DEFAULT_FONT_SHADOW
  144.       contents.font.outline = Vlue_Popup::PU_DEFAULT_FONT_OUTLINE
  145.     end
  146.     self.contents_opacity = 0
  147.     $game_player.animation_id = Vlue_Popup::PU_POPUP_ANIMATION if Vlue_Popup::PU_USE_ANIMATION
  148.     update
  149.   end
  150.   def update
  151.     #super
  152.     return if self.disposed?
  153.     return if @item.nil?
  154.     self.visible = true if !self.visible
  155.     @event = 0 if @event.nil?
  156.     if @event != 0
  157.       self.x = $game_map.events[@event].screen_x - contents.width/4 + 12
  158.       self.y = $game_map.events[@event].screen_y - 80 + @yoff
  159.     else
  160.       self.x = $game_player.screen_x - contents.width/4 + 12
  161.       self.y = $game_player.screen_y - 80 + @yoff
  162.     end
  163.     self.x -= self.width / 3
  164.     if self.x < $game_player.screen_x - 32 && $game_player.screen_x < 64
  165.       self.x = 0
  166.     end
  167.     if $game_player.screen_x > (Graphics.width - 64)
  168.       self.x -= 48
  169.     end
  170.     open if @timer < (Vlue_Popup::PU_FADEIN_TIME)
  171.     close if @timer > (Vlue_Popup::PU_FADEOUT_TIME + @duration)
  172.     @timer += 1
  173.     return if @timer % @split != 0
  174.     @text += @name.slice!(0,1)
  175.     @padding.slice!(0,1)
  176.     contents.clear
  177.     contents.font.color = @red
  178.     stringamount = @amount
  179.     stringamount = "+" + @amount.to_s if @amount > 0
  180.     if Vlue_Popup::PU_SINGLE_LINE
  181.       width = text_size(@item.name).width
  182.       draw_text(27 + width,0,36,24,stringamount) unless Vlue_Popup::PU_COMPACT_MODE and @amount == 1
  183.       if Module.const_defined?(:AFFIXES)
  184.         contents.font.color = @item.color
  185.       else
  186.         contents.font.color = Font.default_color
  187.       end
  188.       change_color(@item.rarity_colour) if $imported[:TH_ItemRarity]
  189.       draw_text(24,0,contents.width,contents.height,@text+@padding)
  190.       change_color(normal_color)
  191.       draw_icon(Vlue_Popup::PU_BACKGROUND_ICON,0,0) if Vlue_Popup::PU_USE_BACKGROUND_ICON
  192.       draw_icon(@item.icon_index,0,0)
  193.     else
  194.       draw_text(contents.width / 4 + 16,24,36,24,stringamount) unless Vlue_Popup::PU_COMPACT_MODE and @amount == 1
  195.       if Module.const_defined?(:AFFIXES)
  196.         contents.font.color = @item.color
  197.       else
  198.         contents.font.color = Font.default_color
  199.       end
  200.       draw_icon(Vlue_Popup::PU_BACKGROUND_ICON,contents.width / 2 - 24,24) if Vlue_Popup::PU_USE_BACKGROUND_ICON
  201.       draw_icon(@item.icon_index,contents.width / 2 - 24,24)
  202.       draw_text(0,0,contents.width,line_height,@text+@padding)
  203.     end
  204.   end
  205.   def close
  206.     self.contents_opacity -= (255 / (Vlue_Popup::PU_FADEOUT_TIME))
  207.   end
  208.   def open
  209.     self.contents_opacity += (255 / (Vlue_Popup::PU_FADEIN_TIME))
  210.   end
  211. end
  212.  
  213. class Game_Interpreter
  214.   alias pu_command_126 command_126
  215.   alias pu_command_127 command_127
  216.   alias pu_command_128 command_128
  217.   alias pu_command_125 command_125
  218.   def popup(type,item,amount,duration = Vlue_Popup::PU_DEFAULT_DURATION,nosound = false, xo = 0, yo = 0, event)
  219.     event = 0 if event.nil?
  220.     data = $data_items[item] if type == 0
  221.     data = $data_weapons[item] if type == 1
  222.     data = $data_armors[item] if type == 2
  223.     if type == 3
  224.       data = RPG::Item.new
  225.       data.name = Vlue_Popup::PU_GOLD_NAME
  226.       data.icon_index = Vlue_Popup::PU_GOLD_ICON
  227.     end
  228.     Popup_Manager.add(data,amount,duration,nosound,xo,yo,event)
  229.   end
  230.   def command_125
  231.     pu_command_125
  232.     value = operate_value(@params[0], @params[1], @params[2])
  233.     popup(3,@params[0],value,0) if $game_switches[Vlue_Popup::PU_AUTOMATIC_POPUP]
  234.   end
  235. end
  236.  
  237. module Popup_Manager
  238.   def self.init
  239.     @queue = {}
  240.     @last_item = nil
  241.     @last_event = 0
  242.     @yoff = false
  243.   end
  244.   def self.add(item,value,dura,ns,xo,yo,event)
  245.     return if Vlue_Popup::PU_IGNORE_ITEM_LOSS && value < 1
  246.     @last_item = item if @last_item.nil?
  247.     @last_event = event if @last_event.nil?
  248.     if @last_item != item && @last_event == event
  249.       @yoff = true
  250.       @last_item = item
  251.       @last_event = event
  252.     else
  253.       @yoff = false
  254.     end
  255.     i = @queue.size
  256.     @queue[i] = [item,value,dura,ns,xo,yo,event]
  257.   end
  258.   def self.queue
  259.     @queue
  260.   end
  261.   def self.yoff
  262.     @yoff
  263.   end
  264. end  
  265.  
  266. class Scene_Map
  267.   attr_accessor :popupwindow
  268.   alias popup_update update
  269.   alias popup_preterminate pre_terminate
  270.   alias r2_popup_start  start
  271.   def start
  272.     @popupwindow = {}
  273.     Popup_Manager.init
  274.     r2_popup_start
  275.   end
  276.   alias r2_popup_call_menu call_menu
  277.   def call_menu
  278.     @popupwindow.each_with_index do |pop, i|
  279.       @popupwindow[i].dispose if !@popupwindow[i].nil?
  280.       if @popupwindow[i].nil?
  281.         Popup_Manager.queue.delete(i)
  282.       end
  283.     end
  284.     r2_popup_call_menu
  285.   end
  286.   def update
  287.     popup_update
  288.     update_popup_window unless @popupwindow.nil?
  289.     for i in 0..Popup_Manager.queue.size - 1
  290.       if @popupwindow[i].nil? or @popupwindow[i].contents_opacity <= 20
  291.         var = Popup_Manager.queue[i]
  292.         Popup_Manager.queue.delete(i)
  293.         next if var.nil?
  294.         if Popup_Manager.yoff == true
  295.           var[5] -= 24 * i
  296.         end
  297.         @popupwindow[i].dispose if !@popupwindow[i].nil? and !@popupwindow[i].disposed?
  298.         @popupwindow[i] = Item_Popup.new(var[0],var[1],var[2],var[3],var[4],var[5],var[6]) unless !@popupwindow[i].nil?
  299.       end
  300.       update_popup_window unless @popupwindow[i].nil?
  301.     end
  302.   end
  303.   def update_popup_window
  304.     for i in 0..@popupwindow.size - 1
  305.       next if @popupwindow[i].nil?
  306.       @popupwindow[i].update
  307.       @popupwindow[i].dispose if !@popupwindow[i].disposed? and @popupwindow[i].contents_opacity <= 10
  308.       @popupwindow[i] = nil if @popupwindow[i].disposed?
  309.     end
  310.   end
  311.   def pre_terminate
  312.     popup_preterminate
  313.     for i in 0..@popupwindow.size - 1
  314.       @popupwindow[i].visible = false unless @popupwindow[i].nil?
  315.     end
  316.   end
  317. end
  318.  
  319. class Game_Party
  320.   def gain_item(item, amount, include_equip = false)
  321.     container = item_container(item.class)
  322.     return unless container
  323.     last_number = item_number(item)
  324.     new_number = last_number + amount
  325.     container[item.id] = [[new_number, 0].max, max_item_number(item)].min
  326.     container.delete(item.id) if container[item.id] == 0
  327.     if include_equip && new_number < 0
  328.       discard_members_equip(item, -new_number)
  329.     end
  330.     $game_map.need_refresh = true
  331.     if SceneManager.scene.is_a?(Scene_Map) && $game_switches[Vlue_Popup::PU_AUTOMATIC_POPUP]
  332.       Popup_Manager.add(item,amount,90,false,0,0,0)
  333.     end
  334.   end
  335. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement