Guest User

Window_ShopBuy

a guest
Jun 22nd, 2014
192
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. # ** Window_ShopBuy
  3. #------------------------------------------------------------------------------
  4. # This window displays a list of buyable goods on the shop screen.
  5. #==============================================================================
  6.  
  7. class Window_ShopBuy < Window_Selectable
  8. #--------------------------------------------------------------------------
  9. # * Public Instance Variables
  10. #--------------------------------------------------------------------------
  11. attr_reader :status_window # Status window
  12. #--------------------------------------------------------------------------
  13. # * Object Initialization
  14. #--------------------------------------------------------------------------
  15. def initialize(x, y, height, shop_goods)
  16. super(x, y, window_width, height)
  17. @shop_goods = shop_goods
  18. @money = 0
  19. refresh
  20. select(0)
  21. end
  22. #--------------------------------------------------------------------------
  23. # * Get Window Width
  24. #--------------------------------------------------------------------------
  25. def window_width
  26. return 304
  27. end
  28. #--------------------------------------------------------------------------
  29. # * Get Number of Items
  30. #--------------------------------------------------------------------------
  31. def item_max
  32. @data ? @data.size : 1
  33. end
  34. #--------------------------------------------------------------------------
  35. # * Get Item
  36. #--------------------------------------------------------------------------
  37. def item
  38. @data[index]
  39. end
  40. #--------------------------------------------------------------------------
  41. # * Set Party Gold
  42. #--------------------------------------------------------------------------
  43. def money=(money)
  44. @money = money
  45. refresh
  46. end
  47. #--------------------------------------------------------------------------
  48. # * Get Activation State of Selection Item
  49. #--------------------------------------------------------------------------
  50. def current_item_enabled?
  51. enable?(@data[index])
  52. end
  53. #--------------------------------------------------------------------------
  54. # * Get Price of Item
  55. #--------------------------------------------------------------------------
  56. def price(item)
  57. @price[item]
  58. end
  59. #--------------------------------------------------------------------------
  60. # * Display in Enabled State?
  61. #--------------------------------------------------------------------------
  62. def enable?(item)
  63. item && price(item) <= @money && !$game_party.item_max?(item)
  64. end
  65. #--------------------------------------------------------------------------
  66. # * Refresh
  67. #--------------------------------------------------------------------------
  68. def refresh
  69. make_item_list
  70. create_contents
  71. draw_all_items
  72. end
  73. #--------------------------------------------------------------------------
  74. # * Create Item List
  75. #--------------------------------------------------------------------------
  76. def make_item_list
  77. @data = []
  78. @price = {}
  79. @shop_goods.each do |goods|
  80. case goods[0]
  81. when 0; item = $data_items[goods[1]]
  82. when 1; item = $data_weapons[goods[1]]
  83. when 2; item = $data_armors[goods[1]]
  84. end
  85. if item
  86. @data.push(item)
  87. @price[item] = goods[2] == 0 ? item.price : goods[3]
  88. end
  89. end
  90. end
  91. #--------------------------------------------------------------------------
  92. # * Draw Item
  93. #--------------------------------------------------------------------------
  94. def draw_item(index)
  95. item = @data[index]
  96. rect = item_rect(index)
  97. draw_item_name(item, rect.x, rect.y, enable?(item))
  98. rect.width -= 4
  99. draw_text(rect, price(item), 2)
  100. end
  101. #--------------------------------------------------------------------------
  102. # * Set Status Window
  103. #--------------------------------------------------------------------------
  104. def status_window=(status_window)
  105. @status_window = status_window
  106. call_update_help
  107. end
  108. #--------------------------------------------------------------------------
  109. # * Update Help Text
  110. #--------------------------------------------------------------------------
  111. def update_help
  112. @help_window.set_item(item) if @help_window
  113. @status_window.item = item if @status_window
  114. end
  115. end
RAW Paste Data