Advertisement
ZEkA10000

RPG Maker VX Ace PopUp window

Nov 6th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.68 KB | None | 0 0
  1. #SimplePopUp for items
  2. # script by: ZEkA10000
  3. # create date: 14-jul-2018
  4. # updated: 21-jan-2019
  5.  
  6. #Description:
  7. #This scpipt creates window and shows added items from chests
  8.  
  9. #Updates 0.1:
  10. #Window can show more that 1 item
  11.  
  12. #Updates 0.2:
  13. #Added window animation
  14. #Fixed error with Yanfly Party System
  15.  
  16. #Updates 0.3:
  17. #Added message "You found:
  18. #Added window styles
  19. #Fixed disposed bitmap for window styles
  20.  
  21. #How to instal:
  22. #Just copy this script into ▼ Materials
  23.  
  24. #Copyright for using.
  25. #If you use it, don't forget to indicate that I am the author of this scpript in your game.
  26.  
  27. class Simple_Popup
  28.  
  29.   #more than 11 items
  30.   MOR_STU      = "" #And more...
  31.   #found message | "" for don't using that message
  32.   FOUNDED      = "" #You found:
  33.  
  34.   MOR_STU_ICON = 261 #RTP bag icon
  35.   SHOWING_TIME = 60  #60 Frames
  36.  
  37.   # TURN ON showing window
  38.   POP_UP_ON    = true
  39.  
  40.   # RTP Money icon
  41.   MONEY        = 361
  42.  
  43.   VARIABLE_FOR_STYLE = 1
  44.   # Variable = 0 default window
  45.   # Variable = 1 custom shadowed window
  46.   # Variable = 2 without window
  47.  
  48.  
  49.   def self.shadow_back
  50.     shadowskin = Bitmap.new(128, 128)
  51.     shadowskin.fill_rect(0, 0, 64, 64, Color.new(0, 0, 0, 160))
  52.     shadowskin.gradient_fill_rect(0, 0,  64, 12, Color.new(0, 0, 0, 0),   Color.new(0, 0, 0, 160), true)
  53.     shadowskin.gradient_fill_rect(0, 52, 64, 12, Color.new(0, 0, 0, 160), Color.new(0, 0, 0, 0),   true)
  54.     shadowskin.fill_rect(64, 96, 8, 8, Color.new(255, 255, 255, 255))
  55.     return shadowskin
  56.   end
  57.  
  58.   def self.nograf
  59.     shadowskin = Bitmap.new(128, 128)
  60.     shadowskin.fill_rect(64, 96, 8, 8, Color.new(255, 255, 255, 255))
  61.     return shadowskin
  62.   end
  63.  
  64.   def self.show_items(item, amount)
  65.     dont_add = false
  66.     if POP_UP_ON
  67.       $names = [] if $names == nil
  68.       $disposetime = [] if $disposetime == nil
  69.       $icons_index = [] if $icons_index == nil
  70.       $name_sizes = [] if $name_sizes == nil
  71.      
  72.       $my_message.dispose if $my_message != nil
  73.       f_s = 8
  74.       if item == nil
  75.         n = " "
  76.         visibility = false
  77.         i_ind = 0
  78.       else
  79.         if item.class == Fixnum
  80.           amount > 0 ? n = "x#{amount}" : n = "-#{amount}"
  81.           i_ind = item
  82.         else
  83.           amount > 0 ? n = " #{item.name} x#{amount}" : " #{item.name} -#{amount}"
  84.           i_ind = item.icon_index
  85.         end
  86.         visibility = true
  87.       end
  88.       if $disposetime.size >= 11
  89.         $names.shift
  90.         $disposetime.shift
  91.         $icons_index.shift
  92.         $name_sizes.shift
  93.       end
  94.       $names.push(n) if n != " "
  95.       $icons_index.push(i_ind) if i_ind != 0
  96.       $disposetime[0] == 0 ? $disposetime[0] = Simple_Popup::SHOWING_TIME : $disposetime.push(Simple_Popup::SHOWING_TIME)
  97.       $names.each { |nm| $name_sizes.push(nm.size) }
  98.       sz = $names.size
  99.       sz = 11 if $names.size > 11
  100.      
  101.       if visibility == true
  102.         @w = 32 + 30 + (f_s * $name_sizes.max) + n.size
  103.         @h = 32 + (24 * sz)
  104.         @x = $game_player.screen_x - @w / 2
  105.         @x = 0 if @x < 0
  106.         if @x + @w > Graphics.width
  107.           x = @x
  108.           w = @w
  109.           while x + w > Graphics.width
  110.             x -= 1
  111.           end
  112.           @x = x
  113.         end
  114.         @y = $game_player.screen_y - @h - 32
  115.         @y = $game_player.screen_y if $game_player.screen_y < 64
  116.         if @y < 0
  117.           @y = 0
  118.           @x = $game_player.screen_x + 16
  119.           @x = $game_player.screen_x - 16 - @w if @x + @w > Graphics.width
  120.         end
  121.         $my_message = Window_Base.new(@x, @y, @w, @h)
  122.         $my_message.openness = 0
  123.         $my_message.open
  124.         if $game_variables[Simple_Popup::VARIABLE_FOR_STYLE] == 1; $my_message.windowskin = shadow_back; end
  125.         if $game_variables[Simple_Popup::VARIABLE_FOR_STYLE] == 2; $my_message.windowskin = nograf; end
  126.         $my_message.visible = visibility
  127.         (0..10).each do |i|
  128.           if $names != nil
  129.             if $names[i] != nil
  130.               if i == 0 and sz == 11
  131.                 out_name = MOR_STU
  132.                 out_icon = MOR_STU_ICON
  133.               else
  134.                 if Simple_Popup::FOUNDED != ""
  135.                   if $names[0] != Simple_Popup::FOUNDED
  136.                     $names.unshift(Simple_Popup::FOUNDED)
  137.                     $disposetime.unshift(Simple_Popup::SHOWING_TIME)
  138.                     $icons_index.unshift(0)
  139.                     $name_sizes.unshift(Simple_Popup::FOUNDED.size)
  140.                   end
  141.                 end
  142.                 out_name = $names[i]
  143.                 out_icon = $icons_index[i]
  144.               end
  145.               $my_message.draw_icon(out_icon, 0, 24 * i)
  146.               $my_message.draw_currency_value2(out_name, "", 0, 24 * i, @w - 24)
  147.             end
  148.           end
  149.         end
  150.       end
  151.     end
  152.   end
  153. end
  154. class Scene_Base
  155.   alias dispose_update update
  156.   def update
  157.     if SceneManager.scene_is?(Scene_Title)
  158.       $my_message = nil if $my_message != nil
  159.     end
  160.     if Simple_Popup::POP_UP_ON
  161.       $my_message.update if $my_message != nil
  162.       if $disposetime != nil
  163.         if $disposetime.index(nil) != nil
  164.           $disposetime.compact!  
  165.         end
  166.         if $disposetime.max != nil
  167.           if $disposetime.max > 0
  168.             $disposetime.collect! { |x| x -= 1 if x > 0}
  169.           elsif $disposetime.max == 0
  170.             $my_message.close if $my_message != nil
  171.             $names = []
  172.             $icons_index = []
  173.             $name_sizes = []
  174.             $disposetime = []
  175.           end
  176.         end
  177.       end
  178.     end
  179.     dispose_update
  180.   end
  181. end
  182.  
  183. #==============================================================================
  184. # ** Window_Base
  185. #------------------------------------------------------------------------------
  186. #  This is a super class of all windows within the game.
  187. #==============================================================================
  188.  
  189. class Window_Base < Window
  190.   def draw_currency_value2(value, unit, x, y, width)
  191.     cx = text_size(unit).width
  192.     change_color(normal_color)
  193.     draw_text(x, y, width - cx - 2, line_height, value, 2)
  194.     change_color(system_color)
  195.     draw_text(x, y, width, line_height, unit, 2)
  196.   end
  197. end
  198. class Game_Interpreter
  199.   #--------------------------------------------------------------------------
  200.   # * Change Gold
  201.   #--------------------------------------------------------------------------
  202.   def command_125
  203.     value = operate_value(@params[0], @params[1], @params[2])
  204.     Simple_Popup.show_items(Simple_Popup::MONEY, value)
  205.     $game_party.gain_gold(value)
  206.   end
  207.   #--------------------------------------------------------------------------
  208.   # * Change Items
  209.   #--------------------------------------------------------------------------
  210.   def command_126
  211.     value = operate_value(@params[1], @params[2], @params[3])
  212.     Simple_Popup.show_items($data_items[@params[0]], value)
  213.     $game_party.gain_item($data_items[@params[0]], value)
  214.   end
  215.   #--------------------------------------------------------------------------
  216.   # * Change Weapons
  217.   #--------------------------------------------------------------------------
  218.   def command_127
  219.     value = operate_value(@params[1], @params[2], @params[3])
  220.     Simple_Popup.show_items($data_weapons[@params[0]], value)
  221.     $game_party.gain_item($data_weapons[@params[0]], value, @params[4])
  222.   end
  223.   #--------------------------------------------------------------------------
  224.   # * Change Armor
  225.   #--------------------------------------------------------------------------
  226.   def command_128
  227.     value = operate_value(@params[1], @params[2], @params[3])
  228.     Simple_Popup.show_items($data_armors[@params[0]], value)
  229.     $game_party.gain_item($data_armors[@params[0]], value, @params[4])
  230.   end
  231. end
  232. 1
  233. Downloading1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement