Equip item window clear bitmap problem

Started by gerrtunk, September 30, 2011, 06:44:59 am

Previous topic - Next topic

gerrtunk

Im trying to modify the equipitem window so each time it refreshes it shows a different type of equipment piece, not using a large number of them for each piece.

This is a modification creted for my golem system. Note that the window is refreshed and changued the slot each time its moved the cursor in the equip right slot window.

My problem is that the bitamp isnt erasing. It draws but there is also the last draw, and so on.
This code is executed so i dont get whats happening:

    if self.contents != nil
      #p'nil'
      self.contents = Bitmap.new(width - 32, height - 32)
      self.contents.clear
      self.contents.dispose
      self.contents = nil
    end


#==============================================================================
# ** Window_EquipItem
#------------------------------------------------------------------------------
#  This window displays choices when opting to change equipment on the
#  equipment screen.
#==============================================================================

class Window_GolemEquipItem < Window_Selectable
  attr_accessor   :slot_index
  #--------------------------------------------------------------------------
  # * Object Initialization
  #     actor      : actor
  #     equip_type : equip region (0-3)
  #--------------------------------------------------------------------------
  def initialize(actor, equip_type, slot_index=0)
    if actor.is_golem?
      super(0, 256, 272, 224)
    else
      super(0, 256, 640, 224)
    end
    @slot_index = slot_index
    @actor = actor
    @equip_type = equip_type
    @column_max = 1
    refresh
    self.active = false
    self.index = -1
  end
 
  def changue_slot (slot)
    @slot_index = slot
    refresh
  end
 
  #--------------------------------------------------------------------------
  # * Item Acquisition
  #--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end
 
  def test
    #p @data
  end
 
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
   
   
    if self.contents != nil
      #p'nil'
      self.contents = Bitmap.new(width - 32, height - 32)
      self.contents.clear
      self.contents.dispose
      self.contents = nil
    end
   
    @data = []
   
    if @actor.is_golem?
      #p'gol'
      # Add equipabble pieces
      for i in 1...$data_items.size
        # Only add pieces that exist, that are pieces, are equippables for
        # the actor and for the slot
        #p i, slot_index
       
        #piece_id = Piece.item_piece_id(i)
        if $game_party.item_number(i) > 0 and Piece.is_piece?(i)
          #p 't'
           if Piece.equipable?(@actor.actor_id, i)
            #p 'tst', i
            #p slot_index, @actor.golemslots[slot_index].type, Piece.item_piece_id(i)
           
            if @actor.golemslots[slot_index].equipable?(i)
               #p 'pushed', i
               @data.push(Piece.new(Piece.item_piece_id(i)))
            end
             
          end
        end
      end
     
      #p @data
    else
      # Add equippable weapons
      if @equip_type == 0
        weapon_set = $data_classes[@actor.class_id].weapon_set
        for i in 1...$data_weapons.size
          if $game_party.weapon_number(i) > 0 and weapon_set.include?(i)
            @data.push($data_weapons[i])
          end
        end
      end
      # Add equippable armor
      if @equip_type != 0
        armor_set = $data_classes[@actor.class_id].armor_set
        for i in 1...$data_armors.size
          if $game_party.armor_number(i) > 0 and armor_set.include?(i)
            if $data_armors[i].kind == @equip_type-1
              @data.push($data_armors[i])
            end
          end
        end
      end
    end
    # Add blank page
    @data.push(nil)
    # Make a bit map and draw all items
    @item_max = @data.size
    self.contents = Bitmap.new(width - 32, row_max * 32)
   
    for i in 0...@item_max-1
      draw_item(i)
    end
  end
 
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    #
   
    item = @data[index]
   
    #p 'di', index, item, item.name
    x = 0 #4 + index % 2 * (288 + 32)
    y = index * 32 #index / 2 * 32
    if @actor.is_golem?
      number = item.number
     
    else
      case item
      when RPG::Weapon
        number = $game_party.weapon_number(item.id)
      when RPG::Armor
        number = $game_party.armor_number(item.id)
      end
    end
   
    bitmap = RPG::Cache.icon(item.icon_name)
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
    self.contents.font.color = normal_color
   
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
    # originalment, 240, 256
    self.contents.draw_text(x + 128, y, 16, 32, ":", 1)
    self.contents.draw_text(x + 144, y, 24, 32, number.to_s, 2)
  end
 
  #--------------------------------------------------------------------------
  # * Help Text Update
  #--------------------------------------------------------------------------
  def update_help
    @help_window.set_text(self.item == nil ? "" : self.item.description)
  end
 
end

ForeverZer0

if self.contents != nil
  self.contents.dispose
  self.contents = nil
end

# Rest of method here


You are created a new instance, and then disposing it right afterwards.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

gerrtunk

That dont work too. I added these two lines so i tryed to erase the self.contents in any form, but even that fails.