Advertisement
FlipelyFlip

Chest Item Pop-Up

Jan 6th, 2013
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 34.08 KB | None | 0 0
  1. #==============================================================================
  2. # Chest Item Pop-Up
  3. #==============================================================================
  4. # Author    : OriginalWij
  5. # Edited By : Mac Malone (Dr. ?)
  6. # New Edits : FlipelyFlip
  7. # Version   : 3.0 - Dr. ? Edit v1.1 Flipely's Edit v1.0
  8. #==============================================================================
  9.  
  10. #==============================================================================
  11. # v1.0
  12. # - Initial release
  13. # v1.1
  14. # - Added description window
  15. # v1.2
  16. # - Bug fix and added forgotten aliases
  17. # v1.3
  18. # - Added option to only popup once for many of the same item
  19. # v2.0
  20. # - Reworked name popup window (won't show "1 x" if only one item)
  21. # - Reworked gold display (more efficient)
  22. # - Added option to turn popup sound on/off
  23. # - Added option to turn popup text on/off
  24. # - Added icon to name popup and the ability to turn it on/off
  25. # - Added adjustable X & Y coordinates for name popup window
  26. # - Added "call" feature - with and without adding the item to inventory
  27. # - Added option to wait for button or time for popup name window
  28. # - Added options to define button and time for popup name window wait
  29. # - Added option to enable/disable the "close window" sound
  30. # - Added options to define "close window" sound
  31. # v2.1
  32. # - Fixed moving event bug
  33. # - Added option to have popup always active
  34. # - Added option for overlay graphic
  35. # - Added auto-adjust name window location, depending on actor X/Y
  36. # v2.2
  37. # - Several minor (non-bug) display fixes
  38. # - Removed overlay option due to compatibility problems
  39. # - Optimized script
  40. # v3.0
  41. # - Bugfix for when called from a common event
  42. # - Reworked main popup scene for new X/Y determination
  43. # - Added option for 2nd window cancellation button
  44. # - Added option to center the text window or auto-move to not cover the player
  45. # - Added option to popup items & gold after battle
  46. # v3.0 - Dr. ? Edit
  47. # - Added sound groups
  48. # - Added ME compadibiltiy
  49. # - Added Chest_Popup.new2 command
  50. # - Added option to show or not show gold
  51. # - Added option to show popup above event
  52. # - Added Chest_Popup.new3 command
  53. # - Added Popup_Data class (Incompadible with old save files)
  54. # v3.0 - Dr. ? Edit v1.1
  55. # - Bugfix for $popup.show_above_event
  56. # v3.0 - Dr. ? Edit v1.1 Flipely's Edit v1.0
  57. # - Added Variable Function
  58. #==============================================================================
  59.  
  60. #==============================================================================
  61. # To use:
  62. #
  63. #   Normal Mode    : turn on the switch (designated below) BEFORE
  64. #                    each gold/item/variable addition
  65. #   Automatic Mode : turn on the switch (designated below) if you DON'T want
  66. #                    popups and then turn the switch off when done
  67. #
  68. # To call manually:
  69. #
  70. #   (useful if using a break-limits script and popping-up 100+ of one item)
  71. #
  72. #   $scene = Chest_Popup.new(type, amount, index, add = false, x = pX, y = pY, sound_group = nil)
  73. #          type : 0 :gold, 1 :items, 2 :weapons, 3 :armor, 4 :variable
  74. #        amount : number of items "gaining"
  75. #         index : item ID
  76. #           add : adds item(s) shown into inventory if true (default = false)
  77. #             x : custom X coordinate to pop-up at (default = player X)
  78. #             y : custom Y coordinate to pop-up at (default = player Y)
  79. #   sound_group : play different sounds; an array containing [SI, VI, PI] look
  80. #               : at PLAY_P_SOUND for more. (default = nil) - Dr.? Edit
  81. #==============================================================================
  82.  
  83. #==============================================================================
  84. # NOTE: when adding multiple (different) items in an event, insert a WAIT(1)
  85. #       between them (insert the WAIT(1) even if in AUTOMATIC mode)
  86. #==============================================================================
  87. # NOTE: the switch turns itself off after each "add item/gold" event command
  88. #       UNLESS in automatic mode (you MUST turn it off MANUALLY in auto-mode)
  89. #==============================================================================
  90. # NOTE: insert a WAIT(7) between a text message and adding items in events
  91. #       (allows time for the message window to close)
  92. #==============================================================================
  93.  
  94.   #-----------------------------------------------------------------------------
  95.   # Popup Controls
  96.   #-----------------------------------------------------------------------------
  97.   # Automatic popup mode
  98.   # (true = ALWAYS popup UNLESS $game_switches[POPUP_SWITCH] is on)
  99.   AUTO_POPUP = true
  100.   # Switch to activate/deactivate popups
  101.   # (activate if AUTO_POPUP = false) (deactivate if AUTO_POPUP = true)
  102.   POPUP_SWITCH = 998
  103.   # Popup gold
  104.   GOLD_POP = true
  105.     # "Gold" icon index
  106.     # (if GOLD_POPUP = true)
  107.     GOLD_ICON = 205
  108.   # Variable Popup
  109.   VAR_POP = true
  110.     # Variable ID => Icon,
  111.     VAR_ID_ICON = {1 => 200,}
  112.   # Only popup once (if many of the same item)
  113.   ONLY_SHOW_ONE = true
  114.   # Popup gold/items gained in battle (pops-up after battle)
  115.   BATTLE_POP = false
  116.     # Battle reward prefix text for popup text window
  117.     # (if BATTLE_POP = true)
  118.     BATTLE_REWARD = 'Battle Reward: '
  119.   # Show the Popup icon above the event which gave you the item.
  120.   SHOW_ABOVE_EVENT = false
  121.  
  122.   #-----------------------------------------------------------------------------
  123.   # Sound Groups (Dr. ?)
  124.   #-----------------------------------------------------------------------------
  125.   # With this edit you can play multiple sounds depending on what you pick up.
  126.   # You can also play custom sounds when an important item is gained.
  127.   #
  128.   # Defining your Sounds, Volumes, and Pitches:
  129.   # ===========================================
  130.   # To set up your volumes, pitchs, and sound files you put a new pitch, volume,
  131.   # and or sound into the 3 constants below (P_SND, P_SND_V, P_SND_P).
  132.   #
  133.   # Sounds:
  134.   # -------
  135.   # For sounds you can either play a SE or a ME.
  136.   # To add a new sound simply add new index to P_SND like so:
  137.   #
  138.   # old:
  139.   # P_SND = ['Audio/SE/Chime2']
  140.   # new:
  141.   # P_SND = ['Audio/SE/Chime2', 'Audio/SE/Item1'] # Added a new SE called Item1
  142.   #
  143.   # Volumes:
  144.   # --------
  145.   # To add a new volume add a new index to P_SND_V like so:
  146.   #
  147.   # old:
  148.   # P_SND_V = [100]
  149.   # new:
  150.   # P_SND_V = [100, 80] # Added a volume with a percentage of 80. The precentage can be 0 - 100
  151.   #
  152.   # Pitchs:
  153.   # -------
  154.   # Same as with volumes except you add it to P_SND_P. The precentage can be 0 - 150.
  155.   # Examples: [150] # Pitch of 150
  156.   #
  157.   # Defining your Sound Groups:
  158.   # ===========================
  159.   # A sound group is an array cosisting of a Sound Index (SI), a Volume Index (VI),
  160.   # and a Pitch Index (PI). So the format is: [SI, VI, PI]. A sound index is the
  161.   # index of one of your defined sounds, a volume index is the index of one of
  162.   # your defined volumes, and a pitch index is the index of one of your defined
  163.   # pitchs. Here are some examples (Using the values above):
  164.   #
  165.   # [0, 0, 0] # This would be the SE, Chime2, with a volume of 100 and a pitch of 150.
  166.   # [1, 1, 0] # This would be the SE, Item1, with a volume of 80 and a pitch of 150.
  167.   #
  168.   # I hope you understood that.
  169.   #
  170.   # Using Sound Groups:
  171.   # ===================
  172.   # There are two ways to use sound groups. The GOLD_SOUND, WEAPON_SOUND, etc.
  173.   # constants and via Chest_Popup.new or Chest_Popup.new2 commands.
  174.   #
  175.   # GOLD_SOUND, ITEM_SOUND, WEAPON_SOUND, etc.:
  176.   # -------------------------------------------
  177.   # To use a sound group in these constants simply write: GOLD_SOUND = [0, 0, 0]
  178.   # or whatever your sound group is. These constants mean what sounds will play
  179.   # when gold is gained, when a weapon is gained, etc. It should be evident, but
  180.   # it does tell you what each one is beside the constant definition. Examples:
  181.   #
  182.   # GOLD_SOUND = [0, 0, 0] # This would play the SE, Chime2, with a volume of 100
  183.   # and a pitch of 150 when gold is gained.
  184.   # ITEM_SOUND = [1, 1, 0] # This would play the SE, Item1, witha volume of 80
  185.   # and a pitch of 150 when an item is gained.
  186.   #
  187.   # Chest_Popup.new and Chest_Popup.new2 Commands:
  188.   # ----------------------------------------------
  189.   # Use this to make special music play when you get a special item.
  190.   #
  191.   # Example:
  192.   # Let's say we get a very special item (Like a crystal) and we want it to
  193.   # popup and play the ME Fanfare1 with the defualt volume and pitch (100, 150).
  194.   # So here is what we would do. We would first add that ME into P_SND like so:
  195.   #
  196.   # P_SND = ['Audio/SE/Chime2', 'Audio/SE/Item1', 'Audio/ME/Fanfare1']
  197.   #
  198.   # Then we would make our event with Quick Event Creation > Treasure Chest,
  199.   # select our chest character set and choose our crystal item from the drop-down.
  200.   # Then we open up the event. We delete the second to last event on the first
  201.   # page, the one that adds the a item. Then We replace it with a script event.
  202.   # If the index of the crystal was 8 it would look like this:
  203.   #
  204.   # $scene=Chest_Popup.new(1,1,8,true,nil,nil,[2,0,0]) # See the 8 in this command?
  205.   # That is the index of the item in the database.
  206.   #
  207.   # Note: This WON'T fit one just one line, and I'm not sure if that's going to
  208.   # be a problem or not. If you want the command to fit on one line you could
  209.   # ethier use the new2 command or do this:
  210.   #
  211.   # sg = [2,0,0] # sound group
  212.   # t = true     # add value
  213.   # $scene=Chest_Popup.new(1,1,8,t,nil,nil,sg)
  214.   #
  215.   # This would end up taking 3 lines but all of the commands would fit on one
  216.   # line.
  217.   #
  218.   # After that, click OK and you are done.
  219.   #
  220.   # About New2:
  221.   # -----------
  222.   # The Chest_Popup.new2 is a command made just for the sound group purpose. It
  223.   # shortens the new command by rearrganing it and removing the x, y settings.
  224.   # In the example above the new2 command would have made the script look like
  225.   # this:
  226.   #
  227.   # $scene = Chest_Popup.new2(1, 1, 10, [2,0,0])
  228.   #
  229.   # Thus, it would fit on one line. The syntax for this command is:
  230.   #
  231.   # $scene = Chest_Popup.new2(type, amount, index, sound_group=nil, add=true)
  232.   #
  233.   # Each of them have the same meaning the same as their counterparts in the
  234.   # Chest_Popup.new command explained at the top of this script, with the
  235.   # exception of the defualt of add now being true.
  236.   #
  237.   # Notes:
  238.   # ======
  239.   # PLAY_P_SND must be true for any of this to work.
  240.   #
  241.   #-----------------------------------------------------------------------------
  242.   # Play sound on popup?
  243.   PLAY_P_SND = true
  244.     #######################################################
  245.     # 3 options below are valid ONLY if PLAY_P_SND = true #
  246.     #######################################################
  247.     # Sound to play upon popup
  248.     # Can be a list of sounds, volumes, and pitchs, but must be surrounded in []
  249.     P_SND = ['Audio/SE/Chime2', 'Audio/SE/Item1', 'Audio/ME/Fanfare1']
  250.     P_SND_V = [100]
  251.     P_SND_P = [150]
  252.    
  253.   # Which sound to play from P_SND at certain occasions.
  254.   # SI = Sound Index, VI = Volume Index, PI = Pitch Index
  255.   #                SI VI PI
  256.   GOLD_SOUND    =  [1, 0, 0]      # Sound to play if gold
  257.   VAR_SOUND     =  [1, 0, 0]      # Sound to play if gold
  258.   ITEM_SOUND    =  [0, 0, 0]      # Sound to play if item
  259.   ARMOR_SOUND   =  [1, 0, 0]      # Sound to play if armour
  260.   WEAPON_SOUND  =  [1, 0, 0]      # Sound to play if weapon
  261.   DEFAULT_SOUND =  [0, 0, 0]      # Sound to play if all others are nil
  262.    
  263.   # Play "close window" sound?
  264.   # Sound Groups do not currently work with this sound.
  265.   PLAY_C_SND = false
  266.     #######################################################
  267.     # 3 options below are valid ONLY if PLAY_C_SND = true #
  268.     #######################################################
  269.     # Sound to play upon popup close
  270.     C_SND = 'Audio/SE/Cancel'
  271.     C_SND_V = 80
  272.     C_SND_P = 100
  273.    
  274.   #-----------------------------------------------------------------------------
  275.   # Popup Text Controls
  276.   #-----------------------------------------------------------------------------
  277.   # Show popup text?
  278.   SHOW_POPUP_TEXT = true
  279.     ##############################################################
  280.     # ALL options below are valid ONLY if SHOW_POPUP_TEXT = true #
  281.     ##############################################################
  282.     # Show icon with popup text?
  283.     SHOW_POPUP_TEXT_ICON = true
  284.     # Auto adjust window if over player
  285.     TEXT_WINDOW_MOVE = true
  286.     # Popup text window Y coordinate
  287.     TEXT_WINDOW_Y = 180
  288.     # Popup text window X coordinate offset
  289.     # 0 (Zero)         : centered in the window
  290.     # negative integer : offset left  (centered)
  291.     # positive integer : offset right (centered)
  292.     TEXT_WINDOW_X_OFFSET = 0
  293.     # Wait for button to close? (false = wait for time)
  294.     WAIT_FOR_BUTTON = false
  295.       # Buttons to wait for
  296.       # (if WAIT_FOR_BUTTON = true)
  297.       # (Set both to the same button to check for only one)
  298.       BUTTON_TO_WAIT_FOR1 = Input::C
  299.       BUTTON_TO_WAIT_FOR2 = Input::B
  300.       # Frames to wait
  301.       # (if WAIT_FOR_BUTTON = false)
  302.       WAIT_FOR_TIME = 40
  303.  
  304. #==============================================================================
  305. # Popup_Data
  306. #   - Added by Dr.?
  307. #==============================================================================
  308.  
  309. class Popup_Data
  310.  
  311.   attr_accessor :gold_pop, :only_show_one, :show_above_event, :battle_pop, :play_p_snd, :play_c_snd,
  312.   :c_snd, :c_snd_v, :c_snd_p, :show_popup_text, :show_popup_text_icon, :text_window_move,
  313.   :text_window_y, :text_window_x_offset, :wait_for_button, :wait_for_time, :var_pop
  314.  
  315.   def initialize
  316.     create_popup_data
  317.   end
  318.  
  319.   def create_popup_data
  320.     @gold_pop = GOLD_POP
  321.     @var_pop = VAR_POP
  322.     @only_show_one = ONLY_SHOW_ONE
  323.     @battle_pop = BATTLE_POP
  324.     @show_above_event = SHOW_ABOVE_EVENT
  325.     @play_p_snd = PLAY_P_SND
  326.     @play_c_snd = PLAY_C_SND
  327.     @c_snd = C_SND
  328.     @c_snd_v = C_SND_V
  329.     @c_snd_p = C_SND_P
  330.     @show_popup_text = SHOW_POPUP_TEXT
  331.     @show_popup_text_icon = SHOW_POPUP_TEXT_ICON
  332.     @text_window_move = TEXT_WINDOW_MOVE
  333.     @text_window_y = TEXT_WINDOW_Y
  334.     @text_window_x_offset = TEXT_WINDOW_X_OFFSET
  335.     @wait_for_button = WAIT_FOR_BUTTON
  336.     @wait_for_time = WAIT_FOR_TIME
  337.   end
  338.  
  339. end
  340.  
  341. $popup = Popup_Data.new
  342. #==============================================================================
  343. # Game_System
  344. #==============================================================================
  345.  
  346. class Game_System
  347.   #--------------------------------------------------------------------------
  348.   # Public Instance Variables (Added)
  349.   #--------------------------------------------------------------------------
  350.   attr_accessor :battle_pop       # holds items to popup after battle
  351.   attr_accessor :battle_pop_gold  # holds gold to popup after battle
  352.   attr_accessor :pop_event        # holds the event if SHOW_ABOVE_EVENT=true
  353.   #--------------------------------------------------------------------------
  354.   # Initialize (Mod)
  355.   #--------------------------------------------------------------------------
  356.   alias chest_pop_gs_initialize initialize unless $@
  357.   def initialize
  358.     chest_pop_gs_initialize
  359.     @battle_pop = nil
  360.     @battle_pop_gold = 0
  361.     @pop_event = nil # Add by Dr. ?
  362.   end
  363.   #--------------------------------------------------------------------------
  364.   # Get Battle Pop (New)
  365.   #--------------------------------------------------------------------------
  366.   def battle_pop
  367.     return @battle_pop
  368.   end
  369.   #--------------------------------------------------------------------------
  370.   # Set Battle Pop (New)
  371.   #--------------------------------------------------------------------------
  372.   def battle_pop=(items)
  373.     @battle_pop = items
  374.   end
  375.   #--------------------------------------------------------------------------
  376.   # Get Battle Pop Gold (New)
  377.   #--------------------------------------------------------------------------
  378.   def battle_pop_gold
  379.     return @battle_pop_gold
  380.   end
  381.   #--------------------------------------------------------------------------
  382.   # Set Battle Pop Gold (New)
  383.   #--------------------------------------------------------------------------
  384.   def battle_pop_gold=(gold)
  385.     @battle_pop_gold = gold
  386.   end
  387.  
  388. end
  389.  
  390. #==============================================================================
  391. # Game_Interpreter
  392. #==============================================================================
  393.  
  394. class Game_Interpreter
  395.   #--------------------------------------------------------------------------
  396.   # * Control Variables
  397.   #--------------------------------------------------------------------------
  398.   alias chest_pop_command_122 command_122 unless $@
  399.   def command_122
  400.     if VAR_ID_ICON.include?(@params[0])
  401.       event = $game_map.events[@event_id]
  402.       $game_system.pop_event = event
  403.       if @params[4] > 0
  404.         if @params[2] == 1 or @params[2] == 0
  405.           if !$popup.show_above_event
  406.             $scene = Chest_Popup.new(4, @params[4], @params[0])
  407.           elsif !@event_id.nil?
  408.             $scene = Chest_Popup.new(4, @params[4], @params[0], false, event.screen_x, event.screen_y)
  409.           end
  410.         end
  411.       end
  412.     end
  413.     chest_pop_command_122    
  414.   end
  415.   #--------------------------------------------------------------------------
  416.   # Change Gold (Mod)
  417.   #--------------------------------------------------------------------------
  418.   alias chest_pop_command_125 command_125 unless $@
  419.   def command_125
  420.     value = operate_value(@params[0], @params[1], @params[2])
  421.     # Pop-up
  422.     event = $game_map.events[@event_id]
  423.     $game_system.pop_event = event
  424.     if $game_switches[POPUP_SWITCH] != AUTO_POPUP and @params[0] == 0 and $popup.gold_pop
  425.       if !$popup.show_above_event
  426.         $scene = Chest_Popup.new(0, value, 1)
  427.       elsif !@event_id.nil?
  428.         $scene = Chest_Popup.new(0, value, 1, false, event.screen_x, event.screen_y)
  429.       end
  430.     end
  431.     chest_pop_command_125    
  432.   end
  433.   #--------------------------------------------------------------------------
  434.   # Change Items (Mod)
  435.   #--------------------------------------------------------------------------
  436.   alias chest_pop_command_126 command_126 unless $@
  437.   def command_126
  438.     value = operate_value(@params[1], @params[2], @params[3])
  439.     # Pop-up
  440.     event = $game_map.events[@event_id]
  441.     $game_system.pop_event = event
  442.     if $game_switches[POPUP_SWITCH] != AUTO_POPUP and @params[1] == 0
  443.       if !$popup.show_above_event
  444.         $scene = Chest_Popup.new(1, value, @params[0])
  445.       elsif !@event_id.nil?
  446.         $scene = Chest_Popup.new(1, value, @params[0], false, event.screen_x, event.screen_y)
  447.       end
  448.     end
  449.     chest_pop_command_126
  450.   end
  451.   #--------------------------------------------------------------------------
  452.   # Change Weapons (Mod)
  453.   #--------------------------------------------------------------------------
  454.   alias chest_pop_command_127 command_127 unless $@
  455.   def command_127
  456.     value = operate_value(@params[1], @params[2], @params[3])
  457.     # Pop-up
  458.     event = $game_map.events[@event_id]
  459.     $game_system.pop_event = event
  460.     if $game_switches[POPUP_SWITCH] != AUTO_POPUP and @params[1] == 0
  461.       if !$popup.show_above_event
  462.         $scene = Chest_Popup.new(2, value, @params[0])
  463.       elsif !@event_id.nil?
  464.         $scene = Chest_Popup.new(2, value, @params[0], false, event.screen_x, event.screen_y)
  465.       end
  466.     end
  467.     chest_pop_command_127
  468.   end
  469.   #--------------------------------------------------------------------------
  470.   # Change Armor (Mod)
  471.   #--------------------------------------------------------------------------
  472.   alias chest_pop_command_128 command_128 unless $@
  473.   def command_128
  474.     value = operate_value(@params[1], @params[2], @params[3])
  475.     # Pop-up
  476.     event = $game_map.events[@event_id]
  477.     $game_system.pop_event = event
  478.     if $game_switches[POPUP_SWITCH] != AUTO_POPUP and @params[1] == 0
  479.       if !$popup.show_above_event
  480.         $scene = Chest_Popup.new(3, value, @params[0])
  481.       elsif !@event_id.nil?
  482.         $scene = Chest_Popup.new(3, value, @params[0], false, event.screen_x, event.screen_y)
  483.       end
  484.     end
  485.     chest_pop_command_128
  486.   end
  487. end
  488.  
  489. #==============================================================================
  490. # Item Popup Window (New)
  491. #==============================================================================
  492.  
  493. class Item_Popup_Window < Window_Base
  494.   #--------------------------------------------------------------------------
  495.   # Initialize
  496.   #--------------------------------------------------------------------------
  497.   def initialize(x, y)
  498.     super(0, 0, 544, 416)
  499.     self.opacity = 0
  500.     # Adjust X/Y to proper origin
  501.     @x, @y = x - 27, y - 60
  502.   end
  503.   #--------------------------------------------------------------------------
  504.   # Pop-Up
  505.   #--------------------------------------------------------------------------
  506.   def pop_up(icon_index, x_offset, y_offset)
  507.     self.contents.clear
  508.     # Draw pop-up icon
  509.     draw_icon(icon_index, @x + x_offset, @y + y_offset, true)
  510.   end
  511. end
  512.  
  513. #==============================================================================
  514. # Name window (New)
  515. #==============================================================================
  516.  
  517. class Name_Window < Window_Base
  518.   #--------------------------------------------------------------------------
  519.   # Initialize
  520.   #--------------------------------------------------------------------------
  521.   def initialize(x, y, desc, no_desc, index, gold = false, icon = 0)
  522.     super(x, y, 56, WLH + 32)
  523.     # Adjust window to content's size and center
  524.     icon_x = self.contents.text_size(index).width + 6
  525.     width = self.contents.text_size(desc).width
  526.     self.width = width + 32
  527.     self.x = ((544 - self.width) / 2) + $popup.text_window_x_offset
  528.     create_contents
  529.     # Draw pop-up text
  530.     ix = no_desc ? 0 : icon_x
  531.     item_check = $game_system.battle_pop
  532.     gold_check = $game_system.battle_pop_gold
  533.     if $popup.battle_pop and (item_check != nil or gold_check > 0) # If battle reward
  534.       ix += self.contents.text_size(BATTLE_REWARD).width + 2
  535.     end
  536.     tx = gold ? 4 : 0
  537.     draw_icon(icon, ix, 0) if $popup.show_popup_text_icon and !gold
  538.     self.contents.draw_text(tx, 0, width, WLH, desc, 0)
  539.     draw_icon(GOLD_ICON, width - 24, 0, true) if gold
  540.   end
  541. end
  542.  
  543. #==============================================================================
  544. # Scene_Base
  545. #==============================================================================
  546.  
  547. class Scene_Base
  548.   #--------------------------------------------------------------------------
  549.   # Initialize (New)
  550.   #--------------------------------------------------------------------------
  551.   def initialize
  552.     @disable_blur = false
  553.   end
  554.   #--------------------------------------------------------------------------
  555.   # Disable blur (New)
  556.   #--------------------------------------------------------------------------
  557.   def disable_blur=(enabled)
  558.     @disable_blur = enabled
  559.   end
  560.   #--------------------------------------------------------------------------
  561.   # Create Snapshot for Using as Background of Another Screen (Rewrite)
  562.   #--------------------------------------------------------------------------
  563.   def snapshot_for_background
  564.     $game_temp.background_bitmap.dispose
  565.     $game_temp.background_bitmap = Graphics.snap_to_bitmap
  566.     # Don't blur if disabled
  567.     $game_temp.background_bitmap.blur unless @disable_blur # changed
  568.   end
  569. end
  570.  
  571. #==============================================================================
  572. # Scene_Map
  573. #==============================================================================
  574.  
  575. class Scene_Map < Scene_Base
  576.   #--------------------------------------------------------------------------
  577.   # Start (Mod)
  578.   #--------------------------------------------------------------------------
  579.   alias chest_pop_start start unless $@
  580.   def start
  581.     chest_pop_start
  582.     # Popup battle rewards
  583.     if $popup.battle_pop
  584.       if $game_system.battle_pop_gold > 0  # gold
  585.         gold = $game_system.battle_pop_gold
  586.         $game_system.battle_pop_gold = 0
  587.         $scene = Chest_Popup.new(0, gold, 0, true)
  588.       elsif $game_system.battle_pop != nil # items
  589.         item = $game_system.battle_pop.shift
  590.         if item == nil
  591.           $game_system.battle_pop = nil
  592.         else
  593.           type = 1 if item.is_a?(RPG::Item)
  594.           type = 2 if item.is_a?(RPG::Weapon)
  595.           type = 3 if item.is_a?(RPG::Armor)
  596.           $scene = Chest_Popup.new(type, 1, item.id, true)
  597.         end
  598.       end
  599.     end
  600.   end
  601. end
  602.  
  603. #==============================================================================
  604. # Scene_Battle
  605. #==============================================================================
  606.  
  607. class Scene_Battle < Scene_Base
  608.   #--------------------------------------------------------------------------
  609.   # Display Gained Experience and Gold (Rewrite)
  610.   #--------------------------------------------------------------------------
  611.   def display_exp_and_gold
  612.     # Save gold to popup after battle
  613.     $game_system.battle_pop_gold = $game_troop.gold_total if $popup.battle_pop # added
  614.     exp = $game_troop.exp_total
  615.     gold = $popup.battle_pop && $popup.gold_pop ? 0 : $game_troop.gold_total # changed
  616.     $game_party.gain_gold(gold) unless $popup.battle_pop  # changed
  617.     text = sprintf(Vocab::Victory, $game_party.name)
  618.     $game_message.texts.push('\|' + text)
  619.     if exp > 0
  620.       text = sprintf(Vocab::ObtainExp, exp)
  621.       $game_message.texts.push('\.' + text)
  622.     end
  623.     if gold > 0
  624.       text = sprintf(Vocab::ObtainGold, gold, Vocab::gold)
  625.       $game_message.texts.push('\.' + text)
  626.     end
  627.     wait_for_message
  628.   end
  629.   #--------------------------------------------------------------------------
  630.   # Display Gained Drop Items (Mod)
  631.   #--------------------------------------------------------------------------
  632.   alias chest_pop_display_drop_items display_drop_items unless $@
  633.   def display_drop_items
  634.     # Save items to popup after battle
  635.     $game_system.battle_pop = $game_troop.make_drop_items if $popup.battle_pop
  636.     return if $popup.battle_pop
  637.     chest_pop_display_drop_items
  638.   end
  639. end
  640.  
  641. #==============================================================================
  642. # Chest_Popup (New)
  643. #==============================================================================
  644.  
  645. class Chest_Popup < Scene_Base
  646.   #--------------------------------------------------------------------------
  647.   # Initialize
  648.   #--------------------------------------------------------------------------
  649.   def initialize(type, amount, index, add = false, x = nil, y = nil, sound_group = nil)
  650.     x = $game_player.screen_x if x == nil
  651.     y = $game_player.screen_y if y == nil
  652.     $game_switches[POPUP_SWITCH] = !AUTO_POPUP
  653.     $scene.disable_blur = true
  654.     @x, @y, @amount = x, y, amount
  655.     @gold = @no_desc = false
  656.     case type
  657.     when 0 # Gold
  658.       $game_party.gain_gold(amount) if add
  659.       @icon = GOLD_ICON
  660.       @desc_amount = ''
  661.       @desc = @amount.to_s
  662.       @amount = 1
  663.       @gold = true
  664.       @sound = GOLD_SOUND
  665.     when 1 # Items
  666.       $game_party.gain_item($data_items[index], amount) if add
  667.       @icon = $data_items[index].icon_index
  668.       @desc_amount = @amount.to_s + ' x'
  669.       @desc_amount = '' if @amount == 1
  670.       @no_desc = true if @amount == 1
  671.       @desc = $data_items[index].name
  672.       @amount = 1 if $popup.only_show_one
  673.       @sound = ITEM_SOUND
  674.     when 2 # Weapons
  675.       $game_party.gain_item($data_weapons[index], amount) if add
  676.       @icon = $data_weapons[index].icon_index
  677.       @desc_amount = @amount.to_s + ' x'
  678.       @desc_amount = '' if @amount == 1
  679.       @no_desc = true if @amount == 1
  680.       @desc = $data_weapons[index].name
  681.       @amount = 1 if $popup.only_show_one
  682.       @sound = WEAPON_SOUND
  683.     when 3 # Armors
  684.       $game_party.gain_item($data_armors[index], amount) if add
  685.       @icon = $data_armors[index].icon_index
  686.       @desc_amount = @amount.to_s + ' x'
  687.       @desc_amount = '' if @amount == 1
  688.       @no_desc = true if @amount == 1
  689.       @desc = $data_armors[index].name
  690.       @amount = 1 if $popup.only_show_one
  691.       @sound = ARMOR_SOUND
  692.     when 4 # Variable
  693.       @amount if add
  694.       @icon = VAR_ID_ICON[index]
  695.       @desc_amount = ''
  696.       @desc = @amount.to_s
  697.       @amount = 1
  698.       @var = true
  699.       @sound = VAR_SOUND
  700.     end
  701.     # Check sound_group
  702.     @sound = sound_group if !sound_group.nil?
  703.     # Set index
  704.     @index = @desc_amount
  705.     # Add description to text
  706.     if @gold
  707.       @desc = @desc + '      '
  708.     else
  709.       if $popup.show_popup_text_icon
  710.         @desc = @desc_amount + '      ' + @desc
  711.       else
  712.         @desc = @desc_amount + ' ' + @desc if @desc_amount != ''
  713.       end
  714.     end
  715.     # If battle reward
  716.     item_check = $game_system.battle_pop
  717.     gold_check = $game_system.battle_pop_gold
  718.     if $popup.battle_pop and (item_check != nil or gold_check > 0)
  719.       @desc = BATTLE_REWARD + @desc
  720.     end
  721.   end
  722.   #--------------------------------------------------------------------------
  723.   # New2
  724.   #   - Added by Dr.?
  725.   #   - This is mostly used for controling sound groups
  726.   #--------------------------------------------------------------------------
  727.   def self.new2(type, amount, index, sound_group = nil, add = true)
  728.     return Chest_Popup.new(type, amount, index, add, nil, nil, sound_group)
  729.   end
  730.   #--------------------------------------------------------------------------
  731.   # New3
  732.   #   - Added by Dr.?
  733.   #   - This is mostly used for making the icon pop-up over an event
  734.   #--------------------------------------------------------------------------
  735.   def self.new3(type, amount, index, event, add = false, sound_group = nil)
  736.     event = $game_map.events[event] if event.is_a?(Integer)
  737.     return Chest_Popup.new(type, amount, index, add, event.screen_x, event.screen_y, sound_group)
  738.   end
  739.   #--------------------------------------------------------------------------
  740.   # Start
  741.   #--------------------------------------------------------------------------
  742.   def start
  743.     create_background
  744.     # Create pop-up window
  745.     @popup_window = Item_Popup_Window.new(@x, @y)
  746.   end
  747.   #--------------------------------------------------------------------------
  748.   # Terminate
  749.   #--------------------------------------------------------------------------
  750.   def terminate
  751.     # Dispose windows
  752.     @popup_window.dispose
  753.     @menuback_sprite.dispose
  754.     @name_window.dispose if $popup.show_popup_text
  755.   end
  756.   #--------------------------------------------------------------------------
  757.   # Return Scene
  758.   #--------------------------------------------------------------------------
  759.   def return_scene
  760.     # Turn off blur and pop-up switch
  761.     $scene.disable_blur = false
  762.     $game_switches[POPUP_SWITCH] = false
  763.     $scene = Scene_Map.new
  764.   end
  765.   #--------------------------------------------------------------------------
  766.   # Update
  767.   #--------------------------------------------------------------------------
  768.   def update
  769.     super
  770.     # Update pop-up window
  771.     @popup_window.update
  772.     @menuback_sprite.update
  773.     # Do the actual popping-up
  774.     do_popup
  775.   end
  776.   #--------------------------------------------------------------------------
  777.   # Update Basic
  778.   #--------------------------------------------------------------------------
  779.   def update_basic
  780.     Graphics.update              
  781.     Input.update                  
  782.   end
  783.   #--------------------------------------------------------------------------
  784.   # Wait
  785.   #--------------------------------------------------------------------------
  786.   def wait(duration)
  787.     # Wait for DURATION frames
  788.     for i in 0..duration
  789.       update_basic
  790.     end
  791.   end
  792.   #--------------------------------------------------------------------------
  793.   # Wait for close
  794.   #--------------------------------------------------------------------------
  795.   def wait_for_close
  796.     count = 0
  797.     loop do
  798.       update_basic
  799.       count += 1
  800.       # Close if button 1 pressed
  801.       break if Input.trigger?(BUTTON_TO_WAIT_FOR1) and $popup.wait_for_button
  802.       # Close if button 2 pressed
  803.       break if Input.trigger?(BUTTON_TO_WAIT_FOR2) and $popup.wait_for_button
  804.       # Close if time elapsed
  805.       break if count >= $popup.wait_for_time and !$popup.wait_for_button
  806.     end
  807.   end
  808.   #--------------------------------------------------------------------------
  809.   # Create Background
  810.   #--------------------------------------------------------------------------
  811.   def create_background
  812.     # Create modified background
  813.     @menuback_sprite = Sprite.new
  814.     @menuback_sprite.bitmap = $game_temp.background_bitmap
  815.     @menuback_sprite.update
  816.   end
  817.   #--------------------------------------------------------------------------
  818.   # Show Name
  819.   #--------------------------------------------------------------------------
  820.   def show_name
  821.     x = 272
  822.     y = $popup.text_window_y
  823.     py = $game_player.screen_y - 32
  824.     cy = (py - y).abs
  825.     # Offset Y if text box is above player's position
  826.     if cy < 128 and $popup.text_window_move
  827.       y = py < y ? y + (y / 2) : y - (y / 2)
  828.     end
  829.     # Create Window
  830.     @name_window = Name_Window.new(x, y, @desc, @no_desc, @index, @gold, @icon)
  831.     # Wait for button(s) or time
  832.     wait_for_close
  833.     # Play sound
  834.     Audio.se_play($popup.c_snd, $popup.c_snd_v, $popup.c_snd_p) if $popup.wait_for_button and $popup.play_c_snd
  835.   end
  836.   #--------------------------------------------------------------------------
  837.   # Do Pop-Up
  838.   #--------------------------------------------------------------------------
  839.   def do_popup
  840.     # Set sound index - Dr.?
  841.     @sound = DEFAULT_SOUND if @sound.nil?
  842.     # Pop-up icon(s)
  843.     for i in 1..@amount
  844.       # Support for ME added - Dr.?
  845.       if P_SND[@sound[0]].include?("/SE/")
  846.         Audio.se_play(P_SND[@sound[0]], P_SND_V[@sound[1]], P_SND_P[@sound[2]]) if $popup.play_p_snd
  847.       elsif P_SND[@sound[0]].include?("/ME/")
  848.         Audio.me_play(P_SND[@sound[0]], P_SND_V[@sound[1]], P_SND_P[@sound[2]]) if $popup.play_p_snd
  849.       end
  850.       for i in 0..4
  851.         @popup_window.pop_up(@icon, 0, i * -4)
  852.         @popup_window.update
  853.         wait(2)
  854.       end
  855.       wait(5) if i != @amount and !$popup.only_show_one
  856.     end
  857.     wait(5)
  858.     # Pop-up text
  859.     show_name if $popup.show_popup_text
  860.     # Exit
  861.     return_scene
  862.   end
  863.  
  864. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement