Advertisement
khanhdu

Galv's New Item Indication

May 19th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.30 KB | None | 0 0
  1. #------------------------------------------------------------------------------#
  2. #  Galv's New Item Indication
  3. #------------------------------------------------------------------------------#
  4. #  For: RPGMAKER VX ACE
  5. #  Version 1.4
  6. #------------------------------------------------------------------------------#
  7. #  2013-07-16 - Version 1.4 - made key items work
  8. #  2013-03-05 - Version 1.3 - fixed bug when all items are new when battle exit
  9. #  2013-03-03 - Version 1.2 - added script call to manually remove 'new' images
  10. #                           - fixed unequipping item creating 'new' images
  11. #  2013-03-03 - Version 1.1 - fixed method 2 new not appearing for drops
  12. #  2013-03-03 - Version 1.0 - release
  13. #------------------------------------------------------------------------------#
  14. #  Adds a 'new' image on items in the inventory that the player has recently
  15. #  acquired. There are 2 methods for you to chose from as to when this image
  16. #  appears and when it is removed and no longer counted as new.
  17. #------------------------------------------------------------------------------#
  18. #  SCRIPT CALL
  19. #------------------------------------------------------------------------------#
  20. #
  21. #  clear_new(type)      # Manually removes 'new' images from selected type
  22. #                       # type can be one of the following
  23. #                       # :all    :item     :weapon    :armor
  24. #------------------------------------------------------------------------------#
  25. #  EXAMPLE:
  26. #  clear_new(:item)     # all 'new' image on items will be cleared
  27. #  clear_new(:all)      # all 'new' images on everything will be cleared
  28. #------------------------------------------------------------------------------#
  29.  
  30. ($imported ||= {})["Galv_New_Item_Indicator"] = true
  31. module Galv_Nitem
  32.    
  33. #------------------------------------------------------------------------------#
  34. #  SETUP OPTIONS
  35. #------------------------------------------------------------------------------#
  36.  
  37.   IMAGE = "new_indicator"    # Image located in /Graphics/System/
  38.    
  39.   METHOD = 1     # METHOD option can be 1 or 2 (see below)
  40.  
  41. #------------------------------------------------------------------------------#
  42. #
  43. #   1: The 'new' image appears on items that the player hasn't seen before and
  44. #      is only removed when the player moves the cursor over them (from any
  45. #      scene)
  46. #
  47. #   2: The new image appears for items that are picked up and are removed
  48. #      when the player leaves the item scene OR cursors over the item.
  49. #      Any items picked up again will re-add the 'new' image for the player to
  50. #      see what items they picked up recently. (So if you already had 4 potions
  51. #      and pick up another, potions would have 'new' image again).
  52. #
  53. #------------------------------------------------------------------------------#
  54. #  END SETUP OPTIONS
  55. #------------------------------------------------------------------------------#
  56.  
  57. end
  58.  
  59. class Game_Interpreter
  60.   def clear_new(type)
  61.     if type == :all
  62.       $game_party.nitems[:weapon] = []
  63.       $game_party.nitems[:armor] = []
  64.       $game_party.nitems[:item] = []
  65.     else
  66.       $game_party.nitems[type] = []
  67.     end
  68.   end
  69. end # Game_Interpreter
  70.  
  71.  
  72. module Galv_GetCat
  73.   def get_category(item)
  74.     if item.is_a?(RPG::Item)
  75.       return :item
  76.     elsif item.is_a?(RPG::Weapon)
  77.       return :weapon
  78.     elsif item.is_a?(RPG::Armor)
  79.       return :armor
  80.     else
  81.       return :none
  82.     end
  83.   end
  84. end # Galv_GetCat
  85.  
  86.  
  87. class Window_Help < Window_Base
  88.   include Galv_GetCat
  89.    
  90.   alias galv_nitem_wh_set_item set_item
  91.   def set_item(item)
  92.     galv_nitem_wh_set_item(item)
  93.     add_to_known_items(item)
  94.   end
  95.    
  96.   def add_to_known_items(item)
  97.     category = get_category(item)
  98.     return if category == :none
  99.     if !$game_party.nitems[category][item.id] && Galv_Nitem::METHOD == 1
  100.       $game_party.nitems[category][item.id] = true
  101.     elsif $game_party.nitems[category][item.id] && Galv_Nitem::METHOD == 2
  102.       $game_party.nitems[category][item.id] = false
  103.     end
  104.     SceneManager.scene.refresh_new
  105.   end
  106. end # Window_Help < Window_Base
  107.  
  108.  
  109. class Game_Party < Game_Unit
  110.   attr_accessor :nitems
  111.   include Galv_GetCat
  112.    
  113.   alias galv_nitem_gp_initialize initialize
  114.   def initialize
  115.     @nitems = {:item=>[],:weapon=>[],:armor=>[]}
  116.     galv_nitem_gp_initialize
  117.   end
  118.    
  119.   alias galv_nitem_gp_gain_item gain_item
  120.   def gain_item(item, amount, include_equip = false)
  121.     galv_nitem_gp_gain_item(item, amount, include_equip)
  122.     if Galv_Nitem::METHOD == 2
  123.       last_number = item_number(item)
  124.       new_number = last_number + amount
  125.       if [[new_number, 0].max, max_item_number(item)].min > last_number
  126.         cat = get_category(item)
  127.         return if cat == :none
  128.         $game_party.nitems[cat][item.id] = true
  129.       end
  130.     end
  131.   end
  132. end # Game_Party < Game_Unit
  133.  
  134.  
  135. class Window_ItemList < Window_Selectable
  136.   include Galv_GetCat
  137.    
  138.   alias galv_nitem_wi_draw_item draw_item
  139.   def draw_item(index)
  140.     galv_nitem_wi_draw_item(index)
  141.     item = @data[index]
  142.     return if item.nil?
  143.      
  144.     cat = get_category(item)
  145.     return if cat == :none
  146.     rect = item_rect(index)
  147.     if Galv_Nitem::METHOD == 1 && !$game_party.nitems[cat][item.id] ||
  148.         Galv_Nitem::METHOD == 2 && $game_party.nitems[cat][item.id]
  149.       draw_item_new(item, rect.x, rect.y)
  150.     end
  151.   end
  152.    
  153.   def draw_item_new(item, x, y)
  154.     bitmap = Cache.system(Galv_Nitem::IMAGE)
  155.     rect = Rect.new(0, 0, 24, 24)
  156.     contents.blt(x, y, bitmap, rect, 255)
  157.   end
  158. end # Window_ItemList < Window_Selectable
  159.  
  160.  
  161. class Window_EquipItem
  162.   # If Yanfly's Equip Engine:
  163.   if $imported["YEA-AceEquipEngine"]
  164.     def draw_item(index)
  165.       item = @data[index]
  166.       rect = item_rect(index)
  167.       rect.width -= 4
  168.       if item.nil?
  169.         draw_remove_equip(rect)
  170.         return
  171.       end
  172.       dw = contents.width - rect.x - 24
  173.       draw_item_name(item, rect.x, rect.y, enable?(item), dw)
  174.       draw_item_number(rect, item)
  175.       cat = get_category(item)
  176.       return if cat == :none
  177.       if !$game_party.nitems[cat][item.id] && Galv_Nitem::METHOD == 1 ||
  178.           $game_party.nitems[cat][item.id] && Galv_Nitem::METHOD == 2
  179.         rect = item_rect(index)
  180.         draw_item_new(item, rect.x, rect.y)
  181.       end
  182.     end
  183.   end
  184. end # Window_EquipItem (For Yanfly's Equip Script)
  185.  
  186.  
  187. class Scene_Base
  188.   def refresh_new
  189.     @item_window.refresh if @item_window
  190.   end
  191.    
  192.   alias galv_nitem_sb_return_scene return_scene
  193.   def return_scene
  194.     clear_new if Galv_Nitem::METHOD == 2
  195.     galv_nitem_sb_return_scene
  196.   end
  197.    
  198.   def clear_new
  199.     if SceneManager.scene_is?(Scene_Item)
  200.       $game_party.nitems[:weapon] = []
  201.       $game_party.nitems[:armor] = []
  202.       $game_party.nitems[:item] = []
  203.     end
  204.   end
  205. end # Scene_Base
  206.  
  207.  
  208. class Game_Actor < Game_Battler
  209.   include Galv_GetCat
  210.    
  211.   # OVERWRITE
  212.   def trade_item_with_party(new_item, old_item)
  213.     return false if new_item && !$game_party.has_item?(new_item)
  214.     $game_party.gain_item(old_item, 1)
  215.     $game_party.lose_item(new_item, 1)
  216.     unequipped_not_new(old_item)
  217.     return true
  218.   end
  219.    
  220.   def unequipped_not_new(item)
  221.     cat = get_category(item)
  222.     return if cat == :none || Galv_Nitem::METHOD == 1
  223.     $game_party.nitems[cat][item.id] = false
  224.   end
  225. end # Game_Actor < Game_Battler
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement