Advertisement
LiTTleDRAgo

[RGSS2] DRG Inventory System VX Compatibility Patch

Jul 10th, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 8.84 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # DRG Inventory System VX Compatibility Patch
  3. # Version: 1.00
  4. # Author : LiTTleDRAgo
  5. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  6.                         "Place Above DRG Inventory System"
  7. #==============================================================================
  8. # ** Window_Selectable
  9. #------------------------------------------------------------------------------
  10. #  This window class contains cursor movement and scroll functions.
  11. #==============================================================================
  12. if defined?(Window_ActorCommand)
  13. class Window_Selectable_Drago < Window_Base
  14.   #--------------------------------------------------------------------------
  15.   # * Public Instance Variables
  16.   #--------------------------------------------------------------------------
  17.   attr_reader   :index,:help_window     # cursor position and  help window
  18.   #--------------------------------------------------------------------------
  19.   # * Object Initialization
  20.   #--------------------------------------------------------------------------
  21.   def initialize(x, y, width, height)
  22.     super(x, y, width, height)
  23.     @item_max, @column_max, @index = 1,1,-1
  24.   end
  25.   #--------------------------------------------------------------------------
  26.   # * Set Cursor Position
  27.   #--------------------------------------------------------------------------
  28.   def index=(index)
  29.     @index = index
  30.     update_help if self.active and @help_window != nil
  31.     update_cursor_rect
  32.   end
  33.   #--------------------------------------------------------------------------
  34.   # * Get Row Count
  35.   #--------------------------------------------------------------------------
  36.   def row_max() (@item_max + @column_max - 1) / @column_max  end
  37.   #--------------------------------------------------------------------------
  38.   # * Get Top Row
  39.   #--------------------------------------------------------------------------
  40.   def top_row()  self.oy / 32  end
  41.   #--------------------------------------------------------------------------
  42.   # * Set Top Row
  43.   #--------------------------------------------------------------------------
  44.   def top_row=(row)   self.oy = [[row,0].max, row_max-1].min * 32  end
  45.   #--------------------------------------------------------------------------
  46.   # * Get Number of Rows Displayable on 1 Page
  47.   #--------------------------------------------------------------------------
  48.   def page_row_max() (self.height - 32) / 32  end
  49.   #--------------------------------------------------------------------------
  50.   # * Get Number of Items Displayable on 1 Page
  51.   #--------------------------------------------------------------------------
  52.   def page_item_max() page_row_max * @column_max  end
  53.   #--------------------------------------------------------------------------
  54.   # * Set Help Window
  55.   #--------------------------------------------------------------------------
  56.   def help_window=(help_window)
  57.     @help_window = help_window
  58.     update_help if self.active and @help_window != nil
  59.   end
  60.   #--------------------------------------------------------------------------
  61.   # * Update Cursor Rectangle
  62.   #--------------------------------------------------------------------------
  63.   def update_cursor_rect
  64.     return  self.cursor_rect.empty if @index < 0
  65.     row = @index / @column_max
  66.     self.top_row = row if row < self.top_row
  67.     if row > self.top_row + (self.page_row_max - 1)
  68.       self.top_row = row - (self.page_row_max - 1)
  69.     end
  70.     cursor_width = self.width / @column_max - 32
  71.     x = @index % @column_max * (cursor_width + 32)
  72.     y = @index / @column_max * 32 - self.oy
  73.     self.cursor_rect.set(x, y, cursor_width, 32)
  74.   end
  75.   #--------------------------------------------------------------------------
  76.   # * Frame Update
  77.   #--------------------------------------------------------------------------
  78.   def update
  79.     super
  80.     if self.active and @item_max > 0 and @index >= 0
  81.       if Input.repeat?(Input::DOWN)
  82.         if (@column_max == 1 and Input.trigger?(Input::DOWN)) or
  83.            @index < @item_max - @column_max
  84.           Sound.play_cursor
  85.           @index = (@index + @column_max) % @item_max
  86.         end
  87.       end
  88.       if Input.repeat?(Input::UP)
  89.         if (@column_max == 1 and Input.trigger?(Input::UP)) or
  90.            @index >= @column_max
  91.           Sound.play_cursor
  92.           @index = (@index - @column_max + @item_max) % @item_max
  93.         end
  94.       end
  95.       if Input.repeat?(Input::RIGHT)
  96.         if @column_max >= 2 and @index < @item_max - 1
  97.           Sound.play_cursor
  98.           @index += 1
  99.         end
  100.       end
  101.       if Input.repeat?(Input::LEFT)
  102.         if @column_max >= 2 and @index > 0
  103.           Sound.play_cursor
  104.           @index -= 1
  105.         end
  106.       end
  107.       if Input.repeat?(Input::R)
  108.         if self.top_row + (self.page_row_max - 1) < (self.row_max - 1)
  109.           Sound.play_cursor
  110.           @index = [@index + self.page_item_max, @item_max - 1].min
  111.           self.top_row += self.page_row_max
  112.         end
  113.       end
  114.       if Input.repeat?(Input::L)
  115.         if self.top_row > 0
  116.           Sound.play_cursor
  117.           @index = [@index - self.page_item_max, 0].max
  118.           self.top_row -= self.page_row_max
  119.         end
  120.       end
  121.     end
  122.     update_help if self.active and @help_window != nil
  123.     update_cursor_rect
  124.   end
  125. end
  126. #==============================================================================
  127. # ** Window_InputNumber
  128. #------------------------------------------------------------------------------
  129. #  This window is for inputting numbers, and is used within the
  130. #  message window.
  131. #==============================================================================
  132.  
  133. class Window_InputNumber < Window_Base
  134.   #--------------------------------------------------------------------------
  135.   # * Object Initialization
  136.   #     digits_max : digit count
  137.   #--------------------------------------------------------------------------
  138.   def initialize(digits_max)
  139.     @digits_max = digits_max
  140.     @number = 0
  141.     # Calculate cursor width from number width (0-9 equal width and postulate)
  142.     dummy_bitmap = Bitmap.new(32, 32)
  143.     @cursor_width = dummy_bitmap.text_size("0").width + 8
  144.     dummy_bitmap.dispose
  145.     super(0, 0, @cursor_width * @digits_max + 32, 64)
  146.     self.contents = Bitmap.new(width - 32, height - 32)
  147.     self.z += 9999
  148.     self.opacity = 0
  149.     @index = 0
  150.     refresh
  151.     update_cursor_rect
  152.   end
  153.   #--------------------------------------------------------------------------
  154.   # * Get Number
  155.   #--------------------------------------------------------------------------
  156.   def number
  157.     return @number
  158.   end
  159.   #--------------------------------------------------------------------------
  160.   # * Set Number
  161.   #     number : new number
  162.   #--------------------------------------------------------------------------
  163.   def number=(number)
  164.     @number = [[number, 0].max, 10 ** @digits_max - 1].min
  165.     refresh
  166.   end
  167.   #--------------------------------------------------------------------------
  168.   # * Cursor Rectangle Update
  169.   #--------------------------------------------------------------------------
  170.   def update_cursor_rect
  171.     self.cursor_rect.set(@index * @cursor_width, 0, @cursor_width, 32)
  172.   end
  173.   #--------------------------------------------------------------------------
  174.   # * Frame Update
  175.   #--------------------------------------------------------------------------
  176.   def update
  177.     super
  178.     # If up or down directional button was pressed
  179.     if Input.repeat?(Input::UP) or Input.repeat?(Input::DOWN)
  180.       $game_system.se_play($data_system.cursor_se)
  181.       # Get current place number and change it to 0
  182.       place = 10 ** (@digits_max - 1 - @index)
  183.       n = @number / place % 10
  184.       @number -= n * place
  185.       # If up add 1, if down substract 1
  186.       n = (n + 1) % 10 if Input.repeat?(Input::UP)
  187.       n = (n + 9) % 10 if Input.repeat?(Input::DOWN)
  188.       # Reset current place number
  189.       @number += n * place
  190.       refresh
  191.     end
  192.     # Cursor right
  193.     if Input.repeat?(Input::RIGHT)
  194.       if @digits_max >= 2
  195.           Sound.play_cursor
  196.         @index = (@index + 1) % @digits_max
  197.       end
  198.     end
  199.     # Cursor left
  200.     if Input.repeat?(Input::LEFT)
  201.       if @digits_max >= 2
  202.           Sound.play_cursor
  203.         @index = (@index + @digits_max - 1) % @digits_max
  204.       end
  205.     end
  206.     update_cursor_rect
  207.   end
  208.   #--------------------------------------------------------------------------
  209.   # * Refresh
  210.   #--------------------------------------------------------------------------
  211.   def refresh
  212.     self.contents.clear
  213.     self.contents.font.color = normal_color
  214.     s = sprintf("%0*d", @digits_max, @number)
  215.     for i in 0...@digits_max
  216.       self.contents.draw_text(i * @cursor_width + 4, 0, 32, 32, s[i,1])
  217.     end
  218.   end
  219. end
  220.  
  221. end
  222. $drg_inv_sys_vx = true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement