Guest User

Shopaholic Page 7

a guest
Jul 29th, 2012
20
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #-------------------------------------------------------------------------------
  2. # page 7 of 12
  3. # Shopoholic v 2.0
  4. # code by cmpsr2000
  5. # available exclusively @ rpgrevolution.com/forums
  6. # Released June 25, 2008
  7. #
  8. #-------------------------------------------------------------------------------
  9. class Window_Bank_Vault < Window_Selectable
  10. #-----------------------------------------------------------------------------
  11. # Creates the bank vault window
  12. # x: The x-coordinate of the window
  13. # y: The y-coordinate of the window
  14. # bankID: The ID of the bank creating the window
  15. #-----------------------------------------------------------------------------
  16. def initialize(x, y, bankID)
  17. super(x, y, 304, 304)
  18. @bankID = bankID
  19. @column_max = 8
  20. @boxLabel = "Safety Deposit Boxes"
  21. @buyBoxesLabel = "Buy more boxes"
  22. refresh
  23. self.index = 0
  24. end
  25. #-----------------------------------------------------------------------------
  26. # Refreshes the contents of the window
  27. #-----------------------------------------------------------------------------
  28. def refresh
  29. @data = []
  30. @data.push(nil) #for heading
  31. for slot in $game_banking.bankVaults[@bankID]
  32. @data.push(slot)
  33. end
  34. @data.push(nil) #for buying more slots
  35. @item_max = @data.length
  36. create_contents
  37. for i in 0...@item_max
  38. if @data[i] != nil
  39. draw_item(i)
  40. else
  41. draw_label(i)
  42. end
  43. end
  44. if self.index > @item_max - 1
  45. self.index = @item_max - 1
  46. end
  47. end
  48. #-----------------------------------------------------------------------------
  49. # Determines the rectangle for the specified object index
  50. # index: The index of the object that needs a rectangle
  51. #-----------------------------------------------------------------------------
  52. def item_rect(index)
  53. rect = Rect.new(0, 0, 0, 0)
  54. if index == 0 or index == @data.length - 1
  55. rect.width = contents.width
  56. rect.height = WLH
  57. rect.x = 0
  58. rect.y = index == 0 ? 0 : WLH + (28 * ((@data.length - 2).to_f / @column_max).ceil)
  59. else
  60. rect.width = 28
  61. rect.height = 28
  62. rect.x = ((index - 1) % @column_max * (rect.width)) + 24
  63. rect.y = ((index - 1) / @column_max * rect.height) + WLH
  64. end
  65. return rect
  66. end
  67. #-----------------------------------------------------------------------------
  68. # Draws the label for the specified object index
  69. # index: The index of the label
  70. #-----------------------------------------------------------------------------
  71. def draw_label(index)
  72. rect = item_rect(index)
  73. self.contents.clear_rect(rect)
  74. self.contents.font.color = system_color
  75. self.contents.font.color.alpha = 255
  76. width = contents.width
  77. if index == 0
  78. self.contents.draw_text(rect.x, rect.y, width, WLH, @boxLabel, 1)
  79. else
  80. self.contents.draw_text(rect.x, rect.y, width, WLH, @buyBoxesLabel, 1)
  81. end
  82. end
  83. #-----------------------------------------------------------------------------
  84. # Draws the item for the specified object index
  85. # index: The index of the item
  86. #-----------------------------------------------------------------------------
  87. def draw_item(index)
  88. slot = @data[index]
  89. enabled = !slot.locked
  90. rect = item_rect(index)
  91. self.contents.clear_rect(rect)
  92. x = rect.x
  93. y = rect.y
  94. draw_icon(slot.icon_index, x + 2, y + 2, enabled)
  95. if slot.item != nil
  96. draw_icon(slot.item.icon_index, x + 2, y + 2, false)
  97. self.contents.font.color = text_color(6) #yellow
  98. self.contents.font.size = 16
  99. self.contents.font.color.alpha = 255
  100. self.contents.draw_text(x + 1, y + 2, 24, 16, slot.amount.to_s, 2)
  101. self.contents.font.size = 20
  102. end
  103. end
  104. #--------------------------------------------------------------------------
  105. # * Move cursor down
  106. # wrap : Wraparound allowed
  107. #--------------------------------------------------------------------------
  108. def cursor_down(wrap = false)
  109. if (@index < @item_max - 1)
  110. if @index == 0
  111. @index = 1
  112. else
  113. @index = (@index + @column_max)
  114. if @index > @item_max -1
  115. @index = @item_max - 1
  116. end
  117. end
  118. end
  119. end
  120. #--------------------------------------------------------------------------
  121. # * Move cursor up
  122. # wrap : Wraparound allowed
  123. #--------------------------------------------------------------------------
  124. def cursor_up(wrap = false)
  125. if (@index > 0)
  126. if @index == @item_max - 1
  127. move = ((@item_max - 2) % @column_max)
  128. move = @column_max if move == 0
  129. @index -= move
  130. else
  131. @index = @index - @column_max
  132. if @index < 0
  133. @index = 0
  134. end
  135. end
  136. end
  137. end
  138. #--------------------------------------------------------------------------
  139. # * Move cursor right
  140. # wrap : Wraparound allowed
  141. #--------------------------------------------------------------------------
  142. def cursor_right(wrap = false)
  143. if (@column_max >= 2) and (@index < @item_max - 1)
  144. @index = (@index + 1) % @item_max
  145. end
  146. end
  147. #--------------------------------------------------------------------------
  148. # * Move cursor left
  149. # wrap : Wraparound allowed
  150. #--------------------------------------------------------------------------
  151. def cursor_left(wrap = false)
  152. if (@column_max >= 2) and (@index > 0)
  153. @index = (@index - 1 + @item_max) % @item_max
  154. end
  155. end
  156. #-----------------------------------------------------------------------------
  157. # Returns the slot object at the currently highlighted index
  158. # RETURNS: Storage_Slot
  159. #-----------------------------------------------------------------------------
  160. def slot
  161. return @data[@index]
  162. end
  163. end
RAW Paste Data