示例#1
0
 /**
  * Sets the background drawable and sets the table's padding to {@link Drawable#getBottomHeight()}
  * , {@link Drawable#getTopHeight()}, {@link Drawable#getLeftWidth()}, and {@link
  * Drawable#getRightWidth()}.
  *
  * @param background If null, the background will be cleared and all padding is removed.
  */
 public void setBackground(Drawable background) {
   if (this.background == background) return;
   this.background = background;
   if (background == null) pad(null);
   else {
     padBottom(background.getBottomHeight());
     padTop(background.getTopHeight());
     padLeft(background.getLeftWidth());
     padRight(background.getRightWidth());
     invalidate();
   }
 }
  public HotbarInventoryView(
      Stage stage,
      Skin skin,
      Inventory hotbarInventory,
      Inventory inventory,
      DragAndDrop dragAndDrop,
      OreClient client) {
    m_skin = skin;
    m_inventory = inventory;
    m_client = client;
    m_stage = stage;

    m_hotbarInventory = hotbarInventory;
    // attach to the inventory model
    m_hotbarInventory.addListener(this);

    container = new Table(m_skin);
    container.setFillParent(true);
    container.top().left().setSize(800, 100);
    container.padLeft(10).padTop(10);

    container.defaults().space(4);

    stage.addActor(container);

    Image dragImage = new Image();
    dragImage.setSize(32, 32);

    for (byte i = 0; i < Inventory.maxHotbarSlots; ++i) {

      Image slotImage = new Image();

      SlotElement element = new SlotElement();
      m_slots[i] = element;

      element.itemImage = slotImage;

      Table slotTable = new Table(m_skin);
      element.table = slotTable;
      slotTable.setTouchable(Touchable.enabled);
      slotTable.addListener(new SlotClickListener(this, i));
      slotTable.addListener(new SlotInputListener(this, i));

      slotTable.add(slotImage);
      slotTable.background("default-pane");

      slotTable.row();

      Label itemCount = new Label(null, m_skin);
      slotTable.add(itemCount).bottom().fill();
      element.itemCountLabel = itemCount;

      //            container.add(slotTable).size(50, 50);
      container.add(slotTable).fill().size(50, 50);
      setHotbarSlotVisible(i, false);

      dragAndDrop.addSource(new HotbarDragSource(slotTable, i, dragImage, this));

      dragAndDrop.addTarget(new HotbarDragTarget(slotTable, i, this));
    }

    m_tooltip = new Label(null, m_skin);
    stage.addActor(m_tooltip);
  }