Heartbreak61

「SIMPLE STUPID」 Item Filter ver.0.61

Jul 1st, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.31 KB | None | 0 0
  1. #==============================================================================
  2. # ■ 「SIMPLE STUPID」 Item Filter ver.0.61
  3. # by HBK61
  4. # Requires: N/A
  5. # Rewrites method:
  6. #   Window_ItemList#make_item_list
  7. # Aliases method:
  8. #   Window_ItemList#initialize
  9. #   Scene_Item#start
  10. #   Scene_Item#create_category_window
  11. #   Scene_Item#create_item_window
  12. #              
  13. #==============================================================================
  14. # CHANGELOG
  15. # - ver0.60  2013.07.01   Started the script & finished
  16. # - ver0.61  2013.07.01   Add sorting function
  17. #==============================================================================
  18. # INTRODUCTION
  19. # - Simply stupidly add filtering & sorting function in Scene Item.
  20. #==============================================================================
  21. # INSTRUCTION
  22. # - Simply write "<category(space)=(space)my_category>" (without quotes)
  23. #   in item's/weapon's/armor's note.
  24. # example:
  25. #   <category = loot_items>
  26. #==============================================================================
  27.  
  28. module HBK
  29.   module ITEM_TAB
  30.     #enable/disable
  31.     ENABLED = true
  32.    
  33.     # use "_" for space & no upcase!
  34.     FILTER =[
  35.     :alchemy,
  36.     :tradeable,
  37.     :loots,
  38.     :crap,
  39.     ]
  40.     CAT_HELP_TEXT = "←→:Category select\nA: Organize B:Back C:Decision"
  41.    
  42.   end #ITEM_TAB
  43. end #HBK
  44.  
  45. if HBK::ITEM_TAB::ENABLED
  46.  
  47. #==============================================================================
  48. # ■ Window_ItemCategory
  49. #==============================================================================
  50. class Window_ItemCategory < Window_HorzCommand
  51.   def process_handling
  52.     super
  53.     return process_extend if handle?(:extend) && Input.trigger?(:A) && active
  54.   end
  55.  
  56.   def process_extend
  57.     Sound.play_ok
  58.     Input.update
  59.     call_handler(:extend)
  60.   end
  61.  
  62.   def update_help
  63.     @help_window.set_text(HBK::ITEM_TAB::CAT_HELP_TEXT)
  64.   end
  65. end #Window_ItemCategory
  66.  
  67. #==============================================================================
  68. # ■ Window_ItemList
  69. #==============================================================================
  70. class Window_ItemList < Window_Selectable
  71.   alias hbk_ssit_initialize initialize
  72.   def initialize(x, y, width, height)
  73.     hbk_ssit_initialize(x, y, width, height)
  74.     @filter = :none
  75.     @sort = :none
  76.   end
  77.  
  78.   def process_handling
  79.     super
  80.     return process_extend if handle?(:extend) && Input.trigger?(:A) && active
  81.   end
  82.  
  83.   def process_extend
  84.     Sound.play_ok
  85.     Input.update
  86.     call_handler(:extend)
  87.   end
  88.  
  89.   def filter=(filter)
  90.     return if @filter == filter
  91.     @filter = filter
  92.     refresh
  93.     self.oy = 0
  94.   end
  95.  
  96.   def filter?(item)
  97.     return false if item.nil?
  98.     if HBK::ITEM_TAB::FILTER.include?(@filter)
  99.       item.note.include?("<category = " + @filter.to_s + ">")
  100.     elsif @filter == :no_filter
  101.       true
  102.     else
  103.       false
  104.     end
  105.   end
  106.  
  107.   def sorting=(value)
  108.     return if @sorting == value
  109.     @sorting = value
  110.     refresh
  111.     self.oy = 0
  112.   end
  113.  
  114.   #--------------------------------------------------------------------------
  115.   # ● rewrite
  116.   #--------------------------------------------------------------------------
  117.   def make_item_list
  118.     @data = $game_party.all_items.select {|item|
  119.       ( include?(item) && filter?(item) )
  120.     }
  121.     @data.push(nil) if include?(nil)
  122.     #~~
  123.     if @sorting == :default
  124.       return
  125.     elsif @sorting == :alphabet_a
  126.       @data.sort!{|a,b| a.name <=> b.name}
  127.     elsif @sorting == :alphabet_d
  128.       @data.sort!{|a,b| b.name <=> a.name}
  129.     elsif @sorting == :quantity_a
  130.       @data.sort!{|a,b|
  131.         $game_party.item_number(a) - $game_party.item_number(b) }
  132.     elsif @sorting == :quantity_d
  133.       @data.sort!{|a,b|
  134.         $game_party.item_number(b) - $game_party.item_number(a) }
  135.     elsif @sorting == :price_a
  136.       @data.sort!{|a,b| a.price - b.price}
  137.     elsif @sorting == :price_d
  138.       @data.sort!{|a,b| b.price - a.price}
  139.     end
  140.     #~~
  141.   end
  142. end #Window_ItemList
  143.  
  144.  
  145. #==============================================================================
  146. # ■ Window_ItemOrganizer
  147. #==============================================================================
  148. class Window_ItemOrganizer < Window_Command
  149.   def initialize(x,y)
  150.     super(x,y)
  151.     @previous = nil
  152.   end
  153.  
  154.   def window_width
  155.     return 180
  156.   end
  157.  
  158.   def make_command_list
  159.     add_command("Filter", :filter)
  160.     add_command("Sort", :sort)
  161.   end
  162.   attr_accessor :previous
  163. end #Window_ItemOrganizer
  164.  
  165. #==============================================================================
  166. # ■ Window_ItemSort
  167. #==============================================================================
  168. class Window_ItemSort < Window_Command
  169.   def initialize(x,y)
  170.     super(x,y)
  171.   end
  172.  
  173.   def window_width
  174.     return 180
  175.   end
  176.  
  177.   def make_command_list
  178.     add_command("Default", :default)
  179.     add_command("Alphabet ↑", :alphabet_a)
  180.     add_command("Alphabet ↓", :alphabet_d)
  181.     add_command("Quantity ↑", :quantity_a)
  182.     add_command("Quantity ↓", :quantity_d)
  183.     add_command("Price ↑", :price_a)
  184.     add_command("Price ↓", :price_d)
  185.   end
  186. end #Window_ItemSort
  187.  
  188. #==============================================================================
  189. # ■ Window_ItemFilter
  190. #==============================================================================
  191. class Window_ItemFilter < Window_Command
  192.   def window_width
  193.     return 180
  194.   end
  195.  
  196.   def make_command_list
  197.     add_command("Clear Filter", :no_filter)
  198.     HBK::ITEM_TAB::FILTER.size.times{|i|
  199.       sym = HBK::ITEM_TAB::FILTER[i]
  200.       next if sym.nil?
  201.       txt = sym.to_s.capitalize
  202.       txt.gsub!(/_/) {" "}
  203.       txt.gsub!(/(\s\w)/) {$&.upcase}
  204.       add_command(txt, sym)
  205.       }
  206.   end
  207. end #Window_ItemSort
  208.  
  209. #==============================================================================
  210. # ■ Scene_Item
  211. #==============================================================================
  212. class Scene_Item
  213.   alias hbk_ssit_start start
  214.   def start
  215.     hbk_ssit_start
  216.     create_item_organizer_window
  217.     create_item_filter_window
  218.     create_item_sort_window
  219.   end
  220.  
  221.   alias hbk_ssit_create_category_window create_category_window
  222.   def create_category_window
  223.     hbk_ssit_create_category_window
  224.     @category_window.set_handler(:extend, method(:category_window_pre_organize))
  225.   end
  226.  
  227.   alias hbk_ssit_create_item_window create_item_window
  228.   def create_item_window
  229.     hbk_ssit_create_item_window
  230.     @item_window.set_handler(:extend, method(:item_window_pre_organize))
  231.     @item_window.filter = :no_filter
  232.     @item_window.sorting = :default
  233.   end
  234.  
  235.   def create_item_organizer_window
  236.     @organizer_window = Window_ItemOrganizer.new(0,0)
  237.     @organizer_window.hide
  238.     @organizer_window.close
  239.     @organizer_window.x = Graphics.width - @organizer_window.width
  240.     @organizer_window.y = @help_window.height
  241.     @organizer_window.z = @viewport.z + 1
  242.     @organizer_window.set_handler(:filter, method(:open_next_window))
  243.     @organizer_window.set_handler(:sort, method(:open_next_window))
  244.     @organizer_window.set_handler(:cancel, method(:return_prev_window))
  245.   end
  246.  
  247.   def create_item_filter_window
  248.     @filter_window = Window_ItemFilter.new(0,0)
  249.     @filter_window.hide
  250.     @filter_window.close
  251.     @filter_window.x = @organizer_window.x
  252.     @filter_window.y = @organizer_window.y
  253.     @filter_window.z = @organizer_window.z + 1
  254.     @filter_window.set_handler(:ok, method(:on_filter_ok))
  255.     @filter_window.set_handler(:cancel, method(:return_organizer))
  256.   end
  257.  
  258.   def create_item_sort_window
  259.     @sort_window = Window_ItemSort.new(0,0)
  260.     @sort_window.hide
  261.     @sort_window.close
  262.     @sort_window.x = @organizer_window.x
  263.     @sort_window.y = @organizer_window.y
  264.     @sort_window.z = @organizer_window.z + 1
  265.     @sort_window.set_handler(:ok, method(:on_sort_ok))
  266.     @sort_window.set_handler(:cancel, method(:return_organizer))
  267.   end
  268.  
  269.   def item_window_pre_organize
  270.     @item_window.deactivate
  271.     @organizer_window.previous = @item_window
  272.     start_organizer
  273.   end
  274.  
  275.   def category_window_pre_organize
  276.     @category_window.deactivate
  277.     @organizer_window.previous = @category_window
  278.     start_organizer
  279.   end
  280.  
  281.   def start_organizer
  282.     @organizer_window.show
  283.     @organizer_window.open
  284.     @organizer_window.activate
  285.   end
  286.  
  287.   def open_next_window
  288.     @organizer_window.close
  289.     @organizer_window.deactivate
  290.     if @organizer_window.current_symbol == :filter
  291.       @filter_window.show
  292.       @filter_window.open
  293.       @filter_window.activate
  294.     elsif @organizer_window.current_symbol == :sort
  295.       @sort_window.show
  296.       @sort_window.open
  297.       @sort_window.activate
  298.     end
  299.   end
  300.  
  301.   def return_prev_window
  302.     @organizer_window.close
  303.     @organizer_window.deactivate
  304.     @organizer_window.previous.activate
  305.     @organizer_window.previous = nil
  306.   end
  307.  
  308.   def on_filter_ok
  309.     @item_window.filter = @filter_window.current_symbol
  310.     return_organizer
  311.   end
  312.  
  313.   def on_sort_ok
  314.     @item_window.sorting = @sort_window.current_symbol
  315.     return_organizer
  316.   end
  317.  
  318.   def return_organizer
  319.     @filter_window.close
  320.     @filter_window.deactivate
  321.     @sort_window.close
  322.     @sort_window.deactivate
  323.     @organizer_window.open
  324.     @organizer_window.activate
  325.   end
  326. end #Scene_Item
  327.  
  328. end #if HBK::ITEM_TAB::ENABLED
Advertisement
Add Comment
Please, Sign In to add comment