SHARE
TWEET

Untitled

marlosgama Mar 24th, 2020 323 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. # ** Sprite_Hotbar
  3. #------------------------------------------------------------------------------
  4. #  Esta classe lida com a exibição dos atalhos.
  5. #------------------------------------------------------------------------------
  6. #  Autor: Valentine
  7. #==============================================================================
  8.  
  9. class Sprite_Hotbar < Sprite2
  10.  
  11.   def initialize
  12.     super
  13.     self.bitmap = Bitmap.new(355, 40)
  14.     self.x = adjust_x
  15.     self.y = adjust_y
  16.     self.z = 50
  17.     @back = Cache.system('Hotbar')
  18.     @iconset = Cache.system('Iconset')
  19.     @dragable = true
  20.     @old_item = nil
  21.     create_desc
  22.     refresh
  23.   end
  24.  
  25.   def adjust_x
  26.     Graphics.width / 2 - 127
  27.   end
  28.  
  29.   def adjust_y
  30.     Graphics.height - 70
  31.   end
  32.  
  33.   def slot_width
  34.     28
  35.   end
  36.  
  37.   def slot_height
  38.     28
  39.   end
  40.  
  41.   def create_desc
  42.     @desc_sprite = Sprite_Desc.new
  43.     # Deixa a janela de informações sobre o inventário
  44.     @desc_sprite.z = self.z + 100
  45.   end
  46.  
  47.   def refresh
  48.     draw_background
  49.     draw_items
  50.   end
  51.  
  52.   def draw_background
  53.     self.bitmap.clear
  54.     self.bitmap.blt(0, 0, @back, self.bitmap.rect)
  55.   end
  56.  
  57.   def draw_items
  58.     $game_actors[1].hotbar.each_with_index do |item, i|
  59.       draw_icon(item, i) if item
  60.     end
  61.   end
  62.  
  63.   def x_slots
  64.     [9, 43, 77, 111, 194, 228, 264, 296]
  65.   end
  66.  
  67.   def draw_icon(item, index)
  68.     rect = Rect.new(item.icon_index % 16 * 24, item.icon_index / 16 * 24, 24, 24)
  69.     opacity = item.is_a?(RPG::Item) & !$game_party.has_item?(item) ? 160 : 255
  70.     self.bitmap.blt(x_slots[index], 7, @iconset, rect, opacity)
  71.     self.bitmap.draw_text(x_slots[index] - 8, 19, slot_width, 18, $game_party.item_number(item), 2) if item.is_a?(RPG::Item)
  72.   end
  73.  
  74.   def show_desc(item)
  75.     return if @old_item == item
  76.     @desc_sprite.refresh(item)
  77.     @old_item = item
  78.   end
  79.  
  80.   def hide_desc
  81.     @desc_sprite.visible = false
  82.     @old_item = nil
  83.   end
  84.  
  85.   def update
  86.     super
  87.     update_drop
  88.     remove_item
  89.     update_desc
  90.   end
  91.  
  92.   def update_drop
  93.     return if Mouse.press?(:L)
  94.     return unless $cursor.object.is_a?(RPG::Item) || $cursor.object.is_a?(RPG::Skill)
  95.     $game_actors[1].hotbar.each_index do |i|
  96.       next unless in_area?(x_slots[i], 0, slot_width, slot_height)
  97.       $network.send_change_hotbar(i, $cursor.type, $cursor.object.id)
  98.       break
  99.     end
  100.   end
  101.  
  102.   def remove_item
  103.     return unless Mouse.click?(:R)
  104.     $game_actors[1].hotbar.each_with_index do |item, i|
  105.       next unless in_area?(x_slots[i], 0, slot_width, slot_height) && item
  106.       $network.send_change_hotbar(i, Constants::HOTBAR_NONE, 0)
  107.       break
  108.     end
  109.   end
  110.  
  111.   def update_desc
  112.     return if $dragging_window
  113.     index = -1
  114.     $game_actors[1].hotbar.each_with_index do |item, i|
  115.       next unless in_area?(x_slots[i], 0, slot_width, slot_height) && item
  116.       index = i
  117.       break
  118.     end
  119.     if index >= 0 && !$cursor.object
  120.       show_desc($game_actors[1].hotbar[index])
  121.     else
  122.       hide_desc
  123.     end
  124.   end
  125.  
  126. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top