Advertisement
roninator2

Yanfly Shop Options - Buy categories

Dec 8th, 2024
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.82 KB | None | 0 0
  1. # modifies the shop option for yanfly to include categories for buying.
  2.  
  3. class Window_ShopBuy < Window_Selectable
  4.  
  5.   def category=(category)
  6.     return if @category == category
  7.     @category = category
  8.     refresh
  9.     self.oy = 0
  10.   end
  11.  
  12.   def make_item_list
  13.     @data = []
  14.     @price = {}
  15.     categories = { :item => 0,:weapon => 1 ,:armor => 2, :key_item => 0 }
  16.     @shop_goods.each do |goods|
  17.       next unless goods[0] == categories[@category]
  18.       case goods[0]
  19.       when 0;  item = $data_items[goods[1]]
  20.       when 1;  item = $data_weapons[goods[1]]
  21.       when 2;  item = $data_armors[goods[1]]
  22.       end
  23.       if item
  24.         next if (@category == :item && item.key_item?)
  25.         next if (@category == :key_item && !item.key_item?)
  26.         @data.push(item)
  27.         @price[item] = goods[2] == 0 ? item.price : goods[3]
  28.       end
  29.     end
  30.   end
  31. end
  32.  
  33. class Scene_Shop < Scene_MenuBase
  34.  
  35.   alias scene_shop_start_r2 start
  36.   def start
  37.     scene_shop_start_r2
  38.     create_buy_category_window
  39.   end
  40.  
  41.   def create_buy_window
  42.     wy = @dummy_window.y
  43.     wh = @dummy_window.height
  44.     @buy_window = Window_ShopBuy.new(0, wy, wh, @goods)
  45.     @buy_window.viewport = @viewport
  46.     @buy_window.help_window = @help_window
  47.     @buy_window.status_window = @status_window
  48.     @buy_window.hide
  49.     @buy_window.set_handler(:ok,     method(:on_buy_ok))
  50.     @buy_window.set_handler(:cancel, method(:on_buy_cancel))
  51.   end
  52.  
  53.   def command_buy
  54.     @dummy_window.hide
  55.     @buy_category_window.x = 0
  56.     @command_window.x = Graphics.width
  57.     @buy_window.x = 0
  58.     @sell_window.x = Graphics.width
  59.     @buy_window.unselect
  60.     @buy_window.refresh
  61.     @data_window.item_window = @buy_window
  62.     @buy_window.show
  63.     @status_window.show
  64.     @buy_category_window.show.activate
  65.     @buy_category_window.item_window = @buy_window
  66.   end
  67.  
  68.   def activate_buy_window
  69.     @buy_window.show
  70.     @buy_window.money = money
  71.     @buy_window.show.activate
  72.     @status_window.show
  73.   end
  74.  
  75.   def on_buy_cancel
  76.     @dummy_window.show
  77.     @status_window.item = nil
  78.     @help_window.clear
  79.     @buy_category_window.activate
  80.   end
  81.  
  82.   def create_buy_category_window
  83.     @buy_category_window = Window_ShopCategory.new
  84.     @buy_category_window.viewport = @viewport
  85.     @buy_category_window.help_window = @help_window
  86.     @buy_category_window.y = @category_window.y
  87.     @buy_category_window.hide.deactivate
  88.     @buy_category_window.set_handler(:ok,     method(:on_buy_category_ok))
  89.     @buy_category_window.set_handler(:cancel, method(:on_buy_category_cancel))
  90.   end
  91.  
  92.   def on_buy_category_ok
  93.     activate_buy_window
  94.     @buy_window.select(0)
  95.   end
  96.  
  97.   def on_buy_category_cancel
  98.     on_category_cancel
  99.     @buy_category_window.hide
  100.     @buy_window.deactivate
  101.     @status_window.item = nil
  102.     @help_window.clear
  103.   end  
  104.  
  105. end
  106.  
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement