Guest User

Manual Item Sorting v1.0

a guest
Oct 22nd, 2013
440
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # ------------------------------------------------------------------------------
  2. # Manual Item Sorting v1.0
  3. # FenixFyreX
  4. # RPG Maker VXAce
  5. # ------------------------------------------------------------------------------
  6. # This script allows manual sorting of items, weapons, armors, and skills.
  7. # It is completely Plug-and-Play.
  8. # All you do is select each item once to move items around. Selecting the same
  9. # item twice selects the item like normal.
  10. # ------------------------------------------------------------------------------
  11. # DO NOT EDIT BELOW UNLESS YOU KNOW WHAT YOU ARE DOING
  12. # ------------------------------------------------------------------------------
  13.  
  14. class Game_System
  15.   attr_reader :item_order, :weapon_order, :armor_order, :skill_order
  16.   alias initialize_item_skill_order_fyx initialize
  17.   def initialize(*argv, &argb)
  18.     initialize_item_skill_order_fyx(*argv, &argb)
  19.     setup_orders
  20.   end
  21.  
  22.   def setup_orders
  23.     @item_order = $data_items.map {|item| item ? item.id : 0 }
  24.     @weapon_order = $data_weapons.map {|wep| wep ? wep.id : 0 }
  25.     @armor_order = $data_armors.map {|arm| arm ? arm.id : 0 }
  26.     @skill_order = []
  27.     $data_actors.each do |actor|
  28.       if actor
  29.         @skill_order[actor.id] = $data_skills.map {|skill| skill ? skill.id : 0 }
  30.       end
  31.     end
  32.   end
  33.  
  34.   def swap_item_order(id, id2)
  35.     idx1 = @item_order.index(id)
  36.     idx2 = @item_order.index(id2)
  37.    
  38.     @item_order[idx1], @item_order[idx2] = @item_order[idx2], @item_order[idx1]
  39.   end
  40.  
  41.   def swap_weapon_order(id, id2)
  42.     idx1 = @weapon_order.index(id)
  43.     idx2 = @weapon_order.index(id2)
  44.    
  45.     @weapon_order[idx1], @weapon_order[idx2] = @weapon_order[idx2], @weapon_order[idx1]
  46.   end
  47.  
  48.   def swap_armor_order(id, id2)
  49.     idx1 = @armor_order.index(id)
  50.     idx2 = @armor_order.index(id2)
  51.    
  52.     @armor_order[idx1], @armor_order[idx2] = @armor_order[idx2], @armor_order[idx1]
  53.   end
  54.  
  55.   def swap_skill_order(aid, id, id2)
  56.     idx1 = @skill_order[aid].index(id)
  57.     idx2 = @skill_order[aid].index(id2)
  58.    
  59.     @skill_order[aid][idx1], @skill_order[aid][idx2] =
  60.     @skill_order[aid][idx2], @skill_order[aid][idx1]
  61.   end
  62. end
  63.  
  64. class Window_Selectable
  65.  
  66.   def draw_item_cursor_fade(index)
  67.     contents.fill_rect(item_rect(index), Color.new(0,0,0,100))
  68.   end
  69. end
  70.  
  71. class Window_ItemList
  72.  
  73.   def process_ok
  74.     if (@bypass_switch_ids && (item.id == @bypass_index))
  75.       @bypass_switch_ids = @bypass_index = nil
  76.       super
  77.     elsif (@bypass_switch_ids && (item.id != @bypass_index))
  78.       process_switch_order
  79.     elsif !@bypass_switch_ids
  80.       if item
  81.         Sound.play_ok
  82.         @bypass_switch_ids = true
  83.         @bypass_index = item ? item.id : 0
  84.         refresh
  85.       else
  86.         @bypass_switch_ids = @bypass_index = nil
  87.         super
  88.       end
  89.     end
  90.   end
  91.  
  92.   alias process_cancel_bypass_swap process_cancel
  93.   def process_cancel(*argv, &argb)
  94.     @bypass_switch_ids = @bypass_index = nil
  95.     refresh
  96.     process_cancel_bypass_swap(*argv, &argb)
  97.   end
  98.  
  99.   def process_switch_order
  100.     Sound.play_ok
  101.     swap_order(@bypass_index, item.id)
  102.     @bypass_index = @bypass_switch_ids = nil
  103.     refresh
  104.   end
  105.  
  106.   def system_order_container
  107.     case @category
  108.     when :none
  109.       []
  110.     when :item, :key_item
  111.       $game_system.item_order
  112.     when :weapon
  113.       $game_system.weapon_order
  114.     when :armor
  115.       $game_system.armor_order
  116.     end
  117.   end
  118.  
  119.   def swap_order(id1, id2)
  120.     case @category
  121.     when :item, :key_item
  122.       $game_system.swap_item_order(id1, id2)
  123.     when :weapon
  124.       $game_system.swap_weapon_order(id1, id2)
  125.     when :armor
  126.       $game_system.swap_armor_order(id1, id2)
  127.     end
  128.   end
  129.  
  130.   alias sort_item_list_fyx make_item_list
  131.   def make_item_list(*argv, &argb)
  132.     sort_item_list_fyx(*argv, &argb)
  133.     @data.sort_by! do |item|
  134.       item ? system_order_container.index(item.id) : 0
  135.     end
  136.     @data
  137.   end
  138.  
  139.   alias draw_item_fyx_swap_fade draw_item
  140.   def draw_item(index, *argv, &argb)
  141.     if @bypass_switch_ids
  142.       idx = @data.index(@data.find {|i| i.id == @bypass_index})
  143.       draw_item_cursor_fade(idx) if idx == index
  144.     end
  145.     draw_item_fyx_swap_fade(index, *argv, &argb)
  146.   end
  147. end
  148.  
  149. class Window_SkillList
  150.   def process_ok
  151.     if (@bypass_switch_ids && (item.id == @bypass_index))
  152.       super
  153.     elsif (@bypass_switch_ids && (item.id != @bypass_index))
  154.       process_switch_order
  155.     elsif !@bypass_switch_ids
  156.       Sound.play_ok
  157.       @bypass_switch_ids = true
  158.       @bypass_index = item.id
  159.       refresh
  160.     end
  161.   end
  162.  
  163.   alias process_cancel_bypass_swap process_cancel
  164.   def process_cancel(*argv, &argb)
  165.     @bypass_switch_ids = @bypass_index = nil
  166.     refresh
  167.     process_cancel_bypass_swap(*argv, &argb)
  168.   end
  169.  
  170.   def process_switch_order
  171.     Sound.play_ok
  172.     $game_system.swap_skill_order(@actor.id, @bypass_index, item.id)
  173.     @bypass_index = -1000
  174.     @bypass_switch_ids = false
  175.     refresh
  176.   end
  177.  
  178.   alias sort_item_list_fyx make_item_list
  179.   def make_item_list(*argv, &argb)
  180.     sort_item_list_fyx(*argv, &argb)
  181.     @data.sort_by! do |item|
  182.       $game_system.skill_order[@actor.id].index(item.id)
  183.     end
  184.     @data
  185.   end
  186.  
  187.   alias draw_item_fyx_swap_fade draw_item
  188.   def draw_item(index, *argv, &argb)
  189.     if @bypass_switch_ids
  190.       idx = @data.index(@data.find {|i| i.id == @bypass_index})
  191.       draw_item_cursor_fade(idx) if idx == index
  192.     end
  193.     draw_item_fyx_swap_fade(index, *argv, &argb)
  194.   end
  195. end
  196. # ------------------------------------------------------------------------------
  197. # END OF SCRIPT
  198. # ------------------------------------------------------------------------------
RAW Paste Data